]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a 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. | |
8f6c56a5 | 11 | * |
6601e61a 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 | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a 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. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
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 | ||
44 | struct tty cons; | |
45 | struct tty *constty; /* current console device */ | |
46 | ||
91447636 A |
47 | int cnopen(__unused dev_t dev, int flag, int devtype, struct proc *pp); |
48 | int cnclose(__unused dev_t dev, int flag, int mode, struct proc *pp); | |
49 | int cnread(__unused dev_t dev, struct uio *uio, int ioflag); | |
50 | int cnwrite(__unused dev_t dev, struct uio *uio, int ioflag); | |
51 | int cnioctl(__unused dev_t dev, int cmd, caddr_t addr, int flg, struct proc *p); | |
52 | int cnselect(__unused dev_t dev, int flag, void * wql, struct proc *p); | |
53 | ||
54 | void slave_cnenable(void); | |
55 | ||
56 | int alert( | |
57 | __unused int width, | |
58 | __unused int height, | |
59 | __unused const char *title, | |
60 | const char *msg, | |
61 | int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8); | |
62 | int alert_done(void); | |
63 | ||
1c79356b A |
64 | /*ARGSUSED*/ |
65 | int | |
91447636 | 66 | cnopen(__unused dev_t dev, int flag, int devtype, struct proc *pp) |
1c79356b A |
67 | { |
68 | dev_t device; | |
91447636 A |
69 | boolean_t funnel_state; |
70 | int error; | |
71 | ||
72 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
1c79356b A |
73 | |
74 | if (constty) | |
75 | device = constty->t_dev; | |
76 | else | |
77 | device = cons.t_dev; | |
91447636 A |
78 | error = (*cdevsw[major(device)].d_open)(device, flag, devtype, pp); |
79 | thread_funnel_set(kernel_flock, funnel_state); | |
80 | ||
81 | return(error); | |
1c79356b A |
82 | } |
83 | ||
84 | /*ARGSUSED*/ | |
85 | int | |
91447636 | 86 | cnclose(__unused dev_t dev, int flag, int mode, struct proc *pp) |
1c79356b A |
87 | { |
88 | dev_t device; | |
91447636 A |
89 | boolean_t funnel_state; |
90 | int error; | |
1c79356b | 91 | |
91447636 | 92 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
93 | if (constty) |
94 | device = constty->t_dev; | |
95 | else | |
96 | device = cons.t_dev; | |
91447636 A |
97 | error = (*cdevsw[major(device)].d_close)(device, flag, mode, pp); |
98 | thread_funnel_set(kernel_flock, funnel_state); | |
99 | ||
100 | return(error); | |
101 | ||
102 | ||
1c79356b A |
103 | } |
104 | ||
105 | /*ARGSUSED*/ | |
106 | int | |
91447636 | 107 | cnread(__unused dev_t dev, struct uio *uio, int ioflag) |
1c79356b A |
108 | { |
109 | dev_t device; | |
91447636 A |
110 | boolean_t funnel_state; |
111 | int error; | |
1c79356b | 112 | |
91447636 | 113 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
114 | if (constty) |
115 | device = constty->t_dev; | |
116 | else | |
117 | device = cons.t_dev; | |
91447636 A |
118 | error = (*cdevsw[major(device)].d_read)(device, uio, ioflag); |
119 | thread_funnel_set(kernel_flock, funnel_state); | |
120 | ||
121 | return(error); | |
1c79356b A |
122 | } |
123 | ||
124 | /*ARGSUSED*/ | |
125 | int | |
91447636 | 126 | cnwrite(__unused dev_t dev, struct uio *uio, int ioflag) |
1c79356b A |
127 | { |
128 | dev_t device; | |
91447636 A |
129 | boolean_t funnel_state; |
130 | int error; | |
1c79356b | 131 | |
91447636 | 132 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
133 | if (constty) |
134 | device = constty->t_dev; | |
135 | else | |
136 | device = cons.t_dev; | |
91447636 A |
137 | error = (*cdevsw[major(device)].d_write)(device, uio, ioflag); |
138 | thread_funnel_set(kernel_flock, funnel_state); | |
139 | ||
140 | return(error); | |
1c79356b A |
141 | } |
142 | ||
143 | /*ARGSUSED*/ | |
144 | int | |
91447636 | 145 | cnioctl(__unused dev_t dev, int cmd, caddr_t addr, int flag, struct proc *p) |
1c79356b A |
146 | { |
147 | dev_t device; | |
91447636 A |
148 | boolean_t funnel_state; |
149 | int error; | |
150 | ||
151 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
1c79356b A |
152 | |
153 | if (constty) | |
154 | device = constty->t_dev; | |
155 | else | |
156 | device = cons.t_dev; | |
157 | /* | |
158 | * Superuser can always use this to wrest control of console | |
159 | * output from the "virtual" console. | |
160 | */ | |
91447636 A |
161 | if ((unsigned) cmd == TIOCCONS && constty) { |
162 | error = proc_suser(p); | |
163 | if (error) { | |
164 | goto out; | |
165 | } | |
1c79356b | 166 | constty = NULL; |
91447636 A |
167 | error = 0; |
168 | goto out; | |
1c79356b | 169 | } |
91447636 A |
170 | error = (*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p); |
171 | out: | |
172 | thread_funnel_set(kernel_flock, funnel_state); | |
173 | ||
174 | return(error); | |
1c79356b A |
175 | } |
176 | ||
177 | /*ARGSUSED*/ | |
91447636 | 178 | /* called with funnel held */ |
1c79356b | 179 | int |
91447636 | 180 | cnselect(__unused dev_t dev, int flag, void * wql, struct proc *p) |
1c79356b A |
181 | { |
182 | dev_t device; | |
183 | ||
184 | if (constty) | |
185 | device = constty->t_dev; | |
186 | else | |
187 | device = cons.t_dev; | |
0b4e3aa0 | 188 | return ((*cdevsw[major(device)].d_select)(device, flag, wql, p)); |
1c79356b A |
189 | } |
190 | ||
191 | #if 0 /* FIXME - using OSFMK console driver for the moment */ | |
192 | int | |
193 | cngetc() | |
194 | { | |
195 | dev_t device; | |
91447636 A |
196 | boolean_t funnel_state; |
197 | int error; | |
1c79356b | 198 | |
91447636 | 199 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
200 | if (constty) |
201 | device = constty->t_dev; | |
202 | else | |
203 | device = cons.t_dev; | |
91447636 A |
204 | error = (*cdevsw[major(device)].d_getc)(device); |
205 | thread_funnel_set(kernel_flock, funnel_state); | |
206 | ||
207 | return(error); | |
1c79356b A |
208 | } |
209 | ||
210 | /*ARGSUSED*/ | |
211 | int | |
212 | cnputc(c) | |
213 | char c; | |
214 | { | |
215 | dev_t device; | |
91447636 A |
216 | boolean_t funnel_state; |
217 | int error; | |
1c79356b | 218 | |
91447636 | 219 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
220 | if (constty) |
221 | device = constty->t_dev; | |
222 | else | |
223 | device = cons.t_dev; | |
91447636 A |
224 | error = (*cdevsw[major(device)].d_putc)(device, c); |
225 | thread_funnel_set(kernel_flock, funnel_state); | |
226 | ||
227 | return(error); | |
1c79356b A |
228 | } |
229 | #endif | |
230 | ||
91447636 A |
231 | void |
232 | slave_cnenable(void) | |
1c79356b A |
233 | { |
234 | /* FIXME: what to do here? */ | |
235 | } | |
1c79356b A |
236 | |
237 | #if 0 | |
238 | void | |
239 | kprintf( const char *format, ...) | |
240 | { | |
241 | /* on PPC this outputs to the serial line */ | |
242 | /* nop on intel ... umeshv@apple.com */ | |
243 | ||
244 | } | |
245 | #endif | |
246 | ||
247 | /* | |
248 | * Write message to console; create an alert panel if no text-type window | |
249 | * currently exists. Caller must call alert_done() when finished. | |
250 | * The height and width arguments are not used; they are provided for | |
251 | * compatibility with the 68k version of alert(). | |
252 | */ | |
253 | int | |
254 | alert( | |
91447636 A |
255 | __unused int width, |
256 | __unused int height, | |
257 | __unused const char *title, | |
1c79356b A |
258 | const char *msg, |
259 | int p1, | |
260 | int p2, | |
261 | int p3, | |
262 | int p4, | |
263 | int p5, | |
264 | int p6, | |
265 | int p7, | |
266 | int p8) | |
267 | { | |
268 | char smsg[200]; | |
269 | ||
270 | sprintf(smsg, msg, p1, p2, p3, p4, p5, p6, p7, p8); | |
271 | #if FIXME /* [ */ | |
272 | /* DoAlert(title, smsg); */ | |
273 | #else | |
274 | printf("%s\n",smsg); | |
275 | #endif /* FIXME ] */ | |
276 | ||
277 | return 0; | |
278 | } | |
279 | ||
280 | int | |
91447636 | 281 | alert_done(void) |
1c79356b A |
282 | { |
283 | /* DoRestore(); */ | |
284 | return 0; | |
285 | } | |
286 |