blob: e34872fcb4d36ab4b72539eff7703933f51b2991 [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
36/* NOTE: header <machine/cpu-features.h> could not be included directly
37 * since it defines extra macros, such as PLD.
38 */
39#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || \
40 defined(__ARM_ARCH_7__) || \
41 defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
42 defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || \
43 defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__)
44
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.
53 */
54#ifdef __thumb__
55#define REV_LO_REG asm("r4")
56#else
57#define REV_LO_REG
58#endif
59
60#define __swap16md(x) ({ \
61 register u_int16_t _x REV_LO_REG = (x); \
62 __asm volatile ("rev16 %0, %0" : "+r" (_x)); \
63 _x; \
64})
65
66#define __swap32md(x) ({ \
67 register u_int32_t _x REV_LO_REG = (x); \
68 __asm volatile ("rev %0, %0" : "+r" (_x)); \
69 _x; \
70})
71
72#define __swap64md(x) ({ \
73 u_int64_t _x = (x); \
74 (u_int64_t) __swap32md(_x >> 32) | \
75 (u_int64_t) __swap32md(_x & 0xffffffff) << 32; \
76})
77
78/* Tell sys/endian.h we have MD variants of the swap macros. */
79#define MD_SWAP
80
81#endif /* __ARM_ARCH__ */
82#endif /* __GNUC__ */
83
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080084#ifdef __ARMEB__
85#define _BYTE_ORDER _BIG_ENDIAN
86#else
87#define _BYTE_ORDER _LITTLE_ENDIAN
88#endif
89#define __STRICT_ALIGNMENT
90#include <sys/types.h>
91#include <sys/endian.h>
Jim Huangaa350952010-08-31 14:51:44 +080092
93#endif /* !_ARM_ENDIAN_H_ */