diff --git a/xtoskrnl/includes/mm/amd64/pte.hh b/xtoskrnl/includes/mm/amd64/pte.hh index 50fefec..c5d4f6b 100644 --- a/xtoskrnl/includes/mm/amd64/pte.hh +++ b/xtoskrnl/includes/mm/amd64/pte.hh @@ -18,7 +18,10 @@ namespace MM class Pte { public: + STATIC XTAPI BOOLEAN AddressValid(IN PVOID VirtualAddress); STATIC XTAPI ULONG GetPtesPerPage(VOID); + STATIC XTAPI PMMPTE GetSystemPteBaseAddress(VOID); + STATIC XTAPI VOID InitializePageTable(VOID); STATIC XTAPI VOID MapP5E(PVOID StartAddress, PVOID EndAddress, PMMP5E TemplateP5e); diff --git a/xtoskrnl/includes/mm/i686/pte.hh b/xtoskrnl/includes/mm/i686/pte.hh index 34eaa14..b29f91a 100644 --- a/xtoskrnl/includes/mm/i686/pte.hh +++ b/xtoskrnl/includes/mm/i686/pte.hh @@ -18,7 +18,10 @@ namespace MM class Pte { public: + STATIC XTAPI BOOLEAN AddressValid(IN PVOID VirtualAddress); STATIC XTAPI ULONG GetPtesPerPage(VOID); + STATIC XTAPI PMMPTE GetSystemPteBaseAddress(VOID); + STATIC XTAPI VOID InitializePageTable(VOID); STATIC XTAPI VOID MapPDE(PVOID StartAddress, PVOID EndAddress, PMMPDE TemplatePde); diff --git a/xtoskrnl/mm/amd64/pte.cc b/xtoskrnl/mm/amd64/pte.cc index d74156a..796cd45 100644 --- a/xtoskrnl/mm/amd64/pte.cc +++ b/xtoskrnl/mm/amd64/pte.cc @@ -9,6 +9,89 @@ #include +/** + * Checks if the virtual address is valid and mapped in the page tables. + * + * @param VirtualAddress + * The virtual address to check. + * + * @return This routine returns TRUE if the address is valid, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTAPI +BOOLEAN +MM::Pte::AddressValid(IN PVOID VirtualAddress) +{ + /* Check XPA status */ + if(MM::Paging::GetXpaStatus()) + { + /* Check if the P5E is valid */ + if(!MM::Paging::PteValid(MM::Paging::GetP5eAddress(VirtualAddress))) + { + /* Invalid P5E, return FALSE */ + return FALSE; + } + } + + /* Check if PXE, PPE, PDE and PTE are valid */ + if(!MM::Paging::PteValid(MM::Paging::GetPxeAddress(VirtualAddress)) || + !MM::Paging::PteValid(MM::Paging::GetPpeAddress(VirtualAddress)) || + !MM::Paging::PteValid(MM::Paging::GetPdeAddress(VirtualAddress)) || + !MM::Paging::PteValid(MM::Paging::GetPteAddress(VirtualAddress))) + { + /* Invalid PXE, PPE, PDE or PTE, return FALSE */ + return FALSE; + } + + /* Address is valid, return TRUE */ + return TRUE; +} + +/** + * Retrieves the base virtual address of the system PTEs. + * + * @return This routine returns a pointer to the first PTE in the system PTE space. + * + * @since XT 1.0 + */ +XTAPI +PMMPTE +MM::Pte::GetSystemPteBaseAddress(VOID) +{ + PMMMEMORY_LAYOUT MemoryLayout; + + /* Retrieve the system's memory layout */ + MemoryLayout = MM::Manager::GetMemoryLayout(); + + /* Determine the base address for system PTEs based on the paging mode */ + if(MM::Paging::GetXpaStatus()) + { + /* For 5-level paging, system PTEs start at the beginning of system space */ + return MM::Paging::GetPteAddress((PVOID)MemoryLayout->SystemSpaceStart); + } + else + { + /* For 4-level paging, system PTEs start at the legacy KSEG0_BASE */ + return MM::Paging::GetPteAddress((PVOID)KSEG0_BASE); + } +} + + +/** + * Performs the initial setup of the system's page table hierarchy. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Pte::InitializePageTable(VOID) +{ + UNIMPLEMENTED; +} + /** * Maps a range of virtual addresses at the P5E (PML5) level. * diff --git a/xtoskrnl/mm/i686/pte.cc b/xtoskrnl/mm/i686/pte.cc index 97db714..b425228 100644 --- a/xtoskrnl/mm/i686/pte.cc +++ b/xtoskrnl/mm/i686/pte.cc @@ -8,3 +8,68 @@ #include + +/** + * Checks if the virtual address is valid and mapped in the page tables. + * + * @param VirtualAddress + * The virtual address to check. + * + * @return This routine returns TRUE if the address is valid, or FALSE otherwise. + * + * @since XT 1.0 + */ +XTAPI +BOOLEAN +MM::Pte::AddressValid(IN PVOID VirtualAddress) +{ + /* Check XPA status */ + if(MM::Paging::GetXpaStatus()) + { + /* Check if the P5E is valid */ + if(!MM::Paging::PteValid(MM::Paging::GetPpeAddress(VirtualAddress))) + { + /* Invalid PPE, return FALSE */ + return FALSE; + } + } + + /* Check if PDE and PTE are valid */ + if(!MM::Paging::PteValid(MM::Paging::GetPdeAddress(VirtualAddress)) || + !MM::Paging::PteValid(MM::Paging::GetPteAddress(VirtualAddress))) + { + /* Invalid PDE or PTE, return FALSE */ + return FALSE; + } + + /* Address is valid, return TRUE */ + return TRUE; +} + +/** + * Retrieves the base virtual address of the system PTEs. + * + * @return This routine returns a pointer to the first PTE in the system PTE space. + * + * @since XT 1.0 + */ +XTAPI +PMMPTE +MM::Pte::GetSystemPteBaseAddress(VOID) +{ + return MM::Paging::GetPteAddress(NULLPTR); +} + +/** + * Performs the initial setup of the system's page table hierarchy. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Pte::InitializePageTable(VOID) +{ + UNIMPLEMENTED; +}