1 /*	$OpenBSD: rf_general.h,v 1.6 2003/04/27 11:22:54 ho Exp $	*/
2 /*	$NetBSD: rf_general.h,v 1.5 2000/03/03 02:04:48 oster Exp $	*/
3 
4 /*
5  * Copyright (c) 1995 Carnegie-Mellon University.
6  * All rights reserved.
7  *
8  * Author: Mark Holland
9  *
10  * Permission to use, copy, modify and distribute this software and
11  * its documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  *
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  *
20  * Carnegie Mellon requests users of this software to return to
21  *
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  *
27  * any improvements or extensions that they make and grant Carnegie the
28  * rights to redistribute these changes.
29  */
30 
31 /*
32  * rf_general.h -- Some general-use definitions.
33  */
34 
35 /*#define NOASSERT*/
36 
37 #ifndef	_RF__RF_GENERAL_H_
38 #define	_RF__RF_GENERAL_H_
39 
40 /* Error reporting and handling. */
41 
42 #ifdef	_KERNEL
43 #include <sys/systm.h>		/* printf, snprintf, and friends. */
44 #endif
45 
46 #define	RF_ERRORMSG(s)		printf((s))
47 #define	RF_ERRORMSG1(s,a)	printf((s), (a))
48 #define	RF_ERRORMSG2(s,a,b)	printf((s), (a), (b))
49 #define	RF_ERRORMSG3(s,a,b,c)	printf((s), (a), (b), (c))
50 
51 extern char rf_panicbuf[2048];
52 #define	RF_PANIC()							\
53 do {									\
54 	snprintf(rf_panicbuf, sizeof rf_panicbuf,			\
55 	    "RAIDframe error at line %d file %s",			\
56 	    __LINE__, __FILE__);					\
57 	panic(rf_panicbuf);						\
58 } while (0)
59 
60 #ifdef	_KERNEL
61 #ifdef	RF_ASSERT
62 #undef	RF_ASSERT
63 #endif	/* RF_ASSERT */
64 #ifndef	NOASSERT
65 #define	RF_ASSERT(_x_)							\
66 do {									\
67 	if (!(_x_)) {							\
68 		snprintf(rf_panicbuf, sizeof rf_panicbuf,		\
69 		    "RAIDframe error at line %d"			\
70 		    " file %s (failed asserting %s)\n", __LINE__,	\
71 		     __FILE__, #_x_);					\
72 		panic(rf_panicbuf);					\
73 	}								\
74 } while (0)
75 #else	/* !NOASSERT */
76 #define	RF_ASSERT(x)		{/*noop*/}
77 #endif	/* !NOASSERT */
78 #else	/* _KERNEL */
79 #define	RF_ASSERT(x)		{/*noop*/}
80 #endif	/* _KERNEL */
81 
82 /* Random stuff. */
83 #define	RF_MAX(a,b)		(((a) > (b)) ? (a) : (b))
84 #define	RF_MIN(a,b)		(((a) < (b)) ? (a) : (b))
85 
86 /* Divide-by-zero check. */
87 #define	RF_DB0_CHECK(a,b)	(((b)==0) ? 0 : (a)/(b))
88 
89 /* Get time of day. */
90 #define	RF_GETTIME(_t)		microtime(&(_t))
91 
92 /*
93  * Zero memory - Not all bzero calls go through here, only
94  * those which in the kernel may have a user address.
95  */
96 
97 #define	RF_BZERO(_bp,_b,_l)	bzero(_b, _l)	/*
98 						 * XXX This is likely
99 						 * incorrect. GO
100 						 */
101 
102 #define	RF_UL(x)		((unsigned long)(x))
103 #define	RF_PGMASK		RF_UL(NBPG-1)
104 #define	RF_BLIP(x)		(NBPG - (RF_UL(x) & RF_PGMASK))	/*
105 								 * Bytes left
106 								 * in page.
107 								 */
108 #define	RF_PAGE_ALIGNED(x)	((RF_UL(x) & RF_PGMASK) == 0)
109 
110 #ifdef	__STDC__
111 #define	RF_STRING(_str_)	#_str_
112 #else	/* __STDC__ */
113 #define	RF_STRING(_str_)	"_str_"
114 #endif	/* __STDC__ */
115 
116 #endif	/* !_RF__RF_GENERAL_H_ */
117