OSDN Git Service

riscv: add macro to get instruction length
authorZong Li <zong.li@sifive.com>
Mon, 9 Mar 2020 16:55:42 +0000 (00:55 +0800)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Thu, 26 Mar 2020 16:24:49 +0000 (09:24 -0700)
Extract the calculation of instruction length for common use.

Signed-off-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
arch/riscv/include/asm/bug.h
arch/riscv/kernel/traps.c

index 75604fe..d6f1ec0 100644 (file)
 #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
index ffb3d94..a4d1363 100644 (file)
@@ -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)