blob: 338f36cd9934bc4e4d95ff712e33d83da97a051e [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00008#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"
155001: PPC_LONG \addr, 5002f
16 .short \line, \flags
17 .org 5001b+BUG_ENTRY_SIZE
18 .previous
19 .section .rodata,"a"
205002: .asciz "\file"
21 .previous
22.endm
23#else
24.macro EMIT_BUG_ENTRY addr,file,line,flags
25 .section __bug_table,"aw"
265001: 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
Olivier Deprez157378f2022-04-04 15:47:50 +020052#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
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000061/*
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 { \
Olivier Deprez157378f2022-04-04 15:47:50 +020068 BUG_ENTRY("twi 31, 0, 0", 0); \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000069 unreachable(); \
70} while (0)
71
72#define BUG_ON(x) do { \
73 if (__builtin_constant_p(x)) { \
74 if (x) \
75 BUG(); \
76 } else { \
Olivier Deprez157378f2022-04-04 15:47:50 +020077 BUG_ENTRY(PPC_TLNEI " %4, 0", 0, "r" ((__force long)(x))); \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000078 } \
79} while (0)
80
Olivier Deprez157378f2022-04-04 15:47:50 +020081#define __WARN_FLAGS(flags) BUG_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags))
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000082
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 { \
Olivier Deprez157378f2022-04-04 15:47:50 +020089 BUG_ENTRY(PPC_TLNEI " %4, 0", \
90 BUGFLAG_WARNING | BUGFLAG_TAINT(TAINT_WARN), \
91 "r" (__ret_warn_on)); \
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000092 } \
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
113struct pt_regs;
114extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
115extern void bad_page_fault(struct pt_regs *, unsigned long, int);
116extern void _exception(int, struct pt_regs *, int, unsigned long);
David Brazdil0f672f62019-12-10 10:32:29 +0000117extern void _exception_pkey(struct pt_regs *, unsigned long, int);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000118extern void die(const char *, struct pt_regs *, long);
119extern bool die_will_crash(void);
120extern void panic_flush_kmsg_start(void);
121extern void panic_flush_kmsg_end(void);
122#endif /* !__ASSEMBLY__ */
123
124#endif /* __KERNEL__ */
125#endif /* _ASM_POWERPC_BUG_H */