Annotation of 43BSDReno/sys/hp300/mem.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988 University of Utah.
                      3:  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
                      4:  * All rights reserved.
                      5:  *
                      6:  * This code is derived from software contributed to Berkeley by
                      7:  * the Systems Programming Group of the University of Utah Computer
                      8:  * Science Department.
                      9:  *
                     10:  * Redistribution is only permitted until one year after the first shipment
                     11:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
                     12:  * binary forms are permitted provided that: (1) source distributions retain
                     13:  * this entire copyright notice and comment, and (2) distributions including
                     14:  * binaries display the following acknowledgement:  This product includes
                     15:  * software developed by the University of California, Berkeley and its
                     16:  * contributors'' in the documentation or other materials provided with the
                     17:  * distribution and in all advertising materials mentioning features or use
                     18:  * of this software.  Neither the name of the University nor the names of
                     19:  * its contributors may be used to endorse or promote products derived from
                     20:  * this software without specific prior written permission.
                     21:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     22:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     23:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     24:  *
                     25:  * from: Utah $Hdr: mem.c 1.13 89/10/08$
                     26:  *
                     27:  *     @(#)mem.c       7.1 (Berkeley) 5/8/90
                     28:  */
                     29: 
                     30: /*
                     31:  * Memory special file
                     32:  */
                     33: 
                     34: #include "pte.h"
                     35: 
                     36: #include "param.h"
                     37: #include "user.h"
                     38: #include "conf.h"
                     39: #include "buf.h"
                     40: #include "systm.h"
                     41: #include "vm.h"
                     42: #include "cmap.h"
                     43: #include "uio.h"
                     44: #include "malloc.h"
                     45: 
                     46: #include "cpu.h"
                     47: 
                     48: /*ARGSUSED*/
                     49: mmrw(dev, uio, flags)
                     50:        dev_t dev;
                     51:        struct uio *uio;
                     52:        int flags;
                     53: {
                     54:        register int o;
                     55:        register u_int c, v;
                     56:        register struct iovec *iov;
                     57:        int error = 0;
                     58:        caddr_t zbuf = NULL;
                     59:        extern u_int lowram;
                     60: 
                     61:        while (uio->uio_resid > 0 && error == 0) {
                     62:                iov = uio->uio_iov;
                     63:                if (iov->iov_len == 0) {
                     64:                        uio->uio_iov++;
                     65:                        uio->uio_iovcnt--;
                     66:                        if (uio->uio_iovcnt < 0)
                     67:                                panic("mmrw");
                     68:                        continue;
                     69:                }
                     70:                switch (minor(dev)) {
                     71: 
                     72: /* minor device 0 is physical memory */
                     73:                case 0:
                     74:                        v = uio->uio_offset;
                     75: #ifndef DEBUG
                     76:                        /* allow reads only in RAM (except for DEBUG) */
                     77:                        if (v >= 0xFFFFFFFC || v < lowram)
                     78:                                goto fault;
                     79: #endif
                     80:                        *(int *)mmap = (v & PG_FRAME) | PG_CI | PG_V |
                     81:                                (uio->uio_rw == UIO_READ ? PG_RO : PG_RW);
                     82:                        TBIS(vmmap);
                     83:                        o = (int)uio->uio_offset & PGOFSET;
                     84:                        c = (u_int)(NBPG - ((int)iov->iov_base & PGOFSET));
                     85:                        c = MIN(c, (u_int)(NBPG - o));
                     86:                        c = MIN(c, (u_int)iov->iov_len);
                     87:                        error = uiomove((caddr_t)&vmmap[o], (int)c, uio);
                     88:                        continue;
                     89: 
                     90: /* minor device 1 is kernel memory */
                     91:                case 1:
                     92:                        c = iov->iov_len;
                     93:                        if (!kernacc((caddr_t)uio->uio_offset, c,
                     94:                            uio->uio_rw == UIO_READ ? B_READ : B_WRITE))
                     95:                                goto fault;
                     96:                        error = uiomove((caddr_t)uio->uio_offset, (int)c, uio);
                     97:                        continue;
                     98: 
                     99: /* minor device 2 is EOF/RATHOLE */
                    100:                case 2:
                    101:                        if (uio->uio_rw == UIO_READ)
                    102:                                return (0);
                    103:                        c = iov->iov_len;
                    104:                        break;
                    105: 
                    106: /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */
                    107:                case 12:
                    108:                        if (uio->uio_rw == UIO_WRITE) {
                    109:                                c = iov->iov_len;
                    110:                                break;
                    111:                        }
                    112:                        if (zbuf == NULL) {
                    113:                                zbuf = (caddr_t)
                    114:                                    malloc(CLBYTES, M_TEMP, M_WAITOK);
                    115:                                bzero(zbuf, CLBYTES);
                    116:                        }
                    117:                        c = MIN(iov->iov_len, CLBYTES);
                    118:                        error = uiomove(zbuf, (int)c, uio);
                    119:                        continue;
                    120: 
                    121:                default:
                    122:                        return (ENXIO);
                    123:                }
                    124:                if (error)
                    125:                        break;
                    126:                iov->iov_base += c;
                    127:                iov->iov_len -= c;
                    128:                uio->uio_offset += c;
                    129:                uio->uio_resid -= c;
                    130:        }
                    131:        if (zbuf)
                    132:                free(zbuf, M_TEMP);
                    133:        return (error);
                    134: fault:
                    135:        return (EFAULT);
                    136: }

unix.superglobalmegacorp.com

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