From 9027632c4f81a78edca7c6449f36b34d4e79181a Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Mon, 5 Jan 2026 23:39:42 +0100 Subject: [PATCH] Make memory descriptor processing architecture-dependent --- xtoskrnl/mm/amd64/pfn.cc | 84 ++++++++++++++++++++++++++++++++++++++++ xtoskrnl/mm/i686/pfn.cc | 84 ++++++++++++++++++++++++++++++++++++++++ xtoskrnl/mm/pfn.cc | 84 ---------------------------------------- 3 files changed, 168 insertions(+), 84 deletions(-) diff --git a/xtoskrnl/mm/amd64/pfn.cc b/xtoskrnl/mm/amd64/pfn.cc index caa864f..fd25f3c 100644 --- a/xtoskrnl/mm/amd64/pfn.cc +++ b/xtoskrnl/mm/amd64/pfn.cc @@ -167,6 +167,90 @@ MM::Pfn::InitializePageTablePfns(VOID) } } +/** + * Processes a memory descriptor and initializes the corresponding PFN database entries + * + * @param BasePage + * The starting physical page number of the memory run + * + * @param PageCount + * The number of pages in the memory run + * + * @param MemoryType + * The type of memory as reported by the bootloader (e.g., free, ROM, in-use) + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage, + IN PFN_NUMBER PageCount, + IN LOADER_MEMORY_TYPE MemoryType) +{ + PFN_NUMBER CurrentPage, PageNumber; + PMMPFN Pfn; + + /* Check if the memory descriptor describes a free memory region */ + if(MM::Manager::VerifyMemoryTypeFree(MemoryType)) + { + /* Iterate over each page in this free memory run */ + for(PageNumber = 0; PageNumber < PageCount; PageNumber++) + { + /* Get the PFN entry for the current page and set its initial cache attribute */ + CurrentPage = BasePage + PageNumber; + Pfn = GetPfnEntry(CurrentPage); + Pfn->u3.e1.CacheAttribute = PfnNonCached; + + /* Add the page to the free list to make it available for allocation */ + LinkFreePage(CurrentPage); + } + } + else + { + /* Handle all other (non-free) memory types */ + switch(MemoryType) + { + case LoaderBad: + /* This memory is marked as bad and should not be used, add it to the bad pages list */ + LinkPage(&BadPagesList, BasePage); + break; + case LoaderXIPRom: + /* This memory range contains Read-Only Memory (ROM) */ + for(PageNumber = 0; PageNumber < PageCount; PageNumber++) + { + /* Get the PFN entry for the current ROM page */ + Pfn = GetPfnEntry(BasePage + PageNumber); + + /* Initialize the PFN entry to represent a ROM page */ + Pfn->PteAddress = 0; + Pfn->u1.Flink = 0; + Pfn->u2.ShareCount = 0; + Pfn->u3.e1.CacheAttribute = PfnNonCached; + Pfn->u3.e1.PageLocation = 0; + Pfn->u3.e1.PrototypePte = 1; + Pfn->u3.e1.Rom = 1; + Pfn->u3.e2.ReferenceCount = 0; + Pfn->u4.InPageError = 0; + Pfn->u4.PteFrame = 0; + } + break; + default: + /* All other types are considered in-use (ie, by the kernel, ACPI, etc) */ + for(PageNumber = 0; PageNumber < PageCount; PageNumber++) + { + /* Get the PFN entry for the current in-use page */ + Pfn = GetPfnEntry(BasePage + PageNumber); + + /* Mark the PFN as active and valid to prevent it from being allocated */ + Pfn->u3.e1.PageLocation = ActiveAndValid; + } + break; + } + } +} + /** * Recursively scans a page table to initialize PFN database entries for active pages. * diff --git a/xtoskrnl/mm/i686/pfn.cc b/xtoskrnl/mm/i686/pfn.cc index 030f97c..5af5508 100644 --- a/xtoskrnl/mm/i686/pfn.cc +++ b/xtoskrnl/mm/i686/pfn.cc @@ -155,6 +155,90 @@ MM::Pfn::InitializePageTablePfns(VOID) } } +/** + * Processes a memory descriptor and initializes the corresponding PFN database entries + * + * @param BasePage + * The starting physical page number of the memory run + * + * @param PageCount + * The number of pages in the memory run + * + * @param MemoryType + * The type of memory as reported by the bootloader (e.g., free, ROM, in-use) + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage, + IN PFN_NUMBER PageCount, + IN LOADER_MEMORY_TYPE MemoryType) +{ + PFN_NUMBER CurrentPage, PageNumber; + PMMPFN Pfn; + + /* Check if the memory descriptor describes a free memory region */ + if(MM::Manager::VerifyMemoryTypeFree(MemoryType)) + { + /* Iterate over each page in this free memory run */ + for(PageNumber = 0; PageNumber < PageCount; PageNumber++) + { + /* Get the PFN entry for the current page and set its initial cache attribute */ + CurrentPage = BasePage + PageNumber; + Pfn = GetPfnEntry(CurrentPage); + Pfn->u3.e1.CacheAttribute = PfnNonCached; + + /* Add the page to the free list to make it available for allocation */ + LinkFreePage(CurrentPage); + } + } + else + { + /* Handle all other (non-free) memory types */ + switch(MemoryType) + { + case LoaderBad: + /* This memory is marked as bad and should not be used, add it to the bad pages list */ + LinkPage(&BadPagesList, BasePage); + break; + case LoaderXIPRom: + /* This memory range contains Read-Only Memory (ROM) */ + for(PageNumber = 0; PageNumber < PageCount; PageNumber++) + { + /* Get the PFN entry for the current ROM page */ + Pfn = GetPfnEntry(BasePage + PageNumber); + + /* Initialize the PFN entry to represent a ROM page */ + Pfn->PteAddress = 0; + Pfn->u1.Flink = 0; + Pfn->u2.ShareCount = 0; + Pfn->u3.e1.CacheAttribute = PfnNonCached; + Pfn->u3.e1.PageLocation = 0; + Pfn->u3.e1.PrototypePte = 1; + Pfn->u3.e1.Rom = 1; + Pfn->u3.e2.ReferenceCount = 0; + Pfn->u4.InPageError = 0; + Pfn->u4.PteFrame = 0; + } + break; + default: + /* All other types are considered in-use (ie, by the kernel, ACPI, etc) */ + for(PageNumber = 0; PageNumber < PageCount; PageNumber++) + { + /* Get the PFN entry for the current in-use page */ + Pfn = GetPfnEntry(BasePage + PageNumber); + + /* Mark the PFN as active and valid to prevent it from being allocated */ + Pfn->u3.e1.PageLocation = ActiveAndValid; + } + break; + } + } +} + /** * Recursively scans a page table to initialize PFN database entries for active pages. * diff --git a/xtoskrnl/mm/pfn.cc b/xtoskrnl/mm/pfn.cc index 164526c..5372154 100644 --- a/xtoskrnl/mm/pfn.cc +++ b/xtoskrnl/mm/pfn.cc @@ -949,90 +949,6 @@ MM::Pfn::LinkStandbyPage(IN PFN_NUMBER PageFrameIndex) IncrementAvailablePages(); } -/** - * Processes a memory descriptor and initializes the corresponding PFN database entries - * - * @param BasePage - * The starting physical page number of the memory run - * - * @param PageCount - * The number of pages in the memory run - * - * @param MemoryType - * The type of memory as reported by the bootloader (e.g., free, ROM, in-use) - * - * @return This routine does not return any value. - * - * @since XT 1.0 - */ -XTAPI -VOID -MM::Pfn::ProcessMemoryDescriptor(IN PFN_NUMBER BasePage, - IN PFN_NUMBER PageCount, - IN LOADER_MEMORY_TYPE MemoryType) -{ - PFN_NUMBER CurrentPage, PageNumber; - PMMPFN Pfn; - - /* Check if the memory descriptor describes a free memory region */ - if(MM::Manager::VerifyMemoryTypeFree(MemoryType)) - { - /* Iterate over each page in this free memory run */ - for(PageNumber = 0; PageNumber < PageCount; PageNumber++) - { - /* Get the PFN entry for the current page and set its initial cache attribute */ - CurrentPage = BasePage + PageNumber; - Pfn = GetPfnEntry(CurrentPage); - Pfn->u3.e1.CacheAttribute = PfnNonCached; - - /* Add the page to the free list to make it available for allocation */ - LinkFreePage(CurrentPage); - } - } - else - { - /* Handle all other (non-free) memory types */ - switch(MemoryType) - { - case LoaderBad: - /* This memory is marked as bad and should not be used, add it to the bad pages list */ - LinkPage(&BadPagesList, BasePage); - break; - case LoaderXIPRom: - /* This memory range contains Read-Only Memory (ROM) */ - for(PageNumber = 0; PageNumber < PageCount; PageNumber++) - { - /* Get the PFN entry for the current ROM page */ - Pfn = GetPfnEntry(BasePage + PageNumber); - - /* Initialize the PFN entry to represent a ROM page */ - Pfn->PteAddress = 0; - Pfn->u1.Flink = 0; - Pfn->u2.ShareCount = 0; - Pfn->u3.e1.CacheAttribute = PfnNonCached; - Pfn->u3.e1.PageLocation = 0; - Pfn->u3.e1.PrototypePte = 1; - Pfn->u3.e1.Rom = 1; - Pfn->u3.e2.ReferenceCount = 0; - Pfn->u4.InPageError = 0; - Pfn->u4.PteFrame = 0; - } - break; - default: - /* All other types are considered in-use (ie, by the kernel, ACPI, etc) */ - for(PageNumber = 0; PageNumber < PageCount; PageNumber++) - { - /* Get the PFN entry for the current in-use page */ - Pfn = GetPfnEntry(BasePage + PageNumber); - - /* Mark the PFN as active and valid to prevent it from being allocated */ - Pfn->u3.e1.PageLocation = ActiveAndValid; - } - break; - } - } -} - /** * Scans memory descriptors provided by the boot loader. *