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