1 /* Remote serial interface using Hitachi E7000 PC ISA card in a PC
2 Copyright 1994, 1996, 1997, 1998, 1999, 2000
3 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,
20 Boston, MA 02111-1307, USA. */
22 #if defined __GO32__ || defined _WIN32
25 #include "gdb_string.h"
27 /* MSVC uses strnicmp instead of strncasecmp */
29 #define strncasecmp strnicmp
30 #define WIN32_LEAN_AND_MEAN
41 static int e7000pc_open (serial_t scb
, const char *name
);
42 static void e7000pc_raw (serial_t scb
);
43 static int e7000pc_readchar (serial_t scb
, int timeout
);
44 static int e7000pc_setbaudrate (serial_t scb
, int rate
);
45 static int e7000pc_write (serial_t scb
, const char *str
, int len
);
46 static void e7000pc_close (serial_t scb
);
47 static serial_ttystate
e7000pc_get_tty_state (serial_t scb
);
48 static int e7000pc_set_tty_state (serial_t scb
, serial_ttystate state
);
50 #define OFF_DPD 0x0000
51 #define OFF_DDP 0x1000
52 #define OFF_CPD 0x2000
53 #define OFF_CDP 0x2400
57 #define OFF_IRQTOD 0x3008
58 #define OFF_IRQTOP 0x300a
59 #define OFF_READY 0x300c
60 #define OFF_PON 0x300e
76 static unsigned long fa
;
77 static unsigned long irqtod
;
78 static unsigned long ready
;
79 static unsigned long fb
;
80 static unsigned long cpd
;
81 static unsigned long cdp
;
82 static unsigned long ready
;
83 static unsigned long pon
;
84 static unsigned long irqtop
;
85 static unsigned long board_at
;
89 #define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
90 #define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
91 #define GET_BYTE(x) ( dosmemget(x,1,&bb), bb)
92 #define GET_WORD(x) ( dosmemget(x,2,&sb), sb)
93 static unsigned char bb
;
94 static unsigned short sb
;
98 #define SET_BYTE(x,y) *(volatile unsigned char *)(x) = (y)
99 #define SET_WORD(x,y) *(volatile unsigned short *)(x) = (y)
100 #define GET_BYTE(x) (*(volatile unsigned char *)(x))
101 #define GET_WORD(x) (*(volatile unsigned short *)(x))
102 #define dosmemget(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
103 #define dosmemput(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
133 /* Get the base of the data segment. This is needed to calculate the offset
134 between data segment addresses and the base of linear memory, which is where
135 device registers reside. Note that this is really only necessary for
136 Win32s, since Win95 and NT keep the data segment at linear 0. */
141 unsigned short dsval
;
143 unsigned long dsbase
;
152 GetThreadSelectorEntry (GetCurrentThread (), dsval
, &ldt
);
154 dsbase
= ldt
.HighWord
.Bits
.BaseHi
<< 24 | ldt
.HighWord
.Bits
.BaseMid
<< 16
159 #else /* !_MSC_VER */
160 #define get_ds_base() 0
161 #endif /* _MSC_VER */
167 unsigned long dsbase
;
169 dsbase
= get_ds_base ();
171 /* Look around in memory for the board's signature */
173 for (try = 0; sigs
[try].sw
; try++)
176 board_at
= sigs
[try].addr
- dsbase
;
177 fa
= board_at
+ OFF_FA
;
178 fb
= board_at
+ OFF_FB
;
179 cpd
= board_at
+ OFF_CPD
;
180 cdp
= board_at
+ OFF_CDP
;
181 ready
= board_at
+ OFF_READY
;
182 pon
= board_at
+ OFF_PON
;
183 irqtop
= board_at
+ OFF_IRQTOP
;
184 irqtod
= board_at
+ OFF_IRQTOD
;
186 val
= GET_WORD (ready
);
188 if (val
== (0xaaa0 | sigs
[try].sw
))
190 if (GET_WORD (pon
) & 0xf)
195 SET_WORD (irqtop
, 1); /* Disable interrupts from e7000 */
197 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
201 error ("The E7000 PC board is working, but the E7000 is turned off.\n");
206 error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
207 and that the switch settings are correct. Some other DOS programs can \n\
208 stop the board from working. Try starting from a very minimal boot, \n\
209 perhaps you need to disable EMM386 over the region where the board has\n\
210 its I/O space, remove other unneeded cards, etc etc\n");
215 static int pbuf_size
;
216 static int pbuf_index
;
218 /* Return next byte from cdp. If no more, then return -1. */
223 static char pbuf
[1000];
227 if (pbuf_index
< pbuf_size
)
229 x
= pbuf
[pbuf_index
++];
231 else if ((GET_WORD (fb
) & 1))
234 pbuf_size
= GET_WORD (cdp
+ 2);
236 dosmemget (cdp
+ 8, pbuf_size
+ 1, tmp
);
238 /* Tell the E7000 we've eaten */
241 for (i
= 0; i
< pbuf_size
; i
++)
243 pbuf
[i
] = tmp
[i
^ 1];
246 x
= pbuf
[pbuf_index
++];
255 /* Works just like read(), except that it takes a TIMEOUT in seconds. Note
256 that TIMEOUT == 0 is a poll, and TIMEOUT == -1 means wait forever. */
259 dosasync_read (int fd
, char *buf
, int len
, int timeout
)
265 /* Then look for some more if we're still hungry */
267 then
= now
+ timeout
;
270 int ch
= e7000_get ();
272 /* While there's room in the buffer, and we've already
273 read the stuff in, suck it over */
277 while (i
< len
&& pbuf_index
< pbuf_size
)
290 if (now
>= then
&& timeout
> 0)
300 dosasync_write (int fd
, const char *buf
, int len
)
305 /* Construct copy locally */
306 ((short *) dummy
)[0] = CMD_CI
;
307 ((short *) dummy
)[1] = len
;
308 ((short *) dummy
)[2] = 0;
309 ((short *) dummy
)[3] = 0;
310 for (i
= 0; i
< len
; i
++)
312 dummy
[(8 + i
) ^ 1] = buf
[i
];
315 /* Wait for the card to get ready */
316 while (GET_WORD (fa
) & 1);
318 /* Blast onto the ISA card */
319 dosmemput (dummy
, 8 + len
+ 1, cpd
);
322 SET_WORD (irqtod
, 1); /* Interrupt the E7000 */
328 e7000pc_open (serial_t scb
, const char *name
)
330 if (strncasecmp (name
, "pc", 2) != 0)
336 scb
->fd
= e7000pc_init ();
345 e7000pc_noop (serial_t scb
)
351 e7000pc_raw (serial_t scb
)
353 /* Always in raw mode */
357 e7000pc_readchar (serial_t scb
, int timeout
)
363 if (dosasync_read (scb
->fd
, &buf
, 1, timeout
))
370 return SERIAL_TIMEOUT
;
373 struct e7000pc_ttystate
378 /* e7000pc_{get set}_tty_state() are both dummys to fill out the function
379 vector. Someday, they may do something real... */
381 static serial_ttystate
382 e7000pc_get_tty_state (serial_t scb
)
384 struct e7000pc_ttystate
*state
;
386 state
= (struct e7000pc_ttystate
*) xmalloc (sizeof *state
);
388 return (serial_ttystate
) state
;
392 e7000pc_set_tty_state (serial_t scb
, serial_ttystate ttystate
)
398 e7000pc_noflush_set_tty_state (serial_t scb
, serial_ttystate new_ttystate
,
399 serial_ttystate old_ttystate
)
405 e7000pc_print_tty_state (serial_t scb
,
406 serial_ttystate ttystate
,
407 struct ui_file
*stream
)
409 /* Nothing to print. */
414 e7000pc_setbaudrate (serial_t scb
, int rate
)
420 e7000pc_setstopbits (serial_t scb
, int rate
)
426 e7000pc_write (serial_t scb
, const char *str
, int len
)
428 dosasync_write (scb
->fd
, str
, len
);
434 e7000pc_close (serial_t scb
)
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
,
456 e7000pc_noop
, /* wait for output to drain */
460 _initialize_ser_e7000pc (void)
462 serial_add_interface (&e7000pc_ops
);
467 _initialize_ser_e7000pc (void)