| 1 | /* Remote debugging for the ARM RDP interface. |
| 2 | Copyright 1994, 1995, 1998, 1999, 2000, 2001 |
| 3 | Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | Boston, MA 02111-1307, USA. |
| 21 | |
| 22 | |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | /* |
| 27 | Much of this file (in particular the SWI stuff) is based on code by |
| 28 | David Taylor (djt1000@uk.ac.cam.hermes). |
| 29 | |
| 30 | I hacked on and simplified it by removing a lot of sexy features he |
| 31 | had added, and some of the (unix specific) workarounds he'd done |
| 32 | for other GDB problems - which if they still exist should be fixed |
| 33 | in GDB, not in a remote-foo thing . I also made it conform more to |
| 34 | the doc I have; which may be wrong. |
| 35 | |
| 36 | Steve Chamberlain (sac@cygnus.com). |
| 37 | */ |
| 38 | |
| 39 | |
| 40 | #include "defs.h" |
| 41 | #include "inferior.h" |
| 42 | #include "value.h" |
| 43 | #include "callback.h" |
| 44 | #include "command.h" |
| 45 | #include <ctype.h> |
| 46 | #include <fcntl.h> |
| 47 | #include "symfile.h" |
| 48 | #include "remote-utils.h" |
| 49 | #include "gdb_string.h" |
| 50 | #include "gdbcore.h" |
| 51 | #include "regcache.h" |
| 52 | |
| 53 | #ifdef HAVE_TIME_H |
| 54 | #include <time.h> |
| 55 | #endif |
| 56 | |
| 57 | extern struct target_ops remote_rdp_ops; |
| 58 | static serial_t io; |
| 59 | static host_callback *callback = &default_callback; |
| 60 | |
| 61 | struct |
| 62 | { |
| 63 | int step_info; |
| 64 | int break_info; |
| 65 | int model_info; |
| 66 | int target_info; |
| 67 | int can_step; |
| 68 | char command_line[10]; |
| 69 | int rdi_level; |
| 70 | int rdi_stopped_status; |
| 71 | } |
| 72 | ds; |
| 73 | |
| 74 | |
| 75 | |
| 76 | /* Definitions for the RDP protocol. */ |
| 77 | |
| 78 | #define RDP_MOUTHFULL (1<<6) |
| 79 | #define FPU_COPRO_NUMBER 1 |
| 80 | |
| 81 | #define RDP_OPEN 0 |
| 82 | #define RDP_OPEN_TYPE_COLD 0 |
| 83 | #define RDP_OPEN_TYPE_WARM 1 |
| 84 | #define RDP_OPEN_TYPE_BAUDRATE 2 |
| 85 | |
| 86 | #define RDP_OPEN_BAUDRATE_9600 1 |
| 87 | #define RDP_OPEN_BAUDRATE_19200 2 |
| 88 | #define RDP_OPEN_BAUDRATE_38400 3 |
| 89 | |
| 90 | #define RDP_OPEN_TYPE_RETURN_SEX (1<<3) |
| 91 | |
| 92 | #define RDP_CLOSE 1 |
| 93 | |
| 94 | #define RDP_MEM_READ 2 |
| 95 | |
| 96 | #define RDP_MEM_WRITE 3 |
| 97 | |
| 98 | #define RDP_CPU_READ 4 |
| 99 | #define RDP_CPU_WRITE 5 |
| 100 | #define RDP_CPU_READWRITE_MODE_CURRENT 255 |
| 101 | #define RDP_CPU_READWRITE_MASK_PC (1<<16) |
| 102 | #define RDP_CPU_READWRITE_MASK_CPSR (1<<17) |
| 103 | #define RDP_CPU_READWRITE_MASK_SPSR (1<<18) |
| 104 | |
| 105 | #define RDP_COPRO_READ 6 |
| 106 | #define RDP_COPRO_WRITE 7 |
| 107 | #define RDP_FPU_READWRITE_MASK_FPS (1<<8) |
| 108 | |
| 109 | #define RDP_SET_BREAK 0xa |
| 110 | #define RDP_SET_BREAK_TYPE_PC_EQUAL 0 |
| 111 | #define RDP_SET_BREAK_TYPE_GET_HANDLE (0x10) |
| 112 | |
| 113 | #define RDP_CLEAR_BREAK 0xb |
| 114 | |
| 115 | #define RDP_EXEC 0x10 |
| 116 | #define RDP_EXEC_TYPE_SYNC 0 |
| 117 | |
| 118 | #define RDP_STEP 0x11 |
| 119 | |
| 120 | #define RDP_INFO 0x12 |
| 121 | #define RDP_INFO_ABOUT_STEP 2 |
| 122 | #define RDP_INFO_ABOUT_STEP_GT_1 1 |
| 123 | #define RDP_INFO_ABOUT_STEP_TO_JMP 2 |
| 124 | #define RDP_INFO_ABOUT_STEP_1 4 |
| 125 | #define RDP_INFO_ABOUT_TARGET 0 |
| 126 | #define RDP_INFO_ABOUT_BREAK 1 |
| 127 | #define RDP_INFO_ABOUT_BREAK_COMP 1 |
| 128 | #define RDP_INFO_ABOUT_BREAK_RANGE 2 |
| 129 | #define RDP_INFO_ABOUT_BREAK_BYTE_READ 4 |
| 130 | #define RDP_INFO_ABOUT_BREAK_HALFWORD_READ 8 |
| 131 | #define RDP_INFO_ABOUT_BREAK_WORD_READ (1<<4) |
| 132 | #define RDP_INFO_ABOUT_BREAK_BYTE_WRITE (1<<5) |
| 133 | #define RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE (1<<6) |
| 134 | #define RDP_INFO_ABOUT_BREAK_WORD_WRITE (1<<7) |
| 135 | #define RDP_INFO_ABOUT_BREAK_MASK (1<<8) |
| 136 | #define RDP_INFO_ABOUT_BREAK_THREAD_BREAK (1<<9) |
| 137 | #define RDP_INFO_ABOUT_BREAK_THREAD_WATCH (1<<10) |
| 138 | #define RDP_INFO_ABOUT_BREAK_COND (1<<11) |
| 139 | #define RDP_INFO_VECTOR_CATCH (0x180) |
| 140 | #define RDP_INFO_ICEBREAKER (7) |
| 141 | #define RDP_INFO_SET_CMDLINE (0x300) |
| 142 | |
| 143 | #define RDP_SELECT_CONFIG (0x16) |
| 144 | #define RDI_ConfigCPU 0 |
| 145 | #define RDI_ConfigSystem 1 |
| 146 | #define RDI_MatchAny 0 |
| 147 | #define RDI_MatchExactly 1 |
| 148 | #define RDI_MatchNoEarlier 2 |
| 149 | |
| 150 | #define RDP_RESET 0x7f |
| 151 | |
| 152 | /* Returns from RDP */ |
| 153 | #define RDP_RES_STOPPED 0x20 |
| 154 | #define RDP_RES_SWI 0x21 |
| 155 | #define RDP_RES_FATAL 0x5e |
| 156 | #define RDP_RES_VALUE 0x5f |
| 157 | #define RDP_RES_VALUE_LITTLE_ENDIAN 240 |
| 158 | #define RDP_RES_VALUE_BIG_ENDIAN 241 |
| 159 | #define RDP_RES_RESET 0x7f |
| 160 | #define RDP_RES_AT_BREAKPOINT 143 |
| 161 | #define RDP_RES_IDUNNO 0xe6 |
| 162 | #define RDP_OSOpReply 0x13 |
| 163 | #define RDP_OSOpWord 2 |
| 164 | #define RDP_OSOpNothing 0 |
| 165 | |
| 166 | static int timeout = 2; |
| 167 | |
| 168 | static char *commandline = NULL; |
| 169 | |
| 170 | static int |
| 171 | remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, |
| 172 | int write, |
| 173 | struct mem_attrib *attrib, |
| 174 | struct target_ops *target); |
| 175 | |
| 176 | |
| 177 | /* Stuff for talking to the serial layer. */ |
| 178 | |
| 179 | static unsigned char |
| 180 | get_byte (void) |
| 181 | { |
| 182 | int c = SERIAL_READCHAR (io, timeout); |
| 183 | |
| 184 | if (remote_debug) |
| 185 | fprintf_unfiltered (gdb_stdlog, "[%02x]\n", c); |
| 186 | |
| 187 | if (c == SERIAL_TIMEOUT) |
| 188 | { |
| 189 | if (timeout == 0) |
| 190 | return (unsigned char) c; |
| 191 | |
| 192 | error ("Timeout reading from remote_system"); |
| 193 | } |
| 194 | |
| 195 | return c; |
| 196 | } |
| 197 | |
| 198 | /* Note that the target always speaks little-endian to us, |
| 199 | even if it's a big endian machine. */ |
| 200 | static unsigned int |
| 201 | get_word (void) |
| 202 | { |
| 203 | unsigned int val = 0; |
| 204 | unsigned int c; |
| 205 | int n; |
| 206 | for (n = 0; n < 4; n++) |
| 207 | { |
| 208 | c = get_byte (); |
| 209 | val |= c << (n * 8); |
| 210 | } |
| 211 | return val; |
| 212 | } |
| 213 | |
| 214 | static void |
| 215 | put_byte (char val) |
| 216 | { |
| 217 | if (remote_debug) |
| 218 | fprintf_unfiltered (gdb_stdlog, "(%02x)\n", val); |
| 219 | SERIAL_WRITE (io, &val, 1); |
| 220 | } |
| 221 | |
| 222 | static void |
| 223 | put_word (int val) |
| 224 | { |
| 225 | /* We always send in little endian */ |
| 226 | unsigned char b[4]; |
| 227 | b[0] = val; |
| 228 | b[1] = val >> 8; |
| 229 | b[2] = val >> 16; |
| 230 | b[3] = val >> 24; |
| 231 | |
| 232 | if (remote_debug) |
| 233 | fprintf_unfiltered (gdb_stdlog, "(%04x)", val); |
| 234 | |
| 235 | SERIAL_WRITE (io, b, 4); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | |
| 240 | /* Stuff for talking to the RDP layer. */ |
| 241 | |
| 242 | /* This is a bit more fancy that need be so that it syncs even in nasty cases. |
| 243 | |
| 244 | I'be been unable to make it reliably sync up with the change |
| 245 | baudrate open command. It likes to sit and say it's been reset, |
| 246 | with no more action. So I took all that code out. I'd rather sync |
| 247 | reliably at 9600 than wait forever for a possible 19200 connection. |
| 248 | |
| 249 | */ |
| 250 | static void |
| 251 | rdp_init (int cold, int tty) |
| 252 | { |
| 253 | int sync = 0; |
| 254 | int type = cold ? RDP_OPEN_TYPE_COLD : RDP_OPEN_TYPE_WARM; |
| 255 | int baudtry = 9600; |
| 256 | |
| 257 | time_t now = time (0); |
| 258 | time_t stop_time = now + 10; /* Try and sync for 10 seconds, then give up */ |
| 259 | |
| 260 | |
| 261 | while (time (0) < stop_time && !sync) |
| 262 | { |
| 263 | int restype; |
| 264 | QUIT; |
| 265 | |
| 266 | SERIAL_FLUSH_INPUT (io); |
| 267 | SERIAL_FLUSH_OUTPUT (io); |
| 268 | |
| 269 | if (tty) |
| 270 | printf_unfiltered ("Trying to connect at %d baud.\n", baudtry); |
| 271 | |
| 272 | /* |
| 273 | ** It seems necessary to reset an EmbeddedICE to get it going. |
| 274 | ** This has the side benefit of displaying the startup banner. |
| 275 | */ |
| 276 | if (cold) |
| 277 | { |
| 278 | put_byte (RDP_RESET); |
| 279 | while ((restype = SERIAL_READCHAR (io, 1)) > 0) |
| 280 | { |
| 281 | switch (restype) |
| 282 | { |
| 283 | case SERIAL_TIMEOUT: |
| 284 | break; |
| 285 | case RDP_RESET: |
| 286 | /* Sent at start of reset process: ignore */ |
| 287 | break; |
| 288 | default: |
| 289 | printf_unfiltered ("%c", isgraph (restype) ? restype : ' '); |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | if (restype == 0) |
| 295 | { |
| 296 | /* Got end-of-banner mark */ |
| 297 | printf_filtered ("\n"); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | put_byte (RDP_OPEN); |
| 302 | |
| 303 | put_byte (type | RDP_OPEN_TYPE_RETURN_SEX); |
| 304 | put_word (0); |
| 305 | |
| 306 | while (!sync && (restype = SERIAL_READCHAR (io, 1)) > 0) |
| 307 | { |
| 308 | if (remote_debug) |
| 309 | fprintf_unfiltered (gdb_stdlog, "[%02x]\n", restype); |
| 310 | |
| 311 | switch (restype) |
| 312 | { |
| 313 | case SERIAL_TIMEOUT: |
| 314 | break; |
| 315 | |
| 316 | case RDP_RESET: |
| 317 | while ((restype = SERIAL_READCHAR (io, 1)) == RDP_RESET) |
| 318 | ; |
| 319 | do |
| 320 | { |
| 321 | printf_unfiltered ("%c", isgraph (restype) ? restype : ' '); |
| 322 | } |
| 323 | while ((restype = SERIAL_READCHAR (io, 1)) > 0); |
| 324 | |
| 325 | if (tty) |
| 326 | { |
| 327 | printf_unfiltered ("\nThe board has sent notification that it was reset.\n"); |
| 328 | printf_unfiltered ("Waiting for it to settle down...\n"); |
| 329 | } |
| 330 | sleep (3); |
| 331 | if (tty) |
| 332 | printf_unfiltered ("\nTrying again.\n"); |
| 333 | cold = 0; |
| 334 | break; |
| 335 | |
| 336 | default: |
| 337 | break; |
| 338 | |
| 339 | case RDP_RES_VALUE: |
| 340 | { |
| 341 | int resval = SERIAL_READCHAR (io, 1); |
| 342 | |
| 343 | if (remote_debug) |
| 344 | fprintf_unfiltered (gdb_stdlog, "[%02x]\n", resval); |
| 345 | |
| 346 | switch (resval) |
| 347 | { |
| 348 | case SERIAL_TIMEOUT: |
| 349 | break; |
| 350 | case RDP_RES_VALUE_LITTLE_ENDIAN: |
| 351 | target_byte_order = LITTLE_ENDIAN; |
| 352 | sync = 1; |
| 353 | break; |
| 354 | case RDP_RES_VALUE_BIG_ENDIAN: |
| 355 | target_byte_order = BIG_ENDIAN; |
| 356 | sync = 1; |
| 357 | break; |
| 358 | default: |
| 359 | break; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | if (!sync) |
| 367 | { |
| 368 | error ("Couldn't reset the board, try pressing the reset button"); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | |
| 373 | void |
| 374 | send_rdp (char *template,...) |
| 375 | { |
| 376 | char buf[200]; |
| 377 | char *dst = buf; |
| 378 | va_list alist; |
| 379 | va_start (alist, template); |
| 380 | |
| 381 | while (*template) |
| 382 | { |
| 383 | unsigned int val; |
| 384 | int *pi; |
| 385 | int *pstat; |
| 386 | char *pc; |
| 387 | int i; |
| 388 | switch (*template++) |
| 389 | { |
| 390 | case 'b': |
| 391 | val = va_arg (alist, int); |
| 392 | *dst++ = val; |
| 393 | break; |
| 394 | case 'w': |
| 395 | val = va_arg (alist, int); |
| 396 | *dst++ = val; |
| 397 | *dst++ = val >> 8; |
| 398 | *dst++ = val >> 16; |
| 399 | *dst++ = val >> 24; |
| 400 | break; |
| 401 | case 'S': |
| 402 | val = get_byte (); |
| 403 | if (val != RDP_RES_VALUE) |
| 404 | { |
| 405 | printf_unfiltered ("got bad res value of %d, %x\n", val, val); |
| 406 | } |
| 407 | break; |
| 408 | case 'V': |
| 409 | pstat = va_arg (alist, int *); |
| 410 | pi = va_arg (alist, int *); |
| 411 | |
| 412 | *pstat = get_byte (); |
| 413 | /* Check the result was zero, if not read the syndrome */ |
| 414 | if (*pstat) |
| 415 | { |
| 416 | *pi = get_word (); |
| 417 | } |
| 418 | break; |
| 419 | case 'Z': |
| 420 | /* Check the result code */ |
| 421 | switch (get_byte ()) |
| 422 | { |
| 423 | case 0: |
| 424 | /* Success */ |
| 425 | break; |
| 426 | case 253: |
| 427 | /* Target can't do it; never mind */ |
| 428 | printf_unfiltered ("RDP: Insufficient privilege\n"); |
| 429 | return; |
| 430 | case 254: |
| 431 | /* Target can't do it; never mind */ |
| 432 | printf_unfiltered ("RDP: Unimplemented message\n"); |
| 433 | return; |
| 434 | case 255: |
| 435 | error ("Command garbled"); |
| 436 | break; |
| 437 | default: |
| 438 | error ("Corrupt reply from target"); |
| 439 | break; |
| 440 | } |
| 441 | break; |
| 442 | case 'W': |
| 443 | /* Read a word from the target */ |
| 444 | pi = va_arg (alist, int *); |
| 445 | *pi = get_word (); |
| 446 | break; |
| 447 | case 'P': |
| 448 | /* Read in some bytes from the target. */ |
| 449 | pc = va_arg (alist, char *); |
| 450 | val = va_arg (alist, int); |
| 451 | for (i = 0; i < val; i++) |
| 452 | { |
| 453 | pc[i] = get_byte (); |
| 454 | } |
| 455 | break; |
| 456 | case 'p': |
| 457 | /* send what's being pointed at */ |
| 458 | pc = va_arg (alist, char *); |
| 459 | val = va_arg (alist, int); |
| 460 | dst = buf; |
| 461 | SERIAL_WRITE (io, pc, val); |
| 462 | break; |
| 463 | case '-': |
| 464 | /* Send whats in the queue */ |
| 465 | if (dst != buf) |
| 466 | { |
| 467 | SERIAL_WRITE (io, buf, dst - buf); |
| 468 | dst = buf; |
| 469 | } |
| 470 | break; |
| 471 | case 'B': |
| 472 | pi = va_arg (alist, int *); |
| 473 | *pi = get_byte (); |
| 474 | break; |
| 475 | default: |
| 476 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
| 477 | } |
| 478 | } |
| 479 | va_end (alist); |
| 480 | |
| 481 | if (dst != buf) |
| 482 | internal_error (__FILE__, __LINE__, "failed internal consistency check"); |
| 483 | } |
| 484 | |
| 485 | |
| 486 | static int |
| 487 | rdp_write (CORE_ADDR memaddr, char *buf, int len) |
| 488 | { |
| 489 | int res; |
| 490 | int val; |
| 491 | |
| 492 | send_rdp ("bww-p-SV", RDP_MEM_WRITE, memaddr, len, buf, len, &res, &val); |
| 493 | |
| 494 | if (res) |
| 495 | { |
| 496 | return val; |
| 497 | } |
| 498 | return len; |
| 499 | } |
| 500 | |
| 501 | |
| 502 | static int |
| 503 | rdp_read (CORE_ADDR memaddr, char *buf, int len) |
| 504 | { |
| 505 | int res; |
| 506 | int val; |
| 507 | send_rdp ("bww-S-P-V", |
| 508 | RDP_MEM_READ, memaddr, len, |
| 509 | buf, len, |
| 510 | &res, &val); |
| 511 | if (res) |
| 512 | { |
| 513 | return val; |
| 514 | } |
| 515 | return len; |
| 516 | } |
| 517 | |
| 518 | static void |
| 519 | rdp_fetch_one_register (int mask, char *buf) |
| 520 | { |
| 521 | int val; |
| 522 | send_rdp ("bbw-SWZ", RDP_CPU_READ, RDP_CPU_READWRITE_MODE_CURRENT, mask, &val); |
| 523 | store_signed_integer (buf, 4, val); |
| 524 | } |
| 525 | |
| 526 | static void |
| 527 | rdp_fetch_one_fpu_register (int mask, char *buf) |
| 528 | { |
| 529 | #if 0 |
| 530 | /* !!! Since the PIE board doesn't work as documented, |
| 531 | and it doesn't have FPU hardware anyway and since it |
| 532 | slows everything down, I've disabled this. */ |
| 533 | int val; |
| 534 | if (mask == RDP_FPU_READWRITE_MASK_FPS) |
| 535 | { |
| 536 | /* this guy is only a word */ |
| 537 | send_rdp ("bbw-SWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, &val); |
| 538 | store_signed_integer (buf, 4, val); |
| 539 | } |
| 540 | else |
| 541 | { |
| 542 | /* There are 12 bytes long |
| 543 | !! fixme about endianness |
| 544 | */ |
| 545 | int dummy; /* I've seen these come back as four words !! */ |
| 546 | send_rdp ("bbw-SWWWWZ", RDP_COPRO_READ, FPU_COPRO_NUMBER, mask, buf + 0, buf + 4, buf + 8, &dummy); |
| 547 | } |
| 548 | #endif |
| 549 | memset (buf, 0, MAX_REGISTER_RAW_SIZE); |
| 550 | } |
| 551 | |
| 552 | |
| 553 | static void |
| 554 | rdp_store_one_register (int mask, char *buf) |
| 555 | { |
| 556 | int val = extract_unsigned_integer (buf, 4); |
| 557 | |
| 558 | send_rdp ("bbww-SZ", |
| 559 | RDP_CPU_WRITE, RDP_CPU_READWRITE_MODE_CURRENT, mask, val); |
| 560 | } |
| 561 | |
| 562 | |
| 563 | static void |
| 564 | rdp_store_one_fpu_register (int mask, char *buf) |
| 565 | { |
| 566 | #if 0 |
| 567 | /* See comment in fetch_one_fpu_register */ |
| 568 | if (mask == RDP_FPU_READWRITE_MASK_FPS) |
| 569 | { |
| 570 | int val = extract_unsigned_integer (buf, 4); |
| 571 | /* this guy is only a word */ |
| 572 | send_rdp ("bbww-SZ", RDP_COPRO_WRITE, |
| 573 | FPU_COPRO_NUMBER, |
| 574 | mask, val); |
| 575 | } |
| 576 | else |
| 577 | { |
| 578 | /* There are 12 bytes long |
| 579 | !! fixme about endianness |
| 580 | */ |
| 581 | int dummy = 0; |
| 582 | /* I've seen these come as four words, not the three advertized !! */ |
| 583 | printf ("Sending mask %x\n", mask); |
| 584 | send_rdp ("bbwwwww-SZ", |
| 585 | RDP_COPRO_WRITE, |
| 586 | FPU_COPRO_NUMBER, |
| 587 | mask, |
| 588 | *(int *) (buf + 0), |
| 589 | *(int *) (buf + 4), |
| 590 | *(int *) (buf + 8), |
| 591 | 0); |
| 592 | |
| 593 | printf ("done mask %x\n", mask); |
| 594 | } |
| 595 | #endif |
| 596 | } |
| 597 | \f |
| 598 | |
| 599 | /* Convert between GDB requests and the RDP layer. */ |
| 600 | |
| 601 | static void |
| 602 | remote_rdp_fetch_register (int regno) |
| 603 | { |
| 604 | if (regno == -1) |
| 605 | { |
| 606 | for (regno = 0; regno < NUM_REGS; regno++) |
| 607 | remote_rdp_fetch_register (regno); |
| 608 | } |
| 609 | else |
| 610 | { |
| 611 | char buf[MAX_REGISTER_RAW_SIZE]; |
| 612 | if (regno < 15) |
| 613 | rdp_fetch_one_register (1 << regno, buf); |
| 614 | else if (regno == PC_REGNUM) |
| 615 | rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_PC, buf); |
| 616 | else if (regno == PS_REGNUM) |
| 617 | rdp_fetch_one_register (RDP_CPU_READWRITE_MASK_CPSR, buf); |
| 618 | else if (regno == FPS_REGNUM) |
| 619 | rdp_fetch_one_fpu_register (RDP_FPU_READWRITE_MASK_FPS, buf); |
| 620 | else if (regno >= F0_REGNUM && regno <= F7_REGNUM) |
| 621 | rdp_fetch_one_fpu_register (1 << (regno - F0_REGNUM), buf); |
| 622 | else |
| 623 | { |
| 624 | printf ("Help me with fetch reg %d\n", regno); |
| 625 | } |
| 626 | supply_register (regno, buf); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | |
| 631 | static void |
| 632 | remote_rdp_store_register (int regno) |
| 633 | { |
| 634 | if (regno == -1) |
| 635 | { |
| 636 | for (regno = 0; regno < NUM_REGS; regno++) |
| 637 | remote_rdp_store_register (regno); |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | char tmp[MAX_REGISTER_RAW_SIZE]; |
| 642 | read_register_gen (regno, tmp); |
| 643 | if (regno < 15) |
| 644 | rdp_store_one_register (1 << regno, tmp); |
| 645 | else if (regno == PC_REGNUM) |
| 646 | rdp_store_one_register (RDP_CPU_READWRITE_MASK_PC, tmp); |
| 647 | else if (regno == PS_REGNUM) |
| 648 | rdp_store_one_register (RDP_CPU_READWRITE_MASK_CPSR, tmp); |
| 649 | else if (regno >= F0_REGNUM && regno <= F7_REGNUM) |
| 650 | rdp_store_one_fpu_register (1 << (regno - F0_REGNUM), tmp); |
| 651 | else |
| 652 | { |
| 653 | printf ("Help me with reg %d\n", regno); |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | static void |
| 659 | remote_rdp_kill (void) |
| 660 | { |
| 661 | callback->shutdown (callback); |
| 662 | } |
| 663 | |
| 664 | |
| 665 | static void |
| 666 | rdp_info (void) |
| 667 | { |
| 668 | send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_STEP, |
| 669 | &ds.step_info); |
| 670 | send_rdp ("bw-S-W-Z", RDP_INFO, RDP_INFO_ABOUT_BREAK, |
| 671 | &ds.break_info); |
| 672 | send_rdp ("bw-S-WW-Z", RDP_INFO, RDP_INFO_ABOUT_TARGET, |
| 673 | &ds.target_info, |
| 674 | &ds.model_info); |
| 675 | |
| 676 | ds.can_step = ds.step_info & RDP_INFO_ABOUT_STEP_1; |
| 677 | |
| 678 | ds.rdi_level = (ds.target_info >> 5) & 3; |
| 679 | } |
| 680 | |
| 681 | |
| 682 | static void |
| 683 | rdp_execute_start (void) |
| 684 | { |
| 685 | /* Start it off, but don't wait for it */ |
| 686 | send_rdp ("bb-", RDP_EXEC, RDP_EXEC_TYPE_SYNC); |
| 687 | } |
| 688 | |
| 689 | |
| 690 | static void |
| 691 | rdp_set_command_line (char *command, char *args) |
| 692 | { |
| 693 | /* |
| 694 | ** We could use RDP_INFO_SET_CMDLINE to send this, but EmbeddedICE systems |
| 695 | ** don't implement that, and get all confused at the unexpected text. |
| 696 | ** Instead, just keep a copy, and send it when the target does a SWI_GetEnv |
| 697 | */ |
| 698 | |
| 699 | if (commandline != NULL) |
| 700 | xfree (commandline); |
| 701 | |
| 702 | commandline = malloc (strlen (command) + strlen (args) + 2); |
| 703 | if (commandline != NULL) |
| 704 | { |
| 705 | strcpy (commandline, command); |
| 706 | strcat (commandline, " "); |
| 707 | strcat (commandline, args); |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | static void |
| 712 | rdp_catch_vectors (void) |
| 713 | { |
| 714 | /* |
| 715 | ** We want the target monitor to intercept the abort vectors |
| 716 | ** i.e. stop the program if any of these are used. |
| 717 | */ |
| 718 | send_rdp ("bww-SZ", RDP_INFO, RDP_INFO_VECTOR_CATCH, |
| 719 | /* |
| 720 | ** Specify a bitmask including |
| 721 | ** the reset vector |
| 722 | ** the undefined instruction vector |
| 723 | ** the prefetch abort vector |
| 724 | ** the data abort vector |
| 725 | ** the address exception vector |
| 726 | */ |
| 727 | (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) |
| 728 | ); |
| 729 | } |
| 730 | |
| 731 | |
| 732 | |
| 733 | #define a_byte 1 |
| 734 | #define a_word 2 |
| 735 | #define a_string 3 |
| 736 | |
| 737 | |
| 738 | typedef struct |
| 739 | { |
| 740 | CORE_ADDR n; |
| 741 | const char *s; |
| 742 | } |
| 743 | argsin; |
| 744 | |
| 745 | #define ABYTE 1 |
| 746 | #define AWORD 2 |
| 747 | #define ASTRING 3 |
| 748 | #define ADDRLEN 4 |
| 749 | |
| 750 | #define SWI_WriteC 0x0 |
| 751 | #define SWI_Write0 0x2 |
| 752 | #define SWI_ReadC 0x4 |
| 753 | #define SWI_CLI 0x5 |
| 754 | #define SWI_GetEnv 0x10 |
| 755 | #define SWI_Exit 0x11 |
| 756 | #define SWI_EnterOS 0x16 |
| 757 | |
| 758 | #define SWI_GetErrno 0x60 |
| 759 | #define SWI_Clock 0x61 |
| 760 | |
| 761 | #define SWI_Time 0x63 |
| 762 | #define SWI_Remove 0x64 |
| 763 | #define SWI_Rename 0x65 |
| 764 | #define SWI_Open 0x66 |
| 765 | |
| 766 | #define SWI_Close 0x68 |
| 767 | #define SWI_Write 0x69 |
| 768 | #define SWI_Read 0x6a |
| 769 | #define SWI_Seek 0x6b |
| 770 | #define SWI_Flen 0x6c |
| 771 | |
| 772 | #define SWI_IsTTY 0x6e |
| 773 | #define SWI_TmpNam 0x6f |
| 774 | #define SWI_InstallHandler 0x70 |
| 775 | #define SWI_GenerateError 0x71 |
| 776 | |
| 777 | |
| 778 | #ifndef O_BINARY |
| 779 | #define O_BINARY 0 |
| 780 | #endif |
| 781 | |
| 782 | static int translate_open_mode[] = |
| 783 | { |
| 784 | O_RDONLY, /* "r" */ |
| 785 | O_RDONLY + O_BINARY, /* "rb" */ |
| 786 | O_RDWR, /* "r+" */ |
| 787 | O_RDWR + O_BINARY, /* "r+b" */ |
| 788 | O_WRONLY + O_CREAT + O_TRUNC, /* "w" */ |
| 789 | O_WRONLY + O_BINARY + O_CREAT + O_TRUNC, /* "wb" */ |
| 790 | O_RDWR + O_CREAT + O_TRUNC, /* "w+" */ |
| 791 | O_RDWR + O_BINARY + O_CREAT + O_TRUNC, /* "w+b" */ |
| 792 | O_WRONLY + O_APPEND + O_CREAT, /* "a" */ |
| 793 | O_WRONLY + O_BINARY + O_APPEND + O_CREAT, /* "ab" */ |
| 794 | O_RDWR + O_APPEND + O_CREAT, /* "a+" */ |
| 795 | O_RDWR + O_BINARY + O_APPEND + O_CREAT /* "a+b" */ |
| 796 | }; |
| 797 | |
| 798 | static int |
| 799 | exec_swi (int swi, argsin *args) |
| 800 | { |
| 801 | int i; |
| 802 | char c; |
| 803 | switch (swi) |
| 804 | { |
| 805 | case SWI_WriteC: |
| 806 | callback->write_stdout (callback, &c, 1); |
| 807 | return 0; |
| 808 | case SWI_Write0: |
| 809 | for (i = 0; i < args->n; i++) |
| 810 | callback->write_stdout (callback, args->s, strlen (args->s)); |
| 811 | return 0; |
| 812 | case SWI_ReadC: |
| 813 | callback->read_stdin (callback, &c, 1); |
| 814 | args->n = c; |
| 815 | return 1; |
| 816 | case SWI_CLI: |
| 817 | args->n = callback->system (callback, args->s); |
| 818 | return 1; |
| 819 | case SWI_GetErrno: |
| 820 | args->n = callback->get_errno (callback); |
| 821 | return 1; |
| 822 | case SWI_Time: |
| 823 | args->n = callback->time (callback, NULL); |
| 824 | return 1; |
| 825 | |
| 826 | case SWI_Clock: |
| 827 | /* return number of centi-seconds... */ |
| 828 | args->n = |
| 829 | #ifdef CLOCKS_PER_SEC |
| 830 | (CLOCKS_PER_SEC >= 100) |
| 831 | ? (clock () / (CLOCKS_PER_SEC / 100)) |
| 832 | : ((clock () * 100) / CLOCKS_PER_SEC); |
| 833 | #else |
| 834 | /* presume unix... clock() returns microseconds */ |
| 835 | clock () / 10000; |
| 836 | #endif |
| 837 | return 1; |
| 838 | |
| 839 | case SWI_Remove: |
| 840 | args->n = callback->unlink (callback, args->s); |
| 841 | return 1; |
| 842 | case SWI_Rename: |
| 843 | args->n = callback->rename (callback, args[0].s, args[1].s); |
| 844 | return 1; |
| 845 | |
| 846 | case SWI_Open: |
| 847 | /* Now we need to decode the Demon open mode */ |
| 848 | i = translate_open_mode[args[1].n]; |
| 849 | |
| 850 | /* Filename ":tt" is special: it denotes stdin/out */ |
| 851 | if (strcmp (args->s, ":tt") == 0) |
| 852 | { |
| 853 | if (i == O_RDONLY) /* opening tty "r" */ |
| 854 | args->n = 0 /* stdin */ ; |
| 855 | else |
| 856 | args->n = 1 /* stdout */ ; |
| 857 | } |
| 858 | else |
| 859 | args->n = callback->open (callback, args->s, i); |
| 860 | return 1; |
| 861 | |
| 862 | case SWI_Close: |
| 863 | args->n = callback->close (callback, args->n); |
| 864 | return 1; |
| 865 | |
| 866 | case SWI_Write: |
| 867 | /* Return the number of bytes *not* written */ |
| 868 | args->n = args[1].n - |
| 869 | callback->write (callback, args[0].n, args[1].s, args[1].n); |
| 870 | return 1; |
| 871 | |
| 872 | case SWI_Read: |
| 873 | { |
| 874 | char *copy = alloca (args[2].n); |
| 875 | int done = callback->read (callback, args[0].n, copy, args[2].n); |
| 876 | if (done > 0) |
| 877 | remote_rdp_xfer_inferior_memory (args[1].n, copy, done, 1, 0, 0); |
| 878 | args->n = args[2].n - done; |
| 879 | return 1; |
| 880 | } |
| 881 | |
| 882 | case SWI_Seek: |
| 883 | /* Return non-zero on failure */ |
| 884 | args->n = callback->lseek (callback, args[0].n, args[1].n, 0) < 0; |
| 885 | return 1; |
| 886 | |
| 887 | case SWI_Flen: |
| 888 | { |
| 889 | long old = callback->lseek (callback, args->n, 0, SEEK_CUR); |
| 890 | args->n = callback->lseek (callback, args->n, 0, SEEK_END); |
| 891 | callback->lseek (callback, args->n, old, 0); |
| 892 | return 1; |
| 893 | } |
| 894 | |
| 895 | case SWI_IsTTY: |
| 896 | args->n = callback->isatty (callback, args->n); |
| 897 | return 1; |
| 898 | |
| 899 | case SWI_GetEnv: |
| 900 | if (commandline != NULL) |
| 901 | { |
| 902 | int len = strlen (commandline); |
| 903 | if (len > 255) |
| 904 | { |
| 905 | len = 255; |
| 906 | commandline[255] = '\0'; |
| 907 | } |
| 908 | remote_rdp_xfer_inferior_memory (args[0].n, |
| 909 | commandline, len + 1, 1, 0, 0); |
| 910 | } |
| 911 | else |
| 912 | remote_rdp_xfer_inferior_memory (args[0].n, "", 1, 1, 0, 0); |
| 913 | return 1; |
| 914 | |
| 915 | default: |
| 916 | return 0; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | |
| 921 | static void |
| 922 | handle_swi (void) |
| 923 | { |
| 924 | argsin args[3]; |
| 925 | char *buf; |
| 926 | int len; |
| 927 | int count = 0; |
| 928 | |
| 929 | int swino = get_word (); |
| 930 | int type = get_byte (); |
| 931 | while (type != 0) |
| 932 | { |
| 933 | switch (type & 0x3) |
| 934 | { |
| 935 | case ABYTE: |
| 936 | args[count].n = get_byte (); |
| 937 | break; |
| 938 | |
| 939 | case AWORD: |
| 940 | args[count].n = get_word (); |
| 941 | break; |
| 942 | |
| 943 | case ASTRING: |
| 944 | /* If the word is under 32 bytes it will be sent otherwise |
| 945 | an address to it is passed. Also: Special case of 255 */ |
| 946 | |
| 947 | len = get_byte (); |
| 948 | if (len > 32) |
| 949 | { |
| 950 | if (len == 255) |
| 951 | { |
| 952 | len = get_word (); |
| 953 | } |
| 954 | buf = alloca (len); |
| 955 | remote_rdp_xfer_inferior_memory (get_word (), |
| 956 | buf, |
| 957 | len, |
| 958 | 0, |
| 959 | 0, |
| 960 | 0); |
| 961 | } |
| 962 | else |
| 963 | { |
| 964 | int i; |
| 965 | buf = alloca (len + 1); |
| 966 | for (i = 0; i < len; i++) |
| 967 | buf[i] = get_byte (); |
| 968 | buf[i] = 0; |
| 969 | } |
| 970 | args[count].n = len; |
| 971 | args[count].s = buf; |
| 972 | break; |
| 973 | |
| 974 | default: |
| 975 | error ("Unimplemented SWI argument"); |
| 976 | } |
| 977 | |
| 978 | type = type >> 2; |
| 979 | count++; |
| 980 | } |
| 981 | |
| 982 | if (exec_swi (swino, args)) |
| 983 | { |
| 984 | /* We have two options here reply with either a byte or a word |
| 985 | which is stored in args[0].n. There is no harm in replying with |
| 986 | a word all the time, so thats what I do! */ |
| 987 | send_rdp ("bbw-", RDP_OSOpReply, RDP_OSOpWord, args[0].n); |
| 988 | } |
| 989 | else |
| 990 | { |
| 991 | send_rdp ("bb-", RDP_OSOpReply, RDP_OSOpNothing); |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | static void |
| 996 | rdp_execute_finish (void) |
| 997 | { |
| 998 | int running = 1; |
| 999 | |
| 1000 | while (running) |
| 1001 | { |
| 1002 | int res; |
| 1003 | res = SERIAL_READCHAR (io, 1); |
| 1004 | while (res == SERIAL_TIMEOUT) |
| 1005 | { |
| 1006 | QUIT; |
| 1007 | printf_filtered ("Waiting for target..\n"); |
| 1008 | res = SERIAL_READCHAR (io, 1); |
| 1009 | } |
| 1010 | |
| 1011 | switch (res) |
| 1012 | { |
| 1013 | case RDP_RES_SWI: |
| 1014 | handle_swi (); |
| 1015 | break; |
| 1016 | case RDP_RES_VALUE: |
| 1017 | send_rdp ("B", &ds.rdi_stopped_status); |
| 1018 | running = 0; |
| 1019 | break; |
| 1020 | case RDP_RESET: |
| 1021 | printf_filtered ("Target reset\n"); |
| 1022 | running = 0; |
| 1023 | break; |
| 1024 | default: |
| 1025 | printf_filtered ("Ignoring %x\n", res); |
| 1026 | break; |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | |
| 1032 | static void |
| 1033 | rdp_execute (void) |
| 1034 | { |
| 1035 | rdp_execute_start (); |
| 1036 | rdp_execute_finish (); |
| 1037 | } |
| 1038 | |
| 1039 | static int |
| 1040 | remote_rdp_insert_breakpoint (CORE_ADDR addr, char *save) |
| 1041 | { |
| 1042 | int res; |
| 1043 | if (ds.rdi_level > 0) |
| 1044 | { |
| 1045 | send_rdp ("bwb-SWB", |
| 1046 | RDP_SET_BREAK, |
| 1047 | addr, |
| 1048 | RDP_SET_BREAK_TYPE_PC_EQUAL | RDP_SET_BREAK_TYPE_GET_HANDLE, |
| 1049 | save, |
| 1050 | &res); |
| 1051 | } |
| 1052 | else |
| 1053 | { |
| 1054 | send_rdp ("bwb-SB", |
| 1055 | RDP_SET_BREAK, |
| 1056 | addr, |
| 1057 | RDP_SET_BREAK_TYPE_PC_EQUAL, |
| 1058 | &res); |
| 1059 | } |
| 1060 | return res; |
| 1061 | } |
| 1062 | |
| 1063 | static int |
| 1064 | remote_rdp_remove_breakpoint (CORE_ADDR addr, char *save) |
| 1065 | { |
| 1066 | int res; |
| 1067 | if (ds.rdi_level > 0) |
| 1068 | { |
| 1069 | send_rdp ("b-p-S-B", |
| 1070 | RDP_CLEAR_BREAK, |
| 1071 | save, 4, |
| 1072 | &res); |
| 1073 | } |
| 1074 | else |
| 1075 | { |
| 1076 | send_rdp ("bw-S-B", |
| 1077 | RDP_CLEAR_BREAK, |
| 1078 | addr, |
| 1079 | &res); |
| 1080 | } |
| 1081 | return res; |
| 1082 | } |
| 1083 | |
| 1084 | static void |
| 1085 | rdp_step (void) |
| 1086 | { |
| 1087 | if (ds.can_step && 0) |
| 1088 | { |
| 1089 | /* The pie board can't do steps so I can't test this, and |
| 1090 | the other code will always work. */ |
| 1091 | int status; |
| 1092 | send_rdp ("bbw-S-B", |
| 1093 | RDP_STEP, 0, 1, |
| 1094 | &status); |
| 1095 | } |
| 1096 | else |
| 1097 | { |
| 1098 | char handle[4]; |
| 1099 | CORE_ADDR pc = read_register (PC_REGNUM); |
| 1100 | pc = arm_get_next_pc (pc); |
| 1101 | remote_rdp_insert_breakpoint (pc, handle); |
| 1102 | rdp_execute (); |
| 1103 | remote_rdp_remove_breakpoint (pc, handle); |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | static void |
| 1108 | remote_rdp_open (char *args, int from_tty) |
| 1109 | { |
| 1110 | int not_icebreaker; |
| 1111 | |
| 1112 | if (!args) |
| 1113 | error_no_arg ("serial port device name"); |
| 1114 | |
| 1115 | baud_rate = 9600; |
| 1116 | |
| 1117 | target_preopen (from_tty); |
| 1118 | |
| 1119 | io = SERIAL_OPEN (args); |
| 1120 | |
| 1121 | if (!io) |
| 1122 | perror_with_name (args); |
| 1123 | |
| 1124 | SERIAL_RAW (io); |
| 1125 | |
| 1126 | rdp_init (1, from_tty); |
| 1127 | |
| 1128 | |
| 1129 | if (from_tty) |
| 1130 | { |
| 1131 | printf_unfiltered ("Remote RDP debugging using %s at %d baud\n", args, baud_rate); |
| 1132 | } |
| 1133 | |
| 1134 | rdp_info (); |
| 1135 | |
| 1136 | /* Need to set up the vector interception state */ |
| 1137 | rdp_catch_vectors (); |
| 1138 | |
| 1139 | /* |
| 1140 | ** If it's an EmbeddedICE, we need to set the processor config. |
| 1141 | ** Assume we can always have ARM7TDI... |
| 1142 | */ |
| 1143 | send_rdp ("bw-SB", RDP_INFO, RDP_INFO_ICEBREAKER, ¬_icebreaker); |
| 1144 | if (!not_icebreaker) |
| 1145 | { |
| 1146 | const char *CPU = "ARM7TDI"; |
| 1147 | int ICEversion; |
| 1148 | int len = strlen (CPU); |
| 1149 | |
| 1150 | send_rdp ("bbbbw-p-SWZ", |
| 1151 | RDP_SELECT_CONFIG, |
| 1152 | RDI_ConfigCPU, /* Aspect: set the CPU */ |
| 1153 | len, /* The number of bytes in the name */ |
| 1154 | RDI_MatchAny, /* We'll take whatever we get */ |
| 1155 | 0, /* We'll take whatever version's there */ |
| 1156 | CPU, len, |
| 1157 | &ICEversion); |
| 1158 | } |
| 1159 | |
| 1160 | /* command line initialised on 'run' */ |
| 1161 | |
| 1162 | push_target (&remote_rdp_ops); |
| 1163 | |
| 1164 | callback->init (callback); |
| 1165 | flush_cached_frames (); |
| 1166 | registers_changed (); |
| 1167 | stop_pc = read_pc (); |
| 1168 | set_current_frame (create_new_frame (read_fp (), stop_pc)); |
| 1169 | select_frame (get_current_frame (), 0); |
| 1170 | print_stack_frame (selected_frame, -1, 1); |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | /* Close out all files and local state before this target loses control. */ |
| 1176 | |
| 1177 | static void |
| 1178 | remote_rdp_close (int quitting) |
| 1179 | { |
| 1180 | callback->shutdown (callback); |
| 1181 | if (io) |
| 1182 | SERIAL_CLOSE (io); |
| 1183 | io = 0; |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | /* Resume execution of the target process. STEP says whether to single-step |
| 1188 | or to run free; SIGGNAL is the signal value (e.g. SIGINT) to be given |
| 1189 | to the target, or zero for no signal. */ |
| 1190 | |
| 1191 | static void |
| 1192 | remote_rdp_resume (int pid, int step, enum target_signal siggnal) |
| 1193 | { |
| 1194 | if (step) |
| 1195 | rdp_step (); |
| 1196 | else |
| 1197 | rdp_execute (); |
| 1198 | } |
| 1199 | |
| 1200 | /* Wait for inferior process to do something. Return pid of child, |
| 1201 | or -1 in case of error; store status through argument pointer STATUS, |
| 1202 | just as `wait' would. */ |
| 1203 | |
| 1204 | static int |
| 1205 | remote_rdp_wait (int pid, struct target_waitstatus *status) |
| 1206 | { |
| 1207 | switch (ds.rdi_stopped_status) |
| 1208 | { |
| 1209 | default: |
| 1210 | case RDP_RES_RESET: |
| 1211 | case RDP_RES_SWI: |
| 1212 | status->kind = TARGET_WAITKIND_EXITED; |
| 1213 | status->value.integer = read_register (0); |
| 1214 | break; |
| 1215 | case RDP_RES_AT_BREAKPOINT: |
| 1216 | status->kind = TARGET_WAITKIND_STOPPED; |
| 1217 | /* The signal in sigrc is a host signal. That probably |
| 1218 | should be fixed. */ |
| 1219 | status->value.sig = TARGET_SIGNAL_TRAP; |
| 1220 | break; |
| 1221 | #if 0 |
| 1222 | case rdp_signalled: |
| 1223 | status->kind = TARGET_WAITKIND_SIGNALLED; |
| 1224 | /* The signal in sigrc is a host signal. That probably |
| 1225 | should be fixed. */ |
| 1226 | status->value.sig = target_signal_from_host (sigrc); |
| 1227 | break; |
| 1228 | #endif |
| 1229 | } |
| 1230 | |
| 1231 | return inferior_pid; |
| 1232 | } |
| 1233 | |
| 1234 | /* Get ready to modify the registers array. On machines which store |
| 1235 | individual registers, this doesn't need to do anything. On machines |
| 1236 | which store all the registers in one fell swoop, this makes sure |
| 1237 | that registers contains all the registers from the program being |
| 1238 | debugged. */ |
| 1239 | |
| 1240 | static void |
| 1241 | remote_rdp_prepare_to_store (void) |
| 1242 | { |
| 1243 | /* Do nothing, since we can store individual regs */ |
| 1244 | } |
| 1245 | |
| 1246 | /* Transfer LEN bytes between GDB address MYADDR and target address |
| 1247 | MEMADDR. If WRITE is non-zero, transfer them to the target, |
| 1248 | otherwise transfer them from the target. TARGET is unused. |
| 1249 | |
| 1250 | Returns the number of bytes transferred. */ |
| 1251 | |
| 1252 | static int |
| 1253 | remote_rdp_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, |
| 1254 | int write, |
| 1255 | struct mem_attrib *attrib ATTRIBUTE_UNUSED, |
| 1256 | struct target_ops *target ATTRIBUTE_UNUSED) |
| 1257 | { |
| 1258 | /* I infer from D Taylor's code that there's a limit on the amount |
| 1259 | we can transfer in one chunk.. */ |
| 1260 | int done = 0; |
| 1261 | while (done < len) |
| 1262 | { |
| 1263 | int justdone; |
| 1264 | int thisbite = len - done; |
| 1265 | if (thisbite > RDP_MOUTHFULL) |
| 1266 | thisbite = RDP_MOUTHFULL; |
| 1267 | |
| 1268 | QUIT; |
| 1269 | |
| 1270 | if (write) |
| 1271 | { |
| 1272 | justdone = rdp_write (memaddr + done, myaddr + done, thisbite); |
| 1273 | } |
| 1274 | else |
| 1275 | { |
| 1276 | justdone = rdp_read (memaddr + done, myaddr + done, thisbite); |
| 1277 | } |
| 1278 | |
| 1279 | done += justdone; |
| 1280 | |
| 1281 | if (justdone != thisbite) |
| 1282 | break; |
| 1283 | } |
| 1284 | return done; |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | struct yn |
| 1290 | { |
| 1291 | const char *name; |
| 1292 | int bit; |
| 1293 | }; |
| 1294 | static struct yn stepinfo[] = |
| 1295 | { |
| 1296 | {"Step more than one instruction", RDP_INFO_ABOUT_STEP_GT_1}, |
| 1297 | {"Step to jump", RDP_INFO_ABOUT_STEP_TO_JMP}, |
| 1298 | {"Step one instruction", RDP_INFO_ABOUT_STEP_1}, |
| 1299 | {0} |
| 1300 | }; |
| 1301 | |
| 1302 | static struct yn breakinfo[] = |
| 1303 | { |
| 1304 | {"comparison breakpoints supported", RDP_INFO_ABOUT_BREAK_COMP}, |
| 1305 | {"range breakpoints supported", RDP_INFO_ABOUT_BREAK_RANGE}, |
| 1306 | {"watchpoints for byte reads supported", RDP_INFO_ABOUT_BREAK_BYTE_READ}, |
| 1307 | {"watchpoints for half-word reads supported", RDP_INFO_ABOUT_BREAK_HALFWORD_READ}, |
| 1308 | {"watchpoints for word reads supported", RDP_INFO_ABOUT_BREAK_WORD_READ}, |
| 1309 | {"watchpoints for byte writes supported", RDP_INFO_ABOUT_BREAK_BYTE_WRITE}, |
| 1310 | {"watchpoints for half-word writes supported", RDP_INFO_ABOUT_BREAK_HALFWORD_WRITE}, |
| 1311 | {"watchpoints for word writes supported", RDP_INFO_ABOUT_BREAK_WORD_WRITE}, |
| 1312 | {"mask break/watch-points supported", RDP_INFO_ABOUT_BREAK_MASK}, |
| 1313 | {"thread-specific breakpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_BREAK}, |
| 1314 | {"thread-specific watchpoints supported", RDP_INFO_ABOUT_BREAK_THREAD_WATCH}, |
| 1315 | {"conditional breakpoints supported", RDP_INFO_ABOUT_BREAK_COND}, |
| 1316 | {0} |
| 1317 | }; |
| 1318 | |
| 1319 | |
| 1320 | static void |
| 1321 | dump_bits (struct yn *t, int info) |
| 1322 | { |
| 1323 | while (t->name) |
| 1324 | { |
| 1325 | printf_unfiltered (" %-45s : %s\n", t->name, (info & t->bit) ? "Yes" : "No"); |
| 1326 | t++; |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static void |
| 1331 | remote_rdp_files_info (struct target_ops *target) |
| 1332 | { |
| 1333 | printf_filtered ("Target capabilities:\n"); |
| 1334 | dump_bits (stepinfo, ds.step_info); |
| 1335 | dump_bits (breakinfo, ds.break_info); |
| 1336 | printf_unfiltered ("target level RDI %x\n", (ds.target_info >> 5) & 3); |
| 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | static void |
| 1341 | remote_rdp_create_inferior (char *exec_file, char *allargs, char **env) |
| 1342 | { |
| 1343 | CORE_ADDR entry_point; |
| 1344 | |
| 1345 | if (exec_file == 0 || exec_bfd == 0) |
| 1346 | error ("No executable file specified."); |
| 1347 | |
| 1348 | entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd); |
| 1349 | |
| 1350 | remote_rdp_kill (); |
| 1351 | remove_breakpoints (); |
| 1352 | init_wait_for_inferior (); |
| 1353 | |
| 1354 | /* This gives us a chance to set up the command line */ |
| 1355 | rdp_set_command_line (exec_file, allargs); |
| 1356 | |
| 1357 | inferior_pid = 42; |
| 1358 | insert_breakpoints (); /* Needed to get correct instruction in cache */ |
| 1359 | |
| 1360 | /* |
| 1361 | ** RDP targets don't provide any facility to set the top of memory, |
| 1362 | ** so we don't bother to look for MEMSIZE in the environment. |
| 1363 | */ |
| 1364 | |
| 1365 | /* Let's go! */ |
| 1366 | proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0); |
| 1367 | } |
| 1368 | |
| 1369 | /* Accept any stray run/attach commands */ |
| 1370 | static int |
| 1371 | remote_rdp_can_run (void) |
| 1372 | { |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | /* Attach doesn't need to do anything */ |
| 1377 | static void |
| 1378 | remote_rdp_attach (char *args, int from_tty) |
| 1379 | { |
| 1380 | return; |
| 1381 | } |
| 1382 | |
| 1383 | /* Define the target subroutine names */ |
| 1384 | |
| 1385 | struct target_ops remote_rdp_ops; |
| 1386 | |
| 1387 | static void |
| 1388 | init_remote_rdp_ops (void) |
| 1389 | { |
| 1390 | remote_rdp_ops.to_shortname = "rdp"; |
| 1391 | remote_rdp_ops.to_longname = "Remote Target using the RDProtocol"; |
| 1392 | remote_rdp_ops.to_doc = "Use a remote ARM system which uses the ARM Remote Debugging Protocol"; |
| 1393 | remote_rdp_ops.to_open = remote_rdp_open; |
| 1394 | remote_rdp_ops.to_close = remote_rdp_close; |
| 1395 | remote_rdp_ops.to_attach = remote_rdp_attach; |
| 1396 | remote_rdp_ops.to_post_attach = NULL; |
| 1397 | remote_rdp_ops.to_require_attach = NULL; |
| 1398 | remote_rdp_ops.to_detach = NULL; |
| 1399 | remote_rdp_ops.to_require_detach = NULL; |
| 1400 | remote_rdp_ops.to_resume = remote_rdp_resume; |
| 1401 | remote_rdp_ops.to_wait = remote_rdp_wait; |
| 1402 | remote_rdp_ops.to_post_wait = NULL; |
| 1403 | remote_rdp_ops.to_fetch_registers = remote_rdp_fetch_register; |
| 1404 | remote_rdp_ops.to_store_registers = remote_rdp_store_register; |
| 1405 | remote_rdp_ops.to_prepare_to_store = remote_rdp_prepare_to_store; |
| 1406 | remote_rdp_ops.to_xfer_memory = remote_rdp_xfer_inferior_memory; |
| 1407 | remote_rdp_ops.to_files_info = remote_rdp_files_info; |
| 1408 | remote_rdp_ops.to_insert_breakpoint = remote_rdp_insert_breakpoint; |
| 1409 | remote_rdp_ops.to_remove_breakpoint = remote_rdp_remove_breakpoint; |
| 1410 | remote_rdp_ops.to_terminal_init = NULL; |
| 1411 | remote_rdp_ops.to_terminal_inferior = NULL; |
| 1412 | remote_rdp_ops.to_terminal_ours_for_output = NULL; |
| 1413 | remote_rdp_ops.to_terminal_ours = NULL; |
| 1414 | remote_rdp_ops.to_terminal_info = NULL; |
| 1415 | remote_rdp_ops.to_kill = remote_rdp_kill; |
| 1416 | remote_rdp_ops.to_load = generic_load; |
| 1417 | remote_rdp_ops.to_lookup_symbol = NULL; |
| 1418 | remote_rdp_ops.to_create_inferior = remote_rdp_create_inferior; |
| 1419 | remote_rdp_ops.to_post_startup_inferior = NULL; |
| 1420 | remote_rdp_ops.to_acknowledge_created_inferior = NULL; |
| 1421 | remote_rdp_ops.to_clone_and_follow_inferior = NULL; |
| 1422 | remote_rdp_ops.to_post_follow_inferior_by_clone = NULL; |
| 1423 | remote_rdp_ops.to_insert_fork_catchpoint = NULL; |
| 1424 | remote_rdp_ops.to_remove_fork_catchpoint = NULL; |
| 1425 | remote_rdp_ops.to_insert_vfork_catchpoint = NULL; |
| 1426 | remote_rdp_ops.to_remove_vfork_catchpoint = NULL; |
| 1427 | remote_rdp_ops.to_has_forked = NULL; |
| 1428 | remote_rdp_ops.to_has_vforked = NULL; |
| 1429 | remote_rdp_ops.to_can_follow_vfork_prior_to_exec = NULL; |
| 1430 | remote_rdp_ops.to_post_follow_vfork = NULL; |
| 1431 | remote_rdp_ops.to_insert_exec_catchpoint = NULL; |
| 1432 | remote_rdp_ops.to_remove_exec_catchpoint = NULL; |
| 1433 | remote_rdp_ops.to_has_execd = NULL; |
| 1434 | remote_rdp_ops.to_reported_exec_events_per_exec_call = NULL; |
| 1435 | remote_rdp_ops.to_has_exited = NULL; |
| 1436 | remote_rdp_ops.to_mourn_inferior = generic_mourn_inferior; |
| 1437 | remote_rdp_ops.to_can_run = remote_rdp_can_run; |
| 1438 | remote_rdp_ops.to_notice_signals = 0; |
| 1439 | remote_rdp_ops.to_thread_alive = 0; |
| 1440 | remote_rdp_ops.to_stop = 0; |
| 1441 | remote_rdp_ops.to_pid_to_exec_file = NULL; |
| 1442 | remote_rdp_ops.to_core_file_to_sym_file = NULL; |
| 1443 | remote_rdp_ops.to_stratum = process_stratum; |
| 1444 | remote_rdp_ops.DONT_USE = NULL; |
| 1445 | remote_rdp_ops.to_has_all_memory = 1; |
| 1446 | remote_rdp_ops.to_has_memory = 1; |
| 1447 | remote_rdp_ops.to_has_stack = 1; |
| 1448 | remote_rdp_ops.to_has_registers = 1; |
| 1449 | remote_rdp_ops.to_has_execution = 1; |
| 1450 | remote_rdp_ops.to_sections = NULL; |
| 1451 | remote_rdp_ops.to_sections_end = NULL; |
| 1452 | remote_rdp_ops.to_magic = OPS_MAGIC; |
| 1453 | } |
| 1454 | |
| 1455 | void |
| 1456 | _initialize_remote_rdp (void) |
| 1457 | { |
| 1458 | init_remote_rdp_ops (); |
| 1459 | add_target (&remote_rdp_ops); |
| 1460 | } |