- Fix KiDispatchException to unmask KI_EXCEPTION_INTERNAL when setting the exception...
[reactos.git] / reactos / include / reactos / windbgkd.h
1 #ifndef _WINDBGKD_
2 #define _WINDBGKG_
3
4 //
5 // Dependencies
6 //
7 #include "wdbgexts.h"
8
9 //
10 // Conversion Macros
11 //
12 #define COPYSE(p64, p32, f) \
13 p64->f = (ULONG64)(LONG64)(LONG)p32->f
14
15 //
16 // Packet Size and Control Stream Size
17 //
18 #define PACKET_MAX_SIZE 4000
19 #define DBGKD_MAXSTREAM 16
20
21 //
22 // Magic Packet IDs
23 //
24 #define INITIAL_PACKET_ID 0x80800000
25 #define SYNC_PACKET_ID 0x00000800
26
27 //
28 // Magic Packet bytes
29 //
30 #define BREAKIN_PACKET 0x62626262
31 #define BREAKIN_PACKET_BYTE 0x62
32 #define PACKET_LEADER 0x30303030
33 #define PACKET_LEADER_BYTE 0x30
34 #define CONTROL_PACKET_LEADER 0x69696969
35 #define CONTROL_PACKET_LEADER_BYTE 0x69
36 #define PACKET_TRAILING_BYTE 0xAA
37
38 //
39 // Packet Types
40 //
41 #define PACKET_TYPE_UNUSED 0
42 #define PACKET_TYPE_KD_STATE_CHANGE32 1
43 #define PACKET_TYPE_KD_STATE_MANIPULATE 2
44 #define PACKET_TYPE_KD_DEBUG_IO 3
45 #define PACKET_TYPE_KD_ACKNOWLEDGE 4
46 #define PACKET_TYPE_KD_RESEND 5
47 #define PACKET_TYPE_KD_RESET 6
48 #define PACKET_TYPE_KD_STATE_CHANGE64 7
49 #define PACKET_TYPE_KD_POLL_BREAKIN 8
50 #define PACKET_TYPE_KD_TRACE_IO 9
51 #define PACKET_TYPE_KD_CONTROL_REQUEST 10
52 #define PACKET_TYPE_KD_FILE_IO 11
53 #define PACKET_TYPE_MAX 12
54
55 //
56 // Wait State Change Types
57 //
58 #define DbgKdMinimumStateChange 0x00003030
59 #define DbgKdExceptionStateChange 0x00003030
60 #define DbgKdLoadSymbolsStateChange 0x00003031
61 #define DbgKdCommandStringStateChange 0x00003032
62 #define DbgKdMaximumStateChange 0x00003033
63
64 //
65 // Manipulate Types
66 //
67 #define DbgKdMinimumManipulate 0x00003130
68 #define DbgKdReadVirtualMemoryApi 0x00003130
69 #define DbgKdWriteVirtualMemoryApi 0x00003131
70 #define DbgKdGetContextApi 0x00003132
71 #define DbgKdSetContextApi 0x00003133
72 #define DbgKdWriteBreakPointApi 0x00003134
73 #define DbgKdRestoreBreakPointApi 0x00003135
74 #define DbgKdContinueApi 0x00003136
75 #define DbgKdReadControlSpaceApi 0x00003137
76 #define DbgKdWriteControlSpaceApi 0x00003138
77 #define DbgKdReadIoSpaceApi 0x00003139
78 #define DbgKdWriteIoSpaceApi 0x0000313A
79 #define DbgKdRebootApi 0x0000313B
80 #define DbgKdContinueApi2 0x0000313C
81 #define DbgKdReadPhysicalMemoryApi 0x0000313D
82 #define DbgKdWritePhysicalMemoryApi 0x0000313E
83 #define DbgKdQuerySpecialCallsApi 0x0000313F
84 #define DbgKdSetSpecialCallApi 0x00003140
85 #define DbgKdClearSpecialCallsApi 0x00003141
86 #define DbgKdSetInternalBreakPointApi 0x00003142
87 #define DbgKdGetInternalBreakPointApi 0x00003143
88 #define DbgKdReadIoSpaceExtendedApi 0x00003144
89 #define DbgKdWriteIoSpaceExtendedApi 0x00003145
90 #define DbgKdGetVersionApi 0x00003146
91 #define DbgKdWriteBreakPointExApi 0x00003147
92 #define DbgKdRestoreBreakPointExApi 0x00003148
93 #define DbgKdCauseBugCheckApi 0x00003149
94 #define DbgKdSwitchProcessor 0x00003150
95 #define DbgKdPageInApi 0x00003151
96 #define DbgKdReadMachineSpecificRegister 0x00003152
97 #define DbgKdWriteMachineSpecificRegister 0x00003153
98 #define OldVlm1 0x00003154
99 #define OldVlm2 0x00003155
100 #define DbgKdSearchMemoryApi 0x00003156
101 #define DbgKdGetBusDataApi 0x00003157
102 #define DbgKdSetBusDataApi 0x00003158
103 #define DbgKdCheckLowMemoryApi 0x00003159
104 #define DbgKdClearAllInternalBreakpointsApi 0x0000315A
105 #define DbgKdFillMemoryApi 0x0000315B
106 #define DbgKdQueryMemoryApi 0x0000315C
107 #define DbgKdSwitchPartition 0x0000315D
108 #define DbgKdMaximumManipulate 0x0000315E
109
110 //
111 // Debug I/O Types
112 //
113 #define DbgKdPrintStringApi 0x00003230
114 #define DbgKdGetStringApi 0x00003231
115
116 //
117 // Control Report Flags
118 //
119 #define REPORT_INCLUDES_SEGS 0x0001
120 #define REPORT_INCLUDES_CS 0x0002
121
122 //
123 // Protocol Versions
124 //
125 #define DBGKD_64BIT_PROTOCOL_VERSION1 5
126 #define DBGKD_64BIT_PROTOCOL_VERSION2 6
127
128 //
129 // KD Packet Structure
130 //
131 typedef struct _KD_PACKET
132 {
133 ULONG PacketLeader;
134 USHORT PacketType;
135 USHORT ByteCount;
136 ULONG PacketId;
137 ULONG Checksum;
138 } KD_PACKET, *PKD_PACKET;
139
140 //
141 // KD Context
142 //
143 typedef struct _KD_CONTEXT
144 {
145 ULONG KdpDefaultRetries;
146 BOOLEAN KdpControlCPending;
147 } KD_CONTEXT, *PKD_CONTEXT;
148
149 //
150 // Control Sets for Supported Architectures
151 //
152 #include <pshpack4.h>
153 typedef struct _X86_DBGKD_CONTROL_SET
154 {
155 ULONG TraceFlag;
156 ULONG Dr7;
157 ULONG CurrentSymbolStart;
158 ULONG CurrentSymbolEnd;
159 } X86_DBGKD_CONTROL_SET, *PX86_DBGKD_CONTROL_SET;
160
161 typedef struct _IA64_DBGKD_CONTROL_SET
162 {
163 ULONG Continue;
164 ULONG64 CurrentSymbolStart;
165 ULONG64 CurrentSymbolEnd;
166 } IA64_DBGKD_CONTROL_SET, *PIA64_DBGKD_CONTROL_SET;
167
168 typedef struct _AMD64_DBGKD_CONTROL_SET
169 {
170 ULONG TraceFlag;
171 ULONG64 Dr7;
172 ULONG64 CurrentSymbolStart;
173 ULONG64 CurrentSymbolEnd;
174 } AMD64_DBGKD_CONTROL_SET, *PAMD64_DBGKD_CONTROL_SET;
175
176 typedef struct _DBGKD_ANY_CONTROL_SET
177 {
178 union
179 {
180 X86_DBGKD_CONTROL_SET X86ControlSet;
181 IA64_DBGKD_CONTROL_SET IA64ControlSet;
182 AMD64_DBGKD_CONTROL_SET Amd64ControlSet;
183 };
184 } DBGKD_ANY_CONTROL_SET, *PDBGKD_ANY_CONTROL_SET;
185 #include <poppack.h>
186
187 typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET;
188
189 //
190 // DBGKM Structure for Exceptions
191 //
192 typedef struct _DBGKM_EXCEPTION64
193 {
194 EXCEPTION_RECORD64 ExceptionRecord;
195 ULONG FirstChance;
196 } DBGKM_EXCEPTION64, *PDBGKM_EXCEPTION64;
197
198 //
199 // DBGKD Structure for State Change
200 //
201 typedef struct _DBGKD_CONTROL_REPORT
202 {
203 ULONG Dr6;
204 ULONG Dr7;
205 USHORT InstructionCount;
206 USHORT ReportFlags;
207 UCHAR InstructionStream[DBGKD_MAXSTREAM];
208 USHORT SegCs;
209 USHORT SegDs;
210 USHORT SegEs;
211 USHORT SegFs;
212 ULONG EFlags;
213 } DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
214
215 //
216 // DBGKD Structure for Debug I/O Type Print String
217 //
218 typedef struct _DBGKD_PRINT_STRING
219 {
220 ULONG LengthOfString;
221 } DBGKD_PRINT_STRING, *PDBGKD_PRINT_STRING;
222
223 //
224 // DBGKD Structure for Debug I/O Type Get String
225 //
226 typedef struct _DBGKD_GET_STRING
227 {
228 ULONG LengthOfPromptString;
229 ULONG LengthOfStringRead;
230 } DBGKD_GET_STRING, *PDBGKD_GET_STRING;
231
232 //
233 // DBGKD Structure for Debug I/O
234 //
235 typedef struct _DBGKD_DEBUG_IO
236 {
237 ULONG ApiNumber;
238 USHORT ProcessorLevel;
239 USHORT Processor;
240 union
241 {
242 DBGKD_PRINT_STRING PrintString;
243 DBGKD_GET_STRING GetString;
244 } u;
245 } DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;
246
247 //
248 // DBGKD Structure for Load Symbols
249 //
250 typedef struct _DBGKD_LOAD_SYMBOLS64
251 {
252 ULONG PathNameLength;
253 ULONG64 BaseOfDll;
254 ULONG64 ProcessId;
255 ULONG CheckSum;
256 ULONG SizeOfImage;
257 BOOLEAN UnloadSymbols;
258 } DBGKD_LOAD_SYMBOLS64, *PDBGKD_LOAD_SYMBOLS64;
259
260 //
261 // DBGKD Structure for Wait State Change
262 //
263 typedef struct _DBGKD_WAIT_STATE_CHANGE64
264 {
265 ULONG NewState;
266 USHORT ProcessorLevel;
267 USHORT Processor;
268 ULONG NumberProcessors;
269 ULONG64 Thread;
270 ULONG64 ProgramCounter;
271 union
272 {
273 DBGKM_EXCEPTION64 Exception;
274 DBGKD_LOAD_SYMBOLS64 LoadSymbols;
275 } u;
276 DBGKD_CONTROL_REPORT ControlReport;
277 CONTEXT Context;
278 } DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
279
280 //
281 // DBGKD Manipulate Structures
282 //
283 typedef struct _DBGKD_READ_MEMORY64
284 {
285 ULONG64 TargetBaseAddress;
286 ULONG TransferCount;
287 ULONG ActualBytesRead;
288 } DBGKD_READ_MEMORY64, *PDBGKD_READ_MEMORY64;
289
290 typedef struct _DBGKD_WRITE_MEMORY64
291 {
292 ULONG64 TargetBaseAddress;
293 ULONG TransferCount;
294 ULONG ActualBytesWritten;
295 } DBGKD_WRITE_MEMORY64, *PDBGKD_WRITE_MEMORY64;
296
297 typedef struct _DBGKD_GET_CONTEXT
298 {
299 ULONG Unused;
300 } DBGKD_GET_CONTEXT, *PDBGKD_GET_CONTEXT;
301
302 typedef struct _DBGKD_SET_CONTEXT
303 {
304 ULONG ContextFlags;
305 } DBGKD_SET_CONTEXT, *PDBGKD_SET_CONTEXT;
306
307 typedef struct _DBGKD_WRITE_BREAKPOINT64
308 {
309 ULONG64 BreakPointAddress;
310 ULONG BreakPointHandle;
311 } DBGKD_WRITE_BREAKPOINT64, *PDBGKD_WRITE_BREAKPOINT64;
312
313 typedef struct _DBGKD_RESTORE_BREAKPOINT
314 {
315 ULONG BreakPointHandle;
316 } DBGKD_RESTORE_BREAKPOINT, *PDBGKD_RESTORE_BREAKPOINT;
317
318 typedef struct _DBGKD_CONTINUE
319 {
320 NTSTATUS ContinueStatus;
321 } DBGKD_CONTINUE, *PDBGKD_CONTINUE;
322
323 #include <pshpack4.h>
324 typedef struct _DBGKD_CONTINUE2
325 {
326 NTSTATUS ContinueStatus;
327 union
328 {
329 DBGKD_CONTROL_SET ControlSet;
330 DBGKD_ANY_CONTROL_SET AnyControlSet;
331 };
332 } DBGKD_CONTINUE2, *PDBGKD_CONTINUE2;
333 #include <poppack.h>
334
335 typedef struct _DBGKD_READ_WRITE_IO64
336 {
337 ULONG64 IoAddress;
338 ULONG DataSize;
339 ULONG DataValue;
340 } DBGKD_READ_WRITE_IO64, *PDBGKD_READ_WRITE_IO64;
341
342 typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
343 {
344 ULONG DataSize;
345 ULONG InterfaceType;
346 ULONG BusNumber;
347 ULONG AddressSpace;
348 ULONG64 IoAddress;
349 ULONG DataValue;
350 } DBGKD_READ_WRITE_IO_EXTENDED64, *PDBGKD_READ_WRITE_IO_EXTENDED64;
351
352 typedef struct _DBGKD_READ_WRITE_MSR
353 {
354 ULONG Msr;
355 ULONG DataValueLow;
356 ULONG DataValueHigh;
357 } DBGKD_READ_WRITE_MSR, *PDBGKD_READ_WRITE_MSR;
358
359 typedef struct _DBGKD_QUERY_SPECIAL_CALLS
360 {
361 ULONG NumberOfSpecialCalls;
362 } DBGKD_QUERY_SPECIAL_CALLS, *PDBGKD_QUERY_SPECIAL_CALLS;
363
364 typedef struct _DBGKD_SET_SPECIAL_CALL64
365 {
366 ULONG64 SpecialCall;
367 } DBGKD_SET_SPECIAL_CALL64, *PDBGKD_SET_SPECIAL_CALL64;
368
369 typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
370 {
371 ULONG64 BreakpointAddress;
372 ULONG Flags;
373 } DBGKD_SET_INTERNAL_BREAKPOINT64, *PDBGKD_SET_INTERNAL_BREAKPOINT64;
374
375 typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
376 {
377 ULONG64 BreakpointAddress;
378 ULONG Flags;
379 ULONG Calls;
380 ULONG MaxCallsPerPeriod;
381 ULONG MinInstructions;
382 ULONG MaxInstructions;
383 ULONG TotalInstructions;
384 } DBGKD_GET_INTERNAL_BREAKPOINT64, *PDBGKD_GET_INTERNAL_BREAKPOINT64;
385
386 typedef struct _DBGKD_BREAKPOINTEX
387 {
388 ULONG BreakPointCount;
389 NTSTATUS ContinueStatus;
390 } DBGKD_BREAKPOINTEX, *PDBGKD_BREAKPOINTEX;
391
392 typedef struct _DBGKD_SEARCH_MEMORY
393 {
394 union
395 {
396 ULONG64 SearchAddress;
397 ULONG64 FoundAddress;
398 };
399 ULONG64 SearchLength;
400 ULONG PatternLength;
401 } DBGKD_SEARCH_MEMORY, *PDBGKD_SEARCH_MEMORY;
402
403 typedef struct _DBGKD_GET_SET_BUS_DATA
404 {
405 ULONG BusDataType;
406 ULONG BusNumber;
407 ULONG SlotNumber;
408 ULONG Offset;
409 ULONG Length;
410 } DBGKD_GET_SET_BUS_DATA, *PDBGKD_GET_SET_BUS_DATA;
411
412 typedef struct _DBGKD_FILL_MEMORY
413 {
414 ULONG64 Address;
415 ULONG Length;
416 USHORT Flags;
417 USHORT PatternLength;
418 } DBGKD_FILL_MEMORY, *PDBGKD_FILL_MEMORY;
419
420 typedef struct _DBGKD_QUERY_MEMORY
421 {
422 ULONG64 Address;
423 ULONG64 Reserved;
424 ULONG AddressSpace;
425 ULONG Flags;
426 } DBGKD_QUERY_MEMORY, *PDBGKD_QUERY_MEMORY;
427
428 typedef struct _DBGKD_SWITCH_PARTITION
429 {
430 ULONG Partition;
431 } DBGKD_SWITCH_PARTITION;
432
433 //
434 // DBGKD Structure for Manipulate
435 //
436 typedef struct _DBGKD_MANIPULATE_STATE64
437 {
438 ULONG ApiNumber;
439 USHORT ProcessorLevel;
440 USHORT Processor;
441 NTSTATUS ReturnStatus;
442 union
443 {
444 DBGKD_READ_MEMORY64 ReadMemory;
445 DBGKD_WRITE_MEMORY64 WriteMemory;
446 DBGKD_GET_CONTEXT GetContext;
447 DBGKD_SET_CONTEXT SetContext;
448 DBGKD_WRITE_BREAKPOINT64 WriteBreakPoint;
449 DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint;
450 DBGKD_CONTINUE Continue;
451 DBGKD_CONTINUE2 Continue2;
452 DBGKD_READ_WRITE_IO64 ReadWriteIo;
453 DBGKD_READ_WRITE_IO_EXTENDED64 ReadWriteIoExtended;
454 DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls;
455 DBGKD_SET_SPECIAL_CALL64 SetSpecialCall;
456 DBGKD_SET_INTERNAL_BREAKPOINT64 SetInternalBreakpoint;
457 DBGKD_GET_INTERNAL_BREAKPOINT64 GetInternalBreakpoint;
458 DBGKD_GET_VERSION64 GetVersion64;
459 DBGKD_BREAKPOINTEX BreakPointEx;
460 DBGKD_READ_WRITE_MSR ReadWriteMsr;
461 DBGKD_SEARCH_MEMORY SearchMemory;
462 DBGKD_GET_SET_BUS_DATA GetSetBusData;
463 DBGKD_FILL_MEMORY FillMemory;
464 DBGKD_QUERY_MEMORY QueryMemory;
465 DBGKD_SWITCH_PARTITION SwitchPartition;
466 } u;
467 } DBGKD_MANIPULATE_STATE64, *PDBGKD_MANIPULATE_STATE64;
468
469 FORCEINLINE
470 VOID
471 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
472 OUT PEXCEPTION_RECORD64 Ex64)
473 {
474 ULONG i;
475
476 Ex64->ExceptionCode = Ex32->ExceptionCode;
477 Ex64->ExceptionFlags = Ex32->ExceptionFlags;
478 Ex64->ExceptionRecord = Ex32->ExceptionRecord;
479 COPYSE(Ex64,Ex32,ExceptionAddress);
480 Ex64->NumberParameters = Ex32->NumberParameters;
481
482 for (i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
483 {
484 COPYSE(Ex64,Ex32,ExceptionInformation[i]);
485 }
486 }
487
488 #endif