static int readchar (int timeout) { int c; do { c = serial_readchar (e7000_desc, timeout); } while (c > 127); if (c == SERIAL_TIMEOUT) { if (timeout == 0) return -1; echo = 0; error ("Timeout reading from remote system."); } else if (c < 0) error ("Serial communication error"); if (remote_debug) { putchar_unfiltered (c); gdb_flush (gdb_stdout); } return normal (c); }
static void expect (char *string) { char *p = string; int c; int nl = 0; while (1) { c = readchar (timeout); if (echo) { if (c == '\r' || c == '\n') { if (!nl) putchar_unfiltered ('\n'); nl = 1; } else { nl = 0; putchar_unfiltered (c); } gdb_flush (gdb_stdout); } if (normal (c) == normal (*p++)) { if (*p == '\0') return; } else { p = string; if (normal (c) == normal (string[0])) p++; } } }
static void w89k_load (struct serial *desc, char *file, int hashmark) { bfd *abfd; asection *s; char *buffer; int i; buffer = alloca (XMODEM_PACKETSIZE); abfd = bfd_openr (file, 0); if (!abfd) { printf_filtered ("Unable to open file %s\n", file); return; } if (bfd_check_format (abfd, bfd_object) == 0) { printf_filtered ("File is not an object file\n"); return; } for (s = abfd->sections; s; s = s->next) if (s->flags & SEC_LOAD) { bfd_size_type section_size; printf_filtered ("%s\t: 0x%4x .. 0x%4x ", s->name, s->vma, s->vma + s->_raw_size); gdb_flush (gdb_stdout); monitor_printf (w89k_cmds.load, s->vma); if (w89k_cmds.loadresp) monitor_expect (w89k_cmds.loadresp, NULL, 0); xmodem_init_xfer (desc); section_size = bfd_section_size (abfd, s); for (i = 0; i < section_size; i += XMODEM_DATASIZE) { int numbytes; numbytes = min (XMODEM_DATASIZE, section_size - i); bfd_get_section_contents (abfd, s, buffer + XMODEM_DATAOFFSET, i, numbytes); xmodem_send_packet (desc, buffer, numbytes, hashmark); if (hashmark) { putchar_unfiltered ('#'); gdb_flush (gdb_stdout); } } /* Per-packet (or S-record) loop */ xmodem_finish_xfer (desc); monitor_expect_prompt (NULL, 0); putchar_unfiltered ('\n'); } /* Loadable sections */ if (hashmark) putchar_unfiltered ('\n'); }