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