new serial interface.
+Fri Apr 9 15:53:19 1993 Stu Grossman (grossman@cygnus.com)
+
+ * remote-mips.c, remote-monitor.c, remote-st2000.c: Convert to
+ new serial interface.
+
Fri Apr 9 15:01:12 1993 Stu Grossman (grossman@cygnus.com)
* remote.c (remote_open): Use SERIAL_OPEN instead of serial_open.
/* This can be set to get debugging with ``set remotedebug''. */
static int mips_debug = 0;
+/* Handle used to access serial I/O stream. */
+static serial_t mips_desc;
+
/* Read a character from the remote, aborting on error. Returns -2 on
timeout (since that's what serial_readchar returns). FIXME: If we
see the string "<IDT>" from the board, then we are debugging on the
static int state = 0;
static char nextstate[5] = { '<', 'I', 'D', 'T', '>' };
- ch = serial_readchar (timeout);
- if (ch == EOF)
+ ch = SERIAL_READCHAR (mips_desc, timeout);
+ if (ch == SERIAL_EOF)
error ("End of file from remote");
- if (ch == -3)
+ if (ch == SERIAL_ERROR)
error ("Error reading from remote: %s", safe_strerror (errno));
if (mips_debug > 1)
{
- if (ch != -2)
+ if (ch != SERIAL_TIMEOUT)
printf_filtered ("Read '%c' %d 0x%x\n", ch, ch, ch);
else
printf_filtered ("Timed out in read\n");
described above. The first character in a packet after the SYN
(which is not echoed) is always an @ unless the packet is more
than 64 characters long, which ours never are. */
- if ((ch == -2 || ch == '@')
+ if ((ch == SERIAL_TIMEOUT || ch == '@')
&& state == 5
&& ! mips_initializing)
{
if (mips_debug > 0)
printf_filtered ("Reinitializing MIPS debugging mode\n");
- serial_write ("\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
+ SERIAL_WRITE (mips_desc, "\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
sleep (1);
mips_need_reply = 0;
printf_filtered ("Writing \"%s\"\n", packet + 1);
}
- if (serial_write (packet, HDR_LENGTH + len + TRLR_LENGTH) == 0)
+ if (SERIAL_WRITE (mips_desc, packet, HDR_LENGTH + len + TRLR_LENGTH))
error ("write to target failed: %s", safe_strerror (errno));
garbage = 0;
ack + 1);
}
- if (serial_write (ack, HDR_LENGTH + TRLR_LENGTH) == 0)
+ if (SERIAL_WRITE (mips_desc, ack, HDR_LENGTH + TRLR_LENGTH))
error ("write to target failed: %s", safe_strerror (errno));
}
ack + 1);
}
- if (serial_write (ack, HDR_LENGTH + TRLR_LENGTH) == 0)
+ if (SERIAL_WRITE (mips_desc, ack, HDR_LENGTH + TRLR_LENGTH))
error ("write to target failed: %s", safe_strerror (errno));
return len;
it means. The packet seems to be triggered by a carriage return
character, although perhaps any character would do. */
cr = '\r';
- serial_write (&cr, 1);
+ SERIAL_WRITE (mip_desc, &cr, 1);
hold_wait = mips_receive_wait;
mips_receive_wait = 3;
board and trying again. */
printf_filtered ("Failed to initialize; trying to reset board\n");
cc = '\003';
- serial_write (&cc, 1);
+ SERIAL_WRITE (mips_desc, &cc, 1);
sleep (2);
- serial_write ("\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
+ SERIAL_WRITE (mips_desc, "\rdb tty0\r", sizeof "\rdb tty0\r" - 1);
sleep (1);
cr = '\r';
- serial_write (&cr, 1);
+ SERIAL_WRITE (mips_desc, &cr, 1);
}
mips_receive_wait = hold_wait;
if (mips_is_open)
unpush_target (&mips_ops);
- if (serial_open (name) == 0)
+ mips_desc = SERIAL_OPEN (name);
+
+ if (!mips_desc)
perror_with_name (name);
+ SERIAL_RAW (mips_desc);
+
mips_is_open = 1;
mips_initialize ();
/* Get the board out of remote debugging mode. */
mips_request ('x', (unsigned int) 0, (unsigned int) 0, &err);
- serial_close ();
+ SERIAL_CLOSE (mips_desc);
}
}
/* Send a ^C. */
cc = '\003';
- serial_write (&cc, 1);
+ SERIAL_WRITE (mips_desc, &cc, 1);
sleep (1);
target_mourn_inferior ();
}
/* Descriptor for I/O to remote machine. Initialize it to -1 so that
monitor_open knows that we don't have a file open when the program
starts. */
-int monitor_desc = -1;
+static serial_t monitor_desc;
/* Send data to monitor. Works just like printf. */
vsprintf(buf, pattern, args);
- if (!serial_write(buf, strlen(buf)))
- fprintf(stderr, "serial_write failed: %s\n", safe_strerror(errno));
+ if (SERIAL_WRITE(monitor_desc, buf, strlen(buf)))
+ fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
}
/* Read a character from the remote system, doing all the fancy
{
int c;
- c = serial_readchar(timeout);
+ c = SERIAL_READCHAR(monitor_desc, timeout);
if (kiodebug)
putchar(c & 0x7f);
if (c >= 0)
return c & 0x7f;
- if (c == -2)
+ if (c == SERIAL_TIMEOUT)
{
if (timeout == 0)
return c; /* Polls shouldn't generate timeout errors */
static char dev_name[100];
static void
-rom68k_open(args, from_tty)
+general_open(args, name, from_tty)
char *args;
+ char *name;
int from_tty;
{
int n;
char junk[100];
- TERMINAL sg;
target_preopen(from_tty);
n = sscanf(args, " %s %d %s", dev_name, &baudrate, junk);
if (n != 2)
- error("Bad arguments. Usage: target rom68k <device> <speed>\n\
-or target monitor <host> <port>\n");
+ error("Bad arguments. Usage: target %s <device> <speed>\n\
+or target monitor <host> <port>\n", name);
monitor_close(0);
- monitor_desc = serial_open(dev_name);
+ monitor_desc = SERIAL_OPEN(dev_name);
- serial_setbaudrate(baudrate);
+ if (!monitor_desc)
+ perror_with_name(dev_name);
- ioctl (monitor_desc, TIOCGETP, &sg);
- sg.sg_flags = O_CRDELAY | O_NLDELAY | ~(RAW);
- ioctl (monitor_desc, TIOCSETN, &sg);
+ SERIAL_SETBAUDRATE(monitor_desc, baudrate);
- push_target(&rom68k_ops);
- push_monitor (&rom68k_cmds);
+ SERIAL_RAW(monitor_desc);
#if defined (LOG_FILE)
log_file = fopen (LOG_FILE, "w");
#endif
/* Hello? Are you there? */
- printf_monitor("\n"); /* CR wakes up monitor */
+ printf_monitor("\r"); /* CR wakes up monitor */
expect_prompt(1);
}
static void
-mon68_open(args, from_tty)
+rom68k_open(args, from_tty)
char *args;
int from_tty;
{
- int n;
- char junk[100];
-
- target_preopen(from_tty);
-
- n = sscanf(args, " %s %d %s", dev_name, &baudrate, junk);
-
- if (n != 2)
- error("Bad arguments. Usage: target mon68 <device> <speed>\n\
-or target monitor <host> <port>\n");
-
- monitor_close(0);
-
- monitor_desc = serial_open(dev_name);
+ push_target(&rom68k_ops);
+ push_monitor (&rom68k_cmds);
- serial_setbaudrate(baudrate);
+ general_open (args, "rom68k", from_tty);
+}
+static void
+mon68_open(args, from_tty)
+ char *args;
+ int from_tty;
+{
push_target(&mon68_ops);
push_monitor (&mon68_cmds);
-#if defined (LOG_FILE)
- log_file = fopen (LOG_FILE, "w");
- if (log_file == NULL)
- perror_with_name (LOG_FILE);
-#endif
-
- /* Hello? Are you there? */
- printf_monitor("\n"); /* CR wakes up dbug */
-
- expect_prompt(1);
-
- if (from_tty)
- printf("Remote %s connected to %s\n", target_shortname,
- dev_name);
+ general_open (args, "mon68", from_tty);
}
static void
char *args;
int from_tty;
{
- int n;
- char junk[100];
-
- target_preopen(from_tty);
-
- n = sscanf(args, " %s %d %s", dev_name, &baudrate, junk);
-
- if (n != 2)
- error("Bad arguments. Usage: target bug <device> <speed>\n\
-or target monitor <host> <port>\n");
-
- monitor_close(0);
-
- monitor_desc = serial_open(dev_name);
-
- serial_setbaudrate(baudrate);
-
push_target(&bug_ops);
push_monitor (&bug_cmds);
-#if defined (LOG_FILE)
- log_file = fopen (LOG_FILE, "w");
- if (log_file == NULL)
- perror_with_name (LOG_FILE);
-#endif
-
- /* Hello? Are you there? */
- printf_monitor("\r"); /* CR wakes up dbug */
-
- expect_prompt(1);
-
- if (from_tty)
- printf("Remote %s connected to %s\n", target_shortname,
- dev_name);
+ general_open (args, "bug", from_tty);
}
/*
* _close -- Close out all files and local state before this target loses control.
*/
+
static void
monitor_close (quitting)
int quitting;
{
- serial_close();
+ SERIAL_CLOSE(monitor_desc);
#if defined (LOG_FILE)
if (log_file) {
fflush (stdout);
}
- if (!serial_write(buf, bytes_read)) {
- fprintf(stderr, "serial_write failed: (while downloading) %s\n", safe_strerror(errno));
+ if (SERIAL_WRITE(monitor_desc, buf, bytes_read)) {
+ fprintf(stderr, "SERIAL_WRITE failed: (while downloading) %s\n", safe_strerror(errno));
break;
}
i = 0;
expect_prompt(0);
}
+#if 0
+
/* Connect the user directly to MONITOR. This command acts just like the
'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
static void
cleanup_tty()
{ printf("\r\n[Exiting connect mode]\r\n");
- serial_restore(0, &ttystate);
+ /*SERIAL_RESTORE(0, &ttystate);*/
}
static void
}
}
}
+#endif
/*
* Define the monitor command strings. Since these are passed directly
/* Descriptor for I/O to remote machine. Initialize it to -1 so that
st2000_open knows that we don't have a file open when the program
starts. */
-int st2000_desc = -1;
+
+static serial_t st2000_desc;
/* Send data to stdebug. Works just like printf. */
pattern = va_arg(args, char *);
vsprintf(buf, pattern, args);
- if (!serial_write(buf, strlen(buf)))
- fprintf(stderr, "serial_write failed: %s\n", safe_strerror(errno));
+ if (SERIAL_WRITE(st2000_desc, buf, strlen(buf)))
+ fprintf(stderr, "SERIAL_WRITE failed: %s\n", safe_strerror(errno));
}
-/* Read a character from the remote system, doing all the fancy
- timeout stuff. */
+/* Read a character from the remote system, doing all the fancy timeout
+ stuff. */
+
static int
readchar(timeout)
int timeout;
{
int c;
- c = serial_readchar(timeout);
+ c = SERIAL_READCHAR(st2000_desc, timeout);
#ifdef LOG_FILE
putc(c & 0x7f, log_file);
if (c >= 0)
return c & 0x7f;
- if (c == -2)
+ if (c == SERIAL_TIMEOUT)
{
if (timeout == 0)
return c; /* Polls shouldn't generate timeout errors */
st2000_close(0);
- st2000_desc = serial_open(dev_name);
+ st2000_desc = SERIAL_OPEN(dev_name);
+
+ if (!st2000_desc)
+ perror_with_name(dev_name);
- serial_setbaudrate(baudrate);
+ SERIAL_SETBAUDRATE(st2000_desc, baudrate);
+
+ SERIAL_RAW(st2000_desc);
push_target(&st2000_ops);
st2000_close (quitting)
int quitting;
{
- serial_close();
+ SERIAL_CLOSE(st2000_desc);
#if defined (LOG_FILE)
if (log_file) {
char *args;
int fromtty;
{
- if (st2000_desc < 0)
+ if (!st2000_desc)
error("st2000 target not open.");
if (!args)
/* Connect the user directly to STDBUG. This command acts just like the
'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
-static struct ttystate ttystate;
+/*static struct ttystate ttystate;*/
static void
cleanup_tty()
{
printf("\r\n[Exiting connect mode]\r\n");
- serial_restore(0, &ttystate);
+/* SERIAL_RESTORE(0, &ttystate);*/
}
+#if 0
+/* This all should now be in serial.c */
+
static void
connect_command (args, fromtty)
char *args;
}
}
}
+#endif /* 0 */
/* Define the target subroutine names */