]>
Commit | Line | Data |
---|---|---|
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. */ |
25 | struct go32_ttystate | |
08c0d7b8 SC |
26 | { |
27 | int bogus; | |
28 | }; | |
29 | ||
30 | typedef 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 | } | |
41 | ASYNC_STRUCT; | |
452b4b00 | 42 | |
38dc5e12 SG |
43 | static int go32_open PARAMS ((serial_t scb, const char *name)); |
44 | static void go32_raw PARAMS ((serial_t scb)); | |
38dc5e12 | 45 | static int go32_readchar PARAMS ((serial_t scb, int timeout)); |
38dc5e12 SG |
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)); | |
38dc5e12 | 48 | static void go32_close PARAMS ((serial_t scb)); |
452b4b00 | 49 | static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb)); |
38dc5e12 | 50 | static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state)); |
38dc5e12 SG |
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)); | |
38dc5e12 SG |
55 | static int dos_async_rx PARAMS (()); |
56 | static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout)); | |
452b4b00 | 57 | static 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 | 65 | static volatile ASYNC_STRUCT *async; |
ae0ea72e SC |
66 | static 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 | 76 | static char * |
08c0d7b8 | 77 | aptr (p) |
5d2b030a | 78 | short p; |
ae0ea72e | 79 | { |
08c0d7b8 | 80 | return (char *) ((unsigned) async - OFFSET + p); |
ae0ea72e SC |
81 | } |
82 | ||
5d2b030a | 83 | static ASYNC_STRUCT * |
08c0d7b8 | 84 | getivec (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 | 102 | static int |
08c0d7b8 | 103 | dos_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 |
121 | and that serial I/O is not being redirected (perhaps by NFS)\n\n\ |
122 | example configuration:\n\ | |
a037b21e SG |
123 | C> mode com%d:9600,n,8,1,p\n\ |
124 | C> asynctsr %d\n\ | |
125 | C> 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 | 137 | static void |
08c0d7b8 | 138 | dos_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 | 148 | static int |
08c0d7b8 | 149 | dos_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++); |
63eef03a | 163 | |
ae0ea72e | 164 | if (async->getp >= async->buffer_end) |
5d2b030a | 165 | async->getp = async->buffer_start; |
ae0ea72e | 166 | |
5d2b030a | 167 | return rv; |
ae0ea72e SC |
168 | } |
169 | ||
63eef03a | 170 | |
5d2b030a SG |
171 | static int |
172 | dosasync_read (fd, buf, len, timeout) | |
173 | int fd; | |
174 | char *buf; | |
175 | int len; | |
176 | int timeout; | |
ae0ea72e SC |
177 | { |
178 | long now, then; | |
08c0d7b8 | 179 | int i; |
5d2b030a | 180 | |
ae0ea72e | 181 | time (&now); |
5d2b030a SG |
182 | then = now + timeout; |
183 | ||
08c0d7b8 | 184 | for (i = 0; i < len; i++) |
ae0ea72e | 185 | { |
5d2b030a SG |
186 | if (timeout) |
187 | { | |
08c0d7b8 | 188 | while (!dos_async_ready ()) |
5d2b030a SG |
189 | { |
190 | time (&now); | |
63eef03a | 191 | if (now >= then && timeout > 0) |
08c0d7b8 | 192 | return i; |
5d2b030a SG |
193 | } |
194 | } | |
08c0d7b8 | 195 | *buf++ = dos_async_rx (); |
ae0ea72e | 196 | } |
5d2b030a | 197 | return len; |
ae0ea72e SC |
198 | } |
199 | ||
5d2b030a | 200 | static int |
08c0d7b8 | 201 | dosasync_write (fd, buf, len) |
5d2b030a SG |
202 | int fd; |
203 | const char *buf; | |
204 | int len; | |
205 | { | |
08c0d7b8 | 206 | int l; |
ae0ea72e | 207 | |
08c0d7b8 | 208 | for (l = 0; l < len; l++) |
5d2b030a | 209 | dos_async_tx (*buf++); |
ae0ea72e | 210 | |
5d2b030a | 211 | return len; |
ae0ea72e SC |
212 | } |
213 | ||
5d2b030a SG |
214 | static int |
215 | go32_open (scb, name) | |
216 | serial_t scb; | |
217 | const char *name; | |
b52373a2 | 218 | { |
b83bf6b3 SG |
219 | int port; |
220 | ||
221 | if (strncasecmp (name, "com", 3) != 0) | |
222 | { | |
223 | errno = ENOENT; | |
4febd102 | 224 | return -1; |
b83bf6b3 SG |
225 | } |
226 | ||
227 | port = name[3] - '0'; | |
228 | ||
229 | if ((port != 1) && (port != 2)) | |
230 | { | |
231 | errno = ENOENT; | |
4febd102 | 232 | return -11; |
b83bf6b3 SG |
233 | } |
234 | ||
08c0d7b8 | 235 | scb->fd = dos_async_init (port); |
07861607 | 236 | if (!scb->fd) |
4febd102 | 237 | return -1; |
ae0ea72e | 238 | |
5d2b030a | 239 | return 0; |
ae0ea72e SC |
240 | } |
241 | ||
c2e247c4 | 242 | static int |
704deef2 | 243 | go32_noop (scb) |
c2e247c4 JK |
244 | serial_t scb; |
245 | { | |
c2e247c4 JK |
246 | return 0; |
247 | } | |
248 | ||
5d2b030a SG |
249 | static void |
250 | go32_raw (scb) | |
251 | serial_t scb; | |
ae0ea72e | 252 | { |
5d2b030a | 253 | /* Always in raw mode */ |
ae0ea72e SC |
254 | } |
255 | ||
5d2b030a SG |
256 | static int |
257 | go32_readchar (scb, timeout) | |
258 | serial_t scb; | |
259 | int timeout; | |
ae0ea72e SC |
260 | { |
261 | char buf; | |
5d2b030a | 262 | |
63eef03a | 263 | |
08c0d7b8 SC |
264 | /* Shortcut for polling */ |
265 | if (timeout == 0) | |
266 | { | |
267 | if (dos_async_ready ()) | |
268 | { | |
269 | return dos_async_rx (); | |
270 | } | |
271 | return SERIAL_TIMEOUT; | |
272 | } | |
273 | ||
274 | if (dosasync_read (scb->fd, &buf, 1, timeout)) | |
5a6242dd | 275 | return buf; |
ae0ea72e | 276 | else |
4febd102 | 277 | return SERIAL_TIMEOUT; |
ae0ea72e SC |
278 | } |
279 | ||
38dc5e12 SG |
280 | /* go32_{get set}_tty_state() are both dummys to fill out the function |
281 | vector. Someday, they may do something real... */ | |
282 | ||
283 | static serial_ttystate | |
08c0d7b8 | 284 | go32_get_tty_state (scb) |
38dc5e12 SG |
285 | serial_t scb; |
286 | { | |
287 | struct go32_ttystate *state; | |
288 | ||
08c0d7b8 | 289 | state = (struct go32_ttystate *) xmalloc (sizeof *state); |
38dc5e12 | 290 | |
08c0d7b8 | 291 | return (serial_ttystate) state; |
38dc5e12 SG |
292 | } |
293 | ||
294 | static int | |
08c0d7b8 | 295 | go32_set_tty_state (scb, ttystate) |
38dc5e12 SG |
296 | serial_t scb; |
297 | serial_ttystate ttystate; | |
298 | { | |
38dc5e12 SG |
299 | return 0; |
300 | } | |
301 | ||
c2e247c4 JK |
302 | static int |
303 | go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate) | |
304 | serial_t scb; | |
305 | serial_ttystate new_ttystate; | |
306 | serial_ttystate old_ttystate; | |
307 | { | |
308 | return 0; | |
309 | } | |
310 | ||
311 | static void | |
312 | go32_print_tty_state (scb, ttystate) | |
313 | serial_t scb; | |
314 | serial_ttystate ttystate; | |
315 | { | |
316 | /* Nothing to print. */ | |
317 | return; | |
318 | } | |
319 | ||
5d2b030a SG |
320 | static int |
321 | go32_setbaudrate (scb, rate) | |
322 | serial_t scb; | |
323 | int rate; | |
ae0ea72e SC |
324 | { |
325 | return 0; | |
326 | } | |
327 | ||
5d2b030a SG |
328 | static int |
329 | go32_write (scb, str, len) | |
330 | serial_t scb; | |
331 | const char *str; | |
332 | int len; | |
333 | { | |
08c0d7b8 | 334 | dosasync_write (scb->fd, str, len); |
4febd102 SG |
335 | |
336 | return 0; | |
5d2b030a SG |
337 | } |
338 | ||
339 | static void | |
452b4b00 SG |
340 | go32_close (scb) |
341 | serial_t scb; | |
ae0ea72e | 342 | { |
ae0ea72e SC |
343 | } |
344 | ||
5d2b030a SG |
345 | static struct serial_ops go32_ops = |
346 | { | |
347 | "hardwire", | |
348 | 0, | |
349 | go32_open, | |
350 | go32_close, | |
351 | go32_readchar, | |
352 | go32_write, | |
08c0d7b8 SC |
353 | go32_noop, /* flush output */ |
354 | go32_noop, /* flush input */ | |
355 | go32_noop, /* send break -- currently used only for nindy */ | |
5d2b030a | 356 | go32_raw, |
38dc5e12 SG |
357 | go32_get_tty_state, |
358 | go32_set_tty_state, | |
c2e247c4 JK |
359 | go32_print_tty_state, |
360 | go32_noflush_set_tty_state, | |
361 | go32_setbaudrate, | |
5d2b030a SG |
362 | }; |
363 | ||
976bb0be | 364 | void |
5d2b030a | 365 | _initialize_ser_go32 () |
ae0ea72e | 366 | { |
5d2b030a | 367 | serial_add_interface (&go32_ops); |
ae0ea72e | 368 | } |