1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/stringify.h>
6 #include <linux/instrumentation.h>
9 * Despite that some emulators terminate on UD2, we use it for WARN().
11 #define ASM_UD2 ".byte 0x0f, 0x0b"
12 #define INSN_UD2 0x0b0f
15 #ifdef CONFIG_GENERIC_BUG
18 # define __BUG_REL(val) ".long " __stringify(val)
20 # define __BUG_REL(val) ".long " __stringify(val) " - 2b"
23 #ifdef CONFIG_DEBUG_BUGVERBOSE
25 #define _BUG_FLAGS(ins, flags, extra) \
27 asm_inline volatile("1:\t" ins "\n" \
28 ".pushsection __bug_table,\"aw\"\n" \
29 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
30 "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
31 "\t.word %c1" "\t# bug_entry::line\n" \
32 "\t.word %c2" "\t# bug_entry::flags\n" \
36 : : "i" (__FILE__), "i" (__LINE__), \
38 "i" (sizeof(struct bug_entry))); \
41 #else /* !CONFIG_DEBUG_BUGVERBOSE */
43 #define _BUG_FLAGS(ins, flags, extra) \
45 asm_inline volatile("1:\t" ins "\n" \
46 ".pushsection __bug_table,\"aw\"\n" \
47 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
48 "\t.word %c0" "\t# bug_entry::flags\n" \
53 "i" (sizeof(struct bug_entry))); \
56 #endif /* CONFIG_DEBUG_BUGVERBOSE */
60 #define _BUG_FLAGS(ins, flags, extra) asm volatile(ins)
62 #endif /* CONFIG_GENERIC_BUG */
67 instrumentation_begin(); \
68 _BUG_FLAGS(ASM_UD2, 0, ""); \
69 __builtin_unreachable(); \
73 * This instrumentation_begin() is strictly speaking incorrect; but it
74 * suppresses the complaints from WARN()s in noinstr code. If such a WARN()
75 * were to trigger, we'd rather wreck the machine in an attempt to get the
76 * message out than not know about it.
78 #define __WARN_FLAGS(flags) \
80 __auto_type __flags = BUGFLAG_WARNING|(flags); \
81 instrumentation_begin(); \
82 _BUG_FLAGS(ASM_UD2, __flags, ASM_REACHABLE); \
83 instrumentation_end(); \
86 #include <asm-generic/bug.h>
88 #endif /* _ASM_X86_BUG_H */