diff --git a/zion/memory/paging_util.cpp b/zion/memory/paging_util.cpp index 727a276..ccad031 100644 --- a/zion/memory/paging_util.cpp +++ b/zion/memory/paging_util.cpp @@ -41,6 +41,39 @@ uint64_t ShiftForEntryIndexing(uint64_t addr, uint64_t offset) { return addr; } +uint64_t* Pml4Entry(uint64_t addr) { + return reinterpret_cast(PML_RECURSE | + ShiftForEntryIndexing(addr, PML_OFFSET)); +} + +uint64_t* PageDirectoryPointerEntry(uint64_t addr) { + return reinterpret_cast(PDP_RECURSE | + ShiftForEntryIndexing(addr, PDP_OFFSET)); +} + +uint64_t* PageDirectoryEntry(uint64_t addr) { + return reinterpret_cast(PD_RECURSE | + ShiftForEntryIndexing(addr, PD_OFFSET)); +} + +uint64_t* PageTableEntry(uint64_t addr) { + return reinterpret_cast(PT_RECURSE | + ShiftForEntryIndexing(addr, PT_OFFSET)); +} + +bool PageDirectoryPointerLoaded(uint64_t addr) { + return *Pml4Entry(addr) & PRESENT_BIT; +} + +bool PageDirectoryLoaded(uint64_t addr) { + return PageDirectoryPointerLoaded(addr) && + (*PageDirectoryPointerEntry(addr) & PRESENT_BIT); +} + +bool PageTableLoaded(uint64_t addr) { + return PageDirectoryLoaded(addr) && (*PageDirectoryEntry(addr) & PRESENT_BIT); +} + void MapPage(uint64_t virt, uint64_t phys) { if (PageLoaded(virt)) { panic("Allocating Over Existing Page: %m", virt); @@ -97,39 +130,6 @@ void EnsureResident(uint64_t addr, uint64_t size) { } } -uint64_t* Pml4Entry(uint64_t addr) { - return reinterpret_cast(PML_RECURSE | - ShiftForEntryIndexing(addr, PML_OFFSET)); -} - -uint64_t* PageDirectoryPointerEntry(uint64_t addr) { - return reinterpret_cast(PDP_RECURSE | - ShiftForEntryIndexing(addr, PDP_OFFSET)); -} - -uint64_t* PageDirectoryEntry(uint64_t addr) { - return reinterpret_cast(PD_RECURSE | - ShiftForEntryIndexing(addr, PD_OFFSET)); -} - -uint64_t* PageTableEntry(uint64_t addr) { - return reinterpret_cast(PT_RECURSE | - ShiftForEntryIndexing(addr, PT_OFFSET)); -} - -bool PageDirectoryPointerLoaded(uint64_t addr) { - return *Pml4Entry(addr) & PRESENT_BIT; -} - -bool PageDirectoryLoaded(uint64_t addr) { - return PageDirectoryPointerLoaded(addr) && - (*PageDirectoryPointerEntry(addr) & PRESENT_BIT); -} - -bool PageTableLoaded(uint64_t addr) { - return PageDirectoryLoaded(addr) && (*PageDirectoryEntry(addr) & PRESENT_BIT); -} - bool PageLoaded(uint64_t addr) { return PageTableLoaded(addr) && (*PageTableEntry(addr) & PRESENT_BIT); } diff --git a/zion/memory/paging_util.h b/zion/memory/paging_util.h index fb261a7..744b9e8 100644 --- a/zion/memory/paging_util.h +++ b/zion/memory/paging_util.h @@ -5,18 +5,7 @@ void InitPaging(); void InitializePml4(uint64_t pml4_physical_addr); -void AllocatePageDirectoryPointer(uint64_t addr); -void AllocatePageDirectory(uint64_t addr); -void AllocatePageTable(uint64_t addr); void AllocatePage(uint64_t addr); void EnsureResident(uint64_t addr, uint64_t size); -uint64_t* Pml4Entry(uint64_t addr); -uint64_t* PageDirectoryPointerEntry(uint64_t addr); -uint64_t* PageDirectoryEntry(uint64_t addr); -uint64_t* PageTableEntry(uint64_t addr); - -bool PageDirectoryPointerLoaded(uint64_t addr); -bool PageDirectoryLoaded(uint64_t addr); -bool PageTableLoaded(uint64_t addr); bool PageLoaded(uint64_t addr);