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