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