blob: 8d9723d7a85c0aa075c5501078b2ce3051c91d72 [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
Jim Huangaa350952010-08-31 14:51:44 +080036/* According to RealView Assembler User's Guide, REV and REV16 are available
37 * in Thumb code and 16-bit instructions when used in Thumb-2 code.
38 *
39 * REV Rd, Rm
40 * Rd and Rm must both be Lo registers.
41 *
42 * REV16 Rd, Rm
43 * Rd and Rm must both be Lo registers.
Elliott Hughes3cf53d12010-09-24 17:55:58 -070044 *
45 * The +l constraint takes care of this without constraining us in ARM mode.
Jim Huangaa350952010-08-31 14:51:44 +080046 */
Elliott Hughes3cf53d12010-09-24 17:55:58 -070047#define __swap16md(x) ({ \
48 register u_int16_t _x = (x); \
Elliott Hughesc54ca402013-12-13 12:17:13 -080049 __asm__ __volatile__("rev16 %0, %0" : "+l" (_x)); \
Elliott Hughes3cf53d12010-09-24 17:55:58 -070050 _x; \
Jim Huangaa350952010-08-31 14:51:44 +080051})
52
Elliott Hughes3cf53d12010-09-24 17:55:58 -070053#define __swap32md(x) ({ \
54 register u_int32_t _x = (x); \
Elliott Hughesc54ca402013-12-13 12:17:13 -080055 __asm__ __volatile__("rev %0, %0" : "+l" (_x)); \
Elliott Hughes3cf53d12010-09-24 17:55:58 -070056 _x; \
Jim Huangaa350952010-08-31 14:51:44 +080057})
58
Elliott Hughes3cf53d12010-09-24 17:55:58 -070059#define __swap64md(x) ({ \
60 u_int64_t _swap64md_x = (x); \
61 (u_int64_t) __swap32md(_swap64md_x >> 32) | \
62 (u_int64_t) __swap32md(_swap64md_x & 0xffffffff) << 32; \
Jim Huangaa350952010-08-31 14:51:44 +080063})
64
65/* Tell sys/endian.h we have MD variants of the swap macros. */
66#define MD_SWAP
67
Elliott Hughes3cf53d12010-09-24 17:55:58 -070068#endif /* __GNUC__ */
Jim Huangaa350952010-08-31 14:51:44 +080069
Elliott Hughesb15c58b2012-11-27 14:18:04 -080070#if defined(__ARMEB__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080071#define _BYTE_ORDER _BIG_ENDIAN
72#else
73#define _BYTE_ORDER _LITTLE_ENDIAN
74#endif
Elliott Hughes3cf53d12010-09-24 17:55:58 -070075#define __STRICT_ALIGNMENT
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080076#include <sys/types.h>
77#include <sys/endian.h>
Jim Huangaa350952010-08-31 14:51:44 +080078
Elliott Hughes3cf53d12010-09-24 17:55:58 -070079#endif /* !_ARM_ENDIAN_H_ */