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
46 /* Offset of member MEMBER in a struct of type TYPE. */
47 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
49 /* #define DEBUG 1 /* */
51 # define DENTER(NAME) (printf("Entering %s\n",NAME), fflush(stdout))
52 # define DEXIT(NAME) (printf("Exiting %s\n",NAME), fflush(stdout))
58 #define DRAIN_INPUT() (msg_recv_serial((union msg_t*)0))
60 extern int stop_soon_quietly
; /* for wait_for_inferior */
62 static void mm_resume();
63 static void mm_fetch_registers ();
64 static int fetch_register ();
65 static int mm_store_registers ();
66 static int store_register ();
67 static int regnum_to_srnum();
68 static void mm_close ();
69 static char* msg_str();
70 static char* error_msg_str();
71 static int expect_msg();
72 static void init_target_mm();
73 static int mm_memory_space();
78 #define TYPE_UNKNOWN 0
82 static char *processor_name
[] = { "Unknown", "A29000", "A29030", "A29050" };
83 static int processor_type
=TYPE_UNKNOWN
;
84 #define FREEZE_MODE (read_register(CPS_REGNUM) && 0x400)
85 #define USE_SHADOW_PC ((processor_type == TYPE_A29050) && FREEZE_MODE)
87 #define LLOG_FILE "minimon.log"
88 #if defined (LOG_FILE)
93 * Size of message buffers. I couldn't get memory reads to work when
94 * the byte_count was larger than 512 (it may be a baud rate problem).
96 #define BUFER_SIZE 512
98 * Size of data area in message buffer on the TARGET (remote system).
100 #define MAXDATA_T (target_config.max_msg_size - \
101 offsetof(struct write_r_msg_t,data[0]))
103 * Size of data area in message buffer on the HOST (gdb).
105 #define MAXDATA_H (BUFER_SIZE - offsetof(struct write_r_msg_t,data[0]))
107 * Defined as the minimum size of data areas of the two message buffers
109 #define MAXDATA (MAXDATA_H < MAXDATA_T ? MAXDATA_H : MAXDATA_T)
111 static char out_buf
[BUFER_SIZE
];
112 static char in_buf
[BUFER_SIZE
];
114 int msg_recv_serial();
115 int msg_send_serial();
117 #define MAX_RETRIES 5000
118 extern struct target_ops mm_ops
; /* Forward declaration */
119 struct config_msg_t target_config
; /* HIF needs this */
120 union msg_t
*out_msg_buf
= (union msg_t
*)out_buf
;
121 union msg_t
*in_msg_buf
= (union msg_t
*)in_buf
;
123 static int timeout
= 5;
125 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
126 mm_open knows that we don't have a file open when the program
130 /* stream which is fdopen'd from mm_desc. Only valid when
134 /* Called when SIGALRM signal sent due to alarm() timeout. */
139 # define volatile /**/
142 volatile int n_alarms
;
149 printf ("mm_timer called\n");
153 #endif /* HAVE_TERMIO */
155 /* malloc'd name of the program on the remote system. */
156 static char *prog_name
= NULL
;
159 /* Number of SIGTRAPs we need to simulate. That is, the next
160 NEED_ARTIFICIAL_TRAP calls to mm_wait should just return
161 SIGTRAP without actually waiting for anything. */
163 /**************************************************** REMOTE_CREATE_INFERIOR */
164 /* This is called not only when we first attach, but also when the
165 user types "run" after having attached. */
167 mm_create_inferior (execfile
, args
, env
)
172 #define MAX_TOKENS 25
173 #define BUFFER_SIZE 256
176 char *token
[MAX_TOKENS
];
177 char cmd_line
[BUFFER_SIZE
];
179 DENTER("mm_create_inferior()");
182 error ("Can't pass arguments to remote mm process (yet).");
184 if (execfile
== 0 /* || exec_bfd == 0 */ )
185 error ("No exec file specified");
188 printf("Minimon not open yet.\n");
192 /* On ultra3 (NYU) we assume the kernel is already running so there is
194 FIXME: Fixed required here -> load your program, possibly with mm_load().
196 printf_filtered ("\n\
197 Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n");
199 /* We will get a task spawn event immediately. */
200 #ifdef NOTDEF /* start_remote() now does a wait without a resume
204 init_wait_for_inferior ();
205 clear_proceed_status ();
206 stop_soon_quietly
= 1;
210 DEXIT("mm_create_inferior()");
212 /**************************************************** REMOTE_MOURN_INFERIOR */
216 DENTER("mm_mourn()");
217 pop_target (); /* Pop back to no-child state */
218 generic_mourn_inferior ();
222 /********************************************************************** damn_b
224 /* Translate baud rates from integers to damn B_codes. Unix should
225 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
234 static struct {int rate
, damn_b
;} baudtab
[] = {
254 static int damn_b (rate
)
259 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
260 if (rate
== baudtab
[i
].rate
) return baudtab
[i
].damn_b
;
261 return B38400
; /* Random */
265 /***************************************************************** REMOTE_OPEN
266 ** Open a connection to remote minimon.
267 NAME is the filename used for communication, then a space,
269 'target adapt /dev/ttya 9600 [prognam]' for example.
272 static char *dev_name
;
275 mm_open (name
, from_tty
)
285 /* Find the first whitespace character, it separates dev_name from
288 p
&& *p
&& !isspace (*p
); p
++)
290 if (p
== 0 || *p
== '\0')
292 error ("Usage : <command> <serial-device> <baud-rate> [progname]");
293 dev_name
= (char*)malloc (p
- name
+ 1);
294 strncpy (dev_name
, name
, p
- name
);
295 dev_name
[p
- name
] = '\0';
297 /* Skip over the whitespace after dev_name */
298 for (; isspace (*p
); p
++)
301 if (1 != sscanf (p
, "%d ", &baudrate
))
304 /* Skip the number and then the spaces */
305 for (; isdigit (*p
); p
++)
307 for (; isspace (*p
); p
++)
310 if (prog_name
!= NULL
)
312 prog_name
= savestring (p
, strlen (p
));
318 mm_desc
= open (dev_name
, O_RDWR
);
320 perror_with_name (dev_name
);
321 ioctl (mm_desc
, TIOCGETP
, &sg
);
323 sg
.c_cc
[VMIN
] = 0; /* read with timeout. */
324 sg
.c_cc
[VTIME
] = timeout
* 10;
325 sg
.c_lflag
&= ~(ICANON
| ECHO
);
326 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | damn_b (baudrate
);
328 sg
.sg_ispeed
= damn_b (baudrate
);
329 sg
.sg_ospeed
= damn_b (baudrate
);
332 sg
.sg_flags
&= ~ECHO
;
336 ioctl (mm_desc
, TIOCSETP
, &sg
);
337 mm_stream
= fdopen (mm_desc
, "r+");
339 push_target (&mm_ops
);
342 #ifndef NO_SIGINTERRUPT
343 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
345 if (siginterrupt (SIGALRM
, 1) != 0)
346 perror ("mm_open: error in siginterrupt");
349 /* Set up read timeout timer. */
350 if ((void (*)) signal (SIGALRM
, mm_timer
) == (void (*)) -1)
351 perror ("mm_open: error in signal");
354 #if defined (LOG_FILE)
355 log_file
= fopen (LOG_FILE
, "w");
356 if (log_file
== NULL
)
357 perror_with_name (LOG_FILE
);
360 ** Initialize target configuration structure (global)
363 out_msg_buf
->config_req_msg
.code
= CONFIG_REQ
;
364 out_msg_buf
->config_req_msg
.length
= 4*0;
365 msg_send_serial(out_msg_buf
); /* send config request message */
367 expect_msg(CONFIG
,in_msg_buf
,1);
369 /* Determine the processor revision level */
370 /* FIXME: this code is the same as in remote-adapt.c */
371 prl
= (unsigned int)read_register(CFG_REGNUM
) >> 24;
373 processor_type
= TYPE_A29000
;
374 } else if ((prl
&0xf0) == 0x40) { /* 29030 = 0x4* */
375 processor_type
= TYPE_A29030
;
376 fprintf_filtered(stderr
,"WARNING: debugging of A29030 not tested.\n");
377 } else if ((prl
&0xf0) == 0x20) { /* 29050 = 0x2* */
378 processor_type
= TYPE_A29050
;
379 fprintf_filtered(stderr
,"WARNING: debugging of A29050 not tested.\n");
381 processor_type
= TYPE_UNKNOWN
;
382 fprintf_filtered(stderr
,"WARNING: processor type unknown.\n");
385 /* Print out some stuff, letting the user now what's going on */
386 printf_filtered("Remote debugging on an %s connect to MiniMon via %s.\n",
387 processor_name
[processor_type
],dev_name
);
388 /* FIXME: can this restriction be removed? */
389 printf_filtered("Remote debugging using virtual addresses works only\n");
390 printf_filtered("\twhen virtual addresses map 1:1 to physical addresses.\n")
392 if (processor_type
!= TYPE_A29050
) {
393 fprintf_filtered(stderr
,
394 "Freeze-mode debugging not available, and can only be done on an A29050.\n");
397 target_config
.code
= CONFIG
;
398 target_config
.length
= 0;
399 target_config
.processor_id
= in_msg_buf
->config_msg
.processor_id
;
400 target_config
.version
= in_msg_buf
->config_msg
.version
;
401 target_config
.I_mem_start
= in_msg_buf
->config_msg
.I_mem_start
;
402 target_config
.I_mem_size
= in_msg_buf
->config_msg
.I_mem_size
;
403 target_config
.D_mem_start
= in_msg_buf
->config_msg
.D_mem_start
;
404 target_config
.D_mem_size
= in_msg_buf
->config_msg
.D_mem_size
;
405 target_config
.ROM_start
= in_msg_buf
->config_msg
.ROM_start
;
406 target_config
.ROM_size
= in_msg_buf
->config_msg
.ROM_size
;
407 target_config
.max_msg_size
= in_msg_buf
->config_msg
.max_msg_size
;
408 target_config
.max_bkpts
= in_msg_buf
->config_msg
.max_bkpts
;
409 target_config
.coprocessor
= in_msg_buf
->config_msg
.coprocessor
;
410 target_config
.reserved
= in_msg_buf
->config_msg
.reserved
;
412 printf("Connected to MiniMON :\n");
413 printf(" Debugcore version %d.%d\n",
414 0x0f & (target_config
.version
>> 4),
415 0x0f & (target_config
.version
) );
416 printf(" Configuration version %d.%d\n",
417 0x0f & (target_config
.version
>> 12),
418 0x0f & (target_config
.version
>> 8) );
419 printf(" Message system version %d.%d\n",
420 0x0f & (target_config
.version
>> 20),
421 0x0f & (target_config
.version
>> 16) );
422 printf(" Communication driver version %d.%d\n",
423 0x0f & (target_config
.version
>> 28),
424 0x0f & (target_config
.version
>> 24) );
427 /* Leave the target running...
428 * The above message stopped the target in the dbg core (MiniMon),
429 * so restart the target out of MiniMon,
431 out_msg_buf
->go_msg
.code
= GO
;
432 out_msg_buf
->go_msg
.length
= 0;
433 msg_send_serial(out_msg_buf
);
434 /* No message to expect after a GO */
439 /**************************************************************** REMOTE_CLOSE
440 ** Close the open connection to the minimon debugger.
441 Use this when you want to detach and do something else
444 mm_close (quitting
) /*FIXME: how is quitting used */
447 DENTER("mm_close()");
450 error ("Can't close remote connection: not debugging remotely.");
452 /* We should never get here if there isn't something valid in
453 mm_desc and mm_stream.
455 Due to a bug in Unix, fclose closes not only the stdio stream,
456 but also the file descriptor. So we don't actually close
460 /* close (mm_desc); */
462 /* Do not try to close mm_desc again, later in the program. */
466 #if defined (LOG_FILE)
467 if (ferror (log_file
))
468 printf ("Error writing log file.\n");
469 if (fclose (log_file
) != 0)
470 printf ("Error closing log file.\n");
473 printf ("Ending remote debugging\n");
479 /************************************************************* REMOTE_ATACH */
480 /* Attach to a program that is already loaded and running
481 * Upon exiting the process's execution is stopped.
484 mm_attach (args
, from_tty
)
489 DENTER("mm_attach()");
492 printf ("MiniMon not opened yet, use the 'target minimon' command.\n");
497 printf ("Attaching to remote program %s...\n", prog_name
);
500 /* Make sure the target is currently running, it is supposed to be. */
501 /* FIXME: is it ok to send MiniMon a BREAK if it is already stopped in
502 * the dbg core. If so, we don't need to send this GO.
504 out_msg_buf
->go_msg
.code
= GO
;
505 out_msg_buf
->go_msg
.length
= 0;
506 msg_send_serial(out_msg_buf
);
507 sleep(2); /* At the worst it will stop, receive a message, continue */
509 /* Send the mm a break. */
510 out_msg_buf
->break_msg
.code
= BREAK
;
511 out_msg_buf
->break_msg
.length
= 0;
512 msg_send_serial(out_msg_buf
);
514 mark_breakpoints_out ();
515 init_wait_for_inferior ();
516 clear_proceed_status ();
517 stop_soon_quietly
= 1;
518 wait_for_inferior ();
519 stop_soon_quietly
= 0;
522 DEXIT("mm_attach()");
524 /********************************************************** REMOTE_DETACH */
525 /* Terminate the open connection to the remote debugger.
526 Use this when you want to detach and do something else
527 with your gdb. Leave remote process running (with no breakpoints set). */
529 mm_detach (args
,from_tty
)
533 DENTER("mm_dettach()");
534 remove_breakpoints(); /* Just in case there were any left in */
535 out_msg_buf
->go_msg
.code
= GO
;
536 out_msg_buf
->go_msg
.length
= 0;
537 msg_send_serial(out_msg_buf
);
538 pop_target(); /* calls mm_close to do the real work */
539 DEXIT("mm_dettach()");
543 /*************************************************************** REMOTE_RESUME
544 ** Tell the remote machine to resume. */
547 mm_resume (step
, sig
)
550 DENTER("mm_resume()");
553 error ("Can't send signals to a remote MiniMon system.");
556 out_msg_buf
->step_msg
.code
= STEP
;
557 out_msg_buf
->step_msg
.length
= 1*4;
558 out_msg_buf
->step_msg
.count
= 1; /* step 1 instruction */
559 msg_send_serial(out_msg_buf
);
561 out_msg_buf
->go_msg
.code
= GO
;
562 out_msg_buf
->go_msg
.length
= 0;
563 msg_send_serial(out_msg_buf
);
566 DEXIT("mm_resume()");
569 /***************************************************************** REMOTE_WAIT
570 ** Wait until the remote machine stops, then return,
571 storing status in STATUS just as `wait' would. */
578 int old_timeout
= timeout
;
579 int old_immediate_quit
= immediate_quit
;
582 WSETEXIT ((*status
), 0);
585 /* wait for message to arrive. It should be:
586 - A HIF service request.
587 - A HIF exit service request.
589 - A CHANNEL1 request.
590 - a debugcore HALT message.
591 HIF services must be responded too, and while-looping continued.
592 If the target stops executing, mm_wait() should return.
594 timeout
= 0; /* Wait indefinetly for a message */
595 immediate_quit
= 1; /* Helps ability to QUIT */
598 while(msg_recv_serial(in_msg_buf
)) {
599 QUIT
; /* Let user quit if they want */
601 switch (in_msg_buf
->halt_msg
.code
)
604 i
= in_msg_buf
->hif_call_rtn_msg
.service_number
;
605 result
=service_HIF(in_msg_buf
);
606 if(i
== 1) /* EXIT */
609 printf("Warning: failure during HIF service %d\n", i
);
612 service_HIF(in_msg_buf
);
615 i
=in_msg_buf
->channel1_msg
.length
;
616 in_msg_buf
->channel1_msg
.data
[i
] = '\0';
617 printf("%s", in_msg_buf
->channel1_msg
.data
);
619 /* Send CHANNEL1_ACK message */
620 out_msg_buf
->channel1_ack_msg
.code
= CHANNEL1_ACK
;
621 out_msg_buf
->channel1_ack_msg
.length
= 0;
622 result
= msg_send_serial(out_msg_buf
);
631 /* FIXME, these printfs should not be here. This is a source level
633 if (in_msg_buf
->halt_msg
.trap_number
== 0)
634 { printf("Am290*0 received vector number %d (break point)\n",
635 in_msg_buf
->halt_msg
.trap_number
);
636 WSETSTOP ((*status
), SIGTRAP
);
638 else if (in_msg_buf
->halt_msg
.trap_number
== 1)
639 { printf("Am290*0 received vector number %d\n",
640 in_msg_buf
->halt_msg
.trap_number
);
641 WSETSTOP ((*status
), SIGBUS
);
643 else if (in_msg_buf
->halt_msg
.trap_number
== 3
644 || in_msg_buf
->halt_msg
.trap_number
== 4)
645 { printf("Am290*0 received vector number %d\n",
646 in_msg_buf
->halt_msg
.trap_number
);
647 WSETSTOP ((*status
), SIGFPE
);
649 else if (in_msg_buf
->halt_msg
.trap_number
== 5)
650 { printf("Am290*0 received vector number %d\n",
651 in_msg_buf
->halt_msg
.trap_number
);
652 WSETSTOP ((*status
), SIGILL
);
654 else if (in_msg_buf
->halt_msg
.trap_number
>= 6
655 && in_msg_buf
->halt_msg
.trap_number
<= 11)
656 { printf("Am290*0 received vector number %d\n",
657 in_msg_buf
->halt_msg
.trap_number
);
658 WSETSTOP ((*status
), SIGSEGV
);
660 else if (in_msg_buf
->halt_msg
.trap_number
== 12
661 || in_msg_buf
->halt_msg
.trap_number
== 13)
662 { printf("Am290*0 received vector number %d\n",
663 in_msg_buf
->halt_msg
.trap_number
);
664 WSETSTOP ((*status
), SIGILL
);
666 else if (in_msg_buf
->halt_msg
.trap_number
== 14)
667 { printf("Am290*0 received vector number %d\n",
668 in_msg_buf
->halt_msg
.trap_number
);
669 WSETSTOP ((*status
), SIGALRM
);
671 else if (in_msg_buf
->halt_msg
.trap_number
== 15)
672 WSETSTOP ((*status
), SIGTRAP
);
673 else if (in_msg_buf
->halt_msg
.trap_number
>= 16
674 && in_msg_buf
->halt_msg
.trap_number
<= 21)
675 { printf("Am290*0 received vector number %d\n",
676 in_msg_buf
->halt_msg
.trap_number
);
677 WSETSTOP ((*status
), SIGINT
);
679 else if (in_msg_buf
->halt_msg
.trap_number
== 22)
680 { printf("Am290*0 received vector number %d\n",
681 in_msg_buf
->halt_msg
.trap_number
);
682 WSETSTOP ((*status
), SIGILL
);
683 } /* BREAK message was sent */
684 else if (in_msg_buf
->halt_msg
.trap_number
== 75)
685 WSETSTOP ((*status
), SIGTRAP
);
688 WSETEXIT ((*status
), 0);
690 timeout
= old_timeout
; /* Restore original timeout value */
691 immediate_quit
= old_immediate_quit
;
696 /******************************************************* REMOTE_FETCH_REGISTERS
697 * Read a remote register 'regno'.
698 * If regno==-1 then read all the registers.
701 mm_fetch_registers (regno
)
707 fetch_register(regno
);
711 DENTER("mm_fetch_registers()");
714 out_msg_buf
->read_req_msg
.byte_count
= 4*1;
715 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
716 out_msg_buf
->read_req_msg
.address
= 1;
717 msg_send_serial(out_msg_buf
);
718 expect_msg(READ_ACK
,in_msg_buf
,1);
719 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
720 supply_register (GR1_REGNUM
, data_p
);
722 #if defined(GR64_REGNUM) /* Read gr64-127 */
723 /* Global Registers gr64-gr95 */
724 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
725 out_msg_buf
->read_req_msg
.length
= 4*3;
726 out_msg_buf
->read_req_msg
.byte_count
= 4*32;
727 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
728 out_msg_buf
->read_req_msg
.address
= 64;
729 msg_send_serial(out_msg_buf
);
730 expect_msg(READ_ACK
,in_msg_buf
,1);
731 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
733 for (regno
=GR64_REGNUM
; regno
<GR64_REGNUM
+32; regno
++) {
734 supply_register (regno
, data_p
++);
736 #endif /* GR64_REGNUM */
738 /* Global Registers gr96-gr127 */
739 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
740 out_msg_buf
->read_req_msg
.length
= 4*3;
741 out_msg_buf
->read_req_msg
.byte_count
= 4 * 32;
742 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
743 out_msg_buf
->read_req_msg
.address
= 96;
744 msg_send_serial(out_msg_buf
);
745 expect_msg(READ_ACK
,in_msg_buf
,1);
746 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
748 for (regno
=GR96_REGNUM
; regno
<GR96_REGNUM
+32; regno
++) {
749 supply_register (regno
, data_p
++);
752 /* Local Registers */
753 out_msg_buf
->read_req_msg
.byte_count
= 4 * (128);
754 out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
755 out_msg_buf
->read_req_msg
.address
= 0;
756 msg_send_serial(out_msg_buf
);
757 expect_msg(READ_ACK
,in_msg_buf
,1);
758 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
760 for (regno
=LR0_REGNUM
; regno
<LR0_REGNUM
+128; regno
++) {
761 supply_register (regno
, data_p
++);
764 /* Protected Special Registers */
765 out_msg_buf
->read_req_msg
.byte_count
= 4*15;
766 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
767 out_msg_buf
->read_req_msg
.address
= 0;
768 msg_send_serial( out_msg_buf
);
769 expect_msg(READ_ACK
,in_msg_buf
,1);
770 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
772 for (regno
=0; regno
<=14; regno
++) {
773 supply_register (SR_REGNUM(regno
), data_p
++);
775 if (USE_SHADOW_PC
) { /* Let regno_to_srnum() handle the register number */
776 fetch_register(NPC_REGNUM
);
777 fetch_register(PC_REGNUM
);
778 fetch_register(PC2_REGNUM
);
781 /* Unprotected Special Registers */
782 out_msg_buf
->read_req_msg
.byte_count
= 4*8;
783 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
784 out_msg_buf
->read_req_msg
.address
= 128;
785 msg_send_serial( out_msg_buf
);
786 expect_msg(READ_ACK
,in_msg_buf
,1);
787 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
789 for (regno
=128; regno
<=135; regno
++) {
790 supply_register (SR_REGNUM(regno
), data_p
++);
793 /* There doesn't seem to be any way to get these. */
796 supply_register (FPE_REGNUM
, &val
);
797 supply_register (INT_REGNUM
, &val
);
798 supply_register (FPS_REGNUM
, &val
);
799 supply_register (EXO_REGNUM
, &val
);
802 DEXIT("mm_fetch_registerS()");
806 /****************************************************** REMOTE_STORE_REGISTERS
807 * Store register regno into the target.
808 * If regno==-1 then store all the registers.
809 * Result is 0 for success, -1 for failure.
813 mm_store_registers (regno
)
819 return(store_register(regno
));
821 DENTER("mm_store_registers()");
824 out_msg_buf
->write_r_msg
.code
= WRITE_REQ
;
827 out_msg_buf
->write_r_msg
.byte_count
= 4*1;
828 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
829 out_msg_buf
->write_r_msg
.memory_space
= GLOBAL_REG
;
830 out_msg_buf
->write_r_msg
.address
= 1;
831 out_msg_buf
->write_r_msg
.data
[0] = read_register (GR1_REGNUM
);
833 msg_send_serial( out_msg_buf
);
834 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
838 #if defined(GR64_REGNUM)
839 /* Global registers gr64-gr95 */
840 out_msg_buf
->write_r_msg
.byte_count
= 4* (32);
841 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
842 out_msg_buf
->write_r_msg
.address
= 64;
844 for (regno
=GR64_REGNUM
; regno
<GR64_REGNUM
+32 ; regno
++)
846 out_msg_buf
->write_r_msg
.data
[regno
-GR64_REGNUM
] = read_register (regno
);
848 msg_send_serial(out_msg_buf
);
849 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
852 #endif /* GR64_REGNUM */
854 /* Global registers gr96-gr127 */
855 out_msg_buf
->write_r_msg
.byte_count
= 4* (32);
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
= 96;
858 for (regno
=GR96_REGNUM
; regno
<GR96_REGNUM
+32 ; regno
++)
860 out_msg_buf
->write_r_msg
.data
[regno
-GR96_REGNUM
] = read_register (regno
);
862 msg_send_serial( out_msg_buf
);
863 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
867 /* Local Registers */
868 out_msg_buf
->write_r_msg
.memory_space
= LOCAL_REG
;
869 out_msg_buf
->write_r_msg
.byte_count
= 4*128;
870 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
871 out_msg_buf
->write_r_msg
.address
= 0;
873 for (regno
= LR0_REGNUM
; regno
< LR0_REGNUM
+128 ; regno
++)
875 out_msg_buf
->write_r_msg
.data
[regno
-LR0_REGNUM
] = read_register (regno
);
877 msg_send_serial( out_msg_buf
);
878 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
882 /* Protected Special Registers */
883 /* VAB through TMR */
884 out_msg_buf
->write_r_msg
.memory_space
= SPECIAL_REG
;
885 out_msg_buf
->write_r_msg
.byte_count
= 4* 10;
886 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
887 out_msg_buf
->write_r_msg
.address
= 0;
888 for (regno
= 0 ; regno
<=9 ; regno
++) /* VAB through TMR */
889 out_msg_buf
->write_r_msg
.data
[regno
] = read_register (SR_REGNUM(regno
));
890 msg_send_serial( out_msg_buf
);
891 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
895 /* PC0, PC1, PC2 possibly as shadow registers */
896 out_msg_buf
->write_r_msg
.byte_count
= 4* 3;
897 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
898 for (regno
=10 ; regno
<=12 ; regno
++) /* LRU and MMU */
899 out_msg_buf
->write_r_msg
.data
[regno
-10] = read_register (SR_REGNUM(regno
));
901 out_msg_buf
->write_r_msg
.address
= 20; /* SPC0 */
903 out_msg_buf
->write_r_msg
.address
= 10; /* PC0 */
904 msg_send_serial( out_msg_buf
);
905 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
910 out_msg_buf
->write_r_msg
.byte_count
= 4* 2;
911 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
912 out_msg_buf
->write_r_msg
.address
= 13;
913 for (regno
=13 ; regno
<=14 ; regno
++) /* LRU and MMU */
914 out_msg_buf
->write_r_msg
.data
[regno
-13] = read_register (SR_REGNUM(regno
));
915 msg_send_serial( out_msg_buf
);
916 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
920 /* Unprotected Special Registers */
921 out_msg_buf
->write_r_msg
.byte_count
= 4*8;
922 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
923 out_msg_buf
->write_r_msg
.address
= 128;
924 for (regno
= 128 ; regno
<=135 ; regno
++)
925 out_msg_buf
->write_r_msg
.data
[regno
-128] = read_register(SR_REGNUM(regno
));
926 msg_send_serial( out_msg_buf
);
927 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
931 registers_changed ();
932 DEXIT("mm_store_registers()");
936 /*************************************************** REMOTE_PREPARE_TO_STORE */
937 /* Get ready to modify the registers array. On machines which store
938 individual registers, this doesn't need to do anything. On machines
939 which store all the registers in one fell swoop, this makes sure
940 that registers contains all the registers from the program being
944 mm_prepare_to_store ()
946 /* Do nothing, since we can store individual regs */
949 /******************************************************* REMOTE_XFER_MEMORY */
954 #if defined(KERNEL_DEBUGGING)
955 /* Check for a virtual address in the kernel */
956 /* Assume physical address of ublock is in paddr_u register */
957 /* FIXME: doesn't work for user virtual addresses */
958 if (addr
>= UVADDR
) {
959 /* PADDR_U register holds the physical address of the ublock */
960 CORE_ADDR i
= (CORE_ADDR
)read_register(PADDR_U_REGNUM
);
961 return(i
+ addr
- (CORE_ADDR
)UVADDR
);
970 /******************************************************* REMOTE_FILES_INFO */
974 printf ("\tAttached to %s at %d baud and running program %s.\n",
975 dev_name
, baudrate
, prog_name
);
978 /************************************************* REMOTE_INSERT_BREAKPOINT */
980 mm_insert_breakpoint (addr
, contents_cache
)
982 char *contents_cache
;
984 DENTER("mm_insert_breakpoint()");
985 out_msg_buf
->bkpt_set_msg
.code
= BKPT_SET
;
986 out_msg_buf
->bkpt_set_msg
.length
= 4*4;
987 out_msg_buf
->bkpt_set_msg
.memory_space
= I_MEM
;
988 out_msg_buf
->bkpt_set_msg
.bkpt_addr
= (ADDR32
) addr
;
989 out_msg_buf
->bkpt_set_msg
.pass_count
= 1;
990 out_msg_buf
->bkpt_set_msg
.bkpt_type
= -1; /* use illop for 29000 */
991 msg_send_serial( out_msg_buf
);
992 if (expect_msg(BKPT_SET_ACK
,in_msg_buf
,1)) {
993 DEXIT("mm_insert_breakpoint() success");
994 return 0; /* Success */
996 DEXIT("mm_insert_breakpoint() failure");
997 return 1; /* Failure */
1001 /************************************************* REMOTE_DELETE_BREAKPOINT */
1003 mm_remove_breakpoint (addr
, contents_cache
)
1005 char *contents_cache
;
1007 DENTER("mm_remove_breakpoint()");
1008 out_msg_buf
->bkpt_rm_msg
.code
= BKPT_RM
;
1009 out_msg_buf
->bkpt_rm_msg
.length
= 4*3;
1010 out_msg_buf
->bkpt_rm_msg
.memory_space
= I_MEM
;
1011 out_msg_buf
->bkpt_rm_msg
.bkpt_addr
= (ADDR32
) addr
;
1012 msg_send_serial( out_msg_buf
);
1013 if (expect_msg(BKPT_RM_ACK
,in_msg_buf
,1)) {
1014 DEXIT("mm_remove_breakpoint()");
1015 return 0; /* Success */
1017 DEXIT("mm_remove_breakpoint()");
1018 return 1; /* Failure */
1023 /******************************************************* REMOTE_KILL */
1025 mm_kill(arg
,from_tty
)
1031 DENTER("mm_kill()");
1032 #if defined(KERNEL_DEBUGGING)
1033 /* We don't ever kill the kernel */
1035 printf("Kernel not killed, but left in current state.\n");
1036 printf("Use detach to leave kernel running.\n");
1039 out_msg_buf
->break_msg
.code
= BREAK
;
1040 out_msg_buf
->bkpt_set_msg
.length
= 4*0;
1041 expect_msg(HALT
,in_msg_buf
,from_tty
);
1043 printf("Target has been stopped.");
1044 printf("Would you like to do a hardware reset (y/n) [n] ");
1046 if (buf
[0] == 'y') {
1047 out_msg_buf
->reset_msg
.code
= RESET
;
1048 out_msg_buf
->bkpt_set_msg
.length
= 4*0;
1049 expect_msg(RESET_ACK
,in_msg_buf
,from_tty
);
1050 printf("Target has been reset.");
1060 /***************************************************************************/
1062 * Load a program into the target.
1065 mm_load(arg_string
,from_tty
)
1071 #if defined(KERNEL_DEBUGGING)
1072 printf("The kernel had better be loaded already! Loading not done.\n");
1074 if (arg_string
== 0)
1075 error ("The load command takes a file name");
1077 arg_string
= tilde_expand (arg_string
);
1078 make_cleanup (free
, arg_string
);
1081 error("File loading is not yet supported for MiniMon.");
1082 /* FIXME, code to load your file here... */
1083 /* You may need to do an init_target_mm() */
1084 /* init_target_mm(?,?,?,?,?,?,?,?); */
1086 /* symbol_file_add (arg_string, from_tty, text_addr, 0); */
1091 /************************************************ REMOTE_WRITE_INFERIOR_MEMORY
1092 ** Copy LEN bytes of data from debugger memory at MYADDR
1093 to inferior's memory at MEMADDR. Returns number of bytes written. */
1095 mm_write_inferior_memory (memaddr
, myaddr
, len
)
1102 /* DENTER("mm_write_inferior_memory()"); */
1103 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1104 out_msg_buf
->write_req_msg
.memory_space
= mm_memory_space(memaddr
);
1107 while (nwritten
< len
) {
1108 int num_to_write
= len
- nwritten
;
1109 if (num_to_write
> MAXDATA
) num_to_write
= MAXDATA
;
1110 for (i
=0 ; i
< num_to_write
; i
++)
1111 out_msg_buf
->write_req_msg
.data
[i
] = myaddr
[i
+nwritten
];
1112 out_msg_buf
->write_req_msg
.byte_count
= num_to_write
;
1113 out_msg_buf
->write_req_msg
.length
= 3*4 + num_to_write
;
1114 out_msg_buf
->write_req_msg
.address
= memaddr
+ nwritten
;
1115 msg_send_serial(out_msg_buf
);
1117 if (expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
1118 nwritten
+= in_msg_buf
->write_ack_msg
.byte_count
;
1123 /* DEXIT("mm_write_inferior_memory()"); */
1127 /************************************************* REMOTE_READ_INFERIOR_MEMORY
1128 ** Read LEN bytes from inferior memory at MEMADDR. Put the result
1129 at debugger address MYADDR. Returns number of bytes read. */
1131 mm_read_inferior_memory(memaddr
, myaddr
, len
)
1138 /* DENTER("mm_read_inferior_memory()"); */
1139 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1140 out_msg_buf
->read_req_msg
.memory_space
= mm_memory_space(memaddr
);
1143 while (nread
< len
) {
1144 int num_to_read
= (len
- nread
);
1145 if (num_to_read
> MAXDATA
) num_to_read
= MAXDATA
;
1146 out_msg_buf
->read_req_msg
.byte_count
= num_to_read
;
1147 out_msg_buf
->read_req_msg
.length
= 3*4 + num_to_read
;
1148 out_msg_buf
->read_req_msg
.address
= memaddr
+ nread
;
1149 msg_send_serial(out_msg_buf
);
1151 if (expect_msg(READ_ACK
,in_msg_buf
,1)) {
1152 for (i
=0 ; i
<in_msg_buf
->read_ack_msg
.byte_count
; i
++)
1153 myaddr
[i
+nread
] = in_msg_buf
->read_ack_msg
.data
[i
];
1154 nread
+= in_msg_buf
->read_ack_msg
.byte_count
;
1162 /* FIXME! Merge these two. */
1164 mm_xfer_inferior_memory (memaddr
, myaddr
, len
, write
)
1171 memaddr
= translate_addr(memaddr
);
1174 return mm_write_inferior_memory (memaddr
, myaddr
, len
);
1176 return mm_read_inferior_memory (memaddr
, myaddr
, len
);
1180 /********************************************************** MSG_SEND_SERIAL
1181 ** This function is used to send a message over the
1184 ** If the message is successfully sent, a zero is
1185 ** returned. If the message was not sendable, a -1
1186 ** is returned. This function blocks. That is, it
1187 ** does not return until the message is completely
1188 ** sent, or until an error is encountered.
1193 msg_send_serial(msg_ptr
)
1194 union msg_t
*msg_ptr
;
1201 /* Send message header */
1203 message_size
= msg_ptr
->generic_msg
.length
+ (2 * sizeof(INT32
));
1205 c
= *((char *)msg_ptr
+byte_count
);
1206 result
= write(mm_desc
, &c
, 1);
1208 byte_count
= byte_count
+ 1;
1210 } while ((byte_count
< message_size
) );
1213 } /* end msg_send_serial() */
1215 /********************************************************** MSG_RECV_SERIAL
1216 ** This function is used to receive a message over a
1219 ** If the message is waiting in the buffer, a zero is
1220 ** returned and the buffer pointed to by msg_ptr is filled
1221 ** in. If no message was available, a -1 is returned.
1222 ** If timeout==0, wait indefinetly for a character.
1227 msg_recv_serial(msg_ptr
)
1228 union msg_t
*msg_ptr
;
1230 static INT32 length
=0;
1231 static INT32 byte_count
=0;
1234 if(msg_ptr
== 0) /* re-sync request */
1238 /* The timeout here is the prevailing timeout set with VTIME */
1239 ->"timeout==0 semantics not supported"
1240 read(mm_desc
, in_buf
, BUFER_SIZE
);
1243 read(mm_desc
, in_buf
, BUFER_SIZE
);
1248 /* Receive message */
1250 /* Timeout==0, help support the mm_wait() routine */
1251 ->"timeout==0 semantics not supported (and its nice if they are)"
1252 result
= read(mm_desc
, &c
, 1);
1255 result
= read(mm_desc
, &c
, 1);
1259 if (errno
== EINTR
) {
1260 error ("Timeout reading from remote system.");
1262 perror_with_name ("remote");
1263 } else if (result
== 1) {
1264 *((char *)msg_ptr
+byte_count
) = c
;
1265 byte_count
= byte_count
+ 1;
1268 /* Message header received. Save message length. */
1269 if (byte_count
== (2 * sizeof(INT32
)))
1270 length
= msg_ptr
->generic_msg
.length
;
1272 if (byte_count
>= (length
+ (2 * sizeof(INT32
)))) {
1273 /* Message received */
1279 } /* end msg_recv_serial() */
1281 /********************************************************************* KBD_RAW
1282 ** This function is used to put the keyboard in "raw"
1283 ** mode for BSD Unix. The original status is saved
1284 ** so that it may be restored later.
1293 /* Get keyboard termio (to save to restore original modes) */
1295 result
= ioctl(0, TCGETA
, &kbd_tbuf
);
1297 result
= ioctl(0, TIOCGETP
, &kbd_tbuf
);
1302 /* Get keyboard TERMINAL (for modification) */
1304 result
= ioctl(0, TCGETA
, &tbuf
);
1306 result
= ioctl(0, TIOCGETP
, &tbuf
);
1311 /* Set up new parameters */
1313 tbuf
.c_iflag
= tbuf
.c_iflag
&
1314 ~(INLCR
| ICRNL
| IUCLC
| ISTRIP
| IXON
| BRKINT
);
1315 tbuf
.c_lflag
= tbuf
.c_lflag
& ~(ICANON
| ISIG
| ECHO
);
1316 tbuf
.c_cc
[4] = 0; /* MIN */
1317 tbuf
.c_cc
[5] = 0; /* TIME */
1319 /* FIXME: not sure if this is correct (matches HAVE_TERMIO). */
1320 tbuf
.sg_flags
|= RAW
;
1321 tbuf
.sg_flags
|= ANYP
;
1322 tbuf
.sg_flags
&= ~ECHO
;
1325 /* Set keyboard termio to new mode (RAW) */
1327 result
= ioctl(0, TCSETAF
, &tbuf
);
1329 result
= ioctl(0, TIOCSETP
, &tbuf
);
1335 } /* end kbd_raw() */
1339 /***************************************************************** KBD_RESTORE
1340 ** This function is used to put the keyboard back in the
1341 ** mode it was in before kbk_raw was called. Note that
1342 ** kbk_raw() must have been called at least once before
1343 ** kbd_restore() is called.
1350 /* Set keyboard termio to original mode */
1352 result
= ioctl(0, TCSETAF
, &kbd_tbuf
);
1354 result
= ioctl(0, TIOCGETP
, &kbd_tbuf
);
1361 } /* end kbd_cooked() */
1364 /*****************************************************************************/
1365 /* Fetch a single register indicatated by 'regno'.
1366 * Returns 0/-1 on success/failure.
1369 fetch_register (regno
)
1373 DENTER("mm_fetch_register()");
1374 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1375 out_msg_buf
->read_req_msg
.length
= 4*3;
1376 out_msg_buf
->read_req_msg
.byte_count
= 4;
1378 if (regno
== GR1_REGNUM
)
1379 { out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1380 out_msg_buf
->read_req_msg
.address
= 1;
1382 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1383 { out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1384 out_msg_buf
->read_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1386 #if defined(GR64_REGNUM)
1387 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32 )
1388 { out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1389 out_msg_buf
->read_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1391 #endif /* GR64_REGNUM */
1392 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1393 { out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
1394 out_msg_buf
->read_req_msg
.address
= (regno
- LR0_REGNUM
);
1396 else if (regno
>=FPE_REGNUM
&& regno
<=EXO_REGNUM
)
1398 supply_register(160 + (regno
- FPE_REGNUM
),&val
);
1399 return 0; /* Pretend Success */
1402 { out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
1403 out_msg_buf
->read_req_msg
.address
= regnum_to_srnum(regno
);
1406 msg_send_serial(out_msg_buf
);
1408 if (expect_msg(READ_ACK
,in_msg_buf
,1)) {
1409 supply_register (regno
, &(in_msg_buf
->read_r_ack_msg
.data
[0]));
1414 DEXIT("mm_fetch_register()");
1417 /*****************************************************************************/
1418 /* Store a single register indicated by 'regno'.
1419 * Returns 0/-1 on success/failure.
1422 store_register (regno
)
1427 DENTER("store_register()");
1428 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1429 out_msg_buf
->write_req_msg
.length
= 4*4;
1430 out_msg_buf
->write_req_msg
.byte_count
= 4;
1431 out_msg_buf
->write_r_msg
.data
[0] = read_register (regno
);
1433 if (regno
== GR1_REGNUM
)
1434 { out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1435 out_msg_buf
->write_req_msg
.address
= 1;
1436 /* Setting GR1 changes the numbers of all the locals, so invalidate the
1437 * register cache. Do this *after* calling read_register, because we want
1438 * read_register to return the value that write_register has just stuffed
1439 * into the registers array, not the value of the register fetched from
1442 registers_changed ();
1444 #if defined(GR64_REGNUM)
1445 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32 )
1446 { out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1447 out_msg_buf
->write_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1449 #endif /* GR64_REGNUM */
1450 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1451 { out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1452 out_msg_buf
->write_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1454 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1455 { out_msg_buf
->write_req_msg
.memory_space
= LOCAL_REG
;
1456 out_msg_buf
->write_req_msg
.address
= (regno
- LR0_REGNUM
);
1458 else if (regno
>=FPE_REGNUM
&& regno
<=EXO_REGNUM
)
1460 return 0; /* Pretend Success */
1462 else /* An unprotected or protected special register */
1463 { out_msg_buf
->write_req_msg
.memory_space
= SPECIAL_REG
;
1464 out_msg_buf
->write_req_msg
.address
= regnum_to_srnum(regno
);
1467 msg_send_serial(out_msg_buf
);
1469 if (expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
1474 DEXIT("store_register()");
1477 /****************************************************************************/
1479 * Convert a gdb special register number to a 29000 special register number.
1482 regnum_to_srnum(regno
)
1486 case VAB_REGNUM
: return(0);
1487 case OPS_REGNUM
: return(1);
1488 case CPS_REGNUM
: return(2);
1489 case CFG_REGNUM
: return(3);
1490 case CHA_REGNUM
: return(4);
1491 case CHD_REGNUM
: return(5);
1492 case CHC_REGNUM
: return(6);
1493 case RBP_REGNUM
: return(7);
1494 case TMC_REGNUM
: return(8);
1495 case TMR_REGNUM
: return(9);
1496 case NPC_REGNUM
: return(USE_SHADOW_PC
? (20) : (10));
1497 case PC_REGNUM
: return(USE_SHADOW_PC
? (21) : (11));
1498 case PC2_REGNUM
: return(USE_SHADOW_PC
? (22) : (12));
1499 case MMU_REGNUM
: return(13);
1500 case LRU_REGNUM
: return(14);
1501 case IPC_REGNUM
: return(128);
1502 case IPA_REGNUM
: return(129);
1503 case IPB_REGNUM
: return(130);
1504 case Q_REGNUM
: return(131);
1505 case ALU_REGNUM
: return(132);
1506 case BP_REGNUM
: return(133);
1507 case FC_REGNUM
: return(134);
1508 case CR_REGNUM
: return(135);
1509 case FPE_REGNUM
: return(160);
1510 case INT_REGNUM
: return(161);
1511 case FPS_REGNUM
: return(162);
1512 case EXO_REGNUM
:return(164);
1514 return(255); /* Failure ? */
1517 /****************************************************************************/
1519 * Initialize the target debugger (minimon only).
1522 init_target_mm(tstart
,tend
,dstart
,dend
,entry
,ms_size
,rs_size
,arg_start
)
1523 ADDR32 tstart
,tend
,dstart
,dend
,entry
;
1524 INT32 ms_size
,rs_size
;
1527 out_msg_buf
->init_msg
.code
= INIT
;
1528 out_msg_buf
->init_msg
.length
= sizeof(struct init_msg_t
)-2*sizeof(INT32
);
1529 out_msg_buf
->init_msg
.text_start
= tstart
;
1530 out_msg_buf
->init_msg
.text_end
= tend
;
1531 out_msg_buf
->init_msg
.data_start
= dstart
;
1532 out_msg_buf
->init_msg
.data_end
= dend
;
1533 out_msg_buf
->init_msg
.entry_point
= entry
;
1534 out_msg_buf
->init_msg
.mem_stack_size
= ms_size
;
1535 out_msg_buf
->init_msg
.reg_stack_size
= rs_size
;
1536 out_msg_buf
->init_msg
.arg_start
= arg_start
;
1537 msg_send_serial(out_msg_buf
);
1538 expect_msg(INIT_ACK
,in_msg_buf
,1);
1540 /****************************************************************************/
1542 * Return a pointer to a string representing the given message code.
1543 * Not all messages are represented here, only the ones that we expect
1544 * to be called with.
1550 static char cbuf
[32];
1553 case BKPT_SET_ACK
: sprintf(cbuf
,"%s (%d)","BKPT_SET_ACK",code
); break;
1554 case BKPT_RM_ACK
: sprintf(cbuf
,"%s (%d)","BKPT_RM_ACK",code
); break;
1555 case INIT_ACK
: sprintf(cbuf
,"%s (%d)","INIT_ACK",code
); break;
1556 case READ_ACK
: sprintf(cbuf
,"%s (%d)","READ_ACK",code
); break;
1557 case WRITE_ACK
: sprintf(cbuf
,"%s (%d)","WRITE_ACK",code
); break;
1558 case ERROR
: sprintf(cbuf
,"%s (%d)","ERROR",code
); break;
1559 case HALT
: sprintf(cbuf
,"%s (%d)","HALT",code
); break;
1560 default: sprintf(cbuf
,"UNKNOWN (%d)",code
); break;
1564 /****************************************************************************/
1566 * Selected (not all of them) error codes that we might get.
1572 static char cbuf
[50];
1575 case EMFAIL
: return("EMFAIL: unrecoverable error");
1576 case EMBADADDR
: return("EMBADADDR: Illegal address");
1577 case EMBADREG
: return("EMBADREG: Illegal register ");
1578 case EMACCESS
: return("EMACCESS: Could not access memory");
1579 case EMBADMSG
: return("EMBADMSG: Unknown message type");
1580 case EMMSG2BIG
: return("EMMSG2BIG: Message to large");
1581 case EMNOSEND
: return("EMNOSEND: Could not send message");
1582 case EMNORECV
: return("EMNORECV: Could not recv message");
1583 case EMRESET
: return("EMRESET: Could not RESET target");
1584 case EMCONFIG
: return("EMCONFIG: Could not get target CONFIG");
1585 case EMSTATUS
: return("EMSTATUS: Could not get target STATUS");
1586 case EMREAD
: return("EMREAD: Could not READ target memory");
1587 case EMWRITE
: return("EMWRITE: Could not WRITE target memory");
1588 case EMBKPTSET
: return("EMBKPTSET: Could not set breakpoint");
1589 case EMBKPTRM
: return("EMBKPTRM: Could not remove breakpoint");
1590 case EMBKPTSTAT
:return("EMBKPTSTAT: Could not get breakpoint status");
1591 case EMBKPTNONE
:return("EMBKPTNONE: All breakpoints in use");
1592 case EMBKPTUSED
:return("EMBKPTUSED: Breakpoints already in use");
1593 case EMINIT
: return("EMINIT: Could not init target memory");
1594 case EMGO
: return("EMGO: Could not start execution");
1595 case EMSTEP
: return("EMSTEP: Could not single step");
1596 case EMBREAK
: return("EMBREAK: Could not BREAK");
1597 case EMCOMMERR
: return("EMCOMMERR: Communication error");
1598 default: sprintf(cbuf
,"error number %d",code
); break;
1603 /****************************************************************************/
1605 * Receive a message and expect it to be of type msgcode.
1606 * Returns 0/1 on failure/success.
1609 expect_msg(msgcode
,msg_buf
,from_tty
)
1610 INT32 msgcode
; /* Msg code we expect */
1611 union msg_t
*msg_buf
; /* Where to put the message received */
1612 int from_tty
; /* Print message on error if non-zero */
1614 /* DENTER("expect_msg()"); */
1616 while(msg_recv_serial(msg_buf
) && (retries
++<MAX_RETRIES
));
1617 if (retries
>= MAX_RETRIES
) {
1618 printf("Expected msg %s, ",msg_str(msgcode
));
1619 printf("no message received!\n");
1620 /* DEXIT("expect_msg() failure"); */
1621 return(0); /* Failure */
1624 if (msg_buf
->generic_msg
.code
!= msgcode
) {
1626 printf("Expected msg %s, ",msg_str(msgcode
));
1627 printf("got msg %s\n",msg_str(msg_buf
->generic_msg
.code
));
1628 if (msg_buf
->generic_msg
.code
== ERROR
)
1629 printf("%s\n",error_msg_str(msg_buf
->error_msg
.error_code
));
1631 /* DEXIT("expect_msg() failure"); */
1632 return(0); /* Failure */
1634 /* DEXIT("expect_msg() success"); */
1635 return(1); /* Success */
1637 /****************************************************************************/
1639 * Determine the MiniMon memory space qualifier based on the addr.
1640 * FIXME: Can't distinguis I_ROM/D_ROM.
1641 * FIXME: Doesn't know anything about I_CACHE/D_CACHE.
1644 mm_memory_space(addr
)
1647 ADDR32 tstart
= target_config
.I_mem_start
;
1648 ADDR32 tend
= tstart
+ target_config
.I_mem_size
;
1649 ADDR32 dstart
= target_config
.D_mem_start
;
1650 ADDR32 dend
= tstart
+ target_config
.D_mem_size
;
1651 ADDR32 rstart
= target_config
.ROM_start
;
1652 ADDR32 rend
= tstart
+ target_config
.ROM_size
;
1654 if (((ADDR32
)addr
>= tstart
) && ((ADDR32
)addr
< tend
)) {
1656 } else if (((ADDR32
)addr
>= dstart
) && ((ADDR32
)addr
< dend
)) {
1658 } else if (((ADDR32
)addr
>= rstart
) && ((ADDR32
)addr
< rend
)) {
1659 /* FIXME: how do we determine between D_ROM and I_ROM */
1661 } else /* FIXME: what do me do now? */
1662 return D_MEM
; /* Hmmm! */
1665 /****************************************************************************/
1667 * Define the target subroutine names
1669 struct target_ops mm_ops
= {
1670 "minimon", "Remote AMD/Minimon target",
1671 "Remote debug an AMD 290*0 using the MiniMon dbg core on the target",
1673 mm_attach
, mm_detach
, mm_resume
, mm_wait
,
1674 mm_fetch_registers
, mm_store_registers
,
1675 mm_prepare_to_store
, 0, 0, /* conv_to, conv_from */
1676 mm_xfer_inferior_memory
,
1678 mm_insert_breakpoint
, mm_remove_breakpoint
, /* Breakpoints */
1679 0, 0, 0, 0, 0, /* Terminal handling */
1680 mm_kill
, /* FIXME, kill */
1682 0, /* lookup_symbol */
1683 mm_create_inferior
, /* create_inferior */
1684 mm_mourn
, /* mourn_inferior FIXME */
1685 process_stratum
, 0, /* next */
1686 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1687 0,0, /* sections, sections_end */
1688 OPS_MAGIC
, /* Always the last thing */
1692 _initialize_remote_mm()
1694 add_target (&mm_ops
);
1697 #ifdef NO_HIF_SUPPORT
1701 return(0); /* Emulate a failure */