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