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