141058Swilliam /*-
263359Sbostic * Copyright (c) 1990, 1993
363359Sbostic * The Regents of the University of California. All rights reserved.
441058Swilliam *
541058Swilliam * This code is derived from software contributed to Berkeley by
641058Swilliam * William Jolitz.
741058Swilliam *
846006Swilliam * %sccs.include.redist.c%
941058Swilliam *
10*69463Smckusick * @(#)param.h 8.3 (Berkeley) 05/14/95
1141058Swilliam */
1241058Swilliam
1340461Sbill /*
1440461Sbill * Machine dependent constants for Intel 386.
1540461Sbill */
1640461Sbill
1740461Sbill #define MACHINE "i386"
18*69463Smckusick #define NCPUS 1
1940461Sbill
2050141Ssklower /*
2152589Sbostic * Round p (pointer or byte index) up to a correctly-aligned value for all
2252589Sbostic * data types (int, long, ...). The result is u_int and must be cast to
2352589Sbostic * any desired pointer type.
2450141Ssklower */
2553673Sbostic #define ALIGNBYTES 3
2653673Sbostic #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
2750141Ssklower
2840461Sbill #define NBPG 4096 /* bytes/page */
2940461Sbill #define PGOFSET (NBPG-1) /* byte offset into page */
3040461Sbill #define PGSHIFT 12 /* LOG2(NBPG) */
3140461Sbill #define NPTEPG (NBPG/(sizeof (struct pte)))
3240461Sbill
3340461Sbill #define NBPDR (1024*NBPG) /* bytes/page dir */
3440461Sbill #define PDROFSET (NBPDR-1) /* byte offset into page dir */
3540461Sbill #define PDRSHIFT 22 /* LOG2(NBPDR) */
3640461Sbill
3740461Sbill #define KERNBASE 0xFE000000 /* start of kernel virtual */
3840461Sbill #define BTOPKERNBASE ((u_long)KERNBASE >> PGSHIFT)
3940461Sbill
4040461Sbill #define DEV_BSIZE 512
4140461Sbill #define DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
4240461Sbill #define BLKDEV_IOSIZE 2048
4340461Sbill #define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
4440461Sbill
4540461Sbill #define CLSIZE 1
4640461Sbill #define CLSIZELOG2 0
4740461Sbill
4848796Sbostic /* NOTE: SSIZE, SINCR and UPAGES must be multiples of CLSIZE */
4940461Sbill #define SSIZE 1 /* initial stack size/NBPG */
5040461Sbill #define SINCR 1 /* increment of stack/NBPG */
5140461Sbill
5241058Swilliam #define UPAGES 2 /* pages of u-area */
5340461Sbill
5440461Sbill /*
5545964Swilliam * Constants related to network buffer management.
5645964Swilliam * MCLBYTES must be no larger than CLBYTES (the software page size), and,
5745964Swilliam * on machines that exchange pages of input or output buffers with mbuf
5845964Swilliam * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
5945964Swilliam * of the hardware page size.
6045964Swilliam */
6145964Swilliam #define MSIZE 128 /* size of an mbuf */
6245964Swilliam #define MCLBYTES 1024
6345964Swilliam #define MCLSHIFT 10
6445964Swilliam #define MCLOFSET (MCLBYTES - 1)
6545964Swilliam #ifndef NMBCLUSTERS
6645964Swilliam #ifdef GATEWAY
6745964Swilliam #define NMBCLUSTERS 512 /* map size, max cluster allocation */
6845964Swilliam #else
6945964Swilliam #define NMBCLUSTERS 256 /* map size, max cluster allocation */
7045964Swilliam #endif
7145964Swilliam #endif
7245964Swilliam
7345964Swilliam /*
7445964Swilliam * Size of kernel malloc arena in CLBYTES-sized logical pages
7545964Swilliam */
7645964Swilliam #ifndef NKMEMCLUSTERS
7750267Skarels #define NKMEMCLUSTERS (2048*1024/CLBYTES)
7845964Swilliam #endif
7945964Swilliam /*
8040461Sbill * Some macros for units conversion
8140461Sbill */
8240461Sbill /* Core clicks (4096 bytes) to segments and vice versa */
8340461Sbill #define ctos(x) (x)
8440461Sbill #define stoc(x) (x)
8540461Sbill
8640461Sbill /* Core clicks (4096 bytes) to disk blocks */
8740461Sbill #define ctod(x) ((x)<<(PGSHIFT-DEV_BSHIFT))
8840461Sbill #define dtoc(x) ((x)>>(PGSHIFT-DEV_BSHIFT))
8940461Sbill #define dtob(x) ((x)<<DEV_BSHIFT)
9040461Sbill
9140461Sbill /* clicks to bytes */
9240461Sbill #define ctob(x) ((x)<<PGSHIFT)
9340461Sbill
9440461Sbill /* bytes to clicks */
9540461Sbill #define btoc(x) (((unsigned)(x)+(NBPG-1))>>PGSHIFT)
9640461Sbill
9740461Sbill #define btodb(bytes) /* calculates (bytes / DEV_BSIZE) */ \
9868632Smckusick ((bytes) >> DEV_BSHIFT)
9940461Sbill #define dbtob(db) /* calculates (db * DEV_BSIZE) */ \
10068632Smckusick ((db) << DEV_BSHIFT)
10140461Sbill
10240461Sbill /*
10340461Sbill * Map a ``block device block'' to a file system block.
10440461Sbill * This should be device dependent, and will be if we
10540461Sbill * add an entry to cdevsw/bdevsw for that purpose.
10640461Sbill * For now though just use DEV_BSIZE.
10740461Sbill */
10840461Sbill #define bdbtofsb(bn) ((bn) / (BLKDEV_IOSIZE/DEV_BSIZE))
10940461Sbill
11047999Swilliam /*
11147999Swilliam * Mach derived conversion macros
11247999Swilliam */
11347999Swilliam #define i386_round_pdr(x) ((((unsigned)(x)) + NBPDR - 1) & ~(NBPDR-1))
11447999Swilliam #define i386_trunc_pdr(x) ((unsigned)(x) & ~(NBPDR-1))
11547999Swilliam #define i386_round_page(x) ((((unsigned)(x)) + NBPG - 1) & ~(NBPG-1))
11647999Swilliam #define i386_trunc_page(x) ((unsigned)(x) & ~(NBPG-1))
11747999Swilliam #define i386_btod(x) ((unsigned)(x) >> PDRSHIFT)
11847999Swilliam #define i386_dtob(x) ((unsigned)(x) << PDRSHIFT)
11947999Swilliam #define i386_btop(x) ((unsigned)(x) >> PGSHIFT)
12047999Swilliam #define i386_ptob(x) ((unsigned)(x) << PGSHIFT)
12147999Swilliam
12253638Sbostic #ifndef KERNEL
12353638Sbostic /* DELAY is in locore.s for the kernel */
12440461Sbill #define DELAY(n) { register int N = (n); while (--N > 0); }
12550031Sbostic #endif
126*69463Smckusick
127*69463Smckusick #ifndef _SIMPLELOCK_H_
128*69463Smckusick #define _SIMPLELOCK_H_
129*69463Smckusick /*
130*69463Smckusick * A simple spin lock.
131*69463Smckusick *
132*69463Smckusick * This structure only sets one bit of data, but is sized based on the
133*69463Smckusick * minimum word size that can be operated on by the hardware test-and-set
134*69463Smckusick * instruction. It is only needed for multiprocessors, as uniprocessors
135*69463Smckusick * will always run to completion or a sleep. It is an error to hold one
136*69463Smckusick * of these locks while a process is sleeping.
137*69463Smckusick */
138*69463Smckusick struct simplelock {
139*69463Smckusick int lock_data;
140*69463Smckusick };
141*69463Smckusick
142*69463Smckusick #if !defined(DEBUG) && NCPUS > 1
143*69463Smckusick /*
144*69463Smckusick * The simple-lock routines are the primitives out of which the lock
145*69463Smckusick * package is built. The machine-dependent code must implement an
146*69463Smckusick * atomic test_and_set operation that indivisibly sets the simple lock
147*69463Smckusick * to non-zero and returns its old value. It also assumes that the
148*69463Smckusick * setting of the lock to zero below is indivisible. Simple locks may
149*69463Smckusick * only be used for exclusive locks.
150*69463Smckusick */
151*69463Smckusick static __inline void
simple_lock_init(lkp)152*69463Smckusick simple_lock_init(lkp)
153*69463Smckusick struct simplelock *lkp;
154*69463Smckusick {
155*69463Smckusick
156*69463Smckusick lkp->lock_data = 0;
157*69463Smckusick }
158*69463Smckusick
159*69463Smckusick static __inline void
simple_lock(lkp)160*69463Smckusick simple_lock(lkp)
161*69463Smckusick __volatile struct simplelock *lkp;
162*69463Smckusick {
163*69463Smckusick
164*69463Smckusick while (test_and_set(&lkp->lock_data))
165*69463Smckusick continue;
166*69463Smckusick }
167*69463Smckusick
168*69463Smckusick static __inline int
simple_lock_try(lkp)169*69463Smckusick simple_lock_try(lkp)
170*69463Smckusick __volatile struct simplelock *lkp;
171*69463Smckusick {
172*69463Smckusick
173*69463Smckusick return (!test_and_set(&lkp->lock_data))
174*69463Smckusick }
175*69463Smckusick
176*69463Smckusick static __inline void
177*69463Smckusick simple_unlock(lkp)
178*69463Smckusick __volatile struct simplelock *lkp;
179*69463Smckusick {
180*69463Smckusick
181*69463Smckusick lkp->lock_data = 0;
182*69463Smckusick }
183*69463Smckusick #endif /* NCPUS > 1 */
184*69463Smckusick #endif /* !_SIMPLELOCK_H_ */
185