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@
22 /* Copyright (c) 1991 by NeXT Computer, Inc.
24 * File: services/kdp.h
26 * Definition of remote debugger protocol.
29 * 27-Oct-91 Mike DeMoney (mike@next.com)
33 #include <mach/vm_prot.h>
36 * Retransmit parameters
38 #if DDEBUG_DEBUG || DEBUG_DEBUG
39 #define KDP_REXMIT_SECS 20 /* rexmit if no ack in 3 secs */
40 #else /* DDEBUG_DEBUG || DEBUG_DEBUG */
41 #define KDP_REXMIT_SECS 3 /* rexmit if no ack in 3 secs */
42 #endif /* DDEBUG_DEBUG || DEBUG_DEBUG */
43 #define KDP_REXMIT_TRIES 8 /* xmit 8 times, then give up */
46 * (NMI) Attention Max Wait Time
47 * Remote will resume unless KDP requests is received within this
48 * many seconds after an attention (nmi) packet is sent.
50 #define KDP_MAX_ATTN_WAIT 30 /* wait max of 30 seconds */
53 * Well-known UDP port, debugger side.
54 * FIXME: This is what the 68K guys use, but beats me how they chose it...
56 #define KDP_REMOTE_PORT 41139 /* pick one and register it */
59 * UDP ports, KDB side. 5 port numbers are reserved for each port (request
60 * and exception). This allows multiple KDBs to run on one host.
62 #define UDP_HOST_COMM_BASE 41140
63 #define UDP_HOST_EXCEP_BASE 41145
64 #define NUM_UDP_HOST_PORTS 5
70 /* connection oriented requests */
71 KDP_CONNECT
, KDP_DISCONNECT
,
73 /* obtaining client info */
74 KDP_HOSTINFO
, KDP_REGIONS
, KDP_MAXBYTES
,
77 KDP_READMEM
, KDP_WRITEMEM
,
80 KDP_READREGS
, KDP_WRITEREGS
,
82 /* executable image info */
83 KDP_LOAD
, KDP_IMAGEPATH
,
85 /* execution control */
86 KDP_SUSPEND
, KDP_RESUMECPUS
,
88 /* exception and termination notification, NOT true requests */
89 KDP_EXCEPTION
, KDP_TERMINATION
,
91 /* remote reboot request */
96 * Common KDP packet header
99 kdp_req_t request
:7; /* request type */
100 unsigned is_reply
:1; /* 0 => request, 1 => reply */
101 unsigned seq
:8; /* sequence number within session */
102 unsigned len
:16; /* length of entire pkt including hdr */
103 unsigned key
; /* session key */
111 KDPERR_ALREADY_CONNECTED
,
113 KDPERR_BADFLAVOR
/* bad flavor in w/r regs */
117 * KDP requests and reply packet formats
123 typedef struct { /* KDP_CONNECT request */
125 unsigned short req_reply_port
; /* udp port which to send replies */
126 unsigned short exc_note_port
; /* udp port which to send exc notes */
127 char greeting
[0]; /* "greetings", null-terminated */
130 typedef struct { /* KDP_CONNECT reply */
133 } kdp_connect_reply_t
;
138 typedef struct { /* KDP_DISCONNECT request */
140 } kdp_disconnect_req_t
;
142 typedef struct { /* KDP_DISCONNECT reply */
144 } kdp_disconnect_reply_t
;
149 typedef struct { /* KDP_HOSTINFO request */
151 } kdp_hostinfo_req_t
;
154 unsigned cpus_mask
; /* bit is 1 if cpu present */
159 typedef struct { /* KDP_HOSTINFO reply */
161 kdp_hostinfo_t hostinfo
;
162 } kdp_hostinfo_reply_t
;
167 typedef struct { /* KDP_REGIONS request */
171 #define VM_PROT_VOLATILE ((vm_prot_t) 0x08) /* not cacheable */
172 #define VM_PROT_SPARSE ((vm_prot_t) 0x10) /* sparse addr space */
177 vm_prot_t protection
;
180 typedef struct { /* KDP_REGIONS reply */
183 kdp_region_t regions
[0];
184 } kdp_regions_reply_t
;
189 typedef struct { /* KDP_MAXBYTES request */
191 } kdp_maxbytes_req_t
;
193 typedef struct { /* KDP_MAXBYTES reply */
196 } kdp_maxbytes_reply_t
;
201 typedef struct { /* KDP_READMEM request */
207 typedef struct { /* KDP_READMEM reply */
211 } kdp_readmem_reply_t
;
216 typedef struct { /* KDP_WRITEMEM request */
221 } kdp_writemem_req_t
;
223 typedef struct { /* KDP_WRITEMEM reply */
226 } kdp_writemem_reply_t
;
231 typedef struct { /* KDP_READREGS request */
235 } kdp_readregs_req_t
;
237 typedef struct { /* KDP_READREGS reply */
239 kdp_error_t error
; /* could be KDPERR_BADFLAVOR */
241 } kdp_readregs_reply_t
;
246 typedef struct { /* KDP_WRITEREGS request */
251 } kdp_writeregs_req_t
;
253 typedef struct { /* KDP_WRITEREGS reply */
256 } kdp_writeregs_reply_t
;
261 typedef struct { /* KDP_LOAD request */
266 typedef struct { /* KDP_LOAD reply */
274 typedef struct { /* KDP_IMAGEPATH request */
276 } kdp_imagepath_req_t
;
278 typedef struct { /* KDP_IMAGEPATH reply */
281 } kdp_imagepath_reply_t
;
286 typedef struct { /* KDP_SUSPEND request */
290 typedef struct { /* KDP_SUSPEND reply */
292 } kdp_suspend_reply_t
;
297 typedef struct { /* KDP_RESUMECPUS request */
300 } kdp_resumecpus_req_t
;
302 typedef struct { /* KDP_RESUMECPUS reply */
304 } kdp_resumecpus_reply_t
;
307 * Exception notifications
308 * (Exception notifications are not requests, and in fact travel from
309 * the remote debugger to the gdb agent KDB.)
311 typedef struct { /* exc. info for one cpu */
314 * Following info is defined as
315 * per <mach/exception.h>
322 typedef struct { /* KDP_EXCEPTION notification */
325 kdp_exc_info_t exc_info
[0];
328 typedef struct { /* KDP_EXCEPTION acknowledgement */
330 } kdp_exception_ack_t
;
333 * Child termination messages
336 KDP_FAULT
= 0, /* child took fault (internal use) */
337 KDP_EXIT
, /* child exited */
338 KDP_POWEROFF
, /* child power-off */
339 KDP_REBOOT
, /* child reboot */
340 KDP_COMMAND_MODE
/* child exit to mon command_mode */
341 } kdp_termination_code_t
;
343 typedef struct { /* KDP_TERMINATION notification */
345 kdp_termination_code_t term_code
;
351 } kdp_termination_ack_t
;
355 kdp_connect_req_t connect_req
;
356 kdp_connect_reply_t connect_reply
;
357 kdp_disconnect_req_t disconnect_req
;
358 kdp_disconnect_reply_t disconnect_reply
;
359 kdp_hostinfo_req_t hostinfo_req
;
360 kdp_hostinfo_reply_t hostinfo_reply
;
361 kdp_regions_req_t regions_req
;
362 kdp_regions_reply_t regions_reply
;
363 kdp_maxbytes_req_t maxbytes_req
;
364 kdp_maxbytes_reply_t maxbytes_reply
;
365 kdp_readmem_req_t readmem_req
;
366 kdp_readmem_reply_t readmem_reply
;
367 kdp_writemem_req_t writemem_req
;
368 kdp_writemem_reply_t writemem_reply
;
369 kdp_readregs_req_t readregs_req
;
370 kdp_readregs_reply_t readregs_reply
;
371 kdp_writeregs_req_t writeregs_req
;
372 kdp_writeregs_reply_t writeregs_reply
;
373 kdp_load_req_t load_req
;
374 kdp_load_reply_t load_reply
;
375 kdp_imagepath_req_t imagepath_req
;
376 kdp_imagepath_reply_t imagepath_reply
;
377 kdp_suspend_req_t suspend_req
;
378 kdp_suspend_reply_t suspend_reply
;
379 kdp_resumecpus_req_t resumecpus_req
;
380 kdp_resumecpus_reply_t resumecpus_reply
;
381 kdp_exception_t exception
;
382 kdp_exception_ack_t exception_ack
;
383 kdp_termination_t termination
;
384 kdp_termination_ack_t termination_ack
;
387 #define MAX_KDP_PKT_SIZE 1200 /* max packet size */
388 #define MAX_KDP_DATA_SIZE 1024 /* max r/w data per packet */