acompiled

The catalog contains seeded project examples. Your workspace stores your own projects and conversations.

kestrel-os/kestrel

Public
Star8

A small x86-64 kernel. Stage 0 goes from real mode to long mode inside the boot sector.

Identity-map the first 2 MiB with one huge page

Browse files
mirellecommitted 1 parent 3a97cbb commit ae43b29f23713173b81375e3d28c7ae0af44a5a1
failing 1 step in 1 ms
1 file changed +22−1
modified boot/boot.asm +22−1
@@ -1,7 +1,8 @@
11 ; boot.asm — Kestrel stage 0.
22 ;
33 ; The BIOS loads this sector at 0x7C00 and jumps to it in 16-bit real mode.
4−; We set up flat segments and a stack, enable A20, and halt.
4+; We enable A20 and identity-map the first 2 MiB with a single huge page,
5+; ready for the switch to long mode.
56 ;
67 ; nasm -f bin boot.asm -o boot.bin
78 ; qemu-system-x86_64 -drive format=raw,file=boot.bin
@@ -9,6 +10,12 @@
910 bits 16
1011 org 0x7C00
1112
13+PML4 equ 0x1000 ; page tables live in free low memory
14+PDPT equ 0x2000
15+PD equ 0x3000
16+PRESENT_WRITABLE equ 0x03
17+HUGE equ 0x80
18+
1219 start:
1320 cli
1421 xor ax, ax
@@ -22,6 +29,20 @@ start:
2229 or al, 2
2330 out 0x92, al
2431
32+ mov di, PML4 ; clear the PML4
33+ mov cx, 4096 / 2
34+ xor ax, ax
35+ rep stosw
36+ mov di, PDPT ; clear the PDPT
37+ mov cx, 4096 / 2
38+ rep stosw
39+ mov di, PD ; clear the PD
40+ mov cx, 4096 / 2
41+ rep stosw
42+ mov word [PML4], PDPT | PRESENT_WRITABLE
43+ mov word [PDPT], PD | PRESENT_WRITABLE
44+ mov word [PD], HUGE | PRESENT_WRITABLE ; 0..2 MiB, identity
45+
2546 .halt: hlt
2647 jmp .halt
2748