Based on patches from H.J. Lu <hjl@nynexst.com>:
[deliverable/binutils-gdb.git] / gdb / ser-go32-para.c
1 /* Remote parallel interface for local parallel ports for GO32.
2 Copyright 1992, 1993 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #include "defs.h"
21 #include "serial.h"
22 #include <sys/dos.h>
23
24 #if 0
25 #define disable() asm("cli")
26 #define enable() asm("sti")
27 #endif
28
29 /* this is a duumy to fill the ops structure */
30 struct go32_ttystate
31 {
32 int bogus;
33 };
34
35 static int go32_open PARAMS ((serial_t scb, const char *name));
36 static void go32_raw PARAMS ((serial_t scb));
37 static int go32_readchar PARAMS ((serial_t scb, int timeout));
38 static int go32_setbaudrate PARAMS ((serial_t scb, int rate));
39 static int go32_write PARAMS ((serial_t scb, const char *str, int len));
40 static void go32_close PARAMS ((serial_t scb));
41 static serial_ttystate go32_get_tty_state PARAMS ((serial_t scb));
42 static int go32_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
43 static unsigned long getivec PARAMS ((int which));
44 static int dos_read PARAMS ((int fd, char *buf, int len));
45 static int dos_write PARAMS ((int fd, const char *buf, int len));
46
47 #if 0
48 static int iov[2];
49 #define com_rb(n) iov[n]
50 #define com_tb(n) iov[n]
51 #define com_ier(n) iov[n]+1
52 #define com_ifr(n) iov[n]+2
53 #define com_bfr(n) iov[n]+3
54 #define com_mcr(n) iov[n]+4
55 #define com_lsr(n) iov[n]+5
56 #define com_msr(n) iov[n]+6
57
58 static unsigned long
59 getivec (int which)
60 {
61 long tryaindex;
62
63 if (GET_WORD (which * 4) != OFFSET)
64 return 0;
65
66 /* Find out where in memory this lives */
67 tryaindex = GET_WORD (which * 4 + 2) * 16 + GET_WORD (which * 4);
68
69 if (GET_WORD (tryaindex + 2) != SIGNATURE)
70 return 0;
71 if (GET_WORD (tryaindex + 4) != VERSION)
72 return 0;
73 return tryaindex;
74 }
75 #endif /* 0 */
76
77 static int biosprn (cmd, byte, port)
78 int cmd;
79 int byte;
80 int port;
81 {
82 union REGS regs;
83 regs.h.ah = cmd;
84 regs.h.al = byte;
85 regs.x.dx = port;
86 int86 (0x17, &regs, &regs);
87 return regs.h.ah;
88 }
89
90 static int
91 dos_read (fd, buf, len)
92 int fd;
93 char *buf;
94 int len;
95 {
96 int i;
97
98 for (i = 0; i < len; i++)
99 {
100 *buf++ = biosprn (2, 0, fd);
101 }
102 return len;
103 }
104
105 static int
106 dos_write (fd, buf, len)
107 int fd;
108 const char *buf;
109 int len;
110 {
111 int l;
112
113 for (l = 0; l < len; l++)
114 biosprn (0, *buf++, fd);
115
116 return len;
117 }
118
119 static int
120 go32_open (scb, name)
121 serial_t scb;
122 const char *name;
123 {
124 int port, ret;
125
126 if (strncasecmp (name, "lpt", 3) != 0)
127 {
128 errno = ENOENT;
129 return -1;
130 }
131
132 port = name[3] - '0';
133
134 if (port != 1 && port != 2 && port != 3)
135 {
136 errno = ENOENT;
137 return -11;
138 }
139
140 ret = biosprn (1, 0, port);
141 if (!ret)
142 return -1;
143
144 scb->fd = port;
145 return 0;
146 }
147
148 static int
149 go32_noop (scb)
150 serial_t scb;
151 {
152 return 0;
153 }
154
155 static void
156 go32_raw (scb)
157 serial_t scb;
158 {
159 /* Always in raw mode */
160 }
161
162 static int
163 go32_readchar (scb, timeout)
164 serial_t scb;
165 int timeout;
166 {
167 char buf;
168
169 if (dos_read (scb->fd, &buf, 1))
170 return buf;
171 else
172 return SERIAL_TIMEOUT;
173 }
174
175 static int
176 go32_write (scb, str, len)
177 serial_t scb;
178 const char *str;
179 int len;
180 {
181 dos_write (scb->fd, str, len);
182 return 0;
183 }
184
185 /* go32_{get set}_tty_state() are both dummys to fill out the function
186 vector. Someday, they may do something real... */
187
188 static serial_ttystate
189 go32_get_tty_state (scb)
190 serial_t scb;
191 {
192 struct go32_ttystate *state;
193
194 state = (struct go32_ttystate *) xmalloc (sizeof *state);
195
196 return (serial_ttystate) state;
197 }
198
199 static int
200 go32_set_tty_state (scb, ttystate)
201 serial_t scb;
202 serial_ttystate ttystate;
203 {
204 return 0;
205 }
206
207 static int
208 go32_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
209 serial_t scb;
210 serial_ttystate new_ttystate;
211 serial_ttystate old_ttystate;
212 {
213 return 0;
214 }
215
216 static void
217 go32_print_tty_state (scb, ttystate)
218 serial_t scb;
219 serial_ttystate ttystate;
220 {
221 /* Nothing to print. */
222 return;
223 }
224
225 static int
226 go32_setbaudrate (scb, rate)
227 serial_t scb;
228 int rate;
229 {
230 return 0;
231 }
232
233 static int
234 go32_setstopbits (scb, num)
235 serial_t scb;
236 int num;
237 {
238 return 0;
239 }
240
241 static void
242 go32_close (scb)
243 serial_t scb;
244 {
245 }
246
247 static struct serial_ops go32_ops =
248 {
249 "parallel",
250 0,
251 go32_open,
252 go32_close,
253 go32_readchar,
254 go32_write,
255 go32_noop, /* flush output */
256 go32_noop, /* flush input */
257 go32_noop, /* send break -- currently used only for nindy */
258 go32_raw,
259 go32_get_tty_state,
260 go32_set_tty_state,
261 go32_print_tty_state,
262 go32_noflush_set_tty_state,
263 go32_setbaudrate,
264 go32_setstopbits,
265 };
266
267 void
268 _initialize_ser_go32 ()
269 {
270 serial_add_interface (&go32_ops);
271 }
This page took 0.047303 seconds and 4 git commands to generate.