* config/mips/tm-mips.h (SETUP_ARBITRARY_FRAME): Revise comment
[deliverable/binutils-gdb.git] / gdb / ser-mac.c
1 /* Remote serial interface for local (hardwired) serial ports for Macintosh.
2 Copyright 1994 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
23 #include <Types.h>
24 #include <Devices.h>
25 #include <Serial.h>
26
27 /* This is unused for now. We just return a placeholder. */
28
29 struct mac_ttystate
30 {
31 int bogus;
32 };
33
34 static int mac_open PARAMS ((serial_t scb, const char *name));
35 static void mac_raw PARAMS ((serial_t scb));
36 static int mac_readchar PARAMS ((serial_t scb, int timeout));
37 static int mac_setbaudrate PARAMS ((serial_t scb, int rate));
38 static int mac_write PARAMS ((serial_t scb, const char *str, int len));
39 static void mac_close PARAMS ((serial_t scb));
40 static serial_ttystate mac_get_tty_state PARAMS ((serial_t scb));
41 static int mac_set_tty_state PARAMS ((serial_t scb, serial_ttystate state));
42 static char *aptr PARAMS ((short p));
43
44 short input_refnum;
45 short output_refnum;
46
47 char *mac_input_buffer;
48 char *mac_output_buffer;
49
50 static int
51 mac_open (scb, name)
52 serial_t scb;
53 const char *name;
54 {
55 OSErr err;
56
57 /* Alloc buffer space first - that way any allocation failures are
58 intercepted before the serial driver gets involved. */
59 if (mac_input_buffer == NULL)
60 mac_input_buffer = (char *) xmalloc (256);
61 /* Match on a name and open a port. */
62 if (strcmp (name, "modem") == 0)
63 {
64 err = OpenDriver ("\p.AIn", &input_refnum);
65 if (err != 0)
66 {
67 return (-1);
68 }
69 err = OpenDriver ("\p.AOut", &output_refnum);
70 if (err != 0)
71 {
72 CloseDriver (input_refnum);
73 return (-1);
74 }
75 }
76 else if (strcmp (name, "printer") == 0)
77 {
78 err = OpenDriver ("\p.BIn", &input_refnum);
79 if (err != 0)
80 {
81 return (-1);
82 }
83 err = OpenDriver ("\p.BOut", &output_refnum);
84 if (err != 0)
85 {
86 CloseDriver (input_refnum);
87 return (-1);
88 }
89 /* fake */
90 scb->fd = 1;
91 return 0;
92 }
93 else
94 {
95 errno = ENOENT;
96 return (-1);
97 }
98 /* We got something open. */
99 if (1 /* using custom buffer */)
100 SerSetBuf (input_refnum, mac_input_buffer, 256);
101 /* Set to a GDB-preferred state. */
102 SerReset (input_refnum, stop10|noParity|data8|baud9600);
103 SerReset (output_refnum, stop10|noParity|data8|baud9600);
104 {
105 CntrlParam cb;
106 struct SerShk *handshake;
107
108 cb.ioCRefNum = output_refnum;
109 cb.csCode = 14;
110 handshake = (struct SerShk *) &cb.csParam[0];
111 handshake->fXOn = 0;
112 handshake->fCTS = 0;
113 handshake->xOn = 0;
114 handshake->xOff = 0;
115 handshake->errs = 0;
116 handshake->evts = 0;
117 handshake->fInX = 0;
118 handshake->fDTR = 0;
119 err = PBControl ((ParmBlkPtr) &cb, 0);
120 if (err < 0)
121 return (-1);
122 }
123 /* fake */
124 scb->fd = 1;
125 return 0;
126 }
127
128 static int
129 mac_noop (scb)
130 serial_t scb;
131 {
132 return 0;
133 }
134
135 static void
136 mac_raw (scb)
137 serial_t scb;
138 {
139 /* Always effectively in raw mode. */
140 }
141
142 /* Read a character with user-specified timeout. TIMEOUT is number of seconds
143 to wait, or -1 to wait forever. Use timeout of 0 to effect a poll. Returns
144 char if successful. Returns -2 if timeout expired, EOF if line dropped
145 dead, or -3 for any other error (see errno in that case). */
146
147 static int
148 mac_readchar (scb, timeout)
149 serial_t scb;
150 int timeout;
151 {
152 int status, n;
153 /* time_t */ unsigned long starttime, now;
154 OSErr err;
155 CntrlParam cb;
156 IOParam pb;
157
158 if (scb->bufcnt-- > 0)
159 return *scb->bufp++;
160
161 time (&starttime);
162
163 while (1)
164 {
165 cb.ioCRefNum = input_refnum;
166 cb.csCode = 2;
167 err = PBStatus ((ParmBlkPtr) &cb, 0);
168 if (err < 0)
169 return SERIAL_ERROR;
170 n = *((long *) &cb.csParam[0]);
171 if (n > 0)
172 {
173 pb.ioRefNum = input_refnum;
174 pb.ioBuffer = (Ptr) (scb->buf);
175 pb.ioReqCount = (n > 64 ? 64 : n);
176 err = PBRead ((ParmBlkPtr) &pb, 0);
177 if (err < 0)
178 return SERIAL_ERROR;
179 scb->bufcnt = pb.ioReqCount;
180 scb->bufcnt--;
181 scb->bufp = scb->buf;
182 return *scb->bufp++;
183 }
184 else if (timeout == 0)
185 return SERIAL_TIMEOUT;
186 else if (timeout == -1)
187 ;
188 else
189 {
190 time (&now);
191 if (now > starttime + timeout) {
192 printf_unfiltered ("start %u, now %u, timeout %d\n", starttime, now, timeout);
193 return SERIAL_TIMEOUT;
194 }
195 }
196 }
197 }
198
199 /* mac_{get set}_tty_state() are both dummys to fill out the function
200 vector. Someday, they may do something real... */
201
202 static serial_ttystate
203 mac_get_tty_state (scb)
204 serial_t scb;
205 {
206 struct mac_ttystate *state;
207
208 state = (struct mac_ttystate *) xmalloc (sizeof *state);
209
210 return (serial_ttystate) state;
211 }
212
213 static int
214 mac_set_tty_state (scb, ttystate)
215 serial_t scb;
216 serial_ttystate ttystate;
217 {
218 return 0;
219 }
220
221 static int
222 mac_noflush_set_tty_state (scb, new_ttystate, old_ttystate)
223 serial_t scb;
224 serial_ttystate new_ttystate;
225 serial_ttystate old_ttystate;
226 {
227 return 0;
228 }
229
230 static void
231 mac_print_tty_state (scb, ttystate)
232 serial_t scb;
233 serial_ttystate ttystate;
234 {
235 /* Nothing to print. */
236 return;
237 }
238
239 static int
240 mac_set_baud_rate (scb, rate)
241 serial_t scb;
242 int rate;
243 {
244 return 0;
245 }
246
247 static int
248 mac_write (scb, str, len)
249 serial_t scb;
250 const char *str;
251 int len;
252 {
253 OSErr err;
254 IOParam pb;
255
256 pb.ioRefNum = output_refnum;
257 pb.ioBuffer = (Ptr) str;
258 pb.ioReqCount = len;
259 err = PBWrite ((ParmBlkPtr) &pb, 0);
260 if (err < 0)
261 {
262 return 1;
263 }
264 return 0;
265 }
266
267 static void
268 mac_close (scb)
269 serial_t scb;
270 {
271 if (input_refnum)
272 {
273 if (1 /* custom buffer */)
274 SerSetBuf (input_refnum, mac_input_buffer, 0);
275 CloseDriver (input_refnum);
276 input_refnum = 0;
277 }
278 if (output_refnum)
279 {
280 if (0 /* custom buffer */)
281 SetSetBuf (input_refnum, mac_output_buffer, 0);
282 CloseDriver (output_refnum);
283 output_refnum = 0;
284 }
285 }
286
287 static struct serial_ops mac_ops =
288 {
289 "hardwire",
290 0,
291 mac_open,
292 mac_close,
293 mac_readchar,
294 mac_write,
295 mac_noop, /* flush output */
296 mac_noop, /* flush input */
297 mac_noop, /* send break -- currently only for nindy */
298 mac_raw,
299 mac_get_tty_state,
300 mac_set_tty_state,
301 mac_print_tty_state,
302 mac_noflush_set_tty_state,
303 mac_set_baud_rate,
304 };
305
306 void
307 _initialize_ser_mac ()
308 {
309 serial_add_interface (&mac_ops);
310 }
This page took 0.035572 seconds and 4 git commands to generate.