2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/mm/mminit.c
5 * PURPOSE: Memory Manager Initialization
9 /* INCLUDES ******************************************************************/
15 /* GLOBALS *******************************************************************/
48 PBOOLEAN Mm64BitPhysicalAddress
= FALSE
;
49 ULONG MmReadClusterSize
;
51 PMMPTE MmSharedUserDataPte
;
52 PMMSUPPORT MmKernelAddressSpace
;
53 extern KMUTANT MmSystemLoadLock
;
54 extern ULONG MmBootImageSize
;
55 BOOLEAN MiDbgEnableMdDump
=
62 /* PRIVATE FUNCTIONS *********************************************************/
67 MiInitSystemMemoryAreas()
70 PHYSICAL_ADDRESS BoundaryAddressMultiple
;
72 BoundaryAddressMultiple
.QuadPart
= 0;
75 // First initialize the page table and hyperspace memory areas
77 MiInitPageDirectoryMap();
82 BaseAddress
= (PVOID
)PCR
;
83 MmCreateMemoryArea(MmGetKernelAddressSpace(),
84 MEMORY_AREA_SYSTEM
| MEMORY_AREA_STATIC
,
86 PAGE_SIZE
* KeNumberProcessors
,
91 BoundaryAddressMultiple
);
94 // Now the KUSER_SHARED_DATA
96 BaseAddress
= (PVOID
)KI_USER_SHARED_DATA
;
97 MmCreateMemoryArea(MmGetKernelAddressSpace(),
98 MEMORY_AREA_SYSTEM
| MEMORY_AREA_STATIC
,
105 BoundaryAddressMultiple
);
110 MiDbgDumpMemoryDescriptors(VOID
)
112 PLIST_ENTRY NextEntry
;
113 PMEMORY_ALLOCATION_DESCRIPTOR Md
;
114 ULONG TotalPages
= 0;
116 DPRINT1("Base\t\tLength\t\tType\n");
117 for (NextEntry
= KeLoaderBlock
->MemoryDescriptorListHead
.Flink
;
118 NextEntry
!= &KeLoaderBlock
->MemoryDescriptorListHead
;
119 NextEntry
= NextEntry
->Flink
)
121 Md
= CONTAINING_RECORD(NextEntry
, MEMORY_ALLOCATION_DESCRIPTOR
, ListEntry
);
122 DPRINT1("%08lX\t%08lX\t%s\n", Md
->BasePage
, Md
->PageCount
, MemType
[Md
->MemoryType
]);
123 TotalPages
+= Md
->PageCount
;
126 DPRINT1("Total: %08lX (%d MB)\n", TotalPages
, (TotalPages
* PAGE_SIZE
) / 1024 / 1024);
131 MmArmInitSystem(IN ULONG Phase
,
132 IN PLOADER_PARAMETER_BLOCK LoaderBlock
);
139 /* Initialize the kernel address space */
140 KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock
);
141 MmKernelAddressSpace
= MmGetCurrentAddressSpace();
142 MmInitGlobalKernelPageDirectory();
144 /* Dump memory descriptors */
145 if (MiDbgEnableMdDump
) MiDbgDumpMemoryDescriptors();
148 // Initialize ARM³ in phase 0
150 MmArmInitSystem(0, KeLoaderBlock
);
152 /* Intialize system memory areas */
153 MiInitSystemMemoryAreas();
155 /* Initialize the page list */
156 MmInitializePageList();
159 // Initialize ARM³ in phase 1
161 MmArmInitSystem(1, KeLoaderBlock
);
163 /* Put the paged pool after the loaded modules */
164 MmPagedPoolBase
= (PVOID
)PAGE_ROUND_UP((ULONG_PTR
)MmSystemRangeStart
+
166 MmPagedPoolSize
= MM_PAGED_POOL_SIZE
;
169 // Initialize ARM³ in phase 2
171 MmArmInitSystem(2, KeLoaderBlock
);
173 /* Initialize paged pool */
174 MmInitializePagedPool();
176 /* Initialize working sets */
177 MmInitializeMemoryConsumer(MC_USER
, MmTrimUserMemory
);
182 MmInitSystem(IN ULONG Phase
,
183 IN PLOADER_PARAMETER_BLOCK LoaderBlock
)
185 extern MMPTE HyperTemplatePte
;
187 MMPTE TempPte
= HyperTemplatePte
;
188 PFN_NUMBER PageFrameNumber
;
192 /* Initialize Mm bootstrap */
195 /* Initialize the Loader Lock */
196 KeInitializeMutant(&MmSystemLoadLock
, FALSE
);
198 /* Reload boot drivers */
199 MiReloadBootLoadedDrivers(LoaderBlock
);
201 /* Initialize the loaded module list */
202 MiInitializeLoadedModuleList(LoaderBlock
);
204 /* Setup shared user data settings that NT does as well */
205 ASSERT(SharedUserData
->NumberOfPhysicalPages
== 0);
206 SharedUserData
->NumberOfPhysicalPages
= MmStats
.NrTotalPages
;
207 SharedUserData
->LargePageMinimum
= 0;
209 /* For now, we assume that we're always Server */
210 SharedUserData
->NtProductType
= NtProductServer
;
214 MmInitializeRmapList();
215 MmInitializePageOp();
216 MmInitSectionImplementation();
220 // Create a PTE to double-map the shared data section. We allocate it
221 // from paged pool so that we can't fault when trying to touch the PTE
222 // itself (to map it), since paged pool addresses will already be mapped
223 // by the fault handler.
225 MmSharedUserDataPte
= ExAllocatePoolWithTag(PagedPool
,
228 if (!MmSharedUserDataPte
) return FALSE
;
231 // Now get the PTE for shared data, and read the PFN that holds it
233 PointerPte
= MiAddressToPte(KI_USER_SHARED_DATA
);
234 ASSERT(PointerPte
->u
.Hard
.Valid
== 1);
235 PageFrameNumber
= PFN_FROM_PTE(PointerPte
);
238 // Now write a copy of it
240 TempPte
.u
.Hard
.Owner
= 1;
241 TempPte
.u
.Hard
.PageFrameNumber
= PageFrameNumber
;
242 *MmSharedUserDataPte
= TempPte
;
247 MiInitBalancerThread();
250 * Initialise the modified page writer.
254 /* Initialize the balance set manager */