Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 1 | /* ===-- endianness.h - configuration header for libgcc replacement --------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
| 5 | * This file is distributed under the University of Illinois Open Source |
| 6 | * License. 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 | |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 19 | /* |
| 20 | * Known limitations: |
| 21 | * Middle endian systems are not handled currently. |
| 22 | */ |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 23 | |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 24 | #if defined(__SVR4) && defined(__sun) |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 25 | #include <sys/byteorder.h> |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 26 | |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 27 | #if _BYTE_ORDER == _BIG_ENDIAN |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 28 | #define _YUGA_LITTLE_ENDIAN 0 |
| 29 | #define _YUGA_BIG_ENDIAN 1 |
| 30 | #elif _BYTE_ORDER == _LITTLE_ENDIAN |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 31 | #define _YUGA_LITTLE_ENDIAN 1 |
| 32 | #define _YUGA_BIG_ENDIAN 0 |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 33 | #endif /* _BYTE_ORDER */ |
| 34 | |
| 35 | #endif /* Solaris and AuroraUX. */ |
| 36 | |
| 37 | /* .. */ |
| 38 | |
| 39 | #if defined(__FreeBSD__) && defined(__NetBSD__) && defined(__OpenBSD__) && defined(__DragonflyBSD__) |
| 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 | /* Mac OSX has __BIG_ENDIAN__ or __LITTLE_ENDIAN__ automatically set by the compiler (at least with GCC) */ |
| 55 | #if defined(__APPLE__) && defined(__MACH__) |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 56 | |
| 57 | #ifdef __BIG_ENDIAN__ |
| 58 | #if __BIG_ENDIAN__ |
| 59 | #define _YUGA_LITTLE_ENDIAN 0 |
| 60 | #define _YUGA_BIG_ENDIAN 1 |
| 61 | #endif |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 62 | #endif /* __BIG_ENDIAN__ */ |
| 63 | |
| 64 | #ifdef __LITTLE_ENDIAN__ |
| 65 | #if __LITTLE_ENDIAN__ |
| 66 | #define _YUGA_LITTLE_ENDIAN 1 |
| 67 | #define _YUGA_BIG_ENDIAN 0 |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 68 | #endif |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 69 | #endif /* __LITTLE_ENDIAN__ */ |
| 70 | |
| 71 | #endif /* Mac OSX */ |
| 72 | |
| 73 | /* .. */ |
| 74 | |
Nuno Lopes | 166b783 | 2009-08-09 18:59:21 +0000 | [diff] [blame^] | 75 | #if defined(__linux__) |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 76 | #include <endian.h> |
| 77 | |
| 78 | #if __BYTE_ORDER == __BIG_ENDIAN |
| 79 | #define _YUGA_LITTLE_ENDIAN 0 |
| 80 | #define _YUGA_BIG_ENDIAN 1 |
| 81 | #elif __BYTE_ORDER == __LITTLE_ENDIAN |
| 82 | #define _YUGA_LITTLE_ENDIAN 1 |
| 83 | #define _YUGA_BIG_ENDIAN 0 |
| 84 | #endif /* __BYTE_ORDER */ |
| 85 | |
| 86 | #endif /* GNU/Linux */ |
| 87 | |
| 88 | /* . */ |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 89 | |
| 90 | #if !defined(_YUGA_LITTLE_ENDIAN) || !defined(_YUGA_BIG_ENDIAN) |
Edward O'Callaghan | bb119a4 | 2009-08-08 02:31:50 +0000 | [diff] [blame] | 91 | #error Unable to determine endian |
| 92 | #endif /* Check we found an endianness correctly. */ |
Edward O'Callaghan | 1fcb40b | 2009-08-05 19:06:50 +0000 | [diff] [blame] | 93 | |
| 94 | #endif /* ENDIANNESS_H */ |