1 /* Remote serial interface for local (hardwired) serial ports for GO32.
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. */
24 /* This is unused for now. We just return a placeholder. */
41 static int go32_open PARAMS ((serial_t scb, const char *name));
42 static void go32_raw PARAMS ((serial_t scb));
43 static int wait_for PARAMS ((serial_t scb, int timeout));
44 static int go32_readchar PARAMS ((serial_t scb, int timeout));
45 static int rate_to_code PARAMS ((int rate));
46 static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
47 static int go32_write PARAMS ((serial_t scb, const char *str, int len));
48 static void go32_restore PARAMS ((serial_t scb));
49 static void go32_close PARAMS ((serial_t scb));
50 static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
51 static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
52 static int strncasecmp PARAMS ((const char *str1, const char *str2, int len));
53 static char *aptr PARAMS ((short p));
54 static ASYNC_STRUCT *getivec PARAMS ((int which));
55 static int dos_async_init PARAMS ((int port));
56 static void dos_async_tx PARAMS ((const char c));
57 static int dos_async_ready PARAMS (());
58 static int dos_async_rx PARAMS (());
59 static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
60 static int dosasync_write PARAMS ((int fd, const char *buf, int len));
62 #define SIGNATURE 0x4154
66 #define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
68 static ASYNC_STRUCT *async;
80 strncasecmp(str1, str2, len)
81 const char *str1, *str2;
86 for (; len != 0; --len)
91 if (toupper(c1) != toupper(c2))
92 return toupper(c1) - toupper(c2);
104 return (char *)((unsigned)async - OFFSET + p);
107 static ASYNC_STRUCT *
112 if (peek(0, which*4) != OFFSET)
115 a = (ASYNC_STRUCT *)(0xe0000000 + peek(0, which*4+2)*16 + peek(0, which*4));
117 if (a->signature != SIGNATURE)
120 if (a->version != VERSION)
135 async = getivec (12);
138 async = getivec (11);
146 error("GDB cannot connect to asynctsr program, check that it is installed\n\
147 and that serial I/O is not being redirected (perhaps by NFS)\n\n\
148 example configuration:\n\
149 C> mode com%d:9600,n,8,1,p\n\
151 C> gdb \n", port, port);
155 outportb(com_ier, 0x0f);
156 outportb(com_bfr, 0x03);
157 outportb(com_mcr, 0x0b);
158 async->getp = async->putp = async->buffer_start;
167 while (~inportb(com_lsr) & 0x20);
175 return (async->getp != async->putp);
183 while (!dos_async_ready())
190 rv = *aptr(async->getp++);
191 if (async->getp >= async->buffer_end)
192 async->getp = async->buffer_start;
198 dosasync_read (fd, buf, len, timeout)
208 then = now + timeout;
214 while (!dos_async_ready())
221 *buf++ = dos_async_rx();
228 dosasync_write(fd, buf, len)
236 dos_async_tx (*buf++);
242 go32_open (scb, name)
248 if (strncasecmp (name, "com", 3) != 0)
254 port = name[3] - '0';
256 if ((port != 1) && (port != 2))
262 scb->fd = dos_async_init(port);
270 go32_flush_output (scb)
273 /* No need to flush, because there is no buffering. */
281 /* Always in raw mode */
285 go32_readchar (scb, timeout)
291 if (dosasync_read(scb->fd, &buf, 1, timeout))
294 return SERIAL_TIMEOUT;
297 /* go32_{get set}_tty_state() are both dummys to fill out the function
298 vector. Someday, they may do something real... */
300 static serial_ttystate
301 go32_get_tty_state(scb)
304 struct go32_ttystate *state;
306 state = (struct go32_ttystate *)xmalloc(sizeof *state);
308 return (serial_ttystate)state;
312 go32_set_tty_state(scb, ttystate)
314 serial_ttystate ttystate;
316 struct go32_ttystate *state;
322 go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
324 serial_ttystate new_ttystate;
325 serial_ttystate old_ttystate;
331 go32_print_tty_state (scb, ttystate)
333 serial_ttystate ttystate;
335 /* Nothing to print. */
340 go32_setbaudrate (scb, rate)
348 go32_set_process_group (scb, ttystate, group)
350 serial_ttystate ttystate;
357 go32_write (scb, str, len)
362 dosasync_write(scb->fd, str, len);
373 static struct serial_ops go32_ops =
385 go32_print_tty_state,
386 go32_noflush_set_tty_state,
388 go32_set_process_group
391 /* There is never job control on go32. */
398 _initialize_ser_go32 ()
401 serial_add_interface (&go32_ops);