[NTOS]: Enable usage of ARM3 paged pool, up until Mm Phase 2.
[reactos.git] / reactos / ntoskrnl / mm / mminit.c
index ff8a740..83c45f1 100644 (file)
@@ -48,7 +48,7 @@ MemType[] =
     "LoaderXIPRom      "
 };
 
-PBOOLEAN Mm64BitPhysicalAddress = FALSE;
+BOOLEAN Mm64BitPhysicalAddress = FALSE;
 ULONG MmReadClusterSize;
 //
 // 0 | 1 is on/off paging, 2 is undocumented
@@ -56,7 +56,6 @@ ULONG MmReadClusterSize;
 UCHAR MmDisablePagingExecutive = 1; // Forced to off
 PMMPTE MmSharedUserDataPte;
 PMMSUPPORT MmKernelAddressSpace;
-extern KMUTANT MmSystemLoadLock;
 BOOLEAN MiDbgEnableMdDump =
 #ifdef _ARM_
 TRUE;
@@ -203,43 +202,78 @@ MiInitSystemMemoryAreas()
     // And now, ReactOS paged pool
     //
     BaseAddress = MmPagedPoolBase;
-    MmCreateMemoryArea(MmGetKernelAddressSpace(),
-                       MEMORY_AREA_PAGED_POOL | MEMORY_AREA_STATIC,
-                       &BaseAddress,
-                       MmPagedPoolSize,
-                       PAGE_READWRITE,
-                       &MArea,
-                       TRUE,
-                       0,
-                       BoundaryAddressMultiple);
+    Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+                                MEMORY_AREA_PAGED_POOL | MEMORY_AREA_STATIC,
+                                &BaseAddress,
+                                MmPagedPoolSize,
+                                PAGE_READWRITE,
+                                &MArea,
+                                TRUE,
+                                0,
+                                BoundaryAddressMultiple);
+    ASSERT(Status == STATUS_SUCCESS);
     
     //
     // Next, the KPCR
     //
     BaseAddress = (PVOID)PCR;
-    MmCreateMemoryArea(MmGetKernelAddressSpace(),
-                       MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
-                       &BaseAddress,
-                       PAGE_SIZE * KeNumberProcessors,
-                       PAGE_READWRITE,
-                       &MArea,
-                       TRUE,
-                       0,
-                       BoundaryAddressMultiple);
+    Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+                                MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
+                                &BaseAddress,
+                                PAGE_SIZE * KeNumberProcessors,
+                                PAGE_READWRITE,
+                                &MArea,
+                                TRUE,
+                                0,
+                                BoundaryAddressMultiple);
+    ASSERT(Status == STATUS_SUCCESS);
     
     //
     // Now the KUSER_SHARED_DATA
     //
     BaseAddress = (PVOID)KI_USER_SHARED_DATA;
-    MmCreateMemoryArea(MmGetKernelAddressSpace(),
-                       MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
-                       &BaseAddress,
-                       PAGE_SIZE,
-                       PAGE_READWRITE,
-                       &MArea,
-                       TRUE,
-                       0,
-                       BoundaryAddressMultiple);
+    Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+                                MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
+                                &BaseAddress,
+                                PAGE_SIZE,
+                                PAGE_READWRITE,
+                                &MArea,
+                                TRUE,
+                                0,
+                                BoundaryAddressMultiple);
+    ASSERT(Status == STATUS_SUCCESS);
+
+    //
+    // And the debugger mapping
+    //
+    BaseAddress = MI_DEBUG_MAPPING;
+    Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+                                MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
+                                &BaseAddress,
+                                PAGE_SIZE,
+                                PAGE_READWRITE,
+                                &MArea,
+                                TRUE,
+                                0,
+                                BoundaryAddressMultiple);
+    ASSERT(Status == STATUS_SUCCESS);
+
+#if defined(_X86_)
+    //
+    // Finally, reserve the 2  pages we currently make use of for HAL mappings
+    //
+    BaseAddress = (PVOID)0xFFC00000;
+    Status = MmCreateMemoryArea(MmGetKernelAddressSpace(),
+                                MEMORY_AREA_OWNED_BY_ARM3 | MEMORY_AREA_STATIC,
+                                &BaseAddress,
+                                PAGE_SIZE * 2,
+                                PAGE_READWRITE,
+                                &MArea,
+                                TRUE,
+                                0,
+                                BoundaryAddressMultiple);
+    ASSERT(Status == STATUS_SUCCESS);
+#endif
 }
 
 VOID
@@ -315,14 +349,16 @@ MiDbgDumpMemoryDescriptors(VOID)
     DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
 }
 
+VOID NTAPI MiInitializeUserPfnBitmap(VOID);
+
 BOOLEAN
 NTAPI
 MmInitSystem(IN ULONG Phase,
              IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 {
-    extern MMPTE HyperTemplatePte;
+    extern MMPTE ValidKernelPte;
     PMMPTE PointerPte;
-    MMPTE TempPte = HyperTemplatePte;
+    MMPTE TempPte = ValidKernelPte;
     PFN_NUMBER PageFrameNumber;
     
     if (Phase == 0)
@@ -335,19 +371,9 @@ MmInitSystem(IN ULONG Phase,
         /* Dump memory descriptors */
         if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
         
-        //
-        // Initialize ARM³ in phase 0
-        //
+        /* Initialize ARM³ in phase 0 */
         MmArmInitSystem(0, KeLoaderBlock);    
         
-        /* Initialize the page list */
-        MmInitializePageList();
-        
-        //
-        // Initialize ARM³ in phase 1
-        //
-        MmArmInitSystem(1, KeLoaderBlock);
-        
         /* Put the paged pool after the loaded modules */
         MmPagedPoolBase = (PVOID)PAGE_ROUND_UP((ULONG_PTR)MmSystemRangeStart +
                                                MmBootImageSize);
@@ -355,97 +381,15 @@ MmInitSystem(IN ULONG Phase,
         
         /* Intialize system memory areas */
         MiInitSystemMemoryAreas();
-        
-        //
-        // STEP 1: Allocate and free a single page, repeatedly
-        // We should always get the same address back
-        //
-        if (1)
-        {
-            PULONG Test, OldTest;
-            ULONG i;
-        
-            OldTest = Test = MiAllocatePoolPages(PagedPool, PAGE_SIZE);
-            ASSERT(Test);
-            for (i = 0; i < 16; i++)
-            {
-                MiFreePoolPages(Test);
-                Test = MiAllocatePoolPages(PagedPool, PAGE_SIZE);
-                ASSERT(OldTest == Test);
-            }
-            MiFreePoolPages(Test);
-        }
-        
-        //
-        // STEP 2: Allocate 2048 pages without freeing them
-        // We should run out of space at 1024 pages, since we don't support
-        // expansion yet.
-        //
-        if (1)
-        {
-            PULONG Test[2048];
-            ULONG i;
-            
-            for (i = 0; i < 2048; i++)
-            {
-                Test[i] = MiAllocatePoolPages(PagedPool, PAGE_SIZE);
-                if (!Test[i]) 
-                {
-                    ASSERT(i == 1024);
-                    break;
-                }
-            }
-            
-            //
-            // Cleanup
-            //
-            while (--i) if (Test[i]) MiFreePoolPages(Test[i]);
-        }
-        
-        //
-        // STEP 3: Allocate a page and touch it.
-        // We should get an ARM3 page fault and it should handle the fault
-        //
-        if (1)
-        {
-            PULONG Test;
-            
-            Test = MiAllocatePoolPages(PagedPool, PAGE_SIZE);
-            ASSERT(*Test == 0);
-            MiFreePoolPages(Test);
-        }
-        
+
         /* Dump the address space */
         MiDbgDumpAddressSpace();
-        
-        /* Initialize paged pool */
-        MmInitializePagedPool();
-        
-        /* Initialize working sets */
-        MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
-
-        /* Initialize the user mode image list */
-        InitializeListHead(&MmLoadedUserImageList);
-
-        /* Initialize the Loader Lock */
-        KeInitializeMutant(&MmSystemLoadLock, FALSE);
-
-        /* Reload boot drivers */
-        MiReloadBootLoadedDrivers(LoaderBlock);
-
-        /* Initialize the loaded module list */
-        MiInitializeLoadedModuleList(LoaderBlock);
-
-        /* Setup shared user data settings that NT does as well */
-        ASSERT(SharedUserData->NumberOfPhysicalPages == 0);
-        SharedUserData->NumberOfPhysicalPages = MmNumberOfPhysicalPages;
-        SharedUserData->LargePageMinimum = 0;
-        
-        /* For now, we assume that we're always Server */
-        SharedUserData->NtProductType = NtProductServer;
     }
     else if (Phase == 1)
     {
+        MmInitializePagedPool();
+        MiInitializeUserPfnBitmap();
+        MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
         MmInitializeRmapList();
         MmInitializePageOp();
         MmInitSectionImplementation();
@@ -476,6 +420,9 @@ MmInitSystem(IN ULONG Phase,
         TempPte.u.Hard.PageFrameNumber = PageFrameNumber;
         *MmSharedUserDataPte = TempPte;
         
+        /* Setup the memory threshold events */
+        if (!MiInitializeMemoryEvents()) return FALSE;
+        
         /*
          * Unmap low memory
          */
@@ -491,7 +438,9 @@ MmInitSystem(IN ULONG Phase,
     }
     else if (Phase == 2)
     {
-
+        /* Enough fun for now */
+        extern BOOLEAN AllowPagedPool;
+        AllowPagedPool = FALSE;
     }
 
     return TRUE;