[PATCH 1/3] ARM: assembler: generalize byte swapping macro into rev_32

Ard Biesheuvel ardb at kernel.org
Wed Dec 9 05:36:32 EST 2020


Take the 4 instruction byte swapping sequence from the decompressor's
head.S, and turn it into a rev_32 GAS macro for general use. While
at it, make it use the 'rev' instruction when compiling for v6 or
later.

Signed-off-by: Ard Biesheuvel <ardb at kernel.org>
---
 arch/arm/boot/compressed/head.S  |  5 +----
 arch/arm/include/asm/assembler.h | 11 +++++++++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 804d66668019..d70c78ab68c8 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -174,10 +174,7 @@
 		.macro	be32tocpu, val, tmp
 #ifndef __ARMEB__
 		/* convert to little endian */
-		eor	\tmp, \val, \val, ror #16
-		bic	\tmp, \tmp, #0x00ff0000
-		mov	\val, \val, ror #8
-		eor	\val, \val, \tmp, lsr #8
+		rev_32	\val, \tmp
 #endif
 		.endm
 
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 6ed30421f697..a674eba4cd27 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -578,4 +578,15 @@ THUMB(	orr	\reg , \reg , #PSR_T_BIT	)
 	__adldst_l	str, \src, \sym, \tmp, \cond
 	.endm
 
+	.macro		rev_32, val:req, tmp:req
+	.if		__LINUX_ARM_ARCH__ < 6
+	eor		\tmp, \val, \val, ror #16
+	bic		\tmp, \tmp, #0x00ff0000
+	mov		\val, \val, ror #8
+	eor		\val, \val, \tmp, lsr #8
+	.else
+	rev		\val, \val
+	.endif
+	.endm
+
 #endif /* __ASM_ASSEMBLER_H__ */
-- 
2.17.1




More information about the linux-arm-kernel mailing list