]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/cons.c
xnu-1228.tar.gz
[apple/xnu.git] / bsd / dev / i386 / cons.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 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
50struct tty cons;
51struct tty *constty; /* current console device */
52
91447636
A
53int cnopen(__unused dev_t dev, int flag, int devtype, struct proc *pp);
54int cnclose(__unused dev_t dev, int flag, int mode, struct proc *pp);
55int cnread(__unused dev_t dev, struct uio *uio, int ioflag);
56int cnwrite(__unused dev_t dev, struct uio *uio, int ioflag);
57int cnioctl(__unused dev_t dev, int cmd, caddr_t addr, int flg, struct proc *p);
58int cnselect(__unused dev_t dev, int flag, void * wql, struct proc *p);
59
60void slave_cnenable(void);
61
62int alert(
63 __unused int width,
64 __unused int height,
65 __unused const char *title,
66 const char *msg,
67 int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8);
68int alert_done(void);
69
1c79356b
A
70/*ARGSUSED*/
71int
91447636 72cnopen(__unused dev_t dev, int flag, int devtype, struct proc *pp)
1c79356b
A
73{
74 dev_t device;
91447636
A
75 boolean_t funnel_state;
76 int error;
77
78 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
79
80 if (constty)
81 device = constty->t_dev;
82 else
83 device = cons.t_dev;
91447636
A
84 error = (*cdevsw[major(device)].d_open)(device, flag, devtype, pp);
85 thread_funnel_set(kernel_flock, funnel_state);
86
87 return(error);
1c79356b
A
88}
89
90/*ARGSUSED*/
91int
91447636 92cnclose(__unused dev_t dev, int flag, int mode, struct proc *pp)
1c79356b
A
93{
94 dev_t device;
91447636
A
95 boolean_t funnel_state;
96 int error;
1c79356b 97
91447636 98 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
99 if (constty)
100 device = constty->t_dev;
101 else
102 device = cons.t_dev;
91447636
A
103 error = (*cdevsw[major(device)].d_close)(device, flag, mode, pp);
104 thread_funnel_set(kernel_flock, funnel_state);
105
106 return(error);
107
108
1c79356b
A
109}
110
111/*ARGSUSED*/
112int
91447636 113cnread(__unused dev_t dev, struct uio *uio, int ioflag)
1c79356b
A
114{
115 dev_t device;
91447636
A
116 boolean_t funnel_state;
117 int error;
1c79356b 118
91447636 119 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
120 if (constty)
121 device = constty->t_dev;
122 else
123 device = cons.t_dev;
91447636
A
124 error = (*cdevsw[major(device)].d_read)(device, uio, ioflag);
125 thread_funnel_set(kernel_flock, funnel_state);
126
127 return(error);
1c79356b
A
128}
129
130/*ARGSUSED*/
131int
91447636 132cnwrite(__unused dev_t dev, struct uio *uio, int ioflag)
1c79356b
A
133{
134 dev_t device;
91447636
A
135 boolean_t funnel_state;
136 int error;
1c79356b 137
91447636 138 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
139 if (constty)
140 device = constty->t_dev;
141 else
142 device = cons.t_dev;
91447636
A
143 error = (*cdevsw[major(device)].d_write)(device, uio, ioflag);
144 thread_funnel_set(kernel_flock, funnel_state);
145
146 return(error);
1c79356b
A
147}
148
149/*ARGSUSED*/
150int
91447636 151cnioctl(__unused dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p)
1c79356b
A
152{
153 dev_t device;
91447636
A
154 boolean_t funnel_state;
155 int error;
156
157 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
158
159 if (constty)
160 device = constty->t_dev;
161 else
162 device = cons.t_dev;
163 /*
164 * Superuser can always use this to wrest control of console
165 * output from the "virtual" console.
166 */
91447636
A
167 if ((unsigned) cmd == TIOCCONS && constty) {
168 error = proc_suser(p);
169 if (error) {
170 goto out;
171 }
1c79356b 172 constty = NULL;
91447636
A
173 error = 0;
174 goto out;
1c79356b 175 }
91447636
A
176 error = (*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p);
177out:
178 thread_funnel_set(kernel_flock, funnel_state);
179
180 return(error);
1c79356b
A
181}
182
183/*ARGSUSED*/
91447636 184/* called with funnel held */
1c79356b 185int
91447636 186cnselect(__unused dev_t dev, int flag, void * wql, struct proc *p)
1c79356b
A
187{
188 dev_t device;
189
190 if (constty)
191 device = constty->t_dev;
192 else
193 device = cons.t_dev;
0b4e3aa0 194 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
1c79356b
A
195}
196
197#if 0 /* FIXME - using OSFMK console driver for the moment */
198int
199cngetc()
200{
201 dev_t device;
91447636
A
202 boolean_t funnel_state;
203 int error;
1c79356b 204
91447636 205 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
206 if (constty)
207 device = constty->t_dev;
208 else
209 device = cons.t_dev;
91447636
A
210 error = (*cdevsw[major(device)].d_getc)(device);
211 thread_funnel_set(kernel_flock, funnel_state);
212
213 return(error);
1c79356b
A
214}
215
216/*ARGSUSED*/
217int
218cnputc(c)
219 char c;
220{
221 dev_t device;
91447636
A
222 boolean_t funnel_state;
223 int error;
1c79356b 224
91447636 225 funnel_state = thread_funnel_set(kernel_flock, TRUE);
1c79356b
A
226 if (constty)
227 device = constty->t_dev;
228 else
229 device = cons.t_dev;
91447636
A
230 error = (*cdevsw[major(device)].d_putc)(device, c);
231 thread_funnel_set(kernel_flock, funnel_state);
232
233 return(error);
1c79356b
A
234}
235#endif
236
91447636
A
237void
238slave_cnenable(void)
1c79356b
A
239{
240 /* FIXME: what to do here? */
241}
1c79356b
A
242
243#if 0
244void
245kprintf( const char *format, ...)
246{
247 /* on PPC this outputs to the serial line */
248 /* nop on intel ... umeshv@apple.com */
249
250}
251#endif
252
253/*
254 * Write message to console; create an alert panel if no text-type window
255 * currently exists. Caller must call alert_done() when finished.
256 * The height and width arguments are not used; they are provided for
257 * compatibility with the 68k version of alert().
258 */
259int
260alert(
91447636
A
261 __unused int width,
262 __unused int height,
263 __unused const char *title,
1c79356b
A
264 const char *msg,
265 int p1,
266 int p2,
267 int p3,
268 int p4,
269 int p5,
270 int p6,
271 int p7,
272 int p8)
273{
274 char smsg[200];
275
2d21ac55 276 snprintf(smsg, sizeof(smsg), msg, p1, p2, p3, p4, p5, p6, p7, p8);
1c79356b
A
277#if FIXME /* [ */
278 /* DoAlert(title, smsg); */
279#else
280 printf("%s\n",smsg);
281#endif /* FIXME ] */
282
283 return 0;
284}
285
286int
91447636 287alert_done(void)
1c79356b
A
288{
289 /* DoRestore(); */
290 return 0;
291}
292