No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / gdb6 / gdb / ser-unix.c
blob7c10815a4e0f7d1ea73a9d8f918fde2820fcfddf
1 /* Serial interface for local (hardwired) serial ports on Un*x like systems
3 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
4 2003, 2004, 2005 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 #include "defs.h"
24 #include "serial.h"
25 #include "ser-base.h"
26 #include "ser-unix.h"
28 #include <fcntl.h>
29 #include <sys/types.h>
30 #include "terminal.h"
31 #include <sys/socket.h>
32 #include <sys/time.h>
34 #include "gdb_select.h"
35 #include "gdb_string.h"
37 #ifdef HAVE_TERMIOS
39 struct hardwire_ttystate
41 struct termios termios;
43 #endif /* termios */
45 #ifdef HAVE_TERMIO
47 /* It is believed that all systems which have added job control to SVR3
48 (e.g. sco) have also added termios. Even if not, trying to figure out
49 all the variations (TIOCGPGRP vs. TCGETPGRP, etc.) would be pretty
50 bewildering. So we don't attempt it. */
52 struct hardwire_ttystate
54 struct termio termio;
56 #endif /* termio */
58 #ifdef HAVE_SGTTY
59 struct hardwire_ttystate
61 struct sgttyb sgttyb;
62 struct tchars tc;
63 struct ltchars ltc;
64 /* Line discipline flags. */
65 int lmode;
67 #endif /* sgtty */
69 static int hardwire_open (struct serial *scb, const char *name);
70 static void hardwire_raw (struct serial *scb);
71 static int wait_for (struct serial *scb, int timeout);
72 static int hardwire_readchar (struct serial *scb, int timeout);
73 static int do_hardwire_readchar (struct serial *scb, int timeout);
74 static int rate_to_code (int rate);
75 static int hardwire_setbaudrate (struct serial *scb, int rate);
76 static void hardwire_close (struct serial *scb);
77 static int get_tty_state (struct serial *scb,
78 struct hardwire_ttystate * state);
79 static int set_tty_state (struct serial *scb,
80 struct hardwire_ttystate * state);
81 static serial_ttystate hardwire_get_tty_state (struct serial *scb);
82 static int hardwire_set_tty_state (struct serial *scb, serial_ttystate state);
83 static int hardwire_noflush_set_tty_state (struct serial *, serial_ttystate,
84 serial_ttystate);
85 static void hardwire_print_tty_state (struct serial *, serial_ttystate,
86 struct ui_file *);
87 static int hardwire_drain_output (struct serial *);
88 static int hardwire_flush_output (struct serial *);
89 static int hardwire_flush_input (struct serial *);
90 static int hardwire_send_break (struct serial *);
91 static int hardwire_setstopbits (struct serial *, int);
93 void _initialize_ser_hardwire (void);
95 /* Open up a real live device for serial I/O */
97 static int
98 hardwire_open (struct serial *scb, const char *name)
100 scb->fd = open (name, O_RDWR);
101 if (scb->fd < 0)
102 return -1;
104 return 0;
107 static int
108 get_tty_state (struct serial *scb, struct hardwire_ttystate *state)
110 #ifdef HAVE_TERMIOS
111 if (tcgetattr (scb->fd, &state->termios) < 0)
112 return -1;
114 return 0;
115 #endif
117 #ifdef HAVE_TERMIO
118 if (ioctl (scb->fd, TCGETA, &state->termio) < 0)
119 return -1;
120 return 0;
121 #endif
123 #ifdef HAVE_SGTTY
124 if (ioctl (scb->fd, TIOCGETP, &state->sgttyb) < 0)
125 return -1;
126 if (ioctl (scb->fd, TIOCGETC, &state->tc) < 0)
127 return -1;
128 if (ioctl (scb->fd, TIOCGLTC, &state->ltc) < 0)
129 return -1;
130 if (ioctl (scb->fd, TIOCLGET, &state->lmode) < 0)
131 return -1;
133 return 0;
134 #endif
137 static int
138 set_tty_state (struct serial *scb, struct hardwire_ttystate *state)
140 #ifdef HAVE_TERMIOS
141 if (tcsetattr (scb->fd, TCSANOW, &state->termios) < 0)
142 return -1;
144 return 0;
145 #endif
147 #ifdef HAVE_TERMIO
148 if (ioctl (scb->fd, TCSETA, &state->termio) < 0)
149 return -1;
150 return 0;
151 #endif
153 #ifdef HAVE_SGTTY
154 if (ioctl (scb->fd, TIOCSETN, &state->sgttyb) < 0)
155 return -1;
156 if (ioctl (scb->fd, TIOCSETC, &state->tc) < 0)
157 return -1;
158 if (ioctl (scb->fd, TIOCSLTC, &state->ltc) < 0)
159 return -1;
160 if (ioctl (scb->fd, TIOCLSET, &state->lmode) < 0)
161 return -1;
163 return 0;
164 #endif
167 static serial_ttystate
168 hardwire_get_tty_state (struct serial *scb)
170 struct hardwire_ttystate *state;
172 state = (struct hardwire_ttystate *) xmalloc (sizeof *state);
174 if (get_tty_state (scb, state))
175 return NULL;
177 return (serial_ttystate) state;
180 static int
181 hardwire_set_tty_state (struct serial *scb, serial_ttystate ttystate)
183 struct hardwire_ttystate *state;
185 state = (struct hardwire_ttystate *) ttystate;
187 return set_tty_state (scb, state);
190 static int
191 hardwire_noflush_set_tty_state (struct serial *scb,
192 serial_ttystate new_ttystate,
193 serial_ttystate old_ttystate)
195 struct hardwire_ttystate new_state;
196 #ifdef HAVE_SGTTY
197 struct hardwire_ttystate *state = (struct hardwire_ttystate *) old_ttystate;
198 #endif
200 new_state = *(struct hardwire_ttystate *) new_ttystate;
202 /* Don't change in or out of raw mode; we don't want to flush input.
203 termio and termios have no such restriction; for them flushing input
204 is separate from setting the attributes. */
206 #ifdef HAVE_SGTTY
207 if (state->sgttyb.sg_flags & RAW)
208 new_state.sgttyb.sg_flags |= RAW;
209 else
210 new_state.sgttyb.sg_flags &= ~RAW;
212 /* I'm not sure whether this is necessary; the manpage just mentions
213 RAW not CBREAK. */
214 if (state->sgttyb.sg_flags & CBREAK)
215 new_state.sgttyb.sg_flags |= CBREAK;
216 else
217 new_state.sgttyb.sg_flags &= ~CBREAK;
218 #endif
220 return set_tty_state (scb, &new_state);
223 static void
224 hardwire_print_tty_state (struct serial *scb,
225 serial_ttystate ttystate,
226 struct ui_file *stream)
228 struct hardwire_ttystate *state = (struct hardwire_ttystate *) ttystate;
229 int i;
231 #ifdef HAVE_TERMIOS
232 fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
233 (int) state->termios.c_iflag,
234 (int) state->termios.c_oflag);
235 fprintf_filtered (stream, "c_cflag = 0x%x, c_lflag = 0x%x\n",
236 (int) state->termios.c_cflag,
237 (int) state->termios.c_lflag);
238 #if 0
239 /* This not in POSIX, and is not really documented by those systems
240 which have it (at least not Sun). */
241 fprintf_filtered (stream, "c_line = 0x%x.\n", state->termios.c_line);
242 #endif
243 fprintf_filtered (stream, "c_cc: ");
244 for (i = 0; i < NCCS; i += 1)
245 fprintf_filtered (stream, "0x%x ", state->termios.c_cc[i]);
246 fprintf_filtered (stream, "\n");
247 #endif
249 #ifdef HAVE_TERMIO
250 fprintf_filtered (stream, "c_iflag = 0x%x, c_oflag = 0x%x,\n",
251 state->termio.c_iflag, state->termio.c_oflag);
252 fprintf_filtered (stream, "c_cflag = 0x%x, c_lflag = 0x%x, c_line = 0x%x.\n",
253 state->termio.c_cflag, state->termio.c_lflag,
254 state->termio.c_line);
255 fprintf_filtered (stream, "c_cc: ");
256 for (i = 0; i < NCC; i += 1)
257 fprintf_filtered (stream, "0x%x ", state->termio.c_cc[i]);
258 fprintf_filtered (stream, "\n");
259 #endif
261 #ifdef HAVE_SGTTY
262 fprintf_filtered (stream, "sgttyb.sg_flags = 0x%x.\n",
263 state->sgttyb.sg_flags);
265 fprintf_filtered (stream, "tchars: ");
266 for (i = 0; i < (int) sizeof (struct tchars); i++)
267 fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->tc)[i]);
268 fprintf_filtered (stream, "\n");
270 fprintf_filtered (stream, "ltchars: ");
271 for (i = 0; i < (int) sizeof (struct ltchars); i++)
272 fprintf_filtered (stream, "0x%x ", ((unsigned char *) &state->ltc)[i]);
273 fprintf_filtered (stream, "\n");
275 fprintf_filtered (stream, "lmode: 0x%x\n", state->lmode);
276 #endif
279 /* Wait for the output to drain away, as opposed to flushing (discarding) it */
281 static int
282 hardwire_drain_output (struct serial *scb)
284 #ifdef HAVE_TERMIOS
285 return tcdrain (scb->fd);
286 #endif
288 #ifdef HAVE_TERMIO
289 return ioctl (scb->fd, TCSBRK, 1);
290 #endif
292 #ifdef HAVE_SGTTY
293 /* Get the current state and then restore it using TIOCSETP,
294 which should cause the output to drain and pending input
295 to be discarded. */
297 struct hardwire_ttystate state;
298 if (get_tty_state (scb, &state))
300 return (-1);
302 else
304 return (ioctl (scb->fd, TIOCSETP, &state.sgttyb));
307 #endif
310 static int
311 hardwire_flush_output (struct serial *scb)
313 #ifdef HAVE_TERMIOS
314 return tcflush (scb->fd, TCOFLUSH);
315 #endif
317 #ifdef HAVE_TERMIO
318 return ioctl (scb->fd, TCFLSH, 1);
319 #endif
321 #ifdef HAVE_SGTTY
322 /* This flushes both input and output, but we can't do better. */
323 return ioctl (scb->fd, TIOCFLUSH, 0);
324 #endif
327 static int
328 hardwire_flush_input (struct serial *scb)
330 ser_base_flush_input (scb);
332 #ifdef HAVE_TERMIOS
333 return tcflush (scb->fd, TCIFLUSH);
334 #endif
336 #ifdef HAVE_TERMIO
337 return ioctl (scb->fd, TCFLSH, 0);
338 #endif
340 #ifdef HAVE_SGTTY
341 /* This flushes both input and output, but we can't do better. */
342 return ioctl (scb->fd, TIOCFLUSH, 0);
343 #endif
346 static int
347 hardwire_send_break (struct serial *scb)
349 #ifdef HAVE_TERMIOS
350 return tcsendbreak (scb->fd, 0);
351 #endif
353 #ifdef HAVE_TERMIO
354 return ioctl (scb->fd, TCSBRK, 0);
355 #endif
357 #ifdef HAVE_SGTTY
359 int status;
360 struct timeval timeout;
362 status = ioctl (scb->fd, TIOCSBRK, 0);
364 /* Can't use usleep; it doesn't exist in BSD 4.2. */
365 /* Note that if this select() is interrupted by a signal it will not wait
366 the full length of time. I think that is OK. */
367 timeout.tv_sec = 0;
368 timeout.tv_usec = 250000;
369 gdb_select (0, 0, 0, 0, &timeout);
370 status = ioctl (scb->fd, TIOCCBRK, 0);
371 return status;
373 #endif
376 static void
377 hardwire_raw (struct serial *scb)
379 struct hardwire_ttystate state;
381 if (get_tty_state (scb, &state))
382 fprintf_unfiltered (gdb_stderr, "get_tty_state failed: %s\n", safe_strerror (errno));
384 #ifdef HAVE_TERMIOS
385 state.termios.c_iflag = 0;
386 state.termios.c_oflag = 0;
387 state.termios.c_lflag = 0;
388 state.termios.c_cflag &= ~(CSIZE | PARENB);
389 state.termios.c_cflag |= CLOCAL | CS8;
390 state.termios.c_cc[VMIN] = 0;
391 state.termios.c_cc[VTIME] = 0;
392 #endif
394 #ifdef HAVE_TERMIO
395 state.termio.c_iflag = 0;
396 state.termio.c_oflag = 0;
397 state.termio.c_lflag = 0;
398 state.termio.c_cflag &= ~(CSIZE | PARENB);
399 state.termio.c_cflag |= CLOCAL | CS8;
400 state.termio.c_cc[VMIN] = 0;
401 state.termio.c_cc[VTIME] = 0;
402 #endif
404 #ifdef HAVE_SGTTY
405 state.sgttyb.sg_flags |= RAW | ANYP;
406 state.sgttyb.sg_flags &= ~(CBREAK | ECHO);
407 #endif
409 scb->current_timeout = 0;
411 if (set_tty_state (scb, &state))
412 fprintf_unfiltered (gdb_stderr, "set_tty_state failed: %s\n", safe_strerror (errno));
415 /* Wait for input on scb, with timeout seconds. Returns 0 on success,
416 otherwise SERIAL_TIMEOUT or SERIAL_ERROR.
418 For termio{s}, we actually just setup VTIME if necessary, and let the
419 timeout occur in the read() in hardwire_read().
422 /* FIXME: cagney/1999-09-16: Don't replace this with the equivalent
423 ser_base*() until the old TERMIOS/SGTTY/... timer code has been
424 flushed. . */
426 /* NOTE: cagney/1999-09-30: Much of the code below is dead. The only
427 possible values of the TIMEOUT parameter are ONE and ZERO.
428 Consequently all the code that tries to handle the possability of
429 an overflowed timer is unnecessary. */
431 static int
432 wait_for (struct serial *scb, int timeout)
434 #ifdef HAVE_SGTTY
435 while (1)
437 struct timeval tv;
438 fd_set readfds;
439 int numfds;
441 /* NOTE: Some OS's can scramble the READFDS when the select()
442 call fails (ex the kernel with Red Hat 5.2). Initialize all
443 arguments before each call. */
445 tv.tv_sec = timeout;
446 tv.tv_usec = 0;
448 FD_ZERO (&readfds);
449 FD_SET (scb->fd, &readfds);
451 if (timeout >= 0)
452 numfds = gdb_select (scb->fd + 1, &readfds, 0, 0, &tv);
453 else
454 numfds = gdb_select (scb->fd + 1, &readfds, 0, 0, 0);
456 if (numfds <= 0)
457 if (numfds == 0)
458 return SERIAL_TIMEOUT;
459 else if (errno == EINTR)
460 continue;
461 else
462 return SERIAL_ERROR; /* Got an error from select or poll */
464 return 0;
466 #endif /* HAVE_SGTTY */
468 #if defined HAVE_TERMIO || defined HAVE_TERMIOS
469 if (timeout == scb->current_timeout)
470 return 0;
472 scb->current_timeout = timeout;
475 struct hardwire_ttystate state;
477 if (get_tty_state (scb, &state))
478 fprintf_unfiltered (gdb_stderr, "get_tty_state failed: %s\n", safe_strerror (errno));
480 #ifdef HAVE_TERMIOS
481 if (timeout < 0)
483 /* No timeout. */
484 state.termios.c_cc[VTIME] = 0;
485 state.termios.c_cc[VMIN] = 1;
487 else
489 state.termios.c_cc[VMIN] = 0;
490 state.termios.c_cc[VTIME] = timeout * 10;
491 if (state.termios.c_cc[VTIME] != timeout * 10)
494 /* If c_cc is an 8-bit signed character, we can't go
495 bigger than this. If it is always unsigned, we could use
496 25. */
498 scb->current_timeout = 12;
499 state.termios.c_cc[VTIME] = scb->current_timeout * 10;
500 scb->timeout_remaining = timeout - scb->current_timeout;
503 #endif
505 #ifdef HAVE_TERMIO
506 if (timeout < 0)
508 /* No timeout. */
509 state.termio.c_cc[VTIME] = 0;
510 state.termio.c_cc[VMIN] = 1;
512 else
514 state.termio.c_cc[VMIN] = 0;
515 state.termio.c_cc[VTIME] = timeout * 10;
516 if (state.termio.c_cc[VTIME] != timeout * 10)
518 /* If c_cc is an 8-bit signed character, we can't go
519 bigger than this. If it is always unsigned, we could use
520 25. */
522 scb->current_timeout = 12;
523 state.termio.c_cc[VTIME] = scb->current_timeout * 10;
524 scb->timeout_remaining = timeout - scb->current_timeout;
527 #endif
529 if (set_tty_state (scb, &state))
530 fprintf_unfiltered (gdb_stderr, "set_tty_state failed: %s\n", safe_strerror (errno));
532 return 0;
534 #endif /* HAVE_TERMIO || HAVE_TERMIOS */
537 /* Read a character with user-specified timeout. TIMEOUT is number of seconds
538 to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns
539 char if successful. Returns SERIAL_TIMEOUT if timeout expired, EOF if line
540 dropped dead, or SERIAL_ERROR for any other error (see errno in that case). */
542 /* FIXME: cagney/1999-09-16: Don't replace this with the equivalent
543 ser_base*() until the old TERMIOS/SGTTY/... timer code has been
544 flushed. */
546 /* NOTE: cagney/1999-09-16: This function is not identical to
547 ser_base_readchar() as part of replacing it with ser_base*()
548 merging will be required - this code handles the case where read()
549 times out due to no data while ser_base_readchar() doesn't expect
550 that. */
552 static int
553 do_hardwire_readchar (struct serial *scb, int timeout)
555 int status, delta;
556 int detach = 0;
558 if (timeout > 0)
559 timeout++;
561 /* We have to be able to keep the GUI alive here, so we break the
562 original timeout into steps of 1 second, running the "keep the
563 GUI alive" hook each time through the loop.
565 Also, timeout = 0 means to poll, so we just set the delta to 0,
566 so we will only go through the loop once. */
568 delta = (timeout == 0 ? 0 : 1);
569 while (1)
572 /* N.B. The UI may destroy our world (for instance by calling
573 remote_stop,) in which case we want to get out of here as
574 quickly as possible. It is not safe to touch scb, since
575 someone else might have freed it. The
576 deprecated_ui_loop_hook signals that we should exit by
577 returning 1. */
579 if (deprecated_ui_loop_hook)
580 detach = deprecated_ui_loop_hook (0);
582 if (detach)
583 return SERIAL_TIMEOUT;
585 scb->timeout_remaining = (timeout < 0 ? timeout : timeout - delta);
586 status = wait_for (scb, delta);
588 if (status < 0)
589 return status;
591 status = read (scb->fd, scb->buf, BUFSIZ);
593 if (status <= 0)
595 if (status == 0)
597 /* Zero characters means timeout (it could also be EOF, but
598 we don't (yet at least) distinguish). */
599 if (scb->timeout_remaining > 0)
601 timeout = scb->timeout_remaining;
602 continue;
604 else if (scb->timeout_remaining < 0)
605 continue;
606 else
607 return SERIAL_TIMEOUT;
609 else if (errno == EINTR)
610 continue;
611 else
612 return SERIAL_ERROR; /* Got an error from read */
615 scb->bufcnt = status;
616 scb->bufcnt--;
617 scb->bufp = scb->buf;
618 return *scb->bufp++;
622 static int
623 hardwire_readchar (struct serial *scb, int timeout)
625 return generic_readchar (scb, timeout, do_hardwire_readchar);
629 #ifndef B19200
630 #define B19200 EXTA
631 #endif
633 #ifndef B38400
634 #define B38400 EXTB
635 #endif
637 /* Translate baud rates from integers to damn B_codes. Unix should
638 have outgrown this crap years ago, but even POSIX wouldn't buck it. */
640 static struct
642 int rate;
643 int code;
645 baudtab[] =
648 50, B50
652 75, B75
656 110, B110
660 134, B134
664 150, B150
668 200, B200
672 300, B300
676 600, B600
680 1200, B1200
684 1800, B1800
688 2400, B2400
692 4800, B4800
696 9600, B9600
700 19200, B19200
704 38400, B38400
707 #ifdef B57600
709 57600, B57600
712 #endif
713 #ifdef B115200
715 115200, B115200
718 #endif
719 #ifdef B230400
721 230400, B230400
724 #endif
725 #ifdef B460800
727 460800, B460800
730 #endif
732 -1, -1
737 static int
738 rate_to_code (int rate)
740 int i;
742 for (i = 0; baudtab[i].rate != -1; i++)
744 /* test for perfect macth. */
745 if (rate == baudtab[i].rate)
746 return baudtab[i].code;
747 else
749 /* check if it is in between valid values. */
750 if (rate < baudtab[i].rate)
752 if (i)
754 warning (_("Invalid baud rate %d. Closest values are %d and %d."),
755 rate, baudtab[i - 1].rate, baudtab[i].rate);
757 else
759 warning (_("Invalid baud rate %d. Minimum value is %d."),
760 rate, baudtab[0].rate);
762 return -1;
767 /* The requested speed was too large. */
768 warning (_("Invalid baud rate %d. Maximum value is %d."),
769 rate, baudtab[i - 1].rate);
770 return -1;
773 static int
774 hardwire_setbaudrate (struct serial *scb, int rate)
776 struct hardwire_ttystate state;
777 int baud_code = rate_to_code (rate);
779 if (baud_code < 0)
781 /* The baud rate was not valid.
782 A warning has already been issued. */
783 errno = EINVAL;
784 return -1;
787 if (get_tty_state (scb, &state))
788 return -1;
790 #ifdef HAVE_TERMIOS
791 cfsetospeed (&state.termios, baud_code);
792 cfsetispeed (&state.termios, baud_code);
793 #endif
795 #ifdef HAVE_TERMIO
796 #ifndef CIBAUD
797 #define CIBAUD CBAUD
798 #endif
800 state.termio.c_cflag &= ~(CBAUD | CIBAUD);
801 state.termio.c_cflag |= baud_code;
802 #endif
804 #ifdef HAVE_SGTTY
805 state.sgttyb.sg_ispeed = baud_code;
806 state.sgttyb.sg_ospeed = baud_code;
807 #endif
809 return set_tty_state (scb, &state);
812 static int
813 hardwire_setstopbits (struct serial *scb, int num)
815 struct hardwire_ttystate state;
816 int newbit;
818 if (get_tty_state (scb, &state))
819 return -1;
821 switch (num)
823 case SERIAL_1_STOPBITS:
824 newbit = 0;
825 break;
826 case SERIAL_1_AND_A_HALF_STOPBITS:
827 case SERIAL_2_STOPBITS:
828 newbit = 1;
829 break;
830 default:
831 return 1;
834 #ifdef HAVE_TERMIOS
835 if (!newbit)
836 state.termios.c_cflag &= ~CSTOPB;
837 else
838 state.termios.c_cflag |= CSTOPB; /* two bits */
839 #endif
841 #ifdef HAVE_TERMIO
842 if (!newbit)
843 state.termio.c_cflag &= ~CSTOPB;
844 else
845 state.termio.c_cflag |= CSTOPB; /* two bits */
846 #endif
848 #ifdef HAVE_SGTTY
849 return 0; /* sgtty doesn't support this */
850 #endif
852 return set_tty_state (scb, &state);
855 static void
856 hardwire_close (struct serial *scb)
858 if (scb->fd < 0)
859 return;
861 close (scb->fd);
862 scb->fd = -1;
866 void
867 _initialize_ser_hardwire (void)
869 struct serial_ops *ops = XMALLOC (struct serial_ops);
870 memset (ops, 0, sizeof (struct serial_ops));
871 ops->name = "hardwire";
872 ops->next = 0;
873 ops->open = hardwire_open;
874 ops->close = hardwire_close;
875 /* FIXME: Don't replace this with the equivalent ser_base*() until
876 the old TERMIOS/SGTTY/... timer code has been flushed. cagney
877 1999-09-16. */
878 ops->readchar = hardwire_readchar;
879 ops->write = ser_base_write;
880 ops->flush_output = hardwire_flush_output;
881 ops->flush_input = hardwire_flush_input;
882 ops->send_break = hardwire_send_break;
883 ops->go_raw = hardwire_raw;
884 ops->get_tty_state = hardwire_get_tty_state;
885 ops->set_tty_state = hardwire_set_tty_state;
886 ops->print_tty_state = hardwire_print_tty_state;
887 ops->noflush_set_tty_state = hardwire_noflush_set_tty_state;
888 ops->setbaudrate = hardwire_setbaudrate;
889 ops->setstopbits = hardwire_setstopbits;
890 ops->drain_output = hardwire_drain_output;
891 ops->async = ser_base_async;
892 ops->read_prim = ser_unix_read_prim;
893 ops->write_prim = ser_unix_write_prim;
894 serial_add_interface (ops);
898 ser_unix_read_prim (struct serial *scb, size_t count)
900 int status;
902 while (1)
904 status = read (scb->fd, scb->buf, count);
905 if (status != -1 || errno != EINTR)
906 break;
908 return status;
912 ser_unix_write_prim (struct serial *scb, const void *buf, size_t len)
914 /* ??? Historically, GDB has not retried calls to "write" that
915 result in EINTR. */
916 return write (scb->fd, buf, len);