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

1.1       root        1: /*     mem.c   4.3     81/03/08        */
                      2: 
                      3: /*
                      4:  * Memory special file
                      5:  *     minor device 0 is physical memory
                      6:  *     minor device 1 is kernel memory 
                      7:  *     minor device 2 is EOF/RATHOLE
                      8:  *     minor device 3 is unibus memory (addressed by shorts)
                      9:  *     minor device 4 is public part of kernel memory (read only)
                     10:  *     minor device 5 is processor registers
                     11:  */
                     12: 
                     13: #include "../h/param.h"
                     14: #include "../h/dir.h"
                     15: #include "../h/user.h"
                     16: #include "../h/conf.h"
                     17: #include "../h/buf.h"
                     18: #include "../h/systm.h"
                     19: #include "../h/pte.h"
                     20: #include "../h/mtpr.h"
                     21: #include "../h/vm.h"
                     22: #include "../h/cmap.h"
                     23: #include "sparam.h"
                     24: 
                     25: #define SYSADR ((caddr_t)0x80000000)   /* virtual address  of system seg. */
                     26: 
                     27: #ifndef        NBLKBIG
                     28: #define        NBLKBIG 0
                     29: #endif
                     30: #define        NBLKDATA (1024*NBLKBIG + 64*NBLK64 + 16*NBLK16 + 4*NBLK4)
                     31: 
                     32: extern u_char  blkdata[];
                     33: 
                     34: mmread(dev)
                     35: {
                     36:        register int o; long lbuf;
                     37:        register unsigned c, v;
                     38: 
                     39:        switch (minor(dev)) {
                     40: 
                     41:        case 0:
                     42:                while (u.u_count != 0 && u.u_error == 0) {
                     43:                        if (fubyte(u.u_base) == -1)
                     44:                                goto fault;
                     45:                        v = btop(u.u_offset);
                     46:                        *(int *)mmap = v | (PG_V | PG_KR);
                     47:                        mtpr(TBIS, vmmap);
                     48:                        o = (int)u.u_offset & PGOFSET;
                     49:                        c = min((unsigned)(NBPG - o), u.u_count);
                     50:                        c = min(c, (unsigned)(NBPG - ((int)u.u_base&PGOFSET)));
                     51:                        if (copyout((caddr_t)&vmmap[o], u.u_base, c))
                     52:                                goto fault;
                     53:                        u.u_count -= c;
                     54:                        u.u_base += c;
                     55:                        u.u_offset += c;
                     56:                }
                     57:                return;
                     58: 
                     59:        case 1:
                     60:                c = u.u_count;
                     61:                if (copyout((caddr_t)u.u_offset, u.u_base, c))
                     62:                        goto fault;
                     63:                u.u_count = 0;
                     64:                u.u_base += c;
                     65:                u.u_offset += c;
                     66:                return;
                     67: 
                     68:        case 2:
                     69:                return;
                     70: 
                     71:        case 3:
                     72:                if (!useracc(u.u_base, u.u_count, B_WRITE))
                     73:                        goto fault;
                     74:                if (UNIcpy((caddr_t)u.u_offset, u.u_base, u.u_count, B_READ))
                     75:                        goto fault;
                     76:                c = u.u_count;
                     77:                u.u_count = 0;
                     78:                u.u_base += c;
                     79:                u.u_offset += c;
                     80:                return;
                     81: 
                     82:        case 4:
                     83:                if ((u_long)u.u_offset < (u_long)SYSADR)
                     84:                        goto fault;
                     85:                c = u.u_count;
                     86: 
                     87: #define EXCLUDE(laddr, maddr)  \
                     88:                if ((u_long)u.u_offset >= (u_long)(laddr)) {    \
                     89:                        if ((u_long)u.u_offset < (u_long)(maddr))       \
                     90:                                goto fault;     \
                     91:                } else  \
                     92:                        c = min(c, (u_long)(laddr) - (u_long)u.u_offset)
                     93: 
                     94:                /* cf. startup() in machdep.c */
                     95:                EXCLUDE(buffers, buffers + BUFSIZE*nbuf);
                     96:                EXCLUDE(blkdata, blkdata + NBLKDATA);
                     97:                EXCLUDE(ecmap, 0xffffffff);
                     98: 
                     99:                if (!kernacc((caddr_t)u.u_offset, c, B_READ))
                    100:                        goto fault;
                    101:                if (copyout((caddr_t)u.u_offset, u.u_base, c))
                    102:                        goto fault;
                    103:                u.u_count -= c;
                    104:                u.u_base += c;
                    105:                u.u_offset += c;
                    106:                return;
                    107: 
                    108:        case 5:
                    109:                c = min(u.u_count, sizeof(long));
                    110:                lbuf = umfpr(u.u_offset/sizeof(long));
                    111:                if (copyout((caddr_t)&lbuf, u.u_base, c))
                    112:                        goto fault;
                    113:                u.u_count -= c;
                    114:                u.u_base += c;
                    115:                u.u_offset += c;
                    116:                return;
                    117:        }
                    118: fault:
                    119:        u.u_error = EFAULT;
                    120:        return;
                    121: }
                    122: 
                    123: mmwrite(dev)
                    124: {
                    125:        register int o; long lbuf;
                    126:        register unsigned c, v;
                    127: 
                    128:        switch (minor(dev)) {
                    129: 
                    130:        case 0:
                    131:                while (u.u_count != 0 && u.u_error == 0) {
                    132:                        if (fubyte(u.u_base) == -1)
                    133:                                goto fault;
                    134:                        v = btop(u.u_offset);
                    135:                        *(int *)mmap = v | (PG_V | PG_KW);
                    136:                        mtpr(TBIS, vmmap);
                    137:                        o = (int)u.u_offset & PGOFSET;
                    138:                        c = min((unsigned)(NBPG - o), u.u_count);
                    139:                        c = min(c, (unsigned)(NBPG - ((int)u.u_base&PGOFSET)));
                    140:                        if (copyin(u.u_base, (caddr_t)&vmmap[o], c))
                    141:                                goto fault;
                    142:                        u.u_count -= c;
                    143:                        u.u_base += c;
                    144:                        u.u_offset += c;
                    145:                }
                    146:                return;
                    147: 
                    148:        case 1:
                    149:                if (copyin(u.u_base, (caddr_t)u.u_offset, u.u_count))
                    150:                        goto fault;
                    151:                u.u_base += u.u_count;
                    152:                u.u_offset += u.u_count;
                    153:                u.u_count = 0;
                    154:                return;
                    155: 
                    156:        case 2:
                    157:                u.u_offset += u.u_count;
                    158:                u.u_count = 0;
                    159:                return;
                    160: 
                    161:        case 3:
                    162:                if (!useracc(u.u_base, u.u_count, B_READ))
                    163:                        goto fault;
                    164:                if (UNIcpy((caddr_t)u.u_offset, u.u_base, u.u_count, B_WRITE))
                    165:                        goto fault;
                    166:                u.u_base += u.u_count;
                    167:                u.u_offset += u.u_count;
                    168:                u.u_count = 0;
                    169:                return;
                    170: 
                    171:        case 5:
                    172:                if (u.u_count < sizeof(long))
                    173:                        goto fault;
                    174:                if (copyin(u.u_base, (caddr_t)&lbuf, sizeof(long)))
                    175:                        goto fault;
                    176:                if (umtpr(u.u_offset / sizeof(long), lbuf) == 0)
                    177:                        goto fault;
                    178:                u.u_count -= sizeof(long);
                    179:                u.u_base += sizeof(long);
                    180:                u.u_offset += sizeof(long);
                    181:                return;
                    182:        }
                    183: fault:
                    184:        u.u_error = EFAULT;
                    185:        return;
                    186: }

unix.superglobalmegacorp.com

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