Annotation of lucent/sys/src/9/bbmalloc.c, revision 1.1.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: 
                     34: extern flushvirtpage(void (*)(void));
                     35: 
                     36: void *
                     37: bbmalloc(int nbytes)
                     38: {
                     39:        int nw, a;
                     40:        int s;
                     41:        ulong *ans;
                     42: 
                     43:        nw = nbytes/sizeof(long);
                     44:        s = splhi();
                     45:        a = INTLEVEL(s)? 1 : 0;
                     46:        if(bbcur[a] + nw > &bbarena[a][nbbarena])
                     47:                ans = bbarena[a];
                     48:        else
                     49:                ans = bbcur[a];
                     50:        bbcur[a] = ans + nw;
                     51:        splx(s);
                     52:        bblast[a] = ans;
                     53:        return ans;
                     54: }
                     55: 
                     56: void
                     57: bbfree(void *p, int n)
                     58: {
                     59:        int a, s;
                     60: 
                     61:        s = splhi();
                     62:        a = INTLEVEL(s)? 1 : 0;
                     63:        if(p == bblast[a])
                     64:                bbcur[a] = (ulong *)(((char *)bblast[a]) + n);
                     65:        splx(s);
                     66: }
                     67: 
                     68: void
                     69: bbdflush(void *p, int n)
                     70: {
                     71:        ulong pe, l;
                     72: 
                     73:        pe = (ulong)(((char *)p) + n + (BY2PG-1));
                     74:        for(l = (ulong)p; l < pe; l += BY2PG)
                     75:                flushpage(l);
                     76: }
                     77: 
                     78: int
                     79: bbonstack(void)
                     80: {
                     81:        if(u)
                     82:                return 1;
                     83:        return 0;
                     84: }
                     85: 
                     86: void
                     87: bbexec(void (*memstart)(void), int len, int onstack)
                     88: {
                     89:        if(onstack) {
                     90:                flushvirtpage(memstart);
                     91:                memstart();
                     92:        } else {
                     93:                bbdflush(memstart, len);
                     94:                memstart();
                     95:                bbfree(memstart, len);
                     96:        }
                     97: }

unix.superglobalmegacorp.com

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