M2 step 1-2: loader builds bootstrap tables + CR3 handoff

Add the higher-half layout constants (physToVirt/virtToPhys, physmap
and kernel bases) to the danos handoff module, and KernelSegment.phys
so the loader records where it actually placed each segment.

The loader now builds its own page tables before ExitBootServices —
identity + a physmap of low RAM (2 MiB pages) plus 4 KiB mappings for
any higher-half kernel segment — and switches CR3, then calls the entry
with boot_info in RDI, interrupts off. The kernel still links and runs
low (identity), oblivious; this proves the CR3 dance in isolation.
Suite 27/27.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Samson
2026-07-08 22:28:43 +01:00
co-authored by Claude Fable 5
parent 91aff2bc4a
commit 75bc429aa1
3 changed files with 186 additions and 11 deletions
+4 -3
View File
@@ -107,9 +107,10 @@ pub fn init(allocFrame: *const fn () ?u64, boot_info: *const danos.BootInfo) voi
var flags: u64 = present;
if (seg.flags & pf_w != 0) flags |= writable;
if (seg.flags & pf_x == 0) flags |= no_execute;
var addr = seg.virt;
const end = seg.virt + seg.pages * page_size;
while (addr < end) : (addr += page_size) mapPage(pml4, addr, addr, flags);
var off: u64 = 0;
while (off < seg.pages * page_size) : (off += page_size) {
mapPage(pml4, seg.virt + off, seg.phys + off, flags);
}
}
kernel_pml4 = pml4;