1 /* Remote serial interface using Hitachi E7000 PC ISA card in a PC
2 Copyright 1994, 1999 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #if defined __GO32__ || defined _WIN32
23 #include "gdb_string.h"
25 /* MSVC uses strnicmp instead of strncasecmp */
27 #define strncasecmp strnicmp
28 #define WIN32_LEAN_AND_MEAN
39 static int e7000pc_open PARAMS ((serial_t scb, const char *name));
40 static void e7000pc_raw PARAMS ((serial_t scb));
41 static int e7000pc_readchar PARAMS ((serial_t scb, int timeout));
42 static int e7000pc_setbaudrate PARAMS ((serial_t scb, int rate));
43 static int e7000pc_write PARAMS ((serial_t scb, const char *str, int len));
44 static void e7000pc_close PARAMS ((serial_t scb));
45 static serial_ttystate e7000pc_get_tty_state PARAMS ((serial_t scb));
46 static int e7000pc_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
48 #define OFF_DPD 0x0000
49 #define OFF_DDP 0x1000
50 #define OFF_CPD 0x2000
51 #define OFF_CDP 0x2400
55 #define OFF_IRQTOD 0x3008
56 #define OFF_IRQTOP 0x300a
57 #define OFF_READY 0x300c
58 #define OFF_PON 0x300e
74 static unsigned long fa;
75 static unsigned long irqtod;
76 static unsigned long ready;
77 static unsigned long fb;
78 static unsigned long cpd ;
79 static unsigned long cdp ;
80 static unsigned long ready;
81 static unsigned long pon;
82 static unsigned long irqtop;
83 static unsigned long board_at;
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)
91 static unsigned char bb;
92 static unsigned short sb;
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))
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. */
124 unsigned short dsval;
126 unsigned long dsbase;
135 GetThreadSelectorEntry (GetCurrentThread(), dsval, &ldt);
137 dsbase = ldt.HighWord.Bits.BaseHi << 24 | ldt.HighWord.Bits.BaseMid << 16
142 #else /* !_MSC_VER */
143 #define get_ds_base() 0
144 #endif /* _MSC_VER */
150 unsigned long dsbase;
152 dsbase = get_ds_base ();
154 /* Look around in memory for the board's signature */
156 for (try = 0; sigs[try].sw; try++)
159 board_at = sigs[try].addr - dsbase;
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;
169 val = GET_WORD (ready);
171 if (val == (0xaaa0 | sigs[try].sw))
173 if (GET_WORD (pon) & 0xf)
178 SET_WORD (irqtop, 1); /* Disable interrupts from e7000 */
180 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
184 error ("The E7000 PC board is working, but the E7000 is turned off.\n");
189 error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
190 and that the switch settings are correct. Some other DOS programs can \n\
191 stop the board from working. Try starting from a very minimal boot, \n\
192 perhaps you need to disable EMM386 over the region where the board has\n\
193 its I/O space, remove other unneeded cards, etc etc\n");
198 static int pbuf_size;
199 static int pbuf_index;
201 /* Return next byte from cdp. If no more, then return -1. */
206 static char pbuf[1000];
210 if (pbuf_index < pbuf_size)
212 x = pbuf[pbuf_index++];
214 else if ((GET_WORD (fb) & 1))
217 pbuf_size = GET_WORD (cdp + 2);
219 dosmemget (cdp + 8, pbuf_size + 1, tmp);
221 /* Tell the E7000 we've eaten */
224 for (i = 0; i < pbuf_size; i++)
229 x = pbuf[pbuf_index++];
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. */
242 dosasync_read (fd, buf, len, timeout)
253 /* Then look for some more if we're still hungry */
255 then = now + timeout;
258 int ch = e7000_get();
260 /* While there's room in the buffer, and we've already
261 read the stuff in, suck it over */
265 while (i < len && pbuf_index < pbuf_size )
278 if (now >= then && timeout > 0)
288 dosasync_write (fd, buf, len)
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++)
303 dummy[8 + i ^ 1] = buf[i];
306 /* Wait for the card to get ready */
307 while (GET_WORD (fa) & 1) ;
309 /* Blast onto the ISA card */
310 dosmemput (dummy, 8 + len + 1, cpd);
313 SET_WORD (irqtod, 1); /* Interrupt the E7000 */
319 e7000pc_open (scb, name)
323 if (strncasecmp (name, "pc", 2) != 0)
329 scb->fd = e7000pc_init ();
348 /* Always in raw mode */
352 e7000pc_readchar (scb, timeout)
360 if (dosasync_read (scb->fd, &buf, 1, timeout))
362 if (buf == 0) goto top;
366 return SERIAL_TIMEOUT;
369 struct e7000pc_ttystate {
373 /* e7000pc_{get set}_tty_state() are both dummys to fill out the function
374 vector. Someday, they may do something real... */
376 static serial_ttystate
377 e7000pc_get_tty_state (scb)
380 struct e7000pc_ttystate *state;
382 state = (struct e7000pc_ttystate *) xmalloc (sizeof *state);
384 return (serial_ttystate) state;
388 e7000pc_set_tty_state (scb, ttystate)
390 serial_ttystate ttystate;
396 e7000pc_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
398 serial_ttystate new_ttystate;
399 serial_ttystate old_ttystate;
405 e7000pc_print_tty_state (scb, ttystate)
407 serial_ttystate ttystate;
409 /* Nothing to print. */
414 e7000pc_setbaudrate (scb, rate)
422 e7000pc_write (scb, str, len)
427 dosasync_write (scb->fd, str, len);
438 static struct serial_ops e7000pc_ops =
446 e7000pc_noop, /* flush output */
447 e7000pc_noop, /* flush input */
448 e7000pc_noop, /* send break -- currently used only for nindy */
450 e7000pc_get_tty_state,
451 e7000pc_set_tty_state,
452 e7000pc_print_tty_state,
453 e7000pc_noflush_set_tty_state,
455 e7000pc_noop, /* wait for output to drain */
459 _initialize_ser_e7000pc ()
461 serial_add_interface (&e7000pc_ops);
466 _initialize_ser_e7000pc ()