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