Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 2 | #ifndef _ASM_X86_BUG_H |
| 3 | #define _ASM_X86_BUG_H |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 4 | |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 5 | #include <linux/stringify.h> |
| 6 | |
| 7 | /* |
| 8 | * Since some emulators terminate on UD2, we cannot use it for WARN. |
| 9 | * Since various instruction decoders disagree on the length of UD1, |
| 10 | * we cannot use it either. So use UD0 for WARN. |
| 11 | * |
| 12 | * (binutils knows about "ud1" but {en,de}codes it as 2 bytes, whereas |
| 13 | * our kernel decoder thinks it takes a ModRM byte, which seems consistent |
| 14 | * with various things like the Intel SDM instruction encoding rules) |
| 15 | */ |
| 16 | |
| 17 | #define ASM_UD0 ".byte 0x0f, 0xff" |
| 18 | #define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */ |
| 19 | #define ASM_UD2 ".byte 0x0f, 0x0b" |
| 20 | |
| 21 | #define INSN_UD0 0xff0f |
| 22 | #define INSN_UD2 0x0b0f |
| 23 | |
| 24 | #define LEN_UD0 2 |
| 25 | |
| 26 | #ifdef CONFIG_GENERIC_BUG |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 27 | |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 28 | #ifdef CONFIG_X86_32 |
| 29 | # define __BUG_REL(val) ".long " __stringify(val) |
| 30 | #else |
| 31 | # define __BUG_REL(val) ".long " __stringify(val) " - 2b" |
| 32 | #endif |
| 33 | |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 34 | #ifdef CONFIG_DEBUG_BUGVERBOSE |
| 35 | |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 36 | #define _BUG_FLAGS(ins, flags) \ |
| 37 | do { \ |
| 38 | asm volatile("1:\t" ins "\n" \ |
Josh Poimboeuf | 325cdac | 2017-07-15 00:10:58 -0500 | [diff] [blame] | 39 | ".pushsection __bug_table,\"aw\"\n" \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 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))); \ |
| 49 | } while (0) |
| 50 | |
| 51 | #else /* !CONFIG_DEBUG_BUGVERBOSE */ |
| 52 | |
| 53 | #define _BUG_FLAGS(ins, flags) \ |
| 54 | do { \ |
| 55 | asm volatile("1:\t" ins "\n" \ |
Josh Poimboeuf | 325cdac | 2017-07-15 00:10:58 -0500 | [diff] [blame] | 56 | ".pushsection __bug_table,\"aw\"\n" \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 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 */ |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 66 | |
Arnd Bergmann | 70579a8 | 2017-03-29 23:16:31 +0200 | [diff] [blame] | 67 | #else |
| 68 | |
| 69 | #define _BUG_FLAGS(ins, flags) asm volatile(ins) |
| 70 | |
| 71 | #endif /* CONFIG_GENERIC_BUG */ |
| 72 | |
| 73 | #define HAVE_ARCH_BUG |
Joe Perches | 86d8a08 | 2008-03-23 01:01:46 -0700 | [diff] [blame] | 74 | #define BUG() \ |
| 75 | do { \ |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 76 | _BUG_FLAGS(ASM_UD2, 0); \ |
David Daney | a5fc5eb | 2009-12-04 17:44:51 -0800 | [diff] [blame] | 77 | unreachable(); \ |
Joe Perches | 86d8a08 | 2008-03-23 01:01:46 -0700 | [diff] [blame] | 78 | } while (0) |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 79 | |
Josh Poimboeuf | 2b5db66 | 2018-02-08 17:09:26 -0600 | [diff] [blame^] | 80 | #define __WARN_FLAGS(flags) \ |
| 81 | do { \ |
| 82 | _BUG_FLAGS(ASM_UD0, BUGFLAG_WARNING|(flags)); \ |
| 83 | annotate_reachable(); \ |
| 84 | } while (0) |
Peter Zijlstra | 9a93848 | 2017-02-02 14:43:51 +0100 | [diff] [blame] | 85 | |
Thomas Gleixner | 68fdc55 | 2007-10-17 17:19:30 +0200 | [diff] [blame] | 86 | #include <asm-generic/bug.h> |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame] | 87 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 88 | #endif /* _ASM_X86_BUG_H */ |