]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/ppc/cons.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / dev / ppc / cons.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * Copyright (c) 1987, 1988 NeXT, Inc.
30 *
31 * HISTORY
32 * 7-Jan-93 Mac Gillon (mgillon) at NeXT
33 * Integrated POSIX support
34 *
35 * 12-Aug-87 John Seamons (jks) at NeXT
36 * Ported to NeXT.
37 */
38
39/*
40 * Indirect driver for console.
41 */
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/conf.h>
45#include <sys/ioctl.h>
46#include <sys/tty.h>
47#include <sys/proc.h>
48#include <sys/uio.h>
49#include <dev/ppc/cons.h>
50
51struct tty cons;
52struct tty *constty; /* current console device */
53
54/*ARGSUSED*/
55int
56consopen(dev, flag, devtype, pp)
57 dev_t dev;
58 int flag, devtype;
59 struct proc *pp;
60{
61 dev_t device;
91447636
A
62 boolean_t funnel_state;
63 int error;
64
65 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
66
67 if (constty)
68 device = constty->t_dev;
69 else
70 device = cons.t_dev;
91447636
A
71 error = (*cdevsw[major(device)].d_open)(device, flag, devtype, pp);
72 thread_funnel_set(kernel_flock, funnel_state);
73
74 return(error);
1c79356b
A
75}
76
77/*ARGSUSED*/
78int
79consclose(dev, flag, mode, pp)
80 dev_t dev;
81 int flag, mode;
82 struct proc *pp;
83{
84 dev_t device;
91447636
A
85 boolean_t funnel_state;
86 int error;
1c79356b 87
91447636 88 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
89 if (constty)
90 device = constty->t_dev;
91 else
92 device = cons.t_dev;
91447636
A
93 error = (*cdevsw[major(device)].d_close)(device, flag, mode, pp);
94 thread_funnel_set(kernel_flock, funnel_state);
95
96 return(error);
97
98
1c79356b
A
99}
100
101/*ARGSUSED*/
102int
103consread(dev, uio, ioflag)
104 dev_t dev;
105 struct uio *uio;
106 int ioflag;
107{
108 dev_t device;
91447636
A
109 boolean_t funnel_state;
110 int error;
1c79356b 111
91447636 112 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
113 if (constty)
114 device = constty->t_dev;
115 else
116 device = cons.t_dev;
91447636
A
117 error = (*cdevsw[major(device)].d_read)(device, uio, ioflag);
118 thread_funnel_set(kernel_flock, funnel_state);
119
120 return(error);
1c79356b
A
121}
122
123/*ARGSUSED*/
124int
125conswrite(dev, uio, ioflag)
126 dev_t dev;
127 struct uio *uio;
128 int ioflag;
129{
130 dev_t device;
91447636
A
131 boolean_t funnel_state;
132 int error;
1c79356b 133
91447636 134 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
135 if (constty)
136 device = constty->t_dev;
137 else
138 device = cons.t_dev;
91447636
A
139 error = (*cdevsw[major(device)].d_write)(device, uio, ioflag);
140 thread_funnel_set(kernel_flock, funnel_state);
141
142 return(error);
1c79356b
A
143}
144
145/*ARGSUSED*/
146int
147consioctl(dev, cmd, addr, flag, p)
148 dev_t dev;
149 int cmd;
150 caddr_t addr;
151 int flag;
152 struct proc *p;
153{
154 dev_t device;
91447636
A
155 boolean_t funnel_state;
156 int error;
157
158 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
159
160 if (constty)
161 device = constty->t_dev;
162 else
163 device = cons.t_dev;
164 /*
165 * Superuser can always use this to wrest control of console
166 * output from the "virtual" console.
167 */
168 if (cmd == TIOCCONS && constty) {
91447636
A
169 error = proc_suser(p);
170 if (error) {
171 goto out;
172 }
1c79356b 173 constty = NULL;
91447636
A
174 error = 0;
175 goto out;
1c79356b 176 }
91447636
A
177 error = (*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p);
178out:
179 thread_funnel_set(kernel_flock, funnel_state);
180
181 return(error);
1c79356b
A
182}
183
184/*ARGSUSED*/
91447636 185/* called with funnel held */
1c79356b 186int
0b4e3aa0 187consselect(dev, flag, wql, p)
1c79356b
A
188 dev_t dev;
189 int flag;
0b4e3aa0 190 void *wql;
1c79356b
A
191 struct proc *p;
192{
193 dev_t device;
194
195 if (constty)
196 device = constty->t_dev;
197 else
198 device = cons.t_dev;
0b4e3aa0 199 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
1c79356b
A
200}
201
202int
203cons_getc()
204{
205 dev_t device;
91447636
A
206 boolean_t funnel_state;
207 int error;
1c79356b 208
91447636 209 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
210 if (constty)
211 device = constty->t_dev;
212 else
213 device = cons.t_dev;
91447636
A
214 error = (*cdevsw[major(device)].d_getc)(device);
215 thread_funnel_set(kernel_flock, funnel_state);
216
217 return(error);
1c79356b
A
218}
219
220/*ARGSUSED*/
221int
222cons_putc(c)
223 char c;
224{
225 dev_t device;
91447636
A
226 boolean_t funnel_state;
227 int error;
1c79356b 228
91447636 229 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
230 if (constty)
231 device = constty->t_dev;
232 else
233 device = cons.t_dev;
91447636
A
234 error = (*cdevsw[major(device)].d_putc)(device, c);
235 thread_funnel_set(kernel_flock, funnel_state);
236
237 return(error);
1c79356b
A
238}
239
240/*
241 * Write message to console; create an alert panel if no text-type window
242 * currently exists. Caller must call alert_done() when finished.
243 * The height and width arguments are not used; they are provided for
244 * compatibility with the 68k version of alert().
245 */
246int
247alert(
248 int width,
249 int height,
250 const char *title,
251 const char *msg,
252 int p1,
253 int p2,
254 int p3,
255 int p4,
256 int p5,
257 int p6,
258 int p7,
259 int p8)
260{
261 char smsg[200];
262
263 sprintf(smsg, msg, p1, p2, p3, p4, p5, p6, p7, p8);
264#if FIXME /* [ */
265 /* DoAlert(title, smsg); */
266#else
267 printf("%s\n",smsg);
268#endif /* FIXME ] */
269
270 return 0;
271}
272
273int
274alert_done()
275{
276 /* DoRestore(); */
277 return 0;
278}
279