xref: /titanic_51/usr/src/uts/common/sys/sysmacros.h (revision 2c32020f848d8e5619a1f441a92f0ee4aca1b297)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2c32020fSeschrock  * Common Development and Distribution License (the "License").
6*2c32020fSeschrock  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
227c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26*2c32020fSeschrock  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_SYSMACROS_H
317c478bd9Sstevel@tonic-gate #define	_SYS_SYSMACROS_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/param.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
387c478bd9Sstevel@tonic-gate extern "C" {
397c478bd9Sstevel@tonic-gate #endif
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Some macros for units conversion
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Disk blocks (sectors) and bytes.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate #define	dtob(DD)	((DD) << DEV_BSHIFT)
487c478bd9Sstevel@tonic-gate #define	btod(BB)	(((BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
497c478bd9Sstevel@tonic-gate #define	btodt(BB)	((BB) >> DEV_BSHIFT)
507c478bd9Sstevel@tonic-gate #define	lbtod(BB)	(((offset_t)(BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /* common macros */
537c478bd9Sstevel@tonic-gate #ifndef MIN
547c478bd9Sstevel@tonic-gate #define	MIN(a, b)	((a) < (b) ? (a) : (b))
557c478bd9Sstevel@tonic-gate #endif
567c478bd9Sstevel@tonic-gate #ifndef MAX
577c478bd9Sstevel@tonic-gate #define	MAX(a, b)	((a) < (b) ? (b) : (a))
587c478bd9Sstevel@tonic-gate #endif
597c478bd9Sstevel@tonic-gate #ifndef ABS
607c478bd9Sstevel@tonic-gate #define	ABS(a)		((a) < 0 ? -(a) : (a))
617c478bd9Sstevel@tonic-gate #endif
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #ifdef _KERNEL
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Convert a single byte to/from binary-coded decimal (BCD).
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate extern unsigned char byte_to_bcd[256];
697c478bd9Sstevel@tonic-gate extern unsigned char bcd_to_byte[256];
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate #define	BYTE_TO_BCD(x)	byte_to_bcd[(x) & 0xff]
727c478bd9Sstevel@tonic-gate #define	BCD_TO_BYTE(x)	bcd_to_byte[(x) & 0xff]
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * WARNING: The device number macros defined here should not be used by device
787c478bd9Sstevel@tonic-gate  * drivers or user software. Device drivers should use the device functions
797c478bd9Sstevel@tonic-gate  * defined in the DDI/DKI interface (see also ddi.h). Application software
807c478bd9Sstevel@tonic-gate  * should make use of the library routines available in makedev(3). A set of
817c478bd9Sstevel@tonic-gate  * new device macros are provided to operate on the expanded device number
827c478bd9Sstevel@tonic-gate  * format supported in SVR4. Macro versions of the DDI device functions are
837c478bd9Sstevel@tonic-gate  * provided for use by kernel proper routines only. Macro routines bmajor(),
847c478bd9Sstevel@tonic-gate  * major(), minor(), emajor(), eminor(), and makedev() will be removed or
857c478bd9Sstevel@tonic-gate  * their definitions changed at the next major release following SVR4.
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	O_BITSMAJOR	7	/* # of SVR3 major device bits */
897c478bd9Sstevel@tonic-gate #define	O_BITSMINOR	8	/* # of SVR3 minor device bits */
907c478bd9Sstevel@tonic-gate #define	O_MAXMAJ	0x7f	/* SVR3 max major value */
917c478bd9Sstevel@tonic-gate #define	O_MAXMIN	0xff	/* SVR3 max minor value */
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #define	L_BITSMAJOR32	14	/* # of SVR4 major device bits */
957c478bd9Sstevel@tonic-gate #define	L_BITSMINOR32	18	/* # of SVR4 minor device bits */
967c478bd9Sstevel@tonic-gate #define	L_MAXMAJ32	0x3fff	/* SVR4 max major value */
977c478bd9Sstevel@tonic-gate #define	L_MAXMIN32	0x3ffff	/* MAX minor for 3b2 software drivers. */
987c478bd9Sstevel@tonic-gate 				/* For 3b2 hardware devices the minor is */
997c478bd9Sstevel@tonic-gate 				/* restricted to 256 (0-255) */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate #ifdef _LP64
1027c478bd9Sstevel@tonic-gate #define	L_BITSMAJOR	32	/* # of major device bits in 64-bit Solaris */
1037c478bd9Sstevel@tonic-gate #define	L_BITSMINOR	32	/* # of minor device bits in 64-bit Solaris */
1047c478bd9Sstevel@tonic-gate #define	L_MAXMAJ	0xfffffffful	/* max major value */
1057c478bd9Sstevel@tonic-gate #define	L_MAXMIN	0xfffffffful	/* max minor value */
1067c478bd9Sstevel@tonic-gate #else
1077c478bd9Sstevel@tonic-gate #define	L_BITSMAJOR	L_BITSMAJOR32
1087c478bd9Sstevel@tonic-gate #define	L_BITSMINOR	L_BITSMINOR32
1097c478bd9Sstevel@tonic-gate #define	L_MAXMAJ	L_MAXMAJ32
1107c478bd9Sstevel@tonic-gate #define	L_MAXMIN	L_MAXMIN32
1117c478bd9Sstevel@tonic-gate #endif
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /* major part of a device internal to the kernel */
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	major(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
1187c478bd9Sstevel@tonic-gate #define	bmajor(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /* get internal major part of expanded device number */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #define	getmajor(x)	(major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ)
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /* minor part of a device internal to the kernel */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define	minor(x)	(minor_t)((x) & O_MAXMIN)
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /* get internal minor part of expanded device number */
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	getminor(x)	(minor_t)((x) & L_MAXMIN)
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #else
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /* major part of a device external from the kernel (same as emajor below) */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #define	major(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /* minor part of a device external from the kernel  (same as eminor below) */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	minor(x)	(minor_t)((x) & O_MAXMIN)
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /* create old device number */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #define	makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN))
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* make an new device number */
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #define	makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN))
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * emajor() allows kernel/driver code to print external major numbers
1557c478bd9Sstevel@tonic-gate  * eminor() allows kernel/driver code to print external minor numbers
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #define	emajor(x) \
1597c478bd9Sstevel@tonic-gate 	(major_t)(((unsigned int)(x) >> O_BITSMINOR) > O_MAXMAJ) ? \
1607c478bd9Sstevel@tonic-gate 	    NODEV : (((unsigned int)(x) >> O_BITSMINOR) & O_MAXMAJ)
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #define	eminor(x) \
1637c478bd9Sstevel@tonic-gate 	(minor_t)((x) & O_MAXMIN)
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * get external major and minor device
1677c478bd9Sstevel@tonic-gate  * components from expanded device number
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #define	getemajor(x)	(major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
1707c478bd9Sstevel@tonic-gate 			    NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
1717c478bd9Sstevel@tonic-gate #define	geteminor(x)	(minor_t)((x) & L_MAXMIN)
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * These are versions of the kernel routines for compressing and
1757c478bd9Sstevel@tonic-gate  * expanding long device numbers that don't return errors.
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate #if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR)
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #define	DEVCMPL(x)	(x)
1807c478bd9Sstevel@tonic-gate #define	DEVEXPL(x)	(x)
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #else
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	DEVCMPL(x)	\
1857c478bd9Sstevel@tonic-gate 	(dev32_t)((((x) >> L_BITSMINOR) > L_MAXMAJ32 || \
1867c478bd9Sstevel@tonic-gate 	    ((x) & L_MAXMIN) > L_MAXMIN32) ? NODEV32 : \
1877c478bd9Sstevel@tonic-gate 	    ((((x) >> L_BITSMINOR) << L_BITSMINOR32) | ((x) & L_MAXMIN32)))
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #define	DEVEXPL(x)	\
1907c478bd9Sstevel@tonic-gate 	(((x) == NODEV32) ? NODEV : \
1917c478bd9Sstevel@tonic-gate 	makedevice(((x) >> L_BITSMINOR32) & L_MAXMAJ32, (x) & L_MAXMIN32))
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate #endif /* L_BITSMAJOR32 ... */
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /* convert to old (SVR3.2) dev format */
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #define	cmpdev(x) \
1987c478bd9Sstevel@tonic-gate 	(o_dev_t)((((x) >> L_BITSMINOR) > O_MAXMAJ || \
1997c478bd9Sstevel@tonic-gate 	    ((x) & L_MAXMIN) > O_MAXMIN) ? NODEV : \
2007c478bd9Sstevel@tonic-gate 	    ((((x) >> L_BITSMINOR) << O_BITSMINOR) | ((x) & O_MAXMIN)))
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /* convert to new (SVR4) dev format */
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate #define	expdev(x) \
2057c478bd9Sstevel@tonic-gate 	(dev_t)(((dev_t)(((x) >> O_BITSMINOR) & O_MAXMAJ) << L_BITSMINOR) | \
2067c478bd9Sstevel@tonic-gate 	    ((x) & O_MAXMIN))
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * Macro for checking power of 2 address alignment.
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate #define	IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate /*
2147c478bd9Sstevel@tonic-gate  * Macros for counting and rounding.
2157c478bd9Sstevel@tonic-gate  */
2167c478bd9Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
2177c478bd9Sstevel@tonic-gate #define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate /*
2207c478bd9Sstevel@tonic-gate  * Macro to determine if value is a power of 2
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate #define	ISP2(x)		(((x) & ((x) - 1)) == 0)
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate /*
2257c478bd9Sstevel@tonic-gate  * Macros for various sorts of alignment and rounding when the alignment
2267c478bd9Sstevel@tonic-gate  * is known to be a power of 2.
2277c478bd9Sstevel@tonic-gate  */
2287c478bd9Sstevel@tonic-gate #define	P2ALIGN(x, align)		((x) & -(align))
2297c478bd9Sstevel@tonic-gate #define	P2PHASE(x, align)		((x) & ((align) - 1))
2307c478bd9Sstevel@tonic-gate #define	P2NPHASE(x, align)		(-(x) & ((align) - 1))
2317c478bd9Sstevel@tonic-gate #define	P2ROUNDUP(x, align)		(-(-(x) & -(align)))
2327c478bd9Sstevel@tonic-gate #define	P2END(x, align)			(-(~(x) & -(align)))
2337c478bd9Sstevel@tonic-gate #define	P2PHASEUP(x, align, phase)	((phase) - (((phase) - (x)) & -(align)))
2347c478bd9Sstevel@tonic-gate #define	P2CROSS(x, y, align)		(((x) ^ (y)) > (align) - 1)
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * Determine whether two numbers have the same high-order bit.
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate #define	P2SAMEHIGHBIT(x, y)		(((x) ^ (y)) < ((x) & (y)))
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate  * Typed version of the P2* macros.  These macros should be used to ensure
2427c478bd9Sstevel@tonic-gate  * that the result is correctly calculated based on the data type of (x),
2437c478bd9Sstevel@tonic-gate  * which is passed in as the last argument, regardless of the data
2447c478bd9Sstevel@tonic-gate  * type of the alignment.  For example, if (x) is of type uint64_t,
2457c478bd9Sstevel@tonic-gate  * and we want to round it up to a page boundary using "PAGESIZE" as
2467c478bd9Sstevel@tonic-gate  * the alignment, we can do either
2477c478bd9Sstevel@tonic-gate  *	P2ROUNDUP(x, (uint64_t)PAGESIZE)
2487c478bd9Sstevel@tonic-gate  * or
2497c478bd9Sstevel@tonic-gate  *	P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
2507c478bd9Sstevel@tonic-gate  */
2517c478bd9Sstevel@tonic-gate #define	P2ALIGN_TYPED(x, align, type)	\
2527c478bd9Sstevel@tonic-gate 	((type)(x) & -(type)(align))
2537c478bd9Sstevel@tonic-gate #define	P2PHASE_TYPED(x, align, type)	\
2547c478bd9Sstevel@tonic-gate 	((type)(x) & ((type)(align) - 1))
2557c478bd9Sstevel@tonic-gate #define	P2NPHASE_TYPED(x, align, type)	\
2567c478bd9Sstevel@tonic-gate 	(-(type)(x) & ((type)(align) - 1))
2577c478bd9Sstevel@tonic-gate #define	P2ROUNDUP_TYPED(x, align, type)	\
2587c478bd9Sstevel@tonic-gate 	(-(-(type)(x) & -(type)(align)))
2597c478bd9Sstevel@tonic-gate #define	P2END_TYPED(x, align, type)	\
2607c478bd9Sstevel@tonic-gate 	(-(~(type)(x) & -(type)(align)))
2617c478bd9Sstevel@tonic-gate #define	P2PHASEUP_TYPED(x, align, phase, type)	\
2627c478bd9Sstevel@tonic-gate 	((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
2637c478bd9Sstevel@tonic-gate #define	P2CROSS_TYPED(x, y, align, type)	\
2647c478bd9Sstevel@tonic-gate 	(((type)(x) ^ (type)(y)) > (type)(align) - 1)
2657c478bd9Sstevel@tonic-gate #define	P2SAMEHIGHBIT_TYPED(x, y, type) \
2667c478bd9Sstevel@tonic-gate 	(((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate  * Macros to atomically increment/decrement a variable.  mutex and var
2707c478bd9Sstevel@tonic-gate  * must be pointers.
2717c478bd9Sstevel@tonic-gate  */
2727c478bd9Sstevel@tonic-gate #define	INCR_COUNT(var, mutex) mutex_enter(mutex), (*(var))++, mutex_exit(mutex)
2737c478bd9Sstevel@tonic-gate #define	DECR_COUNT(var, mutex) mutex_enter(mutex), (*(var))--, mutex_exit(mutex)
2747c478bd9Sstevel@tonic-gate 
275*2c32020fSeschrock /*
276*2c32020fSeschrock  * Macros to declare bitfields - the order in the parameter list is
277*2c32020fSeschrock  * Low to High - that is, declare bit 0 first.  We only support 8-bit bitfields
278*2c32020fSeschrock  * because if a field crosses a byte boundary it's not likely to be meaningful
279*2c32020fSeschrock  * without reassembly in its nonnative endianness.
280*2c32020fSeschrock  */
281*2c32020fSeschrock #if defined(_BIT_FIELDS_LTOH)
282*2c32020fSeschrock #define	DECL_BITFIELD2(_a, _b)				\
283*2c32020fSeschrock 	uint8_t _a, _b
284*2c32020fSeschrock #define	DECL_BITFIELD3(_a, _b, _c)			\
285*2c32020fSeschrock 	uint8_t _a, _b, _c
286*2c32020fSeschrock #define	DECL_BITFIELD4(_a, _b, _c, _d)			\
287*2c32020fSeschrock 	uint8_t _a, _b, _c, _d
288*2c32020fSeschrock #define	DECL_BITFIELD5(_a, _b, _c, _d, _e)		\
289*2c32020fSeschrock 	uint8_t _a, _b, _c, _d, _e
290*2c32020fSeschrock #define	DECL_BITFIELD6(_a, _b, _c, _d, _e, _f)		\
291*2c32020fSeschrock 	uint8_t _a, _b, _c, _d, _e, _f
292*2c32020fSeschrock #define	DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g)	\
293*2c32020fSeschrock 	uint8_t _a, _b, _c, _d, _e, _f, _g
294*2c32020fSeschrock #define	DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h)	\
295*2c32020fSeschrock 	uint8_t _a, _b, _c, _d, _e, _f, _g, _h
296*2c32020fSeschrock #elif defined(_BIT_FIELDS_HTOL)
297*2c32020fSeschrock #define	DECL_BITFIELD2(_a, _b)				\
298*2c32020fSeschrock 	uint8_t _b, _a
299*2c32020fSeschrock #define	DECL_BITFIELD3(_a, _b, _c)			\
300*2c32020fSeschrock 	uint8_t _c, _b, _a
301*2c32020fSeschrock #define	DECL_BITFIELD4(_a, _b, _c, _d)			\
302*2c32020fSeschrock 	uint8_t _d, _c, _b, _a
303*2c32020fSeschrock #define	DECL_BITFIELD5(_a, _b, _c, _d, _e)		\
304*2c32020fSeschrock 	uint8_t _e, _d, _c, _b, _a
305*2c32020fSeschrock #define	DECL_BITFIELD6(_a, _b, _c, _d, _e, _f)		\
306*2c32020fSeschrock 	uint8_t _f, _e, _d, _c, _b, _a
307*2c32020fSeschrock #define	DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g)	\
308*2c32020fSeschrock 	uint8_t _g, _f, _e, _d, _c, _b, _a
309*2c32020fSeschrock #define	DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h)	\
310*2c32020fSeschrock 	uint8_t _h, _g, _f, _e, _d, _c, _b, _a
311*2c32020fSeschrock #else
312*2c32020fSeschrock #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
313*2c32020fSeschrock #endif  /* _BIT_FIELDS_LTOH */
314*2c32020fSeschrock 
3157c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate /* avoid any possibility of clashing with <stddef.h> version */
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate #define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
3207c478bd9Sstevel@tonic-gate #endif
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3237c478bd9Sstevel@tonic-gate }
3247c478bd9Sstevel@tonic-gate #endif
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate #endif	/* _SYS_SYSMACROS_H */
327