fix: paging::get()

This commit is contained in:
2026-10-20 15:55:26 +02:00
parent 811ce51c2c
commit 3aa3538489
+27 -8
View File
@@ -95,7 +95,14 @@ paging::paging(pmm& pmm)
m_pml4 = reinterpret_cast<u64*>(m_pml4Phys + HHDM_BASE);
pmm.relocate_bitmap(HHDM_BASE);
// TODO: Map the rest of RAM
for (auto *entry = pmm.get_mmap().entries, *end = entry + pmm.get_mmap().entryCount; entry != end; ++entry) {
if (entry->type != mmap::entry::AVAILABLE) continue;
const physaddr_t begin = entry->base;
const physaddr_t entryEnd = entry->base + entry->size;
if (entryEnd < BOOTSTRAP_HHDM_LIMIT) continue;
map_hhdm(begin >= BOOTSTRAP_HHDM_LIMIT ? begin : BOOTSTRAP_HHDM_LIMIT, entryEnd);
}
}
physaddr_t paging::get(virtaddr_t virtualAddr) {
@@ -106,14 +113,26 @@ physaddr_t paging::get(virtaddr_t virtualAddr) {
u64 pdIdx = (addrInt >> 21) & ENTRY_INDEX_MASK;
u64 ptIdx = (addrInt >> 12) & ENTRY_INDEX_MASK;
const bool bootstrap = reinterpret_cast<virtaddr_t>(m_pml4) < HHDM_BASE;
auto tableFromPhys = [bootstrap](physaddr_t physical) -> u64* {
return bootstrap ? reinterpret_cast<u64*>(physical) : reinterpret_cast<u64*>(HHDM_BASE + physical);
};
u64 pml4e = m_pml4[pml4Idx];
if ((pml4e & 0x01) == 0) return INVALID_PHYSADDR;
u64 pdpte = reinterpret_cast<u64*>(pml4e & PHYS_MASK)[pdptIdx];
if ((pdpte & 0x01) == 0) return INVALID_PHYSADDR;
u64 pde = reinterpret_cast<u64*>(pdpte & PHYS_MASK)[pdIdx];
if ((pde & 0x01) == 0) return INVALID_PHYSADDR;
u64 pte = reinterpret_cast<u64*>(pde & PHYS_MASK)[ptIdx];
if ((pte & 0x01) == 0) return INVALID_PHYSADDR;
if ((pml4e & PAGE_PRESENT) == 0) return INVALID_PHYSADDR;
u64* pdpt = tableFromPhys(pml4e & PHYS_MASK);
u64 pdpte = pdpt[pdptIdx];
if ((pdpte & PAGE_PRESENT) == 0) return INVALID_PHYSADDR;
u64* pd = tableFromPhys(pdpte & PHYS_MASK);
u64 pde = pd[pdIdx];
if ((pde & PAGE_PRESENT) == 0) return INVALID_PHYSADDR;
if ((pde & PAGE_LARGE) == PAGE_LARGE) panic();
u64* pt = tableFromPhys(pde & PHYS_MASK);
u64 pte = pt[ptIdx];
return (pte & PHYS_MASK) | (addrInt & ((1 << 12) - 1));
}