blob: 6804d66427673ec314659944e65052b5dfba273e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_BUG_H
3#define _ASM_X86_BUG_H
Thomas Gleixner68fdc552007-10-17 17:19:30 +02004
Peter Zijlstra9a938482017-02-02 14:43:51 +01005#include <linux/stringify.h>
6
7/*
Peter Zijlstra3b3a3712018-02-09 13:16:59 +01008 * Despite that some emulators terminate on UD2, we use it for WARN().
Peter Zijlstra9a938482017-02-02 14:43:51 +01009 *
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010010 * Since various instruction decoders/specs disagree on the encoding of
11 * UD0/UD1.
Peter Zijlstra9a938482017-02-02 14:43:51 +010012 */
13
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010014#define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */
Peter Zijlstra9a938482017-02-02 14:43:51 +010015#define ASM_UD1 ".byte 0x0f, 0xb9" /* + ModRM */
16#define ASM_UD2 ".byte 0x0f, 0x0b"
17
18#define INSN_UD0 0xff0f
19#define INSN_UD2 0x0b0f
20
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010021#define LEN_UD2 2
Peter Zijlstra9a938482017-02-02 14:43:51 +010022
23#ifdef CONFIG_GENERIC_BUG
Thomas Gleixner68fdc552007-10-17 17:19:30 +020024
Peter Zijlstra9a938482017-02-02 14:43:51 +010025#ifdef CONFIG_X86_32
26# define __BUG_REL(val) ".long " __stringify(val)
27#else
28# define __BUG_REL(val) ".long " __stringify(val) " - 2b"
29#endif
30
Thomas Gleixner68fdc552007-10-17 17:19:30 +020031#ifdef CONFIG_DEBUG_BUGVERBOSE
32
Peter Zijlstra9a938482017-02-02 14:43:51 +010033#define _BUG_FLAGS(ins, flags) \
34do { \
35 asm volatile("1:\t" ins "\n" \
Josh Poimboeuf325cdac2017-07-15 00:10:58 -050036 ".pushsection __bug_table,\"aw\"\n" \
Peter Zijlstra9a938482017-02-02 14:43:51 +010037 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
38 "\t" __BUG_REL(%c0) "\t# bug_entry::file\n" \
39 "\t.word %c1" "\t# bug_entry::line\n" \
40 "\t.word %c2" "\t# bug_entry::flags\n" \
41 "\t.org 2b+%c3\n" \
42 ".popsection" \
43 : : "i" (__FILE__), "i" (__LINE__), \
44 "i" (flags), \
45 "i" (sizeof(struct bug_entry))); \
46} while (0)
47
48#else /* !CONFIG_DEBUG_BUGVERBOSE */
49
50#define _BUG_FLAGS(ins, flags) \
51do { \
52 asm volatile("1:\t" ins "\n" \
Josh Poimboeuf325cdac2017-07-15 00:10:58 -050053 ".pushsection __bug_table,\"aw\"\n" \
Peter Zijlstra9a938482017-02-02 14:43:51 +010054 "2:\t" __BUG_REL(1b) "\t# bug_entry::bug_addr\n" \
55 "\t.word %c0" "\t# bug_entry::flags\n" \
56 "\t.org 2b+%c1\n" \
57 ".popsection" \
58 : : "i" (flags), \
59 "i" (sizeof(struct bug_entry))); \
60} while (0)
61
62#endif /* CONFIG_DEBUG_BUGVERBOSE */
Thomas Gleixner68fdc552007-10-17 17:19:30 +020063
Arnd Bergmann70579a82017-03-29 23:16:31 +020064#else
65
66#define _BUG_FLAGS(ins, flags) asm volatile(ins)
67
68#endif /* CONFIG_GENERIC_BUG */
69
70#define HAVE_ARCH_BUG
Joe Perches86d8a082008-03-23 01:01:46 -070071#define BUG() \
72do { \
Peter Zijlstra9a938482017-02-02 14:43:51 +010073 _BUG_FLAGS(ASM_UD2, 0); \
David Daneya5fc5eb2009-12-04 17:44:51 -080074 unreachable(); \
Joe Perches86d8a082008-03-23 01:01:46 -070075} while (0)
Thomas Gleixner68fdc552007-10-17 17:19:30 +020076
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060077#define __WARN_FLAGS(flags) \
78do { \
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010079 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060080 annotate_reachable(); \
81} while (0)
Peter Zijlstra9a938482017-02-02 14:43:51 +010082
Thomas Gleixner68fdc552007-10-17 17:19:30 +020083#include <asm-generic/bug.h>
David Howellsf05e7982012-03-28 18:11:12 +010084
H. Peter Anvin1965aae2008-10-22 22:26:29 -070085#endif /* _ASM_X86_BUG_H */