1 /* Remote serial interface using Renesas 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. */
23 #if defined __GO32__ || defined _WIN32
25 #include "gdb_string.h"
28 #define WIN32_LEAN_AND_MEAN
36 static int e7000pc_open (struct serial
*scb
, const char *name
);
37 static void e7000pc_raw (struct serial
*scb
);
38 static int e7000pc_readchar (struct serial
*scb
, int timeout
);
39 static int e7000pc_setbaudrate (struct serial
*scb
, int rate
);
40 static int e7000pc_write (struct serial
*scb
, const char *str
, int len
);
41 static void e7000pc_close (struct serial
*scb
);
42 static serial_ttystate
e7000pc_get_tty_state (struct serial
*scb
);
43 static int e7000pc_set_tty_state (struct serial
*scb
, serial_ttystate state
);
45 #define OFF_DPD 0x0000
46 #define OFF_DDP 0x1000
47 #define OFF_CPD 0x2000
48 #define OFF_CDP 0x2400
52 #define OFF_IRQTOD 0x3008
53 #define OFF_IRQTOP 0x300a
54 #define OFF_READY 0x300c
55 #define OFF_PON 0x300e
71 static unsigned long fa
;
72 static unsigned long irqtod
;
73 static unsigned long ready
;
74 static unsigned long fb
;
75 static unsigned long cpd
;
76 static unsigned long cdp
;
77 static unsigned long ready
;
78 static unsigned long pon
;
79 static unsigned long irqtop
;
80 static unsigned long board_at
;
84 #define SET_BYTE(x,y) { char _buf = y;dosmemput(&_buf,1, x);}
85 #define SET_WORD(x,y) { short _buf = y;dosmemput(&_buf,2, x);}
86 #define GET_BYTE(x) ( dosmemget(x,1,&bb), bb)
87 #define GET_WORD(x) ( dosmemget(x,2,&sb), sb)
88 static unsigned char bb
;
89 static unsigned short sb
;
93 #define SET_BYTE(x,y) *(volatile unsigned char *)(x) = (y)
94 #define SET_WORD(x,y) *(volatile unsigned short *)(x) = (y)
95 #define GET_BYTE(x) (*(volatile unsigned char *)(x))
96 #define GET_WORD(x) (*(volatile unsigned short *)(x))
97 #define dosmemget(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
98 #define dosmemput(FROM, LEN, TO) memcpy ((void *)(TO), (void *)(FROM), (LEN))
127 #define get_ds_base() 0
133 unsigned long dsbase
;
135 dsbase
= get_ds_base ();
137 /* Look around in memory for the board's signature */
139 for (try = 0; sigs
[try].sw
; try++)
142 board_at
= sigs
[try].addr
- dsbase
;
143 fa
= board_at
+ OFF_FA
;
144 fb
= board_at
+ OFF_FB
;
145 cpd
= board_at
+ OFF_CPD
;
146 cdp
= board_at
+ OFF_CDP
;
147 ready
= board_at
+ OFF_READY
;
148 pon
= board_at
+ OFF_PON
;
149 irqtop
= board_at
+ OFF_IRQTOP
;
150 irqtod
= board_at
+ OFF_IRQTOD
;
152 val
= GET_WORD (ready
);
154 if (val
== (0xaaa0 | sigs
[try].sw
))
156 if (GET_WORD (pon
) & 0xf)
161 SET_WORD (irqtop
, 1); /* Disable interrupts from e7000 */
163 printf_filtered ("\nConnected to the E7000PC at address 0x%x\n",
167 error ("The E7000 PC board is working, but the E7000 is turned off.\n");
172 error ("GDB cannot connect to the E7000 PC board, check that it is installed\n\
173 and that the switch settings are correct. Some other DOS programs can \n\
174 stop the board from working. Try starting from a very minimal boot, \n\
175 perhaps you need to disable EMM386 over the region where the board has\n\
176 its I/O space, remove other unneeded cards, etc etc\n");
181 static int pbuf_size
;
182 static int pbuf_index
;
184 /* Return next byte from cdp. If no more, then return -1. */
189 static char pbuf
[1000];
193 if (pbuf_index
< pbuf_size
)
195 x
= pbuf
[pbuf_index
++];
197 else if ((GET_WORD (fb
) & 1))
200 pbuf_size
= GET_WORD (cdp
+ 2);
202 dosmemget (cdp
+ 8, pbuf_size
+ 1, tmp
);
204 /* Tell the E7000 we've eaten */
207 for (i
= 0; i
< pbuf_size
; i
++)
209 pbuf
[i
] = tmp
[i
^ 1];
212 x
= pbuf
[pbuf_index
++];
221 /* Works just like read(), except that it takes a TIMEOUT in seconds. Note
222 that TIMEOUT == 0 is a poll, and TIMEOUT == -1 means wait forever. */
225 dosasync_read (int fd
, char *buf
, int len
, int timeout
)
231 /* Then look for some more if we're still hungry */
233 then
= now
+ timeout
;
236 int ch
= e7000_get ();
238 /* While there's room in the buffer, and we've already
239 read the stuff in, suck it over */
243 while (i
< len
&& pbuf_index
< pbuf_size
)
256 if (now
>= then
&& timeout
> 0)
266 dosasync_write (int fd
, const char *buf
, int len
)
271 /* Construct copy locally */
272 ((short *) dummy
)[0] = CMD_CI
;
273 ((short *) dummy
)[1] = len
;
274 ((short *) dummy
)[2] = 0;
275 ((short *) dummy
)[3] = 0;
276 for (i
= 0; i
< len
; i
++)
278 dummy
[(8 + i
) ^ 1] = buf
[i
];
281 /* Wait for the card to get ready */
282 while (GET_WORD (fa
) & 1);
284 /* Blast onto the ISA card */
285 dosmemput (dummy
, 8 + len
+ 1, cpd
);
288 SET_WORD (irqtod
, 1); /* Interrupt the E7000 */
294 e7000pc_open (struct serial
*scb
, const char *name
)
296 if (strncasecmp (name
, "pc", 2) != 0)
302 scb
->fd
= e7000pc_init ();
311 e7000pc_noop (struct serial
*scb
)
317 e7000pc_raw (struct serial
*scb
)
319 /* Always in raw mode */
323 e7000pc_readchar (struct serial
*scb
, int timeout
)
329 if (dosasync_read (scb
->fd
, &buf
, 1, timeout
))
336 return SERIAL_TIMEOUT
;
339 struct e7000pc_ttystate
344 /* e7000pc_{get set}_tty_state() are both dummys to fill out the function
345 vector. Someday, they may do something real... */
347 static serial_ttystate
348 e7000pc_get_tty_state (struct serial
*scb
)
350 struct e7000pc_ttystate
*state
;
352 state
= (struct e7000pc_ttystate
*) xmalloc (sizeof *state
);
354 return (serial_ttystate
) state
;
358 e7000pc_set_tty_state (struct serial
*scb
, serial_ttystate ttystate
)
364 e7000pc_noflush_set_tty_state (struct serial
*scb
,
365 serial_ttystate new_ttystate
,
366 serial_ttystate old_ttystate
)
372 e7000pc_print_tty_state (struct serial
*scb
,
373 serial_ttystate ttystate
,
374 struct ui_file
*stream
)
376 /* Nothing to print. */
381 e7000pc_setbaudrate (struct serial
*scb
, int rate
)
387 e7000pc_setstopbits (struct serial
*scb
, int rate
)
393 e7000pc_write (struct serial
*scb
, const char *str
, int len
)
395 dosasync_write (scb
->fd
, str
, len
);
401 e7000pc_close (struct serial
*scb
)
405 static struct serial_ops e7000pc_ops
=
413 e7000pc_noop
, /* flush output */
414 e7000pc_noop
, /* flush input */
415 e7000pc_noop
, /* send break -- currently used only for nindy */
417 e7000pc_get_tty_state
,
418 e7000pc_set_tty_state
,
419 e7000pc_print_tty_state
,
420 e7000pc_noflush_set_tty_state
,
423 e7000pc_noop
, /* wait for output to drain */
426 #endif /*_WIN32 or __GO32__*/
428 extern initialize_file_ftype _initialize_ser_e7000pc
; /* -Wmissing-prototypes */
431 _initialize_ser_e7000pc (void)
433 #if defined __GO32__ || defined _WIN32
434 serial_add_interface (&e7000pc_ops
);