From: Jens Remus The range check macro turns cryptic assembler errors into an easy to understand error if e.g. someone mistypes an input value in an asm macro. Add an asm macro that verifies that a given input value is in a specific range. Add macros which check for ranges often used when creating instructions. While at it, add a range check for the register numbers in the GR_NUM and VX_NUM macro. Signed-off-by: Jens Remus Signed-off-by: Steffen Eiden --- arch/s390/include/asm/insn-common-asm.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/s390/include/asm/insn-common-asm.h b/arch/s390/include/asm/insn-common-asm.h index fd9b3cacb7c5..f3f10f2c92bb 100644 --- a/arch/s390/include/asm/insn-common-asm.h +++ b/arch/s390/include/asm/insn-common-asm.h @@ -9,6 +9,32 @@ #ifdef __ASSEMBLER__ +.macro RANGECHECK min max val + .if (\val < \min) || (\val > \max) + .error "operand out of range (\val is not between \min and \max)" + .endif +.endm + +.macro ASSERT_U16 val + RANGECHECK 0, 65535, \val +.endm + +.macro ASSERT_S16 val + RANGECHECK -32768, 32767, \val +.endm + +.macro ASSERT_U8 val + RANGECHECK 0, 255, \val +.endm + +.macro ASSERT_U4 val + RANGECHECK 0, 15, \val +.endm + +.macro ASSERT_U5 val + RANGECHECK 0, 31, \val +.endm + /* * GR_NUM - Retrieve general-purpose register number * @@ -24,6 +50,7 @@ .endr .if \opd == 255 \opd = \gr + ASSERT_U4 \opd .endif .endm @@ -46,6 +73,7 @@ .endr .if \opd == 255 \opd = \vxr + ASSERT_U5 \opd .endif .endm -- 2.56.1