Annotation of researchv10no/sys/io/mem.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Memory special file
        !             3:  *     minor device 0 is physical memory
        !             4:  *     minor device 1 is kernel memory 
        !             5:  *     minor device 2 is EOF/RATHOLE
        !             6:  *     minor device 3 is unibus memory (addressed by shorts)
        !             7:  *     minor device 4 is obsolete
        !             8:  *     minor device 5 is processor registers
        !             9:  */
        !            10: 
        !            11: #include "sys/param.h"
        !            12: #include "sys/user.h"
        !            13: #include "sys/buf.h"
        !            14: #include "sys/conf.h"
        !            15: #include "sys/pte.h"
        !            16: #include "sys/mtpr.h"
        !            17: #include "sys/vm.h"
        !            18: 
        !            19: int mmread(), mmwrite();
        !            20: struct cdevsw mmcdev = cdinit(nulldev, nulldev, mmread, mmwrite, nodev);
        !            21: 
        !            22: char *vmmap;
        !            23: struct pte *mmap;
        !            24: 
        !            25: mmread(dev)
        !            26: {
        !            27:        register int o; long lbuf;
        !            28:        register unsigned c, v;
        !            29: 
        !            30:        switch (minor(dev)) {
        !            31: 
        !            32:        case 0:
        !            33:                while (u.u_count != 0 && u.u_error == 0) {
        !            34:                        if (fubyte(u.u_base) == -1)
        !            35:                                goto fault;
        !            36:                        v = btop(Ltol(u.u_offset));
        !            37:                        *(int *)mmap = v | (PG_V | PG_KR);
        !            38:                        mtpr(TBIS, vmmap);
        !            39:                        o = Ltol(u.u_offset) & PGOFSET;
        !            40:                        c = min((unsigned)(NBPG - o), u.u_count);
        !            41:                        c = min(c, (unsigned)(NBPG - ((int)u.u_base&PGOFSET)));
        !            42:                        if (copyout((caddr_t)&vmmap[o], u.u_base, c))
        !            43:                                goto fault;
        !            44:                        u.u_count -= c;
        !            45:                        u.u_base += c;
        !            46:                        u.u_offset = Lladd(u.u_offset, c);
        !            47:                }
        !            48:                return;
        !            49: 
        !            50:        case 1:
        !            51:                iomove((caddr_t)Ltol(u.u_offset), u.u_count, B_READ);
        !            52:                return;
        !            53: 
        !            54:        case 2:
        !            55:                return;
        !            56: 
        !            57:        case 3:
        !            58:                if (!useracc(u.u_base, u.u_count, B_WRITE))
        !            59:                        goto fault;
        !            60:                if (UNIcpy((caddr_t)Ltol(u.u_offset), u.u_base, u.u_count, B_READ))
        !            61:                        goto fault;
        !            62:                c = u.u_count;
        !            63:                u.u_count = 0;
        !            64:                u.u_base += c;
        !            65:                u.u_offset = Lladd(u.u_offset, c);
        !            66:                return;
        !            67: 
        !            68:        case 5:
        !            69:                c = min(u.u_count, sizeof(long));
        !            70:                lbuf = umfpr(Ltol(u.u_offset)/sizeof(long));
        !            71:                if (copyout((caddr_t)&lbuf, u.u_base, c))
        !            72:                        goto fault;
        !            73:                u.u_count -= c;
        !            74:                u.u_base += c;
        !            75:                u.u_offset = Lladd(u.u_offset, c);
        !            76:                return;
        !            77:        }
        !            78: fault:
        !            79:        u.u_error = EFAULT;
        !            80:        return;
        !            81: }
        !            82: 
        !            83: mmwrite(dev)
        !            84: {
        !            85:        register int o; long lbuf;
        !            86:        register unsigned c, v;
        !            87: 
        !            88:        switch (minor(dev)) {
        !            89: 
        !            90:        case 0:
        !            91:                while (u.u_count != 0 && u.u_error == 0) {
        !            92:                        if (fubyte(u.u_base) == -1)
        !            93:                                goto fault;
        !            94:                        v = btop(Ltol(u.u_offset));
        !            95:                        *(int *)mmap = v | (PG_V | PG_KW);
        !            96:                        mtpr(TBIS, vmmap);
        !            97:                        o = Ltol(u.u_offset) & PGOFSET;
        !            98:                        c = min((unsigned)(NBPG - o), u.u_count);
        !            99:                        c = min(c, (unsigned)(NBPG - ((int)u.u_base&PGOFSET)));
        !           100:                        if (copyin(u.u_base, (caddr_t)&vmmap[o], c))
        !           101:                                goto fault;
        !           102:                        u.u_count -= c;
        !           103:                        u.u_base += c;
        !           104:                        u.u_offset = Lladd(u.u_offset, c);
        !           105:                }
        !           106:                return;
        !           107: 
        !           108:        case 1:
        !           109:                iomove((caddr_t)Ltol(u.u_offset), u.u_count, B_WRITE);
        !           110:                return;
        !           111: 
        !           112:        case 2:
        !           113:                u.u_offset = Lladd(u.u_offset, u.u_count);
        !           114:                u.u_count = 0;
        !           115:                return;
        !           116: 
        !           117:        case 3:
        !           118:                if (!useracc(u.u_base, u.u_count, B_READ))
        !           119:                        goto fault;
        !           120:                if (UNIcpy((caddr_t)Ltol(u.u_offset), u.u_base, u.u_count, B_WRITE))
        !           121:                        goto fault;
        !           122:                u.u_base += u.u_count;
        !           123:                u.u_offset = Lladd(u.u_offset, u.u_count);
        !           124:                u.u_count = 0;
        !           125:                return;
        !           126: 
        !           127:        case 5:
        !           128:                if (u.u_count < sizeof(long))
        !           129:                        goto fault;
        !           130:                if (copyin(u.u_base, (caddr_t)&lbuf, sizeof(long)))
        !           131:                        goto fault;
        !           132:                if (umtpr(Ltol(u.u_offset) / sizeof(long), lbuf) == 0)
        !           133:                        goto fault;
        !           134:                u.u_count -= sizeof(long);
        !           135:                u.u_base += sizeof(long);
        !           136:                u.u_offset = Lladd(u.u_offset, sizeof(long));
        !           137:                return;
        !           138:        }
        !           139: fault:
        !           140:        u.u_error = EFAULT;
        !           141:        return;
        !           142: }

unix.superglobalmegacorp.com

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