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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #if defined(__GO32__) || defined(__WIN32__)
22 #if defined(__WIN32__)
25 //#include <windows.h>
26 /* we define the 32-bit calls which thunk to 16-bit dll calls
28 #include "win-e7kpc.h"
29 /* msvc uses strnicmp instead */
30 #define strncasecmp strnicmp
38 static int e7000pc_open PARAMS ((serial_t scb, const char *name));
39 static void e7000pc_raw PARAMS ((serial_t scb));
40 static int e7000pc_readchar PARAMS ((serial_t scb, int timeout));
41 static int e7000pc_setbaudrate PARAMS ((serial_t scb, int rate));
42 static int e7000pc_write PARAMS ((serial_t scb, const char *str, int len));
43 static void e7000pc_close PARAMS ((serial_t scb));
44 static serial_ttystate e7000pc_get_tty_state PARAMS ((serial_t scb));
45 static int e7000pc_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
46 static char *aptr PARAMS ((short p));
48 static int dos_async_init PARAMS ((int port));
49 static void dos_async_tx PARAMS ((const char c));
50 static int dos_async_rx PARAMS (());
54 #define OFF_DPD 0x0000
55 #define OFF_DDP 0x1000
56 #define OFF_CPD 0x2000
57 #define OFF_CDP 0x2400
61 #define OFF_IRQTOD 0x3008
62 #define OFF_IRQTOP 0x300a
63 #define OFF_READY 0x300c
64 #define OFF_PON 0x300e
80 static unsigned long fa;
81 static unsigned long irqtod;
82 static unsigned long ready;
83 static unsigned long fb;
84 static unsigned long cpd ;
85 static unsigned long cdp ;
86 static unsigned long ready;
87 static unsigned long pon;
88 static unsigned long irqtop;
89 static unsigned long board_at;
92 // These routines are normally part of the go32 dos extender.
93 // We redefine them here to be calls into their Windoze equivs.
94 static void dosmemget(int offset, int length, void *buffer);
95 static void dosmemput(const void *buffer, int length, int offset);
97 void dosmemget(int offset, int length, void *buffer)
99 win_mem_get(buffer, length, offset);
101 void dosmemput(const void *buffer, int length, int offset)
103 win_mem_put (buffer, length, offset);
108 #define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
109 #define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
110 #define GET_BYTE(x) ( dosmemget(x,1,&bb), bb)
111 #define GET_WORD(x) ( dosmemget(x,2,&sb), sb)
113 static unsigned char bb;
114 static unsigned short sb;
131 /* Look around in memory for the board's signature */
135 for (try = 0; sigs[try].sw; try++)
139 board_at = sigs[try].addr;
140 fa = board_at + OFF_FA;
141 fb = board_at + OFF_FB;
142 cpd = board_at + OFF_CPD;
143 cdp = board_at + OFF_CDP;
144 ready =board_at + OFF_READY;
145 pon = board_at + OFF_PON;
146 irqtop = board_at + OFF_IRQTOP;
147 irqtod = board_at + OFF_IRQTOD;
149 val = GET_WORD (ready);
151 if (val == (0xaaa0 | sigs[try].sw))
153 if (GET_BYTE (pon) & 0xf)
158 SET_BYTE (irqtop, 1); /* Disable interrupts from e7000 */
160 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
164 error ("The E7000 PC board is working, but the E7000 is turned off.\n");
169 error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
170 and that the switch settings are correct. Some other DOS programs can \n\
171 stop the board from working. Try starting from a very minimal boot, \n\
172 perhaps you need to disable EMM386 over the region where the board has\n\
173 its I/O space, remove other unneeded cards, etc etc\n");
178 static int pbuf_size;
179 static int pbuf_index;
185 static char pbuf[1000];
188 if (pbuf_index < pbuf_size)
190 x = pbuf[pbuf_index++];
192 else if ((GET_BYTE (fb) & 1))
195 pbuf_size = GET_WORD(cdp + 2);
197 dosmemget (cdp + 8, pbuf_size + 1, tmp);
199 /* Tell the E7000 we've eaten */
202 for (i = 0; i < pbuf_size; i++)
207 x = pbuf[pbuf_index++];
217 dosasync_read (fd, buf, len, timeout)
229 /* Then look for some more if we're still hungry */
231 then = now + timeout;
234 int ch = e7000_get();
236 /* While there's room in the buffer, and we've already
237 read the stuff in, suck it over */
241 while (i < len && pbuf_index < pbuf_size )
254 if (now >= then && timeout > 0)
264 dosasync_write (fd, buf, len)
273 /* Construct copy locally */
274 ((short *)dummy)[0] = CMD_CI;
275 ((short *)dummy)[1] = len;
276 ((short *)dummy)[2] = 0;
277 ((short *)dummy)[3] = 0;
278 for (i = 0; i < len ; i++)
280 dummy[8 + i ^ 1] = buf[i];
283 /* Wait for the card to get ready */
284 while ((GET_BYTE(fa) & 1) != 0)
287 /* Blast onto the ISA card */
288 dosmemput (dummy, 8 + len + 1, cpd);
291 SET_BYTE(irqtod, 1); /* Interrupt the E7000 */
297 e7000pc_open (scb, name)
301 if (strncasecmp (name, "pc", 2) != 0)
307 if (win_load_e7kpc () != 0)
313 scb->fd = e7000pc_init ();
332 /* Always in raw mode */
336 e7000pc_readchar (scb, timeout)
344 if (dosasync_read (scb->fd, &buf, 1, timeout))
346 if (buf == 0) goto top;
350 return SERIAL_TIMEOUT;
353 struct e7000pc_ttystate {
357 /* e7000pc_{get set}_tty_state() are both dummys to fill out the function
358 vector. Someday, they may do something real... */
360 static serial_ttystate
361 e7000pc_get_tty_state (scb)
364 struct e7000pc_ttystate *state;
366 state = (struct e7000pc_ttystate *) xmalloc (sizeof *state);
368 return (serial_ttystate) state;
372 e7000pc_set_tty_state (scb, ttystate)
374 serial_ttystate ttystate;
380 e7000pc_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
382 serial_ttystate new_ttystate;
383 serial_ttystate old_ttystate;
389 e7000pc_print_tty_state (scb, ttystate)
391 serial_ttystate ttystate;
393 /* Nothing to print. */
398 e7000pc_setbaudrate (scb, rate)
406 e7000pc_write (scb, str, len)
411 dosasync_write (scb->fd, str, len);
425 static struct serial_ops e7000pc_ops =
433 e7000pc_noop, /* flush output */
434 e7000pc_noop, /* flush input */
435 e7000pc_noop, /* send break -- currently used only for nindy */
437 e7000pc_get_tty_state,
438 e7000pc_set_tty_state,
439 e7000pc_print_tty_state,
440 e7000pc_noflush_set_tty_state,
445 _initialize_ser_e7000pc ()
447 serial_add_interface (&e7000pc_ops);
452 _initialize_ser_e7000pc ()