xref: /openbmc/linux/arch/powerpc/include/asm/bug.h (revision 69f03be1)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_BUG_H
3 #define _ASM_POWERPC_BUG_H
4 #ifdef __KERNEL__
5 
6 #include <asm/asm-compat.h>
7 
8 #ifdef CONFIG_BUG
9 
10 #ifdef __ASSEMBLY__
11 #include <asm/asm-offsets.h>
12 #ifdef CONFIG_DEBUG_BUGVERBOSE
13 .macro EMIT_BUG_ENTRY addr,file,line,flags
14 	 .section __bug_table,"aw"
15 5001:	 .4byte \addr - .
16 	 .4byte 5002f - .
17 	 .short \line, \flags
18 	 .org 5001b+BUG_ENTRY_SIZE
19 	 .previous
20 	 .section .rodata,"a"
21 5002:	 .asciz "\file"
22 	 .previous
23 .endm
24 #else
25 .macro EMIT_BUG_ENTRY addr,file,line,flags
26 	 .section __bug_table,"aw"
27 5001:	 .4byte \addr - .
28 	 .short \flags
29 	 .org 5001b+BUG_ENTRY_SIZE
30 	 .previous
31 .endm
32 #endif /* verbose */
33 
34 #else /* !__ASSEMBLY__ */
35 /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
36    sizeof(struct bug_entry), respectively */
37 #ifdef CONFIG_DEBUG_BUGVERBOSE
38 #define _EMIT_BUG_ENTRY				\
39 	".section __bug_table,\"aw\"\n"		\
40 	"2:	.4byte 1b - .\n"		\
41 	"	.4byte %0 - .\n"		\
42 	"	.short %1, %2\n"		\
43 	".org 2b+%3\n"				\
44 	".previous\n"
45 #else
46 #define _EMIT_BUG_ENTRY				\
47 	".section __bug_table,\"aw\"\n"		\
48 	"2:	.4byte 1b - .\n"		\
49 	"	.short %2\n"			\
50 	".org 2b+%3\n"				\
51 	".previous\n"
52 #endif
53 
54 #define BUG_ENTRY(insn, flags, ...)			\
55 	__asm__ __volatile__(				\
56 		"1:	" insn "\n"			\
57 		_EMIT_BUG_ENTRY				\
58 		: : "i" (__FILE__), "i" (__LINE__),	\
59 		  "i" (flags),				\
60 		  "i" (sizeof(struct bug_entry)),	\
61 		  ##__VA_ARGS__)
62 
63 /*
64  * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
65  * optimisations. However depending on the complexity of the condition
66  * some compiler versions may not produce optimal results.
67  */
68 
69 #define BUG() do {						\
70 	BUG_ENTRY("twi 31, 0, 0", 0);				\
71 	unreachable();						\
72 } while (0)
73 #define HAVE_ARCH_BUG
74 
75 #define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags))
76 
77 #ifdef CONFIG_PPC64
78 #define BUG_ON(x) do {						\
79 	if (__builtin_constant_p(x)) {				\
80 		if (x)						\
81 			BUG();					\
82 	} else {						\
83 		BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x)));	\
84 	}							\
85 } while (0)
86 
87 #define WARN_ON(x) ({						\
88 	int __ret_warn_on = !!(x);				\
89 	if (__builtin_constant_p(__ret_warn_on)) {		\
90 		if (__ret_warn_on)				\
91 			__WARN();				\
92 	} else {						\
93 		BUG_ENTRY(PPC_TLNEI " %4, 0",			\
94 			  BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN),	\
95 			  "r" (__ret_warn_on));	\
96 	}							\
97 	unlikely(__ret_warn_on);				\
98 })
99 
100 #define HAVE_ARCH_BUG_ON
101 #define HAVE_ARCH_WARN_ON
102 #endif
103 
104 #endif /* __ASSEMBLY __ */
105 #else
106 #ifdef __ASSEMBLY__
107 .macro EMIT_BUG_ENTRY addr,file,line,flags
108 .endm
109 #else /* !__ASSEMBLY__ */
110 #define _EMIT_BUG_ENTRY
111 #endif
112 #endif /* CONFIG_BUG */
113 
114 #define EMIT_WARN_ENTRY EMIT_BUG_ENTRY
115 
116 #include <asm-generic/bug.h>
117 
118 #ifndef __ASSEMBLY__
119 
120 struct pt_regs;
121 void hash__do_page_fault(struct pt_regs *);
122 void bad_page_fault(struct pt_regs *, int);
123 void emulate_single_step(struct pt_regs *regs);
124 extern void _exception(int, struct pt_regs *, int, unsigned long);
125 extern void _exception_pkey(struct pt_regs *, unsigned long, int);
126 extern void die(const char *, struct pt_regs *, long);
127 void die_mce(const char *str, struct pt_regs *regs, long err);
128 extern bool die_will_crash(void);
129 extern void panic_flush_kmsg_start(void);
130 extern void panic_flush_kmsg_end(void);
131 #endif /* !__ASSEMBLY__ */
132 
133 #endif /* __KERNEL__ */
134 #endif /* _ASM_POWERPC_BUG_H */
135