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 - 5001b, 5002f - 5001b 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: .4byte \addr - 5001b 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.4byte 1b - 2b, %0 - 2b\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.4byte 1b - 2b\n" \ 47 "\t.short %2\n" \ 48 ".org 2b+%3\n" \ 49 ".previous\n" 50 #endif 51 52 #define BUG_ENTRY(insn, flags, ...) \ 53 __asm__ __volatile__( \ 54 "1: " insn "\n" \ 55 _EMIT_BUG_ENTRY \ 56 : : "i" (__FILE__), "i" (__LINE__), \ 57 "i" (flags), \ 58 "i" (sizeof(struct bug_entry)), \ 59 ##__VA_ARGS__) 60 61 /* 62 * BUG_ON() and WARN_ON() do their best to cooperate with compile-time 63 * optimisations. However depending on the complexity of the condition 64 * some compiler versions may not produce optimal results. 65 */ 66 67 #define BUG() do { \ 68 BUG_ENTRY("twi 31, 0, 0", 0); \ 69 unreachable(); \ 70 } while (0) 71 72 #define BUG_ON(x) do { \ 73 if (__builtin_constant_p(x)) { \ 74 if (x) \ 75 BUG(); \ 76 } else { \ 77 BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \ 78 } \ 79 } while (0) 80 81 #define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags)) 82 83 #define WARN_ON(x) ({ \ 84 int __ret_warn_on = !!(x); \ 85 if (__builtin_constant_p(__ret_warn_on)) { \ 86 if (__ret_warn_on) \ 87 __WARN(); \ 88 } else { \ 89 BUG_ENTRY(PPC_TLNEI " %4, 0", \ 90 BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \ 91 "r" (__ret_warn_on)); \ 92 } \ 93 unlikely(__ret_warn_on); \ 94 }) 95 96 #define HAVE_ARCH_BUG 97 #define HAVE_ARCH_BUG_ON 98 #define HAVE_ARCH_WARN_ON 99 #endif /* __ASSEMBLY __ */ 100 #else 101 #ifdef __ASSEMBLY__ 102 .macro EMIT_BUG_ENTRY addr,file,line,flags 103 .endm 104 #else /* !__ASSEMBLY__ */ 105 #define _EMIT_BUG_ENTRY 106 #endif 107 #endif /* CONFIG_BUG */ 108 109 #include <asm-generic/bug.h> 110 111 #ifndef __ASSEMBLY__ 112 113 struct pt_regs; 114 extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long); 115 extern void bad_page_fault(struct pt_regs *, unsigned long, int); 116 void __bad_page_fault(struct pt_regs *regs, unsigned long address, int sig); 117 extern void _exception(int, struct pt_regs *, int, unsigned long); 118 extern void _exception_pkey(struct pt_regs *, unsigned long, int); 119 extern void die(const char *, struct pt_regs *, long); 120 extern bool die_will_crash(void); 121 extern void panic_flush_kmsg_start(void); 122 extern void panic_flush_kmsg_end(void); 123 #endif /* !__ASSEMBLY__ */ 124 125 #endif /* __KERNEL__ */ 126 #endif /* _ASM_POWERPC_BUG_H */ 127