2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * Definition of remote debugger protocol.
35 #include <mach/vm_prot.h>
38 * Retransmit parameters
40 #if DDEBUG_DEBUG || DEBUG_DEBUG
41 #define KDP_REXMIT_SECS 20 /* rexmit if no ack in 3 secs */
42 #else /* DDEBUG_DEBUG || DEBUG_DEBUG */
43 #define KDP_REXMIT_SECS 3 /* rexmit if no ack in 3 secs */
44 #endif /* DDEBUG_DEBUG || DEBUG_DEBUG */
45 #define KDP_REXMIT_TRIES 8 /* xmit 8 times, then give up */
48 * (NMI) Attention Max Wait Time
49 * Remote will resume unless KDP requests is received within this
50 * many seconds after an attention (nmi) packet is sent.
52 #define KDP_MAX_ATTN_WAIT 30 /* wait max of 30 seconds */
55 * Well-known UDP port, debugger side.
56 * FIXME: This is what the 68K guys use, but beats me how they chose it...
58 #define KDP_REMOTE_PORT 41139 /* pick one and register it */
61 * UDP ports, KDB side. 5 port numbers are reserved for each port (request
62 * and exception). This allows multiple KDBs to run on one host.
64 #define UDP_HOST_COMM_BASE 41140
65 #define UDP_HOST_EXCEP_BASE 41145
66 #define NUM_UDP_HOST_PORTS 5
72 /* connection oriented requests */
73 KDP_CONNECT
, KDP_DISCONNECT
,
75 /* obtaining client info */
76 KDP_HOSTINFO
, KDP_VERSION
, KDP_MAXBYTES
,
79 KDP_READMEM
, KDP_WRITEMEM
,
82 KDP_READREGS
, KDP_WRITEREGS
,
84 /* executable image info */
85 KDP_LOAD
, KDP_IMAGEPATH
,
87 /* execution control */
88 KDP_SUSPEND
, KDP_RESUMECPUS
,
90 /* exception and termination notification, NOT true requests */
91 KDP_EXCEPTION
, KDP_TERMINATION
,
93 /* breakpoint control */
94 KDP_BREAKPOINT_SET
, KDP_BREAKPOINT_REMOVE
,
99 /* reattach to a connected host */
102 /* remote reboot request */
107 * Common KDP packet header
110 kdp_req_t request
:7; /* request type */
111 unsigned is_reply
:1; /* 0 => request, 1 => reply */
112 unsigned seq
:8; /* sequence number within session */
113 unsigned len
:16; /* length of entire pkt including hdr */
114 unsigned key
; /* session key */
122 KDPERR_ALREADY_CONNECTED
,
124 KDPERR_BADFLAVOR
/* bad flavor in w/r regs */
128 * KDP requests and reply packet formats
134 typedef struct { /* KDP_CONNECT request */
136 unsigned short req_reply_port
; /* udp port which to send replies */
137 unsigned short exc_note_port
; /* udp port which to send exc notes */
138 char greeting
[0]; /* "greetings", null-terminated */
141 typedef struct { /* KDP_CONNECT reply */
144 } kdp_connect_reply_t
;
149 typedef struct { /* KDP_DISCONNECT request */
151 } kdp_disconnect_req_t
;
153 typedef struct { /* KDP_DISCONNECT reply */
155 } kdp_disconnect_reply_t
;
162 unsigned short req_reply_port
; /* udp port which to send replies */
163 } kdp_reattach_req_t
;
168 typedef struct { /* KDP_HOSTINFO request */
170 } kdp_hostinfo_req_t
;
173 unsigned cpus_mask
; /* bit is 1 if cpu present */
178 typedef struct { /* KDP_HOSTINFO reply */
180 kdp_hostinfo_t hostinfo
;
181 } kdp_hostinfo_reply_t
;
186 typedef struct { /* KDP_VERSION request */
190 #define KDP_FEATURE_BP 0x1 /* local breakpoint support */
192 typedef struct { /* KDP_REGIONS reply */
198 } kdp_version_reply_t
;
203 typedef struct { /* KDP_REGIONS request */
207 #define VM_PROT_VOLATILE ((vm_prot_t) 0x08) /* not cacheable */
208 #define VM_PROT_SPARSE ((vm_prot_t) 0x10) /* sparse addr space */
213 vm_prot_t protection
;
216 typedef struct { /* KDP_REGIONS reply */
219 kdp_region_t regions
[0];
220 } kdp_regions_reply_t
;
225 typedef struct { /* KDP_MAXBYTES request */
227 } kdp_maxbytes_req_t
;
229 typedef struct { /* KDP_MAXBYTES reply */
232 } kdp_maxbytes_reply_t
;
237 typedef struct { /* KDP_READMEM request */
243 typedef struct { /* KDP_READMEM reply */
247 } kdp_readmem_reply_t
;
252 typedef struct { /* KDP_WRITEMEM request */
257 } kdp_writemem_req_t
;
259 typedef struct { /* KDP_WRITEMEM reply */
262 } kdp_writemem_reply_t
;
267 typedef struct { /* KDP_READREGS request */
271 } kdp_readregs_req_t
;
273 typedef struct { /* KDP_READREGS reply */
275 kdp_error_t error
; /* could be KDPERR_BADFLAVOR */
277 } kdp_readregs_reply_t
;
282 typedef struct { /* KDP_WRITEREGS request */
287 } kdp_writeregs_req_t
;
289 typedef struct { /* KDP_WRITEREGS reply */
292 } kdp_writeregs_reply_t
;
297 typedef struct { /* KDP_LOAD request */
302 typedef struct { /* KDP_LOAD reply */
310 typedef struct { /* KDP_IMAGEPATH request */
312 } kdp_imagepath_req_t
;
314 typedef struct { /* KDP_IMAGEPATH reply */
317 } kdp_imagepath_reply_t
;
322 typedef struct { /* KDP_SUSPEND request */
326 typedef struct { /* KDP_SUSPEND reply */
328 } kdp_suspend_reply_t
;
333 typedef struct { /* KDP_RESUMECPUS request */
336 } kdp_resumecpus_req_t
;
338 typedef struct { /* KDP_RESUMECPUS reply */
340 } kdp_resumecpus_reply_t
;
344 unsigned long address
;
345 } kdp_breakpoint_req_t
;
350 } kdp_breakpoint_reply_t
;
353 * Exception notifications
354 * (Exception notifications are not requests, and in fact travel from
355 * the remote debugger to the gdb agent KDB.)
357 typedef struct { /* exc. info for one cpu */
360 * Following info is defined as
361 * per <mach/exception.h>
368 typedef struct { /* KDP_EXCEPTION notification */
371 kdp_exc_info_t exc_info
[0];
374 typedef struct { /* KDP_EXCEPTION acknowledgement */
376 } kdp_exception_ack_t
;
379 * Child termination messages
382 KDP_FAULT
= 0, /* child took fault (internal use) */
383 KDP_EXIT
, /* child exited */
384 KDP_POWEROFF
, /* child power-off */
385 KDP_REBOOT
, /* child reboot */
386 KDP_COMMAND_MODE
/* child exit to mon command_mode */
387 } kdp_termination_code_t
;
389 typedef struct { /* KDP_TERMINATION notification */
391 kdp_termination_code_t term_code
;
397 } kdp_termination_ack_t
;
401 kdp_connect_req_t connect_req
;
402 kdp_connect_reply_t connect_reply
;
403 kdp_disconnect_req_t disconnect_req
;
404 kdp_disconnect_reply_t disconnect_reply
;
405 kdp_hostinfo_req_t hostinfo_req
;
406 kdp_hostinfo_reply_t hostinfo_reply
;
407 kdp_version_req_t version_req
;
408 kdp_version_reply_t version_reply
;
409 kdp_maxbytes_req_t maxbytes_req
;
410 kdp_maxbytes_reply_t maxbytes_reply
;
411 kdp_readmem_req_t readmem_req
;
412 kdp_readmem_reply_t readmem_reply
;
413 kdp_writemem_req_t writemem_req
;
414 kdp_writemem_reply_t writemem_reply
;
415 kdp_readregs_req_t readregs_req
;
416 kdp_readregs_reply_t readregs_reply
;
417 kdp_writeregs_req_t writeregs_req
;
418 kdp_writeregs_reply_t writeregs_reply
;
419 kdp_load_req_t load_req
;
420 kdp_load_reply_t load_reply
;
421 kdp_imagepath_req_t imagepath_req
;
422 kdp_imagepath_reply_t imagepath_reply
;
423 kdp_suspend_req_t suspend_req
;
424 kdp_suspend_reply_t suspend_reply
;
425 kdp_resumecpus_req_t resumecpus_req
;
426 kdp_resumecpus_reply_t resumecpus_reply
;
427 kdp_exception_t exception
;
428 kdp_exception_ack_t exception_ack
;
429 kdp_termination_t termination
;
430 kdp_termination_ack_t termination_ack
;
431 kdp_breakpoint_req_t breakpoint_req
;
432 kdp_breakpoint_reply_t breakpoint_reply
;
433 kdp_reattach_req_t reattach_req
;
434 kdp_regions_req_t regions_req
;
435 kdp_regions_reply_t regions_reply
;
438 #define MAX_KDP_PKT_SIZE 1200 /* max packet size */
439 #define MAX_KDP_DATA_SIZE 1024 /* max r/w data per packet */