use IMIN macro to save call overhead
[unix-history] / usr / src / sys / kern / subr_xxx.c
CommitLineData
44a388b8 1/* subr_xxx.c 6.3 84/07/28 */
961945a8
SL
2
3#include "../machine/pte.h"
ae9e2121
BJ
4
5#include "../h/param.h"
6#include "../h/systm.h"
7#include "../h/conf.h"
8#include "../h/inode.h"
9#include "../h/dir.h"
10#include "../h/user.h"
11#include "../h/buf.h"
12#include "../h/proc.h"
6459ebe0 13#include "../h/fs.h"
cb99a88a 14#include "../h/vm.h"
cb99a88a 15#include "../h/cmap.h"
d6d7360b 16#include "../h/uio.h"
ae9e2121 17
ae9e2121 18/*
50a84b40 19 * Routine placed in illegal entries in the bdevsw and cdevsw tables.
ae9e2121
BJ
20 */
21nodev()
22{
23
50a84b40 24 return (ENODEV);
ae9e2121
BJ
25}
26
27/*
28 * Null routine; placed in insignificant entries
29 * in the bdevsw and cdevsw tables.
30 */
31nulldev()
32{
33
50a84b40 34 return (0);
ae9e2121
BJ
35}
36
37imin(a, b)
38{
39
40 return (a < b ? a : b);
41}
42
43imax(a, b)
44{
45
46 return (a > b ? a : b);
47}
48
6459ebe0
KM
49unsigned
50min(a, b)
b32450f4 51 u_int a, b;
6459ebe0
KM
52{
53
54 return (a < b ? a : b);
55}
56
57unsigned
58max(a, b)
b32450f4 59 u_int a, b;
6459ebe0
KM
60{
61
62 return (a > b ? a : b);
63}
b32450f4 64
cb99a88a
BJ
65extern cabase, calimit;
66extern struct pte camap[];
67
68caddr_t cacur = (caddr_t)&cabase;
69caddr_t camax = (caddr_t)&cabase;
70int cax = 0;
71/*
72 * This is a kernel-mode storage allocator.
73 * It is very primitive, currently, in that
74 * there is no way to give space back.
75 * It serves, for the time being, the needs of
76 * auto-configuration code and the like which
77 * need to allocate some stuff at boot time.
78 */
79caddr_t
80calloc(size)
81 int size;
82{
83 register caddr_t res;
84 register int i;
85
86 if (cacur+size >= (caddr_t)&calimit)
87 panic("calloc");
88 while (cacur+size > camax) {
89 (void) vmemall(&camap[cax], CLSIZE, &proc[0], CSYS);
90 vmaccess(&camap[cax], camax, CLSIZE);
91 for (i = 0; i < CLSIZE; i++)
92 clearseg(camap[cax++].pg_pfnum);
93 camax += NBPG * CLSIZE;
94 }
95 res = cacur;
96 cacur += size;
97 return (res);
98}
febd1daa 99
44a388b8
KM
100/*
101 * Stub routine in case it is ever possible to free space.
102 */
103cfreemem(cp, size)
104 caddr_t cp;
105 int size;
106{
107 printf("freeing %x, size %d\n", cp, size);
108}
109
cb99a88a
BJ
110#ifndef vax
111ffs(mask)
112 register long mask;
113{
114 register int i;
115
88a7a62a 116 for(i = 1; i < NSIG; i++) {
cb99a88a
BJ
117 if (mask & 1)
118 return (i);
119 mask >>= 1;
120 }
121 return (0);
122}
febd1daa 123
febd1daa
BJ
124bcmp(s1, s2, len)
125 register char *s1, *s2;
126 register int len;
127{
128
f49dd739 129 while (len--)
febd1daa
BJ
130 if (*s1++ != *s2++)
131 return (1);
132 return (0);
133}
134
135strlen(s1)
136 register char *s1;
137{
138 register int len;
139
140 for (len = 0; *s1++ != '\0'; len++)
141 /* void */;
142 return (len);
143}
144#endif