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,\"aw\"\n"	\
32 			     "2:\t" ASM_WORD_INSN "1b, %c0\n"		\
33 			     "\t.short %c1, %c2\n"			\
34 			     "\t.org 2b+%c3\n"				\
35 			     "\t.popsection"				\
36 			     : : "i" (__FILE__), "i" (__LINE__),	\
37 			     "i" (0), "i" (sizeof(struct bug_entry)) ); \
38 		unreachable();						\
39 	} while(0)
40 
41 #else
42 #define BUG()								\
43 	do {								\
44 		asm volatile(PARISC_BUG_BREAK_ASM : : );		\
45 		unreachable();						\
46 	} while(0)
47 #endif
48 
49 #ifdef CONFIG_DEBUG_BUGVERBOSE
50 #define __WARN_FLAGS(flags)						\
51 	do {								\
52 		asm volatile("\n"					\
53 			     "1:\t" PARISC_BUG_BREAK_ASM "\n"		\
54 			     "\t.pushsection __bug_table,\"aw\"\n"	\
55 			     "2:\t" ASM_WORD_INSN "1b, %c0\n"		\
56 			     "\t.short %c1, %c2\n"			\
57 			     "\t.org 2b+%c3\n"				\
58 			     "\t.popsection"				\
59 			     : : "i" (__FILE__), "i" (__LINE__),	\
60 			     "i" (BUGFLAG_WARNING|(flags)),		\
61 			     "i" (sizeof(struct bug_entry)) );		\
62 	} while(0)
63 #else
64 #define __WARN_FLAGS(flags)						\
65 	do {								\
66 		asm volatile("\n"					\
67 			     "1:\t" PARISC_BUG_BREAK_ASM "\n"		\
68 			     "\t.pushsection __bug_table,\"aw\"\n"	\
69 			     "2:\t" ASM_WORD_INSN "1b\n"		\
70 			     "\t.short %c0\n"				\
71 			     "\t.org 2b+%c1\n"				\
72 			     "\t.popsection"				\
73 			     : : "i" (BUGFLAG_WARNING|(flags)),		\
74 			     "i" (sizeof(struct bug_entry)) );		\
75 	} while(0)
76 #endif
77 
78 
79 #define WARN_ON(x) ({						\
80 	int __ret_warn_on = !!(x);				\
81 	if (__builtin_constant_p(__ret_warn_on)) {		\
82 		if (__ret_warn_on)				\
83 			__WARN();				\
84 	} else {						\
85 		if (unlikely(__ret_warn_on))			\
86 			__WARN();				\
87 	}							\
88 	unlikely(__ret_warn_on);				\
89 })
90 
91 #endif
92 
93 #include <asm-generic/bug.h>
94 #endif
95 
96