* som.h (R_HPPA_COMPLEX): Fix dumb typo.
[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
aa48187b
SC
24#define disable() asm("cli")
25#define enable() asm("sti")
26
38dc5e12 27struct go32_ttystate
08c0d7b8
SC
28 {
29 int bogus;
30 };
08c0d7b8
SC
31typedef struct
32 {
33 short jmp_op;
34 short signature;
35 short version;
36 short buffer_start;
37 short buffer_end;
38 short getp;
39 short putp;
40 short iov;
aa48187b
SC
41 short count;
42 short overflow;
43 short buffer_size;
44 short ovflushes;
08c0d7b8
SC
45 }
46ASYNC_STRUCT;
452b4b00 47
aa48187b
SC
48#define AOFF_JMP_OP 0
49#define AOFF_SIGNATURE 2
50#define AOFF_VERSION 4
51#define AOFF_BUFFER_START 6
52#define AOFF_BUFFER_END 8
53#define AOFF_GETP 10
54#define AOFF_PUTP 12
55#define AOFF_IOV 14
56#define AOFF_COUNT 16
57#define AOFF_OVERFLOW 18
58#define AOFF_BUFFER_SIZE 20
59#define AOFF_OVFLUSHES 22
60
61
62static ASYNC_STRUCT a; /* Copy in our mem of the struct */
63static long aindex; /* index into dos space of struct */
64
38dc5e12
SG
65static int go32_open PARAMS ((serial_t scb, const char *name));
66static void go32_raw PARAMS ((serial_t scb));
38dc5e12 67static int go32_readchar PARAMS ((serial_t scb, int timeout));
38dc5e12
SG
68static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
69static int go32_write PARAMS ((serial_t scb, const char *str, int len));
38dc5e12 70static void go32_close PARAMS ((serial_t scb));
452b4b00 71static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
38dc5e12 72static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
aa48187b
SC
73static unsigned char aptr PARAMS ((short p));
74static unsigned long getivec PARAMS ((int which));
38dc5e12
SG
75static int dos_async_init PARAMS ((int port));
76static void dos_async_tx PARAMS ((const char c));
38dc5e12
SG
77static int dos_async_rx PARAMS (());
78static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
452b4b00 79static int dosasync_write PARAMS ((int fd, const char *buf, int len));
38dc5e12 80
ae0ea72e
SC
81#define SIGNATURE 0x4154
82#define VERSION 1
83#define OFFSET 0x104
84
aa48187b
SC
85unsigned char bb;
86unsigned short sb;
87unsigned long sl;
88
89#define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
90#define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
91#define GET_BYTE(x) ( dosmemget((x),1,&bb), bb)
92
93
94#define GET_LONG(x) ( dosmemget((x),4,&sl), sl)
95
96static
97unsigned short
98GET_WORD (x)
99{
100 unsigned short sb;
101 dosmemget ((x), 2, &sb);
102 return sb;
103}
104
105static int iov[2];
ae0ea72e 106
aa48187b
SC
107#define com_rb(n) iov[n]
108#define com_tb(n) iov[n]
109#define com_ier(n) iov[n]+1
110#define com_ifr(n) iov[n]+2
111#define com_bfr(n) iov[n]+3
112#define com_mcr(n) iov[n]+4
113#define com_lsr(n) iov[n]+5
114#define com_msr(n) iov[n]+6
ae0ea72e 115
aa48187b 116static unsigned char
08c0d7b8 117aptr (p)
5d2b030a 118 short p;
ae0ea72e 119{
aa48187b 120 return GET_BYTE (aindex - OFFSET + p);
ae0ea72e
SC
121}
122
aa48187b 123static unsigned long
08c0d7b8 124getivec (int which)
ae0ea72e 125{
aa48187b 126 long tryaindex;
ae0ea72e 127
aa48187b 128 if (GET_WORD (which * 4) != OFFSET)
ae0ea72e 129 return 0;
b83bf6b3 130
aa48187b
SC
131 /* Find out where in memory this lives */
132 tryaindex = GET_WORD (which * 4 + 2) * 16 + GET_WORD (which * 4);
ae0ea72e 133
aa48187b 134 if (GET_WORD (tryaindex + 2) != SIGNATURE)
ae0ea72e 135 return 0;
aa48187b 136 if (GET_WORD (tryaindex + 4) != VERSION)
ae0ea72e 137 return 0;
aa48187b 138 return tryaindex;
ae0ea72e
SC
139}
140
5d2b030a 141static int
08c0d7b8 142dos_async_init (port)
b83bf6b3 143 int port;
ae0ea72e 144{
b83bf6b3 145 switch (port)
07861607 146 {
b83bf6b3 147 case 1:
aa48187b 148 aindex = getivec (12);
b83bf6b3
SG
149 break;
150 case 2:
aa48187b 151 aindex = getivec (11);
b83bf6b3
SG
152 break;
153 default:
154 return 0;
07861607
SG
155 }
156
aa48187b 157 if (!aindex)
07861607 158 {
08c0d7b8 159 error ("GDB cannot connect to asynctsr program, check that it is installed\n\
ae0ea72e
SC
160and that serial I/O is not being redirected (perhaps by NFS)\n\n\
161example configuration:\n\
a037b21e
SG
162C> mode com%d:9600,n,8,1,p\n\
163C> asynctsr %d\n\
164C> gdb \n", port, port);
07861607
SG
165 }
166
aa48187b
SC
167 iov[0] = GET_WORD (aindex + AOFF_IOV);
168 outportb (com_ier (0), 0x0f);
169 outportb (com_bfr (0), 0x03);
170 outportb (com_mcr (0), 0x0b);
b83bf6b3 171 return 1;
ae0ea72e
SC
172}
173
5d2b030a 174static void
08c0d7b8 175dos_async_tx (c)
5d2b030a 176 const char c;
ae0ea72e 177{
aa48187b 178 while (~inportb (com_lsr (0)) & 0x20)
08c0d7b8 179 ;
aa48187b 180 outportb (com_tb (0), c);
ae0ea72e
SC
181}
182
aa48187b
SC
183static int
184dos_async_ready ()
185{
186 int ret;
187
188 disable ();
189#if RDY_CNT
190 ret = GET_WORD (aindex + AOFF_COUNT);
191#else
192 ret = GET_WORD (aindex + AOFF_GETP) != GET_WORD (aindex + AOFF_PUTP);
193#endif
194 enable ();
195 return ret;
196
197
198}
ae0ea72e 199
5d2b030a 200static int
08c0d7b8 201dos_async_rx ()
ae0ea72e
SC
202{
203 char rv;
aa48187b 204 short idx;
5d2b030a 205
08c0d7b8
SC
206 while (!dos_async_ready ())
207 {
208 if (kbhit ())
209 {
210 printf_unfiltered ("abort!\n");
211 return 0;
212 }
213 }
aa48187b
SC
214 disable ();
215 idx = GET_WORD (aindex + AOFF_GETP);
216 idx++;
217 SET_WORD (aindex + AOFF_GETP, idx);
218 rv = aptr (idx - 1);
219 SET_WORD (aindex + AOFF_COUNT, GET_WORD (aindex + AOFF_COUNT) - 1);
220 if (GET_WORD (aindex + AOFF_GETP) > GET_WORD (aindex + AOFF_BUFFER_END))
221 SET_WORD (aindex + AOFF_GETP, GET_WORD (aindex + AOFF_BUFFER_START));
222 enable ();
5d2b030a 223 return rv;
ae0ea72e
SC
224}
225
63eef03a 226
5d2b030a
SG
227static int
228dosasync_read (fd, buf, len, timeout)
229 int fd;
230 char *buf;
231 int len;
232 int timeout;
ae0ea72e
SC
233{
234 long now, then;
08c0d7b8 235 int i;
5d2b030a 236
ae0ea72e 237 time (&now);
5d2b030a
SG
238 then = now + timeout;
239
08c0d7b8 240 for (i = 0; i < len; i++)
ae0ea72e 241 {
5d2b030a
SG
242 if (timeout)
243 {
08c0d7b8 244 while (!dos_async_ready ())
5d2b030a
SG
245 {
246 time (&now);
63eef03a 247 if (now >= then && timeout > 0)
08c0d7b8 248 return i;
5d2b030a
SG
249 }
250 }
08c0d7b8 251 *buf++ = dos_async_rx ();
ae0ea72e 252 }
5d2b030a 253 return len;
ae0ea72e
SC
254}
255
5d2b030a 256static int
08c0d7b8 257dosasync_write (fd, buf, len)
5d2b030a
SG
258 int fd;
259 const char *buf;
260 int len;
261{
08c0d7b8 262 int l;
ae0ea72e 263
08c0d7b8 264 for (l = 0; l < len; l++)
5d2b030a 265 dos_async_tx (*buf++);
ae0ea72e 266
5d2b030a 267 return len;
ae0ea72e
SC
268}
269
5d2b030a
SG
270static int
271go32_open (scb, name)
272 serial_t scb;
273 const char *name;
b52373a2 274{
b83bf6b3
SG
275 int port;
276
277 if (strncasecmp (name, "com", 3) != 0)
278 {
279 errno = ENOENT;
4febd102 280 return -1;
b83bf6b3
SG
281 }
282
283 port = name[3] - '0';
284
285 if ((port != 1) && (port != 2))
286 {
287 errno = ENOENT;
4febd102 288 return -11;
b83bf6b3
SG
289 }
290
08c0d7b8 291 scb->fd = dos_async_init (port);
07861607 292 if (!scb->fd)
4febd102 293 return -1;
ae0ea72e 294
5d2b030a 295 return 0;
ae0ea72e
SC
296}
297
c2e247c4 298static int
704deef2 299go32_noop (scb)
c2e247c4
JK
300 serial_t scb;
301{
c2e247c4
JK
302 return 0;
303}
304
5d2b030a
SG
305static void
306go32_raw (scb)
307 serial_t scb;
ae0ea72e 308{
5d2b030a 309 /* Always in raw mode */
ae0ea72e
SC
310}
311
5d2b030a
SG
312static int
313go32_readchar (scb, timeout)
314 serial_t scb;
315 int timeout;
ae0ea72e
SC
316{
317 char buf;
5d2b030a 318
08c0d7b8
SC
319 /* Shortcut for polling */
320 if (timeout == 0)
321 {
322 if (dos_async_ready ())
323 {
324 return dos_async_rx ();
325 }
326 return SERIAL_TIMEOUT;
327 }
328
329 if (dosasync_read (scb->fd, &buf, 1, timeout))
5a6242dd 330 return buf;
ae0ea72e 331 else
4febd102 332 return SERIAL_TIMEOUT;
ae0ea72e
SC
333}
334
38dc5e12
SG
335/* go32_{get set}_tty_state() are both dummys to fill out the function
336 vector. Someday, they may do something real... */
337
338static serial_ttystate
08c0d7b8 339go32_get_tty_state (scb)
38dc5e12
SG
340 serial_t scb;
341{
342 struct go32_ttystate *state;
343
08c0d7b8 344 state = (struct go32_ttystate *) xmalloc (sizeof *state);
38dc5e12 345
08c0d7b8 346 return (serial_ttystate) state;
38dc5e12
SG
347}
348
349static int
08c0d7b8 350go32_set_tty_state (scb, ttystate)
38dc5e12
SG
351 serial_t scb;
352 serial_ttystate ttystate;
353{
38dc5e12
SG
354 return 0;
355}
356
c2e247c4
JK
357static int
358go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
359 serial_t scb;
360 serial_ttystate new_ttystate;
361 serial_ttystate old_ttystate;
362{
363 return 0;
364}
365
366static void
367go32_print_tty_state (scb, ttystate)
368 serial_t scb;
369 serial_ttystate ttystate;
370{
371 /* Nothing to print. */
372 return;
373}
374
5d2b030a
SG
375static int
376go32_setbaudrate (scb, rate)
377 serial_t scb;
378 int rate;
ae0ea72e
SC
379{
380 return 0;
381}
382
5d2b030a
SG
383static int
384go32_write (scb, str, len)
385 serial_t scb;
386 const char *str;
387 int len;
388{
08c0d7b8 389 dosasync_write (scb->fd, str, len);
4febd102
SG
390
391 return 0;
5d2b030a
SG
392}
393
394static void
452b4b00
SG
395go32_close (scb)
396 serial_t scb;
ae0ea72e 397{
ae0ea72e
SC
398}
399
5d2b030a
SG
400static struct serial_ops go32_ops =
401{
402 "hardwire",
403 0,
404 go32_open,
405 go32_close,
406 go32_readchar,
407 go32_write,
08c0d7b8
SC
408 go32_noop, /* flush output */
409 go32_noop, /* flush input */
410 go32_noop, /* send break -- currently used only for nindy */
5d2b030a 411 go32_raw,
38dc5e12
SG
412 go32_get_tty_state,
413 go32_set_tty_state,
c2e247c4
JK
414 go32_print_tty_state,
415 go32_noflush_set_tty_state,
416 go32_setbaudrate,
5d2b030a
SG
417};
418
976bb0be 419void
5d2b030a 420_initialize_ser_go32 ()
ae0ea72e 421{
5d2b030a 422 serial_add_interface (&go32_ops);
ae0ea72e 423}
This page took 0.163058 seconds and 4 git commands to generate.