From 6e2071019a5684581fd5765adcbeeb92c04fa4a8 Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Tue, 12 Mar 2024 09:58:28 +0100 Subject: [PATCH] fix sparc compiler warning: "__BYTE_ORDER__" is not defined and "__ORDER_LITTLE_ENDIAN__" is not defined --- lib/common/byteorder.h | 24 +++++++++++++++++++----- lib/common/cmp_data_types.c | 4 ++-- lib/rdcu_compress/rdcu_ctrl.c | 16 ++++++++++------ lib/rdcu_compress/rdcu_rmap.c | 8 ++++---- lib/rdcu_compress/rmap.h | 5 +++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/lib/common/byteorder.h b/lib/common/byteorder.h index 4b58a45..634e184 100644 --- a/lib/common/byteorder.h +++ b/lib/common/byteorder.h @@ -53,16 +53,30 @@ #undef __LITTLE_ENDIAN #endif -#if defined(__sparc__) #ifndef __BIG_ENDIAN -#define __BIG_ENDIAN 4321 -#endif +# if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +# define __BIG_ENDIAN 4321 +# elif defined(__clang__) && __BIG_ENDIAN__ +# define __BIG_ENDIAN 4321 +# elif defined(__sparc__) +# define __BIG_ENDIAN 4321 +# endif #endif -#if defined(__i386__) || defined(__x86_64__) #ifndef __LITTLE_ENDIAN -#define __LITTLE_ENDIAN 1234 +# if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +# define __LITTLE_ENDIAN 1234 +# elif defined(__clang__) && __LITTLE_ENDIAN__ +# define __LITTLE_ENDIAN 1234 +# elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86) +# define __LITTLE_ENDIAN 1234 +# elif defined(__i386__) || defined(__x86_64__) +# define __LITTLE_ENDIAN 1234 +# endif #endif + +#if defined(__BIG_ENDIAN) == defined(__LITTLE_ENDIAN) +#error "Unknown byte order!" #endif diff --git a/lib/common/cmp_data_types.c b/lib/common/cmp_data_types.c index bba86c8..f548702 100644 --- a/lib/common/cmp_data_types.c +++ b/lib/common/cmp_data_types.c @@ -885,7 +885,7 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type } samples = data_size_byte / sample_size; -#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#ifdef __LITTLE_ENDIAN switch (data_type) { case DATA_TYPE_IMAGETTE: case DATA_TYPE_IMAGETTE_ADAPTIVE: @@ -949,7 +949,7 @@ int be_to_cpu_data_type(void *data, uint32_t data_size_byte, enum cmp_data_type return -1; /* LCOV_EXCL_STOP */ } -#endif /*__BYTE_ORDER__ */ +#endif /* __LITTLE_ENDIAN */ return 0; } diff --git a/lib/rdcu_compress/rdcu_ctrl.c b/lib/rdcu_compress/rdcu_ctrl.c index 0c23b5b..c5d748e 100644 --- a/lib/rdcu_compress/rdcu_ctrl.c +++ b/lib/rdcu_compress/rdcu_ctrl.c @@ -1653,9 +1653,9 @@ int rdcu_write_sram_16(const uint16_t *buf, uint32_t addr, uint32_t size) if (addr + size > RDCU_SRAM_START + RDCU_SRAM_SIZE) return -1; -#if !(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#ifdef __BIG_ENDIAN return rdcu_write_sram(buf, addr, size); -#else +#elif defined(__LITTLE_ENDIAN) { uint32_t i; @@ -1666,7 +1666,9 @@ int rdcu_write_sram_16(const uint16_t *buf, uint32_t addr, uint32_t size) } } return (int)size; /* lol */ -#endif /* __BYTE_ORDER__ */ +#else +#error "Unknown byte order!" +#endif } @@ -1699,9 +1701,9 @@ int rdcu_write_sram_32(const uint32_t *buf, uint32_t addr, uint32_t size) if (addr + size > RDCU_SRAM_START + RDCU_SRAM_SIZE) return -1; -#if !(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#ifdef __BIG_ENDIAN return rdcu_write_sram(buf, addr, size); -#else +#elif defined(__LITTLE_ENDIAN) { uint32_t i; @@ -1712,7 +1714,9 @@ int rdcu_write_sram_32(const uint32_t *buf, uint32_t addr, uint32_t size) } } return (int)size; /* lol */ -#endif /* __BYTE_ORDER__ */ +#else +#error "Unknown byte order!" +#endif } diff --git a/lib/rdcu_compress/rdcu_rmap.c b/lib/rdcu_compress/rdcu_rmap.c index 7a740e8..dc7c71a 100644 --- a/lib/rdcu_compress/rdcu_rmap.c +++ b/lib/rdcu_compress/rdcu_rmap.c @@ -292,7 +292,7 @@ static int rdcu_process_rx(void) uint8_t crc8; /* convert endianness in-place if needed */ -#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#ifdef __LITTLE_ENDIAN { uint32_t i, tmp; @@ -302,7 +302,7 @@ static int rdcu_process_rx(void) memcpy(&rp->data[i], &tmp, sizeof(tmp)); } } -#endif /* __BYTE_ORDER__ */ +#endif /* __LITTLE_ENDIAN */ crc8 = rmap_crc8(rp->data, rp->data_len); if (crc8 != rp->data_crc) { @@ -471,7 +471,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd), } /* convert endianness if needed */ -#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#ifdef __LITTLE_ENDIAN if (data_len) { uint32_t i; uint32_t *tmp_buf = alloca(data_len); @@ -482,7 +482,7 @@ int rdcu_sync(int (*fn)(uint16_t trans_id, uint8_t *cmd), addr = tmp_buf; } -#endif /* __BYTE_ORDER__ */ +#endif /* __LITTLE_ENDIAN */ n = rdcu_submit_tx(rmap_cmd, (uint32_t)n, addr, data_len); free(rmap_cmd); diff --git a/lib/rdcu_compress/rmap.h b/lib/rdcu_compress/rmap.h index 3dde009..9c21780 100644 --- a/lib/rdcu_compress/rmap.h +++ b/lib/rdcu_compress/rmap.h @@ -23,6 +23,7 @@ #include <stddef.h> #include "../common/compiler.h" +#include "../common/byteorder.h" /** * valid RMAP command codes, see Table 5-1 of ECSS‐E‐ST‐50‐52C @@ -142,12 +143,12 @@ __extension__ struct rmap_instruction { -#if (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#ifdef __BIG_ENDIAN uint8_t reserved:1; uint8_t cmd_resp:1; uint8_t cmd:4; uint8_t reply_addr_len:2; -#elif (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#elif defined (__LITTLE_ENDIAN) uint8_t reply_addr_len:2; uint8_t cmd:4; uint8_t cmd_resp:1; -- GitLab