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.
5 This file is part of GDB.
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.
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.
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. */
21 /* This is like remote.c but ecpects MiniMON to be running on the Am29000
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
45 /* Offset of member MEMBER in a struct of type TYPE. */
46 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
48 #define DRAIN_INPUT() (msg_recv_serial((union msg_t*)0))
50 extern int stop_soon_quietly; /* for wait_for_inferior */
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();
68 #define TYPE_UNKNOWN 0
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)
77 #define LLOG_FILE "minimon.log"
78 #if defined (LOG_FILE)
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).
86 #define BUFER_SIZE 512
88 * Size of data area in message buffer on the TARGET (remote system).
90 #define MAXDATA_T (target_config.max_msg_size - \
91 offsetof(struct write_r_msg_t,data[0]))
93 * Size of data area in message buffer on the HOST (gdb).
95 #define MAXDATA_H (BUFER_SIZE - offsetof(struct write_r_msg_t,data[0]))
97 * Defined as the minimum size of data areas of the two message buffers
99 #define MAXDATA (MAXDATA_H < MAXDATA_T ? MAXDATA_H : MAXDATA_T)
101 static char out_buf[BUFER_SIZE];
102 static char in_buf[BUFER_SIZE];
104 int msg_recv_serial();
105 int msg_send_serial();
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;
113 static int timeout = 5;
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
120 /* stream which is fdopen'd from mm_desc. Only valid when
124 /* Called when SIGALRM signal sent due to alarm() timeout. */
129 # define volatile /**/
132 volatile int n_alarms;
139 printf ("mm_timer called\n");
143 #endif /* HAVE_TERMIO */
145 /* malloc'd name of the program on the remote system. */
146 static char *prog_name = NULL;
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. */
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. */
157 mm_create_inferior (execfile, args, env)
162 #define MAX_TOKENS 25
163 #define BUFFER_SIZE 256
166 char *token[MAX_TOKENS];
167 char cmd_line[BUFFER_SIZE];
170 error ("Can't pass arguments to remote mm process (yet).");
172 if (execfile == 0 /* || exec_bfd == 0 */ )
173 error ("No exec file specified");
176 printf("Minimon not open yet.\n");
180 /* On ultra3 (NYU) we assume the kernel is already running so there is
182 FIXME: Fixed required here -> load your program, possibly with mm_load().
184 printf_filtered ("\n\
185 Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n");
187 /* We will get a task spawn event immediately. */
188 init_wait_for_inferior ();
189 clear_proceed_status ();
190 stop_soon_quietly = 1;
194 /**************************************************** REMOTE_MOURN_INFERIOR */
198 pop_target (); /* Pop back to no-child state */
199 generic_mourn_inferior ();
202 /********************************************************************** damn_b
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. */
214 static struct {int rate, damn_b;} baudtab[] = {
234 static int damn_b (rate)
239 for (i = 0; baudtab[i].rate != -1; i++)
240 if (rate == baudtab[i].rate) return baudtab[i].damn_b;
241 return B38400; /* Random */
245 /***************************************************************** REMOTE_OPEN
246 ** Open a connection to remote minimon.
247 NAME is the filename used for communication, then a space,
249 'target adapt /dev/ttya 9600 [prognam]' for example.
252 static char *dev_name;
255 mm_open (name, from_tty)
263 /* Find the first whitespace character, it separates dev_name from
266 p && *p && !isspace (*p); p++)
268 if (p == 0 || *p == '\0')
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';
275 /* Skip over the whitespace after dev_name */
276 for (; isspace (*p); p++)
279 if (1 != sscanf (p, "%d ", &baudrate))
282 /* Skip the number and then the spaces */
283 for (; isdigit (*p); p++)
285 for (; isspace (*p); p++)
288 if (prog_name != NULL)
290 prog_name = savestring (p, strlen (p));
296 mm_desc = open (dev_name, O_RDWR);
298 perror_with_name (dev_name);
299 ioctl (mm_desc, TIOCGETP, &sg);
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);
306 sg.sg_ispeed = damn_b (baudrate);
307 sg.sg_ospeed = damn_b (baudrate);
310 sg.sg_flags &= ~ECHO;
314 ioctl (mm_desc, TIOCSETP, &sg);
315 mm_stream = fdopen (mm_desc, "r+");
317 push_target (&mm_ops);
320 #ifndef NO_SIGINTERRUPT
321 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
323 if (siginterrupt (SIGALRM, 1) != 0)
324 perror ("mm_open: error in siginterrupt");
327 /* Set up read timeout timer. */
328 if ((void (*)) signal (SIGALRM, mm_timer) == (void (*)) -1)
329 perror ("mm_open: error in signal");
332 #if defined (LOG_FILE)
333 log_file = fopen (LOG_FILE, "w");
334 if (log_file == NULL)
335 perror_with_name (LOG_FILE);
338 ** Initialize target configuration structure (global)
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 */
345 expect_msg(CONFIG,in_msg_buf,1);
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;
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");
359 processor_type = TYPE_UNKNOWN;
360 fprintf_filtered(stderr,"WARNING: processor type unknown.\n");
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")
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");
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;
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) );
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,
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 */
415 /**************************************************************** REMOTE_CLOSE
416 ** Close the open connection to the minimon debugger.
417 Use this when you want to detach and do something else
420 mm_close (quitting) /*FIXME: how is quitting used */
424 error ("Can't close remote connection: not debugging remotely.");
426 /* We should never get here if there isn't something valid in
427 mm_desc and mm_stream.
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
434 /* close (mm_desc); */
436 /* Do not try to close mm_desc again, later in the program. */
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");
447 printf ("Ending remote debugging\n");
450 /************************************************************* REMOTE_ATACH */
451 /* Attach to a program that is already loaded and running
452 * Upon exiting the process's execution is stopped.
455 mm_attach (args, from_tty)
461 error ("MiniMon not opened yet, use the 'target minimon' command.\n");
464 printf ("Attaching to remote program %s...\n", prog_name);
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.
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 */
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);
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). */
485 mm_detach (args,from_tty)
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 */
497 /*************************************************************** REMOTE_RESUME
498 ** Tell the remote machine to resume. */
501 mm_resume (step, sig)
505 error ("Can't send signals to a remote MiniMon system.");
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);
513 out_msg_buf->go_msg.code= GO;
514 out_msg_buf->go_msg.length = 0;
515 msg_send_serial(out_msg_buf);
519 /***************************************************************** REMOTE_WAIT
520 ** Wait until the remote machine stops, then return,
521 storing status in STATUS just as `wait' would. */
528 int old_timeout = timeout;
529 int old_immediate_quit = immediate_quit;
531 WSETEXIT ((*status), 0);
534 /* wait for message to arrive. It should be:
535 - A HIF service request.
536 - A HIF exit service request.
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.
543 timeout = 0; /* Wait indefinetly for a message */
544 immediate_quit = 1; /* Helps ability to QUIT */
547 while(msg_recv_serial(in_msg_buf)) {
548 QUIT; /* Let user quit if they want */
550 switch (in_msg_buf->halt_msg.code)
553 i = in_msg_buf->hif_call_rtn_msg.service_number;
554 result=service_HIF(in_msg_buf);
555 if(i == 1) /* EXIT */
558 printf("Warning: failure during HIF service %d\n", i);
561 service_HIF(in_msg_buf);
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);
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);
580 /* FIXME, these printfs should not be here. This is a source level
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);
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);
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);
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);
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);
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);
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);
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);
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);
637 WSETEXIT ((*status), 0);
639 timeout = old_timeout; /* Restore original timeout value */
640 immediate_quit = old_immediate_quit;
644 /******************************************************* REMOTE_FETCH_REGISTERS
645 * Read a remote register 'regno'.
646 * If regno==-1 then read all the registers.
649 mm_fetch_registers (regno)
655 fetch_register(regno);
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);
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]);
679 for (regno=GR64_REGNUM; regno<GR64_REGNUM+32; regno++) {
680 supply_register (regno, data_p++);
682 #endif /* GR64_REGNUM */
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]);
694 for (regno=GR96_REGNUM; regno<GR96_REGNUM+32; regno++) {
695 supply_register (regno, data_p++);
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]);
706 for (regno=LR0_REGNUM; regno<LR0_REGNUM+128; regno++) {
707 supply_register (regno, data_p++);
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]);
718 for (regno=0; regno<=14; regno++) {
719 supply_register (SR_REGNUM(regno), data_p++);
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);
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]);
735 for (regno=128; regno<=135; regno++) {
736 supply_register (SR_REGNUM(regno), data_p++);
739 /* There doesn't seem to be any way to get these. */
742 supply_register (FPE_REGNUM, &val);
743 supply_register (INTE_REGNUM, &val);
744 supply_register (FPS_REGNUM, &val);
745 supply_register (EXO_REGNUM, &val);
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.
757 mm_store_registers (regno)
763 store_register(regno);
769 out_msg_buf->write_r_msg.code= WRITE_REQ;
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);
778 msg_send_serial( out_msg_buf);
779 if (!expect_msg(WRITE_ACK,in_msg_buf,1)) {
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;
789 for (regno=GR64_REGNUM ; regno<GR64_REGNUM+32 ; regno++)
791 out_msg_buf->write_r_msg.data[regno-GR64_REGNUM] = read_register (regno);
793 msg_send_serial(out_msg_buf);
794 if (!expect_msg(WRITE_ACK,in_msg_buf,1)) {
797 #endif /* GR64_REGNUM */
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++)
805 out_msg_buf->write_r_msg.data[regno-GR96_REGNUM] = read_register (regno);
807 msg_send_serial( out_msg_buf);
808 if (!expect_msg(WRITE_ACK,in_msg_buf,1)) {
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;
818 for (regno = LR0_REGNUM ; regno < LR0_REGNUM+128 ; regno++)
820 out_msg_buf->write_r_msg.data[regno-LR0_REGNUM] = read_register (regno);
822 msg_send_serial( out_msg_buf);
823 if (!expect_msg(WRITE_ACK,in_msg_buf,1)) {
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)) {
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));
846 out_msg_buf->write_r_msg.address = 20; /* SPC0 */
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)) {
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)) {
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)) {
876 registers_changed ();
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
887 mm_prepare_to_store ()
889 /* Do nothing, since we can store individual regs */
892 /******************************************************* REMOTE_XFER_MEMORY */
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);
913 /******************************************************* REMOTE_FILES_INFO */
917 printf ("\tAttached to %s at %d baud and running program %s.\n",
918 dev_name, baudrate, prog_name);
921 /************************************************* REMOTE_INSERT_BREAKPOINT */
923 mm_insert_breakpoint (addr, contents_cache)
925 char *contents_cache;
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 */
937 return 1; /* Failure */
941 /************************************************* REMOTE_DELETE_BREAKPOINT */
943 mm_remove_breakpoint (addr, contents_cache)
945 char *contents_cache;
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 */
955 return 1; /* Failure */
960 /******************************************************* REMOTE_KILL */
962 mm_kill(arg,from_tty)
968 #if defined(KERNEL_DEBUGGING)
969 /* We don't ever kill the kernel */
971 printf("Kernel not killed, but left in current state.\n");
972 printf("Use detach to leave kernel running.\n");
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);
979 printf("Target has been stopped.");
980 printf("Would you like to do a hardware reset (y/n) [n] ");
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.");
995 /***************************************************************************/
997 * Load a program into the target.
1000 mm_load(arg_string,from_tty)
1006 #if defined(KERNEL_DEBUGGING)
1007 printf("The kernel had better be loaded already! Loading not done.\n");
1009 if (arg_string == 0)
1010 error ("The load command takes a file name");
1012 arg_string = tilde_expand (arg_string);
1013 make_cleanup (free, arg_string);
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(?,?,?,?,?,?,?,?); */
1021 /* symbol_file_add (arg_string, from_tty, text_addr, 0, 0); */
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. */
1030 mm_write_inferior_memory (memaddr, myaddr, len)
1037 out_msg_buf->write_req_msg.code= WRITE_REQ;
1038 out_msg_buf->write_req_msg.memory_space = mm_memory_space(memaddr);
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);
1051 if (expect_msg(WRITE_ACK,in_msg_buf,1)) {
1052 nwritten += in_msg_buf->write_ack_msg.byte_count;
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. */
1064 mm_read_inferior_memory(memaddr, myaddr, len)
1071 out_msg_buf->read_req_msg.code= READ_REQ;
1072 out_msg_buf->read_req_msg.memory_space = mm_memory_space(memaddr);
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);
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;
1094 /* FIXME! Merge these two. */
1096 mm_xfer_inferior_memory (memaddr, myaddr, len, write)
1103 memaddr = translate_addr(memaddr);
1106 return mm_write_inferior_memory (memaddr, myaddr, len);
1108 return mm_read_inferior_memory (memaddr, myaddr, len);
1112 /********************************************************** MSG_SEND_SERIAL
1113 ** This function is used to send a message over the
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.
1125 msg_send_serial(msg_ptr)
1126 union msg_t *msg_ptr;
1133 /* Send message header */
1135 message_size = msg_ptr->generic_msg.length + (2 * sizeof(INT32));
1137 c = *((char *)msg_ptr+byte_count);
1138 result = write(mm_desc, &c, 1);
1140 byte_count = byte_count + 1;
1142 } while ((byte_count < message_size) );
1145 } /* end msg_send_serial() */
1147 /********************************************************** MSG_RECV_SERIAL
1148 ** This function is used to receive a message over a
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.
1159 msg_recv_serial(msg_ptr)
1160 union msg_t *msg_ptr;
1162 static INT32 length=0;
1163 static INT32 byte_count=0;
1166 if(msg_ptr == 0) /* re-sync request */
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);
1175 read(mm_desc, in_buf, BUFER_SIZE);
1180 /* Receive message */
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);
1187 result = read(mm_desc, &c, 1);
1191 if (errno == EINTR) {
1192 error ("Timeout reading from remote system.");
1194 perror_with_name ("remote");
1195 } else if (result == 1) {
1196 *((char *)msg_ptr+byte_count) = c;
1197 byte_count = byte_count + 1;
1200 /* Message header received. Save message length. */
1201 if (byte_count == (2 * sizeof(INT32)))
1202 length = msg_ptr->generic_msg.length;
1204 if (byte_count >= (length + (2 * sizeof(INT32)))) {
1205 /* Message received */
1211 } /* end msg_recv_serial() */
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.
1225 /* Get keyboard termio (to save to restore original modes) */
1227 result = ioctl(0, TCGETA, &kbd_tbuf);
1229 result = ioctl(0, TIOCGETP, &kbd_tbuf);
1234 /* Get keyboard TERMINAL (for modification) */
1236 result = ioctl(0, TCGETA, &tbuf);
1238 result = ioctl(0, TIOCGETP, &tbuf);
1243 /* Set up new parameters */
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 */
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;
1257 /* Set keyboard termio to new mode (RAW) */
1259 result = ioctl(0, TCSETAF, &tbuf);
1261 result = ioctl(0, TIOCSETP, &tbuf);
1267 } /* end kbd_raw() */
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.
1282 /* Set keyboard termio to original mode */
1284 result = ioctl(0, TCSETAF, &kbd_tbuf);
1286 result = ioctl(0, TIOCGETP, &kbd_tbuf);
1293 } /* end kbd_cooked() */
1296 /*****************************************************************************/
1297 /* Fetch a single register indicatated by 'regno'.
1298 * Returns 0/-1 on success/failure.
1301 fetch_register (regno)
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;
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;
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;
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;
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);
1327 else if (regno>=FPE_REGNUM && regno<=EXO_REGNUM)
1329 supply_register(160 + (regno - FPE_REGNUM),&val);
1330 return 0; /* Pretend Success */
1333 { out_msg_buf->read_req_msg.memory_space = SPECIAL_REG;
1334 out_msg_buf->read_req_msg.address = regnum_to_srnum(regno);
1337 msg_send_serial(out_msg_buf);
1339 if (expect_msg(READ_ACK,in_msg_buf,1)) {
1340 supply_register (regno, &(in_msg_buf->read_r_ack_msg.data[0]));
1347 /*****************************************************************************/
1348 /* Store a single register indicated by 'regno'.
1349 * Returns 0/-1 on success/failure.
1352 store_register (regno)
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);
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
1371 registers_changed ();
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;
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;
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);
1387 else if (regno>=FPE_REGNUM && regno<=EXO_REGNUM)
1389 return 0; /* Pretend Success */
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);
1396 msg_send_serial(out_msg_buf);
1398 if (expect_msg(WRITE_ACK,in_msg_buf,1)) {
1405 /****************************************************************************/
1407 * Convert a gdb special register number to a 29000 special register number.
1410 regnum_to_srnum(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);
1442 return(255); /* Failure ? */
1445 /****************************************************************************/
1447 * Initialize the target debugger (minimon only).
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;
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);
1468 /****************************************************************************/
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.
1478 static char cbuf[32];
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;
1492 /****************************************************************************/
1494 * Selected (not all of them) error codes that we might get.
1500 static char cbuf[50];
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;
1531 /****************************************************************************/
1533 * Receive a message and expect it to be of type msgcode.
1534 * Returns 0/1 on failure/success.
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 */
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 */
1550 if (msg_buf->generic_msg.code != msgcode) {
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));
1557 return(0); /* Failure */
1559 return(1); /* Success */
1561 /****************************************************************************/
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.
1568 mm_memory_space(addr)
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;
1578 if (((ADDR32)addr >= tstart) && ((ADDR32)addr < tend)) {
1580 } else if (((ADDR32)addr >= dstart) && ((ADDR32)addr < dend)) {
1582 } else if (((ADDR32)addr >= rstart) && ((ADDR32)addr < rend)) {
1583 /* FIXME: how do we determine between D_ROM and I_ROM */
1585 } else /* FIXME: what do me do now? */
1586 return D_MEM; /* Hmmm! */
1589 /****************************************************************************/
1591 * Define the target subroutine names
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",
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,
1602 mm_insert_breakpoint, mm_remove_breakpoint, /* Breakpoints */
1603 0, 0, 0, 0, 0, /* Terminal handling */
1604 mm_kill, /* FIXME, kill */
1606 0, /* lookup_symbol */
1607 mm_create_inferior, /* create_inferior */
1608 mm_mourn, /* mourn_inferior FIXME */
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 */
1618 _initialize_remote_mm()
1620 add_target (&mm_ops);
1623 #ifdef NO_HIF_SUPPORT
1627 return(0); /* Emulate a failure */