* Copyright (c) 1990, 1991, 1992 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Lawrence Berkeley Laboratory,
* Berkeley, CA. The name of the University may not be used to
* endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) $Header: /usr/src/contrib/gdb-4.7.lbl/gdb/RCS/remote-sl.c,v 1.2 1993/06/03 03:01:03 mccanne Exp $ (LBL)";
#if BSD >= 199103 /* XXX ifdef on POSIX? */
#elif defined(HAVE_TERMIO)
#define FD_SET(n, fdp) ((fdp)->fds_bits[0] |= (1 << (n)))
#define FD_ISSET(n, fdp) ((fdp)->fds_bits[0] & (1 << (n)))
#define FD_ZERO(fdp) ((fdp)->fds_bits[0] = 0)
* Descriptor for I/O to remote machine.
* User-configurable baud rate of serial line.
* Configure the serial link.
(void)tcgetattr(fd
, &tios
);
/* Set 8 bit characters, enable receiver, non-dialup. */
tios
.c_cflag
= CS8
|CREAD
|CLOCAL
;
cfsetspeed(&tios
, speed
);
(void)tcsetattr(fd
, TCSANOW
, &tios
);
#elif defined(HAVE_TERMIO)
ioctl(fd
, TCGETA
, &tios
);
tios
.c_lflag
&= ~(ICANON
| ECHO
);
/* Set speed, 8 bit characters, enable receiver, non-dialup. */
tios
.c_cflag
= (speed
& CBAUD
)|CS8
|CREAD
|CLOCAL
;
ioctl(fd
, TCSETA
, &tios
);
ioctl(fd
, TIOCGETP
, &sg
);
sg
.sg_flags
= RAW
| ANYP
;
sg
.sg_ispeed
= sg
.sg_ospeed
= speed
;
ioctl(fd
, TIOCSETP
, &sg
);
* Open a serial line for remote debugging.
sl_open(name
, remote_fnp
)
struct remote_fn
*remote_fnp
;
(void)sprintf(device
, "/dev/%s", name
);
* Use non-blocking mode so we don't wait for a carrier.
* This allows the open to complete, then we set CLOCAL
* mode since we don't need the modem control lines.
sl_fd
= open(name
, O_RDWR
|O_NONBLOCK
);
speed
= getbaud(baud_rate
);
remote_fnp
->send
= sl_send
;
remote_fnp
->recv
= sl_recv
;
remote_fnp
->close
= sl_close
;
remote_fnp
->maxdata
= SL_MAXDATA
;
remote_fnp
->rpcsize
= SL_RPCSIZE
;
* Remote input buffering.
static u_char rib
[2 * SL_MTU
];
static u_char
*rib_cp
, *rib_ep
;
#define GETC(to) ((rib_cp < rib_ep) ? *rib_cp++ : rib_filbuf(to))
* Fill up the input buffer (with a non-blocking read).
* On error, return the negation of the error code, otherwise
* return the first character read and set things up so GETC will
* read the remaining chars.
struct timeval timeout
, *tp
;
timeout
.tv_sec
= to
/ 1000;
timeout
.tv_usec
= to
% 1000;
cc
= select(fd
+ 1, &fds
, (fd_set
*)0, (fd_set
*)0, tp
);
cc
= read(fd
, (caddr_t
)rib
, sizeof(rib
));
} else if (c == FRAME_ESCAPE) { \
c = TRANS_FRAME_ESCAPE; \
} else if (c == FRAME_START) { \
* Send a message to the remote host. An error code is returned.
* Build a packet. The framing byte comes first, then the command
* byte, the message, the checksum, and another framing character.
* We must escape any bytes that match the framing or escape chars.
for (ep
= bp
+ len
; bp
< ep
; ) {
if (write(sl_fd
, (caddr_t
)buf
, len
) != len
)
* Read a packet from the remote machine. An error code is returned.
sl_recv(tp
, ip
, lenp
, to
)
register u_char csum
, *bp
;
register int escape
, len
;
u_char buf
[SL_RPCSIZE
+ 1]; /* room for checksum at end of buffer */
* Allow immediate quit while reading from device, it could be hung.
* Throw away garbage characters until we see the start
* of a frame (i.e., don't let framing errors propagate up).
* If we don't do this, we can get pretty confused.
while ((c
= GETC(to
)) != FRAME_START
)
if (type
< 0 || --len
< 0) {
/* Store saved rpc reply type */
/* Store length of rpc reply packet */
bcopy((caddr_t
)buf
, (caddr_t
)ip
, len
);
if (++len
> sizeof(buf
)) {
} while (c
!= FRAME_END
);
case 1200: return (B1200
);
case 1800: return (B1800
);
case 2400: return (B2400
);
case 4800: return (B4800
);
case 9600: return (B9600
);
case 19200: return (EXTA
);
case 38400: return (EXTB
);
set_sl_baudrate_command(arg
, from_tty
)
error_no_arg("set remote-baudrate");
while (*arg
== ' ' || *arg
== '\t')
error_no_arg("set remote-baudrate");
if (*arg
< '0' || *arg
> '9')
error("non-numeric arg to \"set remote-baudrate\".");
error("unknown baudrate for \"set remote-baudrate\".");
* Don't use command line option anymore.
default: linespeed
= 0; break;
case B50
: linespeed
= 50; break;
case B75
: linespeed
= 75; break;
case B110
: linespeed
= 110; break;
case B134
: linespeed
= 134; break;
case B150
: linespeed
= 150; break;
case B200
: linespeed
= 200; break;
case B300
: linespeed
= 300; break;
case B600
: linespeed
= 600; break;
case B1200
: linespeed
= 1200; break;
case B1800
: linespeed
= 1800; break;
case B2400
: linespeed
= 2400; break;
case B4800
: linespeed
= 4800; break;
case B9600
: linespeed
= 9600; break;
case EXTA
: linespeed
= 19200; break;
case EXTB
: linespeed
= 38400; break;
printf("sl-baudrate %6d\n", linespeed
);
printf("bytes received %6d\n", sl_inbytes
);
printf("bytes sent %6d\n", sl_outbytes
);
printf("checksum errors %6d\n", sl_errs
);
extern struct cmd_list_element
*setlist
;
"Show current settings of serial line debugging options.");
add_cmd("sl-baudrate", class_support
, set_sl_baudrate_command
,
"Set remote debug serial line baudrate.", &setlist
);