1
2#ifndef _ASM_X86_BUG_H
3#define _ASM_X86_BUG_H
4
5#include <linux/stringify.h>
6#include <linux/instrumentation.h>
7
8
9
10
11#define ASM_UD2 ".byte 0x0f, 0x0b"
12#define INSN_UD2 0x0b0f
13#define LEN_UD2 2
14
15#ifdef CONFIG_GENERIC_BUG
16
17#ifdef CONFIG_X86_32
18# define __BUG_REL(val) ".long " __stringify(val)
19#else
20# define __BUG_REL(val) ".long " __stringify(val) " - 2b"
21#endif
22
23#ifdef CONFIG_DEBUG_BUGVERBOSE
24
25#define _BUG_FLAGS(ins, flags) \
26do { \
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" \
33 "\t.org 2b+%c3\n" \
34 ".popsection" \
35 : : "i" (__FILE__), "i" (__LINE__), \
36 "i" (flags), \
37 "i" (sizeof(struct bug_entry))); \
38} while (0)
39
40#else
41
42#define _BUG_FLAGS(ins, flags) \
43do { \
44 asm_inline volatile("1:\t" ins "\n" \
45 ".pushsection __bug_table,\"aw\"\n" \
46 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
47 "\t.word %c0" "\t# bug_entry::flags\n" \
48 "\t.org 2b+%c1\n" \
49 ".popsection" \
50 : : "i" (flags), \
51 "i" (sizeof(struct bug_entry))); \
52} while (0)
53
54#endif
55
56#else
57
58#define _BUG_FLAGS(ins, flags) asm volatile(ins)
59
60#endif
61
62#define HAVE_ARCH_BUG
63#define BUG() \
64do { \
65 instrumentation_begin(); \
66 _BUG_FLAGS(ASM_UD2, 0); \
67 unreachable(); \
68} while (0)
69
70
71
72
73
74
75
76#define __WARN_FLAGS(flags) \
77do { \
78 instrumentation_begin(); \
79 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
80 annotate_reachable(); \
81 instrumentation_end(); \
82} while (0)
83
84#include <asm-generic/bug.h>
85
86#endif
87