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