]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * Copyright (c) 1987, 1988 NeXT, Inc. | |
30 | * | |
31 | * HISTORY | |
32 | * 7-Jan-93 Mac Gillon (mgillon) at NeXT | |
33 | * Integrated POSIX support | |
34 | * | |
35 | * 12-Aug-87 John Seamons (jks) at NeXT | |
36 | * Ported to NeXT. | |
37 | */ | |
38 | ||
39 | /* | |
40 | * Indirect driver for console. | |
41 | */ | |
42 | #include <sys/param.h> | |
43 | #include <sys/systm.h> | |
44 | #include <sys/conf.h> | |
45 | #include <sys/ioctl.h> | |
46 | #include <sys/tty.h> | |
47 | #include <sys/proc.h> | |
48 | #include <sys/uio.h> | |
49 | #include <dev/ppc/cons.h> | |
50 | ||
51 | struct tty cons; | |
52 | struct tty *constty; /* current console device */ | |
53 | ||
54 | /*ARGSUSED*/ | |
55 | int | |
2d21ac55 | 56 | consopen(__unused dev_t dev, int flag, int devtype, struct proc *pp) |
1c79356b A |
57 | { |
58 | dev_t device; | |
91447636 A |
59 | boolean_t funnel_state; |
60 | int error; | |
61 | ||
62 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
1c79356b A |
63 | |
64 | if (constty) | |
65 | device = constty->t_dev; | |
66 | else | |
67 | device = cons.t_dev; | |
91447636 A |
68 | error = (*cdevsw[major(device)].d_open)(device, flag, devtype, pp); |
69 | thread_funnel_set(kernel_flock, funnel_state); | |
70 | ||
71 | return(error); | |
1c79356b A |
72 | } |
73 | ||
74 | /*ARGSUSED*/ | |
75 | int | |
2d21ac55 | 76 | consclose(__unused dev_t dev, int flag, int mode, struct proc *pp) |
1c79356b A |
77 | { |
78 | dev_t device; | |
91447636 A |
79 | boolean_t funnel_state; |
80 | int error; | |
1c79356b | 81 | |
91447636 | 82 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
83 | if (constty) |
84 | device = constty->t_dev; | |
85 | else | |
86 | device = cons.t_dev; | |
91447636 A |
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 | ||
1c79356b A |
93 | } |
94 | ||
95 | /*ARGSUSED*/ | |
96 | int | |
2d21ac55 | 97 | consread(__unused dev_t dev, struct uio *uio, int ioflag) |
1c79356b A |
98 | { |
99 | dev_t device; | |
91447636 A |
100 | boolean_t funnel_state; |
101 | int error; | |
1c79356b | 102 | |
91447636 | 103 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
104 | if (constty) |
105 | device = constty->t_dev; | |
106 | else | |
107 | device = cons.t_dev; | |
91447636 A |
108 | error = (*cdevsw[major(device)].d_read)(device, uio, ioflag); |
109 | thread_funnel_set(kernel_flock, funnel_state); | |
110 | ||
111 | return(error); | |
1c79356b A |
112 | } |
113 | ||
114 | /*ARGSUSED*/ | |
115 | int | |
2d21ac55 | 116 | conswrite(__unused dev_t dev, struct uio *uio, int ioflag) |
1c79356b A |
117 | { |
118 | dev_t device; | |
91447636 A |
119 | boolean_t funnel_state; |
120 | int error; | |
1c79356b | 121 | |
91447636 | 122 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
123 | if (constty) |
124 | device = constty->t_dev; | |
125 | else | |
126 | device = cons.t_dev; | |
91447636 A |
127 | error = (*cdevsw[major(device)].d_write)(device, uio, ioflag); |
128 | thread_funnel_set(kernel_flock, funnel_state); | |
129 | ||
130 | return(error); | |
1c79356b A |
131 | } |
132 | ||
133 | /*ARGSUSED*/ | |
134 | int | |
2d21ac55 | 135 | consioctl(__unused dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p) |
1c79356b A |
136 | { |
137 | dev_t device; | |
91447636 A |
138 | boolean_t funnel_state; |
139 | int error; | |
140 | ||
141 | funnel_state = thread_funnel_set(kernel_flock, TRUE); | |
1c79356b A |
142 | |
143 | if (constty) | |
144 | device = constty->t_dev; | |
145 | else | |
146 | device = cons.t_dev; | |
147 | /* | |
148 | * Superuser can always use this to wrest control of console | |
149 | * output from the "virtual" console. | |
150 | */ | |
2d21ac55 | 151 | if ((unsigned int)cmd == TIOCCONS && constty) { |
91447636 A |
152 | error = proc_suser(p); |
153 | if (error) { | |
154 | goto out; | |
155 | } | |
1c79356b | 156 | constty = NULL; |
91447636 A |
157 | error = 0; |
158 | goto out; | |
1c79356b | 159 | } |
91447636 A |
160 | error = (*cdevsw[major(device)].d_ioctl)(device, cmd, addr, flag, p); |
161 | out: | |
162 | thread_funnel_set(kernel_flock, funnel_state); | |
163 | ||
164 | return(error); | |
1c79356b A |
165 | } |
166 | ||
167 | /*ARGSUSED*/ | |
91447636 | 168 | /* called with funnel held */ |
1c79356b | 169 | int |
2d21ac55 | 170 | consselect(__unused dev_t dev, int flag, void *wql, struct proc *p) |
1c79356b A |
171 | { |
172 | dev_t device; | |
173 | ||
174 | if (constty) | |
175 | device = constty->t_dev; | |
176 | else | |
177 | device = cons.t_dev; | |
0b4e3aa0 | 178 | return ((*cdevsw[major(device)].d_select)(device, flag, wql, p)); |
1c79356b A |
179 | } |
180 | ||
181 | int | |
2d21ac55 | 182 | cons_getc(__unused dev_t dev) |
1c79356b A |
183 | { |
184 | dev_t device; | |
91447636 A |
185 | boolean_t funnel_state; |
186 | int error; | |
1c79356b | 187 | |
91447636 | 188 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
189 | if (constty) |
190 | device = constty->t_dev; | |
191 | else | |
192 | device = cons.t_dev; | |
91447636 A |
193 | error = (*cdevsw[major(device)].d_getc)(device); |
194 | thread_funnel_set(kernel_flock, funnel_state); | |
195 | ||
196 | return(error); | |
1c79356b A |
197 | } |
198 | ||
1c79356b | 199 | int |
2d21ac55 | 200 | cons_putc(__unused dev_t dev, char c) |
1c79356b A |
201 | { |
202 | dev_t device; | |
91447636 A |
203 | boolean_t funnel_state; |
204 | int error; | |
1c79356b | 205 | |
91447636 | 206 | funnel_state = thread_funnel_set(kernel_flock, TRUE); |
1c79356b A |
207 | if (constty) |
208 | device = constty->t_dev; | |
209 | else | |
210 | device = cons.t_dev; | |
91447636 A |
211 | error = (*cdevsw[major(device)].d_putc)(device, c); |
212 | thread_funnel_set(kernel_flock, funnel_state); | |
213 | ||
214 | return(error); | |
1c79356b A |
215 | } |
216 | ||
217 | /* | |
218 | * Write message to console; create an alert panel if no text-type window | |
219 | * currently exists. Caller must call alert_done() when finished. | |
220 | * The height and width arguments are not used; they are provided for | |
221 | * compatibility with the 68k version of alert(). | |
222 | */ | |
223 | int | |
224 | alert( | |
2d21ac55 A |
225 | __unused int width, |
226 | __unused int height, | |
227 | __unused const char *title, | |
1c79356b A |
228 | const char *msg, |
229 | int p1, | |
230 | int p2, | |
231 | int p3, | |
232 | int p4, | |
233 | int p5, | |
234 | int p6, | |
235 | int p7, | |
236 | int p8) | |
237 | { | |
238 | char smsg[200]; | |
239 | ||
2d21ac55 | 240 | snprintf(smsg, sizeof(smsg), msg, p1, p2, p3, p4, p5, p6, p7, p8); |
1c79356b A |
241 | #if FIXME /* [ */ |
242 | /* DoAlert(title, smsg); */ | |
243 | #else | |
244 | printf("%s\n",smsg); | |
245 | #endif /* FIXME ] */ | |
246 | ||
247 | return 0; | |
248 | } | |
249 | ||
250 | int | |
2d21ac55 | 251 | alert_done(void) |
1c79356b A |
252 | { |
253 | /* DoRestore(); */ | |
254 | return 0; | |
255 | } | |
256 |