]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/cons.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / dev / i386 / cons.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
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.
1c79356b
A
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
47struct tty cons;
48struct tty *constty; /* current console device */
49
50/*ARGSUSED*/
51int
52cnopen(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*/
67int
68cnclose(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*/
83int
84cnread(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*/
99int
100cnwrite(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*/
115int
116cnioctl(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*/
144int
0b4e3aa0 145cnselect(dev, flag, wql, p)
1c79356b
A
146 dev_t dev;
147 int flag;
0b4e3aa0 148 void * wql;
1c79356b
A
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;
0b4e3aa0 157 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
1c79356b
A
158}
159
160#if 0 /* FIXME - using OSFMK console driver for the moment */
161int
162cngetc()
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*/
174int
175cnputc(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
189slave_cnenable()
190{
191 /* FIXME: what to do here? */
192}
193#endif NCPUS > 1
194
195#if 0
196void
197kprintf( 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 */
211int
212alert(
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
238int
239alert_done()
240{
241 /* DoRestore(); */
242 return 0;
243}
244