summaryrefslogtreecommitdiffstats
path: root/cpukit/include
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-04-19 10:22:06 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-30 08:11:39 +0200
commit868cd24dcd149bc2871130d77f398f9202c5e6ff (patch)
treed2ce551d00af3968bc674c502cf179cd15fcf8f9 /cpukit/include
parentnetwork: Align with Newlib type definitions (diff)
downloadrtems-868cd24dcd149bc2871130d77f398f9202c5e6ff.tar.bz2
score: Use Newlib provided <machine/endian.h>
Diffstat (limited to 'cpukit/include')
-rw-r--r--cpukit/include/rtems/endian.h85
-rw-r--r--cpukit/include/sys/endian.h46
2 files changed, 37 insertions, 94 deletions
diff --git a/cpukit/include/rtems/endian.h b/cpukit/include/rtems/endian.h
index e6704779ac..802cc4bb91 100644
--- a/cpukit/include/rtems/endian.h
+++ b/cpukit/include/rtems/endian.h
@@ -8,90 +8,23 @@
#ifndef _RTEMS_ENDIAN_H
#define _RTEMS_ENDIAN_H
-#include <rtems/score/cpu.h>
+#include <stdint.h>
-/*
- * BSD-style endian declaration
- */
-#define BIG_ENDIAN 4321
-#define LITTLE_ENDIAN 1234
-
-#ifndef BYTE_ORDER
-#if CPU_BIG_ENDIAN
-# define BYTE_ORDER BIG_ENDIAN
-#elif CPU_LITTLE_ENDIAN
-# define BYTE_ORDER LITTLE_ENDIAN
-#else
-# error "Can't decide which end is which!"
-#endif
-#endif
-
-#if ( CPU_BIG_ENDIAN == TRUE )
-
-/*
- * Very simply on big endian CPUs
- */
-
-static inline uint32_t ntohl( uint32_t _x )
-{
- return _x;
-}
-
-static inline uint16_t ntohs( uint16_t _x )
-{
- return _x;
-}
-
-static inline uint32_t htonl( uint32_t _x )
-{
- return _x;
-}
-
-static inline uint16_t htons( uint16_t _x )
-{
- return _x;
-}
+#include <machine/endian.h>
-#define NTOHS(x)
-#define HTONS(x)
-#define NTOHL(x)
-#define HTONL(x)
-
-#elif ( CPU_LITTLE_ENDIAN == TRUE )
-
-/*
- * A little more complicated on little endian CPUs
- */
-
-static inline uint32_t ntohl( uint32_t _x )
-{
- return CPU_swap_u32(_x);
-}
-
-static inline uint16_t ntohs( uint16_t _x )
-{
- return CPU_swap_u16(_x);
-}
-
-static inline uint32_t htonl( uint32_t _x )
-{
- return CPU_swap_u32(_x);
-}
-
-static inline uint16_t htons( uint16_t _x )
-{
- return CPU_swap_u16(_x);
-}
+#ifndef _BYTEORDER_FUNC_DEFINED
+#define _BYTEORDER_FUNC_DEFINED
+#define htonl(x) __htonl(x)
+#define htons(x) __htons(x)
+#define ntohl(x) __ntohl(x)
+#define ntohs(x) __ntohs(x)
+#endif
#define NTOHS(x) (x) = ntohs(x)
#define HTONS(x) (x) = htons(x)
#define NTOHL(x) (x) = ntohl(x)
#define HTONL(x) (x) = htonl(x)
-#else
-#error "Unknown endian-ness for this cpu"
-#endif
-
static inline uint16_t rtems_uint16_from_little_endian( const uint8_t *data)
{
uint16_t value = 0;
diff --git a/cpukit/include/sys/endian.h b/cpukit/include/sys/endian.h
index b78d8c711a..f7efc5dac1 100644
--- a/cpukit/include/sys/endian.h
+++ b/cpukit/include/sys/endian.h
@@ -30,31 +30,41 @@
#define _SYS_ENDIAN_H_
#include <sys/cdefs.h>
-#include <rtems/endian.h>
+#include <sys/_types.h>
+#include <machine/endian.h>
+
+#ifndef _UINT8_T_DECLARED
+typedef __uint8_t uint8_t;
+#define _UINT8_T_DECLARED
+#endif
+
+#ifndef _UINT16_T_DECLARED
+typedef __uint16_t uint16_t;
+#define _UINT16_T_DECLARED
+#endif
+
+#ifndef _UINT32_T_DECLARED
+typedef __uint32_t uint32_t;
+#define _UINT32_T_DECLARED
+#endif
+
+#ifndef _UINT64_T_DECLARED
+typedef __uint64_t uint64_t;
+#define _UINT64_T_DECLARED
+#endif
/*
* General byte order swapping functions.
*/
-#define bswap16(x) CPU_swap_u16(x)
-#define bswap32(x) CPU_swap_u32(x)
-static __inline uint64_t
-bswap64(uint64_t v)
-{
-#ifdef __GNUC__
- return __builtin_bswap64(v);
-#else
- return ((v >> 56) | ((v >> 40) & 0xff00) | ((v >> 24) & 0xff0000) |
- ((v >> 8) & 0xff000000) | ((v << 8) & ((uint64_t)0xff << 32)) |
- ((v << 24) & ((uint64_t)0xff << 40)) |
- ((v << 40) & ((uint64_t)0xff << 48)) | ((v << 56)));
-#endif
-}
+#define bswap16(x) __bswap16(x)
+#define bswap32(x) __bswap32(x)
+#define bswap64(x) __bswap64(x)
/*
* Host to big endian, host to little endian, big endian to host, and little
* endian to host byte order functions as detailed in byteorder(9).
*/
-#if BYTE_ORDER == LITTLE_ENDIAN
+#if _BYTE_ORDER == _LITTLE_ENDIAN
#define htobe16(x) bswap16((x))
#define htobe32(x) bswap32((x))
#define htobe64(x) bswap64((x))
@@ -68,7 +78,7 @@ bswap64(uint64_t v)
#define le16toh(x) ((uint16_t)(x))
#define le32toh(x) ((uint32_t)(x))
#define le64toh(x) ((uint64_t)(x))
-#else /* BYTE_ORDER != LITTLE_ENDIAN */
+#else /* _BYTE_ORDER != _LITTLE_ENDIAN */
#define htobe16(x) ((uint16_t)(x))
#define htobe32(x) ((uint32_t)(x))
#define htobe64(x) ((uint64_t)(x))
@@ -82,7 +92,7 @@ bswap64(uint64_t v)
#define le16toh(x) bswap16((x))
#define le32toh(x) bswap32((x))
#define le64toh(x) bswap64((x))
-#endif /* BYTE_ORDER == LITTLE_ENDIAN */
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */