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