| 1 | /* GDB interface to ARM RDI library. |
| 2 | Copyright 1997, 1998, 2001 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 19 | Boston, MA 02111-1307, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "gdb_string.h" |
| 23 | #include <fcntl.h> |
| 24 | #include "frame.h" |
| 25 | #include "inferior.h" |
| 26 | #include "bfd.h" |
| 27 | #include "symfile.h" |
| 28 | #include "target.h" |
| 29 | #include "gdbcmd.h" |
| 30 | #include "objfiles.h" |
| 31 | #include "gdb-stabs.h" |
| 32 | #include "gdbthread.h" |
| 33 | #include "gdbcore.h" |
| 34 | #include "breakpoint.h" |
| 35 | #include "completer.h" |
| 36 | #include "regcache.h" |
| 37 | |
| 38 | #ifdef USG |
| 39 | #include <sys/types.h> |
| 40 | #endif |
| 41 | |
| 42 | #include <signal.h> |
| 43 | |
| 44 | #include "rdi-share/ardi.h" |
| 45 | #include "rdi-share/adp.h" |
| 46 | #include "rdi-share/hsys.h" |
| 47 | |
| 48 | extern int isascii (int); |
| 49 | |
| 50 | /* Prototypes for local functions */ |
| 51 | |
| 52 | static void arm_rdi_files_info (struct target_ops *ignore); |
| 53 | |
| 54 | static int arm_rdi_xfer_memory (CORE_ADDR memaddr, char *myaddr, |
| 55 | int len, int should_write, |
| 56 | struct mem_attrib *attrib, |
| 57 | struct target_ops *target); |
| 58 | |
| 59 | static void arm_rdi_prepare_to_store (void); |
| 60 | |
| 61 | static void arm_rdi_fetch_registers (int regno); |
| 62 | |
| 63 | static void arm_rdi_resume (int pid, int step, enum target_signal siggnal); |
| 64 | |
| 65 | static int arm_rdi_start_remote (char *dummy); |
| 66 | |
| 67 | static void arm_rdi_open (char *name, int from_tty); |
| 68 | |
| 69 | static void arm_rdi_create_inferior (char *exec_file, char *args, char **env); |
| 70 | |
| 71 | static void arm_rdi_close (int quitting); |
| 72 | |
| 73 | static void arm_rdi_store_registers (int regno); |
| 74 | |
| 75 | static void arm_rdi_mourn (void); |
| 76 | |
| 77 | static void arm_rdi_send (char *buf); |
| 78 | |
| 79 | static int arm_rdi_wait (int pid, struct target_waitstatus *status); |
| 80 | |
| 81 | static void arm_rdi_kill (void); |
| 82 | |
| 83 | static void arm_rdi_detach (char *args, int from_tty); |
| 84 | |
| 85 | static void arm_rdi_interrupt (int signo); |
| 86 | |
| 87 | static void arm_rdi_interrupt_twice (int signo); |
| 88 | |
| 89 | static void interrupt_query (void); |
| 90 | |
| 91 | static int arm_rdi_insert_breakpoint (CORE_ADDR, char *); |
| 92 | |
| 93 | static int arm_rdi_remove_breakpoint (CORE_ADDR, char *); |
| 94 | |
| 95 | static char *rdi_error_message (int err); |
| 96 | |
| 97 | static enum target_signal rdi_error_signal (int err); |
| 98 | |
| 99 | /* Global variables. */ |
| 100 | |
| 101 | struct target_ops arm_rdi_ops; |
| 102 | |
| 103 | static struct Dbg_ConfigBlock gdb_config; |
| 104 | |
| 105 | static struct Dbg_HostosInterface gdb_hostif; |
| 106 | |
| 107 | static int max_load_size; |
| 108 | |
| 109 | static int execute_status; |
| 110 | |
| 111 | /* Send heatbeat packets? */ |
| 112 | static int rdi_heartbeat = 0; |
| 113 | |
| 114 | /* Target has ROM at address 0. */ |
| 115 | static int rom_at_zero = 0; |
| 116 | |
| 117 | /* Enable logging? */ |
| 118 | static int log_enable = 0; |
| 119 | |
| 120 | /* Name of the log file. Default is "rdi.log". */ |
| 121 | static char *log_filename; |
| 122 | |
| 123 | /* A little list of breakpoints that have been set. */ |
| 124 | |
| 125 | static struct local_bp_list_entry |
| 126 | { |
| 127 | CORE_ADDR addr; |
| 128 | PointHandle point; |
| 129 | struct local_bp_list_entry *next; |
| 130 | } |
| 131 | *local_bp_list; |
| 132 | \f |
| 133 | |
| 134 | /* Stub for catch_errors. */ |
| 135 | |
| 136 | static int |
| 137 | arm_rdi_start_remote (char *dummy) |
| 138 | { |
| 139 | return 1; |
| 140 | } |
| 141 | |
| 142 | /* Helper callbacks for the "host interface" structure. RDI functions call |
| 143 | these to forward output from the target system and so forth. */ |
| 144 | |
| 145 | void |
| 146 | voiddummy (void *dummy) |
| 147 | { |
| 148 | fprintf_unfiltered (gdb_stdout, "void dummy\n"); |
| 149 | } |
| 150 | |
| 151 | static void |
| 152 | myprint (PTR arg, const char *format, va_list ap) |
| 153 | { |
| 154 | vfprintf_unfiltered (gdb_stdout, format, ap); |
| 155 | } |
| 156 | |
| 157 | static void |
| 158 | mywritec (PTR arg, int c) |
| 159 | { |
| 160 | if (isascii (c)) |
| 161 | fputc_unfiltered (c, gdb_stdout); |
| 162 | } |
| 163 | |
| 164 | static int |
| 165 | mywrite (PTR arg, char const *buffer, int len) |
| 166 | { |
| 167 | int i; |
| 168 | char *e; |
| 169 | |
| 170 | e = (char *) buffer; |
| 171 | for (i = 0; i < len; i++) |
| 172 | { |
| 173 | if (isascii ((int) *e)) |
| 174 | { |
| 175 | fputc_unfiltered ((int) *e, gdb_stdout); |
| 176 | e++; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | return len; |
| 181 | } |
| 182 | |
| 183 | static void |
| 184 | mypause (PTR arg) |
| 185 | { |
| 186 | } |
| 187 | |
| 188 | /* These last two are tricky as we have to handle the special case of |
| 189 | being interrupted more carefully */ |
| 190 | |
| 191 | static int |
| 192 | myreadc (PTR arg) |
| 193 | { |
| 194 | return fgetc (stdin); |
| 195 | } |
| 196 | |
| 197 | static char * |
| 198 | mygets (PTR arg, char *buffer, int len) |
| 199 | { |
| 200 | return fgets (buffer, len, stdin); |
| 201 | } |
| 202 | |
| 203 | /* Prevent multiple calls to angel_RDI_close(). */ |
| 204 | static int closed_already = 1; |
| 205 | |
| 206 | /* Open a connection to a remote debugger. NAME is the filename used |
| 207 | for communication. */ |
| 208 | |
| 209 | static void |
| 210 | arm_rdi_open (char *name, int from_tty) |
| 211 | { |
| 212 | int rslt, i; |
| 213 | unsigned long arg1, arg2; |
| 214 | char *openArgs = NULL; |
| 215 | char *devName = NULL; |
| 216 | char *p; |
| 217 | |
| 218 | if (name == NULL) |
| 219 | error ("To open an RDI connection, you need to specify what serial\n\ |
| 220 | device is attached to the remote system (e.g. /dev/ttya)."); |
| 221 | |
| 222 | /* split name after whitespace, pass tail as arg to open command */ |
| 223 | |
| 224 | devName = xstrdup (name); |
| 225 | p = strchr (devName, ' '); |
| 226 | if (p) |
| 227 | { |
| 228 | *p = '\0'; |
| 229 | ++p; |
| 230 | |
| 231 | while (*p == ' ') |
| 232 | ++p; |
| 233 | |
| 234 | openArgs = p; |
| 235 | } |
| 236 | |
| 237 | /* Make the basic low-level connection. */ |
| 238 | |
| 239 | arm_rdi_close (0); |
| 240 | rslt = Adp_OpenDevice (devName, openArgs, rdi_heartbeat); |
| 241 | |
| 242 | if (rslt != adp_ok) |
| 243 | error ("Could not open device \"%s\"", name); |
| 244 | |
| 245 | gdb_config.bytesex = 2 | (TARGET_BYTE_ORDER == BIG_ENDIAN ? 1 : 0); |
| 246 | gdb_config.fpe = 1; |
| 247 | gdb_config.rditype = 2; |
| 248 | gdb_config.heartbeat_on = 1; |
| 249 | gdb_config.flags = 2; |
| 250 | |
| 251 | gdb_hostif.dbgprint = myprint; |
| 252 | gdb_hostif.dbgpause = mypause; |
| 253 | gdb_hostif.dbgarg = NULL; |
| 254 | gdb_hostif.writec = mywritec; |
| 255 | gdb_hostif.readc = myreadc; |
| 256 | gdb_hostif.write = mywrite; |
| 257 | gdb_hostif.gets = mygets; |
| 258 | gdb_hostif.hostosarg = NULL; |
| 259 | gdb_hostif.reset = voiddummy; |
| 260 | |
| 261 | rslt = angel_RDI_open (10, &gdb_config, &gdb_hostif, NULL); |
| 262 | if (rslt == RDIError_BigEndian || rslt == RDIError_LittleEndian) |
| 263 | ; /* do nothing, this is the expected return */ |
| 264 | else if (rslt) |
| 265 | { |
| 266 | printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt)); |
| 267 | Adp_CloseDevice (); |
| 268 | error ("RDI_open failed\n"); |
| 269 | } |
| 270 | |
| 271 | rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2); |
| 272 | if (rslt) |
| 273 | { |
| 274 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 275 | } |
| 276 | rslt = angel_RDI_info (RDIInfo_Points, &arg1, &arg2); |
| 277 | if (rslt) |
| 278 | { |
| 279 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 280 | } |
| 281 | rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2); |
| 282 | if (rslt) |
| 283 | { |
| 284 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 285 | } |
| 286 | rslt = angel_RDI_info (RDIInfo_CoPro, &arg1, &arg2); |
| 287 | if (rslt) |
| 288 | { |
| 289 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 290 | } |
| 291 | rslt = angel_RDI_info (RDIInfo_SemiHosting, &arg1, &arg2); |
| 292 | if (rslt) |
| 293 | { |
| 294 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 295 | } |
| 296 | |
| 297 | rslt = angel_RDI_info (RDIInfo_GetLoadSize, &arg1, &arg2); |
| 298 | if (rslt) |
| 299 | { |
| 300 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 301 | } |
| 302 | max_load_size = arg1; |
| 303 | |
| 304 | push_target (&arm_rdi_ops); |
| 305 | |
| 306 | target_fetch_registers (-1); |
| 307 | |
| 308 | rslt = angel_RDI_open (1, &gdb_config, NULL, NULL); |
| 309 | if (rslt) |
| 310 | { |
| 311 | printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt)); |
| 312 | } |
| 313 | |
| 314 | arg1 = rom_at_zero ? 0x0 : 0x13b; |
| 315 | |
| 316 | rslt = angel_RDI_info (RDIVector_Catch, &arg1, &arg2); |
| 317 | if (rslt) |
| 318 | { |
| 319 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 320 | } |
| 321 | |
| 322 | arg1 = (unsigned long) ""; |
| 323 | rslt = angel_RDI_info (RDISet_Cmdline, &arg1, &arg2); |
| 324 | if (rslt) |
| 325 | { |
| 326 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 327 | } |
| 328 | |
| 329 | /* Clear out any existing records of breakpoints. */ |
| 330 | { |
| 331 | struct local_bp_list_entry *entry, *preventry = NULL; |
| 332 | |
| 333 | for (entry = local_bp_list; entry != NULL; entry = entry->next) |
| 334 | { |
| 335 | if (preventry) |
| 336 | xfree (preventry); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | printf_filtered ("Connected to ARM RDI target.\n"); |
| 341 | closed_already = 0; |
| 342 | inferior_pid = 42; |
| 343 | } |
| 344 | |
| 345 | /* Start an inferior process and set inferior_pid to its pid. |
| 346 | EXEC_FILE is the file to run. |
| 347 | ARGS is a string containing the arguments to the program. |
| 348 | ENV is the environment vector to pass. Errors reported with error(). |
| 349 | On VxWorks and various standalone systems, we ignore exec_file. */ |
| 350 | /* This is called not only when we first attach, but also when the |
| 351 | user types "run" after having attached. */ |
| 352 | |
| 353 | static void |
| 354 | arm_rdi_create_inferior (char *exec_file, char *args, char **env) |
| 355 | { |
| 356 | int len, rslt; |
| 357 | unsigned long arg1, arg2; |
| 358 | char *arg_buf; |
| 359 | CORE_ADDR entry_point; |
| 360 | |
| 361 | if (exec_file == 0 || exec_bfd == 0) |
| 362 | error ("No executable file specified."); |
| 363 | |
| 364 | entry_point = (CORE_ADDR) bfd_get_start_address (exec_bfd); |
| 365 | |
| 366 | arm_rdi_kill (); |
| 367 | remove_breakpoints (); |
| 368 | init_wait_for_inferior (); |
| 369 | |
| 370 | len = strlen (exec_file) + 1 + strlen (args) + 1 + /*slop */ 10; |
| 371 | arg_buf = (char *) alloca (len); |
| 372 | arg_buf[0] = '\0'; |
| 373 | strcat (arg_buf, exec_file); |
| 374 | strcat (arg_buf, " "); |
| 375 | strcat (arg_buf, args); |
| 376 | |
| 377 | inferior_pid = 42; |
| 378 | insert_breakpoints (); /* Needed to get correct instruction in cache */ |
| 379 | |
| 380 | if (env != NULL) |
| 381 | { |
| 382 | while (*env) |
| 383 | { |
| 384 | if (strncmp (*env, "MEMSIZE=", sizeof ("MEMSIZE=") - 1) == 0) |
| 385 | { |
| 386 | unsigned long top_of_memory; |
| 387 | char *end_of_num; |
| 388 | |
| 389 | /* Set up memory limit */ |
| 390 | top_of_memory = strtoul (*env + sizeof ("MEMSIZE=") - 1, |
| 391 | &end_of_num, 0); |
| 392 | printf_filtered ("Setting top-of-memory to 0x%lx\n", |
| 393 | top_of_memory); |
| 394 | |
| 395 | rslt = angel_RDI_info (RDIInfo_SetTopMem, &top_of_memory, &arg2); |
| 396 | if (rslt) |
| 397 | { |
| 398 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 399 | } |
| 400 | } |
| 401 | env++; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | arg1 = (unsigned long) arg_buf; |
| 406 | rslt = angel_RDI_info (RDISet_Cmdline, /* &arg1 */ (unsigned long *) arg_buf, &arg2); |
| 407 | if (rslt) |
| 408 | { |
| 409 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 410 | } |
| 411 | |
| 412 | proceed (entry_point, TARGET_SIGNAL_DEFAULT, 0); |
| 413 | } |
| 414 | |
| 415 | /* This takes a program previously attached to and detaches it. After |
| 416 | this is done, GDB can be used to debug some other program. We |
| 417 | better not have left any breakpoints in the target program or it'll |
| 418 | die when it hits one. */ |
| 419 | |
| 420 | static void |
| 421 | arm_rdi_detach (char *args, int from_tty) |
| 422 | { |
| 423 | pop_target (); |
| 424 | } |
| 425 | |
| 426 | /* Clean up connection to a remote debugger. */ |
| 427 | |
| 428 | static void |
| 429 | arm_rdi_close (int quitting) |
| 430 | { |
| 431 | int rslt; |
| 432 | |
| 433 | if (!closed_already) |
| 434 | { |
| 435 | rslt = angel_RDI_close (); |
| 436 | if (rslt) |
| 437 | { |
| 438 | printf_filtered ("RDI_close: %s\n", rdi_error_message (rslt)); |
| 439 | } |
| 440 | closed_already = 1; |
| 441 | inferior_pid = 0; |
| 442 | Adp_CloseDevice (); |
| 443 | generic_mourn_inferior (); |
| 444 | } |
| 445 | } |
| 446 | \f |
| 447 | /* Tell the remote machine to resume. */ |
| 448 | |
| 449 | static void |
| 450 | arm_rdi_resume (int pid, int step, enum target_signal siggnal) |
| 451 | { |
| 452 | int rslt; |
| 453 | PointHandle point; |
| 454 | |
| 455 | if (0 /* turn on when hardware supports single-stepping */ ) |
| 456 | { |
| 457 | rslt = angel_RDI_step (1, &point); |
| 458 | if (rslt) |
| 459 | { |
| 460 | printf_filtered ("RDI_step: %s\n", rdi_error_message (rslt)); |
| 461 | } |
| 462 | } |
| 463 | else |
| 464 | { |
| 465 | char handle[4]; |
| 466 | CORE_ADDR pc; |
| 467 | |
| 468 | if (step) |
| 469 | { |
| 470 | pc = read_register (PC_REGNUM); |
| 471 | pc = arm_get_next_pc (pc); |
| 472 | arm_rdi_insert_breakpoint (pc, handle); |
| 473 | } |
| 474 | execute_status = rslt = angel_RDI_execute (&point); |
| 475 | if (rslt == RDIError_BreakpointReached) |
| 476 | ; |
| 477 | else if (rslt) |
| 478 | { |
| 479 | printf_filtered ("RDI_execute: %s\n", rdi_error_message (rslt)); |
| 480 | } |
| 481 | if (step) |
| 482 | { |
| 483 | arm_rdi_remove_breakpoint (pc, handle); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | \f |
| 488 | /* Send ^C to target to halt it. Target will respond, and send us a |
| 489 | packet. */ |
| 490 | |
| 491 | static void |
| 492 | arm_rdi_interrupt (int signo) |
| 493 | { |
| 494 | } |
| 495 | |
| 496 | static void (*ofunc) (); |
| 497 | |
| 498 | /* The user typed ^C twice. */ |
| 499 | static void |
| 500 | arm_rdi_interrupt_twice (int signo) |
| 501 | { |
| 502 | } |
| 503 | |
| 504 | /* Ask the user what to do when an interrupt is received. */ |
| 505 | |
| 506 | static void |
| 507 | interrupt_query (void) |
| 508 | { |
| 509 | } |
| 510 | |
| 511 | /* Wait until the remote machine stops, then return, storing status in |
| 512 | STATUS just as `wait' would. Returns "pid" (though it's not clear |
| 513 | what, if anything, that means in the case of this target). */ |
| 514 | |
| 515 | static int |
| 516 | arm_rdi_wait (int pid, struct target_waitstatus *status) |
| 517 | { |
| 518 | status->kind = (execute_status == RDIError_NoError ? |
| 519 | TARGET_WAITKIND_EXITED : TARGET_WAITKIND_STOPPED); |
| 520 | |
| 521 | /* convert stopped code from target into right signal */ |
| 522 | status->value.sig = rdi_error_signal (execute_status); |
| 523 | |
| 524 | return inferior_pid; |
| 525 | } |
| 526 | |
| 527 | /* Read the remote registers into the block REGS. */ |
| 528 | |
| 529 | /* ARGSUSED */ |
| 530 | static void |
| 531 | arm_rdi_fetch_registers (int regno) |
| 532 | { |
| 533 | int rslt, rdi_regmask; |
| 534 | unsigned long rawreg, rawregs[32]; |
| 535 | char cookedreg[4]; |
| 536 | |
| 537 | if (regno == -1) |
| 538 | { |
| 539 | rslt = angel_RDI_CPUread (255, 0x27fff, rawregs); |
| 540 | if (rslt) |
| 541 | { |
| 542 | printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt)); |
| 543 | } |
| 544 | |
| 545 | for (regno = 0; regno < 15; regno++) |
| 546 | { |
| 547 | store_unsigned_integer (cookedreg, 4, rawregs[regno]); |
| 548 | supply_register (regno, (char *) cookedreg); |
| 549 | } |
| 550 | store_unsigned_integer (cookedreg, 4, rawregs[15]); |
| 551 | supply_register (PS_REGNUM, (char *) cookedreg); |
| 552 | arm_rdi_fetch_registers (PC_REGNUM); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | if (regno == PC_REGNUM) |
| 557 | rdi_regmask = RDIReg_PC; |
| 558 | else if (regno == PS_REGNUM) |
| 559 | rdi_regmask = RDIReg_CPSR; |
| 560 | else if (regno < 0 || regno > 15) |
| 561 | { |
| 562 | rawreg = 0; |
| 563 | supply_register (regno, (char *) &rawreg); |
| 564 | return; |
| 565 | } |
| 566 | else |
| 567 | rdi_regmask = 1 << regno; |
| 568 | |
| 569 | rslt = angel_RDI_CPUread (255, rdi_regmask, &rawreg); |
| 570 | if (rslt) |
| 571 | { |
| 572 | printf_filtered ("RDI_CPUread: %s\n", rdi_error_message (rslt)); |
| 573 | } |
| 574 | store_unsigned_integer (cookedreg, 4, rawreg); |
| 575 | supply_register (regno, (char *) cookedreg); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | static void |
| 580 | arm_rdi_prepare_to_store (void) |
| 581 | { |
| 582 | /* Nothing to do. */ |
| 583 | } |
| 584 | |
| 585 | /* Store register REGNO, or all registers if REGNO == -1, from the contents |
| 586 | of REGISTERS. FIXME: ignores errors. */ |
| 587 | |
| 588 | static void |
| 589 | arm_rdi_store_registers (int regno) |
| 590 | { |
| 591 | int rslt, rdi_regmask; |
| 592 | |
| 593 | /* These need to be able to take 'floating point register' contents */ |
| 594 | unsigned long rawreg[3], rawerreg[3]; |
| 595 | |
| 596 | if (regno == -1) |
| 597 | { |
| 598 | for (regno = 0; regno < NUM_REGS; regno++) |
| 599 | arm_rdi_store_registers (regno); |
| 600 | } |
| 601 | else |
| 602 | { |
| 603 | read_register_gen (regno, (char *) rawreg); |
| 604 | /* RDI manipulates data in host byte order, so convert now. */ |
| 605 | store_unsigned_integer (rawerreg, 4, rawreg[0]); |
| 606 | |
| 607 | if (regno == PC_REGNUM) |
| 608 | rdi_regmask = RDIReg_PC; |
| 609 | else if (regno == PS_REGNUM) |
| 610 | rdi_regmask = RDIReg_CPSR; |
| 611 | else if (regno < 0 || regno > 15) |
| 612 | return; |
| 613 | else |
| 614 | rdi_regmask = 1 << regno; |
| 615 | |
| 616 | rslt = angel_RDI_CPUwrite (255, rdi_regmask, rawerreg); |
| 617 | if (rslt) |
| 618 | { |
| 619 | printf_filtered ("RDI_CPUwrite: %s\n", rdi_error_message (rslt)); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | \f |
| 624 | /* Read or write LEN bytes from inferior memory at MEMADDR, |
| 625 | transferring to or from debugger address MYADDR. Write to inferior |
| 626 | if SHOULD_WRITE is nonzero. Returns length of data written or |
| 627 | read; 0 for error. TARGET is unused. */ |
| 628 | |
| 629 | /* ARGSUSED */ |
| 630 | static int |
| 631 | arm_rdi_xfer_memory (CORE_ADDR memaddr, char *myaddr, int len, int should_write, |
| 632 | struct mem_attrib *attrib ATTRIBUTE_UNUSED, |
| 633 | struct target_ops *target ATTRIBUTE_UNUSED) |
| 634 | { |
| 635 | int rslt, i; |
| 636 | |
| 637 | if (should_write) |
| 638 | { |
| 639 | rslt = angel_RDI_write (myaddr, memaddr, &len); |
| 640 | if (rslt) |
| 641 | { |
| 642 | printf_filtered ("RDI_write: %s\n", rdi_error_message (rslt)); |
| 643 | } |
| 644 | } |
| 645 | else |
| 646 | { |
| 647 | rslt = angel_RDI_read (memaddr, myaddr, &len); |
| 648 | if (rslt) |
| 649 | { |
| 650 | printf_filtered ("RDI_read: %s\n", rdi_error_message (rslt)); |
| 651 | len = 0; |
| 652 | } |
| 653 | } |
| 654 | return len; |
| 655 | } |
| 656 | \f |
| 657 | /* Display random info collected from the target. */ |
| 658 | |
| 659 | static void |
| 660 | arm_rdi_files_info (struct target_ops *ignore) |
| 661 | { |
| 662 | char *file = "nothing"; |
| 663 | int rslt; |
| 664 | unsigned long arg1, arg2; |
| 665 | |
| 666 | rslt = angel_RDI_info (RDIInfo_Target, &arg1, &arg2); |
| 667 | if (rslt) |
| 668 | { |
| 669 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 670 | } |
| 671 | if (arg1 & (1 << 15)) |
| 672 | printf_filtered ("Target supports Thumb code.\n"); |
| 673 | if (arg1 & (1 << 14)) |
| 674 | printf_filtered ("Target can do profiling.\n"); |
| 675 | if (arg1 & (1 << 4)) |
| 676 | printf_filtered ("Target is real hardware.\n"); |
| 677 | |
| 678 | rslt = angel_RDI_info (RDIInfo_Step, &arg1, &arg2); |
| 679 | if (rslt) |
| 680 | { |
| 681 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 682 | } |
| 683 | printf_filtered ("Target can%s single-step.\n", (arg1 & 0x4 ? "" : "not")); |
| 684 | |
| 685 | rslt = angel_RDI_info (RDIInfo_Icebreaker, &arg1, &arg2); |
| 686 | if (rslt) |
| 687 | { |
| 688 | printf_filtered ("RDI_info: %s\n", rdi_error_message (rslt)); |
| 689 | } |
| 690 | else |
| 691 | printf_filtered ("Target includes an EmbeddedICE.\n"); |
| 692 | } |
| 693 | \f |
| 694 | static void |
| 695 | arm_rdi_kill (void) |
| 696 | { |
| 697 | int rslt; |
| 698 | |
| 699 | rslt = angel_RDI_open (1, &gdb_config, NULL, NULL); |
| 700 | if (rslt) |
| 701 | { |
| 702 | printf_filtered ("RDI_open: %s\n", rdi_error_message (rslt)); |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | static void |
| 707 | arm_rdi_mourn_inferior (void) |
| 708 | { |
| 709 | /* We remove the inserted breakpoints in case the user wants to |
| 710 | issue another target and load commands to rerun his application; |
| 711 | This is something that wouldn't work on a native target, for instance, |
| 712 | as the process goes away when the inferior exits, but it works with |
| 713 | some remote targets like this one. That is why this is done here. */ |
| 714 | remove_breakpoints(); |
| 715 | unpush_target (&arm_rdi_ops); |
| 716 | generic_mourn_inferior (); |
| 717 | } |
| 718 | \f |
| 719 | /* While the RDI library keeps track of its own breakpoints, we need |
| 720 | to remember "handles" so that we can delete them later. Since |
| 721 | breakpoints get used for stepping, be careful not to leak memory |
| 722 | here. */ |
| 723 | |
| 724 | static int |
| 725 | arm_rdi_insert_breakpoint (CORE_ADDR addr, char *contents_cache) |
| 726 | { |
| 727 | int rslt; |
| 728 | PointHandle point; |
| 729 | struct local_bp_list_entry *entry; |
| 730 | int type = RDIPoint_EQ; |
| 731 | |
| 732 | if (arm_pc_is_thumb (addr) || arm_pc_is_thumb_dummy (addr)) |
| 733 | type |= RDIPoint_16Bit; |
| 734 | rslt = angel_RDI_setbreak (addr, type, 0, &point); |
| 735 | if (rslt) |
| 736 | { |
| 737 | printf_filtered ("RDI_setbreak: %s\n", rdi_error_message (rslt)); |
| 738 | } |
| 739 | entry = |
| 740 | (struct local_bp_list_entry *) xmalloc (sizeof (struct local_bp_list_entry)); |
| 741 | entry->addr = addr; |
| 742 | entry->point = point; |
| 743 | entry->next = local_bp_list; |
| 744 | local_bp_list = entry; |
| 745 | return rslt; |
| 746 | } |
| 747 | |
| 748 | static int |
| 749 | arm_rdi_remove_breakpoint (CORE_ADDR addr, char *contents_cache) |
| 750 | { |
| 751 | int rslt; |
| 752 | PointHandle point; |
| 753 | struct local_bp_list_entry *entry, *preventry; |
| 754 | |
| 755 | for (entry = local_bp_list; entry != NULL; entry = entry->next) |
| 756 | { |
| 757 | if (entry->addr == addr) |
| 758 | { |
| 759 | break; |
| 760 | } |
| 761 | preventry = entry; |
| 762 | } |
| 763 | if (entry) |
| 764 | { |
| 765 | rslt = angel_RDI_clearbreak (entry->point); |
| 766 | if (rslt) |
| 767 | { |
| 768 | printf_filtered ("RDI_clearbreak: %s\n", rdi_error_message (rslt)); |
| 769 | } |
| 770 | /* Delete the breakpoint entry locally. */ |
| 771 | if (entry == local_bp_list) |
| 772 | { |
| 773 | local_bp_list = entry->next; |
| 774 | } |
| 775 | else |
| 776 | { |
| 777 | preventry->next = entry->next; |
| 778 | } |
| 779 | xfree (entry); |
| 780 | } |
| 781 | return 0; |
| 782 | } |
| 783 | \f |
| 784 | static char * |
| 785 | rdi_error_message (int err) |
| 786 | { |
| 787 | switch (err) |
| 788 | { |
| 789 | case RDIError_NoError: |
| 790 | return "no error"; |
| 791 | case RDIError_Reset: |
| 792 | return "debuggee reset"; |
| 793 | case RDIError_UndefinedInstruction: |
| 794 | return "undefined instruction"; |
| 795 | case RDIError_SoftwareInterrupt: |
| 796 | return "SWI trapped"; |
| 797 | case RDIError_PrefetchAbort: |
| 798 | return "prefetch abort, execution ran into unmapped memory?"; |
| 799 | case RDIError_DataAbort: |
| 800 | return "data abort, no memory at specified address?"; |
| 801 | case RDIError_AddressException: |
| 802 | return "address exception, access >26bit in 26bit mode"; |
| 803 | case RDIError_IRQ: |
| 804 | return "IRQ, interrupt trapped"; |
| 805 | case RDIError_FIQ: |
| 806 | return "FIQ, fast interrupt trapped"; |
| 807 | case RDIError_Error: |
| 808 | return "a miscellaneous type of error"; |
| 809 | case RDIError_BranchThrough0: |
| 810 | return "branch through location 0"; |
| 811 | case RDIError_NotInitialised: |
| 812 | return "internal error, RDI_open not called first"; |
| 813 | case RDIError_UnableToInitialise: |
| 814 | return "internal error, target world is broken"; |
| 815 | case RDIError_WrongByteSex: |
| 816 | return "See Operator: WrongByteSex"; |
| 817 | case RDIError_UnableToTerminate: |
| 818 | return "See Operator: Unable to Terminate"; |
| 819 | case RDIError_BadInstruction: |
| 820 | return "bad instruction, illegal to execute this instruction"; |
| 821 | case RDIError_IllegalInstruction: |
| 822 | return "illegal instruction, the effect of executing it is undefined"; |
| 823 | case RDIError_BadCPUStateSetting: |
| 824 | return "internal error, tried to set SPSR of user mode"; |
| 825 | case RDIError_UnknownCoPro: |
| 826 | return "unknown co-processor"; |
| 827 | case RDIError_UnknownCoProState: |
| 828 | return "cannot execute co-processor request"; |
| 829 | case RDIError_BadCoProState: |
| 830 | return "recognizably broken co-processor request"; |
| 831 | case RDIError_BadPointType: |
| 832 | return "internal error, bad point yype"; |
| 833 | case RDIError_UnimplementedType: |
| 834 | return "internal error, unimplemented type"; |
| 835 | case RDIError_BadPointSize: |
| 836 | return "internal error, bad point size"; |
| 837 | case RDIError_UnimplementedSize: |
| 838 | return "internal error, unimplemented size"; |
| 839 | case RDIError_NoMorePoints: |
| 840 | return "last break/watch point was used"; |
| 841 | case RDIError_BreakpointReached: |
| 842 | return "breakpoint reached"; |
| 843 | case RDIError_WatchpointAccessed: |
| 844 | return "watchpoint accessed"; |
| 845 | case RDIError_NoSuchPoint: |
| 846 | return "attempted to clear non-existent break/watch point"; |
| 847 | case RDIError_ProgramFinishedInStep: |
| 848 | return "end of the program reached while stepping"; |
| 849 | case RDIError_UserInterrupt: |
| 850 | return "you pressed Escape"; |
| 851 | case RDIError_CantSetPoint: |
| 852 | return "no more break/watch points available"; |
| 853 | case RDIError_IncompatibleRDILevels: |
| 854 | return "incompatible RDI levels"; |
| 855 | case RDIError_LittleEndian: |
| 856 | return "debuggee is little endian"; |
| 857 | case RDIError_BigEndian: |
| 858 | return "debuggee is big endian"; |
| 859 | case RDIError_SoftInitialiseError: |
| 860 | return "recoverable error in RDI initialization"; |
| 861 | case RDIError_InsufficientPrivilege: |
| 862 | return "internal error, supervisor state not accessible to monitor"; |
| 863 | case RDIError_UnimplementedMessage: |
| 864 | return "internal error, unimplemented message"; |
| 865 | case RDIError_UndefinedMessage: |
| 866 | return "internal error, undefined message"; |
| 867 | default: |
| 868 | return "undefined error message, should reset target"; |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | /* Convert the ARM error messages to signals that GDB knows about. */ |
| 873 | |
| 874 | static enum target_signal |
| 875 | rdi_error_signal (int err) |
| 876 | { |
| 877 | switch (err) |
| 878 | { |
| 879 | case RDIError_NoError: |
| 880 | return 0; |
| 881 | case RDIError_Reset: |
| 882 | return TARGET_SIGNAL_TERM; /* ??? */ |
| 883 | case RDIError_UndefinedInstruction: |
| 884 | return TARGET_SIGNAL_ILL; |
| 885 | case RDIError_SoftwareInterrupt: |
| 886 | case RDIError_PrefetchAbort: |
| 887 | case RDIError_DataAbort: |
| 888 | return TARGET_SIGNAL_TRAP; |
| 889 | case RDIError_AddressException: |
| 890 | return TARGET_SIGNAL_SEGV; |
| 891 | case RDIError_IRQ: |
| 892 | case RDIError_FIQ: |
| 893 | return TARGET_SIGNAL_TRAP; |
| 894 | case RDIError_Error: |
| 895 | return TARGET_SIGNAL_TERM; |
| 896 | case RDIError_BranchThrough0: |
| 897 | return TARGET_SIGNAL_TRAP; |
| 898 | case RDIError_NotInitialised: |
| 899 | case RDIError_UnableToInitialise: |
| 900 | case RDIError_WrongByteSex: |
| 901 | case RDIError_UnableToTerminate: |
| 902 | return TARGET_SIGNAL_UNKNOWN; |
| 903 | case RDIError_BadInstruction: |
| 904 | case RDIError_IllegalInstruction: |
| 905 | return TARGET_SIGNAL_ILL; |
| 906 | case RDIError_BadCPUStateSetting: |
| 907 | case RDIError_UnknownCoPro: |
| 908 | case RDIError_UnknownCoProState: |
| 909 | case RDIError_BadCoProState: |
| 910 | case RDIError_BadPointType: |
| 911 | case RDIError_UnimplementedType: |
| 912 | case RDIError_BadPointSize: |
| 913 | case RDIError_UnimplementedSize: |
| 914 | case RDIError_NoMorePoints: |
| 915 | return TARGET_SIGNAL_UNKNOWN; |
| 916 | case RDIError_BreakpointReached: |
| 917 | case RDIError_WatchpointAccessed: |
| 918 | return TARGET_SIGNAL_TRAP; |
| 919 | case RDIError_NoSuchPoint: |
| 920 | case RDIError_ProgramFinishedInStep: |
| 921 | return TARGET_SIGNAL_UNKNOWN; |
| 922 | case RDIError_UserInterrupt: |
| 923 | return TARGET_SIGNAL_INT; |
| 924 | case RDIError_IncompatibleRDILevels: |
| 925 | case RDIError_LittleEndian: |
| 926 | case RDIError_BigEndian: |
| 927 | case RDIError_SoftInitialiseError: |
| 928 | case RDIError_InsufficientPrivilege: |
| 929 | case RDIError_UnimplementedMessage: |
| 930 | case RDIError_UndefinedMessage: |
| 931 | default: |
| 932 | return TARGET_SIGNAL_UNKNOWN; |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | static void |
| 937 | arm_rdi_stop(void) |
| 938 | { |
| 939 | angel_RDI_stop_request(); |
| 940 | } |
| 941 | |
| 942 | \f |
| 943 | /* Define the target operations structure. */ |
| 944 | |
| 945 | static void |
| 946 | init_rdi_ops (void) |
| 947 | { |
| 948 | arm_rdi_ops.to_shortname = "rdi"; |
| 949 | arm_rdi_ops.to_longname = "ARM RDI"; |
| 950 | arm_rdi_ops.to_doc = "Use a remote ARM-based computer; via the RDI library.\n\ |
| 951 | Specify the serial device it is connected to (e.g. /dev/ttya)."; |
| 952 | arm_rdi_ops.to_open = arm_rdi_open; |
| 953 | arm_rdi_ops.to_close = arm_rdi_close; |
| 954 | arm_rdi_ops.to_detach = arm_rdi_detach; |
| 955 | arm_rdi_ops.to_resume = arm_rdi_resume; |
| 956 | arm_rdi_ops.to_wait = arm_rdi_wait; |
| 957 | arm_rdi_ops.to_stop = arm_rdi_stop; |
| 958 | arm_rdi_ops.to_fetch_registers = arm_rdi_fetch_registers; |
| 959 | arm_rdi_ops.to_store_registers = arm_rdi_store_registers; |
| 960 | arm_rdi_ops.to_prepare_to_store = arm_rdi_prepare_to_store; |
| 961 | arm_rdi_ops.to_xfer_memory = arm_rdi_xfer_memory; |
| 962 | arm_rdi_ops.to_files_info = arm_rdi_files_info; |
| 963 | arm_rdi_ops.to_insert_breakpoint = arm_rdi_insert_breakpoint; |
| 964 | arm_rdi_ops.to_remove_breakpoint = arm_rdi_remove_breakpoint; |
| 965 | arm_rdi_ops.to_kill = arm_rdi_kill; |
| 966 | arm_rdi_ops.to_load = generic_load; |
| 967 | arm_rdi_ops.to_create_inferior = arm_rdi_create_inferior; |
| 968 | arm_rdi_ops.to_mourn_inferior = arm_rdi_mourn_inferior; |
| 969 | arm_rdi_ops.to_stratum = process_stratum; |
| 970 | arm_rdi_ops.to_has_all_memory = 1; |
| 971 | arm_rdi_ops.to_has_memory = 1; |
| 972 | arm_rdi_ops.to_has_stack = 1; |
| 973 | arm_rdi_ops.to_has_registers = 1; |
| 974 | arm_rdi_ops.to_has_execution = 1; |
| 975 | arm_rdi_ops.to_magic = OPS_MAGIC; |
| 976 | } |
| 977 | |
| 978 | static void |
| 979 | rdilogfile_command (char *arg, int from_tty) |
| 980 | { |
| 981 | if (!arg || strlen (arg) == 0) |
| 982 | { |
| 983 | printf_filtered ("rdi log file is '%s'\n", log_filename); |
| 984 | return; |
| 985 | } |
| 986 | |
| 987 | if (log_filename) |
| 988 | xfree (log_filename); |
| 989 | |
| 990 | log_filename = xstrdup (arg); |
| 991 | |
| 992 | Adp_SetLogfile (log_filename); |
| 993 | } |
| 994 | |
| 995 | static void |
| 996 | rdilogenable_command (char *args, int from_tty) |
| 997 | { |
| 998 | if (!args || strlen (args) == 0) |
| 999 | { |
| 1000 | printf_filtered ("rdi log is %s\n", log_enable ? "enabled" : "disabled"); |
| 1001 | return; |
| 1002 | } |
| 1003 | |
| 1004 | if (!strcasecmp (args, "1") || |
| 1005 | !strcasecmp (args, "y") || |
| 1006 | !strcasecmp (args, "yes") || |
| 1007 | !strcasecmp (args, "on") || |
| 1008 | !strcasecmp (args, "t") || |
| 1009 | !strcasecmp (args, "true")) |
| 1010 | Adp_SetLogEnable (log_enable = 1); |
| 1011 | else if (!strcasecmp (args, "0") || |
| 1012 | !strcasecmp (args, "n") || |
| 1013 | !strcasecmp (args, "no") || |
| 1014 | !strcasecmp (args, "off") || |
| 1015 | !strcasecmp (args, "f") || |
| 1016 | !strcasecmp (args, "false")) |
| 1017 | Adp_SetLogEnable (log_enable = 0); |
| 1018 | else |
| 1019 | printf_filtered ("rdilogenable: unrecognized argument '%s'\n" |
| 1020 | " try y or n\n", args); |
| 1021 | } |
| 1022 | |
| 1023 | void |
| 1024 | _initialize_remote_rdi (void) |
| 1025 | { |
| 1026 | struct cmd_list_element *c; |
| 1027 | |
| 1028 | init_rdi_ops (); |
| 1029 | add_target (&arm_rdi_ops); |
| 1030 | |
| 1031 | log_filename = xstrdup ("rdi.log"); |
| 1032 | Adp_SetLogfile (log_filename); |
| 1033 | Adp_SetLogEnable (log_enable); |
| 1034 | |
| 1035 | c = add_cmd ("rdilogfile", class_maintenance, |
| 1036 | rdilogfile_command, |
| 1037 | "Set filename for ADP packet log.\n\ |
| 1038 | This file is used to log Angel Debugger Protocol packets.\n\ |
| 1039 | With a single argument, sets the logfile name to that value.\n\ |
| 1040 | Without an argument, shows the current logfile name.\n\ |
| 1041 | See also: rdilogenable\n", |
| 1042 | &maintenancelist); |
| 1043 | c->completer = filename_completer; |
| 1044 | |
| 1045 | add_cmd ("rdilogenable", class_maintenance, |
| 1046 | rdilogenable_command, |
| 1047 | "Set enable logging of ADP packets.\n\ |
| 1048 | This will log ADP packets exchanged between gdb and the\n\ |
| 1049 | rdi target device.\n\ |
| 1050 | An argument of 1,t,true,y,yes will enable.\n\ |
| 1051 | An argument of 0,f,false,n,no will disabled.\n\ |
| 1052 | Withough an argument, it will display current state.\n", |
| 1053 | &maintenancelist); |
| 1054 | |
| 1055 | add_show_from_set |
| 1056 | (add_set_cmd ("rdiromatzero", no_class, |
| 1057 | var_boolean, (char *) &rom_at_zero, |
| 1058 | "Set target has ROM at addr 0.\n\ |
| 1059 | A true value disables vector catching, false enables vector catching.\n\ |
| 1060 | This is evaluated at the time the 'target rdi' command is executed\n", |
| 1061 | &setlist), |
| 1062 | &showlist); |
| 1063 | |
| 1064 | add_show_from_set |
| 1065 | (add_set_cmd ("rdiheartbeat", no_class, |
| 1066 | var_boolean, (char *) &rdi_heartbeat, |
| 1067 | "Set enable for ADP heartbeat packets.\n\ |
| 1068 | I don't know why you would want this. If you enable them,\n\ |
| 1069 | it will confuse ARM and EPI JTAG interface boxes as well\n\ |
| 1070 | as the Angel Monitor.\n", |
| 1071 | &setlist), |
| 1072 | &showlist); |
| 1073 | } |
| 1074 | |
| 1075 | /* A little dummy to make linking with the library succeed. */ |
| 1076 | |
| 1077 | int |
| 1078 | Fail (void) |
| 1079 | { |
| 1080 | return 0; |
| 1081 | } |