xref: /original-bsd/sys/vax/vax/cons.c (revision 8a0cb482)
1 /*	cons.c	4.13	82/03/13	*/
2 
3 /*
4  * Vax console driver and floppy interface
5  *
6  * Note:
7  *	We avoid use the ready bit in txcs because it doesn't
8  *	work on an 11/750 with an rdm plugged in.
9  */
10 #include "../h/param.h"
11 #include "../h/conf.h"
12 #include "../h/dir.h"
13 #include "../h/user.h"
14 #include "../h/proc.h"
15 #include "../h/tty.h"
16 #include "../h/systm.h"
17 #include "../h/cons.h"
18 #include "../h/mtpr.h"
19 #include "../h/cpu.h"
20 
21 struct	tty cons;
22 int	cnstart();
23 int	ttrstrt();
24 char	partab[];
25 
26 /*ARGSUSED*/
27 cnopen(dev, flag)
28 dev_t dev;
29 {
30 	register struct tty *tp;
31 
32 	tp = &cons;
33 	tp->t_oproc = cnstart;
34 	if ((tp->t_state&TS_ISOPEN) == 0) {
35 		ttychars(tp);
36 		tp->t_state = TS_ISOPEN|TS_CARR_ON;
37 		tp->t_flags = EVENP|ECHO|XTABS|CRMOD;
38 	}
39 	if (tp->t_state&TS_XCLUDE && u.u_uid != 0) {
40 		u.u_error = EBUSY;
41 		return;
42 	}
43 	mtpr(RXCS, mfpr(RXCS)|RXCS_IE);
44 	mtpr(TXCS, mfpr(TXCS)|TXCS_IE);
45 	(*linesw[tp->t_line].l_open)(dev, tp);
46 }
47 
48 /*ARGSUSED*/
49 cnclose(dev)
50 dev_t dev;
51 {
52 	register struct tty *tp;
53 
54 	tp = &cons;
55 	(*linesw[tp->t_line].l_close)(tp);
56 	ttyclose(tp);
57 }
58 
59 /*ARGSUSED*/
60 cnread(dev)
61 dev_t dev;
62 {
63 	register struct tty *tp;
64 
65 	tp = &cons;
66 	(*linesw[tp->t_line].l_read)(tp);
67 }
68 
69 /*ARGSUSED*/
70 cnwrite(dev)
71 dev_t dev;
72 {
73 	register struct tty *tp;
74 
75 	tp = &cons;
76 	(*linesw[tp->t_line].l_write)(tp);
77 }
78 
79 /*
80  * Got a level-20 receive interrupt -
81  * the LSI wants to give us a character.
82  * Catch the character, and see who it goes to.
83  */
84 /*ARGSUSED*/
85 cnrint(dev)
86 dev_t dev;
87 {
88 	register int c;
89 	register struct tty *tp;
90 
91 	c = mfpr(RXDB);
92 	if (c&RXDB_ID) {
93 #if VAX780
94 		if (cpu == VAX_780)
95 			cnrfl(c);
96 #endif
97 		return;
98 	}
99 	tp = &cons;
100 	(*linesw[tp->t_line].l_rint)(c, tp);
101 }
102 
103 /*ARGSUSED*/
104 cnioctl(dev, cmd, addr, flag)
105 dev_t dev;
106 caddr_t addr;
107 {
108 	register struct tty *tp;
109 
110 	tp = &cons;
111 	cmd = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr);
112 	if (cmd == 0)
113 		return;
114 	if (ttioctl(tp, cmd, addr, flag) == 0)
115 		u.u_error = ENOTTY;
116 }
117 
118 int	consdone = 1;
119 /*
120  * Got a level-20 transmission interrupt -
121  * the LSI wants another character.  First,
122  * see if we can send something to the typewriter.
123  * If not, try the floppy.
124  */
125 /*ARGSUSED*/
126 cnxint(dev)
127 dev_t dev;
128 {
129 	register struct tty *tp;
130 
131 	consdone++;
132 	tp = &cons;
133 	tp->t_state &= ~TS_BUSY;
134 	if (tp->t_line)
135 		(*linesw[tp->t_line].l_start)(tp);
136 	else
137 		cnstart(tp);
138 #if VAX780
139 	if (cpu==VAX_780 && (tp->t_state & TS_BUSY) == 0)
140 		conxfl();
141 #endif
142 }
143 
144 cnstart(tp)
145 register struct tty *tp;
146 {
147 	register c;
148 	register s;
149 
150 	s = spl5();
151 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
152 		goto out;
153 	if (tp->t_outq.c_cc <= TTLOWAT(tp)) {
154 		if (tp->t_state&TS_ASLEEP) {
155 			tp->t_state &= ~TS_ASLEEP;
156 			wakeup((caddr_t)&tp->t_outq);
157 		}
158 		if (tp->t_wsel) {
159 			selwakeup(tp->t_wsel, tp->t_state & TS_WCOLL);
160 			tp->t_wsel = 0;
161 			tp->t_state &= ~TS_WCOLL;
162 		}
163 	}
164 	if (tp->t_outq.c_cc == 0)
165 		goto out;
166 	if (consdone == 0)
167 		return;
168 	c = getc(&tp->t_outq);
169 	if (tp->t_flags&RAW || tp->t_local&LLITOUT)
170 		mtpr(TXDB, c&0xff);
171 	else if (c<=0177)
172 		mtpr(TXDB, (c | (partab[c]&0200))&0xff);
173 	else {
174 		timeout(ttrstrt, (caddr_t)tp, (c&0177));
175 		tp->t_state |= TS_TIMEOUT;
176 		goto out;
177 	}
178 	consdone = 0;
179 	tp->t_state |= TS_BUSY;
180     out:
181 	splx(s);
182 }
183 
184 /*
185  * Print a character on console.
186  * Attempts to save and restore device
187  * status.
188  */
189 cnputc(c)
190 register c;
191 {
192 	register s, timo;
193 
194 	timo = 30000;
195 	/*
196 	 * Try waiting for the console tty to come ready,
197 	 * otherwise give up after a reasonable time.
198 	 */
199 	while((mfpr(TXCS)&TXCS_RDY) == 0)
200 		if(--timo == 0)
201 			break;
202 	if(c == 0)
203 		return;
204 	s = mfpr(TXCS);
205 	mtpr(TXCS, 0);
206 	mtpr(TXDB, c&0xff);
207 	if(c == '\n')
208 		cnputc('\r');
209 	cnputc(0);
210 	mtpr(TXCS, s);
211 }
212