2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Definition of remote debugger protocol.
30 #include <mach/vm_prot.h>
33 * Retransmit parameters
35 #if DDEBUG_DEBUG || DEBUG_DEBUG
36 #define KDP_REXMIT_SECS 20 /* rexmit if no ack in 3 secs */
37 #else /* DDEBUG_DEBUG || DEBUG_DEBUG */
38 #define KDP_REXMIT_SECS 3 /* rexmit if no ack in 3 secs */
39 #endif /* DDEBUG_DEBUG || DEBUG_DEBUG */
40 #define KDP_REXMIT_TRIES 8 /* xmit 8 times, then give up */
43 * (NMI) Attention Max Wait Time
44 * Remote will resume unless KDP requests is received within this
45 * many seconds after an attention (nmi) packet is sent.
47 #define KDP_MAX_ATTN_WAIT 30 /* wait max of 30 seconds */
50 * Well-known UDP port, debugger side.
51 * FIXME: This is what the 68K guys use, but beats me how they chose it...
53 #define KDP_REMOTE_PORT 41139 /* pick one and register it */
56 * UDP ports, KDB side. 5 port numbers are reserved for each port (request
57 * and exception). This allows multiple KDBs to run on one host.
59 #define UDP_HOST_COMM_BASE 41140
60 #define UDP_HOST_EXCEP_BASE 41145
61 #define NUM_UDP_HOST_PORTS 5
67 /* connection oriented requests */
68 KDP_CONNECT
, KDP_DISCONNECT
,
70 /* obtaining client info */
71 KDP_HOSTINFO
, KDP_VERSION
, KDP_MAXBYTES
,
74 KDP_READMEM
, KDP_WRITEMEM
,
77 KDP_READREGS
, KDP_WRITEREGS
,
79 /* executable image info */
80 KDP_LOAD
, KDP_IMAGEPATH
,
82 /* execution control */
83 KDP_SUSPEND
, KDP_RESUMECPUS
,
85 /* exception and termination notification, NOT true requests */
86 KDP_EXCEPTION
, KDP_TERMINATION
,
88 /* breakpoint control */
89 KDP_BREAKPOINT_SET
, KDP_BREAKPOINT_REMOVE
,
94 /* reattach to a connected host */
97 /* remote reboot request */
102 * Common KDP packet header
105 kdp_req_t request
:7; /* request type */
106 unsigned is_reply
:1; /* 0 => request, 1 => reply */
107 unsigned seq
:8; /* sequence number within session */
108 unsigned len
:16; /* length of entire pkt including hdr */
109 unsigned key
; /* session key */
117 KDPERR_ALREADY_CONNECTED
,
119 KDPERR_BADFLAVOR
/* bad flavor in w/r regs */
123 * KDP requests and reply packet formats
129 typedef struct { /* KDP_CONNECT request */
131 unsigned short req_reply_port
; /* udp port which to send replies */
132 unsigned short exc_note_port
; /* udp port which to send exc notes */
133 char greeting
[0]; /* "greetings", null-terminated */
136 typedef struct { /* KDP_CONNECT reply */
139 } kdp_connect_reply_t
;
144 typedef struct { /* KDP_DISCONNECT request */
146 } kdp_disconnect_req_t
;
148 typedef struct { /* KDP_DISCONNECT reply */
150 } kdp_disconnect_reply_t
;
157 unsigned short req_reply_port
; /* udp port which to send replies */
158 } kdp_reattach_req_t
;
163 typedef struct { /* KDP_HOSTINFO request */
165 } kdp_hostinfo_req_t
;
168 unsigned cpus_mask
; /* bit is 1 if cpu present */
173 typedef struct { /* KDP_HOSTINFO reply */
175 kdp_hostinfo_t hostinfo
;
176 } kdp_hostinfo_reply_t
;
181 typedef struct { /* KDP_VERSION request */
185 #define KDP_FEATURE_BP 0x1 /* local breakpoint support */
187 typedef struct { /* KDP_REGIONS reply */
193 } kdp_version_reply_t
;
198 typedef struct { /* KDP_REGIONS request */
202 #define VM_PROT_VOLATILE ((vm_prot_t) 0x08) /* not cacheable */
203 #define VM_PROT_SPARSE ((vm_prot_t) 0x10) /* sparse addr space */
208 vm_prot_t protection
;
211 typedef struct { /* KDP_REGIONS reply */
214 kdp_region_t regions
[0];
215 } kdp_regions_reply_t
;
220 typedef struct { /* KDP_MAXBYTES request */
222 } kdp_maxbytes_req_t
;
224 typedef struct { /* KDP_MAXBYTES reply */
227 } kdp_maxbytes_reply_t
;
232 typedef struct { /* KDP_READMEM request */
238 typedef struct { /* KDP_READMEM reply */
242 } kdp_readmem_reply_t
;
247 typedef struct { /* KDP_WRITEMEM request */
252 } kdp_writemem_req_t
;
254 typedef struct { /* KDP_WRITEMEM reply */
257 } kdp_writemem_reply_t
;
262 typedef struct { /* KDP_READREGS request */
266 } kdp_readregs_req_t
;
268 typedef struct { /* KDP_READREGS reply */
270 kdp_error_t error
; /* could be KDPERR_BADFLAVOR */
272 } kdp_readregs_reply_t
;
277 typedef struct { /* KDP_WRITEREGS request */
282 } kdp_writeregs_req_t
;
284 typedef struct { /* KDP_WRITEREGS reply */
287 } kdp_writeregs_reply_t
;
292 typedef struct { /* KDP_LOAD request */
297 typedef struct { /* KDP_LOAD reply */
305 typedef struct { /* KDP_IMAGEPATH request */
307 } kdp_imagepath_req_t
;
309 typedef struct { /* KDP_IMAGEPATH reply */
312 } kdp_imagepath_reply_t
;
317 typedef struct { /* KDP_SUSPEND request */
321 typedef struct { /* KDP_SUSPEND reply */
323 } kdp_suspend_reply_t
;
328 typedef struct { /* KDP_RESUMECPUS request */
331 } kdp_resumecpus_req_t
;
333 typedef struct { /* KDP_RESUMECPUS reply */
335 } kdp_resumecpus_reply_t
;
339 unsigned long address
;
340 } kdp_breakpoint_req_t
;
345 } kdp_breakpoint_reply_t
;
348 * Exception notifications
349 * (Exception notifications are not requests, and in fact travel from
350 * the remote debugger to the gdb agent KDB.)
352 typedef struct { /* exc. info for one cpu */
355 * Following info is defined as
356 * per <mach/exception.h>
363 typedef struct { /* KDP_EXCEPTION notification */
366 kdp_exc_info_t exc_info
[0];
369 typedef struct { /* KDP_EXCEPTION acknowledgement */
371 } kdp_exception_ack_t
;
374 * Child termination messages
377 KDP_FAULT
= 0, /* child took fault (internal use) */
378 KDP_EXIT
, /* child exited */
379 KDP_POWEROFF
, /* child power-off */
380 KDP_REBOOT
, /* child reboot */
381 KDP_COMMAND_MODE
/* child exit to mon command_mode */
382 } kdp_termination_code_t
;
384 typedef struct { /* KDP_TERMINATION notification */
386 kdp_termination_code_t term_code
;
392 } kdp_termination_ack_t
;
396 kdp_connect_req_t connect_req
;
397 kdp_connect_reply_t connect_reply
;
398 kdp_disconnect_req_t disconnect_req
;
399 kdp_disconnect_reply_t disconnect_reply
;
400 kdp_hostinfo_req_t hostinfo_req
;
401 kdp_hostinfo_reply_t hostinfo_reply
;
402 kdp_version_req_t version_req
;
403 kdp_version_reply_t version_reply
;
404 kdp_maxbytes_req_t maxbytes_req
;
405 kdp_maxbytes_reply_t maxbytes_reply
;
406 kdp_readmem_req_t readmem_req
;
407 kdp_readmem_reply_t readmem_reply
;
408 kdp_writemem_req_t writemem_req
;
409 kdp_writemem_reply_t writemem_reply
;
410 kdp_readregs_req_t readregs_req
;
411 kdp_readregs_reply_t readregs_reply
;
412 kdp_writeregs_req_t writeregs_req
;
413 kdp_writeregs_reply_t writeregs_reply
;
414 kdp_load_req_t load_req
;
415 kdp_load_reply_t load_reply
;
416 kdp_imagepath_req_t imagepath_req
;
417 kdp_imagepath_reply_t imagepath_reply
;
418 kdp_suspend_req_t suspend_req
;
419 kdp_suspend_reply_t suspend_reply
;
420 kdp_resumecpus_req_t resumecpus_req
;
421 kdp_resumecpus_reply_t resumecpus_reply
;
422 kdp_exception_t exception
;
423 kdp_exception_ack_t exception_ack
;
424 kdp_termination_t termination
;
425 kdp_termination_ack_t termination_ack
;
426 kdp_breakpoint_req_t breakpoint_req
;
427 kdp_breakpoint_reply_t breakpoint_reply
;
428 kdp_reattach_req_t reattach_req
;
429 kdp_regions_req_t regions_req
;
430 kdp_regions_reply_t regions_reply
;
433 #define MAX_KDP_PKT_SIZE 1200 /* max packet size */
434 #define MAX_KDP_DATA_SIZE 1024 /* max r/w data per packet */