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 #define disable() asm("cli")
25 #define enable() asm("sti")
50 #define AOFF_SIGNATURE 2
51 #define AOFF_VERSION 4
52 #define AOFF_BUFFER_START 6
53 #define AOFF_BUFFER_END 8
58 #define AOFF_OVERFLOW 18
59 #define AOFF_BUFFER_SIZE 20
60 #define AOFF_OVFLUSHES 22
63 static ASYNC_STRUCT a; /* Copy in our mem of the struct */
64 static long aindex; /* index into dos space of struct */
66 static int go32_open PARAMS ((serial_t scb, const char *name));
67 static void go32_raw PARAMS ((serial_t scb));
68 static int go32_readchar PARAMS ((serial_t scb, int timeout));
69 static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
70 static int go32_write PARAMS ((serial_t scb, const char *str, int len));
71 static void go32_close PARAMS ((serial_t scb));
72 static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
73 static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
74 static unsigned char aptr PARAMS ((short p));
75 static unsigned long getivec PARAMS ((int which));
76 static int dos_async_init PARAMS ((int port));
77 static void dos_async_tx PARAMS ((const char c));
78 static int dos_async_rx PARAMS (());
79 static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
80 static int dosasync_write PARAMS ((int fd, const char *buf, int len));
82 #define SIGNATURE 0x4154
94 #define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
95 #define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
96 #define GET_BYTE(x) ( dosmemget((x),1,&bb), bb)
99 #define GET_LONG(x) ( dosmemget((x),4,&sl), sl)
106 dosmemget ((x), 2, &sb);
112 #define com_rb(n) iov[n]
113 #define com_tb(n) iov[n]
114 #define com_ier(n) iov[n]+1
115 #define com_ifr(n) iov[n]+2
116 #define com_bfr(n) iov[n]+3
117 #define com_mcr(n) iov[n]+4
118 #define com_lsr(n) iov[n]+5
119 #define com_msr(n) iov[n]+6
125 return GET_BYTE (aindex - OFFSET + p);
133 if (GET_WORD (which * 4) != OFFSET)
136 /* Find out where in memory this lives */
137 tryaindex = GET_WORD (which * 4 + 2) * 16 + GET_WORD (which * 4);
139 if (GET_WORD (tryaindex + 2) != SIGNATURE)
141 if (GET_WORD (tryaindex + 4) != VERSION)
147 dos_async_init (port)
153 aindex = getivec (12);
156 aindex = getivec (11);
164 error ("GDB cannot connect to asynctsr program, check that it is installed\n\
165 and that serial I/O is not being redirected (perhaps by NFS)\n\n\
166 example configuration:\n\
167 C> mode com%d:9600,n,8,1,p\n\
169 C> gdb \n", port, port);
172 iov[0] = GET_WORD (aindex + AOFF_IOV);
173 outportb (com_ier (0), 0x0f);
174 outportb (com_bfr (0), 0x03);
175 outportb (com_mcr (0), 0x0b);
183 while (~inportb (com_lsr (0)) & 0x20)
185 outportb (com_tb (0), c);
193 if (packet_idx < packet_len)
198 ret = GET_WORD (aindex + AOFF_COUNT);
200 ret = GET_WORD (aindex + AOFF_GETP) != GET_WORD (aindex + AOFF_PUTP);
216 if (packet_idx < packet_len)
218 char x = packet[packet_idx++];
221 while (!dos_async_ready ())
225 printf_unfiltered ("abort!\n");
231 /* Sometimes we can read more than one char at a time
232 from the buffer, which is good, cause it'll mean
233 less time with interrupts turned off, which means
234 less dropped characters */
236 /* We only do the simplest case here - not bothering with
240 int getp = GET_WORD (aindex + AOFF_GETP);
241 int putp = GET_WORD (aindex + AOFF_PUTP);
242 int endb = GET_WORD (aindex + AOFF_BUFFER_END);
243 int startb = GET_WORD (aindex + AOFF_BUFFER_START);
245 /* We'd like to grab to the end of the the input,
246 but it may have wrapped, so max is to the end
249 if (putp > endb || putp < getp)
252 /* Work out the length of the suck */
255 /* But only suck as many as we can hold in one go */
256 if (len > sizeof (packet))
257 len = sizeof (packet);
259 dosmemget (aindex - OFFSET + getp, len, packet);
264 if (getp + len >= endb)
273 SET_WORD (aindex + AOFF_GETP, getp);
274 SET_WORD (aindex + AOFF_COUNT, GET_WORD (aindex + AOFF_COUNT) - len);
282 dosasync_read (fd, buf, len, timeout)
292 then = now + timeout;
294 for (i = 0; i < len; i++)
298 while (!dos_async_ready ())
301 if (now >= then && timeout > 0 && its > 1000)
306 *buf++ = dos_async_rx ();
312 dosasync_write (fd, buf, len)
319 for (l = 0; l < len; l++)
320 dos_async_tx (*buf++);
326 go32_open (scb, name)
332 if (strncasecmp (name, "com", 3) != 0)
338 port = name[3] - '0';
340 if ((port != 1) && (port != 2))
346 scb->fd = dos_async_init (port);
364 /* Always in raw mode */
368 go32_readchar (scb, timeout)
374 /* Shortcut for polling */
377 if (dos_async_ready ())
379 return dos_async_rx ();
381 return SERIAL_TIMEOUT;
384 if (dosasync_read (scb->fd, &buf, 1, timeout))
387 return SERIAL_TIMEOUT;
390 /* go32_{get set}_tty_state() are both dummys to fill out the function
391 vector. Someday, they may do something real... */
393 static serial_ttystate
394 go32_get_tty_state (scb)
397 struct go32_ttystate *state;
399 state = (struct go32_ttystate *) xmalloc (sizeof *state);
401 return (serial_ttystate) state;
405 go32_set_tty_state (scb, ttystate)
407 serial_ttystate ttystate;
413 go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
415 serial_ttystate new_ttystate;
416 serial_ttystate old_ttystate;
422 go32_print_tty_state (scb, ttystate)
424 serial_ttystate ttystate;
426 /* Nothing to print. */
431 go32_setbaudrate (scb, rate)
439 go32_write (scb, str, len)
444 dosasync_write (scb->fd, str, len);
455 static struct serial_ops go32_ops =
463 go32_noop, /* flush output */
464 go32_noop, /* flush input */
465 go32_noop, /* send break -- currently used only for nindy */
469 go32_print_tty_state,
470 go32_noflush_set_tty_state,
475 _initialize_ser_go32 ()
477 serial_add_interface (&go32_ops);