xref: /reactos/sdk/include/reactos/windbgkd.h (revision 4363e74d)
1 #ifndef _WINDBGKD_
2 #define _WINDBGKD_
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 // This is combined with the basic state change code
66 // if the state is from an alternate source
67 //
68 #define DbgKdAlternateStateChange           0x00010000
69 
70 //
71 // Manipulate Types
72 //
73 #define DbgKdMinimumManipulate              0x00003130
74 #define DbgKdReadVirtualMemoryApi           0x00003130
75 #define DbgKdWriteVirtualMemoryApi          0x00003131
76 #define DbgKdGetContextApi                  0x00003132
77 #define DbgKdSetContextApi                  0x00003133
78 #define DbgKdWriteBreakPointApi             0x00003134
79 #define DbgKdRestoreBreakPointApi           0x00003135
80 #define DbgKdContinueApi                    0x00003136
81 #define DbgKdReadControlSpaceApi            0x00003137
82 #define DbgKdWriteControlSpaceApi           0x00003138
83 #define DbgKdReadIoSpaceApi                 0x00003139
84 #define DbgKdWriteIoSpaceApi                0x0000313A
85 #define DbgKdRebootApi                      0x0000313B
86 #define DbgKdContinueApi2                   0x0000313C
87 #define DbgKdReadPhysicalMemoryApi          0x0000313D
88 #define DbgKdWritePhysicalMemoryApi         0x0000313E
89 #define DbgKdQuerySpecialCallsApi           0x0000313F
90 #define DbgKdSetSpecialCallApi              0x00003140
91 #define DbgKdClearSpecialCallsApi           0x00003141
92 #define DbgKdSetInternalBreakPointApi       0x00003142
93 #define DbgKdGetInternalBreakPointApi       0x00003143
94 #define DbgKdReadIoSpaceExtendedApi         0x00003144
95 #define DbgKdWriteIoSpaceExtendedApi        0x00003145
96 #define DbgKdGetVersionApi                  0x00003146
97 #define DbgKdWriteBreakPointExApi           0x00003147
98 #define DbgKdRestoreBreakPointExApi         0x00003148
99 #define DbgKdCauseBugCheckApi               0x00003149
100 #define DbgKdSwitchProcessor                0x00003150
101 #define DbgKdPageInApi                      0x00003151
102 #define DbgKdReadMachineSpecificRegister    0x00003152
103 #define DbgKdWriteMachineSpecificRegister   0x00003153
104 #define OldVlm1                             0x00003154
105 #define OldVlm2                             0x00003155
106 #define DbgKdSearchMemoryApi                0x00003156
107 #define DbgKdGetBusDataApi                  0x00003157
108 #define DbgKdSetBusDataApi                  0x00003158
109 #define DbgKdCheckLowMemoryApi              0x00003159
110 #define DbgKdClearAllInternalBreakpointsApi 0x0000315A
111 #define DbgKdFillMemoryApi                  0x0000315B
112 #define DbgKdQueryMemoryApi                 0x0000315C
113 #define DbgKdSwitchPartition                0x0000315D
114 #define DbgKdWriteCustomBreakpointApi       0x0000315E
115 #define DbgKdGetContextExApi                0x0000315F
116 #define DbgKdSetContextExApi                0x00003160
117 #define DbgKdMaximumManipulate              0x00003161
118 
119 //
120 // Debug I/O Types
121 //
122 #define DbgKdPrintStringApi                 0x00003230
123 #define DbgKdGetStringApi                   0x00003231
124 
125 //
126 // Trace I/O Types
127 //
128 #define DbgKdPrintTraceApi                  0x00003330
129 
130 //
131 // Control Request Types
132 //
133 #define DbgKdRequestHardwareBp              0x00004300
134 #define DbgKdReleaseHardwareBp              0x00004301
135 
136 //
137 // File I/O Types
138 //
139 #define DbgKdCreateFileApi                 0x00003430
140 #define DbgKdReadFileApi                   0x00003431
141 #define DbgKdWriteFileApi                  0x00003432
142 #define DbgKdCloseFileApi                  0x00003433
143 
144 //
145 // Control Report Flags
146 //
147 #define REPORT_INCLUDES_SEGS                0x0001
148 #define REPORT_STANDARD_CS                  0x0002
149 
150 //
151 // Protocol Versions
152 //
153 #define DBGKD_64BIT_PROTOCOL_VERSION1       5
154 #define DBGKD_64BIT_PROTOCOL_VERSION2       6
155 
156 //
157 // Query Memory Address Spaces
158 //
159 #define DBGKD_QUERY_MEMORY_VIRTUAL          0
160 #define DBGKD_QUERY_MEMORY_PROCESS          0
161 #define DBGKD_QUERY_MEMORY_SESSION          1
162 #define DBGKD_QUERY_MEMORY_KERNEL           2
163 
164 //
165 // Query Memory Flags
166 //
167 #define DBGKD_QUERY_MEMORY_READ             0x01
168 #define DBGKD_QUERY_MEMORY_WRITE            0x02
169 #define DBGKD_QUERY_MEMORY_EXECUTE          0x04
170 #define DBGKD_QUERY_MEMORY_FIXED            0x08
171 
172 //
173 // Internal Breakpoint Flags
174 //
175 #define DBGKD_INTERNAL_BP_FLAG_COUNTONLY    0x01
176 #define DBGKD_INTERNAL_BP_FLAG_INVALID      0x02
177 #define DBGKD_INTERNAL_BP_FLAG_SUSPENDED    0x04
178 #define DBGKD_INTERNAL_BP_FLAG_DYING        0x08
179 
180 //
181 // Fill Memory Flags
182 //
183 #define DBGKD_FILL_MEMORY_VIRTUAL           0x01
184 #define DBGKD_FILL_MEMORY_PHYSICAL          0x02
185 
186 //
187 // Physical Memory Caching Flags
188 //
189 #define DBGKD_CACHING_DEFAULT               0
190 #define DBGKD_CACHING_CACHED                1
191 #define DBGKD_CACHING_UNCACHED              2
192 #define DBGKD_CACHING_WRITE_COMBINED        3
193 
194 //
195 // Partition Switch Flags
196 //
197 #define DBGKD_PARTITION_DEFAULT             0x00
198 #define DBGKD_PARTITION_ALTERNATE           0x01
199 
200 //
201 // AMD64 Control Space types
202 //
203 #define AMD64_DEBUG_CONTROL_SPACE_KPCR 0
204 #define AMD64_DEBUG_CONTROL_SPACE_KPRCB 1
205 #define AMD64_DEBUG_CONTROL_SPACE_KSPECIAL 2
206 #define AMD64_DEBUG_CONTROL_SPACE_KTHREAD 3
207 
208 
209 //
210 // KD Packet Structure
211 //
212 typedef struct _KD_PACKET
213 {
214     ULONG PacketLeader;
215     USHORT PacketType;
216     USHORT ByteCount;
217     ULONG PacketId;
218     ULONG Checksum;
219 } KD_PACKET, *PKD_PACKET;
220 
221 //
222 // KD Context
223 //
224 typedef struct _KD_CONTEXT
225 {
226     ULONG KdpDefaultRetries;
227     BOOLEAN KdpControlCPending;
228 } KD_CONTEXT, *PKD_CONTEXT;
229 
230 //
231 // Control Sets for Supported Architectures
232 //
233 #include <pshpack4.h>
234 typedef struct _X86_DBGKD_CONTROL_SET
235 {
236     ULONG TraceFlag;
237     ULONG Dr7;
238     ULONG CurrentSymbolStart;
239     ULONG CurrentSymbolEnd;
240 } X86_DBGKD_CONTROL_SET, *PX86_DBGKD_CONTROL_SET;
241 
242 typedef struct _ALPHA_DBGKD_CONTROL_SET
243 {
244     ULONG __padding;
245 } ALPHA_DBGKD_CONTROL_SET, *PALPHA_DBGKD_CONTROL_SET;
246 
247 typedef struct _IA64_DBGKD_CONTROL_SET
248 {
249     ULONG Continue;
250     ULONG64 CurrentSymbolStart;
251     ULONG64 CurrentSymbolEnd;
252 } IA64_DBGKD_CONTROL_SET, *PIA64_DBGKD_CONTROL_SET;
253 
254 typedef struct _AMD64_DBGKD_CONTROL_SET
255 {
256     ULONG TraceFlag;
257     ULONG64 Dr7;
258     ULONG64 CurrentSymbolStart;
259     ULONG64 CurrentSymbolEnd;
260 } AMD64_DBGKD_CONTROL_SET, *PAMD64_DBGKD_CONTROL_SET;
261 
262 typedef struct _ARM_DBGKD_CONTROL_SET
263 {
264     ULONG Continue;
265     ULONG CurrentSymbolStart;
266     ULONG CurrentSymbolEnd;
267 } ARM_DBGKD_CONTROL_SET, *PARM_DBGKD_CONTROL_SET;
268 
269 typedef struct _ARM64_DBGKD_CONTROL_SET
270 {
271     ULONG Continue;
272     ULONG CurrentSymbolStart;
273     ULONG CurrentSymbolEnd;
274 } ARM64_DBGKD_CONTROL_SET, *PARM64_DBGKD_CONTROL_SET;
275 
276 typedef struct _DBGKD_ANY_CONTROL_SET
277 {
278     union
279     {
280         X86_DBGKD_CONTROL_SET X86ControlSet;
281         ALPHA_DBGKD_CONTROL_SET AlphaControlSet;
282         IA64_DBGKD_CONTROL_SET IA64ControlSet;
283         AMD64_DBGKD_CONTROL_SET Amd64ControlSet;
284         ARM_DBGKD_CONTROL_SET ARMControlSet;
285     };
286 } DBGKD_ANY_CONTROL_SET, *PDBGKD_ANY_CONTROL_SET;
287 #include <poppack.h>
288 
289 #if defined(_M_IX86)
290 typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
291 #elif defined(_M_AMD64)
292 typedef AMD64_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
293 #elif defined(_M_ARM)
294 typedef ARM_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
295 #elif defined(_M_ARM64)
296 typedef ARM64_DBGKD_CONTROL_SET DBGKD_CONTROL_SET, *PDBGKD_CONTROL_SET;
297 #else
298 #error Unsupported Architecture
299 #endif
300 
301 //
302 // DBGKM Structure for Exceptions
303 //
304 typedef struct _DBGKM_EXCEPTION32
305 {
306     EXCEPTION_RECORD32 ExceptionRecord;
307     ULONG FirstChance;
308 } DBGKM_EXCEPTION32, *PDBGKM_EXCEPTION32;
309 
310 typedef struct _DBGKM_EXCEPTION64
311 {
312     EXCEPTION_RECORD64 ExceptionRecord;
313     ULONG FirstChance;
314 } DBGKM_EXCEPTION64, *PDBGKM_EXCEPTION64;
315 
316 //
317 // DBGKD Structure for State Change
318 //
319 typedef struct _X86_DBGKD_CONTROL_REPORT
320 {
321     ULONG   Dr6;
322     ULONG   Dr7;
323     USHORT  InstructionCount;
324     USHORT  ReportFlags;
325     UCHAR   InstructionStream[DBGKD_MAXSTREAM];
326     USHORT  SegCs;
327     USHORT  SegDs;
328     USHORT  SegEs;
329     USHORT  SegFs;
330     ULONG   EFlags;
331 } X86_DBGKD_CONTROL_REPORT, *PX86_DBGKD_CONTROL_REPORT;
332 
333 typedef struct _ALPHA_DBGKD_CONTROL_REPORT
334 {
335     ULONG InstructionCount;
336     UCHAR InstructionStream[DBGKD_MAXSTREAM];
337 } ALPHA_DBGKD_CONTROL_REPORT, *PALPHA_DBGKD_CONTROL_REPORT;
338 
339 typedef struct _IA64_DBGKD_CONTROL_REPORT
340 {
341     ULONG InstructionCount;
342     UCHAR InstructionStream[DBGKD_MAXSTREAM];
343 } IA64_DBGKD_CONTROL_REPORT, *PIA64_DBGKD_CONTROL_REPORT;
344 
345 typedef struct _AMD64_DBGKD_CONTROL_REPORT
346 {
347     ULONG64 Dr6;
348     ULONG64 Dr7;
349     ULONG EFlags;
350     USHORT InstructionCount;
351     USHORT ReportFlags;
352     UCHAR InstructionStream[DBGKD_MAXSTREAM];
353     USHORT SegCs;
354     USHORT SegDs;
355     USHORT SegEs;
356     USHORT SegFs;
357 } AMD64_DBGKD_CONTROL_REPORT, *PAMD64_DBGKD_CONTROL_REPORT;
358 
359 typedef struct _ARM_DBGKD_CONTROL_REPORT
360 {
361     ULONG Cpsr;
362     ULONG InstructionCount;
363     UCHAR InstructionStream[DBGKD_MAXSTREAM];
364 } ARM_DBGKD_CONTROL_REPORT, *PARM_DBGKD_CONTROL_REPORT;
365 
366 typedef struct _ARM64_DBGKD_CONTROL_REPORT
367 {
368     ULONG64 Bvr;
369     ULONG64 Wvr;
370     ULONG InstructionCount;
371     UCHAR InstructionStream[DBGKD_MAXSTREAM];
372 } ARM64_DBGKD_CONTROL_REPORT, *PARM64_DBGKD_CONTROL_REPORT;
373 
374 typedef struct _DBGKD_ANY_CONTROL_REPORT
375 {
376     union
377     {
378         X86_DBGKD_CONTROL_REPORT X86ControlReport;
379         ALPHA_DBGKD_CONTROL_REPORT AlphaControlReport;
380         IA64_DBGKD_CONTROL_REPORT IA64ControlReport;
381         AMD64_DBGKD_CONTROL_REPORT Amd64ControlReport;
382         ARM_DBGKD_CONTROL_REPORT ARMControlReport;
383         ARM64_DBGKD_CONTROL_REPORT ARM64ControlReport;
384     };
385 } DBGKD_ANY_CONTROL_REPORT, *PDBGKD_ANY_CONTROL_REPORT;
386 
387 #if defined(_M_IX86)
388 typedef X86_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
389 #elif defined(_M_AMD64)
390 typedef AMD64_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
391 #elif defined(_M_ARM)
392 typedef ARM_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
393 #elif defined(_M_ARM64)
394 typedef ARM64_DBGKD_CONTROL_REPORT DBGKD_CONTROL_REPORT, *PDBGKD_CONTROL_REPORT;
395 #else
396 #error Unsupported Architecture
397 #endif
398 
399 //
400 // DBGKD Structure for Debug I/O Type Print String
401 //
402 typedef struct _DBGKD_PRINT_STRING
403 {
404     ULONG LengthOfString;
405 } DBGKD_PRINT_STRING, *PDBGKD_PRINT_STRING;
406 
407 //
408 // DBGKD Structure for Debug I/O Type Get String
409 //
410 typedef struct _DBGKD_GET_STRING
411 {
412     ULONG LengthOfPromptString;
413     ULONG LengthOfStringRead;
414 } DBGKD_GET_STRING, *PDBGKD_GET_STRING;
415 
416 //
417 // DBGKD Structure for Debug I/O
418 //
419 typedef struct _DBGKD_DEBUG_IO
420 {
421     ULONG ApiNumber;
422     USHORT ProcessorLevel;
423     USHORT Processor;
424     union
425     {
426         DBGKD_PRINT_STRING PrintString;
427         DBGKD_GET_STRING GetString;
428     } u;
429 } DBGKD_DEBUG_IO, *PDBGKD_DEBUG_IO;
430 
431 //
432 // DBGkD Structure for Command String
433 //
434 typedef struct _DBGKD_COMMAND_STRING
435 {
436     ULONG Flags;
437     ULONG Reserved1;
438     ULONG64 Reserved2[7];
439 } DBGKD_COMMAND_STRING, *PDBGKD_COMMAND_STRING;
440 
441 //
442 // DBGKD Structure for Load Symbols
443 //
444 typedef struct _DBGKD_LOAD_SYMBOLS32
445 {
446     ULONG PathNameLength;
447     ULONG BaseOfDll;
448     ULONG ProcessId;
449     ULONG CheckSum;
450     ULONG SizeOfImage;
451     BOOLEAN UnloadSymbols;
452 } DBGKD_LOAD_SYMBOLS32, *PDBGKD_LOAD_SYMBOLS32;
453 
454 typedef struct _DBGKD_LOAD_SYMBOLS64
455 {
456     ULONG PathNameLength;
457     ULONG64 BaseOfDll;
458     ULONG64 ProcessId;
459     ULONG CheckSum;
460     ULONG SizeOfImage;
461     BOOLEAN UnloadSymbols;
462 } DBGKD_LOAD_SYMBOLS64, *PDBGKD_LOAD_SYMBOLS64;
463 
464 //
465 // DBGKD Structure for Wait State Change
466 //
467 
468 typedef struct _DBGKD_WAIT_STATE_CHANGE32
469 {
470     ULONG NewState;
471     USHORT ProcessorLevel;
472     USHORT Processor;
473     ULONG NumberProcessors;
474     ULONG Thread;
475     ULONG ProgramCounter;
476     union
477     {
478         DBGKM_EXCEPTION32 Exception;
479         DBGKD_LOAD_SYMBOLS32 LoadSymbols;
480     } u;
481 } DBGKD_WAIT_STATE_CHANGE32, *PDBGKD_WAIT_STATE_CHANGE32;
482 
483 typedef struct _DBGKD_WAIT_STATE_CHANGE64
484 {
485     ULONG NewState;
486     USHORT ProcessorLevel;
487     USHORT Processor;
488     ULONG NumberProcessors;
489     ULONG64 Thread;
490     ULONG64 ProgramCounter;
491     union
492     {
493         DBGKM_EXCEPTION64 Exception;
494         DBGKD_LOAD_SYMBOLS64 LoadSymbols;
495     } u;
496 } DBGKD_WAIT_STATE_CHANGE64, *PDBGKD_WAIT_STATE_CHANGE64;
497 
498 typedef struct _DBGKD_ANY_WAIT_STATE_CHANGE
499 {
500     ULONG NewState;
501     USHORT ProcessorLevel;
502     USHORT Processor;
503     ULONG NumberProcessors;
504     ULONG64 Thread;
505     ULONG64 ProgramCounter;
506     union
507     {
508         DBGKM_EXCEPTION64 Exception;
509         DBGKD_LOAD_SYMBOLS64 LoadSymbols;
510         DBGKD_COMMAND_STRING CommandString;
511     } u;
512     union
513     {
514         DBGKD_CONTROL_REPORT ControlReport;
515         DBGKD_ANY_CONTROL_REPORT AnyControlReport;
516     };
517 } DBGKD_ANY_WAIT_STATE_CHANGE, *PDBGKD_ANY_WAIT_STATE_CHANGE;
518 
519 //
520 // DBGKD Manipulate Structures
521 //
522 typedef struct _DBGKD_READ_MEMORY32
523 {
524     ULONG TargetBaseAddress;
525     ULONG TransferCount;
526     ULONG ActualBytesRead;
527 } DBGKD_READ_MEMORY32, *PDBGKD_READ_MEMORY32;
528 
529 typedef struct _DBGKD_READ_MEMORY64
530 {
531     ULONG64 TargetBaseAddress;
532     ULONG TransferCount;
533     ULONG ActualBytesRead;
534 } DBGKD_READ_MEMORY64, *PDBGKD_READ_MEMORY64;
535 
536 typedef struct _DBGKD_WRITE_MEMORY32
537 {
538     ULONG TargetBaseAddress;
539     ULONG TransferCount;
540     ULONG ActualBytesWritten;
541 } DBGKD_WRITE_MEMORY32, *PDBGKD_WRITE_MEMORY32;
542 
543 typedef struct _DBGKD_WRITE_MEMORY64
544 {
545     ULONG64 TargetBaseAddress;
546     ULONG TransferCount;
547     ULONG ActualBytesWritten;
548 } DBGKD_WRITE_MEMORY64, *PDBGKD_WRITE_MEMORY64;
549 
550 typedef struct _DBGKD_GET_CONTEXT
551 {
552     ULONG Unused;
553 } DBGKD_GET_CONTEXT, *PDBGKD_GET_CONTEXT;
554 
555 typedef struct _DBGKD_SET_CONTEXT
556 {
557     ULONG ContextFlags;
558 } DBGKD_SET_CONTEXT, *PDBGKD_SET_CONTEXT;
559 
560 typedef struct _DBGKD_WRITE_BREAKPOINT32
561 {
562     ULONG BreakPointAddress;
563     ULONG BreakPointHandle;
564 } DBGKD_WRITE_BREAKPOINT32, *PDBGKD_WRITE_BREAKPOINT32;
565 
566 typedef struct _DBGKD_WRITE_BREAKPOINT64
567 {
568     ULONG64 BreakPointAddress;
569     ULONG BreakPointHandle;
570 } DBGKD_WRITE_BREAKPOINT64, *PDBGKD_WRITE_BREAKPOINT64;
571 
572 typedef struct _DBGKD_RESTORE_BREAKPOINT
573 {
574     ULONG BreakPointHandle;
575 } DBGKD_RESTORE_BREAKPOINT, *PDBGKD_RESTORE_BREAKPOINT;
576 
577 typedef struct _DBGKD_CONTINUE
578 {
579     NTSTATUS ContinueStatus;
580 } DBGKD_CONTINUE, *PDBGKD_CONTINUE;
581 
582 #include <pshpack4.h>
583 typedef struct _DBGKD_CONTINUE2
584 {
585     NTSTATUS ContinueStatus;
586     union
587     {
588         DBGKD_CONTROL_SET ControlSet;
589         DBGKD_ANY_CONTROL_SET AnyControlSet;
590     };
591 } DBGKD_CONTINUE2, *PDBGKD_CONTINUE2;
592 #include <poppack.h>
593 
594 typedef struct _DBGKD_READ_WRITE_IO32
595 {
596     ULONG IoAddress;
597     ULONG DataSize;
598     ULONG DataValue;
599 } DBGKD_READ_WRITE_IO32, *PDBGKD_READ_WRITE_IO32;
600 
601 typedef struct _DBGKD_READ_WRITE_IO64
602 {
603     ULONG64 IoAddress;
604     ULONG DataSize;
605     ULONG DataValue;
606 } DBGKD_READ_WRITE_IO64, *PDBGKD_READ_WRITE_IO64;
607 
608 typedef struct _DBGKD_READ_WRITE_IO_EXTENDED32
609 {
610     ULONG DataSize;
611     ULONG InterfaceType;
612     ULONG BusNumber;
613     ULONG AddressSpace;
614     ULONG IoAddress;
615     ULONG DataValue;
616 } DBGKD_READ_WRITE_IO_EXTENDED32, *PDBGKD_READ_WRITE_IO_EXTENDED32;
617 
618 typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
619 {
620     ULONG DataSize;
621     ULONG InterfaceType;
622     ULONG BusNumber;
623     ULONG AddressSpace;
624     ULONG64 IoAddress;
625     ULONG DataValue;
626 } DBGKD_READ_WRITE_IO_EXTENDED64, *PDBGKD_READ_WRITE_IO_EXTENDED64;
627 
628 typedef struct _DBGKD_READ_WRITE_MSR
629 {
630     ULONG Msr;
631     ULONG DataValueLow;
632     ULONG DataValueHigh;
633 } DBGKD_READ_WRITE_MSR, *PDBGKD_READ_WRITE_MSR;
634 
635 typedef struct _DBGKD_QUERY_SPECIAL_CALLS
636 {
637     ULONG NumberOfSpecialCalls;
638 } DBGKD_QUERY_SPECIAL_CALLS, *PDBGKD_QUERY_SPECIAL_CALLS;
639 
640 typedef struct _DBGKD_SET_SPECIAL_CALL32
641 {
642     ULONG SpecialCall;
643 } DBGKD_SET_SPECIAL_CALL32, *PDBGKD_SET_SPECIAL_CALL32;
644 
645 typedef struct _DBGKD_SET_SPECIAL_CALL64
646 {
647     ULONG64 SpecialCall;
648 } DBGKD_SET_SPECIAL_CALL64, *PDBGKD_SET_SPECIAL_CALL64;
649 
650 typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT32
651 {
652     ULONG BreakpointAddress;
653     ULONG Flags;
654 } DBGKD_SET_INTERNAL_BREAKPOINT32, *PDBGKD_SET_INTERNAL_BREAKPOINT32;
655 
656 typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
657 {
658     ULONG64 BreakpointAddress;
659     ULONG Flags;
660 } DBGKD_SET_INTERNAL_BREAKPOINT64, *PDBGKD_SET_INTERNAL_BREAKPOINT64;
661 
662 typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT32
663 {
664     ULONG BreakpointAddress;
665     ULONG Flags;
666     ULONG Calls;
667     ULONG MaxCallsPerPeriod;
668     ULONG MinInstructions;
669     ULONG MaxInstructions;
670     ULONG TotalInstructions;
671 } DBGKD_GET_INTERNAL_BREAKPOINT32, *PDBGKD_GET_INTERNAL_BREAKPOINT32;
672 
673 typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
674 {
675     ULONG64 BreakpointAddress;
676     ULONG Flags;
677     ULONG Calls;
678     ULONG MaxCallsPerPeriod;
679     ULONG MinInstructions;
680     ULONG MaxInstructions;
681     ULONG TotalInstructions;
682 } DBGKD_GET_INTERNAL_BREAKPOINT64, *PDBGKD_GET_INTERNAL_BREAKPOINT64;
683 
684 typedef struct _DBGKD_BREAKPOINTEX
685 {
686     ULONG BreakPointCount;
687     NTSTATUS ContinueStatus;
688 } DBGKD_BREAKPOINTEX, *PDBGKD_BREAKPOINTEX;
689 
690 typedef struct _DBGKD_SEARCH_MEMORY
691 {
692     union
693     {
694         ULONG64 SearchAddress;
695         ULONG64 FoundAddress;
696     };
697     ULONG64 SearchLength;
698     ULONG PatternLength;
699 } DBGKD_SEARCH_MEMORY, *PDBGKD_SEARCH_MEMORY;
700 
701 typedef struct _DBGKD_GET_SET_BUS_DATA
702 {
703     ULONG BusDataType;
704     ULONG BusNumber;
705     ULONG SlotNumber;
706     ULONG Offset;
707     ULONG Length;
708 } DBGKD_GET_SET_BUS_DATA, *PDBGKD_GET_SET_BUS_DATA;
709 
710 typedef struct _DBGKD_FILL_MEMORY
711 {
712     ULONG64 Address;
713     ULONG Length;
714     USHORT Flags;
715     USHORT PatternLength;
716 } DBGKD_FILL_MEMORY, *PDBGKD_FILL_MEMORY;
717 
718 typedef struct _DBGKD_QUERY_MEMORY
719 {
720     ULONG64 Address;
721     ULONG64 Reserved;
722     ULONG AddressSpace;
723     ULONG Flags;
724 } DBGKD_QUERY_MEMORY, *PDBGKD_QUERY_MEMORY;
725 
726 typedef struct _DBGKD_SWITCH_PARTITION
727 {
728     ULONG Partition;
729 } DBGKD_SWITCH_PARTITION;
730 
731 typedef struct _DBGKD_CONTEXT_EX
732 {
733    ULONG Offset;
734    ULONG ByteCount;
735    ULONG BytesCopied;
736 } DBGKD_CONTEXT_EX, *PDBGKD_CONTEXT_EX;
737 
738 typedef struct _DBGKD_WRITE_CUSTOM_BREAKPOINT
739 {
740    ULONG64 BreakPointAddress;
741    ULONG64 BreakPointInstruction;
742    ULONG BreakPointHandle;
743    UCHAR BreakPointInstructionSize;
744    UCHAR BreakPointInstructionAlignment;
745 } DBGKD_WRITE_CUSTOM_BREAKPOINT, *PDBGKD_WRITE_CUSTOM_BREAKPOINT;
746 
747 //
748 // DBGKD Structure for Manipulate
749 //
750 typedef struct _DBGKD_MANIPULATE_STATE32
751 {
752     ULONG ApiNumber;
753     USHORT ProcessorLevel;
754     USHORT Processor;
755     NTSTATUS ReturnStatus;
756     union
757     {
758         DBGKD_READ_MEMORY32 ReadMemory;
759         DBGKD_WRITE_MEMORY32 WriteMemory;
760         DBGKD_READ_MEMORY64 ReadMemory64;
761         DBGKD_WRITE_MEMORY64 WriteMemory64;
762         DBGKD_GET_CONTEXT GetContext;
763         DBGKD_SET_CONTEXT SetContext;
764         DBGKD_WRITE_BREAKPOINT32 WriteBreakPoint;
765         DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint;
766         DBGKD_CONTINUE Continue;
767         DBGKD_CONTINUE2 Continue2;
768         DBGKD_READ_WRITE_IO32 ReadWriteIo;
769         DBGKD_READ_WRITE_IO_EXTENDED32 ReadWriteIoExtended;
770         DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls;
771         DBGKD_SET_SPECIAL_CALL32 SetSpecialCall;
772         DBGKD_SET_INTERNAL_BREAKPOINT32 SetInternalBreakpoint;
773         DBGKD_GET_INTERNAL_BREAKPOINT32 GetInternalBreakpoint;
774         DBGKD_GET_VERSION32 GetVersion32;
775         DBGKD_BREAKPOINTEX BreakPointEx;
776         DBGKD_READ_WRITE_MSR ReadWriteMsr;
777         DBGKD_SEARCH_MEMORY SearchMemory;
778         DBGKD_GET_SET_BUS_DATA GetSetBusData;
779         DBGKD_FILL_MEMORY FillMemory;
780         DBGKD_QUERY_MEMORY QueryMemory;
781         DBGKD_SWITCH_PARTITION SwitchPartition;
782     } u;
783 } DBGKD_MANIPULATE_STATE32, *PDBGKD_MANIPULATE_STATE32;
784 
785 typedef struct _DBGKD_MANIPULATE_STATE64
786 {
787     ULONG ApiNumber;
788     USHORT ProcessorLevel;
789     USHORT Processor;
790     NTSTATUS ReturnStatus;
791     union
792     {
793         DBGKD_READ_MEMORY64 ReadMemory;
794         DBGKD_WRITE_MEMORY64 WriteMemory;
795         DBGKD_GET_CONTEXT GetContext;
796         DBGKD_SET_CONTEXT SetContext;
797         DBGKD_WRITE_BREAKPOINT64 WriteBreakPoint;
798         DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint;
799         DBGKD_CONTINUE Continue;
800         DBGKD_CONTINUE2 Continue2;
801         DBGKD_READ_WRITE_IO64 ReadWriteIo;
802         DBGKD_READ_WRITE_IO_EXTENDED64 ReadWriteIoExtended;
803         DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls;
804         DBGKD_SET_SPECIAL_CALL64 SetSpecialCall;
805         DBGKD_SET_INTERNAL_BREAKPOINT64 SetInternalBreakpoint;
806         DBGKD_GET_INTERNAL_BREAKPOINT64 GetInternalBreakpoint;
807         DBGKD_GET_VERSION64 GetVersion64;
808         DBGKD_BREAKPOINTEX BreakPointEx;
809         DBGKD_READ_WRITE_MSR ReadWriteMsr;
810         DBGKD_SEARCH_MEMORY SearchMemory;
811         DBGKD_GET_SET_BUS_DATA GetSetBusData;
812         DBGKD_FILL_MEMORY FillMemory;
813         DBGKD_QUERY_MEMORY QueryMemory;
814         DBGKD_SWITCH_PARTITION SwitchPartition;
815         DBGKD_WRITE_CUSTOM_BREAKPOINT WriteCustomBreakpoint;
816         DBGKD_CONTEXT_EX ContextEx;
817     } u;
818 } DBGKD_MANIPULATE_STATE64, *PDBGKD_MANIPULATE_STATE64;
819 
820 //
821 // File I/O Structure
822 //
823 typedef struct _DBGKD_CREATE_FILE
824 {
825     ULONG DesiredAccess;
826     ULONG FileAttributes;
827     ULONG ShareAccess;
828     ULONG CreateDisposition;
829     ULONG CreateOptions;
830     ULONG64 Handle;
831     ULONG64 Length;
832 } DBGKD_CREATE_FILE, *PDBGKD_CREATE_FILE;
833 
834 typedef struct _DBGKD_READ_FILE
835 {
836     ULONG64 Handle;
837     ULONG64 Offset;
838     ULONG Length;
839 } DBGKD_READ_FILE, *PDBGKD_READ_FILE;
840 
841 typedef struct _DBGKD_WRITE_FILE
842 {
843     ULONG64 Handle;
844     ULONG64 Offset;
845     ULONG Length;
846 } DBGKD_WRITE_FILE, *PDBGKD_WRITE_FILE;
847 
848 typedef struct _DBGKD_CLOSE_FILE
849 {
850     ULONG64 Handle;
851 } DBGKD_CLOSE_FILE, *PDBGKD_CLOSE_FILE;
852 
853 typedef struct _DBGKD_FILE_IO
854 {
855     ULONG ApiNumber;
856     ULONG Status;
857     union
858     {
859         ULONG64 ReserveSpace[7];
860         DBGKD_CREATE_FILE CreateFile;
861         DBGKD_READ_FILE ReadFile;
862         DBGKD_WRITE_FILE WriteFile;
863         DBGKD_CLOSE_FILE CloseFile;
864     } u;
865 } DBGKD_FILE_IO, *PDBGKD_FILE_IO;
866 
867 
868 //
869 // Control Request Structure
870 //
871 typedef struct _DBGKD_REQUEST_BREAKPOINT
872 {
873     ULONG HardwareBreakPointNumber;
874     ULONG Available;
875 } DBGKD_REQUEST_BREAKPOINT, *PDBGKD_REQUEST_BREAKPOINT;
876 
877 typedef struct _DBGKD_RELEASE_BREAKPOINT
878 {
879     ULONG HardwareBreakPointNumber;
880     ULONG Released;
881 } DBGKD_RELEASE_BREAKPOINT, *PDBGKD_RELEASE_BREAKPOINT;
882 
883 typedef struct _DBGKD_CONTROL_REQUEST
884 {
885     ULONG ApiNumber;
886     union
887     {
888         DBGKD_REQUEST_BREAKPOINT RequestBreakpoint;
889         DBGKD_RELEASE_BREAKPOINT ReleaseBreakpoint;
890     } u;
891 } DBGKD_CONTROL_REQUEST, *PDBGKD_CONTROL_REQUEST;
892 
893 //
894 // Trace I/O Structure
895 //
896 typedef struct _DBGKD_PRINT_TRACE
897 {
898     ULONG LengthOfData;
899 } DBGKD_PRINT_TRACE, *PDBGKD_PRINT_TRACE;
900 
901 typedef struct _DBGKD_TRACE_IO
902 {
903    ULONG ApiNumber;
904    USHORT ProcessorLevel;
905    USHORT Processor;
906    union
907    {
908        ULONG64 ReserveSpace[7];
909        DBGKD_PRINT_TRACE PrintTrace;
910    } u;
911 } DBGKD_TRACE_IO, *PDBGKD_TRACE_IO;
912 
913 static
914 __inline
915 VOID
916 NTAPI
ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,OUT PEXCEPTION_RECORD64 Ex64)917 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32,
918                       OUT PEXCEPTION_RECORD64 Ex64)
919 {
920     ULONG i;
921 
922     Ex64->ExceptionCode = Ex32->ExceptionCode;
923     Ex64->ExceptionFlags = Ex32->ExceptionFlags;
924     Ex64->ExceptionRecord = Ex32->ExceptionRecord;
925     COPYSE(Ex64,Ex32,ExceptionAddress);
926     Ex64->NumberParameters = Ex32->NumberParameters;
927 
928     for (i = 0; i < EXCEPTION_MAXIMUM_PARAMETERS; i++)
929     {
930         COPYSE(Ex64,Ex32,ExceptionInformation[i]);
931     }
932 }
933 
934 #endif
935