| 1 | /* Remote debugging interface for Am290*0 running MiniMON monitor, for GDB. |
| 2 | Copyright 1990, 1991, 1992, 2001 Free Software Foundation, Inc. |
| 3 | Originally written by Daniel Mann at AMD. |
| 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 | /* This is like remote.c but ecpects MiniMON to be running on the Am29000 |
| 23 | target hardware. |
| 24 | - David Wood (wood@lab.ultra.nyu.edu) at New York University adapted this |
| 25 | file to gdb 3.95. I was unable to get this working on sun3os4 |
| 26 | with termio, only with sgtty. Because we are only attempting to |
| 27 | use this module to debug our kernel, which is already loaded when |
| 28 | gdb is started up, I did not code up the file downloading facilities. |
| 29 | As a result this module has only the stubs to download files. |
| 30 | You should get tagged at compile time if you need to make any |
| 31 | changes/additions. */ |
| 32 | |
| 33 | #include "defs.h" |
| 34 | #include "inferior.h" |
| 35 | #include "gdb_wait.h" |
| 36 | #include "value.h" |
| 37 | #include <ctype.h> |
| 38 | #include <fcntl.h> |
| 39 | #include <signal.h> |
| 40 | #include <errno.h> |
| 41 | #include "gdb_string.h" |
| 42 | #include "terminal.h" |
| 43 | #include "minimon.h" |
| 44 | #include "target.h" |
| 45 | |
| 46 | /* Offset of member MEMBER in a struct of type TYPE. */ |
| 47 | #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER) |
| 48 | |
| 49 | #define DRAIN_INPUT() (msg_recv_serial((union msg_t*)0)) |
| 50 | |
| 51 | extern int stop_soon_quietly; /* for wait_for_inferior */ |
| 52 | |
| 53 | static void mm_resume (); |
| 54 | static void mm_fetch_registers (); |
| 55 | static int fetch_register (); |
| 56 | static void mm_store_registers (); |
| 57 | static int store_register (); |
| 58 | static int regnum_to_srnum (); |
| 59 | static void mm_close (); |
| 60 | static char *msg_str (); |
| 61 | static char *error_msg_str (); |
| 62 | static int expect_msg (); |
| 63 | static void init_target_mm (); |
| 64 | static int mm_memory_space (); |
| 65 | |
| 66 | #define FREEZE_MODE (read_register(CPS_REGNUM) && 0x400) |
| 67 | #define USE_SHADOW_PC ((processor_type == a29k_freeze_mode) && FREEZE_MODE) |
| 68 | |
| 69 | /* FIXME: Replace with `set remotedebug'. */ |
| 70 | #define LLOG_FILE "minimon.log" |
| 71 | #if defined (LOG_FILE) |
| 72 | FILE *log_file; |
| 73 | #endif |
| 74 | |
| 75 | /* |
| 76 | * Size of message buffers. I couldn't get memory reads to work when |
| 77 | * the byte_count was larger than 512 (it may be a baud rate problem). |
| 78 | */ |
| 79 | #define BUFER_SIZE 512 |
| 80 | /* |
| 81 | * Size of data area in message buffer on the TARGET (remote system). |
| 82 | */ |
| 83 | #define MAXDATA_T (target_config.max_msg_size - \ |
| 84 | offsetof(struct write_r_msg_t,data[0])) |
| 85 | /* |
| 86 | * Size of data area in message buffer on the HOST (gdb). |
| 87 | */ |
| 88 | #define MAXDATA_H (BUFER_SIZE - offsetof(struct write_r_msg_t,data[0])) |
| 89 | /* |
| 90 | * Defined as the minimum size of data areas of the two message buffers |
| 91 | */ |
| 92 | #define MAXDATA (MAXDATA_H < MAXDATA_T ? MAXDATA_H : MAXDATA_T) |
| 93 | |
| 94 | static char out_buf[BUFER_SIZE]; |
| 95 | static char in_buf[BUFER_SIZE]; |
| 96 | |
| 97 | int msg_recv_serial (); |
| 98 | int msg_send_serial (); |
| 99 | |
| 100 | #define MAX_RETRIES 5000 |
| 101 | extern struct target_ops mm_ops; /* Forward declaration */ |
| 102 | struct config_msg_t target_config; /* HIF needs this */ |
| 103 | union msg_t *out_msg_buf = (union msg_t *) out_buf; |
| 104 | union msg_t *in_msg_buf = (union msg_t *) in_buf; |
| 105 | |
| 106 | static int timeout = 5; |
| 107 | |
| 108 | /* Descriptor for I/O to remote machine. Initialize it to -1 so that |
| 109 | mm_open knows that we don't have a file open when the program |
| 110 | starts. */ |
| 111 | int mm_desc = -1; |
| 112 | |
| 113 | /* stream which is fdopen'd from mm_desc. Only valid when |
| 114 | mm_desc != -1. */ |
| 115 | FILE *mm_stream; |
| 116 | |
| 117 | /* Called when SIGALRM signal sent due to alarm() timeout. */ |
| 118 | #ifndef HAVE_TERMIO |
| 119 | |
| 120 | #ifndef __STDC__ |
| 121 | #ifndef volatile |
| 122 | #define volatile |
| 123 | /**/ |
| 124 | # endif |
| 125 | #endif |
| 126 | volatile int n_alarms; |
| 127 | |
| 128 | static void |
| 129 | mm_timer (void) |
| 130 | { |
| 131 | #if 0 |
| 132 | if (kiodebug) |
| 133 | printf ("mm_timer called\n"); |
| 134 | #endif |
| 135 | n_alarms++; |
| 136 | } |
| 137 | #endif /* HAVE_TERMIO */ |
| 138 | |
| 139 | /* malloc'd name of the program on the remote system. */ |
| 140 | static char *prog_name = NULL; |
| 141 | |
| 142 | |
| 143 | /* Number of SIGTRAPs we need to simulate. That is, the next |
| 144 | NEED_ARTIFICIAL_TRAP calls to mm_wait should just return |
| 145 | SIGTRAP without actually waiting for anything. */ |
| 146 | |
| 147 | /**************************************************** REMOTE_CREATE_INFERIOR */ |
| 148 | /* This is called not only when we first attach, but also when the |
| 149 | user types "run" after having attached. */ |
| 150 | static void |
| 151 | mm_create_inferior (char *execfile, char *args, char **env) |
| 152 | { |
| 153 | #define MAX_TOKENS 25 |
| 154 | #define BUFFER_SIZE 256 |
| 155 | int token_count; |
| 156 | int result; |
| 157 | char *token[MAX_TOKENS]; |
| 158 | char cmd_line[BUFFER_SIZE]; |
| 159 | |
| 160 | if (args && *args) |
| 161 | error ("Can't pass arguments to remote mm process (yet)."); |
| 162 | |
| 163 | if (execfile == 0 /* || exec_bfd == 0 */ ) |
| 164 | error ("No executable file specified"); |
| 165 | |
| 166 | if (!mm_stream) |
| 167 | { |
| 168 | printf ("Minimon not open yet.\n"); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | /* On ultra3 (NYU) we assume the kernel is already running so there is |
| 173 | no file to download. |
| 174 | FIXME: Fixed required here -> load your program, possibly with mm_load(). |
| 175 | */ |
| 176 | printf_filtered ("\n\ |
| 177 | Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n"); |
| 178 | |
| 179 | /* We will get a task spawn event immediately. */ |
| 180 | init_wait_for_inferior (); |
| 181 | clear_proceed_status (); |
| 182 | stop_soon_quietly = 1; |
| 183 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
| 184 | normal_stop (); |
| 185 | } |
| 186 | /**************************************************** REMOTE_MOURN_INFERIOR */ |
| 187 | static void |
| 188 | mm_mourn (void) |
| 189 | { |
| 190 | pop_target (); /* Pop back to no-child state */ |
| 191 | generic_mourn_inferior (); |
| 192 | } |
| 193 | |
| 194 | /********************************************************************** damn_b |
| 195 | */ |
| 196 | /* Translate baud rates from integers to damn B_codes. Unix should |
| 197 | have outgrown this crap years ago, but even POSIX wouldn't buck it. */ |
| 198 | |
| 199 | #ifndef B19200 |
| 200 | #define B19200 EXTA |
| 201 | #endif |
| 202 | #ifndef B38400 |
| 203 | #define B38400 EXTB |
| 204 | #endif |
| 205 | |
| 206 | static struct |
| 207 | { |
| 208 | int rate, damn_b; |
| 209 | } |
| 210 | baudtab[] = |
| 211 | { |
| 212 | { |
| 213 | 0, B0 |
| 214 | } |
| 215 | , |
| 216 | { |
| 217 | 50, B50 |
| 218 | } |
| 219 | , |
| 220 | { |
| 221 | 75, B75 |
| 222 | } |
| 223 | , |
| 224 | { |
| 225 | 110, B110 |
| 226 | } |
| 227 | , |
| 228 | { |
| 229 | 134, B134 |
| 230 | } |
| 231 | , |
| 232 | { |
| 233 | 150, B150 |
| 234 | } |
| 235 | , |
| 236 | { |
| 237 | 200, B200 |
| 238 | } |
| 239 | , |
| 240 | { |
| 241 | 300, B300 |
| 242 | } |
| 243 | , |
| 244 | { |
| 245 | 600, B600 |
| 246 | } |
| 247 | , |
| 248 | { |
| 249 | 1200, B1200 |
| 250 | } |
| 251 | , |
| 252 | { |
| 253 | 1800, B1800 |
| 254 | } |
| 255 | , |
| 256 | { |
| 257 | 2400, B2400 |
| 258 | } |
| 259 | , |
| 260 | { |
| 261 | 4800, B4800 |
| 262 | } |
| 263 | , |
| 264 | { |
| 265 | 9600, B9600 |
| 266 | } |
| 267 | , |
| 268 | { |
| 269 | 19200, B19200 |
| 270 | } |
| 271 | , |
| 272 | { |
| 273 | 38400, B38400 |
| 274 | } |
| 275 | , |
| 276 | { |
| 277 | -1, -1 |
| 278 | } |
| 279 | , |
| 280 | }; |
| 281 | |
| 282 | static int |
| 283 | damn_b (int rate) |
| 284 | { |
| 285 | int i; |
| 286 | |
| 287 | for (i = 0; baudtab[i].rate != -1; i++) |
| 288 | if (rate == baudtab[i].rate) |
| 289 | return baudtab[i].damn_b; |
| 290 | return B38400; /* Random */ |
| 291 | } |
| 292 | |
| 293 | |
| 294 | /***************************************************************** REMOTE_OPEN |
| 295 | ** Open a connection to remote minimon. |
| 296 | NAME is the filename used for communication, then a space, |
| 297 | then the baud rate. |
| 298 | 'target adapt /dev/ttya 9600 [prognam]' for example. |
| 299 | */ |
| 300 | |
| 301 | static char *dev_name; |
| 302 | int baudrate = 9600; |
| 303 | static void |
| 304 | mm_open (char *name, int from_tty) |
| 305 | { |
| 306 | TERMINAL sg; |
| 307 | unsigned int prl; |
| 308 | char *p; |
| 309 | |
| 310 | /* Find the first whitespace character, it separates dev_name from |
| 311 | prog_name. */ |
| 312 | for (p = name; |
| 313 | p && *p && !isspace (*p); p++) |
| 314 | ; |
| 315 | if (p == 0 || *p == '\0') |
| 316 | erroid: |
| 317 | error ("Usage : <command> <serial-device> <baud-rate> [progname]"); |
| 318 | dev_name = (char *) xmalloc (p - name + 1); |
| 319 | strncpy (dev_name, name, p - name); |
| 320 | dev_name[p - name] = '\0'; |
| 321 | |
| 322 | /* Skip over the whitespace after dev_name */ |
| 323 | for (; isspace (*p); p++) |
| 324 | /*EMPTY */ ; |
| 325 | |
| 326 | if (1 != sscanf (p, "%d ", &baudrate)) |
| 327 | goto erroid; |
| 328 | |
| 329 | /* Skip the number and then the spaces */ |
| 330 | for (; isdigit (*p); p++) |
| 331 | /*EMPTY */ ; |
| 332 | for (; isspace (*p); p++) |
| 333 | /*EMPTY */ ; |
| 334 | |
| 335 | if (prog_name != NULL) |
| 336 | xfree (prog_name); |
| 337 | prog_name = savestring (p, strlen (p)); |
| 338 | |
| 339 | |
| 340 | if (mm_desc >= 0) |
| 341 | close (mm_desc); |
| 342 | |
| 343 | mm_desc = open (dev_name, O_RDWR); |
| 344 | if (mm_desc < 0) |
| 345 | perror_with_name (dev_name); |
| 346 | ioctl (mm_desc, TIOCGETP, &sg); |
| 347 | #ifdef HAVE_TERMIO |
| 348 | sg.c_cc[VMIN] = 0; /* read with timeout. */ |
| 349 | sg.c_cc[VTIME] = timeout * 10; |
| 350 | sg.c_lflag &= ~(ICANON | ECHO); |
| 351 | sg.c_cflag = (sg.c_cflag & ~CBAUD) | damn_b (baudrate); |
| 352 | #else |
| 353 | sg.sg_ispeed = damn_b (baudrate); |
| 354 | sg.sg_ospeed = damn_b (baudrate); |
| 355 | sg.sg_flags |= RAW; |
| 356 | sg.sg_flags |= ANYP; |
| 357 | sg.sg_flags &= ~ECHO; |
| 358 | #endif |
| 359 | |
| 360 | |
| 361 | ioctl (mm_desc, TIOCSETP, &sg); |
| 362 | mm_stream = fdopen (mm_desc, "r+"); |
| 363 | |
| 364 | push_target (&mm_ops); |
| 365 | |
| 366 | #ifndef HAVE_TERMIO |
| 367 | #ifndef NO_SIGINTERRUPT |
| 368 | /* Cause SIGALRM's to make reads fail with EINTR instead of resuming |
| 369 | the read. */ |
| 370 | if (siginterrupt (SIGALRM, 1) != 0) |
| 371 | perror ("mm_open: error in siginterrupt"); |
| 372 | #endif |
| 373 | |
| 374 | /* Set up read timeout timer. */ |
| 375 | if ((void (*)) signal (SIGALRM, mm_timer) == (void (*)) -1) |
| 376 | perror ("mm_open: error in signal"); |
| 377 | #endif |
| 378 | |
| 379 | #if defined (LOG_FILE) |
| 380 | log_file = fopen (LOG_FILE, "w"); |
| 381 | if (log_file == NULL) |
| 382 | perror_with_name (LOG_FILE); |
| 383 | #endif |
| 384 | /* |
| 385 | ** Initialize target configuration structure (global) |
| 386 | */ |
| 387 | DRAIN_INPUT (); |
| 388 | out_msg_buf->config_req_msg.code = CONFIG_REQ; |
| 389 | out_msg_buf->config_req_msg.length = 4 * 0; |
| 390 | msg_send_serial (out_msg_buf); /* send config request message */ |
| 391 | |
| 392 | expect_msg (CONFIG, in_msg_buf, 1); |
| 393 | |
| 394 | a29k_get_processor_type (); |
| 395 | |
| 396 | /* Print out some stuff, letting the user now what's going on */ |
| 397 | printf_filtered ("Connected to MiniMon via %s.\n", dev_name); |
| 398 | /* FIXME: can this restriction be removed? */ |
| 399 | printf_filtered ("Remote debugging using virtual addresses works only\n"); |
| 400 | printf_filtered ("\twhen virtual addresses map 1:1 to physical addresses.\n") |
| 401 | ; |
| 402 | if (processor_type != a29k_freeze_mode) |
| 403 | { |
| 404 | fprintf_filtered (gdb_stderr, |
| 405 | "Freeze-mode debugging not available, and can only be done on an A29050.\n"); |
| 406 | } |
| 407 | |
| 408 | target_config.code = CONFIG; |
| 409 | target_config.length = 0; |
| 410 | target_config.processor_id = in_msg_buf->config_msg.processor_id; |
| 411 | target_config.version = in_msg_buf->config_msg.version; |
| 412 | target_config.I_mem_start = in_msg_buf->config_msg.I_mem_start; |
| 413 | target_config.I_mem_size = in_msg_buf->config_msg.I_mem_size; |
| 414 | target_config.D_mem_start = in_msg_buf->config_msg.D_mem_start; |
| 415 | target_config.D_mem_size = in_msg_buf->config_msg.D_mem_size; |
| 416 | target_config.ROM_start = in_msg_buf->config_msg.ROM_start; |
| 417 | target_config.ROM_size = in_msg_buf->config_msg.ROM_size; |
| 418 | target_config.max_msg_size = in_msg_buf->config_msg.max_msg_size; |
| 419 | target_config.max_bkpts = in_msg_buf->config_msg.max_bkpts; |
| 420 | target_config.coprocessor = in_msg_buf->config_msg.coprocessor; |
| 421 | target_config.reserved = in_msg_buf->config_msg.reserved; |
| 422 | if (from_tty) |
| 423 | { |
| 424 | printf ("Connected to MiniMON :\n"); |
| 425 | printf (" Debugcore version %d.%d\n", |
| 426 | 0x0f & (target_config.version >> 4), |
| 427 | 0x0f & (target_config.version)); |
| 428 | printf (" Configuration version %d.%d\n", |
| 429 | 0x0f & (target_config.version >> 12), |
| 430 | 0x0f & (target_config.version >> 8)); |
| 431 | printf (" Message system version %d.%d\n", |
| 432 | 0x0f & (target_config.version >> 20), |
| 433 | 0x0f & (target_config.version >> 16)); |
| 434 | printf (" Communication driver version %d.%d\n", |
| 435 | 0x0f & (target_config.version >> 28), |
| 436 | 0x0f & (target_config.version >> 24)); |
| 437 | } |
| 438 | |
| 439 | /* Leave the target running... |
| 440 | * The above message stopped the target in the dbg core (MiniMon), |
| 441 | * so restart the target out of MiniMon, |
| 442 | */ |
| 443 | out_msg_buf->go_msg.code = GO; |
| 444 | out_msg_buf->go_msg.length = 0; |
| 445 | msg_send_serial (out_msg_buf); |
| 446 | /* No message to expect after a GO */ |
| 447 | } |
| 448 | |
| 449 | /**************************************************************** REMOTE_CLOSE |
| 450 | ** Close the open connection to the minimon debugger. |
| 451 | Use this when you want to detach and do something else |
| 452 | with your gdb. */ |
| 453 | static void |
| 454 | mm_close ( /*FIXME: how is quitting used */ |
| 455 | int quitting) |
| 456 | { |
| 457 | if (mm_desc < 0) |
| 458 | error ("Can't close remote connection: not debugging remotely."); |
| 459 | |
| 460 | /* We should never get here if there isn't something valid in |
| 461 | mm_desc and mm_stream. |
| 462 | |
| 463 | Due to a bug in Unix, fclose closes not only the stdio stream, |
| 464 | but also the file descriptor. So we don't actually close |
| 465 | mm_desc. */ |
| 466 | DRAIN_INPUT (); |
| 467 | fclose (mm_stream); |
| 468 | /* close (mm_desc); */ |
| 469 | |
| 470 | /* Do not try to close mm_desc again, later in the program. */ |
| 471 | mm_stream = NULL; |
| 472 | mm_desc = -1; |
| 473 | |
| 474 | #if defined (LOG_FILE) |
| 475 | if (ferror (log_file)) |
| 476 | printf ("Error writing log file.\n"); |
| 477 | if (fclose (log_file) != 0) |
| 478 | printf ("Error closing log file.\n"); |
| 479 | #endif |
| 480 | |
| 481 | printf ("Ending remote debugging\n"); |
| 482 | } |
| 483 | |
| 484 | /************************************************************* REMOTE_ATACH */ |
| 485 | /* Attach to a program that is already loaded and running |
| 486 | * Upon exiting the process's execution is stopped. |
| 487 | */ |
| 488 | static void |
| 489 | mm_attach (char *args, int from_tty) |
| 490 | { |
| 491 | |
| 492 | if (!mm_stream) |
| 493 | error ("MiniMon not opened yet, use the 'target minimon' command.\n"); |
| 494 | |
| 495 | if (from_tty) |
| 496 | printf ("Attaching to remote program %s...\n", prog_name); |
| 497 | |
| 498 | /* Make sure the target is currently running, it is supposed to be. */ |
| 499 | /* FIXME: is it ok to send MiniMon a BREAK if it is already stopped in |
| 500 | * the dbg core. If so, we don't need to send this GO. |
| 501 | */ |
| 502 | out_msg_buf->go_msg.code = GO; |
| 503 | out_msg_buf->go_msg.length = 0; |
| 504 | msg_send_serial (out_msg_buf); |
| 505 | sleep (2); /* At the worst it will stop, receive a message, continue */ |
| 506 | |
| 507 | /* Send the mm a break. */ |
| 508 | out_msg_buf->break_msg.code = BREAK; |
| 509 | out_msg_buf->break_msg.length = 0; |
| 510 | msg_send_serial (out_msg_buf); |
| 511 | } |
| 512 | /********************************************************** REMOTE_DETACH */ |
| 513 | /* Terminate the open connection to the remote debugger. |
| 514 | Use this when you want to detach and do something else |
| 515 | with your gdb. Leave remote process running (with no breakpoints set). */ |
| 516 | static void |
| 517 | mm_detach (char *args, int from_tty) |
| 518 | { |
| 519 | remove_breakpoints (); /* Just in case there were any left in */ |
| 520 | out_msg_buf->go_msg.code = GO; |
| 521 | out_msg_buf->go_msg.length = 0; |
| 522 | msg_send_serial (out_msg_buf); |
| 523 | pop_target (); /* calls mm_close to do the real work */ |
| 524 | } |
| 525 | |
| 526 | |
| 527 | /*************************************************************** REMOTE_RESUME |
| 528 | ** Tell the remote machine to resume. */ |
| 529 | |
| 530 | static void |
| 531 | mm_resume (int pid, int step, enum target_signal sig) |
| 532 | { |
| 533 | if (sig != TARGET_SIGNAL_0) |
| 534 | warning ("Can't send signals to a remote MiniMon system."); |
| 535 | |
| 536 | if (step) |
| 537 | { |
| 538 | out_msg_buf->step_msg.code = STEP; |
| 539 | out_msg_buf->step_msg.length = 1 * 4; |
| 540 | out_msg_buf->step_msg.count = 1; /* step 1 instruction */ |
| 541 | msg_send_serial (out_msg_buf); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | out_msg_buf->go_msg.code = GO; |
| 546 | out_msg_buf->go_msg.length = 0; |
| 547 | msg_send_serial (out_msg_buf); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /***************************************************************** REMOTE_WAIT |
| 552 | ** Wait until the remote machine stops, then return, |
| 553 | storing status in STATUS just as `wait' would. */ |
| 554 | |
| 555 | static int |
| 556 | mm_wait (struct target_waitstatus *status) |
| 557 | { |
| 558 | int i, result; |
| 559 | int old_timeout = timeout; |
| 560 | int old_immediate_quit = immediate_quit; |
| 561 | |
| 562 | status->kind = TARGET_WAITKIND_EXITED; |
| 563 | status->value.integer = 0; |
| 564 | |
| 565 | /* wait for message to arrive. It should be: |
| 566 | - A HIF service request. |
| 567 | - A HIF exit service request. |
| 568 | - A CHANNEL0_ACK. |
| 569 | - A CHANNEL1 request. |
| 570 | - a debugcore HALT message. |
| 571 | HIF services must be responded too, and while-looping continued. |
| 572 | If the target stops executing, mm_wait() should return. |
| 573 | */ |
| 574 | timeout = 0; /* Wait indefinetly for a message */ |
| 575 | immediate_quit = 1; /* Helps ability to QUIT */ |
| 576 | while (1) |
| 577 | { |
| 578 | while (msg_recv_serial (in_msg_buf)) |
| 579 | { |
| 580 | QUIT; /* Let user quit if they want */ |
| 581 | } |
| 582 | switch (in_msg_buf->halt_msg.code) |
| 583 | { |
| 584 | case HIF_CALL: |
| 585 | i = in_msg_buf->hif_call_rtn_msg.service_number; |
| 586 | result = service_HIF (in_msg_buf); |
| 587 | if (i == 1) /* EXIT */ |
| 588 | goto exit; |
| 589 | if (result) |
| 590 | printf ("Warning: failure during HIF service %d\n", i); |
| 591 | break; |
| 592 | case CHANNEL0_ACK: |
| 593 | service_HIF (in_msg_buf); |
| 594 | break; |
| 595 | case CHANNEL1: |
| 596 | i = in_msg_buf->channel1_msg.length; |
| 597 | in_msg_buf->channel1_msg.data[i] = '\0'; |
| 598 | printf ("%s", in_msg_buf->channel1_msg.data); |
| 599 | gdb_flush (gdb_stdout); |
| 600 | /* Send CHANNEL1_ACK message */ |
| 601 | out_msg_buf->channel1_ack_msg.code = CHANNEL1_ACK; |
| 602 | out_msg_buf->channel1_ack_msg.length = 0; |
| 603 | result = msg_send_serial (out_msg_buf); |
| 604 | break; |
| 605 | case HALT: |
| 606 | goto halted; |
| 607 | default: |
| 608 | goto halted; |
| 609 | } |
| 610 | } |
| 611 | halted: |
| 612 | /* FIXME, these printfs should not be here. This is a source level |
| 613 | debugger, guys! */ |
| 614 | if (in_msg_buf->halt_msg.trap_number == 0) |
| 615 | { |
| 616 | printf ("Am290*0 received vector number %d (break point)\n", |
| 617 | in_msg_buf->halt_msg.trap_number); |
| 618 | status->kind = TARGET_WAITKIND_STOPPED; |
| 619 | status->value.sig = TARGET_SIGNAL_TRAP; |
| 620 | } |
| 621 | else if (in_msg_buf->halt_msg.trap_number == 1) |
| 622 | { |
| 623 | printf ("Am290*0 received vector number %d\n", |
| 624 | in_msg_buf->halt_msg.trap_number); |
| 625 | status->kind = TARGET_WAITKIND_STOPPED; |
| 626 | status->value.sig = TARGET_SIGNAL_BUS; |
| 627 | } |
| 628 | else if (in_msg_buf->halt_msg.trap_number == 3 |
| 629 | || in_msg_buf->halt_msg.trap_number == 4) |
| 630 | { |
| 631 | printf ("Am290*0 received vector number %d\n", |
| 632 | in_msg_buf->halt_msg.trap_number); |
| 633 | status->kind = TARGET_WAITKIND_STOPPED; |
| 634 | status->value.sig = TARGET_SIGNAL_FPE; |
| 635 | } |
| 636 | else if (in_msg_buf->halt_msg.trap_number == 5) |
| 637 | { |
| 638 | printf ("Am290*0 received vector number %d\n", |
| 639 | in_msg_buf->halt_msg.trap_number); |
| 640 | status->kind = TARGET_WAITKIND_STOPPED; |
| 641 | status->value.sig = TARGET_SIGNAL_ILL; |
| 642 | } |
| 643 | else if (in_msg_buf->halt_msg.trap_number >= 6 |
| 644 | && in_msg_buf->halt_msg.trap_number <= 11) |
| 645 | { |
| 646 | printf ("Am290*0 received vector number %d\n", |
| 647 | in_msg_buf->halt_msg.trap_number); |
| 648 | status->kind = TARGET_WAITKIND_STOPPED; |
| 649 | status->value.sig = TARGET_SIGNAL_SEGV; |
| 650 | } |
| 651 | else if (in_msg_buf->halt_msg.trap_number == 12 |
| 652 | || in_msg_buf->halt_msg.trap_number == 13) |
| 653 | { |
| 654 | printf ("Am290*0 received vector number %d\n", |
| 655 | in_msg_buf->halt_msg.trap_number); |
| 656 | status->kind = TARGET_WAITKIND_STOPPED; |
| 657 | status->value.sig = TARGET_SIGNAL_ILL; |
| 658 | } |
| 659 | else if (in_msg_buf->halt_msg.trap_number == 14) |
| 660 | { |
| 661 | printf ("Am290*0 received vector number %d\n", |
| 662 | in_msg_buf->halt_msg.trap_number); |
| 663 | status->kind = TARGET_WAITKIND_STOPPED; |
| 664 | status->value.sig = TARGET_SIGNAL_ALRM; |
| 665 | } |
| 666 | else if (in_msg_buf->halt_msg.trap_number == 15) |
| 667 | { |
| 668 | status->kind = TARGET_WAITKIND_STOPPED; |
| 669 | status->value.sig = TARGET_SIGNAL_TRAP; |
| 670 | } |
| 671 | else if (in_msg_buf->halt_msg.trap_number >= 16 |
| 672 | && in_msg_buf->halt_msg.trap_number <= 21) |
| 673 | { |
| 674 | printf ("Am290*0 received vector number %d\n", |
| 675 | in_msg_buf->halt_msg.trap_number); |
| 676 | status->kind = TARGET_WAITKIND_STOPPED; |
| 677 | status->value.sig = TARGET_SIGNAL_INT; |
| 678 | } |
| 679 | else if (in_msg_buf->halt_msg.trap_number == 22) |
| 680 | { |
| 681 | printf ("Am290*0 received vector number %d\n", |
| 682 | in_msg_buf->halt_msg.trap_number); |
| 683 | status->kind = TARGET_WAITKIND_STOPPED; |
| 684 | status->value.sig = TARGET_SIGNAL_ILL; |
| 685 | } /* BREAK message was sent */ |
| 686 | else if (in_msg_buf->halt_msg.trap_number == 75) |
| 687 | { |
| 688 | status->kind = TARGET_WAITKIND_STOPPED; |
| 689 | status->value.sig = TARGET_SIGNAL_TRAP; |
| 690 | } |
| 691 | else |
| 692 | exit: |
| 693 | { |
| 694 | status->kind = TARGET_WAITKIND_EXITED; |
| 695 | status->value.integer = 0; |
| 696 | } |
| 697 | |
| 698 | timeout = old_timeout; /* Restore original timeout value */ |
| 699 | immediate_quit = old_immediate_quit; |
| 700 | return 0; |
| 701 | } |
| 702 | |
| 703 | /******************************************************* REMOTE_FETCH_REGISTERS |
| 704 | * Read a remote register 'regno'. |
| 705 | * If regno==-1 then read all the registers. |
| 706 | */ |
| 707 | static void |
| 708 | mm_fetch_registers (int regno) |
| 709 | { |
| 710 | INT32 *data_p; |
| 711 | |
| 712 | if (regno >= 0) |
| 713 | { |
| 714 | fetch_register (regno); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | /* Gr1/rsp */ |
| 719 | out_msg_buf->read_req_msg.byte_count = 4 * 1; |
| 720 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
| 721 | out_msg_buf->read_req_msg.address = 1; |
| 722 | msg_send_serial (out_msg_buf); |
| 723 | expect_msg (READ_ACK, in_msg_buf, 1); |
| 724 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
| 725 | supply_register (GR1_REGNUM, data_p); |
| 726 | |
| 727 | #if defined(GR64_REGNUM) /* Read gr64-127 */ |
| 728 | /* Global Registers gr64-gr95 */ |
| 729 | out_msg_buf->read_req_msg.code = READ_REQ; |
| 730 | out_msg_buf->read_req_msg.length = 4 * 3; |
| 731 | out_msg_buf->read_req_msg.byte_count = 4 * 32; |
| 732 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
| 733 | out_msg_buf->read_req_msg.address = 64; |
| 734 | msg_send_serial (out_msg_buf); |
| 735 | expect_msg (READ_ACK, in_msg_buf, 1); |
| 736 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
| 737 | |
| 738 | for (regno = GR64_REGNUM; regno < GR64_REGNUM + 32; regno++) |
| 739 | { |
| 740 | supply_register (regno, data_p++); |
| 741 | } |
| 742 | #endif /* GR64_REGNUM */ |
| 743 | |
| 744 | /* Global Registers gr96-gr127 */ |
| 745 | out_msg_buf->read_req_msg.code = READ_REQ; |
| 746 | out_msg_buf->read_req_msg.length = 4 * 3; |
| 747 | out_msg_buf->read_req_msg.byte_count = 4 * 32; |
| 748 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
| 749 | out_msg_buf->read_req_msg.address = 96; |
| 750 | msg_send_serial (out_msg_buf); |
| 751 | expect_msg (READ_ACK, in_msg_buf, 1); |
| 752 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
| 753 | |
| 754 | for (regno = GR96_REGNUM; regno < GR96_REGNUM + 32; regno++) |
| 755 | { |
| 756 | supply_register (regno, data_p++); |
| 757 | } |
| 758 | |
| 759 | /* Local Registers */ |
| 760 | out_msg_buf->read_req_msg.byte_count = 4 * (128); |
| 761 | out_msg_buf->read_req_msg.memory_space = LOCAL_REG; |
| 762 | out_msg_buf->read_req_msg.address = 0; |
| 763 | msg_send_serial (out_msg_buf); |
| 764 | expect_msg (READ_ACK, in_msg_buf, 1); |
| 765 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
| 766 | |
| 767 | for (regno = LR0_REGNUM; regno < LR0_REGNUM + 128; regno++) |
| 768 | { |
| 769 | supply_register (regno, data_p++); |
| 770 | } |
| 771 | |
| 772 | /* Protected Special Registers */ |
| 773 | out_msg_buf->read_req_msg.byte_count = 4 * 15; |
| 774 | out_msg_buf->read_req_msg.memory_space = SPECIAL_REG; |
| 775 | out_msg_buf->read_req_msg.address = 0; |
| 776 | msg_send_serial (out_msg_buf); |
| 777 | expect_msg (READ_ACK, in_msg_buf, 1); |
| 778 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
| 779 | |
| 780 | for (regno = 0; regno <= 14; regno++) |
| 781 | { |
| 782 | supply_register (SR_REGNUM (regno), data_p++); |
| 783 | } |
| 784 | if (USE_SHADOW_PC) |
| 785 | { /* Let regno_to_srnum() handle the register number */ |
| 786 | fetch_register (NPC_REGNUM); |
| 787 | fetch_register (PC_REGNUM); |
| 788 | fetch_register (PC2_REGNUM); |
| 789 | } |
| 790 | |
| 791 | /* Unprotected Special Registers */ |
| 792 | out_msg_buf->read_req_msg.byte_count = 4 * 8; |
| 793 | out_msg_buf->read_req_msg.memory_space = SPECIAL_REG; |
| 794 | out_msg_buf->read_req_msg.address = 128; |
| 795 | msg_send_serial (out_msg_buf); |
| 796 | expect_msg (READ_ACK, in_msg_buf, 1); |
| 797 | data_p = &(in_msg_buf->read_r_ack_msg.data[0]); |
| 798 | |
| 799 | for (regno = 128; regno <= 135; regno++) |
| 800 | { |
| 801 | supply_register (SR_REGNUM (regno), data_p++); |
| 802 | } |
| 803 | |
| 804 | /* There doesn't seem to be any way to get these. */ |
| 805 | { |
| 806 | int val = -1; |
| 807 | supply_register (FPE_REGNUM, &val); |
| 808 | supply_register (INTE_REGNUM, &val); |
| 809 | supply_register (FPS_REGNUM, &val); |
| 810 | supply_register (EXO_REGNUM, &val); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | |
| 815 | /****************************************************** REMOTE_STORE_REGISTERS |
| 816 | * Store register regno into the target. |
| 817 | * If regno==-1 then store all the registers. |
| 818 | * Result is 0 for success, -1 for failure. |
| 819 | */ |
| 820 | |
| 821 | static void |
| 822 | mm_store_registers (int regno) |
| 823 | { |
| 824 | int result; |
| 825 | |
| 826 | if (regno >= 0) |
| 827 | { |
| 828 | store_register (regno); |
| 829 | return; |
| 830 | } |
| 831 | |
| 832 | result = 0; |
| 833 | |
| 834 | out_msg_buf->write_r_msg.code = WRITE_REQ; |
| 835 | |
| 836 | /* Gr1/rsp */ |
| 837 | out_msg_buf->write_r_msg.byte_count = 4 * 1; |
| 838 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 839 | out_msg_buf->write_r_msg.memory_space = GLOBAL_REG; |
| 840 | out_msg_buf->write_r_msg.address = 1; |
| 841 | out_msg_buf->write_r_msg.data[0] = read_register (GR1_REGNUM); |
| 842 | |
| 843 | msg_send_serial (out_msg_buf); |
| 844 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 845 | { |
| 846 | result = -1; |
| 847 | } |
| 848 | |
| 849 | #if defined(GR64_REGNUM) |
| 850 | /* Global registers gr64-gr95 */ |
| 851 | out_msg_buf->write_r_msg.byte_count = 4 * (32); |
| 852 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 853 | out_msg_buf->write_r_msg.address = 64; |
| 854 | |
| 855 | for (regno = GR64_REGNUM; regno < GR64_REGNUM + 32; regno++) |
| 856 | { |
| 857 | out_msg_buf->write_r_msg.data[regno - GR64_REGNUM] = read_register (regno); |
| 858 | } |
| 859 | msg_send_serial (out_msg_buf); |
| 860 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 861 | { |
| 862 | result = -1; |
| 863 | } |
| 864 | #endif /* GR64_REGNUM */ |
| 865 | |
| 866 | /* Global registers gr96-gr127 */ |
| 867 | out_msg_buf->write_r_msg.byte_count = 4 * (32); |
| 868 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 869 | out_msg_buf->write_r_msg.address = 96; |
| 870 | for (regno = GR96_REGNUM; regno < GR96_REGNUM + 32; regno++) |
| 871 | { |
| 872 | out_msg_buf->write_r_msg.data[regno - GR96_REGNUM] = read_register (regno); |
| 873 | } |
| 874 | msg_send_serial (out_msg_buf); |
| 875 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 876 | { |
| 877 | result = -1; |
| 878 | } |
| 879 | |
| 880 | /* Local Registers */ |
| 881 | out_msg_buf->write_r_msg.memory_space = LOCAL_REG; |
| 882 | out_msg_buf->write_r_msg.byte_count = 4 * 128; |
| 883 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 884 | out_msg_buf->write_r_msg.address = 0; |
| 885 | |
| 886 | for (regno = LR0_REGNUM; regno < LR0_REGNUM + 128; regno++) |
| 887 | { |
| 888 | out_msg_buf->write_r_msg.data[regno - LR0_REGNUM] = read_register (regno); |
| 889 | } |
| 890 | msg_send_serial (out_msg_buf); |
| 891 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 892 | { |
| 893 | result = -1; |
| 894 | } |
| 895 | |
| 896 | /* Protected Special Registers */ |
| 897 | /* VAB through TMR */ |
| 898 | out_msg_buf->write_r_msg.memory_space = SPECIAL_REG; |
| 899 | out_msg_buf->write_r_msg.byte_count = 4 * 10; |
| 900 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 901 | out_msg_buf->write_r_msg.address = 0; |
| 902 | for (regno = 0; regno <= 9; regno++) /* VAB through TMR */ |
| 903 | out_msg_buf->write_r_msg.data[regno] = read_register (SR_REGNUM (regno)); |
| 904 | msg_send_serial (out_msg_buf); |
| 905 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 906 | { |
| 907 | result = -1; |
| 908 | } |
| 909 | |
| 910 | /* PC0, PC1, PC2 possibly as shadow registers */ |
| 911 | out_msg_buf->write_r_msg.byte_count = 4 * 3; |
| 912 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 913 | for (regno = 10; regno <= 12; regno++) /* LRU and MMU */ |
| 914 | out_msg_buf->write_r_msg.data[regno - 10] = read_register (SR_REGNUM (regno)); |
| 915 | if (USE_SHADOW_PC) |
| 916 | out_msg_buf->write_r_msg.address = 20; /* SPC0 */ |
| 917 | else |
| 918 | out_msg_buf->write_r_msg.address = 10; /* PC0 */ |
| 919 | msg_send_serial (out_msg_buf); |
| 920 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 921 | { |
| 922 | result = -1; |
| 923 | } |
| 924 | |
| 925 | /* LRU and MMU */ |
| 926 | out_msg_buf->write_r_msg.byte_count = 4 * 2; |
| 927 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 928 | out_msg_buf->write_r_msg.address = 13; |
| 929 | for (regno = 13; regno <= 14; regno++) /* LRU and MMU */ |
| 930 | out_msg_buf->write_r_msg.data[regno - 13] = read_register (SR_REGNUM (regno)); |
| 931 | msg_send_serial (out_msg_buf); |
| 932 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 933 | { |
| 934 | result = -1; |
| 935 | } |
| 936 | |
| 937 | /* Unprotected Special Registers */ |
| 938 | out_msg_buf->write_r_msg.byte_count = 4 * 8; |
| 939 | out_msg_buf->write_r_msg.length = 3 * 4 + out_msg_buf->write_r_msg.byte_count; |
| 940 | out_msg_buf->write_r_msg.address = 128; |
| 941 | for (regno = 128; regno <= 135; regno++) |
| 942 | out_msg_buf->write_r_msg.data[regno - 128] = read_register (SR_REGNUM (regno)); |
| 943 | msg_send_serial (out_msg_buf); |
| 944 | if (!expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 945 | { |
| 946 | result = -1; |
| 947 | } |
| 948 | |
| 949 | registers_changed (); |
| 950 | } |
| 951 | |
| 952 | /*************************************************** REMOTE_PREPARE_TO_STORE */ |
| 953 | /* Get ready to modify the registers array. On machines which store |
| 954 | individual registers, this doesn't need to do anything. On machines |
| 955 | which store all the registers in one fell swoop, this makes sure |
| 956 | that registers contains all the registers from the program being |
| 957 | debugged. */ |
| 958 | |
| 959 | static void |
| 960 | mm_prepare_to_store (void) |
| 961 | { |
| 962 | /* Do nothing, since we can store individual regs */ |
| 963 | } |
| 964 | |
| 965 | /******************************************************* REMOTE_XFER_MEMORY */ |
| 966 | static CORE_ADDR |
| 967 | translate_addr (CORE_ADDR addr) |
| 968 | { |
| 969 | #if defined(KERNEL_DEBUGGING) |
| 970 | /* Check for a virtual address in the kernel */ |
| 971 | /* Assume physical address of ublock is in paddr_u register */ |
| 972 | /* FIXME: doesn't work for user virtual addresses */ |
| 973 | if (addr >= UVADDR) |
| 974 | { |
| 975 | /* PADDR_U register holds the physical address of the ublock */ |
| 976 | CORE_ADDR i = (CORE_ADDR) read_register (PADDR_U_REGNUM); |
| 977 | return (i + addr - (CORE_ADDR) UVADDR); |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | return (addr); |
| 982 | } |
| 983 | #else |
| 984 | return (addr); |
| 985 | #endif |
| 986 | } |
| 987 | |
| 988 | /******************************************************* REMOTE_FILES_INFO */ |
| 989 | static void |
| 990 | mm_files_info (void) |
| 991 | { |
| 992 | printf ("\tAttached to %s at %d baud and running program %s.\n", |
| 993 | dev_name, baudrate, prog_name); |
| 994 | } |
| 995 | |
| 996 | /************************************************* REMOTE_INSERT_BREAKPOINT */ |
| 997 | static int |
| 998 | mm_insert_breakpoint (CORE_ADDR addr, char *contents_cache) |
| 999 | { |
| 1000 | out_msg_buf->bkpt_set_msg.code = BKPT_SET; |
| 1001 | out_msg_buf->bkpt_set_msg.length = 4 * 4; |
| 1002 | out_msg_buf->bkpt_set_msg.memory_space = I_MEM; |
| 1003 | out_msg_buf->bkpt_set_msg.bkpt_addr = (ADDR32) addr; |
| 1004 | out_msg_buf->bkpt_set_msg.pass_count = 1; |
| 1005 | out_msg_buf->bkpt_set_msg.bkpt_type = -1; /* use illop for 29000 */ |
| 1006 | msg_send_serial (out_msg_buf); |
| 1007 | if (expect_msg (BKPT_SET_ACK, in_msg_buf, 1)) |
| 1008 | { |
| 1009 | return 0; /* Success */ |
| 1010 | } |
| 1011 | else |
| 1012 | { |
| 1013 | return 1; /* Failure */ |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /************************************************* REMOTE_DELETE_BREAKPOINT */ |
| 1018 | static int |
| 1019 | mm_remove_breakpoint (CORE_ADDR addr, char *contents_cache) |
| 1020 | { |
| 1021 | out_msg_buf->bkpt_rm_msg.code = BKPT_RM; |
| 1022 | out_msg_buf->bkpt_rm_msg.length = 4 * 3; |
| 1023 | out_msg_buf->bkpt_rm_msg.memory_space = I_MEM; |
| 1024 | out_msg_buf->bkpt_rm_msg.bkpt_addr = (ADDR32) addr; |
| 1025 | msg_send_serial (out_msg_buf); |
| 1026 | if (expect_msg (BKPT_RM_ACK, in_msg_buf, 1)) |
| 1027 | { |
| 1028 | return 0; /* Success */ |
| 1029 | } |
| 1030 | else |
| 1031 | { |
| 1032 | return 1; /* Failure */ |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | |
| 1037 | /******************************************************* REMOTE_KILL */ |
| 1038 | static void |
| 1039 | mm_kill (char *arg, int from_tty) |
| 1040 | { |
| 1041 | char buf[4]; |
| 1042 | |
| 1043 | #if defined(KERNEL_DEBUGGING) |
| 1044 | /* We don't ever kill the kernel */ |
| 1045 | if (from_tty) |
| 1046 | { |
| 1047 | printf ("Kernel not killed, but left in current state.\n"); |
| 1048 | printf ("Use detach to leave kernel running.\n"); |
| 1049 | } |
| 1050 | #else |
| 1051 | out_msg_buf->break_msg.code = BREAK; |
| 1052 | out_msg_buf->bkpt_set_msg.length = 4 * 0; |
| 1053 | expect_msg (HALT, in_msg_buf, from_tty); |
| 1054 | if (from_tty) |
| 1055 | { |
| 1056 | printf ("Target has been stopped."); |
| 1057 | printf ("Would you like to do a hardware reset (y/n) [n] "); |
| 1058 | fgets (buf, 3, stdin); |
| 1059 | if (buf[0] == 'y') |
| 1060 | { |
| 1061 | out_msg_buf->reset_msg.code = RESET; |
| 1062 | out_msg_buf->bkpt_set_msg.length = 4 * 0; |
| 1063 | expect_msg (RESET_ACK, in_msg_buf, from_tty); |
| 1064 | printf ("Target has been reset."); |
| 1065 | } |
| 1066 | } |
| 1067 | pop_target (); |
| 1068 | #endif |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | /***************************************************************************/ |
| 1074 | /* |
| 1075 | * Load a program into the target. |
| 1076 | */ |
| 1077 | static void |
| 1078 | mm_load (char *arg_string, int from_tty) |
| 1079 | { |
| 1080 | dont_repeat (); |
| 1081 | |
| 1082 | #if defined(KERNEL_DEBUGGING) |
| 1083 | printf ("The kernel had better be loaded already! Loading not done.\n"); |
| 1084 | #else |
| 1085 | if (arg_string == 0) |
| 1086 | error ("The load command takes a file name"); |
| 1087 | |
| 1088 | arg_string = tilde_expand (arg_string); |
| 1089 | make_cleanup (xfree, arg_string); |
| 1090 | QUIT; |
| 1091 | immediate_quit++; |
| 1092 | error ("File loading is not yet supported for MiniMon."); |
| 1093 | /* FIXME, code to load your file here... */ |
| 1094 | /* You may need to do an init_target_mm() */ |
| 1095 | /* init_target_mm(?,?,?,?,?,?,?,?); */ |
| 1096 | immediate_quit--; |
| 1097 | /* symbol_file_add (arg_string, from_tty, text_addr, 0, 0); */ |
| 1098 | #endif |
| 1099 | |
| 1100 | } |
| 1101 | |
| 1102 | /************************************************ REMOTE_WRITE_INFERIOR_MEMORY |
| 1103 | ** Copy LEN bytes of data from debugger memory at MYADDR |
| 1104 | to inferior's memory at MEMADDR. Returns number of bytes written. */ |
| 1105 | static int |
| 1106 | mm_write_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) |
| 1107 | { |
| 1108 | int i, nwritten; |
| 1109 | |
| 1110 | out_msg_buf->write_req_msg.code = WRITE_REQ; |
| 1111 | out_msg_buf->write_req_msg.memory_space = mm_memory_space (memaddr); |
| 1112 | |
| 1113 | nwritten = 0; |
| 1114 | while (nwritten < len) |
| 1115 | { |
| 1116 | int num_to_write = len - nwritten; |
| 1117 | if (num_to_write > MAXDATA) |
| 1118 | num_to_write = MAXDATA; |
| 1119 | for (i = 0; i < num_to_write; i++) |
| 1120 | out_msg_buf->write_req_msg.data[i] = myaddr[i + nwritten]; |
| 1121 | out_msg_buf->write_req_msg.byte_count = num_to_write; |
| 1122 | out_msg_buf->write_req_msg.length = 3 * 4 + num_to_write; |
| 1123 | out_msg_buf->write_req_msg.address = memaddr + nwritten; |
| 1124 | msg_send_serial (out_msg_buf); |
| 1125 | |
| 1126 | if (expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 1127 | { |
| 1128 | nwritten += in_msg_buf->write_ack_msg.byte_count; |
| 1129 | } |
| 1130 | else |
| 1131 | { |
| 1132 | break; |
| 1133 | } |
| 1134 | } |
| 1135 | return (nwritten); |
| 1136 | } |
| 1137 | |
| 1138 | /************************************************* REMOTE_READ_INFERIOR_MEMORY |
| 1139 | ** Read LEN bytes from inferior memory at MEMADDR. Put the result |
| 1140 | at debugger address MYADDR. Returns number of bytes read. */ |
| 1141 | static int |
| 1142 | mm_read_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len) |
| 1143 | { |
| 1144 | int i, nread; |
| 1145 | |
| 1146 | out_msg_buf->read_req_msg.code = READ_REQ; |
| 1147 | out_msg_buf->read_req_msg.memory_space = mm_memory_space (memaddr); |
| 1148 | |
| 1149 | nread = 0; |
| 1150 | while (nread < len) |
| 1151 | { |
| 1152 | int num_to_read = (len - nread); |
| 1153 | if (num_to_read > MAXDATA) |
| 1154 | num_to_read = MAXDATA; |
| 1155 | out_msg_buf->read_req_msg.byte_count = num_to_read; |
| 1156 | out_msg_buf->read_req_msg.length = 3 * 4 + num_to_read; |
| 1157 | out_msg_buf->read_req_msg.address = memaddr + nread; |
| 1158 | msg_send_serial (out_msg_buf); |
| 1159 | |
| 1160 | if (expect_msg (READ_ACK, in_msg_buf, 1)) |
| 1161 | { |
| 1162 | for (i = 0; i < in_msg_buf->read_ack_msg.byte_count; i++) |
| 1163 | myaddr[i + nread] = in_msg_buf->read_ack_msg.data[i]; |
| 1164 | nread += in_msg_buf->read_ack_msg.byte_count; |
| 1165 | } |
| 1166 | else |
| 1167 | { |
| 1168 | break; |
| 1169 | } |
| 1170 | } |
| 1171 | return (nread); |
| 1172 | } |
| 1173 | |
| 1174 | /* FIXME! Merge these two. */ |
| 1175 | static int |
| 1176 | mm_xfer_inferior_memory (CORE_ADDR memaddr, char *myaddr, int len, int write, |
| 1177 | struct mem_attrib *attrib ATTRIBUTE_UNUSED, |
| 1178 | struct target_ops *target ATTRIBUTE_UNUSED) |
| 1179 | { |
| 1180 | |
| 1181 | memaddr = translate_addr (memaddr); |
| 1182 | |
| 1183 | if (write) |
| 1184 | return mm_write_inferior_memory (memaddr, myaddr, len); |
| 1185 | else |
| 1186 | return mm_read_inferior_memory (memaddr, myaddr, len); |
| 1187 | } |
| 1188 | |
| 1189 | |
| 1190 | /********************************************************** MSG_SEND_SERIAL |
| 1191 | ** This function is used to send a message over the |
| 1192 | ** serial line. |
| 1193 | ** |
| 1194 | ** If the message is successfully sent, a zero is |
| 1195 | ** returned. If the message was not sendable, a -1 |
| 1196 | ** is returned. This function blocks. That is, it |
| 1197 | ** does not return until the message is completely |
| 1198 | ** sent, or until an error is encountered. |
| 1199 | ** |
| 1200 | */ |
| 1201 | |
| 1202 | int |
| 1203 | msg_send_serial (union msg_t *msg_ptr) |
| 1204 | { |
| 1205 | INT32 message_size; |
| 1206 | int byte_count; |
| 1207 | int result; |
| 1208 | char c; |
| 1209 | |
| 1210 | /* Send message header */ |
| 1211 | byte_count = 0; |
| 1212 | message_size = msg_ptr->generic_msg.length + (2 * sizeof (INT32)); |
| 1213 | do |
| 1214 | { |
| 1215 | c = *((char *) msg_ptr + byte_count); |
| 1216 | result = write (mm_desc, &c, 1); |
| 1217 | if (result == 1) |
| 1218 | { |
| 1219 | byte_count = byte_count + 1; |
| 1220 | } |
| 1221 | } |
| 1222 | while ((byte_count < message_size)); |
| 1223 | |
| 1224 | return (0); |
| 1225 | } /* end msg_send_serial() */ |
| 1226 | |
| 1227 | /********************************************************** MSG_RECV_SERIAL |
| 1228 | ** This function is used to receive a message over a |
| 1229 | ** serial line. |
| 1230 | ** |
| 1231 | ** If the message is waiting in the buffer, a zero is |
| 1232 | ** returned and the buffer pointed to by msg_ptr is filled |
| 1233 | ** in. If no message was available, a -1 is returned. |
| 1234 | ** If timeout==0, wait indefinetly for a character. |
| 1235 | ** |
| 1236 | */ |
| 1237 | |
| 1238 | int |
| 1239 | msg_recv_serial (union msg_t *msg_ptr) |
| 1240 | { |
| 1241 | static INT32 length = 0; |
| 1242 | static INT32 byte_count = 0; |
| 1243 | int result; |
| 1244 | char c; |
| 1245 | if (msg_ptr == 0) /* re-sync request */ |
| 1246 | { |
| 1247 | length = 0; |
| 1248 | byte_count = 0; |
| 1249 | #ifdef HAVE_TERMIO |
| 1250 | /* The timeout here is the prevailing timeout set with VTIME */ |
| 1251 | ->"timeout==0 semantics not supported" |
| 1252 | read (mm_desc, in_buf, BUFER_SIZE); |
| 1253 | #else |
| 1254 | alarm (1); |
| 1255 | read (mm_desc, in_buf, BUFER_SIZE); |
| 1256 | alarm (0); |
| 1257 | #endif |
| 1258 | return (0); |
| 1259 | } |
| 1260 | /* Receive message */ |
| 1261 | #ifdef HAVE_TERMIO |
| 1262 | /* Timeout==0, help support the mm_wait() routine */ |
| 1263 | ->"timeout==0 semantics not supported (and its nice if they are)" |
| 1264 | result = read (mm_desc, &c, 1); |
| 1265 | #else |
| 1266 | alarm (timeout); |
| 1267 | result = read (mm_desc, &c, 1); |
| 1268 | alarm (0); |
| 1269 | #endif |
| 1270 | if (result < 0) |
| 1271 | { |
| 1272 | if (errno == EINTR) |
| 1273 | { |
| 1274 | error ("Timeout reading from remote system."); |
| 1275 | } |
| 1276 | else |
| 1277 | perror_with_name ("remote"); |
| 1278 | } |
| 1279 | else if (result == 1) |
| 1280 | { |
| 1281 | *((char *) msg_ptr + byte_count) = c; |
| 1282 | byte_count = byte_count + 1; |
| 1283 | } |
| 1284 | |
| 1285 | /* Message header received. Save message length. */ |
| 1286 | if (byte_count == (2 * sizeof (INT32))) |
| 1287 | length = msg_ptr->generic_msg.length; |
| 1288 | |
| 1289 | if (byte_count >= (length + (2 * sizeof (INT32)))) |
| 1290 | { |
| 1291 | /* Message received */ |
| 1292 | byte_count = 0; |
| 1293 | return (0); |
| 1294 | } |
| 1295 | else |
| 1296 | return (-1); |
| 1297 | |
| 1298 | } /* end msg_recv_serial() */ |
| 1299 | |
| 1300 | /********************************************************************* KBD_RAW |
| 1301 | ** This function is used to put the keyboard in "raw" |
| 1302 | ** mode for BSD Unix. The original status is saved |
| 1303 | ** so that it may be restored later. |
| 1304 | */ |
| 1305 | TERMINAL kbd_tbuf; |
| 1306 | |
| 1307 | int |
| 1308 | kbd_raw (void) |
| 1309 | { |
| 1310 | int result; |
| 1311 | TERMINAL tbuf; |
| 1312 | |
| 1313 | /* Get keyboard termio (to save to restore original modes) */ |
| 1314 | #ifdef HAVE_TERMIO |
| 1315 | result = ioctl (0, TCGETA, &kbd_tbuf); |
| 1316 | #else |
| 1317 | result = ioctl (0, TIOCGETP, &kbd_tbuf); |
| 1318 | #endif |
| 1319 | if (result == -1) |
| 1320 | return (errno); |
| 1321 | |
| 1322 | /* Get keyboard TERMINAL (for modification) */ |
| 1323 | #ifdef HAVE_TERMIO |
| 1324 | result = ioctl (0, TCGETA, &tbuf); |
| 1325 | #else |
| 1326 | result = ioctl (0, TIOCGETP, &tbuf); |
| 1327 | #endif |
| 1328 | if (result == -1) |
| 1329 | return (errno); |
| 1330 | |
| 1331 | /* Set up new parameters */ |
| 1332 | #ifdef HAVE_TERMIO |
| 1333 | tbuf.c_iflag = tbuf.c_iflag & |
| 1334 | ~(INLCR | ICRNL | IUCLC | ISTRIP | IXON | BRKINT); |
| 1335 | tbuf.c_lflag = tbuf.c_lflag & ~(ICANON | ISIG | ECHO); |
| 1336 | tbuf.c_cc[4] = 0; /* MIN */ |
| 1337 | tbuf.c_cc[5] = 0; /* TIME */ |
| 1338 | #else |
| 1339 | /* FIXME: not sure if this is correct (matches HAVE_TERMIO). */ |
| 1340 | tbuf.sg_flags |= RAW; |
| 1341 | tbuf.sg_flags |= ANYP; |
| 1342 | tbuf.sg_flags &= ~ECHO; |
| 1343 | #endif |
| 1344 | |
| 1345 | /* Set keyboard termio to new mode (RAW) */ |
| 1346 | #ifdef HAVE_TERMIO |
| 1347 | result = ioctl (0, TCSETAF, &tbuf); |
| 1348 | #else |
| 1349 | result = ioctl (0, TIOCSETP, &tbuf); |
| 1350 | #endif |
| 1351 | if (result == -1) |
| 1352 | return (errno); |
| 1353 | |
| 1354 | return (0); |
| 1355 | } /* end kbd_raw() */ |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | /***************************************************************** KBD_RESTORE |
| 1360 | ** This function is used to put the keyboard back in the |
| 1361 | ** mode it was in before kbk_raw was called. Note that |
| 1362 | ** kbk_raw() must have been called at least once before |
| 1363 | ** kbd_restore() is called. |
| 1364 | */ |
| 1365 | |
| 1366 | int |
| 1367 | kbd_restore (void) |
| 1368 | { |
| 1369 | int result; |
| 1370 | |
| 1371 | /* Set keyboard termio to original mode */ |
| 1372 | #ifdef HAVE_TERMIO |
| 1373 | result = ioctl (0, TCSETAF, &kbd_tbuf); |
| 1374 | #else |
| 1375 | result = ioctl (0, TIOCGETP, &kbd_tbuf); |
| 1376 | #endif |
| 1377 | |
| 1378 | if (result == -1) |
| 1379 | return (errno); |
| 1380 | |
| 1381 | return (0); |
| 1382 | } /* end kbd_cooked() */ |
| 1383 | |
| 1384 | |
| 1385 | /*****************************************************************************/ |
| 1386 | /* Fetch a single register indicatated by 'regno'. |
| 1387 | * Returns 0/-1 on success/failure. |
| 1388 | */ |
| 1389 | static int |
| 1390 | fetch_register (int regno) |
| 1391 | { |
| 1392 | int result; |
| 1393 | out_msg_buf->read_req_msg.code = READ_REQ; |
| 1394 | out_msg_buf->read_req_msg.length = 4 * 3; |
| 1395 | out_msg_buf->read_req_msg.byte_count = 4; |
| 1396 | |
| 1397 | if (regno == GR1_REGNUM) |
| 1398 | { |
| 1399 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
| 1400 | out_msg_buf->read_req_msg.address = 1; |
| 1401 | } |
| 1402 | else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32) |
| 1403 | { |
| 1404 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
| 1405 | out_msg_buf->read_req_msg.address = (regno - GR96_REGNUM) + 96; |
| 1406 | } |
| 1407 | #if defined(GR64_REGNUM) |
| 1408 | else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32) |
| 1409 | { |
| 1410 | out_msg_buf->read_req_msg.memory_space = GLOBAL_REG; |
| 1411 | out_msg_buf->read_req_msg.address = (regno - GR64_REGNUM) + 64; |
| 1412 | } |
| 1413 | #endif /* GR64_REGNUM */ |
| 1414 | else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128) |
| 1415 | { |
| 1416 | out_msg_buf->read_req_msg.memory_space = LOCAL_REG; |
| 1417 | out_msg_buf->read_req_msg.address = (regno - LR0_REGNUM); |
| 1418 | } |
| 1419 | else if (regno >= FPE_REGNUM && regno <= EXO_REGNUM) |
| 1420 | { |
| 1421 | int val = -1; |
| 1422 | supply_register (160 + (regno - FPE_REGNUM), &val); |
| 1423 | return 0; /* Pretend Success */ |
| 1424 | } |
| 1425 | else |
| 1426 | { |
| 1427 | out_msg_buf->read_req_msg.memory_space = SPECIAL_REG; |
| 1428 | out_msg_buf->read_req_msg.address = regnum_to_srnum (regno); |
| 1429 | } |
| 1430 | |
| 1431 | msg_send_serial (out_msg_buf); |
| 1432 | |
| 1433 | if (expect_msg (READ_ACK, in_msg_buf, 1)) |
| 1434 | { |
| 1435 | supply_register (regno, &(in_msg_buf->read_r_ack_msg.data[0])); |
| 1436 | result = 0; |
| 1437 | } |
| 1438 | else |
| 1439 | { |
| 1440 | result = -1; |
| 1441 | } |
| 1442 | return result; |
| 1443 | } |
| 1444 | /*****************************************************************************/ |
| 1445 | /* Store a single register indicated by 'regno'. |
| 1446 | * Returns 0/-1 on success/failure. |
| 1447 | */ |
| 1448 | static int |
| 1449 | store_register (int regno) |
| 1450 | { |
| 1451 | int result; |
| 1452 | |
| 1453 | out_msg_buf->write_req_msg.code = WRITE_REQ; |
| 1454 | out_msg_buf->write_req_msg.length = 4 * 4; |
| 1455 | out_msg_buf->write_req_msg.byte_count = 4; |
| 1456 | out_msg_buf->write_r_msg.data[0] = read_register (regno); |
| 1457 | |
| 1458 | if (regno == GR1_REGNUM) |
| 1459 | { |
| 1460 | out_msg_buf->write_req_msg.memory_space = GLOBAL_REG; |
| 1461 | out_msg_buf->write_req_msg.address = 1; |
| 1462 | /* Setting GR1 changes the numbers of all the locals, so invalidate the |
| 1463 | * register cache. Do this *after* calling read_register, because we want |
| 1464 | * read_register to return the value that write_register has just stuffed |
| 1465 | * into the registers array, not the value of the register fetched from |
| 1466 | * the inferior. |
| 1467 | */ |
| 1468 | registers_changed (); |
| 1469 | } |
| 1470 | #if defined(GR64_REGNUM) |
| 1471 | else if (regno >= GR64_REGNUM && regno < GR64_REGNUM + 32) |
| 1472 | { |
| 1473 | out_msg_buf->write_req_msg.memory_space = GLOBAL_REG; |
| 1474 | out_msg_buf->write_req_msg.address = (regno - GR64_REGNUM) + 64; |
| 1475 | } |
| 1476 | #endif /* GR64_REGNUM */ |
| 1477 | else if (regno >= GR96_REGNUM && regno < GR96_REGNUM + 32) |
| 1478 | { |
| 1479 | out_msg_buf->write_req_msg.memory_space = GLOBAL_REG; |
| 1480 | out_msg_buf->write_req_msg.address = (regno - GR96_REGNUM) + 96; |
| 1481 | } |
| 1482 | else if (regno >= LR0_REGNUM && regno < LR0_REGNUM + 128) |
| 1483 | { |
| 1484 | out_msg_buf->write_req_msg.memory_space = LOCAL_REG; |
| 1485 | out_msg_buf->write_req_msg.address = (regno - LR0_REGNUM); |
| 1486 | } |
| 1487 | else if (regno >= FPE_REGNUM && regno <= EXO_REGNUM) |
| 1488 | { |
| 1489 | return 0; /* Pretend Success */ |
| 1490 | } |
| 1491 | else |
| 1492 | /* An unprotected or protected special register */ |
| 1493 | { |
| 1494 | out_msg_buf->write_req_msg.memory_space = SPECIAL_REG; |
| 1495 | out_msg_buf->write_req_msg.address = regnum_to_srnum (regno); |
| 1496 | } |
| 1497 | |
| 1498 | msg_send_serial (out_msg_buf); |
| 1499 | |
| 1500 | if (expect_msg (WRITE_ACK, in_msg_buf, 1)) |
| 1501 | { |
| 1502 | result = 0; |
| 1503 | } |
| 1504 | else |
| 1505 | { |
| 1506 | result = -1; |
| 1507 | } |
| 1508 | return result; |
| 1509 | } |
| 1510 | /****************************************************************************/ |
| 1511 | /* |
| 1512 | * Convert a gdb special register number to a 29000 special register number. |
| 1513 | */ |
| 1514 | static int |
| 1515 | regnum_to_srnum (int regno) |
| 1516 | { |
| 1517 | switch (regno) |
| 1518 | { |
| 1519 | case VAB_REGNUM: |
| 1520 | return (0); |
| 1521 | case OPS_REGNUM: |
| 1522 | return (1); |
| 1523 | case CPS_REGNUM: |
| 1524 | return (2); |
| 1525 | case CFG_REGNUM: |
| 1526 | return (3); |
| 1527 | case CHA_REGNUM: |
| 1528 | return (4); |
| 1529 | case CHD_REGNUM: |
| 1530 | return (5); |
| 1531 | case CHC_REGNUM: |
| 1532 | return (6); |
| 1533 | case RBP_REGNUM: |
| 1534 | return (7); |
| 1535 | case TMC_REGNUM: |
| 1536 | return (8); |
| 1537 | case TMR_REGNUM: |
| 1538 | return (9); |
| 1539 | case NPC_REGNUM: |
| 1540 | return (USE_SHADOW_PC ? (20) : (10)); |
| 1541 | case PC_REGNUM: |
| 1542 | return (USE_SHADOW_PC ? (21) : (11)); |
| 1543 | case PC2_REGNUM: |
| 1544 | return (USE_SHADOW_PC ? (22) : (12)); |
| 1545 | case MMU_REGNUM: |
| 1546 | return (13); |
| 1547 | case LRU_REGNUM: |
| 1548 | return (14); |
| 1549 | case IPC_REGNUM: |
| 1550 | return (128); |
| 1551 | case IPA_REGNUM: |
| 1552 | return (129); |
| 1553 | case IPB_REGNUM: |
| 1554 | return (130); |
| 1555 | case Q_REGNUM: |
| 1556 | return (131); |
| 1557 | case ALU_REGNUM: |
| 1558 | return (132); |
| 1559 | case BP_REGNUM: |
| 1560 | return (133); |
| 1561 | case FC_REGNUM: |
| 1562 | return (134); |
| 1563 | case CR_REGNUM: |
| 1564 | return (135); |
| 1565 | case FPE_REGNUM: |
| 1566 | return (160); |
| 1567 | case INTE_REGNUM: |
| 1568 | return (161); |
| 1569 | case FPS_REGNUM: |
| 1570 | return (162); |
| 1571 | case EXO_REGNUM: |
| 1572 | return (164); |
| 1573 | default: |
| 1574 | return (255); /* Failure ? */ |
| 1575 | } |
| 1576 | } |
| 1577 | /****************************************************************************/ |
| 1578 | /* |
| 1579 | * Initialize the target debugger (minimon only). |
| 1580 | */ |
| 1581 | static void |
| 1582 | init_target_mm (ADDR32 tstart, ADDR32 tend, ADDR32 dstart, ADDR32 dend, |
| 1583 | ADDR32 entry, INT32 ms_size, INT32 rs_size, ADDR32 arg_start) |
| 1584 | { |
| 1585 | out_msg_buf->init_msg.code = INIT; |
| 1586 | out_msg_buf->init_msg.length = sizeof (struct init_msg_t) - 2 * sizeof (INT32); |
| 1587 | out_msg_buf->init_msg.text_start = tstart; |
| 1588 | out_msg_buf->init_msg.text_end = tend; |
| 1589 | out_msg_buf->init_msg.data_start = dstart; |
| 1590 | out_msg_buf->init_msg.data_end = dend; |
| 1591 | out_msg_buf->init_msg.entry_point = entry; |
| 1592 | out_msg_buf->init_msg.mem_stack_size = ms_size; |
| 1593 | out_msg_buf->init_msg.reg_stack_size = rs_size; |
| 1594 | out_msg_buf->init_msg.arg_start = arg_start; |
| 1595 | msg_send_serial (out_msg_buf); |
| 1596 | expect_msg (INIT_ACK, in_msg_buf, 1); |
| 1597 | } |
| 1598 | /****************************************************************************/ |
| 1599 | /* |
| 1600 | * Return a pointer to a string representing the given message code. |
| 1601 | * Not all messages are represented here, only the ones that we expect |
| 1602 | * to be called with. |
| 1603 | */ |
| 1604 | static char * |
| 1605 | msg_str (INT32 code) |
| 1606 | { |
| 1607 | static char cbuf[32]; |
| 1608 | |
| 1609 | switch (code) |
| 1610 | { |
| 1611 | case BKPT_SET_ACK: |
| 1612 | sprintf (cbuf, "%s (%d)", "BKPT_SET_ACK", code); |
| 1613 | break; |
| 1614 | case BKPT_RM_ACK: |
| 1615 | sprintf (cbuf, "%s (%d)", "BKPT_RM_ACK", code); |
| 1616 | break; |
| 1617 | case INIT_ACK: |
| 1618 | sprintf (cbuf, "%s (%d)", "INIT_ACK", code); |
| 1619 | break; |
| 1620 | case READ_ACK: |
| 1621 | sprintf (cbuf, "%s (%d)", "READ_ACK", code); |
| 1622 | break; |
| 1623 | case WRITE_ACK: |
| 1624 | sprintf (cbuf, "%s (%d)", "WRITE_ACK", code); |
| 1625 | break; |
| 1626 | case ERROR: |
| 1627 | sprintf (cbuf, "%s (%d)", "ERROR", code); |
| 1628 | break; |
| 1629 | case HALT: |
| 1630 | sprintf (cbuf, "%s (%d)", "HALT", code); |
| 1631 | break; |
| 1632 | default: |
| 1633 | sprintf (cbuf, "UNKNOWN (%d)", code); |
| 1634 | break; |
| 1635 | } |
| 1636 | return (cbuf); |
| 1637 | } |
| 1638 | /****************************************************************************/ |
| 1639 | /* |
| 1640 | * Selected (not all of them) error codes that we might get. |
| 1641 | */ |
| 1642 | static char * |
| 1643 | error_msg_str (INT32 code) |
| 1644 | { |
| 1645 | static char cbuf[50]; |
| 1646 | |
| 1647 | switch (code) |
| 1648 | { |
| 1649 | case EMFAIL: |
| 1650 | return ("EMFAIL: unrecoverable error"); |
| 1651 | case EMBADADDR: |
| 1652 | return ("EMBADADDR: Illegal address"); |
| 1653 | case EMBADREG: |
| 1654 | return ("EMBADREG: Illegal register "); |
| 1655 | case EMACCESS: |
| 1656 | return ("EMACCESS: Could not access memory"); |
| 1657 | case EMBADMSG: |
| 1658 | return ("EMBADMSG: Unknown message type"); |
| 1659 | case EMMSG2BIG: |
| 1660 | return ("EMMSG2BIG: Message to large"); |
| 1661 | case EMNOSEND: |
| 1662 | return ("EMNOSEND: Could not send message"); |
| 1663 | case EMNORECV: |
| 1664 | return ("EMNORECV: Could not recv message"); |
| 1665 | case EMRESET: |
| 1666 | return ("EMRESET: Could not RESET target"); |
| 1667 | case EMCONFIG: |
| 1668 | return ("EMCONFIG: Could not get target CONFIG"); |
| 1669 | case EMSTATUS: |
| 1670 | return ("EMSTATUS: Could not get target STATUS"); |
| 1671 | case EMREAD: |
| 1672 | return ("EMREAD: Could not READ target memory"); |
| 1673 | case EMWRITE: |
| 1674 | return ("EMWRITE: Could not WRITE target memory"); |
| 1675 | case EMBKPTSET: |
| 1676 | return ("EMBKPTSET: Could not set breakpoint"); |
| 1677 | case EMBKPTRM: |
| 1678 | return ("EMBKPTRM: Could not remove breakpoint"); |
| 1679 | case EMBKPTSTAT: |
| 1680 | return ("EMBKPTSTAT: Could not get breakpoint status"); |
| 1681 | case EMBKPTNONE: |
| 1682 | return ("EMBKPTNONE: All breakpoints in use"); |
| 1683 | case EMBKPTUSED: |
| 1684 | return ("EMBKPTUSED: Breakpoints already in use"); |
| 1685 | case EMINIT: |
| 1686 | return ("EMINIT: Could not init target memory"); |
| 1687 | case EMGO: |
| 1688 | return ("EMGO: Could not start execution"); |
| 1689 | case EMSTEP: |
| 1690 | return ("EMSTEP: Could not single step"); |
| 1691 | case EMBREAK: |
| 1692 | return ("EMBREAK: Could not BREAK"); |
| 1693 | case EMCOMMERR: |
| 1694 | return ("EMCOMMERR: Communication error"); |
| 1695 | default: |
| 1696 | sprintf (cbuf, "error number %d", code); |
| 1697 | break; |
| 1698 | } /* end switch */ |
| 1699 | |
| 1700 | return (cbuf); |
| 1701 | } |
| 1702 | /****************************************************************************/ |
| 1703 | |
| 1704 | /* Receive a message, placing it in MSG_BUF, and expect it to be of |
| 1705 | type MSGCODE. If an error occurs, a non-zero FROM_TTY indicates |
| 1706 | that the message should be printed. |
| 1707 | |
| 1708 | Return 0 for failure, 1 for success. */ |
| 1709 | |
| 1710 | static int |
| 1711 | expect_msg (INT32 msgcode, union msg_t *msg_buf, int from_tty) |
| 1712 | { |
| 1713 | int retries = 0; |
| 1714 | while (msg_recv_serial (msg_buf) && (retries++ < MAX_RETRIES)); |
| 1715 | if (retries >= MAX_RETRIES) |
| 1716 | { |
| 1717 | printf ("Expected msg %s, ", msg_str (msgcode)); |
| 1718 | printf ("no message received!\n"); |
| 1719 | return (0); /* Failure */ |
| 1720 | } |
| 1721 | |
| 1722 | if (msg_buf->generic_msg.code != msgcode) |
| 1723 | { |
| 1724 | if (from_tty) |
| 1725 | { |
| 1726 | printf ("Expected msg %s, ", msg_str (msgcode)); |
| 1727 | printf ("got msg %s\n", msg_str (msg_buf->generic_msg.code)); |
| 1728 | if (msg_buf->generic_msg.code == ERROR) |
| 1729 | printf ("%s\n", error_msg_str (msg_buf->error_msg.error_code)); |
| 1730 | } |
| 1731 | return (0); /* Failure */ |
| 1732 | } |
| 1733 | return (1); /* Success */ |
| 1734 | } |
| 1735 | /****************************************************************************/ |
| 1736 | /* |
| 1737 | * Determine the MiniMon memory space qualifier based on the addr. |
| 1738 | * FIXME: Can't distinguis I_ROM/D_ROM. |
| 1739 | * FIXME: Doesn't know anything about I_CACHE/D_CACHE. |
| 1740 | */ |
| 1741 | static int |
| 1742 | mm_memory_space (CORE_ADDR *addr) |
| 1743 | { |
| 1744 | ADDR32 tstart = target_config.I_mem_start; |
| 1745 | ADDR32 tend = tstart + target_config.I_mem_size; |
| 1746 | ADDR32 dstart = target_config.D_mem_start; |
| 1747 | ADDR32 dend = tstart + target_config.D_mem_size; |
| 1748 | ADDR32 rstart = target_config.ROM_start; |
| 1749 | ADDR32 rend = tstart + target_config.ROM_size; |
| 1750 | |
| 1751 | if (((ADDR32) addr >= tstart) && ((ADDR32) addr < tend)) |
| 1752 | { |
| 1753 | return I_MEM; |
| 1754 | } |
| 1755 | else if (((ADDR32) addr >= dstart) && ((ADDR32) addr < dend)) |
| 1756 | { |
| 1757 | return D_MEM; |
| 1758 | } |
| 1759 | else if (((ADDR32) addr >= rstart) && ((ADDR32) addr < rend)) |
| 1760 | { |
| 1761 | /* FIXME: how do we determine between D_ROM and I_ROM */ |
| 1762 | return D_ROM; |
| 1763 | } |
| 1764 | else /* FIXME: what do me do now? */ |
| 1765 | return D_MEM; /* Hmmm! */ |
| 1766 | } |
| 1767 | |
| 1768 | /****************************************************************************/ |
| 1769 | /* |
| 1770 | * Define the target subroutine names |
| 1771 | */ |
| 1772 | struct target_ops mm_ops; |
| 1773 | |
| 1774 | static void |
| 1775 | init_mm_ops (void) |
| 1776 | { |
| 1777 | mm_ops.to_shortname = "minimon"; |
| 1778 | mm_ops.to_longname = "Remote AMD/Minimon target"; |
| 1779 | mm_ops.to_doc = "Remote debug an AMD 290*0 using the MiniMon dbg core on the target"; |
| 1780 | mm_ops.to_open = mm_open; |
| 1781 | mm_ops.to_close = mm_close; |
| 1782 | mm_ops.to_attach = mm_attach; |
| 1783 | mm_ops.to_post_attach = NULL; |
| 1784 | mm_ops.to_require_attach = NULL; |
| 1785 | mm_ops.to_detach = mm_detach; |
| 1786 | mm_ops.to_require_detach = NULL; |
| 1787 | mm_ops.to_resume = mm_resume; |
| 1788 | mm_ops.to_wait = mm_wait; |
| 1789 | mm_ops.to_post_wait = NULL; |
| 1790 | mm_ops.to_fetch_registers = mm_fetch_registers; |
| 1791 | mm_ops.to_store_registers = mm_store_registers; |
| 1792 | mm_ops.to_prepare_to_store = mm_prepare_to_store; |
| 1793 | mm_ops.to_xfer_memory = mm_xfer_inferior_memory; |
| 1794 | mm_ops.to_files_info = mm_files_info; |
| 1795 | mm_ops.to_insert_breakpoint = mm_insert_breakpoint; |
| 1796 | mm_ops.to_remove_breakpoint = mm_remove_breakpoint; |
| 1797 | mm_ops.to_terminal_init = 0; |
| 1798 | mm_ops.to_terminal_inferior = 0; |
| 1799 | mm_ops.to_terminal_ours_for_output = 0; |
| 1800 | mm_ops.to_terminal_ours = 0; |
| 1801 | mm_ops.to_terminal_info = 0; |
| 1802 | mm_ops.to_kill = mm_kill; |
| 1803 | mm_ops.to_load = mm_load; |
| 1804 | mm_ops.to_lookup_symbol = 0; |
| 1805 | mm_ops.to_create_inferior = mm_create_inferior; |
| 1806 | mm_ops.to_post_startup_inferior = NULL; |
| 1807 | mm_ops.to_acknowledge_created_inferior = NULL; |
| 1808 | mm_ops.to_clone_and_follow_inferior = NULL; |
| 1809 | mm_ops.to_post_follow_inferior_by_clone = NULL; |
| 1810 | mm_ops.to_insert_fork_catchpoint = NULL; |
| 1811 | mm_ops.to_remove_fork_catchpoint = NULL; |
| 1812 | mm_ops.to_insert_vfork_catchpoint = NULL; |
| 1813 | mm_ops.to_remove_vfork_catchpoint = NULL; |
| 1814 | mm_ops.to_has_forked = NULL; |
| 1815 | mm_ops.to_has_vforked = NULL; |
| 1816 | mm_ops.to_can_follow_vfork_prior_to_exec = NULL; |
| 1817 | mm_ops.to_post_follow_vfork = NULL; |
| 1818 | mm_ops.to_insert_exec_catchpoint = NULL; |
| 1819 | mm_ops.to_remove_exec_catchpoint = NULL; |
| 1820 | mm_ops.to_has_execd = NULL; |
| 1821 | mm_ops.to_reported_exec_events_per_exec_call = NULL; |
| 1822 | mm_ops.to_has_exited = NULL; |
| 1823 | mm_ops.to_mourn_inferior = mm_mourn; |
| 1824 | mm_ops.to_can_run = 0; |
| 1825 | mm_ops.to_notice_signals = 0; |
| 1826 | mm_ops.to_thread_alive = 0; |
| 1827 | mm_ops.to_stop = 0; |
| 1828 | mm_ops.to_pid_to_exec_file = NULL; |
| 1829 | mm_ops.to_core_file_to_sym_file = NULL; |
| 1830 | mm_ops.to_stratum = process_stratum; |
| 1831 | mm_ops.DONT_USE = 0; |
| 1832 | mm_ops.to_has_all_memory = 1; |
| 1833 | mm_ops.to_has_memory = 1; |
| 1834 | mm_ops.to_has_stack = 1; |
| 1835 | mm_ops.to_has_registers = 1; |
| 1836 | mm_ops.to_has_execution = 1; |
| 1837 | mm_ops.to_sections = 0; |
| 1838 | mm_ops.to_sections_end = 0; |
| 1839 | mm_ops.to_magic = OPS_MAGIC; |
| 1840 | }; |
| 1841 | |
| 1842 | void |
| 1843 | _initialize_remote_mm (void) |
| 1844 | { |
| 1845 | init_mm_ops (); |
| 1846 | add_target (&mm_ops); |
| 1847 | } |
| 1848 | |
| 1849 | #ifdef NO_HIF_SUPPORT |
| 1850 | service_HIF (union msg_t *msg) |
| 1851 | { |
| 1852 | return (0); /* Emulate a failure */ |
| 1853 | } |
| 1854 | #endif |