Annotation of coherent/d/PS2_KERNEL/coh.386/clist.c, revision 1.1.1.1

1.1       root        1: /* $Header: /kernel/kersrc/coh.386/RCS/clist.c,v 1.2 92/08/04 12:30:26 bin Exp Locker: bin $ */
                      2: /* (lgl-
                      3:  *     The information contained herein is a trade secret of Mark Williams
                      4:  *     Company, and  is confidential information.  It is provided  under a
                      5:  *     license agreement,  and may be  copied or disclosed  only under the
                      6:  *     terms of  that agreement.  Any  reproduction or disclosure  of this
                      7:  *     material without the express written authorization of Mark Williams
                      8:  *     Company or persuant to the license agreement is unlawful.
                      9:  *
                     10:  *     COHERENT Version 2.3.37
                     11:  *     Copyright (c) 1982, 1983, 1984.
                     12:  *     An unpublished work by Mark Williams Company, Chicago.
                     13:  *     All rights reserved.
                     14:  -lgl) */
                     15: /*
                     16:  * Coherent.
                     17:  * Character list management.
                     18:  *
                     19:  * $Log:       clist.c,v $
                     20:  * Revision 1.2  92/08/04  12:30:26  bin
                     21:  * changed for kernel 59
                     22:  * 
                     23:  * Revision 1.2  92/01/06  11:58:44  hal
                     24:  * Compile with cc.mwc.
                     25:  * 
                     26:  * Revision 1.1        88/03/24  16:13:33      src
                     27:  * Initial revision
                     28:  * 
                     29:  */
                     30: #include <sys/coherent.h>
                     31: #include <sys/clist.h>
                     32: #include <sys/sched.h>
                     33: 
                     34: #define        cvirt(p)        ((CLIST *)(p))
                     35: #ifdef TRACER
                     36: int nclfree = 0;
                     37: #endif
                     38: 
                     39: /*
                     40:  * Initialise character list queues.
                     41:  *
                     42:  * Clist are not mapped.
                     43:  */
                     44: cltinit()
                     45: {
                     46:        register cmap_t cm;
                     47:        register cmap_t lm;
                     48:        register paddr_t p;
                     49:        register int s;
                     50: 
                     51:        s = sphi();
                     52:        lm = 0;
                     53:        for (p = clistp+NCLIST*sizeof(CLIST); (p-=sizeof(CLIST)) >= clistp; ) {
                     54:                cm = p;
                     55:                cvirt(cm)->cl_fp = lm;
                     56:                lm = cm;
                     57:        }
                     58:        cltfree = lm;
                     59: #ifdef TRACER
                     60:        nclfree = NCLIST;
                     61: #endif
                     62:        spl(s);
                     63: }
                     64: 
                     65: /*
                     66:  * Get a character from the given queue.
                     67:  */
                     68: getq(cqp)
                     69: register CQUEUE *cqp;
                     70: {
                     71:        register cmap_t op;
                     72:        register cmap_t np;
                     73:        register int ox;
                     74:        register int c;
                     75:        register int s;
                     76: 
                     77:        if (cqp->cq_cc == 0)
                     78:                return (-1);
                     79:        s = sphi();
                     80:        op = cqp->cq_op;
                     81:        ox = cqp->cq_ox;
                     82:        c = cvirt(op)->cl_ch[ox]&0377;
                     83:        if (--cqp->cq_cc==0 || ++cqp->cq_ox==NCPCL) {
                     84:                cqp->cq_ox = 0;
                     85:                np = cvirt(op)->cl_fp;
                     86:                cvirt(op)->cl_fp = cltfree;
                     87:                cqp->cq_op = np;
                     88:                cltfree = op;
                     89:                if (np == 0) {
                     90:                        cqp->cq_ip = 0;
                     91:                        cqp->cq_ix = 0;
                     92:                }
                     93:                if (cltwant) {
                     94:                        cltwant = 0;
                     95:                        wakeup((char *)&cltwant);
                     96:                }
                     97: #ifdef TRACER
                     98:                T_HAL(0x0040, {nclfree++; printf("F%d ", nclfree);});
                     99: #endif
                    100:        }
                    101:        spl(s);
                    102:        return (c);
                    103: }
                    104: 
                    105: /*
                    106:  * Put a character on the given queue.
                    107:  */
                    108: putq(cqp, c)
                    109: register CQUEUE *cqp;
                    110: {
                    111:        register cmap_t ip;
                    112:        register int ix;
                    113:        register int s;
                    114:        register cmap_t np;
                    115: 
                    116:        s = sphi();
                    117:        ip = cqp->cq_ip;
                    118:        if ((ix=cqp->cq_ix) == 0) {
                    119:                if ((ip=cltfree) == 0) {
                    120:                        spl(s);
                    121:                        return (-1);
                    122:                }
                    123:                cltfree = cvirt(ip)->cl_fp;
                    124:                cvirt(ip)->cl_fp = 0;
                    125:                if ((np=cqp->cq_ip) == 0)
                    126:                        cqp->cq_op = ip;
                    127:                else {
                    128:                        cvirt(np)->cl_fp = ip;
                    129:                }
                    130:                cqp->cq_ip = ip;
                    131:                T_HAL(0x0040, { nclfree--; printf("f%d ", nclfree);});
                    132:        }
                    133:        cvirt(ip)->cl_ch[ix] = c;
                    134:        if (++cqp->cq_ix == NCPCL)
                    135:                cqp->cq_ix = 0;
                    136:        cqp->cq_cc++;
                    137:        spl(s);
                    138:        return c;
                    139: }
                    140: 
                    141: /*
                    142:  * Clear a character queue.
                    143:  */
                    144: clrq(cqp)
                    145: register CQUEUE *cqp;
                    146: {
                    147:        register int s;
                    148: 
                    149:        s = sphi();
                    150:        while (getq(cqp) >= 0)
                    151:                ;
                    152:        spl(s);
                    153: }
                    154: 
                    155: /*
                    156:  * Wait for more character queues to become available.
                    157:  */
                    158: waitq()
                    159: {
                    160:        while (cltfree == 0) {
                    161:                T_HAL(0x0080, putchar('+'));
                    162:                cltwant = 1;
                    163:                v_sleep((char *)&cltwant, CVCLIST, IVCLIST, SVCLIST, "waitq");
                    164:                /* Wait for more character queues to become available.  */
                    165:        }
                    166: }

unix.superglobalmegacorp.com

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