+hardwire_print_tty_state (struct serial *scb,
+ serial_ttystate ttystate,
+ struct ui_file *stream)
+{
+ struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
+ int i;
+
+#ifdef HAVE_TERMIOS
+ fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
+ (int) state->termios.c_iflag,
+ (int) state->termios.c_oflag);
+ fprintf_filtered (stream, "c_cflag = 0x%x, c_lflag = 0x%x\n",
+ (int) state->termios.c_cflag,
+ (int) state->termios.c_lflag);
+#if 0
+ /* This not in POSIX, and is not really documented by those systems
+ which have it (at least not Sun). */
+ fprintf_filtered (stream, "c_line = 0x%x.\n", state->termios.c_line);
+#endif
+ fprintf_filtered (stream, "c_cc: ");
+ for (i = 0; i < NCCS; i += 1)
+ fprintf_filtered (stream, "0x%x ", state->termios.c_cc[i]);
+ fprintf_filtered (stream, "\n");
+#endif
+
+#ifdef HAVE_TERMIO
+ fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
+ state->termio.c_iflag, state->termio.c_oflag);
+ fprintf_filtered (stream, "c_cflag = 0x%x, c_lflag = 0x%x, c_line = 0x%x.\n",
+ state->termio.c_cflag, state->termio.c_lflag,
+ state->termio.c_line);
+ fprintf_filtered (stream, "c_cc: ");
+ for (i = 0; i < NCC; i += 1)
+ fprintf_filtered (stream, "0x%x ", state->termio.c_cc[i]);
+ fprintf_filtered (stream, "\n");
+#endif
+
+#ifdef HAVE_SGTTY
+ fprintf_filtered (stream, "sgttyb.sg_flags = 0x%x.\n",
+ state->sgttyb.sg_flags);
+
+ fprintf_filtered (stream, "tchars: ");
+ for (i = 0; i < (int) sizeof (struct tchars); i++)
+ fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->tc)[i]);
+ fprintf_filtered (stream, "\n");
+
+ fprintf_filtered (stream, "ltchars: ");
+ for (i = 0; i < (int) sizeof (struct ltchars); i++)
+ fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->ltc)[i]);
+ fprintf_filtered (stream, "\n");
+
+ fprintf_filtered (stream, "lmode: 0x%x\n", state->lmode);
+#endif
+}
+
+/* Wait for the output to drain away, as opposed to flushing
+ (discarding) it. */
+
+static int
+hardwire_drain_output (struct serial *scb)
+{
+#ifdef HAVE_TERMIOS
+ return tcdrain (scb->fd);
+#endif
+
+#ifdef HAVE_TERMIO
+ return ioctl (scb->fd, TCSBRK, 1);
+#endif
+
+#ifdef HAVE_SGTTY
+ /* Get the current state and then restore it using TIOCSETP,
+ which should cause the output to drain and pending input
+ to be discarded. */
+ {
+ struct hardwire_ttystate state;
+
+ if (get_tty_state (scb, &state))
+ {
+ return (-1);
+ }
+ else
+ {
+ return (ioctl (scb->fd, TIOCSETP, &state.sgttyb));
+ }
+ }
+#endif
+}
+
+static int
+hardwire_flush_output (struct serial *scb)
+{
+#ifdef HAVE_TERMIOS
+ return tcflush (scb->fd, TCOFLUSH);
+#endif
+
+#ifdef HAVE_TERMIO
+ return ioctl (scb->fd, TCFLSH, 1);
+#endif
+
+#ifdef HAVE_SGTTY
+ /* This flushes both input and output, but we can't do better. */
+ return ioctl (scb->fd, TIOCFLUSH, 0);
+#endif
+}
+
+static int
+hardwire_flush_input (struct serial *scb)
+{
+ ser_base_flush_input (scb);
+
+#ifdef HAVE_TERMIOS
+ return tcflush (scb->fd, TCIFLUSH);
+#endif
+
+#ifdef HAVE_TERMIO
+ return ioctl (scb->fd, TCFLSH, 0);
+#endif
+
+#ifdef HAVE_SGTTY
+ /* This flushes both input and output, but we can't do better. */
+ return ioctl (scb->fd, TIOCFLUSH, 0);
+#endif
+}
+
+static int
+hardwire_send_break (struct serial *scb)
+{
+#ifdef HAVE_TERMIOS
+ return tcsendbreak (scb->fd, 0);
+#endif
+
+#ifdef HAVE_TERMIO
+ return ioctl (scb->fd, TCSBRK, 0);
+#endif
+
+#ifdef HAVE_SGTTY
+ {
+ int status;
+
+ status = ioctl (scb->fd, TIOCSBRK, 0);
+
+ /* Can't use usleep; it doesn't exist in BSD 4.2. */
+ /* Note that if this gdb_select() is interrupted by a signal it will not
+ wait the full length of time. I think that is OK. */
+ gdb_usleep (250000);
+ status = ioctl (scb->fd, TIOCCBRK, 0);
+ return status;
+ }
+#endif
+}
+
+static void
+hardwire_raw (struct serial *scb)