/*
|
/*
|
* $Id: endian.h,v 1.2 2001-09-27 12:01:53 chris Exp $
|
* $Id: endian.h,v 1.2 2001-09-27 12:01:53 chris Exp $
|
*/
|
*/
|
|
|
#ifndef _MACHINE_ENDIAN_H_
|
#ifndef _MACHINE_ENDIAN_H_
|
#define _MACHINE_ENDIAN_H_
|
#define _MACHINE_ENDIAN_H_
|
|
|
#include <rtems/score/cpu.h>
|
#include <rtems/score/cpu.h>
|
|
|
/*
|
/*
|
* BSD-style endian declaration
|
* BSD-style endian declaration
|
*/
|
*/
|
#define BIG_ENDIAN 4321
|
#define BIG_ENDIAN 4321
|
#define LITTLE_ENDIAN 1234
|
#define LITTLE_ENDIAN 1234
|
|
|
#if CPU_BIG_ENDIAN
|
#if CPU_BIG_ENDIAN
|
# define BYTE_ORDER BIG_ENDIAN
|
# define BYTE_ORDER BIG_ENDIAN
|
#elif CPU_LITTLE_ENDIAN
|
#elif CPU_LITTLE_ENDIAN
|
# define BYTE_ORDER LITTLE_ENDIAN
|
# define BYTE_ORDER LITTLE_ENDIAN
|
#else
|
#else
|
# error "Can't decide which end is which!"
|
# error "Can't decide which end is which!"
|
#endif
|
#endif
|
|
|
#if ( CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES == FALSE )
|
#if ( CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES == FALSE )
|
|
|
#if ( CPU_BIG_ENDIAN == TRUE )
|
#if ( CPU_BIG_ENDIAN == TRUE )
|
|
|
/*
|
/*
|
* Very simply on big endian CPUs
|
* Very simply on big endian CPUs
|
*/
|
*/
|
|
|
#define ntohl(_x) (_x)
|
#define ntohl(_x) (_x)
|
#define ntohs(_x) (_x)
|
#define ntohs(_x) (_x)
|
#define htonl(_x) (_x)
|
#define htonl(_x) (_x)
|
#define htons(_x) (_x)
|
#define htons(_x) (_x)
|
|
|
#define NTOHS(x)
|
#define NTOHS(x)
|
#define HTONS(x)
|
#define HTONS(x)
|
#define NTOHL(x)
|
#define NTOHL(x)
|
#define HTONL(x)
|
#define HTONL(x)
|
|
|
#elif ( CPU_LITTLE_ENDIAN == TRUE )
|
#elif ( CPU_LITTLE_ENDIAN == TRUE )
|
|
|
/*
|
/*
|
* A little more complicated on little endian CPUs
|
* A little more complicated on little endian CPUs
|
*/
|
*/
|
|
|
#define ntohl(_x) ((long) CPU_swap_u32((unsigned32)_x))
|
#define ntohl(_x) ((long) CPU_swap_u32((unsigned32)_x))
|
#define ntohs(_x) ((short) CPU_swap_u16((unsigned16)_x))
|
#define ntohs(_x) ((short) CPU_swap_u16((unsigned16)_x))
|
#define htonl(_x) ((long) CPU_swap_u32((unsigned32)_x))
|
#define htonl(_x) ((long) CPU_swap_u32((unsigned32)_x))
|
#define htons(_x) ((short) CPU_swap_u16((unsigned16)_x))
|
#define htons(_x) ((short) CPU_swap_u16((unsigned16)_x))
|
|
|
#define NTOHS(x) (x) = ntohs(x)
|
#define NTOHS(x) (x) = ntohs(x)
|
#define HTONS(x) (x) = htons(x)
|
#define HTONS(x) (x) = htons(x)
|
#define NTOHL(x) (x) = ntohl(x)
|
#define NTOHL(x) (x) = ntohl(x)
|
#define HTONL(x) (x) = htonl(x)
|
#define HTONL(x) (x) = htonl(x)
|
|
|
#else
|
#else
|
#error "Unknown endian-ness for this cpu"
|
#error "Unknown endian-ness for this cpu"
|
#endif
|
#endif
|
|
|
#endif /* CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES */
|
#endif /* CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES */
|
|
|
#endif /* _MACHINE_ENDIAN_H_ */
|
#endif /* _MACHINE_ENDIAN_H_ */
|
|
|