; boot.asm — Kestrel stage 0. ; ; The BIOS loads this sector at 0x7C00 and jumps to it in 16-bit real mode. ; We enable A20 and identity-map the first 2 MiB with a single huge page, ; ready for the switch to long mode. ; ; nasm -f bin boot.asm -o boot.bin ; qemu-system-x86_64 -drive format=raw,file=boot.bin bits 16 org 0x7C00 PML4 equ 0x1000 ; page tables live in free low memory PDPT equ 0x2000 PD equ 0x3000 PRESENT_WRITABLE equ 0x03 HUGE equ 0x80 start: cli xor ax, ax mov ds, ax mov es, ax mov ss, ax mov sp, 0x7C00 cld in al, 0x92 ; fast A20 gate or al, 2 and al, 0xFE ; bit 0 would reset the machine out 0x92, al mov di, PML4 ; clear the PML4 mov cx, 4096 / 2 xor ax, ax rep stosw mov di, PDPT ; clear the PDPT mov cx, 4096 / 2 rep stosw mov di, PD ; clear the PD mov cx, 4096 / 2 rep stosw mov word [PML4], PDPT | PRESENT_WRITABLE mov word [PDPT], PD | PRESENT_WRITABLE mov word [PD], HUGE | PRESENT_WRITABLE ; 0..2 MiB, identity .halt: hlt jmp .halt times 510 - ($ - $$) db 0 dw 0xAA55 ; boot signature