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"
46 # define TERMINAL struct termios
48 # define TERMINAL struct sgttyb
51 struct monitor_ops *current_monitor;
52 extern struct cmd_list_element *setlist;
53 extern struct cmd_list_element *unsetlist;
54 struct cmd_list_element *showlist;
56 extern char *host_name;
57 extern char *target_name;
59 static int hashmark; /* flag set by "set hash" */
61 /* FIXME: Replace with sr_get_debug (). */
62 #define LOG_FILE "monitor.log"
63 #if defined (LOG_FILE)
67 static int timeout = 24;
69 /* Descriptor for I/O to remote machine. Initialize it to NULL so that
70 monitor_open knows that we don't have a file open when the program starts.
72 static serial_t monitor_desc = NULL;
74 /* sets the download protocol, choices are srec, generic, boot */
76 static char *loadtype_str;
77 static void set_loadtype_command();
78 static void monitor_load_srec();
79 static int monitor_write_srec();
82 * set_loadtype_command -- set the type for downloading. Check to make
83 * sure you have a support protocol for this target.
86 set_loadtype_command (ignore, from_tty, c)
89 struct cmd_list_element *c;
93 if (STREQ (LOADTYPES, "")) {
94 error ("No loadtype set");
98 tmp = savestring (LOADTYPES, strlen(LOADTYPES));
99 type = strtok(tmp, ",");
100 if (STREQ (type, (*(char **) c->var))) {
101 loadtype_str = savestring (*(char **) c->var, strlen (*(char **) c->var));
105 while ((type = strtok (NULL, ",")) != (char *)NULL) {
106 if (STREQ (type, (*(char **) c->var)))
107 loadtype_str = savestring (*(char **) c->var, strlen (*(char **) c->var));
111 error ("Loadtype \"%s\" does not exist.", (*(char **) c->var));
115 * printf_monitor -- send data to monitor. Works just like printf.
118 printf_monitor(va_alist)
128 pattern = va_arg(args, char *);
130 vsprintf(buf, pattern, args);
132 debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf);
134 if (SERIAL_WRITE(monitor_desc, buf, strlen(buf)))
135 fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
139 * debuglogs -- deal with debugging info to multiple sources. This takes
140 * two real args, the first one is the level to be compared against
141 * the sr_get_debug() value, the second arg is a printf buffer and args
142 * to be formatted and printed. A CR is added after each string is printed.
156 level = va_arg(args, int); /* get the debug level */
157 if ((level <0) || (level > 100)) {
158 error ("Bad argument passed to debuglogs()");
162 pattern = va_arg(args, char *); /* get the printf style pattern */
164 vsprintf(buf, pattern, args); /* format the string */
166 /* convert some characters so it'll look right in the log */
168 for (i=0 ; buf[i] != '\0'; i++) {
170 case '\n': /* newlines */
174 case '\r': /* carriage returns */
178 case '\033': /* escape */
186 case '\b': /* backspace */
190 default: /* no change */
194 if (buf[i] < 26) { /* modify control characters */
200 *p = '\0'; /* terminate the string */
202 if (sr_get_debug() > level)
205 #ifdef LOG_FILE /* write to the monitor log */
206 if (log_file != 0x0) {
207 fputs (newbuf, log_file);
208 fputc ('\n', log_file);
214 /* readchar -- read a character from the remote system, doing all the fancy
223 c = SERIAL_READCHAR(monitor_desc, timeout);
225 if (sr_get_debug() > 4)
230 putc(c & 0x7f, log_file);
236 if (c == SERIAL_TIMEOUT) {
238 return c; /* Polls shouldn't generate timeout errors */
239 error("Timeout reading from remote system.");
241 fputc ("ERROR: Timeout reading from remote system", log_file);
244 perror_with_name("remote-monitor");
248 * expect -- scan input from the remote system, until STRING is found.
249 * If DISCARD is non-zero, then discard non-matching input, else print
250 * it out. Let the user break out immediately.
253 expect (string, discard)
261 debuglogs (1, "Expecting \"%s\".", string);
265 c = readchar(timeout);
271 debuglogs (4, "Matched");
276 fwrite(string, 1, (p - 1) - string, stdout);
285 /* Keep discarding input until we see the MONITOR prompt.
287 The convention for dealing with the prompt is that you
289 o *then* wait for the prompt.
291 Thus the last thing that a procedure does with the serial line
292 will be an expect_prompt(). Exception: monitor_resume does not
293 wait for the prompt, because the terminal is being handed over
294 to the inferior. However, the next thing which happens after that
295 is a monitor_wait which does wait for the prompt.
296 Note that this includes abnormal exit, e.g. error(). This is
297 necessary to prevent getting into states from which we can't
300 expect_prompt(discard)
303 #if defined (LOG_FILE)
304 /* This is a convenient place to do this. The idea is to do it often
305 enough that we never lose much data if we terminate abnormally. */
308 expect (PROMPT, discard);
312 * junk -- ignore junk characters. Returns a 1 if junk, 0 otherwise
324 if (sr_get_debug() > 5)
325 debuglogs (5, "Ignoring \'%c\'.", ch);
328 if (sr_get_debug() > 5)
329 debuglogs (5, "Accepting \'%c\'.", ch);
335 * get_hex_digit -- Get a hex digit from the remote system & return its value.
336 * If ignore is nonzero, ignore spaces, newline & tabs.
339 get_hex_digit(ignore)
344 ch = readchar(timeout);
347 if (sr_get_debug() > 4)
348 debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch, ch);
350 if (ch >= '0' && ch <= '9')
352 else if (ch >= 'A' && ch <= 'F')
353 return ch - 'A' + 10;
354 else if (ch >= 'a' && ch <= 'f')
355 return ch - 'a' + 10;
356 else if (ch == ' ' && ignore)
360 error("Invalid hex digit from remote system.");
365 /* get_hex_byte -- Get a byte from monitor and put it in *BYT.
366 * Accept any number leading spaces.
374 val = get_hex_digit (1) << 4;
375 debuglogs (4, "get_hex_digit() -- Read first nibble 0x%x", val);
377 val |= get_hex_digit (0);
378 debuglogs (4, "get_hex_digit() -- Read second nibble 0x%x", val);
381 debuglogs (4, "get_hex_digit() -- Read a 0x%x", val);
385 * get_hex_word -- Get N 32-bit words from remote, each preceded by a space,
386 * and put them in registers starting at REGNO.
395 for (i = 0; i < 8; i++)
396 val = (val << 4) + get_hex_digit (i == 0);
398 debuglogs (4, "get_hex_word() got a 0x%x.", val);
403 /* This is called not only when we first attach, but also when the
404 user types "run" after having attached. */
406 monitor_create_inferior (execfile, args, env)
414 error("Can't pass arguments to remote MONITOR process");
416 if (execfile == 0 || exec_bfd == 0)
417 error("No exec file specified");
419 entry_pt = (int) bfd_get_start_address (exec_bfd);
421 debuglogs (1, "create_inferior(exexfile=%s, args=%s, env=%s)", execfile, args, env);
423 /* The "process" (board) is already stopped awaiting our commands, and
424 the program is already downloaded. We just set its PC and go. */
426 clear_proceed_status ();
428 /* Tell wait_for_inferior that we've started a new process. */
429 init_wait_for_inferior ();
431 /* Set up the "saved terminal modes" of the inferior
432 based on what modes we are starting it with. */
433 target_terminal_init ();
435 /* Install inferior's terminal modes. */
436 target_terminal_inferior ();
438 /* insert_step_breakpoint (); FIXME, do we need this? */
441 proceed ((CORE_ADDR)entry_pt, TARGET_SIGNAL_DEFAULT, 0);
445 * monitor_open -- open a connection to a remote debugger.
446 * NAME is the filename used for communication.
448 static int baudrate = 9600;
449 static char dev_name[100];
452 monitor_open(args, name, from_tty)
459 error ("Use `target %s DEVICE-NAME' to use a serial port, or \n\
460 `target %s HOST-NAME:PORT-NUMBER' to use a network connection.", name, name);
465 strcpy(dev_name, args);
466 monitor_desc = SERIAL_OPEN(dev_name);
468 if (monitor_desc == NULL)
469 perror_with_name(dev_name);
471 if (baud_rate != -1) {
472 if (SERIAL_SETBAUDRATE (monitor_desc, baud_rate)) {
473 SERIAL_CLOSE (monitor_desc);
474 perror_with_name (name);
478 SERIAL_RAW(monitor_desc);
480 #if defined (LOG_FILE)
481 log_file = fopen (LOG_FILE, "w");
482 if (log_file == NULL)
483 perror_with_name (LOG_FILE);
484 fprintf_filtered (log_file, "GDB %s (%s", version, host_name);
485 fprintf_filtered (log_file, " --target %s)\n", target_name);
486 fprintf_filtered (log_file, "Remote target %s connected to %s\n\n", TARGET_NAME, dev_name);
489 /* wake up the monitor and see if it's alive */
490 printf_monitor(INIT_CMD);
491 expect_prompt(1); /* See if we get a prompt */
493 /* try again to be sure */
494 printf_monitor(INIT_CMD);
495 expect_prompt(1); /* See if we get a prompt */
498 printf("Remote target %s connected to %s\n", TARGET_NAME, dev_name);
502 * monitor_close -- Close out all files and local state before this
503 * target loses control.
507 monitor_close (quitting)
510 SERIAL_CLOSE(monitor_desc);
513 debuglogs (1, "monitor_close (quitting=%d)", quitting);
515 #if defined (LOG_FILE)
517 if (ferror(log_file))
518 fprintf(stderr, "Error writing log file.\n");
519 if (fclose(log_file) != 0)
520 fprintf(stderr, "Error closing log file.\n");
526 * monitor_detach -- terminate the open connection to the remote
527 * debugger. Use this when you want to detach and do something
528 * else with your gdb.
531 monitor_detach (from_tty)
535 debuglogs (1, "monitor_detach ()");
537 pop_target(); /* calls monitor_close to do the real work */
539 printf ("Ending remote %s debugging\n", target_shortname);
543 * monitor_attach -- attach GDB to the target.
546 monitor_attach (args, from_tty)
551 printf ("Starting remote %s debugging\n", target_shortname);
553 debuglogs (1, "monitor_attach (args=%s)", args);
555 printf_monitor (GO_CMD);
556 /* swallow the echo. */
561 * monitor_resume -- Tell the remote machine to resume.
564 monitor_resume (pid, step, sig)
566 enum target_signal sig;
568 debuglogs (1, "monitor_resume (step=%d, sig=%d)", step, sig);
571 printf_monitor (STEP_CMD);
573 printf_monitor (CONT_CMD);
578 * monitor_wait -- Wait until the remote machine stops, then return,
579 * storing status in status just as `wait' would.
582 monitor_wait (pid, status)
584 struct target_waitstatus *status;
586 int old_timeout = timeout;
588 debuglogs(1, "monitor_wait (), printing extraneous text.");
590 status->kind = TARGET_WAITKIND_EXITED;
591 status->value.integer = 0;
593 timeout = 0; /* Don't time out -- user program is running. */
595 expect_prompt(0); /* Wait for prompt, outputting extraneous text */
596 debuglogs (4, "monitor_wait(), got the prompt.");
598 status->kind = TARGET_WAITKIND_STOPPED;
599 status->value.sig = TARGET_SIGNAL_TRAP;
601 timeout = old_timeout;
606 /* Return the name of register number regno in the form input and output by
607 monitor. Currently, register_names just happens to contain exactly what
608 monitor wants. Lets take advantage of that just as long as possible! */
623 for (p = REGNAMES(regno); *p; p++)
628 debuglogs (5, "Got name \"%s\" from regno #%d.", buf, regno);
634 * monitor_fetch_registers -- read the remote registers into the
638 monitor_fetch_registers ()
642 /* yeah yeah, i know this is horribly inefficient. but it isn't done
643 very often... i'll clean it up later. */
645 for (regno = 0; regno <= PC_REGNUM; regno++)
646 monitor_fetch_register(regno);
650 * monitor_fetch_register -- fetch register REGNO, or all registers if REGNO
651 * is -1. Returns errno value.
654 monitor_fetch_register (regno)
659 debuglogs (1, "monitor_fetch_register (reg=%s)", get_reg_name (regno));
662 monitor_fetch_registers ();
664 char *name = get_reg_name (regno);
667 printf_monitor (ROMCMD(GET_REG), name); /* send the command */
668 expect (name, 1); /* then strip the leading garbage */
669 if (*ROMDELIM(GET_REG) != 0) { /* if there's a delimiter */
670 expect (ROMDELIM(GET_REG), 1);
673 val = get_hex_word(); /* get the value, ignore junk */
674 supply_register (regno, (char *) &val);
676 if (*ROMDELIM(GET_REG) != 0) {
677 /*** expect (ROMRES(GET_REG)); ***/
678 printf_monitor (CMD_END);
685 /* Store the remote registers from the contents of the block REGS. */
688 monitor_store_registers ()
692 debuglogs (1, "monitor_store_registers()");
694 for (regno = 0; regno <= PC_REGNUM; regno++)
695 monitor_store_register(regno);
697 registers_changed ();
701 * monitor_store_register -- store register REGNO, or all if REGNO == 0.
702 * return errno value.
705 monitor_store_register (regno)
711 i = read_register(regno);
713 debuglogs (1, "monitor_store_register (regno=%d)", regno);
716 monitor_store_registers ();
718 debuglogs (3, "Setting register %s to 0x%x", get_reg_name (regno), read_register (regno));
720 name = get_reg_name (regno);
723 printf_monitor (ROMCMD(SET_REG), name, read_register(regno));
724 expect (name, 1); /* strip the leading garbage */
725 if (*ROMDELIM(SET_REG) != 0) { /* if there's a delimiter */
726 expect (ROMDELIM(SET_REG), 1);
728 printf_monitor ("%d%s\n", i, CMD_END);
735 printf_monitor (SET_REG, get_reg_name (regno),
736 read_register (regno));
742 /* Get ready to modify the registers array. On machines which store
743 individual registers, this doesn't need to do anything. On machines
744 which store all the registers in one fell swoop, this makes sure
745 that registers contains all the registers from the program being
749 monitor_prepare_to_store ()
751 /* Do nothing, since we can store individual regs */
755 monitor_files_info ()
757 printf ("\tAttached to %s at %d baud.\n",
762 * monitor_write_inferior_memory -- Copy LEN bytes of data from debugger
763 * memory at MYADDR to inferior's memory at MEMADDR. Returns length moved.
766 monitor_write_inferior_memory (memaddr, myaddr, len)
768 unsigned char *myaddr;
774 debuglogs (1, "monitor_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
776 for (i = 0; i < len; i++) {
777 printf_monitor (ROMCMD(SET_MEM), memaddr + i, myaddr[i] );
778 if (*ROMDELIM(SET_MEM) != 0) { /* if there's a delimiter */
779 expect (ROMDELIM(SET_MEM), 1);
781 printf_monitor ("%x", myaddr[i]);
783 /*** printf_monitor ("%x", myaddr[i]); ***/
784 if (sr_get_debug() > 1)
785 printf ("\nSet 0x%x to 0x%x\n", memaddr + i, myaddr[i]);
786 if (*ROMDELIM(SET_MEM) != 0) {
788 printf_monitor (CMD_END);
796 * monitor_read_inferior_memory -- read LEN bytes from inferior memory
797 * at MEMADDR. Put the result at debugger address MYADDR. Returns
801 monitor_read_inferior_memory(memaddr, myaddr, len)
809 /* Number of bytes read so far. */
812 /* Starting address of this pass. */
813 unsigned long startaddr;
815 /* Number of bytes to read in this pass. */
818 debuglogs (1, "monitor_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
820 /* Note that this code works correctly if startaddr is just less
821 than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
822 thing). That is, something like
823 monitor_read_bytes (CORE_ADDR_MAX - 4, foo, 4)
824 works--it never adds len To memaddr and gets 0. */
825 /* However, something like
826 monitor_read_bytes (CORE_ADDR_MAX - 3, foo, 4)
827 doesn't need to work. Detect it and give up if there's an attempt
829 if (((memaddr - 1) + len) < memaddr) {
836 while (count < len) {
838 if ((startaddr % 16) != 0)
839 len_this_pass -= startaddr % 16;
840 if (len_this_pass > (len - count))
841 len_this_pass = (len - count);
843 debuglogs (3, "Display %d bytes at %x", len_this_pass, startaddr);
845 for (i = 0; i < len_this_pass; i++) {
846 printf_monitor (ROMCMD(GET_MEM), startaddr, startaddr);
847 sprintf (buf, ROMCMD(GET_MEM), startaddr, startaddr);
848 if (*ROMDELIM(GET_MEM) != 0) { /* if there's a delimiter */
849 expect (ROMDELIM(GET_MEM), 1);
851 sprintf (buf, ROMCMD(GET_MEM), startaddr, startaddr);
852 expect (buf,1); /* get the command echo */
853 get_hex_word(1); /* strip away the address */
855 get_hex_byte (&myaddr[count++]); /* get the value at this address */
857 if (*ROMDELIM(GET_MEM) != 0) {
858 printf_monitor (CMD_END);
867 /* FIXME-someday! merge these two. */
869 monitor_xfer_inferior_memory (memaddr, myaddr, len, write, target)
874 struct target_ops *target; /* ignored */
877 return monitor_write_inferior_memory (memaddr, myaddr, len);
879 return monitor_read_inferior_memory (memaddr, myaddr, len);
883 monitor_kill (args, from_tty)
887 return; /* ignore attempts to kill target system */
890 /* Clean up when a program exits.
891 The program actually lives on in the remote processor's RAM, and may be
892 run again without a download. Don't leave it full of breakpoint
896 monitor_mourn_inferior ()
898 remove_breakpoints ();
899 generic_mourn_inferior (); /* Do all the proper things now */
902 #define MAX_MONITOR_BREAKPOINTS 16
904 extern int memory_breakpoint_size;
905 static CORE_ADDR breakaddr[MAX_MONITOR_BREAKPOINTS] = {0};
908 * monitor_insert_breakpoint -- add a breakpoint
911 monitor_insert_breakpoint (addr, shadow)
917 debuglogs (1, "monitor_insert_breakpoint() addr = 0x%x", addr);
919 for (i = 0; i <= MAX_MONITOR_BREAKPOINTS; i++) {
920 if (breakaddr[i] == 0) {
922 if (sr_get_debug() > 4)
923 printf ("Breakpoint at %x\n", addr);
924 monitor_read_inferior_memory(addr, shadow, memory_breakpoint_size);
925 printf_monitor(SET_BREAK_CMD, addr);
931 fprintf(stderr, "Too many breakpoints (> 16) for monitor\n");
936 * _remove_breakpoint -- Tell the monitor to remove a breakpoint
939 monitor_remove_breakpoint (addr, shadow)
945 debuglogs (1, "monitor_remove_breakpoint() addr = 0x%x", addr);
947 for (i = 0; i < MAX_MONITOR_BREAKPOINTS; i++) {
948 if (breakaddr[i] == addr) {
950 /* some monitors remove breakpoints based on the address */
952 printf_monitor(CLR_BREAK_CMD, addr);
954 printf_monitor(CLR_BREAK_CMD, i);
959 fprintf(stderr, "Can't find breakpoint associated with 0x%x\n", addr);
963 /* monitor_load -- load a file. This file determines which of the
964 * supported formats to use. The current types are:
965 * FIXME: not all types supported yet.
966 * default - reads any file using bfd and writes it to memory.
967 * srec - reads binary file using bfd and writes it as an
969 * xmodem-bin - reads a binary file using bfd, and downloads it
970 * using xmodem protocol.
971 * xmodem-srec - reads a binary file using bfd, and after converting
972 * it downloads it as an srecord using xmodem protocol.
973 * ascii-srec - reads a ascii srecord file and downloads it
975 * ascii-xmodem - reads a ascii file and downloads using xmodem
979 monitor_load (file, fromtty)
986 debuglogs (1, "Loading %s to monitor", file);
988 if (STREQ (loadtype_str, "default")) { /* default, load a binary */
989 gr_load_image (file, fromtty); /* by writing it into memory */
992 if (STREQ (loadtype_str, "srec")) { /* load an srecord by converting */
993 monitor_load_srec(file, fromtty); /* if from a binary */
996 if (STREQ (loadtype_str, "ascii-srec")) { /* load an srecord file */
997 monitor_load_ascii_srec(file, fromtty); /* if from a binary */
1000 if (STREQ (loadtype_str, "xmodem-srec")) { /* load an srecord using the */
1001 error ("This protocol is not implemented yet."); /* xmodem protocol */
1006 * monitor_load_ascii_srec -- download an ASCII srecord file.
1008 #define DOWNLOAD_LINE_SIZE 100
1010 monitor_load_ascii_srec (file, fromtty)
1015 char buf[DOWNLOAD_LINE_SIZE];
1018 debuglogs (1, "Loading an ASCII srecord file, %s.", file);
1020 download = fopen (file, "r");
1021 if (download == NULL) {
1022 error ("%s Does not exist", file);
1026 printf_monitor (LOAD_CMD);
1028 while (!feof (download)) {
1029 bytes_read = fread (buf, sizeof (char), DOWNLOAD_LINE_SIZE, download);
1034 if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
1035 fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
1039 while (i++ <=200) {} ; /* Ugly HACK, probably needs flow control */
1040 if (bytes_read < DOWNLOAD_LINE_SIZE) {
1041 if (!feof (download))
1042 error ("Only read %d bytes\n", bytes_read);
1050 if (!feof (download))
1051 error ("Never got EOF while downloading");
1057 * monitor_command -- put a command string, in args, out to MONITOR.
1058 * Output from MONITOR is placed on the users terminal until the
1059 * prompt is seen. FIXME: We read the charcters ourseleves here
1060 * cause of a nasty echo.
1063 monitor_command (args, fromtty)
1072 debuglogs (1, "monitor_command (args=%s)", args);
1074 if (monitor_desc == NULL)
1075 error("monitor target not open.");
1078 error("Missing command.");
1080 printf_monitor ("%s\n", args);
1086 * monitor_load_srec -- download a binary file by converting it to srecords.
1089 monitor_load_srec (args, fromtty)
1096 int srec_frame = SREC_SIZE;
1098 abfd = bfd_openr (args, 0);
1100 printf_filtered ("Unable to open file %s\n", args);
1104 if (bfd_check_format (abfd, bfd_object) == 0) {
1105 printf_filtered ("File is not an object file\n");
1110 while (s != (asection *) NULL) {
1111 srec_frame = SREC_SIZE;
1112 if (s->flags & SEC_LOAD) {
1114 char *buffer = xmalloc (srec_frame);
1115 printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, s->vma + s
1118 for (i = 0; i < s->_raw_size; i += srec_frame) {
1119 if (srec_frame > s->_raw_size - i)
1120 srec_frame = s->_raw_size - i;
1122 bfd_get_section_contents (abfd, s, buffer, i, srec_frame);
1123 monitor_write_srec (s->vma + i, buffer, srec_frame);
1124 printf_filtered ("*");
1127 printf_filtered ("\n");
1132 sprintf (buffer, "rs ip %lx", (unsigned long) abfd->start_address);
1133 printf_monitor (buffer);
1139 monitor_write_srec (memaddr, myaddr, len)
1141 unsigned char *myaddr;
1148 int srec_bytes = 40;
1149 int srec_max_retries = 3;
1150 int srec_echo_pace = 0;
1153 char *buffer = alloca ((srec_bytes + 8) << 1);
1157 while (1) { /* FIXME !!! */
1160 if (retries > srec_max_retries)
1164 if (sr_get_debug() > 0)
1165 printf("\n<retrying...>\n");
1167 /* This gr_expect_prompt call is extremely important. Without
1168 it, we will tend to resend our packet so fast that it
1169 will arrive before the bug monitor is ready to receive
1170 it. This would lead to a very ugly resend loop. */
1175 /* FIXME: this is just start_load pasted in... */
1177 command = (srec_echo_pace ? "lo 0 ;x" : "lo 0");
1178 sr_write_cr (command);
1179 sr_expect (command);
1182 bug_srec_write_cr ("S0030000FC");
1187 while (done < len) {
1194 thisgo = len - done;
1195 if (thisgo > srec_bytes)
1196 thisgo = srec_bytes;
1198 address = memaddr + done;
1199 sprintf (buf, "S3%02X%08X", thisgo + 4 + 1, address);
1202 checksum += (thisgo + 4 + 1
1204 + ((address >> 8) & 0xff)
1205 + ((address >> 16) & 0xff)
1206 + ((address >> 24) & 0xff));
1208 for (idx = 0; idx < thisgo; idx++) {
1209 sprintf (buf, "%02X", myaddr[idx + done]);
1210 checksum += myaddr[idx + done];
1214 if (srec_noise > 0) {
1215 /* FIXME-NOW: insert a deliberate error every now and then.
1216 This is intended for testing/debugging the error handling
1218 static int counter = 0;
1219 if (++counter > srec_noise) {
1225 sprintf(buf, "%02X", ~checksum & 0xff);
1227 bug_srec_write_cr (buffer);
1230 if (srec_sleep != 0)
1233 /* This pollchar is probably redundant to the gr_multi_scan
1234 below. Trouble is, we can't be sure when or where an
1235 error message will appear. Apparently, when running at
1236 full speed from a typical sun4, error messages tend to
1237 appear to arrive only *after* the s7 record. */
1239 if ((x = sr_pollchar()) != 0) {
1240 if (sr_get_debug() > 0)
1241 printf("\n<retrying...>\n");
1245 /* flush any remaining input and verify that we are back
1246 at the prompt level. */
1248 /* start all over again. */
1249 /* FIXME: this is just start_load pasted in... */
1251 command = (srec_echo_pace ? "lo 0 ;x" : "lo 0");
1252 sr_write_cr (command);
1253 sr_expect (command);
1256 bug_srec_write_cr ("S0030000FC");
1268 bug_srec_write_cr("S7060000000000F9");
1272 /* Having finished the load, we need to figure out whether we
1280 * _initialize_remote_monitors -- setup a few addtitional commands that
1281 * are usually only used by monitors.
1284 _initialize_remote_monitors ()
1286 struct cmd_list_element *c;
1288 /* this sets the type of download protocol */
1289 c = add_set_cmd ("loadtype", no_class, var_string, (char *)&loadtype_str,
1290 "Set the type of the remote load protocol.\n", &setlist);
1291 c->function.sfunc = set_loadtype_command;
1292 add_show_from_set (c, &showlist);
1293 loadtype_str = savestring ("default", 8);
1295 add_show_from_set (add_set_cmd ("hash", no_class, var_boolean,
1297 "Set display of activity while downloading a file.\n\
1298 When enabled, a period \'.\' is displayed.",
1302 /* generic monitor command */
1303 add_com ("monitor", class_obscure, monitor_command,
1304 "Send a command to the debug monitor.");