1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 Regents of the University of California
6 #ifndef _ASM_RISCV_BUG_H
7 #define _ASM_RISCV_BUG_H
9 #include <linux/compiler.h>
10 #include <linux/const.h>
11 #include <linux/types.h>
15 #define __INSN_LENGTH_MASK _UL(0x3)
16 #define __INSN_LENGTH_32 _UL(0x3)
17 #define __COMPRESSED_INSN_MASK _UL(0xffff)
19 #define __BUG_INSN_32 _UL(0x00100073) /* ebreak */
20 #define __BUG_INSN_16 _UL(0x9002) /* c.ebreak */
22 #define GET_INSN_LENGTH(insn) \
24 unsigned long __len; \
25 __len = ((insn & __INSN_LENGTH_MASK) == __INSN_LENGTH_32) ? \
30 typedef u32 bug_insn_t
;
32 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
33 #define __BUG_ENTRY_ADDR RISCV_INT " 1b - 2b"
34 #define __BUG_ENTRY_FILE RISCV_INT " %0 - 2b"
36 #define __BUG_ENTRY_ADDR RISCV_PTR " 1b"
37 #define __BUG_ENTRY_FILE RISCV_PTR " %0"
40 #ifdef CONFIG_DEBUG_BUGVERBOSE
42 __BUG_ENTRY_ADDR "\n\t" \
43 __BUG_ENTRY_FILE "\n\t" \
44 RISCV_SHORT " %1\n\t" \
48 __BUG_ENTRY_ADDR "\n\t" \
52 #ifdef CONFIG_GENERIC_BUG
53 #define __BUG_FLAGS(flags) \
55 __asm__ __volatile__ ( \
58 ".pushsection __bug_table,\"aw\"\n\t" \
64 : "i" (__FILE__), "i" (__LINE__), \
66 "i" (sizeof(struct bug_entry))); \
68 #else /* CONFIG_GENERIC_BUG */
69 #define __BUG_FLAGS(flags) do { \
70 __asm__ __volatile__ ("ebreak\n"); \
72 #endif /* CONFIG_GENERIC_BUG */
79 #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
83 #include <asm-generic/bug.h>
88 void die(struct pt_regs
*regs
, const char *str
);
89 void do_trap(struct pt_regs
*regs
, int signo
, int code
, unsigned long addr
);
91 #endif /* _ASM_RISCV_BUG_H */