1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_POWERPC_BUG_H
3 #define _ASM_POWERPC_BUG_H
6 #include <asm/asm-compat.h>
7 #include <asm/extable.h>
12 #include <asm/asm-offsets.h>
13 #ifdef CONFIG_DEBUG_BUGVERBOSE
14 .macro __EMIT_BUG_ENTRY addr,file,line,flags
15 .section __bug_table,"aw"
16 5001: .4byte \addr - .
19 .org 5001b+BUG_ENTRY_SIZE
26 .macro __EMIT_BUG_ENTRY addr,file,line,flags
27 .section __bug_table,"aw"
28 5001: .4byte \addr - .
30 .org 5001b+BUG_ENTRY_SIZE
35 .macro EMIT_WARN_ENTRY addr,file,line,flags
36 EX_TABLE(\addr,\addr+4)
37 __EMIT_BUG_ENTRY \addr,\file,\line,\flags
40 .macro EMIT_BUG_ENTRY addr,file,line,flags
41 .if \flags & 1 /* BUGFLAG_WARNING */
42 .err /* Use EMIT_WARN_ENTRY for warnings */
44 __EMIT_BUG_ENTRY \addr,\file,\line,\flags
47 #else /* !__ASSEMBLY__ */
48 /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
49 sizeof(struct bug_entry), respectively */
50 #ifdef CONFIG_DEBUG_BUGVERBOSE
51 #define _EMIT_BUG_ENTRY \
52 ".section __bug_table,\"aw\"\n" \
53 "2: .4byte 1b - .\n" \
59 #define _EMIT_BUG_ENTRY \
60 ".section __bug_table,\"aw\"\n" \
61 "2: .4byte 1b - .\n" \
67 #define BUG_ENTRY(insn, flags, ...) \
68 __asm__ __volatile__( \
71 : : "i" (__FILE__), "i" (__LINE__), \
73 "i" (sizeof(struct bug_entry)), \
76 #define WARN_ENTRY(insn, flags, label, ...) \
79 EX_TABLE(1b, %l[label]) \
81 : : "i" (__FILE__), "i" (__LINE__), \
83 "i" (sizeof(struct bug_entry)), \
84 ##__VA_ARGS__ : : label)
87 * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
88 * optimisations. However depending on the complexity of the condition
89 * some compiler versions may not produce optimal results.
93 BUG_ENTRY("twi 31, 0, 0", 0); \
98 #define __WARN_FLAGS(flags) do { \
99 __label__ __label_warn_on; \
101 WARN_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags), __label_warn_on); \
109 #define BUG_ON(x) do { \
110 if (__builtin_constant_p(x)) { \
114 BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
118 #define WARN_ON(x) ({ \
119 bool __ret_warn_on = false; \
121 if (__builtin_constant_p((x))) { \
125 __ret_warn_on = true; \
127 __label__ __label_warn_on; \
129 WARN_ENTRY(PPC_TLNEI " %4, 0", \
130 BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
132 "r" ((__force long)(x))); \
135 __ret_warn_on = true; \
138 unlikely(__ret_warn_on); \
141 #define HAVE_ARCH_BUG_ON
142 #define HAVE_ARCH_WARN_ON
145 #endif /* __ASSEMBLY __ */
148 .macro EMIT_BUG_ENTRY addr,file,line,flags
150 .macro EMIT_WARN_ENTRY addr,file,line,flags
152 #else /* !__ASSEMBLY__ */
153 #define _EMIT_BUG_ENTRY
154 #define _EMIT_WARN_ENTRY
156 #endif /* CONFIG_BUG */
158 #include <asm-generic/bug.h>
163 void hash__do_page_fault(struct pt_regs *);
164 void bad_page_fault(struct pt_regs *, int);
165 extern void _exception(int, struct pt_regs *, int, unsigned long);
166 extern void _exception_pkey(struct pt_regs *, unsigned long, int);
167 extern void die(const char *, struct pt_regs *, long);
168 void die_mce(const char *str, struct pt_regs *regs, long err);
169 extern bool die_will_crash(void);
170 extern void panic_flush_kmsg_start(void);
171 extern void panic_flush_kmsg_end(void);
172 #endif /* !__ASSEMBLY__ */
174 #endif /* __KERNEL__ */
175 #endif /* _ASM_POWERPC_BUG_H */