1 /* Remote debugging interface for MIPS remote debugging protocol.
2 Copyright 1993, 1994, 1995 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Ian Lance Taylor
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, Boston, MA 02111-1307, USA. */
31 #include "remote-utils.h"
32 #include "gdb_string.h"
35 #include <sys/types.h>
37 #ifdef ANSI_PROTOTYPES
43 /* Microsoft C's stat.h doesn't define all the POSIX file modes. */
45 #define S_IROTH S_IREAD
48 extern void mips_set_processor_type_command
PARAMS ((char *, int));
51 /* Prototypes for local functions. */
53 static int mips_readchar
PARAMS ((int timeout
));
55 static int mips_receive_header
PARAMS ((unsigned char *hdr
, int *pgarbage
,
56 int ch
, int timeout
));
58 static int mips_receive_trailer
PARAMS ((unsigned char *trlr
, int *pgarbage
,
59 int *pch
, int timeout
));
61 static int mips_cksum
PARAMS ((const unsigned char *hdr
,
62 const unsigned char *data
,
65 static void mips_send_packet
PARAMS ((const char *s
, int get_ack
));
67 static void mips_send_command
PARAMS ((const char *cmd
, int prompt
));
69 static int mips_receive_packet
PARAMS ((char *buff
, int throw_error
,
72 static CORE_ADDR mips_request
PARAMS ((int cmd
, CORE_ADDR addr
,
73 CORE_ADDR data
, int *perr
, int timeout
,
76 static void mips_initialize
PARAMS ((void));
78 static void mips_open
PARAMS ((char *name
, int from_tty
));
80 static void pmon_open
PARAMS ((char *name
, int from_tty
));
82 static void ddb_open
PARAMS ((char *name
, int from_tty
));
84 static void lsi_open
PARAMS ((char *name
, int from_tty
));
86 static void mips_close
PARAMS ((int quitting
));
88 static void mips_detach
PARAMS ((char *args
, int from_tty
));
90 static void mips_resume
PARAMS ((int pid
, int step
,
91 enum target_signal siggnal
));
93 static int mips_wait
PARAMS ((int pid
, struct target_waitstatus
*status
));
95 static int pmon_wait
PARAMS ((int pid
, struct target_waitstatus
*status
));
97 static int mips_map_regno
PARAMS ((int regno
));
99 static void mips_fetch_registers
PARAMS ((int regno
));
101 static void mips_prepare_to_store
PARAMS ((void));
103 static void mips_store_registers
PARAMS ((int regno
));
105 static unsigned int mips_fetch_word
PARAMS ((CORE_ADDR addr
));
107 static int mips_store_word
PARAMS ((CORE_ADDR addr
, unsigned int value
,
108 char *old_contents
));
110 static int mips_xfer_memory
PARAMS ((CORE_ADDR memaddr
, char *myaddr
, int len
,
111 int write
, struct target_ops
*ignore
));
113 static void mips_files_info
PARAMS ((struct target_ops
*ignore
));
115 static void mips_create_inferior
PARAMS ((char *execfile
, char *args
,
118 static void mips_mourn_inferior
PARAMS ((void));
120 static int pmon_makeb64
PARAMS ((unsigned long v
, char *p
, int n
, int *chksum
));
122 static int pmon_zeroset
PARAMS ((int recsize
, char **buff
, int *amount
,
123 unsigned int *chksum
));
125 static int pmon_checkset
PARAMS ((int recsize
, char **buff
, int *value
));
127 static void pmon_make_fastrec
PARAMS ((char **outbuf
, unsigned char *inbuf
,
128 int *inptr
, int inamount
, int *recsize
,
129 unsigned int *csum
, unsigned int *zerofill
));
131 static int pmon_check_ack
PARAMS ((char *mesg
));
133 static void pmon_start_download
PARAMS ((void));
135 static void pmon_end_download
PARAMS ((int final
, int bintotal
));
137 static void pmon_download
PARAMS ((char *buffer
, int length
));
139 static void pmon_load_fast
PARAMS ((char *file
));
141 static void mips_load
PARAMS ((char *file
, int from_tty
));
143 static int mips_make_srec
PARAMS ((char *buffer
, int type
, CORE_ADDR memaddr
,
144 unsigned char *myaddr
, int len
));
146 static int common_breakpoint
PARAMS ((int cmd
, CORE_ADDR addr
, CORE_ADDR mask
,
149 /* Forward declarations. */
150 extern struct target_ops mips_ops
;
151 extern struct target_ops pmon_ops
;
152 extern struct target_ops ddb_ops
;
154 /* The MIPS remote debugging interface is built on top of a simple
155 packet protocol. Each packet is organized as follows:
157 SYN The first character is always a SYN (ASCII 026, or ^V). SYN
158 may not appear anywhere else in the packet. Any time a SYN is
159 seen, a new packet should be assumed to have begun.
162 This byte contains the upper five bits of the logical length
163 of the data section, plus a single bit indicating whether this
164 is a data packet or an acknowledgement. The documentation
165 indicates that this bit is 1 for a data packet, but the actual
166 board uses 1 for an acknowledgement. The value of the byte is
167 0x40 + (ack ? 0x20 : 0) + (len >> 6)
168 (we always have 0 <= len < 1024). Acknowledgement packets do
169 not carry data, and must have a data length of 0.
171 LEN1 This byte contains the lower six bits of the logical length of
172 the data section. The value is
175 SEQ This byte contains the six bit sequence number of the packet.
178 An acknowlegment packet contains the sequence number of the
179 packet being acknowledged plus 1 modulo 64. Data packets are
180 transmitted in sequence. There may only be one outstanding
181 unacknowledged data packet at a time. The sequence numbers
182 are independent in each direction. If an acknowledgement for
183 the previous packet is received (i.e., an acknowledgement with
184 the sequence number of the packet just sent) the packet just
185 sent should be retransmitted. If no acknowledgement is
186 received within a timeout period, the packet should be
187 retransmitted. This has an unfortunate failure condition on a
188 high-latency line, as a delayed acknowledgement may lead to an
189 endless series of duplicate packets.
191 DATA The actual data bytes follow. The following characters are
192 escaped inline with DLE (ASCII 020, or ^P):
198 The additional DLE characters are not counted in the logical
199 length stored in the TYPE_LEN and LEN1 bytes.
204 These bytes contain an 18 bit checksum of the complete
205 contents of the packet excluding the SEQ byte and the
206 CSUM[123] bytes. The checksum is simply the twos complement
207 addition of all the bytes treated as unsigned characters. The
208 values of the checksum bytes are:
209 CSUM1: 0x40 + ((cksum >> 12) & 0x3f)
210 CSUM2: 0x40 + ((cksum >> 6) & 0x3f)
211 CSUM3: 0x40 + (cksum & 0x3f)
213 It happens that the MIPS remote debugging protocol always
214 communicates with ASCII strings. Because of this, this
215 implementation doesn't bother to handle the DLE quoting mechanism,
216 since it will never be required. */
218 /* The SYN character which starts each packet. */
221 /* The 0x40 used to offset each packet (this value ensures that all of
222 the header and trailer bytes, other than SYN, are printable ASCII
224 #define HDR_OFFSET 0x40
226 /* The indices of the bytes in the packet header. */
227 #define HDR_INDX_SYN 0
228 #define HDR_INDX_TYPE_LEN 1
229 #define HDR_INDX_LEN1 2
230 #define HDR_INDX_SEQ 3
233 /* The data/ack bit in the TYPE_LEN header byte. */
234 #define TYPE_LEN_DA_BIT 0x20
235 #define TYPE_LEN_DATA 0
236 #define TYPE_LEN_ACK TYPE_LEN_DA_BIT
238 /* How to compute the header bytes. */
239 #define HDR_SET_SYN(data, len, seq) (SYN)
240 #define HDR_SET_TYPE_LEN(data, len, seq) \
242 + ((data) ? TYPE_LEN_DATA : TYPE_LEN_ACK) \
243 + (((len) >> 6) & 0x1f))
244 #define HDR_SET_LEN1(data, len, seq) (HDR_OFFSET + ((len) & 0x3f))
245 #define HDR_SET_SEQ(data, len, seq) (HDR_OFFSET + (seq))
247 /* Check that a header byte is reasonable. */
248 #define HDR_CHECK(ch) (((ch) & HDR_OFFSET) == HDR_OFFSET)
250 /* Get data from the header. These macros evaluate their argument
252 #define HDR_IS_DATA(hdr) \
253 (((hdr)[HDR_INDX_TYPE_LEN] & TYPE_LEN_DA_BIT) == TYPE_LEN_DATA)
254 #define HDR_GET_LEN(hdr) \
255 ((((hdr)[HDR_INDX_TYPE_LEN] & 0x1f) << 6) + (((hdr)[HDR_INDX_LEN1] & 0x3f)))
256 #define HDR_GET_SEQ(hdr) ((unsigned int)(hdr)[HDR_INDX_SEQ] & 0x3f)
258 /* The maximum data length. */
259 #define DATA_MAXLEN 1023
261 /* The trailer offset. */
262 #define TRLR_OFFSET HDR_OFFSET
264 /* The indices of the bytes in the packet trailer. */
265 #define TRLR_INDX_CSUM1 0
266 #define TRLR_INDX_CSUM2 1
267 #define TRLR_INDX_CSUM3 2
268 #define TRLR_LENGTH 3
270 /* How to compute the trailer bytes. */
271 #define TRLR_SET_CSUM1(cksum) (TRLR_OFFSET + (((cksum) >> 12) & 0x3f))
272 #define TRLR_SET_CSUM2(cksum) (TRLR_OFFSET + (((cksum) >> 6) & 0x3f))
273 #define TRLR_SET_CSUM3(cksum) (TRLR_OFFSET + (((cksum) ) & 0x3f))
275 /* Check that a trailer byte is reasonable. */
276 #define TRLR_CHECK(ch) (((ch) & TRLR_OFFSET) == TRLR_OFFSET)
278 /* Get data from the trailer. This evaluates its argument multiple
280 #define TRLR_GET_CKSUM(trlr) \
281 ((((trlr)[TRLR_INDX_CSUM1] & 0x3f) << 12) \
282 + (((trlr)[TRLR_INDX_CSUM2] & 0x3f) << 6) \
283 + ((trlr)[TRLR_INDX_CSUM3] & 0x3f))
285 /* The sequence number modulos. */
286 #define SEQ_MODULOS (64)
288 /* PMON commands to load from the serial port or UDP socket. */
289 #define LOAD_CMD "load -b -s tty0\r"
290 #define LOAD_CMD_UDP "load -b -s udp\r"
292 enum mips_monitor_type
{
293 /* IDT/SIM monitor being used: */
295 /* PMON monitor being used: */
296 MON_PMON
, /* 3.0.83 [COGENT,EB,FP,NET] Algorithmics Ltd. Nov 9 1995 17:19:50 */
297 MON_DDB
, /* 2.7.473 [DDBVR4300,EL,FP,NET] Risq Modular Systems, Thu Jun 6 09:28:40 PDT 1996 */
298 MON_LSI
, /* 4.3.12 [EB,FP], LSI LOGIC Corp. Tue Feb 25 13:22:14 1997 */
299 /* Last and unused value, for sizing vectors, etc. */
302 static enum mips_monitor_type mips_monitor
= MON_LAST
;
304 /* The default monitor prompt text: */
305 static char *mips_monitor_prompt
;
307 /* For the Cogent PMON world this is still not ideal. The default
308 prompt is "PMON> ", unfortunately the user can change the prompt
309 and the new prompt will survive over a power-cycle (EEPROM). This
310 means that the code should really force the monitor prompt to a
311 known value as the very first action, and that the
312 "mips_monitor_prompt" support is not needed... since the prompt
313 could be explicitly set to TARGET_MONITOR_PROMPT (even though it
314 may be the prompt for a different monitor). However, this will
315 require changing the mips_initialize reset sequence. (TODO) */
317 /* Set to 1 if the target is open. */
318 static int mips_is_open
;
320 /* Currently active target description (if mips_is_open == 1) */
321 static struct target_ops
*current_ops
;
323 /* Set to 1 while the connection is being initialized. */
324 static int mips_initializing
;
326 /* Set to 1 while the connection is being brought down. */
327 static int mips_exiting
;
329 /* The next sequence number to send. */
330 static unsigned int mips_send_seq
;
332 /* The next sequence number we expect to receive. */
333 static unsigned int mips_receive_seq
;
335 /* The time to wait before retransmitting a packet, in seconds. */
336 static int mips_retransmit_wait
= 3;
338 /* The number of times to try retransmitting a packet before giving up. */
339 static int mips_send_retries
= 10;
341 /* The number of garbage characters to accept when looking for an
342 SYN for the next packet. */
343 static int mips_syn_garbage
= 1050;
345 /* The time to wait for a packet, in seconds. */
346 static int mips_receive_wait
= 5;
348 /* Set if we have sent a packet to the board but have not yet received
350 static int mips_need_reply
= 0;
352 /* Handle used to access serial I/O stream. */
353 static serial_t mips_desc
;
355 /* UDP handle used to download files to target. */
356 static serial_t udp_desc
;
357 static int udp_in_use
;
359 /* TFTP filename used to download files to DDB board, in the form
361 static char *tftp_name
; /* host:filename */
362 static char *tftp_localname
; /* filename portion of above */
363 static int tftp_in_use
;
364 static FILE *tftp_file
;
366 /* Counts the number of times the user tried to interrupt the target (usually
368 static int interrupt_count
;
370 /* If non-zero, means that the target is running. */
371 static int mips_wait_flag
= 0;
373 /* If non-zero, monitor supports breakpoint commands. */
374 static monitor_supports_breakpoints
= 0;
376 /* Data cache header. */
378 #if 0 /* not used (yet?) */
379 static DCACHE
*mips_dcache
;
382 /* Non-zero means that we've just hit a read or write watchpoint */
383 static int hit_watchpoint
;
389 SERIAL_CLOSE (mips_desc
);
393 SERIAL_CLOSE (udp_desc
);
399 /* Handle low-level error that we can't recover from. Note that just
400 error()ing out from target_wait or some such low-level place will cause
401 all hell to break loose--the rest of GDB will tend to get left in an
402 inconsistent state. */
405 #ifdef ANSI_PROTOTYPES
406 mips_error (char *string
, ...)
408 mips_error (va_alist
)
414 #ifdef ANSI_PROTOTYPES
415 va_start (args
, string
);
419 string
= va_arg (args
, char *);
422 target_terminal_ours ();
423 wrap_here(""); /* Force out any buffered output */
424 gdb_flush (gdb_stdout
);
426 fprintf_filtered (gdb_stderr
, error_pre_print
);
427 vfprintf_filtered (gdb_stderr
, string
, args
);
428 fprintf_filtered (gdb_stderr
, "\n");
430 gdb_flush (gdb_stderr
);
432 /* Clean up in such a way that mips_close won't try to talk to the
433 board (it almost surely won't work since we weren't able to talk to
437 printf_unfiltered ("Ending remote MIPS debugging.\n");
438 target_mourn_inferior ();
440 return_to_top_level (RETURN_ERROR
);
443 /* putc_readable - print a character, displaying non-printable chars in
444 ^x notation or in hex. */
451 putchar_unfiltered ('\n');
453 printf_unfiltered ("\\r");
454 else if (ch
< 0x20) /* ASCII control character */
455 printf_unfiltered ("^%c", ch
+ '@');
456 else if (ch
>= 0x7f) /* non-ASCII characters (rubout or greater) */
457 printf_unfiltered ("[%02x]", ch
& 0xff);
459 putchar_unfiltered (ch
);
463 /* puts_readable - print a string, displaying non-printable chars in
464 ^x notation or in hex. */
467 puts_readable (string
)
472 while ((c
= *string
++) != '\0')
477 /* Wait until STRING shows up in mips_desc. Returns 1 if successful, else 0 if
478 timed out. TIMEOUT specifies timeout value in seconds.
482 mips_expect_timeout (string
, timeout
)
490 printf_unfiltered ("Expected \"");
491 puts_readable (string
);
492 printf_unfiltered ("\", got \"");
500 /* Must use SERIAL_READCHAR here cuz mips_readchar would get confused if we
501 were waiting for the mips_monitor_prompt... */
503 c
= SERIAL_READCHAR (mips_desc
, timeout
);
505 if (c
== SERIAL_TIMEOUT
)
508 printf_unfiltered ("\": FAIL\n");
521 printf_unfiltered ("\": OK\n");
534 /* Wait until STRING shows up in mips_desc. Returns 1 if successful, else 0 if
535 timed out. The timeout value is hard-coded to 2 seconds. Use
536 mips_expect_timeout if a different timeout value is needed.
543 return mips_expect_timeout (string
, 2);
546 /* Read the required number of characters into the given buffer (which
547 is assumed to be large enough). The only failure is a timeout. */
549 mips_getstring (string
, n
)
559 c
= SERIAL_READCHAR (mips_desc
, 2);
561 if (c
== SERIAL_TIMEOUT
) {
562 fprintf_unfiltered (stderr
, "Failed to read %d characters from target (TIMEOUT)\n", n
);
573 /* Read a character from the remote, aborting on error. Returns
574 SERIAL_TIMEOUT on timeout (since that's what SERIAL_READCHAR
575 returns). FIXME: If we see the string mips_monitor_prompt from
576 the board, then we are debugging on the main console port, and we
577 have somehow dropped out of remote debugging mode. In this case,
578 we automatically go back in to remote debugging mode. This is a
579 hack, put in because I can't find any way for a program running on
580 the remote board to terminate without also ending remote debugging
581 mode. I assume users won't have any trouble with this; for one
582 thing, the IDT documentation generally assumes that the remote
583 debugging port is not the console port. This is, however, very
584 convenient for DejaGnu when you only have one connected serial
588 mips_readchar (timeout
)
592 static int state
= 0;
593 int mips_monitor_prompt_len
= strlen (mips_monitor_prompt
);
595 #ifdef MAINTENANCE_CMDS
600 if (i
== -1 && watchdog
> 0)
605 if (state
== mips_monitor_prompt_len
)
607 ch
= SERIAL_READCHAR (mips_desc
, timeout
);
608 #ifdef MAINTENANCE_CMDS
609 if (ch
== SERIAL_TIMEOUT
&& timeout
== -1) /* Watchdog went off */
611 target_mourn_inferior ();
612 error ("Watchdog has expired. Target detached.\n");
615 if (ch
== SERIAL_EOF
)
616 mips_error ("End of file from remote");
617 if (ch
== SERIAL_ERROR
)
618 mips_error ("Error reading from remote: %s", safe_strerror (errno
));
619 if (remote_debug
> 1)
621 /* Don't use _filtered; we can't deal with a QUIT out of
622 target_wait, and I think this might be called from there. */
623 if (ch
!= SERIAL_TIMEOUT
)
624 printf_unfiltered ("Read '%c' %d 0x%x\n", ch
, ch
, ch
);
626 printf_unfiltered ("Timed out in read\n");
629 /* If we have seen mips_monitor_prompt and we either time out, or
630 we see a @ (which was echoed from a packet we sent), reset the
631 board as described above. The first character in a packet after
632 the SYN (which is not echoed) is always an @ unless the packet is
633 more than 64 characters long, which ours never are. */
634 if ((ch
== SERIAL_TIMEOUT
|| ch
== '@')
635 && state
== mips_monitor_prompt_len
636 && ! mips_initializing
639 if (remote_debug
> 0)
640 /* Don't use _filtered; we can't deal with a QUIT out of
641 target_wait, and I think this might be called from there. */
642 printf_unfiltered ("Reinitializing MIPS debugging mode\n");
649 /* At this point, about the only thing we can do is abort the command
650 in progress and get back to command level as quickly as possible. */
652 error ("Remote board reset, debug protocol re-initialized.");
655 if (ch
== mips_monitor_prompt
[state
])
663 /* Get a packet header, putting the data in the supplied buffer.
664 PGARBAGE is a pointer to the number of garbage characters received
665 so far. CH is the last character received. Returns 0 for success,
666 or -1 for timeout. */
669 mips_receive_header (hdr
, pgarbage
, ch
, timeout
)
679 /* Wait for a SYN. mips_syn_garbage is intended to prevent
680 sitting here indefinitely if the board sends us one garbage
681 character per second. ch may already have a value from the
682 last time through the loop. */
685 ch
= mips_readchar (timeout
);
686 if (ch
== SERIAL_TIMEOUT
)
690 /* Printing the character here lets the user of gdb see
691 what the program is outputting, if the debugging is
692 being done on the console port. Don't use _filtered;
693 we can't deal with a QUIT out of target_wait. */
694 if (! mips_initializing
|| remote_debug
> 0)
697 gdb_flush (gdb_stdout
);
701 if (mips_syn_garbage
> 0
702 && *pgarbage
> mips_syn_garbage
)
703 mips_error ("Debug protocol failure: more than %d characters before a sync.",
708 /* Get the packet header following the SYN. */
709 for (i
= 1; i
< HDR_LENGTH
; i
++)
711 ch
= mips_readchar (timeout
);
712 if (ch
== SERIAL_TIMEOUT
)
714 /* Make sure this is a header byte. */
715 if (ch
== SYN
|| ! HDR_CHECK (ch
))
721 /* If we got the complete header, we can return. Otherwise we
722 loop around and keep looking for SYN. */
728 /* Get a packet header, putting the data in the supplied buffer.
729 PGARBAGE is a pointer to the number of garbage characters received
730 so far. The last character read is returned in *PCH. Returns 0
731 for success, -1 for timeout, -2 for error. */
734 mips_receive_trailer (trlr
, pgarbage
, pch
, timeout
)
743 for (i
= 0; i
< TRLR_LENGTH
; i
++)
745 ch
= mips_readchar (timeout
);
747 if (ch
== SERIAL_TIMEOUT
)
749 if (! TRLR_CHECK (ch
))
756 /* Get the checksum of a packet. HDR points to the packet header.
757 DATA points to the packet data. LEN is the length of DATA. */
760 mips_cksum (hdr
, data
, len
)
761 const unsigned char *hdr
;
762 const unsigned char *data
;
765 register const unsigned char *p
;
771 /* The initial SYN is not included in the checksum. */
785 /* Send a packet containing the given ASCII string. */
788 mips_send_packet (s
, get_ack
)
792 /* unsigned */ int len
;
793 unsigned char *packet
;
798 if (len
> DATA_MAXLEN
)
799 mips_error ("MIPS protocol data packet too long: %s", s
);
801 packet
= (unsigned char *) alloca (HDR_LENGTH
+ len
+ TRLR_LENGTH
+ 1);
803 packet
[HDR_INDX_SYN
] = HDR_SET_SYN (1, len
, mips_send_seq
);
804 packet
[HDR_INDX_TYPE_LEN
] = HDR_SET_TYPE_LEN (1, len
, mips_send_seq
);
805 packet
[HDR_INDX_LEN1
] = HDR_SET_LEN1 (1, len
, mips_send_seq
);
806 packet
[HDR_INDX_SEQ
] = HDR_SET_SEQ (1, len
, mips_send_seq
);
808 memcpy (packet
+ HDR_LENGTH
, s
, len
);
810 cksum
= mips_cksum (packet
, packet
+ HDR_LENGTH
, len
);
811 packet
[HDR_LENGTH
+ len
+ TRLR_INDX_CSUM1
] = TRLR_SET_CSUM1 (cksum
);
812 packet
[HDR_LENGTH
+ len
+ TRLR_INDX_CSUM2
] = TRLR_SET_CSUM2 (cksum
);
813 packet
[HDR_LENGTH
+ len
+ TRLR_INDX_CSUM3
] = TRLR_SET_CSUM3 (cksum
);
815 /* Increment the sequence number. This will set mips_send_seq to
816 the sequence number we expect in the acknowledgement. */
817 mips_send_seq
= (mips_send_seq
+ 1) % SEQ_MODULOS
;
819 /* We can only have one outstanding data packet, so we just wait for
820 the acknowledgement here. Keep retransmitting the packet until
821 we get one, or until we've tried too many times. */
822 for (try = 0; try < mips_send_retries
; try++)
827 if (remote_debug
> 0)
829 /* Don't use _filtered; we can't deal with a QUIT out of
830 target_wait, and I think this might be called from there. */
831 packet
[HDR_LENGTH
+ len
+ TRLR_LENGTH
] = '\0';
832 printf_unfiltered ("Writing \"%s\"\n", packet
+ 1);
835 if (SERIAL_WRITE (mips_desc
, packet
,
836 HDR_LENGTH
+ len
+ TRLR_LENGTH
) != 0)
837 mips_error ("write to target failed: %s", safe_strerror (errno
));
846 unsigned char hdr
[HDR_LENGTH
+ 1];
847 unsigned char trlr
[TRLR_LENGTH
+ 1];
851 /* Get the packet header. If we time out, resend the data
853 err
= mips_receive_header (hdr
, &garbage
, ch
, mips_retransmit_wait
);
859 /* If we get a data packet, assume it is a duplicate and
860 ignore it. FIXME: If the acknowledgement is lost, this
861 data packet may be the packet the remote sends after the
863 if (HDR_IS_DATA (hdr
)) {
866 /* Ignore any errors raised whilst attempting to ignore
869 len
= HDR_GET_LEN (hdr
);
871 for (i
= 0; i
< len
; i
++)
875 rch
= mips_readchar (2);
881 if (rch
== SERIAL_TIMEOUT
)
883 /* ignore the character */
887 (void) mips_receive_trailer (trlr
, &garbage
, &ch
, 2);
889 /* We don't bother checking the checksum, or providing an
890 ACK to the packet. */
894 /* If the length is not 0, this is a garbled packet. */
895 if (HDR_GET_LEN (hdr
) != 0)
898 /* Get the packet trailer. */
899 err
= mips_receive_trailer (trlr
, &garbage
, &ch
,
900 mips_retransmit_wait
);
902 /* If we timed out, resend the data packet. */
906 /* If we got a bad character, reread the header. */
910 /* If the checksum does not match the trailer checksum, this
911 is a bad packet; ignore it. */
912 if (mips_cksum (hdr
, (unsigned char *) NULL
, 0)
913 != TRLR_GET_CKSUM (trlr
))
916 if (remote_debug
> 0)
918 hdr
[HDR_LENGTH
] = '\0';
919 trlr
[TRLR_LENGTH
] = '\0';
920 /* Don't use _filtered; we can't deal with a QUIT out of
921 target_wait, and I think this might be called from there. */
922 printf_unfiltered ("Got ack %d \"%s%s\"\n",
923 HDR_GET_SEQ (hdr
), hdr
+ 1, trlr
);
926 /* If this ack is for the current packet, we're done. */
927 seq
= HDR_GET_SEQ (hdr
);
928 if (seq
== mips_send_seq
)
931 /* If this ack is for the last packet, resend the current
933 if ((seq
+ 1) % SEQ_MODULOS
== mips_send_seq
)
936 /* Otherwise this is a bad ack; ignore it. Increment the
937 garbage count to ensure that we do not stay in this loop
943 mips_error ("Remote did not acknowledge packet");
946 /* Receive and acknowledge a packet, returning the data in BUFF (which
947 should be DATA_MAXLEN + 1 bytes). The protocol documentation
948 implies that only the sender retransmits packets, so this code just
949 waits silently for a packet. It returns the length of the received
950 packet. If THROW_ERROR is nonzero, call error() on errors. If not,
951 don't print an error message and return -1. */
954 mips_receive_packet (buff
, throw_error
, timeout
)
962 unsigned char ack
[HDR_LENGTH
+ TRLR_LENGTH
+ 1];
969 unsigned char hdr
[HDR_LENGTH
];
970 unsigned char trlr
[TRLR_LENGTH
];
974 if (mips_receive_header (hdr
, &garbage
, ch
, timeout
) != 0)
977 mips_error ("Timed out waiting for remote packet");
984 /* An acknowledgement is probably a duplicate; ignore it. */
985 if (! HDR_IS_DATA (hdr
))
987 len
= HDR_GET_LEN (hdr
);
988 /* Check if the length is valid for an ACK, we may aswell
989 try and read the remainder of the packet: */
992 /* Ignore the error condition, since we are going to
993 ignore the packet anyway. */
994 (void) mips_receive_trailer (trlr
, &garbage
, &ch
, timeout
);
996 /* Don't use _filtered; we can't deal with a QUIT out of
997 target_wait, and I think this might be called from there. */
998 if (remote_debug
> 0)
999 printf_unfiltered ("Ignoring unexpected ACK\n");
1003 len
= HDR_GET_LEN (hdr
);
1004 for (i
= 0; i
< len
; i
++)
1008 rch
= mips_readchar (timeout
);
1014 if (rch
== SERIAL_TIMEOUT
)
1017 mips_error ("Timed out waiting for remote packet");
1026 /* Don't use _filtered; we can't deal with a QUIT out of
1027 target_wait, and I think this might be called from there. */
1028 if (remote_debug
> 0)
1029 printf_unfiltered ("Got new SYN after %d chars (wanted %d)\n",
1034 err
= mips_receive_trailer (trlr
, &garbage
, &ch
, timeout
);
1038 mips_error ("Timed out waiting for packet");
1044 /* Don't use _filtered; we can't deal with a QUIT out of
1045 target_wait, and I think this might be called from there. */
1046 if (remote_debug
> 0)
1047 printf_unfiltered ("Got SYN when wanted trailer\n");
1051 /* If this is the wrong sequence number, ignore it. */
1052 if (HDR_GET_SEQ (hdr
) != mips_receive_seq
)
1054 /* Don't use _filtered; we can't deal with a QUIT out of
1055 target_wait, and I think this might be called from there. */
1056 if (remote_debug
> 0)
1057 printf_unfiltered ("Ignoring sequence number %d (want %d)\n",
1058 HDR_GET_SEQ (hdr
), mips_receive_seq
);
1062 if (mips_cksum (hdr
, buff
, len
) == TRLR_GET_CKSUM (trlr
))
1065 if (remote_debug
> 0)
1066 /* Don't use _filtered; we can't deal with a QUIT out of
1067 target_wait, and I think this might be called from there. */
1068 printf_unfiltered ("Bad checksum; data %d, trailer %d\n",
1069 mips_cksum (hdr
, buff
, len
),
1070 TRLR_GET_CKSUM (trlr
));
1072 /* The checksum failed. Send an acknowledgement for the
1073 previous packet to tell the remote to resend the packet. */
1074 ack
[HDR_INDX_SYN
] = HDR_SET_SYN (0, 0, mips_receive_seq
);
1075 ack
[HDR_INDX_TYPE_LEN
] = HDR_SET_TYPE_LEN (0, 0, mips_receive_seq
);
1076 ack
[HDR_INDX_LEN1
] = HDR_SET_LEN1 (0, 0, mips_receive_seq
);
1077 ack
[HDR_INDX_SEQ
] = HDR_SET_SEQ (0, 0, mips_receive_seq
);
1079 cksum
= mips_cksum (ack
, (unsigned char *) NULL
, 0);
1081 ack
[HDR_LENGTH
+ TRLR_INDX_CSUM1
] = TRLR_SET_CSUM1 (cksum
);
1082 ack
[HDR_LENGTH
+ TRLR_INDX_CSUM2
] = TRLR_SET_CSUM2 (cksum
);
1083 ack
[HDR_LENGTH
+ TRLR_INDX_CSUM3
] = TRLR_SET_CSUM3 (cksum
);
1085 if (remote_debug
> 0)
1087 ack
[HDR_LENGTH
+ TRLR_LENGTH
] = '\0';
1088 /* Don't use _filtered; we can't deal with a QUIT out of
1089 target_wait, and I think this might be called from there. */
1090 printf_unfiltered ("Writing ack %d \"%s\"\n", mips_receive_seq
,
1094 if (SERIAL_WRITE (mips_desc
, ack
, HDR_LENGTH
+ TRLR_LENGTH
) != 0)
1097 mips_error ("write to target failed: %s", safe_strerror (errno
));
1103 if (remote_debug
> 0)
1106 /* Don't use _filtered; we can't deal with a QUIT out of
1107 target_wait, and I think this might be called from there. */
1108 printf_unfiltered ("Got packet \"%s\"\n", buff
);
1111 /* We got the packet. Send an acknowledgement. */
1112 mips_receive_seq
= (mips_receive_seq
+ 1) % SEQ_MODULOS
;
1114 ack
[HDR_INDX_SYN
] = HDR_SET_SYN (0, 0, mips_receive_seq
);
1115 ack
[HDR_INDX_TYPE_LEN
] = HDR_SET_TYPE_LEN (0, 0, mips_receive_seq
);
1116 ack
[HDR_INDX_LEN1
] = HDR_SET_LEN1 (0, 0, mips_receive_seq
);
1117 ack
[HDR_INDX_SEQ
] = HDR_SET_SEQ (0, 0, mips_receive_seq
);
1119 cksum
= mips_cksum (ack
, (unsigned char *) NULL
, 0);
1121 ack
[HDR_LENGTH
+ TRLR_INDX_CSUM1
] = TRLR_SET_CSUM1 (cksum
);
1122 ack
[HDR_LENGTH
+ TRLR_INDX_CSUM2
] = TRLR_SET_CSUM2 (cksum
);
1123 ack
[HDR_LENGTH
+ TRLR_INDX_CSUM3
] = TRLR_SET_CSUM3 (cksum
);
1125 if (remote_debug
> 0)
1127 ack
[HDR_LENGTH
+ TRLR_LENGTH
] = '\0';
1128 /* Don't use _filtered; we can't deal with a QUIT out of
1129 target_wait, and I think this might be called from there. */
1130 printf_unfiltered ("Writing ack %d \"%s\"\n", mips_receive_seq
,
1134 if (SERIAL_WRITE (mips_desc
, ack
, HDR_LENGTH
+ TRLR_LENGTH
) != 0)
1137 mips_error ("write to target failed: %s", safe_strerror (errno
));
1145 /* Optionally send a request to the remote system and optionally wait
1146 for the reply. This implements the remote debugging protocol,
1147 which is built on top of the packet protocol defined above. Each
1148 request has an ADDR argument and a DATA argument. The following
1149 requests are defined:
1151 \0 don't send a request; just wait for a reply
1152 i read word from instruction space at ADDR
1153 d read word from data space at ADDR
1154 I write DATA to instruction space at ADDR
1155 D write DATA to data space at ADDR
1156 r read register number ADDR
1157 R set register number ADDR to value DATA
1158 c continue execution (if ADDR != 1, set pc to ADDR)
1159 s single step (if ADDR != 1, set pc to ADDR)
1161 The read requests return the value requested. The write requests
1162 return the previous value in the changed location. The execution
1163 requests return a UNIX wait value (the approximate signal which
1164 caused execution to stop is in the upper eight bits).
1166 If PERR is not NULL, this function waits for a reply. If an error
1167 occurs, it sets *PERR to 1 and sets errno according to what the
1168 target board reports. */
1171 mips_request (cmd
, addr
, data
, perr
, timeout
, buff
)
1179 char myBuff
[DATA_MAXLEN
+ 1];
1186 if (buff
== (char *) NULL
)
1191 if (mips_need_reply
)
1192 fatal ("mips_request: Trying to send command before reply");
1193 sprintf (buff
, "0x0 %c 0x%s 0x%s", cmd
, paddr_nz (addr
), paddr_nz (data
));
1194 mips_send_packet (buff
, 1);
1195 mips_need_reply
= 1;
1198 if (perr
== (int *) NULL
)
1201 if (! mips_need_reply
)
1202 fatal ("mips_request: Trying to get reply before command");
1204 mips_need_reply
= 0;
1206 len
= mips_receive_packet (buff
, 1, timeout
);
1209 if (sscanf (buff
, "0x%x %c 0x%x 0x%x",
1210 &rpid
, &rcmd
, &rerrflg
, &rresponse
) != 4
1211 || (cmd
!= '\0' && rcmd
!= cmd
))
1212 mips_error ("Bad response from remote board");
1218 /* FIXME: This will returns MIPS errno numbers, which may or may
1219 not be the same as errno values used on other systems. If
1220 they stick to common errno values, they will be the same, but
1221 if they don't, they must be translated. */
1232 mips_initialize_cleanups (arg
)
1235 mips_initializing
= 0;
1239 mips_exit_cleanups (arg
)
1246 mips_send_command (cmd
, prompt
)
1250 SERIAL_WRITE (mips_desc
, cmd
, strlen(cmd
));
1254 mips_expect (mips_monitor_prompt
);
1257 /* Enter remote (dbx) debug mode: */
1261 /* Reset the sequence numbers, ready for the new debug sequence: */
1263 mips_receive_seq
= 0;
1265 if (mips_monitor
!= MON_IDT
)
1266 mips_send_command ("debug\r", 0);
1267 else /* assume IDT monitor by default */
1268 mips_send_command ("db tty0\r", 0);
1270 SERIAL_WRITE (mips_desc
, "\r", sizeof "\r" - 1);
1272 /* We don't need to absorb any spurious characters here, since the
1273 mips_receive_header will eat up a reasonable number of characters
1274 whilst looking for the SYN, however this avoids the "garbage"
1275 being displayed to the user. */
1276 if (mips_monitor
!= MON_IDT
)
1280 char buff
[DATA_MAXLEN
+ 1];
1281 if (mips_receive_packet (buff
, 1, 3) < 0)
1282 mips_error ("Failed to initialize (didn't receive packet).");
1286 /* Exit remote (dbx) debug mode, returning to the monitor prompt: */
1291 struct cleanup
*old_cleanups
= make_cleanup (mips_exit_cleanups
, NULL
);
1295 if (mips_monitor
!= MON_IDT
)
1297 /* The DDB (NEC) and MiniRISC (LSI) versions of PMON exit immediately,
1298 so we do not get a reply to this command: */
1299 mips_request ('x', (unsigned int) 0, (unsigned int) 0, NULL
,
1300 mips_receive_wait
, NULL
);
1301 mips_need_reply
= 0;
1302 if (!mips_expect (" break!"))
1306 mips_request ('x', (unsigned int) 0, (unsigned int) 0, &err
,
1307 mips_receive_wait
, NULL
);
1309 if (mips_monitor
== MON_IDT
&& !mips_expect ("Exiting remote debug"))
1312 if (mips_monitor
== MON_DDB
)
1314 if (!mips_expect ("\n"))
1318 if (!mips_expect ("\r\n"))
1321 if (!mips_expect (mips_monitor_prompt
))
1324 do_cleanups (old_cleanups
);
1329 /* Initialize a new connection to the MIPS board, and make sure we are
1330 really connected. */
1336 struct cleanup
*old_cleanups
= make_cleanup (mips_initialize_cleanups
, NULL
);
1339 /* What is this code doing here? I don't see any way it can happen, and
1340 it might mean mips_initializing didn't get cleared properly.
1341 So I'll make it a warning. */
1343 if (mips_initializing
)
1345 warning ("internal error: mips_initialize called twice");
1350 mips_initializing
= 1;
1352 /* At this point, the packit protocol isn't responding. We'll try getting
1353 into the monitor, and restarting the protocol. */
1355 /* Force the system into the monitor. After this we *should* be at
1356 the mips_monitor_prompt. */
1357 if (mips_monitor
!= MON_IDT
)
1358 j
= 0; /* start by checking if we are already at the prompt */
1360 j
= 1; /* start by sending a break */
1365 case 0: /* First, try sending a CR */
1366 SERIAL_FLUSH_INPUT (mips_desc
);
1367 SERIAL_WRITE (mips_desc
, "\r", 1);
1369 case 1: /* First, try sending a break */
1370 SERIAL_SEND_BREAK (mips_desc
);
1372 case 2: /* Then, try a ^C */
1373 SERIAL_WRITE (mips_desc
, "\003", 1);
1375 case 3: /* Then, try escaping from download */
1377 if (mips_monitor
!= MON_IDT
)
1381 /* We shouldn't need to send multiple termination
1382 sequences, since the target performs line (or
1383 block) reads, and then processes those
1384 packets. In-case we were downloading a large packet
1385 we flush the output buffer before inserting a
1386 termination sequence. */
1387 SERIAL_FLUSH_OUTPUT (mips_desc
);
1388 sprintf (tbuff
, "\r/E/E\r");
1389 SERIAL_WRITE (mips_desc
, tbuff
, 6);
1396 /* We are possibly in binary download mode, having
1397 aborted in the middle of an S-record. ^C won't
1398 work because of binary mode. The only reliable way
1399 out is to send enough termination packets (8 bytes)
1400 to fill up and then overflow the largest size
1401 S-record (255 bytes in this case). This amounts to
1405 mips_make_srec (srec
, '7', 0, NULL
, 0);
1407 for (i
= 1; i
<= 33; i
++)
1409 SERIAL_WRITE (mips_desc
, srec
, 8);
1411 if (SERIAL_READCHAR (mips_desc
, 0) >= 0)
1412 break; /* Break immediatly if we get something from
1419 mips_error ("Failed to initialize.");
1422 if (mips_expect (mips_monitor_prompt
))
1426 if (mips_monitor
!= MON_IDT
)
1428 /* Ensure the correct target state: */
1429 if (mips_monitor
!= MON_LSI
)
1430 mips_send_command ("set regsize 64\r", -1);
1431 mips_send_command ("set hostport tty0\r", -1);
1432 mips_send_command ("set brkcmd \"\"\r", -1);
1433 /* Delete all the current breakpoints: */
1434 mips_send_command ("db *\r", -1);
1435 /* NOTE: PMON does not have breakpoint support through the
1436 "debug" mode, only at the monitor command-line. */
1439 mips_enter_debug ();
1441 /* Clear all breakpoints: */
1442 if (mips_monitor
== MON_IDT
&& common_breakpoint ('b', -1, 0, NULL
) == 0)
1443 monitor_supports_breakpoints
= 1;
1445 monitor_supports_breakpoints
= 0;
1447 do_cleanups (old_cleanups
);
1449 /* If this doesn't call error, we have connected; we don't care if
1450 the request itself succeeds or fails. */
1452 mips_request ('r', (unsigned int) 0, (unsigned int) 0, &err
,
1453 mips_receive_wait
, NULL
);
1454 set_current_frame (create_new_frame (read_fp (), read_pc ()));
1455 select_frame (get_current_frame (), 0);
1458 /* Open a connection to the remote board. */
1460 common_open (ops
, name
, from_tty
, new_monitor
, new_monitor_prompt
)
1461 struct target_ops
*ops
;
1464 enum mips_monitor_type new_monitor
;
1465 char *new_monitor_prompt
;
1468 char *serial_port_name
;
1469 char *remote_name
= 0;
1470 char *local_name
= 0;
1475 "To open a MIPS remote debugging connection, you need to specify what serial\n\
1476 device is attached to the target board (e.g., /dev/ttya).\n"
1477 "If you want to use TFTP to download to the board, specify the name of a\n"
1478 "temporary file to be used by GDB for downloads as the second argument.\n"
1479 "This filename must be in the form host:filename, where host is the name\n"
1480 "of the host running the TFTP server, and the file must be readable by the\n"
1481 "world. If the local name of the temporary file differs from the name as\n"
1482 "seen from the board via TFTP, specify that name as the third parameter.\n");
1484 /* Parse the serial port name, the optional TFTP name, and the
1485 optional local TFTP name. */
1486 if ((argv
= buildargv (name
)) == NULL
)
1488 make_cleanup (freeargv
, (char *) argv
);
1490 serial_port_name
= strsave (argv
[0]);
1491 if (argv
[1]) /* remote TFTP name specified? */
1493 remote_name
= argv
[1];
1494 if (argv
[2]) /* local TFTP filename specified? */
1495 local_name
= argv
[2];
1498 target_preopen (from_tty
);
1501 unpush_target (current_ops
);
1503 /* Open and initialize the serial port. */
1504 mips_desc
= SERIAL_OPEN (serial_port_name
);
1505 if (mips_desc
== (serial_t
) NULL
)
1506 perror_with_name (serial_port_name
);
1508 if (baud_rate
!= -1)
1510 if (SERIAL_SETBAUDRATE (mips_desc
, baud_rate
))
1512 SERIAL_CLOSE (mips_desc
);
1513 perror_with_name (serial_port_name
);
1517 SERIAL_RAW (mips_desc
);
1519 /* Open and initialize the optional download port. If it is in the form
1520 hostname#portnumber, it's a UDP socket. If it is in the form
1521 hostname:filename, assume it's the TFTP filename that must be
1522 passed to the DDB board to tell it where to get the load file. */
1525 if (strchr (remote_name
, '#'))
1527 udp_desc
= SERIAL_OPEN (remote_name
);
1529 perror_with_name ("Unable to open UDP port");
1534 /* Save the remote and local names of the TFTP temp file. If
1535 the user didn't specify a local name, assume it's the same
1536 as the part of the remote name after the "host:". */
1540 free (tftp_localname
);
1541 if (local_name
== NULL
)
1542 if ((local_name
= strchr (remote_name
, ':')) != NULL
)
1543 local_name
++; /* skip over the colon */
1544 if (local_name
== NULL
)
1545 local_name
= remote_name
; /* local name same as remote name */
1546 tftp_name
= strsave (remote_name
);
1547 tftp_localname
= strsave (local_name
);
1555 /* Reset the expected monitor prompt if it's never been set before. */
1556 if (mips_monitor_prompt
== NULL
)
1557 mips_monitor_prompt
= strsave (new_monitor_prompt
);
1558 mips_monitor
= new_monitor
;
1563 printf_unfiltered ("Remote MIPS debugging using %s\n", serial_port_name
);
1565 /* Switch to using remote target now. */
1568 /* FIXME: Should we call start_remote here? */
1570 /* Try to figure out the processor model if possible. */
1571 ptype
= mips_read_processor_type ();
1573 mips_set_processor_type_command (strsave (ptype
), 0);
1575 /* This is really the job of start_remote however, that makes an assumption
1576 that the target is about to print out a status message of some sort. That
1577 doesn't happen here (in fact, it may not be possible to get the monitor to
1578 send the appropriate packet). */
1580 flush_cached_frames ();
1581 registers_changed ();
1582 stop_pc
= read_pc ();
1583 set_current_frame (create_new_frame (read_fp (), stop_pc
));
1584 select_frame (get_current_frame (), 0);
1585 print_stack_frame (selected_frame
, -1, 1);
1586 free (serial_port_name
);
1590 mips_open (name
, from_tty
)
1594 common_open (&mips_ops
, name
, from_tty
, MON_IDT
, TARGET_MONITOR_PROMPT
);
1598 pmon_open (name
, from_tty
)
1602 common_open (&pmon_ops
, name
, from_tty
, MON_PMON
, "PMON> ");
1606 ddb_open (name
, from_tty
)
1610 common_open (&ddb_ops
, name
, from_tty
, MON_DDB
, "NEC010>");
1614 lsi_open (name
, from_tty
)
1618 common_open (&ddb_ops
, name
, from_tty
, MON_LSI
, "PMON> ");
1621 /* Close a connection to the remote board. */
1624 mips_close (quitting
)
1629 /* Get the board out of remote debugging mode. */
1630 (void) mips_exit_debug ();
1636 /* Detach from the remote board. */
1639 mips_detach (args
, from_tty
)
1644 error ("Argument given to \"detach\" when remotely debugging.");
1651 printf_unfiltered ("Ending remote MIPS debugging.\n");
1654 /* Tell the target board to resume. This does not wait for a reply
1658 mips_resume (pid
, step
, siggnal
)
1660 enum target_signal siggnal
;
1664 /* start-sanitize-gm */
1665 #ifndef GENERAL_MAGIC
1666 if (siggnal
!= TARGET_SIGNAL_0
)
1668 ("Can't send signals to a remote system. Try `handle %s ignore'.",
1669 target_signal_to_name (siggnal
));
1670 #endif /* GENERAL_MAGIC */
1671 /* end-sanitize-gm */
1673 /* LSI PMON requires returns a reply packet "0x1 s 0x0 0x57f" after
1674 a single step, so we wait for that. */
1675 mips_request (step
? 's' : 'c',
1677 (unsigned int) siggnal
,
1678 mips_monitor
== MON_LSI
&& step
? &err
: (int *) NULL
,
1679 mips_receive_wait
, NULL
);
1682 /* Return the signal corresponding to SIG, where SIG is the number which
1683 the MIPS protocol uses for the signal. */
1685 mips_signal_from_protocol (sig
)
1688 /* We allow a few more signals than the IDT board actually returns, on
1689 the theory that there is at least *some* hope that perhaps the numbering
1690 for these signals is widely agreed upon. */
1693 return TARGET_SIGNAL_UNKNOWN
;
1695 /* Don't want to use target_signal_from_host because we are converting
1696 from MIPS signal numbers, not host ones. Our internal numbers
1697 match the MIPS numbers for the signals the board can return, which
1698 are: SIGINT, SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP. */
1699 return (enum target_signal
) sig
;
1702 /* Wait until the remote stops, and return a wait status. */
1705 mips_wait (pid
, status
)
1707 struct target_waitstatus
*status
;
1711 char buff
[DATA_MAXLEN
];
1716 interrupt_count
= 0;
1719 /* If we have not sent a single step or continue command, then the
1720 board is waiting for us to do something. Return a status
1721 indicating that it is stopped. */
1722 if (! mips_need_reply
)
1724 status
->kind
= TARGET_WAITKIND_STOPPED
;
1725 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1729 /* No timeout; we sit here as long as the program continues to execute. */
1731 rstatus
= mips_request ('\000', (unsigned int) 0, (unsigned int) 0, &err
, -1,
1735 mips_error ("Remote failure: %s", safe_strerror (errno
));
1737 nfields
= sscanf (buff
, "0x%*x %*c 0x%*x 0x%*x 0x%x 0x%x 0x%x 0x%*x %s",
1738 &rpc
, &rfp
, &rsp
, flags
);
1740 /* See if we got back extended status. If so, pick out the pc, fp, sp, etc... */
1742 if (nfields
== 7 || nfields
== 9)
1744 char buf
[MAX_REGISTER_RAW_SIZE
];
1746 store_unsigned_integer (buf
, REGISTER_RAW_SIZE (PC_REGNUM
), rpc
);
1747 supply_register (PC_REGNUM
, buf
);
1749 store_unsigned_integer (buf
, REGISTER_RAW_SIZE (PC_REGNUM
), rfp
);
1750 supply_register (30, buf
); /* This register they are avoiding and so it is unnamed */
1752 store_unsigned_integer (buf
, REGISTER_RAW_SIZE (SP_REGNUM
), rsp
);
1753 supply_register (SP_REGNUM
, buf
);
1755 store_unsigned_integer (buf
, REGISTER_RAW_SIZE (FP_REGNUM
), 0);
1756 supply_register (FP_REGNUM
, buf
);
1762 for (i
= 0; i
<= 2; i
++)
1763 if (flags
[i
] == 'r' || flags
[i
] == 'w')
1765 else if (flags
[i
] == '\000')
1770 /* Translate a MIPS waitstatus. We use constants here rather than WTERMSIG
1771 and so on, because the constants we want here are determined by the
1772 MIPS protocol and have nothing to do with what host we are running on. */
1773 if ((rstatus
& 0377) == 0)
1775 status
->kind
= TARGET_WAITKIND_EXITED
;
1776 status
->value
.integer
= (((rstatus
) >> 8) & 0377);
1778 else if ((rstatus
& 0377) == 0177)
1780 status
->kind
= TARGET_WAITKIND_STOPPED
;
1781 status
->value
.sig
= mips_signal_from_protocol (((rstatus
) >> 8) & 0377);
1785 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
1786 status
->value
.sig
= mips_signal_from_protocol (rstatus
& 0177);
1793 pmon_wait (pid
, status
)
1795 struct target_waitstatus
*status
;
1799 char buff
[DATA_MAXLEN
];
1801 interrupt_count
= 0;
1804 /* If we have not sent a single step or continue command, then the
1805 board is waiting for us to do something. Return a status
1806 indicating that it is stopped. */
1807 if (! mips_need_reply
)
1809 status
->kind
= TARGET_WAITKIND_STOPPED
;
1810 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
1814 /* Sit, polling the serial until the target decides to talk to
1815 us. NOTE: the timeout value we use is used not just for the
1816 first character, but for all the characters. */
1818 rstatus
= mips_request ('\000', (unsigned int) 0, (unsigned int) 0, &err
, -1,
1822 mips_error ("Remote failure: %s", safe_strerror (errno
));
1824 /* NOTE: The following (sig) numbers are defined by PMON:
1825 SPP_SIGTRAP 5 breakpoint
1833 /* On returning from a continue, the PMON monitor seems to start
1834 echoing back the messages we send prior to sending back the
1835 ACK. The code can cope with this, but to try and avoid the
1836 unnecessary serial traffic, and "spurious" characters displayed
1837 to the user, we cheat and reset the debug protocol. The problems
1838 seems to be caused by a check on the number of arguments, and the
1839 command length, within the monitor causing it to echo the command
1841 if (mips_monitor
!= MON_DDB
&& mips_monitor
!= MON_LSI
)
1844 mips_enter_debug ();
1847 /* Translate a MIPS waitstatus. We use constants here rather than WTERMSIG
1848 and so on, because the constants we want here are determined by the
1849 MIPS protocol and have nothing to do with what host we are running on. */
1850 if ((rstatus
& 0377) == 0)
1852 status
->kind
= TARGET_WAITKIND_EXITED
;
1853 status
->value
.integer
= (((rstatus
) >> 8) & 0377);
1855 else if ((rstatus
& 0377) == 0177)
1857 status
->kind
= TARGET_WAITKIND_STOPPED
;
1858 status
->value
.sig
= mips_signal_from_protocol (((rstatus
) >> 8) & 0377);
1862 status
->kind
= TARGET_WAITKIND_SIGNALLED
;
1863 status
->value
.sig
= mips_signal_from_protocol (rstatus
& 0177);
1869 /* We have to map between the register numbers used by gdb and the
1870 register numbers used by the debugging protocol. This function
1871 assumes that we are using tm-mips.h. */
1873 #define REGNO_OFFSET 96
1876 mips_map_regno (regno
)
1881 if (regno
>= FP0_REGNUM
&& regno
< FP0_REGNUM
+ 32)
1882 return regno
- FP0_REGNUM
+ 32;
1886 return REGNO_OFFSET
+ 0;
1888 return REGNO_OFFSET
+ 1;
1890 return REGNO_OFFSET
+ 2;
1892 return REGNO_OFFSET
+ 3;
1894 return REGNO_OFFSET
+ 4;
1896 return REGNO_OFFSET
+ 5;
1898 /* FIXME: Is there a way to get the status register? */
1903 /* Fetch the remote registers. */
1906 mips_fetch_registers (regno
)
1909 unsigned LONGEST val
;
1914 for (regno
= 0; regno
< NUM_REGS
; regno
++)
1915 mips_fetch_registers (regno
);
1919 if (regno
== FP_REGNUM
|| regno
== ZERO_REGNUM
)
1920 /* FP_REGNUM on the mips is a hack which is just supposed to read
1921 zero (see also mips-nat.c). */
1925 /* If PMON doesn't support this register, don't waste serial
1926 bandwidth trying to read it. */
1927 int pmon_reg
= mips_map_regno (regno
);
1928 if (regno
!= 0 && pmon_reg
== 0)
1932 /* Unfortunately the PMON version in the Vr4300 board has been
1933 compiled without the 64bit register access commands. This
1934 means we cannot get hold of the full register width. */
1935 if (mips_monitor
== MON_DDB
)
1936 val
= (unsigned)mips_request ('t', (unsigned int) pmon_reg
,
1937 (unsigned int) 0, &err
, mips_receive_wait
, NULL
);
1939 val
= mips_request ('r', (unsigned int) pmon_reg
,
1940 (unsigned int) 0, &err
, mips_receive_wait
, NULL
);
1942 mips_error ("Can't read register %d: %s", regno
,
1943 safe_strerror (errno
));
1948 char buf
[MAX_REGISTER_RAW_SIZE
];
1950 /* We got the number the register holds, but gdb expects to see a
1951 value in the target byte ordering. */
1952 store_unsigned_integer (buf
, REGISTER_RAW_SIZE (regno
), val
);
1953 supply_register (regno
, buf
);
1957 /* Prepare to store registers. The MIPS protocol can store individual
1958 registers, so this function doesn't have to do anything. */
1961 mips_prepare_to_store ()
1965 /* Store remote register(s). */
1968 mips_store_registers (regno
)
1975 for (regno
= 0; regno
< NUM_REGS
; regno
++)
1976 mips_store_registers (regno
);
1980 mips_request ('R', (unsigned int) mips_map_regno (regno
),
1981 read_register (regno
),
1982 &err
, mips_receive_wait
, NULL
);
1984 mips_error ("Can't write register %d: %s", regno
, safe_strerror (errno
));
1987 /* Fetch a word from the target board. */
1990 mips_fetch_word (addr
)
1996 /* FIXME! addr was cast to uint! */
1997 val
= mips_request ('d', addr
, (unsigned int) 0, &err
,
1998 mips_receive_wait
, NULL
);
2001 /* Data space failed; try instruction space. */
2002 /* FIXME! addr was cast to uint! */
2003 val
= mips_request ('i', addr
, (unsigned int) 0, &err
,
2004 mips_receive_wait
, NULL
);
2006 mips_error ("Can't read address 0x%s: %s",
2007 paddr_nz (addr
), safe_strerror (errno
));
2012 /* Store a word to the target board. Returns errno code or zero for
2013 success. If OLD_CONTENTS is non-NULL, put the old contents of that
2014 memory location there. */
2016 /* FIXME! make sure only 32-bit quantities get stored! */
2018 mips_store_word (addr
, val
, old_contents
)
2024 unsigned int oldcontents
;
2026 oldcontents
= mips_request ('D', addr
, (unsigned int) val
,
2028 mips_receive_wait
, NULL
);
2031 /* Data space failed; try instruction space. */
2032 oldcontents
= mips_request ('I', addr
,
2033 (unsigned int) val
, &err
,
2034 mips_receive_wait
, NULL
);
2038 if (old_contents
!= NULL
)
2039 store_unsigned_integer (old_contents
, 4, oldcontents
);
2043 /* Read or write LEN bytes from inferior memory at MEMADDR,
2044 transferring to or from debugger address MYADDR. Write to inferior
2045 if SHOULD_WRITE is nonzero. Returns length of data written or
2046 read; 0 for error. Note that protocol gives us the correct value
2047 for a longword, since it transfers values in ASCII. We want the
2048 byte values, so we have to swap the longword values. */
2051 mips_xfer_memory (memaddr
, myaddr
, len
, write
, ignore
)
2056 struct target_ops
*ignore
;
2059 /* Round starting address down to longword boundary. */
2060 register CORE_ADDR addr
= memaddr
&~ 3;
2061 /* Round ending address up; get number of longwords that makes. */
2062 register int count
= (((memaddr
+ len
) - addr
) + 3) / 4;
2063 /* Allocate buffer of that many longwords. */
2064 register char *buffer
= alloca (count
* 4);
2070 /* Fill start and end extra bytes of buffer with existing data. */
2071 if (addr
!= memaddr
|| len
< 4)
2073 /* Need part of initial word -- fetch it. */
2074 store_unsigned_integer (&buffer
[0], 4, mips_fetch_word (addr
));
2079 /* Need part of last word -- fetch it. FIXME: we do this even
2080 if we don't need it. */
2081 store_unsigned_integer (&buffer
[(count
- 1) * 4], 4,
2082 mips_fetch_word (addr
+ (count
- 1) * 4));
2085 /* Copy data to be written over corresponding part of buffer */
2087 memcpy ((char *) buffer
+ (memaddr
& 3), myaddr
, len
);
2089 /* Write the entire buffer. */
2091 for (i
= 0; i
< count
; i
++, addr
+= 4)
2093 status
= mips_store_word (addr
,
2094 extract_unsigned_integer (&buffer
[i
*4], 4),
2096 /* Report each kilobyte (we download 32-bit words at a time) */
2099 printf_unfiltered ("*");
2107 /* FIXME: Do we want a QUIT here? */
2110 printf_unfiltered ("\n");
2114 /* Read all the longwords */
2115 for (i
= 0; i
< count
; i
++, addr
+= 4)
2117 store_unsigned_integer (&buffer
[i
*4], 4, mips_fetch_word (addr
));
2121 /* Copy appropriate bytes out of the buffer. */
2122 memcpy (myaddr
, buffer
+ (memaddr
& 3), len
);
2127 /* Print info on this target. */
2130 mips_files_info (ignore
)
2131 struct target_ops
*ignore
;
2133 printf_unfiltered ("Debugging a MIPS board over a serial line.\n");
2136 /* Kill the process running on the board. This will actually only
2137 work if we are doing remote debugging over the console input. I
2138 think that if IDT/sim had the remote debug interrupt enabled on the
2139 right port, we could interrupt the process with a break signal. */
2144 if (!mips_wait_flag
)
2149 if (interrupt_count
>= 2)
2151 interrupt_count
= 0;
2153 target_terminal_ours ();
2155 if (query ("Interrupted while waiting for the program.\n\
2156 Give up (and stop debugging it)? "))
2158 /* Clean up in such a way that mips_close won't try to talk to the
2159 board (it almost surely won't work since we weren't able to talk to
2164 printf_unfiltered ("Ending remote MIPS debugging.\n");
2165 target_mourn_inferior ();
2167 return_to_top_level (RETURN_QUIT
);
2170 target_terminal_inferior ();
2173 if (remote_debug
> 0)
2174 printf_unfiltered ("Sending break\n");
2176 SERIAL_SEND_BREAK (mips_desc
);
2185 SERIAL_WRITE (mips_desc
, &cc
, 1);
2187 target_mourn_inferior ();
2192 /* Start running on the target board. */
2195 mips_create_inferior (execfile
, args
, env
)
2205 Can't pass arguments to remote MIPS board; arguments ignored.");
2206 /* And don't try to use them on the next "run" command. */
2207 execute_command ("set args", 0);
2210 if (execfile
== 0 || exec_bfd
== 0)
2211 error ("No executable file specified");
2213 entry_pt
= (CORE_ADDR
) bfd_get_start_address (exec_bfd
);
2215 init_wait_for_inferior ();
2217 /* FIXME: Should we set inferior_pid here? */
2219 /* start-sanitize-gm */
2220 #ifdef GENERAL_MAGIC
2221 magic_create_inferior_hook ();
2222 proceed (entry_pt
, TARGET_SIGNAL_PWR
, 0);
2224 /* end-sanitize-gm */
2225 proceed (entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
2226 /* start-sanitize-gm */
2227 #endif /* GENERAL_MAGIC */
2228 /* end-sanitize-gm */
2231 /* Clean up after a process. Actually nothing to do. */
2234 mips_mourn_inferior ()
2236 if (current_ops
!= NULL
)
2237 unpush_target (current_ops
);
2238 generic_mourn_inferior ();
2241 /* We can write a breakpoint and read the shadow contents in one
2244 /* The IDT board uses an unusual breakpoint value, and sometimes gets
2245 confused when it sees the usual MIPS breakpoint instruction. */
2247 #define BREAK_INSN (0x00000a0d)
2248 #define BREAK_INSN_SIZE (4)
2250 /* Insert a breakpoint on targets that don't have any better breakpoint
2251 support. We read the contents of the target location and stash it,
2252 then overwrite it with a breakpoint instruction. ADDR is the target
2253 location in the target machine. CONTENTS_CACHE is a pointer to
2254 memory allocated for saving the target contents. It is guaranteed
2255 by the caller to be long enough to save sizeof BREAKPOINT bytes (this
2256 is accomplished via BREAKPOINT_MAX). */
2259 mips_insert_breakpoint (addr
, contents_cache
)
2261 char *contents_cache
;
2263 if (monitor_supports_breakpoints
)
2264 return common_breakpoint ('B', addr
, 0x3, "f");
2266 return mips_store_word (addr
, BREAK_INSN
, contents_cache
);
2270 mips_remove_breakpoint (addr
, contents_cache
)
2272 char *contents_cache
;
2274 if (monitor_supports_breakpoints
)
2275 return common_breakpoint ('b', addr
, 0, NULL
);
2277 return target_write_memory (addr
, contents_cache
, BREAK_INSN_SIZE
);
2280 #if 0 /* currently not used */
2281 /* PMON does not currently provide support for the debug mode 'b'
2282 commands to manipulate breakpoints. However, if we wanted to use
2283 the monitor breakpoints (rather than the GDB BREAK_INSN version)
2284 then this code performs the work needed to leave debug mode,
2285 set/clear the breakpoint, and then return to debug mode. */
2287 #define PMON_MAX_BP (33) /* 32 SW, 1 HW */
2288 static CORE_ADDR mips_pmon_bp_info
[PMON_MAX_BP
];
2289 /* NOTE: The code relies on this vector being zero-initialised by the system */
2292 pmon_insert_breakpoint (addr
, contents_cache
)
2294 char *contents_cache
;
2298 if (monitor_supports_breakpoints
)
2300 char tbuff
[12]; /* space for breakpoint command */
2304 /* PMON does not support debug level breakpoint set/remove: */
2305 if (mips_exit_debug ())
2306 mips_error ("Failed to exit debug mode");
2308 sprintf (tbuff
, "b %08x\r", addr
);
2309 mips_send_command (tbuff
, 0);
2311 mips_expect ("Bpt ");
2313 if (!mips_getstring (tbuff
, 2))
2315 tbuff
[2] = '\0'; /* terminate the string */
2316 if (sscanf (tbuff
, "%d", &bpnum
) != 1)
2318 fprintf_unfiltered (stderr
, "Invalid decimal breakpoint number from target: %s\n", tbuff
);
2322 mips_expect (" = ");
2324 /* Lead in the hex number we are expecting: */
2328 /* FIXME!! only 8 bytes! need to expand for Bfd64;
2329 which targets return 64-bit addresses? PMON returns only 32! */
2330 if (!mips_getstring (&tbuff
[2], 8))
2332 tbuff
[10] = '\0'; /* terminate the string */
2334 if (sscanf (tbuff
, "0x%08x", &bpaddr
) != 1)
2336 fprintf_unfiltered (stderr
, "Invalid hex address from target: %s\n", tbuff
);
2340 if (bpnum
>= PMON_MAX_BP
)
2342 fprintf_unfiltered (stderr
, "Error: Returned breakpoint number %d outside acceptable range (0..%d)\n",
2343 bpnum
, PMON_MAX_BP
- 1);
2348 fprintf_unfiltered (stderr
, "Warning: Breakpoint addresses do not match: 0x%x != 0x%x\n", addr
, bpaddr
);
2350 mips_pmon_bp_info
[bpnum
] = bpaddr
;
2352 mips_expect ("\r\n");
2353 mips_expect (mips_monitor_prompt
);
2355 mips_enter_debug ();
2360 return mips_store_word (addr
, BREAK_INSN
, contents_cache
);
2364 pmon_remove_breakpoint (addr
, contents_cache
)
2366 char *contents_cache
;
2368 if (monitor_supports_breakpoints
)
2371 char tbuff
[7]; /* enough for delete breakpoint command */
2373 for (bpnum
= 0; bpnum
< PMON_MAX_BP
; bpnum
++)
2374 if (mips_pmon_bp_info
[bpnum
] == addr
)
2377 if (bpnum
>= PMON_MAX_BP
)
2379 fprintf_unfiltered (stderr
,
2380 "pmon_remove_breakpoint: Failed to find breakpoint at address 0x%s\n",
2385 if (mips_exit_debug ())
2386 mips_error ("Failed to exit debug mode");
2388 sprintf (tbuff
, "db %02d\r", bpnum
);
2390 mips_send_command (tbuff
, -1);
2391 /* NOTE: If the breakpoint does not exist then a "Bpt <dd> not
2392 set" message will be returned. */
2394 mips_enter_debug ();
2399 return target_write_memory (addr
, contents_cache
, BREAK_INSN_SIZE
);
2403 /* Compute a don't care mask for the region bounding ADDR and ADDR + LEN - 1.
2404 This is used for memory ref breakpoints. */
2406 static unsigned long
2407 calculate_mask (addr
, len
)
2414 mask
= addr
^ (addr
+ len
- 1);
2416 for (i
= 32; i
>= 0; i
--)
2422 mask
= (unsigned long) 0xffffffff >> i
;
2427 /* Set a data watchpoint. ADDR and LEN should be obvious. TYPE is either 1
2428 for a read watchpoint, or 2 for a read/write watchpoint. */
2431 remote_mips_set_watchpoint (addr
, len
, type
)
2436 CORE_ADDR first_addr
;
2440 mask
= calculate_mask (addr
, len
);
2442 first_addr
= addr
& ~mask
;
2452 case 2: /* read/write */
2459 if (common_breakpoint ('B', first_addr
, mask
, flags
))
2466 remote_mips_remove_watchpoint (addr
, len
, type
)
2471 CORE_ADDR first_addr
;
2474 mask
= calculate_mask (addr
, len
);
2476 first_addr
= addr
& ~mask
;
2478 if (common_breakpoint ('b', first_addr
, 0, NULL
))
2485 remote_mips_stopped_by_watchpoint ()
2487 return hit_watchpoint
;
2490 /* This routine generates the a breakpoint command of the form:
2492 0x0 <CMD> <ADDR> <MASK> <FLAGS>
2494 Where <CMD> is one of: `B' to set, or `b' to clear a breakpoint. <ADDR> is
2495 the address of the breakpoint. <MASK> is a don't care mask for addresses.
2496 <FLAGS> is any combination of `r', `w', or `f' for read/write/or fetch.
2498 Return 0 if successful; otherwise 1. */
2501 common_breakpoint (cmd
, addr
, mask
, flags
)
2508 char buf
[DATA_MAXLEN
+ 1];
2510 int rpid
, rerrflg
, rresponse
;
2513 addr
= ADDR_BITS_REMOVE (addr
);
2515 sprintf (buf
, "0x0 %c 0x%s 0x%s %s", cmd
, paddr_nz (addr
), paddr_nz (mask
),
2518 sprintf (buf
, "0x0 %c 0x%s", cmd
, paddr_nz (addr
));
2520 mips_send_packet (buf
, 1);
2522 len
= mips_receive_packet (buf
, 1, mips_receive_wait
);
2525 nfields
= sscanf (buf
, "0x%x %c 0x%x 0x%x", &rpid
, &rcmd
, &rerrflg
, &rresponse
);
2529 mips_error ("common_breakpoint: Bad response from remote board: %s", buf
);
2533 /* Ddb returns "0x0 b 0x16 0x0\000", whereas
2534 Cogent returns "0x0 b 0xffffffff 0x16\000": */
2535 if (mips_monitor
== MON_DDB
)
2536 rresponse
= rerrflg
;
2537 if (rresponse
!= 22) /* invalid argument */
2538 fprintf_unfiltered (stderr
, "common_breakpoint (0x%s): Got error: 0x%x\n",
2539 paddr_nz (addr
), rresponse
);
2547 send_srec (srec
, len
, addr
)
2556 SERIAL_WRITE (mips_desc
, srec
, len
);
2558 ch
= mips_readchar (2);
2562 case SERIAL_TIMEOUT
:
2563 error ("Timeout during download.");
2567 case 0x15: /* NACK */
2568 fprintf_unfiltered (gdb_stderr
, "Download got a NACK at byte %d! Retrying.\n", addr
);
2571 error ("Download got unexpected ack char: 0x%x, retrying.\n", ch
);
2576 /* Download a binary file by converting it to S records. */
2579 mips_load_srec (args
)
2584 char *buffer
, srec
[1024];
2586 unsigned int srec_frame
= 200;
2588 static int hashmark
= 1;
2590 buffer
= alloca (srec_frame
* 2 + 256);
2592 abfd
= bfd_openr (args
, 0);
2595 printf_filtered ("Unable to open file %s\n", args
);
2599 if (bfd_check_format (abfd
, bfd_object
) == 0)
2601 printf_filtered ("File is not an object file\n");
2605 /* This actually causes a download in the IDT binary format: */
2606 mips_send_command (LOAD_CMD
, 0);
2608 for (s
= abfd
->sections
; s
; s
= s
->next
)
2610 if (s
->flags
& SEC_LOAD
)
2612 unsigned int numbytes
;
2614 /* FIXME! vma too small?? */
2615 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s
->name
, s
->vma
,
2616 s
->vma
+ s
->_raw_size
);
2617 gdb_flush (gdb_stdout
);
2619 for (i
= 0; i
< s
->_raw_size
; i
+= numbytes
)
2621 numbytes
= min (srec_frame
, s
->_raw_size
- i
);
2623 bfd_get_section_contents (abfd
, s
, buffer
, i
, numbytes
);
2625 reclen
= mips_make_srec (srec
, '3', s
->vma
+ i
, buffer
, numbytes
);
2626 send_srec (srec
, reclen
, s
->vma
+ i
);
2630 putchar_unfiltered ('#');
2631 gdb_flush (gdb_stdout
);
2634 } /* Per-packet (or S-record) loop */
2636 putchar_unfiltered ('\n');
2637 } /* Loadable sections */
2640 putchar_unfiltered ('\n');
2642 /* Write a type 7 terminator record. no data for a type 7, and there
2643 is no data, so len is 0. */
2645 reclen
= mips_make_srec (srec
, '7', abfd
->start_address
, NULL
, 0);
2647 send_srec (srec
, reclen
, abfd
->start_address
);
2649 SERIAL_FLUSH_INPUT (mips_desc
);
2653 * mips_make_srec -- make an srecord. This writes each line, one at a
2654 * time, each with it's own header and trailer line.
2655 * An srecord looks like this:
2657 * byte count-+ address
2658 * start ---+ | | data +- checksum
2660 * S01000006F6B692D746573742E73726563E4
2661 * S315000448600000000000000000FC00005900000000E9
2662 * S31A0004000023C1400037DE00F023604000377B009020825000348D
2663 * S30B0004485A0000000000004E
2666 * S<type><length><address><data><checksum>
2670 * is the number of bytes following upto the checksum. Note that
2671 * this is not the number of chars following, since it takes two
2672 * chars to represent a byte.
2676 * 1) two byte address data record
2677 * 2) three byte address data record
2678 * 3) four byte address data record
2679 * 7) four byte address termination record
2680 * 8) three byte address termination record
2681 * 9) two byte address termination record
2684 * is the start address of the data following, or in the case of
2685 * a termination record, the start address of the image
2689 * is the sum of all the raw byte data in the record, from the length
2690 * upwards, modulo 256 and subtracted from 255.
2692 * This routine returns the length of the S-record.
2697 mips_make_srec (buf
, type
, memaddr
, myaddr
, len
)
2701 unsigned char *myaddr
;
2704 unsigned char checksum
;
2707 /* Create the header for the srec. addr_size is the number of bytes in the address,
2708 and 1 is the number of bytes in the count. */
2710 /* FIXME!! bigger buf required for 64-bit! */
2713 buf
[2] = len
+ 4 + 1; /* len + 4 byte address + 1 byte checksum */
2714 /* This assumes S3 style downloads (4byte addresses). There should
2715 probably be a check, or the code changed to make it more
2717 buf
[3] = memaddr
>> 24;
2718 buf
[4] = memaddr
>> 16;
2719 buf
[5] = memaddr
>> 8;
2721 memcpy (&buf
[7], myaddr
, len
);
2723 /* Note that the checksum is calculated on the raw data, not the
2724 hexified data. It includes the length, address and the data
2725 portions of the packet. */
2727 buf
+= 2; /* Point at length byte */
2728 for (i
= 0; i
< len
+ 4 + 1; i
++)
2736 /* The following manifest controls whether we enable the simple flow
2737 control support provided by the monitor. If enabled the code will
2738 wait for an affirmative ACK between transmitting packets. */
2739 #define DOETXACK (1)
2741 /* The PMON fast-download uses an encoded packet format constructed of
2742 3byte data packets (encoded as 4 printable ASCII characters), and
2743 escape sequences (preceded by a '/'):
2746 'C' compare checksum (12bit value, not included in checksum calculation)
2747 'S' define symbol name (for addr) terminated with "," and padded to 4char boundary
2748 'Z' zero fill multiple of 3bytes
2749 'B' byte (12bit encoded value, of 8bit data)
2750 'A' address (36bit encoded value)
2751 'E' define entry as original address, and exit load
2753 The packets are processed in 4 character chunks, so the escape
2754 sequences that do not have any data (or variable length data)
2755 should be padded to a 4 character boundary. The decoder will give
2756 an error if the complete message block size is not a multiple of
2757 4bytes (size of record).
2759 The encoding of numbers is done in 6bit fields. The 6bit value is
2760 used to index into this string to get the specific character
2761 encoding for the value: */
2762 static char encoding
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,.";
2764 /* Convert the number of bits required into an encoded number, 6bits
2765 at a time (range 0..63). Keep a checksum if required (passed
2766 pointer non-NULL). The function returns the number of encoded
2767 characters written into the buffer. */
2769 pmon_makeb64 (v
, p
, n
, chksum
)
2775 int count
= (n
/ 6);
2777 if ((n
% 12) != 0) {
2778 fprintf_unfiltered(stderr
,"Fast encoding bitcount must be a multiple of 12bits: %dbit%s\n",n
,(n
== 1)?"":"s");
2782 fprintf_unfiltered(stderr
,"Fast encoding cannot process more than 36bits at the moment: %dbits\n",n
);
2786 /* Deal with the checksum: */
2787 if (chksum
!= NULL
) {
2789 case 36: *chksum
+= ((v
>> 24) & 0xFFF);
2790 case 24: *chksum
+= ((v
>> 12) & 0xFFF);
2791 case 12: *chksum
+= ((v
>> 0) & 0xFFF);
2797 *p
++ = encoding
[(v
>> n
) & 0x3F];
2803 /* Shorthand function (that could be in-lined) to output the zero-fill
2804 escape sequence into the data stream. */
2806 pmon_zeroset (recsize
, buff
, amount
, chksum
)
2810 unsigned int *chksum
;
2814 sprintf(*buff
,"/Z");
2815 count
= pmon_makeb64 (*amount
, (*buff
+ 2), 12, chksum
);
2816 *buff
+= (count
+ 2);
2818 return(recsize
+ count
+ 2);
2822 pmon_checkset (recsize
, buff
, value
)
2829 /* Add the checksum (without updating the value): */
2830 sprintf (*buff
, "/C");
2831 count
= pmon_makeb64 (*value
, (*buff
+ 2), 12, NULL
);
2832 *buff
+= (count
+ 2);
2833 sprintf (*buff
, "\n");
2834 *buff
+= 2; /* include zero terminator */
2835 /* Forcing a checksum validation clears the sum: */
2837 return(recsize
+ count
+ 3);
2840 /* Amount of padding we leave after at the end of the output buffer,
2841 for the checksum and line termination characters: */
2842 #define CHECKSIZE (4 + 4 + 4 + 2)
2843 /* zero-fill, checksum, transfer end and line termination space. */
2845 /* The amount of binary data loaded from the object file in a single
2847 #define BINCHUNK (1024)
2849 /* Maximum line of data accepted by the monitor: */
2850 #define MAXRECSIZE (550)
2851 /* NOTE: This constant depends on the monitor being used. This value
2852 is for PMON 5.x on the Cogent Vr4300 board. */
2855 pmon_make_fastrec (outbuf
, inbuf
, inptr
, inamount
, recsize
, csum
, zerofill
)
2857 unsigned char *inbuf
;
2862 unsigned int *zerofill
;
2867 /* This is a simple check to ensure that our data will fit within
2868 the maximum allowable record size. Each record output is 4bytes
2869 in length. We must allow space for a pending zero fill command,
2870 the record, and a checksum record. */
2871 while ((*recsize
< (MAXRECSIZE
- CHECKSIZE
)) && ((inamount
- *inptr
) > 0)) {
2872 /* Process the binary data: */
2873 if ((inamount
- *inptr
) < 3) {
2875 *recsize
= pmon_zeroset (*recsize
, &p
, zerofill
, csum
);
2877 count
= pmon_makeb64 (inbuf
[*inptr
], &p
[2], 12, csum
);
2879 *recsize
+= (2 + count
);
2882 unsigned int value
= ((inbuf
[*inptr
+ 0] << 16) | (inbuf
[*inptr
+ 1] << 8) | inbuf
[*inptr
+ 2]);
2883 /* Simple check for zero data. TODO: A better check would be
2884 to check the last, and then the middle byte for being zero
2885 (if the first byte is not). We could then check for
2886 following runs of zeros, and if above a certain size it is
2887 worth the 4 or 8 character hit of the byte insertions used
2888 to pad to the start of the zeroes. NOTE: This also depends
2889 on the alignment at the end of the zero run. */
2890 if (value
== 0x00000000) {
2892 if (*zerofill
== 0xFFF) /* 12bit counter */
2893 *recsize
= pmon_zeroset (*recsize
, &p
, zerofill
, csum
);
2896 *recsize
= pmon_zeroset (*recsize
, &p
, zerofill
, csum
);
2897 count
= pmon_makeb64 (value
, p
, 24, csum
);
2910 pmon_check_ack(mesg
)
2913 #if defined(DOETXACK)
2918 c
= SERIAL_READCHAR (udp_in_use
? udp_desc
: mips_desc
, 2);
2919 if ((c
== SERIAL_TIMEOUT
) || (c
!= 0x06))
2921 fprintf_unfiltered (gdb_stderr
,
2922 "Failed to receive valid ACK for %s\n", mesg
);
2923 return(-1); /* terminate the download */
2926 #endif /* DOETXACK */
2930 /* pmon_download - Send a sequence of characters to the PMON download port,
2931 which is either a serial port or a UDP socket. */
2934 pmon_start_download ()
2938 /* Create the temporary download file. */
2939 if ((tftp_file
= fopen (tftp_localname
, "w")) == NULL
)
2940 perror_with_name (tftp_localname
);
2944 mips_send_command (udp_in_use
? LOAD_CMD_UDP
: LOAD_CMD
, 0);
2945 mips_expect ("Downloading from ");
2946 mips_expect (udp_in_use
? "udp" : "tty0");
2947 mips_expect (", ^C to abort\r\n");
2952 mips_expect_download (char *string
)
2954 if (!mips_expect (string
))
2956 fprintf_unfiltered (gdb_stderr
, "Load did not complete successfully.\n");
2958 remove (tftp_localname
); /* Remove temporary file */
2966 pmon_end_download (final
, bintotal
)
2970 char hexnumber
[9]; /* includes '\0' space */
2974 static char *load_cmd_prefix
= "load -b -s ";
2978 /* Close off the temporary file containing the load data. */
2982 /* Make the temporary file readable by the world. */
2983 if (stat (tftp_localname
, &stbuf
) == 0)
2984 chmod (tftp_localname
, stbuf
.st_mode
| S_IROTH
);
2986 /* Must reinitialize the board to prevent PMON from crashing. */
2987 mips_send_command ("initEther\r", -1);
2989 /* Send the load command. */
2990 cmd
= xmalloc (strlen (load_cmd_prefix
) + strlen (tftp_name
) + 2);
2991 strcpy (cmd
, load_cmd_prefix
);
2992 strcat (cmd
, tftp_name
);
2994 mips_send_command (cmd
, 0);
2996 if (!mips_expect_download ("Downloading from "))
2998 if (!mips_expect_download (tftp_name
))
3000 if (!mips_expect_download (", ^C to abort\r\n"))
3004 /* Wait for the stuff that PMON prints after the load has completed.
3005 The timeout value for use in the tftp case (15 seconds) was picked
3006 arbitrarily but might be too small for really large downloads. FIXME. */
3007 if (mips_monitor
== MON_LSI
)
3009 pmon_check_ack ("termination");
3010 mips_expect_timeout ("Entry address is ", tftp_in_use
? 15 : 2);
3013 mips_expect_timeout ("Entry Address = ", tftp_in_use
? 15 : 2);
3015 sprintf (hexnumber
,"%x",final
);
3016 mips_expect (hexnumber
);
3017 mips_expect ("\r\n");
3018 if (mips_monitor
!= MON_LSI
)
3019 pmon_check_ack ("termination");
3020 mips_expect ("\r\ntotal = 0x");
3021 sprintf (hexnumber
,"%x",bintotal
);
3022 mips_expect (hexnumber
);
3023 if (!mips_expect_download (" bytes\r\n"))
3027 remove (tftp_localname
); /* Remove temporary file */
3031 pmon_download (buffer
, length
)
3036 fwrite (buffer
, 1, length
, tftp_file
);
3038 SERIAL_WRITE (udp_in_use
? udp_desc
: mips_desc
, buffer
, length
);
3042 pmon_load_fast (file
)
3047 unsigned char *binbuf
;
3050 unsigned int csum
= 0;
3051 int hashmark
= !tftp_in_use
;
3056 buffer
= (char *)xmalloc(MAXRECSIZE
+ 1);
3057 binbuf
= (unsigned char *)xmalloc(BINCHUNK
);
3059 abfd
= bfd_openr(file
,0);
3062 printf_filtered ("Unable to open file %s\n",file
);
3066 if (bfd_check_format(abfd
,bfd_object
) == 0)
3068 printf_filtered("File is not an object file\n");
3072 /* Setup the required download state: */
3073 mips_send_command ("set dlproto etxack\r", -1);
3074 mips_send_command ("set dlecho off\r", -1);
3075 /* NOTE: We get a "cannot set variable" message if the variable is
3076 already defined to have the argument we give. The code doesn't
3077 care, since it just scans to the next prompt anyway. */
3078 /* Start the download: */
3079 pmon_start_download();
3081 /* Zero the checksum */
3082 sprintf(buffer
,"/Kxx\n");
3083 reclen
= strlen(buffer
);
3084 pmon_download (buffer
, reclen
);
3085 finished
= pmon_check_ack("/Kxx");
3087 for (s
= abfd
->sections
; s
&& !finished
; s
= s
->next
)
3088 if (s
->flags
& SEC_LOAD
) /* only deal with loadable sections */
3090 bintotal
+= s
->_raw_size
;
3091 final
= (s
->vma
+ s
->_raw_size
);
3093 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s
->name
, (unsigned int)s
->vma
,
3094 (unsigned int)(s
->vma
+ s
->_raw_size
));
3095 gdb_flush (gdb_stdout
);
3097 /* Output the starting address */
3098 sprintf(buffer
,"/A");
3099 reclen
= pmon_makeb64(s
->vma
,&buffer
[2],36,&csum
);
3100 buffer
[2 + reclen
] = '\n';
3101 buffer
[3 + reclen
] = '\0';
3102 reclen
+= 3; /* for the initial escape code and carriage return */
3103 pmon_download (buffer
, reclen
);
3104 finished
= pmon_check_ack("/A");
3108 unsigned int binamount
;
3109 unsigned int zerofill
= 0;
3115 for (i
= 0; ((i
< s
->_raw_size
) && !finished
); i
+= binamount
) {
3118 binamount
= min (BINCHUNK
, s
->_raw_size
- i
);
3120 bfd_get_section_contents (abfd
, s
, binbuf
, i
, binamount
);
3122 /* This keeps a rolling checksum, until we decide to output
3124 for (; ((binamount
- binptr
) > 0);) {
3125 pmon_make_fastrec (&bp
, binbuf
, &binptr
, binamount
, &reclen
, &csum
, &zerofill
);
3126 if (reclen
>= (MAXRECSIZE
- CHECKSIZE
)) {
3127 reclen
= pmon_checkset (reclen
, &bp
, &csum
);
3128 pmon_download (buffer
, reclen
);
3129 finished
= pmon_check_ack("data record");
3131 zerofill
= 0; /* do not transmit pending zerofills */
3136 putchar_unfiltered ('#');
3137 gdb_flush (gdb_stdout
);
3141 reclen
= 0; /* buffer processed */
3146 /* Ensure no out-standing zerofill requests: */
3148 reclen
= pmon_zeroset (reclen
, &bp
, &zerofill
, &csum
);
3150 /* and then flush the line: */
3152 reclen
= pmon_checkset (reclen
, &bp
, &csum
);
3153 /* Currently pmon_checkset outputs the line terminator by
3154 default, so we write out the buffer so far: */
3155 pmon_download (buffer
, reclen
);
3156 finished
= pmon_check_ack("record remnant");
3160 putchar_unfiltered ('\n');
3163 /* Terminate the transfer. We know that we have an empty output
3164 buffer at this point. */
3165 sprintf (buffer
, "/E/E\n"); /* include dummy padding characters */
3166 reclen
= strlen (buffer
);
3167 pmon_download (buffer
, reclen
);
3169 if (finished
) { /* Ignore the termination message: */
3170 SERIAL_FLUSH_INPUT (udp_in_use
? udp_desc
: mips_desc
);
3171 } else { /* Deal with termination message: */
3172 pmon_end_download (final
, bintotal
);
3178 /* mips_load -- download a file. */
3181 mips_load (file
, from_tty
)
3185 /* Get the board out of remote debugging mode. */
3186 if (mips_exit_debug ())
3187 error ("mips_load: Couldn't get into monitor mode.");
3189 if (mips_monitor
!= MON_IDT
)
3190 pmon_load_fast (file
);
3192 mips_load_srec (file
);
3196 /* Finally, make the PC point at the start address */
3197 if (mips_monitor
== MON_DDB
)
3199 /* Work around problem where DDB monitor does not update the
3200 PC after a load. The following ensures that the write_pc()
3201 WILL update the PC value: */
3202 register_valid
[PC_REGNUM
] = 0;
3205 write_pc (bfd_get_start_address (exec_bfd
));
3207 inferior_pid
= 0; /* No process now */
3209 /* This is necessary because many things were based on the PC at the time that
3210 we attached to the monitor, which is no longer valid now that we have loaded
3211 new code (and just changed the PC). Another way to do this might be to call
3212 normal_stop, except that the stack may not be valid, and things would get
3213 horribly confused... */
3215 clear_symtab_users ();
3218 /* The target vector. */
3220 struct target_ops mips_ops
=
3222 "mips", /* to_shortname */
3223 "Remote MIPS debugging over serial line", /* to_longname */
3225 Debug a board using the MIPS remote debugging protocol over a serial line.\n\
3226 The argument is the device it is connected to or, if it contains a colon,\n\
3227 HOST:PORT to access a board over a network", /* to_doc */
3228 mips_open
, /* to_open */
3229 mips_close
, /* to_close */
3230 NULL
, /* to_attach */
3231 mips_detach
, /* to_detach */
3232 mips_resume
, /* to_resume */
3233 mips_wait
, /* to_wait */
3234 mips_fetch_registers
, /* to_fetch_registers */
3235 mips_store_registers
, /* to_store_registers */
3236 mips_prepare_to_store
, /* to_prepare_to_store */
3237 mips_xfer_memory
, /* to_xfer_memory */
3238 mips_files_info
, /* to_files_info */
3239 mips_insert_breakpoint
, /* to_insert_breakpoint */
3240 mips_remove_breakpoint
, /* to_remove_breakpoint */
3241 NULL
, /* to_terminal_init */
3242 NULL
, /* to_terminal_inferior */
3243 NULL
, /* to_terminal_ours_for_output */
3244 NULL
, /* to_terminal_ours */
3245 NULL
, /* to_terminal_info */
3246 mips_kill
, /* to_kill */
3247 mips_load
, /* to_load */
3248 NULL
, /* to_lookup_symbol */
3249 mips_create_inferior
, /* to_create_inferior */
3250 mips_mourn_inferior
, /* to_mourn_inferior */
3251 NULL
, /* to_can_run */
3252 NULL
, /* to_notice_signals */
3253 0, /* to_thread_alive */
3255 process_stratum
, /* to_stratum */
3257 1, /* to_has_all_memory */
3258 1, /* to_has_memory */
3259 1, /* to_has_stack */
3260 1, /* to_has_registers */
3261 1, /* to_has_execution */
3262 NULL
, /* sections */
3263 NULL
, /* sections_end */
3264 OPS_MAGIC
/* to_magic */
3267 /* An alternative target vector: */
3268 struct target_ops pmon_ops
=
3270 "pmon", /* to_shortname */
3271 "Remote MIPS debugging over serial line", /* to_longname */
3273 Debug a board using the PMON MIPS remote debugging protocol over a serial\n\
3274 line. The argument is the device it is connected to or, if it contains a\n\
3275 colon, HOST:PORT to access a board over a network", /* to_doc */
3276 pmon_open
, /* to_open */
3277 mips_close
, /* to_close */
3278 NULL
, /* to_attach */
3279 mips_detach
, /* to_detach */
3280 mips_resume
, /* to_resume */
3281 pmon_wait
, /* to_wait */
3282 mips_fetch_registers
, /* to_fetch_registers */
3283 mips_store_registers
, /* to_store_registers */
3284 mips_prepare_to_store
, /* to_prepare_to_store */
3285 mips_xfer_memory
, /* to_xfer_memory */
3286 mips_files_info
, /* to_files_info */
3287 mips_insert_breakpoint
, /* to_insert_breakpoint */
3288 mips_remove_breakpoint
, /* to_remove_breakpoint */
3289 NULL
, /* to_terminal_init */
3290 NULL
, /* to_terminal_inferior */
3291 NULL
, /* to_terminal_ours_for_output */
3292 NULL
, /* to_terminal_ours */
3293 NULL
, /* to_terminal_info */
3294 mips_kill
, /* to_kill */
3295 mips_load
, /* to_load */
3296 NULL
, /* to_lookup_symbol */
3297 mips_create_inferior
, /* to_create_inferior */
3298 mips_mourn_inferior
, /* to_mourn_inferior */
3299 NULL
, /* to_can_run */
3300 NULL
, /* to_notice_signals */
3301 0, /* to_thread_alive */
3303 process_stratum
, /* to_stratum */
3305 1, /* to_has_all_memory */
3306 1, /* to_has_memory */
3307 1, /* to_has_stack */
3308 1, /* to_has_registers */
3309 1, /* to_has_execution */
3310 NULL
, /* sections */
3311 NULL
, /* sections_end */
3312 OPS_MAGIC
/* to_magic */
3315 /* Another alternative target vector. This is a PMON system, but with
3316 a different monitor prompt, aswell as some other operational
3318 struct target_ops ddb_ops
=
3320 "ddb", /* to_shortname */
3321 "Remote MIPS debugging over serial line", /* to_longname */
3323 Debug a board using the PMON MIPS remote debugging protocol over a serial\n\
3324 line. The first argument is the device it is connected to or, if it contains\n\
3325 a colon, HOST:PORT to access a board over a network. The optional second\n\
3326 parameter is the temporary file in the form HOST:FILENAME to be used for\n\
3327 TFTP downloads to the board. The optional third parameter is the local\n\
3328 of the TFTP temporary file, if it differs from the filename seen by the board",
3330 ddb_open
, /* to_open */
3331 mips_close
, /* to_close */
3332 NULL
, /* to_attach */
3333 mips_detach
, /* to_detach */
3334 mips_resume
, /* to_resume */
3335 pmon_wait
, /* to_wait */
3336 mips_fetch_registers
, /* to_fetch_registers */
3337 mips_store_registers
, /* to_store_registers */
3338 mips_prepare_to_store
, /* to_prepare_to_store */
3339 mips_xfer_memory
, /* to_xfer_memory */
3340 mips_files_info
, /* to_files_info */
3341 mips_insert_breakpoint
, /* to_insert_breakpoint */
3342 mips_remove_breakpoint
, /* to_remove_breakpoint */
3343 NULL
, /* to_terminal_init */
3344 NULL
, /* to_terminal_inferior */
3345 NULL
, /* to_terminal_ours_for_output */
3346 NULL
, /* to_terminal_ours */
3347 NULL
, /* to_terminal_info */
3348 mips_kill
, /* to_kill */
3349 mips_load
, /* to_load */
3350 NULL
, /* to_lookup_symbol */
3351 mips_create_inferior
, /* to_create_inferior */
3352 mips_mourn_inferior
, /* to_mourn_inferior */
3353 NULL
, /* to_can_run */
3354 NULL
, /* to_notice_signals */
3355 0, /* to_thread_alive */
3357 process_stratum
, /* to_stratum */
3359 1, /* to_has_all_memory */
3360 1, /* to_has_memory */
3361 1, /* to_has_stack */
3362 1, /* to_has_registers */
3363 1, /* to_has_execution */
3364 NULL
, /* sections */
3365 NULL
, /* sections_end */
3366 OPS_MAGIC
/* to_magic */
3369 /* Another alternative target vector for LSI Logic MiniRISC boards.
3370 This is a PMON system, but with some other operational differences. */
3371 struct target_ops lsi_ops
=
3373 "lsi", /* to_shortname */
3374 "Remote MIPS debugging over serial line", /* to_longname */
3376 Debug a board using the PMON MIPS remote debugging protocol over a serial\n\
3377 line. The first argument is the device it is connected to or, if it contains\n\
3378 a colon, HOST:PORT to access a board over a network. The optional second\n\
3379 parameter is the temporary file in the form HOST:FILENAME to be used for\n\
3380 TFTP downloads to the board. The optional third parameter is the local\n\
3381 of the TFTP temporary file, if it differs from the filename seen by the board",
3383 lsi_open
, /* to_open */
3384 mips_close
, /* to_close */
3385 NULL
, /* to_attach */
3386 mips_detach
, /* to_detach */
3387 mips_resume
, /* to_resume */
3388 pmon_wait
, /* to_wait */
3389 mips_fetch_registers
, /* to_fetch_registers */
3390 mips_store_registers
, /* to_store_registers */
3391 mips_prepare_to_store
, /* to_prepare_to_store */
3392 mips_xfer_memory
, /* to_xfer_memory */
3393 mips_files_info
, /* to_files_info */
3394 mips_insert_breakpoint
, /* to_insert_breakpoint */
3395 mips_remove_breakpoint
, /* to_remove_breakpoint */
3396 NULL
, /* to_terminal_init */
3397 NULL
, /* to_terminal_inferior */
3398 NULL
, /* to_terminal_ours_for_output */
3399 NULL
, /* to_terminal_ours */
3400 NULL
, /* to_terminal_info */
3401 mips_kill
, /* to_kill */
3402 mips_load
, /* to_load */
3403 NULL
, /* to_lookup_symbol */
3404 mips_create_inferior
, /* to_create_inferior */
3405 mips_mourn_inferior
, /* to_mourn_inferior */
3406 NULL
, /* to_can_run */
3407 NULL
, /* to_notice_signals */
3408 0, /* to_thread_alive */
3410 process_stratum
, /* to_stratum */
3412 1, /* to_has_all_memory */
3413 1, /* to_has_memory */
3414 1, /* to_has_stack */
3415 1, /* to_has_registers */
3416 1, /* to_has_execution */
3417 NULL
, /* sections */
3418 NULL
, /* sections_end */
3419 OPS_MAGIC
/* to_magic */
3423 _initialize_remote_mips ()
3425 add_target (&mips_ops
);
3426 add_target (&pmon_ops
);
3427 add_target (&ddb_ops
);
3428 add_target (&lsi_ops
);
3431 add_set_cmd ("timeout", no_class
, var_zinteger
,
3432 (char *) &mips_receive_wait
,
3433 "Set timeout in seconds for remote MIPS serial I/O.",
3438 add_set_cmd ("retransmit-timeout", no_class
, var_zinteger
,
3439 (char *) &mips_retransmit_wait
,
3440 "Set retransmit timeout in seconds for remote MIPS serial I/O.\n\
3441 This is the number of seconds to wait for an acknowledgement to a packet\n\
3442 before resending the packet.", &setlist
),
3446 add_set_cmd ("syn-garbage-limit", no_class
, var_zinteger
,
3447 (char *) &mips_syn_garbage
,
3448 "Set the maximum number of characters to ignore when scanning for a SYN.\n\
3449 This is the maximum number of characters GDB will ignore when trying to\n\
3450 synchronize with the remote system. A value of -1 means that there is no limit\n\
3451 (Note that these characters are printed out even though they are ignored.)",
3456 (add_set_cmd ("monitor-prompt", class_obscure
, var_string
,
3457 (char *) &mips_monitor_prompt
,
3458 "Set the prompt that GDB expects from the monitor.",