From c2a4ad026ae89739bacfd8a8dea439a53841f216 Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Thu, 4 Sep 2025 10:49:40 +0200 Subject: [PATCH] Implement KD subsystem, add serial & framebuffer debug providers --- sdk/xtdk/kdtypes.h | 45 ++++++++ sdk/xtdk/xtdebug.h | 2 +- sdk/xtdk/xtkmapi.h | 1 + sdk/xtdk/xtstatus.h | 1 + sdk/xtdk/xtstruct.h | 2 + xtoskrnl/CMakeLists.txt | 3 + xtoskrnl/includes/globals.h | 20 +++- xtoskrnl/includes/kdi.h | 44 ++++++++ xtoskrnl/includes/xtos.h | 1 + xtoskrnl/kd/dbginit.c | 192 +++++++++++++++++++++++++++++++++++ xtoskrnl/kd/dbgio.c | 175 +++++++++++++++++++++++++++++++ xtoskrnl/kd/globals.c | 31 ++++++ xtoskrnl/ke/amd64/krnlinit.c | 1 - xtoskrnl/ke/i686/krnlinit.c | 1 - xtoskrnl/ke/krnlinit.c | 22 ++-- xtoskrnl/ke/panic.c | 2 +- 16 files changed, 530 insertions(+), 13 deletions(-) create mode 100644 sdk/xtdk/kdtypes.h create mode 100644 xtoskrnl/includes/kdi.h create mode 100644 xtoskrnl/kd/dbginit.c create mode 100644 xtoskrnl/kd/dbgio.c create mode 100644 xtoskrnl/kd/globals.c diff --git a/sdk/xtdk/kdtypes.h b/sdk/xtdk/kdtypes.h new file mode 100644 index 00000000..5ebf50ad --- /dev/null +++ b/sdk/xtdk/kdtypes.h @@ -0,0 +1,45 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: sdk/xtdk/kdtypes.h + * DESCRIPTION: Kernel Debugger data structures + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTDK_KDTYPES_H +#define __XTDK_KDTYPES_H + +#include +#include +#include + + +/* Number of debug providers */ +#define KDBG_PROVIDERS_COUNT 2 + +/* Debug providers bitmask definitions */ +#define DEBUG_PROVIDER_COMPORT 0x00000001 +#define DEBUG_PROVIDER_FRAMEBUFFER 0x00000002 + +/* Kernel routine callbacks */ +typedef XTSTATUS (XTAPI *PKD_INIT_ROUTINE)(); +typedef VOID (*PKD_PRINT_ROUTINE)(IN PCWSTR Format, IN ...); + +/* Debug mode structure definition */ +typedef struct _KD_DEBUG_MODE +{ + BOOLEAN Enabled; + ULONG Mode; + ULONG ComPortAddress; + ULONG ComPortNumber; + ULONG ComPortBaudRate; +} KD_DEBUG_MODE, *PKD_DEBUG_MODE; + +/* Kernel debugger dispatch table structure definition */ +typedef struct _KD_DISPATCH_TABLE +{ + LIST_ENTRY ListEntry; + RTL_PRINT_CONTEXT PrintContext; +} KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE; + +#endif /* __XTDK_KDTYPES_H */ diff --git a/sdk/xtdk/xtdebug.h b/sdk/xtdk/xtdebug.h index 56ecb81c..be4681a5 100644 --- a/sdk/xtdk/xtdebug.h +++ b/sdk/xtdk/xtdebug.h @@ -20,7 +20,7 @@ /* XTOS platform debugging macros */ #ifdef DBG #define DEBUG 1 - #define DebugPrint(Format, ...) if(KeDbgPrint) KeDbgPrint(Format, __VA_ARGS__); + #define DebugPrint(Format, ...) if(KdPrint) KdPrint(Format, __VA_ARGS__); #else #define DEBUG 0 #define DebugPrint(Format, ...) ((VOID)NULL) diff --git a/sdk/xtdk/xtkmapi.h b/sdk/xtdk/xtkmapi.h index 86ba3a49..d03d6022 100644 --- a/sdk/xtdk/xtkmapi.h +++ b/sdk/xtdk/xtkmapi.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/sdk/xtdk/xtstatus.h b/sdk/xtdk/xtstatus.h index 309aa2cb..169f507a 100644 --- a/sdk/xtdk/xtstatus.h +++ b/sdk/xtdk/xtstatus.h @@ -59,6 +59,7 @@ #define STATUS_INVALID_PARAMETER ((XTSTATUS) 0xC000000DL) #define STATUS_END_OF_FILE ((XTSTATUS) 0xC0000011L) #define STATUS_NO_MEMORY ((XTSTATUS) 0xC0000017L) +#define STATUS_PORT_DISCONNECTED ((XTSTATUS) 0xC0000037L) #define STATUS_CRC_ERROR ((XTSTATUS) 0xC000003FL) #define STATUS_INSUFFICIENT_RESOURCES ((XTSTATUS) 0xC000009AL) #define STATUS_DEVICE_NOT_READY ((XTSTATUS) 0xC00000A3L) diff --git a/sdk/xtdk/xtstruct.h b/sdk/xtdk/xtstruct.h index d782f111..d0046359 100644 --- a/sdk/xtdk/xtstruct.h +++ b/sdk/xtdk/xtstruct.h @@ -239,6 +239,8 @@ typedef struct _HL_FRAMEBUFFER_DATA HL_FRAMEBUFFER_DATA, *PHL_FRAMEBUFFER_DATA; typedef struct _HL_SCROLL_REGION_DATA HL_SCROLL_REGION_DATA, *PHL_SCROLL_REGION_DATA; typedef struct _KAPC KAPC, *PKAPC; typedef struct _KAPC_STATE KAPC_STATE, *PKAPC_STATE; +typedef struct _KD_DEBUG_MODE KD_DEBUG_MODE, *PKD_DEBUG_MODE; +typedef struct _KD_DISPATCH_TABLE KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE; typedef struct _KDPC KDPC, *PKDPC; typedef struct _KDPC_DATA KDPC_DATA, *PKDPC_DATA; typedef struct _KERNEL_INITIALIZATION_BLOCK KERNEL_INITIALIZATION_BLOCK, *PKERNEL_INITIALIZATION_BLOCK; diff --git a/xtoskrnl/CMakeLists.txt b/xtoskrnl/CMakeLists.txt index 147799ad..5037c0ec 100644 --- a/xtoskrnl/CMakeLists.txt +++ b/xtoskrnl/CMakeLists.txt @@ -39,6 +39,9 @@ list(APPEND XTOSKRNL_SOURCE ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/pic.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/ioport.c ${XTOSKRNL_SOURCE_DIR}/hl/${ARCH}/runlevel.c + ${XTOSKRNL_SOURCE_DIR}/kd/dbginit.c + ${XTOSKRNL_SOURCE_DIR}/kd/dbgio.c + ${XTOSKRNL_SOURCE_DIR}/kd/globals.c ${XTOSKRNL_SOURCE_DIR}/ke/apc.c ${XTOSKRNL_SOURCE_DIR}/ke/dpc.c ${XTOSKRNL_SOURCE_DIR}/ke/event.c diff --git a/xtoskrnl/includes/globals.h b/xtoskrnl/includes/globals.h index 1094dc84..0c45bfe7 100644 --- a/xtoskrnl/includes/globals.h +++ b/xtoskrnl/includes/globals.h @@ -36,8 +36,24 @@ EXTERN HL_SCROLL_REGION_DATA HlpScrollRegionData; /* System information */ EXTERN ACPI_SYSTEM_INFO HlpSystemInfo; -/* Pointer to boot loader provided DbgPrint() routine */ -EXTERN VOID (*KeDbgPrint)(IN PCWSTR Format, IN ...); +/* Pointer to DbgPrint() routine */ +EXTERN PKD_PRINT_ROUTINE KdPrint; + +/* Kernel Debugger mode */ +EXTERN KD_DEBUG_MODE KdpDebugMode; + +/* Debugger I/O providers initialization routines */ +EXTERN PKD_INIT_ROUTINE KdpIoProvidersInitRoutines[KDBG_PROVIDERS_COUNT]; + +/* List of active I/O providers */ +EXTERN LIST_ENTRY KdpProviders; + +/* Debugger's serial port handle */ +EXTERN CPPORT KdpSerialPort; + +/* Pre-defined serial port addresses */ +EXTERN ULONG KdpSerialPortList[COMPORT_COUNT]; + /* Kernel initialization block passed by boot loader */ EXTERN PKERNEL_INITIALIZATION_BLOCK KeInitializationBlock; diff --git a/xtoskrnl/includes/kdi.h b/xtoskrnl/includes/kdi.h new file mode 100644 index 00000000..65152731 --- /dev/null +++ b/xtoskrnl/includes/kdi.h @@ -0,0 +1,44 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/includes/kdi.h + * DESCRIPTION: Kernel Debugger routines + * DEVELOPERS: Aiken Harris + */ + +#ifndef __XTOSKRNL_KDI_H +#define __XTOSKRNL_KDI_H + +#include + + +/* Kernel Debugger routines forward references */ +XTAPI +XTSTATUS +KdInitializeDebugIoProviders(VOID); + +XTAPI +VOID +KdSetPrintRoutine(PVOID DebugPrintRoutine); + +XTCDECL +VOID +KdpDebugPrint(PCWSTR Format, ...); + +XTAPI +XTSTATUS +KdpDetectDebugPorts(VOID); + +XTAPI +XTSTATUS +KdpInitializeFrameBufferProvider(VOID); + +XTAPI +XTSTATUS +KdpInitializeSerialPortProvider(VOID); + +XTCDECL +XTSTATUS +KdpSerialWriteCharacter(WCHAR Character); + +#endif /* __XTOSKRNL_KDI_H */ diff --git a/xtoskrnl/includes/xtos.h b/xtoskrnl/includes/xtos.h index 744c5105..4dd1f245 100644 --- a/xtoskrnl/includes/xtos.h +++ b/xtoskrnl/includes/xtos.h @@ -15,6 +15,7 @@ /* Kernel specific headers */ #include "globals.h" #include "hli.h" +#include "kdi.h" #include "kei.h" #include "mmi.h" #include "poi.h" diff --git a/xtoskrnl/kd/dbginit.c b/xtoskrnl/kd/dbginit.c new file mode 100644 index 00000000..a1b598b1 --- /dev/null +++ b/xtoskrnl/kd/dbginit.c @@ -0,0 +1,192 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/kd/dbginit.c + * DESCRIPTION: Kernel Debugger initialization + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Initializes the kernel's debugger I/O providers. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +KdInitializeDebugIoProviders(VOID) +{ + ULONG Index; + XTSTATUS ProviderStatus, Status; + + /* Initialize debug providers list */ + RtlInitializeListHead(&KdpProviders); + + RtlZeroMemory(&KdpDebugMode, sizeof(KD_DEBUG_MODE)); + KdpDetectDebugPorts(); + + /* Iterate over providers initialization routines */ + for(Index = 0; Index < KDBG_PROVIDERS_COUNT; Index++) + { + /* Initialize provider */ + ProviderStatus = KdpIoProvidersInitRoutines[Index](); + Status = (Status || ProviderStatus); + } + + /* Initialize debug print routine */ + KdSetPrintRoutine(KdpDebugPrint); + + /* Return status code */ + return Status; +} + +/** + * Configures the kernel's debug print routine by setting a new output handler. + * + * @param DebugPrintRoutine + * Supplies a pointer to the new debug print routine. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KdSetPrintRoutine(PVOID DebugPrintRoutine) +{ + /* Set debug print routine */ + KdPrint = DebugPrintRoutine; +} + +/** + * Detects and enables the kernel's debug ports based on the 'DEBUG' parameter passed to the kernel. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +KdpDetectDebugPorts(VOID) +{ + PCWSTR DebugOption; + XTSTATUS Status; + + /* Get debug parameter */ + Status = KeGetKernelParameter(L"DEBUG", &DebugOption); + if(Status != STATUS_SUCCESS) + { + /* Debug parameter not found, disable debugging */ + KdpDebugMode.Enabled = FALSE; + return Status; + } + + /* Skip parameter name and check if it is set */ + DebugOption += 5; + if(*DebugOption != L'=') + { + /* Debug parameter not set, disable debugging */ + KdpDebugMode.Enabled = FALSE; + return STATUS_INVALID_PARAMETER; + } + + /* Skip '=' symbol */ + DebugOption++; + + /* Iterate over all debug ports */ + while(*DebugOption != L'\0' && *DebugOption != L' ') + { + /* Check what port is set for debugging */ + if(RtlCompareWideStringInsensitive(DebugOption, L"COM", 3) == 0) + { + /* Enable serial port debugging mode */ + KdpDebugMode.Mode |= DEBUG_PROVIDER_COMPORT; + + /* Read COM port number */ + DebugOption += 3; + while(*DebugOption >= '0' && *DebugOption <= '9') + { + /* Get port number */ + KdpDebugMode.ComPortNumber *= 10; + KdpDebugMode.ComPortNumber += *DebugOption - '0'; + DebugOption++; + } + + /* Check if custom COM port address supplied */ + if(KdpDebugMode.ComPortNumber == 0 && RtlCompareWideStringInsensitive(DebugOption, L":0x", 3) == 0) + { + /* COM port address provided */ + DebugOption += 3; + while((*DebugOption >= '0' && *DebugOption <= '9') || + (*DebugOption >= 'A' && *DebugOption <= 'F') || + (*DebugOption >= 'a' && *DebugOption <= 'f')) + { + /* Get port address */ + KdpDebugMode.ComPortAddress *= 16; + if(*DebugOption >= '0' && *DebugOption <= '9') + { + KdpDebugMode.ComPortAddress += *DebugOption - '0'; + } + else if(*DebugOption >= 'A' && *DebugOption <= 'F') + { + KdpDebugMode.ComPortAddress += *DebugOption - 'A' + 10; + } + else if(*DebugOption >= 'a' && *DebugOption <= 'f') + { + KdpDebugMode.ComPortAddress += *DebugOption - 'a' + 10; + } + DebugOption++; + } + } + + /* Look for additional COM port parameters */ + if(*DebugOption == ',') + { + /* Baud rate provided */ + DebugOption++; + while(*DebugOption >= '0' && *DebugOption <= '9') + { + /* Get baud rate */ + KdpDebugMode.ComPortBaudRate *= 10; + KdpDebugMode.ComPortBaudRate += *DebugOption - '0'; + DebugOption++; + } + } + } + else if(RtlCompareWideStringInsensitive(DebugOption, L"SCREEN", 6) == 0) + { + /* Enable framebuffer debugging mode */ + KdpDebugMode.Mode |= DEBUG_PROVIDER_FRAMEBUFFER; + DebugOption += 6; + } + else if(*DebugOption == L';') + { + /* Skip separator */ + DebugOption++; + } + else + { + /* Invalid debug option, skip it */ + while(*DebugOption != L'\0' && *DebugOption != L' ' && *DebugOption != L';') + { + /* Advance debug option */ + DebugOption++; + } + + } + } + + /* Ensure at least one debug port is enabled */ + if(KdpDebugMode.Mode != 0) + { + /* Enable debugging */ + KdpDebugMode.Enabled = TRUE; + } + + /* Return success */ + return STATUS_SUCCESS; +} diff --git a/xtoskrnl/kd/dbgio.c b/xtoskrnl/kd/dbgio.c new file mode 100644 index 00000000..301e460f --- /dev/null +++ b/xtoskrnl/kd/dbgio.c @@ -0,0 +1,175 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/kd/dbgio.c + * DESCRIPTION: Kernel Debugger I/O routines + * DEVELOPERS: Aiken Harris + */ + +#include + + +/** + * Prints a formatted string using the configured debug output providers. + * + * @param Format + * Supplies the format string. + * + * @param ... + * Supplies the variable argument list. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTCDECL +VOID +KdpDebugPrint(PCWSTR Format, ...) +{ + VA_LIST Arguments; + PLIST_ENTRY DispatchTableEntry; + PKD_DISPATCH_TABLE DispatchTable; + + /* Initialise the va_list */ + VA_START(Arguments, Format); + + DispatchTableEntry = KdpProviders.Flink; + while(DispatchTableEntry != &KdpProviders) + { + DispatchTable = CONTAIN_RECORD(DispatchTableEntry, KD_DISPATCH_TABLE, ListEntry); + + RtlFormatWideString(&DispatchTable->PrintContext, (PWCHAR)Format, Arguments); + + DispatchTableEntry = DispatchTableEntry->Flink; + } + + /* Clean up the va_list */ + VA_END(Arguments); +} + +/** + * Initializes the framebuffer device provider for the kernel debugger. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +KdpInitializeFrameBufferProvider(VOID) +{ + STATIC KD_DISPATCH_TABLE DispatchTable; + ULONG Height, Width; + + /* Check if framebuffer provider is enabled */ + if(KdpDebugMode.Enabled && (KdpDebugMode.Mode & DEBUG_PROVIDER_FRAMEBUFFER) == 0) + { + /* Screen is not enabled, no need to initialize provider */ + return STATUS_PORT_DISCONNECTED; + } + + /* Ensure frame buffer is initialized and get FB resolution */ + HlInitializeFrameBuffer(); + HlGetFrameBufferResolution(&Width, &Height); + + /* Print debug message */ + DebugPrint(L"Initializing debug console at framebuffer device (%lu x %lu)\n", Width, Height); + + /* Initialize scroll region to full screen and white font color */ + HlInitializeScrollRegion(0, 0, Width - 1, Height - 1, 0xFFFFFFFF); + + /* Initialize screen dispatch table */ + DispatchTable.PrintContext.WriteWideCharacter = HlDisplayCharacter; + RtlInsertHeadList(&KdpProviders, &DispatchTable.ListEntry); + + /* Return success */ + return STATUS_SUCCESS; +} + +/** + * Initializes the serial port device provider for the kernel debugger. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTAPI +XTSTATUS +KdpInitializeSerialPortProvider(VOID) +{ + STATIC KD_DISPATCH_TABLE DispatchTable; + XTSTATUS Status; + + /* Check if serial port provider is enabled */ + if(KdpDebugMode.Enabled && (KdpDebugMode.Mode & DEBUG_PROVIDER_COMPORT) == 0) + { + /* Serial port is not enabled, no need to initialize provider */ + return STATUS_PORT_DISCONNECTED; + } + + /* Check if custom COM port address supplied */ + if(!KdpDebugMode.ComPortAddress) + { + /* We support only a pre-defined number of ports */ + if(KdpDebugMode.ComPortNumber > COMPORT_COUNT) + { + /* Fail if wrong/unsupported port used */ + return STATUS_INVALID_PARAMETER; + } + + /* Check if serial port is set */ + if(KdpDebugMode.ComPortNumber == 0) + { + /* Use COM1 by default */ + KdpDebugMode.ComPortNumber = 1; + } + + /* Set custom port address based on the port number and print debug message */ + KdpDebugMode.ComPortAddress = KdpSerialPortList[KdpDebugMode.ComPortNumber - 1]; + DebugPrint(L"Initializing debug console at serial port (COM%lu, BaudRate: %lu)\n", + KdpDebugMode.ComPortNumber, KdpDebugMode.ComPortBaudRate); + } + else + { + /* Custom port address supplied, print debug message */ + DebugPrint(L"Initializing debug console at serial port (0x%lX, BaudRate: %lu)\n", + KdpDebugMode.ComPortAddress, KdpDebugMode.ComPortBaudRate); + } + + /* Initialize COM port */ + Status = HlInitializeComPort(&KdpSerialPort, UlongToPtr(KdpDebugMode.ComPortAddress), KdpDebugMode.ComPortBaudRate); + if(Status != STATUS_SUCCESS) + { + /* Serial port initialization failed */ + return Status; + } + + /* Initialize serial port dispatch table */ + DispatchTable.PrintContext.WriteWideCharacter = KdpSerialWriteCharacter; + RtlInsertHeadList(&KdpProviders, &DispatchTable.ListEntry); + + /* Return success */ + return STATUS_SUCCESS; +} + +/** + * Writes a character to the serial console. + * + * @param Character + * The integer promotion of the character to be written. + * + * @return This routine returns a status code. + * + * @since XT 1.0 + */ +XTCDECL +XTSTATUS +KdpSerialWriteCharacter(WCHAR Character) +{ + WCHAR Buffer[2]; + + /* Write character to the serial console */ + Buffer[0] = Character; + Buffer[1] = 0; + return HlComPortPutByte(&KdpSerialPort, Buffer[0]); +} diff --git a/xtoskrnl/kd/globals.c b/xtoskrnl/kd/globals.c new file mode 100644 index 00000000..cbc86aae --- /dev/null +++ b/xtoskrnl/kd/globals.c @@ -0,0 +1,31 @@ +/** + * PROJECT: ExectOS + * COPYRIGHT: See COPYING.md in the top level directory + * FILE: xtoskrnl/kd/globals.c + * DESCRIPTION: Architecture independent global variables related to KD subsystem + * DEVELOPERS: Aiken Harris + */ + +#include + + +/* Pointer to DbgPrint() routine */ +PKD_PRINT_ROUTINE KdPrint = NULL; + +/* Kernel Debugger mode */ +KD_DEBUG_MODE KdpDebugMode; + +/* Debugger I/O providers initialization routines */ +PKD_INIT_ROUTINE KdpIoProvidersInitRoutines[KDBG_PROVIDERS_COUNT] = { + KdpInitializeFrameBufferProvider, + KdpInitializeSerialPortProvider +}; + +/* List of active I/O providers */ +LIST_ENTRY KdpProviders; + +/* Debugger's serial port handle */ +CPPORT KdpSerialPort; + +/* Pre-defined serial port addresses */ +ULONG KdpSerialPortList[COMPORT_COUNT] = COMPORT_ADDRESS; diff --git a/xtoskrnl/ke/amd64/krnlinit.c b/xtoskrnl/ke/amd64/krnlinit.c index e6f69b46..610e4efb 100644 --- a/xtoskrnl/ke/amd64/krnlinit.c +++ b/xtoskrnl/ke/amd64/krnlinit.c @@ -109,7 +109,6 @@ KepStartKernel(VOID) CurrentProcess->ActiveProcessors |= (ULONG_PTR)1 << Prcb->CpuNumber; /* Enter infinite loop */ - HlClearScreen(0x7F7F7FFF); DebugPrint(L"KepStartKernel() finished. Entering infinite loop.\n"); for(;;); } diff --git a/xtoskrnl/ke/i686/krnlinit.c b/xtoskrnl/ke/i686/krnlinit.c index ccb193de..6d0d725d 100644 --- a/xtoskrnl/ke/i686/krnlinit.c +++ b/xtoskrnl/ke/i686/krnlinit.c @@ -109,7 +109,6 @@ KepStartKernel(VOID) CurrentProcess->ActiveProcessors |= (ULONG_PTR)1 << Prcb->CpuNumber; /* Enter infinite loop */ - HlClearScreen(0x7F7F7FFF); DebugPrint(L"KepStartKernel() finished. Entering infinite loop.\n"); for(;;); } diff --git a/xtoskrnl/ke/krnlinit.c b/xtoskrnl/ke/krnlinit.c index 1138589a..e8705a26 100644 --- a/xtoskrnl/ke/krnlinit.c +++ b/xtoskrnl/ke/krnlinit.c @@ -39,7 +39,21 @@ KeStartXtSystem(IN PKERNEL_INITIALIZATION_BLOCK Parameters) if(DEBUG && KeInitializationBlock->LoaderInformation.DbgPrint) { /* Use loader's provided DbgPrint() routine for early printing to serial console */ - KeDbgPrint = KeInitializationBlock->LoaderInformation.DbgPrint; + KdSetPrintRoutine(KeInitializationBlock->LoaderInformation.DbgPrint); + DebugPrint(L"Initializing ExectOS v%d.%d for %s\n", XTOS_VERSION_MAJOR, XTOS_VERSION_MINOR, _ARCH_NAME); + } + + /* Initialize boot CPU */ + ArInitializeProcessor(NULL); + + /* Initialize system resources */ + KepInitializeSystemResources(); + + /* Check if debugging enabled */ + if(DEBUG) + { + /* Initialize debug I/O */ + KdInitializeDebugIoProviders(); } /* Announce kernel startup */ @@ -48,12 +62,6 @@ KeStartXtSystem(IN PKERNEL_INITIALIZATION_BLOCK Parameters) XTOS_VERSION_BUILD, XTOS_VERSION_ARCH, XTOS_VERSION_HASH, XTOS_COMPILER_NAME, XTOS_COMPILER_VERSION); - /* Initialize boot CPU */ - ArInitializeProcessor(NULL); - - /* Initialize system resources */ - KepInitializeSystemResources(); - /* Architecture specific kernel initialization */ KepInitializeMachine(); diff --git a/xtoskrnl/ke/panic.c b/xtoskrnl/ke/panic.c index 92832f0d..aa27ca3f 100644 --- a/xtoskrnl/ke/panic.c +++ b/xtoskrnl/ke/panic.c @@ -76,6 +76,6 @@ KePanicEx(IN ULONG Code, IN ULONG_PTR Parameter3, IN ULONG_PTR Parameter4) { - KeDbgPrint(L"Fatal System Error: 0x%08lx\nKernel Panic!\n\n", Code); + KdPrint(L"Fatal System Error: 0x%08lx\nKernel Panic!\n\n", Code); KeHaltSystem(); }