endian.h revision 4fd606d1f5abe38e1f42c38de1d2e895166bd0f4
/** @file
Byte order related definitions and declarations.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available
under the terms and conditions of the BSD License that accompanies this
distribution. The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Copyright (c) 1990, 1993
The Regents of the University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
- Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
NetBSD: endian.h,v 1.24 2006/05/05 15:08:11 christos Exp
endian.h 8.1 (Berkeley) 6/11/93
**/
#ifndef _SYS_ENDIAN_H_
#define _SYS_ENDIAN_H_
#include <sys/EfiCdefs.h>
/*
* Definitions for byte order, according to byte significance from low
* address to high.
*/
#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
#ifndef _LOCORE
/* C-family endian-ness definitions */
#ifndef in_addr_t
typedef __in_addr_t in_addr_t;
#define in_addr_t __in_addr_t
#endif
#ifndef in_port_t
typedef __in_port_t in_port_t;
#define in_port_t __in_port_t
#endif
#endif /* !_LOCORE */
#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
#include <machine/endian_machdep.h>
/*
* Define the order of 32-bit words in 64-bit words.
*/
#if _BYTE_ORDER == _LITTLE_ENDIAN
#define _QUAD_HIGHWORD 1
#define _QUAD_LOWWORD 0
#endif
#if _BYTE_ORDER == _BIG_ENDIAN
#define _QUAD_HIGHWORD 0
#define _QUAD_LOWWORD 1
#endif
#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
/*
* Traditional names for byteorder. These are defined as the numeric
* sequences so that third party code can "#define XXX_ENDIAN" and not
* cause errors.
*/
#define BYTE_ORDER _BYTE_ORDER
#ifndef _LOCORE
/*
*/
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define htons(x) (x)
#define NTOHL(x) (void) (x)
#define NTOHS(x) (void) (x)
#define HTONL(x) (void) (x)
#define HTONS(x) (void) (x)
#else /* LITTLE_ENDIAN || !defined(__lint__) */
#endif /* LITTLE_ENDIAN || !defined(__lint__) */
/*
* Macros to convert to a specific endianness.
*/
#if BYTE_ORDER == BIG_ENDIAN
#define htobe16(x) (x)
#define htobe32(x) (x)
#define htobe64(x) (x)
#define HTOBE16(x) (void) (x)
#define HTOBE32(x) (void) (x)
#define HTOBE64(x) (void) (x)
#else /* LITTLE_ENDIAN */
#define htole16(x) (x)
#define htole32(x) (x)
#define htole64(x) (x)
#define HTOLE16(x) (void) (x)
#define HTOLE32(x) (void) (x)
#define HTOLE64(x) (void) (x)
#endif /* LITTLE_ENDIAN */
/*
*/
{
}
{
p[0] = (uint8_t)(u & 0xff);
}
{
return ((p[0] << 8) | p[1]);
}
{
return ((p[1] << 8) | p[0]);
}
{
}
{
p[0] = (uint8_t)(u & 0xff);
}
{
return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
}
{
return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]);
}
{
}
{
}
{
}
{
}
#endif /* !_LOCORE */
#endif /* _XOPEN_SOURCE || _NETBSD_SOURCE */
#endif /* !_SYS_ENDIAN_H_ */