1 /* ===-- endianness.h - configuration header for libgcc replacement --------===
2  *
3  *		       The LLVM Compiler Infrastructure
4  *
5  * This file is dual licensed under the MIT and the University of Illinois Open
6  * Source Licenses. See LICENSE.TXT for details.
7  *
8  * ===----------------------------------------------------------------------===
9  *
10  * This file is a configuration header for libgcc replacement.
11  * This file is not part of the interface of this library.
12  *
13  * ===----------------------------------------------------------------------===
14  */
15 
16 #ifndef ENDIANNESS_H
17 #define ENDIANNESS_H
18 
19 /*
20  * Known limitations:
21  *   Middle endian systems are not handled currently.
22  */
23 
24 #if defined(__SVR4) && defined(__sun)
25 #include <sys/byteorder.h>
26 
27 #if _BYTE_ORDER == _BIG_ENDIAN
28 #define _YUGA_LITTLE_ENDIAN 0
29 #define _YUGA_BIG_ENDIAN    1
30 #elif _BYTE_ORDER == _LITTLE_ENDIAN
31 #define _YUGA_LITTLE_ENDIAN 1
32 #define _YUGA_BIG_ENDIAN    0
33 #endif /* _BYTE_ORDER */
34 
35 #endif /* Solaris and AuroraUX. */
36 
37 /* .. */
38 
39 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonflyBSD__) || defined(__minix)
40 #include <sys/endian.h>
41 
42 #if _BYTE_ORDER == _BIG_ENDIAN
43 #define _YUGA_LITTLE_ENDIAN 0
44 #define _YUGA_BIG_ENDIAN    1
45 #elif _BYTE_ORDER == _LITTLE_ENDIAN
46 #define _YUGA_LITTLE_ENDIAN 1
47 #define _YUGA_BIG_ENDIAN    0
48 #endif /* _BYTE_ORDER */
49 
50 #endif /* *BSD */
51 
52 /* .. */
53 
54 #if defined(__OpenBSD__) || defined(__Bitrig__)
55 #include <machine/endian.h>
56 
57 #if _BYTE_ORDER == _BIG_ENDIAN
58 #define _YUGA_LITTLE_ENDIAN 0
59 #define _YUGA_BIG_ENDIAN    1
60 #elif _BYTE_ORDER == _LITTLE_ENDIAN
61 #define _YUGA_LITTLE_ENDIAN 1
62 #define _YUGA_BIG_ENDIAN    0
63 #endif /* _BYTE_ORDER */
64 
65 #endif /* OpenBSD and Bitrig. */
66 
67 /* .. */
68 
69 /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */
70 #if defined(__APPLE__) && defined(__MACH__) || defined(__ellcc__ )
71 
72 #ifdef __BIG_ENDIAN__
73 #if __BIG_ENDIAN__
74 #define _YUGA_LITTLE_ENDIAN 0
75 #define _YUGA_BIG_ENDIAN    1
76 #endif
77 #endif /* __BIG_ENDIAN__ */
78 
79 #ifdef __LITTLE_ENDIAN__
80 #if __LITTLE_ENDIAN__
81 #define _YUGA_LITTLE_ENDIAN 1
82 #define _YUGA_BIG_ENDIAN    0
83 #endif
84 #endif /* __LITTLE_ENDIAN__ */
85 
86 #endif /* Mac OSX */
87 
88 /* .. */
89 
90 #if defined(__linux__)
91 #include <endian.h>
92 
93 #if __BYTE_ORDER == __BIG_ENDIAN
94 #define _YUGA_LITTLE_ENDIAN 0
95 #define _YUGA_BIG_ENDIAN    1
96 #elif __BYTE_ORDER == __LITTLE_ENDIAN
97 #define _YUGA_LITTLE_ENDIAN 1
98 #define _YUGA_BIG_ENDIAN    0
99 #endif /* __BYTE_ORDER */
100 
101 #endif /* GNU/Linux */
102 
103 /* . */
104 
105 #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN)
106 #error Unable to determine endian
107 #endif /* Check we found an endianness correctly. */
108 
109 #endif /* ENDIANNESS_H */
110