1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/stringify.h>
6 #include <linux/instrumentation.h>
7 #include <linux/objtool.h>
10 * Despite that some emulators terminate on UD2, we use it for WARN().
12 #define ASM_UD2 ".byte 0x0f, 0x0b"
13 #define INSN_UD2 0x0b0f
16 #ifdef CONFIG_GENERIC_BUG
19 # define __BUG_REL(val) ".long " __stringify(val)
21 # define __BUG_REL(val) ".long " __stringify(val) " - ."
24 #ifdef CONFIG_DEBUG_BUGVERBOSE
26 #define _BUG_FLAGS(ins, flags, extra) \
28 asm_inline volatile("1:\t" ins "\n" \
29 ".pushsection __bug_table,\"aw\"\n" \
30 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
31 "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
32 "\t.word %c1" "\t# bug_entry::line\n" \
33 "\t.word %c2" "\t# bug_entry::flags\n" \
37 : : "i" (__FILE__), "i" (__LINE__), \
39 "i" (sizeof(struct bug_entry))); \
42 #else /* !CONFIG_DEBUG_BUGVERBOSE */
44 #define _BUG_FLAGS(ins, flags, extra) \
46 asm_inline volatile("1:\t" ins "\n" \
47 ".pushsection __bug_table,\"aw\"\n" \
48 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
49 "\t.word %c0" "\t# bug_entry::flags\n" \
54 "i" (sizeof(struct bug_entry))); \
57 #endif /* CONFIG_DEBUG_BUGVERBOSE */
61 #define _BUG_FLAGS(ins, flags, extra) asm volatile(ins)
63 #endif /* CONFIG_GENERIC_BUG */
68 instrumentation_begin(); \
69 _BUG_FLAGS(ASM_UD2, 0, ""); \
70 __builtin_unreachable(); \
74 * This instrumentation_begin() is strictly speaking incorrect; but it
75 * suppresses the complaints from WARN()s in noinstr code. If such a WARN()
76 * were to trigger, we'd rather wreck the machine in an attempt to get the
77 * message out than not know about it.
79 #define __WARN_FLAGS(flags) \
81 __auto_type __flags = BUGFLAG_WARNING|(flags); \
82 instrumentation_begin(); \
83 _BUG_FLAGS(ASM_UD2, __flags, ASM_REACHABLE); \
84 instrumentation_end(); \
87 #include <asm-generic/bug.h>
89 #endif /* _ASM_X86_BUG_H */