1 /* @(#)btorder.h	1.22 12/12/03 Copyright 1996-2012 J. Schilling */
2 /*
3  *	Definitions for Bit and Byte ordering
4  *
5  *	Copyright (c) 1996-2012 J. Schilling
6  */
7 /*
8  * The contents of this file are subject to the terms of the
9  * Common Development and Distribution License, Version 1.0 only
10  * (the "License").  You may not use this file except in compliance
11  * with the License.
12  *
13  * See the file CDDL.Schily.txt in this distribution for details.
14  * A copy of the CDDL is also available via the Internet at
15  * http://www.opensource.org/licenses/cddl1.txt
16  *
17  * When distributing Covered Code, include this CDDL HEADER in each
18  * file and include the License file CDDL.Schily.txt from this distribution.
19  */
20 
21 
22 #ifndef	_SCHILY_BTORDER_H
23 #define	_SCHILY_BTORDER_H
24 
25 #ifndef _SCHILY_MCONFIG_H
26 #include <schily/mconfig.h>		/* load bit/byte-oder from xmconfig.h */
27 #endif
28 
29 #ifndef	_SCHILY_TYPES_H
30 #include <schily/types.h>		/* try to load isa_defs.h on Solaris */
31 #endif
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * Convert bit-order definitions from xconfig.h into our values
39  * and verify them.
40  */
41 #if defined(HAVE_C_BITFIELDS)	&& \
42     defined(BITFIELDS_LTOH)
43 #define	_BIT_FIELDS_LTOH
44 #endif
45 
46 #if defined(HAVE_C_BITFIELDS)	&& \
47     defined(BITFIELDS_HTOL)
48 #define	_BIT_FIELDS_HTOL
49 #endif
50 
51 #if defined(HAVE_C_BITFIELDS) && \
52 	!defined(BITFIELDS_HTOL)
53 #define	BITFIELDS_LTOH
54 #define	_BIT_FIELDS_LTOH
55 #endif
56 
57 #if	defined(_BIT_FIELDS_LTOH) && defined(_BIT_FIELDS_HTOL)
58 /*
59  * #error will not work for all compilers (e.g. sunos4)
60  * The following line will abort compilation on all compilers
61  * if none of the above is defined. And that's  what we want.
62  */
63 error  Only one of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL may be defined
64 
65 #include <schily/err_bit.h>	/* Avoid "unknown directive" with K&R */
66 #endif
67 
68 
69 /*
70  * Convert byte-order definitions from xconfig.h into our values
71  * and verify them.
72  * Note that we cannot use the definitions _LITTLE_ENDIAN and _BIG_ENDIAN
73  * because they are used on IRIX-6.5 with different meaning.
74  */
75 #if defined(HAVE_C_BIGENDIAN) && \
76 	!defined(WORDS_BIGENDIAN)
77 #define	WORDS_LITTLEENDIAN
78 /* #define	_LITTLE_ENDIAN */
79 #endif
80 
81 #if defined(HAVE_C_BIGENDIAN)	&& \
82     defined(WORDS_BIGENDIAN)
83 #undef	WORDS_LITTLEENDIAN
84 /* #define	_BIG_ENDIAN */
85 #endif
86 
87 #if	defined(_BIT_FIELDS_LTOH) || defined(_BIT_FIELDS_HTOL)
88 /*
89  * Bitorder is already known.
90  */
91 #else
92 /*
93  * Bitorder not yet known.
94  */
95 #	if defined(sun3) || defined(mc68000) || \
96 	    defined(sun4) || defined(__sparc) || defined(sparc) || \
97 	    defined(__hppa) || defined(_ARCH_PPC) || defined(_IBMR2)
98 #		define _BIT_FIELDS_HTOL
99 #	endif
100 
101 #	if defined(__sgi) && defined(__mips)
102 #		define _BIT_FIELDS_HTOL
103 #	endif
104 
105 #	if defined(__i386__) || defined(__i386) || defined(i386) || \
106 	    defined(__alpha__) || defined(__alpha) || defined(alpha) || \
107 	    defined(__arm__) || defined(__arm) || defined(arm)
108 #		define _BIT_FIELDS_LTOH
109 #	endif
110 
111 #	if defined(__ppc__) || defined(ppc) || defined(__ppc) || \
112 	    defined(__PPC) || defined(powerpc) || defined(__powerpc__)
113 
114 #		if	defined(__BIG_ENDIAN__)
115 #			define _BIT_FIELDS_HTOL
116 #		else
117 #			define _BIT_FIELDS_LTOH
118 #		endif
119 #	endif
120 #endif
121 
122 #ifdef	__cplusplus
123 }
124 #endif
125 
126 #endif	/* _SCHILY_BTORDER_H */
127