xref: /openbmc/linux/arch/riscv/include/asm/bug.h (revision 2359ccdd)
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 __BUG_INSN	_AC(0x00100073, UL) /* ebreak */
25 
26 #ifndef __ASSEMBLY__
27 typedef u32 bug_insn_t;
28 
29 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
30 #define __BUG_ENTRY_ADDR	RISCV_INT " 1b - 2b"
31 #define __BUG_ENTRY_FILE	RISCV_INT " %0 - 2b"
32 #else
33 #define __BUG_ENTRY_ADDR	RISCV_PTR " 1b"
34 #define __BUG_ENTRY_FILE	RISCV_PTR " %0"
35 #endif
36 
37 #ifdef CONFIG_DEBUG_BUGVERBOSE
38 #define __BUG_ENTRY			\
39 	__BUG_ENTRY_ADDR "\n\t"		\
40 	__BUG_ENTRY_FILE "\n\t"		\
41 	RISCV_SHORT " %1"
42 #else
43 #define __BUG_ENTRY			\
44 	__BUG_ENTRY_ADDR
45 #endif
46 
47 #define BUG()							\
48 do {								\
49 	__asm__ __volatile__ (					\
50 		"1:\n\t"					\
51 			"ebreak\n"				\
52 			".pushsection __bug_table,\"a\"\n\t"	\
53 		"2:\n\t"					\
54 			__BUG_ENTRY "\n\t"			\
55 			".org 2b + %2\n\t"			\
56 			".popsection"				\
57 		:						\
58 		: "i" (__FILE__), "i" (__LINE__),		\
59 		  "i" (sizeof(struct bug_entry)));		\
60 	unreachable();						\
61 } while (0)
62 #endif /* !__ASSEMBLY__ */
63 #else /* CONFIG_GENERIC_BUG */
64 #ifndef __ASSEMBLY__
65 #define BUG()							\
66 do {								\
67 	__asm__ __volatile__ ("ebreak\n");			\
68 	unreachable();						\
69 } while (0)
70 #endif /* !__ASSEMBLY__ */
71 #endif /* CONFIG_GENERIC_BUG */
72 
73 #define HAVE_ARCH_BUG
74 
75 #include <asm-generic/bug.h>
76 
77 #ifndef __ASSEMBLY__
78 
79 struct pt_regs;
80 struct task_struct;
81 
82 extern void die(struct pt_regs *regs, const char *str);
83 extern void do_trap(struct pt_regs *regs, int signo, int code,
84 	unsigned long addr, struct task_struct *tsk);
85 
86 #endif /* !__ASSEMBLY__ */
87 
88 #endif /* _ASM_RISCV_BUG_H */
89