blob: d517c09e8d0b817a371fcb91b2c3c02c44bc69fd [file] [log] [blame]
Thomas Gleixner53aaf262020-02-25 23:16:12 +01001/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_X86_IDTENTRY_H
3#define _ASM_X86_IDTENTRY_H
4
5/* Interrupts/Exceptions */
6#include <asm/trapnr.h>
7
8#ifndef __ASSEMBLY__
9
Thomas Gleixner0ba50e82020-03-26 16:28:52 +010010void idtentry_enter(struct pt_regs *regs);
11void idtentry_exit(struct pt_regs *regs);
12
Thomas Gleixner53aaf262020-02-25 23:16:12 +010013/**
14 * DECLARE_IDTENTRY - Declare functions for simple IDT entry points
15 * No error code pushed by hardware
16 * @vector: Vector number (ignored for C)
17 * @func: Function name of the entry point
18 *
19 * Declares three functions:
20 * - The ASM entry point: asm_##func
21 * - The XEN PV trap entry point: xen_##func (maybe unused)
22 * - The C handler called from the ASM entry point
23 *
24 * Note: This is the C variant of DECLARE_IDTENTRY(). As the name says it
25 * declares the entry points for usage in C code. There is an ASM variant
26 * as well which is used to emit the entry stubs in entry_32/64.S.
27 */
28#define DECLARE_IDTENTRY(vector, func) \
29 asmlinkage void asm_##func(void); \
30 asmlinkage void xen_asm_##func(void); \
31 __visible void func(struct pt_regs *regs)
32
33/**
34 * DEFINE_IDTENTRY - Emit code for simple IDT entry points
35 * @func: Function name of the entry point
36 *
37 * @func is called from ASM entry code with interrupts disabled.
38 *
39 * The macro is written so it acts as function definition. Append the
40 * body with a pair of curly brackets.
41 *
42 * idtentry_enter() contains common code which has to be invoked before
43 * arbitrary code in the body. idtentry_exit() contains common code
44 * which has to run before returning to the low level assembly code.
45 */
46#define DEFINE_IDTENTRY(func) \
47static __always_inline void __##func(struct pt_regs *regs); \
48 \
49__visible noinstr void func(struct pt_regs *regs) \
50{ \
51 idtentry_enter(regs); \
52 instrumentation_begin(); \
53 __##func (regs); \
54 instrumentation_end(); \
55 idtentry_exit(regs); \
56} \
57 \
58static __always_inline void __##func(struct pt_regs *regs)
59
Thomas Gleixneraabfe532020-02-25 23:16:21 +010060/**
61 * DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points
62 * Error code pushed by hardware
63 * @vector: Vector number (ignored for C)
64 * @func: Function name of the entry point
65 *
66 * Declares three functions:
67 * - The ASM entry point: asm_##func
68 * - The XEN PV trap entry point: xen_##func (maybe unused)
69 * - The C handler called from the ASM entry point
70 *
71 * Same as DECLARE_IDTENTRY, but has an extra error_code argument for the
72 * C-handler.
73 */
74#define DECLARE_IDTENTRY_ERRORCODE(vector, func) \
75 asmlinkage void asm_##func(void); \
76 asmlinkage void xen_asm_##func(void); \
77 __visible void func(struct pt_regs *regs, unsigned long error_code)
78
79/**
80 * DEFINE_IDTENTRY_ERRORCODE - Emit code for simple IDT entry points
81 * Error code pushed by hardware
82 * @func: Function name of the entry point
83 *
84 * Same as DEFINE_IDTENTRY, but has an extra error_code argument
85 */
86#define DEFINE_IDTENTRY_ERRORCODE(func) \
87static __always_inline void __##func(struct pt_regs *regs, \
88 unsigned long error_code); \
89 \
90__visible noinstr void func(struct pt_regs *regs, \
91 unsigned long error_code) \
92{ \
93 idtentry_enter(regs); \
94 instrumentation_begin(); \
95 __##func (regs, error_code); \
96 instrumentation_end(); \
97 idtentry_exit(regs); \
98} \
99 \
100static __always_inline void __##func(struct pt_regs *regs, \
101 unsigned long error_code)
102
Thomas Gleixner53aaf262020-02-25 23:16:12 +0100103#else /* !__ASSEMBLY__ */
104
105/*
106 * The ASM variants for DECLARE_IDTENTRY*() which emit the ASM entry stubs.
107 */
108#define DECLARE_IDTENTRY(vector, func) \
109 idtentry vector asm_##func func has_error_code=0 sane=1
110
Thomas Gleixneraabfe532020-02-25 23:16:21 +0100111#define DECLARE_IDTENTRY_ERRORCODE(vector, func) \
112 idtentry vector asm_##func func has_error_code=1 sane=1
113
Thomas Gleixner53aaf262020-02-25 23:16:12 +0100114#endif /* __ASSEMBLY__ */
115
Thomas Gleixner9d06c402020-02-25 23:16:14 +0100116/*
117 * The actual entry points. Note that DECLARE_IDTENTRY*() serves two
118 * purposes:
119 * - provide the function declarations when included from C-Code
120 * - emit the ASM stubs when included from entry_32/64.S
121 *
122 * This avoids duplicate defines and ensures that everything is consistent.
123 */
124
125/* Simple exception entry points. No hardware error code */
126DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error);
Thomas Gleixner4b6b9112020-02-25 23:16:15 +0100127DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow);
Thomas Gleixner58d9c812020-02-25 23:16:17 +0100128DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds);
Thomas Gleixner49893c52020-02-25 23:16:18 +0100129DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalid_op);
Thomas Gleixner866ae2c2020-02-25 23:16:19 +0100130DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available);
Thomas Gleixnerf95658f2020-02-25 23:16:20 +0100131DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun);
Thomas Gleixner9d06c402020-02-25 23:16:14 +0100132
Thomas Gleixner97b3d292020-02-25 23:16:22 +0100133/* Simple exception entries with error code pushed by hardware */
134DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss);
Thomas Gleixner99a3fb82020-02-25 23:16:23 +0100135DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_NP, exc_segment_not_present);
Thomas Gleixner97b3d292020-02-25 23:16:22 +0100136
Thomas Gleixner53aaf262020-02-25 23:16:12 +0100137#endif