Merge branch 'x86/build' into locking/core, to pick up dependent patches and unify...
[sfrench/cifs-2.6.git] / arch / x86 / include / asm / bug.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_BUG_H
3 #define _ASM_X86_BUG_H
4
5 #include <linux/stringify.h>
6
7 #ifndef __ASSEMBLY__
8
9 /*
10  * Despite that some emulators terminate on UD2, we use it for WARN().
11  *
12  * Since various instruction decoders/specs disagree on the encoding of
13  * UD0/UD1.
14  */
15
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"
19
20 #define INSN_UD0        0xff0f
21 #define INSN_UD2        0x0b0f
22
23 #define LEN_UD2         2
24
25 #define _BUG_FLAGS(ins, flags)                                          \
26 do {                                                                    \
27         asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 "       \
28                      "flags=%c2 size=%c3"                               \
29                      : : "i" (__FILE__), "i" (__LINE__),                \
30                          "i" (flags),                                   \
31                          "i" (sizeof(struct bug_entry)));               \
32 } while (0)
33
34 #define HAVE_ARCH_BUG
35 #define BUG()                                                   \
36 do {                                                            \
37         _BUG_FLAGS(ASM_UD2, 0);                                 \
38         unreachable();                                          \
39 } while (0)
40
41 #define __WARN_FLAGS(flags)                                     \
42 do {                                                            \
43         _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags));           \
44         annotate_reachable();                                   \
45 } while (0)
46
47 #include <asm-generic/bug.h>
48
49 #else /* __ASSEMBLY__ */
50
51 #ifdef CONFIG_GENERIC_BUG
52
53 #ifdef CONFIG_X86_32
54 .macro __BUG_REL val:req
55         .long \val
56 .endm
57 #else
58 .macro __BUG_REL val:req
59         .long \val - 2b
60 .endm
61 #endif
62
63 #ifdef CONFIG_DEBUG_BUGVERBOSE
64
65 .macro ASM_BUG ins:req file:req line:req flags:req size:req
66 1:      \ins
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
72         .org 2b+\size
73         .popsection
74 .endm
75
76 #else /* !CONFIG_DEBUG_BUGVERBOSE */
77
78 .macro ASM_BUG ins:req file:req line:req flags:req size:req
79 1:      \ins
80         .pushsection __bug_table,"aw"
81 2:      __BUG_REL val=1b        # bug_entry::bug_addr
82         .word \flags            # bug_entry::flags
83         .org 2b+\size
84         .popsection
85 .endm
86
87 #endif /* CONFIG_DEBUG_BUGVERBOSE */
88
89 #else /* CONFIG_GENERIC_BUG */
90
91 .macro ASM_BUG ins:req file:req line:req flags:req size:req
92         \ins
93 .endm
94
95 #endif /* CONFIG_GENERIC_BUG */
96
97 #endif /* __ASSEMBLY__ */
98
99 #endif /* _ASM_X86_BUG_H */