A small x86-64 kernel. Stage 0 goes from real mode to long mode inside the boot sector.
Print the banner from 64-bit code
Browse files
failing
1 step in 1 ms
2 files changed
+25−2
@@ -1,7 +1,19 @@
11 # kestrel
22
3−A small x86-64 kernel, built one boot stage at a time. Stage 0 lives in the boot sector; for now it boots and halts.
3+A small x86-64 kernel, built one boot stage at a time. Stage 0 fits in the boot sector and goes from real mode straight to long mode.
44
55 ```
66 make run
77 ```
8+
9+QEMU shows `kestrel` in the middle of the screen, written by 64-bit code.
10+
11+## Stage 0, in order
12+
13+1. Zero the segment registers and put the stack under the boot sector.
14+2. Open the A20 gate through port `0x92`, keeping bit 0 clear (it resets the machine).
15+3. Build PML4 → PDPT → PD at `0x1000`–`0x3FFF`, mapping the first 2 MiB with one huge page.
16+4. Set `CR4.PAE`, load `CR3`, set `EFER.LME`, then turn on `CR0.PG` and `CR0.PE` together.
17+5. Far-jump into the 64-bit code segment and write the banner to `0xB8000`.
18+
19+Skipping protected mode works on QEMU. Real-hardware reports belong in the issues.
@@ -2,7 +2,8 @@
22 ;
33 ; The BIOS loads this sector at 0x7C00 and jumps to it in 16-bit real mode.
44 ; We enable A20, identity-map the first 2 MiB with a single huge page, switch
5−; on PAE, long mode and paging in one step, and land in 64-bit code.
5+; on PAE, long mode and paging in one step, and land in 64-bit code that
6+; writes the banner straight into VGA text memory.
67 ;
78 ; nasm -f bin boot.asm -o boot.bin
89 ; qemu-system-x86_64 -drive format=raw,file=boot.bin
@@ -64,9 +65,19 @@ long_mode:
6465 mov ds, ax
6566 mov es, ax
6667 mov ss, ax
68+ mov rsi, banner
69+ mov edi, 0xB8000 + (12 * 80 + 36) * 2 ; row 12, centred
70+ mov ah, 0x07 ; light grey on black
71+.print: lodsb
72+ test al, al
73+ jz .halt
74+ stosw
75+ jmp .print
6776 .halt: hlt
6877 jmp .halt
6978
79+banner: db "kestrel", 0
80+
7081 align 8
7182 gdt: dq 0
7283 .code: equ $ - gdt