Annotation of lucent/sys/src/9/gnot/bbmalloc.c, revision 1.1

1.1     ! root        1: #include       "u.h"
        !             2: #include       "../port/lib.h"
        !             3: #include       "mem.h"
        !             4: #include       "dat.h"
        !             5: #include       "fns.h"
        !             6: #include       "io.h"
        !             7: 
        !             8: /*
        !             9:  * Allocate memory for use in kernel bitblts.
        !            10:  * The allocated memory must have a flushed instruction
        !            11:  * cache, and the data cache must be flushed by bbdflush().
        !            12:  * To avoid the need for frequent cache flushes, the memory
        !            13:  * is allocated out of an arena, and the i-cache is only
        !            14:  * flushed when it has to be reused.  By returning an
        !            15:  * address in non-cached space, the need for flushing the
        !            16:  * d-cache is avoided.
        !            17:  *
        !            18:  * This code will have to be interlocked if we ever get
        !            19:  * a multiprocessor with a bitmapped display.
        !            20:  */
        !            21: 
        !            22: /* a 0->3 bitblt can take 800 longs */
        !            23: enum {
        !            24:        narena=2,       /* put interrupt time stuff in separate arena */
        !            25:        nbbarena=4096   /* number of words in an arena */
        !            26: };
        !            27: 
        !            28: static ulong   bbarena[narena][nbbarena];
        !            29: static ulong   *bbcur[narena] = {&bbarena[0][0], &bbarena[1][0]};
        !            30: static ulong   *bblast[narena] = {0, 0};
        !            31: 
        !            32: #define INTLEVEL(v)    ((v)&0x700)
        !            33: void *
        !            34: bbmalloc(int nbytes)
        !            35: {
        !            36:        int nw, a;
        !            37:        int s;
        !            38:        ulong *ans;
        !            39: 
        !            40:        nw = nbytes/sizeof(long);
        !            41:        s = splhi();
        !            42:        a = INTLEVEL(s)? 1 : 0;
        !            43:        if(bbcur[a] + nw > &bbarena[a][nbbarena])
        !            44:                ans = bbarena[a];
        !            45:        else
        !            46:                ans = bbcur[a];
        !            47:        bbcur[a] = ans + nw;
        !            48:        splx(s);
        !            49:        bblast[a] = ans;
        !            50:        return ans;
        !            51: }
        !            52: 
        !            53: void
        !            54: bbfree(void *p, int n)
        !            55: {
        !            56:        int a, s;
        !            57: 
        !            58:        s = splhi();
        !            59:        a = INTLEVEL(s)? 1 : 0;
        !            60:        if(p == bblast[a])
        !            61:                bbcur[a] = (ulong *)(((char *)bblast[a]) + n);
        !            62:        splx(s);
        !            63: }
        !            64: 
        !            65: void
        !            66: flushvirtpage(void *p)
        !            67: {
        !            68:        USED(p);
        !            69:        flushcpucache();
        !            70: }
        !            71: 
        !            72: void
        !            73: bbdflush(void *p, int n)
        !            74: {
        !            75:        USED(p, n);
        !            76:        flushcpucache();
        !            77: }
        !            78: 
        !            79: int
        !            80: bbonstack(void)
        !            81: {
        !            82:        if(u)
        !            83:                return 1;
        !            84:        return 0;
        !            85: }
        !            86: 
        !            87: void
        !            88: bbexec(void (*memstart)(void), int len, int onstack)
        !            89: {
        !            90:        if(onstack) {
        !            91:                icflush(memstart, len);
        !            92:                memstart();
        !            93:                return;
        !            94:        }
        !            95:        memstart();
        !            96:        bbfree(memstart, len);
        !            97: }

unix.superglobalmegacorp.com

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