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