[NTOS:KD] Merge initialization phases 1 and 2, and fix log file debugging

Phase 2 and 3 were not done anymore since 777a2d94da.

Fix that, by merging phases 1 and 2, and by calling phase 3 later
for log file debugging, when ExpInitializationPhase = 3

CORE-17470
This commit is contained in:
Hervé Poussineau 2021-02-15 23:20:15 +01:00
parent 99a9e7e493
commit 58332b076c

View file

@ -19,6 +19,7 @@
#define KdpBufferSize (1024 * 512) #define KdpBufferSize (1024 * 512)
static BOOLEAN KdpLoggingEnabled = FALSE; static BOOLEAN KdpLoggingEnabled = FALSE;
static BOOLEAN KdpLoggingStarting = FALSE;
static PCHAR KdpDebugBuffer = NULL; static PCHAR KdpDebugBuffer = NULL;
static volatile ULONG KdpCurrentPosition = 0; static volatile ULONG KdpCurrentPosition = 0;
static volatile ULONG KdpFreeBytes = 0; static volatile ULONG KdpFreeBytes = 0;
@ -26,6 +27,7 @@ static KSPIN_LOCK KdpDebugLogSpinLock;
static KEVENT KdpLoggerThreadEvent; static KEVENT KdpLoggerThreadEvent;
static HANDLE KdpLogFileHandle; static HANDLE KdpLogFileHandle;
ANSI_STRING KdpLogFileName = RTL_CONSTANT_STRING("\\SystemRoot\\debug.log"); ANSI_STRING KdpLogFileName = RTL_CONSTANT_STRING("\\SystemRoot\\debug.log");
extern ULONG ExpInitializationPhase;
static KSPIN_LOCK KdpSerialSpinLock; static KSPIN_LOCK KdpSerialSpinLock;
ULONG SerialPortNumber = DEFAULT_DEBUG_PORT; ULONG SerialPortNumber = DEFAULT_DEBUG_PORT;
@ -155,6 +157,7 @@ KdpPrintToLogFile(PCHAR String,
{ {
KIRQL OldIrql; KIRQL OldIrql;
ULONG beg, end, num; ULONG beg, end, num;
BOOLEAN DoReinit = FALSE;
if (KdpDebugBuffer == NULL) return; if (KdpDebugBuffer == NULL) return;
@ -184,8 +187,18 @@ KdpPrintToLogFile(PCHAR String,
} }
/* Release the spinlock */ /* Release the spinlock */
if (OldIrql == PASSIVE_LEVEL && !KdpLoggingStarting && !KdpLoggingEnabled && ExpInitializationPhase >= 2)
{
DoReinit = TRUE;
}
KdpReleaseLock(&KdpDebugLogSpinLock, OldIrql); KdpReleaseLock(&KdpDebugLogSpinLock, OldIrql);
if (DoReinit)
{
KdpLoggingStarting = TRUE;
KdpDebugLogInit(NULL, 3);
}
/* Signal the logger thread */ /* Signal the logger thread */
if (OldIrql <= DISPATCH_LEVEL && KdpLoggingEnabled) if (OldIrql <= DISPATCH_LEVEL && KdpLoggingEnabled)
KeSetEvent(&KdpLoggerThreadEvent, IO_NO_INCREMENT, FALSE); KeSetEvent(&KdpLoggerThreadEvent, IO_NO_INCREMENT, FALSE);
@ -224,9 +237,7 @@ KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable,
/* Initialize spinlock */ /* Initialize spinlock */
KeInitializeSpinLock(&KdpDebugLogSpinLock); KeInitializeSpinLock(&KdpDebugLogSpinLock);
}
else if (BootPhase == 2)
{
HalDisplayString("\r\n File log debugging enabled\r\n\r\n"); HalDisplayString("\r\n File log debugging enabled\r\n\r\n");
} }
else if (BootPhase == 3) else if (BootPhase == 3)
@ -338,7 +349,7 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
/* Register as a Provider */ /* Register as a Provider */
InsertTailList(&KdProviders, &DispatchTable->KdProvidersList); InsertTailList(&KdProviders, &DispatchTable->KdProvidersList);
} }
else if (BootPhase == 2) else if (BootPhase == 1)
{ {
HalDisplayString("\r\n Serial debugging enabled\r\n\r\n"); HalDisplayString("\r\n Serial debugging enabled\r\n\r\n");
} }
@ -508,9 +519,7 @@ KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
/* Initialize spinlock */ /* Initialize spinlock */
KeInitializeSpinLock(&KdpDmesgLogSpinLock); KeInitializeSpinLock(&KdpDmesgLogSpinLock);
}
else if (BootPhase == 2)
{
HalDisplayString("\r\n Screen debugging enabled\r\n\r\n"); HalDisplayString("\r\n Screen debugging enabled\r\n\r\n");
} }
} }