Refine and export kernel debugger printing
This commit is contained in:
23
sdk/xtdk/kdfuncs.h
Normal file
23
sdk/xtdk/kdfuncs.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* PROJECT: ExectOS
|
||||||
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
|
* FILE: sdk/xtdk/kdfuncs.h
|
||||||
|
* DESCRIPTION: XTOS kernel debugger routine definitions
|
||||||
|
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __XTDK_KDFUNCS_H
|
||||||
|
#define __XTDK_KDFUNCS_H
|
||||||
|
|
||||||
|
#include <xtdefs.h>
|
||||||
|
#include <xttypes.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Kernel debugger routines forward references */
|
||||||
|
XTCLINK
|
||||||
|
XTCDECL
|
||||||
|
VOID
|
||||||
|
DbgPrint(PCWSTR Format,
|
||||||
|
...);
|
||||||
|
|
||||||
|
#endif /* __XTDK_KDFUNCS_H */
|
@@ -20,7 +20,7 @@
|
|||||||
/* XTOS platform debugging macros */
|
/* XTOS platform debugging macros */
|
||||||
#ifdef DBG
|
#ifdef DBG
|
||||||
#define DEBUG 1
|
#define DEBUG 1
|
||||||
#define DebugPrint(Format, ...) if(KdPrint) KdPrint(Format, __VA_ARGS__);
|
#define DebugPrint(Format, ...) DbgPrint(Format, __VA_ARGS__);
|
||||||
#else
|
#else
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#define DebugPrint(Format, ...) ((VOID)NULL)
|
#define DebugPrint(Format, ...) ((VOID)NULL)
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
/* XT routines */
|
/* XT routines */
|
||||||
#include <exfuncs.h>
|
#include <exfuncs.h>
|
||||||
#include <hlfuncs.h>
|
#include <hlfuncs.h>
|
||||||
|
#include <kdfuncs.h>
|
||||||
#include <kefuncs.h>
|
#include <kefuncs.h>
|
||||||
#include <rtlfuncs.h>
|
#include <rtlfuncs.h>
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@ list(APPEND XTOSKRNL_SOURCE
|
|||||||
${XTOSKRNL_SOURCE_DIR}/hl/ioreg.cc
|
${XTOSKRNL_SOURCE_DIR}/hl/ioreg.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/kd/data.cc
|
${XTOSKRNL_SOURCE_DIR}/kd/data.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/kd/dbgio.cc
|
${XTOSKRNL_SOURCE_DIR}/kd/dbgio.cc
|
||||||
|
${XTOSKRNL_SOURCE_DIR}/kd/exports.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/irq.cc
|
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/irq.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/krnlinit.cc
|
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/krnlinit.cc
|
||||||
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/kthread.cc
|
${XTOSKRNL_SOURCE_DIR}/ke/${ARCH}/kthread.cc
|
||||||
|
23
xtoskrnl/includes/dbg.hh
Normal file
23
xtoskrnl/includes/dbg.hh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* PROJECT: ExectOS
|
||||||
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
|
* FILE: xtoskrnl/includes/dbg.hh
|
||||||
|
* DESCRIPTION: Kernel debugging support
|
||||||
|
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __XTOSKRNL_DBG_HH
|
||||||
|
#define __XTOSKRNL_DBG_HH
|
||||||
|
|
||||||
|
#include <xtos.hh>
|
||||||
|
|
||||||
|
|
||||||
|
/* Redefine DebugPrint macro for the kernel to enable early debugging */
|
||||||
|
#undef DebugPrint
|
||||||
|
#ifdef DBG
|
||||||
|
#define DebugPrint(Format, ...) if(KD::DebugIo::KdPrint) KD::DebugIo::KdPrint(Format, __VA_ARGS__);
|
||||||
|
#else
|
||||||
|
#define DebugPrint(Format, ...) ((VOID)NULL)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __XTOSKRNL_DBG_HH */
|
@@ -2,7 +2,7 @@
|
|||||||
* PROJECT: ExectOS
|
* PROJECT: ExectOS
|
||||||
* COPYRIGHT: See COPYING.md in the top level directory
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
* FILE: xtoskrnl/includes/kd/dbgio.hh
|
* FILE: xtoskrnl/includes/kd/dbgio.hh
|
||||||
* DESCRIPTION:
|
* DESCRIPTION: Kernel Debugger I/O support
|
||||||
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -17,6 +17,9 @@ namespace KD
|
|||||||
{
|
{
|
||||||
class DebugIo
|
class DebugIo
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
STATIC PKD_PRINT_ROUTINE KdPrint;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
STATIC KD_DEBUG_MODE DebugMode;
|
STATIC KD_DEBUG_MODE DebugMode;
|
||||||
STATIC PKD_INIT_ROUTINE IoProvidersInitRoutines[KDBG_PROVIDERS_COUNT];
|
STATIC PKD_INIT_ROUTINE IoProvidersInitRoutines[KDBG_PROVIDERS_COUNT];
|
||||||
@@ -25,7 +28,10 @@ namespace KD
|
|||||||
STATIC ULONG SerialPortList[COMPORT_COUNT];
|
STATIC ULONG SerialPortList[COMPORT_COUNT];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
STATIC XTCDECL VOID DbgPrint(PCWSTR Format, ...);
|
STATIC XTCDECL VOID DbgPrint(PCWSTR Format,
|
||||||
|
...);
|
||||||
|
STATIC XTCDECL VOID DbgPrintEx(PCWSTR Format,
|
||||||
|
VA_LIST Arguments);
|
||||||
STATIC XTAPI XTSTATUS InitializeDebugIoProviders(VOID);
|
STATIC XTAPI XTSTATUS InitializeDebugIoProviders(VOID);
|
||||||
STATIC XTAPI VOID SetPrintRoutine(PKD_PRINT_ROUTINE DebugPrintRoutine);
|
STATIC XTAPI VOID SetPrintRoutine(PKD_PRINT_ROUTINE DebugPrintRoutine);
|
||||||
|
|
||||||
|
@@ -27,6 +27,7 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
#include <ar.hh>
|
#include <ar.hh>
|
||||||
|
#include <dbg.hh>
|
||||||
#include <ex.hh>
|
#include <ex.hh>
|
||||||
#include <hl.hh>
|
#include <hl.hh>
|
||||||
#include <kd.hh>
|
#include <kd.hh>
|
||||||
|
@@ -9,9 +9,6 @@
|
|||||||
#include <xtos.hh>
|
#include <xtos.hh>
|
||||||
|
|
||||||
|
|
||||||
/* Pointer to DbgPrint() routine */
|
|
||||||
PKD_PRINT_ROUTINE KdPrint = nullptr;
|
|
||||||
|
|
||||||
/* Kernel Debugger mode */
|
/* Kernel Debugger mode */
|
||||||
KD_DEBUG_MODE KD::DebugIo::DebugMode;
|
KD_DEBUG_MODE KD::DebugIo::DebugMode;
|
||||||
|
|
||||||
@@ -21,6 +18,9 @@ PKD_INIT_ROUTINE KD::DebugIo::IoProvidersInitRoutines[KDBG_PROVIDERS_COUNT] = {
|
|||||||
InitializeSerialPortProvider
|
InitializeSerialPortProvider
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Pointer to DbgPrint() routine */
|
||||||
|
PKD_PRINT_ROUTINE KD::DebugIo::KdPrint = nullptr;
|
||||||
|
|
||||||
/* List of active I/O providers */
|
/* List of active I/O providers */
|
||||||
LIST_ENTRY KD::DebugIo::Providers;
|
LIST_ENTRY KD::DebugIo::Providers;
|
||||||
|
|
||||||
|
@@ -24,29 +24,57 @@
|
|||||||
*/
|
*/
|
||||||
XTCDECL
|
XTCDECL
|
||||||
VOID
|
VOID
|
||||||
KD::DebugIo::DbgPrint(PCWSTR Format, ...)
|
KD::DebugIo::DbgPrint(PCWSTR Format,
|
||||||
|
...)
|
||||||
{
|
{
|
||||||
VA_LIST Arguments;
|
VA_LIST Arguments;
|
||||||
PLIST_ENTRY DispatchTableEntry;
|
|
||||||
PKD_DISPATCH_TABLE DispatchTable;
|
|
||||||
|
|
||||||
/* Initialise the va_list */
|
/* Initialise the va_list */
|
||||||
VA_START(Arguments, Format);
|
VA_START(Arguments, Format);
|
||||||
|
|
||||||
DispatchTableEntry = Providers.Flink;
|
/* Call the actual debug print routine */
|
||||||
while(DispatchTableEntry != &Providers)
|
DbgPrintEx(Format, Arguments);
|
||||||
{
|
|
||||||
DispatchTable = CONTAIN_RECORD(DispatchTableEntry, KD_DISPATCH_TABLE, ListEntry);
|
|
||||||
|
|
||||||
RTL::WideString::FormatWideString(&DispatchTable->PrintContext, (PWCHAR)Format, Arguments);
|
|
||||||
|
|
||||||
DispatchTableEntry = DispatchTableEntry->Flink;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Clean up the va_list */
|
/* Clean up the va_list */
|
||||||
VA_END(Arguments);
|
VA_END(Arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints a formatted string using the configured debug output providers (va_list variant).
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
KD::DebugIo::DbgPrintEx(PCWSTR Format,
|
||||||
|
VA_LIST Arguments)
|
||||||
|
{
|
||||||
|
PLIST_ENTRY DispatchTableEntry;
|
||||||
|
PKD_DISPATCH_TABLE DispatchTable;
|
||||||
|
|
||||||
|
/* Iterate over all registered debug providers */
|
||||||
|
DispatchTableEntry = Providers.Flink;
|
||||||
|
while(DispatchTableEntry != &Providers)
|
||||||
|
{
|
||||||
|
/* Get dispatch table */
|
||||||
|
DispatchTable = CONTAIN_RECORD(DispatchTableEntry, KD_DISPATCH_TABLE, ListEntry);
|
||||||
|
|
||||||
|
/* Print formatted string using the provider's print context */
|
||||||
|
RTL::WideString::FormatWideString(&DispatchTable->PrintContext, (PWCHAR)Format, Arguments);
|
||||||
|
|
||||||
|
/* Move to the next provider */
|
||||||
|
DispatchTableEntry = DispatchTableEntry->Flink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detects and enables the kernel's debug ports based on the 'DEBUG' parameter passed to the kernel.
|
* Detects and enables the kernel's debug ports based on the 'DEBUG' parameter passed to the kernel.
|
||||||
*
|
*
|
||||||
|
40
xtoskrnl/kd/exports.cc
Normal file
40
xtoskrnl/kd/exports.cc
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* PROJECT: ExectOS
|
||||||
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
|
* FILE: xtoskrnl/kd/exports.cc
|
||||||
|
* DESCRIPTION: C-compatible API wrappers for exported kernel functions
|
||||||
|
* DEVELOPERS: Aiken Harris <harraiken91@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <xtos.hh>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
XTCLINK
|
||||||
|
XTCDECL
|
||||||
|
VOID
|
||||||
|
DbgPrint(PCWSTR Format,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
VA_LIST Arguments;
|
||||||
|
|
||||||
|
/* Initialise the va_list */
|
||||||
|
VA_START(Arguments, Format);
|
||||||
|
|
||||||
|
KD::DebugIo::DbgPrintEx(Format, Arguments);
|
||||||
|
|
||||||
|
/* Clean up the va_list */
|
||||||
|
VA_END(Arguments);
|
||||||
|
}
|
@@ -76,7 +76,7 @@ KE::Crash::PanicEx(IN ULONG Code,
|
|||||||
IN ULONG_PTR Parameter3,
|
IN ULONG_PTR Parameter3,
|
||||||
IN ULONG_PTR Parameter4)
|
IN ULONG_PTR Parameter4)
|
||||||
{
|
{
|
||||||
KdPrint(L"Fatal System Error: 0x%08lx\nKernel Panic!\n\n", Code);
|
KD::DebugIo::KdPrint(L"Fatal System Error: 0x%08lx\nKernel Panic!\n\n", Code);
|
||||||
HaltSystem();
|
HaltSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
# XTOS kernel exports
|
# XTOS kernel exports
|
||||||
|
@ cdecl DbgPrint(wstr)
|
||||||
@ fastcall ExAcquireRundownProtection(ptr)
|
@ fastcall ExAcquireRundownProtection(ptr)
|
||||||
@ fastcall ExCompleteRundownProtection(ptr)
|
@ fastcall ExCompleteRundownProtection(ptr)
|
||||||
@ fastcall ExInitializeRundownProtection(ptr)
|
@ fastcall ExInitializeRundownProtection(ptr)
|
||||||
|
Reference in New Issue
Block a user