1 /* subr_xxx.c 4.22 83/05/27 */ 2 3 #include "../machine/pte.h" 4 5 #include "../h/param.h" 6 #include "../h/systm.h" 7 #include "../h/conf.h" 8 #include "../h/inode.h" 9 #include "../h/dir.h" 10 #include "../h/user.h" 11 #include "../h/buf.h" 12 #include "../h/proc.h" 13 #include "../h/fs.h" 14 #include "../h/vm.h" 15 #include "../h/cmap.h" 16 #include "../h/uio.h" 17 18 /* 19 * Routine placed in illegal entries in the bdevsw and cdevsw tables. 20 */ 21 nodev() 22 { 23 24 return (ENODEV); 25 } 26 27 /* 28 * Null routine; placed in insignificant entries 29 * in the bdevsw and cdevsw tables. 30 */ 31 nulldev() 32 { 33 34 return (0); 35 } 36 37 imin(a, b) 38 { 39 40 return (a < b ? a : b); 41 } 42 43 imax(a, b) 44 { 45 46 return (a > b ? a : b); 47 } 48 49 unsigned 50 min(a, b) 51 u_int a, b; 52 { 53 54 return (a < b ? a : b); 55 } 56 57 unsigned 58 max(a, b) 59 u_int a, b; 60 { 61 62 return (a > b ? a : b); 63 } 64 65 extern cabase, calimit; 66 extern struct pte camap[]; 67 68 caddr_t cacur = (caddr_t)&cabase; 69 caddr_t camax = (caddr_t)&cabase; 70 int cax = 0; 71 /* 72 * This is a kernel-mode storage allocator. 73 * It is very primitive, currently, in that 74 * there is no way to give space back. 75 * It serves, for the time being, the needs of 76 * auto-configuration code and the like which 77 * need to allocate some stuff at boot time. 78 */ 79 caddr_t 80 calloc(size) 81 int size; 82 { 83 register caddr_t res; 84 register int i; 85 86 if (cacur+size >= (caddr_t)&calimit) 87 panic("calloc"); 88 while (cacur+size > camax) { 89 (void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS); 90 vmaccess(&camap[cax], camax, CLSIZE); 91 for (i = 0; i < CLSIZE; i++) 92 clearseg(camap[cax++].pg_pfnum); 93 camax += NBPG * CLSIZE; 94 } 95 res = cacur; 96 cacur += size; 97 return (res); 98 } 99 100 #ifndef vax 101 ffs(mask) 102 register long mask; 103 { 104 register int i; 105 106 for(i = 1; i < NSIG; i++) { 107 if (mask & 1) 108 return (i); 109 mask >>= 1; 110 } 111 return (0); 112 } 113 114 bcmp(s1, s2, len) 115 register char *s1, *s2; 116 register int len; 117 { 118 119 while (len--) 120 if (*s1++ != *s2++) 121 return (1); 122 return (0); 123 } 124 125 strlen(s1) 126 register char *s1; 127 { 128 register int len; 129 130 for (len = 0; *s1++ != '\0'; len++) 131 /* void */; 132 return (len); 133 } 134 #endif 135 136 /* 137 * Pass back c to the user. 138 */ 139 passuc(c, uio) 140 register c; 141 struct uio *uio; 142 { 143 register struct iovec *iov = uio->uio_iov; 144 145 switch (uio->uio_segflg) { 146 147 case 0: 148 if (subyte(iov->iov_base, c) < 0) 149 goto fault; 150 break; 151 152 case 1: 153 *iov->iov_base = c; 154 break; 155 156 case 2: 157 if (suibyte(iov->iov_base, c) < 0) 158 goto fault; 159 break; 160 } 161 iov->iov_base++; 162 iov->iov_len--; 163 uio->uio_resid--; 164 uio->uio_offset++; 165 if (iov->iov_len <= 0) { 166 uio->uio_iov++; 167 uio->uio_iovcnt--; 168 } 169 return (0); 170 fault: 171 return (EFAULT); 172 } 173