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 |
| 4 | #ifdef __x86_64__ |
| 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: |
Paul Menzel | 6663ad9 | 2019-06-24 18:44:33 +0200 | [diff] [blame] | 112 | #ifdef __x86_64__ |
| 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 */ |
| 173 | #else |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 174 | /* At this point, on x86-32, on the stack there is: |
| 175 | * 0(%esp) vector |
| 176 | * 4(%esp) error code |
| 177 | * 8(%esp) eip |
| 178 | * 12(%esp) cs |
| 179 | * 16(%esp) eflags |
| 180 | */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 181 | pushl %edi |
| 182 | pushl %esi |
| 183 | pushl %ebp |
| 184 | |
| 185 | /* Original stack pointer */ |
| 186 | leal 32(%esp), %ebp |
| 187 | pushl %ebp |
| 188 | pushl %ebx |
| 189 | pushl %edx |
| 190 | pushl %ecx |
| 191 | pushl %eax |
| 192 | |
Aaron Durbin | 38fd668 | 2018-04-21 00:14:08 -0600 | [diff] [blame] | 193 | /* Save pointer to eregs structure */ |
| 194 | movl %esp, %ebp |
| 195 | /* Align stack to 16 bytes. */ |
| 196 | andl $0xfffffff0, %esp |
| 197 | /* Save original stack pointer while keeping stack alignment. This |
| 198 | value is also the eregs argument x86_exception(). */ |
| 199 | sub $12, %esp |
| 200 | pushl %ebp /* Pointer to structure on the stack */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 201 | call x86_exception |
Aaron Durbin | 38fd668 | 2018-04-21 00:14:08 -0600 | [diff] [blame] | 202 | pop %esp /* Unwind the stack alignment and argument passing. */ |
Aaron Durbin | 7a7c70b | 2018-04-20 00:56:57 -0600 | [diff] [blame] | 203 | |
| 204 | popl %eax |
| 205 | popl %ecx |
| 206 | popl %edx |
| 207 | popl %ebx |
| 208 | popl %ebp /* Ignore saved %esp value */ |
| 209 | popl %ebp |
| 210 | popl %esi |
| 211 | popl %edi |
| 212 | |
| 213 | addl $8, %esp /* pop of the vector and error code */ |
| 214 | #endif |
| 215 | |
| 216 | iret |