[NTOS]: Enable usage of ARM3 paged pool, up until Mm Phase 2.
[reactos.git] / reactos / ntoskrnl / mm / ARM3 / i386 / init.c
index 250324c..ed15b40 100644 (file)
@@ -151,6 +151,7 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     MMPTE TempPde, TempPte;
     PVOID NonPagedPoolExpansionVa;
     ULONG OldCount;
+    KIRQL OldIrql;
 
     /* Check for kernel stack size that's too big */
     if (MmLargeStackSize > (KERNEL_LARGE_STACK_SIZE / _1KB))
@@ -305,7 +306,7 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     // then add the color tables and convert to pages
     //
     MxPfnAllocation = (MmHighestPhysicalPage + 1) * sizeof(MMPFN);
-    MxPfnAllocation <<= 1;
+    //MxPfnAllocation <<= 1;
     MxPfnAllocation += (MmSecondaryColors * sizeof(MMCOLOR_TABLES) * 2);
     MxPfnAllocation >>= PAGE_SHIFT;
     
@@ -338,7 +339,7 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     MmNonPagedSystemStart = (PVOID)((ULONG_PTR)MmNonPagedPoolStart -
                                     (MmNumberOfSystemPtes + 1) * PAGE_SIZE);
     MmNonPagedSystemStart = (PVOID)((ULONG_PTR)MmNonPagedSystemStart &
-                                    ~((4 * 1024 * 1024) - 1));
+                                    ~(PDE_MAPPED_VA - 1));
     
     //
     // Don't let it go below the minimum
@@ -379,19 +380,13 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     // with the old memory manager, so we'll create a "Shadow PFN Database"
     // instead, and arbitrarly start it at 0xB0000000.
     //
-    // We actually create two PFN databases, one for ReactOS starting here,
-    // and the next one used for ARM3, which starts right after. The MmPfnAllocation
-    // variable actually holds the size of both (the colored tables come after
-    // the ARM3 PFN database).
-    //
-    MmPfnDatabase[0] = (PVOID)0xB0000000;
-    MmPfnDatabase[1] = &MmPfnDatabase[0][MmHighestPhysicalPage];
-    ASSERT(((ULONG_PTR)MmPfnDatabase[0] & ((4 * 1024 * 1024) - 1)) == 0);
+    MmPfnDatabase = (PVOID)0xB0000000;
+    ASSERT(((ULONG_PTR)MmPfnDatabase & (PDE_MAPPED_VA - 1)) == 0);
             
     //
     // Non paged pool comes after the PFN database
     //
-    MmNonPagedPoolStart = (PVOID)((ULONG_PTR)MmPfnDatabase[0] +
+    MmNonPagedPoolStart = (PVOID)((ULONG_PTR)MmPfnDatabase +
                                   (MxPfnAllocation << PAGE_SHIFT));
 
     //
@@ -442,7 +437,7 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     //
     // Now we need pages for the page tables which will map initial NP
     //
-    StartPde = MiAddressToPde(MmPfnDatabase[0]);
+    StartPde = MiAddressToPde(MmPfnDatabase);
     EndPde = MiAddressToPde((PVOID)((ULONG_PTR)MmNonPagedPoolStart +
                                     MmSizeOfNonPagedPoolInBytes - 1));
     while (StartPde <= EndPde)
@@ -509,12 +504,14 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     /* Initialize the color tables */
     MiInitializeColorTables();
     
+    /* ReactOS Stuff */
+    extern KEVENT ZeroPageThreadEvent;
+    KeInitializeEvent(&ZeroPageThreadEvent, NotificationEvent, TRUE);
+    
     /* Build the PFN Database */
     MiInitializePfnDatabase(LoaderBlock);
+    MmInitializeBalancer(MmAvailablePages, 0);
 
-    /* Call back into shitMM to setup the ReactOS PFN database */
-    MmInitializePageList();
-        
     //
     // Reset the descriptor back so we can create the correct memory blocks
     //
@@ -541,21 +538,26 @@ MiInitMachineDependent(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
     //
     MiInitializeSystemPtes(PointerPte, MmNumberOfSystemPtes, SystemPteSpace);
     
-    //
-    // Get the PDE For hyperspace
-    //
+    /* Get the PDE For hyperspace */
     StartPde = MiAddressToPde(HYPER_SPACE);
     
-    //
-    // Allocate a page for it and create it
-    //
-    PageFrameIndex = MmAllocPage(MC_SYSTEM);
+    /* Lock PFN database */
+    OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
+    
+    /* Allocate a page for hyperspace and create it */
+    PageFrameIndex = MiRemoveAnyPage(0);
     TempPde.u.Hard.PageFrameNumber = PageFrameIndex;
     TempPde.u.Hard.Global = FALSE; // Hyperspace is local!
     ASSERT(StartPde->u.Hard.Valid == 0);
     ASSERT(TempPde.u.Hard.Valid == 1);
     *StartPde = TempPde;
     
+    /* Flush the TLB */
+    KeFlushCurrentTb();
+    
+    /* Release the lock */
+    KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
+    
     //
     // Zero out the page table now
     //