blob: 5090035e6d160fed62820f4eb40a363bb6dff763 [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
Nadav Amitf81f8ad2018-10-03 14:30:56 -07007#ifndef __ASSEMBLY__
8
Peter Zijlstra9a938482017-02-02 14:43:51 +01009/*
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010010 * Despite that some emulators terminate on UD2, we use it for WARN().
Peter Zijlstra9a938482017-02-02 14:43:51 +010011 *
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010012 * Since various instruction decoders/specs disagree on the encoding of
13 * UD0/UD1.
Peter Zijlstra9a938482017-02-02 14:43:51 +010014 */
15
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010016#define ASM_UD0 ".byte 0x0f, 0xff" /* + ModRM (for Intel) */
Peter Zijlstra9a938482017-02-02 14:43:51 +010017#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
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010023#define LEN_UD2 2
Peter Zijlstra9a938482017-02-02 14:43:51 +010024
Peter Zijlstra9a938482017-02-02 14:43:51 +010025#define _BUG_FLAGS(ins, flags) \
26do { \
Nadav Amitf81f8ad2018-10-03 14:30:56 -070027 asm volatile("ASM_BUG ins=\"" ins "\" file=%c0 line=%c1 " \
28 "flags=%c2 size=%c3" \
29 : : "i" (__FILE__), "i" (__LINE__), \
30 "i" (flags), \
Peter Zijlstra9a938482017-02-02 14:43:51 +010031 "i" (sizeof(struct bug_entry))); \
32} while (0)
33
Arnd Bergmann70579a82017-03-29 23:16:31 +020034#define HAVE_ARCH_BUG
Joe Perches86d8a082008-03-23 01:01:46 -070035#define BUG() \
36do { \
Peter Zijlstra9a938482017-02-02 14:43:51 +010037 _BUG_FLAGS(ASM_UD2, 0); \
David Daneya5fc5eb2009-12-04 17:44:51 -080038 unreachable(); \
Joe Perches86d8a082008-03-23 01:01:46 -070039} while (0)
Thomas Gleixner68fdc552007-10-17 17:19:30 +020040
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060041#define __WARN_FLAGS(flags) \
42do { \
Peter Zijlstra3b3a3712018-02-09 13:16:59 +010043 _BUG_FLAGS(ASM_UD2, BUGFLAG_WARNING|(flags)); \
Josh Poimboeuf2b5db662018-02-08 17:09:26 -060044 annotate_reachable(); \
45} while (0)
Peter Zijlstra9a938482017-02-02 14:43:51 +010046
Thomas Gleixner68fdc552007-10-17 17:19:30 +020047#include <asm-generic/bug.h>
David Howellsf05e7982012-03-28 18:11:12 +010048
Nadav Amitf81f8ad2018-10-03 14:30:56 -070049#else /* __ASSEMBLY__ */
50
51#ifdef CONFIG_GENERIC_BUG
52
53#ifdef CONFIG_X86_32
54.macro __BUG_REL val:req
55 .long \val
56.endm
57#else
58.macro __BUG_REL val:req
59 .long \val - 2b
60.endm
61#endif
62
63#ifdef CONFIG_DEBUG_BUGVERBOSE
64
65.macro ASM_BUG ins:req file:req line:req flags:req size:req
661: \ins
67 .pushsection __bug_table,"aw"
682: __BUG_REL val=1b # bug_entry::bug_addr
69 __BUG_REL val=\file # bug_entry::file
70 .word \line # bug_entry::line
71 .word \flags # bug_entry::flags
72 .org 2b+\size
73 .popsection
74.endm
75
76#else /* !CONFIG_DEBUG_BUGVERBOSE */
77
78.macro ASM_BUG ins:req file:req line:req flags:req size:req
791: \ins
80 .pushsection __bug_table,"aw"
812: __BUG_REL val=1b # bug_entry::bug_addr
82 .word \flags # bug_entry::flags
83 .org 2b+\size
84 .popsection
85.endm
86
87#endif /* CONFIG_DEBUG_BUGVERBOSE */
88
89#else /* CONFIG_GENERIC_BUG */
90
91.macro ASM_BUG ins:req file:req line:req flags:req size:req
92 \ins
93.endm
94
95#endif /* CONFIG_GENERIC_BUG */
96
97#endif /* __ASSEMBLY__ */
98
H. Peter Anvin1965aae2008-10-22 22:26:29 -070099#endif /* _ASM_X86_BUG_H */