xref: /openbmc/linux/arch/riscv/include/asm/bug.h (revision ee72e0e7)
1 /*
2  * Copyright (C) 2012 Regents of the University of California
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  */
13 
14 #ifndef _ASM_RISCV_BUG_H
15 #define _ASM_RISCV_BUG_H
16 
17 #include <linux/compiler.h>
18 #include <linux/const.h>
19 #include <linux/types.h>
20 
21 #include <asm/asm.h>
22 
23 #ifdef CONFIG_GENERIC_BUG
24 #define __INSN_LENGTH_MASK  _UL(0x3)
25 #define __INSN_LENGTH_32    _UL(0x3)
26 #define __COMPRESSED_INSN_MASK	_UL(0xffff)
27 
28 #define __BUG_INSN_32	_UL(0x00100073) /* ebreak */
29 #define __BUG_INSN_16	_UL(0x9002) /* c.ebreak */
30 
31 #ifndef __ASSEMBLY__
32 typedef u32 bug_insn_t;
33 
34 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
35 #define __BUG_ENTRY_ADDR	RISCV_INT " 1b - 2b"
36 #define __BUG_ENTRY_FILE	RISCV_INT " %0 - 2b"
37 #else
38 #define __BUG_ENTRY_ADDR	RISCV_PTR " 1b"
39 #define __BUG_ENTRY_FILE	RISCV_PTR " %0"
40 #endif
41 
42 #ifdef CONFIG_DEBUG_BUGVERBOSE
43 #define __BUG_ENTRY			\
44 	__BUG_ENTRY_ADDR "\n\t"		\
45 	__BUG_ENTRY_FILE "\n\t"		\
46 	RISCV_SHORT " %1\n\t"		\
47 	RISCV_SHORT " %2"
48 #else
49 #define __BUG_ENTRY			\
50 	__BUG_ENTRY_ADDR "\n\t"		\
51 	RISCV_SHORT " %2"
52 #endif
53 
54 #define __BUG_FLAGS(flags)					\
55 do {								\
56 	__asm__ __volatile__ (					\
57 		"1:\n\t"					\
58 			"ebreak\n"				\
59 			".pushsection __bug_table,\"aw\"\n\t"	\
60 		"2:\n\t"					\
61 			__BUG_ENTRY "\n\t"			\
62 			".org 2b + %3\n\t"                      \
63 			".popsection"				\
64 		:						\
65 		: "i" (__FILE__), "i" (__LINE__),		\
66 		  "i" (flags),					\
67 		  "i" (sizeof(struct bug_entry)));              \
68 } while (0)
69 
70 #endif /* !__ASSEMBLY__ */
71 #else /* CONFIG_GENERIC_BUG */
72 #ifndef __ASSEMBLY__
73 #define __BUG_FLAGS(flags) do {					\
74 	__asm__ __volatile__ ("ebreak\n");			\
75 } while (0)
76 #endif /* !__ASSEMBLY__ */
77 #endif /* CONFIG_GENERIC_BUG */
78 
79 #define BUG() do {						\
80 	__BUG_FLAGS(0);						\
81 	unreachable();						\
82 } while (0)
83 
84 #define __WARN_FLAGS(flags) __BUG_FLAGS(BUGFLAG_WARNING|(flags))
85 
86 #define HAVE_ARCH_BUG
87 
88 #include <asm-generic/bug.h>
89 
90 #ifndef __ASSEMBLY__
91 
92 struct pt_regs;
93 struct task_struct;
94 
95 extern void die(struct pt_regs *regs, const char *str);
96 extern void do_trap(struct pt_regs *regs, int signo, int code,
97 	unsigned long addr, struct task_struct *tsk);
98 
99 #endif /* !__ASSEMBLY__ */
100 
101 #endif /* _ASM_RISCV_BUG_H */
102