Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
25433b12 BB |
2 | #ifndef _ASM_POWERPC_BUG_H |
3 | #define _ASM_POWERPC_BUG_H | |
88ced031 | 4 | #ifdef __KERNEL__ |
1da177e4 | 5 | |
3ddfbcf1 | 6 | #include <asm/asm-compat.h> |
a58f053b | 7 | |
1da177e4 LT |
8 | /* |
9 | * Define an illegal instr to trap on the bug. | |
10 | * We don't use 0 because that marks the end of a function | |
11 | * in the ELF ABI. That's "Boo Boo" in case you wonder... | |
12 | */ | |
13 | #define BUG_OPCODE .long 0x00b00b00 /* For asm */ | |
14 | #define BUG_ILLEGAL_INSTR "0x00b00b00" /* For BUG macro */ | |
15 | ||
c8538a7a MM |
16 | #ifdef CONFIG_BUG |
17 | ||
007d88d0 | 18 | #ifdef __ASSEMBLY__ |
a58f053b | 19 | #include <asm/asm-offsets.h> |
007d88d0 DW |
20 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
21 | .macro EMIT_BUG_ENTRY addr,file,line,flags | |
325cdacd | 22 | .section __bug_table,"aw" |
007d88d0 DW |
23 | 5001: PPC_LONG \addr, 5002f |
24 | .short \line, \flags | |
25 | .org 5001b+BUG_ENTRY_SIZE | |
26 | .previous | |
27 | .section .rodata,"a" | |
28 | 5002: .asciz "\file" | |
29 | .previous | |
30 | .endm | |
31 | #else | |
a58f053b | 32 | .macro EMIT_BUG_ENTRY addr,file,line,flags |
325cdacd | 33 | .section __bug_table,"aw" |
007d88d0 DW |
34 | 5001: PPC_LONG \addr |
35 | .short \flags | |
36 | .org 5001b+BUG_ENTRY_SIZE | |
37 | .previous | |
38 | .endm | |
39 | #endif /* verbose */ | |
40 | ||
41 | #else /* !__ASSEMBLY__ */ | |
73c9ceab JF |
42 | /* _EMIT_BUG_ENTRY expects args %0,%1,%2,%3 to be FILE, LINE, flags and |
43 | sizeof(struct bug_entry), respectively */ | |
44 | #ifdef CONFIG_DEBUG_BUGVERBOSE | |
45 | #define _EMIT_BUG_ENTRY \ | |
325cdacd | 46 | ".section __bug_table,\"aw\"\n" \ |
73c9ceab JF |
47 | "2:\t" PPC_LONG "1b, %0\n" \ |
48 | "\t.short %1, %2\n" \ | |
49 | ".org 2b+%3\n" \ | |
50 | ".previous\n" | |
51 | #else | |
52 | #define _EMIT_BUG_ENTRY \ | |
325cdacd | 53 | ".section __bug_table,\"aw\"\n" \ |
73c9ceab JF |
54 | "2:\t" PPC_LONG "1b\n" \ |
55 | "\t.short %2\n" \ | |
56 | ".org 2b+%3\n" \ | |
57 | ".previous\n" | |
58 | #endif | |
59 | ||
e3f94b85 ME |
60 | /* |
61 | * BUG_ON() and WARN_ON() do their best to cooperate with compile-time | |
62 | * optimisations. However depending on the complexity of the condition | |
63 | * some compiler versions may not produce optimal results. | |
64 | */ | |
65 | ||
73c9ceab JF |
66 | #define BUG() do { \ |
67 | __asm__ __volatile__( \ | |
68 | "1: twi 31,0,0\n" \ | |
69 | _EMIT_BUG_ENTRY \ | |
70 | : : "i" (__FILE__), "i" (__LINE__), \ | |
71 | "i" (0), "i" (sizeof(struct bug_entry))); \ | |
01ae45bc | 72 | unreachable(); \ |
1da177e4 LT |
73 | } while (0) |
74 | ||
75 | #define BUG_ON(x) do { \ | |
e3f94b85 ME |
76 | if (__builtin_constant_p(x)) { \ |
77 | if (x) \ | |
78 | BUG(); \ | |
79 | } else { \ | |
80 | __asm__ __volatile__( \ | |
73c9ceab JF |
81 | "1: "PPC_TLNEI" %4,0\n" \ |
82 | _EMIT_BUG_ENTRY \ | |
83 | : : "i" (__FILE__), "i" (__LINE__), "i" (0), \ | |
84 | "i" (sizeof(struct bug_entry)), \ | |
97f1e7f7 | 85 | "r" ((__force long)(x))); \ |
e3f94b85 | 86 | } \ |
1da177e4 LT |
87 | } while (0) |
88 | ||
19d43626 | 89 | #define __WARN_FLAGS(flags) do { \ |
1da177e4 | 90 | __asm__ __volatile__( \ |
e3f94b85 | 91 | "1: twi 31,0,0\n" \ |
73c9ceab JF |
92 | _EMIT_BUG_ENTRY \ |
93 | : : "i" (__FILE__), "i" (__LINE__), \ | |
19d43626 | 94 | "i" (BUGFLAG_WARNING|(flags)), \ |
73c9ceab | 95 | "i" (sizeof(struct bug_entry))); \ |
e3f94b85 ME |
96 | } while (0) |
97 | ||
684f9783 | 98 | #define WARN_ON(x) ({ \ |
8d4fbcfb | 99 | int __ret_warn_on = !!(x); \ |
684f9783 HX |
100 | if (__builtin_constant_p(__ret_warn_on)) { \ |
101 | if (__ret_warn_on) \ | |
872345b7 | 102 | __WARN(); \ |
e3f94b85 ME |
103 | } else { \ |
104 | __asm__ __volatile__( \ | |
73c9ceab JF |
105 | "1: "PPC_TLNEI" %4,0\n" \ |
106 | _EMIT_BUG_ENTRY \ | |
107 | : : "i" (__FILE__), "i" (__LINE__), \ | |
a093c92d | 108 | "i" (BUGFLAG_WARNING|BUGFLAG_TAINT(TAINT_WARN)),\ |
73c9ceab JF |
109 | "i" (sizeof(struct bug_entry)), \ |
110 | "r" (__ret_warn_on)); \ | |
e3f94b85 | 111 | } \ |
684f9783 HX |
112 | unlikely(__ret_warn_on); \ |
113 | }) | |
1da177e4 | 114 | |
1da177e4 LT |
115 | #define HAVE_ARCH_BUG |
116 | #define HAVE_ARCH_BUG_ON | |
117 | #define HAVE_ARCH_WARN_ON | |
25433b12 | 118 | #endif /* __ASSEMBLY __ */ |
a58f053b BH |
119 | #else |
120 | #ifdef __ASSEMBLY__ | |
121 | .macro EMIT_BUG_ENTRY addr,file,line,flags | |
122 | .endm | |
123 | #else /* !__ASSEMBLY__ */ | |
124 | #define _EMIT_BUG_ENTRY | |
125 | #endif | |
007d88d0 | 126 | #endif /* CONFIG_BUG */ |
c8538a7a | 127 | |
1da177e4 LT |
128 | #include <asm-generic/bug.h> |
129 | ||
ae3a197e DH |
130 | #ifndef __ASSEMBLY__ |
131 | ||
132 | struct pt_regs; | |
133 | extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long); | |
134 | extern void bad_page_fault(struct pt_regs *, unsigned long, int); | |
135 | extern void _exception(int, struct pt_regs *, int, unsigned long); | |
5d8fb8a5 | 136 | extern void _exception_pkey(struct pt_regs *, unsigned long, int); |
ae3a197e | 137 | extern void die(const char *, struct pt_regs *, long); |
6fcd6baa | 138 | extern bool die_will_crash(void); |
35adacd6 NP |
139 | extern void panic_flush_kmsg_start(void); |
140 | extern void panic_flush_kmsg_end(void); | |
ae3a197e DH |
141 | #endif /* !__ASSEMBLY__ */ |
142 | ||
88ced031 | 143 | #endif /* __KERNEL__ */ |
25433b12 | 144 | #endif /* _ASM_POWERPC_BUG_H */ |