aboutsummaryrefslogtreecommitdiff
path: root/gdb/ser-mac.c
blob: e507cf96da13570c93af48cb501f1d112507ccf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/* OBSOLETE /* Remote serial interface for local (hardwired) serial ports for Macintosh. */
/* OBSOLETE    Copyright 1994, 1995, 1996, 1998, 2000 Free Software Foundation, Inc. */
/* OBSOLETE    Contributed by Cygnus Support.  Written by Stan Shebs. */
/* OBSOLETE  */
/* OBSOLETE    This file is part of GDB. */
/* OBSOLETE  */
/* OBSOLETE    This program is free software; you can redistribute it and/or modify */
/* OBSOLETE    it under the terms of the GNU General Public License as published by */
/* OBSOLETE    the Free Software Foundation; either version 2 of the License, or */
/* OBSOLETE    (at your option) any later version. */
/* OBSOLETE  */
/* OBSOLETE    This program is distributed in the hope that it will be useful, */
/* OBSOLETE    but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* OBSOLETE    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
/* OBSOLETE    GNU General Public License for more details. */
/* OBSOLETE  */
/* OBSOLETE    You should have received a copy of the GNU General Public License */
/* OBSOLETE    along with this program; if not, write to the Free Software */
/* OBSOLETE    Foundation, Inc., 59 Temple Place - Suite 330, */
/* OBSOLETE    Boston, MA 02111-1307, USA.  */ */
/* OBSOLETE  */
/* OBSOLETE #include "defs.h" */
/* OBSOLETE #include "serial.h" */
/* OBSOLETE  */
/* OBSOLETE #include <Types.h> */
/* OBSOLETE #include <Devices.h> */
/* OBSOLETE /* This is the regular Mac Serial.h, but copied to a different name */
/* OBSOLETE    so as not to get confused with the GDB serial.h above.  */ */
/* OBSOLETE #include "MacSerial.h" */
/* OBSOLETE  */
/* OBSOLETE /* This is unused for now.  We just return a placeholder. */ */
/* OBSOLETE  */
/* OBSOLETE struct mac_ttystate */
/* OBSOLETE   { */
/* OBSOLETE     int bogus; */
/* OBSOLETE   }; */
/* OBSOLETE  */
/* OBSOLETE static int mac_open (serial_t scb, const char *name); */
/* OBSOLETE static void mac_raw (serial_t scb); */
/* OBSOLETE static int mac_readchar (serial_t scb, int timeout); */
/* OBSOLETE static int mac_setbaudrate (serial_t scb, int rate); */
/* OBSOLETE static int mac_write (serial_t scb, const char *str, int len); */
/* OBSOLETE static void mac_close (serial_t scb); */
/* OBSOLETE static serial_ttystate mac_get_tty_state (serial_t scb); */
/* OBSOLETE static int mac_set_tty_state (serial_t scb, serial_ttystate state); */
/* OBSOLETE static char *aptr (short p); */
/* OBSOLETE  */
/* OBSOLETE short input_refnum; */
/* OBSOLETE short output_refnum; */
/* OBSOLETE  */
/* OBSOLETE char *mac_input_buffer; */
/* OBSOLETE char *mac_output_buffer; */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_open (serial_t scb, const char *name) */
/* OBSOLETE { */
/* OBSOLETE   OSErr err; */
/* OBSOLETE  */
/* OBSOLETE   /* Alloc buffer space first - that way any allocation failures are */
/* OBSOLETE      intercepted before the serial driver gets involved. */ */
/* OBSOLETE   if (mac_input_buffer == NULL) */
/* OBSOLETE     mac_input_buffer = (char *) xmalloc (4096); */
/* OBSOLETE   /* Match on a name and open a port. */ */
/* OBSOLETE   if (strcmp (name, "modem") == 0) */
/* OBSOLETE     { */
/* OBSOLETE       err = OpenDriver ("\p.AIn", &input_refnum); */
/* OBSOLETE       if (err != 0) */
/* OBSOLETE 	{ */
/* OBSOLETE 	  return (-1); */
/* OBSOLETE 	} */
/* OBSOLETE       err = OpenDriver ("\p.AOut", &output_refnum); */
/* OBSOLETE       if (err != 0) */
/* OBSOLETE 	{ */
/* OBSOLETE 	  CloseDriver (input_refnum); */
/* OBSOLETE 	  return (-1); */
/* OBSOLETE 	} */
/* OBSOLETE     } */
/* OBSOLETE   else if (strcmp (name, "printer") == 0) */
/* OBSOLETE     { */
/* OBSOLETE       err = OpenDriver ("\p.BIn", &input_refnum); */
/* OBSOLETE       if (err != 0) */
/* OBSOLETE 	{ */
/* OBSOLETE 	  return (-1); */
/* OBSOLETE 	} */
/* OBSOLETE       err = OpenDriver ("\p.BOut", &output_refnum); */
/* OBSOLETE       if (err != 0) */
/* OBSOLETE 	{ */
/* OBSOLETE 	  CloseDriver (input_refnum); */
/* OBSOLETE 	  return (-1); */
/* OBSOLETE 	} */
/* OBSOLETE       /* fake */ */
/* OBSOLETE       scb->fd = 1; */
/* OBSOLETE       return 0; */
/* OBSOLETE     } */
/* OBSOLETE   else */
/* OBSOLETE     { */
/* OBSOLETE       error ("You must specify a valid serial port name; your choices are `modem' or `printer'."); */
/* OBSOLETE       errno = ENOENT; */
/* OBSOLETE       return (-1); */
/* OBSOLETE     } */
/* OBSOLETE   /* We got something open. */ */
/* OBSOLETE   if (1 /* using custom buffer */ ) */
/* OBSOLETE     SerSetBuf (input_refnum, mac_input_buffer, 4096); */
/* OBSOLETE   /* Set to a GDB-preferred state. */ */
/* OBSOLETE   SerReset (input_refnum, stop10 | noParity | data8 | baud9600); */
/* OBSOLETE   SerReset (output_refnum, stop10 | noParity | data8 | baud9600); */
/* OBSOLETE   { */
/* OBSOLETE     CntrlParam cb; */
/* OBSOLETE     struct SerShk *handshake; */
/* OBSOLETE  */
/* OBSOLETE     cb.ioCRefNum = output_refnum; */
/* OBSOLETE     cb.csCode = 14; */
/* OBSOLETE     handshake = (struct SerShk *) &cb.csParam[0]; */
/* OBSOLETE     handshake->fXOn = 0; */
/* OBSOLETE     handshake->fCTS = 0; */
/* OBSOLETE     handshake->xOn = 0; */
/* OBSOLETE     handshake->xOff = 0; */
/* OBSOLETE     handshake->errs = 0; */
/* OBSOLETE     handshake->evts = 0; */
/* OBSOLETE     handshake->fInX = 0; */
/* OBSOLETE     handshake->fDTR = 0; */
/* OBSOLETE     err = PBControl ((ParmBlkPtr) & cb, 0); */
/* OBSOLETE     if (err < 0) */
/* OBSOLETE       return (-1); */
/* OBSOLETE   } */
/* OBSOLETE   /* fake */ */
/* OBSOLETE   scb->fd = 1; */
/* OBSOLETE   return 0; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_noop (serial_t scb) */
/* OBSOLETE { */
/* OBSOLETE   return 0; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static void */
/* OBSOLETE mac_raw (serial_t scb) */
/* OBSOLETE { */
/* OBSOLETE   /* Always effectively in raw mode. */ */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE /* Read a character with user-specified timeout.  TIMEOUT is number of seconds */
/* OBSOLETE    to wait, or -1 to wait forever.  Use timeout of 0 to effect a poll.  Returns */
/* OBSOLETE    char if successful.  Returns -2 if timeout expired, EOF if line dropped */
/* OBSOLETE    dead, or -3 for any other error (see errno in that case). */ */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_readchar (serial_t scb, int timeout) */
/* OBSOLETE { */
/* OBSOLETE   int status, n; */
/* OBSOLETE   /* time_t */ unsigned long start_time, now; */
/* OBSOLETE   OSErr err; */
/* OBSOLETE   CntrlParam cb; */
/* OBSOLETE   IOParam pb; */
/* OBSOLETE  */
/* OBSOLETE   if (scb->bufcnt-- > 0) */
/* OBSOLETE     return *scb->bufp++; */
/* OBSOLETE  */
/* OBSOLETE   time (&start_time); */
/* OBSOLETE  */
/* OBSOLETE   while (1) */
/* OBSOLETE     { */
/* OBSOLETE       cb.ioCRefNum = input_refnum; */
/* OBSOLETE       cb.csCode = 2; */
/* OBSOLETE       err = PBStatus ((ParmBlkPtr) & cb, 0); */
/* OBSOLETE       if (err < 0) */
/* OBSOLETE 	return SERIAL_ERROR; */
/* OBSOLETE       n = *((long *) &cb.csParam[0]); */
/* OBSOLETE       if (n > 0) */
/* OBSOLETE 	{ */
/* OBSOLETE 	  pb.ioRefNum = input_refnum; */
/* OBSOLETE 	  pb.ioBuffer = (Ptr) (scb->buf); */
/* OBSOLETE 	  pb.ioReqCount = (n > 64 ? 64 : n); */
/* OBSOLETE 	  err = PBRead ((ParmBlkPtr) & pb, 0); */
/* OBSOLETE 	  if (err < 0) */
/* OBSOLETE 	    return SERIAL_ERROR; */
/* OBSOLETE 	  scb->bufcnt = pb.ioReqCount; */
/* OBSOLETE 	  scb->bufcnt--; */
/* OBSOLETE 	  scb->bufp = scb->buf; */
/* OBSOLETE 	  return *scb->bufp++; */
/* OBSOLETE 	} */
/* OBSOLETE       else if (timeout == 0) */
/* OBSOLETE 	return SERIAL_TIMEOUT; */
/* OBSOLETE       else if (timeout == -1) */
/* OBSOLETE 	; */
/* OBSOLETE       else */
/* OBSOLETE 	{ */
/* OBSOLETE 	  time (&now); */
/* OBSOLETE 	  if (now > start_time + timeout) */
/* OBSOLETE 	    return SERIAL_TIMEOUT; */
/* OBSOLETE 	} */
/* OBSOLETE       PROGRESS (1); */
/* OBSOLETE     } */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE /* mac_{get set}_tty_state() are both dummys to fill out the function */
/* OBSOLETE    vector.  Someday, they may do something real... */ */
/* OBSOLETE  */
/* OBSOLETE static serial_ttystate */
/* OBSOLETE mac_get_tty_state (serial_t scb) */
/* OBSOLETE { */
/* OBSOLETE   struct mac_ttystate *state; */
/* OBSOLETE  */
/* OBSOLETE   state = (struct mac_ttystate *) xmalloc (sizeof *state); */
/* OBSOLETE  */
/* OBSOLETE   return (serial_ttystate) state; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_set_tty_state (serial_t scb, serial_ttystate ttystate) */
/* OBSOLETE { */
/* OBSOLETE   return 0; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_noflush_set_tty_state (serial_t scb, serial_ttystate new_ttystate, */
/* OBSOLETE 			   serial_ttystate old_ttystate) */
/* OBSOLETE { */
/* OBSOLETE   return 0; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static void */
/* OBSOLETE mac_print_tty_state (serial_t scb, */
/* OBSOLETE 		     serial_ttystate ttystate, */
/* OBSOLETE 		     struct ui_file *stream) */
/* OBSOLETE { */
/* OBSOLETE   /* Nothing to print.  */ */
/* OBSOLETE   return; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE /* If there is a tricky formula to relate real baud rates */
/* OBSOLETE    to what the serial driver wants, we should use it.  Until */
/* OBSOLETE    we get one, this table will have to do.  */ */
/* OBSOLETE  */
/* OBSOLETE static struct */
/* OBSOLETE { */
/* OBSOLETE   int real_rate; */
/* OBSOLETE   int bits; */
/* OBSOLETE } */
/* OBSOLETE mac_baud_rate_table[] = */
/* OBSOLETE { */
/* OBSOLETE   { */
/* OBSOLETE     57600, baud57600 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     38400, 1 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     19200, baud19200 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     9600, baud9600 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     7200, baud7200 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     4800, baud4800 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     3600, baud3600 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     2400, baud2400 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     1800, baud1800 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     1200, baud1200 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     600, baud600 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     300, baud300 */
/* OBSOLETE   } */
/* OBSOLETE   , */
/* OBSOLETE   { */
/* OBSOLETE     0, 0 */
/* OBSOLETE   } */
/* OBSOLETE }; */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_set_baud_rate (serial_t scb, int rate) */
/* OBSOLETE { */
/* OBSOLETE   int i, bits; */
/* OBSOLETE  */
/* OBSOLETE   for (i = 0; mac_baud_rate_table[i].real_rate != 0; ++i) */
/* OBSOLETE     { */
/* OBSOLETE       if (mac_baud_rate_table[i].real_rate == rate) */
/* OBSOLETE 	{ */
/* OBSOLETE 	  bits = mac_baud_rate_table[i].bits; */
/* OBSOLETE 	  break; */
/* OBSOLETE 	} */
/* OBSOLETE     } */
/* OBSOLETE   SerReset (input_refnum, stop10 | noParity | data8 | bits); */
/* OBSOLETE   SerReset (output_refnum, stop10 | noParity | data8 | bits); */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_set_stop_bits (serial_t scb, int num) */
/* OBSOLETE { */
/* OBSOLETE   return 0; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE int first_mac_write = 0; */
/* OBSOLETE  */
/* OBSOLETE static int */
/* OBSOLETE mac_write (serial_t scb, const char *str, int len) */
/* OBSOLETE { */
/* OBSOLETE   OSErr err; */
/* OBSOLETE   IOParam pb; */
/* OBSOLETE  */
/* OBSOLETE   if (first_mac_write++ < 4) */
/* OBSOLETE     { */
/* OBSOLETE       sleep (1); */
/* OBSOLETE     } */
/* OBSOLETE   pb.ioRefNum = output_refnum; */
/* OBSOLETE   pb.ioBuffer = (Ptr) str; */
/* OBSOLETE   pb.ioReqCount = len; */
/* OBSOLETE   err = PBWrite ((ParmBlkPtr) & pb, 0); */
/* OBSOLETE   if (err < 0) */
/* OBSOLETE     { */
/* OBSOLETE       return 1; */
/* OBSOLETE     } */
/* OBSOLETE   return 0; */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static void */
/* OBSOLETE mac_close (serial_t scb) */
/* OBSOLETE { */
/* OBSOLETE   if (input_refnum) */
/* OBSOLETE     { */
/* OBSOLETE       if (1 /* custom buffer */ ) */
/* OBSOLETE 	SerSetBuf (input_refnum, mac_input_buffer, 0); */
/* OBSOLETE       CloseDriver (input_refnum); */
/* OBSOLETE       input_refnum = 0; */
/* OBSOLETE     } */
/* OBSOLETE   if (output_refnum) */
/* OBSOLETE     { */
/* OBSOLETE       if (0 /* custom buffer */ ) */
/* OBSOLETE 	SerSetBuf (input_refnum, mac_output_buffer, 0); */
/* OBSOLETE       CloseDriver (output_refnum); */
/* OBSOLETE       output_refnum = 0; */
/* OBSOLETE     } */
/* OBSOLETE } */
/* OBSOLETE  */
/* OBSOLETE static struct serial_ops mac_ops = */
/* OBSOLETE { */
/* OBSOLETE   "hardwire", */
/* OBSOLETE   0, */
/* OBSOLETE   mac_open, */
/* OBSOLETE   mac_close, */
/* OBSOLETE   mac_readchar, */
/* OBSOLETE   mac_write, */
/* OBSOLETE   mac_noop,			/* flush output */ */
/* OBSOLETE   mac_noop,			/* flush input */ */
/* OBSOLETE   mac_noop,			/* send break -- currently only for nindy */ */
/* OBSOLETE   mac_raw, */
/* OBSOLETE   mac_get_tty_state, */
/* OBSOLETE   mac_set_tty_state, */
/* OBSOLETE   mac_print_tty_state, */
/* OBSOLETE   mac_noflush_set_tty_state, */
/* OBSOLETE   mac_set_baud_rate, */
/* OBSOLETE   mac_set_stop_bits, */
/* OBSOLETE   mac_noop,			/* wait for output to drain */ */
/* OBSOLETE }; */
/* OBSOLETE  */
/* OBSOLETE void */
/* OBSOLETE _initialize_ser_mac (void) */
/* OBSOLETE { */
/* OBSOLETE   serial_add_interface (&mac_ops); */
/* OBSOLETE } */