* remote-udi.c: Remove old comment about download not implemented.
[deliverable/binutils-gdb.git] / gdb / ser-go32.c
CommitLineData
5d2b030a
SG
1/* Remote serial interface for local (hardwired) serial ports for GO32.
2 Copyright 1992, 1993 Free Software Foundation, Inc.
ae0ea72e
SC
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
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. */
25struct go32_ttystate
26{
27 int bogus;
28};
29
452b4b00
SG
30typedef 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
38dc5e12
SG
41static int go32_open PARAMS ((serial_t scb, const char *name));
42static void go32_raw PARAMS ((serial_t scb));
43static int wait_for PARAMS ((serial_t scb, int timeout));
44static int go32_readchar PARAMS ((serial_t scb, int timeout));
45static int rate_to_code PARAMS ((int rate));
46static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
47static int go32_write PARAMS ((serial_t scb, const char *str, int len));
48static void go32_restore PARAMS ((serial_t scb));
49static void go32_close PARAMS ((serial_t scb));
452b4b00 50static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
38dc5e12 51static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
a037b21e 52static int strncasecmp PARAMS ((const char *str1, const char *str2, int len));
38dc5e12
SG
53static char *aptr PARAMS ((short p));
54static ASYNC_STRUCT *getivec PARAMS ((int which));
55static int dos_async_init PARAMS ((int port));
56static void dos_async_tx PARAMS ((const char c));
57static int dos_async_ready PARAMS (());
58static int dos_async_rx PARAMS (());
59static int dosasync_read PARAMS ((int fd, char *buf, int len, int timeout));
452b4b00 60static int dosasync_write PARAMS ((int fd, const char *buf, int len));
38dc5e12 61
ae0ea72e
SC
62#define SIGNATURE 0x4154
63#define VERSION 1
64#define OFFSET 0x104
65
ae0ea72e 66#define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
ae0ea72e 67
5d2b030a 68static ASYNC_STRUCT *async;
ae0ea72e
SC
69static 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
b83bf6b3
SG
79static int
80strncasecmp(str1, str2, len)
a037b21e 81 const char *str1, *str2;
b83bf6b3
SG
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}
b52373a2 99
5d2b030a
SG
100static char *
101aptr(p)
102 short p;
ae0ea72e 103{
ae0ea72e 104 return (char *)((unsigned)async - OFFSET + p);
ae0ea72e
SC
105}
106
5d2b030a 107static ASYNC_STRUCT *
b52373a2 108getivec(int which)
ae0ea72e 109{
5d2b030a 110 ASYNC_STRUCT *a;
ae0ea72e
SC
111
112 if (peek(0, which*4) != OFFSET)
113 return 0;
b83bf6b3 114
ae0ea72e
SC
115 a = (ASYNC_STRUCT *)(0xe0000000 + peek(0, which*4+2)*16 + peek(0, which*4));
116
ae0ea72e
SC
117 if (a->signature != SIGNATURE)
118 return 0;
b83bf6b3 119
ae0ea72e
SC
120 if (a->version != VERSION)
121 return 0;
b83bf6b3 122
ae0ea72e
SC
123 return a;
124}
125
5d2b030a 126static int
b83bf6b3
SG
127dos_async_init(port)
128 int port;
ae0ea72e
SC
129{
130 int i;
b83bf6b3
SG
131
132 switch (port)
07861607 133 {
b83bf6b3
SG
134 case 1:
135 async = getivec (12);
136 break;
137 case 2:
138 async = getivec (11);
139 break;
140 default:
141 return 0;
07861607
SG
142 }
143
b83bf6b3 144 if (!async)
07861607 145 {
a037b21e 146 error("GDB cannot connect to asynctsr program, check that it is installed\n\
ae0ea72e
SC
147and that serial I/O is not being redirected (perhaps by NFS)\n\n\
148example configuration:\n\
a037b21e
SG
149C> mode com%d:9600,n,8,1,p\n\
150C> asynctsr %d\n\
151C> gdb \n", port, port);
07861607
SG
152 }
153
ae0ea72e
SC
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
b83bf6b3 160 return 1;
ae0ea72e
SC
161}
162
5d2b030a
SG
163static void
164dos_async_tx(c)
165 const char c;
ae0ea72e 166{
ae0ea72e 167 while (~inportb(com_lsr) & 0x20);
5d2b030a 168
ae0ea72e 169 outportb(com_tb, c);
ae0ea72e
SC
170}
171
5d2b030a 172static int
b52373a2 173dos_async_ready()
ae0ea72e
SC
174{
175 return (async->getp != async->putp);
176}
177
5d2b030a 178static int
b52373a2 179dos_async_rx()
ae0ea72e
SC
180{
181 char rv;
5d2b030a 182
ae0ea72e 183 while (!dos_async_ready())
5d2b030a
SG
184 if (kbhit())
185 {
186 printf("abort!\n");
187 return 0;
188 }
189
ae0ea72e 190 rv = *aptr(async->getp++);
ae0ea72e 191 if (async->getp >= async->buffer_end)
5d2b030a 192 async->getp = async->buffer_start;
ae0ea72e 193
5d2b030a 194 return rv;
ae0ea72e
SC
195}
196
5d2b030a
SG
197static int
198dosasync_read (fd, buf, len, timeout)
199 int fd;
200 char *buf;
201 int len;
202 int timeout;
ae0ea72e
SC
203{
204 long now, then;
5d2b030a
SG
205 int l = len;
206
ae0ea72e 207 time (&now);
5d2b030a
SG
208 then = now + timeout;
209
ae0ea72e 210 while (l--)
ae0ea72e 211 {
5d2b030a
SG
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();
ae0ea72e 222 }
ae0ea72e 223
5d2b030a 224 return len;
ae0ea72e
SC
225}
226
5d2b030a
SG
227static int
228dosasync_write(fd, buf, len)
229 int fd;
230 const char *buf;
231 int len;
232{
233 int l = len;
ae0ea72e 234
5d2b030a
SG
235 while (l--)
236 dos_async_tx (*buf++);
ae0ea72e 237
5d2b030a 238 return len;
ae0ea72e
SC
239}
240
5d2b030a
SG
241static int
242go32_open (scb, name)
243 serial_t scb;
244 const char *name;
b52373a2 245{
b83bf6b3
SG
246 int port;
247
248 if (strncasecmp (name, "com", 3) != 0)
249 {
250 errno = ENOENT;
4febd102 251 return -1;
b83bf6b3
SG
252 }
253
254 port = name[3] - '0';
255
256 if ((port != 1) && (port != 2))
257 {
258 errno = ENOENT;
4febd102 259 return -11;
b83bf6b3
SG
260 }
261
262 scb->fd = dos_async_init(port);
07861607 263 if (!scb->fd)
4febd102 264 return -1;
ae0ea72e 265
5d2b030a 266 return 0;
ae0ea72e
SC
267}
268
c2e247c4
JK
269static int
270go32_flush_output (scb)
271 serial_t scb;
272{
273 /* No need to flush, because there is no buffering. */
274 return 0;
275}
276
5d2b030a
SG
277static void
278go32_raw (scb)
279 serial_t scb;
ae0ea72e 280{
5d2b030a 281 /* Always in raw mode */
ae0ea72e
SC
282}
283
5d2b030a
SG
284static int
285go32_readchar (scb, timeout)
286 serial_t scb;
287 int timeout;
ae0ea72e
SC
288{
289 char buf;
5d2b030a
SG
290
291 if (dosasync_read(scb->fd, &buf, 1, timeout))
5a6242dd 292 return buf;
ae0ea72e 293 else
4febd102 294 return SERIAL_TIMEOUT;
ae0ea72e
SC
295}
296
38dc5e12
SG
297/* go32_{get set}_tty_state() are both dummys to fill out the function
298 vector. Someday, they may do something real... */
299
300static serial_ttystate
301go32_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
311static int
312go32_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
c2e247c4
JK
321static int
322go32_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
330static void
331go32_print_tty_state (scb, ttystate)
332 serial_t scb;
333 serial_ttystate ttystate;
334{
335 /* Nothing to print. */
336 return;
337}
338
5d2b030a
SG
339static int
340go32_setbaudrate (scb, rate)
341 serial_t scb;
342 int rate;
ae0ea72e
SC
343{
344 return 0;
345}
346
c2e247c4
JK
347static int
348go32_set_process_group (scb, ttystate, group)
349 serial_t scb;
350 serial_ttystate ttystate;
351 int group;
352{
353 return 0;
354}
355
5d2b030a
SG
356static int
357go32_write (scb, str, len)
358 serial_t scb;
359 const char *str;
360 int len;
361{
362 dosasync_write(scb->fd, str, len);
4febd102
SG
363
364 return 0;
5d2b030a
SG
365}
366
367static void
452b4b00
SG
368go32_close (scb)
369 serial_t scb;
ae0ea72e 370{
ae0ea72e
SC
371}
372
5d2b030a
SG
373static struct serial_ops go32_ops =
374{
375 "hardwire",
376 0,
377 go32_open,
378 go32_close,
379 go32_readchar,
380 go32_write,
c2e247c4 381 go32_flush_output,
5d2b030a 382 go32_raw,
38dc5e12
SG
383 go32_get_tty_state,
384 go32_set_tty_state,
c2e247c4
JK
385 go32_print_tty_state,
386 go32_noflush_set_tty_state,
387 go32_setbaudrate,
388 go32_set_process_group
5d2b030a
SG
389};
390
c2e247c4
JK
391/* There is never job control on go32. */
392int
393gdb_setpgid ()
394{
395 return 0;
396}
397
5d2b030a 398_initialize_ser_go32 ()
ae0ea72e 399{
c2e247c4 400 job_control = 0;
5d2b030a 401 serial_add_interface (&go32_ops);
ae0ea72e 402}
This page took 0.122375 seconds and 4 git commands to generate.