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