b9cad0bb4461bdb31f8d01c770f2fee3ce435769
[platform/kernel/linux-starfive.git] / arch / parisc / include / asm / bug.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PARISC_BUG_H
3 #define _PARISC_BUG_H
4
5 #include <linux/kernel.h>       /* for BUGFLAG_TAINT */
6
7 /*
8  * Tell the user there is some problem.
9  * The offending file and line are encoded in the __bug_table section.
10  */
11
12 #ifdef CONFIG_BUG
13 #define HAVE_ARCH_BUG
14 #define HAVE_ARCH_WARN_ON
15
16 /* the break instruction is used as BUG() marker.  */
17 #define PARISC_BUG_BREAK_ASM    "break 0x1f, 0x1fff"
18 #define PARISC_BUG_BREAK_INSN   0x03ffe01f  /* PARISC_BUG_BREAK_ASM */
19
20 #if defined(CONFIG_64BIT)
21 #define ASM_WORD_INSN           ".dword\t"
22 #else
23 #define ASM_WORD_INSN           ".word\t"
24 #endif
25
26 #ifdef CONFIG_DEBUG_BUGVERBOSE
27 #define BUG()                                                           \
28         do {                                                            \
29                 asm volatile("\n"                                       \
30                              "1:\t" PARISC_BUG_BREAK_ASM "\n"           \
31                              "\t.pushsection __bug_table,\"a\"\n"       \
32                              "\t.align %4\n"                            \
33                              "2:\t" ASM_WORD_INSN "1b, %c0\n"           \
34                              "\t.short %1, %2\n"                        \
35                              "\t.blockz %3-2*%4-2*2\n"                  \
36                              "\t.popsection"                            \
37                              : : "i" (__FILE__), "i" (__LINE__),        \
38                              "i" (0), "i" (sizeof(struct bug_entry)),   \
39                              "i" (sizeof(long)) );                      \
40                 unreachable();                                          \
41         } while(0)
42
43 #else
44 #define BUG()                                                           \
45         do {                                                            \
46                 asm volatile(PARISC_BUG_BREAK_ASM : : );                \
47                 unreachable();                                          \
48         } while(0)
49 #endif
50
51 #ifdef CONFIG_DEBUG_BUGVERBOSE
52 #define __WARN_FLAGS(flags)                                             \
53         do {                                                            \
54                 asm volatile("\n"                                       \
55                              "1:\t" PARISC_BUG_BREAK_ASM "\n"           \
56                              "\t.pushsection __bug_table,\"a\"\n"       \
57                              "\t.align %4\n"                            \
58                              "2:\t" ASM_WORD_INSN "1b, %c0\n"           \
59                              "\t.short %1, %2\n"                        \
60                              "\t.blockz %3-2*%4-2*2\n"                  \
61                              "\t.popsection"                            \
62                              : : "i" (__FILE__), "i" (__LINE__),        \
63                              "i" (BUGFLAG_WARNING|(flags)),             \
64                              "i" (sizeof(struct bug_entry)),            \
65                              "i" (sizeof(long)) );                      \
66         } while(0)
67 #else
68 #define __WARN_FLAGS(flags)                                             \
69         do {                                                            \
70                 asm volatile("\n"                                       \
71                              "1:\t" PARISC_BUG_BREAK_ASM "\n"           \
72                              "\t.pushsection __bug_table,\"a\"\n"       \
73                              "\t.align %2\n"                            \
74                              "2:\t" ASM_WORD_INSN "1b\n"                \
75                              "\t.short %0\n"                            \
76                              "\t.blockz %1-%2-2\n"                      \
77                              "\t.popsection"                            \
78                              : : "i" (BUGFLAG_WARNING|(flags)),         \
79                              "i" (sizeof(struct bug_entry)),            \
80                              "i" (sizeof(long)) );                      \
81         } while(0)
82 #endif
83
84
85 #define WARN_ON(x) ({                                           \
86         int __ret_warn_on = !!(x);                              \
87         if (__builtin_constant_p(__ret_warn_on)) {              \
88                 if (__ret_warn_on)                              \
89                         __WARN();                               \
90         } else {                                                \
91                 if (unlikely(__ret_warn_on))                    \
92                         __WARN();                               \
93         }                                                       \
94         unlikely(__ret_warn_on);                                \
95 })
96
97 #endif
98
99 #include <asm-generic/bug.h>
100 #endif
101