d3daabfeb7c283a98ca571886ca52ccf43ffe8fa
[reactos.git] / ntoskrnl / include / internal / kd.h
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 LPSTR String,
197 ULONG Length);
198
199 ULONG
200 NTAPI
201 KdpPrompt(
202 IN LPSTR InString,
203 IN USHORT InStringLength,
204 OUT LPSTR OutString,
205 IN USHORT OutStringLength
206 );
207
208 BOOLEAN
209 NTAPI
210 KdpDetectConflicts(PCM_RESOURCE_LIST DriverList);
211
212 VOID
213 NTAPI
214 KdpBochsDebugPrint(
215 IN PCH Message,
216 IN ULONG Length
217 );
218
219 BOOLEAN
220 NTAPI
221 KdpSafeReadMemory(
222 IN ULONG_PTR Addr,
223 IN LONG Len,
224 OUT PVOID Value
225 );
226
227 BOOLEAN
228 NTAPI
229 KdpSafeWriteMemory(
230 IN ULONG_PTR Addr,
231 IN LONG Len,
232 IN ULONGLONG Value
233 );
234
235 VOID
236 NTAPI
237 KdpEnableSafeMem(VOID);
238
239
240 /* KD GLOBALS ***************************************************************/
241
242 typedef
243 BOOLEAN
244 (NTAPI *PKDEBUG_ROUTINE)(
245 IN PKTRAP_FRAME TrapFrame,
246 IN PKEXCEPTION_FRAME ExceptionFrame,
247 IN PEXCEPTION_RECORD ExceptionRecord,
248 IN PCONTEXT Context,
249 IN KPROCESSOR_MODE PreviousMode,
250 IN BOOLEAN SecondChance
251 );
252
253 /* serial debug connection */
254 #define DEFAULT_DEBUG_PORT 2 /* COM2 */
255 #define DEFAULT_DEBUG_COM1_IRQ 4 /* COM1 IRQ */
256 #define DEFAULT_DEBUG_COM2_IRQ 3 /* COM2 IRQ */
257 #define DEFAULT_DEBUG_BAUD_RATE 115200 /* 115200 Baud */
258
259 /* KD Native Modes */
260 #define KdScreen 0
261 #define KdSerial 1
262 #define KdFile 2
263 #define KdBochs 3
264 #define KdKdbg 4
265 #define KdMax 5
266
267 /* KD Private Debug Modes */
268 typedef struct _KDP_DEBUG_MODE
269 {
270 union
271 {
272 struct
273 {
274 /* Native Modes */
275 UCHAR Screen :1;
276 UCHAR Serial :1;
277 UCHAR File :1;
278 UCHAR Bochs :1;
279
280 /* Currently Supported Wrappers */
281 UCHAR Pice :1;
282 UCHAR Gdb :1;
283 };
284
285 /* Generic Value */
286 ULONG Value;
287 };
288 }
289 KDP_DEBUG_MODE;
290
291 /* KD Internal Debug Services */
292 typedef enum _KDP_DEBUG_SERVICE
293 {
294 DumpNonPagedPool = 0x1e, /* a */
295 ManualBugCheck = 0x30, /* b */
296 DumpNonPagedPoolStats = 0x2e, /* c */
297 DumpNewNonPagedPool = 0x20, /* d */
298 DumpNewNonPagedPoolStats = 0x12, /* e */
299 DumpAllThreads = 0x21, /* f */
300 DumpUserThreads = 0x22, /* g */
301 KdSpare1 = 0x23, /* h */
302 KdSpare2 = 0x17, /* i */
303 KdSpare3 = 0x24, /* j */
304 EnterDebugger = 0x25, /* k */
305 ThatsWhatSheSaid = 69 /* FIGURE IT OUT */
306 }
307 KDP_DEBUG_SERVICE;
308
309 /* Dispatch Table for Wrapper Functions */
310 typedef struct _KD_DISPATCH_TABLE
311 {
312 LIST_ENTRY KdProvidersList;
313 PKDP_INIT_ROUTINE KdpInitRoutine;
314 PKDP_PRINT_ROUTINE KdpPrintRoutine;
315 PKDP_PROMPT_ROUTINE KdpPromptRoutine;
316 PKDP_EXCEPTION_ROUTINE KdpExceptionRoutine;
317 }
318 KD_DISPATCH_TABLE, *PKD_DISPATCH_TABLE;
319
320 /* The current Debugging Mode */
321 extern KDP_DEBUG_MODE KdpDebugMode;
322
323 /* The current Port IRQ */
324 extern ULONG KdpPortIrq;
325
326 /* The current Port */
327 extern ULONG KdpPort;
328
329 /* Port Information for the Serial Native Mode */
330 extern ULONG SerialPortNumber;
331 extern CPPORT SerialPortInfo;
332
333 /* Init Functions for Native Providers */
334 extern PKDP_INIT_ROUTINE InitRoutines[KdMax];
335
336 /* Wrapper Init Function */
337 extern PKDP_INIT_ROUTINE WrapperInitRoutine;
338
339 /* Dispatch Tables for Native Providers */
340 extern KD_DISPATCH_TABLE DispatchTable[KdMax];
341
342 /* Dispatch Table for the Wrapper */
343 extern KD_DISPATCH_TABLE WrapperTable;
344
345 /* The KD Native Provider List */
346 extern LIST_ENTRY KdProviders;
347
348 /* Whether to enter KDB as early as possible or not */
349 extern BOOLEAN KdpEarlyBreak;
350
351 extern PKDEBUG_ROUTINE KiDebugRoutine;
352 extern KD_CONTEXT KdpContext;
353 extern ULONG Kd_WIN2000_Mask;
354
355 #endif
356
357 #if DBG && defined(_M_IX86) && !defined(_WINKD_) // See ke/i386/traphdlr.c
358 #define ID_Win32PreServiceHook 'WSH0'
359 #define ID_Win32PostServiceHook 'WSH1'
360 typedef void (NTAPI *PKDBG_PRESERVICEHOOK)(ULONG, PULONG_PTR);
361 typedef ULONG_PTR (NTAPI *PKDBG_POSTSERVICEHOOK)(ULONG, ULONG_PTR);
362 extern PKDBG_PRESERVICEHOOK KeWin32PreServiceHook;
363 extern PKDBG_POSTSERVICEHOOK KeWin32PostServiceHook;
364 #endif