* ser-go32.c: Lint. (strncasecmp): Removed, now in libiberty.
[deliverable/binutils-gdb.git] / gdb / ser-go32.c
CommitLineData
5d2b030a
SG
1/* Remote serial interface for local (hardwired) serial ports for GO32.
2 Copyright 1992, 1993 Free Software Foundation, Inc.
ae0ea72e 3
08c0d7b8 4 This file is part of GDB.
ae0ea72e 5
08c0d7b8
SC
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.
ae0ea72e 10
08c0d7b8
SC
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.
ae0ea72e 15
08c0d7b8
SC
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. */
ae0ea72e 19
ae0ea72e
SC
20#include "defs.h"
21#include "serial.h"
5140562f 22#include <sys/dos.h>
ae0ea72e 23
38dc5e12
SG
24/* This is unused for now. We just return a placeholder. */
25struct go32_ttystate
08c0d7b8
SC
26 {
27 int bogus;
28 };
29
30typedef struct
31 {
32 short jmp_op;
33 short signature;
34 short version;
35 short buffer_start;
36 short buffer_end;
37 short getp;
38 short putp;
39 short iov;
40 }
41ASYNC_STRUCT;
452b4b00 42
38dc5e12
SG
43static int go32_open PARAMS ((serial_t scb, const char *name));
44static void go32_raw PARAMS ((serial_t scb));
38dc5e12 45static int go32_readchar PARAMS ((serial_t scb, int timeout));
38dc5e12
SG
46static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
47static int go32_write PARAMS ((serial_t scb, const char *str, int len));
38dc5e12 48static void go32_close PARAMS ((serial_t scb));
452b4b00 49static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
38dc5e12 50static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
38dc5e12
SG
51static char *aptr PARAMS ((short p));
52static ASYNC_STRUCT *getivec PARAMS ((int which));
53static int dos_async_init PARAMS ((int port));
54static void dos_async_tx PARAMS ((const char c));
38dc5e12
SG
55static int dos_async_rx PARAMS (());
56static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
452b4b00 57static int dosasync_write PARAMS ((int fd, const char *buf, int len));
38dc5e12 58
ae0ea72e
SC
59#define SIGNATURE 0x4154
60#define VERSION 1
61#define OFFSET 0x104
62
ae0ea72e 63#define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
ae0ea72e 64
08c0d7b8 65static volatile ASYNC_STRUCT *async;
ae0ea72e
SC
66static int iov;
67#define com_rb iov
68#define com_tb iov
69#define com_ier iov+1
70#define com_ifr iov+2
71#define com_bfr iov+3
72#define com_mcr iov+4
73#define com_lsr iov+5
74#define com_msr iov+6
75
5d2b030a 76static char *
08c0d7b8 77aptr (p)
5d2b030a 78 short p;
ae0ea72e 79{
08c0d7b8 80 return (char *) ((unsigned) async - OFFSET + p);
ae0ea72e
SC
81}
82
5d2b030a 83static ASYNC_STRUCT *
08c0d7b8 84getivec (int which)
ae0ea72e 85{
5d2b030a 86 ASYNC_STRUCT *a;
ae0ea72e 87
08c0d7b8 88 if (peek (0, which * 4) != OFFSET)
ae0ea72e 89 return 0;
b83bf6b3 90
08c0d7b8 91 a = (ASYNC_STRUCT *) (0xe0000000 + peek (0, which * 4 + 2) * 16 + peek (0, which * 4));
ae0ea72e 92
ae0ea72e
SC
93 if (a->signature != SIGNATURE)
94 return 0;
b83bf6b3 95
ae0ea72e
SC
96 if (a->version != VERSION)
97 return 0;
b83bf6b3 98
ae0ea72e
SC
99 return a;
100}
101
5d2b030a 102static int
08c0d7b8 103dos_async_init (port)
b83bf6b3 104 int port;
ae0ea72e 105{
b83bf6b3 106 switch (port)
07861607 107 {
b83bf6b3
SG
108 case 1:
109 async = getivec (12);
110 break;
111 case 2:
112 async = getivec (11);
113 break;
114 default:
115 return 0;
07861607
SG
116 }
117
b83bf6b3 118 if (!async)
07861607 119 {
08c0d7b8 120 error ("GDB cannot connect to asynctsr program, check that it is installed\n\
ae0ea72e
SC
121and that serial I/O is not being redirected (perhaps by NFS)\n\n\
122example configuration:\n\
a037b21e
SG
123C> mode com%d:9600,n,8,1,p\n\
124C> asynctsr %d\n\
125C> gdb \n", port, port);
07861607
SG
126 }
127
ae0ea72e 128 iov = async->iov;
08c0d7b8
SC
129 outportb (com_ier, 0x0f);
130 outportb (com_bfr, 0x03);
131 outportb (com_mcr, 0x0b);
ae0ea72e 132 async->getp = async->putp = async->buffer_start;
08c0d7b8 133
b83bf6b3 134 return 1;
ae0ea72e
SC
135}
136
5d2b030a 137static void
08c0d7b8 138dos_async_tx (c)
5d2b030a 139 const char c;
ae0ea72e 140{
08c0d7b8
SC
141 while (~inportb (com_lsr) & 0x20)
142 ;
143 outportb (com_tb, c);
ae0ea72e
SC
144}
145
08c0d7b8 146#define dos_async_ready() (async->getp != async->putp)
ae0ea72e 147
5d2b030a 148static int
08c0d7b8 149dos_async_rx ()
ae0ea72e
SC
150{
151 char rv;
5d2b030a 152
08c0d7b8
SC
153 while (!dos_async_ready ())
154 {
155 if (kbhit ())
156 {
157 printf_unfiltered ("abort!\n");
158 return 0;
159 }
160 }
5d2b030a 161
08c0d7b8 162 rv = *aptr (async->getp++);
ae0ea72e 163 if (async->getp >= async->buffer_end)
5d2b030a 164 async->getp = async->buffer_start;
ae0ea72e 165
5d2b030a 166 return rv;
ae0ea72e
SC
167}
168
5d2b030a
SG
169static int
170dosasync_read (fd, buf, len, timeout)
171 int fd;
172 char *buf;
173 int len;
174 int timeout;
ae0ea72e
SC
175{
176 long now, then;
08c0d7b8 177 int i;
5d2b030a 178
ae0ea72e 179 time (&now);
5d2b030a
SG
180 then = now + timeout;
181
08c0d7b8 182 for (i = 0; i < len; i++)
ae0ea72e 183 {
5d2b030a
SG
184 if (timeout)
185 {
08c0d7b8 186 while (!dos_async_ready ())
5d2b030a
SG
187 {
188 time (&now);
189 if (now >= then)
08c0d7b8 190 return i;
5d2b030a
SG
191 }
192 }
08c0d7b8 193 *buf++ = dos_async_rx ();
ae0ea72e 194 }
5d2b030a 195 return len;
ae0ea72e
SC
196}
197
5d2b030a 198static int
08c0d7b8 199dosasync_write (fd, buf, len)
5d2b030a
SG
200 int fd;
201 const char *buf;
202 int len;
203{
08c0d7b8 204 int l;
ae0ea72e 205
08c0d7b8 206 for (l = 0; l < len; l++)
5d2b030a 207 dos_async_tx (*buf++);
ae0ea72e 208
5d2b030a 209 return len;
ae0ea72e
SC
210}
211
5d2b030a
SG
212static int
213go32_open (scb, name)
214 serial_t scb;
215 const char *name;
b52373a2 216{
b83bf6b3
SG
217 int port;
218
219 if (strncasecmp (name, "com", 3) != 0)
220 {
221 errno = ENOENT;
4febd102 222 return -1;
b83bf6b3
SG
223 }
224
225 port = name[3] - '0';
226
227 if ((port != 1) && (port != 2))
228 {
229 errno = ENOENT;
4febd102 230 return -11;
b83bf6b3
SG
231 }
232
08c0d7b8 233 scb->fd = dos_async_init (port);
07861607 234 if (!scb->fd)
4febd102 235 return -1;
ae0ea72e 236
5d2b030a 237 return 0;
ae0ea72e
SC
238}
239
c2e247c4 240static int
704deef2 241go32_noop (scb)
c2e247c4
JK
242 serial_t scb;
243{
c2e247c4
JK
244 return 0;
245}
246
5d2b030a
SG
247static void
248go32_raw (scb)
249 serial_t scb;
ae0ea72e 250{
5d2b030a 251 /* Always in raw mode */
ae0ea72e
SC
252}
253
5d2b030a
SG
254static int
255go32_readchar (scb, timeout)
256 serial_t scb;
257 int timeout;
ae0ea72e
SC
258{
259 char buf;
5d2b030a 260
08c0d7b8
SC
261 /* Shortcut for polling */
262 if (timeout == 0)
263 {
264 if (dos_async_ready ())
265 {
266 return dos_async_rx ();
267 }
268 return SERIAL_TIMEOUT;
269 }
270
271 if (dosasync_read (scb->fd, &buf, 1, timeout))
5a6242dd 272 return buf;
ae0ea72e 273 else
4febd102 274 return SERIAL_TIMEOUT;
ae0ea72e
SC
275}
276
38dc5e12
SG
277/* go32_{get set}_tty_state() are both dummys to fill out the function
278 vector. Someday, they may do something real... */
279
280static serial_ttystate
08c0d7b8 281go32_get_tty_state (scb)
38dc5e12
SG
282 serial_t scb;
283{
284 struct go32_ttystate *state;
285
08c0d7b8 286 state = (struct go32_ttystate *) xmalloc (sizeof *state);
38dc5e12 287
08c0d7b8 288 return (serial_ttystate) state;
38dc5e12
SG
289}
290
291static int
08c0d7b8 292go32_set_tty_state (scb, ttystate)
38dc5e12
SG
293 serial_t scb;
294 serial_ttystate ttystate;
295{
38dc5e12
SG
296 return 0;
297}
298
c2e247c4
JK
299static int
300go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
301 serial_t scb;
302 serial_ttystate new_ttystate;
303 serial_ttystate old_ttystate;
304{
305 return 0;
306}
307
308static void
309go32_print_tty_state (scb, ttystate)
310 serial_t scb;
311 serial_ttystate ttystate;
312{
313 /* Nothing to print. */
314 return;
315}
316
5d2b030a
SG
317static int
318go32_setbaudrate (scb, rate)
319 serial_t scb;
320 int rate;
ae0ea72e
SC
321{
322 return 0;
323}
324
5d2b030a
SG
325static int
326go32_write (scb, str, len)
327 serial_t scb;
328 const char *str;
329 int len;
330{
08c0d7b8 331 dosasync_write (scb->fd, str, len);
4febd102
SG
332
333 return 0;
5d2b030a
SG
334}
335
336static void
452b4b00
SG
337go32_close (scb)
338 serial_t scb;
ae0ea72e 339{
ae0ea72e
SC
340}
341
5d2b030a
SG
342static struct serial_ops go32_ops =
343{
344 "hardwire",
345 0,
346 go32_open,
347 go32_close,
348 go32_readchar,
349 go32_write,
08c0d7b8
SC
350 go32_noop, /* flush output */
351 go32_noop, /* flush input */
352 go32_noop, /* send break -- currently used only for nindy */
5d2b030a 353 go32_raw,
38dc5e12
SG
354 go32_get_tty_state,
355 go32_set_tty_state,
c2e247c4
JK
356 go32_print_tty_state,
357 go32_noflush_set_tty_state,
358 go32_setbaudrate,
5d2b030a
SG
359};
360
976bb0be 361void
5d2b030a 362_initialize_ser_go32 ()
ae0ea72e 363{
5d2b030a 364 serial_add_interface (&go32_ops);
ae0ea72e 365}
This page took 0.13221 seconds and 4 git commands to generate.