- Separe ARM3 Init into 3 defined phases:

- 1: No PFN Database exists
  - 2: PFN Database exists
  - 3: ReactOS NP Pool exists (deprecated)
- Cleanup ReactOS Mm init to work with this.
- ARM3 Phase 1 Init now uses pages directly from the physical memory descriptor.
  - This similar to how "MmAllocEarlyPage" used to work. 
    - A new function MxGetNextPage now does this.
    - MxGetNextPage can allocate more than just one page however (making it possible to get contiguous physical memory without going through the PFN-based MmAllocateContiguousMemory beast)
    - Also MxGetNextPage will bugcheck with INSTALL_MORE_MEMORY if it runs out of pages.
  - Renamed the physical memory descriptor variables to MxFreeDescriptor, MxOldFreeDescriptor instead of MiFreeDescriptor and MiOrgFreeDescriptor (based on NT symbols)
  - Nonpaged pool PDEs, PFN database PDEs, and initial nonpaged pool PTEs are now allocated through MxGetNextPage.
- Fix an off by one error in the sizing of MxPfnAllocation.
- The PFN database is now fully "owned" by ARM3 in terms of its PDE mappings and VA location at 0xB0000000.
  - ie. MmArmPfnDatabase is now MmPfnDatabase.
  - The actual PFN database entries and setup are still done by the ReactOS Mm.
- Got rid of ARM nonpaged pool allocator test.
- Repositioned ReactOS nonpaged pool (deprecated) after the boot image (used to be after the PFN database).
  - Paged pool follows.

svn path=/trunk/; revision=42131
This commit is contained in:
ReactOS Portable Systems Group 2009-07-22 07:33:22 +00:00
parent e3ef0343ba
commit 23a2825b03
4 changed files with 229 additions and 205 deletions

View file

@ -1,8 +1,8 @@
/* /*
* PROJECT: ReactOS Kernel * PROJECT: ReactOS Kernel
* LICENSE: BSD - See COPYING.ARM in the top level directory * LICENSE: BSD - See COPYING.ARM in the top level directory
* FILE: ntoskrnl/mm/ARM3/init.c * FILE: ntoskrnl/mm/ARM3/i386/init.c
* PURPOSE: ARM Memory Manager Initialization * PURPOSE: ARM Memory Manager Initialization for x86
* PROGRAMMERS: ReactOS Portable Systems Group * PROGRAMMERS: ReactOS Portable Systems Group
*/ */
@ -108,16 +108,27 @@ ULONG MmNumberOfSystemPtes;
// //
ULONG MxPfnAllocation; ULONG MxPfnAllocation;
//
// The ARM³ PFN Database
//
PMMPFN MmArmPfnDatabase;
// //
// This structure describes the different pieces of RAM-backed address space // This structure describes the different pieces of RAM-backed address space
// //
PPHYSICAL_MEMORY_DESCRIPTOR MmPhysicalMemoryBlock; PPHYSICAL_MEMORY_DESCRIPTOR MmPhysicalMemoryBlock;
//
// Before we have a PFN database, memory comes straight from our physical memory
// blocks, which is nice because it's guaranteed contiguous and also because once
// we take a page from here, the system doesn't see it anymore.
// However, once the fun is over, those pages must be re-integrated back into
// PFN society life, and that requires us keeping a copy of the original layout
// so that we can parse it later.
//
PMEMORY_ALLOCATION_DESCRIPTOR MxFreeDescriptor;
MEMORY_ALLOCATION_DESCRIPTOR MxOldFreeDescriptor;
//
// This is where we keep track of the most basic physical layout markers
//
ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
/* PRIVATE FUNCTIONS **********************************************************/ /* PRIVATE FUNCTIONS **********************************************************/
// //
@ -143,6 +154,35 @@ MiSyncARM3WithROS(IN PVOID AddressStart,
} }
} }
PFN_NUMBER
NTAPI
MxGetNextPage(IN PFN_NUMBER PageCount)
{
PFN_NUMBER Pfn;
//
// Make sure we have enough pages
//
if (PageCount > MxFreeDescriptor->PageCount)
{
//
// Crash the system
//
KeBugCheckEx(INSTALL_MORE_MEMORY,
MmNumberOfPhysicalPages,
MxFreeDescriptor->PageCount,
MxOldFreeDescriptor.PageCount,
PageCount);
}
//
// Use our highest usable free pages
//
Pfn = MxFreeDescriptor->BasePage + MxFreeDescriptor->PageCount - PageCount;
MxFreeDescriptor->PageCount -= PageCount;
return Pfn;
}
PPHYSICAL_MEMORY_DESCRIPTOR PPHYSICAL_MEMORY_DESCRIPTOR
NTAPI NTAPI
MmInitializeMemoryLimits(IN PLOADER_PARAMETER_BLOCK LoaderBlock, MmInitializeMemoryLimits(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
@ -284,8 +324,11 @@ NTAPI
MmArmInitSystem(IN ULONG Phase, MmArmInitSystem(IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock) IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{ {
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR MdBlock;
ULONG FreePages = 0;
PMEMORY_AREA MArea; PMEMORY_AREA MArea;
PHYSICAL_ADDRESS BoundaryAddressMultiple, Low, High; PHYSICAL_ADDRESS BoundaryAddressMultiple;
PFN_NUMBER PageFrameIndex; PFN_NUMBER PageFrameIndex;
PMMPTE StartPde, EndPde, PointerPte, LastPte; PMMPTE StartPde, EndPde, PointerPte, LastPte;
MMPTE TempPde = HyperTemplatePte, TempPte = HyperTemplatePte; MMPTE TempPde = HyperTemplatePte, TempPte = HyperTemplatePte;
@ -294,8 +337,7 @@ MmArmInitSystem(IN ULONG Phase,
ULONG OldCount; ULONG OldCount;
BOOLEAN IncludeType[LoaderMaximum]; BOOLEAN IncludeType[LoaderMaximum];
ULONG i; ULONG i;
BoundaryAddressMultiple.QuadPart = Low.QuadPart = 0; BoundaryAddressMultiple.QuadPart = 0;
High.QuadPart = -1;
if (Phase == 0) if (Phase == 0)
{ {
@ -313,6 +355,95 @@ MmArmInitSystem(IN ULONG Phase,
EndPde = MiAddressToPde(KSEG0_BASE); EndPde = MiAddressToPde(KSEG0_BASE);
RtlZeroMemory(StartPde, (EndPde - StartPde) * sizeof(MMPTE)); RtlZeroMemory(StartPde, (EndPde - StartPde) * sizeof(MMPTE));
//
// Loop the memory descriptors
//
NextEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
while (NextEntry != &LoaderBlock->MemoryDescriptorListHead)
{
//
// Get the memory block
//
MdBlock = CONTAINING_RECORD(NextEntry,
MEMORY_ALLOCATION_DESCRIPTOR,
ListEntry);
//
// Skip invisible memory
//
if ((MdBlock->MemoryType != LoaderFirmwarePermanent) &&
(MdBlock->MemoryType != LoaderSpecialMemory) &&
(MdBlock->MemoryType != LoaderHALCachedMemory) &&
(MdBlock->MemoryType != LoaderBBTMemory))
{
//
// Check if BURNMEM was used
//
if (MdBlock->MemoryType != LoaderBad)
{
//
// Count this in the total of pages
//
MmNumberOfPhysicalPages += MdBlock->PageCount;
}
//
// Check if this is the new lowest page
//
if (MdBlock->BasePage < MmLowestPhysicalPage)
{
//
// Update the lowest page
//
MmLowestPhysicalPage = MdBlock->BasePage;
}
//
// Check if this is the new highest page
//
PageFrameIndex = MdBlock->BasePage + MdBlock->PageCount;
if (PageFrameIndex > MmHighestPhysicalPage)
{
//
// Update the highest page
//
MmHighestPhysicalPage = PageFrameIndex - 1;
}
//
// Check if this is free memory
//
if ((MdBlock->MemoryType == LoaderFree) ||
(MdBlock->MemoryType == LoaderLoadedProgram) ||
(MdBlock->MemoryType == LoaderFirmwareTemporary) ||
(MdBlock->MemoryType == LoaderOsloaderStack))
{
//
// Check if this is the largest memory descriptor
//
if (MdBlock->PageCount > FreePages)
{
//
// For now, it is
//
FreePages = MdBlock->PageCount;
MxFreeDescriptor = MdBlock;
}
}
}
//
// Keep going
//
NextEntry = MdBlock->ListEntry.Flink;
}
//
// Save original values of the free descriptor, since it'll be
// altered by early allocations
//
MxOldFreeDescriptor = *MxFreeDescriptor;
// //
// Check if this is a machine with less than 19MB of RAM // Check if this is a machine with less than 19MB of RAM
// //
@ -435,6 +566,16 @@ MmArmInitSystem(IN ULONG Phase,
MxPfnAllocation = (MmHighestPhysicalPage + 1) * sizeof(MMPFN); MxPfnAllocation = (MmHighestPhysicalPage + 1) * sizeof(MMPFN);
MxPfnAllocation >>= PAGE_SHIFT; MxPfnAllocation >>= PAGE_SHIFT;
//
// We have to add one to the count here, because in the process of
// shifting down to the page size, we actually ended up getting the
// lower aligned size (so say, 0x5FFFF bytes is now 0x5F pages).
// Later on, we'll shift this number back into bytes, which would cause
// us to end up with only 0x5F000 bytes -- when we actually want to have
// 0x60000 bytes.
//
MxPfnAllocation++;
// //
// Now calculate the nonpaged pool expansion VA region // Now calculate the nonpaged pool expansion VA region
// //
@ -482,35 +623,23 @@ MmArmInitSystem(IN ULONG Phase,
// with the old memory manager, so we'll create a "Shadow PFN Database" // with the old memory manager, so we'll create a "Shadow PFN Database"
// instead, and arbitrarly start it at 0xB0000000. // instead, and arbitrarly start it at 0xB0000000.
// //
MmArmPfnDatabase = (PVOID)0xB0000000; MmPfnDatabase = (PVOID)0xB0000000;
ASSERT(((ULONG_PTR)MmArmPfnDatabase & ((4 * 1024 * 1024) - 1)) == 0); ASSERT(((ULONG_PTR)MmPfnDatabase & ((4 * 1024 * 1024) - 1)) == 0);
// //
// Non paged pool comes after the PFN database // Non paged pool comes after the PFN database
// //
MmNonPagedPoolStart = (PVOID)((ULONG_PTR)MmArmPfnDatabase + MmNonPagedPoolStart = (PVOID)((ULONG_PTR)MmPfnDatabase +
(MxPfnAllocation << PAGE_SHIFT)); (MxPfnAllocation << PAGE_SHIFT));
// //
// Now we actually need to get these many physical pages. Nonpaged pool // Now we actually need to get these many physical pages. Nonpaged pool
// is actually also physically contiguous (but not the expansion) // is actually also physically contiguous (but not the expansion)
// //
PageFrameIndex = MmGetContinuousPages(MmSizeOfNonPagedPoolInBytes + PageFrameIndex = MxGetNextPage(MxPfnAllocation +
(MxPfnAllocation << PAGE_SHIFT), (MmSizeOfNonPagedPoolInBytes >> PAGE_SHIFT));
Low,
High,
BoundaryAddressMultiple,
FALSE);
ASSERT(PageFrameIndex != 0); ASSERT(PageFrameIndex != 0);
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmArmPfnDatabase,
(ULONG_PTR)MmArmPfnDatabase + (MxPfnAllocation << PAGE_SHIFT),
"Shadow PFN Database");
DPRINT("PFN DB PA PFN begins at: %lx\n", PageFrameIndex); DPRINT("PFN DB PA PFN begins at: %lx\n", PageFrameIndex);
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmNonPagedPoolStart,
(ULONG_PTR)MmNonPagedPoolStart + MmSizeOfNonPagedPoolInBytes,
"ARM Non Paged Pool");
DPRINT("NP PA PFN begins at: %lx\n", PageFrameIndex + MxPfnAllocation); DPRINT("NP PA PFN begins at: %lx\n", PageFrameIndex + MxPfnAllocation);
// //
@ -529,7 +658,7 @@ MmArmInitSystem(IN ULONG Phase,
// //
// Get a page // Get a page
// //
TempPde.u.Hard.PageFrameNumber = MmAllocPage(MC_SYSTEM, 0); TempPde.u.Hard.PageFrameNumber = MxGetNextPage(1);
ASSERT(TempPde.u.Hard.Valid == 1); ASSERT(TempPde.u.Hard.Valid == 1);
*StartPde = TempPde; *StartPde = TempPde;
@ -548,7 +677,7 @@ MmArmInitSystem(IN ULONG Phase,
// //
// Now we need pages for the page tables which will map initial NP // Now we need pages for the page tables which will map initial NP
// //
StartPde = MiAddressToPde(MmArmPfnDatabase); StartPde = MiAddressToPde(MmPfnDatabase);
EndPde = MiAddressToPde((PVOID)((ULONG_PTR)MmNonPagedPoolStart + EndPde = MiAddressToPde((PVOID)((ULONG_PTR)MmNonPagedPoolStart +
MmSizeOfNonPagedPoolInBytes - 1)); MmSizeOfNonPagedPoolInBytes - 1));
while (StartPde <= EndPde) while (StartPde <= EndPde)
@ -561,7 +690,7 @@ MmArmInitSystem(IN ULONG Phase,
// //
// Get a page // Get a page
// //
TempPde.u.Hard.PageFrameNumber = MmAllocPage(MC_SYSTEM, 0); TempPde.u.Hard.PageFrameNumber = MxGetNextPage(1);
ASSERT(TempPde.u.Hard.Valid == 1); ASSERT(TempPde.u.Hard.Valid == 1);
*StartPde = TempPde; *StartPde = TempPde;
@ -581,12 +710,6 @@ MmArmInitSystem(IN ULONG Phase,
// Now remember where the expansion starts // Now remember where the expansion starts
// //
MmNonPagedPoolExpansionStart = NonPagedPoolExpansionVa; MmNonPagedPoolExpansionStart = NonPagedPoolExpansionVa;
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmNonPagedSystemStart, MmNonPagedPoolExpansionStart,
"System PTE Space");
DPRINT1(" 0x%p - 0x%p\t%s\n",
MmNonPagedPoolExpansionStart, MmNonPagedPoolEnd,
"Non Paged Pool Expansion PTE Space");
// //
// Last step is to actually map the nonpaged pool // Last step is to actually map the nonpaged pool
@ -646,6 +769,13 @@ MmArmInitSystem(IN ULONG Phase,
// Now go ahead and initialize the ARM pool // Now go ahead and initialize the ARM pool
// //
MiInitializeArmPool(); MiInitializeArmPool();
}
else if (Phase == 1) // IN BETWEEN, THE PFN DATABASE IS NOW CREATED
{
//
// Initialize the nonpaged pool
//
InitializePool(NonPagedPool, 0);
// //
// We PDE-aligned the nonpaged system start VA, so haul some extra PTEs! // We PDE-aligned the nonpaged system start VA, so haul some extra PTEs!
@ -707,36 +837,28 @@ MmArmInitSystem(IN ULONG Phase,
// Sync us up with ReactOS Mm // Sync us up with ReactOS Mm
// //
MiSyncARM3WithROS(MmNonPagedSystemStart, (PVOID)((ULONG_PTR)MmNonPagedPoolEnd - 1)); MiSyncARM3WithROS(MmNonPagedSystemStart, (PVOID)((ULONG_PTR)MmNonPagedPoolEnd - 1));
MiSyncARM3WithROS(MmArmPfnDatabase, (PVOID)((ULONG_PTR)MmNonPagedPoolStart + MmSizeOfNonPagedPoolInBytes - 1)); MiSyncARM3WithROS(MmPfnDatabase, (PVOID)((ULONG_PTR)MmNonPagedPoolStart + MmSizeOfNonPagedPoolInBytes - 1));
MiSyncARM3WithROS((PVOID)HYPER_SPACE, (PVOID)(HYPER_SPACE + PAGE_SIZE - 1)); MiSyncARM3WithROS((PVOID)HYPER_SPACE, (PVOID)(HYPER_SPACE + PAGE_SIZE - 1));
// //
// Initialize the nonpaged pool // Print the memory layout
// //
InitializePool(NonPagedPool, 0); DPRINT1(" 0x%p - 0x%p\t%s\n",
MmPfnDatabase,
// (ULONG_PTR)MmPfnDatabase + (MxPfnAllocation << PAGE_SHIFT),
// Do a little test of the nonpaged pool allocator "PFN Database");
// DPRINT1(" 0x%p - 0x%p\t%s\n",
if (0) MmNonPagedPoolStart,
{ (ULONG_PTR)MmNonPagedPoolStart + MmSizeOfNonPagedPoolInBytes,
ULONG i = 0; "ARM Non Paged Pool");
PVOID Buffers[4096]; DPRINT1(" 0x%p - 0x%p\t%s\n",
while (TRUE) MmNonPagedSystemStart, MmNonPagedPoolExpansionStart,
{ "System PTE Space");
Buffers[i] = MiAllocatePoolPages(NonPagedPool, PAGE_SIZE); DPRINT1(" 0x%p - 0x%p\t%s\n",
if (!Buffers[i]) break; MmNonPagedPoolExpansionStart, MmNonPagedPoolEnd,
if (i == 4096) break; "Non Paged Pool Expansion PTE Space");
i++;
}
while (i--)
{
MiFreePoolPages(Buffers[i]);
}
}
} }
else else // NOW WE HAVE NONPAGED POOL
{ {
// //
// Instantiate memory that we don't consider RAM/usable // Instantiate memory that we don't consider RAM/usable

View file

@ -105,6 +105,9 @@ extern PPHYSICAL_MEMORY_DESCRIPTOR MmPhysicalMemoryBlock;
extern ULONG MmBootImageSize; extern ULONG MmBootImageSize;
extern PMMPTE MmSystemPtesStart[MaximumPtePoolTypes]; extern PMMPTE MmSystemPtesStart[MaximumPtePoolTypes];
extern PMMPTE MmSystemPtesEnd[MaximumPtePoolTypes]; extern PMMPTE MmSystemPtesEnd[MaximumPtePoolTypes];
extern PMEMORY_ALLOCATION_DESCRIPTOR MxFreeDescriptor;
extern MEMORY_ALLOCATION_DESCRIPTOR MxOldFreeDescriptor;
extern ULONG MxPfnAllocation;
VOID VOID
NTAPI NTAPI

View file

@ -713,8 +713,8 @@ MmAllocEarlyPage(VOID)
PFN_TYPE Pfn; PFN_TYPE Pfn;
/* Use one of our highest usable pages */ /* Use one of our highest usable pages */
Pfn = MiFreeDescriptor->BasePage + MiFreeDescriptor->PageCount - 1; Pfn = MxFreeDescriptor->BasePage + MxFreeDescriptor->PageCount - 1;
MiFreeDescriptor->PageCount--; MxFreeDescriptor->PageCount--;
/* Return it */ /* Return it */
return Pfn; return Pfn;
@ -813,7 +813,6 @@ NTAPI
MmInitializePageList(VOID) MmInitializePageList(VOID)
{ {
ULONG i; ULONG i;
ULONG Reserved;
NTSTATUS Status; NTSTATUS Status;
PFN_TYPE Pfn = 0; PFN_TYPE Pfn = 0;
PHYSICAL_PAGE UsedPage; PHYSICAL_PAGE UsedPage;
@ -824,12 +823,9 @@ MmInitializePageList(VOID)
InitializeListHead(&UserPageListHead); InitializeListHead(&UserPageListHead);
InitializeListHead(&FreeUnzeroedPageListHead); InitializeListHead(&FreeUnzeroedPageListHead);
InitializeListHead(&FreeZeroedPageListHead); InitializeListHead(&FreeZeroedPageListHead);
/* Set the size and start of the PFN Database */
Reserved = PAGE_ROUND_UP((MmHighestPhysicalPage * sizeof(PHYSICAL_PAGE))) / PAGE_SIZE;
/* Loop every page required to hold the PFN database */ /* Loop every page required to hold the PFN database */
for (i = 0; i < Reserved; i++) for (i = 0; i < MxPfnAllocation; i++)
{ {
PVOID Address = (char*)MmPfnDatabase + (i * PAGE_SIZE); PVOID Address = (char*)MmPfnDatabase + (i * PAGE_SIZE);
@ -924,10 +920,10 @@ MmInitializePageList(VOID)
} }
} }
} }
/* Finally handle the pages describing the PFN database themselves */ /* Finally handle the pages describing the PFN database themselves */
for (i = (MiFreeDescriptor->BasePage + MiFreeDescriptor->PageCount); for (i = (MxFreeDescriptor->BasePage + MxFreeDescriptor->PageCount);
i < (MiFreeDescriptorOrg.BasePage + MiFreeDescriptorOrg.PageCount); i < (MxOldFreeDescriptor.BasePage + MxOldFreeDescriptor.PageCount);
i++) i++)
{ {
/* Ensure this page was not added previously */ /* Ensure this page was not added previously */

View file

@ -48,10 +48,6 @@ MemType[] =
PVOID MiNonPagedPoolStart; PVOID MiNonPagedPoolStart;
ULONG MiNonPagedPoolLength; ULONG MiNonPagedPoolLength;
ULONG MmBootImageSize; ULONG MmBootImageSize;
ULONG MmNumberOfPhysicalPages, MmHighestPhysicalPage, MmLowestPhysicalPage;
ULONG_PTR MmPfnDatabaseEnd;
PMEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptor;
MEMORY_ALLOCATION_DESCRIPTOR MiFreeDescriptorOrg;
ULONG MmUserProbeAddress = 0; ULONG MmUserProbeAddress = 0;
PVOID MmHighestUserAddress = NULL; PVOID MmHighestUserAddress = NULL;
PBOOLEAN Mm64BitPhysicalAddress = FALSE; PBOOLEAN Mm64BitPhysicalAddress = FALSE;
@ -113,88 +109,6 @@ MiInitSystemMemoryAreas()
BoundaryAddressMultiple); BoundaryAddressMultiple);
} }
VOID
NTAPI
MiCountFreePagesInLoaderBlock(PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PLIST_ENTRY NextEntry;
PMEMORY_ALLOCATION_DESCRIPTOR Md;
ULONG FreePages = 0;
for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
NextEntry = NextEntry->Flink)
{
Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
/* Skip invisible memory */
if ((Md->MemoryType != LoaderFirmwarePermanent) &&
(Md->MemoryType != LoaderSpecialMemory) &&
(Md->MemoryType != LoaderHALCachedMemory) &&
(Md->MemoryType != LoaderBBTMemory))
{
/* Check if BURNMEM was used */
if (Md->MemoryType != LoaderBad)
{
/* Count this in the total of pages */
MmNumberOfPhysicalPages += Md->PageCount;
}
/* Check if this is the new lowest page */
if (Md->BasePage < MmLowestPhysicalPage)
{
/* Update the lowest page */
MmLowestPhysicalPage = Md->BasePage;
}
/* Check if this is the new highest page */
if ((Md->BasePage + Md->PageCount) > MmHighestPhysicalPage)
{
/* Update the highest page */
MmHighestPhysicalPage = Md->BasePage + Md->PageCount - 1;
}
/* Check if this is free memory */
if ((Md->MemoryType == LoaderFree) ||
(Md->MemoryType == LoaderLoadedProgram) ||
(Md->MemoryType == LoaderFirmwareTemporary) ||
(Md->MemoryType == LoaderOsloaderStack))
{
/* Check if this is the largest memory descriptor */
if (Md->PageCount > FreePages)
{
/* For now, it is */
FreePages = Md->PageCount;
MiFreeDescriptor = Md;
}
}
}
}
/* Save original values of the free descriptor, since it'll be
altered by early allocations */
MiFreeDescriptorOrg = *MiFreeDescriptor;
}
VOID
NTAPI
MiDbgKernelLayout(VOID)
{
DPRINT1("%8s%12s\t\t%s\n", "Start", "End", "Type");
DPRINT1("0x%p - 0x%p\t%s\n",
MmSystemRangeStart, (ULONG_PTR)MmSystemRangeStart + MmBootImageSize,
"Boot Image Mapping Region");
DPRINT1("0x%p - 0x%p\t%s\n",
MmPfnDatabase, MmPfnDatabaseEnd,
"PFN Database region");
DPRINT1("0x%p - 0x%p\t%s\n",
MiNonPagedPoolStart, (ULONG_PTR)MiNonPagedPoolStart + MiNonPagedPoolLength,
"Non paged pool region");
DPRINT1("0x%p - 0x%p\t%s\n",
MmPagedPoolBase, (ULONG_PTR)MmPagedPoolBase + MmPagedPoolSize,
"Paged pool region");
}
VOID VOID
NTAPI NTAPI
MiDbgDumpMemoryDescriptors(VOID) MiDbgDumpMemoryDescriptors(VOID)
@ -225,7 +139,12 @@ VOID
INIT_FUNCTION INIT_FUNCTION
NTAPI NTAPI
MmInit1(VOID) MmInit1(VOID)
{ {
/* Initialize the kernel address space */
KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock);
MmKernelAddressSpace = MmGetCurrentAddressSpace();
MmInitGlobalKernelPageDirectory();
/* Dump memory descriptors */ /* Dump memory descriptors */
if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors(); if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
@ -237,62 +156,46 @@ MmInit1(VOID)
MmSystemRangeStart = (PVOID)KSEG0_BASE; MmSystemRangeStart = (PVOID)KSEG0_BASE;
MmUserProbeAddress = (ULONG_PTR)MmSystemRangeStart - 0x10000; MmUserProbeAddress = (ULONG_PTR)MmSystemRangeStart - 0x10000;
MmHighestUserAddress = (PVOID)(MmUserProbeAddress - 1); MmHighestUserAddress = (PVOID)(MmUserProbeAddress - 1);
DPRINT("MmSystemRangeStart: %08x\n", MmSystemRangeStart);
DPRINT("MmUserProbeAddress: %08x\n", MmUserProbeAddress);
DPRINT("MmHighestUserAddress:%08x\n", MmHighestUserAddress);
/* Count RAM */
MiCountFreePagesInLoaderBlock(KeLoaderBlock);
DbgPrint("Used memory %dKb\n", (MmNumberOfPhysicalPages * PAGE_SIZE) / 1024);
/* Initialize the kernel address space */
KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock);
MmKernelAddressSpace = MmGetCurrentAddressSpace();
MmInitGlobalKernelPageDirectory();
/* We'll put the PFN array right after the loaded modules */
MmPfnDatabase = (PVOID)((ULONG_PTR)MmSystemRangeStart + MmBootImageSize);
MmPfnDatabaseEnd = (ULONG_PTR)MmPfnDatabase + (MmHighestPhysicalPage * sizeof(MMPFN));
MmPfnDatabaseEnd = PAGE_ROUND_UP(MmPfnDatabaseEnd);
/* Put nonpaged pool after the PFN database */
MiNonPagedPoolStart = (PVOID)MmPfnDatabaseEnd;
/* Length of non-paged pool */
MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
/* Put the paged pool after the non-paged pool */
MmPagedPoolBase = (PVOID)PAGE_ROUND_UP((ULONG_PTR)MiNonPagedPoolStart +
MiNonPagedPoolLength);
MmPagedPoolSize = MM_PAGED_POOL_SIZE;
/* Dump kernel memory layout */
MiDbgKernelLayout();
/* Intialize system memory areas */
MiInitSystemMemoryAreas();
/* Initialize the page list */
MmInitializePageList();
// //
// Initialize ARM³ in phase 0 // Initialize ARM³ in phase 0
// //
MmArmInitSystem(0, KeLoaderBlock); MmArmInitSystem(0, KeLoaderBlock);
/* Initialize nonpaged pool */ /* Intialize system memory areas */
MiInitializeNonPagedPool(); MiInitSystemMemoryAreas();
/* Initialize the page list */
MmInitializePageList();
//
// Initialize ARM³ in phase 1
//
MmArmInitSystem(1, KeLoaderBlock);
// DEPRECATED
/* Put nonpaged pool after the loaded modules */ // DEPRECATED
MiNonPagedPoolStart = (PVOID)((ULONG_PTR)MmSystemRangeStart + // DEPRECATED
MmBootImageSize); // DEPRECATED
MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE; // DEPRECATED
// DEPRECATED
/* Initialize nonpaged pool */ // DEPRECATED
MiInitializeNonPagedPool(); // DEPRECATED
// DEPRECATED
//
// Initialize ARM³ in phase 2
//
MmArmInitSystem(2, KeLoaderBlock);
/* Put the paged pool after nonpaged pool */
MmPagedPoolBase = (PVOID)PAGE_ROUND_UP((ULONG_PTR)MiNonPagedPoolStart +
MiNonPagedPoolLength);
MmPagedPoolSize = MM_PAGED_POOL_SIZE;
/* Initialize paged pool */ /* Initialize paged pool */
MmInitializePagedPool(); MmInitializePagedPool();
/* Initialize working sets */ /* Initialize working sets */
MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory); MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
//
// Initialize ARM³ in phase 1
//
MmArmInitSystem(1, KeLoaderBlock);
} }
BOOLEAN BOOLEAN