1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/stringify.h>
10 * Despite that some emulators terminate on UD2, we use it for WARN().
12 * Since various instruction decoders/specs disagree on the encoding of
16 #define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */
17 #define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
18 #define ASM_UD2 ".byte 0x0f, 0x0b"
20 #define INSN_UD0 0xff0f
21 #define INSN_UD2 0x0b0f
25 #define _BUG_FLAGS(ins, flags) \
27 asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 " \
28 "flags=%c2 size=%c3" \
29 : : "i" (__FILE__), "i" (__LINE__), \
31 "i" (sizeof(struct bug_entry))); \
37 _BUG_FLAGS(ASM_UD2, 0); \
41 #define __WARN_FLAGS(flags) \
43 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
44 annotate_reachable(); \
47 #include <asm-generic/bug.h>
49 #else /* __ASSEMBLY__ */
51 #ifdef CONFIG_GENERIC_BUG
54 .macro __BUG_REL val:req
58 .macro __BUG_REL val:req
63 #ifdef CONFIG_DEBUG_BUGVERBOSE
65 .macro ASM_BUG ins:req file:req line:req flags:req size:req
67 .pushsection __bug_table,"aw"
68 2: __BUG_REL val=1b # bug_entry::bug_addr
69 __BUG_REL val=\file # bug_entry::file
70 .word \line # bug_entry::line
71 .word \flags # bug_entry::flags
76 #else /* !CONFIG_DEBUG_BUGVERBOSE */
78 .macro ASM_BUG ins:req file:req line:req flags:req size:req
80 .pushsection __bug_table,"aw"
81 2: __BUG_REL val=1b # bug_entry::bug_addr
82 .word \flags # bug_entry::flags
87 #endif /* CONFIG_DEBUG_BUGVERBOSE */
89 #else /* CONFIG_GENERIC_BUG */
91 .macro ASM_BUG ins:req file:req line:req flags:req size:req
95 #endif /* CONFIG_GENERIC_BUG */
97 #endif /* __ASSEMBLY__ */
99 #endif /* _ASM_X86_BUG_H */