From a00a788156e4d4b8d9f48d46802324210ff01e33 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 10 Mar 2021 17:26:04 -0500 Subject: [PATCH] Fix #1217, locally define BIG/LITTLE order macros In a future version OSAL "common_types.h" will no longer provide the bit/byte order macros. This puts the same determination logic directly in cfe_endian.h. Same basic issues still present, just now confined to CFE, and put in a localized header that should be only used by code with an actual endianness dependency, rather than a ubiquitous header that is used everywhere. --- modules/core_api/fsw/inc/cfe_endian.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/core_api/fsw/inc/cfe_endian.h b/modules/core_api/fsw/inc/cfe_endian.h index fd425c40a..6b120dab7 100644 --- a/modules/core_api/fsw/inc/cfe_endian.h +++ b/modules/core_api/fsw/inc/cfe_endian.h @@ -34,6 +34,30 @@ */ #include "common_types.h" +/* + * SOFTWARE_BIG/LITTLE_BIT_ORDER COMPATIBILITY MACRO - + * + * This is provided only for backward compatibilty. Do not write any new code that + * uses this macro. + */ +#if !defined(SOFTWARE_BIG_BIT_ORDER) && !defined(SOFTWARE_LITTLE_BIT_ORDER) + +#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || defined(__BIG_ENDIAN__) || defined(__ARMEB__) || \ + defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) +/* It is a big-endian target architecture */ +#define SOFTWARE_BIG_BIT_ORDER +#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || \ + defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || \ + defined(__i386) || defined(__i386__) || defined(__i686) || defined(__i686__) || defined(__x86_64) || \ + defined(__x86_64__) +/* It is a little-endian target architecture */ +#define SOFTWARE_LITTLE_BIT_ORDER +#else +#error Unknown byte order on this platform +#endif + +#endif /* !defined(SOFTWARE_BIG_BIT_ORDER) && !defined(SOFTWARE_LITTLE_BIT_ORDER) */ + /* Macro to convert 16/32 bit types from platform "endianness" to Big Endian */ #ifdef SOFTWARE_BIG_BIT_ORDER #define CFE_MAKE_BIG16(n) (n)