|
1 | 1 | #ifndef _ASM_X86_BUG_H |
2 | 2 | #define _ASM_X86_BUG_H |
3 | 3 |
|
4 | | -#define HAVE_ARCH_BUG |
| 4 | +#include <linux/stringify.h> |
5 | 5 |
|
6 | | -#ifdef CONFIG_DEBUG_BUGVERBOSE |
| 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 |
| 26 | +#define HAVE_ARCH_BUG |
7 | 27 |
|
8 | 28 | #ifdef CONFIG_X86_32 |
9 | | -# define __BUG_C0 "2:\t.long 1b, %c0\n" |
| 29 | +# define __BUG_REL(val) ".long " __stringify(val) |
10 | 30 | #else |
11 | | -# define __BUG_C0 "2:\t.long 1b - 2b, %c0 - 2b\n" |
| 31 | +# define __BUG_REL(val) ".long " __stringify(val) " - 2b" |
12 | 32 | #endif |
13 | 33 |
|
14 | | -#define BUG() \ |
15 | | -do { \ |
16 | | - asm volatile("1:\tud2\n" \ |
17 | | - ".pushsection __bug_table,\"a\"\n" \ |
18 | | - __BUG_C0 \ |
19 | | - "\t.word %c1, 0\n" \ |
20 | | - "\t.org 2b+%c2\n" \ |
21 | | - ".popsection" \ |
22 | | - : : "i" (__FILE__), "i" (__LINE__), \ |
23 | | - "i" (sizeof(struct bug_entry))); \ |
24 | | - unreachable(); \ |
| 34 | +#ifdef CONFIG_DEBUG_BUGVERBOSE |
| 35 | + |
| 36 | +#define _BUG_FLAGS(ins, flags) \ |
| 37 | +do { \ |
| 38 | + asm volatile("1:\t" ins "\n" \ |
| 39 | + ".pushsection __bug_table,\"a\"\n" \ |
| 40 | + "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ |
| 41 | + "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \ |
| 42 | + "\t.word %c1" "\t# bug_entry::line\n" \ |
| 43 | + "\t.word %c2" "\t# bug_entry::flags\n" \ |
| 44 | + "\t.org 2b+%c3\n" \ |
| 45 | + ".popsection" \ |
| 46 | + : : "i" (__FILE__), "i" (__LINE__), \ |
| 47 | + "i" (flags), \ |
| 48 | + "i" (sizeof(struct bug_entry))); \ |
25 | 49 | } while (0) |
26 | 50 |
|
27 | | -#else |
| 51 | +#else /* !CONFIG_DEBUG_BUGVERBOSE */ |
| 52 | + |
| 53 | +#define _BUG_FLAGS(ins, flags) \ |
| 54 | +do { \ |
| 55 | + asm volatile("1:\t" ins "\n" \ |
| 56 | + ".pushsection __bug_table,\"a\"\n" \ |
| 57 | + "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \ |
| 58 | + "\t.word %c0" "\t# bug_entry::flags\n" \ |
| 59 | + "\t.org 2b+%c1\n" \ |
| 60 | + ".popsection" \ |
| 61 | + : : "i" (flags), \ |
| 62 | + "i" (sizeof(struct bug_entry))); \ |
| 63 | +} while (0) |
| 64 | + |
| 65 | +#endif /* CONFIG_DEBUG_BUGVERBOSE */ |
| 66 | + |
28 | 67 | #define BUG() \ |
29 | 68 | do { \ |
30 | | - asm volatile("ud2"); \ |
| 69 | + _BUG_FLAGS(ASM_UD2, 0); \ |
31 | 70 | unreachable(); \ |
32 | 71 | } while (0) |
33 | | -#endif |
| 72 | + |
| 73 | +#define __WARN_TAINT(taint) _BUG_FLAGS(ASM_UD0, BUGFLAG_TAINT(taint)) |
| 74 | + |
| 75 | +#endif /* CONFIG_GENERIC_BUG */ |
34 | 76 |
|
35 | 77 | #include <asm-generic/bug.h> |
36 | 78 |
|
|
0 commit comments