1 /* Remote serial interface for local (hardwired) serial ports for Macintosh.
2 Copyright 1994 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
27 /* This is unused for now. We just return a placeholder. */
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
));
47 char *mac_input_buffer
;
48 char *mac_output_buffer
;
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)
64 err
= OpenDriver ("\p.AIn", &input_refnum
);
69 err
= OpenDriver ("\p.AOut", &output_refnum
);
72 CloseDriver (input_refnum
);
76 else if (strcmp (name
, "printer") == 0)
78 err
= OpenDriver ("\p.BIn", &input_refnum
);
83 err
= OpenDriver ("\p.BOut", &output_refnum
);
86 CloseDriver (input_refnum
);
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
);
106 struct SerShk
*handshake
;
108 cb
.ioCRefNum
= output_refnum
;
110 handshake
= (struct SerShk
*) &cb
.csParam
[0];
119 err
= PBControl ((ParmBlkPtr
) &cb
, 0);
139 /* Always effectively in raw mode. */
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). */
148 mac_readchar (scb
, timeout
)
153 /* time_t */ unsigned long starttime
, now
;
158 if (scb
->bufcnt
-- > 0)
165 cb
.ioCRefNum
= input_refnum
;
167 err
= PBStatus ((ParmBlkPtr
) &cb
, 0);
170 n
= *((long *) &cb
.csParam
[0]);
173 pb
.ioRefNum
= input_refnum
;
174 pb
.ioBuffer
= (Ptr
) (scb
->buf
);
175 pb
.ioReqCount
= (n
> 64 ? 64 : n
);
176 err
= PBRead ((ParmBlkPtr
) &pb
, 0);
179 scb
->bufcnt
= pb
.ioReqCount
;
181 scb
->bufp
= scb
->buf
;
184 else if (timeout
== 0)
185 return SERIAL_TIMEOUT
;
186 else if (timeout
== -1)
191 if (now
> starttime
+ timeout
) {
192 printf_unfiltered ("start %u, now %u, timeout %d\n", starttime
, now
, timeout
);
193 return SERIAL_TIMEOUT
;
199 /* mac_{get set}_tty_state() are both dummys to fill out the function
200 vector. Someday, they may do something real... */
202 static serial_ttystate
203 mac_get_tty_state (scb
)
206 struct mac_ttystate
*state
;
208 state
= (struct mac_ttystate
*) xmalloc (sizeof *state
);
210 return (serial_ttystate
) state
;
214 mac_set_tty_state (scb
, ttystate
)
216 serial_ttystate ttystate
;
222 mac_noflush_set_tty_state (scb
, new_ttystate
, old_ttystate
)
224 serial_ttystate new_ttystate
;
225 serial_ttystate old_ttystate
;
231 mac_print_tty_state (scb
, ttystate
)
233 serial_ttystate ttystate
;
235 /* Nothing to print. */
240 mac_set_baud_rate (scb
, rate
)
248 mac_write (scb
, str
, len
)
256 pb
.ioRefNum
= output_refnum
;
257 pb
.ioBuffer
= (Ptr
) str
;
259 err
= PBWrite ((ParmBlkPtr
) &pb
, 0);
273 if (1 /* custom buffer */)
274 SerSetBuf (input_refnum
, mac_input_buffer
, 0);
275 CloseDriver (input_refnum
);
280 if (0 /* custom buffer */)
281 SetSetBuf (input_refnum
, mac_output_buffer
, 0);
282 CloseDriver (output_refnum
);
287 static struct serial_ops mac_ops
=
295 mac_noop
, /* flush output */
296 mac_noop
, /* flush input */
297 mac_noop
, /* send break -- currently only for nindy */
302 mac_noflush_set_tty_state
,
307 _initialize_ser_mac ()
309 serial_add_interface (&mac_ops
);