xref: /linux/arch/riscv/include/asm/bug.h (revision 44f57d78)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Regents of the University of California
4  */
5 
6 #ifndef _ASM_RISCV_BUG_H
7 #define _ASM_RISCV_BUG_H
8 
9 #include <linux/compiler.h>
10 #include <linux/const.h>
11 #include <linux/types.h>
12 
13 #include <asm/asm.h>
14 
15 #ifdef CONFIG_GENERIC_BUG
16 #define __INSN_LENGTH_MASK  _UL(0x3)
17 #define __INSN_LENGTH_32    _UL(0x3)
18 #define __COMPRESSED_INSN_MASK	_UL(0xffff)
19 
20 #define __BUG_INSN_32	_UL(0x00100073) /* ebreak */
21 #define __BUG_INSN_16	_UL(0x9002) /* c.ebreak */
22 
23 #ifndef __ASSEMBLY__
24 typedef u32 bug_insn_t;
25 
26 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
27 #define __BUG_ENTRY_ADDR	RISCV_INT " 1b - 2b"
28 #define __BUG_ENTRY_FILE	RISCV_INT " %0 - 2b"
29 #else
30 #define __BUG_ENTRY_ADDR	RISCV_PTR " 1b"
31 #define __BUG_ENTRY_FILE	RISCV_PTR " %0"
32 #endif
33 
34 #ifdef CONFIG_DEBUG_BUGVERBOSE
35 #define __BUG_ENTRY			\
36 	__BUG_ENTRY_ADDR "\n\t"		\
37 	__BUG_ENTRY_FILE "\n\t"		\
38 	RISCV_SHORT " %1\n\t"		\
39 	RISCV_SHORT " %2"
40 #else
41 #define __BUG_ENTRY			\
42 	__BUG_ENTRY_ADDR "\n\t"		\
43 	RISCV_SHORT " %2"
44 #endif
45 
46 #define __BUG_FLAGS(flags)					\
47 do {								\
48 	__asm__ __volatile__ (					\
49 		"1:\n\t"					\
50 			"ebreak\n"				\
51 			".pushsection __bug_table,\"aw\"\n\t"	\
52 		"2:\n\t"					\
53 			__BUG_ENTRY "\n\t"			\
54 			".org 2b + %3\n\t"                      \
55 			".popsection"				\
56 		:						\
57 		: "i" (__FILE__), "i" (__LINE__),		\
58 		  "i" (flags),					\
59 		  "i" (sizeof(struct bug_entry)));              \
60 } while (0)
61 
62 #endif /* !__ASSEMBLY__ */
63 #else /* CONFIG_GENERIC_BUG */
64 #ifndef __ASSEMBLY__
65 #define __BUG_FLAGS(flags) do {					\
66 	__asm__ __volatile__ ("ebreak\n");			\
67 } while (0)
68 #endif /* !__ASSEMBLY__ */
69 #endif /* CONFIG_GENERIC_BUG */
70 
71 #define BUG() do {						\
72 	__BUG_FLAGS(0);						\
73 	unreachable();						\
74 } while (0)
75 
76 #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
77 
78 #define HAVE_ARCH_BUG
79 
80 #include <asm-generic/bug.h>
81 
82 #ifndef __ASSEMBLY__
83 
84 struct pt_regs;
85 struct task_struct;
86 
87 extern void die(struct pt_regs *regs, const char *str);
88 extern void do_trap(struct pt_regs *regs, int signo, int code,
89 	unsigned long addr, struct task_struct *tsk);
90 
91 #endif /* !__ASSEMBLY__ */
92 
93 #endif /* _ASM_RISCV_BUG_H */
94