61 lines
1.2 KiB
NASM
61 lines
1.2 KiB
NASM
[bits 16]
|
|
section .text
|
|
global _start
|
|
|
|
_start:
|
|
mov [BOOT_DRIVE], dl ; Save the boot drive number provided by BIOS
|
|
|
|
mov bp, 0x9000
|
|
mov sp, bp
|
|
|
|
call load_kernel ; Load extra sectors from the disk
|
|
call switch_to_pm ; Transition to 32-bit mode
|
|
jmp $
|
|
|
|
%include "gdt.asm"
|
|
|
|
[bits 16]
|
|
load_kernel:
|
|
mov bx, 0x7e00 ; Destination memory address for kernel code
|
|
mov dh, 30 ; Number of sectors to read
|
|
mov dl, [BOOT_DRIVE]
|
|
mov ah, 0x02 ; BIOS read sectors function
|
|
mov al, dh
|
|
mov ch, 0x00
|
|
mov dh, 0x00
|
|
mov cl, 0x02 ; Start reading from the second sector
|
|
|
|
int 0x13 ; Trigger BIOS disk interrupt
|
|
|
|
jc disk_error
|
|
ret
|
|
|
|
disk_error:
|
|
jmp $
|
|
|
|
[bits 16]
|
|
switch_to_pm:
|
|
cli
|
|
lgdt [gdt_descriptor]
|
|
mov eax, cr0
|
|
or eax, 0x1
|
|
mov cr0, eax
|
|
jmp CODE_SEG:init_pm
|
|
|
|
[bits 32]
|
|
extern main
|
|
init_pm:
|
|
mov ax, DATA_SEG
|
|
mov ds, ax
|
|
mov ss, ax
|
|
mov es, ax
|
|
mov fs, ax
|
|
mov gs, ax
|
|
|
|
mov ebp, 0x90000
|
|
mov esp, ebp
|
|
|
|
call main
|
|
jmp $
|
|
|
|
BOOT_DRIVE db 0 |