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.

History
16 lines·961 B·Markdown Source Raw Blame

Memory map at the end of stage 0

RangeContents
0x0000_0000–0x0000_04FFReal-mode IVT and BIOS data area (left alone)
0x0000_1000–0x0000_1FFFPML4, entry 0 → PDPT
0x0000_2000–0x0000_2FFFPDPT, entry 0 → PD
0x0000_3000–0x0000_3FFFPD, entry 0 = 2 MiB huge page at 0, present and writable
0x0000_7C00–0x0000_7DFFStage 0 (this sector); the stack grows down from 0x7C00
0x000B_8000–0x000B_8F9FVGA text buffer, 80×25 cells of character + attribute

Everything below 2 MiB is identity-mapped, so the far jump into long_mode uses the same addresses the assembler computed with org 0x7C00.

The jump

jmp gdt.code:long_mode is assembled in 16-bit mode, so the offset is 16 bits wide. That only works because long_mode sits below 64 KiB. Stage 1 will be loaded at 0x8000 and must keep the same rule, or switch to a 32-bit far jump through a memory operand.