Skip to content

Commit b42d763

Browse files
zongboxpalmer-dabbelt
authored andcommitted
riscv: add macro to get instruction length
Extract the calculation of instruction length for common use. Signed-off-by: Zong Li <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent d27c3c9 commit b42d763

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

arch/riscv/include/asm/bug.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
#define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
2020
#define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
2121

22+
#define GET_INSN_LENGTH(insn) \
23+
({ \
24+
unsigned long __len; \
25+
__len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
26+
4UL : 2UL; \
27+
__len; \
28+
})
29+
2230
typedef u32 bug_insn_t;
2331

2432
#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS

arch/riscv/kernel/traps.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ static inline unsigned long get_break_insn_length(unsigned long pc)
118118

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

124125
asmlinkage __visible void do_trap_break(struct pt_regs *regs)

0 commit comments

Comments
 (0)