Changeset 868cd24d in rtems


Ignore:
Timestamp:
Apr 19, 2016, 8:22:06 AM (4 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
dfcc8bb
Parents:
cb2651d
git-author:
Sebastian Huber <sebastian.huber@…> (04/19/16 08:22:06)
git-committer:
Sebastian Huber <sebastian.huber@…> (05/30/16 06:11:39)
Message:

score: Use Newlib provided <machine/endian.h>

Location:
cpukit/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/endian.h

    rcb2651d r868cd24d  
    99#define _RTEMS_ENDIAN_H
    1010
    11 #include <rtems/score/cpu.h>
     11#include <stdint.h>
    1212
    13 /*
    14  * BSD-style endian declaration
    15  */
    16 #define BIG_ENDIAN      4321
    17 #define LITTLE_ENDIAN   1234
     13#include <machine/endian.h>
    1814
    19 #ifndef BYTE_ORDER
    20 #if CPU_BIG_ENDIAN
    21 # define BYTE_ORDER BIG_ENDIAN
    22 #elif CPU_LITTLE_ENDIAN
    23 # define BYTE_ORDER LITTLE_ENDIAN
    24 #else
    25 # error "Can't decide which end is which!"
     15#ifndef _BYTEORDER_FUNC_DEFINED
     16#define _BYTEORDER_FUNC_DEFINED
     17#define htonl(x)        __htonl(x)
     18#define htons(x)        __htons(x)
     19#define ntohl(x)        __ntohl(x)
     20#define ntohs(x)        __ntohs(x)
    2621#endif
    27 #endif
    28 
    29 #if ( CPU_BIG_ENDIAN == TRUE )
    30 
    31 /*
    32  *  Very simply on big endian CPUs
    33  */
    34 
    35 static inline uint32_t ntohl( uint32_t _x )
    36 {
    37   return _x;
    38 }
    39 
    40 static inline uint16_t ntohs( uint16_t _x )
    41 {
    42   return _x;
    43 }
    44 
    45 static inline uint32_t htonl( uint32_t _x )
    46 {
    47   return _x;
    48 }
    49 
    50 static inline uint16_t htons( uint16_t _x )
    51 {
    52   return _x;
    53 }
    54 
    55 #define NTOHS(x)
    56 #define HTONS(x)
    57 #define NTOHL(x)
    58 #define HTONL(x)
    59 
    60 #elif ( CPU_LITTLE_ENDIAN == TRUE )
    61 
    62 /*
    63  *  A little more complicated on little endian CPUs
    64  */
    65 
    66 static inline uint32_t ntohl( uint32_t _x )
    67 {
    68   return CPU_swap_u32(_x);
    69 }
    70 
    71 static inline uint16_t ntohs( uint16_t _x )
    72 {
    73   return CPU_swap_u16(_x);
    74 }
    75 
    76 static inline uint32_t htonl( uint32_t _x )
    77 {
    78   return CPU_swap_u32(_x);
    79 }
    80 
    81 static inline uint16_t htons( uint16_t _x )
    82 {
    83   return CPU_swap_u16(_x);
    84 }
    8522
    8623#define NTOHS(x) (x) = ntohs(x)
     
    8825#define NTOHL(x) (x) = ntohl(x)
    8926#define HTONL(x) (x) = htonl(x)
    90 
    91 #else
    92 #error "Unknown endian-ness for this cpu"
    93 #endif
    9427
    9528static inline uint16_t rtems_uint16_from_little_endian( const uint8_t *data)
  • cpukit/include/sys/endian.h

    rcb2651d r868cd24d  
    3131
    3232#include <sys/cdefs.h>
    33 #include <rtems/endian.h>
     33#include <sys/_types.h>
     34#include <machine/endian.h>
     35
     36#ifndef _UINT8_T_DECLARED
     37typedef __uint8_t       uint8_t;
     38#define _UINT8_T_DECLARED
     39#endif
     40 
     41#ifndef _UINT16_T_DECLARED
     42typedef __uint16_t      uint16_t;
     43#define _UINT16_T_DECLARED
     44#endif
     45 
     46#ifndef _UINT32_T_DECLARED
     47typedef __uint32_t      uint32_t;
     48#define _UINT32_T_DECLARED
     49#endif
     50 
     51#ifndef _UINT64_T_DECLARED
     52typedef __uint64_t      uint64_t;
     53#define _UINT64_T_DECLARED
     54#endif
    3455 
    3556/*
    3657 * General byte order swapping functions.
    3758 */
    38 #define bswap16(x)      CPU_swap_u16(x)
    39 #define bswap32(x)      CPU_swap_u32(x)
    40 static __inline uint64_t
    41 bswap64(uint64_t v)
    42 {
    43 #ifdef __GNUC__
    44         return __builtin_bswap64(v);
    45 #else
    46         return ((v >> 56) | ((v >> 40) & 0xff00) | ((v >> 24) & 0xff0000) |
    47             ((v >> 8) & 0xff000000) | ((v << 8) & ((uint64_t)0xff << 32)) |
    48             ((v << 24) & ((uint64_t)0xff << 40)) |
    49             ((v << 40) & ((uint64_t)0xff << 48)) | ((v << 56)));
    50 #endif
    51 }
     59#define bswap16(x)      __bswap16(x)
     60#define bswap32(x)      __bswap32(x)
     61#define bswap64(x)      __bswap64(x)
    5262
    5363/*
     
    5565 * endian to host byte order functions as detailed in byteorder(9).
    5666 */
    57 #if BYTE_ORDER == LITTLE_ENDIAN
     67#if _BYTE_ORDER == _LITTLE_ENDIAN
    5868#define htobe16(x)      bswap16((x))
    5969#define htobe32(x)      bswap32((x))
     
    6979#define le32toh(x)      ((uint32_t)(x))
    7080#define le64toh(x)      ((uint64_t)(x))
    71 #else /* BYTE_ORDER != LITTLE_ENDIAN */
     81#else /* _BYTE_ORDER != _LITTLE_ENDIAN */
    7282#define htobe16(x)      ((uint16_t)(x))
    7383#define htobe32(x)      ((uint32_t)(x))
     
    8393#define le32toh(x)      bswap32((x))
    8494#define le64toh(x)      bswap64((x))
    85 #endif /* BYTE_ORDER == LITTLE_ENDIAN */
     95#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
    8696
    8797/* Alignment-agnostic encode/decode bytestream to/from little/big endian. */
Note: See TracChangeset for help on using the changeset viewer.