ff1bdf119307aeaffa7082b81786a87b18ac7a7c
[deliverable/binutils-gdb.git] / gdb / ser-go32.c
1 /* Remote serial interface for local (hardwired) serial ports for GO32.
2 Copyright 1992, 1993 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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. */
19
20 #include "defs.h"
21 #include "serial.h"
22 #include <sys/dos.h>
23
24 /* This is unused for now. We just return a placeholder. */
25 struct go32_ttystate
26 {
27 int bogus;
28 };
29
30 typedef struct {
31 short jmp_op;
32 short signature;
33 short version;
34 short buffer_start;
35 short buffer_end;
36 short getp;
37 short putp;
38 short iov;
39 } ASYNC_STRUCT;
40
41 static int go32_open PARAMS ((serial_t scb, const char *name));
42 static void go32_raw PARAMS ((serial_t scb));
43 static int wait_for PARAMS ((serial_t scb, int timeout));
44 static int go32_readchar PARAMS ((serial_t scb, int timeout));
45 static int rate_to_code PARAMS ((int rate));
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_restore PARAMS ((serial_t scb));
49 static void go32_close PARAMS ((serial_t scb));
50 static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
51 static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
52 static int strncasecmp PARAMS ((const char *str1, const char *str2, int len));
53 static char *aptr PARAMS ((short p));
54 static ASYNC_STRUCT *getivec PARAMS ((int which));
55 static int dos_async_init PARAMS ((int port));
56 static void dos_async_tx PARAMS ((const char c));
57 static int dos_async_ready PARAMS (());
58 static int dos_async_rx PARAMS (());
59 static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
60 static int dosasync_write PARAMS ((int fd, const char *buf, int len));
61
62 #define SIGNATURE 0x4154
63 #define VERSION 1
64 #define OFFSET 0x104
65
66 #define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
67
68 static ASYNC_STRUCT *async;
69 static int iov;
70 #define com_rb iov
71 #define com_tb iov
72 #define com_ier iov+1
73 #define com_ifr iov+2
74 #define com_bfr iov+3
75 #define com_mcr iov+4
76 #define com_lsr iov+5
77 #define com_msr iov+6
78
79 static int
80 strncasecmp(str1, str2, len)
81 const char *str1, *str2;
82 register int len;
83 {
84 unsigned char c1, c2;
85
86 for (; len != 0; --len)
87 {
88 c1 = *str1++;
89 c2 = *str2++;
90
91 if (toupper(c1) != toupper(c2))
92 return toupper(c1) - toupper(c2);
93
94 if (c1 == '\0')
95 return 0;
96 }
97 return 0;
98 }
99
100 static char *
101 aptr(p)
102 short p;
103 {
104 return (char *)((unsigned)async - OFFSET + p);
105 }
106
107 static ASYNC_STRUCT *
108 getivec(int which)
109 {
110 ASYNC_STRUCT *a;
111
112 if (peek(0, which*4) != OFFSET)
113 return 0;
114
115 a = (ASYNC_STRUCT *)(0xe0000000 + peek(0, which*4+2)*16 + peek(0, which*4));
116
117 if (a->signature != SIGNATURE)
118 return 0;
119
120 if (a->version != VERSION)
121 return 0;
122
123 return a;
124 }
125
126 static int
127 dos_async_init(port)
128 int port;
129 {
130 int i;
131
132 switch (port)
133 {
134 case 1:
135 async = getivec (12);
136 break;
137 case 2:
138 async = getivec (11);
139 break;
140 default:
141 return 0;
142 }
143
144 if (!async)
145 {
146 error("GDB cannot connect to asynctsr program, check that it is installed\n\
147 and that serial I/O is not being redirected (perhaps by NFS)\n\n\
148 example configuration:\n\
149 C> mode com%d:9600,n,8,1,p\n\
150 C> asynctsr %d\n\
151 C> gdb \n", port, port);
152 }
153
154 iov = async->iov;
155 outportb(com_ier, 0x0f);
156 outportb(com_bfr, 0x03);
157 outportb(com_mcr, 0x0b);
158 async->getp = async->putp = async->buffer_start;
159
160 return 1;
161 }
162
163 static void
164 dos_async_tx(c)
165 const char c;
166 {
167 while (~inportb(com_lsr) & 0x20);
168
169 outportb(com_tb, c);
170 }
171
172 static int
173 dos_async_ready()
174 {
175 return (async->getp != async->putp);
176 }
177
178 static int
179 dos_async_rx()
180 {
181 char rv;
182
183 while (!dos_async_ready())
184 if (kbhit())
185 {
186 printf("abort!\n");
187 return 0;
188 }
189
190 rv = *aptr(async->getp++);
191 if (async->getp >= async->buffer_end)
192 async->getp = async->buffer_start;
193
194 return rv;
195 }
196
197 static int
198 dosasync_read (fd, buf, len, timeout)
199 int fd;
200 char *buf;
201 int len;
202 int timeout;
203 {
204 long now, then;
205 int l = len;
206
207 time (&now);
208 then = now + timeout;
209
210 while (l--)
211 {
212 if (timeout)
213 {
214 while (!dos_async_ready())
215 {
216 time (&now);
217 if (now >= then)
218 return len - l - 1;
219 }
220 }
221 *buf++ = dos_async_rx();
222 }
223
224 return len;
225 }
226
227 static int
228 dosasync_write(fd, buf, len)
229 int fd;
230 const char *buf;
231 int len;
232 {
233 int l = len;
234
235 while (l--)
236 dos_async_tx (*buf++);
237
238 return len;
239 }
240
241 static int
242 go32_open (scb, name)
243 serial_t scb;
244 const char *name;
245 {
246 int port;
247
248 if (strncasecmp (name, "com", 3) != 0)
249 {
250 errno = ENOENT;
251 return -1;
252 }
253
254 port = name[3] - '0';
255
256 if ((port != 1) && (port != 2))
257 {
258 errno = ENOENT;
259 return -11;
260 }
261
262 scb->fd = dos_async_init(port);
263 if (!scb->fd)
264 return -1;
265
266 return 0;
267 }
268
269 static int
270 go32_flush_output (scb)
271 serial_t scb;
272 {
273 /* No need to flush, because there is no buffering. */
274 return 0;
275 }
276
277 static void
278 go32_raw (scb)
279 serial_t scb;
280 {
281 /* Always in raw mode */
282 }
283
284 static int
285 go32_readchar (scb, timeout)
286 serial_t scb;
287 int timeout;
288 {
289 char buf;
290
291 if (dosasync_read(scb->fd, &buf, 1, timeout))
292 return buf;
293 else
294 return SERIAL_TIMEOUT;
295 }
296
297 /* go32_{get set}_tty_state() are both dummys to fill out the function
298 vector. Someday, they may do something real... */
299
300 static serial_ttystate
301 go32_get_tty_state(scb)
302 serial_t scb;
303 {
304 struct go32_ttystate *state;
305
306 state = (struct go32_ttystate *)xmalloc(sizeof *state);
307
308 return (serial_ttystate)state;
309 }
310
311 static int
312 go32_set_tty_state(scb, ttystate)
313 serial_t scb;
314 serial_ttystate ttystate;
315 {
316 struct go32_ttystate *state;
317
318 return 0;
319 }
320
321 static int
322 go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
323 serial_t scb;
324 serial_ttystate new_ttystate;
325 serial_ttystate old_ttystate;
326 {
327 return 0;
328 }
329
330 static void
331 go32_print_tty_state (scb, ttystate)
332 serial_t scb;
333 serial_ttystate ttystate;
334 {
335 /* Nothing to print. */
336 return;
337 }
338
339 static int
340 go32_setbaudrate (scb, rate)
341 serial_t scb;
342 int rate;
343 {
344 return 0;
345 }
346
347 static int
348 go32_set_process_group (scb, ttystate, group)
349 serial_t scb;
350 serial_ttystate ttystate;
351 int group;
352 {
353 return 0;
354 }
355
356 static int
357 go32_write (scb, str, len)
358 serial_t scb;
359 const char *str;
360 int len;
361 {
362 dosasync_write(scb->fd, str, len);
363
364 return 0;
365 }
366
367 static void
368 go32_close (scb)
369 serial_t scb;
370 {
371 }
372
373 static struct serial_ops go32_ops =
374 {
375 "hardwire",
376 0,
377 go32_open,
378 go32_close,
379 go32_readchar,
380 go32_write,
381 go32_flush_output,
382 go32_raw,
383 go32_get_tty_state,
384 go32_set_tty_state,
385 go32_print_tty_state,
386 go32_noflush_set_tty_state,
387 go32_setbaudrate,
388 go32_set_process_group
389 };
390
391 /* There is never job control on go32. */
392 int
393 gdb_setpgid ()
394 {
395 return 0;
396 }
397
398 _initialize_ser_go32 ()
399 {
400 job_control = 0;
401 serial_add_interface (&go32_ops);
402 }
This page took 0.050865 seconds and 4 git commands to generate.