diff --git a/sdk/xtdk/amd64/mmtypes.h b/sdk/xtdk/amd64/mmtypes.h index c6211c7..9479175 100644 --- a/sdk/xtdk/amd64/mmtypes.h +++ b/sdk/xtdk/amd64/mmtypes.h @@ -43,12 +43,6 @@ #define MM_PXI_SHIFT 39 #define MM_P5I_SHIFT 48 -/* Number of PTEs per page */ -#define MM_PTE_PER_PAGE 512 -#define MM_PDE_PER_PAGE 512 -#define MM_PPE_PER_PAGE 512 -#define MM_PXE_PER_PAGE 512 - /* PTE state flags */ #define MM_PTE_VALID 0x0000000000000001ULL #define MM_PTE_ACCESSED 0x0000000000000020ULL diff --git a/xtoskrnl/includes/mm/pte.hh b/xtoskrnl/includes/mm/pte.hh index fc7f96f..e43d1fe 100644 --- a/xtoskrnl/includes/mm/pte.hh +++ b/xtoskrnl/includes/mm/pte.hh @@ -18,6 +18,7 @@ namespace MM class Pte { public: + STATIC XTAPI ULONG GetPtesPerPage(VOID); STATIC XTAPI VOID MapP5E(PVOID StartAddress, PVOID EndAddress, PMMP5E TemplateP5e); diff --git a/xtoskrnl/mm/mmgr.cc b/xtoskrnl/mm/mmgr.cc index f08e6a6..79af5a4 100644 --- a/xtoskrnl/mm/mmgr.cc +++ b/xtoskrnl/mm/mmgr.cc @@ -38,10 +38,12 @@ MM::Manager::InitializeMemoryLayout(VOID) { ULONG_PTR PagedPoolSize, PteCount; PFN_NUMBER PfnDatabaseSize; + ULONG PtesPerPage; - /* Calculate size of paged pool (at least 32MiB) */ - PteCount = ((SIZE_TO_PAGES(33554432) + (MM_PTE_PER_PAGE - 1)) / MM_PTE_PER_PAGE); - PagedPoolSize = PteCount * MM_PTE_PER_PAGE * MM_PAGE_SIZE; + /* Get the number of PTEs per page and calculate size of paged pool (at least 32MiB) */ + PtesPerPage = MM::Pte::GetPtesPerPage(); + PteCount = ((SIZE_TO_PAGES(33554432) + (PtesPerPage - 1)) / PtesPerPage); + PagedPoolSize = PteCount * PtesPerPage * MM_PAGE_SIZE; /* Retrieve the PFN database size */ PfnDatabaseSize = MM::Pfn::GetPfnDatabaseSize(); diff --git a/xtoskrnl/mm/pte.cc b/xtoskrnl/mm/pte.cc index c460807..4d2614a 100644 --- a/xtoskrnl/mm/pte.cc +++ b/xtoskrnl/mm/pte.cc @@ -9,6 +9,21 @@ #include +/** + * Calculates the number of Page Table Entries (PTEs) that fit within a single page. + * + * @return This routine returns the number of PTEs per page. + * + * @since XT 1.0 + */ +XTAPI +ULONG +MM::Pte::GetPtesPerPage(VOID) +{ + /* Calculate and return the number of PTEs per page */ + return MM_PAGE_SIZE / MM::Paging::GetPteSize(); +} + /** * Maps a range of virtual addresses at the P5E (PML5) level. *