spelling fix.
[deliverable/binutils-gdb.git] / gdb / ser-e7kpc.c
CommitLineData
55679787 1/* Remote serial interface using Hitachi E7000 PC ISA card in a PC
897ccbb0 2 Copyright 1994, 1999 Free Software Foundation, Inc.
55679787 3
897ccbb0 4This file is part of GDB.
55679787 5
897ccbb0
JM
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.
55679787 10
897ccbb0
JM
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.
55679787 15
897ccbb0
JM
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16a43bf4 19
4ce7ba51
SG
20#if defined __GO32__ || defined _WIN32
21#include "defs.h"
22#include "serial.h"
23#include "gdb_string.h"
16a43bf4 24
4ce7ba51 25/* MSVC uses strnicmp instead of strncasecmp */
16a43bf4 26#ifdef _MSC_VER
5b59224e 27#define strncasecmp strnicmp
4ce7ba51 28#define WIN32_LEAN_AND_MEAN
c1937db3
AC
29#endif
30
31#ifdef _WIN32
4ce7ba51 32#include <windows.h>
16a43bf4 33#endif
16a43bf4 34
4ce7ba51 35#ifdef __GO32__
5b59224e 36#include <sys/dos.h>
4ce7ba51 37#endif
55679787
SC
38
39static int e7000pc_open PARAMS ((serial_t scb, const char *name));
40static void e7000pc_raw PARAMS ((serial_t scb));
41static int e7000pc_readchar PARAMS ((serial_t scb, int timeout));
42static int e7000pc_setbaudrate PARAMS ((serial_t scb, int rate));
43static int e7000pc_write PARAMS ((serial_t scb, const char *str, int len));
44static void e7000pc_close PARAMS ((serial_t scb));
45static serial_ttystate e7000pc_get_tty_state PARAMS ((serial_t scb));
46static int e7000pc_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
55679787
SC
47
48#define OFF_DPD 0x0000
49#define OFF_DDP 0x1000
50#define OFF_CPD 0x2000
51#define OFF_CDP 0x2400
52#define OFF_FA 0x3000
53#define OFF_FB 0x3002
54#define OFF_FC 0x3004
55#define OFF_IRQTOD 0x3008
56#define OFF_IRQTOP 0x300a
57#define OFF_READY 0x300c
58#define OFF_PON 0x300e
59
60#define IDLE 0x0000
61#define CMD_CI 0x4349
62#define CMD_CO 0x434f
63#define CMD_LO 0x4c4f
64#define CMD_LS 0x4c53
65#define CMD_SV 0x5356
66#define CMD_SS 0x5353
67#define CMD_OK 0x4f4b
68#define CMD_ER 0x4552
69#define CMD_NF 0x4e46
70#define CMD_AB 0x4142
71#define CMD_ED 0x4544
72#define CMD_CE 0x4345
73
74static unsigned long fa;
75static unsigned long irqtod;
76static unsigned long ready;
77static unsigned long fb;
78static unsigned long cpd ;
79static unsigned long cdp ;
80static unsigned long ready;
81static unsigned long pon;
82static unsigned long irqtop;
83static unsigned long board_at;
84
4ce7ba51 85#ifdef __GO32__
5b59224e 86
55679787
SC
87#define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
88#define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
89#define GET_BYTE(x) ( dosmemget(x,1,&bb), bb)
90#define GET_WORD(x) ( dosmemget(x,2,&sb), sb)
55679787
SC
91static unsigned char bb;
92static unsigned short sb;
93
4ce7ba51
SG
94#else /* win32 */
95
96#define SET_BYTE(x,y) *(volatile unsigned char *)(x) = (y)
97#define SET_WORD(x,y) *(volatile unsigned short *)(x) = (y)
98#define GET_BYTE(x) (*(volatile unsigned char *)(x))
99#define GET_WORD(x) (*(volatile unsigned short *)(x))
100#define dosmemget(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
101#define dosmemput(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
102#endif
55679787
SC
103
104static struct sw
105{
106 int sw;
107 int addr;
108} sigs[] = {
109 {0x14, 0xd0000},
110 {0x15, 0xd4000},
111 {0x16, 0xd8000},
112 {0x17, 0xdc000},
113 0};
114
c1937db3 115#ifdef _MSC_VER
4ce7ba51
SG
116/* Get the base of the data segment. This is needed to calculate the offset
117 between data segment addresses and the base of linear memory, which is where
118 device registers reside. Note that this is really only necessary for
119 Win32s, since Win95 and NT keep the data segment at linear 0. */
120
121static unsigned long
122get_ds_base (void)
123{
124 unsigned short dsval;
125 LDT_ENTRY ldt;
126 unsigned long dsbase;
127
128 __asm
129 {
130 mov dsval,ds
131 }
132
133 dsbase = 0;
134
135 GetThreadSelectorEntry (GetCurrentThread(), dsval, &ldt);
136
137 dsbase = ldt.HighWord.Bits.BaseHi << 24 | ldt.HighWord.Bits.BaseMid << 16
138 | ldt.BaseLow;
139
140 return dsbase;
141}
c1937db3 142#else /* !_MSC_VER */
4ce7ba51 143#define get_ds_base() 0
c1937db3 144#endif /* _MSC_VER */
4ce7ba51 145
55679787
SC
146static int
147e7000pc_init ()
148{
55679787 149 int try;
4ce7ba51 150 unsigned long dsbase;
55679787 151
4ce7ba51 152 dsbase = get_ds_base ();
55679787 153
4ce7ba51
SG
154 /* Look around in memory for the board's signature */
155
156 for (try = 0; sigs[try].sw; try++)
55679787
SC
157 {
158 int val;
4ce7ba51 159 board_at = sigs[try].addr - dsbase;
55679787
SC
160 fa = board_at + OFF_FA;
161 fb = board_at + OFF_FB;
162 cpd = board_at + OFF_CPD;
163 cdp = board_at + OFF_CDP;
164 ready =board_at + OFF_READY;
165 pon = board_at + OFF_PON;
166 irqtop = board_at + OFF_IRQTOP;
167 irqtod = board_at + OFF_IRQTOD;
4ce7ba51 168
55679787
SC
169 val = GET_WORD (ready);
170
171 if (val == (0xaaa0 | sigs[try].sw))
172 {
4ce7ba51 173 if (GET_WORD (pon) & 0xf)
55679787 174 {
4ce7ba51
SG
175 SET_WORD (fa, 0);
176 SET_WORD (fb, 0);
55679787 177
4ce7ba51 178 SET_WORD (irqtop, 1); /* Disable interrupts from e7000 */
55679787
SC
179 SET_WORD (ready, 1);
180 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
181 sigs[try].addr);
182 return 1;
183 }
184 error ("The E7000 PC board is working, but the E7000 is turned off.\n");
185 return 0;
186 }
187 }
188
189 error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
190and that the switch settings are correct. Some other DOS programs can \n\
191stop the board from working. Try starting from a very minimal boot, \n\
192perhaps you need to disable EMM386 over the region where the board has\n\
193its I/O space, remove other unneeded cards, etc etc\n");
194 return 0;
195
196}
197
198static int pbuf_size;
199static int pbuf_index;
200
4ce7ba51
SG
201/* Return next byte from cdp. If no more, then return -1. */
202
203static int
204e7000_get (void)
55679787
SC
205{
206 static char pbuf[1000];
207 char tmp[1000];
208 int x;
4ce7ba51 209
55679787
SC
210 if (pbuf_index < pbuf_size)
211 {
212 x = pbuf[pbuf_index++];
213 }
4ce7ba51 214 else if ((GET_WORD (fb) & 1))
55679787
SC
215 {
216 int i;
4ce7ba51 217 pbuf_size = GET_WORD (cdp + 2);
55679787
SC
218
219 dosmemget (cdp + 8, pbuf_size + 1, tmp);
220
221 /* Tell the E7000 we've eaten */
4ce7ba51 222 SET_WORD (fb, 0);
55679787
SC
223 /* Swap it around */
224 for (i = 0; i < pbuf_size; i++)
225 {
226 pbuf[i] = tmp[i^1];
227 }
228 pbuf_index = 0;
229 x = pbuf[pbuf_index++];
230 }
231 else
232 {
233 x = -1;
234 }
235 return x;
236}
237
4ce7ba51
SG
238/* Works just like read(), except that it takes a TIMEOUT in seconds. Note
239 that TIMEOUT == 0 is a poll, and TIMEOUT == -1 means wait forever. */
240
55679787
SC
241static int
242dosasync_read (fd, buf, len, timeout)
243 int fd;
244 char *buf;
245 int len;
246 int timeout;
247
248{
249 long now;
250 long then;
251 int i = 0;
55679787
SC
252
253 /* Then look for some more if we're still hungry */
254 time (&now);
255 then = now + timeout;
256 while (i < len)
257 {
258 int ch = e7000_get();
259
260 /* While there's room in the buffer, and we've already
4ce7ba51 261 read the stuff in, suck it over */
55679787
SC
262 if (ch != -1)
263 {
264 buf[i++] = ch;
265 while (i < len && pbuf_index < pbuf_size )
266 {
267 ch = e7000_get();
268 if (ch == -1)
269 break;
270 buf[i++] = ch;
271 }
272 }
273
274 time (&now);
275
4ce7ba51
SG
276 if (timeout == 0)
277 return i;
278 if (now >= then && timeout > 0)
55679787
SC
279 {
280 return i;
281 }
282 }
283 return len;
284}
285
286
287static int
288dosasync_write (fd, buf, len)
289 int fd;
290 const char *buf;
291 int len;
292{
293 int i;
294 char dummy[1000];
55679787
SC
295
296 /* Construct copy locally */
297 ((short *)dummy)[0] = CMD_CI;
298 ((short *)dummy)[1] = len;
299 ((short *)dummy)[2] = 0;
300 ((short *)dummy)[3] = 0;
301 for (i = 0; i < len ; i++)
302 {
303 dummy[8 + i ^ 1] = buf[i];
304 }
305
306 /* Wait for the card to get ready */
4ce7ba51 307 while (GET_WORD (fa) & 1) ;
55679787
SC
308
309 /* Blast onto the ISA card */
310 dosmemput (dummy, 8 + len + 1, cpd);
311
4ce7ba51
SG
312 SET_WORD (fa, 1);
313 SET_WORD (irqtod, 1); /* Interrupt the E7000 */
55679787
SC
314
315 return len;
316}
317
318static int
319e7000pc_open (scb, name)
320 serial_t scb;
321 const char *name;
322{
323 if (strncasecmp (name, "pc", 2) != 0)
324 {
325 errno = ENOENT;
326 return -1;
327 }
4ce7ba51 328
55679787
SC
329 scb->fd = e7000pc_init ();
330
331 if (!scb->fd)
332 return -1;
333
334 return 0;
335}
336
337static int
338e7000pc_noop (scb)
339 serial_t scb;
340{
341 return 0;
342}
343
344static void
345e7000pc_raw (scb)
346 serial_t scb;
347{
348 /* Always in raw mode */
349}
350
351static int
352e7000pc_readchar (scb, timeout)
353 serial_t scb;
354 int timeout;
355{
356 char buf;
357
358 top:
359
360 if (dosasync_read (scb->fd, &buf, 1, timeout))
361 {
362 if (buf == 0) goto top;
363 return buf;
364 }
365 else
366 return SERIAL_TIMEOUT;
367}
368
369struct e7000pc_ttystate {
370 int dummy;
371};
372
373/* e7000pc_{get set}_tty_state() are both dummys to fill out the function
374 vector. Someday, they may do something real... */
375
376static serial_ttystate
377e7000pc_get_tty_state (scb)
378 serial_t scb;
379{
380 struct e7000pc_ttystate *state;
381
382 state = (struct e7000pc_ttystate *) xmalloc (sizeof *state);
383
384 return (serial_ttystate) state;
385}
386
387static int
388e7000pc_set_tty_state (scb, ttystate)
389 serial_t scb;
390 serial_ttystate ttystate;
391{
392 return 0;
393}
394
395static int
396e7000pc_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
397 serial_t scb;
398 serial_ttystate new_ttystate;
399 serial_ttystate old_ttystate;
400{
401 return 0;
402}
403
404static void
405e7000pc_print_tty_state (scb, ttystate)
406 serial_t scb;
407 serial_ttystate ttystate;
408{
409 /* Nothing to print. */
410 return;
411}
412
413static int
414e7000pc_setbaudrate (scb, rate)
415 serial_t scb;
416 int rate;
417{
418 return 0;
419}
420
421static int
422e7000pc_write (scb, str, len)
423 serial_t scb;
424 const char *str;
425 int len;
426{
427 dosasync_write (scb->fd, str, len);
428
429 return 0;
430}
431
432static void
433e7000pc_close (scb)
434 serial_t scb;
435{
436}
437
438static struct serial_ops e7000pc_ops =
439{
440 "pc",
441 0,
442 e7000pc_open,
443 e7000pc_close,
444 e7000pc_readchar,
445 e7000pc_write,
446 e7000pc_noop, /* flush output */
447 e7000pc_noop, /* flush input */
448 e7000pc_noop, /* send break -- currently used only for nindy */
449 e7000pc_raw,
450 e7000pc_get_tty_state,
451 e7000pc_set_tty_state,
452 e7000pc_print_tty_state,
453 e7000pc_noflush_set_tty_state,
454 e7000pc_setbaudrate,
3ffbdf15 455 e7000pc_noop, /* wait for output to drain */
55679787
SC
456};
457
458void
459_initialize_ser_e7000pc ()
460{
461 serial_add_interface (&e7000pc_ops);
462}
463#else
464
465void
466_initialize_ser_e7000pc ()
467{
468
469}
4ce7ba51 470#endif
This page took 0.323766 seconds and 4 git commands to generate.