1 #pragma once 2 3 #include <cportlib/cportlib.h> 4 5 // 6 // Kernel Debugger Port Definition 7 // 8 struct _KD_DISPATCH_TABLE; 9 10 BOOLEAN 11 NTAPI 12 KdPortInitializeEx( 13 PCPPORT PortInformation, 14 ULONG ComPortNumber 15 ); 16 17 BOOLEAN 18 NTAPI 19 KdPortGetByteEx( 20 PCPPORT PortInformation, 21 PUCHAR ByteReceived); 22 23 VOID 24 NTAPI 25 KdPortPutByteEx( 26 PCPPORT PortInformation, 27 UCHAR ByteToSend 28 ); 29 30 /* SYMBOL ROUTINES **********************************************************/ 31 #ifdef __NTOSKRNL__ 32 33 #ifdef KDBG 34 # define KdbInit() KdbpCliInit() 35 # define KdbModuleLoaded(FILENAME) KdbpCliModuleLoaded(FILENAME) 36 #else 37 # define KdbInit() do { } while (0) 38 # define KdbEnter() do { } while (0) 39 # define KdbModuleLoaded(X) do { } while (0) 40 #endif 41 42 /* KD ROUTINES ***************************************************************/ 43 44 typedef enum _KD_CONTINUE_TYPE 45 { 46 kdContinue = 0, 47 kdDoNotHandleException, 48 kdHandleException 49 } KD_CONTINUE_TYPE; 50 51 typedef 52 VOID 53 (NTAPI*PKDP_INIT_ROUTINE)( 54 struct _KD_DISPATCH_TABLE *DispatchTable, 55 ULONG BootPhase 56 ); 57 58 typedef 59 VOID 60 (NTAPI*PKDP_PRINT_ROUTINE)( 61 PCHAR String, 62 ULONG Length 63 ); 64 65 /* INIT ROUTINES *************************************************************/ 66 67 BOOLEAN 68 NTAPI 69 KdInitSystem( 70 ULONG Reserved, 71 PLOADER_PARAMETER_BLOCK LoaderBlock 72 ); 73 74 VOID 75 KdpScreenAcquire(VOID); 76 77 VOID 78 KdpScreenRelease(VOID); 79 80 VOID 81 NTAPI 82 KdpScreenInit( 83 struct _KD_DISPATCH_TABLE *DispatchTable, 84 ULONG BootPhase 85 ); 86 87 VOID 88 NTAPI 89 KdpSerialInit( 90 struct _KD_DISPATCH_TABLE *DispatchTable, 91 ULONG BootPhase 92 ); 93 94 VOID 95 NTAPI 96 KdpDebugLogInit( 97 struct _KD_DISPATCH_TABLE *DispatchTable, 98 ULONG BootPhase 99 ); 100 101 VOID 102 NTAPI 103 KdpKdbgInit( 104 struct _KD_DISPATCH_TABLE *DispatchTable, 105 ULONG BootPhase); 106 107 108 /* KD ROUTINES ***************************************************************/ 109 110 BOOLEAN 111 NTAPI 112 KdpDetectConflicts(PCM_RESOURCE_LIST DriverList); 113 114 BOOLEAN 115 NTAPI 116 KdpSafeReadMemory( 117 IN ULONG_PTR Addr, 118 IN LONG Len, 119 OUT PVOID Value 120 ); 121 122 BOOLEAN 123 NTAPI 124 KdpSafeWriteMemory( 125 IN ULONG_PTR Addr, 126 IN LONG Len, 127 IN ULONGLONG Value 128 ); 129 130 131 /* KD GLOBALS ***************************************************************/ 132 133 /* Serial debug connection */ 134 #define DEFAULT_DEBUG_PORT 2 /* COM2 */ 135 #define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */ 136 #define DEFAULT_DEBUG_COM2_IRQ 3 /* COM2 IRQ */ 137 #define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */ 138 139 /* KD Native Modes */ 140 #define KdScreen 0 141 #define KdSerial 1 142 #define KdFile 2 143 #define KdKdbg 3 144 #define KdMax 4 145 146 /* KD Private Debug Modes */ 147 typedef struct _KDP_DEBUG_MODE 148 { 149 union 150 { 151 struct 152 { 153 /* Native Modes */ 154 UCHAR Screen :1; 155 UCHAR Serial :1; 156 UCHAR File :1; 157 }; 158 159 /* Generic Value */ 160 ULONG Value; 161 }; 162 } KDP_DEBUG_MODE; 163 164 /* KD Internal Debug Services */ 165 typedef enum _KDP_DEBUG_SERVICE 166 { 167 DumpNonPagedPool = 0x1e, /* a */ 168 ManualBugCheck = 0x30, /* b */ 169 DumpNonPagedPoolStats = 0x2e, /* c */ 170 DumpNewNonPagedPool = 0x20, /* d */ 171 DumpNewNonPagedPoolStats = 0x12, /* e */ 172 DumpAllThreads = 0x21, /* f */ 173 DumpUserThreads = 0x22, /* g */ 174 KdSpare1 = 0x23, /* h */ 175 KdSpare2 = 0x17, /* i */ 176 KdSpare3 = 0x24, /* j */ 177 EnterDebugger = 0x25, /* k */ 178 ThatsWhatSheSaid = 69 /* FIGURE IT OUT */ 179 } KDP_DEBUG_SERVICE; 180 181 /* Dispatch Table for Wrapper Functions */ 182 typedef struct _KD_DISPATCH_TABLE 183 { 184 LIST_ENTRY KdProvidersList; 185 PKDP_INIT_ROUTINE KdpInitRoutine; 186 PKDP_PRINT_ROUTINE KdpPrintRoutine; 187 } KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE; 188 189 /* The current Debugging Mode */ 190 extern KDP_DEBUG_MODE KdpDebugMode; 191 192 /* Port Information for the Serial Native Mode */ 193 extern ULONG SerialPortNumber; 194 extern CPPORT SerialPortInfo; 195 196 /* Init Functions for Native Providers */ 197 extern PKDP_INIT_ROUTINE InitRoutines[KdMax]; 198 199 /* Dispatch Tables for Native Providers */ 200 extern KD_DISPATCH_TABLE DispatchTable[KdMax]; 201 202 /* The KD Native Provider List */ 203 extern LIST_ENTRY KdProviders; 204 205 #endif 206 207 #if DBG && defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c 208 #define ID_Win32PreServiceHook 'WSH0' 209 #define ID_Win32PostServiceHook 'WSH1' 210 typedef void (NTAPI *PKDBG_PRESERVICEHOOK)(ULONG, PULONG_PTR); 211 typedef ULONG_PTR (NTAPI *PKDBG_POSTSERVICEHOOK)(ULONG, ULONG_PTR); 212 extern PKDBG_PRESERVICEHOOK KeWin32PreServiceHook; 213 extern PKDBG_POSTSERVICEHOOK KeWin32PostServiceHook; 214 #endif 215