]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/cons.c
xnu-792.25.20.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 * 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 #include <dev/ppc/cons.h>
44
45 struct tty cons;
46 struct tty *constty; /* current console device */
47
48 /*ARGSUSED*/
49 int
50 consopen(dev, flag, devtype, pp)
51 dev_t dev;
52 int flag, devtype;
53 struct proc *pp;
54 {
55 dev_t device;
56 boolean_t funnel_state;
57 int error;
58
59 funnel_state = thread_funnel_set(kernel_flock, TRUE);
60
61 if (constty)
62 device = constty->t_dev;
63 else
64 device = cons.t_dev;
65 error = (*cdevsw[major(device)].d_open)(device, flag, devtype, pp);
66 thread_funnel_set(kernel_flock, funnel_state);
67
68 return(error);
69 }
70
71 /*ARGSUSED*/
72 int
73 consclose(dev, flag, mode, pp)
74 dev_t dev;
75 int flag, mode;
76 struct proc *pp;
77 {
78 dev_t device;
79 boolean_t funnel_state;
80 int error;
81
82 funnel_state = thread_funnel_set(kernel_flock, TRUE);
83 if (constty)
84 device = constty->t_dev;
85 else
86 device = cons.t_dev;
87 error = (*cdevsw[major(device)].d_close)(device, flag, mode, pp);
88 thread_funnel_set(kernel_flock, funnel_state);
89
90 return(error);
91
92
93 }
94
95 /*ARGSUSED*/
96 int
97 consread(dev, uio, ioflag)
98 dev_t dev;
99 struct uio *uio;
100 int ioflag;
101 {
102 dev_t device;
103 boolean_t funnel_state;
104 int error;
105
106 funnel_state = thread_funnel_set(kernel_flock, TRUE);
107 if (constty)
108 device = constty->t_dev;
109 else
110 device = cons.t_dev;
111 error = (*cdevsw[major(device)].d_read)(device, uio, ioflag);
112 thread_funnel_set(kernel_flock, funnel_state);
113
114 return(error);
115 }
116
117 /*ARGSUSED*/
118 int
119 conswrite(dev, uio, ioflag)
120 dev_t dev;
121 struct uio *uio;
122 int ioflag;
123 {
124 dev_t device;
125 boolean_t funnel_state;
126 int error;
127
128 funnel_state = thread_funnel_set(kernel_flock, TRUE);
129 if (constty)
130 device = constty->t_dev;
131 else
132 device = cons.t_dev;
133 error = (*cdevsw[major(device)].d_write)(device, uio, ioflag);
134 thread_funnel_set(kernel_flock, funnel_state);
135
136 return(error);
137 }
138
139 /*ARGSUSED*/
140 int
141 consioctl(dev, cmd, addr, flag, p)
142 dev_t dev;
143 int cmd;
144 caddr_t addr;
145 int flag;
146 struct proc *p;
147 {
148 dev_t device;
149 boolean_t funnel_state;
150 int error;
151
152 funnel_state = thread_funnel_set(kernel_flock, TRUE);
153
154 if (constty)
155 device = constty->t_dev;
156 else
157 device = cons.t_dev;
158 /*
159 * Superuser can always use this to wrest control of console
160 * output from the "virtual" console.
161 */
162 if (cmd == TIOCCONS && constty) {
163 error = proc_suser(p);
164 if (error) {
165 goto out;
166 }
167 constty = NULL;
168 error = 0;
169 goto out;
170 }
171 error = (*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p);
172 out:
173 thread_funnel_set(kernel_flock, funnel_state);
174
175 return(error);
176 }
177
178 /*ARGSUSED*/
179 /* called with funnel held */
180 int
181 consselect(dev, flag, wql, p)
182 dev_t dev;
183 int flag;
184 void *wql;
185 struct proc *p;
186 {
187 dev_t device;
188
189 if (constty)
190 device = constty->t_dev;
191 else
192 device = cons.t_dev;
193 return ((*cdevsw[major(device)].d_select)(device, flag, wql, p));
194 }
195
196 int
197 cons_getc()
198 {
199 dev_t device;
200 boolean_t funnel_state;
201 int error;
202
203 funnel_state = thread_funnel_set(kernel_flock, TRUE);
204 if (constty)
205 device = constty->t_dev;
206 else
207 device = cons.t_dev;
208 error = (*cdevsw[major(device)].d_getc)(device);
209 thread_funnel_set(kernel_flock, funnel_state);
210
211 return(error);
212 }
213
214 /*ARGSUSED*/
215 int
216 cons_putc(c)
217 char c;
218 {
219 dev_t device;
220 boolean_t funnel_state;
221 int error;
222
223 funnel_state = thread_funnel_set(kernel_flock, TRUE);
224 if (constty)
225 device = constty->t_dev;
226 else
227 device = cons.t_dev;
228 error = (*cdevsw[major(device)].d_putc)(device, c);
229 thread_funnel_set(kernel_flock, funnel_state);
230
231 return(error);
232 }
233
234 /*
235 * Write message to console; create an alert panel if no text-type window
236 * currently exists. Caller must call alert_done() when finished.
237 * The height and width arguments are not used; they are provided for
238 * compatibility with the 68k version of alert().
239 */
240 int
241 alert(
242 int width,
243 int height,
244 const char *title,
245 const char *msg,
246 int p1,
247 int p2,
248 int p3,
249 int p4,
250 int p5,
251 int p6,
252 int p7,
253 int p8)
254 {
255 char smsg[200];
256
257 sprintf(smsg, msg, p1, p2, p3, p4, p5, p6, p7, p8);
258 #if FIXME /* [ */
259 /* DoAlert(title, smsg); */
260 #else
261 printf("%s\n",smsg);
262 #endif /* FIXME ] */
263
264 return 0;
265 }
266
267 int
268 alert_done()
269 {
270 /* DoRestore(); */
271 return 0;
272 }
273