Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 1 | /* 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 Gleixner | 0ba50e8 | 2020-03-26 16:28:52 +0100 | [diff] [blame] | 10 | void idtentry_enter(struct pt_regs *regs); |
| 11 | void idtentry_exit(struct pt_regs *regs); |
| 12 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 13 | /** |
| 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) \ |
| 47 | static __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 | \ |
| 58 | static __always_inline void __##func(struct pt_regs *regs) |
| 59 | |
Thomas Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 60 | /** |
| 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) \ |
| 87 | static __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 | \ |
| 100 | static __always_inline void __##func(struct pt_regs *regs, \ |
| 101 | unsigned long error_code) |
| 102 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 103 | #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 Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 111 | #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ |
| 112 | idtentry vector asm_##func func has_error_code=1 sane=1 |
| 113 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 114 | #endif /* __ASSEMBLY__ */ |
| 115 | |
Thomas Gleixner | 9d06c40 | 2020-02-25 23:16:14 +0100 | [diff] [blame] | 116 | /* |
| 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 */ |
| 126 | DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error); |
Thomas Gleixner | 4b6b911 | 2020-02-25 23:16:15 +0100 | [diff] [blame] | 127 | DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow); |
Thomas Gleixner | 58d9c81 | 2020-02-25 23:16:17 +0100 | [diff] [blame] | 128 | DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds); |
Thomas Gleixner | 49893c5 | 2020-02-25 23:16:18 +0100 | [diff] [blame] | 129 | DECLARE_IDTENTRY(X86_TRAP_UD, exc_invalid_op); |
Thomas Gleixner | 866ae2c | 2020-02-25 23:16:19 +0100 | [diff] [blame] | 130 | DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available); |
Thomas Gleixner | f95658f | 2020-02-25 23:16:20 +0100 | [diff] [blame] | 131 | DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun); |
Thomas Gleixner | 9d06c40 | 2020-02-25 23:16:14 +0100 | [diff] [blame] | 132 | |
Thomas Gleixner | 97b3d29 | 2020-02-25 23:16:22 +0100 | [diff] [blame] | 133 | /* Simple exception entries with error code pushed by hardware */ |
| 134 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss); |
Thomas Gleixner | 99a3fb8 | 2020-02-25 23:16:23 +0100 | [diff] [blame^] | 135 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_NP, exc_segment_not_present); |
Thomas Gleixner | 97b3d29 | 2020-02-25 23:16:22 +0100 | [diff] [blame] | 136 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 137 | #endif |