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. */
43 static int go32_open
PARAMS ((serial_t scb
, const char *name
));
44 static void go32_raw
PARAMS ((serial_t scb
));
45 static int go32_readchar
PARAMS ((serial_t scb
, int timeout
));
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_close
PARAMS ((serial_t scb
));
49 static serial_ttystate go32_get_tty_state
PARAMS ((serial_t scb
));
50 static int go32_set_tty_state
PARAMS ((serial_t scb
, serial_ttystate state
));
51 static char *aptr
PARAMS ((short p
));
52 static ASYNC_STRUCT
*getivec
PARAMS ((int which
));
53 static int dos_async_init
PARAMS ((int port
));
54 static void dos_async_tx
PARAMS ((const char c
));
55 static int dos_async_rx
PARAMS (());
56 static int dosasync_read
PARAMS ((int fd
, char *buf
, int len
, int timeout
));
57 static int dosasync_write
PARAMS ((int fd
, const char *buf
, int len
));
59 #define SIGNATURE 0x4154
63 #define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
65 static volatile ASYNC_STRUCT
*async
;
80 return (char *) ((unsigned) async
- OFFSET
+ p
);
88 if (peek (0, which
* 4) != OFFSET
)
91 a
= (ASYNC_STRUCT
*) (0xe0000000 + peek (0, which
* 4 + 2) * 16 + peek (0, which
* 4));
93 if (a
->signature
!= SIGNATURE
)
96 if (a
->version
!= VERSION
)
103 dos_async_init (port
)
109 async
= getivec (12);
112 async
= getivec (11);
120 error ("GDB cannot connect to asynctsr program, check that it is installed\n\
121 and that serial I/O is not being redirected (perhaps by NFS)\n\n\
122 example configuration:\n\
123 C> mode com%d:9600,n,8,1,p\n\
125 C> gdb \n", port
, port
);
129 outportb (com_ier
, 0x0f);
130 outportb (com_bfr
, 0x03);
131 outportb (com_mcr
, 0x0b);
132 async
->getp
= async
->putp
= async
->buffer_start
;
141 while (~inportb (com_lsr
) & 0x20)
143 outportb (com_tb
, c
);
146 #define dos_async_ready() (async->getp != async->putp)
153 while (!dos_async_ready ())
157 printf_unfiltered ("abort!\n");
162 rv
= *aptr (async
->getp
++);
163 if (async
->getp
>= async
->buffer_end
)
164 async
->getp
= async
->buffer_start
;
170 dosasync_read (fd
, buf
, len
, timeout
)
180 then
= now
+ timeout
;
182 for (i
= 0; i
< len
; i
++)
186 while (!dos_async_ready ())
193 *buf
++ = dos_async_rx ();
199 dosasync_write (fd
, buf
, len
)
206 for (l
= 0; l
< len
; l
++)
207 dos_async_tx (*buf
++);
213 go32_open (scb
, name
)
219 if (strncasecmp (name
, "com", 3) != 0)
225 port
= name
[3] - '0';
227 if ((port
!= 1) && (port
!= 2))
233 scb
->fd
= dos_async_init (port
);
251 /* Always in raw mode */
255 go32_readchar (scb
, timeout
)
261 /* Shortcut for polling */
264 if (dos_async_ready ())
266 return dos_async_rx ();
268 return SERIAL_TIMEOUT
;
271 if (dosasync_read (scb
->fd
, &buf
, 1, timeout
))
274 return SERIAL_TIMEOUT
;
277 /* go32_{get set}_tty_state() are both dummys to fill out the function
278 vector. Someday, they may do something real... */
280 static serial_ttystate
281 go32_get_tty_state (scb
)
284 struct go32_ttystate
*state
;
286 state
= (struct go32_ttystate
*) xmalloc (sizeof *state
);
288 return (serial_ttystate
) state
;
292 go32_set_tty_state (scb
, ttystate
)
294 serial_ttystate ttystate
;
300 go32_noflush_set_tty_state (scb
, new_ttystate
, old_ttystate
)
302 serial_ttystate new_ttystate
;
303 serial_ttystate old_ttystate
;
309 go32_print_tty_state (scb
, ttystate
)
311 serial_ttystate ttystate
;
313 /* Nothing to print. */
318 go32_setbaudrate (scb
, rate
)
326 go32_write (scb
, str
, len
)
331 dosasync_write (scb
->fd
, str
, len
);
342 static struct serial_ops go32_ops
=
350 go32_noop
, /* flush output */
351 go32_noop
, /* flush input */
352 go32_noop
, /* send break -- currently used only for nindy */
356 go32_print_tty_state
,
357 go32_noflush_set_tty_state
,
362 _initialize_ser_go32 ()
364 serial_add_interface (&go32_ops
);