blob: 99d6e95ec55951d735587a39eae94d1c4c118228 [file] [log] [blame]
Patrick Georgi11f00792020-03-04 15:10:45 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin7a7c70b2018-04-20 00:56:57 -06002
3 .section ".text._idt", "ax", @progbits
Patrick Rudolphadcf7822020-08-27 20:50:18 +02004#if ENV_X86_64
Aaron Durbin7a7c70b2018-04-20 00:56:57 -06005 .code64
6#else
7 .code32
8#endif
Aaron Durbin4b032e42018-04-20 01:39:30 -06009.global vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9
10.global vec10, vec11, vec12, vec13, vec14, vec15, vec16, vec17, vec18, vec19
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060011vec0:
12 push $0 /* error code */
13 push $0 /* vector */
14 jmp int_hand
15vec1:
16 push $0 /* error code */
17 push $1 /* vector */
18 jmp int_hand
19
20vec2:
21 push $0 /* error code */
22 push $2 /* vector */
23 jmp int_hand
24
25vec3:
26 push $0 /* error code */
27 push $3 /* vector */
28 jmp int_hand
29
30vec4:
31 push $0 /* error code */
32 push $4 /* vector */
33 jmp int_hand
34
35vec5:
36 push $0 /* error code */
37 push $5 /* vector */
38 jmp int_hand
39
40vec6:
41 push $0 /* error code */
42 push $6 /* vector */
43 jmp int_hand
44
45vec7:
46 push $0 /* error code */
47 push $7 /* vector */
48 jmp int_hand
49
50vec8:
51 /* error code */
52 push $8 /* vector */
53 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060054
55vec9:
56 push $0 /* error code */
57 push $9 /* vector */
58 jmp int_hand
59
60vec10:
61 /* error code */
62 push $10 /* vector */
63 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060064
65vec11:
66 /* error code */
67 push $11 /* vector */
68 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060069
70vec12:
71 /* error code */
72 push $12 /* vector */
73 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060074
75vec13:
76 /* error code */
77 push $13 /* vector */
78 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060079
80vec14:
81 /* error code */
82 push $14 /* vector */
83 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060084
85vec15:
86 push $0 /* error code */
87 push $15 /* vector */
88 jmp int_hand
89
90vec16:
91 push $0 /* error code */
92 push $16 /* vector */
93 jmp int_hand
94
95vec17:
96 /* error code */
97 push $17 /* vector */
98 jmp int_hand
Aaron Durbin7a7c70b2018-04-20 00:56:57 -060099
100vec18:
101 push $0 /* error code */
102 push $18 /* vector */
103 jmp int_hand
104
105vec19:
106 push $0 /* error code */
107 push $19 /* vector */
108 jmp int_hand
109
110.global int_hand
111int_hand:
Patrick Rudolphadcf7822020-08-27 20:50:18 +0200112#if ENV_X86_64
Paul Menzel6663ad92019-06-24 18:44:33 +0200113 /* 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 HAOUAS3cd00db2022-01-24 08:48:34 +0100173 iretq
Paul Menzel6663ad92019-06-24 18:44:33 +0200174#else
Aaron Durbin7a7c70b2018-04-20 00:56:57 -0600175 /* 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 Durbin7a7c70b2018-04-20 00:56:57 -0600182 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 Durbin38fd6682018-04-21 00:14:08 -0600194 /* 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 Durbin7a7c70b2018-04-20 00:56:57 -0600202 call x86_exception
Aaron Durbin38fd6682018-04-21 00:14:08 -0600203 pop %esp /* Unwind the stack alignment and argument passing. */
Aaron Durbin7a7c70b2018-04-20 00:56:57 -0600204
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 Durbin7a7c70b2018-04-20 00:56:57 -0600215 iret
Elyes HAOUAS3cd00db2022-01-24 08:48:34 +0100216#endif