1 /* Remote debugging interface for Am290*0 running MiniMON monitor, for GDB.
2 Copyright 1990, 1991, 1992 Free Software Foundation, Inc.
3 Originally written by Daniel Mann at AMD.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This is like remote.c but ecpects MiniMON to be running on the Am29000
23 - David Wood (wood@lab.ultra.nyu.edu) at New York University adapted this
24 file to gdb 3.95. I was unable to get this working on sun3os4
25 with termio, only with sgtty. Because we are only attempting to
26 use this module to debug our kernel, which is already loaded when
27 gdb is started up, I did not code up the file downloading facilities.
28 As a result this module has only the stubs to download files.
29 You should get tagged at compile time if you need to make any
40 #include "gdb_string.h"
45 /* Offset of member MEMBER in a struct of type TYPE. */
46 #define offsetof(TYPE, MEMBER) ((int) &((TYPE *)0)->MEMBER)
48 #define DRAIN_INPUT() (msg_recv_serial((union msg_t*)0))
50 extern int stop_soon_quietly
; /* for wait_for_inferior */
52 static void mm_resume();
53 static void mm_fetch_registers ();
54 static int fetch_register ();
55 static void mm_store_registers ();
56 static int store_register ();
57 static int regnum_to_srnum();
58 static void mm_close ();
59 static char* msg_str();
60 static char* error_msg_str();
61 static int expect_msg();
62 static void init_target_mm();
63 static int mm_memory_space();
65 #define FREEZE_MODE (read_register(CPS_REGNUM) && 0x400)
66 #define USE_SHADOW_PC ((processor_type == a29k_freeze_mode) && FREEZE_MODE)
68 /* FIXME: Replace with `set remotedebug'. */
69 #define LLOG_FILE "minimon.log"
70 #if defined (LOG_FILE)
75 * Size of message buffers. I couldn't get memory reads to work when
76 * the byte_count was larger than 512 (it may be a baud rate problem).
78 #define BUFER_SIZE 512
80 * Size of data area in message buffer on the TARGET (remote system).
82 #define MAXDATA_T (target_config.max_msg_size - \
83 offsetof(struct write_r_msg_t,data[0]))
85 * Size of data area in message buffer on the HOST (gdb).
87 #define MAXDATA_H (BUFER_SIZE - offsetof(struct write_r_msg_t,data[0]))
89 * Defined as the minimum size of data areas of the two message buffers
91 #define MAXDATA (MAXDATA_H < MAXDATA_T ? MAXDATA_H : MAXDATA_T)
93 static char out_buf
[BUFER_SIZE
];
94 static char in_buf
[BUFER_SIZE
];
96 int msg_recv_serial();
97 int msg_send_serial();
99 #define MAX_RETRIES 5000
100 extern struct target_ops mm_ops
; /* Forward declaration */
101 struct config_msg_t target_config
; /* HIF needs this */
102 union msg_t
*out_msg_buf
= (union msg_t
*)out_buf
;
103 union msg_t
*in_msg_buf
= (union msg_t
*)in_buf
;
105 static int timeout
= 5;
107 /* Descriptor for I/O to remote machine. Initialize it to -1 so that
108 mm_open knows that we don't have a file open when the program
112 /* stream which is fdopen'd from mm_desc. Only valid when
116 /* Called when SIGALRM signal sent due to alarm() timeout. */
121 # define volatile /**/
124 volatile int n_alarms
;
131 printf ("mm_timer called\n");
135 #endif /* HAVE_TERMIO */
137 /* malloc'd name of the program on the remote system. */
138 static char *prog_name
= NULL
;
141 /* Number of SIGTRAPs we need to simulate. That is, the next
142 NEED_ARTIFICIAL_TRAP calls to mm_wait should just return
143 SIGTRAP without actually waiting for anything. */
145 /**************************************************** REMOTE_CREATE_INFERIOR */
146 /* This is called not only when we first attach, but also when the
147 user types "run" after having attached. */
149 mm_create_inferior (execfile
, args
, 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 exec file specified");
168 printf("Minimon not open yet.\n");
172 /* On ultra3 (NYU) we assume the kernel is already running so there is
174 FIXME: Fixed required here -> load your program, possibly with mm_load().
176 printf_filtered ("\n\
177 Assuming you are at NYU debuging a kernel, i.e., no need to download.\n\n");
179 /* We will get a task spawn event immediately. */
180 init_wait_for_inferior ();
181 clear_proceed_status ();
182 stop_soon_quietly
= 1;
183 proceed (-1, TARGET_SIGNAL_DEFAULT
, 0);
186 /**************************************************** REMOTE_MOURN_INFERIOR */
190 pop_target (); /* Pop back to no-child state */
191 generic_mourn_inferior ();
194 /********************************************************************** damn_b
196 /* Translate baud rates from integers to damn B_codes. Unix should
197 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
206 static struct {int rate
, damn_b
;} baudtab
[] = {
226 static int damn_b (rate
)
231 for (i
= 0; baudtab
[i
].rate
!= -1; i
++)
232 if (rate
== baudtab
[i
].rate
) return baudtab
[i
].damn_b
;
233 return B38400
; /* Random */
237 /***************************************************************** REMOTE_OPEN
238 ** Open a connection to remote minimon.
239 NAME is the filename used for communication, then a space,
241 'target adapt /dev/ttya 9600 [prognam]' for example.
244 static char *dev_name
;
247 mm_open (name
, from_tty
)
255 /* Find the first whitespace character, it separates dev_name from
258 p
&& *p
&& !isspace (*p
); p
++)
260 if (p
== 0 || *p
== '\0')
262 error ("Usage : <command> <serial-device> <baud-rate> [progname]");
263 dev_name
= (char*)malloc (p
- name
+ 1);
264 strncpy (dev_name
, name
, p
- name
);
265 dev_name
[p
- name
] = '\0';
267 /* Skip over the whitespace after dev_name */
268 for (; isspace (*p
); p
++)
271 if (1 != sscanf (p
, "%d ", &baudrate
))
274 /* Skip the number and then the spaces */
275 for (; isdigit (*p
); p
++)
277 for (; isspace (*p
); p
++)
280 if (prog_name
!= NULL
)
282 prog_name
= savestring (p
, strlen (p
));
288 mm_desc
= open (dev_name
, O_RDWR
);
290 perror_with_name (dev_name
);
291 ioctl (mm_desc
, TIOCGETP
, &sg
);
293 sg
.c_cc
[VMIN
] = 0; /* read with timeout. */
294 sg
.c_cc
[VTIME
] = timeout
* 10;
295 sg
.c_lflag
&= ~(ICANON
| ECHO
);
296 sg
.c_cflag
= (sg
.c_cflag
& ~CBAUD
) | damn_b (baudrate
);
298 sg
.sg_ispeed
= damn_b (baudrate
);
299 sg
.sg_ospeed
= damn_b (baudrate
);
302 sg
.sg_flags
&= ~ECHO
;
306 ioctl (mm_desc
, TIOCSETP
, &sg
);
307 mm_stream
= fdopen (mm_desc
, "r+");
309 push_target (&mm_ops
);
312 #ifndef NO_SIGINTERRUPT
313 /* Cause SIGALRM's to make reads fail with EINTR instead of resuming
315 if (siginterrupt (SIGALRM
, 1) != 0)
316 perror ("mm_open: error in siginterrupt");
319 /* Set up read timeout timer. */
320 if ((void (*)) signal (SIGALRM
, mm_timer
) == (void (*)) -1)
321 perror ("mm_open: error in signal");
324 #if defined (LOG_FILE)
325 log_file
= fopen (LOG_FILE
, "w");
326 if (log_file
== NULL
)
327 perror_with_name (LOG_FILE
);
330 ** Initialize target configuration structure (global)
333 out_msg_buf
->config_req_msg
.code
= CONFIG_REQ
;
334 out_msg_buf
->config_req_msg
.length
= 4*0;
335 msg_send_serial(out_msg_buf
); /* send config request message */
337 expect_msg(CONFIG
,in_msg_buf
,1);
339 a29k_get_processor_type ();
341 /* Print out some stuff, letting the user now what's going on */
342 printf_filtered("Connected to MiniMon via %s.\n", dev_name
);
343 /* FIXME: can this restriction be removed? */
344 printf_filtered("Remote debugging using virtual addresses works only\n");
345 printf_filtered("\twhen virtual addresses map 1:1 to physical addresses.\n")
347 if (processor_type
!= a29k_freeze_mode
) {
348 fprintf_filtered(stderr
,
349 "Freeze-mode debugging not available, and can only be done on an A29050.\n");
352 target_config
.code
= CONFIG
;
353 target_config
.length
= 0;
354 target_config
.processor_id
= in_msg_buf
->config_msg
.processor_id
;
355 target_config
.version
= in_msg_buf
->config_msg
.version
;
356 target_config
.I_mem_start
= in_msg_buf
->config_msg
.I_mem_start
;
357 target_config
.I_mem_size
= in_msg_buf
->config_msg
.I_mem_size
;
358 target_config
.D_mem_start
= in_msg_buf
->config_msg
.D_mem_start
;
359 target_config
.D_mem_size
= in_msg_buf
->config_msg
.D_mem_size
;
360 target_config
.ROM_start
= in_msg_buf
->config_msg
.ROM_start
;
361 target_config
.ROM_size
= in_msg_buf
->config_msg
.ROM_size
;
362 target_config
.max_msg_size
= in_msg_buf
->config_msg
.max_msg_size
;
363 target_config
.max_bkpts
= in_msg_buf
->config_msg
.max_bkpts
;
364 target_config
.coprocessor
= in_msg_buf
->config_msg
.coprocessor
;
365 target_config
.reserved
= in_msg_buf
->config_msg
.reserved
;
367 printf("Connected to MiniMON :\n");
368 printf(" Debugcore version %d.%d\n",
369 0x0f & (target_config
.version
>> 4),
370 0x0f & (target_config
.version
) );
371 printf(" Configuration version %d.%d\n",
372 0x0f & (target_config
.version
>> 12),
373 0x0f & (target_config
.version
>> 8) );
374 printf(" Message system version %d.%d\n",
375 0x0f & (target_config
.version
>> 20),
376 0x0f & (target_config
.version
>> 16) );
377 printf(" Communication driver version %d.%d\n",
378 0x0f & (target_config
.version
>> 28),
379 0x0f & (target_config
.version
>> 24) );
382 /* Leave the target running...
383 * The above message stopped the target in the dbg core (MiniMon),
384 * so restart the target out of MiniMon,
386 out_msg_buf
->go_msg
.code
= GO
;
387 out_msg_buf
->go_msg
.length
= 0;
388 msg_send_serial(out_msg_buf
);
389 /* No message to expect after a GO */
392 /**************************************************************** REMOTE_CLOSE
393 ** Close the open connection to the minimon debugger.
394 Use this when you want to detach and do something else
397 mm_close (quitting
) /*FIXME: how is quitting used */
401 error ("Can't close remote connection: not debugging remotely.");
403 /* We should never get here if there isn't something valid in
404 mm_desc and mm_stream.
406 Due to a bug in Unix, fclose closes not only the stdio stream,
407 but also the file descriptor. So we don't actually close
411 /* close (mm_desc); */
413 /* Do not try to close mm_desc again, later in the program. */
417 #if defined (LOG_FILE)
418 if (ferror (log_file
))
419 printf ("Error writing log file.\n");
420 if (fclose (log_file
) != 0)
421 printf ("Error closing log file.\n");
424 printf ("Ending remote debugging\n");
427 /************************************************************* REMOTE_ATACH */
428 /* Attach to a program that is already loaded and running
429 * Upon exiting the process's execution is stopped.
432 mm_attach (args
, from_tty
)
438 error ("MiniMon not opened yet, use the 'target minimon' command.\n");
441 printf ("Attaching to remote program %s...\n", prog_name
);
443 /* Make sure the target is currently running, it is supposed to be. */
444 /* FIXME: is it ok to send MiniMon a BREAK if it is already stopped in
445 * the dbg core. If so, we don't need to send this GO.
447 out_msg_buf
->go_msg
.code
= GO
;
448 out_msg_buf
->go_msg
.length
= 0;
449 msg_send_serial(out_msg_buf
);
450 sleep(2); /* At the worst it will stop, receive a message, continue */
452 /* Send the mm a break. */
453 out_msg_buf
->break_msg
.code
= BREAK
;
454 out_msg_buf
->break_msg
.length
= 0;
455 msg_send_serial(out_msg_buf
);
457 /********************************************************** REMOTE_DETACH */
458 /* Terminate the open connection to the remote debugger.
459 Use this when you want to detach and do something else
460 with your gdb. Leave remote process running (with no breakpoints set). */
462 mm_detach (args
,from_tty
)
466 remove_breakpoints(); /* Just in case there were any left in */
467 out_msg_buf
->go_msg
.code
= GO
;
468 out_msg_buf
->go_msg
.length
= 0;
469 msg_send_serial(out_msg_buf
);
470 pop_target(); /* calls mm_close to do the real work */
474 /*************************************************************** REMOTE_RESUME
475 ** Tell the remote machine to resume. */
478 mm_resume (pid
, step
, sig
)
480 enum target_signal sig
;
482 if (sig
!= TARGET_SIGNAL_0
)
483 warning ("Can't send signals to a remote MiniMon system.");
486 out_msg_buf
->step_msg
.code
= STEP
;
487 out_msg_buf
->step_msg
.length
= 1*4;
488 out_msg_buf
->step_msg
.count
= 1; /* step 1 instruction */
489 msg_send_serial(out_msg_buf
);
491 out_msg_buf
->go_msg
.code
= GO
;
492 out_msg_buf
->go_msg
.length
= 0;
493 msg_send_serial(out_msg_buf
);
497 /***************************************************************** REMOTE_WAIT
498 ** Wait until the remote machine stops, then return,
499 storing status in STATUS just as `wait' would. */
503 struct target_waitstatus
*status
;
506 int old_timeout
= timeout
;
507 int old_immediate_quit
= immediate_quit
;
509 status
->kind
= TARGET_WAITKIND_EXITED
;
510 status
->value
.integer
= 0;
512 /* wait for message to arrive. It should be:
513 - A HIF service request.
514 - A HIF exit service request.
516 - A CHANNEL1 request.
517 - a debugcore HALT message.
518 HIF services must be responded too, and while-looping continued.
519 If the target stops executing, mm_wait() should return.
521 timeout
= 0; /* Wait indefinetly for a message */
522 immediate_quit
= 1; /* Helps ability to QUIT */
525 while(msg_recv_serial(in_msg_buf
)) {
526 QUIT
; /* Let user quit if they want */
528 switch (in_msg_buf
->halt_msg
.code
)
531 i
= in_msg_buf
->hif_call_rtn_msg
.service_number
;
532 result
=service_HIF(in_msg_buf
);
533 if(i
== 1) /* EXIT */
536 printf("Warning: failure during HIF service %d\n", i
);
539 service_HIF(in_msg_buf
);
542 i
=in_msg_buf
->channel1_msg
.length
;
543 in_msg_buf
->channel1_msg
.data
[i
] = '\0';
544 printf("%s", in_msg_buf
->channel1_msg
.data
);
546 /* Send CHANNEL1_ACK message */
547 out_msg_buf
->channel1_ack_msg
.code
= CHANNEL1_ACK
;
548 out_msg_buf
->channel1_ack_msg
.length
= 0;
549 result
= msg_send_serial(out_msg_buf
);
558 /* FIXME, these printfs should not be here. This is a source level
560 if (in_msg_buf
->halt_msg
.trap_number
== 0)
561 { printf("Am290*0 received vector number %d (break point)\n",
562 in_msg_buf
->halt_msg
.trap_number
);
563 status
->kind
= TARGET_WAITKIND_STOPPED
;
564 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
566 else if (in_msg_buf
->halt_msg
.trap_number
== 1)
568 printf("Am290*0 received vector number %d\n",
569 in_msg_buf
->halt_msg
.trap_number
);
570 status
->kind
= TARGET_WAITKIND_STOPPED
;
571 status
->value
.sig
= TARGET_SIGNAL_BUS
;
573 else if (in_msg_buf
->halt_msg
.trap_number
== 3
574 || in_msg_buf
->halt_msg
.trap_number
== 4)
575 { printf("Am290*0 received vector number %d\n",
576 in_msg_buf
->halt_msg
.trap_number
);
577 status
->kind
= TARGET_WAITKIND_STOPPED
;
578 status
->value
.sig
= TARGET_SIGNAL_FPE
;
580 else if (in_msg_buf
->halt_msg
.trap_number
== 5)
581 { printf("Am290*0 received vector number %d\n",
582 in_msg_buf
->halt_msg
.trap_number
);
583 status
->kind
= TARGET_WAITKIND_STOPPED
;
584 status
->value
.sig
= TARGET_SIGNAL_ILL
;
586 else if (in_msg_buf
->halt_msg
.trap_number
>= 6
587 && in_msg_buf
->halt_msg
.trap_number
<= 11)
588 { printf("Am290*0 received vector number %d\n",
589 in_msg_buf
->halt_msg
.trap_number
);
590 status
->kind
= TARGET_WAITKIND_STOPPED
;
591 status
->value
.sig
= TARGET_SIGNAL_SEGV
;
593 else if (in_msg_buf
->halt_msg
.trap_number
== 12
594 || in_msg_buf
->halt_msg
.trap_number
== 13)
595 { printf("Am290*0 received vector number %d\n",
596 in_msg_buf
->halt_msg
.trap_number
);
597 status
->kind
= TARGET_WAITKIND_STOPPED
;
598 status
->value
.sig
= TARGET_SIGNAL_ILL
;
600 else if (in_msg_buf
->halt_msg
.trap_number
== 14)
601 { printf("Am290*0 received vector number %d\n",
602 in_msg_buf
->halt_msg
.trap_number
);
603 status
->kind
= TARGET_WAITKIND_STOPPED
;
604 status
->value
.sig
= TARGET_SIGNAL_ALRM
;
606 else if (in_msg_buf
->halt_msg
.trap_number
== 15)
608 status
->kind
= TARGET_WAITKIND_STOPPED
;
609 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
611 else if (in_msg_buf
->halt_msg
.trap_number
>= 16
612 && in_msg_buf
->halt_msg
.trap_number
<= 21)
613 { printf("Am290*0 received vector number %d\n",
614 in_msg_buf
->halt_msg
.trap_number
);
615 status
->kind
= TARGET_WAITKIND_STOPPED
;
616 status
->value
.sig
= TARGET_SIGNAL_INT
;
618 else if (in_msg_buf
->halt_msg
.trap_number
== 22)
619 { printf("Am290*0 received vector number %d\n",
620 in_msg_buf
->halt_msg
.trap_number
);
621 status
->kind
= TARGET_WAITKIND_STOPPED
;
622 status
->value
.sig
= TARGET_SIGNAL_ILL
;
623 } /* BREAK message was sent */
624 else if (in_msg_buf
->halt_msg
.trap_number
== 75)
626 status
->kind
= TARGET_WAITKIND_STOPPED
;
627 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
632 status
->kind
= TARGET_WAITKIND_EXITED
;
633 status
->value
.integer
= 0;
636 timeout
= old_timeout
; /* Restore original timeout value */
637 immediate_quit
= old_immediate_quit
;
641 /******************************************************* REMOTE_FETCH_REGISTERS
642 * Read a remote register 'regno'.
643 * If regno==-1 then read all the registers.
646 mm_fetch_registers (regno
)
652 fetch_register(regno
);
657 out_msg_buf
->read_req_msg
.byte_count
= 4*1;
658 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
659 out_msg_buf
->read_req_msg
.address
= 1;
660 msg_send_serial(out_msg_buf
);
661 expect_msg(READ_ACK
,in_msg_buf
,1);
662 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
663 supply_register (GR1_REGNUM
, data_p
);
665 #if defined(GR64_REGNUM) /* Read gr64-127 */
666 /* Global Registers gr64-gr95 */
667 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
668 out_msg_buf
->read_req_msg
.length
= 4*3;
669 out_msg_buf
->read_req_msg
.byte_count
= 4*32;
670 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
671 out_msg_buf
->read_req_msg
.address
= 64;
672 msg_send_serial(out_msg_buf
);
673 expect_msg(READ_ACK
,in_msg_buf
,1);
674 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
676 for (regno
=GR64_REGNUM
; regno
<GR64_REGNUM
+32; regno
++) {
677 supply_register (regno
, data_p
++);
679 #endif /* GR64_REGNUM */
681 /* Global Registers gr96-gr127 */
682 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
683 out_msg_buf
->read_req_msg
.length
= 4*3;
684 out_msg_buf
->read_req_msg
.byte_count
= 4 * 32;
685 out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
686 out_msg_buf
->read_req_msg
.address
= 96;
687 msg_send_serial(out_msg_buf
);
688 expect_msg(READ_ACK
,in_msg_buf
,1);
689 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
691 for (regno
=GR96_REGNUM
; regno
<GR96_REGNUM
+32; regno
++) {
692 supply_register (regno
, data_p
++);
695 /* Local Registers */
696 out_msg_buf
->read_req_msg
.byte_count
= 4 * (128);
697 out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
698 out_msg_buf
->read_req_msg
.address
= 0;
699 msg_send_serial(out_msg_buf
);
700 expect_msg(READ_ACK
,in_msg_buf
,1);
701 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
703 for (regno
=LR0_REGNUM
; regno
<LR0_REGNUM
+128; regno
++) {
704 supply_register (regno
, data_p
++);
707 /* Protected Special Registers */
708 out_msg_buf
->read_req_msg
.byte_count
= 4*15;
709 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
710 out_msg_buf
->read_req_msg
.address
= 0;
711 msg_send_serial( out_msg_buf
);
712 expect_msg(READ_ACK
,in_msg_buf
,1);
713 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
715 for (regno
=0; regno
<=14; regno
++) {
716 supply_register (SR_REGNUM(regno
), data_p
++);
718 if (USE_SHADOW_PC
) { /* Let regno_to_srnum() handle the register number */
719 fetch_register(NPC_REGNUM
);
720 fetch_register(PC_REGNUM
);
721 fetch_register(PC2_REGNUM
);
724 /* Unprotected Special Registers */
725 out_msg_buf
->read_req_msg
.byte_count
= 4*8;
726 out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
727 out_msg_buf
->read_req_msg
.address
= 128;
728 msg_send_serial( out_msg_buf
);
729 expect_msg(READ_ACK
,in_msg_buf
,1);
730 data_p
= &(in_msg_buf
->read_r_ack_msg
.data
[0]);
732 for (regno
=128; regno
<=135; regno
++) {
733 supply_register (SR_REGNUM(regno
), data_p
++);
736 /* There doesn't seem to be any way to get these. */
739 supply_register (FPE_REGNUM
, &val
);
740 supply_register (INTE_REGNUM
, &val
);
741 supply_register (FPS_REGNUM
, &val
);
742 supply_register (EXO_REGNUM
, &val
);
747 /****************************************************** REMOTE_STORE_REGISTERS
748 * Store register regno into the target.
749 * If regno==-1 then store all the registers.
750 * Result is 0 for success, -1 for failure.
754 mm_store_registers (regno
)
760 store_register(regno
);
766 out_msg_buf
->write_r_msg
.code
= WRITE_REQ
;
769 out_msg_buf
->write_r_msg
.byte_count
= 4*1;
770 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
771 out_msg_buf
->write_r_msg
.memory_space
= GLOBAL_REG
;
772 out_msg_buf
->write_r_msg
.address
= 1;
773 out_msg_buf
->write_r_msg
.data
[0] = read_register (GR1_REGNUM
);
775 msg_send_serial( out_msg_buf
);
776 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
780 #if defined(GR64_REGNUM)
781 /* Global registers gr64-gr95 */
782 out_msg_buf
->write_r_msg
.byte_count
= 4* (32);
783 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
784 out_msg_buf
->write_r_msg
.address
= 64;
786 for (regno
=GR64_REGNUM
; regno
<GR64_REGNUM
+32 ; regno
++)
788 out_msg_buf
->write_r_msg
.data
[regno
-GR64_REGNUM
] = read_register (regno
);
790 msg_send_serial(out_msg_buf
);
791 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
794 #endif /* GR64_REGNUM */
796 /* Global registers gr96-gr127 */
797 out_msg_buf
->write_r_msg
.byte_count
= 4* (32);
798 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
799 out_msg_buf
->write_r_msg
.address
= 96;
800 for (regno
=GR96_REGNUM
; regno
<GR96_REGNUM
+32 ; regno
++)
802 out_msg_buf
->write_r_msg
.data
[regno
-GR96_REGNUM
] = read_register (regno
);
804 msg_send_serial( out_msg_buf
);
805 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
809 /* Local Registers */
810 out_msg_buf
->write_r_msg
.memory_space
= LOCAL_REG
;
811 out_msg_buf
->write_r_msg
.byte_count
= 4*128;
812 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
813 out_msg_buf
->write_r_msg
.address
= 0;
815 for (regno
= LR0_REGNUM
; regno
< LR0_REGNUM
+128 ; regno
++)
817 out_msg_buf
->write_r_msg
.data
[regno
-LR0_REGNUM
] = read_register (regno
);
819 msg_send_serial( out_msg_buf
);
820 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
824 /* Protected Special Registers */
825 /* VAB through TMR */
826 out_msg_buf
->write_r_msg
.memory_space
= SPECIAL_REG
;
827 out_msg_buf
->write_r_msg
.byte_count
= 4* 10;
828 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
829 out_msg_buf
->write_r_msg
.address
= 0;
830 for (regno
= 0 ; regno
<=9 ; regno
++) /* VAB through TMR */
831 out_msg_buf
->write_r_msg
.data
[regno
] = read_register (SR_REGNUM(regno
));
832 msg_send_serial( out_msg_buf
);
833 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
837 /* PC0, PC1, PC2 possibly as shadow registers */
838 out_msg_buf
->write_r_msg
.byte_count
= 4* 3;
839 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
840 for (regno
=10 ; regno
<=12 ; regno
++) /* LRU and MMU */
841 out_msg_buf
->write_r_msg
.data
[regno
-10] = read_register (SR_REGNUM(regno
));
843 out_msg_buf
->write_r_msg
.address
= 20; /* SPC0 */
845 out_msg_buf
->write_r_msg
.address
= 10; /* PC0 */
846 msg_send_serial( out_msg_buf
);
847 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
852 out_msg_buf
->write_r_msg
.byte_count
= 4* 2;
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
= 13;
855 for (regno
=13 ; regno
<=14 ; regno
++) /* LRU and MMU */
856 out_msg_buf
->write_r_msg
.data
[regno
-13] = read_register (SR_REGNUM(regno
));
857 msg_send_serial( out_msg_buf
);
858 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
862 /* Unprotected Special Registers */
863 out_msg_buf
->write_r_msg
.byte_count
= 4*8;
864 out_msg_buf
->write_r_msg
.length
= 3*4 + out_msg_buf
->write_r_msg
.byte_count
;
865 out_msg_buf
->write_r_msg
.address
= 128;
866 for (regno
= 128 ; regno
<=135 ; regno
++)
867 out_msg_buf
->write_r_msg
.data
[regno
-128] = read_register(SR_REGNUM(regno
));
868 msg_send_serial( out_msg_buf
);
869 if (!expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
873 registers_changed ();
876 /*************************************************** REMOTE_PREPARE_TO_STORE */
877 /* Get ready to modify the registers array. On machines which store
878 individual registers, this doesn't need to do anything. On machines
879 which store all the registers in one fell swoop, this makes sure
880 that registers contains all the registers from the program being
884 mm_prepare_to_store ()
886 /* Do nothing, since we can store individual regs */
889 /******************************************************* REMOTE_XFER_MEMORY */
894 #if defined(KERNEL_DEBUGGING)
895 /* Check for a virtual address in the kernel */
896 /* Assume physical address of ublock is in paddr_u register */
897 /* FIXME: doesn't work for user virtual addresses */
898 if (addr
>= UVADDR
) {
899 /* PADDR_U register holds the physical address of the ublock */
900 CORE_ADDR i
= (CORE_ADDR
)read_register(PADDR_U_REGNUM
);
901 return(i
+ addr
- (CORE_ADDR
)UVADDR
);
910 /******************************************************* REMOTE_FILES_INFO */
914 printf ("\tAttached to %s at %d baud and running program %s.\n",
915 dev_name
, baudrate
, prog_name
);
918 /************************************************* REMOTE_INSERT_BREAKPOINT */
920 mm_insert_breakpoint (addr
, contents_cache
)
922 char *contents_cache
;
924 out_msg_buf
->bkpt_set_msg
.code
= BKPT_SET
;
925 out_msg_buf
->bkpt_set_msg
.length
= 4*4;
926 out_msg_buf
->bkpt_set_msg
.memory_space
= I_MEM
;
927 out_msg_buf
->bkpt_set_msg
.bkpt_addr
= (ADDR32
) addr
;
928 out_msg_buf
->bkpt_set_msg
.pass_count
= 1;
929 out_msg_buf
->bkpt_set_msg
.bkpt_type
= -1; /* use illop for 29000 */
930 msg_send_serial( out_msg_buf
);
931 if (expect_msg(BKPT_SET_ACK
,in_msg_buf
,1)) {
932 return 0; /* Success */
934 return 1; /* Failure */
938 /************************************************* REMOTE_DELETE_BREAKPOINT */
940 mm_remove_breakpoint (addr
, contents_cache
)
942 char *contents_cache
;
944 out_msg_buf
->bkpt_rm_msg
.code
= BKPT_RM
;
945 out_msg_buf
->bkpt_rm_msg
.length
= 4*3;
946 out_msg_buf
->bkpt_rm_msg
.memory_space
= I_MEM
;
947 out_msg_buf
->bkpt_rm_msg
.bkpt_addr
= (ADDR32
) addr
;
948 msg_send_serial( out_msg_buf
);
949 if (expect_msg(BKPT_RM_ACK
,in_msg_buf
,1)) {
950 return 0; /* Success */
952 return 1; /* Failure */
957 /******************************************************* REMOTE_KILL */
959 mm_kill(arg
,from_tty
)
965 #if defined(KERNEL_DEBUGGING)
966 /* We don't ever kill the kernel */
968 printf("Kernel not killed, but left in current state.\n");
969 printf("Use detach to leave kernel running.\n");
972 out_msg_buf
->break_msg
.code
= BREAK
;
973 out_msg_buf
->bkpt_set_msg
.length
= 4*0;
974 expect_msg(HALT
,in_msg_buf
,from_tty
);
976 printf("Target has been stopped.");
977 printf("Would you like to do a hardware reset (y/n) [n] ");
980 out_msg_buf
->reset_msg
.code
= RESET
;
981 out_msg_buf
->bkpt_set_msg
.length
= 4*0;
982 expect_msg(RESET_ACK
,in_msg_buf
,from_tty
);
983 printf("Target has been reset.");
992 /***************************************************************************/
994 * Load a program into the target.
997 mm_load(arg_string
,from_tty
)
1003 #if defined(KERNEL_DEBUGGING)
1004 printf("The kernel had better be loaded already! Loading not done.\n");
1006 if (arg_string
== 0)
1007 error ("The load command takes a file name");
1009 arg_string
= tilde_expand (arg_string
);
1010 make_cleanup (free
, arg_string
);
1013 error("File loading is not yet supported for MiniMon.");
1014 /* FIXME, code to load your file here... */
1015 /* You may need to do an init_target_mm() */
1016 /* init_target_mm(?,?,?,?,?,?,?,?); */
1018 /* symbol_file_add (arg_string, from_tty, text_addr, 0, 0); */
1023 /************************************************ REMOTE_WRITE_INFERIOR_MEMORY
1024 ** Copy LEN bytes of data from debugger memory at MYADDR
1025 to inferior's memory at MEMADDR. Returns number of bytes written. */
1027 mm_write_inferior_memory (memaddr
, myaddr
, len
)
1034 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1035 out_msg_buf
->write_req_msg
.memory_space
= mm_memory_space(memaddr
);
1038 while (nwritten
< len
) {
1039 int num_to_write
= len
- nwritten
;
1040 if (num_to_write
> MAXDATA
) num_to_write
= MAXDATA
;
1041 for (i
=0 ; i
< num_to_write
; i
++)
1042 out_msg_buf
->write_req_msg
.data
[i
] = myaddr
[i
+nwritten
];
1043 out_msg_buf
->write_req_msg
.byte_count
= num_to_write
;
1044 out_msg_buf
->write_req_msg
.length
= 3*4 + num_to_write
;
1045 out_msg_buf
->write_req_msg
.address
= memaddr
+ nwritten
;
1046 msg_send_serial(out_msg_buf
);
1048 if (expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
1049 nwritten
+= in_msg_buf
->write_ack_msg
.byte_count
;
1057 /************************************************* REMOTE_READ_INFERIOR_MEMORY
1058 ** Read LEN bytes from inferior memory at MEMADDR. Put the result
1059 at debugger address MYADDR. Returns number of bytes read. */
1061 mm_read_inferior_memory(memaddr
, myaddr
, len
)
1068 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1069 out_msg_buf
->read_req_msg
.memory_space
= mm_memory_space(memaddr
);
1072 while (nread
< len
) {
1073 int num_to_read
= (len
- nread
);
1074 if (num_to_read
> MAXDATA
) num_to_read
= MAXDATA
;
1075 out_msg_buf
->read_req_msg
.byte_count
= num_to_read
;
1076 out_msg_buf
->read_req_msg
.length
= 3*4 + num_to_read
;
1077 out_msg_buf
->read_req_msg
.address
= memaddr
+ nread
;
1078 msg_send_serial(out_msg_buf
);
1080 if (expect_msg(READ_ACK
,in_msg_buf
,1)) {
1081 for (i
=0 ; i
<in_msg_buf
->read_ack_msg
.byte_count
; i
++)
1082 myaddr
[i
+nread
] = in_msg_buf
->read_ack_msg
.data
[i
];
1083 nread
+= in_msg_buf
->read_ack_msg
.byte_count
;
1091 /* FIXME! Merge these two. */
1093 mm_xfer_inferior_memory (memaddr
, myaddr
, len
, write
)
1100 memaddr
= translate_addr(memaddr
);
1103 return mm_write_inferior_memory (memaddr
, myaddr
, len
);
1105 return mm_read_inferior_memory (memaddr
, myaddr
, len
);
1109 /********************************************************** MSG_SEND_SERIAL
1110 ** This function is used to send a message over the
1113 ** If the message is successfully sent, a zero is
1114 ** returned. If the message was not sendable, a -1
1115 ** is returned. This function blocks. That is, it
1116 ** does not return until the message is completely
1117 ** sent, or until an error is encountered.
1122 msg_send_serial(msg_ptr
)
1123 union msg_t
*msg_ptr
;
1130 /* Send message header */
1132 message_size
= msg_ptr
->generic_msg
.length
+ (2 * sizeof(INT32
));
1134 c
= *((char *)msg_ptr
+byte_count
);
1135 result
= write(mm_desc
, &c
, 1);
1137 byte_count
= byte_count
+ 1;
1139 } while ((byte_count
< message_size
) );
1142 } /* end msg_send_serial() */
1144 /********************************************************** MSG_RECV_SERIAL
1145 ** This function is used to receive a message over a
1148 ** If the message is waiting in the buffer, a zero is
1149 ** returned and the buffer pointed to by msg_ptr is filled
1150 ** in. If no message was available, a -1 is returned.
1151 ** If timeout==0, wait indefinetly for a character.
1156 msg_recv_serial(msg_ptr
)
1157 union msg_t
*msg_ptr
;
1159 static INT32 length
=0;
1160 static INT32 byte_count
=0;
1163 if(msg_ptr
== 0) /* re-sync request */
1167 /* The timeout here is the prevailing timeout set with VTIME */
1168 ->"timeout==0 semantics not supported"
1169 read(mm_desc
, in_buf
, BUFER_SIZE
);
1172 read(mm_desc
, in_buf
, BUFER_SIZE
);
1177 /* Receive message */
1179 /* Timeout==0, help support the mm_wait() routine */
1180 ->"timeout==0 semantics not supported (and its nice if they are)"
1181 result
= read(mm_desc
, &c
, 1);
1184 result
= read(mm_desc
, &c
, 1);
1188 if (errno
== EINTR
) {
1189 error ("Timeout reading from remote system.");
1191 perror_with_name ("remote");
1192 } else if (result
== 1) {
1193 *((char *)msg_ptr
+byte_count
) = c
;
1194 byte_count
= byte_count
+ 1;
1197 /* Message header received. Save message length. */
1198 if (byte_count
== (2 * sizeof(INT32
)))
1199 length
= msg_ptr
->generic_msg
.length
;
1201 if (byte_count
>= (length
+ (2 * sizeof(INT32
)))) {
1202 /* Message received */
1208 } /* end msg_recv_serial() */
1210 /********************************************************************* KBD_RAW
1211 ** This function is used to put the keyboard in "raw"
1212 ** mode for BSD Unix. The original status is saved
1213 ** so that it may be restored later.
1222 /* Get keyboard termio (to save to restore original modes) */
1224 result
= ioctl(0, TCGETA
, &kbd_tbuf
);
1226 result
= ioctl(0, TIOCGETP
, &kbd_tbuf
);
1231 /* Get keyboard TERMINAL (for modification) */
1233 result
= ioctl(0, TCGETA
, &tbuf
);
1235 result
= ioctl(0, TIOCGETP
, &tbuf
);
1240 /* Set up new parameters */
1242 tbuf
.c_iflag
= tbuf
.c_iflag
&
1243 ~(INLCR
| ICRNL
| IUCLC
| ISTRIP
| IXON
| BRKINT
);
1244 tbuf
.c_lflag
= tbuf
.c_lflag
& ~(ICANON
| ISIG
| ECHO
);
1245 tbuf
.c_cc
[4] = 0; /* MIN */
1246 tbuf
.c_cc
[5] = 0; /* TIME */
1248 /* FIXME: not sure if this is correct (matches HAVE_TERMIO). */
1249 tbuf
.sg_flags
|= RAW
;
1250 tbuf
.sg_flags
|= ANYP
;
1251 tbuf
.sg_flags
&= ~ECHO
;
1254 /* Set keyboard termio to new mode (RAW) */
1256 result
= ioctl(0, TCSETAF
, &tbuf
);
1258 result
= ioctl(0, TIOCSETP
, &tbuf
);
1264 } /* end kbd_raw() */
1268 /***************************************************************** KBD_RESTORE
1269 ** This function is used to put the keyboard back in the
1270 ** mode it was in before kbk_raw was called. Note that
1271 ** kbk_raw() must have been called at least once before
1272 ** kbd_restore() is called.
1279 /* Set keyboard termio to original mode */
1281 result
= ioctl(0, TCSETAF
, &kbd_tbuf
);
1283 result
= ioctl(0, TIOCGETP
, &kbd_tbuf
);
1290 } /* end kbd_cooked() */
1293 /*****************************************************************************/
1294 /* Fetch a single register indicatated by 'regno'.
1295 * Returns 0/-1 on success/failure.
1298 fetch_register (regno
)
1302 out_msg_buf
->read_req_msg
.code
= READ_REQ
;
1303 out_msg_buf
->read_req_msg
.length
= 4*3;
1304 out_msg_buf
->read_req_msg
.byte_count
= 4;
1306 if (regno
== GR1_REGNUM
)
1307 { out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1308 out_msg_buf
->read_req_msg
.address
= 1;
1310 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1311 { out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1312 out_msg_buf
->read_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1314 #if defined(GR64_REGNUM)
1315 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32 )
1316 { out_msg_buf
->read_req_msg
.memory_space
= GLOBAL_REG
;
1317 out_msg_buf
->read_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1319 #endif /* GR64_REGNUM */
1320 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1321 { out_msg_buf
->read_req_msg
.memory_space
= LOCAL_REG
;
1322 out_msg_buf
->read_req_msg
.address
= (regno
- LR0_REGNUM
);
1324 else if (regno
>=FPE_REGNUM
&& regno
<=EXO_REGNUM
)
1326 supply_register(160 + (regno
- FPE_REGNUM
),&val
);
1327 return 0; /* Pretend Success */
1330 { out_msg_buf
->read_req_msg
.memory_space
= SPECIAL_REG
;
1331 out_msg_buf
->read_req_msg
.address
= regnum_to_srnum(regno
);
1334 msg_send_serial(out_msg_buf
);
1336 if (expect_msg(READ_ACK
,in_msg_buf
,1)) {
1337 supply_register (regno
, &(in_msg_buf
->read_r_ack_msg
.data
[0]));
1344 /*****************************************************************************/
1345 /* Store a single register indicated by 'regno'.
1346 * Returns 0/-1 on success/failure.
1349 store_register (regno
)
1354 out_msg_buf
->write_req_msg
.code
= WRITE_REQ
;
1355 out_msg_buf
->write_req_msg
.length
= 4*4;
1356 out_msg_buf
->write_req_msg
.byte_count
= 4;
1357 out_msg_buf
->write_r_msg
.data
[0] = read_register (regno
);
1359 if (regno
== GR1_REGNUM
)
1360 { out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1361 out_msg_buf
->write_req_msg
.address
= 1;
1362 /* Setting GR1 changes the numbers of all the locals, so invalidate the
1363 * register cache. Do this *after* calling read_register, because we want
1364 * read_register to return the value that write_register has just stuffed
1365 * into the registers array, not the value of the register fetched from
1368 registers_changed ();
1370 #if defined(GR64_REGNUM)
1371 else if (regno
>= GR64_REGNUM
&& regno
< GR64_REGNUM
+ 32 )
1372 { out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1373 out_msg_buf
->write_req_msg
.address
= (regno
- GR64_REGNUM
) + 64;
1375 #endif /* GR64_REGNUM */
1376 else if (regno
>= GR96_REGNUM
&& regno
< GR96_REGNUM
+ 32)
1377 { out_msg_buf
->write_req_msg
.memory_space
= GLOBAL_REG
;
1378 out_msg_buf
->write_req_msg
.address
= (regno
- GR96_REGNUM
) + 96;
1380 else if (regno
>= LR0_REGNUM
&& regno
< LR0_REGNUM
+ 128)
1381 { out_msg_buf
->write_req_msg
.memory_space
= LOCAL_REG
;
1382 out_msg_buf
->write_req_msg
.address
= (regno
- LR0_REGNUM
);
1384 else if (regno
>=FPE_REGNUM
&& regno
<=EXO_REGNUM
)
1386 return 0; /* Pretend Success */
1388 else /* An unprotected or protected special register */
1389 { out_msg_buf
->write_req_msg
.memory_space
= SPECIAL_REG
;
1390 out_msg_buf
->write_req_msg
.address
= regnum_to_srnum(regno
);
1393 msg_send_serial(out_msg_buf
);
1395 if (expect_msg(WRITE_ACK
,in_msg_buf
,1)) {
1402 /****************************************************************************/
1404 * Convert a gdb special register number to a 29000 special register number.
1407 regnum_to_srnum(regno
)
1411 case VAB_REGNUM
: return(0);
1412 case OPS_REGNUM
: return(1);
1413 case CPS_REGNUM
: return(2);
1414 case CFG_REGNUM
: return(3);
1415 case CHA_REGNUM
: return(4);
1416 case CHD_REGNUM
: return(5);
1417 case CHC_REGNUM
: return(6);
1418 case RBP_REGNUM
: return(7);
1419 case TMC_REGNUM
: return(8);
1420 case TMR_REGNUM
: return(9);
1421 case NPC_REGNUM
: return(USE_SHADOW_PC
? (20) : (10));
1422 case PC_REGNUM
: return(USE_SHADOW_PC
? (21) : (11));
1423 case PC2_REGNUM
: return(USE_SHADOW_PC
? (22) : (12));
1424 case MMU_REGNUM
: return(13);
1425 case LRU_REGNUM
: return(14);
1426 case IPC_REGNUM
: return(128);
1427 case IPA_REGNUM
: return(129);
1428 case IPB_REGNUM
: return(130);
1429 case Q_REGNUM
: return(131);
1430 case ALU_REGNUM
: return(132);
1431 case BP_REGNUM
: return(133);
1432 case FC_REGNUM
: return(134);
1433 case CR_REGNUM
: return(135);
1434 case FPE_REGNUM
: return(160);
1435 case INTE_REGNUM
: return(161);
1436 case FPS_REGNUM
: return(162);
1437 case EXO_REGNUM
:return(164);
1439 return(255); /* Failure ? */
1442 /****************************************************************************/
1444 * Initialize the target debugger (minimon only).
1447 init_target_mm(tstart
,tend
,dstart
,dend
,entry
,ms_size
,rs_size
,arg_start
)
1448 ADDR32 tstart
,tend
,dstart
,dend
,entry
;
1449 INT32 ms_size
,rs_size
;
1452 out_msg_buf
->init_msg
.code
= INIT
;
1453 out_msg_buf
->init_msg
.length
= sizeof(struct init_msg_t
)-2*sizeof(INT32
);
1454 out_msg_buf
->init_msg
.text_start
= tstart
;
1455 out_msg_buf
->init_msg
.text_end
= tend
;
1456 out_msg_buf
->init_msg
.data_start
= dstart
;
1457 out_msg_buf
->init_msg
.data_end
= dend
;
1458 out_msg_buf
->init_msg
.entry_point
= entry
;
1459 out_msg_buf
->init_msg
.mem_stack_size
= ms_size
;
1460 out_msg_buf
->init_msg
.reg_stack_size
= rs_size
;
1461 out_msg_buf
->init_msg
.arg_start
= arg_start
;
1462 msg_send_serial(out_msg_buf
);
1463 expect_msg(INIT_ACK
,in_msg_buf
,1);
1465 /****************************************************************************/
1467 * Return a pointer to a string representing the given message code.
1468 * Not all messages are represented here, only the ones that we expect
1469 * to be called with.
1475 static char cbuf
[32];
1478 case BKPT_SET_ACK
: sprintf(cbuf
,"%s (%d)","BKPT_SET_ACK",code
); break;
1479 case BKPT_RM_ACK
: sprintf(cbuf
,"%s (%d)","BKPT_RM_ACK",code
); break;
1480 case INIT_ACK
: sprintf(cbuf
,"%s (%d)","INIT_ACK",code
); break;
1481 case READ_ACK
: sprintf(cbuf
,"%s (%d)","READ_ACK",code
); break;
1482 case WRITE_ACK
: sprintf(cbuf
,"%s (%d)","WRITE_ACK",code
); break;
1483 case ERROR
: sprintf(cbuf
,"%s (%d)","ERROR",code
); break;
1484 case HALT
: sprintf(cbuf
,"%s (%d)","HALT",code
); break;
1485 default: sprintf(cbuf
,"UNKNOWN (%d)",code
); break;
1489 /****************************************************************************/
1491 * Selected (not all of them) error codes that we might get.
1497 static char cbuf
[50];
1500 case EMFAIL
: return("EMFAIL: unrecoverable error");
1501 case EMBADADDR
: return("EMBADADDR: Illegal address");
1502 case EMBADREG
: return("EMBADREG: Illegal register ");
1503 case EMACCESS
: return("EMACCESS: Could not access memory");
1504 case EMBADMSG
: return("EMBADMSG: Unknown message type");
1505 case EMMSG2BIG
: return("EMMSG2BIG: Message to large");
1506 case EMNOSEND
: return("EMNOSEND: Could not send message");
1507 case EMNORECV
: return("EMNORECV: Could not recv message");
1508 case EMRESET
: return("EMRESET: Could not RESET target");
1509 case EMCONFIG
: return("EMCONFIG: Could not get target CONFIG");
1510 case EMSTATUS
: return("EMSTATUS: Could not get target STATUS");
1511 case EMREAD
: return("EMREAD: Could not READ target memory");
1512 case EMWRITE
: return("EMWRITE: Could not WRITE target memory");
1513 case EMBKPTSET
: return("EMBKPTSET: Could not set breakpoint");
1514 case EMBKPTRM
: return("EMBKPTRM: Could not remove breakpoint");
1515 case EMBKPTSTAT
:return("EMBKPTSTAT: Could not get breakpoint status");
1516 case EMBKPTNONE
:return("EMBKPTNONE: All breakpoints in use");
1517 case EMBKPTUSED
:return("EMBKPTUSED: Breakpoints already in use");
1518 case EMINIT
: return("EMINIT: Could not init target memory");
1519 case EMGO
: return("EMGO: Could not start execution");
1520 case EMSTEP
: return("EMSTEP: Could not single step");
1521 case EMBREAK
: return("EMBREAK: Could not BREAK");
1522 case EMCOMMERR
: return("EMCOMMERR: Communication error");
1523 default: sprintf(cbuf
,"error number %d",code
); break;
1528 /****************************************************************************/
1530 * Receive a message and expect it to be of type msgcode.
1531 * Returns 0/1 on failure/success.
1534 expect_msg(msgcode
,msg_buf
,from_tty
)
1535 INT32 msgcode
; /* Msg code we expect */
1536 union msg_t
*msg_buf
; /* Where to put the message received */
1537 int from_tty
; /* Print message on error if non-zero */
1540 while(msg_recv_serial(msg_buf
) && (retries
++<MAX_RETRIES
));
1541 if (retries
>= MAX_RETRIES
) {
1542 printf("Expected msg %s, ",msg_str(msgcode
));
1543 printf("no message received!\n");
1544 return(0); /* Failure */
1547 if (msg_buf
->generic_msg
.code
!= msgcode
) {
1549 printf("Expected msg %s, ",msg_str(msgcode
));
1550 printf("got msg %s\n",msg_str(msg_buf
->generic_msg
.code
));
1551 if (msg_buf
->generic_msg
.code
== ERROR
)
1552 printf("%s\n",error_msg_str(msg_buf
->error_msg
.error_code
));
1554 return(0); /* Failure */
1556 return(1); /* Success */
1558 /****************************************************************************/
1560 * Determine the MiniMon memory space qualifier based on the addr.
1561 * FIXME: Can't distinguis I_ROM/D_ROM.
1562 * FIXME: Doesn't know anything about I_CACHE/D_CACHE.
1565 mm_memory_space(addr
)
1568 ADDR32 tstart
= target_config
.I_mem_start
;
1569 ADDR32 tend
= tstart
+ target_config
.I_mem_size
;
1570 ADDR32 dstart
= target_config
.D_mem_start
;
1571 ADDR32 dend
= tstart
+ target_config
.D_mem_size
;
1572 ADDR32 rstart
= target_config
.ROM_start
;
1573 ADDR32 rend
= tstart
+ target_config
.ROM_size
;
1575 if (((ADDR32
)addr
>= tstart
) && ((ADDR32
)addr
< tend
)) {
1577 } else if (((ADDR32
)addr
>= dstart
) && ((ADDR32
)addr
< dend
)) {
1579 } else if (((ADDR32
)addr
>= rstart
) && ((ADDR32
)addr
< rend
)) {
1580 /* FIXME: how do we determine between D_ROM and I_ROM */
1582 } else /* FIXME: what do me do now? */
1583 return D_MEM
; /* Hmmm! */
1586 /****************************************************************************/
1588 * Define the target subroutine names
1590 struct target_ops mm_ops
= {
1591 "minimon", "Remote AMD/Minimon target",
1592 "Remote debug an AMD 290*0 using the MiniMon dbg core on the target",
1594 mm_attach
, mm_detach
, mm_resume
, mm_wait
,
1595 mm_fetch_registers
, mm_store_registers
,
1596 mm_prepare_to_store
,
1597 mm_xfer_inferior_memory
,
1599 mm_insert_breakpoint
, mm_remove_breakpoint
, /* Breakpoints */
1600 0, 0, 0, 0, 0, /* Terminal handling */
1601 mm_kill
, /* FIXME, kill */
1603 0, /* lookup_symbol */
1604 mm_create_inferior
, /* create_inferior */
1605 mm_mourn
, /* mourn_inferior FIXME */
1607 0, /* notice_signals */
1609 process_stratum
, 0, /* next */
1610 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
1611 0,0, /* sections, sections_end */
1612 OPS_MAGIC
, /* Always the last thing */
1616 _initialize_remote_mm()
1618 add_target (&mm_ops
);
1621 #ifdef NO_HIF_SUPPORT
1625 return(0); /* Emulate a failure */