Subject: [PATCH 1/6] powerpc: Add ZERO_GPRS macros for register clears

From: Rohan McLure <[email-masked]>
Date: Wed, 1 Jun 2022 15:48:45 +1000

Macros for restoring saving registers to and from the stack exist.
Provide a macro for simply zeroing a range of gprs, or an individual
gpr.

Signed-off-by: Rohan McLure <[email-masked]>
---
 arch/powerpc/include/asm/ppc_asm.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
index 4dea2d963738..3fb37a9767f7 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -33,6 +33,19 @@
 	.endr
 .endm
 
+/*
+ * Simplification of OP_REGS, for an arbitrary right hand operand.
+ *
+ *   op  reg, rhs
+ */
+.macro BINOP_REGS op, rhs, start, end
+	.Lreg=\start
+	.rept (\end - \start + 1)
+	\op .Lreg, \rhs
+	.Lreg=.Lreg+1
+	.endr
+.endm
+
 /*
  * Macros for storing registers into and loading registers from
  * exception frames.
@@ -49,6 +62,10 @@
 #define REST_NVGPRS(base)		REST_GPRS(13, 31, base)
 #endif
 
+#define ZERO_GPRS(start, end)		BINOP_REGS li, 0, start, end
+#define ZERO_NVGPRS()			ZERO_GPRS(14, 31)
+#define ZERO_GPR(n)			ZERO_GPRS(n, n)
+
 #define SAVE_GPR(n, base)		SAVE_GPRS(n, n, base)
 #define REST_GPR(n, base)		REST_GPRS(n, n, base)
 
-- 
2.34.1