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