2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Definition of remote debugger protocol.
27 #include <mach/vm_prot.h>
30 * Retransmit parameters
32 #if DDEBUG_DEBUG || DEBUG_DEBUG
33 #define KDP_REXMIT_SECS 20 /* rexmit if no ack in 3 secs */
34 #else /* DDEBUG_DEBUG || DEBUG_DEBUG */
35 #define KDP_REXMIT_SECS 3 /* rexmit if no ack in 3 secs */
36 #endif /* DDEBUG_DEBUG || DEBUG_DEBUG */
37 #define KDP_REXMIT_TRIES 8 /* xmit 8 times, then give up */
40 * (NMI) Attention Max Wait Time
41 * Remote will resume unless KDP requests is received within this
42 * many seconds after an attention (nmi) packet is sent.
44 #define KDP_MAX_ATTN_WAIT 30 /* wait max of 30 seconds */
47 * Well-known UDP port, debugger side.
48 * FIXME: This is what the 68K guys use, but beats me how they chose it...
50 #define KDP_REMOTE_PORT 41139 /* pick one and register it */
53 * UDP ports, KDB side. 5 port numbers are reserved for each port (request
54 * and exception). This allows multiple KDBs to run on one host.
56 #define UDP_HOST_COMM_BASE 41140
57 #define UDP_HOST_EXCEP_BASE 41145
58 #define NUM_UDP_HOST_PORTS 5
64 /* connection oriented requests */
65 KDP_CONNECT
, KDP_DISCONNECT
,
67 /* obtaining client info */
68 KDP_HOSTINFO
, KDP_VERSION
, KDP_MAXBYTES
,
71 KDP_READMEM
, KDP_WRITEMEM
,
74 KDP_READREGS
, KDP_WRITEREGS
,
76 /* executable image info */
77 KDP_LOAD
, KDP_IMAGEPATH
,
79 /* execution control */
80 KDP_SUSPEND
, KDP_RESUMECPUS
,
82 /* exception and termination notification, NOT true requests */
83 KDP_EXCEPTION
, KDP_TERMINATION
,
85 /* breakpoint control */
86 KDP_BREAKPOINT_SET
, KDP_BREAKPOINT_REMOVE
,
91 /* reattach to a connected host */
94 /* remote reboot request */
99 * Common KDP packet header
102 kdp_req_t request
:7; /* request type */
103 unsigned is_reply
:1; /* 0 => request, 1 => reply */
104 unsigned seq
:8; /* sequence number within session */
105 unsigned len
:16; /* length of entire pkt including hdr */
106 unsigned key
; /* session key */
114 KDPERR_ALREADY_CONNECTED
,
116 KDPERR_BADFLAVOR
/* bad flavor in w/r regs */
120 * KDP requests and reply packet formats
126 typedef struct { /* KDP_CONNECT request */
128 unsigned short req_reply_port
; /* udp port which to send replies */
129 unsigned short exc_note_port
; /* udp port which to send exc notes */
130 char greeting
[0]; /* "greetings", null-terminated */
133 typedef struct { /* KDP_CONNECT reply */
136 } kdp_connect_reply_t
;
141 typedef struct { /* KDP_DISCONNECT request */
143 } kdp_disconnect_req_t
;
145 typedef struct { /* KDP_DISCONNECT reply */
147 } kdp_disconnect_reply_t
;
154 unsigned short req_reply_port
; /* udp port which to send replies */
155 } kdp_reattach_req_t
;
160 typedef struct { /* KDP_HOSTINFO request */
162 } kdp_hostinfo_req_t
;
165 unsigned cpus_mask
; /* bit is 1 if cpu present */
170 typedef struct { /* KDP_HOSTINFO reply */
172 kdp_hostinfo_t hostinfo
;
173 } kdp_hostinfo_reply_t
;
178 typedef struct { /* KDP_VERSION request */
182 #define KDP_FEATURE_BP 0x1 /* local breakpoint support */
184 typedef struct { /* KDP_REGIONS reply */
190 } kdp_version_reply_t
;
195 typedef struct { /* KDP_REGIONS request */
199 #define VM_PROT_VOLATILE ((vm_prot_t) 0x08) /* not cacheable */
200 #define VM_PROT_SPARSE ((vm_prot_t) 0x10) /* sparse addr space */
205 vm_prot_t protection
;
208 typedef struct { /* KDP_REGIONS reply */
211 kdp_region_t regions
[0];
212 } kdp_regions_reply_t
;
217 typedef struct { /* KDP_MAXBYTES request */
219 } kdp_maxbytes_req_t
;
221 typedef struct { /* KDP_MAXBYTES reply */
224 } kdp_maxbytes_reply_t
;
229 typedef struct { /* KDP_READMEM request */
235 typedef struct { /* KDP_READMEM reply */
239 } kdp_readmem_reply_t
;
244 typedef struct { /* KDP_WRITEMEM request */
249 } kdp_writemem_req_t
;
251 typedef struct { /* KDP_WRITEMEM reply */
254 } kdp_writemem_reply_t
;
259 typedef struct { /* KDP_READREGS request */
263 } kdp_readregs_req_t
;
265 typedef struct { /* KDP_READREGS reply */
267 kdp_error_t error
; /* could be KDPERR_BADFLAVOR */
269 } kdp_readregs_reply_t
;
274 typedef struct { /* KDP_WRITEREGS request */
279 } kdp_writeregs_req_t
;
281 typedef struct { /* KDP_WRITEREGS reply */
284 } kdp_writeregs_reply_t
;
289 typedef struct { /* KDP_LOAD request */
294 typedef struct { /* KDP_LOAD reply */
302 typedef struct { /* KDP_IMAGEPATH request */
304 } kdp_imagepath_req_t
;
306 typedef struct { /* KDP_IMAGEPATH reply */
309 } kdp_imagepath_reply_t
;
314 typedef struct { /* KDP_SUSPEND request */
318 typedef struct { /* KDP_SUSPEND reply */
320 } kdp_suspend_reply_t
;
325 typedef struct { /* KDP_RESUMECPUS request */
328 } kdp_resumecpus_req_t
;
330 typedef struct { /* KDP_RESUMECPUS reply */
332 } kdp_resumecpus_reply_t
;
336 unsigned long address
;
337 } kdp_breakpoint_req_t
;
342 } kdp_breakpoint_reply_t
;
345 * Exception notifications
346 * (Exception notifications are not requests, and in fact travel from
347 * the remote debugger to the gdb agent KDB.)
349 typedef struct { /* exc. info for one cpu */
352 * Following info is defined as
353 * per <mach/exception.h>
360 typedef struct { /* KDP_EXCEPTION notification */
363 kdp_exc_info_t exc_info
[0];
366 typedef struct { /* KDP_EXCEPTION acknowledgement */
368 } kdp_exception_ack_t
;
371 * Child termination messages
374 KDP_FAULT
= 0, /* child took fault (internal use) */
375 KDP_EXIT
, /* child exited */
376 KDP_POWEROFF
, /* child power-off */
377 KDP_REBOOT
, /* child reboot */
378 KDP_COMMAND_MODE
/* child exit to mon command_mode */
379 } kdp_termination_code_t
;
381 typedef struct { /* KDP_TERMINATION notification */
383 kdp_termination_code_t term_code
;
389 } kdp_termination_ack_t
;
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
;
430 #define MAX_KDP_PKT_SIZE 1200 /* max packet size */
431 #define MAX_KDP_DATA_SIZE 1024 /* max r/w data per packet */