Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1988 University of Utah. | |
3 | * Copyright (c) 1991 The Regents of the University of California. | |
4 | * All rights reserved. | |
5 | * | |
6 | * This code is derived from software contributed to Berkeley by | |
7 | * the Systems Programming Group of the University of Utah Computer | |
8 | * Science Department. | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | |
15 | * 2. Redistributions in binary form must reproduce the above copyright | |
16 | * notice, this list of conditions and the following disclaimer in the | |
17 | * documentation and/or other materials provided with the distribution. | |
18 | * 3. All advertising materials mentioning features or use of this software | |
19 | * must display the following acknowledgement: | |
20 | * This product includes software developed by the University of | |
21 | * California, Berkeley and its contributors. | |
22 | * 4. Neither the name of the University nor the names of its contributors | |
23 | * may be used to endorse or promote products derived from this software | |
24 | * without specific prior written permission. | |
25 | * | |
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
36 | * SUCH DAMAGE. | |
37 | * | |
78ed81a3 | 38 | * from: @(#)cons.c 7.2 (Berkeley) 5/9/91 |
39 | * $Id: cons.c,v 1.3 1993/10/16 14:14:49 rgrimes Exp $ | |
15637ed4 RG |
40 | */ |
41 | ||
42 | ||
43 | #include "sys/param.h" | |
44 | #include "sys/proc.h" | |
45 | #include "sys/user.h" | |
46 | #include "sys/systm.h" | |
47 | #include "sys/buf.h" | |
48 | #include "sys/ioctl.h" | |
49 | #include "sys/tty.h" | |
50 | #include "sys/file.h" | |
51 | #include "sys/conf.h" | |
52 | ||
53 | #include "cons.h" | |
54 | ||
55 | /* XXX - all this could be autoconfig()ed */ | |
56 | int pccnprobe(), pccninit(), pccngetc(), pccnputc(); | |
57 | #include "com.h" | |
58 | #if NCOM > 0 | |
59 | int comcnprobe(), comcninit(), comcngetc(), comcnputc(); | |
60 | #endif | |
61 | ||
62 | struct consdev constab[] = { | |
63 | { pccnprobe, pccninit, pccngetc, pccnputc }, | |
64 | #if NCOM > 0 | |
65 | { comcnprobe, comcninit, comcngetc, comcnputc }, | |
66 | #endif | |
67 | { 0 }, | |
68 | }; | |
69 | /* end XXX */ | |
70 | ||
71 | struct tty *constty = 0; /* virtual console output device */ | |
72 | struct consdev *cn_tab; /* physical console device info */ | |
73 | struct tty *cn_tty; /* XXX: console tty struct for tprintf */ | |
74 | ||
75 | cninit() | |
76 | { | |
77 | register struct consdev *cp; | |
78 | ||
79 | /* | |
80 | * Collect information about all possible consoles | |
81 | * and find the one with highest priority | |
82 | */ | |
83 | for (cp = constab; cp->cn_probe; cp++) { | |
84 | (*cp->cn_probe)(cp); | |
85 | if (cp->cn_pri > CN_DEAD && | |
86 | (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri)) | |
87 | cn_tab = cp; | |
88 | } | |
89 | /* | |
90 | * No console, we can handle it | |
91 | */ | |
92 | if ((cp = cn_tab) == NULL) | |
93 | return; | |
94 | /* | |
95 | * Turn on console | |
96 | */ | |
97 | cn_tty = cp->cn_tp; | |
98 | (*cp->cn_init)(cp); | |
99 | } | |
100 | ||
101 | cnopen(dev, flag, mode, p) | |
102 | dev_t dev; | |
103 | int flag, mode; | |
104 | struct proc *p; | |
105 | { | |
106 | if (cn_tab == NULL) | |
107 | return (0); | |
108 | dev = cn_tab->cn_dev; | |
109 | return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p)); | |
110 | } | |
111 | ||
112 | cnclose(dev, flag, mode, p) | |
113 | dev_t dev; | |
114 | int flag, mode; | |
115 | struct proc *p; | |
116 | { | |
117 | if (cn_tab == NULL) | |
118 | return (0); | |
119 | dev = cn_tab->cn_dev; | |
120 | return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p)); | |
121 | } | |
122 | ||
123 | cnread(dev, uio, flag) | |
124 | dev_t dev; | |
125 | struct uio *uio; | |
126 | { | |
127 | if (cn_tab == NULL) | |
128 | return (0); | |
129 | dev = cn_tab->cn_dev; | |
130 | return ((*cdevsw[major(dev)].d_read)(dev, uio, flag)); | |
131 | } | |
132 | ||
133 | cnwrite(dev, uio, flag) | |
134 | dev_t dev; | |
135 | struct uio *uio; | |
136 | { | |
137 | if (cn_tab == NULL) | |
138 | return (0); | |
139 | if (constty) /* 16 Aug 92*/ | |
140 | dev = constty->t_dev; | |
141 | else | |
142 | dev = cn_tab->cn_dev; | |
143 | return ((*cdevsw[major(dev)].d_write)(dev, uio, flag)); | |
144 | } | |
145 | ||
146 | cnioctl(dev, cmd, data, flag, p) | |
147 | dev_t dev; | |
148 | caddr_t data; | |
149 | struct proc *p; | |
150 | { | |
151 | int error; | |
152 | ||
153 | if (cn_tab == NULL) | |
154 | return (0); | |
155 | /* | |
156 | * Superuser can always use this to wrest control of console | |
157 | * output from the "virtual" console. | |
158 | */ | |
159 | if (cmd == TIOCCONS && constty) { | |
160 | error = suser(p->p_ucred, (u_short *) NULL); | |
161 | if (error) | |
162 | return (error); | |
163 | constty = NULL; | |
164 | return (0); | |
165 | } | |
166 | dev = cn_tab->cn_dev; | |
167 | return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p)); | |
168 | } | |
169 | ||
170 | /*ARGSUSED*/ | |
171 | cnselect(dev, rw, p) | |
172 | dev_t dev; | |
173 | int rw; | |
174 | struct proc *p; | |
175 | { | |
176 | if (cn_tab == NULL) | |
177 | return (1); | |
178 | return (ttselect(cn_tab->cn_dev, rw, p)); | |
179 | } | |
180 | ||
181 | cngetc() | |
182 | { | |
183 | if (cn_tab == NULL) | |
184 | return (0); | |
185 | return ((*cn_tab->cn_getc)(cn_tab->cn_dev)); | |
186 | } | |
187 | ||
188 | cnputc(c) | |
189 | register int c; | |
190 | { | |
191 | if (cn_tab == NULL) | |
192 | return; | |
193 | if (c) { | |
194 | (*cn_tab->cn_putc)(cn_tab->cn_dev, c); | |
195 | if (c == '\n') | |
196 | (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r'); | |
197 | } | |
198 | } | |
199 | ||
200 | pg(p,q,r,s,t,u,v,w,x,y,z) char *p; { | |
201 | printf(p,q,r,s,t,u,v,w,x,y,z); | |
202 | printf("\n>"); | |
203 | return(cngetc()); | |
204 | } | |
205 | ||
206 |