1 /*
2 * Copyright (c) 1988 University of Utah.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. 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 and Ralph Campbell.
9 *
10 * %sccs.include.redist.c%
11 *
12 * from: Utah $Hdr: cons.c 1.1 90/07/09$
13 *
14 * @(#)cons.c 8.2 (Berkeley) 01/11/94
15 */
16
17 #include <sys/param.h>
18 #include <sys/proc.h>
19 #include <sys/systm.h>
20 #include <sys/buf.h>
21 #include <sys/ioctl.h>
22 #include <sys/tty.h>
23 #include <sys/file.h>
24 #include <sys/conf.h>
25
26 #include <pmax/stand/dec_prom.h>
27
28 /*
29 * Console I/O is redirected to the appropriate device, either a screen and
30 * keyboard, a serial port, or the "virtual" console.
31 */
32 #include <pmax/pmax/cons.h>
33
34 extern struct tty *constty; /* virtual console output device */
35
36 struct consdev cn_tab = {
37 1,
38 1,
39 NODEV,
40 (struct pmax_fb *)0,
41 (int (*)())0,
42 (int (*)())0,
43 (void (*)())0,
44 (struct tty *)0,
45 };
46
cnopen(dev,flag,mode,p)47 cnopen(dev, flag, mode, p)
48 dev_t dev;
49 int flag, mode;
50 struct proc *p;
51 {
52 if (cn_tab.cn_dev == NODEV)
53 return (0);
54 dev = cn_tab.cn_dev;
55 return ((*cdevsw[major(dev)].d_open)(dev, flag, mode, p));
56 }
57
cnclose(dev,flag,mode,p)58 cnclose(dev, flag, mode, p)
59 dev_t dev;
60 int flag, mode;
61 struct proc *p;
62 {
63 if (cn_tab.cn_dev == NODEV)
64 return (0);
65 dev = cn_tab.cn_dev;
66 return ((*cdevsw[major(dev)].d_close)(dev, flag, mode, p));
67 }
68
cnread(dev,uio,flag)69 cnread(dev, uio, flag)
70 dev_t dev;
71 struct uio *uio;
72 {
73 if (cn_tab.cn_dev == NODEV)
74 return (0);
75 dev = cn_tab.cn_dev;
76 return ((*cdevsw[major(dev)].d_read)(dev, uio, flag));
77 }
78
cnwrite(dev,uio,flag)79 cnwrite(dev, uio, flag)
80 dev_t dev;
81 struct uio *uio;
82 {
83 if (constty)
84 return ((*linesw[constty->t_line].l_write)(constty, uio, flag));
85 if (cn_tab.cn_dev == NODEV)
86 return (0);
87 dev = cn_tab.cn_dev;
88 return ((*cdevsw[major(dev)].d_write)(dev, uio, flag));
89 }
90
cnioctl(dev,cmd,data,flag,p)91 cnioctl(dev, cmd, data, flag, p)
92 dev_t dev;
93 caddr_t data;
94 struct proc *p;
95 {
96 int error;
97
98 /*
99 * Superuser can always use this to wrest control of console
100 * output from the "virtual" console.
101 */
102 if (cmd == TIOCCONS && constty) {
103 error = suser(p->p_ucred, (u_short *) NULL);
104 if (error)
105 return (error);
106 constty = NULL;
107 return (0);
108 }
109 #if 0
110 if (constty) {
111 error = (*linesw[constty->t_line].l_ioctl)
112 (constty, cmd, data, flag, p);
113 if (error >= 0)
114 return (error);
115 }
116 #endif
117 if (cn_tab.cn_dev == NODEV)
118 return (0);
119 dev = cn_tab.cn_dev;
120 return ((*cdevsw[major(dev)].d_ioctl)(dev, cmd, data, flag, p));
121 }
122
123 /*ARGSUSED*/
cnselect(dev,rw,p)124 cnselect(dev, rw, p)
125 dev_t dev;
126 int rw;
127 struct proc *p;
128 {
129 if (cn_tab.cn_dev == NODEV)
130 return (1);
131 return (ttselect(cn_tab.cn_dev, rw, p));
132 }
133
134 /*
135 * Get character from console.
136 */
cngetc()137 cngetc()
138 {
139
140 /* check to be sure device has been initialized */
141 if (cn_tab.cn_dev == NODEV || cn_tab.cn_disabled)
142 return ((*callv->getchar)());
143 return ((*cn_tab.cn_getc)(cn_tab.cn_dev));
144 }
145
146 /*
147 * Print a character on console.
148 */
cnputc(c)149 cnputc(c)
150 register int c;
151 {
152 int s;
153
154 if (cn_tab.cn_dev == NODEV || cn_tab.cn_disabled) {
155 s = splhigh();
156 (*callv->printf)("%c", c);
157 splx(s);
158 } else if (c) {
159 if (c == '\n')
160 (*cn_tab.cn_putc)(cn_tab.cn_dev, '\r');
161 (*cn_tab.cn_putc)(cn_tab.cn_dev, c);
162 }
163 }
164