2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Definition of remote debugger protocol.
28 #include <mach/vm_prot.h>
31 * Retransmit parameters
33 #if DDEBUG_DEBUG || DEBUG_DEBUG
34 #define KDP_REXMIT_SECS 20 /* rexmit if no ack in 3 secs */
35 #else /* DDEBUG_DEBUG || DEBUG_DEBUG */
36 #define KDP_REXMIT_SECS 3 /* rexmit if no ack in 3 secs */
37 #endif /* DDEBUG_DEBUG || DEBUG_DEBUG */
38 #define KDP_REXMIT_TRIES 8 /* xmit 8 times, then give up */
41 * (NMI) Attention Max Wait Time
42 * Remote will resume unless KDP requests is received within this
43 * many seconds after an attention (nmi) packet is sent.
45 #define KDP_MAX_ATTN_WAIT 30 /* wait max of 30 seconds */
48 * Well-known UDP port, debugger side.
49 * FIXME: This is what the 68K guys use, but beats me how they chose it...
51 #define KDP_REMOTE_PORT 41139 /* pick one and register it */
54 * UDP ports, KDB side. 5 port numbers are reserved for each port (request
55 * and exception). This allows multiple KDBs to run on one host.
57 #define UDP_HOST_COMM_BASE 41140
58 #define UDP_HOST_EXCEP_BASE 41145
59 #define NUM_UDP_HOST_PORTS 5
65 /* connection oriented requests */
66 KDP_CONNECT
, KDP_DISCONNECT
,
68 /* obtaining client info */
69 KDP_HOSTINFO
, KDP_VERSION
, KDP_MAXBYTES
,
72 KDP_READMEM
, KDP_WRITEMEM
,
75 KDP_READREGS
, KDP_WRITEREGS
,
77 /* executable image info */
78 KDP_LOAD
, KDP_IMAGEPATH
,
80 /* execution control */
81 KDP_SUSPEND
, KDP_RESUMECPUS
,
83 /* exception and termination notification, NOT true requests */
84 KDP_EXCEPTION
, KDP_TERMINATION
,
86 /* breakpoint control */
87 KDP_BREAKPOINT_SET
, KDP_BREAKPOINT_REMOVE
,
92 /* reattach to a connected host */
95 /* remote reboot request */
100 * Common KDP packet header
103 kdp_req_t request
:7; /* request type */
104 unsigned is_reply
:1; /* 0 => request, 1 => reply */
105 unsigned seq
:8; /* sequence number within session */
106 unsigned len
:16; /* length of entire pkt including hdr */
107 unsigned key
; /* session key */
115 KDPERR_ALREADY_CONNECTED
,
117 KDPERR_BADFLAVOR
/* bad flavor in w/r regs */
121 * KDP requests and reply packet formats
127 typedef struct { /* KDP_CONNECT request */
129 unsigned short req_reply_port
; /* udp port which to send replies */
130 unsigned short exc_note_port
; /* udp port which to send exc notes */
131 char greeting
[0]; /* "greetings", null-terminated */
134 typedef struct { /* KDP_CONNECT reply */
137 } kdp_connect_reply_t
;
142 typedef struct { /* KDP_DISCONNECT request */
144 } kdp_disconnect_req_t
;
146 typedef struct { /* KDP_DISCONNECT reply */
148 } kdp_disconnect_reply_t
;
155 unsigned short req_reply_port
; /* udp port which to send replies */
156 } kdp_reattach_req_t
;
161 typedef struct { /* KDP_HOSTINFO request */
163 } kdp_hostinfo_req_t
;
166 unsigned cpus_mask
; /* bit is 1 if cpu present */
171 typedef struct { /* KDP_HOSTINFO reply */
173 kdp_hostinfo_t hostinfo
;
174 } kdp_hostinfo_reply_t
;
179 typedef struct { /* KDP_VERSION request */
183 #define KDP_FEATURE_BP 0x1 /* local breakpoint support */
185 typedef struct { /* KDP_REGIONS reply */
191 } kdp_version_reply_t
;
196 typedef struct { /* KDP_REGIONS request */
200 #define VM_PROT_VOLATILE ((vm_prot_t) 0x08) /* not cacheable */
201 #define VM_PROT_SPARSE ((vm_prot_t) 0x10) /* sparse addr space */
206 vm_prot_t protection
;
209 typedef struct { /* KDP_REGIONS reply */
212 kdp_region_t regions
[0];
213 } kdp_regions_reply_t
;
218 typedef struct { /* KDP_MAXBYTES request */
220 } kdp_maxbytes_req_t
;
222 typedef struct { /* KDP_MAXBYTES reply */
225 } kdp_maxbytes_reply_t
;
230 typedef struct { /* KDP_READMEM request */
236 typedef struct { /* KDP_READMEM reply */
240 } kdp_readmem_reply_t
;
245 typedef struct { /* KDP_WRITEMEM request */
250 } kdp_writemem_req_t
;
252 typedef struct { /* KDP_WRITEMEM reply */
255 } kdp_writemem_reply_t
;
260 typedef struct { /* KDP_READREGS request */
264 } kdp_readregs_req_t
;
266 typedef struct { /* KDP_READREGS reply */
268 kdp_error_t error
; /* could be KDPERR_BADFLAVOR */
270 } kdp_readregs_reply_t
;
275 typedef struct { /* KDP_WRITEREGS request */
280 } kdp_writeregs_req_t
;
282 typedef struct { /* KDP_WRITEREGS reply */
285 } kdp_writeregs_reply_t
;
290 typedef struct { /* KDP_LOAD request */
295 typedef struct { /* KDP_LOAD reply */
303 typedef struct { /* KDP_IMAGEPATH request */
305 } kdp_imagepath_req_t
;
307 typedef struct { /* KDP_IMAGEPATH reply */
310 } kdp_imagepath_reply_t
;
315 typedef struct { /* KDP_SUSPEND request */
319 typedef struct { /* KDP_SUSPEND reply */
321 } kdp_suspend_reply_t
;
326 typedef struct { /* KDP_RESUMECPUS request */
329 } kdp_resumecpus_req_t
;
331 typedef struct { /* KDP_RESUMECPUS reply */
333 } kdp_resumecpus_reply_t
;
337 unsigned long address
;
338 } kdp_breakpoint_req_t
;
343 } kdp_breakpoint_reply_t
;
346 * Exception notifications
347 * (Exception notifications are not requests, and in fact travel from
348 * the remote debugger to the gdb agent KDB.)
350 typedef struct { /* exc. info for one cpu */
353 * Following info is defined as
354 * per <mach/exception.h>
361 typedef struct { /* KDP_EXCEPTION notification */
364 kdp_exc_info_t exc_info
[0];
367 typedef struct { /* KDP_EXCEPTION acknowledgement */
369 } kdp_exception_ack_t
;
372 * Child termination messages
375 KDP_FAULT
= 0, /* child took fault (internal use) */
376 KDP_EXIT
, /* child exited */
377 KDP_POWEROFF
, /* child power-off */
378 KDP_REBOOT
, /* child reboot */
379 KDP_COMMAND_MODE
/* child exit to mon command_mode */
380 } kdp_termination_code_t
;
382 typedef struct { /* KDP_TERMINATION notification */
384 kdp_termination_code_t term_code
;
390 } kdp_termination_ack_t
;
394 kdp_connect_req_t connect_req
;
395 kdp_connect_reply_t connect_reply
;
396 kdp_disconnect_req_t disconnect_req
;
397 kdp_disconnect_reply_t disconnect_reply
;
398 kdp_hostinfo_req_t hostinfo_req
;
399 kdp_hostinfo_reply_t hostinfo_reply
;
400 kdp_version_req_t version_req
;
401 kdp_version_reply_t version_reply
;
402 kdp_maxbytes_req_t maxbytes_req
;
403 kdp_maxbytes_reply_t maxbytes_reply
;
404 kdp_readmem_req_t readmem_req
;
405 kdp_readmem_reply_t readmem_reply
;
406 kdp_writemem_req_t writemem_req
;
407 kdp_writemem_reply_t writemem_reply
;
408 kdp_readregs_req_t readregs_req
;
409 kdp_readregs_reply_t readregs_reply
;
410 kdp_writeregs_req_t writeregs_req
;
411 kdp_writeregs_reply_t writeregs_reply
;
412 kdp_load_req_t load_req
;
413 kdp_load_reply_t load_reply
;
414 kdp_imagepath_req_t imagepath_req
;
415 kdp_imagepath_reply_t imagepath_reply
;
416 kdp_suspend_req_t suspend_req
;
417 kdp_suspend_reply_t suspend_reply
;
418 kdp_resumecpus_req_t resumecpus_req
;
419 kdp_resumecpus_reply_t resumecpus_reply
;
420 kdp_exception_t exception
;
421 kdp_exception_ack_t exception_ack
;
422 kdp_termination_t termination
;
423 kdp_termination_ack_t termination_ack
;
424 kdp_breakpoint_req_t breakpoint_req
;
425 kdp_breakpoint_reply_t breakpoint_reply
;
426 kdp_reattach_req_t reattach_req
;
427 kdp_regions_req_t regions_req
;
428 kdp_regions_reply_t regions_reply
;
431 #define MAX_KDP_PKT_SIZE 1200 /* max packet size */
432 #define MAX_KDP_DATA_SIZE 1024 /* max r/w data per packet */