Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 2 | |
| 3 | .section ".text._idt", "ax", @progbits |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 4 | #if ENV_X86_64 |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 5 | .code64 |
| 6 | #else |
| 7 | .code32 |
| 8 | #endif |
Aaron Durbin | 4b032e4 | 2018-04-20 01:39:30 -0600 | [diff] [blame] | 9 | .global vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9 |
| 10 | .global vec10, vec11, vec12, vec13, vec14, vec15, vec16, vec17, vec18, vec19 |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 11 | vec0: |
| 12 | push $0 /* error code */ |
| 13 | push $0 /* vector */ |
| 14 | jmp int_hand |
| 15 | vec1: |
| 16 | push $0 /* error code */ |
| 17 | push $1 /* vector */ |
| 18 | jmp int_hand |
| 19 | |
| 20 | vec2: |
| 21 | push $0 /* error code */ |
| 22 | push $2 /* vector */ |
| 23 | jmp int_hand |
| 24 | |
| 25 | vec3: |
| 26 | push $0 /* error code */ |
| 27 | push $3 /* vector */ |
| 28 | jmp int_hand |
| 29 | |
| 30 | vec4: |
| 31 | push $0 /* error code */ |
| 32 | push $4 /* vector */ |
| 33 | jmp int_hand |
| 34 | |
| 35 | vec5: |
| 36 | push $0 /* error code */ |
| 37 | push $5 /* vector */ |
| 38 | jmp int_hand |
| 39 | |
| 40 | vec6: |
| 41 | push $0 /* error code */ |
| 42 | push $6 /* vector */ |
| 43 | jmp int_hand |
| 44 | |
| 45 | vec7: |
| 46 | push $0 /* error code */ |
| 47 | push $7 /* vector */ |
| 48 | jmp int_hand |
| 49 | |
| 50 | vec8: |
| 51 | /* error code */ |
| 52 | push $8 /* vector */ |
| 53 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 54 | |
| 55 | vec9: |
| 56 | push $0 /* error code */ |
| 57 | push $9 /* vector */ |
| 58 | jmp int_hand |
| 59 | |
| 60 | vec10: |
| 61 | /* error code */ |
| 62 | push $10 /* vector */ |
| 63 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 64 | |
| 65 | vec11: |
| 66 | /* error code */ |
| 67 | push $11 /* vector */ |
| 68 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 69 | |
| 70 | vec12: |
| 71 | /* error code */ |
| 72 | push $12 /* vector */ |
| 73 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 74 | |
| 75 | vec13: |
| 76 | /* error code */ |
| 77 | push $13 /* vector */ |
| 78 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 79 | |
| 80 | vec14: |
| 81 | /* error code */ |
| 82 | push $14 /* vector */ |
| 83 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 84 | |
| 85 | vec15: |
| 86 | push $0 /* error code */ |
| 87 | push $15 /* vector */ |
| 88 | jmp int_hand |
| 89 | |
| 90 | vec16: |
| 91 | push $0 /* error code */ |
| 92 | push $16 /* vector */ |
| 93 | jmp int_hand |
| 94 | |
| 95 | vec17: |
| 96 | /* error code */ |
| 97 | push $17 /* vector */ |
| 98 | jmp int_hand |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 99 | |
| 100 | vec18: |
| 101 | push $0 /* error code */ |
| 102 | push $18 /* vector */ |
| 103 | jmp int_hand |
| 104 | |
| 105 | vec19: |
| 106 | push $0 /* error code */ |
| 107 | push $19 /* vector */ |
| 108 | jmp int_hand |
| 109 | |
| 110 | .global int_hand |
| 111 | int_hand: |
Patrick Rudolph | adcf782 | 2020-08-27 20:50:18 +0200 | [diff] [blame] | 112 | #if ENV_X86_64 |
Paul Menzel | 6663ad9 | 2019-06-24 18:44:33 +0200 | [diff] [blame] | 113 | /* At this point, on x86-64, on the stack there is: |
| 114 | * 0(%rsp) vector |
| 115 | * 8(%rsp) error code |
| 116 | * 16(%rsp) rip |
| 117 | * 24(%rsp) cs |
| 118 | * 32(%rsp) rflags |
| 119 | * 40(%rsp) rsp |
| 120 | * 48(%rsp) ss |
| 121 | */ |
| 122 | push %r15 |
| 123 | push %r14 |
| 124 | push %r13 |
| 125 | push %r12 |
| 126 | push %r11 |
| 127 | push %r10 |
| 128 | push %r9 |
| 129 | push %r8 |
| 130 | |
| 131 | push %rdi |
| 132 | push %rsi |
| 133 | push %rbp |
| 134 | |
| 135 | push %rbx |
| 136 | push %rdx |
| 137 | push %rcx |
| 138 | push %rax |
| 139 | |
| 140 | /* Pass pointer to struct as first argument */ |
| 141 | mov %rsp, %rdi |
| 142 | |
| 143 | /* Back up stack pointer */ |
| 144 | mov %rsp, %rbp |
| 145 | |
| 146 | /* Align stack to 16 bytes. */ |
| 147 | and $(~0xf), %rsp |
| 148 | |
| 149 | call x86_exception |
| 150 | |
| 151 | /* Restore stack pointer from backup */ |
| 152 | mov %rbp, %rsp |
| 153 | |
| 154 | pop %rax |
| 155 | pop %rcx |
| 156 | pop %rdx |
| 157 | pop %rbx |
| 158 | |
| 159 | pop %rbp |
| 160 | pop %rsi |
| 161 | pop %rdi |
| 162 | |
| 163 | pop %r8 |
| 164 | pop %r9 |
| 165 | pop %r10 |
| 166 | pop %r11 |
| 167 | pop %r12 |
| 168 | pop %r13 |
| 169 | pop %r14 |
| 170 | pop %r15 |
| 171 | |
| 172 | add $16, %rsp /* pop of the vector and error code */ |
Elyes HAOUAS | 3cd00db | 2022-01-24 08:48:34 +0100 | [diff] [blame] | 173 | iretq |
Paul Menzel | 6663ad9 | 2019-06-24 18:44:33 +0200 | [diff] [blame] | 174 | #else |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 175 | /* At this point, on x86-32, on the stack there is: |
| 176 | * 0(%esp) vector |
| 177 | * 4(%esp) error code |
| 178 | * 8(%esp) eip |
| 179 | * 12(%esp) cs |
| 180 | * 16(%esp) eflags |
| 181 | */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 182 | pushl %edi |
| 183 | pushl %esi |
| 184 | pushl %ebp |
| 185 | |
| 186 | /* Original stack pointer */ |
| 187 | leal 32(%esp), %ebp |
| 188 | pushl %ebp |
| 189 | pushl %ebx |
| 190 | pushl %edx |
| 191 | pushl %ecx |
| 192 | pushl %eax |
| 193 | |
Aaron Durbin | 38fd668 | 2018-04-21 00:14:08 -0600 | [diff] [blame] | 194 | /* Save pointer to eregs structure */ |
| 195 | movl %esp, %ebp |
| 196 | /* Align stack to 16 bytes. */ |
| 197 | andl $0xfffffff0, %esp |
| 198 | /* Save original stack pointer while keeping stack alignment. This |
| 199 | value is also the eregs argument x86_exception(). */ |
| 200 | sub $12, %esp |
| 201 | pushl %ebp /* Pointer to structure on the stack */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 202 | call x86_exception |
Aaron Durbin | 38fd668 | 2018-04-21 00:14:08 -0600 | [diff] [blame] | 203 | pop %esp /* Unwind the stack alignment and argument passing. */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 204 | |
| 205 | popl %eax |
| 206 | popl %ecx |
| 207 | popl %edx |
| 208 | popl %ebx |
| 209 | popl %ebp /* Ignore saved %esp value */ |
| 210 | popl %ebp |
| 211 | popl %esi |
| 212 | popl %edi |
| 213 | |
| 214 | addl $8, %esp /* pop of the vector and error code */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 215 | iret |
Elyes HAOUAS | 3cd00db | 2022-01-24 08:48:34 +0100 | [diff] [blame] | 216 | #endif |