[NTOS:KD] Cleanup of some old code.

- Remove KdbInit() macro and directly use KdbpCliInit() (since the place
  where it was used was already within an #ifdef KDBG block).

- Declare KdpKdbgInit() only when KDBG is defined, move its definition
  into kdio.c and remove the legacy wrappers/kdbg.c file.
  And in KdbInitialize(), set KdpInitRoutine directly to the former,
  instead of using the KdpKdbgInit indirection.

- Don't reset KdComPortInUse in KdpDebugLogInit().

- Minor refactorings: KdpSerialDebugPrint -> KdpSerialPrint and make it
  static; argument name "Message" -> "String", "StringLength" -> "Length".
This commit is contained in:
Hermès Bélusca-Maïto 2022-11-18 17:44:29 +01:00
parent 98e585364b
commit 271b985981
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
6 changed files with 53 additions and 68 deletions

View file

@ -27,16 +27,8 @@ KdPortPutByteEx(
UCHAR ByteToSend UCHAR ByteToSend
); );
/* SYMBOL ROUTINES **********************************************************/
#ifdef _NTOSKRNL_ #ifdef _NTOSKRNL_
#ifdef KDBG
# define KdbInit() KdbpCliInit()
#else
# define KdbInit() do { } while (0)
#endif
/* KD ROUTINES ***************************************************************/ /* KD ROUTINES ***************************************************************/
typedef enum _KD_CONTINUE_TYPE typedef enum _KD_CONTINUE_TYPE
@ -89,11 +81,13 @@ KdpDebugLogInit(
ULONG BootPhase ULONG BootPhase
); );
#ifdef KDBG
VOID VOID
NTAPI NTAPI
KdpKdbgInit( KdpKdbgInit(
struct _KD_DISPATCH_TABLE *DispatchTable, struct _KD_DISPATCH_TABLE *DispatchTable,
ULONG BootPhase); ULONG BootPhase);
#endif
/* KD ROUTINES ***************************************************************/ /* KD ROUTINES ***************************************************************/
@ -193,7 +187,7 @@ extern KD_DISPATCH_TABLE DispatchTable[KdMax];
/* The KD Native Provider List */ /* The KD Native Provider List */
extern LIST_ENTRY KdProviders; extern LIST_ENTRY KdProviders;
#endif #endif // _NTOSKRNL_
#if DBG && defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c #if DBG && defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c
#define ID_Win32PreServiceHook 'WSH0' #define ID_Win32PreServiceHook 'WSH0'

View file

@ -590,7 +590,7 @@ IoInitSystem(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
#if !defined(_WINKD_) && defined(KDBG) #if !defined(_WINKD_) && defined(KDBG)
/* Read KDB Data */ /* Read KDB Data */
KdbInit(); KdbpCliInit();
/* I/O is now setup for disk access, so phase 3 */ /* I/O is now setup for disk access, so phase 3 */
KdInitSystem(3, LoaderBlock); KdInitSystem(3, LoaderBlock);

View file

@ -49,10 +49,15 @@ KDP_DEBUG_MODE KdpDebugMode;
LIST_ENTRY KdProviders = {&KdProviders, &KdProviders}; LIST_ENTRY KdProviders = {&KdProviders, &KdProviders};
KD_DISPATCH_TABLE DispatchTable[KdMax]; KD_DISPATCH_TABLE DispatchTable[KdMax];
PKDP_INIT_ROUTINE InitRoutines[KdMax] = {KdpScreenInit, PKDP_INIT_ROUTINE InitRoutines[KdMax] =
KdpSerialInit, {
KdpDebugLogInit, KdpScreenInit,
KdpKdbgInit}; KdpSerialInit,
KdpDebugLogInit,
#ifdef KDBG
KdpKdbgInit
#endif
};
static ULONG KdbgNextApiNumber = DbgKdContinueApi; static ULONG KdbgNextApiNumber = DbgKdContinueApi;
static CONTEXT KdbgContext; static CONTEXT KdbgContext;
@ -155,7 +160,7 @@ KdpLoggerThread(PVOID Context)
static VOID static VOID
NTAPI NTAPI
KdpPrintToLogFile(PCHAR String, KdpPrintToLogFile(PCHAR String,
ULONG StringLength) ULONG Length)
{ {
KIRQL OldIrql; KIRQL OldIrql;
ULONG beg, end, num; ULONG beg, end, num;
@ -168,8 +173,8 @@ KdpPrintToLogFile(PCHAR String,
beg = KdpCurrentPosition; beg = KdpCurrentPosition;
num = KdpFreeBytes; num = KdpFreeBytes;
if (StringLength < num) if (Length < num)
num = StringLength; num = Length;
if (num != 0) if (num != 0)
{ {
@ -222,8 +227,6 @@ KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable,
if (BootPhase == 0) if (BootPhase == 0)
{ {
KdComPortInUse = NULL;
/* Write out the functions that we support for now */ /* Write out the functions that we support for now */
DispatchTable->KdpInitRoutine = KdpDebugLogInit; DispatchTable->KdpInitRoutine = KdpDebugLogInit;
DispatchTable->KdpPrintRoutine = KdpPrintToLogFile; DispatchTable->KdpPrintRoutine = KdpPrintToLogFile;
@ -303,19 +306,19 @@ KdpDebugLogInit(PKD_DISPATCH_TABLE DispatchTable,
/* SERIAL FUNCTIONS **********************************************************/ /* SERIAL FUNCTIONS **********************************************************/
VOID static VOID
NTAPI NTAPI
KdpSerialDebugPrint(PCHAR Message, KdpSerialPrint(PCHAR String,
ULONG Length) ULONG Length)
{ {
PCHAR pch = (PCHAR)Message; PCHAR pch = String;
KIRQL OldIrql; KIRQL OldIrql;
/* Acquire the printing spinlock without waiting at raised IRQL */ /* Acquire the printing spinlock without waiting at raised IRQL */
OldIrql = KdpAcquireLock(&KdpSerialSpinLock); OldIrql = KdpAcquireLock(&KdpSerialSpinLock);
/* Output the message */ /* Output the string */
while (pch < Message + Length && *pch != '\0') while (pch < String + Length && *pch)
{ {
if (*pch == '\n') if (*pch == '\n')
{ {
@ -340,7 +343,7 @@ KdpSerialInit(PKD_DISPATCH_TABLE DispatchTable,
{ {
/* Write out the functions that we support for now */ /* Write out the functions that we support for now */
DispatchTable->KdpInitRoutine = KdpSerialInit; DispatchTable->KdpInitRoutine = KdpSerialInit;
DispatchTable->KdpPrintRoutine = KdpSerialDebugPrint; DispatchTable->KdpPrintRoutine = KdpSerialPrint;
/* Initialize the Port */ /* Initialize the Port */
if (!KdPortInitializeEx(&SerialPortInfo, SerialPortNumber)) if (!KdPortInitializeEx(&SerialPortInfo, SerialPortNumber))
@ -396,21 +399,21 @@ KdpScreenRelease(VOID)
} }
/* /*
* Screen debug logger function KdpScreenPrint() writes text messages into * Screen debug logger function KdpScreenPrint() writes text strings into
* KdpDmesgBuffer, using it as a circular buffer. KdpDmesgBuffer contents could * KdpDmesgBuffer, using it as a circular buffer. KdpDmesgBuffer contents could
* be later (re)viewed using dmesg command of kdbg. KdpScreenPrint() protects * be later (re)viewed using dmesg command of kdbg. KdpScreenPrint() protects
* KdpDmesgBuffer from simultaneous writes by use of KdpDmesgLogSpinLock. * KdpDmesgBuffer from simultaneous writes by use of KdpDmesgLogSpinLock.
*/ */
static VOID static VOID
NTAPI NTAPI
KdpScreenPrint(PCHAR Message, KdpScreenPrint(PCHAR String,
ULONG Length) ULONG Length)
{ {
PCHAR pch = (PCHAR)Message; PCHAR pch = String;
KIRQL OldIrql; KIRQL OldIrql;
ULONG beg, end, num; ULONG beg, end, num;
while (pch < Message + Length && *pch) while (pch < String + Length && *pch)
{ {
if (*pch == '\b') if (*pch == '\b')
{ {
@ -453,7 +456,7 @@ KdpScreenPrint(PCHAR Message,
KdpScreenLineBufferPos = KdpScreenLineLength; KdpScreenLineBufferPos = KdpScreenLineLength;
} }
/* Dmesg: store Message in the buffer to show it later */ /* Dmesg: store the string in the buffer to show it later */
if (KdbpIsInDmesgMode) if (KdbpIsInDmesgMode)
return; return;
@ -473,12 +476,12 @@ KdpScreenPrint(PCHAR Message,
end = (beg + num) % KdpDmesgBufferSize; end = (beg + num) % KdpDmesgBufferSize;
if (end > beg) if (end > beg)
{ {
RtlCopyMemory(KdpDmesgBuffer + beg, Message, Length); RtlCopyMemory(KdpDmesgBuffer + beg, String, Length);
} }
else else
{ {
RtlCopyMemory(KdpDmesgBuffer + beg, Message, KdpDmesgBufferSize - beg); RtlCopyMemory(KdpDmesgBuffer + beg, String, KdpDmesgBufferSize - beg);
RtlCopyMemory(KdpDmesgBuffer, Message + (KdpDmesgBufferSize - beg), end); RtlCopyMemory(KdpDmesgBuffer, String + (KdpDmesgBufferSize - beg), end);
} }
KdpDmesgCurrentPosition = end; KdpDmesgCurrentPosition = end;
@ -491,7 +494,7 @@ KdpScreenPrint(PCHAR Message,
/* Optional step(?): find out a way to notify about buffer exhaustion, /* Optional step(?): find out a way to notify about buffer exhaustion,
* and possibly fall into kbd to use dmesg command: user will read * and possibly fall into kbd to use dmesg command: user will read
* debug messages before they will be wiped over by next writes. * debug strings before they will be wiped over by next writes.
*/ */
} }
@ -531,6 +534,25 @@ KdpScreenInit(PKD_DISPATCH_TABLE DispatchTable,
} }
} }
#ifdef KDBG
/* KDBG FUNCTIONS ************************************************************/
/* NOTE: This may be moved completely into kdb_symbols.c */
VOID NTAPI
KdbInitialize(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase);
VOID
NTAPI
KdpKdbgInit(
PKD_DISPATCH_TABLE DispatchTable,
ULONG BootPhase)
{
/* Forward the call */
KdbInitialize(DispatchTable, BootPhase);
}
#endif
/* GENERAL FUNCTIONS *********************************************************/ /* GENERAL FUNCTIONS *********************************************************/
BOOLEAN BOOLEAN

View file

@ -1,30 +0,0 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/kd/wrappers/kdbg.c
* PURPOSE: KDBG Wrapper for Kd
*
* PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
*/
#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
VOID NTAPI
KdbInitialize(PKD_DISPATCH_TABLE DispatchTable, ULONG BootPhase);
/* FUNCTIONS *****************************************************************/
VOID
NTAPI
KdpKdbgInit(PKD_DISPATCH_TABLE DispatchTable,
ULONG BootPhase)
{
#ifdef KDBG
/* Forward the call */
KdbInitialize(DispatchTable, BootPhase);
#else
/* When KDBG is disabled, it is not used/initialized at all */
#endif
}

View file

@ -368,7 +368,7 @@ KdbInitialize(
if (BootPhase == 0) if (BootPhase == 0)
{ {
/* Write out the functions that we support for now */ /* Write out the functions that we support for now */
DispatchTable->KdpInitRoutine = KdpKdbgInit; DispatchTable->KdpInitRoutine = KdbInitialize;
DispatchTable->KdpPrintRoutine = KdbDebugPrint; DispatchTable->KdpPrintRoutine = KdbDebugPrint;
/* Register as a Provider */ /* Register as a Provider */
@ -382,7 +382,7 @@ KdbInitialize(
* /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */ * /LOADSYMBOLS={YES|NO}, /NOLOADSYMBOLS={YES|NO} */
ASSERT(KeLoaderBlock); ASSERT(KeLoaderBlock);
p1 = KeLoaderBlock->LoadOptions; p1 = KeLoaderBlock->LoadOptions;
while('\0' != *p1 && NULL != (p2 = strchr(p1, '/'))) while ('\0' != *p1 && NULL != (p2 = strchr(p1, '/')))
{ {
p2++; p2++;
Found = 0; Found = 0;

View file

@ -415,7 +415,6 @@ if(NOT _WINKD_)
endif() endif()
list(APPEND SOURCE list(APPEND SOURCE
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/wrappers/kdbg.c
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdio.c ${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdio.c
${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdmain.c) ${REACTOS_SOURCE_DIR}/ntoskrnl/kd/kdmain.c)