Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * Definition of remote debugger protocol. */ #include <mach/vm_prot.h> /* * Retransmit parameters */ #if DDEBUG_DEBUG || DEBUG_DEBUG #define KDP_REXMIT_SECS 20 /* rexmit if no ack in 3 secs */ #else /* DDEBUG_DEBUG || DEBUG_DEBUG */ #define KDP_REXMIT_SECS 3 /* rexmit if no ack in 3 secs */ #endif /* DDEBUG_DEBUG || DEBUG_DEBUG */ #define KDP_REXMIT_TRIES 8 /* xmit 8 times, then give up */ /* * (NMI) Attention Max Wait Time * Remote will resume unless KDP requests is received within this * many seconds after an attention (nmi) packet is sent. */ #define KDP_MAX_ATTN_WAIT 30 /* wait max of 30 seconds */ /* * Well-known UDP port, debugger side. * FIXME: This is what the 68K guys use, but beats me how they chose it... */ #define KDP_REMOTE_PORT 41139 /* pick one and register it */ /* * UDP ports, KDB side. 5 port numbers are reserved for each port (request * and exception). This allows multiple KDBs to run on one host. */ #define UDP_HOST_COMM_BASE 41140 #define UDP_HOST_EXCEP_BASE 41145 #define NUM_UDP_HOST_PORTS 5 /* * Requests */ typedef enum { /* connection oriented requests */ KDP_CONNECT, KDP_DISCONNECT, /* obtaining client info */ KDP_HOSTINFO, KDP_VERSION, KDP_MAXBYTES, /* memory access */ KDP_READMEM, KDP_WRITEMEM, /* register access */ KDP_READREGS, KDP_WRITEREGS, /* executable image info */ KDP_LOAD, KDP_IMAGEPATH, /* execution control */ KDP_SUSPEND, KDP_RESUMECPUS, /* exception and termination notification, NOT true requests */ KDP_EXCEPTION, KDP_TERMINATION, /* breakpoint control */ KDP_BREAKPOINT_SET, KDP_BREAKPOINT_REMOVE, /* vm regions */ KDP_REGIONS, /* reattach to a connected host */ KDP_REATTACH, /* remote reboot request */ KDP_HOSTREBOOT } kdp_req_t; /* * Common KDP packet header */ typedef struct { kdp_req_t request:7; /* request type */ unsigned is_reply:1; /* 0 => request, 1 => reply */ unsigned seq:8; /* sequence number within session */ unsigned len:16; /* length of entire pkt including hdr */ unsigned key; /* session key */ } kdp_hdr_t; /* * KDP errors */ typedef enum { KDPERR_NO_ERROR = 0, KDPERR_ALREADY_CONNECTED, KDPERR_BAD_NBYTES, KDPERR_BADFLAVOR /* bad flavor in w/r regs */ } kdp_error_t; /* * KDP requests and reply packet formats */ /* * KDP_CONNECT */ typedef struct { /* KDP_CONNECT request */ kdp_hdr_t hdr; unsigned short req_reply_port; /* udp port which to send replies */ unsigned short exc_note_port; /* udp port which to send exc notes */ char greeting[0]; /* "greetings", null-terminated */ } kdp_connect_req_t; typedef struct { /* KDP_CONNECT reply */ kdp_hdr_t hdr; kdp_error_t error; } kdp_connect_reply_t; /* * KDP_DISCONNECT */ typedef struct { /* KDP_DISCONNECT request */ kdp_hdr_t hdr; } kdp_disconnect_req_t; typedef struct { /* KDP_DISCONNECT reply */ kdp_hdr_t hdr; } kdp_disconnect_reply_t; /* * KDP_REATTACH */ typedef struct { kdp_hdr_t hdr; unsigned short req_reply_port; /* udp port which to send replies */ } kdp_reattach_req_t; /* * KDP_HOSTINFO */ typedef struct { /* KDP_HOSTINFO request */ kdp_hdr_t hdr; } kdp_hostinfo_req_t; typedef struct { unsigned cpus_mask; /* bit is 1 if cpu present */ int cpu_type; int cpu_subtype; } kdp_hostinfo_t; typedef struct { /* KDP_HOSTINFO reply */ kdp_hdr_t hdr; kdp_hostinfo_t hostinfo; } kdp_hostinfo_reply_t; /* * KDP_VERSION */ typedef struct { /* KDP_VERSION request */ kdp_hdr_t hdr; } kdp_version_req_t; #define KDP_FEATURE_BP 0x1 /* local breakpoint support */ typedef struct { /* KDP_REGIONS reply */ kdp_hdr_t hdr; unsigned version; unsigned feature; unsigned pad0; unsigned pad1; } kdp_version_reply_t; /* * KDP_REGIONS */ typedef struct { /* KDP_REGIONS request */ kdp_hdr_t hdr; } kdp_regions_req_t; #define VM_PROT_VOLATILE ((vm_prot_t) 0x08) /* not cacheable */ #define VM_PROT_SPARSE ((vm_prot_t) 0x10) /* sparse addr space */ typedef struct { void *address; unsigned nbytes; vm_prot_t protection; } kdp_region_t; typedef struct { /* KDP_REGIONS reply */ kdp_hdr_t hdr; unsigned nregions; kdp_region_t regions[0]; } kdp_regions_reply_t; /* * KDP_MAXBYTES */ typedef struct { /* KDP_MAXBYTES request */ kdp_hdr_t hdr; } kdp_maxbytes_req_t; typedef struct { /* KDP_MAXBYTES reply */ kdp_hdr_t hdr; unsigned max_bytes; } kdp_maxbytes_reply_t; /* * KDP_READMEM */ typedef struct { /* KDP_READMEM request */ kdp_hdr_t hdr; void *address; unsigned nbytes; } kdp_readmem_req_t; typedef struct { /* KDP_READMEM reply */ kdp_hdr_t hdr; kdp_error_t error; char data[0]; } kdp_readmem_reply_t; /* * KDP_WRITEMEM */ typedef struct { /* KDP_WRITEMEM request */ kdp_hdr_t hdr; void *address; unsigned nbytes; char data[0]; } kdp_writemem_req_t; typedef struct { /* KDP_WRITEMEM reply */ kdp_hdr_t hdr; kdp_error_t error; } kdp_writemem_reply_t; /* * KDP_READREGS */ typedef struct { /* KDP_READREGS request */ kdp_hdr_t hdr; unsigned cpu; unsigned flavor; } kdp_readregs_req_t; typedef struct { /* KDP_READREGS reply */ kdp_hdr_t hdr; kdp_error_t error; /* could be KDPERR_BADFLAVOR */ char data[0]; } kdp_readregs_reply_t; /* * KDP_WRITEREGS */ typedef struct { /* KDP_WRITEREGS request */ kdp_hdr_t hdr; unsigned cpu; unsigned flavor; char data[0]; } kdp_writeregs_req_t; typedef struct { /* KDP_WRITEREGS reply */ kdp_hdr_t hdr; kdp_error_t error; } kdp_writeregs_reply_t; /* * KDP_LOAD */ typedef struct { /* KDP_LOAD request */ kdp_hdr_t hdr; char file_args[0]; } kdp_load_req_t; typedef struct { /* KDP_LOAD reply */ kdp_hdr_t hdr; kdp_error_t error; } kdp_load_reply_t; /* * KDP_IMAGEPATH */ typedef struct { /* KDP_IMAGEPATH request */ kdp_hdr_t hdr; } kdp_imagepath_req_t; typedef struct { /* KDP_IMAGEPATH reply */ kdp_hdr_t hdr; char path[0]; } kdp_imagepath_reply_t; /* * KDP_SUSPEND */ typedef struct { /* KDP_SUSPEND request */ kdp_hdr_t hdr; } kdp_suspend_req_t; typedef struct { /* KDP_SUSPEND reply */ kdp_hdr_t hdr; } kdp_suspend_reply_t; /* * KDP_RESUMECPUS */ typedef struct { /* KDP_RESUMECPUS request */ kdp_hdr_t hdr; unsigned cpu_mask; } kdp_resumecpus_req_t; typedef struct { /* KDP_RESUMECPUS reply */ kdp_hdr_t hdr; } kdp_resumecpus_reply_t; typedef struct { kdp_hdr_t hdr; unsigned long address; } kdp_breakpoint_req_t; typedef struct { kdp_hdr_t hdr; kdp_error_t error; } kdp_breakpoint_reply_t; /* * Exception notifications * (Exception notifications are not requests, and in fact travel from * the remote debugger to the gdb agent KDB.) */ typedef struct { /* exc. info for one cpu */ unsigned cpu; /* * Following info is defined as * per <mach/exception.h> */ unsigned exception; unsigned code; unsigned subcode; } kdp_exc_info_t; typedef struct { /* KDP_EXCEPTION notification */ kdp_hdr_t hdr; unsigned n_exc_info; kdp_exc_info_t exc_info[0]; } kdp_exception_t; typedef struct { /* KDP_EXCEPTION acknowledgement */ kdp_hdr_t hdr; } kdp_exception_ack_t; /* * Child termination messages */ typedef enum { KDP_FAULT = 0, /* child took fault (internal use) */ KDP_EXIT, /* child exited */ KDP_POWEROFF, /* child power-off */ KDP_REBOOT, /* child reboot */ KDP_COMMAND_MODE /* child exit to mon command_mode */ } kdp_termination_code_t; typedef struct { /* KDP_TERMINATION notification */ kdp_hdr_t hdr; kdp_termination_code_t term_code; unsigned exit_code; } kdp_termination_t; typedef struct { kdp_hdr_t hdr; } kdp_termination_ack_t; typedef union { kdp_hdr_t hdr; kdp_connect_req_t connect_req; kdp_connect_reply_t connect_reply; kdp_disconnect_req_t disconnect_req; kdp_disconnect_reply_t disconnect_reply; kdp_hostinfo_req_t hostinfo_req; kdp_hostinfo_reply_t hostinfo_reply; kdp_version_req_t version_req; kdp_version_reply_t version_reply; kdp_maxbytes_req_t maxbytes_req; kdp_maxbytes_reply_t maxbytes_reply; kdp_readmem_req_t readmem_req; kdp_readmem_reply_t readmem_reply; kdp_writemem_req_t writemem_req; kdp_writemem_reply_t writemem_reply; kdp_readregs_req_t readregs_req; kdp_readregs_reply_t readregs_reply; kdp_writeregs_req_t writeregs_req; kdp_writeregs_reply_t writeregs_reply; kdp_load_req_t load_req; kdp_load_reply_t load_reply; kdp_imagepath_req_t imagepath_req; kdp_imagepath_reply_t imagepath_reply; kdp_suspend_req_t suspend_req; kdp_suspend_reply_t suspend_reply; kdp_resumecpus_req_t resumecpus_req; kdp_resumecpus_reply_t resumecpus_reply; kdp_exception_t exception; kdp_exception_ack_t exception_ack; kdp_termination_t termination; kdp_termination_ack_t termination_ack; kdp_breakpoint_req_t breakpoint_req; kdp_breakpoint_reply_t breakpoint_reply; kdp_reattach_req_t reattach_req; kdp_regions_req_t regions_req; kdp_regions_reply_t regions_reply; } kdp_pkt_t; #define MAX_KDP_PKT_SIZE 1200 /* max packet size */ #define MAX_KDP_DATA_SIZE 1024 /* max r/w data per packet */ |