1: /*
2: * Copyright (c) 1986 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: *
6: * @(#)cons.c 1.3 (2.11BSD GTE) 1997/4/25
7: */
8:
9: /*
10: * KL/DL-11 driver
11: */
12: #include "param.h"
13: #include "conf.h"
14: #include "user.h"
15: #include "proc.h"
16: #include "ioctl.h"
17: #include "tty.h"
18: #include "systm.h"
19: #include "cons.h"
20: #include "cn.h"
21:
22: /*
23: * Normal addressing:
24: * minor 0 addresses KLADDR
25: * minor 1 thru n-1 address from KLBASE (0176600),
26: * where n is the number of additional KL11's
27: * minor n on address from DLBASE (0176500)
28: */
29:
30: struct dldevice *cnaddr = (struct dldevice *)0177560;
31:
32: int nkl11 = NKL; /* for pstat */
33: struct tty cons[NKL];
34: int cnstart();
35: char partab[];
36:
37: cnattach(addr, unit)
38: struct dldevice *addr;
39: {
40: if ((u_int)unit <= NKL) {
41: cons[unit].t_addr = (caddr_t)addr;
42: return (1);
43: }
44: return (0);
45: }
46:
47: /*ARGSUSED*/
48: cnopen(dev, flag)
49: dev_t dev;
50: {
51: register struct dldevice *addr;
52: register struct tty *tp;
53: register int d;
54:
55: d = minor(dev);
56: tp = &cons[d];
57: if (!d && !tp->t_addr)
58: tp->t_addr = (caddr_t)cnaddr;
59: if (d >= NKL || !(addr = (struct dldevice *)tp->t_addr))
60: return (ENXIO);
61: tp->t_oproc = cnstart;
62: if ((tp->t_state&TS_ISOPEN) == 0) {
63: ttychars(tp);
64: tp->t_state = TS_ISOPEN|TS_CARR_ON;
65: tp->t_flags = EVENP|ECHO|XTABS|CRMOD;
66: }
67: if (tp->t_state&TS_XCLUDE && u.u_uid != 0)
68: return (EBUSY);
69: addr->dlrcsr |= DL_RIE|DL_DTR|DL_RE;
70: addr->dlxcsr |= DLXCSR_TIE;
71: return ((*linesw[tp->t_line].l_open)(dev, tp));
72: }
73:
74: /*ARGSUSED*/
75: cnclose(dev, flag)
76: dev_t dev;
77: {
78: register struct tty *tp = &cons[minor(dev)];
79:
80: (*linesw[tp->t_line].l_close)(tp, flag);
81: ttyclose(tp);
82: return(0);
83: }
84:
85: /*ARGSUSED*/
86: cnread(dev, uio, flag)
87: dev_t dev;
88: struct uio *uio;
89: int flag;
90: {
91: register struct tty *tp = &cons[minor(dev)];
92:
93: return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
94: }
95:
96: /*ARGSUSED*/
97: cnwrite(dev, uio, flag)
98: dev_t dev;
99: struct uio *uio;
100: int flag;
101: {
102: register struct tty *tp = &cons[minor(dev)];
103:
104: return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
105: }
106:
107: /*ARGSUSED*/
108: cnrint(dev)
109: dev_t dev;
110: {
111: register int c;
112: register struct dldevice *addr;
113: register struct tty *tp = &cons[minor(dev)];
114:
115: addr = (struct dldevice *)tp->t_addr;
116: c = addr->dlrbuf;
117: addr->dlrcsr |= DL_RE;
118: (*linesw[tp->t_line].l_rint)(c, tp);
119: }
120:
121: /*ARGSUSED*/
122: cnioctl(dev, cmd, addr, flag)
123: dev_t dev;
124: register u_int cmd;
125: caddr_t addr;
126: {
127: register struct tty *tp = &cons[minor(dev)];
128: register int error;
129:
130: error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, addr, flag);
131: if (error >= 0)
132: return (error);
133: error = ttioctl(tp, cmd, addr, flag);
134: if (error < 0)
135: error = ENOTTY;
136: return (error);
137: }
138:
139: cnxint(dev)
140: dev_t dev;
141: {
142: register struct tty *tp = &cons[minor(dev)];
143:
144: tp->t_state &= ~TS_BUSY;
145: (*linesw[tp->t_line].l_start)(tp);
146: }
147:
148: cnstart(tp)
149: register struct tty *tp;
150: {
151: register struct dldevice *addr;
152: register int c, s;
153:
154: s = spltty();
155: if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
156: goto out;
157: ttyowake(tp);
158: if (tp->t_outq.c_cc == 0)
159: goto out;
160: addr = (struct dldevice *)tp->t_addr;
161: if ((addr->dlxcsr & DLXCSR_TRDY) == 0)
162: goto out;
163: c = getc(&tp->t_outq);
164: if (tp->t_flags & (RAW|LITOUT))
165: addr->dlxbuf = c&0xff;
166: else
167: addr->dlxbuf = c | (partab[c] & 0200);
168: tp->t_state |= TS_BUSY;
169: out:
170: splx(s);
171: }
172:
173: /* copied, for supervisory networking, to sys_sup.c */
174: cnputc(c)
175: char c;
176: {
177: register int s, timo;
178:
179: timo = 30000;
180: /*
181: * Try waiting for the console tty to come ready,
182: * otherwise give up after a reasonable time.
183: */
184: while ((cnaddr->dlxcsr & DLXCSR_TRDY) == 0)
185: if (--timo == 0)
186: break;
187: if (c == 0)
188: return;
189: s = cnaddr->dlxcsr;
190: cnaddr->dlxcsr = 0;
191: cnaddr->dlxbuf = c;
192: if (c == '\n')
193: cnputc('\r');
194: cnputc(0);
195: cnaddr->dlxcsr = s;
196: }
Defined functions
Defined variables
cons
defined in line
33; used 11 times
nkl11
defined in line
32;
never used