xref: /csrg-svn/sys/kern/subr_xxx.c (revision 29946)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)subr_xxx.c	7.2 (Berkeley) 11/03/86
7  */
8 
9 #include "../machine/pte.h"
10 
11 #include "param.h"
12 #include "systm.h"
13 #include "conf.h"
14 #include "inode.h"
15 #include "dir.h"
16 #include "user.h"
17 #include "buf.h"
18 #include "proc.h"
19 #include "fs.h"
20 #include "vm.h"
21 #include "cmap.h"
22 #include "uio.h"
23 
24 /*
25  * Routine placed in illegal entries in the bdevsw and cdevsw tables.
26  */
27 nodev()
28 {
29 
30 	return (ENODEV);
31 }
32 
33 /*
34  * Null routine; placed in insignificant entries
35  * in the bdevsw and cdevsw tables.
36  */
37 nulldev()
38 {
39 
40 	return (0);
41 }
42 
43 /*
44  * Definitions of various trivial functions;
45  * usually expanded inline rather than being defined here.
46  */
47 #if !defined(vax) && !defined(tahoe)
48 imin(a, b)
49 {
50 
51 	return (a < b ? a : b);
52 }
53 
54 imax(a, b)
55 {
56 
57 	return (a > b ? a : b);
58 }
59 
60 unsigned
61 min(a, b)
62 	u_int a, b;
63 {
64 
65 	return (a < b ? a : b);
66 }
67 
68 unsigned
69 max(a, b)
70 	u_int a, b;
71 {
72 
73 	return (a > b ? a : b);
74 }
75 #endif
76 
77 extern	cabase, calimit;
78 extern	struct pte camap[];
79 
80 caddr_t	cacur = (caddr_t)&cabase;
81 caddr_t	camax = (caddr_t)&cabase;
82 int	cax = 0;
83 /*
84  * This is a kernel-mode storage allocator.
85  * It is very primitive, currently, in that
86  * there is no way to give space back.
87  * It serves, for the time being, the needs of
88  * auto-configuration code and the like which
89  * need to allocate some stuff at boot time.
90  */
91 caddr_t
92 calloc(size)
93 	int size;
94 {
95 	register caddr_t res;
96 	register int i;
97 
98 	if (cacur+size >= (caddr_t)&calimit)
99 		panic("calloc");
100 	while (cacur+size > camax) {
101 		(void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
102 		vmaccess(&camap[cax], camax, CLSIZE);
103 		for (i = 0; i < CLSIZE; i++)
104 			clearseg(camap[cax++].pg_pfnum);
105 		camax += NBPG * CLSIZE;
106 	}
107 	res = cacur;
108 	cacur += size;
109 	return (res);
110 }
111 
112 #ifdef GPROF
113 /*
114  * Stub routine in case it is ever possible to free space.
115  */
116 cfreemem(cp, size)
117 	caddr_t cp;
118 	int size;
119 {
120 	printf("freeing %x, size %d\n", cp, size);
121 }
122 #endif
123 
124 #if !defined(vax) && !defined(tahoe)
125 ffs(mask)
126 	register long mask;
127 {
128 	register int i;
129 
130 	for(i = 1; i < NSIG; i++) {
131 		if (mask & 1)
132 			return (i);
133 		mask >>= 1;
134 	}
135 	return (0);
136 }
137 #endif
138 
139 #if !defined(vax)
140 bcmp(s1, s2, len)
141 	register char *s1, *s2;
142 	register int len;
143 {
144 
145 	while (len--)
146 		if (*s1++ != *s2++)
147 			return (1);
148 	return (0);
149 }
150 
151 strlen(s1)
152 	register char *s1;
153 {
154 	register int len;
155 
156 	for (len = 0; *s1++ != '\0'; len++)
157 		/* void */;
158 	return (len);
159 }
160 #endif
161