xref: /csrg-svn/sys/kern/subr_xxx.c (revision 7819)
1 /*	subr_xxx.c	4.17	82/08/22	*/
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 which sets a user error; placed in
19  * illegal entries in the bdevsw and cdevsw tables.
20  */
21 nodev()
22 {
23 
24 	u.u_error = ENODEV;
25 }
26 
27 /*
28  * Null routine; placed in insignificant entries
29  * in the bdevsw and cdevsw tables.
30  */
31 nulldev()
32 {
33 
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 	unsigned int a, b;
51 {
52 
53 	return (a < b ? a : b);
54 }
55 
56 unsigned
57 max(a, b)
58 	unsigned int a, b;
59 {
60 
61 	return (a > b ? a : b);
62 }
63 extern	cabase, calimit;
64 extern	struct pte camap[];
65 
66 caddr_t	cacur = (caddr_t)&cabase;
67 caddr_t	camax = (caddr_t)&cabase;
68 int	cax = 0;
69 /*
70  * This is a kernel-mode storage allocator.
71  * It is very primitive, currently, in that
72  * there is no way to give space back.
73  * It serves, for the time being, the needs of
74  * auto-configuration code and the like which
75  * need to allocate some stuff at boot time.
76  */
77 caddr_t
78 calloc(size)
79 	int size;
80 {
81 	register caddr_t res;
82 	register int i;
83 
84 	if (cacur+size >= (caddr_t)&calimit)
85 		panic("calloc");
86 	while (cacur+size > camax) {
87 		(void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
88 		vmaccess(&camap[cax], camax, CLSIZE);
89 		for (i = 0; i < CLSIZE; i++)
90 			clearseg(camap[cax++].pg_pfnum);
91 		camax += NBPG * CLSIZE;
92 	}
93 	res = cacur;
94 	cacur += size;
95 	return (res);
96 }
97 
98 #ifndef vax
99 ffs(mask)
100 	register long mask;
101 {
102 	register int i;
103 
104 	for(i=1; i<NSIG; i++) {
105 		if (mask & 1)
106 			return (i);
107 		mask >>= 1;
108 	}
109 	return (0);
110 }
111 
112 ffs(mask)
113 	register long mask;
114 {
115 	register int i;
116 
117 	for(i=1; i<NSIG; i++) {
118 		if (mask & 1)
119 			return (i);
120 		mask >>= 1;
121 	}
122 	return (0);
123 }
124 
125 bcmp(s1, s2, len)
126 	register char *s1, *s2;
127 	register int len;
128 {
129 
130 	while (--len)
131 		if (*s1++ != *s2++)
132 			return (1);
133 	return (0);
134 }
135 
136 strlen(s1)
137 	register char *s1;
138 {
139 	register int len;
140 
141 	for (len = 0; *s1++ != '\0'; len++)
142 		/* void */;
143 	return (len);
144 }
145 #endif
146 
147 /*
148  * Pass back c to the user.
149  */
150 passuc(c, uio)
151 	register c;
152 	struct uio *uio;
153 {
154 	register struct iovec *iov = uio->uio_iov;
155 
156 	switch (uio->uio_segflg) {
157 
158 	case 0:
159 		if (subyte(iov->iov_base, c) < 0)
160 			goto fault;
161 		break;
162 
163 	case 1:
164 		*iov->iov_base = c;
165 		break;
166 
167 	case 2:
168 		if (suibyte(iov->iov_base, c) < 0)
169 			goto fault;
170 		break;
171 	}
172 	iov->iov_base++;
173 	iov->iov_len--;
174 	uio->uio_resid--;
175 	uio->uio_offset++;
176 	if (iov->iov_len <= 0) {
177 		uio->uio_iov++;
178 		uio->uio_iovcnt--;
179 	}
180 	return (0);
181 fault:
182 	return (EFAULT);
183 }
184