1 /* Generic serial interface routines
2 Copyright 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Linked list of serial I/O handlers */
25 static struct serial_ops
*serial_ops_list
= NULL
;
27 /* This is the last serial stream opened. Used by connect command. */
29 static serial_t last_serial_opened
= NULL
;
31 static struct serial_ops
*
32 serial_interface_lookup (name
)
35 struct serial_ops
*ops
;
37 for (ops
= serial_ops_list
; ops
; ops
= ops
->next
)
38 if (strcmp (name
, ops
->name
) == 0)
45 serial_add_interface(optable
)
46 struct serial_ops
*optable
;
48 optable
->next
= serial_ops_list
;
49 serial_ops_list
= optable
;
52 /* Open up a device or a network socket, depending upon the syntax of NAME. */
59 struct serial_ops
*ops
;
61 if (strchr (name
, ':'))
62 ops
= serial_interface_lookup ("tcp");
64 ops
= serial_interface_lookup ("hardwire");
69 scb
= (serial_t
)xmalloc (sizeof (struct _serial_t
));
76 if (scb
->ops
->open(scb
, name
))
82 last_serial_opened
= scb
;
92 struct serial_ops
*ops
;
94 ops
= serial_interface_lookup ("hardwire");
99 scb
= (serial_t
)xmalloc (sizeof (struct _serial_t
));
104 scb
->bufp
= scb
->buf
;
108 last_serial_opened
= scb
;
117 last_serial_opened
= NULL
;
119 scb
->ops
->close(scb
);
126 /* Connect the user directly to the remote system. This command acts just like
127 the 'cu' or 'tip' command. Use <CR>~. or <CR>~^D to break out. */
129 static serial_t tty_desc
; /* Controlling terminal */
132 cleanup_tty(ttystate
)
133 serial_ttystate ttystate
;
135 printf ("\r\n[Exiting connect mode]\r\n");
136 SERIAL_SET_TTY_STATE (tty_desc
, ttystate
);
138 SERIAL_CLOSE (tty_desc
);
142 connect_command (args
, fromtty
)
148 serial_ttystate ttystate
;
149 serial_t port_desc
; /* TTY port */
154 fprintf(stderr
, "This command takes no args. They have been ignored.\n");
156 printf("[Entering connect mode. Use ~. or ~^D to escape]\n");
158 tty_desc
= SERIAL_FDOPEN (0);
159 port_desc
= last_serial_opened
;
161 ttystate
= SERIAL_GET_TTY_STATE (tty_desc
);
163 SERIAL_RAW (tty_desc
);
164 SERIAL_RAW (port_desc
);
166 make_cleanup (cleanup_tty
, ttystate
);
172 mask
= SERIAL_WAIT_2 (tty_desc
, port_desc
, -1);
180 c
= SERIAL_READCHAR(tty_desc
, 0);
182 if (c
== SERIAL_TIMEOUT
)
186 perror_with_name("connect");
189 SERIAL_WRITE(port_desc
, &cx
, 1);
204 if (c
== '.' || c
== '\004')
218 c
= SERIAL_READCHAR(port_desc
, 0);
220 if (c
== SERIAL_TIMEOUT
)
224 perror_with_name("connect");
228 SERIAL_WRITE(tty_desc
, &cx
, 1);
235 _initialize_serial ()
237 add_com ("connect", class_obscure
, connect_command
,
238 "Connect the terminal directly up to the command monitor.\n\
239 Use <CR>~. or <CR>~^D to break out.");