update for HEAD-2003091401
[reactos.git] / ntoskrnl / mm / mminit.c
index 1c7eb09..306c878 100644 (file)
@@ -42,21 +42,34 @@ static MM_SYSTEM_SIZE MmSystemSize = MmSmallSystem;
 extern unsigned int _bss_end__;
 
 static MEMORY_AREA* kernel_text_desc = NULL;
+static MEMORY_AREA* kernel_map_desc = NULL;
 static MEMORY_AREA* kernel_data_desc = NULL;
 static MEMORY_AREA* kernel_param_desc = NULL;
 static MEMORY_AREA* kernel_pool_desc = NULL;
 static MEMORY_AREA* kernel_shared_data_desc = NULL;
+static MEMORY_AREA* MiKernelMapDescriptor = NULL;
 static MEMORY_AREA* MiPagedPoolDescriptor = NULL;
 
 PHYSICAL_ADDRESS MmSharedDataPagePhysicalAddress;
 
+PVOID MiNonPagedPoolStart;
+ULONG MiNonPagedPoolLength;
+PVOID MiKernelMapStart;
+ULONG MiKernelMapLength;
+
 /* FUNCTIONS ****************************************************************/
 
+/*
+ * @implemented
+ */
 BOOLEAN STDCALL MmIsThisAnNtAsSystem(VOID)
 {
    return(IsThisAnNtAsSystem);
 }
 
+/*
+ * @implemented
+ */
 MM_SYSTEM_SIZE STDCALL MmQuerySystemSize(VOID)
 {
    return(MmSystemSize);
@@ -84,13 +97,37 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
    DPRINT("MmInitVirtualMemory(%x, %x)\n",LastKernelAddress, KernelLength);
    
    LastKernelAddress = PAGE_ROUND_UP(LastKernelAddress);
-   
+
    MmInitMemoryAreas();
-   ExInitNonPagedPool(LastKernelAddress + PAGE_SIZE);
+
+   /* Don't change the start of kernel map. Pte's must always exist for this region. */
+   MiKernelMapStart = (PVOID)LastKernelAddress + PAGE_SIZE;
+   MiKernelMapLength = MM_KERNEL_MAP_SIZE;
+
+   MiNonPagedPoolStart = MiKernelMapStart + MiKernelMapLength + PAGE_SIZE;
+   MiNonPagedPoolLength = MM_NONPAGED_POOL_SIZE;
+
+   MmPagedPoolBase = MiNonPagedPoolStart + MiNonPagedPoolLength + PAGE_SIZE;
+   MmPagedPoolSize = MM_PAGED_POOL_SIZE;
+
+
+   MiInitKernelMap();
+   MiInitializeNonPagedPool();
 
    /*
     * Setup the system area descriptor list
     */
+   BaseAddress = (PVOID)0xf0000000;
+   MmCreateMemoryArea(NULL,
+                     MmGetKernelAddressSpace(),
+                     MEMORY_AREA_SYSTEM,
+                     &BaseAddress,
+                     0x400000,
+                     0,
+                     &kernel_map_desc,
+                     FALSE,
+                     FALSE);
+
    BaseAddress = (PVOID)KERNEL_BASE;
    Length = PAGE_ROUND_UP(((ULONG)&_text_end__)) - KERNEL_BASE;
    ParamLength = ParamLength - Length;
@@ -106,8 +143,8 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
                      Length,
                      0,
                      &kernel_text_desc,
+                     FALSE,
                      FALSE);
-
    Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) - 
             PAGE_ROUND_UP(((ULONG)&_text_end__));
    ParamLength = ParamLength - Length;
@@ -120,50 +157,60 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
     * the only thread running.
     */
    MmCreateMemoryArea(NULL,
-                     MmGetKernelAddressSpace(),                      
+                     MmGetKernelAddressSpace(),
                      MEMORY_AREA_SYSTEM,
                      &BaseAddress,
                      Length,
                      0,
                      &kernel_data_desc,
+                     FALSE,
                      FALSE);
-   
+
    BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&_bss_end__));
-//   Length = ParamLength;
    Length = LastKernelAddress - (ULONG)BaseAddress;
    MmCreateMemoryArea(NULL,
-                     MmGetKernelAddressSpace(),                      
+                     MmGetKernelAddressSpace(),
                      MEMORY_AREA_SYSTEM,
                      &BaseAddress,
                      Length,
                      0,
                      &kernel_param_desc,
+                     FALSE,
                      FALSE);
-
-   BaseAddress = (PVOID)(LastKernelAddress + PAGE_SIZE);
-   Length = NONPAGED_POOL_SIZE;
+   
+   BaseAddress = MiNonPagedPoolStart;
    MmCreateMemoryArea(NULL,
                      MmGetKernelAddressSpace(),
                      MEMORY_AREA_SYSTEM,
                      &BaseAddress,
-                     Length,
+                     MiNonPagedPoolLength,
                      0,
                      &kernel_pool_desc,
+                     FALSE,
                      FALSE);
 
-   MmPagedPoolSize = MM_PAGED_POOL_SIZE;
-   BaseAddress = (PVOID)(LastKernelAddress + PAGE_SIZE + NONPAGED_POOL_SIZE +
-                        PAGE_SIZE);
-   MmPagedPoolBase = BaseAddress;
-   Length = MM_PAGED_POOL_SIZE;
-   MmCreateMemoryArea(NULL,
+   BaseAddress = MiKernelMapStart;
+   Status = MmCreateMemoryArea(NULL,
+                     MmGetKernelAddressSpace(),
+                     MEMORY_AREA_SYSTEM,
+                     &BaseAddress,
+                     MiKernelMapLength,
+                     0,
+                     &MiKernelMapDescriptor,
+                     FALSE,
+                     FALSE);
+   
+   BaseAddress = MmPagedPoolBase;
+   Status = MmCreateMemoryArea(NULL,
                      MmGetKernelAddressSpace(),
                      MEMORY_AREA_PAGED_POOL,
                      &BaseAddress,
-                     Length,
+                     MmPagedPoolSize,
                      0,
                      &MiPagedPoolDescriptor,
+                     FALSE,
                      FALSE);
+
    MmInitializePagedPool();
 
    /*
@@ -178,6 +225,7 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
                      Length,
                      0,
                      &kernel_shared_data_desc,
+                     FALSE,
                      FALSE);
    Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, 
                                        &MmSharedDataPagePhysicalAddress);
@@ -189,7 +237,7 @@ VOID MmInitVirtualMemory(ULONG LastKernelAddress,
    if (!NT_SUCCESS(Status))
      {
        DbgPrint("Unable to create virtual mapping\n");
-       KeBugCheck(0);
+       KEBUGCHECK(0);
      }
    RtlZeroMemory(BaseAddress, Length);
 
@@ -203,7 +251,8 @@ VOID MmInit1(ULONG FirstKrnlPhysAddr,
             ULONG LastKrnlPhysAddr,
             ULONG LastKernelAddress,
             PADDRESS_RANGE BIOSMemoryMap,
-            ULONG AddressRangeCount)
+            ULONG AddressRangeCount,
+            ULONG MaxMem)
 /*
  * FUNCTION: Initalize memory managment
  */
@@ -219,6 +268,7 @@ VOID MmInit1(ULONG FirstKrnlPhysAddr,
                  LastKrnlPhysAddr,
                  LastKernelAddress);
 
+
    if ((BIOSMemoryMap != NULL) && (AddressRangeCount > 0))
      {
        // If we have a bios memory map, recalulate the the memory size
@@ -237,12 +287,20 @@ VOID MmInit1(ULONG FirstKrnlPhysAddr,
          }
      }
 
+   if (KeLoaderBlock.MemHigher >= (MaxMem - 1) * 1024)
+     {
+        KeLoaderBlock.MemHigher = (MaxMem - 1) * 1024;
+     }
+
    /*
     * FIXME: Set this based on the system command line
     */
+   MmSystemRangeStart = (PVOID)KERNEL_BASE; // 0xC0000000
    MmUserProbeAddress = (PVOID)0x7fff0000;
    MmHighestUserAddress = (PVOID)0x7ffeffff;
    
+   MmInitGlobalKernelPageDirectory();
+
    /*
     * Initialize memory managment statistics
     */
@@ -328,7 +386,7 @@ VOID MmInit1(ULONG FirstKrnlPhysAddr,
         i<(KERNEL_BASE + 2 * PAGE_TABLE_SIZE); 
         i=i+PAGE_SIZE)
      {
-        MmDeleteVirtualMapping(NULL, (PVOID)(i), FALSE, NULL, NULL);
+        MmRawDeleteVirtualMapping((PVOID)(i));
      }
    DPRINT("Almost done MmInit()\n");
 #ifndef MP
@@ -361,6 +419,7 @@ VOID MmInit3(VOID)
       if all processors are started. */
    MmDeletePageTable(NULL, 0);
 #endif
+   MmInitZeroPageThread();
    MmInitPagerThread();
    MmCreatePhysicalMemorySection();
    MmInitializeRmapList();