16f52b16cSGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2cb8db5d4SDavid Howells /*
3cb8db5d4SDavid Howells * arch/arm/include/asm/byteorder.h
4cb8db5d4SDavid Howells *
5cb8db5d4SDavid Howells * ARM Endian-ness. In little endian mode, the data bus is connected such
6cb8db5d4SDavid Howells * that byte accesses appear as:
7cb8db5d4SDavid Howells * 0 = d0...d7, 1 = d8...d15, 2 = d16...d23, 3 = d24...d31
8cb8db5d4SDavid Howells * and word accesses (data or instruction) appear as:
9cb8db5d4SDavid Howells * d0...d31
10cb8db5d4SDavid Howells *
11cb8db5d4SDavid Howells * When in big endian mode, byte accesses appear as:
12cb8db5d4SDavid Howells * 0 = d24...d31, 1 = d16...d23, 2 = d8...d15, 3 = d0...d7
13cb8db5d4SDavid Howells * and word accesses (data or instruction) appear as:
14cb8db5d4SDavid Howells * d0...d31
15cb8db5d4SDavid Howells */
16cb8db5d4SDavid Howells #ifndef _UAPI__ASM_ARM_SWAB_H
17cb8db5d4SDavid Howells #define _UAPI__ASM_ARM_SWAB_H
18cb8db5d4SDavid Howells
19cb8db5d4SDavid Howells #include <linux/compiler.h>
20cb8db5d4SDavid Howells #include <linux/types.h>
21cb8db5d4SDavid Howells
22cb8db5d4SDavid Howells #if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
23cb8db5d4SDavid Howells # define __SWAB_64_THRU_32__
24cb8db5d4SDavid Howells #endif
25cb8db5d4SDavid Howells
26cb8db5d4SDavid Howells
27cb8db5d4SDavid Howells #if !defined(__KERNEL__) || __LINUX_ARM_ARCH__ < 6
__arch_swab32(__u32 x)28cb8db5d4SDavid Howells static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
29cb8db5d4SDavid Howells {
30cb8db5d4SDavid Howells __u32 t;
31cb8db5d4SDavid Howells
32cb8db5d4SDavid Howells #ifndef __thumb__
33cb8db5d4SDavid Howells if (!__builtin_constant_p(x)) {
34cb8db5d4SDavid Howells /*
35cb8db5d4SDavid Howells * The compiler needs a bit of a hint here to always do the
36cb8db5d4SDavid Howells * right thing and not screw it up to different degrees
37cb8db5d4SDavid Howells * depending on the gcc version.
38cb8db5d4SDavid Howells */
39cb8db5d4SDavid Howells asm ("eor\t%0, %1, %1, ror #16" : "=r" (t) : "r" (x));
40cb8db5d4SDavid Howells } else
41cb8db5d4SDavid Howells #endif
42cb8db5d4SDavid Howells t = x ^ ((x << 16) | (x >> 16)); /* eor r1,r0,r0,ror #16 */
43cb8db5d4SDavid Howells
44cb8db5d4SDavid Howells x = (x << 24) | (x >> 8); /* mov r0,r0,ror #8 */
45cb8db5d4SDavid Howells t &= ~0x00FF0000; /* bic r1,r1,#0x00FF0000 */
46cb8db5d4SDavid Howells x ^= (t >> 8); /* eor r0,r0,r1,lsr #8 */
47cb8db5d4SDavid Howells
48cb8db5d4SDavid Howells return x;
49cb8db5d4SDavid Howells }
50cb8db5d4SDavid Howells #define __arch_swab32 __arch_swab32
51cb8db5d4SDavid Howells
52cb8db5d4SDavid Howells #endif
53cb8db5d4SDavid Howells
54cb8db5d4SDavid Howells #endif /* _UAPI__ASM_ARM_SWAB_H */
55