1 /* 2 * Copyright (c) 1988 University of Utah. 3 * Copyright (c) 1992 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 and Ralph Campbell. 9 * 10 * %sccs.include.redist.c% 11 * 12 * from: Utah $Hdr: mem.c 1.14 90/10/12$ 13 * 14 * @(#)mem.c 7.1 (Berkeley) 01/07/92 15 */ 16 17 /* 18 * Memory special file 19 */ 20 21 #include "param.h" 22 #include "conf.h" 23 #include "buf.h" 24 #include "systm.h" 25 #include "malloc.h" 26 27 #include "../include/cpu.h" 28 29 #include "vm/vm_param.h" 30 #include "vm/lock.h" 31 #include "vm/pmap.h" 32 #include "vm/vm_prot.h" 33 34 /*ARGSUSED*/ 35 mmrw(dev, uio, flags) 36 dev_t dev; 37 struct uio *uio; 38 int flags; 39 { 40 register int o; 41 register u_int c, v; 42 register struct iovec *iov; 43 int error = 0; 44 caddr_t zbuf = NULL; 45 extern u_int lowram; 46 47 while (uio->uio_resid > 0 && error == 0) { 48 iov = uio->uio_iov; 49 if (iov->iov_len == 0) { 50 uio->uio_iov++; 51 uio->uio_iovcnt--; 52 if (uio->uio_iovcnt < 0) 53 panic("mmrw"); 54 continue; 55 } 56 switch (minor(dev)) { 57 58 /* minor device 0 is physical memory */ 59 case 0: 60 v = uio->uio_offset; 61 c = iov->iov_len; 62 if (v + c >= physmem) 63 return (EFAULT); 64 error = uiomove((caddr_t)(MACH_CACHED_MEMORY_ADDR + v), 65 (int)c, uio); 66 continue; 67 68 /* minor device 1 is kernel memory */ 69 case 1: 70 c = iov->iov_len; 71 if (!kernacc((caddr_t)uio->uio_offset, c, 72 uio->uio_rw == UIO_READ ? B_READ : B_WRITE)) 73 return (EFAULT); 74 error = uiomove((caddr_t)uio->uio_offset, (int)c, uio); 75 continue; 76 77 /* minor device 2 is EOF/RATHOLE */ 78 case 2: 79 if (uio->uio_rw == UIO_WRITE) 80 uio->uio_resid = 0; 81 return (0); 82 83 /* minor device 12 (/dev/zero) is source of nulls on read, rathole on write */ 84 case 12: 85 if (uio->uio_rw == UIO_WRITE) { 86 c = iov->iov_len; 87 break; 88 } 89 if (zbuf == NULL) { 90 zbuf = (caddr_t) 91 malloc(CLBYTES, M_TEMP, M_WAITOK); 92 bzero(zbuf, CLBYTES); 93 } 94 c = MIN(iov->iov_len, CLBYTES); 95 error = uiomove(zbuf, (int)c, uio); 96 continue; 97 98 default: 99 return (ENXIO); 100 } 101 if (error) 102 break; 103 iov->iov_base += c; 104 iov->iov_len -= c; 105 uio->uio_offset += c; 106 uio->uio_resid -= c; 107 } 108 if (zbuf) 109 free(zbuf, M_TEMP); 110 return (error); 111 } 112