* corelow.c, exec.c, inftarg.c, m3-nat.c, op50-rom.c, procfs.c,
[deliverable/binutils-gdb.git] / gdb / monitor.c
index bd0709dea59500a1b7ca63f975fa0590ca4657d7..0113a057873d93e673191b0408cc21450ab2883e 100644 (file)
@@ -52,6 +52,9 @@ struct monitor_ops *current_monitor;
 extern struct cmd_list_element *setlist;
 extern struct cmd_list_element *unsetlist;
 struct cmd_list_element *showlist;
+extern char *version;
+extern char *host_name;
+extern char *target_name;
 
 static int hashmark;                           /* flag set by "set hash" */
 
@@ -72,6 +75,8 @@ static serial_t monitor_desc = NULL;
 char *loadtype;
 static char *loadtype_str;
 static void set_loadtype_command();
+static void monitor_load_srec();
+static int monitor_write_srec();
 
 /*
  * set_loadtype_command -- set the type for downloading. Check to make
@@ -83,24 +88,27 @@ set_loadtype_command (ignore, from_tty, c)
      int from_tty;
      struct cmd_list_element *c;
 {
-#if 0
+  char *tmp;
   char *type;
-  if (strcmp (LOADTYPES, "")) {
+  if (STREQ (LOADTYPES, "")) {
     error ("No loadtype set");
     return;
   }
   
-  type = strtok(LOADTYPES, ",");
+  tmp = savestring (LOADTYPES, strlen(LOADTYPES));
+  type = strtok(tmp, ",");
   if (STREQ (type, (*(char **) c->var))) {
       loadtype_str = savestring (*(char **) c->var, strlen (*(char **) c->var));
       return;
     }
   
-  while (type = strtok (NULL, ",") != (char *)NULL)
+  while ((type = strtok (NULL, ",")) != (char *)NULL) {
     if (STREQ (type, (*(char **) c->var)))
       loadtype_str = savestring (*(char **) c->var, strlen (*(char **) c->var));
-#endif
-      loadtype_str = savestring (*(char **) c->var, strlen (*(char **) c->var));
+    return;
+  }
+  free (tmp);
+  error ("Loadtype \"%s\" does not exist.", (*(char **) c->var));
 }
 
 /*
@@ -121,13 +129,88 @@ printf_monitor(va_alist)
 
   vsprintf(buf, pattern, args);
 
-  if (sr_get_debug() > 3)
-    printf ("Sending to monitor,\r\n\t\"%s\".\r\n", buf);
+  debuglogs (1, "printf_monitor(), Sending: \"%s\".", buf);
 
   if (SERIAL_WRITE(monitor_desc, buf, strlen(buf)))
     fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
 }
 
+/*
+ * debuglogs -- deal with debugging info to multiple sources. This takes
+ *     two real args, the first one is the level to be compared against 
+ *     the sr_get_debug() value, the second arg is a printf buffer and args
+ *     to be formatted and printed. A CR is added after each string is printed.
+ */
+static void
+debuglogs(va_alist)
+     va_dcl
+{
+  va_list args;
+  char *pattern, *p;
+  char buf[200];
+  char newbuf[300];
+  int level, i;
+
+  va_start(args);
+
+  level = va_arg(args, int);                   /* get the debug level */
+  if ((level <0) || (level > 100)) {
+    error ("Bad argument passed to debuglogs()");
+    return;
+  }
+      
+  pattern = va_arg(args, char *);              /* get the printf style pattern */
+
+  vsprintf(buf, pattern, args);                        /* format the string */
+  
+  /* convert some characters so it'll look right in the log */
+  p = newbuf;
+  for (i=0 ; buf[i] != '\0'; i++) {
+    switch (buf[i]) {
+    case '\n':                                 /* newlines */
+      *p++ = '\\';
+      *p++ = 'n';
+      continue;
+    case '\r':                                 /* carriage returns */
+      *p++ = '\\';
+      *p++ = 'r';
+      continue;
+    case '\033':                               /* escape */
+      *p++ = '\\';
+      *p++ = 'e';
+      continue;
+    case '\t':                                 /* tab */
+      *p++ = '\\';
+      *p++ = 't';
+      continue;
+    case '\b':                                 /* backspace */
+      *p++ = '\\';
+      *p++ = 'b';
+      continue;
+    default:                                   /* no change */
+      *p++ = buf[i];
+    }
+
+    if (buf[i] < 26) {                         /* modify control characters */
+      *p++ = '^';
+      *p++ = buf[i] + 'A';
+      continue;
+    }
+  }
+  *p = '\0';                                   /* terminate the string */
+
+  if (sr_get_debug() > level)
+    puts (newbuf);
+
+#ifdef LOG_FILE                                        /* write to the monitor log */
+  if (log_file != 0x0) {
+    fputs (newbuf, log_file);
+    fputc ('\n', log_file);
+    fflush (log_file);
+  }
+#endif
+}
+
 /* readchar -- read a character from the remote system, doing all the fancy
  *     timeout stuff.
  */
@@ -139,7 +222,7 @@ readchar(timeout)
 
   c = SERIAL_READCHAR(monitor_desc, timeout);
 
-  if (sr_get_debug() > 5)
+  if (sr_get_debug() > 4)
     putchar(c & 0x7f);
 
 #ifdef LOG_FILE
@@ -154,6 +237,9 @@ readchar(timeout)
     if (timeout == 0)
       return c;                /* Polls shouldn't generate timeout errors */
     error("Timeout reading from remote system.");
+#ifdef LOG_FILE
+      fputc ("ERROR: Timeout reading from remote system", log_file);
+#endif
   }
   perror_with_name("remote-monitor");
 }
@@ -172,8 +258,7 @@ expect (string, discard)
   int c;
 
 
-  if (sr_get_debug())
-    printf ("Expecting \"%s\".\n", string);
+  debuglogs (1, "Expecting \"%s\".", string);
 
   immediate_quit = 1;
   while (1) {
@@ -183,8 +268,7 @@ expect (string, discard)
     if (c == *p++) {
       if (*p == '\0') {
        immediate_quit = 0;
-       if (sr_get_debug())
-         printf ("\nMatched\n");
+       debuglogs (4, "Matched");
        return;
       }
     } else {
@@ -238,11 +322,11 @@ junk(ch)
   case '\r':
   case '\n':
     if (sr_get_debug() > 5)
-      printf ("Ignoring \'%c\'.\n", ch);
+      debuglogs (5, "Ignoring \'%c\'.", ch);
     return 1;
   default:
     if (sr_get_debug() > 5)
-      printf ("Accepting \'%c\'.\n", ch);
+      debuglogs (5, "Accepting \'%c\'.", ch);
     return 0;
   }
 }
@@ -261,7 +345,7 @@ get_hex_digit(ignore)
     if (junk(ch))
       continue;
     if (sr_get_debug() > 4)
-      printf ("get_hex_digit() got a 0x%x(%c)\n", ch, ch);
+      debuglogs (4, "get_hex_digit() got a 0x%x(%c)", ch, ch);
 
     if (ch >= '0' && ch <= '9')
       return ch - '0';
@@ -288,16 +372,13 @@ get_hex_byte (byt)
   int val;
 
   val = get_hex_digit (1) << 4;
-   if (sr_get_debug() > 3)
-    printf ("\nget_hex_digit() -- Read first nibble 0x%x\n", val);
+  debuglogs (4, "get_hex_digit() -- Read first nibble 0x%x", val);
  
   val |= get_hex_digit (0);
-  if (sr_get_debug() > 3)
-    printf ("\nget_hex_digit() -- Read second nibble 0x%x\n", val);
+  debuglogs (4, "get_hex_digit() -- Read second nibble 0x%x", val);
   *byt = val;
   
-  if (sr_get_debug() > 3)
-    printf ("\nget_hex_digit() -- Read a 0x%x\n", val);
+  debuglogs (4, "get_hex_digit() -- Read a 0x%x", val);
 }
 
 /* 
@@ -314,8 +395,7 @@ get_hex_word ()
   for (i = 0; i < 8; i++)
     val = (val << 4) + get_hex_digit (i == 0);
   
-  if (sr_get_debug() > 3)
-    printf ("\nget_hex_word() got a 0x%x.\n", val);
+  debuglogs (4, "get_hex_word() got a 0x%x.", val);
 
   return val;
 }
@@ -338,9 +418,7 @@ monitor_create_inferior (execfile, args, env)
 
   entry_pt = (int) bfd_get_start_address (exec_bfd);
 
-#ifdef LOG_FILE
-  fputs ("\nIn Create_inferior()", log_file);
-#endif
+  debuglogs (1, "create_inferior(exexfile=%s, args=%s, env=%s)", execfile, args, env);
 
 /* The "process" (board) is already stopped awaiting our commands, and
    the program is already downloaded.  We just set its PC and go.  */
@@ -390,21 +468,22 @@ monitor_open(args, name, from_tty)
   if (monitor_desc == NULL)
     perror_with_name(dev_name);
 
-  if (baud_rate != -1)
-    {
-      if (SERIAL_SETBAUDRATE (monitor_desc, baud_rate))
-       {
-         SERIAL_CLOSE (monitor_desc);
-         perror_with_name (name);
-       }
+  if (baud_rate != -1) {
+    if (SERIAL_SETBAUDRATE (monitor_desc, baud_rate)) {
+      SERIAL_CLOSE (monitor_desc);
+      perror_with_name (name);
     }
-
+  }
+  
   SERIAL_RAW(monitor_desc);
 
 #if defined (LOG_FILE)
   log_file = fopen (LOG_FILE, "w");
   if (log_file == NULL)
     perror_with_name (LOG_FILE);
+  fprintf_filtered (log_file, "GDB %s (%s", version, host_name);
+  fprintf_filtered (log_file, " --target %s)\n", target_name);
+  fprintf_filtered (log_file, "Remote target %s connected to %s\n\n", TARGET_NAME, dev_name);
 #endif
 
   /* wake up the monitor and see if it's alive */
@@ -417,8 +496,6 @@ monitor_open(args, name, from_tty)
 
   if (from_tty)
     printf("Remote target %s connected to %s\n", TARGET_NAME, dev_name);
-
-  
 }
 
 /*
@@ -433,8 +510,7 @@ monitor_close (quitting)
   SERIAL_CLOSE(monitor_desc);
   monitor_desc = NULL;
 
-  if (sr_get_debug() > 4)
-    puts ("\nmonitor_close ()");
+  debuglogs (1, "monitor_close (quitting=%d)", quitting);
 
 #if defined (LOG_FILE)
   if (log_file) {
@@ -455,9 +531,8 @@ void
 monitor_detach (from_tty)
      int from_tty;
 {
-#ifdef LOG_FILE
-  fprintf (log_file, "\nmonitor_detach ()\n");
-#endif
+
+  debuglogs (1, "monitor_detach ()");
 
   pop_target();                /* calls monitor_close to do the real work */
   if (from_tty)
@@ -475,13 +550,8 @@ monitor_attach (args, from_tty)
   if (from_tty)
     printf ("Starting remote %s debugging\n", target_shortname);
  
-#ifdef LOG_FILE
-  fprintf (log_file, "\nmonitor_attach (args=%s)\n", args);
-#endif
+  debuglogs (1, "monitor_attach (args=%s)", args);
   
-  if (sr_get_debug() > 4)
-    printf ("\nmonitor_attach (args=%s)\n", args);
-
   printf_monitor (GO_CMD);
   /* swallow the echo.  */
   expect (GO_CMD, 1);
@@ -495,45 +565,35 @@ monitor_resume (pid, step, sig)
      int pid, step;
      enum target_signal sig;
 {
-#ifdef LOG_FILE
-  fprintf (log_file, "\nmonitor_resume (step=%d, sig=%d)\n", step, sig);
-#endif
-
-  if (sr_get_debug() > 4)
-    printf ("\nmonitor_resume (step=%d, sig=%d)\n", step, sig);
+  debuglogs (1, "monitor_resume (step=%d, sig=%d)", step, sig);
 
   if (step) {
     printf_monitor (STEP_CMD);
-    /* wait for the echo.  */
-    expect (STEP_CMD, 1);
   } else {
     printf_monitor (CONT_CMD);
-    /* swallow the echo.  */
-    expect (CONT_CMD, 1);
   }
 }
 
 /*
- * _wait -- Wait until the remote machine stops, then return,
+ * monitor_wait -- Wait until the remote machine stops, then return,
  *          storing status in status just as `wait' would.
  */
-
 int
 monitor_wait (pid, status)
      int pid;
      struct target_waitstatus *status;
 {
   int old_timeout = timeout;
-#ifdef LOG_FILE
-  fputs ("\nIn wait ()", log_file);
-#endif
 
+  debuglogs(1, "monitor_wait (), printing extraneous text.");
+  
   status->kind = TARGET_WAITKIND_EXITED;
   status->value.integer = 0;
 
   timeout = 0;         /* Don't time out -- user program is running. */
 
   expect_prompt(0);    /* Wait for prompt, outputting extraneous text */
+  debuglogs (4, "monitor_wait(), got the prompt.");
 
   status->kind = TARGET_WAITKIND_STOPPED;
   status->value.sig = TARGET_SIGNAL_TRAP;
@@ -565,19 +625,15 @@ get_reg_name (regno)
 
   *b = '\000';
 
-  if (sr_get_debug() > 5)
-    printf ("Got name \"%s\" from regno #%d.\n", buf, regno);
-
-#ifdef LOG_FILE
-  fprintf (log_file, "Got name \"%s\" from regno #%d.\n", buf, regno);
-  fflush (log_file);
-#endif
+  debuglogs (5, "Got name \"%s\" from regno #%d.", buf, regno);
 
   return buf;
 }
 
-/* read the remote registers into the block regs.  */
-
+/*
+ * monitor_fetch_registers -- read the remote registers into the
+ *     block regs.
+ */
 void
 monitor_fetch_registers ()
 {
@@ -600,10 +656,7 @@ monitor_fetch_register (regno)
 {
   int val, j;
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Fetch Register (reg=%s)\n", get_reg_name (regno));
-  fflush (log_file);
-#endif
+  debuglogs (1, "monitor_fetch_register (reg=%s)", get_reg_name (regno));
 
   if (regno < 0) {
     monitor_fetch_registers ();
@@ -636,10 +689,8 @@ monitor_store_registers ()
 {
   int regno;
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Fetch Registers\n");
-  fflush (log_file);
-#endif
+  debuglogs (1, "monitor_store_registers()");
+
   for (regno = 0; regno <= PC_REGNUM; regno++)
     monitor_store_register(regno);
 
@@ -659,15 +710,12 @@ monitor_store_register (regno)
 
   i = read_register(regno);
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Store_register (regno=%d)\n", regno);
-#endif
+  debuglogs (1, "monitor_store_register (regno=%d)", regno);
 
   if (regno < 0)
     monitor_store_registers ();
   else {
-    if (sr_get_debug() > 3)
-      printf ("Setting register %s to 0x%x\n", get_reg_name (regno), read_register (regno));
+      debuglogs (3, "Setting register %s to 0x%x", get_reg_name (regno), read_register (regno));
     
     name = get_reg_name (regno);
     if (STREQ(name, ""))
@@ -723,12 +771,7 @@ monitor_write_inferior_memory (memaddr, myaddr, len)
   int i;
   char buf[10];
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Write_inferior_memory (memaddr=%x, len=%d)\n", memaddr, len);
-#endif
-
-  if (sr_get_debug() > 0)
-    printf ("\nTrying to set 0x%x to 0x%x\n", memaddr, myaddr);
+  debuglogs (1, "monitor_write_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
 
   for (i = 0; i < len; i++) {
     printf_monitor (ROMCMD(SET_MEM), memaddr + i, myaddr[i] );
@@ -772,9 +815,7 @@ monitor_read_inferior_memory(memaddr, myaddr, len)
   /* Number of bytes to read in this pass.  */
   int len_this_pass;
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Read_inferior_memory (memaddr=%x, len=%d)\n", memaddr, len);
-#endif
+  debuglogs (1, "monitor_read_inferior_memory (memaddr=0x%x, myaddr=0x%x, len=%d)", memaddr, myaddr, len);
 
   /* Note that this code works correctly if startaddr is just less
      than UINT_MAX (well, really CORE_ADDR_MAX if there was such a
@@ -798,16 +839,12 @@ monitor_read_inferior_memory(memaddr, myaddr, len)
       len_this_pass -= startaddr % 16;
     if (len_this_pass > (len - count))
       len_this_pass = (len - count);
-    if (sr_get_debug())
-      printf ("\nDisplay %d bytes at %x\n", len_this_pass, startaddr);
+
+    debuglogs (3, "Display %d bytes at %x", len_this_pass, startaddr);
     
     for (i = 0; i < len_this_pass; i++) {
       printf_monitor (ROMCMD(GET_MEM), startaddr, startaddr);
       sprintf (buf, ROMCMD(GET_MEM), startaddr, startaddr);
-#if 0
-      expect (buf,1);                          /* get the command echo */
-      get_hex_word(1);                         /* strip away the address */
-#endif
       if (*ROMDELIM(GET_MEM) != 0) {           /* if there's a delimiter */
        expect (ROMDELIM(GET_MEM), 1);
       } else {
@@ -877,12 +914,7 @@ monitor_insert_breakpoint (addr, shadow)
 {
   int i;
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Insert_breakpoint (addr=%x)\n", addr);
-#endif
-
-  if (sr_get_debug() > 4)
-    printf ("insert_breakpoint() addr = 0x%x\n", addr);
+  debuglogs (1, "monitor_insert_breakpoint() addr = 0x%x", addr);
 
   for (i = 0; i <= MAX_MONITOR_BREAKPOINTS; i++) {
     if (breakaddr[i] == 0) {
@@ -910,12 +942,7 @@ monitor_remove_breakpoint (addr, shadow)
 {
   int i;
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nIn Remove_breakpoint (addr=%x)\n", addr);
-#endif
-
-  if (sr_get_debug() > 4)
-    printf ("remove_breakpoint (addr=%x)\n", addr);
+  debuglogs (1, "monitor_remove_breakpoint() addr = 0x%x", addr);
 
   for (i = 0; i < MAX_MONITOR_BREAKPOINTS; i++) {
     if (breakaddr[i] == addr) {
@@ -933,60 +960,96 @@ monitor_remove_breakpoint (addr, shadow)
   return 1;
 }
 
-/* Load a file. This is usually an srecord, which is ascii. No 
-   protocol, just sent line by line. */
+/* monitor_load -- load a file. This file determines which of the
+ *     supported formats to use. The current types are:
+ *     FIXME: not all types supported yet.
+ *     default - reads any file using bfd and writes it to memory.
+ *     srec    - reads binary file using bfd and writes it as an
+ *             ascii srecord.
+ *     xmodem-bin - reads a binary file using bfd, and  downloads it
+ *              using xmodem protocol.
+ *     xmodem-srec - reads a binary file using bfd, and after converting
+ *              it downloads it as an srecord using xmodem protocol.
+ *     ascii-srec - reads a ascii srecord file and downloads it
+ *             without a change.
+ *     ascii-xmodem - reads a ascii file and downloads using xmodem
+ *             protocol.
+ */
+void
+monitor_load (file, fromtty)
+    char *file;
+    int  fromtty;
+{
+  FILE *download;
+  int i, bytes_read;
+
+  debuglogs (1, "Loading %s to monitor", file);
+
+  if (STREQ (loadtype_str, "default")) {       /* default, load a binary */
+    gr_load_image (file, fromtty);             /* by writing it into memory */
+  }
+
+  if (STREQ (loadtype_str, "srec")) {          /* load an srecord by converting */
+    monitor_load_srec(file, fromtty);          /* if from a binary */
+  }
+
+  if (STREQ (loadtype_str, "ascii-srec")) {    /* load an srecord file */
+    monitor_load_ascii_srec(file, fromtty);            /* if from a binary */
+  }
 
+  if (STREQ (loadtype_str, "xmodem-srec")) {   /* load an srecord using the */
+   error ("This protocol is not implemented yet.");    /* xmodem protocol */
+  }
+}
+
+/*
+ * monitor_load_ascii_srec -- download an ASCII srecord file.
+ */
 #define DOWNLOAD_LINE_SIZE 100
-void
-monitor_load (arg)
-    char       *arg;
+int
+monitor_load_ascii_srec (file, fromtty)
+    char *file;
+    int fromtty;
 {
   FILE *download;
   char buf[DOWNLOAD_LINE_SIZE];
   int i, bytes_read;
 
-  if (sr_get_debug())
-    printf ("Loading %s to monitor\n", arg);
+  debuglogs (1, "Loading an ASCII srecord file, %s.", file);
 
-  download = fopen (arg, "r");
-  if (download == NULL)
-    {
-    error (sprintf (buf, "%s Does not exist", arg));
+  download = fopen (file, "r");
+  if (download == NULL) {
+    error ("%s Does not exist", file);
     return;
   }
 
   printf_monitor (LOAD_CMD);
-/*  expect ("Waiting for S-records from host... ", 1); */
-
-  while (!feof (download))
-    {
-      bytes_read = fread (buf, sizeof (char), DOWNLOAD_LINE_SIZE, download);
-      if (hashmark)
-       {
-         putchar ('.');
-         fflush (stdout);
-       }
 
-      if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
-       fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
-       break;
-      }
-      i = 0;
-      while (i++ <=200000) {} ;                        /* Ugly HACK, probably needs flow control */
-      if (bytes_read < DOWNLOAD_LINE_SIZE)
-       {
-         if (!feof (download))
-           error ("Only read %d bytes\n", bytes_read);
-         break;
-       }
+  while (!feof (download)) {
+    bytes_read = fread (buf, sizeof (char), DOWNLOAD_LINE_SIZE, download);
+    if (hashmark) {
+      putchar ('.');
+      fflush (stdout);
     }
-
-  if (hashmark)
-    {
-      putchar ('\n');
+    if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
+      fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
+      break;
     }
+    i = 0;
+    while (i++ <=200) {} ;                             /* Ugly HACK, probably needs flow control */
+    if (bytes_read < DOWNLOAD_LINE_SIZE) {
+      if (!feof (download))
+       error ("Only read %d bytes\n", bytes_read);
+      break;
+    }
+  }
+  
+  if (hashmark) {
+    putchar ('\n');
+  }
   if (!feof (download))
     error ("Never got EOF while downloading");
+  expect_prompt(1);
   fclose (download);
 }
 
@@ -1006,23 +1069,213 @@ monitor_command (args, fromtty)
   char c, cp;
   p = PROMPT;
 
-#ifdef LOG_FILE
-  fprintf (log_file, "\nmonitor_command (args=%s)\n", args);
-#endif
+  debuglogs (1, "monitor_command (args=%s)", args);
+
   if (monitor_desc == NULL)
     error("monitor target not open.");
 
   if (!args)
     error("Missing command.");
        
-  if (sr_get_debug() > 4)
-    printf ("monitor_command (args=%s)\n", args);
-
   printf_monitor ("%s\n", args);
 
   expect_prompt(0);
 }
 
+/*
+ * monitor_load_srec -- download a binary file by converting it to srecords.
+ */
+static void
+monitor_load_srec (args, fromtty)
+     char *args;
+     int fromtty;
+{
+  bfd *abfd;
+  asection *s;
+  char buffer[1024];
+  int srec_frame = SREC_SIZE;
+
+  abfd = bfd_openr (args, 0);
+  if (!abfd) {
+    printf_filtered ("Unable to open file %s\n", args);
+    return;
+  }
+
+  if (bfd_check_format (abfd, bfd_object) == 0) {
+    printf_filtered ("File is not an object file\n");
+    return;
+  }
+  
+  s = abfd->sections;
+  while (s != (asection *) NULL) {
+    srec_frame = SREC_SIZE;
+    if (s->flags & SEC_LOAD) {
+      int i;
+      char *buffer = xmalloc (srec_frame);
+      printf_filtered ("%s\t: 0x%4x .. 0x%4x  ", s->name, s->vma, s->vma + s
+                      ->_raw_size);
+      fflush (stdout);
+      for (i = 0; i < s->_raw_size; i += srec_frame) {
+       if (srec_frame > s->_raw_size - i)
+         srec_frame = s->_raw_size - i;
+       
+       bfd_get_section_contents (abfd, s, buffer, i, srec_frame);
+       monitor_write_srec (s->vma + i, buffer, srec_frame);
+       printf_filtered ("*");
+       fflush (stdout);
+      }
+      printf_filtered ("\n");
+      free (buffer);
+    }
+    s = s->next;
+  }
+  sprintf (buffer, "rs ip %lx", (unsigned long) abfd->start_address);
+  printf_monitor (buffer);
+  expect_prompt ();
+}
+
+
+static int
+monitor_write_srec (memaddr, myaddr, len)
+     CORE_ADDR memaddr;
+     unsigned char *myaddr;
+     int len;
+{
+  int done;
+  int checksum;
+  int x;
+  int retries;
+  int srec_bytes = 40;
+  int srec_max_retries = 3;
+  int srec_echo_pace = 0;
+  int srec_sleep = 0;
+  int srec_noise = 0;
+  char *buffer = alloca ((srec_bytes + 8) << 1);
+
+  retries = 0;
+
+  while (1) {                                  /* FIXME !!! */
+    done = 0;
+    
+    if (retries > srec_max_retries)
+      return(-1);
+    
+      if (retries > 0) {
+       if (sr_get_debug() > 0)
+         printf("\n<retrying...>\n");
+       
+          /* This gr_expect_prompt call is extremely important.  Without
+             it, we will tend to resend our packet so fast that it
+             will arrive before the bug monitor is ready to receive
+             it.  This would lead to a very ugly resend loop.  */
+       
+       gr_expect_prompt();
+      }
+    
+    /* FIXME: this is just start_load pasted in... */
+    { char *command;
+    command = (srec_echo_pace ? "lo 0 ;x" : "lo 0");
+    sr_write_cr (command);
+    sr_expect (command);
+    sr_expect ("\r\n");
+#if 0
+    bug_srec_write_cr ("S0030000FC");
+#endif
+    }
+    /* end of hack */
+
+      while (done < len) {
+       int thisgo;
+       int idx;
+       char *buf = buffer;
+       CORE_ADDR address;
+       
+       checksum = 0;
+       thisgo = len - done;
+       if (thisgo > srec_bytes)
+         thisgo = srec_bytes;
+       
+       address = memaddr + done;
+       sprintf (buf, "S3%02X%08X", thisgo + 4 + 1, address);
+       buf += 12;
+       
+       checksum += (thisgo + 4 + 1
+                    + (address & 0xff)
+                    + ((address >>  8) & 0xff)
+                    + ((address >> 16) & 0xff)
+                    + ((address >> 24) & 0xff));
+       
+       for (idx = 0; idx < thisgo; idx++) {
+         sprintf (buf, "%02X", myaddr[idx + done]);
+         checksum += myaddr[idx + done];
+         buf += 2;
+       }
+       
+       if (srec_noise > 0) {
+         /* FIXME-NOW: insert a deliberate error every now and then.
+            This is intended for testing/debugging the error handling
+            stuff.  */
+         static int counter = 0;
+         if (++counter > srec_noise) {
+           counter = 0;
+           ++checksum;
+         }
+       }
+       
+       sprintf(buf, "%02X", ~checksum & 0xff);
+#if 0
+       bug_srec_write_cr (buffer);
+#endif
+       
+       if (srec_sleep != 0)
+         sleep(srec_sleep);
+       
+       /* This pollchar is probably redundant to the gr_multi_scan
+          below.  Trouble is, we can't be sure when or where an
+          error message will appear.  Apparently, when running at
+          full speed from a typical sun4, error messages tend to
+          appear to arrive only *after* the s7 record.   */
+       
+       if ((x = sr_pollchar()) != 0) {
+         if (sr_get_debug() > 0)
+           printf("\n<retrying...>\n");
+
+         ++retries;
+         
+         /* flush any remaining input and verify that we are back
+            at the prompt level. */
+         gr_expect_prompt();
+         /* start all over again. */
+    /* FIXME: this is just start_load pasted in... */
+    { char *command;
+    command = (srec_echo_pace ? "lo 0 ;x" : "lo 0");
+    sr_write_cr (command);
+    sr_expect (command);
+    sr_expect ("\r\n");
+#if 0
+    bug_srec_write_cr ("S0030000FC");
+#endif
+    }
+    /* end of hack */
+
+         done = 0;
+         continue;
+       }
+       
+       done += thisgo;
+      }
+#if 0    
+    bug_srec_write_cr("S7060000000000F9");
+#endif
+    ++retries;
+    
+    /* Having finished the load, we need to figure out whether we
+       had any errors.  */
+  }
+  
+  return(0);
+}
+
 /*
  * _initialize_remote_monitors -- setup a few addtitional commands that
  *             are usually only used by monitors.
@@ -1037,7 +1290,7 @@ _initialize_remote_monitors ()
        "Set the type of the remote load protocol.\n", &setlist);
   c->function.sfunc =  set_loadtype_command;
   add_show_from_set (c, &showlist);
-  loadtype_str = savestring ("generic", 8);
+  loadtype_str = savestring ("default", 8);
 
   add_show_from_set (add_set_cmd ("hash", no_class, var_boolean,
                                   (char *)&hashmark,
This page took 0.032984 seconds and 4 git commands to generate.