|
|
1.1 root 1: /*
2: * Copyright (c) 1988 University of Utah.
3: * Copyright (c) 1990 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 is only permitted until one year after the first shipment
11: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and
12: * binary forms are permitted provided that: (1) source distributions retain
13: * this entire copyright notice and comment, and (2) distributions including
14: * binaries display the following acknowledgement: This product includes
15: * software developed by the University of California, Berkeley and its
16: * contributors'' in the documentation or other materials provided with the
17: * distribution and in all advertising materials mentioning features or use
18: * of this software. Neither the name of the University nor the names of
19: * its contributors may be used to endorse or promote products derived from
20: * this software without specific prior written permission.
21: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
22: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
23: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
24: *
25: * from: Utah $Hdr: cons.c 1.4 88/12/03$
26: *
27: * @(#)cons.c 7.3 (Berkeley) 6/6/90
28: */
29:
30: #include "param.h"
31: #include "user.h"
32: #include "systm.h"
33: #include "buf.h"
34: #include "ioctl.h"
35: #include "tty.h"
36: #include "file.h"
37: #include "conf.h"
38:
39: #include "cons.h"
40:
41: /* XXX - all this could be autoconfig()ed */
42: #include "ite.h"
43: #if NITE > 0
44: int itecnprobe(), itecninit(), itecngetc(), itecnputc();
45: #endif
46: #include "dca.h"
47: #if NDCA > 0
48: int dcacnprobe(), dcacninit(), dcacngetc(), dcacnputc();
49: #endif
50: #include "dcm.h"
51: #if NDCM > 0
52: int dcmcnprobe(), dcmcninit(), dcmcngetc(), dcmcnputc();
53: #endif
54:
55: struct consdev constab[] = {
56: #if NITE > 0
57: { itecnprobe, itecninit, itecngetc, itecnputc },
58: #endif
59: #if NDCA > 0
60: { dcacnprobe, dcacninit, dcacngetc, dcacnputc },
61: #endif
62: #if NDCM > 0
63: { dcmcnprobe, dcmcninit, dcmcngetc, dcmcnputc },
64: #endif
65: { 0 },
66: };
67: /* end XXX */
68:
69: struct tty *constty = 0; /* virtual console output device */
70: struct consdev *cn_tab; /* physical console device info */
71: struct tty *cn_tty; /* XXX: console tty struct for tprintf */
72:
73: cninit()
74: {
75: register struct consdev *cp;
76:
77: /*
78: * Collect information about all possible consoles
79: * and find the one with highest priority
80: */
81: for (cp = constab; cp->cn_probe; cp++) {
82: (*cp->cn_probe)(cp);
83: if (cp->cn_pri > CN_DEAD &&
84: (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
85: cn_tab = cp;
86: }
87: /*
88: * No console, we can handle it
89: */
90: if ((cp = cn_tab) == NULL)
91: return;
92: /*
93: * Turn on console
94: */
95: cn_tty = cp->cn_tp;
96: (*cp->cn_init)(cp);
97: }
98:
99: cnopen(dev, flag)
100: dev_t dev;
101: {
102: if (cn_tab == NULL)
103: return(0);
104: dev = cn_tab->cn_dev;
105: return ((*cdevsw[major(dev)].d_open)(dev, flag));
106: }
107:
108: cnclose(dev, flag)
109: dev_t dev;
110: {
111: if (cn_tab == NULL)
112: return(0);
113: dev = cn_tab->cn_dev;
114: return ((*cdevsw[major(dev)].d_close)(dev, flag));
115: }
116:
117: cnread(dev, uio, flag)
118: dev_t dev;
119: struct uio *uio;
120: {
121: if (cn_tab == NULL)
122: return(0);
123: dev = cn_tab->cn_dev;
124: return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
125: }
126:
127: cnwrite(dev, uio, flag)
128: dev_t dev;
129: struct uio *uio;
130: {
131: if (cn_tab == NULL)
132: return(0);
133: dev = cn_tab->cn_dev;
134: return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
135: }
136:
137: cnioctl(dev, cmd, data, flag)
138: dev_t dev;
139: caddr_t data;
140: {
141: int error;
142:
143: if (cn_tab == NULL)
144: return(0);
145: /*
146: * Superuser can always use this to wrest control of console
147: * output from the "virtual" console.
148: */
149: if (cmd == TIOCCONS && constty) {
150: error = suser(u.u_cred, &u.u_acflag);
151: if (error)
152: return (error);
153: constty = NULL;
154: return (0);
155: }
156: dev = cn_tab->cn_dev;
157: return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag));
158: }
159:
160: /*ARGSUSED*/
161: cnselect(dev, rw)
162: dev_t dev;
163: int rw;
164: {
165: if (cn_tab == NULL)
166: return(1);
167: return(ttselect(cn_tab->cn_dev, rw));
168: }
169:
170: cngetc()
171: {
172: if (cn_tab == NULL)
173: return(0);
174: return((*cn_tab->cn_getc)(cn_tab->cn_dev));
175: }
176:
177: cnputc(c)
178: register int c;
179: {
180: if (cn_tab == NULL)
181: return;
182: if (c) {
183: (*cn_tab->cn_putc)(cn_tab->cn_dev, c);
184: if (c == '\n')
185: (*cn_tab->cn_putc)(cn_tab->cn_dev, '\r');
186: }
187: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.