blob: 6de0889ef1ea24473c7d354d456b10e1ef232779 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/* $OpenBSD: endian.h,v 1.3 2005/12/13 00:35:23 millert Exp $ */
2
Jim Huangaa350952010-08-31 14:51:44 +08003/*
4 * Copyright (C) 2010 The Android Open Source Project
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#ifndef _ARM_ENDIAN_H_
32#define _ARM_ENDIAN_H_
33
34#ifdef __GNUC__
35
Elliott Hughes3cf53d12010-09-24 17:55:58 -070036/*
37 * REV and REV16 weren't available on ARM5 or ARM4.
38 * We don't include <machine/cpu-features.h> because it pollutes the
39 * namespace with macros like PLD.
Jim Huangaa350952010-08-31 14:51:44 +080040 */
Elliott Hughes3cf53d12010-09-24 17:55:58 -070041#if !defined __ARM_ARCH_5__ && !defined __ARM_ARCH_5T__ && \
42 !defined __ARM_ARCH_5TE__ && !defined __ARM_ARCH_5TEJ__ && \
43 !defined __ARM_ARCH_4T__ && !defined __ARM_ARCH_4__
Jim Huangaa350952010-08-31 14:51:44 +080044
45/* According to RealView Assembler User's Guide, REV and REV16 are available
46 * in Thumb code and 16-bit instructions when used in Thumb-2 code.
47 *
48 * REV Rd, Rm
49 * Rd and Rm must both be Lo registers.
50 *
51 * REV16 Rd, Rm
52 * Rd and Rm must both be Lo registers.
Elliott Hughes3cf53d12010-09-24 17:55:58 -070053 *
54 * The +l constraint takes care of this without constraining us in ARM mode.
Jim Huangaa350952010-08-31 14:51:44 +080055 */
Elliott Hughes3cf53d12010-09-24 17:55:58 -070056#define __swap16md(x) ({ \
57 register u_int16_t _x = (x); \
58 __asm volatile ("rev16 %0, %0" : "+l" (_x)); \
59 _x; \
Jim Huangaa350952010-08-31 14:51:44 +080060})
61
Elliott Hughes3cf53d12010-09-24 17:55:58 -070062#define __swap32md(x) ({ \
63 register u_int32_t _x = (x); \
64 __asm volatile ("rev %0, %0" : "+l" (_x)); \
65 _x; \
Jim Huangaa350952010-08-31 14:51:44 +080066})
67
Elliott Hughes3cf53d12010-09-24 17:55:58 -070068#define __swap64md(x) ({ \
69 u_int64_t _swap64md_x = (x); \
70 (u_int64_t) __swap32md(_swap64md_x >> 32) | \
71 (u_int64_t) __swap32md(_swap64md_x & 0xffffffff) << 32; \
Jim Huangaa350952010-08-31 14:51:44 +080072})
73
74/* Tell sys/endian.h we have MD variants of the swap macros. */
75#define MD_SWAP
76
Elliott Hughes3cf53d12010-09-24 17:55:58 -070077#endif /* __ARM_ARCH__ */
78#endif /* __GNUC__ */
Jim Huangaa350952010-08-31 14:51:44 +080079
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080080#ifdef __ARMEB__
81#define _BYTE_ORDER _BIG_ENDIAN
82#else
83#define _BYTE_ORDER _LITTLE_ENDIAN
84#endif
Elliott Hughes3cf53d12010-09-24 17:55:58 -070085#define __STRICT_ALIGNMENT
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080086#include <sys/types.h>
87#include <sys/endian.h>
Jim Huangaa350952010-08-31 14:51:44 +080088
Elliott Hughes3cf53d12010-09-24 17:55:58 -070089#endif /* !_ARM_ENDIAN_H_ */