A small x86-64 kernel. Stage 0 goes from real mode to long mode inside the boot sector.
Memory map at the end of stage 0
| Range | Contents |
|---|---|
0x0000_0000–0x0000_04FF | Real-mode IVT and BIOS data area (left alone) |
0x0000_1000–0x0000_1FFF | PML4, entry 0 → PDPT |
0x0000_2000–0x0000_2FFF | PDPT, entry 0 → PD |
0x0000_3000–0x0000_3FFF | PD, entry 0 = 2 MiB huge page at 0, present and writable |
0x0000_7C00–0x0000_7DFF | Stage 0 (this sector); the stack grows down from 0x7C00 |
0x000B_8000–0x000B_8F9F | VGA 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.