1 /* Remote debugging interface for Am290*0 running MiniMON monitor, for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000,
3 2001 Free Software Foundation, Inc.
4 Originally written by Daniel Mann at AMD.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* This is like remote.c but ecpects MiniMON to be running on the Am29000
25 - David Wood (wood@lab.ultra.nyu.edu) at New York University adapted this
26 file to gdb 3.95. I was unable to get this working on sun3os4
27 with termio, only with sgtty. Because we are only attempting to
28 use this module to debug our kernel, which is already loaded when
29 gdb is started up, I did not code up the file downloading facilities.
30 As a result this module has only the stubs to download files.
31 You should get tagged at compile time if you need to make any
41 #include "gdb_string.h"
47 /* Offset of member MEMBER in a struct of type TYPE. */
48 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
50 #define DRAIN_INPUT() (msg_recv_serial((union msg_t*)0))
52 extern int stop_soon_quietly
; /* for wait_for_inferior */
54 static void mm_resume ();
55 static void mm_fetch_registers ();
56 static int fetch_register ();
57 static void mm_store_registers ();
58 static int store_register ();
59 static int regnum_to_srnum ();
60 static void mm_close ();
61 static char *msg_str ();
62 static char *error_msg_str ();
63 static int expect_msg ();
64 static void init_target_mm ();
65 static int mm_memory_space ();
67 #define FREEZE_MODE (read_register(CPS_REGNUM) && 0x400)
68 #define USE_SHADOW_PC ((processor_type == a29k_freeze_mode) && FREEZE_MODE)
70 /* FIXME: Replace with `set remotedebug'. */
71 #define LLOG_FILE "minimon.log"
72 #if defined (LOG_FILE)
77 * Size of message buffers. I couldn't get memory reads to work when
78 * the byte_count was larger than 512 (it may be a baud rate problem).
80 #define BUFER_SIZE 512
82 * Size of data area in message buffer on the TARGET (remote system).
84 #define MAXDATA_T (target_config.max_msg_size - \
85 offsetof(struct write_r_msg_t,data[0]))
87 * Size of data area in message buffer on the HOST (gdb).
89 #define MAXDATA_H (BUFER_SIZE - offsetof(struct write_r_msg_t,data[0]))
91 * Defined as the minimum size of data areas of the two message buffers
93 #define MAXDATA (MAXDATA_H < MAXDATA_T ? MAXDATA_H : MAXDATA_T)
95 static char out_buf
[BUFER_SIZE
];
96 static char in_buf
[BUFER_SIZE
];
98 int msg_recv_serial ();
99 int msg_send_serial ();
101 #define MAX_RETRIES 5000
102 extern struct target_ops mm_ops
; /* Forward declaration */
103 struct config_msg_t target_config
; /* HIF needs this */
104 union msg_t
*out_msg_buf
= (union msg_t
*) out_buf
;
105 union msg_t
*in_msg_buf
= (union msg_t
*) in_buf
;
107 static int timeout
= 5;
109 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
110 mm_open knows that we don't have a file open when the program
114 /* stream which is fdopen'd from mm_desc. Only valid when
118 /* Called when SIGALRM signal sent due to alarm() timeout. */
127 volatile int n_alarms
;
134 printf ("mm_timer called\n");
138 #endif /* HAVE_TERMIO */
140 /* malloc'd name of the program on the remote system. */
141 static char *prog_name
= NULL
;
144 /* Number of SIGTRAPs we need to simulate. That is, the next
145 NEED_ARTIFICIAL_TRAP calls to mm_wait should just return
146 SIGTRAP without actually waiting for anything. */
148 /**************************************************** REMOTE_CREATE_INFERIOR */
149 /* This is called not only when we first attach, but also when the
150 user types "run" after having attached. */
152 mm_create_inferior (char *execfile
, char *args
, char **env
)
154 #define MAX_TOKENS 25
155 #define BUFFER_SIZE 256
158 char *token
[MAX_TOKENS
];
159 char cmd_line
[BUFFER_SIZE
];
162 error ("Can't pass arguments to remote mm process (yet).");
164 if (execfile
== 0 /* || exec_bfd == 0 */ )
165 error ("No executable file specified");
169 printf ("Minimon not open yet.\n");
173 /* On ultra3 (NYU) we assume the kernel is already running so there is
175 FIXME: Fixed required here -> load your program, possibly with mm_load().
177 printf_filtered ("\n\
178 Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n");
180 /* We will get a task spawn event immediately. */
181 init_wait_for_inferior ();
182 clear_proceed_status ();
183 stop_soon_quietly
= 1;
184 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
187 /**************************************************** REMOTE_MOURN_INFERIOR */
191 pop_target (); /* Pop back to no-child state */
192 generic_mourn_inferior ();
195 /********************************************************************** damn_b
197 /* Translate baud rates from integers to damn B_codes. Unix should
198 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
288 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
289 if (rate
== baudtab
[i
].rate
)
290 return baudtab
[i
].damn_b
;
291 return B38400
; /* Random */
295 /***************************************************************** REMOTE_OPEN
296 ** Open a connection to remote minimon.
297 NAME is the filename used for communication, then a space,
299 'target adapt /dev/ttya 9600 [prognam]' for example.
302 static char *dev_name
;
305 mm_open (char *name
, int from_tty
)
311 /* Find the first whitespace character, it separates dev_name from
314 p
&& *p
&& !isspace (*p
); p
++)
316 if (p
== 0 || *p
== '\0')
318 error ("Usage : <command> <serial-device> <baud-rate> [progname]");
319 dev_name
= (char *) xmalloc (p
- name
+ 1);
320 strncpy (dev_name
, name
, p
- name
);
321 dev_name
[p
- name
] = '\0';
323 /* Skip over the whitespace after dev_name */
324 for (; isspace (*p
); p
++)
327 if (1 != sscanf (p
, "%d ", &baudrate
))
330 /* Skip the number and then the spaces */
331 for (; isdigit (*p
); p
++)
333 for (; isspace (*p
); p
++)
336 if (prog_name
!= NULL
)
338 prog_name
= savestring (p
, strlen (p
));
344 mm_desc
= open (dev_name
, O_RDWR
);
346 perror_with_name (dev_name
);
347 ioctl (mm_desc
, TIOCGETP
, &sg
);
349 sg
.c_cc
[VMIN
] = 0; /* read with timeout. */
350 sg
.c_cc
[VTIME
] = timeout
* 10;
351 sg
.c_lflag
&= ~(ICANON
| ECHO
);
352 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | damn_b (baudrate
);
354 sg
.sg_ispeed
= damn_b (baudrate
);
355 sg
.sg_ospeed
= damn_b (baudrate
);
358 sg
.sg_flags
&= ~ECHO
;
362 ioctl (mm_desc
, TIOCSETP
, &sg
);
363 mm_stream
= fdopen (mm_desc
, "r+");
365 push_target (&mm_ops
);
368 #ifndef NO_SIGINTERRUPT
369 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
371 if (siginterrupt (SIGALRM
, 1) != 0)
372 perror ("mm_open: error in siginterrupt");
375 /* Set up read timeout timer. */
376 if ((void (*)) signal (SIGALRM
, mm_timer
) == (void (*)) -1)
377 perror ("mm_open: error in signal");
380 #if defined (LOG_FILE)
381 log_file
= fopen (LOG_FILE
, "w");
382 if (log_file
== NULL
)
383 perror_with_name (LOG_FILE
);
386 ** Initialize target configuration structure (global)
389 out_msg_buf
->config_req_msg
.code
= CONFIG_REQ
;
390 out_msg_buf
->config_req_msg
.length
= 4 * 0;
391 msg_send_serial (out_msg_buf
); /* send config request message */
393 expect_msg (CONFIG
, in_msg_buf
, 1);
395 a29k_get_processor_type ();
397 /* Print out some stuff, letting the user now what's going on */
398 printf_filtered ("Connected to MiniMon via %s.\n", dev_name
);
399 /* FIXME: can this restriction be removed? */
400 printf_filtered ("Remote debugging using virtual addresses works only\n");
401 printf_filtered ("\twhen virtual addresses map 1:1 to physical addresses.\n")
403 if (processor_type
!= a29k_freeze_mode
)
405 fprintf_filtered (gdb_stderr
,
406 "Freeze-mode debugging not available, and can only be done on an A29050.\n");
409 target_config
.code
= CONFIG
;
410 target_config
.length
= 0;
411 target_config
.processor_id
= in_msg_buf
->config_msg
.processor_id
;
412 target_config
.version
= in_msg_buf
->config_msg
.version
;
413 target_config
.I_mem_start
= in_msg_buf
->config_msg
.I_mem_start
;
414 target_config
.I_mem_size
= in_msg_buf
->config_msg
.I_mem_size
;
415 target_config
.D_mem_start
= in_msg_buf
->config_msg
.D_mem_start
;
416 target_config
.D_mem_size
= in_msg_buf
->config_msg
.D_mem_size
;
417 target_config
.ROM_start
= in_msg_buf
->config_msg
.ROM_start
;
418 target_config
.ROM_size
= in_msg_buf
->config_msg
.ROM_size
;
419 target_config
.max_msg_size
= in_msg_buf
->config_msg
.max_msg_size
;
420 target_config
.max_bkpts
= in_msg_buf
->config_msg
.max_bkpts
;
421 target_config
.coprocessor
= in_msg_buf
->config_msg
.coprocessor
;
422 target_config
.reserved
= in_msg_buf
->config_msg
.reserved
;
425 printf ("Connected to MiniMON :\n");
426 printf (" Debugcore version %d.%d\n",
427 0x0f & (target_config
.version
>> 4),
428 0x0f & (target_config
.version
));
429 printf (" Configuration version %d.%d\n",
430 0x0f & (target_config
.version
>> 12),
431 0x0f & (target_config
.version
>> 8));
432 printf (" Message system version %d.%d\n",
433 0x0f & (target_config
.version
>> 20),
434 0x0f & (target_config
.version
>> 16));
435 printf (" Communication driver version %d.%d\n",
436 0x0f & (target_config
.version
>> 28),
437 0x0f & (target_config
.version
>> 24));
440 /* Leave the target running...
441 * The above message stopped the target in the dbg core (MiniMon),
442 * so restart the target out of MiniMon,
444 out_msg_buf
->go_msg
.code
= GO
;
445 out_msg_buf
->go_msg
.length
= 0;
446 msg_send_serial (out_msg_buf
);
447 /* No message to expect after a GO */
450 /**************************************************************** REMOTE_CLOSE
451 ** Close the open connection to the minimon debugger.
452 Use this when you want to detach and do something else
455 mm_close ( /*FIXME: how is quitting used */
459 error ("Can't close remote connection: not debugging remotely.");
461 /* We should never get here if there isn't something valid in
462 mm_desc and mm_stream.
464 Due to a bug in Unix, fclose closes not only the stdio stream,
465 but also the file descriptor. So we don't actually close
469 /* close (mm_desc); */
471 /* Do not try to close mm_desc again, later in the program. */
475 #if defined (LOG_FILE)
476 if (ferror (log_file
))
477 printf ("Error writing log file.\n");
478 if (fclose (log_file
) != 0)
479 printf ("Error closing log file.\n");
482 printf ("Ending remote debugging\n");
485 /************************************************************* REMOTE_ATACH */
486 /* Attach to a program that is already loaded and running
487 * Upon exiting the process's execution is stopped.
490 mm_attach (char *args
, int from_tty
)
494 error ("MiniMon not opened yet, use the 'target minimon' command.\n");
497 printf ("Attaching to remote program %s...\n", prog_name
);
499 /* Make sure the target is currently running, it is supposed to be. */
500 /* FIXME: is it ok to send MiniMon a BREAK if it is already stopped in
501 * the dbg core. If so, we don't need to send this GO.
503 out_msg_buf
->go_msg
.code
= GO
;
504 out_msg_buf
->go_msg
.length
= 0;
505 msg_send_serial (out_msg_buf
);
506 sleep (2); /* At the worst it will stop, receive a message, continue */
508 /* Send the mm a break. */
509 out_msg_buf
->break_msg
.code
= BREAK
;
510 out_msg_buf
->break_msg
.length
= 0;
511 msg_send_serial (out_msg_buf
);
513 /********************************************************** REMOTE_DETACH */
514 /* Terminate the open connection to the remote debugger.
515 Use this when you want to detach and do something else
516 with your gdb. Leave remote process running (with no breakpoints set). */
518 mm_detach (char *args
, int from_tty
)
520 remove_breakpoints (); /* Just in case there were any left in */
521 out_msg_buf
->go_msg
.code
= GO
;
522 out_msg_buf
->go_msg
.length
= 0;
523 msg_send_serial (out_msg_buf
);
524 pop_target (); /* calls mm_close to do the real work */
528 /*************************************************************** REMOTE_RESUME
529 ** Tell the remote machine to resume. */
532 mm_resume (int pid
, int step
, enum target_signal sig
)
534 if (sig
!= TARGET_SIGNAL_0
)
535 warning ("Can't send signals to a remote MiniMon system.");
539 out_msg_buf
->step_msg
.code
= STEP
;
540 out_msg_buf
->step_msg
.length
= 1 * 4;
541 out_msg_buf
->step_msg
.count
= 1; /* step 1 instruction */
542 msg_send_serial (out_msg_buf
);
546 out_msg_buf
->go_msg
.code
= GO
;
547 out_msg_buf
->go_msg
.length
= 0;
548 msg_send_serial (out_msg_buf
);
552 /***************************************************************** REMOTE_WAIT
553 ** Wait until the remote machine stops, then return,
554 storing status in STATUS just as `wait' would. */
557 mm_wait (struct target_waitstatus
*status
)
560 int old_timeout
= timeout
;
561 int old_immediate_quit
= immediate_quit
;
563 status
->kind
= TARGET_WAITKIND_EXITED
;
564 status
->value
.integer
= 0;
566 /* wait for message to arrive. It should be:
567 - A HIF service request.
568 - A HIF exit service request.
570 - A CHANNEL1 request.
571 - a debugcore HALT message.
572 HIF services must be responded too, and while-looping continued.
573 If the target stops executing, mm_wait() should return.
575 timeout
= 0; /* Wait indefinetly for a message */
576 immediate_quit
= 1; /* Helps ability to QUIT */
579 while (msg_recv_serial (in_msg_buf
))
581 QUIT
; /* Let user quit if they want */
583 switch (in_msg_buf
->halt_msg
.code
)
586 i
= in_msg_buf
->hif_call_rtn_msg
.service_number
;
587 result
= service_HIF (in_msg_buf
);
588 if (i
== 1) /* EXIT */
591 printf ("Warning: failure during HIF service %d\n", i
);
594 service_HIF (in_msg_buf
);
597 i
= in_msg_buf
->channel1_msg
.length
;
598 in_msg_buf
->channel1_msg
.data
[i
] = '\0';
599 printf ("%s", in_msg_buf
->channel1_msg
.data
);
600 gdb_flush (gdb_stdout
);
601 /* Send CHANNEL1_ACK message */
602 out_msg_buf
->channel1_ack_msg
.code
= CHANNEL1_ACK
;
603 out_msg_buf
->channel1_ack_msg
.length
= 0;
604 result
= msg_send_serial (out_msg_buf
);
613 /* FIXME, these printfs should not be here. This is a source level
615 if (in_msg_buf
->halt_msg
.trap_number
== 0)
617 printf ("Am290*0 received vector number %d (break point)\n",
618 in_msg_buf
->halt_msg
.trap_number
);
619 status
->kind
= TARGET_WAITKIND_STOPPED
;
620 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
622 else if (in_msg_buf
->halt_msg
.trap_number
== 1)
624 printf ("Am290*0 received vector number %d\n",
625 in_msg_buf
->halt_msg
.trap_number
);
626 status
->kind
= TARGET_WAITKIND_STOPPED
;
627 status
->value
.sig
= TARGET_SIGNAL_BUS
;
629 else if (in_msg_buf
->halt_msg
.trap_number
== 3
630 || in_msg_buf
->halt_msg
.trap_number
== 4)
632 printf ("Am290*0 received vector number %d\n",
633 in_msg_buf
->halt_msg
.trap_number
);
634 status
->kind
= TARGET_WAITKIND_STOPPED
;
635 status
->value
.sig
= TARGET_SIGNAL_FPE
;
637 else if (in_msg_buf
->halt_msg
.trap_number
== 5)
639 printf ("Am290*0 received vector number %d\n",
640 in_msg_buf
->halt_msg
.trap_number
);
641 status
->kind
= TARGET_WAITKIND_STOPPED
;
642 status
->value
.sig
= TARGET_SIGNAL_ILL
;
644 else if (in_msg_buf
->halt_msg
.trap_number
>= 6
645 && in_msg_buf
->halt_msg
.trap_number
<= 11)
647 printf ("Am290*0 received vector number %d\n",
648 in_msg_buf
->halt_msg
.trap_number
);
649 status
->kind
= TARGET_WAITKIND_STOPPED
;
650 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
652 else if (in_msg_buf
->halt_msg
.trap_number
== 12
653 || in_msg_buf
->halt_msg
.trap_number
== 13)
655 printf ("Am290*0 received vector number %d\n",
656 in_msg_buf
->halt_msg
.trap_number
);
657 status
->kind
= TARGET_WAITKIND_STOPPED
;
658 status
->value
.sig
= TARGET_SIGNAL_ILL
;
660 else if (in_msg_buf
->halt_msg
.trap_number
== 14)
662 printf ("Am290*0 received vector number %d\n",
663 in_msg_buf
->halt_msg
.trap_number
);
664 status
->kind
= TARGET_WAITKIND_STOPPED
;
665 status
->value
.sig
= TARGET_SIGNAL_ALRM
;
667 else if (in_msg_buf
->halt_msg
.trap_number
== 15)
669 status
->kind
= TARGET_WAITKIND_STOPPED
;
670 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
672 else if (in_msg_buf
->halt_msg
.trap_number
>= 16
673 && 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 status
->kind
= TARGET_WAITKIND_STOPPED
;
678 status
->value
.sig
= TARGET_SIGNAL_INT
;
680 else if (in_msg_buf
->halt_msg
.trap_number
== 22)
682 printf ("Am290*0 received vector number %d\n",
683 in_msg_buf
->halt_msg
.trap_number
);
684 status
->kind
= TARGET_WAITKIND_STOPPED
;
685 status
->value
.sig
= TARGET_SIGNAL_ILL
;
686 } /* BREAK message was sent */
687 else if (in_msg_buf
->halt_msg
.trap_number
== 75)
689 status
->kind
= TARGET_WAITKIND_STOPPED
;
690 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
695 status
->kind
= TARGET_WAITKIND_EXITED
;
696 status
->value
.integer
= 0;
699 timeout
= old_timeout
; /* Restore original timeout value */
700 immediate_quit
= old_immediate_quit
;
704 /******************************************************* REMOTE_FETCH_REGISTERS
705 * Read a remote register 'regno'.
706 * If regno==-1 then read all the registers.
709 mm_fetch_registers (int regno
)
715 fetch_register (regno
);
720 out_msg_buf
->read_req_msg
.byte_count
= 4 * 1;
721 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
722 out_msg_buf
->read_req_msg
.address
= 1;
723 msg_send_serial (out_msg_buf
);
724 expect_msg (READ_ACK
, in_msg_buf
, 1);
725 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
726 supply_register (GR1_REGNUM
, data_p
);
728 #if defined(GR64_REGNUM) /* Read gr64-127 */
729 /* Global Registers gr64-gr95 */
730 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
731 out_msg_buf
->read_req_msg
.length
= 4 * 3;
732 out_msg_buf
->read_req_msg
.byte_count
= 4 * 32;
733 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
734 out_msg_buf
->read_req_msg
.address
= 64;
735 msg_send_serial (out_msg_buf
);
736 expect_msg (READ_ACK
, in_msg_buf
, 1);
737 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
739 for (regno
= GR64_REGNUM
; regno
< GR64_REGNUM
+ 32; regno
++)
741 supply_register (regno
, data_p
++);
743 #endif /* GR64_REGNUM */
745 /* Global Registers gr96-gr127 */
746 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
747 out_msg_buf
->read_req_msg
.length
= 4 * 3;
748 out_msg_buf
->read_req_msg
.byte_count
= 4 * 32;
749 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
750 out_msg_buf
->read_req_msg
.address
= 96;
751 msg_send_serial (out_msg_buf
);
752 expect_msg (READ_ACK
, in_msg_buf
, 1);
753 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
755 for (regno
= GR96_REGNUM
; regno
< GR96_REGNUM
+ 32; regno
++)
757 supply_register (regno
, data_p
++);
760 /* Local Registers */
761 out_msg_buf
->read_req_msg
.byte_count
= 4 * (128);
762 out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
763 out_msg_buf
->read_req_msg
.address
= 0;
764 msg_send_serial (out_msg_buf
);
765 expect_msg (READ_ACK
, in_msg_buf
, 1);
766 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
768 for (regno
= LR0_REGNUM
; regno
< LR0_REGNUM
+ 128; regno
++)
770 supply_register (regno
, data_p
++);
773 /* Protected Special Registers */
774 out_msg_buf
->read_req_msg
.byte_count
= 4 * 15;
775 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
776 out_msg_buf
->read_req_msg
.address
= 0;
777 msg_send_serial (out_msg_buf
);
778 expect_msg (READ_ACK
, in_msg_buf
, 1);
779 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
781 for (regno
= 0; regno
<= 14; regno
++)
783 supply_register (SR_REGNUM (regno
), data_p
++);
786 { /* Let regno_to_srnum() handle the register number */
787 fetch_register (NPC_REGNUM
);
788 fetch_register (PC_REGNUM
);
789 fetch_register (PC2_REGNUM
);
792 /* Unprotected Special Registers */
793 out_msg_buf
->read_req_msg
.byte_count
= 4 * 8;
794 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
795 out_msg_buf
->read_req_msg
.address
= 128;
796 msg_send_serial (out_msg_buf
);
797 expect_msg (READ_ACK
, in_msg_buf
, 1);
798 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
800 for (regno
= 128; regno
<= 135; regno
++)
802 supply_register (SR_REGNUM (regno
), data_p
++);
805 /* There doesn't seem to be any way to get these. */
808 supply_register (FPE_REGNUM
, &val
);
809 supply_register (INTE_REGNUM
, &val
);
810 supply_register (FPS_REGNUM
, &val
);
811 supply_register (EXO_REGNUM
, &val
);
816 /****************************************************** REMOTE_STORE_REGISTERS
817 * Store register regno into the target.
818 * If regno==-1 then store all the registers.
819 * Result is 0 for success, -1 for failure.
823 mm_store_registers (int regno
)
829 store_register (regno
);
835 out_msg_buf
->write_r_msg
.code
= WRITE_REQ
;
838 out_msg_buf
->write_r_msg
.byte_count
= 4 * 1;
839 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
840 out_msg_buf
->write_r_msg
.memory_space
= GLOBAL_REG
;
841 out_msg_buf
->write_r_msg
.address
= 1;
842 out_msg_buf
->write_r_msg
.data
[0] = read_register (GR1_REGNUM
);
844 msg_send_serial (out_msg_buf
);
845 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
850 #if defined(GR64_REGNUM)
851 /* Global registers gr64-gr95 */
852 out_msg_buf
->write_r_msg
.byte_count
= 4 * (32);
853 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
854 out_msg_buf
->write_r_msg
.address
= 64;
856 for (regno
= GR64_REGNUM
; regno
< GR64_REGNUM
+ 32; regno
++)
858 out_msg_buf
->write_r_msg
.data
[regno
- GR64_REGNUM
] = read_register (regno
);
860 msg_send_serial (out_msg_buf
);
861 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
865 #endif /* GR64_REGNUM */
867 /* Global registers gr96-gr127 */
868 out_msg_buf
->write_r_msg
.byte_count
= 4 * (32);
869 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
870 out_msg_buf
->write_r_msg
.address
= 96;
871 for (regno
= GR96_REGNUM
; regno
< GR96_REGNUM
+ 32; regno
++)
873 out_msg_buf
->write_r_msg
.data
[regno
- GR96_REGNUM
] = read_register (regno
);
875 msg_send_serial (out_msg_buf
);
876 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
881 /* Local Registers */
882 out_msg_buf
->write_r_msg
.memory_space
= LOCAL_REG
;
883 out_msg_buf
->write_r_msg
.byte_count
= 4 * 128;
884 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
885 out_msg_buf
->write_r_msg
.address
= 0;
887 for (regno
= LR0_REGNUM
; regno
< LR0_REGNUM
+ 128; regno
++)
889 out_msg_buf
->write_r_msg
.data
[regno
- LR0_REGNUM
] = read_register (regno
);
891 msg_send_serial (out_msg_buf
);
892 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
897 /* Protected Special Registers */
898 /* VAB through TMR */
899 out_msg_buf
->write_r_msg
.memory_space
= SPECIAL_REG
;
900 out_msg_buf
->write_r_msg
.byte_count
= 4 * 10;
901 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
902 out_msg_buf
->write_r_msg
.address
= 0;
903 for (regno
= 0; regno
<= 9; regno
++) /* VAB through TMR */
904 out_msg_buf
->write_r_msg
.data
[regno
] = read_register (SR_REGNUM (regno
));
905 msg_send_serial (out_msg_buf
);
906 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
911 /* PC0, PC1, PC2 possibly as shadow registers */
912 out_msg_buf
->write_r_msg
.byte_count
= 4 * 3;
913 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
914 for (regno
= 10; regno
<= 12; regno
++) /* LRU and MMU */
915 out_msg_buf
->write_r_msg
.data
[regno
- 10] = read_register (SR_REGNUM (regno
));
917 out_msg_buf
->write_r_msg
.address
= 20; /* SPC0 */
919 out_msg_buf
->write_r_msg
.address
= 10; /* PC0 */
920 msg_send_serial (out_msg_buf
);
921 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
927 out_msg_buf
->write_r_msg
.byte_count
= 4 * 2;
928 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
929 out_msg_buf
->write_r_msg
.address
= 13;
930 for (regno
= 13; regno
<= 14; regno
++) /* LRU and MMU */
931 out_msg_buf
->write_r_msg
.data
[regno
- 13] = read_register (SR_REGNUM (regno
));
932 msg_send_serial (out_msg_buf
);
933 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
938 /* Unprotected Special Registers */
939 out_msg_buf
->write_r_msg
.byte_count
= 4 * 8;
940 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
941 out_msg_buf
->write_r_msg
.address
= 128;
942 for (regno
= 128; regno
<= 135; regno
++)
943 out_msg_buf
->write_r_msg
.data
[regno
- 128] = read_register (SR_REGNUM (regno
));
944 msg_send_serial (out_msg_buf
);
945 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
950 registers_changed ();
953 /*************************************************** REMOTE_PREPARE_TO_STORE */
954 /* Get ready to modify the registers array. On machines which store
955 individual registers, this doesn't need to do anything. On machines
956 which store all the registers in one fell swoop, this makes sure
957 that registers contains all the registers from the program being
961 mm_prepare_to_store (void)
963 /* Do nothing, since we can store individual regs */
966 /******************************************************* REMOTE_XFER_MEMORY */
968 translate_addr (CORE_ADDR addr
)
970 #if defined(KERNEL_DEBUGGING)
971 /* Check for a virtual address in the kernel */
972 /* Assume physical address of ublock is in paddr_u register */
973 /* FIXME: doesn't work for user virtual addresses */
976 /* PADDR_U register holds the physical address of the ublock */
977 CORE_ADDR i
= (CORE_ADDR
) read_register (PADDR_U_REGNUM
);
978 return (i
+ addr
- (CORE_ADDR
) UVADDR
);
989 /******************************************************* REMOTE_FILES_INFO */
993 printf ("\tAttached to %s at %d baud and running program %s.\n",
994 dev_name
, baudrate
, prog_name
);
997 /************************************************* REMOTE_INSERT_BREAKPOINT */
999 mm_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
1001 out_msg_buf
->bkpt_set_msg
.code
= BKPT_SET
;
1002 out_msg_buf
->bkpt_set_msg
.length
= 4 * 4;
1003 out_msg_buf
->bkpt_set_msg
.memory_space
= I_MEM
;
1004 out_msg_buf
->bkpt_set_msg
.bkpt_addr
= (ADDR32
) addr
;
1005 out_msg_buf
->bkpt_set_msg
.pass_count
= 1;
1006 out_msg_buf
->bkpt_set_msg
.bkpt_type
= -1; /* use illop for 29000 */
1007 msg_send_serial (out_msg_buf
);
1008 if (expect_msg (BKPT_SET_ACK
, in_msg_buf
, 1))
1010 return 0; /* Success */
1014 return 1; /* Failure */
1018 /************************************************* REMOTE_DELETE_BREAKPOINT */
1020 mm_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
1022 out_msg_buf
->bkpt_rm_msg
.code
= BKPT_RM
;
1023 out_msg_buf
->bkpt_rm_msg
.length
= 4 * 3;
1024 out_msg_buf
->bkpt_rm_msg
.memory_space
= I_MEM
;
1025 out_msg_buf
->bkpt_rm_msg
.bkpt_addr
= (ADDR32
) addr
;
1026 msg_send_serial (out_msg_buf
);
1027 if (expect_msg (BKPT_RM_ACK
, in_msg_buf
, 1))
1029 return 0; /* Success */
1033 return 1; /* Failure */
1038 /******************************************************* REMOTE_KILL */
1040 mm_kill (char *arg
, int from_tty
)
1044 #if defined(KERNEL_DEBUGGING)
1045 /* We don't ever kill the kernel */
1048 printf ("Kernel not killed, but left in current state.\n");
1049 printf ("Use detach to leave kernel running.\n");
1052 out_msg_buf
->break_msg
.code
= BREAK
;
1053 out_msg_buf
->bkpt_set_msg
.length
= 4 * 0;
1054 expect_msg (HALT
, in_msg_buf
, from_tty
);
1057 printf ("Target has been stopped.");
1058 printf ("Would you like to do a hardware reset (y/n) [n] ");
1059 fgets (buf
, 3, stdin
);
1062 out_msg_buf
->reset_msg
.code
= RESET
;
1063 out_msg_buf
->bkpt_set_msg
.length
= 4 * 0;
1064 expect_msg (RESET_ACK
, in_msg_buf
, from_tty
);
1065 printf ("Target has been reset.");
1074 /***************************************************************************/
1076 * Load a program into the target.
1079 mm_load (char *arg_string
, int from_tty
)
1083 #if defined(KERNEL_DEBUGGING)
1084 printf ("The kernel had better be loaded already! Loading not done.\n");
1086 if (arg_string
== 0)
1087 error ("The load command takes a file name");
1089 arg_string
= tilde_expand (arg_string
);
1090 make_cleanup (xfree
, arg_string
);
1093 error ("File loading is not yet supported for MiniMon.");
1094 /* FIXME, code to load your file here... */
1095 /* You may need to do an init_target_mm() */
1096 /* init_target_mm(?,?,?,?,?,?,?,?); */
1098 /* symbol_file_add (arg_string, from_tty, text_addr, 0, 0); */
1103 /************************************************ REMOTE_WRITE_INFERIOR_MEMORY
1104 ** Copy LEN bytes of data from debugger memory at MYADDR
1105 to inferior's memory at MEMADDR. Returns number of bytes written. */
1107 mm_write_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
1111 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1112 out_msg_buf
->write_req_msg
.memory_space
= mm_memory_space (memaddr
);
1115 while (nwritten
< len
)
1117 int num_to_write
= len
- nwritten
;
1118 if (num_to_write
> MAXDATA
)
1119 num_to_write
= MAXDATA
;
1120 for (i
= 0; i
< num_to_write
; i
++)
1121 out_msg_buf
->write_req_msg
.data
[i
] = myaddr
[i
+ nwritten
];
1122 out_msg_buf
->write_req_msg
.byte_count
= num_to_write
;
1123 out_msg_buf
->write_req_msg
.length
= 3 * 4 + num_to_write
;
1124 out_msg_buf
->write_req_msg
.address
= memaddr
+ nwritten
;
1125 msg_send_serial (out_msg_buf
);
1127 if (expect_msg (WRITE_ACK
, in_msg_buf
, 1))
1129 nwritten
+= in_msg_buf
->write_ack_msg
.byte_count
;
1139 /************************************************* REMOTE_READ_INFERIOR_MEMORY
1140 ** Read LEN bytes from inferior memory at MEMADDR. Put the result
1141 at debugger address MYADDR. Returns number of bytes read. */
1143 mm_read_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
1147 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1148 out_msg_buf
->read_req_msg
.memory_space
= mm_memory_space (memaddr
);
1153 int num_to_read
= (len
- nread
);
1154 if (num_to_read
> MAXDATA
)
1155 num_to_read
= MAXDATA
;
1156 out_msg_buf
->read_req_msg
.byte_count
= num_to_read
;
1157 out_msg_buf
->read_req_msg
.length
= 3 * 4 + num_to_read
;
1158 out_msg_buf
->read_req_msg
.address
= memaddr
+ nread
;
1159 msg_send_serial (out_msg_buf
);
1161 if (expect_msg (READ_ACK
, in_msg_buf
, 1))
1163 for (i
= 0; i
< in_msg_buf
->read_ack_msg
.byte_count
; i
++)
1164 myaddr
[i
+ nread
] = in_msg_buf
->read_ack_msg
.data
[i
];
1165 nread
+= in_msg_buf
->read_ack_msg
.byte_count
;
1175 /* FIXME! Merge these two. */
1177 mm_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1178 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
1179 struct target_ops
*target ATTRIBUTE_UNUSED
)
1182 memaddr
= translate_addr (memaddr
);
1185 return mm_write_inferior_memory (memaddr
, myaddr
, len
);
1187 return mm_read_inferior_memory (memaddr
, myaddr
, len
);
1191 /********************************************************** MSG_SEND_SERIAL
1192 ** This function is used to send a message over the
1195 ** If the message is successfully sent, a zero is
1196 ** returned. If the message was not sendable, a -1
1197 ** is returned. This function blocks. That is, it
1198 ** does not return until the message is completely
1199 ** sent, or until an error is encountered.
1204 msg_send_serial (union msg_t
*msg_ptr
)
1211 /* Send message header */
1213 message_size
= msg_ptr
->generic_msg
.length
+ (2 * sizeof (INT32
));
1216 c
= *((char *) msg_ptr
+ byte_count
);
1217 result
= write (mm_desc
, &c
, 1);
1220 byte_count
= byte_count
+ 1;
1223 while ((byte_count
< message_size
));
1226 } /* end msg_send_serial() */
1228 /********************************************************** MSG_RECV_SERIAL
1229 ** This function is used to receive a message over a
1232 ** If the message is waiting in the buffer, a zero is
1233 ** returned and the buffer pointed to by msg_ptr is filled
1234 ** in. If no message was available, a -1 is returned.
1235 ** If timeout==0, wait indefinetly for a character.
1240 msg_recv_serial (union msg_t
*msg_ptr
)
1242 static INT32 length
= 0;
1243 static INT32 byte_count
= 0;
1246 if (msg_ptr
== 0) /* re-sync request */
1251 /* The timeout here is the prevailing timeout set with VTIME */
1252 ->"timeout==0 semantics not supported"
1253 read (mm_desc
, in_buf
, BUFER_SIZE
);
1256 read (mm_desc
, in_buf
, BUFER_SIZE
);
1261 /* Receive message */
1263 /* Timeout==0, help support the mm_wait() routine */
1264 ->"timeout==0 semantics not supported (and its nice if they are)"
1265 result
= read (mm_desc
, &c
, 1);
1268 result
= read (mm_desc
, &c
, 1);
1275 error ("Timeout reading from remote system.");
1278 perror_with_name ("remote");
1280 else if (result
== 1)
1282 *((char *) msg_ptr
+ byte_count
) = c
;
1283 byte_count
= byte_count
+ 1;
1286 /* Message header received. Save message length. */
1287 if (byte_count
== (2 * sizeof (INT32
)))
1288 length
= msg_ptr
->generic_msg
.length
;
1290 if (byte_count
>= (length
+ (2 * sizeof (INT32
))))
1292 /* Message received */
1299 } /* end msg_recv_serial() */
1301 /********************************************************************* KBD_RAW
1302 ** This function is used to put the keyboard in "raw"
1303 ** mode for BSD Unix. The original status is saved
1304 ** so that it may be restored later.
1314 /* Get keyboard termio (to save to restore original modes) */
1316 result
= ioctl (0, TCGETA
, &kbd_tbuf
);
1318 result
= ioctl (0, TIOCGETP
, &kbd_tbuf
);
1323 /* Get keyboard TERMINAL (for modification) */
1325 result
= ioctl (0, TCGETA
, &tbuf
);
1327 result
= ioctl (0, TIOCGETP
, &tbuf
);
1332 /* Set up new parameters */
1334 tbuf
.c_iflag
= tbuf
.c_iflag
&
1335 ~(INLCR
| ICRNL
| IUCLC
| ISTRIP
| IXON
| BRKINT
);
1336 tbuf
.c_lflag
= tbuf
.c_lflag
& ~(ICANON
| ISIG
| ECHO
);
1337 tbuf
.c_cc
[4] = 0; /* MIN */
1338 tbuf
.c_cc
[5] = 0; /* TIME */
1340 /* FIXME: not sure if this is correct (matches HAVE_TERMIO). */
1341 tbuf
.sg_flags
|= RAW
;
1342 tbuf
.sg_flags
|= ANYP
;
1343 tbuf
.sg_flags
&= ~ECHO
;
1346 /* Set keyboard termio to new mode (RAW) */
1348 result
= ioctl (0, TCSETAF
, &tbuf
);
1350 result
= ioctl (0, TIOCSETP
, &tbuf
);
1356 } /* end kbd_raw() */
1360 /***************************************************************** KBD_RESTORE
1361 ** This function is used to put the keyboard back in the
1362 ** mode it was in before kbk_raw was called. Note that
1363 ** kbk_raw() must have been called at least once before
1364 ** kbd_restore() is called.
1372 /* Set keyboard termio to original mode */
1374 result
= ioctl (0, TCSETAF
, &kbd_tbuf
);
1376 result
= ioctl (0, TIOCGETP
, &kbd_tbuf
);
1383 } /* end kbd_cooked() */
1386 /*****************************************************************************/
1387 /* Fetch a single register indicatated by 'regno'.
1388 * Returns 0/-1 on success/failure.
1391 fetch_register (int regno
)
1394 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1395 out_msg_buf
->read_req_msg
.length
= 4 * 3;
1396 out_msg_buf
->read_req_msg
.byte_count
= 4;
1398 if (regno
== GR1_REGNUM
)
1400 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1401 out_msg_buf
->read_req_msg
.address
= 1;
1403 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1405 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1406 out_msg_buf
->read_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1408 #if defined(GR64_REGNUM)
1409 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32)
1411 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1412 out_msg_buf
->read_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1414 #endif /* GR64_REGNUM */
1415 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1417 out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
1418 out_msg_buf
->read_req_msg
.address
= (regno
- LR0_REGNUM
);
1420 else if (regno
>= FPE_REGNUM
&& regno
<= EXO_REGNUM
)
1423 supply_register (160 + (regno
- FPE_REGNUM
), &val
);
1424 return 0; /* Pretend Success */
1428 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
1429 out_msg_buf
->read_req_msg
.address
= regnum_to_srnum (regno
);
1432 msg_send_serial (out_msg_buf
);
1434 if (expect_msg (READ_ACK
, in_msg_buf
, 1))
1436 supply_register (regno
, &(in_msg_buf
->read_r_ack_msg
.data
[0]));
1445 /*****************************************************************************/
1446 /* Store a single register indicated by 'regno'.
1447 * Returns 0/-1 on success/failure.
1450 store_register (int regno
)
1454 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1455 out_msg_buf
->write_req_msg
.length
= 4 * 4;
1456 out_msg_buf
->write_req_msg
.byte_count
= 4;
1457 out_msg_buf
->write_r_msg
.data
[0] = read_register (regno
);
1459 if (regno
== GR1_REGNUM
)
1461 out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1462 out_msg_buf
->write_req_msg
.address
= 1;
1463 /* Setting GR1 changes the numbers of all the locals, so invalidate the
1464 * register cache. Do this *after* calling read_register, because we want
1465 * read_register to return the value that write_register has just stuffed
1466 * into the registers array, not the value of the register fetched from
1469 registers_changed ();
1471 #if defined(GR64_REGNUM)
1472 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32)
1474 out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1475 out_msg_buf
->write_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1477 #endif /* GR64_REGNUM */
1478 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1480 out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1481 out_msg_buf
->write_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1483 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1485 out_msg_buf
->write_req_msg
.memory_space
= LOCAL_REG
;
1486 out_msg_buf
->write_req_msg
.address
= (regno
- LR0_REGNUM
);
1488 else if (regno
>= FPE_REGNUM
&& regno
<= EXO_REGNUM
)
1490 return 0; /* Pretend Success */
1493 /* An unprotected or protected special register */
1495 out_msg_buf
->write_req_msg
.memory_space
= SPECIAL_REG
;
1496 out_msg_buf
->write_req_msg
.address
= regnum_to_srnum (regno
);
1499 msg_send_serial (out_msg_buf
);
1501 if (expect_msg (WRITE_ACK
, in_msg_buf
, 1))
1511 /****************************************************************************/
1513 * Convert a gdb special register number to a 29000 special register number.
1516 regnum_to_srnum (int regno
)
1541 return (USE_SHADOW_PC
? (20) : (10));
1543 return (USE_SHADOW_PC
? (21) : (11));
1545 return (USE_SHADOW_PC
? (22) : (12));
1575 return (255); /* Failure ? */
1578 /****************************************************************************/
1580 * Initialize the target debugger (minimon only).
1583 init_target_mm (ADDR32 tstart
, ADDR32 tend
, ADDR32 dstart
, ADDR32 dend
,
1584 ADDR32 entry
, INT32 ms_size
, INT32 rs_size
, ADDR32 arg_start
)
1586 out_msg_buf
->init_msg
.code
= INIT
;
1587 out_msg_buf
->init_msg
.length
= sizeof (struct init_msg_t
) - 2 * sizeof (INT32
);
1588 out_msg_buf
->init_msg
.text_start
= tstart
;
1589 out_msg_buf
->init_msg
.text_end
= tend
;
1590 out_msg_buf
->init_msg
.data_start
= dstart
;
1591 out_msg_buf
->init_msg
.data_end
= dend
;
1592 out_msg_buf
->init_msg
.entry_point
= entry
;
1593 out_msg_buf
->init_msg
.mem_stack_size
= ms_size
;
1594 out_msg_buf
->init_msg
.reg_stack_size
= rs_size
;
1595 out_msg_buf
->init_msg
.arg_start
= arg_start
;
1596 msg_send_serial (out_msg_buf
);
1597 expect_msg (INIT_ACK
, in_msg_buf
, 1);
1599 /****************************************************************************/
1601 * Return a pointer to a string representing the given message code.
1602 * Not all messages are represented here, only the ones that we expect
1603 * to be called with.
1606 msg_str (INT32 code
)
1608 static char cbuf
[32];
1613 sprintf (cbuf
, "%s (%d)", "BKPT_SET_ACK", code
);
1616 sprintf (cbuf
, "%s (%d)", "BKPT_RM_ACK", code
);
1619 sprintf (cbuf
, "%s (%d)", "INIT_ACK", code
);
1622 sprintf (cbuf
, "%s (%d)", "READ_ACK", code
);
1625 sprintf (cbuf
, "%s (%d)", "WRITE_ACK", code
);
1628 sprintf (cbuf
, "%s (%d)", "ERROR", code
);
1631 sprintf (cbuf
, "%s (%d)", "HALT", code
);
1634 sprintf (cbuf
, "UNKNOWN (%d)", code
);
1639 /****************************************************************************/
1641 * Selected (not all of them) error codes that we might get.
1644 error_msg_str (INT32 code
)
1646 static char cbuf
[50];
1651 return ("EMFAIL: unrecoverable error");
1653 return ("EMBADADDR: Illegal address");
1655 return ("EMBADREG: Illegal register ");
1657 return ("EMACCESS: Could not access memory");
1659 return ("EMBADMSG: Unknown message type");
1661 return ("EMMSG2BIG: Message to large");
1663 return ("EMNOSEND: Could not send message");
1665 return ("EMNORECV: Could not recv message");
1667 return ("EMRESET: Could not RESET target");
1669 return ("EMCONFIG: Could not get target CONFIG");
1671 return ("EMSTATUS: Could not get target STATUS");
1673 return ("EMREAD: Could not READ target memory");
1675 return ("EMWRITE: Could not WRITE target memory");
1677 return ("EMBKPTSET: Could not set breakpoint");
1679 return ("EMBKPTRM: Could not remove breakpoint");
1681 return ("EMBKPTSTAT: Could not get breakpoint status");
1683 return ("EMBKPTNONE: All breakpoints in use");
1685 return ("EMBKPTUSED: Breakpoints already in use");
1687 return ("EMINIT: Could not init target memory");
1689 return ("EMGO: Could not start execution");
1691 return ("EMSTEP: Could not single step");
1693 return ("EMBREAK: Could not BREAK");
1695 return ("EMCOMMERR: Communication error");
1697 sprintf (cbuf
, "error number %d", code
);
1703 /****************************************************************************/
1705 /* Receive a message, placing it in MSG_BUF, and expect it to be of
1706 type MSGCODE. If an error occurs, a non-zero FROM_TTY indicates
1707 that the message should be printed.
1709 Return 0 for failure, 1 for success. */
1712 expect_msg (INT32 msgcode
, union msg_t
*msg_buf
, int from_tty
)
1715 while (msg_recv_serial (msg_buf
) && (retries
++ < MAX_RETRIES
));
1716 if (retries
>= MAX_RETRIES
)
1718 printf ("Expected msg %s, ", msg_str (msgcode
));
1719 printf ("no message received!\n");
1720 return (0); /* Failure */
1723 if (msg_buf
->generic_msg
.code
!= msgcode
)
1727 printf ("Expected msg %s, ", msg_str (msgcode
));
1728 printf ("got msg %s\n", msg_str (msg_buf
->generic_msg
.code
));
1729 if (msg_buf
->generic_msg
.code
== ERROR
)
1730 printf ("%s\n", error_msg_str (msg_buf
->error_msg
.error_code
));
1732 return (0); /* Failure */
1734 return (1); /* Success */
1736 /****************************************************************************/
1738 * Determine the MiniMon memory space qualifier based on the addr.
1739 * FIXME: Can't distinguis I_ROM/D_ROM.
1740 * FIXME: Doesn't know anything about I_CACHE/D_CACHE.
1743 mm_memory_space (CORE_ADDR
*addr
)
1745 ADDR32 tstart
= target_config
.I_mem_start
;
1746 ADDR32 tend
= tstart
+ target_config
.I_mem_size
;
1747 ADDR32 dstart
= target_config
.D_mem_start
;
1748 ADDR32 dend
= tstart
+ target_config
.D_mem_size
;
1749 ADDR32 rstart
= target_config
.ROM_start
;
1750 ADDR32 rend
= tstart
+ target_config
.ROM_size
;
1752 if (((ADDR32
) addr
>= tstart
) && ((ADDR32
) addr
< tend
))
1756 else if (((ADDR32
) addr
>= dstart
) && ((ADDR32
) addr
< dend
))
1760 else if (((ADDR32
) addr
>= rstart
) && ((ADDR32
) addr
< rend
))
1762 /* FIXME: how do we determine between D_ROM and I_ROM */
1765 else /* FIXME: what do me do now? */
1766 return D_MEM
; /* Hmmm! */
1769 /****************************************************************************/
1771 * Define the target subroutine names
1773 struct target_ops mm_ops
;
1778 mm_ops
.to_shortname
= "minimon";
1779 mm_ops
.to_longname
= "Remote AMD/Minimon target";
1780 mm_ops
.to_doc
= "Remote debug an AMD 290*0 using the MiniMon dbg core on the target";
1781 mm_ops
.to_open
= mm_open
;
1782 mm_ops
.to_close
= mm_close
;
1783 mm_ops
.to_attach
= mm_attach
;
1784 mm_ops
.to_post_attach
= NULL
;
1785 mm_ops
.to_require_attach
= NULL
;
1786 mm_ops
.to_detach
= mm_detach
;
1787 mm_ops
.to_require_detach
= NULL
;
1788 mm_ops
.to_resume
= mm_resume
;
1789 mm_ops
.to_wait
= mm_wait
;
1790 mm_ops
.to_post_wait
= NULL
;
1791 mm_ops
.to_fetch_registers
= mm_fetch_registers
;
1792 mm_ops
.to_store_registers
= mm_store_registers
;
1793 mm_ops
.to_prepare_to_store
= mm_prepare_to_store
;
1794 mm_ops
.to_xfer_memory
= mm_xfer_inferior_memory
;
1795 mm_ops
.to_files_info
= mm_files_info
;
1796 mm_ops
.to_insert_breakpoint
= mm_insert_breakpoint
;
1797 mm_ops
.to_remove_breakpoint
= mm_remove_breakpoint
;
1798 mm_ops
.to_terminal_init
= 0;
1799 mm_ops
.to_terminal_inferior
= 0;
1800 mm_ops
.to_terminal_ours_for_output
= 0;
1801 mm_ops
.to_terminal_ours
= 0;
1802 mm_ops
.to_terminal_info
= 0;
1803 mm_ops
.to_kill
= mm_kill
;
1804 mm_ops
.to_load
= mm_load
;
1805 mm_ops
.to_lookup_symbol
= 0;
1806 mm_ops
.to_create_inferior
= mm_create_inferior
;
1807 mm_ops
.to_post_startup_inferior
= NULL
;
1808 mm_ops
.to_acknowledge_created_inferior
= NULL
;
1809 mm_ops
.to_clone_and_follow_inferior
= NULL
;
1810 mm_ops
.to_post_follow_inferior_by_clone
= NULL
;
1811 mm_ops
.to_insert_fork_catchpoint
= NULL
;
1812 mm_ops
.to_remove_fork_catchpoint
= NULL
;
1813 mm_ops
.to_insert_vfork_catchpoint
= NULL
;
1814 mm_ops
.to_remove_vfork_catchpoint
= NULL
;
1815 mm_ops
.to_has_forked
= NULL
;
1816 mm_ops
.to_has_vforked
= NULL
;
1817 mm_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
1818 mm_ops
.to_post_follow_vfork
= NULL
;
1819 mm_ops
.to_insert_exec_catchpoint
= NULL
;
1820 mm_ops
.to_remove_exec_catchpoint
= NULL
;
1821 mm_ops
.to_has_execd
= NULL
;
1822 mm_ops
.to_reported_exec_events_per_exec_call
= NULL
;
1823 mm_ops
.to_has_exited
= NULL
;
1824 mm_ops
.to_mourn_inferior
= mm_mourn
;
1825 mm_ops
.to_can_run
= 0;
1826 mm_ops
.to_notice_signals
= 0;
1827 mm_ops
.to_thread_alive
= 0;
1829 mm_ops
.to_pid_to_exec_file
= NULL
;
1830 mm_ops
.to_core_file_to_sym_file
= NULL
;
1831 mm_ops
.to_stratum
= process_stratum
;
1832 mm_ops
.DONT_USE
= 0;
1833 mm_ops
.to_has_all_memory
= 1;
1834 mm_ops
.to_has_memory
= 1;
1835 mm_ops
.to_has_stack
= 1;
1836 mm_ops
.to_has_registers
= 1;
1837 mm_ops
.to_has_execution
= 1;
1838 mm_ops
.to_sections
= 0;
1839 mm_ops
.to_sections_end
= 0;
1840 mm_ops
.to_magic
= OPS_MAGIC
;
1844 _initialize_remote_mm (void)
1847 add_target (&mm_ops
);
1850 #ifdef NO_HIF_SUPPORT
1851 service_HIF (union msg_t
*msg
)
1853 return (0); /* Emulate a failure */