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