Annotation of researchv8dc/sys/dev/cons.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Vax console driver
                      3:  */
                      4: #include "../h/param.h"
                      5: #include "../h/inode.h"
                      6: #include "../h/stream.h"
                      7: #include "../h/ioctl.h"
                      8: #include "../h/ttyld.h"
                      9: #include "../h/cons.h"
                     10: #include "../h/mtpr.h"
                     11: #include "../h/conf.h"
                     12: #include "../h/cpu.h"
                     13: 
                     14: #define        BUSY    02
                     15: #define        TIMEOUT 04
                     16: 
                     17: short  cnstate;
                     18: struct queue   *cnrq;
                     19: struct queue   *cnwq;
                     20: 
                     21: int    cnopen(), cnclose(), cnoput(), nodev();
                     22: 
                     23: static struct qinit cnrinit = { nodev, NULL, cnopen, cnclose, 0, 0 };
                     24: static struct qinit cnwinit = { cnoput, NULL, cnopen, cnclose, 200, 100 };
                     25: struct streamtab cninfo = { &cnrinit, &cnwinit };
                     26: 
                     27: cnopen(qp, dev)
                     28: register struct queue *qp;
                     29: {
                     30:        cnrq = qp;
                     31:        cnwq = WR(qp);
                     32:        mtpr(RXCS, mfpr(RXCS)|RXCS_IE);
                     33:        mtpr(TXCS, mfpr(TXCS)|TXCS_IE);
                     34:        return(1);
                     35: }
                     36: 
                     37: cnclose(qp)
                     38: {
                     39:        cnrq = NULL;
                     40:        cnwq = NULL;
                     41: }
                     42: 
                     43: /*
                     44:  * Console write put routine
                     45:  */
                     46: cnoput(q, bp)
                     47: register struct queue *q;
                     48: register struct block *bp;
                     49: {
                     50: 
                     51:        switch(bp->type) {
                     52: 
                     53:        case M_IOCTL:           /* just acknowledge */
                     54:                switch (((union stmsg *)bp->rptr)->ioc0.com) {
                     55: 
                     56:                case TIOCSETP:
                     57:                case TIOCSETN:
                     58:                        bp->wptr = bp->rptr;
                     59:                case TIOCGETP:
                     60:                        bp->type = M_IOCACK;
                     61:                        qreply(q, bp);
                     62:                        return;
                     63: 
                     64:                default:
                     65:                        bp->type = M_IOCNAK;
                     66:                        bp->wptr = bp->rptr;
                     67:                        qreply(q, bp);
                     68:                        return;
                     69:                }
                     70: 
                     71:        case M_STOP:
                     72:                cnstate |= TTSTOP;
                     73:                break;
                     74: 
                     75:        case M_START:
                     76:                cnstate &= ~TTSTOP;
                     77:                cnstart();
                     78:                break;
                     79: 
                     80:        case M_FLUSH:
                     81:                flushq(q, 0);
                     82:                break;
                     83: 
                     84:        case M_DELAY:
                     85:        case M_DATA:
                     86:                putq(q, bp);
                     87:                cnstart();
                     88:                return;
                     89:        
                     90:        default:                /* not handled; just toss */
                     91:                break;
                     92:        }
                     93:        freeb(bp);
                     94: }
                     95: 
                     96: /*
                     97:  * Console receive interrupt
                     98:  */
                     99: /*ARGSUSED*/
                    100: cnrint(dev)
                    101: {
                    102:        register int c;
                    103: 
                    104:        c = mfpr(RXDB);
                    105: #if VAX780
                    106:        if (c & RXDB_ID && cpu == VAX_780)
                    107:                cnrfl (c);
                    108: #endif
                    109:        if (c&RXDB_ID || cnrq==NULL)
                    110:                return;
                    111:        if ((cnrq->next->flag & QFULL) == 0)
                    112:                putd(cnrq->next->qinfo->putp, cnrq->next, c);
                    113: }
                    114: 
                    115: 
                    116: /*
                    117:  * Transmitter interrupt
                    118:  */
                    119: /*ARGSUSED*/
                    120: cnxint(dev)
                    121: {
                    122:        cnstate &= ~BUSY;
                    123:        cnstart();
                    124: #if VAX780
                    125:        /* if the console wasn't started, try the floppy */
                    126:        if (cpu==VAX_780 && (cnstate & BUSY) == 0)
                    127:                conxfl();
                    128: #endif
                    129: }
                    130: 
                    131: cntime()
                    132: {
                    133:        cnstate &= ~TIMEOUT;
                    134:        cnstart();
                    135: }
                    136: 
                    137: cnstart()
                    138: {
                    139:        register s;
                    140:        register struct block *bp;
                    141: 
                    142:        if (cnwq==NULL)
                    143:                return;
                    144:        s = spl6();
                    145:        if ((cnstate & (TIMEOUT|BUSY|TTSTOP))==0 && cnwq->count) {
                    146:                bp = getq(cnwq);
                    147:                switch (bp->type) {
                    148: 
                    149:                case M_DATA:
                    150:                        mtpr(TXDB, *bp->rptr++);
                    151:                        cnstate |= BUSY;
                    152:                        if (bp->rptr >= bp->wptr)
                    153:                                freeb(bp);
                    154:                        else
                    155:                                putbq(cnwq, bp);
                    156:                        break;
                    157: 
                    158:                case M_DELAY:
                    159:                        timeout(cntime, (caddr_t)NULL, (int)*bp->rptr);
                    160:                        cnstate |= TIMEOUT;
                    161:                default:        /* flow through */
                    162:                        freeb(bp);
                    163:                        break;
                    164:                }
                    165:        }
                    166:        splx(s);
                    167: }
                    168: 
                    169: /*
                    170:  * Print a character on console.
                    171:  * Attempts to save and restore device
                    172:  * status.
                    173:  */
                    174: cnputc(c)
                    175: register c;
                    176: {
                    177:        register 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((mfpr(TXCS)&TXCS_RDY) == 0)
                    185:                if(--timo == 0)
                    186:                        break;
                    187:        if(c == 0)
                    188:                return;
                    189:        s = mfpr(TXCS);
                    190:        mtpr(TXCS, 0);
                    191:        mtpr(TXDB, c&0xff);
                    192:        if(c == '\n')
                    193:                cnputc('\r');
                    194:        cnputc(0);
                    195:        mtpr(TXCS, s);
                    196: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.