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)
330 printf_unfiltered ("%s\n", newbuf);
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");
407 fwrite(string, 1, (p - 1) - string, stdout);
417 /* Keep discarding input until we see the MONITOR prompt.
419 The convention for dealing with the prompt is that you
421 o *then* wait for the prompt.
423 Thus the last thing that a procedure does with the serial line
424 will be an expect_prompt(). Exception: monitor_resume does not
425 wait for the prompt, because the terminal is being handed over
426 to the inferior. However, the next thing which happens after that
427 is a monitor_wait which does wait for the prompt.
428 Note that this includes abnormal exit, e.g. error(). This is
429 necessary to prevent getting into states from which we can't
432 expect_prompt(discard)
435 expect (PROMPT, discard);
439 * junk -- ignore junk characters. Returns a 1 if junk, 0 otherwise
452 if (sr_get_debug() > 5)
453 debuglogs (5, "Ignoring \'%c\'.", ch);
456 if (sr_get_debug() > 5)
457 debuglogs (5, "Accepting \'%c\'.", ch);
463 * get_hex_digit -- Get a hex digit from the remote system & return its value.
464 * If ignore is nonzero, ignore spaces, newline & tabs.
467 get_hex_digit(ignore)
472 ch = readchar(timeout);
475 if (sr_get_debug() > 4) {
476 debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch, ch);
478 #ifdef LOG_FILE /* write to the monitor log */
479 if (log_file != 0x0) {
480 fputs ("get_hex_digit() got a 0x", log_file);
481 fputc (ch, log_file);
482 fputc ('\n', log_file);
488 if (ch >= '0' && ch <= '9')
490 else if (ch >= 'A' && ch <= 'F')
491 return ch - 'A' + 10;
492 else if (ch >= 'a' && ch <= 'f')
493 return ch - 'a' + 10;
494 else if (ch == ' ' && ignore)
498 debuglogs (4, "Invalid hex digit from remote system. (0x%x)", ch);
499 error("Invalid hex digit from remote system. (0x%x)", ch);
504 /* get_hex_byte -- Get a byte from monitor and put it in *BYT.
505 * Accept any number leading spaces.
513 val = get_hex_digit (1) << 4;
514 debuglogs (4, "get_hex_byte() -- Read first nibble 0x%x", val);
516 val |= get_hex_digit (0);
517 debuglogs (4, "get_hex_byte() -- Read second nibble 0x%x", val);
520 debuglogs (4, "get_hex_byte() -- Read a 0x%x", val);
524 * get_hex_word -- Get N 32-bit words from remote, each preceded by a space,
525 * and put them in registers starting at REGNO.
536 if (HOST_BYTE_ORDER == BIG_ENDIAN) {
538 for (i = 0; i < 8; i++)
539 val = (val << 4) + get_hex_digit (i == 0);
542 for (i = 7; i >= 0; i--)
543 val = (val << 4) + get_hex_digit (i == 0);
547 debuglogs (4, "get_hex_word() got a 0x%x for a %s host.", val, (HOST_BYTE_ORDER == BIG_ENDIAN) ? "big endian" : "little endian");
552 /* This is called not only when we first attach, but also when the
553 user types "run" after having attached. */
555 monitor_create_inferior (execfile, args, env)
563 error("Can't pass arguments to remote MONITOR process");
565 if (execfile == 0 || exec_bfd == 0)
566 error("No exec file specified");
568 entry_pt = (int) bfd_get_start_address (exec_bfd);
570 /* The "process" (board) is already stopped awaiting our commands, and
571 the program is already downloaded. We just set its PC and go. */
573 clear_proceed_status ();
575 /* Tell wait_for_inferior that we've started a new process. */
576 init_wait_for_inferior ();
578 /* Set up the "saved terminal modes" of the inferior
579 based on what modes we are starting it with. */
580 target_terminal_init ();
582 /* Install inferior's terminal modes. */
583 target_terminal_inferior ();
585 /* insert_step_breakpoint (); FIXME, do we need this? */
588 proceed ((CORE_ADDR)entry_pt, TARGET_SIGNAL_DEFAULT, 0);
592 * monitor_open -- open a connection to a remote debugger.
593 * NAME is the filename used for communication.
595 static int baudrate = 9600;
596 static char dev_name[100];
599 monitor_open(args, name, from_tty)
604 TERMINAL *temptempio;
607 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
608 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name, name);
613 strcpy(dev_name, args);
614 monitor_desc = SERIAL_OPEN(dev_name);
616 if (monitor_desc == NULL)
617 perror_with_name(dev_name);
619 if (baud_rate != -1) {
620 if (SERIAL_SETBAUDRATE (monitor_desc, baud_rate)) {
621 SERIAL_CLOSE (monitor_desc);
622 perror_with_name (name);
626 SERIAL_RAW(monitor_desc);
628 /* some systems only work with 2 stop bits */
629 #if !defined(__GO32__) && !defined(GDB_TARGET_IS_PA_ELF)
631 if (!strchr (dev_name, ':')) { /* don't set for a tcp connection */
632 temptempio = (TERMINAL *)SERIAL_GET_TTY_STATE(monitor_desc);
634 temptempio->sg_cflag |= baud_rate | CSTOPB;
636 temptempio->c_cflag |= baud_rate | CSTOPB;
638 SERIAL_SET_TTY_STATE(monitor_desc, temptempio);
639 debuglogs (4, "Set serial port to 2 stop bits");
642 #endif /* __GO32__ */
644 #if defined (LOG_FILE)
645 log_file = fopen (LOG_FILE, "w");
646 if (log_file == NULL)
647 perror_with_name (LOG_FILE);
648 fprintf_filtered (log_file, "GDB %s (%s", version, host_name);
649 fprintf_filtered (log_file, " --target %s)\n", target_name);
650 fprintf_filtered (log_file, "Remote target %s connected to %s\n\n", TARGET_NAME, dev_name);
653 /* see if the target is alive. For a ROM monitor, we can just try to force the
654 prompt to print a few times. FOr the GDB remote protocol, the application
655 being debugged is sitting at a breakpoint and waiting for GDB to initialize
656 the connection. We force it to give us an empty packet to see if it's alive.
659 debuglogs (3, "Trying to ACK the target's debug stub");
660 printf_monitor (INIT_CMD); /* ask for the last signal */
661 expect ("$S05#b8",0); /* look for a response */
662 printf_monitor ("+"); /* ask for the last signal */
663 expect_prompt(1); /* See if we get a prompt */
665 /* wake up the monitor and see if it's alive */
666 printf_monitor(INIT_CMD);
667 expect_prompt(1); /* See if we get a prompt */
669 /* try again to be sure */
670 printf_monitor(INIT_CMD);
671 expect_prompt(1); /* See if we get a prompt */
675 printf("Remote target %s connected to %s\n", TARGET_NAME, dev_name);
679 * monitor_close -- Close out all files and local state before this
680 * target loses control.
684 monitor_close (quitting)
687 SERIAL_CLOSE(monitor_desc);
690 debuglogs (1, "monitor_close (quitting=%d)", quitting);
692 #if defined (LOG_FILE)
694 if (ferror(log_file))
695 fprintf(stderr, "Error writing log file.\n");
696 if (fclose(log_file) != 0)
697 fprintf(stderr, "Error closing log file.\n");
703 * monitor_detach -- terminate the open connection to the remote
704 * debugger. Use this when you want to detach and do something
705 * else with your gdb.
708 monitor_detach (from_tty)
712 debuglogs (1, "monitor_detach ()");
714 pop_target(); /* calls monitor_close to do the real work */
716 printf ("Ending remote %s debugging\n", target_shortname);
720 * monitor_attach -- attach GDB to the target.
723 monitor_attach (args, from_tty)
728 printf ("Starting remote %s debugging\n", target_shortname);
730 debuglogs (1, "monitor_attach (args=%s)", args);
732 printf_monitor (GO_CMD);
733 /* swallow the echo. */
738 * monitor_resume -- Tell the remote machine to resume.
741 monitor_resume (pid, step, sig)
743 enum target_signal sig;
745 debuglogs (1, "monitor_resume (step=%d, sig=%d)", step, sig);
748 printf_monitor (STEP_CMD);
750 printf_monitor (CONT_CMD);
755 * monitor_wait -- Wait until the remote machine stops, then return,
756 * storing status in status just as `wait' would.
759 monitor_wait (pid, status)
761 struct target_waitstatus *status;
763 int old_timeout = timeout;
765 debuglogs(1, "monitor_wait (), printing extraneous text.");
767 status->kind = TARGET_WAITKIND_EXITED;
768 status->value.integer = 0;
770 timeout = 0; /* Don't time out -- user program is running. */
772 expect_prompt(0); /* Wait for prompt, outputting extraneous text */
773 debuglogs (4, "monitor_wait(), got the prompt.");
775 status->kind = TARGET_WAITKIND_STOPPED;
776 status->value.sig = TARGET_SIGNAL_TRAP;
780 timeout = old_timeout;
785 /* Return the name of register number regno in the form input and output by
786 monitor. Currently, register_names just happens to contain exactly what
787 monitor wants. Lets take advantage of that just as long as possible! */
802 for (p = REGNAMES(regno); *p; p++)
807 debuglogs (5, "Got name \"%s\" from regno #%d.", buf, regno);
813 * monitor_fetch_registers -- read the remote registers into the
817 monitor_fetch_registers (ignored)
822 unsigned char packet[PBUFSIZ];
823 char regs[REGISTER_BYTES];
825 debuglogs (1, "monitor_fetch_registers (ignored=%d)\n", ignored);
827 memset (packet, 0, PBUFSIZ);
829 /* Unimplemented registers read as all bits zero. */
830 memset (regs, 0, REGISTER_BYTES);
831 make_gdb_packet (packet, "g");
832 if (monitor_send_packet (packet) == 0)
833 error ("Couldn't transmit packet\n");
834 if (monitor_get_packet (packet) == 0)
835 error ("Couldn't receive packet\n");
836 /* FIXME: read bytes from packet */
837 debuglogs (4, "monitor_fetch_registers: Got a \"%s\" back\n", packet);
838 for (regno = 0; regno <= PC_REGNUM+4; regno++) {
839 /* supply register stores in target byte order, so swap here */
840 /* FIXME: convert from ASCII hex to raw bytes */
841 i = ascii2hexword (packet + (regno * 8));
842 debuglogs (5, "Adding register %d = %x\n", regno, i);
843 SWAP_TARGET_AND_HOST (&i, 4);
844 supply_register (regno, (char *)&i);
847 for (regno = 0; regno <= PC_REGNUM; regno++)
848 monitor_fetch_register(regno);
853 * monitor_fetch_register -- fetch register REGNO, or all registers if REGNO
854 * is -1. Returns errno value.
857 monitor_fetch_register (regno)
862 debuglogs (1, "monitor_fetch_register (reg=%s)", get_reg_name (regno));
865 monitor_fetch_registers ();
867 char *name = get_reg_name (regno);
870 printf_monitor (ROMCMD(GET_REG), name); /* send the command */
871 expect (name, 1); /* then strip the leading garbage */
872 if (*ROMDELIM(GET_REG) != 0) { /* if there's a delimiter */
873 expect (ROMDELIM(GET_REG), 1);
876 val = get_hex_word(); /* get the value, ignore junk */
879 /* supply register stores in target byte order, so swap here */
880 SWAP_TARGET_AND_HOST (&val, 4);
881 supply_register (regno, (char *) &val);
883 if (*ROMDELIM(GET_REG) != 0) {
884 /*** expect (ROMRES(GET_REG)); ***/
885 printf_monitor (CMD_END);
893 * monitor_store_registers - store the remote registers.
896 monitor_store_registers (ignored)
901 char packet[PBUFSIZ];
905 debuglogs (1, "monitor_store_registers()");
908 memset (packet, 0, PBUFSIZ);
909 memset (buf, 0, PBUFSIZ);
912 /* Unimplemented registers read as all bits zero. */
913 /* FIXME: read bytes from packet */
914 for (regno = 0; regno < 41; regno++) { /* FIXME */
915 /* supply register stores in target byte order, so swap here */
916 /* FIXME: convert from ASCII hex to raw bytes */
917 i = (unsigned long)read_register (regno);
919 SWAP_TARGET_AND_HOST (&i, 4);
921 hexword2ascii (num, i);
922 strcpy (buf+(regno * 8)+1, num);
924 *(buf + (regno * 8) + 2) = 0;
925 make_gdb_packet (packet, buf);
926 if (monitor_send_packet (packet) == 0)
927 error ("Couldn't transmit packet\n");
928 if (monitor_get_packet (packet) == 0)
929 error ("Couldn't receive packet\n");
931 for (regno = 0; regno <= PC_REGNUM; regno++)
932 monitor_store_register(regno);
935 registers_changed ();
939 * monitor_store_register -- store register REGNO, or all if REGNO == 0.
940 * return errno value.
943 monitor_store_register (regno)
949 i = read_register(regno);
951 debuglogs (1, "monitor_store_register (regno=%d)", regno);
954 monitor_store_registers ();
956 debuglogs (3, "Setting register %s to 0x%x", get_reg_name (regno), read_register (regno));
958 name = get_reg_name (regno);
961 printf_monitor (ROMCMD(SET_REG), name, read_register(regno));
962 expect (name, 1); /* strip the leading garbage */
963 if (*ROMDELIM(SET_REG) != 0) { /* if there's a delimiter */
964 expect (ROMDELIM(SET_REG), 1);
966 printf_monitor ("%d%s\n", i, CMD_END);
973 printf_monitor (SET_REG, get_reg_name (regno),
974 read_register (regno));
980 /* Get ready to modify the registers array. On machines which store
981 individual registers, this doesn't need to do anything. On machines
982 which store all the registers in one fell swoop, this makes sure
983 that registers contains all the registers from the program being
987 monitor_prepare_to_store ()
989 /* Do nothing, since we can store individual regs */
993 monitor_files_info ()
995 printf ("\tAttached to %s at %d baud.\n",
1000 * monitor_write_inferior_memory -- Copy LEN bytes of data from debugger
1001 * memory at MYADDR to inferior's memory at MEMADDR. Returns length moved.
1004 monitor_write_inferior_memory (memaddr, myaddr, len)
1006 unsigned char *myaddr;
1011 char packet[PBUFSIZ];
1016 debuglogs (1, "monitor_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
1017 memset (buf, '\0', PBUFSIZ); /* this also sets the string terminator */
1021 *p++ = 'M'; /* The command to write memory */
1022 hexword2ascii (num, memaddr); /* convert the address */
1023 strcpy (p, num); /* copy the address */
1025 *p++ = ','; /* add comma delimeter */
1026 hexword2ascii (num, len); /* Get the length as a 4 digit number */
1031 *p++ = ':'; /* add the colon delimeter */
1032 for (j = 0; j < len; j++) { /* copy the data in after converting it */
1033 *p++ = tohex ((myaddr[j] >> 4) & 0xf);
1034 *p++ = tohex (myaddr[j] & 0xf);
1037 make_gdb_packet (packet, buf);
1038 if (monitor_send_packet (packet) == 0)
1039 error ("Couldn't transmit packet\n");
1040 if (monitor_get_packet (packet) == 0)
1041 error ("Couldn't receive packet\n");
1043 for (i = 0; i < len; i++) {
1044 printf_monitor (ROMCMD(SET_MEM), memaddr + i, myaddr[i] );
1045 if (*ROMDELIM(SET_MEM) != 0) { /* if there's a delimiter */
1046 expect (ROMDELIM(SET_MEM), 1);
1048 printf_monitor ("%x", myaddr[i]);
1050 /*** printf_monitor ("%x", myaddr[i]); ***/
1051 if (sr_get_debug() > 1)
1052 printf ("\nSet 0x%x to 0x%x\n", memaddr + i, myaddr[i]);
1053 if (*ROMDELIM(SET_MEM) != 0) {
1055 printf_monitor (CMD_END);
1064 * monitor_read_inferior_memory -- read LEN bytes from inferior memory
1065 * at MEMADDR. Put the result at debugger address MYADDR. Returns
1069 monitor_read_inferior_memory(memaddr, myaddr, len)
1076 char packet[PBUFSIZ];
1078 /* Number of bytes read so far. */
1081 /* Starting address of this pass. */
1082 unsigned long startaddr;
1084 /* Starting address of this pass. */
1085 unsigned long endaddr;
1087 /* Number of bytes to read in this pass. */
1090 debuglogs (1, "monitor_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
1092 /* Note that this code works correctly if startaddr is just less
1093 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
1094 thing). That is, something like
1095 monitor_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
1096 works--it never adds len To memaddr and gets 0. */
1097 /* However, something like
1098 monitor_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
1099 doesn't need to work. Detect it and give up if there's an attempt
1101 if (((memaddr - 1) + len) < memaddr) {
1106 startaddr = memaddr;
1108 while (count < len) {
1110 if ((startaddr % 16) != 0)
1111 len_this_pass -= startaddr % 16;
1112 if (len_this_pass > (len - count))
1113 len_this_pass = (len - count);
1115 debuglogs (3, "Display %d bytes at %x for Big Endian host", len_this_pass, startaddr);
1118 for (i = 0; i < len_this_pass; i++) {
1119 sprintf (buf, "m%08x,%04x", startaddr, len_this_pass);
1120 make_gdb_packet (packet, buf);
1121 if (monitor_send_packet (packet) == 0)
1122 error ("Couldn't transmit packet\n");
1123 if (monitor_get_packet (packet) == 0)
1124 error ("Couldn't receive packet\n");
1125 debuglogs (4, "monitor_read_inferior: Got a \"%s\" back\n", packet);
1126 for (j = 0; j < len_this_pass ; j++) { /* extract the byte values */
1127 myaddr[count++] = from_hex (*(packet+(j*2))) * 16 + from_hex (*(packet+(j*2)+1));
1128 debuglogs (5, "myaddr set to %x\n", myaddr[count-1]);
1133 for (i = 0; i < len_this_pass; i++) {
1134 printf_monitor (ROMCMD(GET_MEM), startaddr, startaddr);
1135 sprintf (buf, ROMCMD(GET_MEM), startaddr, startaddr);
1136 if (*ROMDELIM(GET_MEM) != 0) { /* if there's a delimiter */
1137 expect (ROMDELIM(GET_MEM), 1);
1139 sprintf (buf, ROMCMD(GET_MEM), startaddr, startaddr);
1140 expect (buf,1); /* get the command echo */
1141 get_hex_word(1); /* strip away the address */
1143 get_hex_byte (&myaddr[count++]); /* get the value at this address */
1145 if (*ROMDELIM(GET_MEM) != 0) {
1146 printf_monitor (CMD_END);
1156 /* FIXME-someday! merge these two. */
1158 monitor_xfer_inferior_memory (memaddr, myaddr, len, write, target)
1163 struct target_ops *target; /* ignored */
1166 return monitor_write_inferior_memory (memaddr, myaddr, len);
1168 return monitor_read_inferior_memory (memaddr, myaddr, len);
1172 monitor_kill (args, from_tty)
1176 return; /* ignore attempts to kill target system */
1179 /* Clean up when a program exits.
1180 The program actually lives on in the remote processor's RAM, and may be
1181 run again without a download. Don't leave it full of breakpoint
1185 monitor_mourn_inferior ()
1187 remove_breakpoints ();
1188 generic_mourn_inferior (); /* Do all the proper things now */
1191 #define MAX_MONITOR_BREAKPOINTS 16
1193 extern int memory_breakpoint_size;
1194 static CORE_ADDR breakaddr[MAX_MONITOR_BREAKPOINTS] = {0};
1197 * monitor_insert_breakpoint -- add a breakpoint
1200 monitor_insert_breakpoint (addr, shadow)
1206 debuglogs (1, "monitor_insert_breakpoint() addr = 0x%x", addr);
1208 for (i = 0; i <= MAX_MONITOR_BREAKPOINTS; i++) {
1209 if (breakaddr[i] == 0) {
1210 breakaddr[i] = addr;
1211 if (sr_get_debug() > 4)
1212 printf ("Breakpoint at %x\n", addr);
1213 monitor_read_inferior_memory(addr, shadow, memory_breakpoint_size);
1214 printf_monitor(SET_BREAK_CMD, addr);
1220 fprintf(stderr, "Too many breakpoints (> 16) for monitor\n");
1225 * _remove_breakpoint -- Tell the monitor to remove a breakpoint
1228 monitor_remove_breakpoint (addr, shadow)
1234 debuglogs (1, "monitor_remove_breakpoint() addr = 0x%x", addr);
1236 for (i = 0; i < MAX_MONITOR_BREAKPOINTS; i++) {
1237 if (breakaddr[i] == addr) {
1239 /* some monitors remove breakpoints based on the address */
1241 printf_monitor(CLR_BREAK_CMD, addr);
1243 printf_monitor(CLR_BREAK_CMD, i);
1248 fprintf(stderr, "Can't find breakpoint associated with 0x%x\n", addr);
1252 /* monitor_load -- load a file. This file determines which of the
1253 * supported formats to use. The current types are:
1254 * FIXME: not all types supported yet.
1255 * default - reads any file using bfd and writes it to memory. This
1257 * srec - reads binary file using bfd and writes it as an
1259 * xmodem-bin - reads a binary file using bfd, and downloads it
1260 * using xmodem protocol.
1261 * xmodem-srec - reads a binary file using bfd, and after converting
1262 * it downloads it as an srecord using xmodem protocol.
1263 * ascii-srec - reads a ascii srecord file and downloads it
1265 * ascii-xmodem - reads a ascii file and downloads using xmodem
1269 monitor_load (file, fromtty)
1276 debuglogs (1, "Loading %s to monitor", file);
1278 if (STREQ (loadtype_str, "default")) { /* default, load a binary */
1279 gr_load_image (file, fromtty); /* by writing it into memory */
1283 /* load an srecord by converting */
1284 if ((STREQ (loadtype_str, "srec")) && STREQ (loadproto_str, "xmodem")) {
1285 monitor_load_srec(file, XMODEM);
1289 if (STREQ (loadtype_str, "srec")) { /* load an srecord by converting */
1290 monitor_load_srec(file, 0); /* if from a binary */
1294 if (STREQ (loadtype_str, "none")) { /* load an srecord by converting */
1295 error ("Unimplemented");
1299 if (STREQ (loadproto_str, "none")) { /* load an srecord file */
1300 monitor_load_ascii_srec(file, fromtty); /* if from a binary */
1304 if (STREQ (loadproto_str, "xmodem")) { /* load an srecord using the */
1305 monitor_load_srec(file, XMODEM);
1311 * monitor_load_ascii_srec -- download an ASCII srecord file.
1313 #define DOWNLOAD_LINE_SIZE 100
1315 monitor_load_ascii_srec (file, fromtty)
1320 char buf[DOWNLOAD_LINE_SIZE];
1323 debuglogs (1, "Loading an ASCII srecord file, %s.", file);
1325 download = fopen (file, "r");
1326 if (download == NULL) {
1327 error ("%s Does not exist", file);
1331 printf_monitor (LOAD_CMD);
1333 while (!feof (download)) {
1334 bytes_read = fread (buf, sizeof (char), DOWNLOAD_LINE_SIZE, download);
1339 if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
1340 fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
1344 while (i++ <=200) {} ; /* Ugly HACK, probably needs flow control */
1345 if (bytes_read < DOWNLOAD_LINE_SIZE) {
1346 if (!feof (download))
1347 error ("Only read %d bytes\n", bytes_read);
1355 if (!feof (download))
1356 error ("Never got EOF while downloading");
1362 * monitor_command -- put a command string, in args, out to MONITOR.
1363 * Output from MONITOR is placed on the users terminal until the
1364 * prompt is seen. FIXME: We read the charcters ourseleves here
1365 * cause of a nasty echo.
1368 monitor_command (args, fromtty)
1377 debuglogs (1, "monitor_command (args=%s)", args);
1379 if (monitor_desc == NULL)
1380 error("monitor target not open.");
1383 error("Missing command.");
1385 printf_monitor ("%s\n", args);
1391 * monitor_load_srec -- download a binary file by converting it to srecords. This
1392 * will also use xmodem to download the resulting file.
1394 * A download goes like this when using xmodem:
1397 * <-------- (packet) [SOH|1|1|data|SUM]
1399 * <-------- (packet) [SOH|2|2|data|SUM]
1410 monitor_load_srec (args, protocol)
1418 char packet[XMODEM_PACKETSIZE];
1421 int type = 0; /* default to a type 0, header record */
1422 int srec_frame = 57; /* FIXME: this must be 57 There is 12 bytes
1423 of header, and 2 bytes of checksum at the end.
1424 The problem is an xmodem packet holds exactly
1427 abfd = bfd_openr (args, 0);
1429 printf_filtered ("Unable to open file %s\n", args);
1433 if (bfd_check_format (abfd, bfd_object) == 0) {
1434 printf_filtered ("File is not an object file\n");
1438 printf_monitor (LOAD_CMD); /* tell the monitor to load */
1439 if (protocol == XMODEM) { /* get the NAK from the target */
1441 debuglogs (3, "Got the NAK to start loading");
1443 printf_monitor ("%c", EOT);
1444 debuglogs (3, "Never got the NAK to start loading");
1445 error ("Never got the NAK to start loading");
1450 while (s != (asection *) NULL) {
1451 if (s->flags & SEC_LOAD) {
1452 char *buffer = xmalloc (srec_frame);
1453 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, s->vma + s->_raw_size);
1455 for (i = 0; i < s->_raw_size; i += srec_frame) {
1456 if (srec_frame > s->_raw_size - i)
1457 srec_frame = s->_raw_size - i;
1459 bfd_get_section_contents (abfd, s, buffer, i, srec_frame);
1460 monitor_make_srec (srec, type, s->vma + i, buffer, srec_frame);
1461 if (protocol == XMODEM) { /* send a packet using xmodem */
1462 make_xmodem_packet (packet, srec, XMODEM_DATASIZE);
1463 write_monitor (packet, XMODEM_PACKETSIZE+1);
1465 while (retries++ <= 3) {
1466 if (GETNAK) { /* Resend packet */
1467 debuglogs (3, "Got a NAK, resending packet");
1469 write_monitor (packet, XMODEM_PACKETSIZE+1); /* send it again */
1470 if (GETACK) /* ACKnowledged, get next data chunk */
1472 } else { /* assume we got an ACK */
1474 putc_unfiltered ('#');
1475 fflush (gdb_stdout);
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 putc_unfiltered ('#');
1490 fflush (gdb_stdout);
1492 type = 3; /* switch to a 4 byte address record */
1493 fflush (gdb_stdout);
1497 debuglogs (3, "%s doesn't need to be loaded", s->name);
1501 putc_unfiltered ('\n');
1504 write a type 7 terminator record. no data for a type 7,
1505 and there is no data, so len is 0.
1507 if (protocol == XMODEM) { /* send a packet using xmodem */
1508 monitor_make_srec (srec, 7, abfd->start_address, "", 0);
1509 make_xmodem_packet (packet, srec, XMODEM_DATASIZE);
1510 write_monitor (packet, XMODEM_PACKETSIZE+1);
1512 monitor_make_srec (srec, 7, abfd->start_address, "", 0);
1513 printf_monitor ("%s\n", srec);
1515 if (protocol == XMODEM) {
1516 printf_monitor ("%c", EOT);
1518 error ("Never got ACK after sending EOT");
1522 putc_unfiltered ('\n');
1528 * getacknak -- get an ACK or a NAK from the target.
1529 * returns 1 (true) or 0 (false) This is
1530 * for xmodem. ANy string starting with "***"
1531 * is an error message from the target.
1532 * Here's a few from the WinBond w89k "Cougar" PA board.
1533 * *** Too many errors found.
1535 * *** Command syntax error
1546 character = (char)readchar (0);
1547 if ((character == 0xfffffffe) || (character == 0x7f)) { /* empty uart */
1548 if (sr_get_debug() > 3)
1554 if (character == CANCEL) { /* target aborted load */
1556 error ("Got a CANCEL from the target.");
1558 if (character == '*') { /* look for missed error message */
1560 error ("Got an error message from the target");
1562 debuglogs (3, "Got a %s (0x%x or \'%c\'), expecting a %s.\n",
1563 (character == ACK) ? "ACK" : (character == NAK) ? "NAK" : "BOGUS",
1564 character, character, (byte == ACK) ? "ACK" : "NAK");
1565 if (character == byte) /* got what we wanted */
1567 if (character == ((byte == ACK) ? NAK : ACK)) { /* got the opposite */
1568 debuglogs (3, "Got the opposite, wanted 0x%x, got a 0x%x", byte, character);
1577 * monitor_make_srec -- make an srecord. This writes each line, one at a
1578 * time, each with it's own header and trailer line.
1579 * An srecord looks like this:
1581 * byte count-+ address
1582 * start ---+ | | data +- checksum
1584 * S01000006F6B692D746573742E73726563E4
1585 * S315000448600000000000000000FC00005900000000E9
1586 * S31A0004000023C1400037DE00F023604000377B009020825000348D
1587 * S30B0004485A0000000000004E
1590 * S<type><length><address><data><checksum>
1594 * is the number of bytes following upto the checksum. Note that
1595 * this is not the number of chars following, since it takes two
1596 * chars to represent a byte.
1600 * 1) two byte address data record
1601 * 2) three byte address data record
1602 * 3) four byte address data record
1603 * 7) four byte address termination record
1604 * 8) three byte address termination record
1605 * 9) two byte address termination record
1608 * is the start address of the data following, or in the case of
1609 * a termination record, the start address of the image
1613 * is the sum of all the raw byte data in the record, from the length
1614 * upwards, modulo 256 and subtracted from 255.
1617 monitor_make_srec (buffer, type, memaddr, myaddr, len)
1621 unsigned char *myaddr;
1629 debuglogs (4, "monitor_make_srec (buffer=0x%x, type=%d, memaddr=0x%x, len=%d",
1630 buffer, type, memaddr, len);
1634 create the header for the srec. 4 is the number of bytes in the address,
1635 and 1 is the number of bytes in the count.
1637 if (type == 0) /* FIXME: type 0 is optional */
1638 type = 3; /* so use data as it works */
1639 sprintf (buf, "S%d%02X%08X", type, len + 4 + 1, memaddr);
1642 checksum += (len + 4 + 1 /* calculate the checksum */
1644 + ((memaddr >> 8) & 0xff)
1645 + ((memaddr >> 16) & 0xff)
1646 + ((memaddr >> 24) & 0xff));
1648 for (i = 0; i < len; i++) { /* build the srecord */
1649 sprintf (buf, "%02X", myaddr[i]);
1650 checksum += myaddr[i];
1654 sprintf(buf, "%02X", ~checksum & 0xff); /* add the checksum */
1655 debuglogs (3, "srec is \"%s\"", buffer);
1661 * make_xmodem_packet -- this takes a 128 bytes of data and makes a packet
1664 * Each packet looks like this:
1665 * +-----+-------+-------+------+-----+
1666 * | SOH | Seq1. | Seq2. | data | SUM |
1667 * +-----+-------+-------+------+-----+
1669 * Seq1 = The sequence number.
1670 * Seq2 = The complement of the sequence number.
1671 * Data = A 128 bytes of data.
1672 * SUM = Add the contents of the 128 bytes and use the low-order
1673 * 8 bits of the result.
1676 make_xmodem_packet (packet, data, len)
1677 unsigned char packet[];
1678 unsigned char *data;
1681 static int sequence = 1;
1686 /* build the packet header */
1688 packet[1] = sequence;
1689 packet[2] = 255 - sequence;
1692 packet[2] = ~sequence++; /* the complement is the sequence checksum */
1695 sum = 0; /* calculate the data checksum */
1696 for (i = 3; i <= len + 2; i++) {
1702 for (i = len+1 ; i <= XMODEM_DATASIZE ; i++) { /* add padding for the rest of the packet */
1706 packet[XMODEM_PACKETSIZE] = sum & 0xff; /* add the checksum */
1708 if (sr_get_debug() > 4) {
1709 debuglogs (4, "The xmodem checksum is %d (0x%x)\n", sum & 0xff, sum & 0xff);
1710 print_xmodem_packet (packet);
1715 * print_xmodem_packet -- print the packet as a debug check
1718 print_xmodem_packet(packet)
1725 /* take apart the packet header the packet header */
1726 if (packet[0] == SOH) {
1729 error ("xmodem: SOH is wrong");
1732 /* check the sequence */
1733 if (packet[1] != 0) {
1734 lastseq = packet[1];
1735 if (packet[2] != ~lastseq)
1736 error ("xmodem: Sequence checksum is wrong");
1738 printf_filtered (" %d %d", lastseq, ~lastseq);
1741 /* check the data checksum */
1743 for (i = 3; i <= XMODEM_DATASIZE; i++) {
1747 /* ignore the data */
1749 printf (" [128 bytes of data] %d\n", sum & 0xff);
1751 printf_filtered (" [%s] %d\n", packet, sum & 0xff);
1753 if ((packet[XMODEM_PACKETSIZE] & 0xff) != (sum & 0xff)) {
1754 debuglogs (4, "xmodem: data checksum wrong, got a %d", packet[XMODEM_PACKETSIZE] & 0xff);
1760 * make_gdb_packet -- make a GDB packet. The data is always ASCII.
1761 * A debug packet whose contents are <data>
1762 * is encapsulated for transmission in the form:
1764 * $ <data> # CSUM1 CSUM2
1766 * <data> must be ASCII alphanumeric and cannot include characters
1767 * '$' or '#'. If <data> starts with two characters followed by
1768 * ':', then the existing stubs interpret this as a sequence number.
1770 * CSUM1 and CSUM2 are ascii hex representation of an 8-bit
1771 * checksum of <data>, the most significant nibble is sent first.
1772 * the hex digits 0-9,a-f are used.
1776 make_gdb_packet (buf, data)
1780 unsigned char csum = 0;
1784 debuglogs (3, "make_gdb_packet(%s)\n", data);
1785 cnt = strlen (data);
1787 error ("make_gdb_packet(): to much data\n");
1789 /* start with the packet header */
1793 /* calculate the checksum */
1794 for (i = 0; i < cnt; i++) {
1799 /* terminate the data with a '#' */
1802 /* add the checksum as two ascii digits */
1803 *p++ = tohex ((csum >> 4) & 0xf);
1804 *p++ = tohex (csum & 0xf);
1805 *p = 0x0; /* Null terminator on string */
1809 * monitor_send_packet -- send a GDB packet to the target with error handling. We
1810 * get a '+' (ACK) back if the packet is received and the checksum
1811 * matches. Otherwise a '-' (NAK) is returned. It returns a 1 for a
1812 * successful transmition, or a 0 for a failure.
1815 monitor_send_packet (packet)
1824 /* scan the packet to make sure it only contains valid characters.
1825 this may sound silly, but sometimes a garbled packet will hang
1826 the target board. We scan the whole thing, then print the error
1829 for (i = 0; i < strlen(packet); i++) {
1830 debuglogs (5, "monitor_send_packet(): Scanning \'%c\'\n", packet[i]);
1831 /* legit hex numbers or command */
1832 if ((isxdigit(packet[i])) || (isalpha(packet[i])))
1834 switch (packet[i]) {
1837 case '#': /* end of packet */
1838 case '$': /* start of packet */
1840 default: /* bogus character */
1842 debuglogs (4, "monitor_send_packet(): Found a non-ascii digit \'%c\' in the packet.\n", packet[i]);
1848 error ("Can't send packet, found %d non-ascii characters", retries);
1850 /* ok, try to send the packet */
1852 while (retries <= 10) {
1853 printf_monitor ("%s", packet);
1855 /* read until either a timeout occurs (-2) or '+' is read */
1856 while (retries <= 10) {
1857 c = readchar (timeout);
1858 debuglogs (3, "Reading a GDB protocol packet... Got a '%c'\n", c);
1861 debuglogs (3, "Got Ack\n");
1863 case SERIAL_TIMEOUT:
1864 debuglogs (3, "Timed out reading serial port\n");
1865 break; /* Retransmit buffer */
1867 debuglogs (3, "Got NAK\n");
1868 break; /* FIXME: (maybe) was a continue */
1870 /* it's probably an old response, or the echo of our command.
1871 * just gobble up the packet and ignore it.
1873 debuglogs (3, "Got a junk packet\n");
1875 c = readchar (timeout);
1878 c = readchar (timeout);
1880 c = readchar (timeout);
1883 debuglogs (3, "Reading a junk packet, got a \"%s\"\n", junk);
1884 continue; /* Now, go look for next packet */
1889 debuglogs (3, "Retransmitting packet \"%s\"\n", packet);
1890 break; /* Here to retransmit */
1897 * monitor_get_packet -- get a GDB packet from the target. Basically we read till we
1898 * see a '#', then check the checksum. It returns a 1 if it's gotten a
1899 * packet, or a 0 it the packet wasn't transmitted correctly.
1902 monitor_get_packet (packet)
1908 unsigned char pktcsum;
1914 memset (packet, 1, PBUFSIZ);
1916 while (retries <= 10) {
1918 c = readchar (timeout);
1919 if (c == SERIAL_TIMEOUT) {
1920 debuglogs (3, "monitor_get_packet: got time out from serial port.\n");
1922 debuglogs (3, "Waiting for a '$', got a %c\n", c);
1926 while (retries <= 10) {
1927 c = readchar (timeout);
1928 debuglogs (3, "monitor_get_packet: got a '%c'\n", c);
1930 case SERIAL_TIMEOUT:
1931 debuglogs (3, "Timeout in mid-packet, retrying\n");
1934 debuglogs (3, "Saw new packet start in middle of old one\n");
1935 return 0; /* Start a new packet, count retries */
1938 pktcsum = from_hex (readchar (timeout)) << 4;
1939 pktcsum |= from_hex (readchar (timeout));
1940 if (csum == pktcsum) {
1941 debuglogs (3, "\nGDB packet checksum correct, packet data is \"%s\",\n", packet);
1942 printf_monitor ("+");
1946 debuglogs (3, "Bad checksum, sentsum=0x%x, csum=0x%x\n", pktcsum, csum);
1948 case '*': /* Run length encoding */
1949 debuglogs (5, "Run length encoding in packet\n");
1951 c = readchar (timeout);
1953 c = c - ' ' + 3; /* Compute repeat count */
1955 if (c > 0 && c < 255 && bp + c - 1 < packet + PBUFSIZ - 1) {
1956 memset (bp, *(bp - 1), c);
1961 printf_filtered ("Repeat count %d too large for buffer.\n", c);
1965 if ((!isxdigit(c)) && (!ispunct(c)))
1966 debuglogs (4, "Got a non-ascii digit \'%c\'.\\n", c);
1967 if (bp < packet + PBUFSIZ - 1) {
1974 puts_filtered ("Remote packet too long.\n");
1982 * ascii2hexword -- convert an ascii number represented by 8 digits to a hex value.
1984 static unsigned long
1993 for (i = 0; i < 8; i++) {
1995 if (mem[i] >= 'A' && mem[i] <= 'F')
1996 val = val + mem[i] - 'A' + 10;
1997 if (mem[i] >= 'a' && mem[i] <= 'f')
1998 val = val + mem[i] - 'a' + 10;
1999 if (mem[i] >= '0' && mem[i] <= '9')
2000 val = val + mem[i] - '0';
2004 debuglogs (4, "ascii2hexword() got a 0x%x from %s(%x).\n", val, buf, mem);
2009 * ascii2hexword -- convert a hex value to an ascii number represented by 8
2013 hexword2ascii (mem, num)
2020 debuglogs (4, "hexword2ascii() converting %x ", num);
2021 for (i = 7; i >= 0; i--) {
2022 mem[i] = tohex ((num >> 4) & 0xf);
2023 mem[i] = tohex (num & 0xf);
2027 debuglogs (4, "\tto a %s", mem);
2030 /* Convert hex digit A to a number. */
2038 debuglogs (4, "from_hex got a 0x%x(%c)\n",a,a);
2039 if (a >= '0' && a <= '9')
2041 if (a >= 'a' && a <= 'f')
2042 return a - 'a' + 10;
2043 if (a >= 'A' && a <= 'F')
2044 return a - 'A' + 10;
2046 error ("Reply contains invalid hex digit 0x%x", a);
2050 /* Convert number NIB to a hex digit. */
2062 * _initialize_remote_monitors -- setup a few addtitional commands that
2063 * are usually only used by monitors.
2066 _initialize_remote_monitors ()
2068 struct cmd_list_element *c;
2070 /* this sets the type of download protocol */
2071 c = add_set_cmd ("remoteloadprotocol", no_class, var_string, (char *)&loadproto_str,
2072 "Set the type of the remote load protocol.\n", &setlist);
2073 c->function.sfunc = set_loadproto_command;
2074 add_show_from_set (c, &showlist);
2075 loadproto_str = savestring ("none", 5);
2077 /* this sets the conversion type when loading */
2078 c = add_set_cmd ("remoteloadtype", no_class, var_string, (char *)&loadtype_str,
2079 "Set the type of the remote load protocol.\n", &setlist);
2080 c->function.sfunc = set_loadtype_command;
2081 add_show_from_set (c, &showlist);
2082 loadtype_str = savestring ("srec", 5);
2084 add_show_from_set (add_set_cmd ("hash", no_class, var_boolean,
2086 "Set display of activity while downloading a file.\n\
2087 When enabled, a period \'.\' is displayed.",
2091 /* generic monitor command */
2092 add_com ("monitor", class_obscure, monitor_command,
2093 "Send a command to the debug monitor.");