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