1: /*
   2:  *   KL/DL-11 driver
   3:  */
   4: #include "kl.h"
   5: #include "param.h"
   6: #include <sys/conf.h>
   7: #include <sys/dir.h>
   8: #include <sys/user.h>
   9: #include <sys/tty.h>
  10: #include <sys/systm.h>
  11: #include <sys/klreg.h>
  12: 
  13: /*
  14:  *	SCCS id	@(#)kl.c	2.1 (Berkeley)	9/1/83
  15:  */
  16: 
  17: extern  struct  dldevice *KLADDR;
  18: /*
  19:  * Normal addressing:
  20:  * minor 0 addresses KLADDR
  21:  * minor 1 thru n-1 address from KLBASE (0176600),
  22:  *    where n is the number of additional KL11's
  23:  * minor n on address from DLBASE (0176500)
  24:  */
  25: 
  26: struct  tty kl11[NKL];
  27: int nkl11   = NKL;      /* for pstat */
  28: int klstart();
  29: int ttrstrt();
  30: extern  char    partab[];
  31: 
  32: klattach(addr, unit)
  33: struct dldevice *addr;
  34: {
  35:     if ((unsigned) unit <= NKL) {
  36:         kl11[unit].t_addr = addr;
  37:         return(1);
  38:     }
  39:     return(0);
  40: }
  41: 
  42: /*ARGSUSED*/
  43: klopen(dev, flag)
  44: dev_t   dev;
  45: {
  46:     register struct dldevice *addr;
  47:     register struct tty *tp;
  48:     register d;
  49: 
  50:     d = minor(dev);
  51:     tp = &kl11[d];
  52:     if ((d == 0) && (tp->t_addr == 0))
  53:         tp->t_addr = KLADDR;
  54:     if ((d >= NKL) || ((addr = tp->t_addr) == 0)) {
  55:         u.u_error = ENXIO;
  56:         return;
  57:     }
  58:     tp->t_oproc = klstart;
  59:     if ((tp->t_state & ISOPEN) == 0) {
  60:         tp->t_state = ISOPEN | CARR_ON;
  61:         tp->t_flags = EVENP | ECHO | XTABS | CRMOD;
  62:         tp->t_line = DFLT_LDISC;
  63:         ttychars(tp);
  64:     } else if (tp->t_state & XCLUDE && u.u_uid != 0) {
  65:         u.u_error = EBUSY;
  66:         return;
  67:     }
  68:     addr->dlrcsr |= DL_RIE | DL_DTR | DL_RE;
  69:     addr->dlxcsr |= DLXCSR_TIE;
  70:     ttyopen(dev, tp);
  71: }
  72: 
  73: /*ARGSUSED*/
  74: klclose(dev, flag)
  75: dev_t   dev;
  76: int flag;
  77: {
  78:     ttyclose(&kl11[minor(dev)]);
  79: }
  80: 
  81: klread(dev)
  82: dev_t   dev;
  83: {
  84:     register struct tty *tp;
  85: 
  86:     tp = &kl11[minor(dev)];
  87:     (*linesw[tp->t_line].l_read)(tp);
  88: }
  89: 
  90: klwrite(dev)
  91: dev_t   dev;
  92: {
  93:     register struct tty *tp;
  94: 
  95:     tp = &kl11[minor(dev)];
  96:     (*linesw[tp->t_line].l_write)(tp);
  97: }
  98: 
  99: klxint(dev)
 100: dev_t   dev;
 101: {
 102:     register struct tty *tp;
 103: 
 104:     tp = &kl11[minor(dev)];
 105:     ttstart(tp);
 106:     if (tp->t_state & ASLEEP && tp->t_outq.c_cc <= TTLOWAT(tp))
 107: #ifdef  MPX_FILS
 108:         if (tp->t_chan)
 109:             mcstart(tp->t_chan, (caddr_t) &tp->t_outq);
 110:         else
 111: #endif
 112:             wakeup((caddr_t) &tp->t_outq);
 113: }
 114: 
 115: klrint(dev)
 116: dev_t   dev;
 117: {
 118:     register int c;
 119:     register struct dldevice *addr;
 120:     register struct tty *tp;
 121: 
 122:     tp = &kl11[minor(dev)];
 123:     addr = (struct dldevice *) tp->t_addr;
 124:     c = addr->dlrbuf;
 125:     addr->dlrcsr |= DL_RE;
 126:     (*linesw[tp->t_line].l_input)(c, tp);
 127: }
 128: 
 129: klioctl(dev, cmd, addr, flag)
 130: caddr_t addr;
 131: dev_t   dev;
 132: {
 133:     switch (ttioctl(&kl11[minor(dev)], cmd, addr, flag)) {
 134:         case TIOCSETN:
 135:         case TIOCSETP:
 136:         case 0:
 137:             break;
 138:         default:
 139:             u.u_error = ENOTTY;
 140:     }
 141: }
 142: 
 143: klstart(tp)
 144: register struct tty *tp;
 145: {
 146:     register c;
 147:     register struct dldevice *addr;
 148: 
 149:     addr = (struct dldevice *) tp->t_addr;
 150:     if ((addr->dlxcsr & DLXCSR_TRDY) == 0)
 151:         return;
 152:     if ((c=getc(&tp->t_outq)) >= 0) {
 153:         if (tp->t_flags & RAW)
 154:             addr->dlxbuf = c;
 155:         else if (c<=0177)
 156:             addr->dlxbuf = c | (partab[c] & 0200);
 157:         else {
 158:             timeout(ttrstrt, (caddr_t)tp, (c & 0177) + DLDELAY);
 159:             tp->t_state |= TIMEOUT;
 160:         }
 161:     }
 162: }
 163: 
 164: char *msgbufp = msgbuf;     /* Next saved printf character */
 165: /*
 166:  * Print a character on console (or users terminal if touser).
 167:  * Attempts to save and restore device
 168:  * status.
 169:  * If the last character input from the console was a break
 170:  * (null or del), all printing is inhibited.
 171:  *
 172:  * Whether or not printing is inhibited,
 173:  * the last MSGBUFS characters
 174:  * are saved in msgbuf for inspection later.
 175:  */
 176: 
 177: #ifdef  UCB_UPRINTF
 178: putchar(c, touser)
 179: #else
 180: putchar(c)
 181: #endif
 182: register c;
 183: {
 184:     register s;
 185:     register struct dldevice *kladdr = KLADDR;
 186:     long    timo;
 187:     extern  char *panicstr;
 188: 
 189: #ifdef  UCB_UPRINTF
 190:     if (touser) {
 191:         register struct tty *tp = u.u_ttyp;
 192:         if (tp && (tp->t_state & CARR_ON)) {
 193:             register s = spl6();
 194: 
 195:             if (c == '\n')
 196:                 (*linesw[tp->t_line].l_output)('\r', tp);
 197:             (*linesw[tp->t_line].l_output)(c, tp);
 198:             ttstart(tp);
 199:             splx(s);
 200:         }
 201:         return;
 202:     }
 203: #endif
 204:     if (c != '\0' && c != '\r' && c != 0177) {
 205:         *msgbufp++ = c;
 206:         if (msgbufp >= &msgbuf[MSGBUFS])
 207:             msgbufp = msgbuf;
 208:     }
 209: 
 210:     /*
 211: 	 *  If last char was a break or null, don't print
 212: 	 */
 213:     if (panicstr == (char *) 0)
 214:         if ((kladdr->dlrbuf & 0177) == 0)
 215:             return;
 216:     timo = 60000L;
 217:     /*
 218: 	 * Try waiting for the console tty to come ready,
 219: 	 * otherwise give up after a reasonable time.
 220: 	 */
 221:     while((kladdr->dlxcsr & DLXCSR_TRDY) == 0)
 222:         if (--timo == 0L)
 223:             break;
 224:     if (c == 0)
 225:         return;
 226:     s = kladdr->dlxcsr;
 227:     kladdr->dlxcsr = 0;
 228:     kladdr->dlxbuf = c;
 229:     if (c == '\n') {
 230: #ifdef  UCB_UPRINTF
 231:         putchar('\r', 0);
 232:         putchar(0177, 0);
 233:         putchar(0177, 0);
 234: #else
 235:         putchar('\r');
 236:         putchar(0177);
 237:         putchar(0177);
 238: #endif
 239:     }
 240: #ifdef  UCB_UPRINTF
 241:     putchar(0, 0);
 242: #else
 243:     putchar(0);
 244: #endif
 245:     kladdr->dlxcsr = s;
 246: }

Defined functions

klattach defined in line 32; never used
klclose defined in line 74; used 4 times
klioctl defined in line 129; used 4 times
klopen defined in line 43; used 4 times
klread defined in line 81; used 4 times
klrint defined in line 115; used 4 times
klstart defined in line 143; used 4 times
klwrite defined in line 90; used 4 times
klxint defined in line 99; used 4 times
putchar defined in line 178; used 8 times

Defined variables

kl11 defined in line 26; used 10 times
msgbufp defined in line 164; used 3 times
nkl11 defined in line 27; never used
Last modified: 1983-09-02
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1138
Valid CSS Valid XHTML 1.0 Strict