1 #pragma once 2 3 #include <cportlib/cportlib.h> 4 5 // 6 // Kernel Debugger Port Definition 7 // 8 struct _KD_DISPATCH_TABLE; 9 extern CPPORT GdbPortInfo; 10 11 BOOLEAN 12 NTAPI 13 KdPortInitializeEx( 14 PCPPORT PortInformation, 15 ULONG ComPortNumber 16 ); 17 18 BOOLEAN 19 NTAPI 20 KdPortGetByteEx( 21 PCPPORT PortInformation, 22 PUCHAR ByteReceived); 23 24 VOID 25 NTAPI 26 KdPortPutByteEx( 27 PCPPORT PortInformation, 28 UCHAR ByteToSend 29 ); 30 31 /* SYMBOL ROUTINES **********************************************************/ 32 #ifdef __NTOSKRNL__ 33 34 #if defined(KDBG) || DBG 35 36 #if defined(KDBG) 37 typedef 38 BOOLEAN 39 (NTAPI *PKDBG_CLI_ROUTINE)( 40 IN PCHAR Command, 41 IN ULONG Argc, 42 IN PCH Argv[]); 43 44 BOOLEAN 45 NTAPI 46 KdbRegisterCliCallback( 47 PVOID Callback, 48 BOOLEAN Deregister); 49 #endif 50 51 VOID 52 KdbSymProcessSymbols( 53 IN PLDR_DATA_TABLE_ENTRY LdrEntry); 54 55 56 BOOLEAN 57 KdbSymPrintAddress( 58 IN PVOID Address, 59 IN PKTRAP_FRAME Context 60 ); 61 62 NTSTATUS 63 KdbSymGetAddressInformation( 64 IN PROSSYM_INFO RosSymInfo, 65 IN ULONG_PTR RelativeAddress, 66 #ifdef __ROS_DWARF__ 67 IN PROSSYM_LINEINFO RosSymLineInfo 68 #else 69 OUT PULONG LineNumber OPTIONAL, 70 OUT PCH FileName OPTIONAL, 71 OUT PCH FunctionName OPTIONAL 72 #endif 73 ); 74 #endif 75 76 #ifdef KDBG 77 # define KdbInit() KdbpCliInit() 78 # define KdbModuleLoaded(FILENAME) KdbpCliModuleLoaded(FILENAME) 79 #else 80 # define KdbEnterDebuggerException(ER, PM, C, TF, F) kdHandleException 81 # define KdbInit() do { } while (0) 82 # define KdbEnter() do { } while (0) 83 # define KdbModuleLoaded(X) do { } while (0) 84 #endif 85 86 /* KD ROUTINES ***************************************************************/ 87 88 typedef enum _KD_CONTINUE_TYPE 89 { 90 kdContinue = 0, 91 kdDoNotHandleException, 92 kdHandleException 93 } KD_CONTINUE_TYPE; 94 95 typedef 96 VOID 97 (NTAPI*PKDP_INIT_ROUTINE)( 98 struct _KD_DISPATCH_TABLE *DispatchTable, 99 ULONG BootPhase 100 ); 101 102 typedef 103 VOID 104 (NTAPI*PKDP_PRINT_ROUTINE)( 105 PCHAR String, 106 ULONG Length 107 ); 108 109 typedef 110 VOID 111 (NTAPI*PKDP_PROMPT_ROUTINE)(PCH String); 112 113 typedef 114 KD_CONTINUE_TYPE 115 (NTAPI*PKDP_EXCEPTION_ROUTINE)( 116 PEXCEPTION_RECORD ExceptionRecord, 117 PCONTEXT Context, 118 PKTRAP_FRAME TrapFrame 119 ); 120 121 /* INIT ROUTINES *************************************************************/ 122 123 BOOLEAN 124 NTAPI 125 KdInitSystem( 126 ULONG Reserved, 127 PLOADER_PARAMETER_BLOCK LoaderBlock 128 ); 129 130 VOID 131 KdpScreenAcquire(VOID); 132 133 VOID 134 KdpScreenRelease(VOID); 135 136 VOID 137 NTAPI 138 KdpScreenInit( 139 struct _KD_DISPATCH_TABLE *DispatchTable, 140 ULONG BootPhase 141 ); 142 143 VOID 144 NTAPI 145 KdpSerialInit( 146 struct _KD_DISPATCH_TABLE *DispatchTable, 147 ULONG BootPhase 148 ); 149 150 VOID 151 NTAPI 152 KdpDebugLogInit( 153 struct _KD_DISPATCH_TABLE *DispatchTable, 154 ULONG BootPhase 155 ); 156 157 VOID 158 NTAPI 159 KdpBochsInit( 160 struct _KD_DISPATCH_TABLE *DispatchTable, 161 ULONG BootPhase 162 ); 163 164 VOID 165 NTAPI 166 KdpGdbStubInit( 167 struct _KD_DISPATCH_TABLE *DispatchTable, 168 ULONG BootPhase); 169 170 VOID 171 NTAPI 172 KdpKdbgInit( 173 struct _KD_DISPATCH_TABLE *DispatchTable, 174 ULONG BootPhase); 175 176 177 /* KD ROUTINES ***************************************************************/ 178 179 BOOLEAN 180 NTAPI 181 KdpDetectConflicts(PCM_RESOURCE_LIST DriverList); 182 183 BOOLEAN 184 NTAPI 185 KdpSafeReadMemory( 186 IN ULONG_PTR Addr, 187 IN LONG Len, 188 OUT PVOID Value 189 ); 190 191 BOOLEAN 192 NTAPI 193 KdpSafeWriteMemory( 194 IN ULONG_PTR Addr, 195 IN LONG Len, 196 IN ULONGLONG Value 197 ); 198 199 200 /* KD GLOBALS ***************************************************************/ 201 202 /* Serial debug connection */ 203 #define DEFAULT_DEBUG_PORT 2 /* COM2 */ 204 #define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */ 205 #define DEFAULT_DEBUG_COM2_IRQ 3 /* COM2 IRQ */ 206 #define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */ 207 208 /* KD Native Modes */ 209 #define KdScreen 0 210 #define KdSerial 1 211 #define KdFile 2 212 #define KdBochs 3 213 #define KdKdbg 4 214 #define KdMax 5 215 216 /* KD Private Debug Modes */ 217 typedef struct _KDP_DEBUG_MODE 218 { 219 union 220 { 221 struct 222 { 223 /* Native Modes */ 224 UCHAR Screen :1; 225 UCHAR Serial :1; 226 UCHAR File :1; 227 UCHAR Bochs :1; 228 229 /* Currently Supported Wrappers */ 230 UCHAR Pice :1; 231 UCHAR Gdb :1; 232 }; 233 234 /* Generic Value */ 235 ULONG Value; 236 }; 237 } KDP_DEBUG_MODE; 238 239 /* KD Internal Debug Services */ 240 typedef enum _KDP_DEBUG_SERVICE 241 { 242 DumpNonPagedPool = 0x1e, /* a */ 243 ManualBugCheck = 0x30, /* b */ 244 DumpNonPagedPoolStats = 0x2e, /* c */ 245 DumpNewNonPagedPool = 0x20, /* d */ 246 DumpNewNonPagedPoolStats = 0x12, /* e */ 247 DumpAllThreads = 0x21, /* f */ 248 DumpUserThreads = 0x22, /* g */ 249 KdSpare1 = 0x23, /* h */ 250 KdSpare2 = 0x17, /* i */ 251 KdSpare3 = 0x24, /* j */ 252 EnterDebugger = 0x25, /* k */ 253 ThatsWhatSheSaid = 69 /* FIGURE IT OUT */ 254 } KDP_DEBUG_SERVICE; 255 256 /* Dispatch Table for Wrapper Functions */ 257 typedef struct _KD_DISPATCH_TABLE 258 { 259 LIST_ENTRY KdProvidersList; 260 PKDP_INIT_ROUTINE KdpInitRoutine; 261 PKDP_PRINT_ROUTINE KdpPrintRoutine; 262 PKDP_PROMPT_ROUTINE KdpPromptRoutine; 263 PKDP_EXCEPTION_ROUTINE KdpExceptionRoutine; 264 } KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE; 265 266 /* The current Debugging Mode */ 267 extern KDP_DEBUG_MODE KdpDebugMode; 268 269 /* The current Port IRQ */ 270 extern ULONG KdpPortIrq; 271 272 /* The current Port */ 273 extern ULONG KdpPort; 274 275 /* Port Information for the Serial Native Mode */ 276 extern ULONG SerialPortNumber; 277 extern CPPORT SerialPortInfo; 278 279 /* Init Functions for Native Providers */ 280 extern PKDP_INIT_ROUTINE InitRoutines[KdMax]; 281 282 /* Wrapper Init Function */ 283 extern PKDP_INIT_ROUTINE WrapperInitRoutine; 284 285 /* Dispatch Tables for Native Providers */ 286 extern KD_DISPATCH_TABLE DispatchTable[KdMax]; 287 288 /* Dispatch Table for the Wrapper */ 289 extern KD_DISPATCH_TABLE WrapperTable; 290 291 /* The KD Native Provider List */ 292 extern LIST_ENTRY KdProviders; 293 294 #endif 295 296 #if DBG && defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c 297 #define ID_Win32PreServiceHook 'WSH0' 298 #define ID_Win32PostServiceHook 'WSH1' 299 typedef void (NTAPI *PKDBG_PRESERVICEHOOK)(ULONG, PULONG_PTR); 300 typedef ULONG_PTR (NTAPI *PKDBG_POSTSERVICEHOOK)(ULONG, ULONG_PTR); 301 extern PKDBG_PRESERVICEHOOK KeWin32PreServiceHook; 302 extern PKDBG_POSTSERVICEHOOK KeWin32PostServiceHook; 303 #endif 304