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. */
121 volatile int n_alarms
;
128 printf ("mm_timer called\n");
132 #endif /* HAVE_TERMIO */
134 /* malloc'd name of the program on the remote system. */
135 static char *prog_name
= NULL
;
138 /* Number of SIGTRAPs we need to simulate. That is, the next
139 NEED_ARTIFICIAL_TRAP calls to mm_wait should just return
140 SIGTRAP without actually waiting for anything. */
142 /**************************************************** REMOTE_CREATE_INFERIOR */
143 /* This is called not only when we first attach, but also when the
144 user types "run" after having attached. */
146 mm_create_inferior (char *execfile
, char *args
, char **env
)
148 #define MAX_TOKENS 25
149 #define BUFFER_SIZE 256
152 char *token
[MAX_TOKENS
];
153 char cmd_line
[BUFFER_SIZE
];
156 error ("Can't pass arguments to remote mm process (yet).");
158 if (execfile
== 0 /* || exec_bfd == 0 */ )
159 error ("No executable file specified");
163 printf ("Minimon not open yet.\n");
167 /* On ultra3 (NYU) we assume the kernel is already running so there is
169 FIXME: Fixed required here -> load your program, possibly with mm_load().
171 printf_filtered ("\n\
172 Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n");
174 /* We will get a task spawn event immediately. */
175 init_wait_for_inferior ();
176 clear_proceed_status ();
177 stop_soon_quietly
= 1;
178 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
181 /**************************************************** REMOTE_MOURN_INFERIOR */
185 pop_target (); /* Pop back to no-child state */
186 generic_mourn_inferior ();
189 /********************************************************************** damn_b
191 /* Translate baud rates from integers to damn B_codes. Unix should
192 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
282 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
283 if (rate
== baudtab
[i
].rate
)
284 return baudtab
[i
].damn_b
;
285 return B38400
; /* Random */
289 /***************************************************************** REMOTE_OPEN
290 ** Open a connection to remote minimon.
291 NAME is the filename used for communication, then a space,
293 'target adapt /dev/ttya 9600 [prognam]' for example.
296 static char *dev_name
;
299 mm_open (char *name
, int from_tty
)
305 /* Find the first whitespace character, it separates dev_name from
308 p
&& *p
&& !isspace (*p
); p
++)
310 if (p
== 0 || *p
== '\0')
312 error ("Usage : <command> <serial-device> <baud-rate> [progname]");
313 dev_name
= (char *) xmalloc (p
- name
+ 1);
314 strncpy (dev_name
, name
, p
- name
);
315 dev_name
[p
- name
] = '\0';
317 /* Skip over the whitespace after dev_name */
318 for (; isspace (*p
); p
++)
321 if (1 != sscanf (p
, "%d ", &baudrate
))
324 /* Skip the number and then the spaces */
325 for (; isdigit (*p
); p
++)
327 for (; isspace (*p
); p
++)
330 if (prog_name
!= NULL
)
332 prog_name
= savestring (p
, strlen (p
));
338 mm_desc
= open (dev_name
, O_RDWR
);
340 perror_with_name (dev_name
);
341 ioctl (mm_desc
, TIOCGETP
, &sg
);
343 sg
.c_cc
[VMIN
] = 0; /* read with timeout. */
344 sg
.c_cc
[VTIME
] = timeout
* 10;
345 sg
.c_lflag
&= ~(ICANON
| ECHO
);
346 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | damn_b (baudrate
);
348 sg
.sg_ispeed
= damn_b (baudrate
);
349 sg
.sg_ospeed
= damn_b (baudrate
);
352 sg
.sg_flags
&= ~ECHO
;
356 ioctl (mm_desc
, TIOCSETP
, &sg
);
357 mm_stream
= fdopen (mm_desc
, "r+");
359 push_target (&mm_ops
);
362 #ifndef NO_SIGINTERRUPT
363 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
365 if (siginterrupt (SIGALRM
, 1) != 0)
366 perror ("mm_open: error in siginterrupt");
369 /* Set up read timeout timer. */
370 if ((void (*)) signal (SIGALRM
, mm_timer
) == (void (*)) -1)
371 perror ("mm_open: error in signal");
374 #if defined (LOG_FILE)
375 log_file
= fopen (LOG_FILE
, "w");
376 if (log_file
== NULL
)
377 perror_with_name (LOG_FILE
);
380 ** Initialize target configuration structure (global)
383 out_msg_buf
->config_req_msg
.code
= CONFIG_REQ
;
384 out_msg_buf
->config_req_msg
.length
= 4 * 0;
385 msg_send_serial (out_msg_buf
); /* send config request message */
387 expect_msg (CONFIG
, in_msg_buf
, 1);
389 a29k_get_processor_type ();
391 /* Print out some stuff, letting the user now what's going on */
392 printf_filtered ("Connected to MiniMon via %s.\n", dev_name
);
393 /* FIXME: can this restriction be removed? */
394 printf_filtered ("Remote debugging using virtual addresses works only\n");
395 printf_filtered ("\twhen virtual addresses map 1:1 to physical addresses.\n")
397 if (processor_type
!= a29k_freeze_mode
)
399 fprintf_filtered (gdb_stderr
,
400 "Freeze-mode debugging not available, and can only be done on an A29050.\n");
403 target_config
.code
= CONFIG
;
404 target_config
.length
= 0;
405 target_config
.processor_id
= in_msg_buf
->config_msg
.processor_id
;
406 target_config
.version
= in_msg_buf
->config_msg
.version
;
407 target_config
.I_mem_start
= in_msg_buf
->config_msg
.I_mem_start
;
408 target_config
.I_mem_size
= in_msg_buf
->config_msg
.I_mem_size
;
409 target_config
.D_mem_start
= in_msg_buf
->config_msg
.D_mem_start
;
410 target_config
.D_mem_size
= in_msg_buf
->config_msg
.D_mem_size
;
411 target_config
.ROM_start
= in_msg_buf
->config_msg
.ROM_start
;
412 target_config
.ROM_size
= in_msg_buf
->config_msg
.ROM_size
;
413 target_config
.max_msg_size
= in_msg_buf
->config_msg
.max_msg_size
;
414 target_config
.max_bkpts
= in_msg_buf
->config_msg
.max_bkpts
;
415 target_config
.coprocessor
= in_msg_buf
->config_msg
.coprocessor
;
416 target_config
.reserved
= in_msg_buf
->config_msg
.reserved
;
419 printf ("Connected to MiniMON :\n");
420 printf (" Debugcore version %d.%d\n",
421 0x0f & (target_config
.version
>> 4),
422 0x0f & (target_config
.version
));
423 printf (" Configuration version %d.%d\n",
424 0x0f & (target_config
.version
>> 12),
425 0x0f & (target_config
.version
>> 8));
426 printf (" Message system version %d.%d\n",
427 0x0f & (target_config
.version
>> 20),
428 0x0f & (target_config
.version
>> 16));
429 printf (" Communication driver version %d.%d\n",
430 0x0f & (target_config
.version
>> 28),
431 0x0f & (target_config
.version
>> 24));
434 /* Leave the target running...
435 * The above message stopped the target in the dbg core (MiniMon),
436 * so restart the target out of MiniMon,
438 out_msg_buf
->go_msg
.code
= GO
;
439 out_msg_buf
->go_msg
.length
= 0;
440 msg_send_serial (out_msg_buf
);
441 /* No message to expect after a GO */
444 /**************************************************************** REMOTE_CLOSE
445 ** Close the open connection to the minimon debugger.
446 Use this when you want to detach and do something else
449 mm_close ( /*FIXME: how is quitting used */
453 error ("Can't close remote connection: not debugging remotely.");
455 /* We should never get here if there isn't something valid in
456 mm_desc and mm_stream.
458 Due to a bug in Unix, fclose closes not only the stdio stream,
459 but also the file descriptor. So we don't actually close
463 /* close (mm_desc); */
465 /* Do not try to close mm_desc again, later in the program. */
469 #if defined (LOG_FILE)
470 if (ferror (log_file
))
471 printf ("Error writing log file.\n");
472 if (fclose (log_file
) != 0)
473 printf ("Error closing log file.\n");
476 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 (char *args
, int from_tty
)
488 error ("MiniMon not opened yet, use the 'target minimon' command.\n");
491 printf ("Attaching to remote program %s...\n", prog_name
);
493 /* Make sure the target is currently running, it is supposed to be. */
494 /* FIXME: is it ok to send MiniMon a BREAK if it is already stopped in
495 * the dbg core. If so, we don't need to send this GO.
497 out_msg_buf
->go_msg
.code
= GO
;
498 out_msg_buf
->go_msg
.length
= 0;
499 msg_send_serial (out_msg_buf
);
500 sleep (2); /* At the worst it will stop, receive a message, continue */
502 /* Send the mm a break. */
503 out_msg_buf
->break_msg
.code
= BREAK
;
504 out_msg_buf
->break_msg
.length
= 0;
505 msg_send_serial (out_msg_buf
);
507 /********************************************************** REMOTE_DETACH */
508 /* Terminate the open connection to the remote debugger.
509 Use this when you want to detach and do something else
510 with your gdb. Leave remote process running (with no breakpoints set). */
512 mm_detach (char *args
, int from_tty
)
514 remove_breakpoints (); /* Just in case there were any left in */
515 out_msg_buf
->go_msg
.code
= GO
;
516 out_msg_buf
->go_msg
.length
= 0;
517 msg_send_serial (out_msg_buf
);
518 pop_target (); /* calls mm_close to do the real work */
522 /*************************************************************** REMOTE_RESUME
523 ** Tell the remote machine to resume. */
526 mm_resume (int pid
, int step
, enum target_signal sig
)
528 if (sig
!= TARGET_SIGNAL_0
)
529 warning ("Can't send signals to a remote MiniMon system.");
533 out_msg_buf
->step_msg
.code
= STEP
;
534 out_msg_buf
->step_msg
.length
= 1 * 4;
535 out_msg_buf
->step_msg
.count
= 1; /* step 1 instruction */
536 msg_send_serial (out_msg_buf
);
540 out_msg_buf
->go_msg
.code
= GO
;
541 out_msg_buf
->go_msg
.length
= 0;
542 msg_send_serial (out_msg_buf
);
546 /***************************************************************** REMOTE_WAIT
547 ** Wait until the remote machine stops, then return,
548 storing status in STATUS just as `wait' would. */
551 mm_wait (struct target_waitstatus
*status
)
554 int old_timeout
= timeout
;
555 int old_immediate_quit
= immediate_quit
;
557 status
->kind
= TARGET_WAITKIND_EXITED
;
558 status
->value
.integer
= 0;
560 /* wait for message to arrive. It should be:
561 - A HIF service request.
562 - A HIF exit service request.
564 - A CHANNEL1 request.
565 - a debugcore HALT message.
566 HIF services must be responded too, and while-looping continued.
567 If the target stops executing, mm_wait() should return.
569 timeout
= 0; /* Wait indefinetly for a message */
570 immediate_quit
= 1; /* Helps ability to QUIT */
573 while (msg_recv_serial (in_msg_buf
))
575 QUIT
; /* Let user quit if they want */
577 switch (in_msg_buf
->halt_msg
.code
)
580 i
= in_msg_buf
->hif_call_rtn_msg
.service_number
;
581 result
= service_HIF (in_msg_buf
);
582 if (i
== 1) /* EXIT */
585 printf ("Warning: failure during HIF service %d\n", i
);
588 service_HIF (in_msg_buf
);
591 i
= in_msg_buf
->channel1_msg
.length
;
592 in_msg_buf
->channel1_msg
.data
[i
] = '\0';
593 printf ("%s", in_msg_buf
->channel1_msg
.data
);
594 gdb_flush (gdb_stdout
);
595 /* Send CHANNEL1_ACK message */
596 out_msg_buf
->channel1_ack_msg
.code
= CHANNEL1_ACK
;
597 out_msg_buf
->channel1_ack_msg
.length
= 0;
598 result
= msg_send_serial (out_msg_buf
);
607 /* FIXME, these printfs should not be here. This is a source level
609 if (in_msg_buf
->halt_msg
.trap_number
== 0)
611 printf ("Am290*0 received vector number %d (break point)\n",
612 in_msg_buf
->halt_msg
.trap_number
);
613 status
->kind
= TARGET_WAITKIND_STOPPED
;
614 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
616 else if (in_msg_buf
->halt_msg
.trap_number
== 1)
618 printf ("Am290*0 received vector number %d\n",
619 in_msg_buf
->halt_msg
.trap_number
);
620 status
->kind
= TARGET_WAITKIND_STOPPED
;
621 status
->value
.sig
= TARGET_SIGNAL_BUS
;
623 else if (in_msg_buf
->halt_msg
.trap_number
== 3
624 || in_msg_buf
->halt_msg
.trap_number
== 4)
626 printf ("Am290*0 received vector number %d\n",
627 in_msg_buf
->halt_msg
.trap_number
);
628 status
->kind
= TARGET_WAITKIND_STOPPED
;
629 status
->value
.sig
= TARGET_SIGNAL_FPE
;
631 else if (in_msg_buf
->halt_msg
.trap_number
== 5)
633 printf ("Am290*0 received vector number %d\n",
634 in_msg_buf
->halt_msg
.trap_number
);
635 status
->kind
= TARGET_WAITKIND_STOPPED
;
636 status
->value
.sig
= TARGET_SIGNAL_ILL
;
638 else if (in_msg_buf
->halt_msg
.trap_number
>= 6
639 && in_msg_buf
->halt_msg
.trap_number
<= 11)
641 printf ("Am290*0 received vector number %d\n",
642 in_msg_buf
->halt_msg
.trap_number
);
643 status
->kind
= TARGET_WAITKIND_STOPPED
;
644 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
646 else if (in_msg_buf
->halt_msg
.trap_number
== 12
647 || in_msg_buf
->halt_msg
.trap_number
== 13)
649 printf ("Am290*0 received vector number %d\n",
650 in_msg_buf
->halt_msg
.trap_number
);
651 status
->kind
= TARGET_WAITKIND_STOPPED
;
652 status
->value
.sig
= TARGET_SIGNAL_ILL
;
654 else if (in_msg_buf
->halt_msg
.trap_number
== 14)
656 printf ("Am290*0 received vector number %d\n",
657 in_msg_buf
->halt_msg
.trap_number
);
658 status
->kind
= TARGET_WAITKIND_STOPPED
;
659 status
->value
.sig
= TARGET_SIGNAL_ALRM
;
661 else if (in_msg_buf
->halt_msg
.trap_number
== 15)
663 status
->kind
= TARGET_WAITKIND_STOPPED
;
664 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
666 else if (in_msg_buf
->halt_msg
.trap_number
>= 16
667 && in_msg_buf
->halt_msg
.trap_number
<= 21)
669 printf ("Am290*0 received vector number %d\n",
670 in_msg_buf
->halt_msg
.trap_number
);
671 status
->kind
= TARGET_WAITKIND_STOPPED
;
672 status
->value
.sig
= TARGET_SIGNAL_INT
;
674 else if (in_msg_buf
->halt_msg
.trap_number
== 22)
676 printf ("Am290*0 received vector number %d\n",
677 in_msg_buf
->halt_msg
.trap_number
);
678 status
->kind
= TARGET_WAITKIND_STOPPED
;
679 status
->value
.sig
= TARGET_SIGNAL_ILL
;
680 } /* BREAK message was sent */
681 else if (in_msg_buf
->halt_msg
.trap_number
== 75)
683 status
->kind
= TARGET_WAITKIND_STOPPED
;
684 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
689 status
->kind
= TARGET_WAITKIND_EXITED
;
690 status
->value
.integer
= 0;
693 timeout
= old_timeout
; /* Restore original timeout value */
694 immediate_quit
= old_immediate_quit
;
698 /******************************************************* REMOTE_FETCH_REGISTERS
699 * Read a remote register 'regno'.
700 * If regno==-1 then read all the registers.
703 mm_fetch_registers (int regno
)
709 fetch_register (regno
);
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
++)
735 supply_register (regno
, data_p
++);
737 #endif /* GR64_REGNUM */
739 /* Global Registers gr96-gr127 */
740 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
741 out_msg_buf
->read_req_msg
.length
= 4 * 3;
742 out_msg_buf
->read_req_msg
.byte_count
= 4 * 32;
743 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
744 out_msg_buf
->read_req_msg
.address
= 96;
745 msg_send_serial (out_msg_buf
);
746 expect_msg (READ_ACK
, in_msg_buf
, 1);
747 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
749 for (regno
= GR96_REGNUM
; regno
< GR96_REGNUM
+ 32; regno
++)
751 supply_register (regno
, data_p
++);
754 /* Local Registers */
755 out_msg_buf
->read_req_msg
.byte_count
= 4 * (128);
756 out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
757 out_msg_buf
->read_req_msg
.address
= 0;
758 msg_send_serial (out_msg_buf
);
759 expect_msg (READ_ACK
, in_msg_buf
, 1);
760 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
762 for (regno
= LR0_REGNUM
; regno
< LR0_REGNUM
+ 128; regno
++)
764 supply_register (regno
, data_p
++);
767 /* Protected Special Registers */
768 out_msg_buf
->read_req_msg
.byte_count
= 4 * 15;
769 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
770 out_msg_buf
->read_req_msg
.address
= 0;
771 msg_send_serial (out_msg_buf
);
772 expect_msg (READ_ACK
, in_msg_buf
, 1);
773 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
775 for (regno
= 0; regno
<= 14; regno
++)
777 supply_register (SR_REGNUM (regno
), data_p
++);
780 { /* Let regno_to_srnum() handle the register number */
781 fetch_register (NPC_REGNUM
);
782 fetch_register (PC_REGNUM
);
783 fetch_register (PC2_REGNUM
);
786 /* Unprotected Special Registers */
787 out_msg_buf
->read_req_msg
.byte_count
= 4 * 8;
788 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
789 out_msg_buf
->read_req_msg
.address
= 128;
790 msg_send_serial (out_msg_buf
);
791 expect_msg (READ_ACK
, in_msg_buf
, 1);
792 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
794 for (regno
= 128; regno
<= 135; regno
++)
796 supply_register (SR_REGNUM (regno
), data_p
++);
799 /* There doesn't seem to be any way to get these. */
802 supply_register (FPE_REGNUM
, &val
);
803 supply_register (INTE_REGNUM
, &val
);
804 supply_register (FPS_REGNUM
, &val
);
805 supply_register (EXO_REGNUM
, &val
);
810 /****************************************************** REMOTE_STORE_REGISTERS
811 * Store register regno into the target.
812 * If regno==-1 then store all the registers.
813 * Result is 0 for success, -1 for failure.
817 mm_store_registers (int regno
)
823 store_register (regno
);
829 out_msg_buf
->write_r_msg
.code
= WRITE_REQ
;
832 out_msg_buf
->write_r_msg
.byte_count
= 4 * 1;
833 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
834 out_msg_buf
->write_r_msg
.memory_space
= GLOBAL_REG
;
835 out_msg_buf
->write_r_msg
.address
= 1;
836 out_msg_buf
->write_r_msg
.data
[0] = read_register (GR1_REGNUM
);
838 msg_send_serial (out_msg_buf
);
839 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
844 #if defined(GR64_REGNUM)
845 /* Global registers gr64-gr95 */
846 out_msg_buf
->write_r_msg
.byte_count
= 4 * (32);
847 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
848 out_msg_buf
->write_r_msg
.address
= 64;
850 for (regno
= GR64_REGNUM
; regno
< GR64_REGNUM
+ 32; regno
++)
852 out_msg_buf
->write_r_msg
.data
[regno
- GR64_REGNUM
] = read_register (regno
);
854 msg_send_serial (out_msg_buf
);
855 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
859 #endif /* GR64_REGNUM */
861 /* Global registers gr96-gr127 */
862 out_msg_buf
->write_r_msg
.byte_count
= 4 * (32);
863 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
864 out_msg_buf
->write_r_msg
.address
= 96;
865 for (regno
= GR96_REGNUM
; regno
< GR96_REGNUM
+ 32; regno
++)
867 out_msg_buf
->write_r_msg
.data
[regno
- GR96_REGNUM
] = read_register (regno
);
869 msg_send_serial (out_msg_buf
);
870 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
875 /* Local Registers */
876 out_msg_buf
->write_r_msg
.memory_space
= LOCAL_REG
;
877 out_msg_buf
->write_r_msg
.byte_count
= 4 * 128;
878 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
879 out_msg_buf
->write_r_msg
.address
= 0;
881 for (regno
= LR0_REGNUM
; regno
< LR0_REGNUM
+ 128; regno
++)
883 out_msg_buf
->write_r_msg
.data
[regno
- LR0_REGNUM
] = read_register (regno
);
885 msg_send_serial (out_msg_buf
);
886 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
891 /* Protected Special Registers */
892 /* VAB through TMR */
893 out_msg_buf
->write_r_msg
.memory_space
= SPECIAL_REG
;
894 out_msg_buf
->write_r_msg
.byte_count
= 4 * 10;
895 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
896 out_msg_buf
->write_r_msg
.address
= 0;
897 for (regno
= 0; regno
<= 9; regno
++) /* VAB through TMR */
898 out_msg_buf
->write_r_msg
.data
[regno
] = read_register (SR_REGNUM (regno
));
899 msg_send_serial (out_msg_buf
);
900 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
905 /* PC0, PC1, PC2 possibly as shadow registers */
906 out_msg_buf
->write_r_msg
.byte_count
= 4 * 3;
907 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
908 for (regno
= 10; regno
<= 12; regno
++) /* LRU and MMU */
909 out_msg_buf
->write_r_msg
.data
[regno
- 10] = read_register (SR_REGNUM (regno
));
911 out_msg_buf
->write_r_msg
.address
= 20; /* SPC0 */
913 out_msg_buf
->write_r_msg
.address
= 10; /* PC0 */
914 msg_send_serial (out_msg_buf
);
915 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
921 out_msg_buf
->write_r_msg
.byte_count
= 4 * 2;
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
= 13;
924 for (regno
= 13; regno
<= 14; regno
++) /* LRU and MMU */
925 out_msg_buf
->write_r_msg
.data
[regno
- 13] = read_register (SR_REGNUM (regno
));
926 msg_send_serial (out_msg_buf
);
927 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
932 /* Unprotected Special Registers */
933 out_msg_buf
->write_r_msg
.byte_count
= 4 * 8;
934 out_msg_buf
->write_r_msg
.length
= 3 * 4 + out_msg_buf
->write_r_msg
.byte_count
;
935 out_msg_buf
->write_r_msg
.address
= 128;
936 for (regno
= 128; regno
<= 135; regno
++)
937 out_msg_buf
->write_r_msg
.data
[regno
- 128] = read_register (SR_REGNUM (regno
));
938 msg_send_serial (out_msg_buf
);
939 if (!expect_msg (WRITE_ACK
, in_msg_buf
, 1))
944 registers_changed ();
947 /*************************************************** REMOTE_PREPARE_TO_STORE */
948 /* Get ready to modify the registers array. On machines which store
949 individual registers, this doesn't need to do anything. On machines
950 which store all the registers in one fell swoop, this makes sure
951 that registers contains all the registers from the program being
955 mm_prepare_to_store (void)
957 /* Do nothing, since we can store individual regs */
960 /******************************************************* REMOTE_XFER_MEMORY */
962 translate_addr (CORE_ADDR addr
)
964 #if defined(KERNEL_DEBUGGING)
965 /* Check for a virtual address in the kernel */
966 /* Assume physical address of ublock is in paddr_u register */
967 /* FIXME: doesn't work for user virtual addresses */
970 /* PADDR_U register holds the physical address of the ublock */
971 CORE_ADDR i
= (CORE_ADDR
) read_register (PADDR_U_REGNUM
);
972 return (i
+ addr
- (CORE_ADDR
) UVADDR
);
983 /******************************************************* REMOTE_FILES_INFO */
987 printf ("\tAttached to %s at %d baud and running program %s.\n",
988 dev_name
, baudrate
, prog_name
);
991 /************************************************* REMOTE_INSERT_BREAKPOINT */
993 mm_insert_breakpoint (CORE_ADDR addr
, char *contents_cache
)
995 out_msg_buf
->bkpt_set_msg
.code
= BKPT_SET
;
996 out_msg_buf
->bkpt_set_msg
.length
= 4 * 4;
997 out_msg_buf
->bkpt_set_msg
.memory_space
= I_MEM
;
998 out_msg_buf
->bkpt_set_msg
.bkpt_addr
= (ADDR32
) addr
;
999 out_msg_buf
->bkpt_set_msg
.pass_count
= 1;
1000 out_msg_buf
->bkpt_set_msg
.bkpt_type
= -1; /* use illop for 29000 */
1001 msg_send_serial (out_msg_buf
);
1002 if (expect_msg (BKPT_SET_ACK
, in_msg_buf
, 1))
1004 return 0; /* Success */
1008 return 1; /* Failure */
1012 /************************************************* REMOTE_DELETE_BREAKPOINT */
1014 mm_remove_breakpoint (CORE_ADDR addr
, char *contents_cache
)
1016 out_msg_buf
->bkpt_rm_msg
.code
= BKPT_RM
;
1017 out_msg_buf
->bkpt_rm_msg
.length
= 4 * 3;
1018 out_msg_buf
->bkpt_rm_msg
.memory_space
= I_MEM
;
1019 out_msg_buf
->bkpt_rm_msg
.bkpt_addr
= (ADDR32
) addr
;
1020 msg_send_serial (out_msg_buf
);
1021 if (expect_msg (BKPT_RM_ACK
, in_msg_buf
, 1))
1023 return 0; /* Success */
1027 return 1; /* Failure */
1032 /******************************************************* REMOTE_KILL */
1034 mm_kill (char *arg
, int from_tty
)
1038 #if defined(KERNEL_DEBUGGING)
1039 /* We don't ever kill the kernel */
1042 printf ("Kernel not killed, but left in current state.\n");
1043 printf ("Use detach to leave kernel running.\n");
1046 out_msg_buf
->break_msg
.code
= BREAK
;
1047 out_msg_buf
->bkpt_set_msg
.length
= 4 * 0;
1048 expect_msg (HALT
, in_msg_buf
, from_tty
);
1051 printf ("Target has been stopped.");
1052 printf ("Would you like to do a hardware reset (y/n) [n] ");
1053 fgets (buf
, 3, stdin
);
1056 out_msg_buf
->reset_msg
.code
= RESET
;
1057 out_msg_buf
->bkpt_set_msg
.length
= 4 * 0;
1058 expect_msg (RESET_ACK
, in_msg_buf
, from_tty
);
1059 printf ("Target has been reset.");
1068 /***************************************************************************/
1070 * Load a program into the target.
1073 mm_load (char *arg_string
, int from_tty
)
1077 #if defined(KERNEL_DEBUGGING)
1078 printf ("The kernel had better be loaded already! Loading not done.\n");
1080 if (arg_string
== 0)
1081 error ("The load command takes a file name");
1083 arg_string
= tilde_expand (arg_string
);
1084 make_cleanup (xfree
, arg_string
);
1087 error ("File loading is not yet supported for MiniMon.");
1088 /* FIXME, code to load your file here... */
1089 /* You may need to do an init_target_mm() */
1090 /* init_target_mm(?,?,?,?,?,?,?,?); */
1092 /* symbol_file_add (arg_string, from_tty, text_addr, 0, 0); */
1097 /************************************************ REMOTE_WRITE_INFERIOR_MEMORY
1098 ** Copy LEN bytes of data from debugger memory at MYADDR
1099 to inferior's memory at MEMADDR. Returns number of bytes written. */
1101 mm_write_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
1105 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1106 out_msg_buf
->write_req_msg
.memory_space
= mm_memory_space (memaddr
);
1109 while (nwritten
< len
)
1111 int num_to_write
= len
- nwritten
;
1112 if (num_to_write
> MAXDATA
)
1113 num_to_write
= MAXDATA
;
1114 for (i
= 0; i
< num_to_write
; i
++)
1115 out_msg_buf
->write_req_msg
.data
[i
] = myaddr
[i
+ nwritten
];
1116 out_msg_buf
->write_req_msg
.byte_count
= num_to_write
;
1117 out_msg_buf
->write_req_msg
.length
= 3 * 4 + num_to_write
;
1118 out_msg_buf
->write_req_msg
.address
= memaddr
+ nwritten
;
1119 msg_send_serial (out_msg_buf
);
1121 if (expect_msg (WRITE_ACK
, in_msg_buf
, 1))
1123 nwritten
+= in_msg_buf
->write_ack_msg
.byte_count
;
1133 /************************************************* REMOTE_READ_INFERIOR_MEMORY
1134 ** Read LEN bytes from inferior memory at MEMADDR. Put the result
1135 at debugger address MYADDR. Returns number of bytes read. */
1137 mm_read_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
)
1141 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1142 out_msg_buf
->read_req_msg
.memory_space
= mm_memory_space (memaddr
);
1147 int num_to_read
= (len
- nread
);
1148 if (num_to_read
> MAXDATA
)
1149 num_to_read
= MAXDATA
;
1150 out_msg_buf
->read_req_msg
.byte_count
= num_to_read
;
1151 out_msg_buf
->read_req_msg
.length
= 3 * 4 + num_to_read
;
1152 out_msg_buf
->read_req_msg
.address
= memaddr
+ nread
;
1153 msg_send_serial (out_msg_buf
);
1155 if (expect_msg (READ_ACK
, in_msg_buf
, 1))
1157 for (i
= 0; i
< in_msg_buf
->read_ack_msg
.byte_count
; i
++)
1158 myaddr
[i
+ nread
] = in_msg_buf
->read_ack_msg
.data
[i
];
1159 nread
+= in_msg_buf
->read_ack_msg
.byte_count
;
1169 /* FIXME! Merge these two. */
1171 mm_xfer_inferior_memory (CORE_ADDR memaddr
, char *myaddr
, int len
, int write
,
1172 struct mem_attrib
*attrib ATTRIBUTE_UNUSED
,
1173 struct target_ops
*target ATTRIBUTE_UNUSED
)
1176 memaddr
= translate_addr (memaddr
);
1179 return mm_write_inferior_memory (memaddr
, myaddr
, len
);
1181 return mm_read_inferior_memory (memaddr
, myaddr
, len
);
1185 /********************************************************** MSG_SEND_SERIAL
1186 ** This function is used to send a message over the
1189 ** If the message is successfully sent, a zero is
1190 ** returned. If the message was not sendable, a -1
1191 ** is returned. This function blocks. That is, it
1192 ** does not return until the message is completely
1193 ** sent, or until an error is encountered.
1198 msg_send_serial (union msg_t
*msg_ptr
)
1205 /* Send message header */
1207 message_size
= msg_ptr
->generic_msg
.length
+ (2 * sizeof (INT32
));
1210 c
= *((char *) msg_ptr
+ byte_count
);
1211 result
= write (mm_desc
, &c
, 1);
1214 byte_count
= byte_count
+ 1;
1217 while ((byte_count
< message_size
));
1220 } /* end msg_send_serial() */
1222 /********************************************************** MSG_RECV_SERIAL
1223 ** This function is used to receive a message over a
1226 ** If the message is waiting in the buffer, a zero is
1227 ** returned and the buffer pointed to by msg_ptr is filled
1228 ** in. If no message was available, a -1 is returned.
1229 ** If timeout==0, wait indefinetly for a character.
1234 msg_recv_serial (union msg_t
*msg_ptr
)
1236 static INT32 length
= 0;
1237 static INT32 byte_count
= 0;
1240 if (msg_ptr
== 0) /* re-sync request */
1245 /* The timeout here is the prevailing timeout set with VTIME */
1246 ->"timeout==0 semantics not supported"
1247 read (mm_desc
, in_buf
, BUFER_SIZE
);
1250 read (mm_desc
, in_buf
, BUFER_SIZE
);
1255 /* Receive message */
1257 /* Timeout==0, help support the mm_wait() routine */
1258 ->"timeout==0 semantics not supported (and its nice if they are)"
1259 result
= read (mm_desc
, &c
, 1);
1262 result
= read (mm_desc
, &c
, 1);
1269 error ("Timeout reading from remote system.");
1272 perror_with_name ("remote");
1274 else if (result
== 1)
1276 *((char *) msg_ptr
+ byte_count
) = c
;
1277 byte_count
= byte_count
+ 1;
1280 /* Message header received. Save message length. */
1281 if (byte_count
== (2 * sizeof (INT32
)))
1282 length
= msg_ptr
->generic_msg
.length
;
1284 if (byte_count
>= (length
+ (2 * sizeof (INT32
))))
1286 /* Message received */
1293 } /* end msg_recv_serial() */
1295 /********************************************************************* KBD_RAW
1296 ** This function is used to put the keyboard in "raw"
1297 ** mode for BSD Unix. The original status is saved
1298 ** so that it may be restored later.
1308 /* Get keyboard termio (to save to restore original modes) */
1310 result
= ioctl (0, TCGETA
, &kbd_tbuf
);
1312 result
= ioctl (0, TIOCGETP
, &kbd_tbuf
);
1317 /* Get keyboard TERMINAL (for modification) */
1319 result
= ioctl (0, TCGETA
, &tbuf
);
1321 result
= ioctl (0, TIOCGETP
, &tbuf
);
1326 /* Set up new parameters */
1328 tbuf
.c_iflag
= tbuf
.c_iflag
&
1329 ~(INLCR
| ICRNL
| IUCLC
| ISTRIP
| IXON
| BRKINT
);
1330 tbuf
.c_lflag
= tbuf
.c_lflag
& ~(ICANON
| ISIG
| ECHO
);
1331 tbuf
.c_cc
[4] = 0; /* MIN */
1332 tbuf
.c_cc
[5] = 0; /* TIME */
1334 /* FIXME: not sure if this is correct (matches HAVE_TERMIO). */
1335 tbuf
.sg_flags
|= RAW
;
1336 tbuf
.sg_flags
|= ANYP
;
1337 tbuf
.sg_flags
&= ~ECHO
;
1340 /* Set keyboard termio to new mode (RAW) */
1342 result
= ioctl (0, TCSETAF
, &tbuf
);
1344 result
= ioctl (0, TIOCSETP
, &tbuf
);
1350 } /* end kbd_raw() */
1354 /***************************************************************** KBD_RESTORE
1355 ** This function is used to put the keyboard back in the
1356 ** mode it was in before kbk_raw was called. Note that
1357 ** kbk_raw() must have been called at least once before
1358 ** kbd_restore() is called.
1366 /* Set keyboard termio to original mode */
1368 result
= ioctl (0, TCSETAF
, &kbd_tbuf
);
1370 result
= ioctl (0, TIOCGETP
, &kbd_tbuf
);
1377 } /* end kbd_cooked() */
1380 /*****************************************************************************/
1381 /* Fetch a single register indicatated by 'regno'.
1382 * Returns 0/-1 on success/failure.
1385 fetch_register (int regno
)
1388 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1389 out_msg_buf
->read_req_msg
.length
= 4 * 3;
1390 out_msg_buf
->read_req_msg
.byte_count
= 4;
1392 if (regno
== GR1_REGNUM
)
1394 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1395 out_msg_buf
->read_req_msg
.address
= 1;
1397 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1399 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1400 out_msg_buf
->read_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1402 #if defined(GR64_REGNUM)
1403 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32)
1405 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1406 out_msg_buf
->read_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1408 #endif /* GR64_REGNUM */
1409 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1411 out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
1412 out_msg_buf
->read_req_msg
.address
= (regno
- LR0_REGNUM
);
1414 else if (regno
>= FPE_REGNUM
&& regno
<= EXO_REGNUM
)
1417 supply_register (160 + (regno
- FPE_REGNUM
), &val
);
1418 return 0; /* Pretend Success */
1422 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
1423 out_msg_buf
->read_req_msg
.address
= regnum_to_srnum (regno
);
1426 msg_send_serial (out_msg_buf
);
1428 if (expect_msg (READ_ACK
, in_msg_buf
, 1))
1430 supply_register (regno
, &(in_msg_buf
->read_r_ack_msg
.data
[0]));
1439 /*****************************************************************************/
1440 /* Store a single register indicated by 'regno'.
1441 * Returns 0/-1 on success/failure.
1444 store_register (int regno
)
1448 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1449 out_msg_buf
->write_req_msg
.length
= 4 * 4;
1450 out_msg_buf
->write_req_msg
.byte_count
= 4;
1451 out_msg_buf
->write_r_msg
.data
[0] = read_register (regno
);
1453 if (regno
== GR1_REGNUM
)
1455 out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1456 out_msg_buf
->write_req_msg
.address
= 1;
1457 /* Setting GR1 changes the numbers of all the locals, so invalidate the
1458 * register cache. Do this *after* calling read_register, because we want
1459 * read_register to return the value that write_register has just stuffed
1460 * into the registers array, not the value of the register fetched from
1463 registers_changed ();
1465 #if defined(GR64_REGNUM)
1466 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32)
1468 out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1469 out_msg_buf
->write_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1471 #endif /* GR64_REGNUM */
1472 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1474 out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1475 out_msg_buf
->write_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1477 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1479 out_msg_buf
->write_req_msg
.memory_space
= LOCAL_REG
;
1480 out_msg_buf
->write_req_msg
.address
= (regno
- LR0_REGNUM
);
1482 else if (regno
>= FPE_REGNUM
&& regno
<= EXO_REGNUM
)
1484 return 0; /* Pretend Success */
1487 /* An unprotected or protected special register */
1489 out_msg_buf
->write_req_msg
.memory_space
= SPECIAL_REG
;
1490 out_msg_buf
->write_req_msg
.address
= regnum_to_srnum (regno
);
1493 msg_send_serial (out_msg_buf
);
1495 if (expect_msg (WRITE_ACK
, in_msg_buf
, 1))
1505 /****************************************************************************/
1507 * Convert a gdb special register number to a 29000 special register number.
1510 regnum_to_srnum (int regno
)
1535 return (USE_SHADOW_PC
? (20) : (10));
1537 return (USE_SHADOW_PC
? (21) : (11));
1539 return (USE_SHADOW_PC
? (22) : (12));
1569 return (255); /* Failure ? */
1572 /****************************************************************************/
1574 * Initialize the target debugger (minimon only).
1577 init_target_mm (ADDR32 tstart
, ADDR32 tend
, ADDR32 dstart
, ADDR32 dend
,
1578 ADDR32 entry
, INT32 ms_size
, INT32 rs_size
, ADDR32 arg_start
)
1580 out_msg_buf
->init_msg
.code
= INIT
;
1581 out_msg_buf
->init_msg
.length
= sizeof (struct init_msg_t
) - 2 * sizeof (INT32
);
1582 out_msg_buf
->init_msg
.text_start
= tstart
;
1583 out_msg_buf
->init_msg
.text_end
= tend
;
1584 out_msg_buf
->init_msg
.data_start
= dstart
;
1585 out_msg_buf
->init_msg
.data_end
= dend
;
1586 out_msg_buf
->init_msg
.entry_point
= entry
;
1587 out_msg_buf
->init_msg
.mem_stack_size
= ms_size
;
1588 out_msg_buf
->init_msg
.reg_stack_size
= rs_size
;
1589 out_msg_buf
->init_msg
.arg_start
= arg_start
;
1590 msg_send_serial (out_msg_buf
);
1591 expect_msg (INIT_ACK
, in_msg_buf
, 1);
1593 /****************************************************************************/
1595 * Return a pointer to a string representing the given message code.
1596 * Not all messages are represented here, only the ones that we expect
1597 * to be called with.
1600 msg_str (INT32 code
)
1602 static char cbuf
[32];
1607 sprintf (cbuf
, "%s (%d)", "BKPT_SET_ACK", code
);
1610 sprintf (cbuf
, "%s (%d)", "BKPT_RM_ACK", code
);
1613 sprintf (cbuf
, "%s (%d)", "INIT_ACK", code
);
1616 sprintf (cbuf
, "%s (%d)", "READ_ACK", code
);
1619 sprintf (cbuf
, "%s (%d)", "WRITE_ACK", code
);
1622 sprintf (cbuf
, "%s (%d)", "ERROR", code
);
1625 sprintf (cbuf
, "%s (%d)", "HALT", code
);
1628 sprintf (cbuf
, "UNKNOWN (%d)", code
);
1633 /****************************************************************************/
1635 * Selected (not all of them) error codes that we might get.
1638 error_msg_str (INT32 code
)
1640 static char cbuf
[50];
1645 return ("EMFAIL: unrecoverable error");
1647 return ("EMBADADDR: Illegal address");
1649 return ("EMBADREG: Illegal register ");
1651 return ("EMACCESS: Could not access memory");
1653 return ("EMBADMSG: Unknown message type");
1655 return ("EMMSG2BIG: Message to large");
1657 return ("EMNOSEND: Could not send message");
1659 return ("EMNORECV: Could not recv message");
1661 return ("EMRESET: Could not RESET target");
1663 return ("EMCONFIG: Could not get target CONFIG");
1665 return ("EMSTATUS: Could not get target STATUS");
1667 return ("EMREAD: Could not READ target memory");
1669 return ("EMWRITE: Could not WRITE target memory");
1671 return ("EMBKPTSET: Could not set breakpoint");
1673 return ("EMBKPTRM: Could not remove breakpoint");
1675 return ("EMBKPTSTAT: Could not get breakpoint status");
1677 return ("EMBKPTNONE: All breakpoints in use");
1679 return ("EMBKPTUSED: Breakpoints already in use");
1681 return ("EMINIT: Could not init target memory");
1683 return ("EMGO: Could not start execution");
1685 return ("EMSTEP: Could not single step");
1687 return ("EMBREAK: Could not BREAK");
1689 return ("EMCOMMERR: Communication error");
1691 sprintf (cbuf
, "error number %d", code
);
1697 /****************************************************************************/
1699 /* Receive a message, placing it in MSG_BUF, and expect it to be of
1700 type MSGCODE. If an error occurs, a non-zero FROM_TTY indicates
1701 that the message should be printed.
1703 Return 0 for failure, 1 for success. */
1706 expect_msg (INT32 msgcode
, union msg_t
*msg_buf
, int from_tty
)
1709 while (msg_recv_serial (msg_buf
) && (retries
++ < MAX_RETRIES
));
1710 if (retries
>= MAX_RETRIES
)
1712 printf ("Expected msg %s, ", msg_str (msgcode
));
1713 printf ("no message received!\n");
1714 return (0); /* Failure */
1717 if (msg_buf
->generic_msg
.code
!= msgcode
)
1721 printf ("Expected msg %s, ", msg_str (msgcode
));
1722 printf ("got msg %s\n", msg_str (msg_buf
->generic_msg
.code
));
1723 if (msg_buf
->generic_msg
.code
== ERROR
)
1724 printf ("%s\n", error_msg_str (msg_buf
->error_msg
.error_code
));
1726 return (0); /* Failure */
1728 return (1); /* Success */
1730 /****************************************************************************/
1732 * Determine the MiniMon memory space qualifier based on the addr.
1733 * FIXME: Can't distinguis I_ROM/D_ROM.
1734 * FIXME: Doesn't know anything about I_CACHE/D_CACHE.
1737 mm_memory_space (CORE_ADDR
*addr
)
1739 ADDR32 tstart
= target_config
.I_mem_start
;
1740 ADDR32 tend
= tstart
+ target_config
.I_mem_size
;
1741 ADDR32 dstart
= target_config
.D_mem_start
;
1742 ADDR32 dend
= tstart
+ target_config
.D_mem_size
;
1743 ADDR32 rstart
= target_config
.ROM_start
;
1744 ADDR32 rend
= tstart
+ target_config
.ROM_size
;
1746 if (((ADDR32
) addr
>= tstart
) && ((ADDR32
) addr
< tend
))
1750 else if (((ADDR32
) addr
>= dstart
) && ((ADDR32
) addr
< dend
))
1754 else if (((ADDR32
) addr
>= rstart
) && ((ADDR32
) addr
< rend
))
1756 /* FIXME: how do we determine between D_ROM and I_ROM */
1759 else /* FIXME: what do me do now? */
1760 return D_MEM
; /* Hmmm! */
1763 /****************************************************************************/
1765 * Define the target subroutine names
1767 struct target_ops mm_ops
;
1772 mm_ops
.to_shortname
= "minimon";
1773 mm_ops
.to_longname
= "Remote AMD/Minimon target";
1774 mm_ops
.to_doc
= "Remote debug an AMD 290*0 using the MiniMon dbg core on the target";
1775 mm_ops
.to_open
= mm_open
;
1776 mm_ops
.to_close
= mm_close
;
1777 mm_ops
.to_attach
= mm_attach
;
1778 mm_ops
.to_post_attach
= NULL
;
1779 mm_ops
.to_require_attach
= NULL
;
1780 mm_ops
.to_detach
= mm_detach
;
1781 mm_ops
.to_require_detach
= NULL
;
1782 mm_ops
.to_resume
= mm_resume
;
1783 mm_ops
.to_wait
= mm_wait
;
1784 mm_ops
.to_post_wait
= NULL
;
1785 mm_ops
.to_fetch_registers
= mm_fetch_registers
;
1786 mm_ops
.to_store_registers
= mm_store_registers
;
1787 mm_ops
.to_prepare_to_store
= mm_prepare_to_store
;
1788 mm_ops
.to_xfer_memory
= mm_xfer_inferior_memory
;
1789 mm_ops
.to_files_info
= mm_files_info
;
1790 mm_ops
.to_insert_breakpoint
= mm_insert_breakpoint
;
1791 mm_ops
.to_remove_breakpoint
= mm_remove_breakpoint
;
1792 mm_ops
.to_terminal_init
= 0;
1793 mm_ops
.to_terminal_inferior
= 0;
1794 mm_ops
.to_terminal_ours_for_output
= 0;
1795 mm_ops
.to_terminal_ours
= 0;
1796 mm_ops
.to_terminal_info
= 0;
1797 mm_ops
.to_kill
= mm_kill
;
1798 mm_ops
.to_load
= mm_load
;
1799 mm_ops
.to_lookup_symbol
= 0;
1800 mm_ops
.to_create_inferior
= mm_create_inferior
;
1801 mm_ops
.to_post_startup_inferior
= NULL
;
1802 mm_ops
.to_acknowledge_created_inferior
= NULL
;
1803 mm_ops
.to_clone_and_follow_inferior
= NULL
;
1804 mm_ops
.to_post_follow_inferior_by_clone
= NULL
;
1805 mm_ops
.to_insert_fork_catchpoint
= NULL
;
1806 mm_ops
.to_remove_fork_catchpoint
= NULL
;
1807 mm_ops
.to_insert_vfork_catchpoint
= NULL
;
1808 mm_ops
.to_remove_vfork_catchpoint
= NULL
;
1809 mm_ops
.to_has_forked
= NULL
;
1810 mm_ops
.to_has_vforked
= NULL
;
1811 mm_ops
.to_can_follow_vfork_prior_to_exec
= NULL
;
1812 mm_ops
.to_post_follow_vfork
= NULL
;
1813 mm_ops
.to_insert_exec_catchpoint
= NULL
;
1814 mm_ops
.to_remove_exec_catchpoint
= NULL
;
1815 mm_ops
.to_has_execd
= NULL
;
1816 mm_ops
.to_reported_exec_events_per_exec_call
= NULL
;
1817 mm_ops
.to_has_exited
= NULL
;
1818 mm_ops
.to_mourn_inferior
= mm_mourn
;
1819 mm_ops
.to_can_run
= 0;
1820 mm_ops
.to_notice_signals
= 0;
1821 mm_ops
.to_thread_alive
= 0;
1823 mm_ops
.to_pid_to_exec_file
= NULL
;
1824 mm_ops
.to_stratum
= process_stratum
;
1825 mm_ops
.DONT_USE
= 0;
1826 mm_ops
.to_has_all_memory
= 1;
1827 mm_ops
.to_has_memory
= 1;
1828 mm_ops
.to_has_stack
= 1;
1829 mm_ops
.to_has_registers
= 1;
1830 mm_ops
.to_has_execution
= 1;
1831 mm_ops
.to_sections
= 0;
1832 mm_ops
.to_sections_end
= 0;
1833 mm_ops
.to_magic
= OPS_MAGIC
;
1837 _initialize_remote_mm (void)
1840 add_target (&mm_ops
);
1843 #ifdef NO_HIF_SUPPORT
1844 service_HIF (union msg_t
*msg
)
1846 return (0); /* Emulate a failure */