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 // KD Packet Structure
131 typedef struct _KD_PACKET
138 } KD_PACKET
, *PKD_PACKET
;
143 typedef struct _KD_CONTEXT
145 ULONG KdpDefaultRetries
;
146 BOOLEAN KdpControlCPending
;
147 } KD_CONTEXT
, *PKD_CONTEXT
;
150 // Control Sets for Supported Architectures
152 #include <pshpack4.h>
153 typedef struct _X86_DBGKD_CONTROL_SET
157 ULONG CurrentSymbolStart
;
158 ULONG CurrentSymbolEnd
;
159 } X86_DBGKD_CONTROL_SET
, *PX86_DBGKD_CONTROL_SET
;
161 typedef struct _IA64_DBGKD_CONTROL_SET
164 ULONG64 CurrentSymbolStart
;
165 ULONG64 CurrentSymbolEnd
;
166 } IA64_DBGKD_CONTROL_SET
, *PIA64_DBGKD_CONTROL_SET
;
168 typedef struct _AMD64_DBGKD_CONTROL_SET
172 ULONG64 CurrentSymbolStart
;
173 ULONG64 CurrentSymbolEnd
;
174 } AMD64_DBGKD_CONTROL_SET
, *PAMD64_DBGKD_CONTROL_SET
;
176 typedef struct _DBGKD_ANY_CONTROL_SET
180 X86_DBGKD_CONTROL_SET X86ControlSet
;
181 IA64_DBGKD_CONTROL_SET IA64ControlSet
;
182 AMD64_DBGKD_CONTROL_SET Amd64ControlSet
;
184 } DBGKD_ANY_CONTROL_SET
, *PDBGKD_ANY_CONTROL_SET
;
187 typedef X86_DBGKD_CONTROL_SET DBGKD_CONTROL_SET
;
190 // DBGKM Structure for Exceptions
192 typedef struct _DBGKM_EXCEPTION64
194 EXCEPTION_RECORD64 ExceptionRecord
;
196 } DBGKM_EXCEPTION64
, *PDBGKM_EXCEPTION64
;
199 // DBGKD Structure for State Change
201 typedef struct _DBGKD_CONTROL_REPORT
205 USHORT InstructionCount
;
207 UCHAR InstructionStream
[DBGKD_MAXSTREAM
];
213 } DBGKD_CONTROL_REPORT
, *PDBGKD_CONTROL_REPORT
;
216 // DBGKD Structure for Debug I/O Type Print String
218 typedef struct _DBGKD_PRINT_STRING
220 ULONG LengthOfString
;
221 } DBGKD_PRINT_STRING
, *PDBGKD_PRINT_STRING
;
224 // DBGKD Structure for Debug I/O Type Get String
226 typedef struct _DBGKD_GET_STRING
228 ULONG LengthOfPromptString
;
229 ULONG LengthOfStringRead
;
230 } DBGKD_GET_STRING
, *PDBGKD_GET_STRING
;
233 // DBGKD Structure for Debug I/O
235 typedef struct _DBGKD_DEBUG_IO
238 USHORT ProcessorLevel
;
242 DBGKD_PRINT_STRING PrintString
;
243 DBGKD_GET_STRING GetString
;
245 } DBGKD_DEBUG_IO
, *PDBGKD_DEBUG_IO
;
248 // DBGKD Structure for Load Symbols
250 typedef struct _DBGKD_LOAD_SYMBOLS64
252 ULONG PathNameLength
;
257 BOOLEAN UnloadSymbols
;
258 } DBGKD_LOAD_SYMBOLS64
, *PDBGKD_LOAD_SYMBOLS64
;
261 // DBGKD Structure for Wait State Change
263 typedef struct _DBGKD_WAIT_STATE_CHANGE64
266 USHORT ProcessorLevel
;
268 ULONG NumberProcessors
;
270 ULONG64 ProgramCounter
;
273 DBGKM_EXCEPTION64 Exception
;
274 DBGKD_LOAD_SYMBOLS64 LoadSymbols
;
276 DBGKD_CONTROL_REPORT ControlReport
;
278 } DBGKD_WAIT_STATE_CHANGE64
, *PDBGKD_WAIT_STATE_CHANGE64
;
281 // DBGKD Manipulate Structures
283 typedef struct _DBGKD_READ_MEMORY64
285 ULONG64 TargetBaseAddress
;
287 ULONG ActualBytesRead
;
288 } DBGKD_READ_MEMORY64
, *PDBGKD_READ_MEMORY64
;
290 typedef struct _DBGKD_WRITE_MEMORY64
292 ULONG64 TargetBaseAddress
;
294 ULONG ActualBytesWritten
;
295 } DBGKD_WRITE_MEMORY64
, *PDBGKD_WRITE_MEMORY64
;
297 typedef struct _DBGKD_GET_CONTEXT
300 } DBGKD_GET_CONTEXT
, *PDBGKD_GET_CONTEXT
;
302 typedef struct _DBGKD_SET_CONTEXT
305 } DBGKD_SET_CONTEXT
, *PDBGKD_SET_CONTEXT
;
307 typedef struct _DBGKD_WRITE_BREAKPOINT64
309 ULONG64 BreakPointAddress
;
310 ULONG BreakPointHandle
;
311 } DBGKD_WRITE_BREAKPOINT64
, *PDBGKD_WRITE_BREAKPOINT64
;
313 typedef struct _DBGKD_RESTORE_BREAKPOINT
315 ULONG BreakPointHandle
;
316 } DBGKD_RESTORE_BREAKPOINT
, *PDBGKD_RESTORE_BREAKPOINT
;
318 typedef struct _DBGKD_CONTINUE
320 NTSTATUS ContinueStatus
;
321 } DBGKD_CONTINUE
, *PDBGKD_CONTINUE
;
323 #include <pshpack4.h>
324 typedef struct _DBGKD_CONTINUE2
326 NTSTATUS ContinueStatus
;
329 DBGKD_CONTROL_SET ControlSet
;
330 DBGKD_ANY_CONTROL_SET AnyControlSet
;
332 } DBGKD_CONTINUE2
, *PDBGKD_CONTINUE2
;
335 typedef struct _DBGKD_READ_WRITE_IO64
340 } DBGKD_READ_WRITE_IO64
, *PDBGKD_READ_WRITE_IO64
;
342 typedef struct _DBGKD_READ_WRITE_IO_EXTENDED64
350 } DBGKD_READ_WRITE_IO_EXTENDED64
, *PDBGKD_READ_WRITE_IO_EXTENDED64
;
352 typedef struct _DBGKD_READ_WRITE_MSR
357 } DBGKD_READ_WRITE_MSR
, *PDBGKD_READ_WRITE_MSR
;
359 typedef struct _DBGKD_QUERY_SPECIAL_CALLS
361 ULONG NumberOfSpecialCalls
;
362 } DBGKD_QUERY_SPECIAL_CALLS
, *PDBGKD_QUERY_SPECIAL_CALLS
;
364 typedef struct _DBGKD_SET_SPECIAL_CALL64
367 } DBGKD_SET_SPECIAL_CALL64
, *PDBGKD_SET_SPECIAL_CALL64
;
369 typedef struct _DBGKD_SET_INTERNAL_BREAKPOINT64
371 ULONG64 BreakpointAddress
;
373 } DBGKD_SET_INTERNAL_BREAKPOINT64
, *PDBGKD_SET_INTERNAL_BREAKPOINT64
;
375 typedef struct _DBGKD_GET_INTERNAL_BREAKPOINT64
377 ULONG64 BreakpointAddress
;
380 ULONG MaxCallsPerPeriod
;
381 ULONG MinInstructions
;
382 ULONG MaxInstructions
;
383 ULONG TotalInstructions
;
384 } DBGKD_GET_INTERNAL_BREAKPOINT64
, *PDBGKD_GET_INTERNAL_BREAKPOINT64
;
386 typedef struct _DBGKD_BREAKPOINTEX
388 ULONG BreakPointCount
;
389 NTSTATUS ContinueStatus
;
390 } DBGKD_BREAKPOINTEX
, *PDBGKD_BREAKPOINTEX
;
392 typedef struct _DBGKD_SEARCH_MEMORY
396 ULONG64 SearchAddress
;
397 ULONG64 FoundAddress
;
399 ULONG64 SearchLength
;
401 } DBGKD_SEARCH_MEMORY
, *PDBGKD_SEARCH_MEMORY
;
403 typedef struct _DBGKD_GET_SET_BUS_DATA
410 } DBGKD_GET_SET_BUS_DATA
, *PDBGKD_GET_SET_BUS_DATA
;
412 typedef struct _DBGKD_FILL_MEMORY
417 USHORT PatternLength
;
418 } DBGKD_FILL_MEMORY
, *PDBGKD_FILL_MEMORY
;
420 typedef struct _DBGKD_QUERY_MEMORY
426 } DBGKD_QUERY_MEMORY
, *PDBGKD_QUERY_MEMORY
;
428 typedef struct _DBGKD_SWITCH_PARTITION
431 } DBGKD_SWITCH_PARTITION
;
434 // DBGKD Structure for Manipulate
436 typedef struct _DBGKD_MANIPULATE_STATE64
439 USHORT ProcessorLevel
;
441 NTSTATUS ReturnStatus
;
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
;
467 } DBGKD_MANIPULATE_STATE64
, *PDBGKD_MANIPULATE_STATE64
;
471 ExceptionRecord32To64(IN PEXCEPTION_RECORD32 Ex32
,
472 OUT PEXCEPTION_RECORD64 Ex64
)
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
;
482 for (i
= 0; i
< EXCEPTION_MAXIMUM_PARAMETERS
; i
++)
484 COPYSE(Ex64
,Ex32
,ExceptionInformation
[i
]);