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