Index: ntoskrnl/kd/kdio.c =================================================================== --- ntoskrnl/kd/kdio.c (révision 57283) +++ ntoskrnl/kd/kdio.c (copie de travail) @@ -43,6 +43,55 @@ KSPIN_LOCK KdpDmesgLogSpinLock; volatile BOOLEAN KdbpIsInDmesgMode = FALSE; +/* UTILITY FUNCTIONS *********************************************************/ + +/* + * Get the total size of the memory before + * Mm is initialized, by counting the number + * of physical pages. Useful for debug logging. + * + * Strongly inspired by: + * mm\ARM3\mminit.c : MiScanMemoryDescriptors(...) + */ +SIZE_T +NTAPI +KdpGetMemorySizeInMBs(IN PLOADER_PARAMETER_BLOCK LoaderBlock) +{ + PLIST_ENTRY ListEntry; + PMEMORY_ALLOCATION_DESCRIPTOR Descriptor; + PFN_COUNT NumberOfPhysicalPages = 0; + + /* Loop the memory descriptors */ + for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Flink; + ListEntry != &LoaderBlock->MemoryDescriptorListHead; + ListEntry = ListEntry->Flink) + { + /* Get the descriptor */ + Descriptor = CONTAINING_RECORD(ListEntry, + MEMORY_ALLOCATION_DESCRIPTOR, + ListEntry); + + /* Check if this is invisible memory */ + if ((Descriptor->MemoryType == LoaderFirmwarePermanent) || + (Descriptor->MemoryType == LoaderSpecialMemory) || + (Descriptor->MemoryType == LoaderHALCachedMemory) || + (Descriptor->MemoryType == LoaderBBTMemory)) + { + /* Skip this descriptor */ + continue; + } + + /* Check if this is bad memory */ + if (Descriptor->MemoryType != LoaderBad) + { + /* Count this in the total of pages */ + NumberOfPhysicalPages += (PFN_COUNT)Descriptor->PageCount; + } + } + + return (SIZE_T)(NumberOfPhysicalPages * PAGE_SIZE / 1024 / 1024); +} + /* FILE DEBUG LOG FUNCTIONS **************************************************/ VOID @@ -325,7 +374,7 @@ /* Display separator + ReactOS version at start of the debug log */ DPRINT1("-----------------------------------------------------\n"); DPRINT1("ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n"); - MemSizeMBs = MmNumberOfPhysicalPages * PAGE_SIZE / 1024 / 1024; + MemSizeMBs = KdpGetMemorySizeInMBs(KeLoaderBlock); DPRINT1("%u System Processor [%u MB Memory]\n", KeNumberProcessors, MemSizeMBs); DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions); DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, @@ -477,36 +526,36 @@ } else if (BootPhase == 1) { - /* Allocate a buffer for dmesg log buffer. +1 for terminating null, - * see kdbp_cli.c:KdbpCmdDmesg()/2 - */ - KdpDmesgBuffer = ExAllocatePool(NonPagedPool, KdpDmesgBufferSize + 1); - RtlZeroMemory(KdpDmesgBuffer, KdpDmesgBufferSize + 1); - KdpDmesgFreeBytes = KdpDmesgBufferSize; - KdbDmesgTotalWritten = 0; + /* Allocate a buffer for dmesg log buffer. +1 for terminating null, + * see kdbp_cli.c:KdbpCmdDmesg()/2 + */ + KdpDmesgBuffer = ExAllocatePool(NonPagedPool, KdpDmesgBufferSize + 1); + RtlZeroMemory(KdpDmesgBuffer, KdpDmesgBufferSize + 1); + KdpDmesgFreeBytes = KdpDmesgBufferSize; + KdbDmesgTotalWritten = 0; - /* Take control of the display */ - InbvAcquireDisplayOwnership(); - InbvResetDisplay(); - InbvSolidColorFill(0, 0, 639, 479, 0); - InbvSetTextColor(15); - InbvSetScrollRegion(0, 0, 639, 479); - InbvInstallDisplayStringFilter(NULL); - InbvEnableDisplayString(TRUE); + /* Take control of the display */ + InbvAcquireDisplayOwnership(); + InbvResetDisplay(); + InbvSolidColorFill(0, 0, 639, 479, 0); + InbvSetTextColor(15); + InbvSetScrollRegion(0, 0, 639, 479); + InbvInstallDisplayStringFilter(NULL); + InbvEnableDisplayString(TRUE); - /* Initialize spinlock */ - KeInitializeSpinLock(&KdpDmesgLogSpinLock); + /* Initialize spinlock */ + KeInitializeSpinLock(&KdpDmesgLogSpinLock); - /* Display separator + ReactOS version at start of the debug log */ - DPRINT1("-----------------------------------------------------\n"); - DPRINT1("ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n"); - MemSizeMBs = MmNumberOfPhysicalPages * PAGE_SIZE / 1024 / 1024; - DPRINT1("%u System Processor [%u MB Memory]\n", KeNumberProcessors, MemSizeMBs); - DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions); - DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, - KeLoaderBlock->NtHalPathName, - KeLoaderBlock->ArcHalDeviceName, - KeLoaderBlock->NtBootPathName); + /* Display separator + ReactOS version at start of the debug log */ + DPRINT1("-----------------------------------------------------\n"); + DPRINT1("ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n"); + MemSizeMBs = MmNumberOfPhysicalPages * PAGE_SIZE / 1024 / 1024; + DPRINT1("%u System Processor [%u MB Memory]\n", KeNumberProcessors, MemSizeMBs); + DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions); + DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, + KeLoaderBlock->NtHalPathName, + KeLoaderBlock->ArcHalDeviceName, + KeLoaderBlock->NtBootPathName); } else if (BootPhase == 2) {