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")
49 #define AOFF_SIGNATURE 2
50 #define AOFF_VERSION 4
51 #define AOFF_BUFFER_START 6
52 #define AOFF_BUFFER_END 8
57 #define AOFF_OVERFLOW 18
58 #define AOFF_BUFFER_SIZE 20
59 #define AOFF_OVFLUSHES 22
62 static ASYNC_STRUCT a
; /* Copy in our mem of the struct */
63 static long aindex
; /* index into dos space of struct */
65 static int go32_open
PARAMS ((serial_t scb
, const char *name
));
66 static void go32_raw
PARAMS ((serial_t scb
));
67 static int go32_readchar
PARAMS ((serial_t scb
, int timeout
));
68 static int go32_setbaudrate
PARAMS ((serial_t scb
, int rate
));
69 static int go32_write
PARAMS ((serial_t scb
, const char *str
, int len
));
70 static void go32_close
PARAMS ((serial_t scb
));
71 static serial_ttystate go32_get_tty_state
PARAMS ((serial_t scb
));
72 static int go32_set_tty_state
PARAMS ((serial_t scb
, serial_ttystate state
));
73 static unsigned char aptr
PARAMS ((short p
));
74 static unsigned long getivec
PARAMS ((int which
));
75 static int dos_async_init
PARAMS ((int port
));
76 static void dos_async_tx
PARAMS ((const char c
));
77 static int dos_async_rx
PARAMS (());
78 static int dosasync_read
PARAMS ((int fd
, char *buf
, int len
, int timeout
));
79 static int dosasync_write
PARAMS ((int fd
, const char *buf
, int len
));
81 #define SIGNATURE 0x4154
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)
94 #define GET_LONG(x) ( dosmemget((x),4,&sl), sl)
101 dosmemget ((x
), 2, &sb
);
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
120 return GET_BYTE (aindex
- OFFSET
+ p
);
128 if (GET_WORD (which
* 4) != OFFSET
)
131 /* Find out where in memory this lives */
132 tryaindex
= GET_WORD (which
* 4 + 2) * 16 + GET_WORD (which
* 4);
134 if (GET_WORD (tryaindex
+ 2) != SIGNATURE
)
136 if (GET_WORD (tryaindex
+ 4) != VERSION
)
142 dos_async_init (port
)
148 aindex
= getivec (12);
151 aindex
= getivec (11);
159 error ("GDB cannot connect to asynctsr program, check that it is installed\n\
160 and that serial I/O is not being redirected (perhaps by NFS)\n\n\
161 example configuration:\n\
162 C> mode com%d:9600,n,8,1,p\n\
164 C> gdb \n", port
, port
);
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);
178 while (~inportb (com_lsr (0)) & 0x20)
180 outportb (com_tb (0), c
);
190 ret
= GET_WORD (aindex
+ AOFF_COUNT
);
192 ret
= GET_WORD (aindex
+ AOFF_GETP
) != GET_WORD (aindex
+ AOFF_PUTP
);
206 while (!dos_async_ready ())
210 printf_unfiltered ("abort!\n");
215 idx
= GET_WORD (aindex
+ AOFF_GETP
);
217 SET_WORD (aindex
+ AOFF_GETP
, idx
);
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
));
228 dosasync_read (fd
, buf
, len
, timeout
)
238 then
= now
+ timeout
;
240 for (i
= 0; i
< len
; i
++)
244 while (!dos_async_ready ())
247 if (now
>= then
&& timeout
> 0)
251 *buf
++ = dos_async_rx ();
257 dosasync_write (fd
, buf
, len
)
264 for (l
= 0; l
< len
; l
++)
265 dos_async_tx (*buf
++);
271 go32_open (scb
, name
)
277 if (strncasecmp (name
, "com", 3) != 0)
283 port
= name
[3] - '0';
285 if ((port
!= 1) && (port
!= 2))
291 scb
->fd
= dos_async_init (port
);
309 /* Always in raw mode */
313 go32_readchar (scb
, timeout
)
319 /* Shortcut for polling */
322 if (dos_async_ready ())
324 return dos_async_rx ();
326 return SERIAL_TIMEOUT
;
329 if (dosasync_read (scb
->fd
, &buf
, 1, timeout
))
332 return SERIAL_TIMEOUT
;
335 /* go32_{get set}_tty_state() are both dummys to fill out the function
336 vector. Someday, they may do something real... */
338 static serial_ttystate
339 go32_get_tty_state (scb
)
342 struct go32_ttystate
*state
;
344 state
= (struct go32_ttystate
*) xmalloc (sizeof *state
);
346 return (serial_ttystate
) state
;
350 go32_set_tty_state (scb
, ttystate
)
352 serial_ttystate ttystate
;
358 go32_noflush_set_tty_state (scb
, new_ttystate
, old_ttystate
)
360 serial_ttystate new_ttystate
;
361 serial_ttystate old_ttystate
;
367 go32_print_tty_state (scb
, ttystate
)
369 serial_ttystate ttystate
;
371 /* Nothing to print. */
376 go32_setbaudrate (scb
, rate
)
384 go32_write (scb
, str
, len
)
389 dosasync_write (scb
->fd
, str
, len
);
400 static struct serial_ops go32_ops
=
408 go32_noop
, /* flush output */
409 go32_noop
, /* flush input */
410 go32_noop
, /* send break -- currently used only for nindy */
414 go32_print_tty_state
,
415 go32_noflush_set_tty_state
,
420 _initialize_ser_go32 ()
422 serial_add_interface (&go32_ops
);