xref: /csrg-svn/sys/kern/subr_xxx.c (revision 8626)
1 /*	subr_xxx.c	4.19	82/10/17	*/
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 ffs(mask)
114 	register long mask;
115 {
116 	register int i;
117 
118 	for(i=1; i<NSIG; i++) {
119 		if (mask & 1)
120 			return (i);
121 		mask >>= 1;
122 	}
123 	return (0);
124 }
125 
126 bcmp(s1, s2, len)
127 	register char *s1, *s2;
128 	register int len;
129 {
130 
131 	while (--len)
132 		if (*s1++ != *s2++)
133 			return (1);
134 	return (0);
135 }
136 
137 strlen(s1)
138 	register char *s1;
139 {
140 	register int len;
141 
142 	for (len = 0; *s1++ != '\0'; len++)
143 		/* void */;
144 	return (len);
145 }
146 #endif
147 
148 /*
149  * Pass back c to the user.
150  */
151 passuc(c, uio)
152 	register c;
153 	struct uio *uio;
154 {
155 	register struct iovec *iov = uio->uio_iov;
156 
157 	switch (uio->uio_segflg) {
158 
159 	case 0:
160 		if (subyte(iov->iov_base, c) < 0)
161 			goto fault;
162 		break;
163 
164 	case 1:
165 		*iov->iov_base = c;
166 		break;
167 
168 	case 2:
169 		if (suibyte(iov->iov_base, c) < 0)
170 			goto fault;
171 		break;
172 	}
173 	iov->iov_base++;
174 	iov->iov_len--;
175 	uio->uio_resid--;
176 	uio->uio_offset++;
177 	if (iov->iov_len <= 0) {
178 		uio->uio_iov++;
179 		uio->uio_iovcnt--;
180 	}
181 	return (0);
182 fault:
183 	return (EFAULT);
184 }
185