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