12 #define COPYSE(p64, p32, f) \
13 p64->f = (ULONG64)(LONG64)(LONG)p32->f
16 // Packet Size and Control Stream Size
18 #define PACKET_MAX_SIZE 4000
19 #define DBGKD_MAXSTREAM 16
24 #define INITIAL_PACKET_ID 0x80800000
25 #define SYNC_PACKET_ID 0x00000800
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
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
56 // Wait State Change Types
58 #define DbgKdMinimumStateChange 0x00003030
59 #define DbgKdExceptionStateChange 0x00003030
60 #define DbgKdLoadSymbolsStateChange 0x00003031
61 #define DbgKdCommandStringStateChange 0x00003032
62 #define DbgKdMaximumStateChange 0x00003033
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
113 #define DbgKdPrintStringApi 0x00003230
114 #define DbgKdGetStringApi 0x00003231
117 // Control Report Flags
119 #define REPORT_INCLUDES_SEGS 0x0001
120 #define REPORT_INCLUDES_CS 0x0002
125 #define DBGKD_64BIT_PROTOCOL_VERSION1 5
126 #define DBGKD_64BIT_PROTOCOL_VERSION2 6
129 // Query Memory Address Spaces
131 #define DBGKD_QUERY_MEMORY_VIRTUAL 0
132 #define DBGKD_QUERY_MEMORY_PROCESS 0
133 #define DBGKD_QUERY_MEMORY_SESSION 1
134 #define DBGKD_QUERY_MEMORY_KERNEL 2
137 // Query Memory Flags
139 #define DBGKD_QUERY_MEMORY_READ 0x01
140 #define DBGKD_QUERY_MEMORY_WRITE 0x02
141 #define DBGKD_QUERY_MEMORY_EXECUTE 0x04
142 #define DBGKD_QUERY_MEMORY_FIXED 0x08
145 // KD Packet Structure
147 typedef struct _KD_PACKET
154 } KD_PACKET
, *PKD_PACKET
;
159 typedef struct _KD_CONTEXT
161 ULONG KdpDefaultRetries
;
162 BOOLEAN KdpControlCPending
;
163 } KD_CONTEXT
, *PKD_CONTEXT
;
166 // Control Sets for Supported Architectures
168 #include <pshpack4.h>
169 typedef struct _X86_DBGKD_CONTROL_SET
173 ULONG CurrentSymbolStart
;
174 ULONG CurrentSymbolEnd
;
175 } X86_DBGKD_CONTROL_SET
, *PX86_DBGKD_CONTROL_SET
;
177 typedef struct _IA64_DBGKD_CONTROL_SET
180 ULONG64 CurrentSymbolStart
;
181 ULONG64 CurrentSymbolEnd
;
182 } IA64_DBGKD_CONTROL_SET
, *PIA64_DBGKD_CONTROL_SET
;
184 typedef struct _AMD64_DBGKD_CONTROL_SET
188 ULONG64 CurrentSymbolStart
;
189 ULONG64 CurrentSymbolEnd
;
190 } AMD64_DBGKD_CONTROL_SET
, *PAMD64_DBGKD_CONTROL_SET
;
192 typedef struct _DBGKD_ANY_CONTROL_SET
196 X86_DBGKD_CONTROL_SET X86ControlSet
;
197 IA64_DBGKD_CONTROL_SET IA64ControlSet
;
198 AMD64_DBGKD_CONTROL_SET Amd64ControlSet
;
200 } DBGKD_ANY_CONTROL_SET
, *PDBGKD_ANY_CONTROL_SET
;
203 typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET
;
206 // DBGKM Structure for Exceptions
208 typedef struct _DBGKM_EXCEPTION64
210 EXCEPTION_RECORD64 ExceptionRecord
;
212 } DBGKM_EXCEPTION64
, *PDBGKM_EXCEPTION64
;
215 // DBGKD Structure for State Change
217 typedef struct _DBGKD_CONTROL_REPORT
221 USHORT InstructionCount
;
223 UCHAR InstructionStream
[DBGKD_MAXSTREAM
];
229 } DBGKD_CONTROL_REPORT
, *PDBGKD_CONTROL_REPORT
;
232 // DBGKD Structure for Debug I/O Type Print String
234 typedef struct _DBGKD_PRINT_STRING
236 ULONG LengthOfString
;
237 } DBGKD_PRINT_STRING
, *PDBGKD_PRINT_STRING
;
240 // DBGKD Structure for Debug I/O Type Get String
242 typedef struct _DBGKD_GET_STRING
244 ULONG LengthOfPromptString
;
245 ULONG LengthOfStringRead
;
246 } DBGKD_GET_STRING
, *PDBGKD_GET_STRING
;
249 // DBGKD Structure for Debug I/O
251 typedef struct _DBGKD_DEBUG_IO
254 USHORT ProcessorLevel
;
258 DBGKD_PRINT_STRING PrintString
;
259 DBGKD_GET_STRING GetString
;
261 } DBGKD_DEBUG_IO
, *PDBGKD_DEBUG_IO
;
264 // DBGKD Structure for Load Symbols
266 typedef struct _DBGKD_LOAD_SYMBOLS64
268 ULONG PathNameLength
;
273 BOOLEAN UnloadSymbols
;
274 } DBGKD_LOAD_SYMBOLS64
, *PDBGKD_LOAD_SYMBOLS64
;
277 // DBGKD Structure for Wait State Change
279 typedef struct _DBGKD_WAIT_STATE_CHANGE64
282 USHORT ProcessorLevel
;
284 ULONG NumberProcessors
;
286 ULONG64 ProgramCounter
;
289 DBGKM_EXCEPTION64 Exception
;
290 DBGKD_LOAD_SYMBOLS64 LoadSymbols
;
292 DBGKD_CONTROL_REPORT ControlReport
;
294 } DBGKD_WAIT_STATE_CHANGE64
, *PDBGKD_WAIT_STATE_CHANGE64
;
297 // DBGKD Manipulate Structures
299 typedef struct _DBGKD_READ_MEMORY64
301 ULONG64 TargetBaseAddress
;
303 ULONG ActualBytesRead
;
304 } DBGKD_READ_MEMORY64
, *PDBGKD_READ_MEMORY64
;
306 typedef struct _DBGKD_WRITE_MEMORY64
308 ULONG64 TargetBaseAddress
;
310 ULONG ActualBytesWritten
;
311 } DBGKD_WRITE_MEMORY64
, *PDBGKD_WRITE_MEMORY64
;
313 typedef struct _DBGKD_GET_CONTEXT
316 } DBGKD_GET_CONTEXT
, *PDBGKD_GET_CONTEXT
;
318 typedef struct _DBGKD_SET_CONTEXT
321 } DBGKD_SET_CONTEXT
, *PDBGKD_SET_CONTEXT
;
323 typedef struct _DBGKD_WRITE_BREAKPOINT64
325 ULONG64 BreakPointAddress
;
326 ULONG BreakPointHandle
;
327 } DBGKD_WRITE_BREAKPOINT64
, *PDBGKD_WRITE_BREAKPOINT64
;
329 typedef struct _DBGKD_RESTORE_BREAKPOINT
331 ULONG BreakPointHandle
;
332 } DBGKD_RESTORE_BREAKPOINT
, *PDBGKD_RESTORE_BREAKPOINT
;
334 typedef struct _DBGKD_CONTINUE
336 NTSTATUS ContinueStatus
;
337 } DBGKD_CONTINUE
, *PDBGKD_CONTINUE
;
339 #include <pshpack4.h>
340 typedef struct _DBGKD_CONTINUE2
342 NTSTATUS ContinueStatus
;
345 DBGKD_CONTROL_SET ControlSet
;
346 DBGKD_ANY_CONTROL_SET AnyControlSet
;
348 } DBGKD_CONTINUE2
, *PDBGKD_CONTINUE2
;
351 typedef struct _DBGKD_READ_WRITE_IO64
356 } DBGKD_READ_WRITE_IO64
, *PDBGKD_READ_WRITE_IO64
;
358 typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
366 } DBGKD_READ_WRITE_IO_EXTENDED64
, *PDBGKD_READ_WRITE_IO_EXTENDED64
;
368 typedef struct _DBGKD_READ_WRITE_MSR
373 } DBGKD_READ_WRITE_MSR
, *PDBGKD_READ_WRITE_MSR
;
375 typedef struct _DBGKD_QUERY_SPECIAL_CALLS
377 ULONG NumberOfSpecialCalls
;
378 } DBGKD_QUERY_SPECIAL_CALLS
, *PDBGKD_QUERY_SPECIAL_CALLS
;
380 typedef struct _DBGKD_SET_SPECIAL_CALL64
383 } DBGKD_SET_SPECIAL_CALL64
, *PDBGKD_SET_SPECIAL_CALL64
;
385 typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
387 ULONG64 BreakpointAddress
;
389 } DBGKD_SET_INTERNAL_BREAKPOINT64
, *PDBGKD_SET_INTERNAL_BREAKPOINT64
;
391 typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
393 ULONG64 BreakpointAddress
;
396 ULONG MaxCallsPerPeriod
;
397 ULONG MinInstructions
;
398 ULONG MaxInstructions
;
399 ULONG TotalInstructions
;
400 } DBGKD_GET_INTERNAL_BREAKPOINT64
, *PDBGKD_GET_INTERNAL_BREAKPOINT64
;
402 typedef struct _DBGKD_BREAKPOINTEX
404 ULONG BreakPointCount
;
405 NTSTATUS ContinueStatus
;
406 } DBGKD_BREAKPOINTEX
, *PDBGKD_BREAKPOINTEX
;
408 typedef struct _DBGKD_SEARCH_MEMORY
412 ULONG64 SearchAddress
;
413 ULONG64 FoundAddress
;
415 ULONG64 SearchLength
;
417 } DBGKD_SEARCH_MEMORY
, *PDBGKD_SEARCH_MEMORY
;
419 typedef struct _DBGKD_GET_SET_BUS_DATA
426 } DBGKD_GET_SET_BUS_DATA
, *PDBGKD_GET_SET_BUS_DATA
;
428 typedef struct _DBGKD_FILL_MEMORY
433 USHORT PatternLength
;
434 } DBGKD_FILL_MEMORY
, *PDBGKD_FILL_MEMORY
;
436 typedef struct _DBGKD_QUERY_MEMORY
442 } DBGKD_QUERY_MEMORY
, *PDBGKD_QUERY_MEMORY
;
444 typedef struct _DBGKD_SWITCH_PARTITION
447 } DBGKD_SWITCH_PARTITION
;
450 // DBGKD Structure for Manipulate
452 typedef struct _DBGKD_MANIPULATE_STATE64
455 USHORT ProcessorLevel
;
457 NTSTATUS ReturnStatus
;
460 DBGKD_READ_MEMORY64 ReadMemory
;
461 DBGKD_WRITE_MEMORY64 WriteMemory
;
462 DBGKD_GET_CONTEXT GetContext
;
463 DBGKD_SET_CONTEXT SetContext
;
464 DBGKD_WRITE_BREAKPOINT64 WriteBreakPoint
;
465 DBGKD_RESTORE_BREAKPOINT RestoreBreakPoint
;
466 DBGKD_CONTINUE Continue
;
467 DBGKD_CONTINUE2 Continue2
;
468 DBGKD_READ_WRITE_IO64 ReadWriteIo
;
469 DBGKD_READ_WRITE_IO_EXTENDED64 ReadWriteIoExtended
;
470 DBGKD_QUERY_SPECIAL_CALLS QuerySpecialCalls
;
471 DBGKD_SET_SPECIAL_CALL64 SetSpecialCall
;
472 DBGKD_SET_INTERNAL_BREAKPOINT64 SetInternalBreakpoint
;
473 DBGKD_GET_INTERNAL_BREAKPOINT64 GetInternalBreakpoint
;
474 DBGKD_GET_VERSION64 GetVersion64
;
475 DBGKD_BREAKPOINTEX BreakPointEx
;
476 DBGKD_READ_WRITE_MSR ReadWriteMsr
;
477 DBGKD_SEARCH_MEMORY SearchMemory
;
478 DBGKD_GET_SET_BUS_DATA GetSetBusData
;
479 DBGKD_FILL_MEMORY FillMemory
;
480 DBGKD_QUERY_MEMORY QueryMemory
;
481 DBGKD_SWITCH_PARTITION SwitchPartition
;
483 } DBGKD_MANIPULATE_STATE64
, *PDBGKD_MANIPULATE_STATE64
;
487 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32
,
488 OUT PEXCEPTION_RECORD64 Ex64
)
492 Ex64
->ExceptionCode
= Ex32
->ExceptionCode
;
493 Ex64
->ExceptionFlags
= Ex32
->ExceptionFlags
;
494 Ex64
->ExceptionRecord
= Ex32
->ExceptionRecord
;
495 COPYSE(Ex64
,Ex32
,ExceptionAddress
);
496 Ex64
->NumberParameters
= Ex32
->NumberParameters
;
498 for (i
= 0; i
< EXCEPTION_MAXIMUM_PARAMETERS
; i
++)
500 COPYSE(Ex64
,Ex32
,ExceptionInformation
[i
]);