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