]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/cons.c
118878bd1197da648879c5c4e03ac9c89d75b201
[apple/xnu.git] / bsd / dev / i386 / cons.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 1987, 1988 NeXT, Inc.
24 *
25 * HISTORY
26 * 7-Jan-93 Mac Gillon (mgillon) at NeXT
27 * Integrated POSIX support
28 *
29 * 12-Aug-87 John Seamons (jks) at NeXT
30 * Ported to NeXT.
31 */
32
33 /*
34 * Indirect driver for console.
35 */
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/conf.h>
39 #include <sys/ioctl.h>
40 #include <sys/tty.h>
41 #include <sys/proc.h>
42 #include <sys/uio.h>
43
44 struct tty cons;
45 struct tty *constty; /* current console device */
46
47 /*ARGSUSED*/
48 int
49 cnopen(dev, flag, devtype, pp)
50 dev_t dev;
51 int flag, devtype;
52 struct proc *pp;
53 {
54 dev_t device;
55
56 if (constty)
57 device = constty->t_dev;
58 else
59 device = cons.t_dev;
60 return ((*cdevsw[major(device)].d_open)(device, flag, devtype, pp));
61 }
62
63 /*ARGSUSED*/
64 int
65 cnclose(dev, flag, mode, pp)
66 dev_t dev;
67 int flag, mode;
68 struct proc *pp;
69 {
70 dev_t device;
71
72 if (constty)
73 device = constty->t_dev;
74 else
75 device = cons.t_dev;
76 return ((*cdevsw[major(device)].d_close)(device, flag, mode, pp));
77 }
78
79 /*ARGSUSED*/
80 int
81 cnread(dev, uio, ioflag)
82 dev_t dev;
83 struct uio *uio;
84 int ioflag;
85 {
86 dev_t device;
87
88 if (constty)
89 device = constty->t_dev;
90 else
91 device = cons.t_dev;
92 return ((*cdevsw[major(device)].d_read)(device, uio, ioflag));
93 }
94
95 /*ARGSUSED*/
96 int
97 cnwrite(dev, uio, ioflag)
98 dev_t dev;
99 struct uio *uio;
100 int ioflag;
101 {
102 dev_t device;
103
104 if (constty)
105 device = constty->t_dev;
106 else
107 device = cons.t_dev;
108 return ((*cdevsw[major(device)].d_write)(device, uio, ioflag));
109 }
110
111 /*ARGSUSED*/
112 int
113 cnioctl(dev, cmd, addr, flag, p)
114 dev_t dev;
115 int cmd;
116 caddr_t addr;
117 int flag;
118 struct proc *p;
119 {
120 dev_t device;
121
122 if (constty)
123 device = constty->t_dev;
124 else
125 device = cons.t_dev;
126 /*
127 * Superuser can always use this to wrest control of console
128 * output from the "virtual" console.
129 */
130 if (cmd == TIOCCONS && constty) {
131 int error = suser(p->p_ucred, (u_short *) NULL);
132 if (error)
133 return (error);
134 constty = NULL;
135 return (0);
136 }
137 return ((*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p));
138 }
139
140 /*ARGSUSED*/
141 int
142 cnselect(dev, flag, wql, p)
143 dev_t dev;
144 int flag;
145 void * wql;
146 struct proc *p;
147 {
148 dev_t device;
149
150 if (constty)
151 device = constty->t_dev;
152 else
153 device = cons.t_dev;
154 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
155 }
156
157 #if 0 /* FIXME - using OSFMK console driver for the moment */
158 int
159 cngetc()
160 {
161 dev_t device;
162
163 if (constty)
164 device = constty->t_dev;
165 else
166 device = cons.t_dev;
167 return ((*cdevsw[major(device)].d_getc)(device));
168 }
169
170 /*ARGSUSED*/
171 int
172 cnputc(c)
173 char c;
174 {
175 dev_t device;
176
177 if (constty)
178 device = constty->t_dev;
179 else
180 device = cons.t_dev;
181 return ((*cdevsw[major(device)].d_putc)(device, c));
182 }
183 #endif
184
185 #if NCPUS > 1
186 slave_cnenable()
187 {
188 /* FIXME: what to do here? */
189 }
190 #endif NCPUS > 1
191
192 #if 0
193 void
194 kprintf( const char *format, ...)
195 {
196 /* on PPC this outputs to the serial line */
197 /* nop on intel ... umeshv@apple.com */
198
199 }
200 #endif
201
202 /*
203 * Write message to console; create an alert panel if no text-type window
204 * currently exists. Caller must call alert_done() when finished.
205 * The height and width arguments are not used; they are provided for
206 * compatibility with the 68k version of alert().
207 */
208 int
209 alert(
210 int width,
211 int height,
212 const char *title,
213 const char *msg,
214 int p1,
215 int p2,
216 int p3,
217 int p4,
218 int p5,
219 int p6,
220 int p7,
221 int p8)
222 {
223 char smsg[200];
224
225 sprintf(smsg, msg, p1, p2, p3, p4, p5, p6, p7, p8);
226 #if FIXME /* [ */
227 /* DoAlert(title, smsg); */
228 #else
229 printf("%s\n",smsg);
230 #endif /* FIXME ] */
231
232 return 0;
233 }
234
235 int
236 alert_done()
237 {
238 /* DoRestore(); */
239 return 0;
240 }
241