18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * arch/arm/include/asm/byteorder.h 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * ARM Endian-ness. In little endian mode, the data bus is connected such 68c2ecf20Sopenharmony_ci * that byte accesses appear as: 78c2ecf20Sopenharmony_ci * 0 = d0...d7, 1 = d8...d15, 2 = d16...d23, 3 = d24...d31 88c2ecf20Sopenharmony_ci * and word accesses (data or instruction) appear as: 98c2ecf20Sopenharmony_ci * d0...d31 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * When in big endian mode, byte accesses appear as: 128c2ecf20Sopenharmony_ci * 0 = d24...d31, 1 = d16...d23, 2 = d8...d15, 3 = d0...d7 138c2ecf20Sopenharmony_ci * and word accesses (data or instruction) appear as: 148c2ecf20Sopenharmony_ci * d0...d31 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci#ifndef _UAPI__ASM_ARM_SWAB_H 178c2ecf20Sopenharmony_ci#define _UAPI__ASM_ARM_SWAB_H 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <linux/compiler.h> 208c2ecf20Sopenharmony_ci#include <linux/types.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#if !defined(__STRICT_ANSI__) || defined(__KERNEL__) 238c2ecf20Sopenharmony_ci# define __SWAB_64_THRU_32__ 248c2ecf20Sopenharmony_ci#endif 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#if !defined(__KERNEL__) || __LINUX_ARM_ARCH__ < 6 288c2ecf20Sopenharmony_cistatic inline __attribute_const__ __u32 __arch_swab32(__u32 x) 298c2ecf20Sopenharmony_ci{ 308c2ecf20Sopenharmony_ci __u32 t; 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#ifndef __thumb__ 338c2ecf20Sopenharmony_ci if (!__builtin_constant_p(x)) { 348c2ecf20Sopenharmony_ci /* 358c2ecf20Sopenharmony_ci * The compiler needs a bit of a hint here to always do the 368c2ecf20Sopenharmony_ci * right thing and not screw it up to different degrees 378c2ecf20Sopenharmony_ci * depending on the gcc version. 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_ci asm ("eor\t%0, %1, %1, ror #16" : "=r" (t) : "r" (x)); 408c2ecf20Sopenharmony_ci } else 418c2ecf20Sopenharmony_ci#endif 428c2ecf20Sopenharmony_ci t = x ^ ((x << 16) | (x >> 16)); /* eor r1,r0,r0,ror #16 */ 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci x = (x << 24) | (x >> 8); /* mov r0,r0,ror #8 */ 458c2ecf20Sopenharmony_ci t &= ~0x00FF0000; /* bic r1,r1,#0x00FF0000 */ 468c2ecf20Sopenharmony_ci x ^= (t >> 8); /* eor r0,r0,r1,lsr #8 */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci return x; 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci#define __arch_swab32 __arch_swab32 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#endif 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#endif /* _UAPI__ASM_ARM_SWAB_H */ 55