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