1 /* Remote serial interface using Hitachi E7000 PC ISA card in a PC
3 Copyright 1994 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 static int e7000pc_open PARAMS ((serial_t scb, const char *name));
29 static void e7000pc_raw PARAMS ((serial_t scb));
30 static int e7000pc_readchar PARAMS ((serial_t scb, int timeout));
31 static int e7000pc_setbaudrate PARAMS ((serial_t scb, int rate));
32 static int e7000pc_write PARAMS ((serial_t scb, const char *str, int len));
33 static void e7000pc_close PARAMS ((serial_t scb));
34 static serial_ttystate e7000pc_get_tty_state PARAMS ((serial_t scb));
35 static int e7000pc_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
36 static char *aptr PARAMS ((short p));
38 static int dos_async_init PARAMS ((int port));
39 static void dos_async_tx PARAMS ((const char c));
40 static int dos_async_rx PARAMS (());
44 #define OFF_DPD 0x0000
45 #define OFF_DDP 0x1000
46 #define OFF_CPD 0x2000
47 #define OFF_CDP 0x2400
51 #define OFF_IRQTOD 0x3008
52 #define OFF_IRQTOP 0x300a
53 #define OFF_READY 0x300c
54 #define OFF_PON 0x300e
70 static unsigned long fa;
71 static unsigned long irqtod;
72 static unsigned long ready;
73 static unsigned long fb;
74 static unsigned long cpd ;
75 static unsigned long cdp ;
76 static unsigned long ready;
77 static unsigned long pon;
78 static unsigned long irqtop;
79 static unsigned long board_at;
81 #define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
82 #define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
83 #define GET_BYTE(x) ( dosmemget(x,1,&bb), bb)
84 #define GET_WORD(x) ( dosmemget(x,2,&sb), sb)
86 static unsigned char bb;
87 static unsigned short sb;
104 /* Look around in memory for the board's signature */
108 for (try = 0; sigs[try].sw; try++)
112 board_at = sigs[try].addr;
113 fa = board_at + OFF_FA;
114 fb = board_at + OFF_FB;
115 cpd = board_at + OFF_CPD;
116 cdp = board_at + OFF_CDP;
117 ready =board_at + OFF_READY;
118 pon = board_at + OFF_PON;
119 irqtop = board_at + OFF_IRQTOP;
120 irqtod = board_at + OFF_IRQTOD;
122 val = GET_WORD (ready);
124 if (val == (0xaaa0 | sigs[try].sw))
126 if (GET_BYTE (pon) & 0xf)
131 SET_BYTE (irqtop, 1); /* Disable interrupts from e7000 */
133 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
137 error ("The E7000 PC board is working, but the E7000 is turned off.\n");
142 error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
143 and that the switch settings are correct. Some other DOS programs can \n\
144 stop the board from working. Try starting from a very minimal boot, \n\
145 perhaps you need to disable EMM386 over the region where the board has\n\
146 its I/O space, remove other unneeded cards, etc etc\n");
151 static int pbuf_size;
152 static int pbuf_index;
158 static char pbuf[1000];
161 if (pbuf_index < pbuf_size)
163 x = pbuf[pbuf_index++];
165 else if ((GET_BYTE (fb) & 1))
168 pbuf_size = GET_WORD(cdp + 2);
170 dosmemget (cdp + 8, pbuf_size + 1, tmp);
172 /* Tell the E7000 we've eaten */
175 for (i = 0; i < pbuf_size; i++)
180 x = pbuf[pbuf_index++];
190 dosasync_read (fd, buf, len, timeout)
202 /* Then look for some more if we're still hungry */
204 then = now + timeout;
207 int ch = e7000_get();
209 /* While there's room in the buffer, and we've already
210 read the stuff in, suck it over */
214 while (i < len && pbuf_index < pbuf_size )
227 if (now >= then && timeout > 0)
237 dosasync_write (fd, buf, len)
246 /* Construct copy locally */
247 ((short *)dummy)[0] = CMD_CI;
248 ((short *)dummy)[1] = len;
249 ((short *)dummy)[2] = 0;
250 ((short *)dummy)[3] = 0;
251 for (i = 0; i < len ; i++)
253 dummy[8 + i ^ 1] = buf[i];
256 /* Wait for the card to get ready */
257 while ((GET_BYTE(fa) & 1) != 0)
260 /* Blast onto the ISA card */
261 dosmemput (dummy, 8 + len + 1, cpd);
264 SET_BYTE(irqtod, 1); /* Interrupt the E7000 */
270 e7000pc_open (scb, name)
274 if (strncasecmp (name, "pc", 2) != 0)
280 scb->fd = e7000pc_init ();
299 /* Always in raw mode */
303 e7000pc_readchar (scb, timeout)
311 if (dosasync_read (scb->fd, &buf, 1, timeout))
313 if (buf == 0) goto top;
317 return SERIAL_TIMEOUT;
320 struct e7000pc_ttystate {
324 /* e7000pc_{get set}_tty_state() are both dummys to fill out the function
325 vector. Someday, they may do something real... */
327 static serial_ttystate
328 e7000pc_get_tty_state (scb)
331 struct e7000pc_ttystate *state;
333 state = (struct e7000pc_ttystate *) xmalloc (sizeof *state);
335 return (serial_ttystate) state;
339 e7000pc_set_tty_state (scb, ttystate)
341 serial_ttystate ttystate;
347 e7000pc_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
349 serial_ttystate new_ttystate;
350 serial_ttystate old_ttystate;
356 e7000pc_print_tty_state (scb, ttystate)
358 serial_ttystate ttystate;
360 /* Nothing to print. */
365 e7000pc_setbaudrate (scb, rate)
373 e7000pc_write (scb, str, len)
378 dosasync_write (scb->fd, str, len);
389 static struct serial_ops e7000pc_ops =
397 e7000pc_noop, /* flush output */
398 e7000pc_noop, /* flush input */
399 e7000pc_noop, /* send break -- currently used only for nindy */
401 e7000pc_get_tty_state,
402 e7000pc_set_tty_state,
403 e7000pc_print_tty_state,
404 e7000pc_noflush_set_tty_state,
409 _initialize_ser_e7000pc ()
411 serial_add_interface (&e7000pc_ops);
416 _initialize_ser_e7000pc ()