]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/cons.c
xnu-517.12.7.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 *
e5568f75
A
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.
1c79356b 11 *
e5568f75
A
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
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.
1c79356b
A
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
44struct tty cons;
45struct tty *constty; /* current console device */
46
47/*ARGSUSED*/
48int
49cnopen(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*/
64int
65cnclose(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*/
80int
81cnread(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*/
96int
97cnwrite(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*/
112int
113cnioctl(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*/
141int
0b4e3aa0 142cnselect(dev, flag, wql, p)
1c79356b
A
143 dev_t dev;
144 int flag;
0b4e3aa0 145 void * wql;
1c79356b
A
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;
0b4e3aa0 154 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
1c79356b
A
155}
156
157#if 0 /* FIXME - using OSFMK console driver for the moment */
158int
159cngetc()
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*/
171int
172cnputc(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
186slave_cnenable()
187{
188 /* FIXME: what to do here? */
189}
190#endif NCPUS > 1
191
192#if 0
193void
194kprintf( 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 */
208int
209alert(
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
235int
236alert_done()
237{
238 /* DoRestore(); */
239 return 0;
240}
241