1 /* Remote serial interface using Renesas E7000 PC ISA card in a PC
2 Copyright (C) 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 #if defined __GO32__ || defined _WIN32
25 #include "gdb_string.h"
28 #define WIN32_LEAN_AND_MEAN
40 static int e7000pc_open (struct serial
*scb
, const char *name
);
41 static void e7000pc_raw (struct serial
*scb
);
42 static int e7000pc_readchar (struct serial
*scb
, int timeout
);
43 static int e7000pc_setbaudrate (struct serial
*scb
, int rate
);
44 static int e7000pc_write (struct serial
*scb
, const char *str
, int len
);
45 static void e7000pc_close (struct serial
*scb
);
46 static serial_ttystate
e7000pc_get_tty_state (struct serial
*scb
);
47 static int e7000pc_set_tty_state (struct serial
*scb
, serial_ttystate state
);
49 #define OFF_DPD 0x0000
50 #define OFF_DDP 0x1000
51 #define OFF_CPD 0x2000
52 #define OFF_CDP 0x2400
56 #define OFF_IRQTOD 0x3008
57 #define OFF_IRQTOP 0x300a
58 #define OFF_READY 0x300c
59 #define OFF_PON 0x300e
75 static unsigned long fa
;
76 static unsigned long irqtod
;
77 static unsigned long ready
;
78 static unsigned long fb
;
79 static unsigned long cpd
;
80 static unsigned long cdp
;
81 static unsigned long ready
;
82 static unsigned long pon
;
83 static unsigned long irqtop
;
84 static unsigned long board_at
;
88 #define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
89 #define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
90 #define GET_BYTE(x) ( dosmemget(x,1,&bb), bb)
91 #define GET_WORD(x) ( dosmemget(x,2,&sb), sb)
92 static unsigned char bb
;
93 static unsigned short sb
;
97 #define SET_BYTE(x,y) *(volatile unsigned char *)(x) = (y)
98 #define SET_WORD(x,y) *(volatile unsigned short *)(x) = (y)
99 #define GET_BYTE(x) (*(volatile unsigned char *)(x))
100 #define GET_WORD(x) (*(volatile unsigned short *)(x))
101 #define dosmemget(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
102 #define dosmemput(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
131 #define get_ds_base() 0
137 unsigned long dsbase
;
139 dsbase
= get_ds_base ();
141 /* Look around in memory for the board's signature */
143 for (try = 0; sigs
[try].sw
; try++)
146 board_at
= sigs
[try].addr
- dsbase
;
147 fa
= board_at
+ OFF_FA
;
148 fb
= board_at
+ OFF_FB
;
149 cpd
= board_at
+ OFF_CPD
;
150 cdp
= board_at
+ OFF_CDP
;
151 ready
= board_at
+ OFF_READY
;
152 pon
= board_at
+ OFF_PON
;
153 irqtop
= board_at
+ OFF_IRQTOP
;
154 irqtod
= board_at
+ OFF_IRQTOD
;
156 val
= GET_WORD (ready
);
158 if (val
== (0xaaa0 | sigs
[try].sw
))
160 if (GET_WORD (pon
) & 0xf)
165 SET_WORD (irqtop
, 1); /* Disable interrupts from e7000 */
167 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
171 error (_("The E7000 PC board is working, but the E7000 is turned off."));
176 error (_("GDB cannot connect to the E7000 PC board, check that it is installed\n\
177 and that the switch settings are correct. Some other DOS programs can \n\
178 stop the board from working. Try starting from a very minimal boot, \n\
179 perhaps you need to disable EMM386 over the region where the board has\n\
180 its I/O space, remove other unneeded cards, etc etc\n"));
185 static int pbuf_size
;
186 static int pbuf_index
;
188 /* Return next byte from cdp. If no more, then return -1. */
193 static char pbuf
[1000];
197 if (pbuf_index
< pbuf_size
)
199 x
= pbuf
[pbuf_index
++];
201 else if ((GET_WORD (fb
) & 1))
204 pbuf_size
= GET_WORD (cdp
+ 2);
206 dosmemget (cdp
+ 8, pbuf_size
+ 1, tmp
);
208 /* Tell the E7000 we've eaten */
211 for (i
= 0; i
< pbuf_size
; i
++)
213 pbuf
[i
] = tmp
[i
^ 1];
216 x
= pbuf
[pbuf_index
++];
225 /* Works just like read(), except that it takes a TIMEOUT in seconds. Note
226 that TIMEOUT == 0 is a poll, and TIMEOUT == -1 means wait forever. */
229 dosasync_read (int fd
, char *buf
, int len
, int timeout
)
235 /* Then look for some more if we're still hungry */
237 then
= now
+ timeout
;
240 int ch
= e7000_get ();
242 /* While there's room in the buffer, and we've already
243 read the stuff in, suck it over */
247 while (i
< len
&& pbuf_index
< pbuf_size
)
260 if (now
>= then
&& timeout
> 0)
270 dosasync_write (int fd
, const char *buf
, int len
)
275 /* Construct copy locally */
276 ((short *) dummy
)[0] = CMD_CI
;
277 ((short *) dummy
)[1] = len
;
278 ((short *) dummy
)[2] = 0;
279 ((short *) dummy
)[3] = 0;
280 for (i
= 0; i
< len
; i
++)
282 dummy
[(8 + i
) ^ 1] = buf
[i
];
285 /* Wait for the card to get ready */
286 while (GET_WORD (fa
) & 1);
288 /* Blast onto the ISA card */
289 dosmemput (dummy
, 8 + len
+ 1, cpd
);
292 SET_WORD (irqtod
, 1); /* Interrupt the E7000 */
298 e7000pc_open (struct serial
*scb
, const char *name
)
300 if (strncasecmp (name
, "pc", 2) != 0)
306 scb
->fd
= e7000pc_init ();
315 e7000pc_noop (struct serial
*scb
)
321 e7000pc_raw (struct serial
*scb
)
323 /* Always in raw mode */
327 e7000pc_readchar (struct serial
*scb
, int timeout
)
333 if (dosasync_read (scb
->fd
, &buf
, 1, timeout
))
340 return SERIAL_TIMEOUT
;
343 struct e7000pc_ttystate
348 /* e7000pc_{get set}_tty_state() are both dummys to fill out the function
349 vector. Someday, they may do something real... */
351 static serial_ttystate
352 e7000pc_get_tty_state (struct serial
*scb
)
354 struct e7000pc_ttystate
*state
;
356 state
= (struct e7000pc_ttystate
*) xmalloc (sizeof *state
);
358 return (serial_ttystate
) state
;
362 e7000pc_set_tty_state (struct serial
*scb
, serial_ttystate ttystate
)
368 e7000pc_noflush_set_tty_state (struct serial
*scb
,
369 serial_ttystate new_ttystate
,
370 serial_ttystate old_ttystate
)
376 e7000pc_print_tty_state (struct serial
*scb
,
377 serial_ttystate ttystate
,
378 struct ui_file
*stream
)
380 /* Nothing to print. */
385 e7000pc_setbaudrate (struct serial
*scb
, int rate
)
391 e7000pc_setstopbits (struct serial
*scb
, int rate
)
397 e7000pc_write (struct serial
*scb
, const char *str
, int len
)
399 dosasync_write (scb
->fd
, str
, len
);
405 e7000pc_close (struct serial
*scb
)
409 static struct serial_ops e7000pc_ops
=
417 e7000pc_noop
, /* flush output */
418 e7000pc_noop
, /* flush input */
419 e7000pc_noop
, /* send break -- currently used only for nindy */
421 e7000pc_get_tty_state
,
422 e7000pc_set_tty_state
,
423 e7000pc_print_tty_state
,
424 e7000pc_noflush_set_tty_state
,
427 e7000pc_noop
, /* wait for output to drain */
430 #endif /*_WIN32 or __GO32__*/
432 extern initialize_file_ftype _initialize_ser_e7000pc
; /* -Wmissing-prototypes */
435 _initialize_ser_e7000pc (void)
437 #if defined __GO32__ || defined _WIN32
438 serial_add_interface (&e7000pc_ops
);