1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_TRAPS_H
3#define _ASM_X86_TRAPS_H
4
5#include <linux/context_tracking_state.h>
6#include <linux/kprobes.h>
7
8#include <asm/debugreg.h>
9#include <asm/siginfo.h> /* TRAP_TRACE, ... */
10
11#define dotraplinkage __visible
12
13asmlinkage void divide_error(void);
14asmlinkage void debug(void);
15asmlinkage void nmi(void);
16asmlinkage void int3(void);
17asmlinkage void overflow(void);
18asmlinkage void bounds(void);
19asmlinkage void invalid_op(void);
20asmlinkage void device_not_available(void);
21#ifdef CONFIG_X86_64
22asmlinkage void double_fault(void);
23#endif
24asmlinkage void coprocessor_segment_overrun(void);
25asmlinkage void invalid_TSS(void);
26asmlinkage void segment_not_present(void);
27asmlinkage void stack_segment(void);
28asmlinkage void general_protection(void);
29asmlinkage void page_fault(void);
30asmlinkage void async_page_fault(void);
31asmlinkage void spurious_interrupt_bug(void);
32asmlinkage void coprocessor_error(void);
33asmlinkage void alignment_check(void);
34#ifdef CONFIG_X86_MCE
35asmlinkage void machine_check(void);
36#endif /* CONFIG_X86_MCE */
37asmlinkage void simd_coprocessor_error(void);
38
39#if defined(CONFIG_X86_64) && defined(CONFIG_XEN_PV)
40asmlinkage void xen_divide_error(void);
41asmlinkage void xen_xennmi(void);
42asmlinkage void xen_xendebug(void);
43asmlinkage void xen_xenint3(void);
44asmlinkage void xen_overflow(void);
45asmlinkage void xen_bounds(void);
46asmlinkage void xen_invalid_op(void);
47asmlinkage void xen_device_not_available(void);
48asmlinkage void xen_double_fault(void);
49asmlinkage void xen_coprocessor_segment_overrun(void);
50asmlinkage void xen_invalid_TSS(void);
51asmlinkage void xen_segment_not_present(void);
52asmlinkage void xen_stack_segment(void);
53asmlinkage void xen_general_protection(void);
54asmlinkage void xen_page_fault(void);
55asmlinkage void xen_spurious_interrupt_bug(void);
56asmlinkage void xen_coprocessor_error(void);
57asmlinkage void xen_alignment_check(void);
58#ifdef CONFIG_X86_MCE
59asmlinkage void xen_machine_check(void);
60#endif /* CONFIG_X86_MCE */
61asmlinkage void xen_simd_coprocessor_error(void);
62#endif
63
64dotraplinkage void do_divide_error(struct pt_regs *regs, long error_code);
65dotraplinkage void do_debug(struct pt_regs *regs, long error_code);
66dotraplinkage void do_nmi(struct pt_regs *regs, long error_code);
67dotraplinkage void do_int3(struct pt_regs *regs, long error_code);
68dotraplinkage void do_overflow(struct pt_regs *regs, long error_code);
69dotraplinkage void do_bounds(struct pt_regs *regs, long error_code);
70dotraplinkage void do_invalid_op(struct pt_regs *regs, long error_code);
71dotraplinkage void do_device_not_available(struct pt_regs *regs, long error_code);
72dotraplinkage void do_coprocessor_segment_overrun(struct pt_regs *regs, long error_code);
73dotraplinkage void do_invalid_TSS(struct pt_regs *regs, long error_code);
74dotraplinkage void do_segment_not_present(struct pt_regs *regs, long error_code);
75dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code);
76#ifdef CONFIG_X86_64
77dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code);
78asmlinkage __visible notrace struct pt_regs *sync_regs(struct pt_regs *eregs);
79asmlinkage __visible notrace
80struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s);
81void __init trap_init(void);
82#endif
83dotraplinkage void do_general_protection(struct pt_regs *regs, long error_code);
84dotraplinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code);
85dotraplinkage void do_spurious_interrupt_bug(struct pt_regs *regs, long error_code);
86dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code);
87dotraplinkage void do_alignment_check(struct pt_regs *regs, long error_code);
88#ifdef CONFIG_X86_MCE
89dotraplinkage void do_machine_check(struct pt_regs *regs, long error_code);
90#endif
91dotraplinkage void do_simd_coprocessor_error(struct pt_regs *regs, long error_code);
92#ifdef CONFIG_X86_32
93dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code);
94#endif
95dotraplinkage void do_mce(struct pt_regs *regs, long error_code);
96
97static inline int get_si_code(unsigned long condition)
98{
99 if (condition & DR_STEP)
100 return TRAP_TRACE;
101 else if (condition & (DR_TRAP0|DR_TRAP1|DR_TRAP2|DR_TRAP3))
102 return TRAP_HWBKPT;
103 else
104 return TRAP_BRKPT;
105}
106
107extern int panic_on_unrecovered_nmi;
108
109void math_emulate(struct math_emu_info *);
110#ifndef CONFIG_X86_32
111asmlinkage void smp_thermal_interrupt(struct pt_regs *regs);
112asmlinkage void smp_threshold_interrupt(struct pt_regs *regs);
113asmlinkage void smp_deferred_error_interrupt(struct pt_regs *regs);
114#endif
115
116void smp_apic_timer_interrupt(struct pt_regs *regs);
117void smp_spurious_interrupt(struct pt_regs *regs);
118void smp_error_interrupt(struct pt_regs *regs);
119asmlinkage void smp_irq_move_cleanup_interrupt(void);
120
121extern void ist_enter(struct pt_regs *regs);
122extern void ist_exit(struct pt_regs *regs);
123extern void ist_begin_non_atomic(struct pt_regs *regs);
124extern void ist_end_non_atomic(void);
125
126#ifdef CONFIG_VMAP_STACK
127void __noreturn handle_stack_overflow(const char *message,
128 struct pt_regs *regs,
129 unsigned long fault_address);
130#endif
131
132/* Interrupts/Exceptions */
133enum {
134 X86_TRAP_DE = 0, /* 0, Divide-by-zero */
135 X86_TRAP_DB, /* 1, Debug */
136 X86_TRAP_NMI, /* 2, Non-maskable Interrupt */
137 X86_TRAP_BP, /* 3, Breakpoint */
138 X86_TRAP_OF, /* 4, Overflow */
139 X86_TRAP_BR, /* 5, Bound Range Exceeded */
140 X86_TRAP_UD, /* 6, Invalid Opcode */
141 X86_TRAP_NM, /* 7, Device Not Available */
142 X86_TRAP_DF, /* 8, Double Fault */
143 X86_TRAP_OLD_MF, /* 9, Coprocessor Segment Overrun */
144 X86_TRAP_TS, /* 10, Invalid TSS */
145 X86_TRAP_NP, /* 11, Segment Not Present */
146 X86_TRAP_SS, /* 12, Stack Segment Fault */
147 X86_TRAP_GP, /* 13, General Protection Fault */
148 X86_TRAP_PF, /* 14, Page Fault */
149 X86_TRAP_SPURIOUS, /* 15, Spurious Interrupt */
150 X86_TRAP_MF, /* 16, x87 Floating-Point Exception */
151 X86_TRAP_AC, /* 17, Alignment Check */
152 X86_TRAP_MC, /* 18, Machine Check */
153 X86_TRAP_XF, /* 19, SIMD Floating-Point Exception */
154 X86_TRAP_IRET = 32, /* 32, IRET Exception */
155};
156
157/*
158 * Page fault error code bits:
159 *
160 * bit 0 == 0: no page found 1: protection fault
161 * bit 1 == 0: read access 1: write access
162 * bit 2 == 0: kernel-mode access 1: user-mode access
163 * bit 3 == 1: use of reserved bit detected
164 * bit 4 == 1: fault was an instruction fetch
165 * bit 5 == 1: protection keys block access
166 */
167enum x86_pf_error_code {
168 X86_PF_PROT = 1 << 0,
169 X86_PF_WRITE = 1 << 1,
170 X86_PF_USER = 1 << 2,
171 X86_PF_RSVD = 1 << 3,
172 X86_PF_INSTR = 1 << 4,
173 X86_PF_PK = 1 << 5,
174};
175#endif /* _ASM_X86_TRAPS_H */
176