1 /* Remote debugging interface for boot monitors, for GDB.
2 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Rob Savoye for Cygnus.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file was derived from various remote-* modules. It is a collection
22 of generic support functions so GDB can talk directly to a ROM based
23 monitor. This saves use from having to hack an exception based handler
24 into existance, and makes for quick porting.
26 This module talks to a debug monitor called 'MONITOR', which
27 We communicate with MONITOR via either a direct serial line, or a TCP
28 (or possibly TELNET) stream to a terminal multiplexor,
29 which in turn talks to the target board.
39 #include <sys/types.h>
43 #include "remote-utils.h"
45 #if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY)
52 # define TERMINAL struct termios
55 # define TERMINAL struct sgttyb
59 #define CSTOPB 0x00000040
62 static const char hexchars
[]="0123456789abcdef";
63 static char *hex2mem();
65 #define SWAP_TARGET_AND_HOST(buffer,len) \
68 if (TARGET_BYTE_ORDER != HOST_BYTE_ORDER) \
71 char *p = (char *)(buffer); \
72 char *q = ((char *)(buffer)) + len - 1; \
73 for (; p < q; p++, q--) \
83 static void make_xmodem_packet();
84 static void print_xmodem_packet();
85 static void make_gdb_packet();
86 static unsigned long ascii2hexword();
87 static char *hexword2ascii();
90 static int from_hex();
92 struct monitor_ops
*current_monitor
;
93 extern struct cmd_list_element
*setlist
;
94 extern struct cmd_list_element
*unsetlist
;
95 struct cmd_list_element
*showlist
;
97 extern char *host_name
;
98 extern char *target_name
;
100 static int hashmark
; /* flag set by "set hash" */
102 #define LOG_FILE "monitor.log"
103 #if defined (LOG_FILE)
107 static int timeout
= 30;
108 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
109 and i386-stub.c. Normally, no one would notice because it only matters
110 for writing large chunks of memory (e.g. in downloads). Also, this needs
111 to be more than 400 if required to hold the registers (see below, where
112 we round it up based on REGISTER_BYTES). */
116 * Descriptor for I/O to remote machine. Initialize it to NULL so that
117 * monitor_open knows that we don't have a file open when the program starts.
119 serial_t monitor_desc
= NULL
;
121 /* sets the download protocol, choices are srec, generic, boot */
123 static char *loadtype_str
;
124 static char *loadproto_str
;
125 static void set_loadtype_command();
126 static void set_loadproto_command();
127 static void monitor_load_srec();
128 static int monitor_write_srec();
131 * these definitions are for xmodem protocol
138 #define GETACK getacknak(ACK)
139 #define GETNAK getacknak(NAK)
140 #define XMODEM_DATASIZE 128 /* the data size is ALWAYS 128 */
141 #define XMODEM_PACKETSIZE 131 /* the packet size is ALWAYS 132 (zero based) */
145 * set_loadtype_command -- set the type for downloading. Check to make
146 * sure you have a support protocol for this target.
149 set_loadtype_command (ignore
, from_tty
, c
)
152 struct cmd_list_element
*c
;
157 if (current_monitor
== 0x0)
160 if (STREQ (LOADTYPES
, "")) {
161 error ("No loadtype set");
165 tmp
= savestring (LOADTYPES
, strlen(LOADTYPES
));
166 type
= strtok(tmp
, ",");
167 if (STREQ (type
, (*(char **) c
->var
))) {
168 loadtype_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
172 while ((type
= strtok (NULL
, ",")) != (char *)NULL
) {
173 if (STREQ (type
, (*(char **) c
->var
)))
174 loadtype_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
178 error ("Loadtype \"%s\" does not exist.", (*(char **) c
->var
));
181 * set_loadproto_command -- set the protocol for downloading. Check to make
182 * sure you have a supported protocol for this target.
185 set_loadproto_command (ignore
, from_tty
, c
)
188 struct cmd_list_element
*c
;
193 if (current_monitor
== 0x0)
196 if (STREQ (LOADPROTOS
, "")) {
197 error ("No load protocols set");
201 tmp
= savestring (LOADPROTOS
, strlen(LOADPROTOS
));
202 type
= strtok(tmp
, ",");
203 if (STREQ (type
, (*(char **) c
->var
))) {
204 loadproto_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
208 while ((type
= strtok (NULL
, ",")) != (char *)NULL
) {
209 if (STREQ (type
, (*(char **) c
->var
)))
210 loadproto_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
214 error ("Load protocol \"%s\" does not exist.", (*(char **) c
->var
));
218 * printf_monitor -- send data to monitor. Works just like printf.
221 printf_monitor(va_alist
)
231 pattern
= va_arg(args
, char *);
233 vsprintf(buf
, pattern
, args
);
235 debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf
);
237 if (strlen(buf
) > PBUFSIZ
)
238 error ("printf_monitor(): string too long");
239 if (SERIAL_WRITE(monitor_desc
, buf
, strlen(buf
)))
240 fprintf(stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror(errno
));
243 * write_monitor -- send raw data to monitor.
246 write_monitor(data
, len
)
250 if (SERIAL_WRITE(monitor_desc
, data
, len
))
251 fprintf(stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror(errno
));
253 *(data
+ len
+1) = '\0';
254 debuglogs (1, "write_monitor(), Sending: \"%s\".", data
);
259 * debuglogs -- deal with debugging info to multiple sources. This takes
260 * two real args, the first one is the level to be compared against
261 * the sr_get_debug() value, the second arg is a printf buffer and args
262 * to be formatted and printed. A CR is added after each string is printed.
270 unsigned char buf
[PBUFSIZ
];
271 char newbuf
[PBUFSIZ
];
276 level
= va_arg(args
, int); /* get the debug level */
277 if ((level
<0) || (level
> 100)) {
278 error ("Bad argument passed to debuglogs(), needs debug level");
282 pattern
= va_arg(args
, char *); /* get the printf style pattern */
284 vsprintf(buf
, pattern
, args
); /* format the string */
286 /* convert some characters so it'll look right in the log */
288 for (i
= 0 ; buf
[i
] != '\0'; i
++) {
290 error ("Debug message too long");
292 case '\n': /* newlines */
296 case '\r': /* carriage returns */
300 case '\033': /* escape */
308 case '\b': /* backspace */
312 default: /* no change */
316 if (buf
[i
] < 26) { /* modify control characters */
321 if (buf
[i
] >= 128) { /* modify control characters */
327 *p
= '\0'; /* terminate the string */
329 if (sr_get_debug() > level
)
332 #ifdef LOG_FILE /* write to the monitor log */
333 if (log_file
!= 0x0) {
334 fputs (newbuf
, log_file
);
335 fputc ('\n', log_file
);
341 /* readchar -- read a character from the remote system, doing all the fancy
350 c
= SERIAL_READCHAR(monitor_desc
, timeout
);
352 if (sr_get_debug() > 5) {
354 debuglogs (5, "readchar: timeout = %d\n", timeout
);
359 putc(c
& 0x7f, log_file
);
365 if (c
== SERIAL_TIMEOUT
) {
367 return c
; /* Polls shouldn't generate timeout errors */
368 error("Timeout reading from remote system.");
370 fputs ("ERROR: Timeout reading from remote system", log_file
);
373 perror_with_name("remote-monitor");
377 * expect -- scan input from the remote system, until STRING is found.
378 * If DISCARD is non-zero, then discard non-matching input, else print
379 * it out. Let the user break out immediately.
382 expect (string
, discard
)
390 debuglogs (1, "Expecting \"%s\".", string
);
394 c
= readchar(timeout
);
400 debuglogs (4, "Matched");
405 fwrite(string
, 1, (p
- 1) - string
, stdout
);
414 /* Keep discarding input until we see the MONITOR prompt.
416 The convention for dealing with the prompt is that you
418 o *then* wait for the prompt.
420 Thus the last thing that a procedure does with the serial line
421 will be an expect_prompt(). Exception: monitor_resume does not
422 wait for the prompt, because the terminal is being handed over
423 to the inferior. However, the next thing which happens after that
424 is a monitor_wait which does wait for the prompt.
425 Note that this includes abnormal exit, e.g. error(). This is
426 necessary to prevent getting into states from which we can't
429 expect_prompt(discard
)
432 expect (PROMPT
, discard
);
436 * junk -- ignore junk characters. Returns a 1 if junk, 0 otherwise
449 if (sr_get_debug() > 5)
450 debuglogs (5, "Ignoring \'%c\'.", ch
);
453 if (sr_get_debug() > 5)
454 debuglogs (5, "Accepting \'%c\'.", ch
);
460 * get_hex_digit -- Get a hex digit from the remote system & return its value.
461 * If ignore is nonzero, ignore spaces, newline & tabs.
464 get_hex_digit(ignore
)
469 ch
= readchar(timeout
);
472 if (sr_get_debug() > 4) {
473 debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch
, ch
);
475 #ifdef LOG_FILE /* write to the monitor log */
476 if (log_file
!= 0x0) {
477 fputs ("get_hex_digit() got a 0x", log_file
);
478 fputc (ch
, log_file
);
479 fputc ('\n', log_file
);
485 if (ch
>= '0' && ch
<= '9')
487 else if (ch
>= 'A' && ch
<= 'F')
488 return ch
- 'A' + 10;
489 else if (ch
>= 'a' && ch
<= 'f')
490 return ch
- 'a' + 10;
491 else if (ch
== ' ' && ignore
)
495 debuglogs (4, "Invalid hex digit from remote system. (0x%x)", ch
);
496 error("Invalid hex digit from remote system. (0x%x)", ch
);
501 /* get_hex_byte -- Get a byte from monitor and put it in *BYT.
502 * Accept any number leading spaces.
510 val
= get_hex_digit (1) << 4;
511 debuglogs (4, "get_hex_byte() -- Read first nibble 0x%x", val
);
513 val
|= get_hex_digit (0);
514 debuglogs (4, "get_hex_byte() -- Read second nibble 0x%x", val
);
517 debuglogs (4, "get_hex_byte() -- Read a 0x%x", val
);
521 * get_hex_word -- Get N 32-bit words from remote, each preceded by a space,
522 * and put them in registers starting at REGNO.
533 if (HOST_BYTE_ORDER
== BIG_ENDIAN
) {
535 for (i
= 0; i
< 8; i
++)
536 val
= (val
<< 4) + get_hex_digit (i
== 0);
539 for (i
= 7; i
>= 0; i
--)
540 val
= (val
<< 4) + get_hex_digit (i
== 0);
544 debuglogs (4, "get_hex_word() got a 0x%x for a %s host.", val
, (HOST_BYTE_ORDER
== BIG_ENDIAN
) ? "big endian" : "little endian");
549 /* This is called not only when we first attach, but also when the
550 user types "run" after having attached. */
552 monitor_create_inferior (execfile
, args
, env
)
560 error("Can't pass arguments to remote MONITOR process");
562 if (execfile
== 0 || exec_bfd
== 0)
563 error("No exec file specified");
565 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
567 /* The "process" (board) is already stopped awaiting our commands, and
568 the program is already downloaded. We just set its PC and go. */
570 clear_proceed_status ();
572 /* Tell wait_for_inferior that we've started a new process. */
573 init_wait_for_inferior ();
575 /* Set up the "saved terminal modes" of the inferior
576 based on what modes we are starting it with. */
577 target_terminal_init ();
579 /* Install inferior's terminal modes. */
580 target_terminal_inferior ();
582 /* insert_step_breakpoint (); FIXME, do we need this? */
585 proceed ((CORE_ADDR
)entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
589 * monitor_open -- open a connection to a remote debugger.
590 * NAME is the filename used for communication.
592 static int baudrate
= 9600;
593 static char dev_name
[100];
596 monitor_open(args
, name
, from_tty
)
601 TERMINAL
*temptempio
;
604 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
605 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name
, name
);
610 strcpy(dev_name
, args
);
611 monitor_desc
= SERIAL_OPEN(dev_name
);
613 if (monitor_desc
== NULL
)
614 perror_with_name(dev_name
);
616 if (baud_rate
!= -1) {
617 if (SERIAL_SETBAUDRATE (monitor_desc
, baud_rate
)) {
618 SERIAL_CLOSE (monitor_desc
);
619 perror_with_name (name
);
623 SERIAL_RAW(monitor_desc
);
625 #if !defined(__GO32__) && !defined(GDB_TARGET_IS_PA_ELF)
626 /* some systems only work with 2 stop bits */
628 temptempio
= (TERMINAL
*)SERIAL_GET_TTY_STATE(monitor_desc
);
630 temptempio
->sg_cflag
|= baud_rate
| CSTOPB
;
632 temptempio
->c_cflag
|= baud_rate
| CSTOPB
;
633 /*** temptempio->c_lflag |= ~0x00000008; turn off echo ***/
635 SERIAL_SET_TTY_STATE(monitor_desc
, temptempio
);
636 debuglogs (4, "Set serial port to 2 stop bits");
638 #endif /* __GO32__ */
640 #if defined (LOG_FILE)
641 log_file
= fopen (LOG_FILE
, "w");
642 if (log_file
== NULL
)
643 perror_with_name (LOG_FILE
);
644 fprintf_filtered (log_file
, "GDB %s (%s", version
, host_name
);
645 fprintf_filtered (log_file
, " --target %s)\n", target_name
);
646 fprintf_filtered (log_file
, "Remote target %s connected to %s\n\n", TARGET_NAME
, dev_name
);
649 /* see if the target is alive. For a ROM monitor, we can just try to force the
650 prompt to print a few times. FOr the GDB remote protocol, the application
651 being debugged is sitting at a breakpoint and waiting for GDB to initialize
652 the connection. We force it to give us an empty packet to see if it's alive.
655 debuglogs (3, "Trying to ACK the target's debug stub");
656 printf_monitor (INIT_CMD
); /* ask for the last signal */
657 expect ("$S05#b8",0); /* look for a response */
658 printf_monitor ("+"); /* ask for the last signal */
659 expect_prompt(1); /* See if we get a prompt */
661 /* wake up the monitor and see if it's alive */
662 printf_monitor(INIT_CMD
);
663 expect_prompt(1); /* See if we get a prompt */
665 /* try again to be sure */
666 printf_monitor(INIT_CMD
);
667 expect_prompt(1); /* See if we get a prompt */
671 printf("Remote target %s connected to %s\n", TARGET_NAME
, dev_name
);
675 * monitor_close -- Close out all files and local state before this
676 * target loses control.
680 monitor_close (quitting
)
683 SERIAL_CLOSE(monitor_desc
);
686 debuglogs (1, "monitor_close (quitting=%d)", quitting
);
688 #if defined (LOG_FILE)
690 if (ferror(log_file
))
691 fprintf(stderr
, "Error writing log file.\n");
692 if (fclose(log_file
) != 0)
693 fprintf(stderr
, "Error closing log file.\n");
699 * monitor_detach -- terminate the open connection to the remote
700 * debugger. Use this when you want to detach and do something
701 * else with your gdb.
704 monitor_detach (from_tty
)
708 debuglogs (1, "monitor_detach ()");
710 pop_target(); /* calls monitor_close to do the real work */
712 printf ("Ending remote %s debugging\n", target_shortname
);
716 * monitor_attach -- attach GDB to the target.
719 monitor_attach (args
, from_tty
)
724 printf ("Starting remote %s debugging\n", target_shortname
);
726 debuglogs (1, "monitor_attach (args=%s)", args
);
728 printf_monitor (GO_CMD
);
729 /* swallow the echo. */
734 * monitor_resume -- Tell the remote machine to resume.
737 monitor_resume (pid
, step
, sig
)
739 enum target_signal sig
;
741 debuglogs (1, "monitor_resume (step=%d, sig=%d)", step
, sig
);
744 printf_monitor (STEP_CMD
);
746 printf_monitor (CONT_CMD
);
751 * monitor_wait -- Wait until the remote machine stops, then return,
752 * storing status in status just as `wait' would.
755 monitor_wait (pid
, status
)
757 struct target_waitstatus
*status
;
759 int old_timeout
= timeout
;
761 debuglogs(1, "monitor_wait (), printing extraneous text.");
763 status
->kind
= TARGET_WAITKIND_EXITED
;
764 status
->value
.integer
= 0;
766 timeout
= 0; /* Don't time out -- user program is running. */
768 expect_prompt(0); /* Wait for prompt, outputting extraneous text */
769 debuglogs (4, "monitor_wait(), got the prompt.");
771 status
->kind
= TARGET_WAITKIND_STOPPED
;
772 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
776 timeout
= old_timeout
;
781 /* Return the name of register number regno in the form input and output by
782 monitor. Currently, register_names just happens to contain exactly what
783 monitor wants. Lets take advantage of that just as long as possible! */
798 for (p
= REGNAMES(regno
); *p
; p
++)
803 debuglogs (5, "Got name \"%s\" from regno #%d.", buf
, regno
);
809 * monitor_fetch_registers -- read the remote registers into the
813 monitor_fetch_registers (ignored
)
818 unsigned char packet
[PBUFSIZ
];
819 char regs
[REGISTER_BYTES
];
821 debuglogs (1, "monitor_fetch_registers (ignored=%d)\n", ignored
);
823 memset (packet
, 0, PBUFSIZ
);
825 /* Unimplemented registers read as all bits zero. */
826 memset (regs
, 0, REGISTER_BYTES
);
827 make_gdb_packet (packet
, "g");
828 if (monitor_send_packet (packet
) == 0)
829 error ("Couldn't transmit packet\n");
830 if (monitor_get_packet (packet
) == 0)
831 error ("Couldn't receive packet\n");
832 /* FIXME: read bytes from packet */
833 debuglogs (4, "monitor_fetch_registers: Got a \"%s\" back\n", packet
);
834 for (regno
= 0; regno
<= PC_REGNUM
+4; regno
++) {
835 /* supply register stores in target byte order, so swap here */
836 /* FIXME: convert from ASCII hex to raw bytes */
837 i
= ascii2hexword (packet
+ (regno
* 8));
838 debuglogs (5, "Adding register %d = %x\n", regno
, i
);
839 SWAP_TARGET_AND_HOST (&i
, 4);
840 supply_register (regno
, (char *)&i
);
843 for (regno
= 0; regno
<= PC_REGNUM
; regno
++)
844 monitor_fetch_register(regno
);
849 * monitor_fetch_register -- fetch register REGNO, or all registers if REGNO
850 * is -1. Returns errno value.
853 monitor_fetch_register (regno
)
858 debuglogs (1, "monitor_fetch_register (reg=%s)", get_reg_name (regno
));
861 monitor_fetch_registers ();
863 char *name
= get_reg_name (regno
);
866 printf_monitor (ROMCMD(GET_REG
), name
); /* send the command */
867 expect (name
, 1); /* then strip the leading garbage */
868 if (*ROMDELIM(GET_REG
) != 0) { /* if there's a delimiter */
869 expect (ROMDELIM(GET_REG
), 1);
872 val
= get_hex_word(); /* get the value, ignore junk */
875 /* supply register stores in target byte order, so swap here */
876 SWAP_TARGET_AND_HOST (&val
, 4);
877 supply_register (regno
, (char *) &val
);
879 if (*ROMDELIM(GET_REG
) != 0) {
880 /*** expect (ROMRES(GET_REG)); ***/
881 printf_monitor (CMD_END
);
889 * monitor_store_registers - store the remote registers.
892 monitor_store_registers (ignored
)
897 char packet
[PBUFSIZ
];
901 debuglogs (1, "monitor_store_registers()");
904 memset (packet
, 0, PBUFSIZ
);
905 memset (buf
, 0, PBUFSIZ
);
908 /* Unimplemented registers read as all bits zero. */
909 /* FIXME: read bytes from packet */
910 for (regno
= 0; regno
< 41; regno
++) { /* FIXME */
911 /* supply register stores in target byte order, so swap here */
912 /* FIXME: convert from ASCII hex to raw bytes */
913 i
= (unsigned long)read_register (regno
);
915 SWAP_TARGET_AND_HOST (&i
, 4);
917 hexword2ascii (num
, i
);
918 strcpy (buf
+(regno
* 8)+1, num
);
920 *(buf
+ (regno
* 8) + 2) = 0;
921 make_gdb_packet (packet
, buf
);
922 if (monitor_send_packet (packet
) == 0)
923 error ("Couldn't transmit packet\n");
924 if (monitor_get_packet (packet
) == 0)
925 error ("Couldn't receive packet\n");
927 for (regno
= 0; regno
<= PC_REGNUM
; regno
++)
928 monitor_store_register(regno
);
931 registers_changed ();
935 * monitor_store_register -- store register REGNO, or all if REGNO == 0.
936 * return errno value.
939 monitor_store_register (regno
)
945 i
= read_register(regno
);
947 debuglogs (1, "monitor_store_register (regno=%d)", regno
);
950 monitor_store_registers ();
952 debuglogs (3, "Setting register %s to 0x%x", get_reg_name (regno
), read_register (regno
));
954 name
= get_reg_name (regno
);
957 printf_monitor (ROMCMD(SET_REG
), name
, read_register(regno
));
958 expect (name
, 1); /* strip the leading garbage */
959 if (*ROMDELIM(SET_REG
) != 0) { /* if there's a delimiter */
960 expect (ROMDELIM(SET_REG
), 1);
962 printf_monitor ("%d%s\n", i
, CMD_END
);
969 printf_monitor (SET_REG
, get_reg_name (regno
),
970 read_register (regno
));
976 /* Get ready to modify the registers array. On machines which store
977 individual registers, this doesn't need to do anything. On machines
978 which store all the registers in one fell swoop, this makes sure
979 that registers contains all the registers from the program being
983 monitor_prepare_to_store ()
985 /* Do nothing, since we can store individual regs */
989 monitor_files_info ()
991 printf ("\tAttached to %s at %d baud.\n",
996 * monitor_write_inferior_memory -- Copy LEN bytes of data from debugger
997 * memory at MYADDR to inferior's memory at MEMADDR. Returns length moved.
1000 monitor_write_inferior_memory (memaddr
, myaddr
, len
)
1002 unsigned char *myaddr
;
1007 char packet
[PBUFSIZ
];
1012 debuglogs (1, "monitor_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
1013 memset (buf
, '\0', PBUFSIZ
); /* this also sets the string terminator */
1017 *p
++ = 'M'; /* The command to write memory */
1018 hexword2ascii (num
, memaddr
); /* convert the address */
1019 strcpy (p
, num
); /* copy the address */
1021 *p
++ = ','; /* add comma delimeter */
1022 hexword2ascii (num
, len
); /* Get the length as a 4 digit number */
1027 *p
++ = ':'; /* add the colon delimeter */
1028 for (j
= 0; j
< len
; j
++) { /* copy the data in after converting it */
1030 hexword2ascii (num
, myaddr
[j
]);
1032 *p
++ = tohex ((myaddr
[j
] >> 4) & 0xf);
1033 *p
++ = tohex (myaddr
[j
] & 0xf);
1035 strcpy ((buf
+14)+(j
* 2), num
+6);
1039 make_gdb_packet (packet
, buf
);
1040 if (monitor_send_packet (packet
) == 0)
1041 error ("Couldn't transmit packet\n");
1042 if (monitor_get_packet (packet
) == 0)
1043 error ("Couldn't receive packet\n");
1045 for (i
= 0; i
< len
; i
++) {
1046 printf_monitor (ROMCMD(SET_MEM
), memaddr
+ i
, myaddr
[i
] );
1047 if (*ROMDELIM(SET_MEM
) != 0) { /* if there's a delimiter */
1048 expect (ROMDELIM(SET_MEM
), 1);
1050 printf_monitor ("%x", myaddr
[i
]);
1052 /*** printf_monitor ("%x", myaddr[i]); ***/
1053 if (sr_get_debug() > 1)
1054 printf ("\nSet 0x%x to 0x%x\n", memaddr
+ i
, myaddr
[i
]);
1055 if (*ROMDELIM(SET_MEM
) != 0) {
1057 printf_monitor (CMD_END
);
1066 * monitor_read_inferior_memory -- read LEN bytes from inferior memory
1067 * at MEMADDR. Put the result at debugger address MYADDR. Returns
1071 monitor_read_inferior_memory(memaddr
, myaddr
, len
)
1078 char packet
[PBUFSIZ
];
1080 /* Number of bytes read so far. */
1083 /* Starting address of this pass. */
1084 unsigned long startaddr
;
1086 /* Starting address of this pass. */
1087 unsigned long endaddr
;
1089 /* Number of bytes to read in this pass. */
1092 debuglogs (1, "monitor_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
1094 /* Note that this code works correctly if startaddr is just less
1095 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
1096 thing). That is, something like
1097 monitor_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
1098 works--it never adds len To memaddr and gets 0. */
1099 /* However, something like
1100 monitor_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
1101 doesn't need to work. Detect it and give up if there's an attempt
1103 if (((memaddr
- 1) + len
) < memaddr
) {
1108 startaddr
= memaddr
;
1110 while (count
< len
) {
1112 if ((startaddr
% 16) != 0)
1113 len_this_pass
-= startaddr
% 16;
1114 if (len_this_pass
> (len
- count
))
1115 len_this_pass
= (len
- count
);
1117 debuglogs (3, "Display %d bytes at %x for Big Endian host", len_this_pass
, startaddr
);
1120 for (i
= 0; i
< len_this_pass
; i
++) {
1121 sprintf (buf
, "m%08x,%04x", startaddr
, len_this_pass
);
1122 make_gdb_packet (packet
, buf
);
1123 if (monitor_send_packet (packet
) == 0)
1124 error ("Couldn't transmit packet\n");
1125 if (monitor_get_packet (packet
) == 0)
1126 error ("Couldn't receive packet\n");
1127 debuglogs (4, "monitor_read_inferior: Got a \"%s\" back\n", packet
);
1128 for (j
= 0; j
< len_this_pass
; j
++) { /* extract the byte values */
1129 myaddr
[count
++] = from_hex (*(packet
+(j
*2))) * 16 + from_hex (*(packet
+(j
*2)+1));
1130 debuglogs (5, "myaddr set to %x\n", myaddr
[count
-1]);
1135 for (i
= 0; i
< len_this_pass
; i
++) {
1136 printf_monitor (ROMCMD(GET_MEM
), startaddr
, startaddr
);
1137 sprintf (buf
, ROMCMD(GET_MEM
), startaddr
, startaddr
);
1138 if (*ROMDELIM(GET_MEM
) != 0) { /* if there's a delimiter */
1139 expect (ROMDELIM(GET_MEM
), 1);
1141 sprintf (buf
, ROMCMD(GET_MEM
), startaddr
, startaddr
);
1142 expect (buf
,1); /* get the command echo */
1143 get_hex_word(1); /* strip away the address */
1145 get_hex_byte (&myaddr
[count
++]); /* get the value at this address */
1147 if (*ROMDELIM(GET_MEM
) != 0) {
1148 printf_monitor (CMD_END
);
1158 /* FIXME-someday! merge these two. */
1160 monitor_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1165 struct target_ops
*target
; /* ignored */
1168 return monitor_write_inferior_memory (memaddr
, myaddr
, len
);
1170 return monitor_read_inferior_memory (memaddr
, myaddr
, len
);
1174 monitor_kill (args
, from_tty
)
1178 return; /* ignore attempts to kill target system */
1181 /* Clean up when a program exits.
1182 The program actually lives on in the remote processor's RAM, and may be
1183 run again without a download. Don't leave it full of breakpoint
1187 monitor_mourn_inferior ()
1189 remove_breakpoints ();
1190 generic_mourn_inferior (); /* Do all the proper things now */
1193 #define MAX_MONITOR_BREAKPOINTS 16
1195 extern int memory_breakpoint_size
;
1196 static CORE_ADDR breakaddr
[MAX_MONITOR_BREAKPOINTS
] = {0};
1199 * monitor_insert_breakpoint -- add a breakpoint
1202 monitor_insert_breakpoint (addr
, shadow
)
1208 debuglogs (1, "monitor_insert_breakpoint() addr = 0x%x", addr
);
1210 for (i
= 0; i
<= MAX_MONITOR_BREAKPOINTS
; i
++) {
1211 if (breakaddr
[i
] == 0) {
1212 breakaddr
[i
] = addr
;
1213 if (sr_get_debug() > 4)
1214 printf ("Breakpoint at %x\n", addr
);
1215 monitor_read_inferior_memory(addr
, shadow
, memory_breakpoint_size
);
1216 printf_monitor(SET_BREAK_CMD
, addr
);
1222 fprintf(stderr
, "Too many breakpoints (> 16) for monitor\n");
1227 * _remove_breakpoint -- Tell the monitor to remove a breakpoint
1230 monitor_remove_breakpoint (addr
, shadow
)
1236 debuglogs (1, "monitor_remove_breakpoint() addr = 0x%x", addr
);
1238 for (i
= 0; i
< MAX_MONITOR_BREAKPOINTS
; i
++) {
1239 if (breakaddr
[i
] == addr
) {
1241 /* some monitors remove breakpoints based on the address */
1243 printf_monitor(CLR_BREAK_CMD
, addr
);
1245 printf_monitor(CLR_BREAK_CMD
, i
);
1250 fprintf(stderr
, "Can't find breakpoint associated with 0x%x\n", addr
);
1254 /* monitor_load -- load a file. This file determines which of the
1255 * supported formats to use. The current types are:
1256 * FIXME: not all types supported yet.
1257 * default - reads any file using bfd and writes it to memory. This
1259 * srec - reads binary file using bfd and writes it as an
1261 * xmodem-bin - reads a binary file using bfd, and downloads it
1262 * using xmodem protocol.
1263 * xmodem-srec - reads a binary file using bfd, and after converting
1264 * it downloads it as an srecord using xmodem protocol.
1265 * ascii-srec - reads a ascii srecord file and downloads it
1267 * ascii-xmodem - reads a ascii file and downloads using xmodem
1271 monitor_load (file
, fromtty
)
1278 debuglogs (1, "Loading %s to monitor", file
);
1280 if (STREQ (loadtype_str
, "default")) { /* default, load a binary */
1281 gr_load_image (file
, fromtty
); /* by writing it into memory */
1285 /* load an srecord by converting */
1286 if ((STREQ (loadtype_str
, "srec")) && STREQ (loadproto_str
, "xmodem")) {
1287 monitor_load_srec(file
, XMODEM
);
1291 if (STREQ (loadtype_str
, "srec")) { /* load an srecord by converting */
1292 monitor_load_srec(file
, 0); /* if from a binary */
1296 if (STREQ (loadtype_str
, "none")) { /* load an srecord by converting */
1297 error ("Unimplemented");
1301 if (STREQ (loadproto_str
, "none")) { /* load an srecord file */
1302 monitor_load_ascii_srec(file
, fromtty
); /* if from a binary */
1306 if (STREQ (loadproto_str
, "xmodem")) { /* load an srecord using the */
1307 monitor_load_srec(file
, XMODEM
);
1313 * monitor_load_ascii_srec -- download an ASCII srecord file.
1315 #define DOWNLOAD_LINE_SIZE 100
1317 monitor_load_ascii_srec (file
, fromtty
)
1322 char buf
[DOWNLOAD_LINE_SIZE
];
1325 debuglogs (1, "Loading an ASCII srecord file, %s.", file
);
1327 download
= fopen (file
, "r");
1328 if (download
== NULL
) {
1329 error ("%s Does not exist", file
);
1333 printf_monitor (LOAD_CMD
);
1335 while (!feof (download
)) {
1336 bytes_read
= fread (buf
, sizeof (char), DOWNLOAD_LINE_SIZE
, download
);
1341 if (SERIAL_WRITE(monitor_desc
, buf
, bytes_read
)) {
1342 fprintf(stderr
, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno
));
1346 while (i
++ <=200) {} ; /* Ugly HACK, probably needs flow control */
1347 if (bytes_read
< DOWNLOAD_LINE_SIZE
) {
1348 if (!feof (download
))
1349 error ("Only read %d bytes\n", bytes_read
);
1357 if (!feof (download
))
1358 error ("Never got EOF while downloading");
1364 * monitor_command -- put a command string, in args, out to MONITOR.
1365 * Output from MONITOR is placed on the users terminal until the
1366 * prompt is seen. FIXME: We read the charcters ourseleves here
1367 * cause of a nasty echo.
1370 monitor_command (args
, fromtty
)
1379 debuglogs (1, "monitor_command (args=%s)", args
);
1381 if (monitor_desc
== NULL
)
1382 error("monitor target not open.");
1385 error("Missing command.");
1387 printf_monitor ("%s\n", args
);
1393 * monitor_load_srec -- download a binary file by converting it to srecords. This
1394 * will also use xmodem to download the resulting file.
1396 * A download goes like this when using xmodem:
1399 * <-------- (packet) [SOH|1|1|data|SUM]
1401 * <-------- (packet) [SOH|2|2|data|SUM]
1412 monitor_load_srec (args
, protocol
)
1420 char packet
[XMODEM_PACKETSIZE
];
1423 int type
= 0; /* default to a type 0, header record */
1424 int srec_frame
= 57; /* FIXME: this must be 57 There is 12 bytes
1425 of header, and 2 bytes of checksum at the end.
1426 The problem is an xmodem packet holds exactly
1429 abfd
= bfd_openr (args
, 0);
1431 printf_filtered ("Unable to open file %s\n", args
);
1435 if (bfd_check_format (abfd
, bfd_object
) == 0) {
1436 printf_filtered ("File is not an object file\n");
1440 printf_monitor (LOAD_CMD
); /* tell the monitor to load */
1441 if (protocol
== XMODEM
) { /* get the NAK from the target */
1443 debuglogs (3, "Got the NAK to start loading");
1445 printf_monitor ("%c", EOT
);
1446 debuglogs (3, "Never got the NAK to start loading");
1447 error ("Never got the NAK to start loading");
1452 while (s
!= (asection
*) NULL
) {
1453 if (s
->flags
& SEC_LOAD
) {
1454 char *buffer
= xmalloc (srec_frame
);
1455 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
1457 for (i
= 0; i
< s
->_raw_size
; i
+= srec_frame
) {
1458 if (srec_frame
> s
->_raw_size
- i
)
1459 srec_frame
= s
->_raw_size
- i
;
1461 bfd_get_section_contents (abfd
, s
, buffer
, i
, srec_frame
);
1462 monitor_make_srec (srec
, type
, s
->vma
+ i
, buffer
, srec_frame
);
1463 if (protocol
== XMODEM
) { /* send a packet using xmodem */
1464 make_xmodem_packet (packet
, srec
, XMODEM_DATASIZE
);
1465 write_monitor (packet
, XMODEM_PACKETSIZE
+1);
1467 while (retries
++ <= 3) {
1468 if (GETNAK
) { /* Resend packet */
1469 debuglogs (3, "Got a NAK, resending packet");
1471 write_monitor (packet
, XMODEM_PACKETSIZE
+1); /* send it again */
1472 if (GETACK
) /* ACKnowledged, get next data chunk */
1474 } else { /* assume we got an ACK */
1476 printf_filtered ("#");
1477 debuglogs (3, "Got an ACK, sending next packet");
1481 if (retries
>= 4) { /* too many tries, must be hosed */
1482 printf_monitor ("%c", EOT
);
1483 error ("Never got a ACK after sending an xmodem packet");
1485 } else { /* no protocols at all */
1486 printf_monitor ("%s\n", srec
);
1489 printf_filtered ("#");
1490 type
= 3; /* switch to a 4 byte address record */
1495 debuglogs (3, "%s doesn't need to be loaded", s
->name
);
1499 printf_filtered ("\n");
1502 write a type 7 terminator record. no data for a type 7,
1503 and there is no data, so len is 0.
1505 if (protocol
== XMODEM
) { /* send a packet using xmodem */
1506 monitor_make_srec (srec
, 7, abfd
->start_address
, "", 0);
1507 make_xmodem_packet (packet
, srec
, XMODEM_DATASIZE
);
1508 write_monitor (packet
, XMODEM_PACKETSIZE
+1);
1510 monitor_make_srec (srec
, 7, abfd
->start_address
, "", 0);
1511 printf_monitor ("%s\n", srec
);
1513 if (protocol
== XMODEM
) {
1514 printf_monitor ("%c", EOT
);
1516 error ("Never got ACK after sending EOT");
1526 * getacknak -- get an ACK or a NAK from the target.
1527 * returns 1 (true) or 0 (false) This is
1528 * for xmodem. ANy string starting with "***"
1529 * is an error message from the target.
1530 * Here's a few from the WinBond w89k "Cougar" PA board.
1531 * *** Too many errors found.
1533 * *** Command syntax error
1544 character
= (char)readchar (0);
1545 if ((character
== 0xfffffffe) || (character
== 0x7f)) { /* empty uart */
1546 if (sr_get_debug() > 3)
1552 if (character
== CANCEL
) { /* target aborted load */
1554 error ("Got a CANCEL from the target.");
1556 if (character
== '*') { /* look for missed error message */
1558 error ("Got an error message from the target");
1560 debuglogs (3, "Got a %s (0x%x or \'%c\'), expecting a %s.\n",
1561 (character
== ACK
) ? "ACK" : (character
== NAK
) ? "NAK" : "BOGUS",
1562 character
, character
, (byte
== ACK
) ? "ACK" : "NAK");
1563 if (character
== byte
) /* got what we wanted */
1565 if (character
== ((byte
== ACK
) ? NAK
: ACK
)) { /* got the opposite */
1566 debuglogs (3, "Got the opposite, wanted 0x%x, got a 0x%x", byte
, character
);
1575 * monitor_make_srec -- make an srecord. This writes each line, one at a
1576 * time, each with it's own header and trailer line.
1577 * An srecord looks like this:
1579 * byte count-+ address
1580 * start ---+ | | data +- checksum
1582 * S01000006F6B692D746573742E73726563E4
1583 * S315000448600000000000000000FC00005900000000E9
1584 * S31A0004000023C1400037DE00F023604000377B009020825000348D
1585 * S30B0004485A0000000000004E
1588 * S<type><length><address><data><checksum>
1592 * is the number of bytes following upto the checksum. Note that
1593 * this is not the number of chars following, since it takes two
1594 * chars to represent a byte.
1598 * 1) two byte address data record
1599 * 2) three byte address data record
1600 * 3) four byte address data record
1601 * 7) four byte address termination record
1602 * 8) three byte address termination record
1603 * 9) two byte address termination record
1606 * is the start address of the data following, or in the case of
1607 * a termination record, the start address of the image
1611 * is the sum of all the raw byte data in the record, from the length
1612 * upwards, modulo 256 and subtracted from 255.
1615 monitor_make_srec (buffer
, type
, memaddr
, myaddr
, len
)
1619 unsigned char *myaddr
;
1627 debuglogs (4, "monitor_make_srec (buffer=0x%x, type=%d, memaddr=0x%x, len=%d",
1628 buffer
, type
, memaddr
, len
);
1632 create the header for the srec. 4 is the number of bytes in the address,
1633 and 1 is the number of bytes in the count.
1635 if (type
== 0) /* FIXME: type 0 is optional */
1636 type
= 3; /* so use data as it works */
1637 sprintf (buf
, "S%d%02X%08X", type
, len
+ 4 + 1, memaddr
);
1640 checksum
+= (len
+ 4 + 1 /* calculate the checksum */
1642 + ((memaddr
>> 8) & 0xff)
1643 + ((memaddr
>> 16) & 0xff)
1644 + ((memaddr
>> 24) & 0xff));
1646 for (i
= 0; i
< len
; i
++) { /* build the srecord */
1647 sprintf (buf
, "%02X", myaddr
[i
]);
1648 checksum
+= myaddr
[i
];
1652 sprintf(buf
, "%02X", ~checksum
& 0xff); /* add the checksum */
1653 debuglogs (3, "srec is \"%s\"", buffer
);
1659 * make_xmodem_packet -- this takes a 128 bytes of data and makes a packet
1662 * Each packet looks like this:
1663 * +-----+-------+-------+------+-----+
1664 * | SOH | Seq1. | Seq2. | data | SUM |
1665 * +-----+-------+-------+------+-----+
1667 * Seq1 = The sequence number.
1668 * Seq2 = The complement of the sequence number.
1669 * Data = A 128 bytes of data.
1670 * SUM = Add the contents of the 128 bytes and use the low-order
1671 * 8 bits of the result.
1674 make_xmodem_packet (packet
, data
, len
)
1675 unsigned char packet
[];
1676 unsigned char *data
;
1679 static int sequence
= 1;
1684 /* build the packet header */
1686 packet
[1] = sequence
;
1687 packet
[2] = 255 - sequence
;
1690 packet
[2] = ~sequence
++; /* the complement is the sequence checksum */
1693 sum
= 0; /* calculate the data checksum */
1694 for (i
= 3; i
<= len
+ 2; i
++) {
1700 for (i
= len
+1 ; i
<= XMODEM_DATASIZE
; i
++) { /* add padding for the rest of the packet */
1704 packet
[XMODEM_PACKETSIZE
] = sum
& 0xff; /* add the checksum */
1706 if (sr_get_debug() > 4) {
1707 debuglogs (4, "The xmodem checksum is %d (0x%x)\n", sum
& 0xff, sum
& 0xff);
1708 print_xmodem_packet (packet
);
1713 * print_xmodem_packet -- print the packet as a debug check
1716 print_xmodem_packet(packet
)
1723 /* take apart the packet header the packet header */
1724 if (packet
[0] == SOH
) {
1727 error ("xmodem: SOH is wrong");
1730 /* check the sequence */
1731 if (packet
[1] != 0) {
1732 lastseq
= packet
[1];
1733 if (packet
[2] != ~lastseq
)
1734 error ("xmodem: Sequence checksum is wrong");
1736 printf_filtered (" %d %d", lastseq
, ~lastseq
);
1739 /* check the data checksum */
1741 for (i
= 3; i
<= XMODEM_DATASIZE
; i
++) {
1745 /* ignore the data */
1747 printf (" [128 bytes of data] %d\n", sum
& 0xff);
1749 printf_filtered (" [%s] %d\n", packet
, sum
& 0xff);
1751 if ((packet
[XMODEM_PACKETSIZE
] & 0xff) != (sum
& 0xff)) {
1752 debuglogs (4, "xmodem: data checksum wrong, got a %d", packet
[XMODEM_PACKETSIZE
] & 0xff);
1758 * make_gdb_packet -- make a GDB packet. The data is always ASCII.
1759 * A debug packet whose contents are <data>
1760 * is encapsulated for transmission in the form:
1762 * $ <data> # CSUM1 CSUM2
1764 * <data> must be ASCII alphanumeric and cannot include characters
1765 * '$' or '#'. If <data> starts with two characters followed by
1766 * ':', then the existing stubs interpret this as a sequence number.
1768 * CSUM1 and CSUM2 are ascii hex representation of an 8-bit
1769 * checksum of <data>, the most significant nibble is sent first.
1770 * the hex digits 0-9,a-f are used.
1774 make_gdb_packet (buf
, data
)
1778 unsigned char csum
= 0;
1782 debuglogs (3, "make_gdb_packet(%s)\n", data
);
1783 cnt
= strlen (data
);
1785 error ("make_gdb_packet(): to much data\n");
1787 /* start with the packet header */
1791 /* calculate the checksum */
1792 for (i
= 0; i
< cnt
; i
++) {
1797 /* terminate the data with a '#' */
1800 /* add the checksum as two ascii digits */
1801 *p
++ = tohex ((csum
>> 4) & 0xf);
1802 *p
++ = tohex (csum
& 0xf);
1803 *p
= 0x0; /* Null terminator on string */
1807 * monitor_send_packet -- send a GDB packet to the target with error handling. We
1808 * get a '+' (ACK) back if the packet is received and the checksum
1809 * matches. Otherwise a '-' (NAK) is returned. It returns a 1 for a
1810 * successful transmition, or a 0 for a failure.
1813 monitor_send_packet (packet
)
1822 /* scan the packet to make sure it only contains valid characters.
1823 this may sound silly, but sometimes a garbled packet will hang
1824 the target board. We scan the whole thing, then print the error
1827 for (i
= 0; i
< strlen(packet
); i
++) {
1828 debuglogs (5, "monitor_send_packet(): Scanning \'%c\'\n", packet
[i
]);
1829 /* legit hex numbers or command */
1830 if ((isxdigit(packet
[i
])) || (isalpha(packet
[i
])))
1832 switch (packet
[i
]) {
1835 case '#': /* end of packet */
1836 case '$': /* start of packet */
1838 default: /* bogus character */
1840 debuglogs (4, "monitor_send_packet(): Found a non-ascii digit \'%c\' in the packet.\n", packet
[i
]);
1846 error ("Can't send packet, found %d non-ascii characters", retries
);
1848 /* ok, try to send the packet */
1850 while (retries
<= 10) {
1851 printf_monitor ("%s", packet
);
1853 /* read until either a timeout occurs (-2) or '+' is read */
1854 while (retries
<= 10) {
1855 c
= readchar (timeout
);
1856 debuglogs (3, "Reading a GDB protocol packet... Got a '%c'\n", c
);
1859 debuglogs (3, "Got Ack\n");
1861 case SERIAL_TIMEOUT
:
1862 debuglogs (3, "Timed out reading serial port\n");
1863 break; /* Retransmit buffer */
1865 debuglogs (3, "Got NAK\n");
1866 break; /* FIXME: (maybe) was a continue */
1868 /* it's probably an old response, or the echo of our command.
1869 * just gobble up the packet and ignore it.
1871 debuglogs (3, "Got a junk packet\n");
1873 c
= readchar (timeout
);
1876 c
= readchar (timeout
);
1878 c
= readchar (timeout
);
1881 debuglogs (3, "Reading a junk packet, got a \"%s\"\n", junk
);
1882 continue; /* Now, go look for next packet */
1887 debuglogs (3, "Retransmitting packet \"%s\"\n", packet
);
1888 break; /* Here to retransmit */
1895 * monitor_get_packet -- get a GDB packet from the target. Basically we read till we
1896 * see a '#', then check the checksum. It returns a 1 if it's gotten a
1897 * packet, or a 0 it the packet wasn't transmitted correctly.
1900 monitor_get_packet (packet
)
1906 unsigned char pktcsum
;
1912 memset (packet
, 1, PBUFSIZ
);
1914 while (retries
<= 10) {
1916 c
= readchar (timeout
);
1917 if (c
== SERIAL_TIMEOUT
) {
1918 debuglogs (3, "monitor_get_packet: got time out from serial port.\n");
1920 debuglogs (3, "Waiting for a '$', got a %c\n", c
);
1924 while (retries
<= 10) {
1925 c
= readchar (timeout
);
1926 debuglogs (3, "monitor_get_packet: got a '%c'\n", c
);
1928 case SERIAL_TIMEOUT
:
1929 debuglogs (3, "Timeout in mid-packet, retrying\n");
1932 debuglogs (3, "Saw new packet start in middle of old one\n");
1933 return 0; /* Start a new packet, count retries */
1936 pktcsum
= from_hex (readchar (timeout
)) << 4;
1937 pktcsum
|= from_hex (readchar (timeout
));
1938 if (csum
== pktcsum
) {
1939 debuglogs (3, "\nGDB packet checksum correct, packet data is \"%s\",\n", packet
);
1940 printf_monitor ("+");
1944 debuglogs (3, "Bad checksum, sentsum=0x%x, csum=0x%x\n", pktcsum
, csum
);
1946 case '*': /* Run length encoding */
1947 debuglogs (5, "Run length encoding in packet\n");
1949 c
= readchar (timeout
);
1951 c
= c
- ' ' + 3; /* Compute repeat count */
1953 if (c
> 0 && c
< 255 && bp
+ c
- 1 < packet
+ PBUFSIZ
- 1) {
1954 memset (bp
, *(bp
- 1), c
);
1959 printf_filtered ("Repeat count %d too large for buffer.\n", c
);
1963 if ((!isxdigit(c
)) && (!ispunct(c
)))
1964 debuglogs (4, "Got a non-ascii digit \'%c\'.\\n", c
);
1965 if (bp
< packet
+ PBUFSIZ
- 1) {
1972 puts_filtered ("Remote packet too long.\n");
1980 * ascii2hexword -- convert an ascii number represented by 8 digits to a hex value.
1982 static unsigned long
1991 for (i
= 0; i
< 8; i
++) {
1993 if (mem
[i
] >= 'A' && mem
[i
] <= 'F')
1994 val
= val
+ mem
[i
] - 'A' + 10;
1995 if (mem
[i
] >= 'a' && mem
[i
] <= 'f')
1996 val
= val
+ mem
[i
] - 'a' + 10;
1997 if (mem
[i
] >= '0' && mem
[i
] <= '9')
1998 val
= val
+ mem
[i
] - '0';
2002 debuglogs (4, "ascii2hexword() got a 0x%x from %s(%x).\n", val
, buf
, mem
);
2007 * ascii2hexword -- convert a hex value to an ascii number represented by 8
2011 hexword2ascii (mem
, num
)
2018 debuglogs (4, "hexword2ascii() converting %x ", num
);
2019 for (i
= 7; i
>= 0; i
--) {
2020 mem
[i
] = tohex ((num
>> 4) & 0xf);
2021 mem
[i
] = tohex (num
& 0xf);
2025 debuglogs (4, "\tto a %s", mem
);
2028 /* Convert hex digit A to a number. */
2036 debuglogs (4, "from_hex got a 0x%x(%c)\n",a
,a
);
2037 if (a
>= '0' && a
<= '9')
2039 if (a
>= 'a' && a
<= 'f')
2040 return a
- 'a' + 10;
2041 if (a
>= 'A' && a
<= 'F')
2042 return a
- 'A' + 10;
2044 error ("Reply contains invalid hex digit 0x%x", a
);
2048 /* Convert number NIB to a hex digit. */
2060 * _initialize_remote_monitors -- setup a few addtitional commands that
2061 * are usually only used by monitors.
2064 _initialize_remote_monitors ()
2066 struct cmd_list_element
*c
;
2068 /* this sets the type of download protocol */
2069 c
= add_set_cmd ("remoteloadprotocol", no_class
, var_string
, (char *)&loadproto_str
,
2070 "Set the type of the remote load protocol.\n", &setlist
);
2071 c
->function
.sfunc
= set_loadproto_command
;
2072 add_show_from_set (c
, &showlist
);
2073 loadproto_str
= savestring ("none", 5);
2075 /* this sets the conversion type when loading */
2076 c
= add_set_cmd ("remoteloadtype", no_class
, var_string
, (char *)&loadtype_str
,
2077 "Set the type of the remote load protocol.\n", &setlist
);
2078 c
->function
.sfunc
= set_loadtype_command
;
2079 add_show_from_set (c
, &showlist
);
2080 loadtype_str
= savestring ("srec", 5);
2082 add_show_from_set (add_set_cmd ("hash", no_class
, var_boolean
,
2084 "Set display of activity while downloading a file.\n\
2085 When enabled, a period \'.\' is displayed.",
2089 /* generic monitor command */
2090 add_com ("monitor", class_obscure
, monitor_command
,
2091 "Send a command to the debug monitor.");
This page took 0.074046 seconds and 4 git commands to generate.