Annotation of coherent/b/kernel/coh.386/misc.c, revision 1.1

1.1     ! root        1: /* $Header: /src386/kernel/coh.386/RCS/misc.c,v 1.8 93/06/14 13:34:48 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:  * Miscellaneous routines.
        !            18:  *
        !            19:  * $Log:       misc.c,v $
        !            20:  * Revision 1.8  93/06/14  13:34:48  bin
        !            21:  * Hal: kernel 78 update
        !            22:  * 
        !            23:  * Revision 1.4  93/04/14  10:06:36  root
        !            24:  * r75
        !            25:  * 
        !            26:  * Revision 1.3  92/11/09  17:10:53  root
        !            27:  * Just before adding vio segs.
        !            28:  * 
        !            29:  * Revision 1.2  92/01/06  11:59:45  hal
        !            30:  * Compile with cc.mwc.
        !            31:  * 
        !            32:  * Revision 1.1        88/03/24  16:14:01      src
        !            33:  * Initial revision
        !            34:  * 
        !            35:  * 87/05/08    Allan Cornish           /usr/src/sys/coh/misc.c
        !            36:  * System code and data segments no longer reported in panic messages.
        !            37:  *
        !            38:  * 87/02/17    Allan Cornish           /usr/src/sys/coh/misc.c
        !            39:  * Panic message now includes system code and data segments.
        !            40:  */
        !            41: #include <sys/coherent.h>
        !            42: #include <sys/acct.h>
        !            43: #include <errno.h>
        !            44: #include <sys/ino.h>
        !            45: #include <sys/stat.h>
        !            46: 
        !            47: #ifdef TRACER
        !            48: extern unsigned t_piggy;
        !            49: #endif
        !            50: 
        !            51: /*
        !            52:  * Make sure we are the super user.
        !            53:  */
        !            54: super()
        !            55: {
        !            56:        if (u.u_uid) {
        !            57:                u.u_error = EPERM;
        !            58:                return (0);
        !            59:        }
        !            60:        u.u_flag |= ASU;
        !            61:        return (1);
        !            62: }
        !            63: 
        !            64: /*
        !            65:  * Make sure we are the gived `uid' or the super user.
        !            66:  */
        !            67: owner(uid)
        !            68: {
        !            69:        if (u.u_uid == uid)
        !            70:                return (1);
        !            71:        if (u.u_uid == 0) {
        !            72:                u.u_flag |= ASU;
        !            73:                return (1);
        !            74:        }
        !            75:        u.u_error = EPERM;
        !            76:        return (0);
        !            77: }
        !            78: 
        !            79: /*
        !            80:  * Panic.
        !            81:  */
        !            82: void
        !            83: panic(a1)
        !            84: char *a1;
        !            85: {
        !            86:        static panflag;
        !            87:        sphi();
        !            88: 
        !            89: #ifdef TRACER
        !            90:        if ( t_piggy & 0x80 ) {
        !            91:                if (panflag++ == 0) {
        !            92:                        printf("Panic: %r", &a1);
        !            93:                        putchar('\n');
        !            94:                        usync();
        !            95:                }
        !            96:                printf("relax! It really isn't so bad.\n");
        !            97:        } else {
        !            98:                if (panflag++ == 0) {
        !            99:                        if (paging()) {
        !           100:                                printf("Panic: %r", &a1);
        !           101:                                putchar('\n');
        !           102:                        } else {
        !           103:                                strchirp("Panic: ");
        !           104:                                strchirp(a1);
        !           105:                        }
        !           106:                        for (;;);
        !           107:                        usync();
        !           108:                }
        !           109:                halt();
        !           110:        }
        !           111: #else
        !           112:        if (panflag++ == 0) {
        !           113:                printf("Panic: %r", &a1);
        !           114:                putchar('\n');
        !           115:                for (;;);
        !           116:                usync();
        !           117:        }
        !           118:        halt();
        !           119: #endif /* TRACER */
        !           120: 
        !           121:        --panflag;
        !           122: }
        !           123: 
        !           124: /*
        !           125:  * Print a message from a device driver.
        !           126:  */
        !           127: devmsg(dev, a1)
        !           128: dev_t dev;
        !           129: char *a1;
        !           130: {
        !           131:        printf("(%d,%d): %r", major(dev), minor(dev), &a1);
        !           132:        printf("\n");
        !           133: }
        !           134: 
        !           135: /*
        !           136:  * Wait up to "ticks" clock ticks for an event to occur.
        !           137:  * A tick is 1/HZ seconds (10 msec).
        !           138:  * Works whether interrupts are enabled or not.
        !           139:  * Busy-waits the system.
        !           140:  * The event occurs when (*fn)() returns a nonzero value.
        !           141:  * If fn is NULL, delay unconditionally.
        !           142:  *
        !           143:  * Return 0 if timeout occurred, 1 if the desired event occurred.
        !           144:  */
        !           145: 
        !           146: #define THRESH (T0_RATE/2)     /* half of 11932 */
        !           147: 
        !           148: int
        !           149: busyWait(fn, ticks)
        !           150: int (*fn)();
        !           151: int ticks;
        !           152: {
        !           153:        /*
        !           154:         * p0, p1 are 0 if in low half of counting cycle, else 1.
        !           155:         * flips counts the number of changes from low-to-high or vice versa.
        !           156:         * tickCt counts the number of clock ticks at rate HZ.
        !           157:         */
        !           158: 
        !           159:        int tickCt = 0;
        !           160:        int flips = 0;
        !           161:        int p0 = (read_t0() < THRESH)?0:1;
        !           162:        int p1;
        !           163: 
        !           164:        for (;;) {
        !           165:                if (fn && (*fn)())
        !           166:                        return 1;
        !           167: 
        !           168:                /* did we change halves of counter cycle? */
        !           169:                p1 = (read_t0() < THRESH)?0:1;
        !           170:                if (p0 != p1) {
        !           171:                        p0 = p1;
        !           172:                        flips++;
        !           173: 
        !           174:                        /* two phase flips make a tick */
        !           175:                        if (flips >= 2) {
        !           176:                                flips = 0;
        !           177:                                tickCt++;
        !           178:                                if (tickCt > ticks)
        !           179:                                        return 0;
        !           180:                        }
        !           181:                }
        !           182:                
        !           183:        }
        !           184: }
        !           185: 
        !           186: /*
        !           187:  * busyWait2() has finer granularity than busyWait().
        !           188:  *
        !           189:  * Wait up to "counts" clock counts for an event to occur.
        !           190:  * A count is 1/(11932*HZ) seconds (about 0.84 usec).
        !           191:  * Works whether interrupts are enabled or not.
        !           192:  * Busy-waits the system.
        !           193:  * The event occurs when (*fn)() returns a nonzero value.
        !           194:  * If fn is NULL, delay unconditionally.
        !           195:  *
        !           196:  * Return 0 if timeout occurred, 1 if the desired event occurred.
        !           197:  */
        !           198: 
        !           199: int
        !           200: busyWait2(fn, counts)
        !           201: int (*fn)();
        !           202: unsigned int counts;
        !           203: {
        !           204:        /*
        !           205:         * ct0 is previous t0 reading, ct1 is current reading.
        !           206:         * We have timer rollover when ct1 < ct0.
        !           207:         */
        !           208: 
        !           209:        unsigned int totCt = 0;
        !           210:        unsigned int ct0 = read_t0();
        !           211:        unsigned int ct1;
        !           212: 
        !           213:        for (;;) {
        !           214:                if (fn && (*fn)())
        !           215:                        return 1;
        !           216: 
        !           217:                ct1 = read_t0();
        !           218:                if (ct1 > ct0) {
        !           219:                        /* no timer 0 rollover */
        !           220:                        totCt += ct1 - ct0;
        !           221:                } else {
        !           222:                        /* timer 0 rollover */
        !           223:                        totCt += ct1 + T0_RATE - ct0;
        !           224:                }
        !           225:                if (totCt > counts)
        !           226:                        return 0;
        !           227:                ct0 = ct1;
        !           228:        }
        !           229: }

unix.superglobalmegacorp.com

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