#include <debug.h>
#include "ntstrsafe.h"
+/* Temporary hack */
+BOOLEAN
+NTAPI
+MmArmInitSystem(
+ IN ULONG Phase,
+ IN PLOADER_PARAMETER_BLOCK LoaderBlock
+);
+
typedef struct _INIT_BUFFER
{
WCHAR DebugBuffer[256];
if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* Initialize the memory manager at phase 0 */
- if (!MmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
+ if (!MmArmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* Load boot symbols */
ExpLoadBootSymbols(LoaderBlock);
if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
/* Create NLS section */
- ExpInitNls(KeLoaderBlock);
+ ExpInitNls(LoaderBlock);
/* Initialize Cache Views */
if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
NtClose(OptionHandle);
}
- /* Unmap Low memory, and initialize the MPW and Balancer Thread */
- MmInitSystem(2, LoaderBlock);
+ /* FIXME: This doesn't do anything for now */
+ MmArmInitSystem(2, LoaderBlock);
/* Update progress bar */
InbvUpdateProgressBar(80);
SIZE_T MmTotalCommitLimit;
SIZE_T MmTotalCommitLimitMaximum;
+/* Internal setting used for debugging memory descriptors */
+BOOLEAN MiDbgEnableMdDump =
+#ifdef _ARM_
+TRUE;
+#else
+FALSE;
+#endif
+
/* PRIVATE FUNCTIONS **********************************************************/
PFN_NUMBER
MiInitializeSystemSpaceMap(NULL);
}
-NTSTATUS
+VOID
+NTAPI
+MiDbgDumpMemoryDescriptors(VOID)
+{
+ PLIST_ENTRY NextEntry;
+ PMEMORY_ALLOCATION_DESCRIPTOR Md;
+ ULONG TotalPages = 0;
+ PCHAR
+ MemType[] =
+ {
+ "ExceptionBlock ",
+ "SystemBlock ",
+ "Free ",
+ "Bad ",
+ "LoadedProgram ",
+ "FirmwareTemporary ",
+ "FirmwarePermanent ",
+ "OsloaderHeap ",
+ "OsloaderStack ",
+ "SystemCode ",
+ "HalCode ",
+ "BootDriver ",
+ "ConsoleInDriver ",
+ "ConsoleOutDriver ",
+ "StartupDpcStack ",
+ "StartupKernelStack",
+ "StartupPanicStack ",
+ "StartupPcrPage ",
+ "StartupPdrPage ",
+ "RegistryData ",
+ "MemoryData ",
+ "NlsData ",
+ "SpecialMemory ",
+ "BBTMemory ",
+ "LoaderReserve ",
+ "LoaderXIPRom "
+ };
+
+ DPRINT1("Base\t\tLength\t\tType\n");
+ for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
+ NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
+ NextEntry = NextEntry->Flink)
+ {
+ Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
+ DPRINT1("%08lX\t%08lX\t%s\n", Md->BasePage, Md->PageCount, MemType[Md->MemoryType]);
+ TotalPages += Md->PageCount;
+ }
+
+ DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
+}
+
+BOOLEAN
NTAPI
MmArmInitSystem(IN ULONG Phase,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
PPHYSICAL_MEMORY_RUN Run;
PFN_NUMBER PageCount;
+ /* Dump memory descriptors */
+ if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
+
//
// Instantiate memory that we don't consider RAM/usable
// We use the same exclusions that Windows does, in order to try to be
//
// Always return success for now
//
- return STATUS_SUCCESS;
+ return TRUE;
}
/* EOF */
IN KPROCESSOR_MODE Mode,
IN PVOID TrapInformation)
{
- PMEMORY_AREA MemoryArea;
+ PMEMORY_AREA MemoryArea = NULL;
/* Cute little hack for ROS */
if ((ULONG_PTR)Address >= (ULONG_PTR)MmSystemRangeStart)
#endif
}
- /*
- * Check if this is an ARM3 memory area or if there's no memory area at all.
- * The latter can happen early in the boot cycle when ARM3 paged pool is in
- * use before having defined the memory areas proper.
- * A proper fix would be to define memory areas in the ARM3 code, but we want
- * to avoid adding this ReactOS-specific construct to ARM3 code.
- * Either way, in the future, as ReactOS-paged pool is eliminated, this hack
- * can go away.
- */
- MemoryArea = MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address);
- if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
+ /* Is there a ReactOS address space yet? */
+ if (MmGetKernelAddressSpace())
{
- /* Could this be a VAD fault from user-mode? */
- MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address);
+ /* Check if this is an ARM3 memory area */
+ MemoryArea = MmLocateMemoryAreaByAddress(MmGetKernelAddressSpace(), Address);
+ if (!(MemoryArea) && (Address <= MM_HIGHEST_USER_ADDRESS))
+ {
+ /* Could this be a VAD fault from user-mode? */
+ MemoryArea = MmLocateMemoryAreaByAddress(MmGetCurrentAddressSpace(), Address);
+ }
}
- if ((!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
- ((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)))
+
+ /* Is this an ARM3 memory area, or is there no address space yet? */
+ if (((MemoryArea) && (MemoryArea->Type == MEMORY_AREA_OWNED_BY_ARM3)) ||
+ (!(MemoryArea) && ((ULONG_PTR)Address >= (ULONG_PTR)MmPagedPoolStart)) ||
+ (!MmGetKernelAddressSpace()))
{
- //
- // Hand it off to more competent hands...
- //
+ /* This is an ARM3 fault */
DPRINT("ARM3 fault %p\n", MemoryArea);
return MmArmAccessFault(StoreInstruction, Address, Mode, TrapInformation);
}
VOID NTAPI MiInitializeUserPfnBitmap(VOID);
-PCHAR
-MemType[] =
-{
- "ExceptionBlock ",
- "SystemBlock ",
- "Free ",
- "Bad ",
- "LoadedProgram ",
- "FirmwareTemporary ",
- "FirmwarePermanent ",
- "OsloaderHeap ",
- "OsloaderStack ",
- "SystemCode ",
- "HalCode ",
- "BootDriver ",
- "ConsoleInDriver ",
- "ConsoleOutDriver ",
- "StartupDpcStack ",
- "StartupKernelStack",
- "StartupPanicStack ",
- "StartupPcrPage ",
- "StartupPdrPage ",
- "RegistryData ",
- "MemoryData ",
- "NlsData ",
- "SpecialMemory ",
- "BBTMemory ",
- "LoaderReserve ",
- "LoaderXIPRom "
-};
-
HANDLE MpwThreadHandle;
KEVENT MpwThreadEvent;
UCHAR MmDisablePagingExecutive = 1; // Forced to off
PMMPTE MmSharedUserDataPte;
PMMSUPPORT MmKernelAddressSpace;
-BOOLEAN MiDbgEnableMdDump =
-#ifdef _ARM_
-TRUE;
-#else
-FALSE;
-#endif
/* PRIVATE FUNCTIONS *********************************************************/
"Non Paged Pool Expansion PTE Space");
}
-VOID
-NTAPI
-MiDbgDumpMemoryDescriptors(VOID)
-{
- PLIST_ENTRY NextEntry;
- PMEMORY_ALLOCATION_DESCRIPTOR Md;
- ULONG TotalPages = 0;
-
- DPRINT1("Base\t\tLength\t\tType\n");
- for (NextEntry = KeLoaderBlock->MemoryDescriptorListHead.Flink;
- NextEntry != &KeLoaderBlock->MemoryDescriptorListHead;
- NextEntry = NextEntry->Flink)
- {
- Md = CONTAINING_RECORD(NextEntry, MEMORY_ALLOCATION_DESCRIPTOR, ListEntry);
- DPRINT1("%08lX\t%08lX\t%s\n", Md->BasePage, Md->PageCount, MemType[Md->MemoryType]);
- TotalPages += Md->PageCount;
- }
-
- DPRINT1("Total: %08lX (%d MB)\n", TotalPages, (TotalPages * PAGE_SIZE) / 1024 / 1024);
-}
-
NTSTATUS NTAPI
MmMpwThreadMain(PVOID Ignored)
{
MMPTE TempPte = ValidKernelPte;
PFN_NUMBER PageFrameNumber;
- if (Phase == 0)
- {
- /* Initialize the kernel address space */
- KeInitializeGuardedMutex(&PsGetCurrentProcess()->AddressCreationLock);
- MmKernelAddressSpace = MmGetCurrentAddressSpace();
- MmInitGlobalKernelPageDirectory();
-
- /* Dump memory descriptors */
- if (MiDbgEnableMdDump) MiDbgDumpMemoryDescriptors();
-
- /* Initialize ARMĀ³ in phase 0 */
- MmArmInitSystem(0, KeLoaderBlock);
-
- /* Intialize system memory areas */
- MiInitSystemMemoryAreas();
-
- /* Dump the address space */
- MiDbgDumpAddressSpace();
- }
- else if (Phase == 1)
- {
- MiInitializeUserPfnBitmap();
- MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
- MmInitializeRmapList();
- MmInitializePageOp();
- MmInitSectionImplementation();
- MmInitPagingFile();
-
- //
- // Create a PTE to double-map the shared data section. We allocate it
- // from paged pool so that we can't fault when trying to touch the PTE
- // itself (to map it), since paged pool addresses will already be mapped
- // by the fault handler.
- //
- MmSharedUserDataPte = ExAllocatePoolWithTag(PagedPool,
- sizeof(MMPTE),
- ' mM');
- if (!MmSharedUserDataPte) return FALSE;
-
- //
- // Now get the PTE for shared data, and read the PFN that holds it
- //
- PointerPte = MiAddressToPte((PVOID)KI_USER_SHARED_DATA);
- ASSERT(PointerPte->u.Hard.Valid == 1);
- PageFrameNumber = PFN_FROM_PTE(PointerPte);
-
- /* Build the PTE and write it */
- MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte,
- PointerPte,
- MM_READONLY,
- PageFrameNumber);
- *MmSharedUserDataPte = TempPte;
-
- /* Setup the memory threshold events */
- if (!MiInitializeMemoryEvents()) return FALSE;
-
- /*
- * Unmap low memory
- */
- MiInitBalancerThread();
-
- /*
- * Initialise the modified page writer.
- */
- MmInitMpwThread();
-
- /* Initialize the balance set manager */
- MmInitBsmThread();
- }
+ /* Initialize the kernel address space */
+ ASSERT(Phase == 1);
+ KeInitializeGuardedMutex(&PsIdleProcess->AddressCreationLock);
+ MmKernelAddressSpace = &PsIdleProcess->Vm;
+
+ /* Intialize system memory areas */
+ MiInitSystemMemoryAreas();
+
+ /* Dump the address space */
+ MiDbgDumpAddressSpace();
+
+ MmInitGlobalKernelPageDirectory();
+ MiInitializeUserPfnBitmap();
+ MmInitializeMemoryConsumer(MC_USER, MmTrimUserMemory);
+ MmInitializeRmapList();
+ MmInitializePageOp();
+ MmInitSectionImplementation();
+ MmInitPagingFile();
+
+ //
+ // Create a PTE to double-map the shared data section. We allocate it
+ // from paged pool so that we can't fault when trying to touch the PTE
+ // itself (to map it), since paged pool addresses will already be mapped
+ // by the fault handler.
+ //
+ MmSharedUserDataPte = ExAllocatePoolWithTag(PagedPool,
+ sizeof(MMPTE),
+ ' mM');
+ if (!MmSharedUserDataPte) return FALSE;
+
+ //
+ // Now get the PTE for shared data, and read the PFN that holds it
+ //
+ PointerPte = MiAddressToPte((PVOID)KI_USER_SHARED_DATA);
+ ASSERT(PointerPte->u.Hard.Valid == 1);
+ PageFrameNumber = PFN_FROM_PTE(PointerPte);
+
+ /* Build the PTE and write it */
+ MI_MAKE_HARDWARE_PTE_KERNEL(&TempPte,
+ PointerPte,
+ MM_READONLY,
+ PageFrameNumber);
+ *MmSharedUserDataPte = TempPte;
+
+ /* Setup the memory threshold events */
+ if (!MiInitializeMemoryEvents()) return FALSE;
+
+ /*
+ * Unmap low memory
+ */
+ MiInitBalancerThread();
+
+ /*
+ * Initialise the modified page writer.
+ */
+ MmInitMpwThread();
+
+ /* Initialize the balance set manager */
+ MmInitBsmThread();
return TRUE;
}