diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index 08266ea..847c1e2 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -53,6 +53,7 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/ke/timer.cc ${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pagemap.cc ${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/paging.cc + ${XTOSKRNL_SOURCE_DIR}/mm/${ARCH}/pte.cc ${XTOSKRNL_SOURCE_DIR}/mm/data.cc ${XTOSKRNL_SOURCE_DIR}/mm/hlpool.cc ${XTOSKRNL_SOURCE_DIR}/mm/kpool.cc diff --git a/xtoskrnl/includes/mm.hh b/xtoskrnl/includes/mm.hh index a8cb42e..bd94683 100644 --- a/xtoskrnl/includes/mm.hh +++ b/xtoskrnl/includes/mm.hh @@ -13,11 +13,11 @@ #include XTOS_ARCH_HEADER(mm, pagemap.hh) #include XTOS_ARCH_HEADER(mm, paging.hh) +#include XTOS_ARCH_HEADER(mm, pte.hh) #include #include #include #include -#include #endif /* __XTOSKRNL_MM_HH */ diff --git a/xtoskrnl/includes/mm/amd64/pte.hh b/xtoskrnl/includes/mm/amd64/pte.hh new file mode 100644 index 0000000..50fefec --- /dev/null +++ b/xtoskrnl/includes/mm/amd64/pte.hh @@ -0,0 +1,40 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/mm/amd64/pte.hh + * DESCRIPTION: Page table entry (PTE) for AMD64 support + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_MM_AMD64_PTE_HH +#define __XTOSKRNL_MM_AMD64_PTE_HH + +#include + + +/* Memory Manager */ +namespace MM +{ + class Pte + { + public: + STATIC XTAPI ULONG GetPtesPerPage(VOID); + STATIC XTAPI VOID MapP5E(PVOID StartAddress, + PVOID EndAddress, + PMMP5E TemplateP5e); + STATIC XTAPI VOID MapPDE(PVOID StartAddress, + PVOID EndAddress, + PMMPDE TemplatePde); + STATIC XTAPI VOID MapPPE(PVOID StartAddress, + PVOID EndAddress, + PMMPPE TemplatePpe); + STATIC XTAPI VOID MapPTE(PVOID StartAddress, + PVOID EndAddress, + PMMPTE TemplatePte); + STATIC XTAPI VOID MapPXE(PVOID StartAddress, + PVOID EndAddress, + PMMPXE TemplatePxe); + }; +} + +#endif /* __XTOSKRNL_MM_AMD64_PTE_HH */ diff --git a/xtoskrnl/includes/mm/i686/pagemap.hh b/xtoskrnl/includes/mm/i686/pagemap.hh index 9233f2b..5d94662 100644 --- a/xtoskrnl/includes/mm/i686/pagemap.hh +++ b/xtoskrnl/includes/mm/i686/pagemap.hh @@ -1,13 +1,13 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/includes/mm/pagemap.hh + * FILE: xtoskrnl/includes/mm/i686/pagemap.hh * DESCRIPTION: Low-level support for page map manipulation * DEVELOPERS: Aiken Harris */ -#ifndef __XTOSKRNL_MM_PAGEMAP_HH -#define __XTOSKRNL_MM_PAGEMAP_HH +#ifndef __XTOSKRNL_MM_I686_PAGEMAP_HH +#define __XTOSKRNL_MM_I686_PAGEMAP_HH #include @@ -109,4 +109,4 @@ namespace MM }; } -#endif /* __XTOSKRNL_MM_PAGEMAP_HH */ +#endif /* __XTOSKRNL_MM_I686_PAGEMAP_HH */ diff --git a/xtoskrnl/includes/mm/pte.hh b/xtoskrnl/includes/mm/i686/pte.hh similarity index 84% rename from xtoskrnl/includes/mm/pte.hh rename to xtoskrnl/includes/mm/i686/pte.hh index e43d1fe..1fca7b2 100644 --- a/xtoskrnl/includes/mm/pte.hh +++ b/xtoskrnl/includes/mm/i686/pte.hh @@ -1,13 +1,13 @@ /** * PROJECT: ExectOS * COPYRIGHT: See COPYING.md in the top level directory - * FILE: xtoskrnl/includes/mm/pte.hh - * DESCRIPTION: Page table entry (PTE) support + * FILE: xtoskrnl/includes/mm/i686/pte.hh + * DESCRIPTION: Page table entry (PTE) for i686 support * DEVELOPERS: Aiken Harris */ -#ifndef __XTOSKRNL_MM_PTE_HH -#define __XTOSKRNL_MM_PTE_HH +#ifndef __XTOSKRNL_MM_I686_PTE_HH +#define __XTOSKRNL_MM_I686_PTE_HH #include @@ -37,4 +37,4 @@ namespace MM }; } -#endif /* __XTOSKRNL_MM_PTE_HH */ +#endif /* __XTOSKRNL_MM_I686_PTE_HH */ diff --git a/xtoskrnl/mm/amd64/pte.cc b/xtoskrnl/mm/amd64/pte.cc new file mode 100644 index 0000000..d74156a --- /dev/null +++ b/xtoskrnl/mm/amd64/pte.cc @@ -0,0 +1,104 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/mm/amd64/pte.cc + * DESCRIPTION: Page Table Entry (PTE) for AMD64 support + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Maps a range of virtual addresses at the P5E (PML5) level. + * + * @param StartAddress + * The beginning of the virtual address range to map. + * + * @param EndAddress + * The end of the virtual address range to map. + * + * @param TemplateP5e + * A template P5E to use for creating new entries. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Pte::MapP5E(PVOID StartAddress, + PVOID EndAddress, + PMMP5E TemplateP5e) +{ + PMMP5E EndSpace, PointerP5e; + + /* Get P5E addresses */ + PointerP5e = MM::Paging::GetP5eAddress(StartAddress); + EndSpace = MM::Paging::GetP5eAddress(EndAddress); + + /* Iterate over all P5Es */ + while(PointerP5e <= EndSpace) + { + /* Check if P5E is already mapped */ + if(!MM::Paging::PteValid(PointerP5e)) + { + /* Map P5E */ + MM::Paging::SetPte(TemplateP5e, MM::Pfn::AllocateBootstrapPages(1), 0); + *PointerP5e = *TemplateP5e; + + /* Clear the page table */ + RtlZeroMemory(MM::Paging::GetPteVirtualAddress(PointerP5e), MM_PAGE_SIZE); + } + + /* Get next table entry */ + PointerP5e = MM::Paging::GetNextPte(PointerP5e); + } +} + +/** + * Maps a range of virtual addresses at the PXE (PML4) level. + * + * @param StartAddress + * The beginning of the virtual address range to map. + * + * @param EndAddress + * The end of the virtual address range to map. + * + * @param TemplatePxe + * A template PXE to use for creating new entries. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Pte::MapPXE(PVOID StartAddress, + PVOID EndAddress, + PMMPXE TemplatePxe) +{ + PMMPXE EndSpace, PointerPxe; + + /* Get PXE addresses */ + PointerPxe = MM::Paging::GetPxeAddress(StartAddress); + EndSpace = MM::Paging::GetPxeAddress(EndAddress); + + /* Iterate over all PTEs */ + while(PointerPxe <= EndSpace) + { + /* Check if PTE is already mapped */ + if(!MM::Paging::PteValid(PointerPxe)) + { + /* Map PTE */ + MM::Paging::SetPte(TemplatePxe, MM::Pfn::AllocateBootstrapPages(1), 0); + *PointerPxe = *TemplatePxe; + + /* Clear the page table */ + RtlZeroMemory(MM::Paging::GetPteVirtualAddress(PointerPxe), MM_PAGE_SIZE); + } + + /* Get next table entry */ + PointerPxe = MM::Paging::GetNextPte(PointerPxe); + } +} diff --git a/xtoskrnl/mm/i686/pte.cc b/xtoskrnl/mm/i686/pte.cc new file mode 100644 index 0000000..97db714 --- /dev/null +++ b/xtoskrnl/mm/i686/pte.cc @@ -0,0 +1,10 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/mm/i686/pte.cc + * DESCRIPTION: Page Table Entry (PTE) for i686 support + * DEVELOPERS: Aiken Harris + */ + +#include + diff --git a/xtoskrnl/mm/pte.cc b/xtoskrnl/mm/pte.cc index 4d2614a..5123d12 100644 --- a/xtoskrnl/mm/pte.cc +++ b/xtoskrnl/mm/pte.cc @@ -24,53 +24,6 @@ MM::Pte::GetPtesPerPage(VOID) return MM_PAGE_SIZE / MM::Paging::GetPteSize(); } -/** - * Maps a range of virtual addresses at the P5E (PML5) level. - * - * @param StartAddress - * The beginning of the virtual address range to map. - * - * @param EndAddress - * The end of the virtual address range to map. - * - * @param TemplateP5e - * A template P5E to use for creating new entries. - * - * @return This routine does not return any value. - * - * @since XT 1.0 - */ -XTAPI -VOID -MM::Pte::MapP5E(PVOID StartAddress, - PVOID EndAddress, - PMMP5E TemplateP5e) -{ - PMMP5E EndSpace, PointerP5e; - - /* Get P5E addresses */ - PointerP5e = MM::Paging::GetP5eAddress(StartAddress); - EndSpace = MM::Paging::GetP5eAddress(EndAddress); - - /* Iterate over all P5Es */ - while(PointerP5e <= EndSpace) - { - /* Check if P5E is already mapped */ - if(!MM::Paging::PteValid(PointerP5e)) - { - /* Map P5E */ - MM::Paging::SetPte(TemplateP5e, MM::Pfn::AllocateBootstrapPages(1), 0); - *PointerP5e = *TemplateP5e; - - /* Clear the page table */ - RtlZeroMemory(MM::Paging::GetPteVirtualAddress(PointerP5e), MM_PAGE_SIZE); - } - - /* Get next table entry */ - PointerP5e = MM::Paging::GetNextPte(PointerP5e); - } -} - /** * Maps a range of virtual addresses at the PDE (Page Directory Entry) level. * @@ -211,50 +164,3 @@ MM::Pte::MapPTE(PVOID StartAddress, PointerPte = MM::Paging::GetNextPte(PointerPte); } } - -/** - * Maps a range of virtual addresses at the PXE (PML4) level. - * - * @param StartAddress - * The beginning of the virtual address range to map. - * - * @param EndAddress - * The end of the virtual address range to map. - * - * @param TemplatePxe - * A template PXE to use for creating new entries. - * - * @return This routine does not return any value. - * - * @since XT 1.0 - */ -XTAPI -VOID -MM::Pte::MapPXE(PVOID StartAddress, - PVOID EndAddress, - PMMPXE TemplatePxe) -{ - PMMPXE EndSpace, PointerPxe; - - /* Get PXE addresses */ - PointerPxe = MM::Paging::GetPxeAddress(StartAddress); - EndSpace = MM::Paging::GetPxeAddress(EndAddress); - - /* Iterate over all PTEs */ - while(PointerPxe <= EndSpace) - { - /* Check if PTE is already mapped */ - if(!MM::Paging::PteValid(PointerPxe)) - { - /* Map PTE */ - MM::Paging::SetPte(TemplatePxe, MM::Pfn::AllocateBootstrapPages(1), 0); - *PointerPxe = *TemplatePxe; - - /* Clear the page table */ - RtlZeroMemory(MM::Paging::GetPteVirtualAddress(PointerPxe), MM_PAGE_SIZE); - } - - /* Get next table entry */ - PointerPxe = MM::Paging::GetNextPte(PointerPxe); - } -}