powerpc: Add NULLIFY_GPRS macros for register clears
PATCH v2 9/14 powerpc: Add NULLIFY_GPRS macros for register clears
Macros for restoring and saving registers to and from the stack exist. Provide macros with the same interface for clearing a range of gprs by setting each register's value in that range to zero.
The resulting macros are called NULLIFY_GPRS and NULLIFY_NVGPRS, keeping with the naming of the accompanying restore and save macros, and usage of nullify to describe this operation elsewhere in the kernel.
---
V1 -> V2: Change 'ZERO' usage in naming to 'NULLIFY', a more obvious verb
--- arch/powerpc/include/asm/ppc_asm.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
arch/powerpc/include/asm/ppc_asm.h +22 -0
@@ -33,6 +33,20 @@ .endr .endm +/* + * This expands to a sequence of register clears for regs start to end + * inclusive, of the form: + * + * li rN, 0 + */ +.macro NULLIFY_REGS start, end + .Lreg=\start + .rept (\end - \start + 1) + li .Lreg,0 + .Lreg=.Lreg+1 + .endr +.endm +/* * Macros for storing registers into and loading registers from * exception frames.
@@ -49,6 +63,14 @@#define REST_NVGPRS (base) REST_GPRS(13, 31, base)#endif +#define NULLIFY_GPRS (start, end) NULLIFY_REGS start, end +#ifdef __powerpc64__ +#define NULLIFY_NVGPRS () NULLIFY_GPRS(14, 31) +#else +#define NULLIFY_NVGPRS () NULLIFY_GPRS(13, 31) +#endif +#define NULLIFY_GPR (n) NULLIFY_GPRS(n, n) +#define SAVE_GPR (n, base) SAVE_GPRS(n, n, base)#define REST_GPR (n, base) REST_GPRS(n, n, base)
Signature · 1 line
2.34.1
Quoted 12 lines · Rohan McLure
Macros for restoring and saving registers to and from the stack exist.
Provide macros with the same interface for clearing a range of gprs by
setting each register's value in that range to zero.The resulting macros are called
NULLIFY_GPRSandNULLIFY_NVGPRS, keeping
with the naming of the accompanying restore and save macros, and usage
of nullify to describe this operation elsewhere in the kernel.
Quoted 4 lines
Signed-off-by Rohan McLure <[email protected]>---
V1 -> V2: Change 'ZERO' usage in naming to 'NULLIFY', a more obvious verb
And I see you've addressed my comment re 32 v 64 bit from V1 as well.
Quoted 20 lines
---
arch/powerpc/include/asm/ppc_asm.h | 22 ++++++++++++++++++++++1 file changed, 22 insertions(+)arch/powerpc/include/asm/ppc_asm.h +0
-0@@ -33,6 +33,20 @@.endr
.endm
+/*
+ * This expands to a sequence of register clears for regs start to end
+ * inclusive, of the form:
+ *
+ * li rN, 0
+ */
Quoted 8 lines
+.macro
NULLIFY_REGSstart, end
+ .Lreg=\start
+ .rept (\end - \start + 1)
+ li .Lreg, 0
+ .Lreg=.Lreg+1
+ .endr
+.endm
+
I suppose this could be done using the existing OP_REGS macro, something like OP_REGS li, 0, start, end, 0, 0 - but a load immediate is semantically a bit different from the existing uses of OP_REGS so I don't mind either way
Quoted 19 lines
/*
* Macros for storing registers into and loading registers from
* exception frames.arch/powerpc/include/asm/ppc_asm.h +0
-0@@ -49,6 +63,14 @@ #define REST_NVGPRS(base) REST_GPRS(13, 31, base) #endif
+#define NULLIFY_GPRS(start, end) NULLIFY_REGS start, endarch/powerpc/include/asm/ppc_asm.h +7
-0+#ifdef __powerpc64__ +#define NULLIFY_NVGPRS() NULLIFY_GPRS(14, 31) +#else +#define NULLIFY_NVGPRS() NULLIFY_GPRS(13, 31) +#endif +#define NULLIFY_GPR(n) NULLIFY_GPRS(n, n) +#define
SAVE_GPR(n, base)SAVE_GPRS(n, n, base) #defineREST_GPR(n, base)REST_GPRS(n, n, base)
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Le 08/08/2022 à 09:42, Andrew Donnellan a écrit :
Quoted 47 lines · Rohan McLure
Quoted 12 lines
Macros for restoring and saving registers to and from the stack exist.
Provide macros with the same interface for clearing a range of gprs by
setting each register's value in that range to zero.The resulting macros are called
NULLIFY_GPRSandNULLIFY_NVGPRS, keeping
with the naming of the accompanying restore and save macros, and usage
of nullify to describe this operation elsewhere in the kernel.Quoted 4 lines
Signed-off-by Rohan McLure <[email protected]>---
V1 -> V2: Change 'ZERO' usage in naming to 'NULLIFY', a more obvious verbAnd I see you've addressed my comment re 32 v 64 bit from V1 as well.
Reviewed-by Andrew Donnellan <[email protected]>Quoted 25 lines
--- arch/powerpc/include/asm/ppc_asm.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)arch/powerpc/include/asm/ppc_asm.h +2
-0@@ -33,6 +33,20 @@ .endr .endm +/* +* This expands to a sequence of register clears for regs start to end
+ * inclusive, of the form:
+ *
+ * li rN, 0
+ */
+.macroNULLIFY_REGSstart, end
+ .Lreg=\start
+ .rept (\end - \start + 1)
+ li .Lreg, 0
+ .Lreg=.Lreg+1
Quoted 8 lines
Quoted 3 lines
+ .endr
+.endm
+I suppose this could be done using the existing
OP_REGSmacro, something likeOP_REGSli, 0, start, end, 0, 0 - but a load immediate is semantically a bit different from the existing uses ofOP_REGSso I don't mind either way
Not sure it would work. You'd get:
li .Lreg, 0 + 0 * .Lreg(0)
Even if it works that would be odd.
Quoted 21 lines
Quoted 20 lines
/*
* Macros for storing registers into and loading registers from
* exception frames.arch/powerpc/include/asm/ppc_asm.h +1
-0@@ -49,6 +63,14 @@ #define REST_NVGPRS(base) REST_GPRS(13, 31, base) #endif +#define NULLIFY_GPRS(start, end) NULLIFY_REGS start,end
arch/powerpc/include/asm/ppc_asm.h +7
-0+#ifdef __powerpc64__ +#define NULLIFY_NVGPRS() NULLIFY_GPRS(14, 31) +#else +#define NULLIFY_NVGPRS() NULLIFY_GPRS(13, 31) +#endif +#define NULLIFY_GPR(n) NULLIFY_GPRS(n, n) + #define SAVE_GPR(n, base) SAVE_GPRS(n, n, base) #define REST_GPR(n, base) REST_GPRS(n, n, base)