]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/cons.c
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / dev / ppc / cons.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
51 struct tty cons;
52 struct tty *constty; /* current console device */
53
54 /*ARGSUSED*/
55 int
56 consopen(dev, flag, devtype, pp)
57 dev_t dev;
58 int flag, devtype;
59 struct proc *pp;
60 {
61 dev_t device;
62 boolean_t funnel_state;
63 int error;
64
65 funnel_state = thread_funnel_set(kernel_flock, TRUE);
66
67 if (constty)
68 device = constty->t_dev;
69 else
70 device = cons.t_dev;
71 error = (*cdevsw[major(device)].d_open)(device, flag, devtype, pp);
72 thread_funnel_set(kernel_flock, funnel_state);
73
74 return(error);
75 }
76
77 /*ARGSUSED*/
78 int
79 consclose(dev, flag, mode, pp)
80 dev_t dev;
81 int flag, mode;
82 struct proc *pp;
83 {
84 dev_t device;
85 boolean_t funnel_state;
86 int error;
87
88 funnel_state = thread_funnel_set(kernel_flock, TRUE);
89 if (constty)
90 device = constty->t_dev;
91 else
92 device = cons.t_dev;
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
99 }
100
101 /*ARGSUSED*/
102 int
103 consread(dev, uio, ioflag)
104 dev_t dev;
105 struct uio *uio;
106 int ioflag;
107 {
108 dev_t device;
109 boolean_t funnel_state;
110 int error;
111
112 funnel_state = thread_funnel_set(kernel_flock, TRUE);
113 if (constty)
114 device = constty->t_dev;
115 else
116 device = cons.t_dev;
117 error = (*cdevsw[major(device)].d_read)(device, uio, ioflag);
118 thread_funnel_set(kernel_flock, funnel_state);
119
120 return(error);
121 }
122
123 /*ARGSUSED*/
124 int
125 conswrite(dev, uio, ioflag)
126 dev_t dev;
127 struct uio *uio;
128 int ioflag;
129 {
130 dev_t device;
131 boolean_t funnel_state;
132 int error;
133
134 funnel_state = thread_funnel_set(kernel_flock, TRUE);
135 if (constty)
136 device = constty->t_dev;
137 else
138 device = cons.t_dev;
139 error = (*cdevsw[major(device)].d_write)(device, uio, ioflag);
140 thread_funnel_set(kernel_flock, funnel_state);
141
142 return(error);
143 }
144
145 /*ARGSUSED*/
146 int
147 consioctl(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;
155 boolean_t funnel_state;
156 int error;
157
158 funnel_state = thread_funnel_set(kernel_flock, TRUE);
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) {
169 error = proc_suser(p);
170 if (error) {
171 goto out;
172 }
173 constty = NULL;
174 error = 0;
175 goto out;
176 }
177 error = (*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p);
178 out:
179 thread_funnel_set(kernel_flock, funnel_state);
180
181 return(error);
182 }
183
184 /*ARGSUSED*/
185 /* called with funnel held */
186 int
187 consselect(dev, flag, wql, p)
188 dev_t dev;
189 int flag;
190 void *wql;
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;
199 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
200 }
201
202 int
203 cons_getc()
204 {
205 dev_t device;
206 boolean_t funnel_state;
207 int error;
208
209 funnel_state = thread_funnel_set(kernel_flock, TRUE);
210 if (constty)
211 device = constty->t_dev;
212 else
213 device = cons.t_dev;
214 error = (*cdevsw[major(device)].d_getc)(device);
215 thread_funnel_set(kernel_flock, funnel_state);
216
217 return(error);
218 }
219
220 /*ARGSUSED*/
221 int
222 cons_putc(c)
223 char c;
224 {
225 dev_t device;
226 boolean_t funnel_state;
227 int error;
228
229 funnel_state = thread_funnel_set(kernel_flock, TRUE);
230 if (constty)
231 device = constty->t_dev;
232 else
233 device = cons.t_dev;
234 error = (*cdevsw[major(device)].d_putc)(device, c);
235 thread_funnel_set(kernel_flock, funnel_state);
236
237 return(error);
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 */
246 int
247 alert(
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
273 int
274 alert_done()
275 {
276 /* DoRestore(); */
277 return 0;
278 }
279