xref: /csrg-svn/sys/kern/subr_xxx.c (revision 7500)
1 /*	subr_xxx.c	4.13	82/07/24	*/
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 
16 /*
17  * Pass back  c  to the user at his location u_base;
18  * update u_base, u_count, and u_offset.  Return -1
19  * on the last character of the user's read.
20  * u_base is in the user address space unless u_segflg is set.
21  */
22 passc(c)
23 register c;
24 {
25 	register id;
26 
27 	if ((id = u.u_segflg) == 1)
28 		*u.u_base = c;
29 	else
30 		if (id?suibyte(u.u_base, c):subyte(u.u_base, c) < 0) {
31 			u.u_error = EFAULT;
32 			return (-1);
33 		}
34 	u.u_count--;
35 	u.u_offset++;
36 	u.u_base++;
37 	return (u.u_count == 0? -1: 0);
38 }
39 
40 #include "ct.h"
41 #if NCT > 0
42 /*
43  * Pick up and return the next character from the user's
44  * write call at location u_base;
45  * update u_base, u_count, and u_offset.  Return -1
46  * when u_count is exhausted.  u_base is in the user's
47  * address space unless u_segflg is set.
48  */
49 cpass()
50 {
51 	register c, id;
52 
53 	if (u.u_count == 0)
54 		return (-1);
55 	if ((id = u.u_segflg) == 1)
56 		c = *u.u_base;
57 	else
58 		if ((c = id==0?fubyte(u.u_base):fuibyte(u.u_base)) < 0) {
59 			u.u_error = EFAULT;
60 			return (-1);
61 		}
62 	u.u_count--;
63 	u.u_offset++;
64 	u.u_base++;
65 	return (c&0377);
66 }
67 #endif
68 
69 /*
70  * Routine which sets a user error; placed in
71  * illegal entries in the bdevsw and cdevsw tables.
72  */
73 nodev()
74 {
75 
76 	u.u_error = ENODEV;
77 }
78 
79 /*
80  * Null routine; placed in insignificant entries
81  * in the bdevsw and cdevsw tables.
82  */
83 nulldev()
84 {
85 
86 }
87 
88 imin(a, b)
89 {
90 
91 	return (a < b ? a : b);
92 }
93 
94 imax(a, b)
95 {
96 
97 	return (a > b ? a : b);
98 }
99 
100 unsigned
101 min(a, b)
102 	unsigned int a, b;
103 {
104 
105 	return (a < b ? a : b);
106 }
107 
108 unsigned
109 max(a, b)
110 	unsigned int a, b;
111 {
112 
113 	return (a > b ? a : b);
114 }
115 
116 struct proc *
117 pfind(pid)
118 	int pid;
119 {
120 	register struct proc *p;
121 
122 	for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash])
123 		if (p->p_pid == pid)
124 			return (p);
125 	return ((struct proc *)0);
126 }
127 extern	cabase, calimit;
128 extern	struct pte camap[];
129 
130 caddr_t	cacur = (caddr_t)&cabase;
131 caddr_t	camax = (caddr_t)&cabase;
132 int	cax = 0;
133 /*
134  * This is a kernel-mode storage allocator.
135  * It is very primitive, currently, in that
136  * there is no way to give space back.
137  * It serves, for the time being, the needs of
138  * auto-configuration code and the like which
139  * need to allocate some stuff at boot time.
140  */
141 caddr_t
142 calloc(size)
143 	int size;
144 {
145 	register caddr_t res;
146 	register int i;
147 
148 	if (cacur+size >= (caddr_t)&calimit)
149 		panic("calloc");
150 	while (cacur+size > camax) {
151 		(void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
152 		vmaccess(&camap[cax], camax, CLSIZE);
153 		for (i = 0; i < CLSIZE; i++)
154 			clearseg(camap[cax++].pg_pfnum);
155 		camax += NBPG * CLSIZE;
156 	}
157 	res = cacur;
158 	cacur += size;
159 	return (res);
160 }
161 #ifndef vax
162 ffs(mask)
163 	register long mask;
164 {
165 	register int i;
166 
167 	for(i=1; i<NSIG; i++) {
168 		if (mask & 1)
169 			return (i);
170 		mask >>= 1;
171 	}
172 	return (0);
173 }
174 #endif
175 #ifndef vax
176 ffs(mask)
177 	register long mask;
178 {
179 	register int i;
180 
181 	for(i=1; i<NSIG; i++) {
182 		if (mask & 1)
183 			return (i);
184 		mask >>= 1;
185 	}
186 	return (0);
187 }
188 #endif
189 
190