1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/stringify.h>
8 * Despite that some emulators terminate on UD2, we use it for WARN().
10 * Since various instruction decoders/specs disagree on the encoding of
14 #define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */
15 #define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
16 #define ASM_UD2 ".byte 0x0f, 0x0b"
18 #define INSN_UD0 0xff0f
19 #define INSN_UD2 0x0b0f
23 #ifdef CONFIG_GENERIC_BUG
26 # define __BUG_REL(val) ".long " __stringify(val)
28 # define __BUG_REL(val) ".long " __stringify(val) " - 2b"
31 #ifdef CONFIG_DEBUG_BUGVERBOSE
33 #define _BUG_FLAGS(ins, flags) \
35 asm volatile("1:\t" ins "\n" \
36 ".pushsection __bug_table,\"aw\"\n" \
37 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
38 "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
39 "\t.word %c1" "\t# bug_entry::line\n" \
40 "\t.word %c2" "\t# bug_entry::flags\n" \
43 : : "i" (__FILE__), "i" (__LINE__), \
45 "i" (sizeof(struct bug_entry))); \
48 #else /* !CONFIG_DEBUG_BUGVERBOSE */
50 #define _BUG_FLAGS(ins, flags) \
52 asm volatile("1:\t" ins "\n" \
53 ".pushsection __bug_table,\"aw\"\n" \
54 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
55 "\t.word %c0" "\t# bug_entry::flags\n" \
59 "i" (sizeof(struct bug_entry))); \
62 #endif /* CONFIG_DEBUG_BUGVERBOSE */
66 #define _BUG_FLAGS(ins, flags) asm volatile(ins)
68 #endif /* CONFIG_GENERIC_BUG */
73 _BUG_FLAGS(ASM_UD2, 0); \
77 #define __WARN_FLAGS(flags) \
79 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
80 annotate_reachable(); \
83 #include <asm-generic/bug.h>
85 #endif /* _ASM_X86_BUG_H */