Skip to content

Commit efb59cf

Browse files
committed
[NTOS:KD] Move implementation of banner display from each debug output type to common code
1 parent 5758d02 commit efb59cf

File tree

2 files changed

+72
-81
lines changed

2 files changed

+72
-81
lines changed

ntoskrnl/kd/kdinit.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <ntoskrnl.h>
11+
#include <reactos/buildno.h>
1112
#define NDEBUG
1213
#include <debug.h>
1314

@@ -39,6 +40,71 @@ extern ANSI_STRING KdpLogFileName;
3940

4041
/* PRIVATE FUNCTIONS *********************************************************/
4142

43+
/*
44+
* Get the total size of the memory before
45+
* Mm is initialized, by counting the number
46+
* of physical pages. Useful for debug logging.
47+
*
48+
* Strongly inspired by:
49+
* mm\ARM3\mminit.c : MiScanMemoryDescriptors(...)
50+
*
51+
* See also: kd\kdio.c
52+
*/
53+
static INIT_FUNCTION
54+
SIZE_T
55+
KdpGetMemorySizeInMBs(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
56+
{
57+
PLIST_ENTRY ListEntry;
58+
PMEMORY_ALLOCATION_DESCRIPTOR Descriptor;
59+
SIZE_T NumberOfPhysicalPages = 0;
60+
61+
/* Loop the memory descriptors */
62+
for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
63+
ListEntry != &LoaderBlock->MemoryDescriptorListHead;
64+
ListEntry = ListEntry->Flink)
65+
{
66+
/* Get the descriptor */
67+
Descriptor = CONTAINING_RECORD(ListEntry,
68+
MEMORY_ALLOCATION_DESCRIPTOR,
69+
ListEntry);
70+
71+
/* Check if this is invisible memory */
72+
if ((Descriptor->MemoryType == LoaderFirmwarePermanent) ||
73+
(Descriptor->MemoryType == LoaderSpecialMemory) ||
74+
(Descriptor->MemoryType == LoaderHALCachedMemory) ||
75+
(Descriptor->MemoryType == LoaderBBTMemory))
76+
{
77+
/* Skip this descriptor */
78+
continue;
79+
}
80+
81+
/* Check if this is bad memory */
82+
if (Descriptor->MemoryType != LoaderBad)
83+
{
84+
/* Count this in the total of pages */
85+
NumberOfPhysicalPages += Descriptor->PageCount;
86+
}
87+
}
88+
89+
/* Round size up. Assumed to better match actual physical RAM size */
90+
return ALIGN_UP_BY(NumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
91+
}
92+
93+
/* See also: kd\kdio.c */
94+
static INIT_FUNCTION
95+
VOID
96+
KdpPrintBanner(IN SIZE_T MemSizeMBs)
97+
{
98+
DPRINT1("-----------------------------------------------------\n");
99+
DPRINT1("ReactOS " KERNEL_VERSION_STR " (Build " KERNEL_VERSION_BUILD_STR ") (Commit " KERNEL_VERSION_COMMIT_HASH ")\n");
100+
DPRINT1("%u System Processor [%u MB Memory]\n", KeNumberProcessors, MemSizeMBs);
101+
102+
if (KeLoaderBlock)
103+
{
104+
DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions);
105+
DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, KeLoaderBlock->NtHalPathName, KeLoaderBlock->ArcHalDeviceName, KeLoaderBlock->NtBootPathName);
106+
}
107+
}
42108
BOOLEAN
43109
NTAPI
44110
KdRegisterDebuggerDataBlock(IN ULONG Tag,
@@ -84,6 +150,7 @@ KdInitSystem(IN ULONG BootPhase,
84150
PLDR_DATA_TABLE_ENTRY LdrEntry;
85151
ULONG i;
86152
PCHAR CommandLine;
153+
SIZE_T MemSizeMBs;
87154

88155
/* Check if this is Phase 1 */
89156
if (BootPhase)
@@ -234,6 +301,11 @@ KdInitSystem(IN ULONG BootPhase,
234301

235302
/* Let user-mode know that it's enabled as well */
236303
SharedUserData->KdDebuggerEnabled = TRUE;
304+
305+
/* Display separator + ReactOS version at start of the debug log */
306+
MemSizeMBs = KdpGetMemorySizeInMBs(KeLoaderBlock);
307+
KdpPrintBanner(MemSizeMBs);
308+
237309
}
238310
else
239311
{

ntoskrnl/kd/kdio.c

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -46,70 +46,6 @@ volatile ULONG KdbDmesgTotalWritten = 0;
4646
volatile BOOLEAN KdbpIsInDmesgMode = FALSE;
4747
static KSPIN_LOCK KdpDmesgLogSpinLock;
4848

49-
/* UTILITY FUNCTIONS *********************************************************/
50-
51-
/*
52-
* Get the total size of the memory before
53-
* Mm is initialized, by counting the number
54-
* of physical pages. Useful for debug logging.
55-
*
56-
* Strongly inspired by:
57-
* mm\ARM3\mminit.c : MiScanMemoryDescriptors(...)
58-
*
59-
* See also: kd64\kdinit.c
60-
*/
61-
static INIT_FUNCTION
62-
SIZE_T
63-
KdpGetMemorySizeInMBs(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
64-
{
65-
PLIST_ENTRY ListEntry;
66-
PMEMORY_ALLOCATION_DESCRIPTOR Descriptor;
67-
SIZE_T NumberOfPhysicalPages = 0;
68-
69-
/* Loop the memory descriptors */
70-
for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Flink;
71-
ListEntry != &LoaderBlock->MemoryDescriptorListHead;
72-
ListEntry = ListEntry->Flink)
73-
{
74-
/* Get the descriptor */
75-
Descriptor = CONTAINING_RECORD(ListEntry,
76-
MEMORY_ALLOCATION_DESCRIPTOR,
77-
ListEntry);
78-
79-
/* Check if this is invisible memory */
80-
if ((Descriptor->MemoryType == LoaderFirmwarePermanent) ||
81-
(Descriptor->MemoryType == LoaderSpecialMemory) ||
82-
(Descriptor->MemoryType == LoaderHALCachedMemory) ||
83-
(Descriptor->MemoryType == LoaderBBTMemory))
84-
{
85-
/* Skip this descriptor */
86-
continue;
87-
}
88-
89-
/* Check if this is bad memory */
90-
if (Descriptor->MemoryType != LoaderBad)
91-
{
92-
/* Count this in the total of pages */
93-
NumberOfPhysicalPages += Descriptor->PageCount;
94-
}
95-
}
96-
97-
/* Round size up. Assumed to better match actual physical RAM size */
98-
return ALIGN_UP_BY(NumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
99-
}
100-
101-
/* See also: kd64\kdinit.c */
102-
static INIT_FUNCTION
103-
VOID
104-
KdpPrintBanner(IN SIZE_T MemSizeMBs)
105-
{
106-
DPRINT1("-----------------------------------------------------\n");
107-
DPRINT1("ReactOS " KERNEL_VERSION_STR " (Build " KERNEL_VERSION_BUILD_STR ") (Commit " KERNEL_VERSION_COMMIT_HASH ")\n");
108-
DPRINT1("%u System Processor [%u MB Memory]\n", KeNumberProcessors, MemSizeMBs);
109-
DPRINT1("Command Line: %s\n", KeLoaderBlock->LoadOptions);
110-
DPRINT1("ARC Paths: %s %s %s %s\n", KeLoaderBlock->ArcBootDeviceName, KeLoaderBlock->NtHalPathName, KeLoaderBlock->ArcHalDeviceName, KeLoaderBlock->NtBootPathName);
111-
}
112-
11349
/* LOCKING FUNCTIONS *********************************************************/
11450

11551
KIRQL
@@ -254,7 +190,6 @@ KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable,
254190
IO_STATUS_BLOCK Iosb;
255191
HANDLE ThreadHandle;
256192
KPRIORITY Priority;
257-
SIZE_T MemSizeMBs;
258193

259194
if (!KdpDebugMode.File) return;
260195

@@ -277,11 +212,6 @@ KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable,
277212

278213
/* Initialize spinlock */
279214
KeInitializeSpinLock(&KdpDebugLogSpinLock);
280-
281-
/* Display separator + ReactOS version at start of the debug log */
282-
/* Round size up. Assumed to better match actual physical RAM size */
283-
MemSizeMBs = ALIGN_UP_BY(MmNumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
284-
KdpPrintBanner(MemSizeMBs);
285215
}
286216
else if (BootPhase == 2)
287217
{
@@ -374,7 +304,6 @@ NTAPI
374304
KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
375305
ULONG BootPhase)
376306
{
377-
SIZE_T MemSizeMBs;
378307
if (!KdpDebugMode.Serial) return;
379308

380309
if (BootPhase == 0)
@@ -396,10 +325,6 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
396325

397326
/* Register as a Provider */
398327
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
399-
400-
/* Display separator + ReactOS version at start of the debug log */
401-
MemSizeMBs = KdpGetMemorySizeInMBs(KeLoaderBlock);
402-
KdpPrintBanner(MemSizeMBs);
403328
}
404329
else if (BootPhase == 2)
405330
{
@@ -545,7 +470,6 @@ NTAPI
545470
KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
546471
ULONG BootPhase)
547472
{
548-
SIZE_T MemSizeMBs;
549473
if (!KdpDebugMode.Screen) return;
550474

551475
if (BootPhase == 0)
@@ -572,11 +496,6 @@ KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
572496

573497
/* Initialize spinlock */
574498
KeInitializeSpinLock(&KdpDmesgLogSpinLock);
575-
576-
/* Display separator + ReactOS version at start of the debug log */
577-
/* Round size up. Assumed to better match actual physical RAM size */
578-
MemSizeMBs = ALIGN_UP_BY(MmNumberOfPhysicalPages * PAGE_SIZE, 1024 * 1024) / (1024 * 1024);
579-
KdpPrintBanner(MemSizeMBs);
580499
}
581500
else if (BootPhase == 2)
582501
{

0 commit comments

Comments
 (0)