1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <mach/vm_prot.h>
28
29
30
31
32#if DDEBUG_DEBUG || DEBUG_DEBUG
33#define KDP_REXMIT_SECS 20
34#else
35#define KDP_REXMIT_SECS 3
36#endif
37#define KDP_REXMIT_TRIES 8
38
39
40
41
42
43
44#define KDP_MAX_ATTN_WAIT 30
45
46
47
48
49
50#define KDP_REMOTE_PORT 41139
51
52
53
54
55
56#define UDP_HOST_COMM_BASE 41140
57#define UDP_HOST_EXCEP_BASE 41145
58#define NUM_UDP_HOST_PORTS 5
59
60
61
62
63typedef enum {
64
65 KDP_CONNECT, KDP_DISCONNECT,
66
67
68 KDP_HOSTINFO, KDP_VERSION, KDP_MAXBYTES,
69
70
71 KDP_READMEM, KDP_WRITEMEM,
72
73
74 KDP_READREGS, KDP_WRITEREGS,
75
76
77 KDP_LOAD, KDP_IMAGEPATH,
78
79
80 KDP_SUSPEND, KDP_RESUMECPUS,
81
82
83 KDP_EXCEPTION, KDP_TERMINATION,
84
85
86 KDP_BREAKPOINT_SET, KDP_BREAKPOINT_REMOVE,
87
88
89 KDP_REGIONS,
90
91
92 KDP_REATTACH,
93
94
95 KDP_HOSTREBOOT
96} kdp_req_t;
97
98
99
100
101typedef struct {
102 kdp_req_t request:7;
103 unsigned is_reply:1;
104 unsigned seq:8;
105 unsigned len:16;
106 unsigned key;
107} kdp_hdr_t;
108
109
110
111
112typedef enum {
113 KDPERR_NO_ERROR = 0,
114 KDPERR_ALREADY_CONNECTED,
115 KDPERR_BAD_NBYTES,
116 KDPERR_BADFLAVOR
117} kdp_error_t;
118
119
120
121
122
123
124
125
126typedef struct {
127 kdp_hdr_t hdr;
128 unsigned short req_reply_port;
129 unsigned short exc_note_port;
130 char greeting[0];
131} kdp_connect_req_t;
132
133typedef struct {
134 kdp_hdr_t hdr;
135 kdp_error_t error;
136} kdp_connect_reply_t;
137
138
139
140
141typedef struct {
142 kdp_hdr_t hdr;
143} kdp_disconnect_req_t;
144
145typedef struct {
146 kdp_hdr_t hdr;
147} kdp_disconnect_reply_t;
148
149
150
151
152typedef struct {
153 kdp_hdr_t hdr;
154 unsigned short req_reply_port;
155} kdp_reattach_req_t;
156
157
158
159
160typedef struct {
161 kdp_hdr_t hdr;
162} kdp_hostinfo_req_t;
163
164typedef struct {
165 unsigned cpus_mask;
166 int cpu_type;
167 int cpu_subtype;
168} kdp_hostinfo_t;
169
170typedef struct {
171 kdp_hdr_t hdr;
172 kdp_hostinfo_t hostinfo;
173} kdp_hostinfo_reply_t;
174
175
176
177
178typedef struct {
179 kdp_hdr_t hdr;
180} kdp_version_req_t;
181
182#define KDP_FEATURE_BP 0x1
183
184typedef struct {
185 kdp_hdr_t hdr;
186 unsigned version;
187 unsigned feature;
188 unsigned pad0;
189 unsigned pad1;
190} kdp_version_reply_t;
191
192
193
194
195typedef struct {
196 kdp_hdr_t hdr;
197} kdp_regions_req_t;
198
199#define VM_PROT_VOLATILE ((vm_prot_t) 0x08)
200#define VM_PROT_SPARSE ((vm_prot_t) 0x10)
201
202typedef struct {
203 void *address;
204 unsigned nbytes;
205 vm_prot_t protection;
206} kdp_region_t;
207
208typedef struct {
209 kdp_hdr_t hdr;
210 unsigned nregions;
211 kdp_region_t regions[0];
212} kdp_regions_reply_t;
213
214
215
216
217typedef struct {
218 kdp_hdr_t hdr;
219} kdp_maxbytes_req_t;
220
221typedef struct {
222 kdp_hdr_t hdr;
223 unsigned max_bytes;
224} kdp_maxbytes_reply_t;
225
226
227
228
229typedef struct {
230 kdp_hdr_t hdr;
231 void *address;
232 unsigned nbytes;
233} kdp_readmem_req_t;
234
235typedef struct {
236 kdp_hdr_t hdr;
237 kdp_error_t error;
238 char data[0];
239} kdp_readmem_reply_t;
240
241
242
243
244typedef struct {
245 kdp_hdr_t hdr;
246 void *address;
247 unsigned nbytes;
248 char data[0];
249} kdp_writemem_req_t;
250
251typedef struct {
252 kdp_hdr_t hdr;
253 kdp_error_t error;
254} kdp_writemem_reply_t;
255
256
257
258
259typedef struct {
260 kdp_hdr_t hdr;
261 unsigned cpu;
262 unsigned flavor;
263} kdp_readregs_req_t;
264
265typedef struct {
266 kdp_hdr_t hdr;
267 kdp_error_t error;
268 char data[0];
269} kdp_readregs_reply_t;
270
271
272
273
274typedef struct {
275 kdp_hdr_t hdr;
276 unsigned cpu;
277 unsigned flavor;
278 char data[0];
279} kdp_writeregs_req_t;
280
281typedef struct {
282 kdp_hdr_t hdr;
283 kdp_error_t error;
284} kdp_writeregs_reply_t;
285
286
287
288
289typedef struct {
290 kdp_hdr_t hdr;
291 char file_args[0];
292} kdp_load_req_t;
293
294typedef struct {
295 kdp_hdr_t hdr;
296 kdp_error_t error;
297} kdp_load_reply_t;
298
299
300
301
302typedef struct {
303 kdp_hdr_t hdr;
304} kdp_imagepath_req_t;
305
306typedef struct {
307 kdp_hdr_t hdr;
308 char path[0];
309} kdp_imagepath_reply_t;
310
311
312
313
314typedef struct {
315 kdp_hdr_t hdr;
316} kdp_suspend_req_t;
317
318typedef struct {
319 kdp_hdr_t hdr;
320} kdp_suspend_reply_t;
321
322
323
324
325typedef struct {
326 kdp_hdr_t hdr;
327 unsigned cpu_mask;
328} kdp_resumecpus_req_t;
329
330typedef struct {
331 kdp_hdr_t hdr;
332} kdp_resumecpus_reply_t;
333
334typedef struct {
335 kdp_hdr_t hdr;
336 unsigned long address;
337} kdp_breakpoint_req_t;
338
339typedef struct {
340 kdp_hdr_t hdr;
341 kdp_error_t error;
342} kdp_breakpoint_reply_t;
343
344
345
346
347
348
349typedef struct {
350 unsigned cpu;
351
352
353
354
355 unsigned exception;
356 unsigned code;
357 unsigned subcode;
358} kdp_exc_info_t;
359
360typedef struct {
361 kdp_hdr_t hdr;
362 unsigned n_exc_info;
363 kdp_exc_info_t exc_info[0];
364} kdp_exception_t;
365
366typedef struct {
367 kdp_hdr_t hdr;
368} kdp_exception_ack_t;
369
370
371
372
373typedef enum {
374 KDP_FAULT = 0,
375 KDP_EXIT,
376 KDP_POWEROFF,
377 KDP_REBOOT,
378 KDP_COMMAND_MODE
379} kdp_termination_code_t;
380
381typedef struct {
382 kdp_hdr_t hdr;
383 kdp_termination_code_t term_code;
384 unsigned exit_code;
385} kdp_termination_t;
386
387typedef struct {
388 kdp_hdr_t hdr;
389} kdp_termination_ack_t;
390
391typedef union {
392 kdp_hdr_t hdr;
393 kdp_connect_req_t connect_req;
394 kdp_connect_reply_t connect_reply;
395 kdp_disconnect_req_t disconnect_req;
396 kdp_disconnect_reply_t disconnect_reply;
397 kdp_hostinfo_req_t hostinfo_req;
398 kdp_hostinfo_reply_t hostinfo_reply;
399 kdp_version_req_t version_req;
400 kdp_version_reply_t version_reply;
401 kdp_maxbytes_req_t maxbytes_req;
402 kdp_maxbytes_reply_t maxbytes_reply;
403 kdp_readmem_req_t readmem_req;
404 kdp_readmem_reply_t readmem_reply;
405 kdp_writemem_req_t writemem_req;
406 kdp_writemem_reply_t writemem_reply;
407 kdp_readregs_req_t readregs_req;
408 kdp_readregs_reply_t readregs_reply;
409 kdp_writeregs_req_t writeregs_req;
410 kdp_writeregs_reply_t writeregs_reply;
411 kdp_load_req_t load_req;
412 kdp_load_reply_t load_reply;
413 kdp_imagepath_req_t imagepath_req;
414 kdp_imagepath_reply_t imagepath_reply;
415 kdp_suspend_req_t suspend_req;
416 kdp_suspend_reply_t suspend_reply;
417 kdp_resumecpus_req_t resumecpus_req;
418 kdp_resumecpus_reply_t resumecpus_reply;
419 kdp_exception_t exception;
420 kdp_exception_ack_t exception_ack;
421 kdp_termination_t termination;
422 kdp_termination_ack_t termination_ack;
423 kdp_breakpoint_req_t breakpoint_req;
424 kdp_breakpoint_reply_t breakpoint_reply;
425 kdp_reattach_req_t reattach_req;
426 kdp_regions_req_t regions_req;
427 kdp_regions_reply_t regions_reply;
428} kdp_pkt_t;
429
430#define MAX_KDP_PKT_SIZE 1200
431#define MAX_KDP_DATA_SIZE 1024
432