]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/monitor.c
1 /* Remote debugging interface for boot monitors, for GDB.
2 Copyright 1990, 1991, 1992, 1993, 1995 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. */
38 #include <sys/types.h>
42 #include "remote-utils.h"
44 #if !defined (HAVE_TERMIOS) && !defined (HAVE_TERMIO) && !defined (HAVE_SGTTY)
51 # define TERMINAL struct termios
54 # define TERMINAL struct sgttyb
58 #define CSTOPB 0x00000040
61 static const char hexchars
[] = "0123456789abcdef";
62 static char *hex2mem ();
64 static void make_xmodem_packet();
65 static void print_xmodem_packet();
66 static void make_gdb_packet();
67 static unsigned long ascii2hexword();
68 static char *hexword2ascii();
71 static int from_hex();
73 static void monitor_load_ascii_srec
PARAMS ((char *file
, int fromtty
));
75 static int monitor_make_srec
PARAMS ((char *buffer
, int type
,
77 unsigned char *myaddr
, int len
));
79 static unsigned long ascii2hexword ();
80 static char *hexword2ascii ();
83 static int from_hex ();
85 struct monitor_ops
*current_monitor
;
87 extern struct cmd_list_element
*setlist
;
88 extern struct cmd_list_element
*unsetlist
;
90 struct cmd_list_element
*showlist
;
93 extern char *host_name
;
94 extern char *target_name
;
96 static int hashmark
; /* flag set by "set hash" */
98 #define LOG_FILE "monitor.log"
99 #if defined (LOG_FILE)
103 static int timeout
= 30;
105 /* Having this larger than 400 causes us to be incompatible with m68k-stub.c
106 and i386-stub.c. Normally, no one would notice because it only matters
107 for writing large chunks of memory (e.g. in downloads). Also, this needs
108 to be more than 400 if required to hold the registers (see below, where
109 we round it up based on REGISTER_BYTES). */
113 /* Descriptor for I/O to remote machine. Initialize it to NULL so
114 that monitor_open knows that we don't have a file open when the
117 serial_t monitor_desc
= NULL
;
119 /* sets the download protocol, choices are srec, generic, boot */
122 static char *loadtype_str
;
123 static char *loadproto_str
;
124 static void set_loadtype_command();
125 static void set_loadproto_command();
126 static void monitor_load_srec();
128 /* These definitions are for xmodem protocol. */
135 #define GETACK getacknak(ACK)
136 #define GETNAK getacknak(NAK)
137 #define XMODEM_DATASIZE 128 /* the data size is ALWAYS 128 */
138 #define XMODEM_PACKETSIZE 131 /* the packet size is ALWAYS 132 (zero based) */
142 * set_loadtype_command -- set the type for downloading. Check to make
143 * sure you have a support protocol for this target.
146 set_loadtype_command (ignore
, from_tty
, c
)
149 struct cmd_list_element
*c
;
154 if (current_monitor
== 0x0)
157 if (STREQ (LOADTYPES
, "")) {
158 error ("No loadtype set");
162 tmp
= savestring (LOADTYPES
, strlen(LOADTYPES
));
163 type
= strtok(tmp
, ",");
164 if (STREQ (type
, (*(char **) c
->var
))) {
165 loadtype_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
169 while ((type
= strtok (NULL
, ",")) != (char *)NULL
) {
170 if (STREQ (type
, (*(char **) c
->var
)))
171 loadtype_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
175 error ("Loadtype \"%s\" does not exist.", (*(char **) c
->var
));
178 * set_loadproto_command -- set the protocol for downloading. Check to make
179 * sure you have a supported protocol for this target.
182 set_loadproto_command (ignore
, from_tty
, c
)
185 struct cmd_list_element
*c
;
190 if (current_monitor
== 0x0)
193 if (STREQ (LOADPROTOS
, "")) {
194 error ("No load protocols set");
198 tmp
= savestring (LOADPROTOS
, strlen(LOADPROTOS
));
199 type
= strtok(tmp
, ",");
200 if (STREQ (type
, (*(char **) c
->var
))) {
201 loadproto_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
205 while ((type
= strtok (NULL
, ",")) != (char *)NULL
) {
206 if (STREQ (type
, (*(char **) c
->var
)))
207 loadproto_str
= savestring (*(char **) c
->var
, strlen (*(char **) c
->var
));
211 error ("Load protocol \"%s\" does not exist.", (*(char **) c
->var
));
214 /* printf_monitor -- send data to monitor. Works just like printf. */
217 printf_monitor (va_alist
)
226 pattern
= va_arg (args
, char *);
228 vsprintf (buf
, pattern
, args
);
230 debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf
);
232 if (strlen (buf
) > PBUFSIZ
)
233 error ("printf_monitor(): string too long");
234 if (SERIAL_WRITE(monitor_desc
, buf
, strlen (buf
)))
235 fprintf (stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror (errno
));
238 /* Send raw data to monitor. */
241 write_monitor (data
, len
)
245 if (SERIAL_WRITE (monitor_desc
, data
, len
))
246 fprintf (stderr
, "SERIAL_WRITE failed: %s\n", safe_strerror(errno
));
248 *(data
+ len
+ 1) = '\0';
249 debuglogs (1, "write_monitor(), Sending: \"%s\".", data
);
252 /* Deal with debugging info to multiple sources. This takes two real
253 args, the first one is the level to be compared against the
254 sr_get_debug() value, the second arg is a printf buffer and args to
255 be formatted and printed. A CR is added after each string is
264 unsigned char buf
[PBUFSIZ
];
265 char newbuf
[PBUFSIZ
];
270 level
= va_arg(args
, int); /* get the debug level */
271 if ((level
< 0) || (level
> 100))
273 error ("Bad argument passed to debuglogs(), needs debug level");
277 pattern
= va_arg(args
, char *); /* get the printf style pattern */
279 vsprintf(buf
, pattern
, args
); /* format the string */
281 /* convert some characters so it'll look right in the log */
283 for (i
= 0 ; buf
[i
] != '\0'; i
++)
286 error ("Debug message too long");
289 case '\n': /* newlines */
293 case '\r': /* carriage returns */
297 case '\033': /* escape */
305 case '\b': /* backspace */
309 default: /* no change */
313 /* modify control characters */
321 /* modify control characters */
329 *p
= '\0'; /* terminate the string */
331 if (sr_get_debug () > level
)
332 printf_unfiltered ("%s\n", newbuf
);
334 #ifdef LOG_FILE /* write to the monitor log */
337 fputs (newbuf
, log_file
);
338 fputc ('\n', log_file
);
344 /* Read a character from the remote system, doing all the fancy
353 c
= SERIAL_READCHAR (monitor_desc
, timeout
);
355 if (sr_get_debug () > 5)
358 debuglogs (5, "readchar: timeout = %d\n", timeout
);
363 putc(c
& 0x7f, log_file
);
369 if (c
== SERIAL_TIMEOUT
)
372 return c
; /* Polls shouldn't generate timeout errors */
373 error ("Timeout reading from remote system.");
375 fputs ("ERROR: Timeout reading from remote system", log_file
);
378 perror_with_name ("remote-monitor");
381 /* Scan input from the remote system, until STRING is found. If
382 DISCARD is non-zero, then discard non-matching input, else print it
383 out. Let the user break out immediately. */
386 expect (string
, discard
)
393 debuglogs (1, "Expecting \"%s\".", string
);
398 c
= readchar (timeout
);
406 debuglogs (4, "Matched");
416 fwrite(string
, 1, (p
- 1) - string
, stdout
);
426 /* Keep discarding input until we see the MONITOR prompt.
428 The convention for dealing with the prompt is that you
430 o *then* wait for the prompt.
432 Thus the last thing that a procedure does with the serial line
433 will be an expect_prompt(). Exception: monitor_resume does not
434 wait for the prompt, because the terminal is being handed over
435 to the inferior. However, the next thing which happens after that
436 is a monitor_wait which does wait for the prompt.
437 Note that this includes abnormal exit, e.g. error(). This is
438 necessary to prevent getting into states from which we can't
442 expect_prompt (discard
)
445 expect (PROMPT
, discard
);
448 /* Ignore junk characters. Returns a 1 if junk, 0 otherwise. */
462 if (sr_get_debug () > 5)
463 debuglogs (5, "Ignoring \'%c\'.", ch
);
466 if (sr_get_debug () > 5)
467 debuglogs (5, "Accepting \'%c\'.", ch
);
472 /* Get a hex digit from the remote system & return its value. If
473 ignore is nonzero, ignore spaces, newline & tabs. */
476 get_hex_digit (ignore
)
483 ch
= readchar (timeout
);
486 if (sr_get_debug () > 4)
488 debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch
, ch
);
492 #ifdef LOG_FILE /* write to the monitor log */
495 fputs ("get_hex_digit() got a 0x", log_file
);
496 fputc (ch
, log_file
);
497 fputc ('\n', log_file
);
503 if (ch
>= '0' && ch
<= '9')
505 else if (ch
>= 'A' && ch
<= 'F')
506 return ch
- 'A' + 10;
507 else if (ch
>= 'a' && ch
<= 'f')
508 return ch
- 'a' + 10;
509 else if (ch
== ' ' && ignore
)
514 debuglogs (4, "Invalid hex digit from remote system. (0x%x)", ch
);
515 error ("Invalid hex digit from remote system. (0x%x)", ch
);
520 /* Get a byte from monitor and put it in *BYT. Accept any number of
529 val
= get_hex_digit (1) << 4;
530 debuglogs (4, "get_hex_byte() -- Read first nibble 0x%x", val
);
532 val
|= get_hex_digit (0);
533 debuglogs (4, "get_hex_byte() -- Read second nibble 0x%x", val
);
536 debuglogs (4, "get_hex_byte() -- Read a 0x%x", val
);
539 /* Get N 32-bit words from remote, each preceded by a space, and put
540 them in registers starting at REGNO. */
551 if (HOST_BYTE_ORDER
== BIG_ENDIAN
)
554 for (i
= 0; i
< 8; i
++)
555 val
= (val
<< 4) + get_hex_digit (i
== 0);
560 for (i
= 7; i
>= 0; i
--)
561 val
= (val
<< 4) + get_hex_digit (i
== 0);
565 debuglogs (4, "get_hex_word() got a 0x%x for a %s host.",
567 (HOST_BYTE_ORDER
== BIG_ENDIAN
) ? "big endian" : "little endian");
572 /* This is called not only when we first attach, but also when the
573 user types "run" after having attached. */
576 monitor_create_inferior (execfile
, args
, env
)
584 error ("Can't pass arguments to remote MONITOR process");
586 if (execfile
== 0 || exec_bfd
== 0)
587 error ("No exec file specified");
589 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
591 /* The "process" (board) is already stopped awaiting our commands, and
592 the program is already downloaded. We just set its PC and go. */
594 clear_proceed_status ();
596 /* Tell wait_for_inferior that we've started a new process. */
597 init_wait_for_inferior ();
599 /* Set up the "saved terminal modes" of the inferior
600 based on what modes we are starting it with. */
601 target_terminal_init ();
603 /* Install inferior's terminal modes. */
604 target_terminal_inferior ();
606 /* insert_step_breakpoint (); FIXME, do we need this? */
609 proceed ((CORE_ADDR
)entry_pt
, TARGET_SIGNAL_DEFAULT
, 0);
612 /* Open a connection to a remote debugger. NAME is the filename used
613 for communication. */
615 static int baudrate
= 9600;
616 static char dev_name
[100];
619 monitor_open (args
, name
, from_tty
)
624 TERMINAL
*temptempio
;
627 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
628 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name
, name
);
633 strcpy (dev_name
, args
);
634 monitor_desc
= SERIAL_OPEN (dev_name
);
636 if (monitor_desc
== NULL
)
637 perror_with_name (dev_name
);
641 if (SERIAL_SETBAUDRATE (monitor_desc
, baud_rate
))
643 SERIAL_CLOSE (monitor_desc
);
644 perror_with_name (name
);
648 SERIAL_RAW (monitor_desc
);
650 /* some systems only work with 2 stop bits */
651 #if !defined(__GO32__) && !defined(GDB_TARGET_IS_PA_ELF)
653 if (!strchr (dev_name
, ':')) { /* don't set for a tcp connection */
654 temptempio
= (TERMINAL
*) SERIAL_GET_TTY_STATE (monitor_desc
);
656 temptempio
->sg_cflag
|= baud_rate
| CSTOPB
;
658 temptempio
->c_cflag
|= baud_rate
| CSTOPB
;
660 SERIAL_SET_TTY_STATE (monitor_desc
, temptempio
);
661 debuglogs (4, "Set serial port to 2 stop bits");
664 #endif /* __GO32__ */
666 #if defined (LOG_FILE)
667 log_file
= fopen (LOG_FILE
, "w");
668 if (log_file
== NULL
)
669 perror_with_name (LOG_FILE
);
670 fprintf_filtered (log_file
, "GDB %s (%s", version
, host_name
);
671 fprintf_filtered (log_file
, " --target %s)\n", target_name
);
672 fprintf_filtered (log_file
, "Remote target %s connected to %s\n\n",
673 TARGET_NAME
, dev_name
);
676 /* see if the target is alive. For a ROM monitor, we can just try to
677 force the prompt to print a few times. FOr the GDB remote
678 protocol, the application being debugged is sitting at a
679 breakpoint and waiting for GDB to initialize the connection. We
680 force it to give us an empty packet to see if it's alive. */
684 debuglogs (3, "Trying to ACK the target's debug stub");
685 printf_monitor (INIT_CMD
); /* ask for the last signal */
686 expect ("$S05#b8",0); /* look for a response */
687 printf_monitor ("+"); /* ask for the last signal */
688 expect_prompt (1); /* See if we get a prompt */
692 /* wake up the monitor and see if it's alive */
693 printf_monitor (INIT_CMD
);
694 expect_prompt (1); /* See if we get a prompt */
696 /* try again to be sure */
697 printf_monitor (INIT_CMD
);
698 expect_prompt (1); /* See if we get a prompt */
702 printf ("Remote target %s connected to %s\n", TARGET_NAME
, dev_name
);
705 /* Close out all files and local state before this target loses
709 monitor_close (quitting
)
712 SERIAL_CLOSE (monitor_desc
);
715 debuglogs (1, "monitor_close (quitting=%d)", quitting
);
717 #if defined (LOG_FILE)
720 if (ferror (log_file
))
721 printf_filtered ("Error writing log file.\n");
722 if (fclose (log_file
) != 0)
723 printf_filtered ("Error closing log file.\n");
728 /* Terminate the open connection to the remote debugger. Use this
729 when you want to detach and do something else with your gdb. */
732 monitor_detach (from_tty
)
735 debuglogs (1, "monitor_detach ()");
737 pop_target (); /* calls monitor_close to do the real work */
739 printf ("Ending remote %s debugging\n", target_shortname
);
742 /* Attach GDB to the target. */
745 monitor_attach (args
, from_tty
)
750 printf ("Starting remote %s debugging\n", target_shortname
);
752 debuglogs (1, "monitor_attach (args=%s)", args
);
754 printf_monitor (GO_CMD
);
755 /* swallow the echo. */
759 /* Tell the remote machine to resume. */
762 monitor_resume (pid
, step
, sig
)
764 enum target_signal sig
;
766 debuglogs (1, "monitor_resume (step=%d, sig=%d)", step
, sig
);
769 printf_monitor (STEP_CMD
);
771 printf_monitor (CONT_CMD
);
774 /* Wait until the remote machine stops, then return, storing status in
775 status just as `wait' would. */
778 monitor_wait (pid
, status
)
780 struct target_waitstatus
*status
;
782 int old_timeout
= timeout
;
784 debuglogs(1, "monitor_wait (), printing extraneous text.");
786 status
->kind
= TARGET_WAITKIND_EXITED
;
787 status
->value
.integer
= 0;
789 timeout
= 0; /* Don't time out -- user program is running. */
791 expect_prompt (0); /* Wait for prompt, outputting extraneous text */
792 debuglogs (4, "monitor_wait(), got the prompt.");
794 status
->kind
= TARGET_WAITKIND_STOPPED
;
795 status
->value
.sig
= TARGET_SIGNAL_TRAP
;
797 timeout
= old_timeout
;
802 /* Return the name of register number regno in the form input and output by
803 monitor. Currently, register_names just happens to contain exactly what
804 monitor wants. Lets take advantage of that just as long as possible! */
819 for (p
= REGNAMES (regno
); *p
; p
++)
824 debuglogs (5, "Got name \"%s\" from regno #%d.", buf
, regno
);
829 /* Read the remote registers into the block regs. */
832 monitor_fetch_registers (ignored
)
836 unsigned char packet
[PBUFSIZ
];
837 char regs
[REGISTER_BYTES
];
839 debuglogs (1, "monitor_fetch_registers (ignored=%d)\n", ignored
);
841 memset (packet
, 0, PBUFSIZ
);
844 /* Unimplemented registers read as all bits zero. */
845 memset (regs
, 0, REGISTER_BYTES
);
846 make_gdb_packet (packet
, "g");
847 if (monitor_send_packet (packet
) == 0)
848 error ("Couldn't transmit packet\n");
849 if (monitor_get_packet (packet
) == 0)
850 error ("Couldn't receive packet\n");
851 /* FIXME: read bytes from packet */
852 debuglogs (4, "monitor_fetch_registers: Got a \"%s\" back\n", packet
);
853 for (regno
= 0; regno
<= PC_REGNUM
+4; regno
++)
855 /* supply register stores in target byte order, so swap here */
856 /* FIXME: convert from ASCII hex to raw bytes */
857 i
= ascii2hexword (packet
+ (regno
* 8));
858 debuglogs (5, "Adding register %d = %x\n", regno
, i
);
859 SWAP_TARGET_AND_HOST (&i
, 4);
860 supply_register (regno
, (char *)&i
);
865 for (regno
= 0; regno
<= PC_REGNUM
; regno
++)
866 monitor_fetch_register (regno
);
870 /* Fetch register REGNO, or all registers if REGNO is -1. Returns
874 monitor_fetch_register (regno
)
880 debuglogs (1, "monitor_fetch_register (reg=%s)", get_reg_name (regno
));
883 monitor_fetch_registers ();
886 name
= get_reg_name (regno
);
888 if (STREQ (name
, ""))
891 printf_monitor (ROMCMD (GET_REG
), name
); /* send the command */
892 expect (name
, 1); /* then strip the leading garbage */
893 if (*ROMDELIM (GET_REG
) != 0)
894 expect (ROMDELIM (GET_REG
), 1);
896 val
= get_hex_word (); /* get the value, ignore junk */
898 /* supply register stores in target byte order, so swap here */
899 SWAP_TARGET_AND_HOST (&val
, 4);
900 supply_register (regno
, (char *) &val
);
902 if (*ROMDELIM(GET_REG
) != 0)
904 /*** expect (ROMRES(GET_REG)); ***/
905 printf_monitor (CMD_END
);
911 /* Store the remote registers. */
914 monitor_store_registers (ignored
)
919 char packet
[PBUFSIZ
];
923 debuglogs (1, "monitor_store_registers()");
927 memset (packet
, 0, PBUFSIZ
);
928 memset (buf
, 0, PBUFSIZ
);
931 /* Unimplemented registers read as all bits zero. */
932 /* FIXME: read bytes from packet */
933 for (regno
= 0; regno
< 41; regno
++) /* FIXME */
935 /* supply register stores in target byte order, so swap here */
936 /* FIXME: convert from ASCII hex to raw bytes */
937 i
= (unsigned long)read_register (regno
);
939 SWAP_TARGET_AND_HOST (&i
, 4);
941 hexword2ascii (num
, i
);
942 strcpy (buf
+ (regno
* 8) + 1, num
);
945 *(buf
+ (regno
* 8) + 2) = 0;
946 make_gdb_packet (packet
, buf
);
947 if (monitor_send_packet (packet
) == 0)
948 error ("Couldn't transmit packet\n");
949 if (monitor_get_packet (packet
) == 0)
950 error ("Couldn't receive packet\n");
954 for (regno
= 0; regno
<= PC_REGNUM
; regno
++)
955 monitor_store_register(regno
);
958 registers_changed ();
961 /* Store register REGNO, or all if REGNO == 0. Return errno value. */
964 monitor_store_register (regno
)
970 i
= read_register (regno
);
972 debuglogs (1, "monitor_store_register (regno=%d)", regno
);
975 monitor_store_registers ();
978 debuglogs (3, "Setting register %s to 0x%x",
979 get_reg_name (regno
), read_register (regno
));
981 name
= get_reg_name (regno
);
982 if (STREQ (name
, ""))
984 printf_monitor (ROMCMD (SET_REG
), name
, read_register (regno
));
985 expect (name
, 1); /* strip the leading garbage */
986 if (*ROMDELIM (SET_REG
) != 0)
988 expect (ROMDELIM (SET_REG
), 1);
990 printf_monitor ("%d%s\n", i
, CMD_END
);
997 printf_monitor (SET_REG
, get_reg_name (regno
),
998 read_register (regno
));
1003 /* Get ready to modify the registers array. On machines which store
1004 individual registers, this doesn't need to do anything. On machines
1005 which store all the registers in one fell swoop, this makes sure
1006 that registers contains all the registers from the program being
1010 monitor_prepare_to_store ()
1012 /* Do nothing, since we can store individual regs */
1016 monitor_files_info ()
1018 printf ("\tAttached to %s at %d baud.\n", dev_name
, baudrate
);
1021 /* Copy LEN bytes of data from debugger memory at MYADDR to inferior's
1022 memory at MEMADDR. Returns length moved. */
1025 monitor_write_inferior_memory (memaddr
, myaddr
, len
)
1027 unsigned char *myaddr
;
1032 char packet
[PBUFSIZ
];
1037 debuglogs (1, "monitor_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)",
1038 memaddr
, myaddr
, len
);
1039 memset (buf
, '\0', PBUFSIZ
); /* this also sets the string terminator */
1044 *p
++ = 'M'; /* The command to write memory */
1045 hexword2ascii (num
, memaddr
); /* convert the address */
1046 strcpy (p
, num
); /* copy the address */
1048 *p
++ = ','; /* add comma delimeter */
1049 hexword2ascii (num
, len
); /* Get the length as a 4 digit number */
1054 *p
++ = ':'; /* add the colon delimeter */
1055 for (j
= 0; j
< len
; j
++)
1056 { /* copy the data in after converting it */
1057 *p
++ = tohex ((myaddr
[j
] >> 4) & 0xf);
1058 *p
++ = tohex (myaddr
[j
] & 0xf);
1061 make_gdb_packet (packet
, buf
);
1062 if (monitor_send_packet (packet
) == 0)
1063 error ("Couldn't transmit packet\n");
1064 if (monitor_get_packet (packet
) == 0)
1065 error ("Couldn't receive packet\n");
1069 for (i
= 0; i
< len
; i
++)
1071 printf_monitor (ROMCMD (SET_MEM
), memaddr
+ i
, myaddr
[i
]);
1072 if (*ROMDELIM (SET_MEM
) != 0)
1074 expect (ROMDELIM (SET_MEM
), 1);
1076 printf_monitor ("%x", myaddr
[i
]);
1078 /*** printf_monitor ("%x", myaddr[i]); ***/
1079 if (sr_get_debug() > 1)
1080 printf ("\nSet 0x%x to 0x%x\n", memaddr
+ i
, myaddr
[i
]);
1081 if (*ROMDELIM (SET_MEM
) != 0)
1084 printf_monitor (CMD_END
);
1092 /* Read LEN bytes from inferior memory at MEMADDR. Put the result at
1093 debugger address MYADDR. Returns length moved. */
1096 monitor_read_inferior_memory(memaddr
, myaddr
, len
)
1103 char packet
[PBUFSIZ
];
1105 /* Number of bytes read so far. */
1108 /* Starting address of this pass. */
1109 unsigned long startaddr
;
1111 /* Starting address of this pass. */
1112 unsigned long endaddr
;
1114 /* Number of bytes to read in this pass. */
1117 debuglogs (1, "monitor_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr
, myaddr
, len
);
1119 /* Note that this code works correctly if startaddr is just less
1120 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
1121 thing). That is, something like
1122 monitor_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
1123 works--it never adds len To memaddr and gets 0. */
1124 /* However, something like
1125 monitor_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
1126 doesn't need to work. Detect it and give up if there's an attempt
1128 if (((memaddr
- 1) + len
) < memaddr
)
1134 startaddr
= memaddr
;
1139 if ((startaddr
% 16) != 0)
1140 len_this_pass
-= startaddr
% 16;
1141 if (len_this_pass
> (len
- count
))
1142 len_this_pass
= (len
- count
);
1144 debuglogs (3, "Display %d bytes at %x for Big Endian host",
1145 len_this_pass
, startaddr
);
1149 for (i
= 0; i
< len_this_pass
; i
++)
1151 sprintf (buf
, "m%08x,%04x", startaddr
, len_this_pass
);
1152 make_gdb_packet (packet
, buf
);
1153 if (monitor_send_packet (packet
) == 0)
1154 error ("Couldn't transmit packet\n");
1155 if (monitor_get_packet (packet
) == 0)
1156 error ("Couldn't receive packet\n");
1157 debuglogs (4, "monitor_read_inferior: Got a \"%s\" back\n",
1159 for (j
= 0; j
< len_this_pass
; j
++)
1162 from_hex (*(packet
+(j
*2))) * 16
1163 + from_hex (*(packet
+(j
*2)+1));
1164 debuglogs (5, "myaddr set to %x\n", myaddr
[count
-1]);
1171 for (i
= 0; i
< len_this_pass
; i
++)
1173 printf_monitor (ROMCMD (GET_MEM
), startaddr
, startaddr
);
1174 sprintf (buf
, ROMCMD (GET_MEM
), startaddr
, startaddr
);
1175 if (*ROMDELIM(GET_MEM
) != 0)
1177 expect (ROMDELIM(GET_MEM
), 1);
1181 sprintf (buf
, ROMCMD (GET_MEM
), startaddr
, startaddr
);
1182 expect (buf
,1); /* get the command echo */
1183 get_hex_word (1); /* strip away the address */
1185 get_hex_byte (&myaddr
[count
++]); /* get the value at this address */
1187 if (*ROMDELIM(GET_MEM
) != 0)
1188 printf_monitor (CMD_END
);
1197 /* FIXME-someday! merge these two. */
1200 monitor_xfer_inferior_memory (memaddr
, myaddr
, len
, write
, target
)
1205 struct target_ops
*target
; /* ignored */
1208 return monitor_write_inferior_memory (memaddr
, myaddr
, len
);
1210 return monitor_read_inferior_memory (memaddr
, myaddr
, len
);
1214 monitor_kill (args
, from_tty
)
1218 return; /* ignore attempts to kill target system */
1221 /* Clean up when a program exits.
1222 The program actually lives on in the remote processor's RAM, and may be
1223 run again without a download. Don't leave it full of breakpoint
1227 monitor_mourn_inferior ()
1229 remove_breakpoints ();
1230 generic_mourn_inferior (); /* Do all the proper things now */
1233 #define MAX_MONITOR_BREAKPOINTS 16
1235 extern int memory_breakpoint_size
;
1236 static CORE_ADDR breakaddr
[MAX_MONITOR_BREAKPOINTS
] = {0};
1238 /* Tell the monitor to add a breakpoint. */
1241 monitor_insert_breakpoint (addr
, shadow
)
1247 debuglogs (1, "monitor_insert_breakpoint() addr = 0x%x", addr
);
1249 for (i
= 0; i
<= MAX_MONITOR_BREAKPOINTS
; i
++)
1251 if (breakaddr
[i
] == 0)
1253 breakaddr
[i
] = addr
;
1254 if (sr_get_debug () > 4)
1255 printf ("Breakpoint at %x\n", addr
);
1256 monitor_read_inferior_memory (addr
, shadow
, memory_breakpoint_size
);
1257 printf_monitor (SET_BREAK_CMD
, addr
);
1263 fprintf (stderr
, "Too many breakpoints (> 16) for monitor\n");
1267 /* Tell the monitor to remove a breakpoint. */
1270 monitor_remove_breakpoint (addr
, shadow
)
1276 debuglogs (1, "monitor_remove_breakpoint() addr = 0x%x", addr
);
1278 for (i
= 0; i
< MAX_MONITOR_BREAKPOINTS
; i
++)
1280 if (breakaddr
[i
] == addr
)
1283 /* some monitors remove breakpoints based on the address */
1285 printf_monitor(CLR_BREAK_CMD
, addr
);
1287 printf_monitor(CLR_BREAK_CMD
, i
);
1292 fprintf (stderr
, "Can't find breakpoint associated with 0x%x\n", addr
);
1296 /* monitor_load -- load a file. This file determines which of the
1297 * supported formats to use. The current types are:
1298 * FIXME: not all types supported yet.
1299 * default - reads any file using bfd and writes it to memory. This
1301 * srec - reads binary file using bfd and writes it as an
1303 * xmodem-bin - reads a binary file using bfd, and downloads it
1304 * using xmodem protocol.
1305 * xmodem-srec - reads a binary file using bfd, and after converting
1306 * it downloads it as an srecord using xmodem protocol.
1307 * ascii-srec - reads a ascii srecord file and downloads it
1309 * ascii-xmodem - reads a ascii file and downloads using xmodem
1314 monitor_load (file
, fromtty
)
1318 debuglogs (1, "Loading %s to monitor", file
);
1320 /* default, load a binary */
1321 if (STREQ (loadtype_str
, "default"))
1323 gr_load_image (file
, fromtty
); /* by writing it into memory */
1327 /* load an srecord by converting */
1328 if ((STREQ (loadtype_str
, "srec")) && STREQ (loadproto_str
, "xmodem"))
1330 monitor_load_srec (file
, XMODEM
);
1334 /* load an srecord by converting */
1335 if (STREQ (loadtype_str
, "srec"))
1337 monitor_load_srec (file
, 0); /* if from a binary */
1341 /* load an srecord by converting */
1342 if (STREQ (loadtype_str
, "none"))
1344 error ("Unimplemented");
1348 /* load an srecord file */
1349 if (STREQ (loadproto_str
, "none"))
1351 monitor_load_ascii_srec (file
, fromtty
); /* if from a binary */
1355 if (STREQ (loadproto_str
, "xmodem"))
1357 monitor_load_srec (file
, XMODEM
);
1362 /* Download an ASCII srecord file. */
1364 #define DOWNLOAD_LINE_SIZE 100
1367 monitor_load_ascii_srec (file
, fromtty
)
1372 char buf
[DOWNLOAD_LINE_SIZE
];
1375 debuglogs (1, "Loading an ASCII srecord file, %s.", file
);
1377 download
= fopen (file
, "r");
1378 if (download
== NULL
)
1380 error ("%s does not exist", file
);
1384 printf_monitor (LOAD_CMD
);
1386 while (!feof (download
))
1388 bytes_read
= fread (buf
, sizeof (char), DOWNLOAD_LINE_SIZE
, download
);
1394 if (SERIAL_WRITE (monitor_desc
, buf
, bytes_read
))
1396 fprintf (stderr
, "SERIAL_WRITE failed: (while downloading) %s\n",
1397 safe_strerror (errno
));
1401 while (i
++ <=200) {} ; /* Ugly HACK, probably needs flow control */
1402 if (bytes_read
< DOWNLOAD_LINE_SIZE
)
1404 if (!feof (download
))
1405 error ("Only read %d bytes\n", bytes_read
);
1413 if (!feof (download
))
1414 error ("Never got EOF while downloading");
1419 /* Put a command string, in args, out to MONITOR. Output from MONITOR
1420 is placed on the users terminal until the prompt is seen. FIXME: We
1421 read the characters ourseleves here cause of a nasty echo. */
1424 monitor_command (args
, fromtty
)
1432 debuglogs (1, "monitor_command (args=%s)", args
);
1434 if (monitor_desc
== NULL
)
1435 error ("monitor target not open.");
1437 /* Send the command. Note that if no args were supplied, then we're
1438 just sending the monitor a newline, which is sometimes useful. */
1440 printf_monitor ("%s\n", (args
? args
: ""));
1445 /* Download a binary file by converting it to srecords. This
1446 will also use xmodem to download the resulting file.
1448 A download goes like this when using xmodem:
1451 <-------- (packet) [SOH|1|1|data|SUM]
1453 <-------- (packet) [SOH|2|2|data|SUM]
1464 monitor_load_srec (args
, protocol
)
1470 char *buffer
, srec
[1024];
1471 char packet
[XMODEM_PACKETSIZE
];
1474 int type
= 0; /* default to a type 0, header record */
1475 int srec_frame
= 57; /* FIXME: this must be 57 There is 12 bytes
1476 of header, and 2 bytes of checksum at the end.
1477 The problem is an xmodem packet holds exactly
1480 abfd
= bfd_openr (args
, 0);
1483 printf_filtered ("Unable to open file %s\n", args
);
1487 if (bfd_check_format (abfd
, bfd_object
) == 0)
1489 printf_filtered ("File is not an object file\n");
1493 printf_monitor (LOAD_CMD
); /* tell the monitor to load */
1495 /* get the NAK from the target */
1496 if (protocol
== XMODEM
)
1500 debuglogs (3, "Got the NAK to start loading");
1504 printf_monitor ("%c", EOT
);
1505 debuglogs (3, "Never got the NAK to start loading");
1506 error ("Never got the NAK to start loading");
1511 while (s
!= (asection
*) NULL
)
1513 if (s
->flags
& SEC_LOAD
)
1515 buffer
= xmalloc (srec_frame
);
1517 printf_filtered ("%s\t: 0x%4x .. 0x%4x ",
1518 s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
1520 for (i
= 0; i
< s
->_raw_size
; i
+= srec_frame
)
1522 if (srec_frame
> s
->_raw_size
- i
)
1523 srec_frame
= s
->_raw_size
- i
;
1525 bfd_get_section_contents (abfd
, s
, buffer
, i
, srec_frame
);
1526 monitor_make_srec (srec
, type
, s
->vma
+ i
, buffer
, srec_frame
);
1527 /* send a packet using xmodem */
1528 if (protocol
== XMODEM
)
1530 make_xmodem_packet (packet
, srec
, XMODEM_DATASIZE
);
1531 write_monitor (packet
, XMODEM_PACKETSIZE
+1);
1533 while (retries
++ <= 3)
1538 debuglogs (3, "Got a NAK, resending packet");
1541 write_monitor (packet
, XMODEM_PACKETSIZE
+1);
1542 if (GETACK
) /* ACKnowledged, get next data chunk */
1546 { /* assume we got an ACK */
1549 putc_unfiltered ('#');
1550 gdb_flush (gdb_stdout
);
1552 debuglogs (3, "Got an ACK, sending next packet");
1557 { /* too many tries, must be hosed */
1558 printf_monitor ("%c", EOT
);
1559 error ("Never got a ACK after sending an xmodem packet");
1563 { /* no protocols at all */
1564 printf_monitor ("%s\n", srec
);
1568 putc_unfiltered ('#');
1569 gdb_flush (gdb_stdout
);
1571 type
= 3; /* switch to a 4 byte address record */
1572 fflush (gdb_stdout
);
1578 debuglogs (3, "%s doesn't need to be loaded", s
->name
);
1582 putc_unfiltered ('\n');
1584 /* Write a type 7 terminator record. no data for a type 7, and there
1585 is no data, so len is 0. */
1587 if (protocol
== XMODEM
)
1589 /* send a packet using xmodem */
1590 monitor_make_srec (srec
, 7, abfd
->start_address
, "", 0);
1591 make_xmodem_packet (packet
, srec
, XMODEM_DATASIZE
);
1592 write_monitor (packet
, XMODEM_PACKETSIZE
+1);
1596 monitor_make_srec (srec
, 7, abfd
->start_address
, "", 0);
1597 printf_monitor ("%s\n", srec
);
1599 if (protocol
== XMODEM
)
1601 printf_monitor ("%c", EOT
);
1603 error ("Never got ACK after sending EOT");
1607 putc_unfiltered ('\n');
1612 /* Get an ACK or a NAK from the target. returns 1 (true) or 0 (false)
1613 This is for xmodem. ANy string starting with "***" is an error
1614 message from the target. Here's a few from the WinBond w89k
1616 *** Too many errors found.
1618 *** Command syntax error
1631 character
= (char) readchar (0);
1632 if ((character
== 0xfffffffe) || (character
== 0x7f))
1634 if (sr_get_debug () > 3)
1640 if (character
== CANCEL
)
1641 { /* target aborted load */
1643 error ("Got a CANCEL from the target.");
1645 if (character
== '*')
1646 { /* look for missed error message */
1648 error ("Got an error message from the target");
1650 debuglogs (3, "Got a %s (0x%x or \'%c\'), expecting a %s.\n",
1651 (character
== ACK
) ? "ACK"
1652 : (character
== NAK
) ? "NAK"
1654 character
, character
, (byte
== ACK
) ? "ACK" : "NAK");
1655 if (character
== byte
) /* got what we wanted */
1657 if (character
== ((byte
== ACK
) ? NAK
: ACK
))
1658 { /* got the opposite */
1659 debuglogs (3, "Got the opposite, wanted 0x%x, got a 0x%x",
1670 * monitor_make_srec -- make an srecord. This writes each line, one at a
1671 * time, each with it's own header and trailer line.
1672 * An srecord looks like this:
1674 * byte count-+ address
1675 * start ---+ | | data +- checksum
1677 * S01000006F6B692D746573742E73726563E4
1678 * S315000448600000000000000000FC00005900000000E9
1679 * S31A0004000023C1400037DE00F023604000377B009020825000348D
1680 * S30B0004485A0000000000004E
1683 * S<type><length><address><data><checksum>
1687 * is the number of bytes following upto the checksum. Note that
1688 * this is not the number of chars following, since it takes two
1689 * chars to represent a byte.
1693 * 1) two byte address data record
1694 * 2) three byte address data record
1695 * 3) four byte address data record
1696 * 7) four byte address termination record
1697 * 8) three byte address termination record
1698 * 9) two byte address termination record
1701 * is the start address of the data following, or in the case of
1702 * a termination record, the start address of the image
1706 * is the sum of all the raw byte data in the record, from the length
1707 * upwards, modulo 256 and subtracted from 255.
1711 monitor_make_srec (buffer
, type
, memaddr
, myaddr
, len
)
1715 unsigned char *myaddr
;
1723 debuglogs (4, "monitor_make_srec (buffer=0x%x, type=%d, memaddr=0x%x, len=%d",
1724 buffer
, type
, memaddr
, len
);
1727 /* Create the header for the srec. 4 is the number of bytes in the address,
1728 and 1 is the number of bytes in the count. */
1730 if (type
== 0) /* FIXME: type 0 is optional */
1731 type
= 3; /* so use data as it works */
1732 sprintf (buf
, "S%d%02X%08X", type
, len
+ 4 + 1, memaddr
);
1735 checksum
+= (len
+ 4 + 1 /* calculate the checksum */
1737 + ((memaddr
>> 8) & 0xff)
1738 + ((memaddr
>> 16) & 0xff)
1739 + ((memaddr
>> 24) & 0xff));
1741 /* build the srecord */
1742 for (i
= 0; i
< len
; i
++)
1744 sprintf (buf
, "%02X", myaddr
[i
]);
1745 checksum
+= myaddr
[i
];
1749 sprintf(buf
, "%02X", ~checksum
& 0xff); /* add the checksum */
1750 debuglogs (3, "srec is \"%s\"", buffer
);
1755 /* Take 128 bytes of data and make a packet out of it.
1757 * Each packet looks like this:
1758 * +-----+-------+-------+------+-----+
1759 * | SOH | Seq1. | Seq2. | data | SUM |
1760 * +-----+-------+-------+------+-----+
1762 * Seq1 = The sequence number.
1763 * Seq2 = The complement of the sequence number.
1764 * Data = A 128 bytes of data.
1765 * SUM = Add the contents of the 128 bytes and use the low-order
1766 * 8 bits of the result.
1770 make_xmodem_packet (packet
, data
, len
)
1771 unsigned char *packet
;
1772 unsigned char *data
;
1775 static int sequence
= 1;
1780 /* build the packet header */
1782 packet
[1] = sequence
;
1783 packet
[2] = 255 - sequence
;
1786 packet
[2] = ~sequence
++; /* the complement is the sequence checksum */
1789 sum
= 0; /* calculate the data checksum */
1790 for (i
= 3; i
<= len
+ 2; i
++) {
1796 /* add padding for the rest of the packet */
1797 for (i
= len
+1 ; i
<= XMODEM_DATASIZE
; i
++)
1800 packet
[XMODEM_PACKETSIZE
] = sum
& 0xff; /* add the checksum */
1802 if (sr_get_debug () > 4)
1804 debuglogs (4, "The xmodem checksum is %d (0x%x)\n",
1805 sum
& 0xff, sum
& 0xff);
1806 print_xmodem_packet (packet
);
1810 /* Print the packet as a debug check. */
1813 print_xmodem_packet (packet
)
1820 /* take apart the packet header the packet header */
1821 if (packet
[0] == SOH
)
1824 error ("xmodem: SOH is wrong");
1826 /* check the sequence */
1829 lastseq
= packet
[1];
1830 if (packet
[2] != ~lastseq
)
1831 error ("xmodem: Sequence checksum is wrong");
1833 printf_filtered (" %d %d", lastseq
, ~lastseq
);
1836 /* check the data checksum */
1838 for (i
= 3; i
<= XMODEM_DATASIZE
; i
++)
1841 /* ignore the data */
1843 printf (" [128 bytes of data] %d\n", sum
& 0xff);
1845 printf_filtered (" [%s] %d\n", packet
, sum
& 0xff);
1847 if ((packet
[XMODEM_PACKETSIZE
] & 0xff) != (sum
& 0xff))
1848 debuglogs (4, "xmodem: data checksum wrong, got a %d",
1849 packet
[XMODEM_PACKETSIZE
] & 0xff);
1854 /* Make a GDB packet. The data is always ASCII.
1855 * A debug packet whose contents are <data>
1856 * is encapsulated for transmission in the form:
1858 * $ <data> # CSUM1 CSUM2
1860 * <data> must be ASCII alphanumeric and cannot include characters
1861 * '$' or '#'. If <data> starts with two characters followed by
1862 * ':', then the existing stubs interpret this as a sequence number.
1864 * CSUM1 and CSUM2 are ascii hex representation of an 8-bit
1865 * checksum of <data>, the most significant nibble is sent first.
1866 * the hex digits 0-9,a-f are used. */
1869 make_gdb_packet (buf
, data
)
1873 unsigned char csum
= 0;
1877 debuglogs (3, "make_gdb_packet(%s)\n", data
);
1878 cnt
= strlen (data
);
1880 error ("make_gdb_packet(): to much data\n");
1882 /* start with the packet header */
1886 /* calculate the checksum */
1887 for (i
= 0; i
< cnt
; i
++)
1893 /* terminate the data with a '#' */
1896 /* add the checksum as two ascii digits */
1897 *p
++ = tohex ((csum
>> 4) & 0xf);
1898 *p
++ = tohex (csum
& 0xf);
1899 *p
= 0x0; /* Null terminator on string */
1902 /* Send a GDB packet to the target with error handling. We get a '+'
1903 (ACK) back if the packet is received and the checksum
1904 matches. Otherwise a '-' (NAK) is returned. It returns a 1 for a
1905 successful transmition, or a 0 for a failure. */
1908 monitor_send_packet (packet
)
1917 /* scan the packet to make sure it only contains valid characters.
1918 this may sound silly, but sometimes a garbled packet will hang
1919 the target board. We scan the whole thing, then print the error
1922 for (i
= 0; i
< strlen(packet
); i
++) {
1923 debuglogs (5, "monitor_send_packet(): Scanning \'%c\'\n", packet
[i
]);
1924 /* legit hex numbers or command */
1925 if ((isxdigit(packet
[i
])) || (isalpha(packet
[i
])))
1927 switch (packet
[i
]) {
1930 case '#': /* end of packet */
1931 case '$': /* start of packet */
1933 default: /* bogus character */
1935 debuglogs (4, "monitor_send_packet(): Found a non-ascii digit \'%c\' in the packet.\n", packet
[i
]);
1941 error ("Can't send packet, found %d non-ascii characters", retries
);
1943 /* ok, try to send the packet */
1945 while (retries
<= 10)
1947 printf_monitor ("%s", packet
);
1949 /* read until either a timeout occurs (-2) or '+' is read */
1950 while (retries
<= 10)
1952 c
= readchar (timeout
);
1953 debuglogs (3, "Reading a GDB protocol packet... Got a '%c'\n", c
);
1957 debuglogs (3, "Got Ack\n");
1959 case SERIAL_TIMEOUT
:
1960 debuglogs (3, "Timed out reading serial port\n");
1961 break; /* Retransmit buffer */
1963 debuglogs (3, "Got NAK\n");
1964 break; /* FIXME: (maybe) was a continue */
1966 /* It's probably an old response, or the echo of our
1967 command. just gobble up the packet and ignore it. */
1968 debuglogs (3, "Got a junk packet\n");
1971 c
= readchar (timeout
);
1974 c
= readchar (timeout
);
1976 c
= readchar (timeout
);
1979 debuglogs (3, "Reading a junk packet, got a \"%s\"\n", junk
);
1980 continue; /* Now, go look for next packet */
1985 debuglogs (3, "Retransmitting packet \"%s\"\n", packet
);
1986 break; /* Here to retransmit */
1992 /* Get a GDB packet from the target. Basically we read till we see a
1993 '#', then check the checksum. It returns a 1 if it's gotten a
1994 packet, or a 0 it the packet wasn't transmitted correctly. */
1997 monitor_get_packet (packet
)
2003 unsigned char pktcsum
;
2009 memset (packet
, 1, PBUFSIZ
);
2011 while (retries
<= 10)
2015 c
= readchar (timeout
);
2016 if (c
== SERIAL_TIMEOUT
)
2018 debuglogs (3, "monitor_get_packet: got time out from serial port.\n");
2020 debuglogs (3, "Waiting for a '$', got a %c\n", c
);
2024 while (retries
<= 10)
2026 c
= readchar (timeout
);
2027 debuglogs (3, "monitor_get_packet: got a '%c'\n", c
);
2030 case SERIAL_TIMEOUT
:
2031 debuglogs (3, "Timeout in mid-packet, retrying\n");
2034 debuglogs (3, "Saw new packet start in middle of old one\n");
2035 return 0; /* Start a new packet, count retries */
2038 pktcsum
= from_hex (readchar (timeout
)) << 4;
2039 pktcsum
|= from_hex (readchar (timeout
));
2040 if (csum
== pktcsum
)
2042 debuglogs (3, "\nGDB packet checksum correct, packet data is \"%s\",\n", packet
);
2043 printf_monitor ("+");
2047 debuglogs (3, "Bad checksum, sentsum=0x%x, csum=0x%x\n", pktcsum
, csum
);
2049 case '*': /* Run length encoding */
2050 debuglogs (5, "Run length encoding in packet\n");
2052 c
= readchar (timeout
);
2054 c
= c
- ' ' + 3; /* Compute repeat count */
2056 if (c
> 0 && c
< 255 && bp
+ c
- 1 < packet
+ PBUFSIZ
- 1)
2058 memset (bp
, *(bp
- 1), c
);
2063 printf_filtered ("Repeat count %d too large for buffer.\n", c
);
2067 if ((!isxdigit (c
)) && (!ispunct (c
)))
2068 debuglogs (4, "Got a non-ascii digit \'%c\'.\\n", c
);
2069 if (bp
< packet
+ PBUFSIZ
- 1)
2077 puts_filtered ("Remote packet too long.\n");
2084 /* Convert an ascii number represented by 8 digits to a hex value. */
2086 static unsigned long
2095 for (i
= 0; i
< 8; i
++)
2098 if (mem
[i
] >= 'A' && mem
[i
] <= 'F')
2099 val
= val
+ mem
[i
] - 'A' + 10;
2100 if (mem
[i
] >= 'a' && mem
[i
] <= 'f')
2101 val
= val
+ mem
[i
] - 'a' + 10;
2102 if (mem
[i
] >= '0' && mem
[i
] <= '9')
2103 val
= val
+ mem
[i
] - '0';
2107 debuglogs (4, "ascii2hexword() got a 0x%x from %s(%x).\n", val
, buf
, mem
);
2111 /* Convert a hex value to an ascii number represented by 8 digits. */
2114 hexword2ascii (mem
, num
)
2120 debuglogs (4, "hexword2ascii() converting %x ", num
);
2121 for (i
= 7; i
>= 0; i
--)
2123 mem
[i
] = tohex ((num
>> 4) & 0xf);
2124 mem
[i
] = tohex (num
& 0xf);
2128 debuglogs (4, "\tto a %s", mem
);
2131 /* Convert hex digit A to a number. */
2140 debuglogs (4, "from_hex got a 0x%x(%c)\n",a
,a
);
2141 if (a
>= '0' && a
<= '9')
2143 if (a
>= 'a' && a
<= 'f')
2144 return a
- 'a' + 10;
2145 if (a
>= 'A' && a
<= 'F')
2146 return a
- 'A' + 10;
2147 error ("Reply contains invalid hex digit 0x%x", a
);
2150 /* Convert number NIB to a hex digit. */
2159 return 'a' + nib
- 10;
2162 /* Define additional commands that are usually only used by monitors. */
2165 _initialize_remote_monitors ()
2167 struct cmd_list_element
*c
;
2169 /* this sets the type of download protocol */
2170 c
= add_set_cmd ("remoteloadprotocol", no_class
, var_string
, (char *)&loadproto_str
,
2171 "Set the type of the remote load protocol.\n", &setlist
);
2172 c
->function
.sfunc
= set_loadproto_command
;
2173 add_show_from_set (c
, &showlist
);
2174 loadproto_str
= savestring ("none", 5);
2176 /* this sets the conversion type when loading */
2177 c
= add_set_cmd ("remoteloadtype", no_class
, var_string
, (char *)&loadtype_str
,
2178 "Set the type of the remote load protocol.\n", &setlist
);
2179 c
->function
.sfunc
= set_loadtype_command
;
2180 add_show_from_set (c
, &showlist
);
2181 loadtype_str
= savestring ("srec", 5);
2183 add_show_from_set (add_set_cmd ("hash", no_class
, var_boolean
,
2185 "Set display of activity while downloading a file.\n\
2186 When enabled, a period \'.\' is displayed.",
2190 add_com ("monitor", class_obscure
, monitor_command
,
2191 "Send a command to the debug monitor.");