]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/cons.c
xnu-517.tar.gz
[apple/xnu.git] / bsd / dev / ppc / 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 #include <dev/ppc/cons.h>
47
48 struct tty cons;
49 struct tty *constty; /* current console device */
50
51 /*ARGSUSED*/
52 int
53 consopen(dev, flag, devtype, pp)
54 dev_t dev;
55 int flag, devtype;
56 struct proc *pp;
57 {
58 dev_t device;
59
60 if (constty)
61 device = constty->t_dev;
62 else
63 device = cons.t_dev;
64 return ((*cdevsw[major(device)].d_open)(device, flag, devtype, pp));
65 }
66
67 /*ARGSUSED*/
68 int
69 consclose(dev, flag, mode, pp)
70 dev_t dev;
71 int flag, mode;
72 struct proc *pp;
73 {
74 dev_t device;
75
76 if (constty)
77 device = constty->t_dev;
78 else
79 device = cons.t_dev;
80 return ((*cdevsw[major(device)].d_close)(device, flag, mode, pp));
81 }
82
83 /*ARGSUSED*/
84 int
85 consread(dev, uio, ioflag)
86 dev_t dev;
87 struct uio *uio;
88 int ioflag;
89 {
90 dev_t device;
91
92 if (constty)
93 device = constty->t_dev;
94 else
95 device = cons.t_dev;
96 return ((*cdevsw[major(device)].d_read)(device, uio, ioflag));
97 }
98
99 /*ARGSUSED*/
100 int
101 conswrite(dev, uio, ioflag)
102 dev_t dev;
103 struct uio *uio;
104 int ioflag;
105 {
106 dev_t device;
107
108 if (constty)
109 device = constty->t_dev;
110 else
111 device = cons.t_dev;
112 return ((*cdevsw[major(device)].d_write)(device, uio, ioflag));
113 }
114
115 /*ARGSUSED*/
116 int
117 consioctl(dev, cmd, addr, flag, p)
118 dev_t dev;
119 int cmd;
120 caddr_t addr;
121 int flag;
122 struct proc *p;
123 {
124 dev_t device;
125
126 if (constty)
127 device = constty->t_dev;
128 else
129 device = cons.t_dev;
130 /*
131 * Superuser can always use this to wrest control of console
132 * output from the "virtual" console.
133 */
134 if (cmd == TIOCCONS && constty) {
135 int error = suser(p->p_ucred, (u_short *) NULL);
136 if (error)
137 return (error);
138 constty = NULL;
139 return (0);
140 }
141 return ((*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p));
142 }
143
144 /*ARGSUSED*/
145 int
146 consselect(dev, flag, wql, p)
147 dev_t dev;
148 int flag;
149 void *wql;
150 struct proc *p;
151 {
152 dev_t device;
153
154 if (constty)
155 device = constty->t_dev;
156 else
157 device = cons.t_dev;
158 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
159 }
160
161 int
162 cons_getc()
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 cons_putc(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
187 /*
188 * Write message to console; create an alert panel if no text-type window
189 * currently exists. Caller must call alert_done() when finished.
190 * The height and width arguments are not used; they are provided for
191 * compatibility with the 68k version of alert().
192 */
193 int
194 alert(
195 int width,
196 int height,
197 const char *title,
198 const char *msg,
199 int p1,
200 int p2,
201 int p3,
202 int p4,
203 int p5,
204 int p6,
205 int p7,
206 int p8)
207 {
208 char smsg[200];
209
210 sprintf(smsg, msg, p1, p2, p3, p4, p5, p6, p7, p8);
211 #if FIXME /* [ */
212 /* DoAlert(title, smsg); */
213 #else
214 printf("%s\n",smsg);
215 #endif /* FIXME ] */
216
217 return 0;
218 }
219
220 int
221 alert_done()
222 {
223 /* DoRestore(); */
224 return 0;
225 }
226