1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_IDTENTRY_H
3 #define _ASM_X86_IDTENTRY_H
5 /* Interrupts/Exceptions */
6 #include <asm/trapnr.h>
10 void idtentry_enter(struct pt_regs *regs);
11 void idtentry_exit(struct pt_regs *regs);
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
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
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.
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)
34 * DEFINE_IDTENTRY - Emit code for simple IDT entry points
35 * @func: Function name of the entry point
37 * @func is called from ASM entry code with interrupts disabled.
39 * The macro is written so it acts as function definition. Append the
40 * body with a pair of curly brackets.
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.
46 #define DEFINE_IDTENTRY(func) \
47 static __always_inline void __##func(struct pt_regs *regs); \
49 __visible noinstr void func(struct pt_regs *regs) \
51 idtentry_enter(regs); \
52 instrumentation_begin(); \
54 instrumentation_end(); \
55 idtentry_exit(regs); \
58 static __always_inline void __##func(struct pt_regs *regs)
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
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
71 * Same as DECLARE_IDTENTRY, but has an extra error_code argument for the
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)
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
84 * Same as DEFINE_IDTENTRY, but has an extra error_code argument
86 #define DEFINE_IDTENTRY_ERRORCODE(func) \
87 static __always_inline void __##func(struct pt_regs *regs, \
88 unsigned long error_code); \
90 __visible noinstr void func(struct pt_regs *regs, \
91 unsigned long error_code) \
93 idtentry_enter(regs); \
94 instrumentation_begin(); \
95 __##func (regs, error_code); \
96 instrumentation_end(); \
97 idtentry_exit(regs); \
100 static __always_inline void __##func(struct pt_regs *regs, \
101 unsigned long error_code)
103 #else /* !__ASSEMBLY__ */
106 * The ASM variants for DECLARE_IDTENTRY*() which emit the ASM entry stubs.
108 #define DECLARE_IDTENTRY(vector, func) \
109 idtentry vector asm_##func func has_error_code=0 sane=1
111 #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \
112 idtentry vector asm_##func func has_error_code=1 sane=1
114 #endif /* __ASSEMBLY__ */
117 * The actual entry points. Note that DECLARE_IDTENTRY*() serves two
119 * - provide the function declarations when included from C-Code
120 * - emit the ASM stubs when included from entry_32/64.S
122 * This avoids duplicate defines and ensures that everything is consistent.
125 /* Simple exception entry points. No hardware error code */
126 DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error);
127 DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow);
128 DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds);
129 DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalid_op);
130 DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available);
131 DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun);
133 /* Simple exception entries with error code pushed by hardware */
134 DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss);