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 - 5001b, 5002f - 5001b
18 .org 5001b+BUG_ENTRY_SIZE
25 .macro EMIT_BUG_ENTRY addr,file,line,flags
26 .section __bug_table,"aw"
27 5001: .4byte \addr - 5001b
29 .org 5001b+BUG_ENTRY_SIZE
34 .macro EMIT_WARN_ENTRY addr,file,line,flags
35 EX_TABLE(\addr,\addr+4)
36 EMIT_BUG_ENTRY \addr,\file,\line,\flags
39 #else /* !__ASSEMBLY__ */
40 /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and
41 sizeof(struct bug_entry), respectively */
42 #ifdef CONFIG_DEBUG_BUGVERBOSE
43 #define _EMIT_BUG_ENTRY \
44 ".section __bug_table,\"aw\"\n" \
45 "2:\t.4byte 1b - 2b, %0 - 2b\n" \
50 #define _EMIT_BUG_ENTRY \
51 ".section __bug_table,\"aw\"\n" \
52 "2:\t.4byte 1b - 2b\n" \
58 #define BUG_ENTRY(insn, flags, ...) \
59 __asm__ __volatile__( \
62 : : "i" (__FILE__), "i" (__LINE__), \
64 "i" (sizeof(struct bug_entry)), \
67 #define WARN_ENTRY(insn, flags, label, ...) \
70 EX_TABLE(1b, %l[label]) \
72 : : "i" (__FILE__), "i" (__LINE__), \
74 "i" (sizeof(struct bug_entry)), \
75 ##__VA_ARGS__ : : label)
78 * BUG_ON() and WARN_ON() do their best to cooperate with compile-time
79 * optimisations. However depending on the complexity of the condition
80 * some compiler versions may not produce optimal results.
84 BUG_ENTRY("twi 31, 0, 0", 0); \
89 #define __WARN_FLAGS(flags) do { \
90 __label__ __label_warn_on; \
92 WARN_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags), __label_warn_on); \
100 #define BUG_ON(x) do { \
101 if (__builtin_constant_p(x)) { \
105 BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
109 #define WARN_ON(x) ({ \
110 bool __ret_warn_on = false; \
112 if (__builtin_constant_p((x))) { \
116 __ret_warn_on = true; \
118 __label__ __label_warn_on; \
120 WARN_ENTRY(PPC_TLNEI " %4, 0", \
121 BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
123 "r" ((__force long)(x))); \
126 __ret_warn_on = true; \
129 unlikely(__ret_warn_on); \
132 #define HAVE_ARCH_BUG_ON
133 #define HAVE_ARCH_WARN_ON
136 #endif /* __ASSEMBLY __ */
139 .macro EMIT_BUG_ENTRY addr,file,line,flags
141 .macro EMIT_WARN_ENTRY addr,file,line,flags
143 #else /* !__ASSEMBLY__ */
144 #define _EMIT_BUG_ENTRY
145 #define _EMIT_WARN_ENTRY
147 #endif /* CONFIG_BUG */
149 #include <asm-generic/bug.h>
154 void hash__do_page_fault(struct pt_regs *);
155 void bad_page_fault(struct pt_regs *, int);
156 extern void _exception(int, struct pt_regs *, int, unsigned long);
157 extern void _exception_pkey(struct pt_regs *, unsigned long, int);
158 extern void die(const char *, struct pt_regs *, long);
159 void die_mce(const char *str, struct pt_regs *regs, long err);
160 extern bool die_will_crash(void);
161 extern void panic_flush_kmsg_start(void);
162 extern void panic_flush_kmsg_end(void);
163 #endif /* !__ASSEMBLY__ */
165 #endif /* __KERNEL__ */
166 #endif /* _ASM_POWERPC_BUG_H */