xref: /csrg-svn/sys/kern/subr_xxx.c (revision 23383)
1 /*
2  * Copyright (c) 1982 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	6.6 (Berkeley) 06/08/85
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 #ifndef vax
44 imin(a, b)
45 {
46 
47 	return (a < b ? a : b);
48 }
49 
50 imax(a, b)
51 {
52 
53 	return (a > b ? a : b);
54 }
55 
56 unsigned
57 min(a, b)
58 	u_int a, b;
59 {
60 
61 	return (a < b ? a : b);
62 }
63 
64 unsigned
65 max(a, b)
66 	u_int a, b;
67 {
68 
69 	return (a > b ? a : b);
70 }
71 #endif not vax
72 
73 extern	cabase, calimit;
74 extern	struct pte camap[];
75 
76 caddr_t	cacur = (caddr_t)&cabase;
77 caddr_t	camax = (caddr_t)&cabase;
78 int	cax = 0;
79 /*
80  * This is a kernel-mode storage allocator.
81  * It is very primitive, currently, in that
82  * there is no way to give space back.
83  * It serves, for the time being, the needs of
84  * auto-configuration code and the like which
85  * need to allocate some stuff at boot time.
86  */
87 caddr_t
88 calloc(size)
89 	int size;
90 {
91 	register caddr_t res;
92 	register int i;
93 
94 	if (cacur+size >= (caddr_t)&calimit)
95 		panic("calloc");
96 	while (cacur+size > camax) {
97 		(void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
98 		vmaccess(&camap[cax], camax, CLSIZE);
99 		for (i = 0; i < CLSIZE; i++)
100 			clearseg(camap[cax++].pg_pfnum);
101 		camax += NBPG * CLSIZE;
102 	}
103 	res = cacur;
104 	cacur += size;
105 	return (res);
106 }
107 
108 /*
109  * Stub routine in case it is ever possible to free space.
110  */
111 cfreemem(cp, size)
112 	caddr_t cp;
113 	int size;
114 {
115 	printf("freeing %x, size %d\n", cp, size);
116 }
117 
118 #ifndef vax
119 ffs(mask)
120 	register long mask;
121 {
122 	register int i;
123 
124 	for(i = 1; i < NSIG; i++) {
125 		if (mask & 1)
126 			return (i);
127 		mask >>= 1;
128 	}
129 	return (0);
130 }
131 
132 bcmp(s1, s2, len)
133 	register char *s1, *s2;
134 	register int len;
135 {
136 
137 	while (len--)
138 		if (*s1++ != *s2++)
139 			return (1);
140 	return (0);
141 }
142 
143 strlen(s1)
144 	register char *s1;
145 {
146 	register int len;
147 
148 	for (len = 0; *s1++ != '\0'; len++)
149 		/* void */;
150 	return (len);
151 }
152 #endif
153