]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
a49976d1 | 2 | * Copyright (C) 1991,1992 Linus Torvalds |
1da177e4 | 3 | * |
a49976d1 | 4 | * entry_32.S contains the system-call and low-level fault and trap handling routines. |
1da177e4 | 5 | * |
39e8701f | 6 | * Stack layout while running C code: |
a49976d1 IM |
7 | * ptrace needs to have all registers on the stack. |
8 | * If the order here is changed, it needs to be | |
9 | * updated in fork.c:copy_process(), signal.c:do_signal(), | |
1da177e4 LT |
10 | * ptrace.c and ptrace.h |
11 | * | |
12 | * 0(%esp) - %ebx | |
13 | * 4(%esp) - %ecx | |
14 | * 8(%esp) - %edx | |
9b47feb7 | 15 | * C(%esp) - %esi |
1da177e4 LT |
16 | * 10(%esp) - %edi |
17 | * 14(%esp) - %ebp | |
18 | * 18(%esp) - %eax | |
19 | * 1C(%esp) - %ds | |
20 | * 20(%esp) - %es | |
464d1a78 | 21 | * 24(%esp) - %fs |
ccbeed3a TH |
22 | * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS |
23 | * 2C(%esp) - orig_eax | |
24 | * 30(%esp) - %eip | |
25 | * 34(%esp) - %cs | |
26 | * 38(%esp) - %eflags | |
27 | * 3C(%esp) - %oldesp | |
28 | * 40(%esp) - %oldss | |
1da177e4 LT |
29 | */ |
30 | ||
1da177e4 | 31 | #include <linux/linkage.h> |
d7e7528b | 32 | #include <linux/err.h> |
1da177e4 | 33 | #include <asm/thread_info.h> |
55f327fa | 34 | #include <asm/irqflags.h> |
1da177e4 LT |
35 | #include <asm/errno.h> |
36 | #include <asm/segment.h> | |
37 | #include <asm/smp.h> | |
0341c14d | 38 | #include <asm/page_types.h> |
be44d2aa | 39 | #include <asm/percpu.h> |
ab68ed98 | 40 | #include <asm/processor-flags.h> |
395a59d0 | 41 | #include <asm/ftrace.h> |
9b7dc567 | 42 | #include <asm/irq_vectors.h> |
cd4d09ec | 43 | #include <asm/cpufeatures.h> |
b4ca46e4 | 44 | #include <asm/alternative-asm.h> |
6837a54d | 45 | #include <asm/asm.h> |
e59d1b0a | 46 | #include <asm/smap.h> |
1da177e4 | 47 | |
ea714547 JO |
48 | .section .entry.text, "ax" |
49 | ||
139ec7c4 RR |
50 | /* |
51 | * We use macros for low-level operations which need to be overridden | |
52 | * for paravirtualization. The following will never clobber any registers: | |
53 | * INTERRUPT_RETURN (aka. "iret") | |
54 | * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax") | |
d75cd22f | 55 | * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit"). |
139ec7c4 RR |
56 | * |
57 | * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must | |
58 | * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY). | |
59 | * Allowing a register to be clobbered can shrink the paravirt replacement | |
60 | * enough to patch inline, increasing performance. | |
61 | */ | |
62 | ||
1da177e4 | 63 | #ifdef CONFIG_PREEMPT |
a49976d1 | 64 | # define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF |
1da177e4 | 65 | #else |
a49976d1 IM |
66 | # define preempt_stop(clobbers) |
67 | # define resume_kernel restore_all | |
1da177e4 LT |
68 | #endif |
69 | ||
55f327fa IM |
70 | .macro TRACE_IRQS_IRET |
71 | #ifdef CONFIG_TRACE_IRQFLAGS | |
a49976d1 IM |
72 | testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off? |
73 | jz 1f | |
55f327fa IM |
74 | TRACE_IRQS_ON |
75 | 1: | |
76 | #endif | |
77 | .endm | |
78 | ||
ccbeed3a TH |
79 | /* |
80 | * User gs save/restore | |
81 | * | |
82 | * %gs is used for userland TLS and kernel only uses it for stack | |
83 | * canary which is required to be at %gs:20 by gcc. Read the comment | |
84 | * at the top of stackprotector.h for more info. | |
85 | * | |
86 | * Local labels 98 and 99 are used. | |
87 | */ | |
88 | #ifdef CONFIG_X86_32_LAZY_GS | |
89 | ||
90 | /* unfortunately push/pop can't be no-op */ | |
91 | .macro PUSH_GS | |
a49976d1 | 92 | pushl $0 |
ccbeed3a TH |
93 | .endm |
94 | .macro POP_GS pop=0 | |
a49976d1 | 95 | addl $(4 + \pop), %esp |
ccbeed3a TH |
96 | .endm |
97 | .macro POP_GS_EX | |
98 | .endm | |
99 | ||
100 | /* all the rest are no-op */ | |
101 | .macro PTGS_TO_GS | |
102 | .endm | |
103 | .macro PTGS_TO_GS_EX | |
104 | .endm | |
105 | .macro GS_TO_REG reg | |
106 | .endm | |
107 | .macro REG_TO_PTGS reg | |
108 | .endm | |
109 | .macro SET_KERNEL_GS reg | |
110 | .endm | |
111 | ||
112 | #else /* CONFIG_X86_32_LAZY_GS */ | |
113 | ||
114 | .macro PUSH_GS | |
a49976d1 | 115 | pushl %gs |
ccbeed3a TH |
116 | .endm |
117 | ||
118 | .macro POP_GS pop=0 | |
a49976d1 | 119 | 98: popl %gs |
ccbeed3a | 120 | .if \pop <> 0 |
9b47feb7 | 121 | add $\pop, %esp |
ccbeed3a TH |
122 | .endif |
123 | .endm | |
124 | .macro POP_GS_EX | |
125 | .pushsection .fixup, "ax" | |
a49976d1 IM |
126 | 99: movl $0, (%esp) |
127 | jmp 98b | |
ccbeed3a | 128 | .popsection |
a49976d1 | 129 | _ASM_EXTABLE(98b, 99b) |
ccbeed3a TH |
130 | .endm |
131 | ||
132 | .macro PTGS_TO_GS | |
a49976d1 | 133 | 98: mov PT_GS(%esp), %gs |
ccbeed3a TH |
134 | .endm |
135 | .macro PTGS_TO_GS_EX | |
136 | .pushsection .fixup, "ax" | |
a49976d1 IM |
137 | 99: movl $0, PT_GS(%esp) |
138 | jmp 98b | |
ccbeed3a | 139 | .popsection |
a49976d1 | 140 | _ASM_EXTABLE(98b, 99b) |
ccbeed3a TH |
141 | .endm |
142 | ||
143 | .macro GS_TO_REG reg | |
a49976d1 | 144 | movl %gs, \reg |
ccbeed3a TH |
145 | .endm |
146 | .macro REG_TO_PTGS reg | |
a49976d1 | 147 | movl \reg, PT_GS(%esp) |
ccbeed3a TH |
148 | .endm |
149 | .macro SET_KERNEL_GS reg | |
a49976d1 IM |
150 | movl $(__KERNEL_STACK_CANARY), \reg |
151 | movl \reg, %gs | |
ccbeed3a TH |
152 | .endm |
153 | ||
a49976d1 | 154 | #endif /* CONFIG_X86_32_LAZY_GS */ |
ccbeed3a | 155 | |
150ac78d | 156 | .macro SAVE_ALL pt_regs_ax=%eax |
f0d96110 | 157 | cld |
ccbeed3a | 158 | PUSH_GS |
a49976d1 IM |
159 | pushl %fs |
160 | pushl %es | |
161 | pushl %ds | |
150ac78d | 162 | pushl \pt_regs_ax |
a49976d1 IM |
163 | pushl %ebp |
164 | pushl %edi | |
165 | pushl %esi | |
166 | pushl %edx | |
167 | pushl %ecx | |
168 | pushl %ebx | |
169 | movl $(__USER_DS), %edx | |
170 | movl %edx, %ds | |
171 | movl %edx, %es | |
172 | movl $(__KERNEL_PERCPU), %edx | |
173 | movl %edx, %fs | |
ccbeed3a | 174 | SET_KERNEL_GS %edx |
f0d96110 | 175 | .endm |
1da177e4 | 176 | |
f0d96110 | 177 | .macro RESTORE_INT_REGS |
a49976d1 IM |
178 | popl %ebx |
179 | popl %ecx | |
180 | popl %edx | |
181 | popl %esi | |
182 | popl %edi | |
183 | popl %ebp | |
184 | popl %eax | |
f0d96110 | 185 | .endm |
1da177e4 | 186 | |
ccbeed3a | 187 | .macro RESTORE_REGS pop=0 |
f0d96110 | 188 | RESTORE_INT_REGS |
a49976d1 IM |
189 | 1: popl %ds |
190 | 2: popl %es | |
191 | 3: popl %fs | |
ccbeed3a | 192 | POP_GS \pop |
f0d96110 | 193 | .pushsection .fixup, "ax" |
a49976d1 IM |
194 | 4: movl $0, (%esp) |
195 | jmp 1b | |
196 | 5: movl $0, (%esp) | |
197 | jmp 2b | |
198 | 6: movl $0, (%esp) | |
199 | jmp 3b | |
f95d47ca | 200 | .popsection |
a49976d1 IM |
201 | _ASM_EXTABLE(1b, 4b) |
202 | _ASM_EXTABLE(2b, 5b) | |
203 | _ASM_EXTABLE(3b, 6b) | |
ccbeed3a | 204 | POP_GS_EX |
f0d96110 | 205 | .endm |
1da177e4 | 206 | |
1da177e4 | 207 | ENTRY(ret_from_fork) |
a49976d1 IM |
208 | pushl %eax |
209 | call schedule_tail | |
a49976d1 | 210 | popl %eax |
39e8701f AL |
211 | |
212 | /* When we fork, we trace the syscall return in the child, too. */ | |
213 | movl %esp, %eax | |
214 | call syscall_return_slowpath | |
215 | jmp restore_all | |
47a55cd7 | 216 | END(ret_from_fork) |
1da177e4 | 217 | |
22e2430d | 218 | ENTRY(ret_from_kernel_thread) |
a49976d1 IM |
219 | pushl %eax |
220 | call schedule_tail | |
a49976d1 | 221 | popl %eax |
a49976d1 IM |
222 | movl PT_EBP(%esp), %eax |
223 | call *PT_EBX(%esp) | |
224 | movl $0, PT_EAX(%esp) | |
39e8701f AL |
225 | |
226 | /* | |
227 | * Kernel threads return to userspace as if returning from a syscall. | |
228 | * We should check whether anything actually uses this path and, if so, | |
229 | * consider switching it over to ret_from_fork. | |
230 | */ | |
231 | movl %esp, %eax | |
232 | call syscall_return_slowpath | |
233 | jmp restore_all | |
22e2430d | 234 | ENDPROC(ret_from_kernel_thread) |
6783eaa2 | 235 | |
1da177e4 LT |
236 | /* |
237 | * Return to user mode is not as complex as all this looks, | |
238 | * but we want the default path for a system call return to | |
239 | * go as quickly as possible which is why some of this is | |
240 | * less clear than it otherwise should be. | |
241 | */ | |
242 | ||
243 | # userspace resumption stub bypassing syscall exit tracing | |
244 | ALIGN | |
245 | ret_from_exception: | |
139ec7c4 | 246 | preempt_stop(CLBR_ANY) |
1da177e4 | 247 | ret_from_intr: |
29a2e283 | 248 | #ifdef CONFIG_VM86 |
a49976d1 IM |
249 | movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS |
250 | movb PT_CS(%esp), %al | |
251 | andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax | |
29a2e283 DA |
252 | #else |
253 | /* | |
6783eaa2 | 254 | * We can be coming here from child spawned by kernel_thread(). |
29a2e283 | 255 | */ |
a49976d1 IM |
256 | movl PT_CS(%esp), %eax |
257 | andl $SEGMENT_RPL_MASK, %eax | |
29a2e283 | 258 | #endif |
a49976d1 IM |
259 | cmpl $USER_RPL, %eax |
260 | jb resume_kernel # not returning to v8086 or userspace | |
f95d47ca | 261 | |
1da177e4 | 262 | ENTRY(resume_userspace) |
5d73fc70 | 263 | DISABLE_INTERRUPTS(CLBR_ANY) |
e32e58a9 | 264 | TRACE_IRQS_OFF |
5d73fc70 AL |
265 | movl %esp, %eax |
266 | call prepare_exit_to_usermode | |
a49976d1 | 267 | jmp restore_all |
47a55cd7 | 268 | END(ret_from_exception) |
1da177e4 LT |
269 | |
270 | #ifdef CONFIG_PREEMPT | |
271 | ENTRY(resume_kernel) | |
139ec7c4 | 272 | DISABLE_INTERRUPTS(CLBR_ANY) |
1da177e4 | 273 | need_resched: |
a49976d1 IM |
274 | cmpl $0, PER_CPU_VAR(__preempt_count) |
275 | jnz restore_all | |
276 | testl $X86_EFLAGS_IF, PT_EFLAGS(%esp) # interrupts off (exception path) ? | |
277 | jz restore_all | |
278 | call preempt_schedule_irq | |
279 | jmp need_resched | |
47a55cd7 | 280 | END(resume_kernel) |
1da177e4 LT |
281 | #endif |
282 | ||
f2b37575 AL |
283 | GLOBAL(__begin_SYSENTER_singlestep_region) |
284 | /* | |
285 | * All code from here through __end_SYSENTER_singlestep_region is subject | |
286 | * to being single-stepped if a user program sets TF and executes SYSENTER. | |
287 | * There is absolutely nothing that we can do to prevent this from happening | |
288 | * (thanks Intel!). To keep our handling of this situation as simple as | |
289 | * possible, we handle TF just like AC and NT, except that our #DB handler | |
290 | * will ignore all of the single-step traps generated in this range. | |
291 | */ | |
292 | ||
293 | #ifdef CONFIG_XEN | |
294 | /* | |
295 | * Xen doesn't set %esp to be precisely what the normal SYSENTER | |
296 | * entry point expects, so fix it up before using the normal path. | |
297 | */ | |
298 | ENTRY(xen_sysenter_target) | |
299 | addl $5*4, %esp /* remove xen-provided frame */ | |
300 | jmp sysenter_past_esp | |
301 | #endif | |
302 | ||
fda57b22 AL |
303 | /* |
304 | * 32-bit SYSENTER entry. | |
305 | * | |
306 | * 32-bit system calls through the vDSO's __kernel_vsyscall enter here | |
307 | * if X86_FEATURE_SEP is available. This is the preferred system call | |
308 | * entry on 32-bit systems. | |
309 | * | |
310 | * The SYSENTER instruction, in principle, should *only* occur in the | |
311 | * vDSO. In practice, a small number of Android devices were shipped | |
312 | * with a copy of Bionic that inlined a SYSENTER instruction. This | |
313 | * never happened in any of Google's Bionic versions -- it only happened | |
314 | * in a narrow range of Intel-provided versions. | |
315 | * | |
316 | * SYSENTER loads SS, ESP, CS, and EIP from previously programmed MSRs. | |
317 | * IF and VM in RFLAGS are cleared (IOW: interrupts are off). | |
318 | * SYSENTER does not save anything on the stack, | |
319 | * and does not save old EIP (!!!), ESP, or EFLAGS. | |
320 | * | |
321 | * To avoid losing track of EFLAGS.VM (and thus potentially corrupting | |
322 | * user and/or vm86 state), we explicitly disable the SYSENTER | |
323 | * instruction in vm86 mode by reprogramming the MSRs. | |
324 | * | |
325 | * Arguments: | |
326 | * eax system call number | |
327 | * ebx arg1 | |
328 | * ecx arg2 | |
329 | * edx arg3 | |
330 | * esi arg4 | |
331 | * edi arg5 | |
332 | * ebp user stack | |
333 | * 0(%ebp) arg6 | |
334 | */ | |
4c8cd0c5 | 335 | ENTRY(entry_SYSENTER_32) |
a49976d1 | 336 | movl TSS_sysenter_sp0(%esp), %esp |
1da177e4 | 337 | sysenter_past_esp: |
5f310f73 | 338 | pushl $__USER_DS /* pt_regs->ss */ |
30bfa7b3 | 339 | pushl %ebp /* pt_regs->sp (stashed in bp) */ |
5f310f73 AL |
340 | pushfl /* pt_regs->flags (except IF = 0) */ |
341 | orl $X86_EFLAGS_IF, (%esp) /* Fix IF */ | |
342 | pushl $__USER_CS /* pt_regs->cs */ | |
343 | pushl $0 /* pt_regs->ip = 0 (placeholder) */ | |
344 | pushl %eax /* pt_regs->orig_ax */ | |
345 | SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */ | |
346 | ||
67f590e8 | 347 | /* |
f2b37575 AL |
348 | * SYSENTER doesn't filter flags, so we need to clear NT, AC |
349 | * and TF ourselves. To save a few cycles, we can check whether | |
67f590e8 AL |
350 | * either was set instead of doing an unconditional popfq. |
351 | * This needs to happen before enabling interrupts so that | |
352 | * we don't get preempted with NT set. | |
353 | * | |
f2b37575 AL |
354 | * If TF is set, we will single-step all the way to here -- do_debug |
355 | * will ignore all the traps. (Yes, this is slow, but so is | |
356 | * single-stepping in general. This allows us to avoid having | |
357 | * a more complicated code to handle the case where a user program | |
358 | * forces us to single-step through the SYSENTER entry code.) | |
359 | * | |
67f590e8 AL |
360 | * NB.: .Lsysenter_fix_flags is a label with the code under it moved |
361 | * out-of-line as an optimization: NT is unlikely to be set in the | |
362 | * majority of the cases and instead of polluting the I$ unnecessarily, | |
363 | * we're keeping that code behind a branch which will predict as | |
364 | * not-taken and therefore its instructions won't be fetched. | |
365 | */ | |
f2b37575 | 366 | testl $X86_EFLAGS_NT|X86_EFLAGS_AC|X86_EFLAGS_TF, PT_EFLAGS(%esp) |
67f590e8 AL |
367 | jnz .Lsysenter_fix_flags |
368 | .Lsysenter_flags_fixed: | |
369 | ||
55f327fa | 370 | /* |
5f310f73 AL |
371 | * User mode is traced as though IRQs are on, and SYSENTER |
372 | * turned them off. | |
e6e5494c | 373 | */ |
55f327fa | 374 | TRACE_IRQS_OFF |
5f310f73 AL |
375 | |
376 | movl %esp, %eax | |
377 | call do_fast_syscall_32 | |
91e2eea9 BO |
378 | /* XEN PV guests always use IRET path */ |
379 | ALTERNATIVE "testl %eax, %eax; jz .Lsyscall_32_done", \ | |
380 | "jmp .Lsyscall_32_done", X86_FEATURE_XENPV | |
5f310f73 AL |
381 | |
382 | /* Opportunistic SYSEXIT */ | |
383 | TRACE_IRQS_ON /* User mode traces as IRQs on. */ | |
384 | movl PT_EIP(%esp), %edx /* pt_regs->ip */ | |
385 | movl PT_OLDESP(%esp), %ecx /* pt_regs->sp */ | |
3bd29515 AL |
386 | 1: mov PT_FS(%esp), %fs |
387 | PTGS_TO_GS | |
5f310f73 AL |
388 | popl %ebx /* pt_regs->bx */ |
389 | addl $2*4, %esp /* skip pt_regs->cx and pt_regs->dx */ | |
390 | popl %esi /* pt_regs->si */ | |
391 | popl %edi /* pt_regs->di */ | |
392 | popl %ebp /* pt_regs->bp */ | |
393 | popl %eax /* pt_regs->ax */ | |
5f310f73 | 394 | |
c2c9b52f AL |
395 | /* |
396 | * Restore all flags except IF. (We restore IF separately because | |
397 | * STI gives a one-instruction window in which we won't be interrupted, | |
398 | * whereas POPF does not.) | |
399 | */ | |
400 | addl $PT_EFLAGS-PT_DS, %esp /* point esp at pt_regs->flags */ | |
401 | btr $X86_EFLAGS_IF_BIT, (%esp) | |
402 | popfl | |
403 | ||
5f310f73 AL |
404 | /* |
405 | * Return back to the vDSO, which will pop ecx and edx. | |
406 | * Don't bother with DS and ES (they already contain __USER_DS). | |
407 | */ | |
88c15ec9 BO |
408 | sti |
409 | sysexit | |
af0575bb | 410 | |
a49976d1 IM |
411 | .pushsection .fixup, "ax" |
412 | 2: movl $0, PT_FS(%esp) | |
413 | jmp 1b | |
f95d47ca | 414 | .popsection |
a49976d1 | 415 | _ASM_EXTABLE(1b, 2b) |
ccbeed3a | 416 | PTGS_TO_GS_EX |
67f590e8 AL |
417 | |
418 | .Lsysenter_fix_flags: | |
419 | pushl $X86_EFLAGS_FIXED | |
420 | popfl | |
421 | jmp .Lsysenter_flags_fixed | |
f2b37575 | 422 | GLOBAL(__end_SYSENTER_singlestep_region) |
4c8cd0c5 | 423 | ENDPROC(entry_SYSENTER_32) |
1da177e4 | 424 | |
fda57b22 AL |
425 | /* |
426 | * 32-bit legacy system call entry. | |
427 | * | |
428 | * 32-bit x86 Linux system calls traditionally used the INT $0x80 | |
429 | * instruction. INT $0x80 lands here. | |
430 | * | |
431 | * This entry point can be used by any 32-bit perform system calls. | |
432 | * Instances of INT $0x80 can be found inline in various programs and | |
433 | * libraries. It is also used by the vDSO's __kernel_vsyscall | |
434 | * fallback for hardware that doesn't support a faster entry method. | |
435 | * Restarted 32-bit system calls also fall back to INT $0x80 | |
436 | * regardless of what instruction was originally used to do the system | |
437 | * call. (64-bit programs can use INT $0x80 as well, but they can | |
438 | * only run on 64-bit kernels and therefore land in | |
439 | * entry_INT80_compat.) | |
440 | * | |
441 | * This is considered a slow path. It is not used by most libc | |
442 | * implementations on modern hardware except during process startup. | |
443 | * | |
444 | * Arguments: | |
445 | * eax system call number | |
446 | * ebx arg1 | |
447 | * ecx arg2 | |
448 | * edx arg3 | |
449 | * esi arg4 | |
450 | * edi arg5 | |
451 | * ebp arg6 | |
452 | */ | |
b2502b41 | 453 | ENTRY(entry_INT80_32) |
e59d1b0a | 454 | ASM_CLAC |
150ac78d | 455 | pushl %eax /* pt_regs->orig_ax */ |
5f310f73 | 456 | SAVE_ALL pt_regs_ax=$-ENOSYS /* save rest */ |
150ac78d AL |
457 | |
458 | /* | |
a798f091 AL |
459 | * User mode is traced as though IRQs are on, and the interrupt gate |
460 | * turned them off. | |
150ac78d | 461 | */ |
a798f091 | 462 | TRACE_IRQS_OFF |
150ac78d AL |
463 | |
464 | movl %esp, %eax | |
a798f091 | 465 | call do_int80_syscall_32 |
5f310f73 | 466 | .Lsyscall_32_done: |
1da177e4 LT |
467 | |
468 | restore_all: | |
2e04bc76 AH |
469 | TRACE_IRQS_IRET |
470 | restore_all_notrace: | |
34273f41 | 471 | #ifdef CONFIG_X86_ESPFIX32 |
58a5aac5 AL |
472 | ALTERNATIVE "jmp restore_nocheck", "", X86_BUG_ESPFIX |
473 | ||
a49976d1 IM |
474 | movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS |
475 | /* | |
476 | * Warning: PT_OLDSS(%esp) contains the wrong/random values if we | |
477 | * are returning to the kernel. | |
478 | * See comments in process.c:copy_thread() for details. | |
479 | */ | |
480 | movb PT_OLDSS(%esp), %ah | |
481 | movb PT_CS(%esp), %al | |
482 | andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax | |
483 | cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax | |
484 | je ldt_ss # returning to user-space with LDT SS | |
34273f41 | 485 | #endif |
1da177e4 | 486 | restore_nocheck: |
a49976d1 | 487 | RESTORE_REGS 4 # skip orig_eax/error_code |
f7f3d791 | 488 | irq_return: |
3701d863 | 489 | INTERRUPT_RETURN |
a49976d1 IM |
490 | .section .fixup, "ax" |
491 | ENTRY(iret_exc ) | |
492 | pushl $0 # no error code | |
493 | pushl $do_iret_error | |
494 | jmp error_code | |
1da177e4 | 495 | .previous |
a49976d1 | 496 | _ASM_EXTABLE(irq_return, iret_exc) |
1da177e4 | 497 | |
34273f41 | 498 | #ifdef CONFIG_X86_ESPFIX32 |
1da177e4 | 499 | ldt_ss: |
dc4c2a0a AH |
500 | /* |
501 | * Setup and switch to ESPFIX stack | |
502 | * | |
503 | * We're returning to userspace with a 16 bit stack. The CPU will not | |
504 | * restore the high word of ESP for us on executing iret... This is an | |
505 | * "official" bug of all the x86-compatible CPUs, which we can work | |
506 | * around to make dosemu and wine happy. We do this by preloading the | |
507 | * high word of ESP with the high word of the userspace ESP while | |
508 | * compensating for the offset by changing to the ESPFIX segment with | |
509 | * a base address that matches for the difference. | |
510 | */ | |
72c511dd | 511 | #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8) |
a49976d1 IM |
512 | mov %esp, %edx /* load kernel esp */ |
513 | mov PT_OLDESP(%esp), %eax /* load userspace esp */ | |
514 | mov %dx, %ax /* eax: new kernel esp */ | |
9b47feb7 DV |
515 | sub %eax, %edx /* offset (low word is 0) */ |
516 | shr $16, %edx | |
a49976d1 IM |
517 | mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */ |
518 | mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */ | |
519 | pushl $__ESPFIX_SS | |
520 | pushl %eax /* new kernel esp */ | |
521 | /* | |
522 | * Disable interrupts, but do not irqtrace this section: we | |
2e04bc76 | 523 | * will soon execute iret and the tracer was already set to |
a49976d1 IM |
524 | * the irqstate after the IRET: |
525 | */ | |
139ec7c4 | 526 | DISABLE_INTERRUPTS(CLBR_EAX) |
a49976d1 IM |
527 | lss (%esp), %esp /* switch to espfix segment */ |
528 | jmp restore_nocheck | |
34273f41 | 529 | #endif |
b2502b41 | 530 | ENDPROC(entry_INT80_32) |
1da177e4 | 531 | |
f0d96110 | 532 | .macro FIXUP_ESPFIX_STACK |
dc4c2a0a AH |
533 | /* |
534 | * Switch back for ESPFIX stack to the normal zerobased stack | |
535 | * | |
536 | * We can't call C functions using the ESPFIX stack. This code reads | |
537 | * the high word of the segment base from the GDT and swiches to the | |
538 | * normal stack and adjusts ESP with the matching offset. | |
539 | */ | |
34273f41 | 540 | #ifdef CONFIG_X86_ESPFIX32 |
dc4c2a0a | 541 | /* fixup the stack */ |
a49976d1 IM |
542 | mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */ |
543 | mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */ | |
9b47feb7 | 544 | shl $16, %eax |
a49976d1 IM |
545 | addl %esp, %eax /* the adjusted stack pointer */ |
546 | pushl $__KERNEL_DS | |
547 | pushl %eax | |
548 | lss (%esp), %esp /* switch to the normal stack segment */ | |
34273f41 | 549 | #endif |
f0d96110 TH |
550 | .endm |
551 | .macro UNWIND_ESPFIX_STACK | |
34273f41 | 552 | #ifdef CONFIG_X86_ESPFIX32 |
a49976d1 | 553 | movl %ss, %eax |
f0d96110 | 554 | /* see if on espfix stack */ |
a49976d1 IM |
555 | cmpw $__ESPFIX_SS, %ax |
556 | jne 27f | |
557 | movl $__KERNEL_DS, %eax | |
558 | movl %eax, %ds | |
559 | movl %eax, %es | |
f0d96110 TH |
560 | /* switch to normal stack */ |
561 | FIXUP_ESPFIX_STACK | |
562 | 27: | |
34273f41 | 563 | #endif |
f0d96110 | 564 | .endm |
1da177e4 LT |
565 | |
566 | /* | |
3304c9c3 DV |
567 | * Build the entry stubs with some assembler magic. |
568 | * We pack 1 stub into every 8-byte block. | |
1da177e4 | 569 | */ |
3304c9c3 | 570 | .align 8 |
1da177e4 | 571 | ENTRY(irq_entries_start) |
3304c9c3 DV |
572 | vector=FIRST_EXTERNAL_VECTOR |
573 | .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR) | |
a49976d1 | 574 | pushl $(~vector+0x80) /* Note: always in signed byte range */ |
3304c9c3 DV |
575 | vector=vector+1 |
576 | jmp common_interrupt | |
3304c9c3 DV |
577 | .align 8 |
578 | .endr | |
47a55cd7 JB |
579 | END(irq_entries_start) |
580 | ||
55f327fa IM |
581 | /* |
582 | * the CPU automatically disables interrupts when executing an IRQ vector, | |
583 | * so IRQ-flags tracing has to follow that: | |
584 | */ | |
b7c6244f | 585 | .p2align CONFIG_X86_L1_CACHE_SHIFT |
1da177e4 | 586 | common_interrupt: |
e59d1b0a | 587 | ASM_CLAC |
a49976d1 | 588 | addl $-0x80, (%esp) /* Adjust vector into the [-256, -1] range */ |
1da177e4 | 589 | SAVE_ALL |
55f327fa | 590 | TRACE_IRQS_OFF |
a49976d1 IM |
591 | movl %esp, %eax |
592 | call do_IRQ | |
593 | jmp ret_from_intr | |
47a55cd7 | 594 | ENDPROC(common_interrupt) |
1da177e4 | 595 | |
02cf94c3 | 596 | #define BUILD_INTERRUPT3(name, nr, fn) \ |
1da177e4 | 597 | ENTRY(name) \ |
e59d1b0a | 598 | ASM_CLAC; \ |
a49976d1 | 599 | pushl $~(nr); \ |
fe7cacc1 | 600 | SAVE_ALL; \ |
55f327fa | 601 | TRACE_IRQS_OFF \ |
a49976d1 IM |
602 | movl %esp, %eax; \ |
603 | call fn; \ | |
604 | jmp ret_from_intr; \ | |
47a55cd7 | 605 | ENDPROC(name) |
1da177e4 | 606 | |
cf910e83 SA |
607 | |
608 | #ifdef CONFIG_TRACING | |
a49976d1 | 609 | # define TRACE_BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(trace_##name, nr, smp_trace_##name) |
cf910e83 | 610 | #else |
a49976d1 | 611 | # define TRACE_BUILD_INTERRUPT(name, nr) |
cf910e83 SA |
612 | #endif |
613 | ||
a49976d1 IM |
614 | #define BUILD_INTERRUPT(name, nr) \ |
615 | BUILD_INTERRUPT3(name, nr, smp_##name); \ | |
cf910e83 | 616 | TRACE_BUILD_INTERRUPT(name, nr) |
02cf94c3 | 617 | |
1da177e4 | 618 | /* The include is where all of the SMP etc. interrupts come from */ |
1164dd00 | 619 | #include <asm/entry_arch.h> |
1da177e4 | 620 | |
1da177e4 | 621 | ENTRY(coprocessor_error) |
e59d1b0a | 622 | ASM_CLAC |
a49976d1 IM |
623 | pushl $0 |
624 | pushl $do_coprocessor_error | |
625 | jmp error_code | |
47a55cd7 | 626 | END(coprocessor_error) |
1da177e4 LT |
627 | |
628 | ENTRY(simd_coprocessor_error) | |
e59d1b0a | 629 | ASM_CLAC |
a49976d1 | 630 | pushl $0 |
40d2e763 BG |
631 | #ifdef CONFIG_X86_INVD_BUG |
632 | /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */ | |
a49976d1 IM |
633 | ALTERNATIVE "pushl $do_general_protection", \ |
634 | "pushl $do_simd_coprocessor_error", \ | |
8e65f6e0 | 635 | X86_FEATURE_XMM |
40d2e763 | 636 | #else |
a49976d1 | 637 | pushl $do_simd_coprocessor_error |
40d2e763 | 638 | #endif |
a49976d1 | 639 | jmp error_code |
47a55cd7 | 640 | END(simd_coprocessor_error) |
1da177e4 LT |
641 | |
642 | ENTRY(device_not_available) | |
e59d1b0a | 643 | ASM_CLAC |
a49976d1 IM |
644 | pushl $-1 # mark this as an int |
645 | pushl $do_device_not_available | |
646 | jmp error_code | |
47a55cd7 | 647 | END(device_not_available) |
1da177e4 | 648 | |
d3561b7f RR |
649 | #ifdef CONFIG_PARAVIRT |
650 | ENTRY(native_iret) | |
3701d863 | 651 | iret |
6837a54d | 652 | _ASM_EXTABLE(native_iret, iret_exc) |
47a55cd7 | 653 | END(native_iret) |
d3561b7f RR |
654 | #endif |
655 | ||
1da177e4 | 656 | ENTRY(overflow) |
e59d1b0a | 657 | ASM_CLAC |
a49976d1 IM |
658 | pushl $0 |
659 | pushl $do_overflow | |
660 | jmp error_code | |
47a55cd7 | 661 | END(overflow) |
1da177e4 LT |
662 | |
663 | ENTRY(bounds) | |
e59d1b0a | 664 | ASM_CLAC |
a49976d1 IM |
665 | pushl $0 |
666 | pushl $do_bounds | |
667 | jmp error_code | |
47a55cd7 | 668 | END(bounds) |
1da177e4 LT |
669 | |
670 | ENTRY(invalid_op) | |
e59d1b0a | 671 | ASM_CLAC |
a49976d1 IM |
672 | pushl $0 |
673 | pushl $do_invalid_op | |
674 | jmp error_code | |
47a55cd7 | 675 | END(invalid_op) |
1da177e4 LT |
676 | |
677 | ENTRY(coprocessor_segment_overrun) | |
e59d1b0a | 678 | ASM_CLAC |
a49976d1 IM |
679 | pushl $0 |
680 | pushl $do_coprocessor_segment_overrun | |
681 | jmp error_code | |
47a55cd7 | 682 | END(coprocessor_segment_overrun) |
1da177e4 LT |
683 | |
684 | ENTRY(invalid_TSS) | |
e59d1b0a | 685 | ASM_CLAC |
a49976d1 IM |
686 | pushl $do_invalid_TSS |
687 | jmp error_code | |
47a55cd7 | 688 | END(invalid_TSS) |
1da177e4 LT |
689 | |
690 | ENTRY(segment_not_present) | |
e59d1b0a | 691 | ASM_CLAC |
a49976d1 IM |
692 | pushl $do_segment_not_present |
693 | jmp error_code | |
47a55cd7 | 694 | END(segment_not_present) |
1da177e4 LT |
695 | |
696 | ENTRY(stack_segment) | |
e59d1b0a | 697 | ASM_CLAC |
a49976d1 IM |
698 | pushl $do_stack_segment |
699 | jmp error_code | |
47a55cd7 | 700 | END(stack_segment) |
1da177e4 | 701 | |
1da177e4 | 702 | ENTRY(alignment_check) |
e59d1b0a | 703 | ASM_CLAC |
a49976d1 IM |
704 | pushl $do_alignment_check |
705 | jmp error_code | |
47a55cd7 | 706 | END(alignment_check) |
1da177e4 | 707 | |
d28c4393 | 708 | ENTRY(divide_error) |
e59d1b0a | 709 | ASM_CLAC |
a49976d1 IM |
710 | pushl $0 # no error code |
711 | pushl $do_divide_error | |
712 | jmp error_code | |
47a55cd7 | 713 | END(divide_error) |
1da177e4 LT |
714 | |
715 | #ifdef CONFIG_X86_MCE | |
716 | ENTRY(machine_check) | |
e59d1b0a | 717 | ASM_CLAC |
a49976d1 IM |
718 | pushl $0 |
719 | pushl machine_check_vector | |
720 | jmp error_code | |
47a55cd7 | 721 | END(machine_check) |
1da177e4 LT |
722 | #endif |
723 | ||
724 | ENTRY(spurious_interrupt_bug) | |
e59d1b0a | 725 | ASM_CLAC |
a49976d1 IM |
726 | pushl $0 |
727 | pushl $do_spurious_interrupt_bug | |
728 | jmp error_code | |
47a55cd7 | 729 | END(spurious_interrupt_bug) |
1da177e4 | 730 | |
5ead97c8 JF |
731 | #ifdef CONFIG_XEN |
732 | ENTRY(xen_hypervisor_callback) | |
a49976d1 | 733 | pushl $-1 /* orig_ax = -1 => not a system call */ |
5ead97c8 JF |
734 | SAVE_ALL |
735 | TRACE_IRQS_OFF | |
9ec2b804 | 736 | |
a49976d1 IM |
737 | /* |
738 | * Check to see if we got the event in the critical | |
739 | * region in xen_iret_direct, after we've reenabled | |
740 | * events and checked for pending events. This simulates | |
741 | * iret instruction's behaviour where it delivers a | |
742 | * pending interrupt when enabling interrupts: | |
743 | */ | |
744 | movl PT_EIP(%esp), %eax | |
745 | cmpl $xen_iret_start_crit, %eax | |
746 | jb 1f | |
747 | cmpl $xen_iret_end_crit, %eax | |
748 | jae 1f | |
9ec2b804 | 749 | |
a49976d1 | 750 | jmp xen_iret_crit_fixup |
e2a81baf | 751 | |
e2a81baf | 752 | ENTRY(xen_do_upcall) |
a49976d1 IM |
753 | 1: mov %esp, %eax |
754 | call xen_evtchn_do_upcall | |
fdfd811d | 755 | #ifndef CONFIG_PREEMPT |
a49976d1 | 756 | call xen_maybe_preempt_hcall |
fdfd811d | 757 | #endif |
a49976d1 | 758 | jmp ret_from_intr |
5ead97c8 JF |
759 | ENDPROC(xen_hypervisor_callback) |
760 | ||
a49976d1 IM |
761 | /* |
762 | * Hypervisor uses this for application faults while it executes. | |
763 | * We get here for two reasons: | |
764 | * 1. Fault while reloading DS, ES, FS or GS | |
765 | * 2. Fault while executing IRET | |
766 | * Category 1 we fix up by reattempting the load, and zeroing the segment | |
767 | * register if the load fails. | |
768 | * Category 2 we fix up by jumping to do_iret_error. We cannot use the | |
769 | * normal Linux return path in this case because if we use the IRET hypercall | |
770 | * to pop the stack frame we end up in an infinite loop of failsafe callbacks. | |
771 | * We distinguish between categories by maintaining a status value in EAX. | |
772 | */ | |
5ead97c8 | 773 | ENTRY(xen_failsafe_callback) |
a49976d1 IM |
774 | pushl %eax |
775 | movl $1, %eax | |
776 | 1: mov 4(%esp), %ds | |
777 | 2: mov 8(%esp), %es | |
778 | 3: mov 12(%esp), %fs | |
779 | 4: mov 16(%esp), %gs | |
a349e23d DV |
780 | /* EAX == 0 => Category 1 (Bad segment) |
781 | EAX != 0 => Category 2 (Bad IRET) */ | |
a49976d1 IM |
782 | testl %eax, %eax |
783 | popl %eax | |
784 | lea 16(%esp), %esp | |
785 | jz 5f | |
786 | jmp iret_exc | |
787 | 5: pushl $-1 /* orig_ax = -1 => not a system call */ | |
5ead97c8 | 788 | SAVE_ALL |
a49976d1 IM |
789 | jmp ret_from_exception |
790 | ||
791 | .section .fixup, "ax" | |
792 | 6: xorl %eax, %eax | |
793 | movl %eax, 4(%esp) | |
794 | jmp 1b | |
795 | 7: xorl %eax, %eax | |
796 | movl %eax, 8(%esp) | |
797 | jmp 2b | |
798 | 8: xorl %eax, %eax | |
799 | movl %eax, 12(%esp) | |
800 | jmp 3b | |
801 | 9: xorl %eax, %eax | |
802 | movl %eax, 16(%esp) | |
803 | jmp 4b | |
5ead97c8 | 804 | .previous |
a49976d1 IM |
805 | _ASM_EXTABLE(1b, 6b) |
806 | _ASM_EXTABLE(2b, 7b) | |
807 | _ASM_EXTABLE(3b, 8b) | |
808 | _ASM_EXTABLE(4b, 9b) | |
5ead97c8 JF |
809 | ENDPROC(xen_failsafe_callback) |
810 | ||
bc2b0331 | 811 | BUILD_INTERRUPT3(xen_hvm_callback_vector, HYPERVISOR_CALLBACK_VECTOR, |
38e20b07 SY |
812 | xen_evtchn_do_upcall) |
813 | ||
a49976d1 | 814 | #endif /* CONFIG_XEN */ |
bc2b0331 S |
815 | |
816 | #if IS_ENABLED(CONFIG_HYPERV) | |
817 | ||
818 | BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR, | |
819 | hyperv_vector_handler) | |
820 | ||
821 | #endif /* CONFIG_HYPERV */ | |
5ead97c8 | 822 | |
606576ce | 823 | #ifdef CONFIG_FUNCTION_TRACER |
d61f82d0 SR |
824 | #ifdef CONFIG_DYNAMIC_FTRACE |
825 | ||
826 | ENTRY(mcount) | |
d61f82d0 SR |
827 | ret |
828 | END(mcount) | |
829 | ||
830 | ENTRY(ftrace_caller) | |
a49976d1 IM |
831 | pushl %eax |
832 | pushl %ecx | |
833 | pushl %edx | |
834 | pushl $0 /* Pass NULL as regs pointer */ | |
835 | movl 4*4(%esp), %eax | |
836 | movl 0x4(%ebp), %edx | |
837 | movl function_trace_op, %ecx | |
838 | subl $MCOUNT_INSN_SIZE, %eax | |
d61f82d0 SR |
839 | |
840 | .globl ftrace_call | |
841 | ftrace_call: | |
a49976d1 | 842 | call ftrace_stub |
d61f82d0 | 843 | |
a49976d1 IM |
844 | addl $4, %esp /* skip NULL pointer */ |
845 | popl %edx | |
846 | popl %ecx | |
847 | popl %eax | |
4de72395 | 848 | ftrace_ret: |
5a45cfe1 SR |
849 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
850 | .globl ftrace_graph_call | |
851 | ftrace_graph_call: | |
a49976d1 | 852 | jmp ftrace_stub |
5a45cfe1 | 853 | #endif |
d61f82d0 SR |
854 | |
855 | .globl ftrace_stub | |
856 | ftrace_stub: | |
857 | ret | |
858 | END(ftrace_caller) | |
859 | ||
4de72395 SR |
860 | ENTRY(ftrace_regs_caller) |
861 | pushf /* push flags before compare (in cs location) */ | |
4de72395 SR |
862 | |
863 | /* | |
864 | * i386 does not save SS and ESP when coming from kernel. | |
865 | * Instead, to get sp, ®s->sp is used (see ptrace.h). | |
866 | * Unfortunately, that means eflags must be at the same location | |
867 | * as the current return ip is. We move the return ip into the | |
868 | * ip location, and move flags into the return ip location. | |
869 | */ | |
a49976d1 IM |
870 | pushl 4(%esp) /* save return ip into ip slot */ |
871 | ||
872 | pushl $0 /* Load 0 into orig_ax */ | |
873 | pushl %gs | |
874 | pushl %fs | |
875 | pushl %es | |
876 | pushl %ds | |
877 | pushl %eax | |
878 | pushl %ebp | |
879 | pushl %edi | |
880 | pushl %esi | |
881 | pushl %edx | |
882 | pushl %ecx | |
883 | pushl %ebx | |
884 | ||
885 | movl 13*4(%esp), %eax /* Get the saved flags */ | |
886 | movl %eax, 14*4(%esp) /* Move saved flags into regs->flags location */ | |
887 | /* clobbering return ip */ | |
888 | movl $__KERNEL_CS, 13*4(%esp) | |
889 | ||
890 | movl 12*4(%esp), %eax /* Load ip (1st parameter) */ | |
891 | subl $MCOUNT_INSN_SIZE, %eax /* Adjust ip */ | |
892 | movl 0x4(%ebp), %edx /* Load parent ip (2nd parameter) */ | |
893 | movl function_trace_op, %ecx /* Save ftrace_pos in 3rd parameter */ | |
894 | pushl %esp /* Save pt_regs as 4th parameter */ | |
4de72395 SR |
895 | |
896 | GLOBAL(ftrace_regs_call) | |
a49976d1 IM |
897 | call ftrace_stub |
898 | ||
899 | addl $4, %esp /* Skip pt_regs */ | |
900 | movl 14*4(%esp), %eax /* Move flags back into cs */ | |
901 | movl %eax, 13*4(%esp) /* Needed to keep addl from modifying flags */ | |
902 | movl 12*4(%esp), %eax /* Get return ip from regs->ip */ | |
903 | movl %eax, 14*4(%esp) /* Put return ip back for ret */ | |
904 | ||
905 | popl %ebx | |
906 | popl %ecx | |
907 | popl %edx | |
908 | popl %esi | |
909 | popl %edi | |
910 | popl %ebp | |
911 | popl %eax | |
912 | popl %ds | |
913 | popl %es | |
914 | popl %fs | |
915 | popl %gs | |
916 | addl $8, %esp /* Skip orig_ax and ip */ | |
917 | popf /* Pop flags at end (no addl to corrupt flags) */ | |
918 | jmp ftrace_ret | |
4de72395 | 919 | |
4de72395 | 920 | popf |
a49976d1 | 921 | jmp ftrace_stub |
d61f82d0 SR |
922 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
923 | ||
16444a8a | 924 | ENTRY(mcount) |
a49976d1 IM |
925 | cmpl $__PAGE_OFFSET, %esp |
926 | jb ftrace_stub /* Paging not enabled yet? */ | |
af058ab0 | 927 | |
a49976d1 IM |
928 | cmpl $ftrace_stub, ftrace_trace_function |
929 | jnz trace | |
fb52607a | 930 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
a49976d1 IM |
931 | cmpl $ftrace_stub, ftrace_graph_return |
932 | jnz ftrace_graph_caller | |
e49dc19c | 933 | |
a49976d1 IM |
934 | cmpl $ftrace_graph_entry_stub, ftrace_graph_entry |
935 | jnz ftrace_graph_caller | |
caf4b323 | 936 | #endif |
16444a8a ACM |
937 | .globl ftrace_stub |
938 | ftrace_stub: | |
939 | ret | |
940 | ||
941 | /* taken from glibc */ | |
942 | trace: | |
a49976d1 IM |
943 | pushl %eax |
944 | pushl %ecx | |
945 | pushl %edx | |
946 | movl 0xc(%esp), %eax | |
947 | movl 0x4(%ebp), %edx | |
948 | subl $MCOUNT_INSN_SIZE, %eax | |
949 | ||
950 | call *ftrace_trace_function | |
951 | ||
952 | popl %edx | |
953 | popl %ecx | |
954 | popl %eax | |
955 | jmp ftrace_stub | |
16444a8a | 956 | END(mcount) |
d61f82d0 | 957 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
606576ce | 958 | #endif /* CONFIG_FUNCTION_TRACER */ |
16444a8a | 959 | |
fb52607a FW |
960 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
961 | ENTRY(ftrace_graph_caller) | |
a49976d1 IM |
962 | pushl %eax |
963 | pushl %ecx | |
964 | pushl %edx | |
965 | movl 0xc(%esp), %eax | |
966 | lea 0x4(%ebp), %edx | |
967 | movl (%ebp), %ecx | |
968 | subl $MCOUNT_INSN_SIZE, %eax | |
969 | call prepare_ftrace_return | |
970 | popl %edx | |
971 | popl %ecx | |
972 | popl %eax | |
e7d3737e | 973 | ret |
fb52607a | 974 | END(ftrace_graph_caller) |
caf4b323 FW |
975 | |
976 | .globl return_to_handler | |
977 | return_to_handler: | |
a49976d1 IM |
978 | pushl %eax |
979 | pushl %edx | |
980 | movl %ebp, %eax | |
981 | call ftrace_return_to_handler | |
982 | movl %eax, %ecx | |
983 | popl %edx | |
984 | popl %eax | |
985 | jmp *%ecx | |
e7d3737e | 986 | #endif |
16444a8a | 987 | |
25c74b10 SA |
988 | #ifdef CONFIG_TRACING |
989 | ENTRY(trace_page_fault) | |
25c74b10 | 990 | ASM_CLAC |
a49976d1 IM |
991 | pushl $trace_do_page_fault |
992 | jmp error_code | |
25c74b10 SA |
993 | END(trace_page_fault) |
994 | #endif | |
995 | ||
d211af05 | 996 | ENTRY(page_fault) |
e59d1b0a | 997 | ASM_CLAC |
a49976d1 | 998 | pushl $do_page_fault |
d211af05 AH |
999 | ALIGN |
1000 | error_code: | |
ccbeed3a | 1001 | /* the function address is in %gs's slot on the stack */ |
a49976d1 IM |
1002 | pushl %fs |
1003 | pushl %es | |
1004 | pushl %ds | |
1005 | pushl %eax | |
1006 | pushl %ebp | |
1007 | pushl %edi | |
1008 | pushl %esi | |
1009 | pushl %edx | |
1010 | pushl %ecx | |
1011 | pushl %ebx | |
d211af05 | 1012 | cld |
a49976d1 IM |
1013 | movl $(__KERNEL_PERCPU), %ecx |
1014 | movl %ecx, %fs | |
d211af05 | 1015 | UNWIND_ESPFIX_STACK |
ccbeed3a | 1016 | GS_TO_REG %ecx |
a49976d1 IM |
1017 | movl PT_GS(%esp), %edi # get the function address |
1018 | movl PT_ORIG_EAX(%esp), %edx # get the error code | |
1019 | movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart | |
ccbeed3a TH |
1020 | REG_TO_PTGS %ecx |
1021 | SET_KERNEL_GS %ecx | |
a49976d1 IM |
1022 | movl $(__USER_DS), %ecx |
1023 | movl %ecx, %ds | |
1024 | movl %ecx, %es | |
d211af05 | 1025 | TRACE_IRQS_OFF |
a49976d1 IM |
1026 | movl %esp, %eax # pt_regs pointer |
1027 | call *%edi | |
1028 | jmp ret_from_exception | |
d211af05 AH |
1029 | END(page_fault) |
1030 | ||
d211af05 | 1031 | ENTRY(debug) |
7536656f AL |
1032 | /* |
1033 | * #DB can happen at the first instruction of | |
1034 | * entry_SYSENTER_32 or in Xen's SYSENTER prologue. If this | |
1035 | * happens, then we will be running on a very small stack. We | |
1036 | * need to detect this condition and switch to the thread | |
1037 | * stack before calling any C code at all. | |
1038 | * | |
1039 | * If you edit this code, keep in mind that NMIs can happen in here. | |
1040 | */ | |
e59d1b0a | 1041 | ASM_CLAC |
a49976d1 | 1042 | pushl $-1 # mark this as an int |
d211af05 | 1043 | SAVE_ALL |
a49976d1 IM |
1044 | xorl %edx, %edx # error code 0 |
1045 | movl %esp, %eax # pt_regs pointer | |
7536656f AL |
1046 | |
1047 | /* Are we currently on the SYSENTER stack? */ | |
1048 | PER_CPU(cpu_tss + CPU_TSS_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx) | |
1049 | subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */ | |
1050 | cmpl $SIZEOF_SYSENTER_stack, %ecx | |
1051 | jb .Ldebug_from_sysenter_stack | |
1052 | ||
1053 | TRACE_IRQS_OFF | |
1054 | call do_debug | |
1055 | jmp ret_from_exception | |
1056 | ||
1057 | .Ldebug_from_sysenter_stack: | |
1058 | /* We're on the SYSENTER stack. Switch off. */ | |
1059 | movl %esp, %ebp | |
1060 | movl PER_CPU_VAR(cpu_current_top_of_stack), %esp | |
1061 | TRACE_IRQS_OFF | |
a49976d1 | 1062 | call do_debug |
7536656f | 1063 | movl %ebp, %esp |
a49976d1 | 1064 | jmp ret_from_exception |
d211af05 AH |
1065 | END(debug) |
1066 | ||
1067 | /* | |
7536656f AL |
1068 | * NMI is doubly nasty. It can happen on the first instruction of |
1069 | * entry_SYSENTER_32 (just like #DB), but it can also interrupt the beginning | |
1070 | * of the #DB handler even if that #DB in turn hit before entry_SYSENTER_32 | |
1071 | * switched stacks. We handle both conditions by simply checking whether we | |
1072 | * interrupted kernel code running on the SYSENTER stack. | |
d211af05 AH |
1073 | */ |
1074 | ENTRY(nmi) | |
e59d1b0a | 1075 | ASM_CLAC |
34273f41 | 1076 | #ifdef CONFIG_X86_ESPFIX32 |
a49976d1 IM |
1077 | pushl %eax |
1078 | movl %ss, %eax | |
1079 | cmpw $__ESPFIX_SS, %ax | |
1080 | popl %eax | |
1081 | je nmi_espfix_stack | |
34273f41 | 1082 | #endif |
7536656f AL |
1083 | |
1084 | pushl %eax # pt_regs->orig_ax | |
d211af05 | 1085 | SAVE_ALL |
a49976d1 IM |
1086 | xorl %edx, %edx # zero error code |
1087 | movl %esp, %eax # pt_regs pointer | |
7536656f AL |
1088 | |
1089 | /* Are we currently on the SYSENTER stack? */ | |
1090 | PER_CPU(cpu_tss + CPU_TSS_SYSENTER_stack + SIZEOF_SYSENTER_stack, %ecx) | |
1091 | subl %eax, %ecx /* ecx = (end of SYSENTER_stack) - esp */ | |
1092 | cmpl $SIZEOF_SYSENTER_stack, %ecx | |
1093 | jb .Lnmi_from_sysenter_stack | |
1094 | ||
1095 | /* Not on SYSENTER stack. */ | |
a49976d1 IM |
1096 | call do_nmi |
1097 | jmp restore_all_notrace | |
d211af05 | 1098 | |
7536656f AL |
1099 | .Lnmi_from_sysenter_stack: |
1100 | /* | |
1101 | * We're on the SYSENTER stack. Switch off. No one (not even debug) | |
1102 | * is using the thread stack right now, so it's safe for us to use it. | |
1103 | */ | |
1104 | movl %esp, %ebp | |
1105 | movl PER_CPU_VAR(cpu_current_top_of_stack), %esp | |
1106 | call do_nmi | |
1107 | movl %ebp, %esp | |
1108 | jmp restore_all_notrace | |
d211af05 | 1109 | |
34273f41 | 1110 | #ifdef CONFIG_X86_ESPFIX32 |
d211af05 | 1111 | nmi_espfix_stack: |
131484c8 | 1112 | /* |
d211af05 AH |
1113 | * create the pointer to lss back |
1114 | */ | |
a49976d1 IM |
1115 | pushl %ss |
1116 | pushl %esp | |
1117 | addl $4, (%esp) | |
d211af05 AH |
1118 | /* copy the iret frame of 12 bytes */ |
1119 | .rept 3 | |
a49976d1 | 1120 | pushl 16(%esp) |
d211af05 | 1121 | .endr |
a49976d1 | 1122 | pushl %eax |
d211af05 | 1123 | SAVE_ALL |
a49976d1 IM |
1124 | FIXUP_ESPFIX_STACK # %eax == %esp |
1125 | xorl %edx, %edx # zero error code | |
1126 | call do_nmi | |
d211af05 | 1127 | RESTORE_REGS |
a49976d1 IM |
1128 | lss 12+4(%esp), %esp # back to espfix stack |
1129 | jmp irq_return | |
34273f41 | 1130 | #endif |
d211af05 AH |
1131 | END(nmi) |
1132 | ||
1133 | ENTRY(int3) | |
e59d1b0a | 1134 | ASM_CLAC |
a49976d1 | 1135 | pushl $-1 # mark this as an int |
d211af05 AH |
1136 | SAVE_ALL |
1137 | TRACE_IRQS_OFF | |
a49976d1 IM |
1138 | xorl %edx, %edx # zero error code |
1139 | movl %esp, %eax # pt_regs pointer | |
1140 | call do_int3 | |
1141 | jmp ret_from_exception | |
d211af05 AH |
1142 | END(int3) |
1143 | ||
1144 | ENTRY(general_protection) | |
a49976d1 IM |
1145 | pushl $do_general_protection |
1146 | jmp error_code | |
d211af05 AH |
1147 | END(general_protection) |
1148 | ||
631bc487 GN |
1149 | #ifdef CONFIG_KVM_GUEST |
1150 | ENTRY(async_page_fault) | |
e59d1b0a | 1151 | ASM_CLAC |
a49976d1 IM |
1152 | pushl $do_async_page_fault |
1153 | jmp error_code | |
2ae9d293 | 1154 | END(async_page_fault) |
631bc487 | 1155 | #endif |
2deb4be2 AL |
1156 | |
1157 | ENTRY(rewind_stack_do_exit) | |
1158 | /* Prevent any naive code from trying to unwind to our caller. */ | |
1159 | xorl %ebp, %ebp | |
1160 | ||
1161 | movl PER_CPU_VAR(cpu_current_top_of_stack), %esi | |
1162 | leal -TOP_OF_KERNEL_STACK_PADDING-PTREGS_SIZE(%esi), %esp | |
1163 | ||
1164 | call do_exit | |
1165 | 1: jmp 1b | |
1166 | END(rewind_stack_do_exit) |