1 /*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz.
7 *
8 * %sccs.include.redist.c%
9 *
10 * @(#)param.h 8.3 (Berkeley) 05/14/95
11 */
12
13 /*
14 * Machine dependent constants for Intel 386.
15 */
16
17 #define MACHINE "i386"
18 #define NCPUS 1
19
20 /*
21 * Round p (pointer or byte index) up to a correctly-aligned value for all
22 * data types (int, long, ...). The result is u_int and must be cast to
23 * any desired pointer type.
24 */
25 #define ALIGNBYTES 3
26 #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
27
28 #define NBPG 4096 /* bytes/page */
29 #define PGOFSET (NBPG-1) /* byte offset into page */
30 #define PGSHIFT 12 /* LOG2(NBPG) */
31 #define NPTEPG (NBPG/(sizeof (struct pte)))
32
33 #define NBPDR (1024*NBPG) /* bytes/page dir */
34 #define PDROFSET (NBPDR-1) /* byte offset into page dir */
35 #define PDRSHIFT 22 /* LOG2(NBPDR) */
36
37 #define KERNBASE 0xFE000000 /* start of kernel virtual */
38 #define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT)
39
40 #define DEV_BSIZE 512
41 #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
42 #define BLKDEV_IOSIZE 2048
43 #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
44
45 #define CLSIZE 1
46 #define CLSIZELOG2 0
47
48 /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */
49 #define SSIZE 1 /* initial stack size/NBPG */
50 #define SINCR 1 /* increment of stack/NBPG */
51
52 #define UPAGES 2 /* pages of u-area */
53
54 /*
55 * Constants related to network buffer management.
56 * MCLBYTES must be no larger than CLBYTES (the software page size), and,
57 * on machines that exchange pages of input or output buffers with mbuf
58 * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
59 * of the hardware page size.
60 */
61 #define MSIZE 128 /* size of an mbuf */
62 #define MCLBYTES 1024
63 #define MCLSHIFT 10
64 #define MCLOFSET (MCLBYTES - 1)
65 #ifndef NMBCLUSTERS
66 #ifdef GATEWAY
67 #define NMBCLUSTERS 512 /* map size, max cluster allocation */
68 #else
69 #define NMBCLUSTERS 256 /* map size, max cluster allocation */
70 #endif
71 #endif
72
73 /*
74 * Size of kernel malloc arena in CLBYTES-sized logical pages
75 */
76 #ifndef NKMEMCLUSTERS
77 #define NKMEMCLUSTERS (2048*1024/CLBYTES)
78 #endif
79 /*
80 * Some macros for units conversion
81 */
82 /* Core clicks (4096 bytes) to segments and vice versa */
83 #define ctos(x) (x)
84 #define stoc(x) (x)
85
86 /* Core clicks (4096 bytes) to disk blocks */
87 #define ctod(x) ((x)<<(PGSHIFT-DEV_BSHIFT))
88 #define dtoc(x) ((x)>>(PGSHIFT-DEV_BSHIFT))
89 #define dtob(x) ((x)<<DEV_BSHIFT)
90
91 /* clicks to bytes */
92 #define ctob(x) ((x)<<PGSHIFT)
93
94 /* bytes to clicks */
95 #define btoc(x) (((unsigned)(x)+(NBPG-1))>>PGSHIFT)
96
97 #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \
98 ((bytes) >> DEV_BSHIFT)
99 #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \
100 ((db) << DEV_BSHIFT)
101
102 /*
103 * Map a ``block device block'' to a file system block.
104 * This should be device dependent, and will be if we
105 * add an entry to cdevsw/bdevsw for that purpose.
106 * For now though just use DEV_BSIZE.
107 */
108 #define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
109
110 /*
111 * Mach derived conversion macros
112 */
113 #define i386_round_pdr(x) ((((unsigned)(x)) + NBPDR - 1) & ~(NBPDR-1))
114 #define i386_trunc_pdr(x) ((unsigned)(x) & ~(NBPDR-1))
115 #define i386_round_page(x) ((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1))
116 #define i386_trunc_page(x) ((unsigned)(x) & ~(NBPG-1))
117 #define i386_btod(x) ((unsigned)(x) >> PDRSHIFT)
118 #define i386_dtob(x) ((unsigned)(x) << PDRSHIFT)
119 #define i386_btop(x) ((unsigned)(x) >> PGSHIFT)
120 #define i386_ptob(x) ((unsigned)(x) << PGSHIFT)
121
122 #ifndef KERNEL
123 /* DELAY is in locore.s for the kernel */
124 #define DELAY(n) { register int N = (n); while (--N > 0); }
125 #endif
126
127 #ifndef _SIMPLELOCK_H_
128 #define _SIMPLELOCK_H_
129 /*
130 * A simple spin lock.
131 *
132 * This structure only sets one bit of data, but is sized based on the
133 * minimum word size that can be operated on by the hardware test-and-set
134 * instruction. It is only needed for multiprocessors, as uniprocessors
135 * will always run to completion or a sleep. It is an error to hold one
136 * of these locks while a process is sleeping.
137 */
138 struct simplelock {
139 int lock_data;
140 };
141
142 #if !defined(DEBUG) && NCPUS > 1
143 /*
144 * The simple-lock routines are the primitives out of which the lock
145 * package is built. The machine-dependent code must implement an
146 * atomic test_and_set operation that indivisibly sets the simple lock
147 * to non-zero and returns its old value. It also assumes that the
148 * setting of the lock to zero below is indivisible. Simple locks may
149 * only be used for exclusive locks.
150 */
151 static __inline void
simple_lock_init(lkp)152 simple_lock_init(lkp)
153 struct simplelock *lkp;
154 {
155
156 lkp->lock_data = 0;
157 }
158
159 static __inline void
simple_lock(lkp)160 simple_lock(lkp)
161 __volatile struct simplelock *lkp;
162 {
163
164 while (test_and_set(&lkp->lock_data))
165 continue;
166 }
167
168 static __inline int
simple_lock_try(lkp)169 simple_lock_try(lkp)
170 __volatile struct simplelock *lkp;
171 {
172
173 return (!test_and_set(&lkp->lock_data))
174 }
175
176 static __inline void
177 simple_unlock(lkp)
178 __volatile struct simplelock *lkp;
179 {
180
181 lkp->lock_data = 0;
182 }
183 #endif /* NCPUS > 1 */
184 #endif /* !_SIMPLELOCK_H_ */
185