* Makefile.in (HFILES): Fixup list of nm-*.h files. Add missing ones.
[deliverable/binutils-gdb.git] / gdb / ser-go32.c
CommitLineData
b52373a2 1/* Remote serial interface for GO32, for GDB, the GNU Debugger.
5140562f 2 Copyright 1992 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
b52373a2
JG
20/* This file shows most of the obvious problems of code written for
21 the IBM PC. FIXME. -- gnu@cygnus.com, Sep92 */
22
ae0ea72e
SC
23#include "defs.h"
24#include "serial.h"
25
5140562f 26#include <sys/dos.h>
ae0ea72e
SC
27
28#define SIGNATURE 0x4154
29#define VERSION 1
30#define OFFSET 0x104
31
32/*#define MONO 1*/
33
34#define dprintf if(0)printf
35
36#ifdef __GNUC__
37#define far
38#define peek(a,b) (*(unsigned short *)(0xe0000000 + (a)*16 + (b)))
39#endif
40
41typedef struct {
42 short jmp_op;
43 short signature;
44 short version;
45 short buffer_start;
46 short buffer_end;
47 short getp;
48 short putp;
49 short iov;
50} ASYNC_STRUCT;
51
52static ASYNC_STRUCT far *async;
53static int iov;
54#define com_rb iov
55#define com_tb iov
56#define com_ier iov+1
57#define com_ifr iov+2
58#define com_bfr iov+3
59#define com_mcr iov+4
60#define com_lsr iov+5
61#define com_msr iov+6
62
b52373a2
JG
63static int fd;
64
65
ae0ea72e
SC
66#if MONO
67#include <sys/pc.h>
68static int mono_pos=0;
69#define mono_rx 0x07
70#define mono_tx 0x70
71
b52373a2
JG
72void
73mono_put(char byte, char attr)
ae0ea72e
SC
74{
75 ScreenSecondary[320+mono_pos+80] = 0x0720;
76 ScreenSecondary[320+mono_pos] = (attr<<8) | (byte&0xff);
77 mono_pos = (mono_pos+1) % 1200;
78}
79
80#endif
81
b52373a2
JG
82static char far *
83aptr(short p)
ae0ea72e
SC
84{
85#ifdef __GNUC__
86 return (char *)((unsigned)async - OFFSET + p);
87#else
88 return (char far *)MK_FP(FP_SEG(async), p);
89#endif
90}
91
b52373a2
JG
92static ASYNC_STRUCT far *
93getivec(int which)
ae0ea72e
SC
94{
95 ASYNC_STRUCT far *a;
96
97 if (peek(0, which*4) != OFFSET)
98 return 0;
99#ifdef __GNUC__
100 a = (ASYNC_STRUCT *)(0xe0000000 + peek(0, which*4+2)*16 + peek(0, which*4));
101
102#else
103 a = (ASYNC_STRUCT far *)MK_FP(peek(0,which*4+2),peek(0,which*4));
104#endif
105 if (a->signature != SIGNATURE)
106 return 0;
107 if (a->version != VERSION)
108 return 0;
109 return a;
110}
111
b52373a2
JG
112int
113dos_async_init()
ae0ea72e
SC
114{
115 int i;
116 ASYNC_STRUCT far *a1;
117 ASYNC_STRUCT far *a2;
118 a1 = getivec(12);
119 a2 = getivec(11);
120 async = 0;
121 if (a1)
122 async = a1;
123 if (a2)
124 async = a2;
125 if (a1 && a2)
126 {
127 if (a1 < a2)
128 async = a1;
129 else
130 async = a2;
131 }
132 if (async == 0)
133 {
134 error("GDB can not connect to asynctsr program, check that it is installed\n\
135and that serial I/O is not being redirected (perhaps by NFS)\n\n\
136example configuration:\n\
137C> mode com2:9600,n,8,1,p\n\
138C> asynctsr 2\n\
139C> gdb \n");
140
141 }
142 iov = async->iov;
143 outportb(com_ier, 0x0f);
144 outportb(com_bfr, 0x03);
145 outportb(com_mcr, 0x0b);
146 async->getp = async->putp = async->buffer_start;
147
148#if MONO
149 for (i=0; i<1200; i++)
150 ScreenSecondary[320+i] = 0x0720;
151#endif
152 if (iov > 0x300)
153 return 1;
154 else
155 return 2;
156}
157
b52373a2 158void
ae0ea72e
SC
159dos_async_tx(char c)
160{
161 dprintf("dos_async_tx: enter %x - with IOV %x", c, com_lsr);
162 fflush(stdout);
163 while (~inportb(com_lsr) & 0x20);
164 outportb(com_tb, c);
165#if MONO
166 mono_put(c, mono_tx);
167#endif
168 dprintf("exit\n");
169}
170
b52373a2
JG
171int
172dos_async_ready()
ae0ea72e
SC
173{
174 return (async->getp != async->putp);
175}
176
b52373a2
JG
177int
178dos_async_rx()
ae0ea72e
SC
179{
180 char rv;
181 dprintf("dos_async_rx: enter - ");
182 fflush(stdout);
183 while (!dos_async_ready())
184 if (kbhit())
185 {
186 printf("abort!\n");
187 return 0;
188 }
189 dprintf("async=%x getp=%x\n", async, async->getp);
190 fflush(stdout);
191 rv = *aptr(async->getp++);
192#if MONO
193 mono_put(rv, mono_rx);
194#endif
195 if (async->getp >= async->buffer_end)
196 async->getp = async->buffer_start;
197 dprintf("exit %x\n", rv);
198 return rv;
199}
200
b52373a2
JG
201int
202dos_kb_ready()
ae0ea72e
SC
203{
204 return (peek(0x40,0x1a) != peek(0x40,0x1c));
205}
206
b52373a2
JG
207int
208dos_kb_rx()
ae0ea72e
SC
209{
210#ifdef __GNUC__
211 return getkey();
212#else
213 return getch();
214#endif
215}
216
b52373a2
JG
217int
218dosasync_read (int fd, char *buffer, int length, int timeout)
ae0ea72e
SC
219{
220 long now, then;
221 int l = length;
222 time (&now);
223 then = now+timeout;
224 dprintf("dosasync_read: enter(%d,%d)\n", length, timeout);
225 while (l--)
226 {
227 if (timeout)
228 {
229 while (!dos_async_ready())
230 {
231 time (&now);
232 if (now == then)
233 {
234 dprintf("dosasync_read: timeout(%d)\n", length-l-1);
235 return length-l-1;
236 }
237 }
238 }
239 *buffer++ = dos_async_rx();
240 }
241 dprintf("dosasync_read: exit %d\n", length);
242 return length;
243}
244
b52373a2
JG
245int
246dosasync_write(int fd, const char *buffer, int length)
ae0ea72e
SC
247{
248 int l = length;
249 while (l--)
250 dos_async_tx(*buffer++);
251 return length;
252}
253
254
255
b52373a2
JG
256char *
257strlwr(char *s)
ae0ea72e
SC
258{
259 char *p = s;
260 while (*s)
261 {
262 if ((*s >= 'A') && (*s <= 'Z'))
263 *s += 'a'-'A';
264 s++;
265 }
266 return p;
267}
268
b52373a2
JG
269sigsetmask()
270{
ae0ea72e 271}
b52373a2
JG
272\f
273const char *
274serial_default_name ()
ae0ea72e
SC
275{
276 return "com1";
277}
278
279
280void
b52373a2 281serial_raw ()
ae0ea72e 282{
b52373a2 283 /* Always in raw mode */
ae0ea72e
SC
284}
285
286
287int
b52373a2
JG
288serial_open (name)
289 const char *name;
ae0ea72e
SC
290{
291 fd = dos_async_init();
292 if (fd) return 1;
293 return 0;
294}
295
296int
b52373a2
JG
297serial_timedreadchar (to, ok)
298 int to;
299 int *ok;
ae0ea72e
SC
300{
301 char buf;
b52373a2 302 if (dosasync_read(fd, &buf, 1, to))
ae0ea72e
SC
303 {
304 *ok = 1;
305 }
306 else
307 {
308 *ok = 0;
309 }
310 return buf;
311}
312
313int
b52373a2
JG
314serial_setbaudrate (rate)
315 int rate;
ae0ea72e
SC
316{
317 return 0;
318}
319
320int
b52373a2
JG
321serial_nextbaudrate (rate)
322 int rate;
ae0ea72e
SC
323{
324 return 0;
325}
326
327int
b52373a2
JG
328serial_write (str, len)
329 const char *str;
330 int len;
ae0ea72e
SC
331{
332 dosasync_write(fd, str, len);
333}
334
335int
b52373a2 336serial_close ()
ae0ea72e 337{
ae0ea72e 338}
This page took 0.068628 seconds and 4 git commands to generate.