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. */
30 static int go32_open PARAMS ((serial_t scb, const char *name));
31 static void go32_raw PARAMS ((serial_t scb));
32 static int wait_for PARAMS ((serial_t scb, int timeout));
33 static int go32_readchar PARAMS ((serial_t scb, int timeout));
34 static int rate_to_code PARAMS ((int rate));
35 static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
36 static int go32_write PARAMS ((serial_t scb, const char *str, int len));
37 static void go32_restore PARAMS ((serial_t scb));
38 static void go32_close PARAMS ((serial_t scb));
39 serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
40 static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
41 static int strncasecmp PARAMS ((char *str1, char *str2, int len));
42 static char *aptr PARAMS ((short p));
43 static ASYNC_STRUCT *getivec PARAMS ((int which));
44 static int dos_async_init PARAMS ((int port));
45 static void dos_async_tx PARAMS ((const char c));
46 static int dos_async_ready PARAMS (());
47 static int dos_async_rx PARAMS (());
48 static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
49 static int dosasync_write PARAMS ((int fd, const char *buf, int len, int timeout));
51 #define SIGNATURE 0x4154
55 #define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
68 static ASYNC_STRUCT *async;
80 strncasecmp(str1, str2, len)
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 can not 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 com2:9600,n,8,1,p\n\
156 outportb(com_ier, 0x0f);
157 outportb(com_bfr, 0x03);
158 outportb(com_mcr, 0x0b);
159 async->getp = async->putp = async->buffer_start;
168 while (~inportb(com_lsr) & 0x20);
176 return (async->getp != async->putp);
184 while (!dos_async_ready())
191 rv = *aptr(async->getp++);
192 if (async->getp >= async->buffer_end)
193 async->getp = async->buffer_start;
199 dosasync_read (fd, buf, len, timeout)
209 then = now + timeout;
215 while (!dos_async_ready())
222 *buf++ = dos_async_rx();
229 dosasync_write(fd, buf, len)
237 dos_async_tx (*buf++);
243 go32_open (scb, name)
249 if (strncasecmp (name, "com", 3) != 0)
255 port = name[3] - '0';
257 if ((port != 1) && (port != 2))
263 scb->fd = dos_async_init(port);
274 /* Always in raw mode */
278 go32_readchar (scb, timeout)
284 if (dosasync_read(scb->fd, &buf, 1, timeout))
287 return SERIAL_TIMEOUT;
290 /* go32_{get set}_tty_state() are both dummys to fill out the function
291 vector. Someday, they may do something real... */
293 static serial_ttystate
294 go32_get_tty_state(scb)
297 struct go32_ttystate *state;
299 state = (struct go32_ttystate *)xmalloc(sizeof *state);
301 return (serial_ttystate)state;
305 go32_set_tty_state(scb, ttystate)
307 serial_ttystate ttystate;
309 struct go32_ttystate *state;
315 go32_setbaudrate (scb, rate)
323 go32_write (scb, str, len)
328 dosasync_write(scb->fd, str, len);
338 static struct serial_ops go32_ops =
352 _initialize_ser_go32 ()
354 serial_add_interface (&go32_ops);