blob: aa6b2023d8f8bc104e0b30a086a4c981ed47abb1 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_BUG_H
2#define _ASM_X86_BUG_H
Thomas Gleixner68fdc552007-10-17 17:19:30 +02003
Peter Zijlstra9a938482017-02-02 14:43:51 +01004#include <linux/stringify.h>
5
6/*
7 * Since some emulators terminate on UD2, we cannot use it for WARN.
8 * Since various instruction decoders disagree on the length of UD1,
9 * we cannot use it either. So use UD0 for WARN.
10 *
11 * (binutils knows about "ud1" but {en,de}codes it as 2 bytes, whereas
12 * our kernel decoder thinks it takes a ModRM byte, which seems consistent
13 * with various things like the Intel SDM instruction encoding rules)
14 */
15
16#define ASM_UD0 ".byte 0x0f, 0xff"
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_UD0 2
24
25#ifdef CONFIG_GENERIC_BUG
Thomas Gleixner68fdc552007-10-17 17:19:30 +020026
Peter Zijlstra9a938482017-02-02 14:43:51 +010027#ifdef CONFIG_X86_32
28# define __BUG_REL(val) ".long " __stringify(val)
29#else
30# define __BUG_REL(val) ".long " __stringify(val) " - 2b"
31#endif
32
Thomas Gleixner68fdc552007-10-17 17:19:30 +020033#ifdef CONFIG_DEBUG_BUGVERBOSE
34
Peter Zijlstra9a938482017-02-02 14:43:51 +010035#define _BUG_FLAGS(ins, flags) \
36do { \
37 asm volatile("1:\t" ins "\n" \
Josh Poimboeuf325cdac2017-07-15 00:10:58 -050038 ".pushsection __bug_table,\"aw\"\n" \
Peter Zijlstra9a938482017-02-02 14:43:51 +010039 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
40 "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
41 "\t.word %c1" "\t# bug_entry::line\n" \
42 "\t.word %c2" "\t# bug_entry::flags\n" \
43 "\t.org 2b+%c3\n" \
44 ".popsection" \
45 : : "i" (__FILE__), "i" (__LINE__), \
46 "i" (flags), \
47 "i" (sizeof(struct bug_entry))); \
48} while (0)
49
50#else /* !CONFIG_DEBUG_BUGVERBOSE */
51
52#define _BUG_FLAGS(ins, flags) \
53do { \
54 asm volatile("1:\t" ins "\n" \
Josh Poimboeuf325cdac2017-07-15 00:10:58 -050055 ".pushsection __bug_table,\"aw\"\n" \
Peter Zijlstra9a938482017-02-02 14:43:51 +010056 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
57 "\t.word %c0" "\t# bug_entry::flags\n" \
58 "\t.org 2b+%c1\n" \
59 ".popsection" \
60 : : "i" (flags), \
61 "i" (sizeof(struct bug_entry))); \
62} while (0)
63
64#endif /* CONFIG_DEBUG_BUGVERBOSE */
Thomas Gleixner68fdc552007-10-17 17:19:30 +020065
Arnd Bergmann70579a82017-03-29 23:16:31 +020066#else
67
68#define _BUG_FLAGS(ins, flags) asm volatile(ins)
69
70#endif /* CONFIG_GENERIC_BUG */
71
72#define HAVE_ARCH_BUG
Joe Perches86d8a082008-03-23 01:01:46 -070073#define BUG() \
74do { \
Peter Zijlstra9a938482017-02-02 14:43:51 +010075 _BUG_FLAGS(ASM_UD2, 0); \
David Daneya5fc5eb2009-12-04 17:44:51 -080076 unreachable(); \
Joe Perches86d8a082008-03-23 01:01:46 -070077} while (0)
Thomas Gleixner68fdc552007-10-17 17:19:30 +020078
Peter Zijlstra19d43622017-02-25 08:56:53 +010079#define __WARN_FLAGS(flags) _BUG_FLAGS(ASM_UD0, BUGFLAG_WARNING|(flags))
Peter Zijlstra9a938482017-02-02 14:43:51 +010080
Thomas Gleixner68fdc552007-10-17 17:19:30 +020081#include <asm-generic/bug.h>
David Howellsf05e7982012-03-28 18:11:12 +010082
H. Peter Anvin1965aae2008-10-22 22:26:29 -070083#endif /* _ASM_X86_BUG_H */