parisc: Reduce size of the bug_table on 64-bit kernel by half
[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 #ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
21 # define __BUG_REL(val) ".word " __stringify(val) " - ."
22 #else
23 # define __BUG_REL(val) ".word " __stringify(val)
24 #endif
25
26
27 #ifdef CONFIG_DEBUG_BUGVERBOSE
28 #define BUG()                                                           \
29         do {                                                            \
30                 asm volatile("\n"                                       \
31                              "1:\t" PARISC_BUG_BREAK_ASM "\n"           \
32                              "\t.pushsection __bug_table,\"a\"\n"       \
33                              "\t.align 4\n"                             \
34                              "2:\t" __BUG_REL(1b) "\n"                  \
35                              "\t" __BUG_REL(%c0)  "\n"                  \
36                              "\t.short %1, %2\n"                        \
37                              "\t.blockz %3-2*4-2*2\n"                   \
38                              "\t.popsection"                            \
39                              : : "i" (__FILE__), "i" (__LINE__),        \
40                              "i" (0), "i" (sizeof(struct bug_entry)) ); \
41                 unreachable();                                          \
42         } while(0)
43
44 #else
45 #define BUG()                                                           \
46         do {                                                            \
47                 asm volatile(PARISC_BUG_BREAK_ASM : : );                \
48                 unreachable();                                          \
49         } while(0)
50 #endif
51
52 #ifdef CONFIG_DEBUG_BUGVERBOSE
53 #define __WARN_FLAGS(flags)                                             \
54         do {                                                            \
55                 asm volatile("\n"                                       \
56                              "1:\t" PARISC_BUG_BREAK_ASM "\n"           \
57                              "\t.pushsection __bug_table,\"a\"\n"       \
58                              "\t.align 4\n"                             \
59                              "2:\t" __BUG_REL(1b) "\n"                  \
60                              "\t" __BUG_REL(%c0)  "\n"                  \
61                              "\t.short %1, %2\n"                        \
62                              "\t.blockz %3-2*4-2*2\n"                   \
63                              "\t.popsection"                            \
64                              : : "i" (__FILE__), "i" (__LINE__),        \
65                              "i" (BUGFLAG_WARNING|(flags)),             \
66                              "i" (sizeof(struct bug_entry)) );          \
67         } while(0)
68 #else
69 #define __WARN_FLAGS(flags)                                             \
70         do {                                                            \
71                 asm volatile("\n"                                       \
72                              "1:\t" PARISC_BUG_BREAK_ASM "\n"           \
73                              "\t.pushsection __bug_table,\"a\"\n"       \
74                              "\t.align %2\n"                            \
75                              "2:\t" __BUG_REL(1b) "\n"                  \
76                              "\t.short %0\n"                            \
77                              "\t.blockz %1-4-2\n"                       \
78                              "\t.popsection"                            \
79                              : : "i" (BUGFLAG_WARNING|(flags)),         \
80                              "i" (sizeof(struct bug_entry)) );          \
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