2020-04-08 08:00:02

by Zong Li

[permalink] [raw]
Subject: [PATCH v5 1/9] riscv: add macro to get instruction length

Extract the calculation of instruction length for common use.

Signed-off-by: Zong Li <[email protected]>
---
arch/riscv/include/asm/bug.h | 8 ++++++++
arch/riscv/kernel/traps.c | 3 ++-
2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
index 75604fec1b1b..d6f1ec08d97b 100644
--- a/arch/riscv/include/asm/bug.h
+++ b/arch/riscv/include/asm/bug.h
@@ -19,6 +19,14 @@
#define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
#define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */

+#define GET_INSN_LENGTH(insn) \
+({ \
+ unsigned long __len; \
+ __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
+ 4UL : 2UL; \
+ __len; \
+})
+
typedef u32 bug_insn_t;

#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
index ffb3d94bf0cc..a4d136355f78 100644
--- a/arch/riscv/kernel/traps.c
+++ b/arch/riscv/kernel/traps.c
@@ -118,7 +118,8 @@ static inline unsigned long get_break_insn_length(unsigned long pc)

if (probe_kernel_address((bug_insn_t *)pc, insn))
return 0;
- return (((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? 4UL : 2UL);
+
+ return GET_INSN_LENGTH(insn);
}

asmlinkage __visible void do_trap_break(struct pt_regs *regs)
--
2.26.0


2020-04-18 00:24:09

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH v5 1/9] riscv: add macro to get instruction length

On Wed, 08 Apr 2020 00:56:56 PDT (-0700), [email protected] wrote:
> Extract the calculation of instruction length for common use.
>
> Signed-off-by: Zong Li <[email protected]>
> ---
> arch/riscv/include/asm/bug.h | 8 ++++++++
> arch/riscv/kernel/traps.c | 3 ++-
> 2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/include/asm/bug.h b/arch/riscv/include/asm/bug.h
> index 75604fec1b1b..d6f1ec08d97b 100644
> --- a/arch/riscv/include/asm/bug.h
> +++ b/arch/riscv/include/asm/bug.h
> @@ -19,6 +19,14 @@
> #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
> #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
>
> +#define GET_INSN_LENGTH(insn) \
> +({ \
> + unsigned long __len; \
> + __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
> + 4UL : 2UL; \
> + __len; \
> +})
> +
> typedef u32 bug_insn_t;
>
> #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
> diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c
> index ffb3d94bf0cc..a4d136355f78 100644
> --- a/arch/riscv/kernel/traps.c
> +++ b/arch/riscv/kernel/traps.c
> @@ -118,7 +118,8 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
>
> if (probe_kernel_address((bug_insn_t *)pc, insn))
> return 0;
> - return (((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? 4UL : 2UL);
> +
> + return GET_INSN_LENGTH(insn);
> }
>
> asmlinkage __visible void do_trap_break(struct pt_regs *regs)

Reviewed-by: Palmer Dabbelt <[email protected]>