]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/x86/kernel/entry_32.S
ARM: ux500: Enable probing of pinctrl through Device Tree
[karo-tx-linux.git] / arch / x86 / kernel / entry_32.S
1 /*
2  *
3  *  Copyright (C) 1991, 1992  Linus Torvalds
4  */
5
6 /*
7  * entry.S contains the system-call and fault low-level handling routines.
8  * This also contains the timer-interrupt handler, as well as all interrupts
9  * and faults that can result in a task-switch.
10  *
11  * NOTE: This code handles signal-recognition, which happens every time
12  * after a timer-interrupt and after each system call.
13  *
14  * I changed all the .align's to 4 (16 byte alignment), as that's faster
15  * on a 486.
16  *
17  * Stack layout in 'syscall_exit':
18  *      ptrace needs to have all regs on the stack.
19  *      if the order here is changed, it needs to be
20  *      updated in fork.c:copy_process, signal.c:do_signal,
21  *      ptrace.c and ptrace.h
22  *
23  *       0(%esp) - %ebx
24  *       4(%esp) - %ecx
25  *       8(%esp) - %edx
26  *       C(%esp) - %esi
27  *      10(%esp) - %edi
28  *      14(%esp) - %ebp
29  *      18(%esp) - %eax
30  *      1C(%esp) - %ds
31  *      20(%esp) - %es
32  *      24(%esp) - %fs
33  *      28(%esp) - %gs          saved iff !CONFIG_X86_32_LAZY_GS
34  *      2C(%esp) - orig_eax
35  *      30(%esp) - %eip
36  *      34(%esp) - %cs
37  *      38(%esp) - %eflags
38  *      3C(%esp) - %oldesp
39  *      40(%esp) - %oldss
40  *
41  * "current" is in register %ebx during any slow entries.
42  */
43
44 #include <linux/linkage.h>
45 #include <linux/err.h>
46 #include <asm/thread_info.h>
47 #include <asm/irqflags.h>
48 #include <asm/errno.h>
49 #include <asm/segment.h>
50 #include <asm/smp.h>
51 #include <asm/page_types.h>
52 #include <asm/percpu.h>
53 #include <asm/dwarf2.h>
54 #include <asm/processor-flags.h>
55 #include <asm/ftrace.h>
56 #include <asm/irq_vectors.h>
57 #include <asm/cpufeature.h>
58 #include <asm/alternative-asm.h>
59 #include <asm/asm.h>
60
61 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this.  */
62 #include <linux/elf-em.h>
63 #define AUDIT_ARCH_I386         (EM_386|__AUDIT_ARCH_LE)
64 #define __AUDIT_ARCH_LE    0x40000000
65
66 #ifndef CONFIG_AUDITSYSCALL
67 #define sysenter_audit  syscall_trace_entry
68 #define sysexit_audit   syscall_exit_work
69 #endif
70
71         .section .entry.text, "ax"
72
73 /*
74  * We use macros for low-level operations which need to be overridden
75  * for paravirtualization.  The following will never clobber any registers:
76  *   INTERRUPT_RETURN (aka. "iret")
77  *   GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
78  *   ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
79  *
80  * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
81  * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
82  * Allowing a register to be clobbered can shrink the paravirt replacement
83  * enough to patch inline, increasing performance.
84  */
85
86 #ifdef CONFIG_PREEMPT
87 #define preempt_stop(clobbers)  DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
88 #else
89 #define preempt_stop(clobbers)
90 #define resume_kernel           restore_all
91 #endif
92
93 .macro TRACE_IRQS_IRET
94 #ifdef CONFIG_TRACE_IRQFLAGS
95         testl $X86_EFLAGS_IF,PT_EFLAGS(%esp)     # interrupts off?
96         jz 1f
97         TRACE_IRQS_ON
98 1:
99 #endif
100 .endm
101
102 /*
103  * User gs save/restore
104  *
105  * %gs is used for userland TLS and kernel only uses it for stack
106  * canary which is required to be at %gs:20 by gcc.  Read the comment
107  * at the top of stackprotector.h for more info.
108  *
109  * Local labels 98 and 99 are used.
110  */
111 #ifdef CONFIG_X86_32_LAZY_GS
112
113  /* unfortunately push/pop can't be no-op */
114 .macro PUSH_GS
115         pushl_cfi $0
116 .endm
117 .macro POP_GS pop=0
118         addl $(4 + \pop), %esp
119         CFI_ADJUST_CFA_OFFSET -(4 + \pop)
120 .endm
121 .macro POP_GS_EX
122 .endm
123
124  /* all the rest are no-op */
125 .macro PTGS_TO_GS
126 .endm
127 .macro PTGS_TO_GS_EX
128 .endm
129 .macro GS_TO_REG reg
130 .endm
131 .macro REG_TO_PTGS reg
132 .endm
133 .macro SET_KERNEL_GS reg
134 .endm
135
136 #else   /* CONFIG_X86_32_LAZY_GS */
137
138 .macro PUSH_GS
139         pushl_cfi %gs
140         /*CFI_REL_OFFSET gs, 0*/
141 .endm
142
143 .macro POP_GS pop=0
144 98:     popl_cfi %gs
145         /*CFI_RESTORE gs*/
146   .if \pop <> 0
147         add $\pop, %esp
148         CFI_ADJUST_CFA_OFFSET -\pop
149   .endif
150 .endm
151 .macro POP_GS_EX
152 .pushsection .fixup, "ax"
153 99:     movl $0, (%esp)
154         jmp 98b
155 .popsection
156         _ASM_EXTABLE(98b,99b)
157 .endm
158
159 .macro PTGS_TO_GS
160 98:     mov PT_GS(%esp), %gs
161 .endm
162 .macro PTGS_TO_GS_EX
163 .pushsection .fixup, "ax"
164 99:     movl $0, PT_GS(%esp)
165         jmp 98b
166 .popsection
167         _ASM_EXTABLE(98b,99b)
168 .endm
169
170 .macro GS_TO_REG reg
171         movl %gs, \reg
172         /*CFI_REGISTER gs, \reg*/
173 .endm
174 .macro REG_TO_PTGS reg
175         movl \reg, PT_GS(%esp)
176         /*CFI_REL_OFFSET gs, PT_GS*/
177 .endm
178 .macro SET_KERNEL_GS reg
179         movl $(__KERNEL_STACK_CANARY), \reg
180         movl \reg, %gs
181 .endm
182
183 #endif  /* CONFIG_X86_32_LAZY_GS */
184
185 .macro SAVE_ALL
186         cld
187         PUSH_GS
188         pushl_cfi %fs
189         /*CFI_REL_OFFSET fs, 0;*/
190         pushl_cfi %es
191         /*CFI_REL_OFFSET es, 0;*/
192         pushl_cfi %ds
193         /*CFI_REL_OFFSET ds, 0;*/
194         pushl_cfi %eax
195         CFI_REL_OFFSET eax, 0
196         pushl_cfi %ebp
197         CFI_REL_OFFSET ebp, 0
198         pushl_cfi %edi
199         CFI_REL_OFFSET edi, 0
200         pushl_cfi %esi
201         CFI_REL_OFFSET esi, 0
202         pushl_cfi %edx
203         CFI_REL_OFFSET edx, 0
204         pushl_cfi %ecx
205         CFI_REL_OFFSET ecx, 0
206         pushl_cfi %ebx
207         CFI_REL_OFFSET ebx, 0
208         movl $(__USER_DS), %edx
209         movl %edx, %ds
210         movl %edx, %es
211         movl $(__KERNEL_PERCPU), %edx
212         movl %edx, %fs
213         SET_KERNEL_GS %edx
214 .endm
215
216 .macro RESTORE_INT_REGS
217         popl_cfi %ebx
218         CFI_RESTORE ebx
219         popl_cfi %ecx
220         CFI_RESTORE ecx
221         popl_cfi %edx
222         CFI_RESTORE edx
223         popl_cfi %esi
224         CFI_RESTORE esi
225         popl_cfi %edi
226         CFI_RESTORE edi
227         popl_cfi %ebp
228         CFI_RESTORE ebp
229         popl_cfi %eax
230         CFI_RESTORE eax
231 .endm
232
233 .macro RESTORE_REGS pop=0
234         RESTORE_INT_REGS
235 1:      popl_cfi %ds
236         /*CFI_RESTORE ds;*/
237 2:      popl_cfi %es
238         /*CFI_RESTORE es;*/
239 3:      popl_cfi %fs
240         /*CFI_RESTORE fs;*/
241         POP_GS \pop
242 .pushsection .fixup, "ax"
243 4:      movl $0, (%esp)
244         jmp 1b
245 5:      movl $0, (%esp)
246         jmp 2b
247 6:      movl $0, (%esp)
248         jmp 3b
249 .popsection
250         _ASM_EXTABLE(1b,4b)
251         _ASM_EXTABLE(2b,5b)
252         _ASM_EXTABLE(3b,6b)
253         POP_GS_EX
254 .endm
255
256 .macro RING0_INT_FRAME
257         CFI_STARTPROC simple
258         CFI_SIGNAL_FRAME
259         CFI_DEF_CFA esp, 3*4
260         /*CFI_OFFSET cs, -2*4;*/
261         CFI_OFFSET eip, -3*4
262 .endm
263
264 .macro RING0_EC_FRAME
265         CFI_STARTPROC simple
266         CFI_SIGNAL_FRAME
267         CFI_DEF_CFA esp, 4*4
268         /*CFI_OFFSET cs, -2*4;*/
269         CFI_OFFSET eip, -3*4
270 .endm
271
272 .macro RING0_PTREGS_FRAME
273         CFI_STARTPROC simple
274         CFI_SIGNAL_FRAME
275         CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
276         /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
277         CFI_OFFSET eip, PT_EIP-PT_OLDESP
278         /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
279         /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
280         CFI_OFFSET eax, PT_EAX-PT_OLDESP
281         CFI_OFFSET ebp, PT_EBP-PT_OLDESP
282         CFI_OFFSET edi, PT_EDI-PT_OLDESP
283         CFI_OFFSET esi, PT_ESI-PT_OLDESP
284         CFI_OFFSET edx, PT_EDX-PT_OLDESP
285         CFI_OFFSET ecx, PT_ECX-PT_OLDESP
286         CFI_OFFSET ebx, PT_EBX-PT_OLDESP
287 .endm
288
289 ENTRY(ret_from_fork)
290         CFI_STARTPROC
291         pushl_cfi %eax
292         call schedule_tail
293         GET_THREAD_INFO(%ebp)
294         popl_cfi %eax
295         pushl_cfi $0x0202               # Reset kernel eflags
296         popfl_cfi
297         jmp syscall_exit
298         CFI_ENDPROC
299 END(ret_from_fork)
300
301 /*
302  * Interrupt exit functions should be protected against kprobes
303  */
304         .pushsection .kprobes.text, "ax"
305 /*
306  * Return to user mode is not as complex as all this looks,
307  * but we want the default path for a system call return to
308  * go as quickly as possible which is why some of this is
309  * less clear than it otherwise should be.
310  */
311
312         # userspace resumption stub bypassing syscall exit tracing
313         ALIGN
314         RING0_PTREGS_FRAME
315 ret_from_exception:
316         preempt_stop(CLBR_ANY)
317 ret_from_intr:
318         GET_THREAD_INFO(%ebp)
319 resume_userspace_sig:
320 #ifdef CONFIG_VM86
321         movl PT_EFLAGS(%esp), %eax      # mix EFLAGS and CS
322         movb PT_CS(%esp), %al
323         andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
324 #else
325         /*
326          * We can be coming here from a syscall done in the kernel space,
327          * e.g. a failed kernel_execve().
328          */
329         movl PT_CS(%esp), %eax
330         andl $SEGMENT_RPL_MASK, %eax
331 #endif
332         cmpl $USER_RPL, %eax
333         jb resume_kernel                # not returning to v8086 or userspace
334
335 ENTRY(resume_userspace)
336         LOCKDEP_SYS_EXIT
337         DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt
338                                         # setting need_resched or sigpending
339                                         # between sampling and the iret
340         TRACE_IRQS_OFF
341         movl TI_flags(%ebp), %ecx
342         andl $_TIF_WORK_MASK, %ecx      # is there any work to be done on
343                                         # int/exception return?
344         jne work_pending
345         jmp restore_all
346 END(ret_from_exception)
347
348 #ifdef CONFIG_PREEMPT
349 ENTRY(resume_kernel)
350         DISABLE_INTERRUPTS(CLBR_ANY)
351         cmpl $0,TI_preempt_count(%ebp)  # non-zero preempt_count ?
352         jnz restore_all
353 need_resched:
354         movl TI_flags(%ebp), %ecx       # need_resched set ?
355         testb $_TIF_NEED_RESCHED, %cl
356         jz restore_all
357         testl $X86_EFLAGS_IF,PT_EFLAGS(%esp)    # interrupts off (exception path) ?
358         jz restore_all
359         call preempt_schedule_irq
360         jmp need_resched
361 END(resume_kernel)
362 #endif
363         CFI_ENDPROC
364 /*
365  * End of kprobes section
366  */
367         .popsection
368
369 /* SYSENTER_RETURN points to after the "sysenter" instruction in
370    the vsyscall page.  See vsyscall-sysentry.S, which defines the symbol.  */
371
372         # sysenter call handler stub
373 ENTRY(ia32_sysenter_target)
374         CFI_STARTPROC simple
375         CFI_SIGNAL_FRAME
376         CFI_DEF_CFA esp, 0
377         CFI_REGISTER esp, ebp
378         movl TSS_sysenter_sp0(%esp),%esp
379 sysenter_past_esp:
380         /*
381          * Interrupts are disabled here, but we can't trace it until
382          * enough kernel state to call TRACE_IRQS_OFF can be called - but
383          * we immediately enable interrupts at that point anyway.
384          */
385         pushl_cfi $__USER_DS
386         /*CFI_REL_OFFSET ss, 0*/
387         pushl_cfi %ebp
388         CFI_REL_OFFSET esp, 0
389         pushfl_cfi
390         orl $X86_EFLAGS_IF, (%esp)
391         pushl_cfi $__USER_CS
392         /*CFI_REL_OFFSET cs, 0*/
393         /*
394          * Push current_thread_info()->sysenter_return to the stack.
395          * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
396          * pushed above; +8 corresponds to copy_thread's esp0 setting.
397          */
398         pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
399         CFI_REL_OFFSET eip, 0
400
401         pushl_cfi %eax
402         SAVE_ALL
403         ENABLE_INTERRUPTS(CLBR_NONE)
404
405 /*
406  * Load the potential sixth argument from user stack.
407  * Careful about security.
408  */
409         cmpl $__PAGE_OFFSET-3,%ebp
410         jae syscall_fault
411 1:      movl (%ebp),%ebp
412         movl %ebp,PT_EBP(%esp)
413         _ASM_EXTABLE(1b,syscall_fault)
414
415         GET_THREAD_INFO(%ebp)
416
417         testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
418         jnz sysenter_audit
419 sysenter_do_call:
420         cmpl $(NR_syscalls), %eax
421         jae syscall_badsys
422         call *sys_call_table(,%eax,4)
423         movl %eax,PT_EAX(%esp)
424         LOCKDEP_SYS_EXIT
425         DISABLE_INTERRUPTS(CLBR_ANY)
426         TRACE_IRQS_OFF
427         movl TI_flags(%ebp), %ecx
428         testl $_TIF_ALLWORK_MASK, %ecx
429         jne sysexit_audit
430 sysenter_exit:
431 /* if something modifies registers it must also disable sysexit */
432         movl PT_EIP(%esp), %edx
433         movl PT_OLDESP(%esp), %ecx
434         xorl %ebp,%ebp
435         TRACE_IRQS_ON
436 1:      mov  PT_FS(%esp), %fs
437         PTGS_TO_GS
438         ENABLE_INTERRUPTS_SYSEXIT
439
440 #ifdef CONFIG_AUDITSYSCALL
441 sysenter_audit:
442         testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
443         jnz syscall_trace_entry
444         addl $4,%esp
445         CFI_ADJUST_CFA_OFFSET -4
446         /* %esi already in 8(%esp)         6th arg: 4th syscall arg */
447         /* %edx already in 4(%esp)         5th arg: 3rd syscall arg */
448         /* %ecx already in 0(%esp)         4th arg: 2nd syscall arg */
449         movl %ebx,%ecx                  /* 3rd arg: 1st syscall arg */
450         movl %eax,%edx                  /* 2nd arg: syscall number */
451         movl $AUDIT_ARCH_I386,%eax      /* 1st arg: audit arch */
452         call __audit_syscall_entry
453         pushl_cfi %ebx
454         movl PT_EAX(%esp),%eax          /* reload syscall number */
455         jmp sysenter_do_call
456
457 sysexit_audit:
458         testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
459         jne syscall_exit_work
460         TRACE_IRQS_ON
461         ENABLE_INTERRUPTS(CLBR_ANY)
462         movl %eax,%edx          /* second arg, syscall return value */
463         cmpl $-MAX_ERRNO,%eax   /* is it an error ? */
464         setbe %al               /* 1 if so, 0 if not */
465         movzbl %al,%eax         /* zero-extend that */
466         call __audit_syscall_exit
467         DISABLE_INTERRUPTS(CLBR_ANY)
468         TRACE_IRQS_OFF
469         movl TI_flags(%ebp), %ecx
470         testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
471         jne syscall_exit_work
472         movl PT_EAX(%esp),%eax  /* reload syscall return value */
473         jmp sysenter_exit
474 #endif
475
476         CFI_ENDPROC
477 .pushsection .fixup,"ax"
478 2:      movl $0,PT_FS(%esp)
479         jmp 1b
480 .popsection
481         _ASM_EXTABLE(1b,2b)
482         PTGS_TO_GS_EX
483 ENDPROC(ia32_sysenter_target)
484
485 /*
486  * syscall stub including irq exit should be protected against kprobes
487  */
488         .pushsection .kprobes.text, "ax"
489         # system call handler stub
490 ENTRY(system_call)
491         RING0_INT_FRAME                 # can't unwind into user space anyway
492         pushl_cfi %eax                  # save orig_eax
493         SAVE_ALL
494         GET_THREAD_INFO(%ebp)
495                                         # system call tracing in operation / emulation
496         testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
497         jnz syscall_trace_entry
498         cmpl $(NR_syscalls), %eax
499         jae syscall_badsys
500 syscall_call:
501         call *sys_call_table(,%eax,4)
502         movl %eax,PT_EAX(%esp)          # store the return value
503 syscall_exit:
504         LOCKDEP_SYS_EXIT
505         DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt
506                                         # setting need_resched or sigpending
507                                         # between sampling and the iret
508         TRACE_IRQS_OFF
509         movl TI_flags(%ebp), %ecx
510         testl $_TIF_ALLWORK_MASK, %ecx  # current->work
511         jne syscall_exit_work
512
513 restore_all:
514         TRACE_IRQS_IRET
515 restore_all_notrace:
516         movl PT_EFLAGS(%esp), %eax      # mix EFLAGS, SS and CS
517         # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
518         # are returning to the kernel.
519         # See comments in process.c:copy_thread() for details.
520         movb PT_OLDSS(%esp), %ah
521         movb PT_CS(%esp), %al
522         andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
523         cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
524         CFI_REMEMBER_STATE
525         je ldt_ss                       # returning to user-space with LDT SS
526 restore_nocheck:
527         RESTORE_REGS 4                  # skip orig_eax/error_code
528 irq_return:
529         INTERRUPT_RETURN
530 .section .fixup,"ax"
531 ENTRY(iret_exc)
532         pushl $0                        # no error code
533         pushl $do_iret_error
534         jmp error_code
535 .previous
536         _ASM_EXTABLE(irq_return,iret_exc)
537
538         CFI_RESTORE_STATE
539 ldt_ss:
540         larl PT_OLDSS(%esp), %eax
541         jnz restore_nocheck
542         testl $0x00400000, %eax         # returning to 32bit stack?
543         jnz restore_nocheck             # allright, normal return
544
545 #ifdef CONFIG_PARAVIRT
546         /*
547          * The kernel can't run on a non-flat stack if paravirt mode
548          * is active.  Rather than try to fixup the high bits of
549          * ESP, bypass this code entirely.  This may break DOSemu
550          * and/or Wine support in a paravirt VM, although the option
551          * is still available to implement the setting of the high
552          * 16-bits in the INTERRUPT_RETURN paravirt-op.
553          */
554         cmpl $0, pv_info+PARAVIRT_enabled
555         jne restore_nocheck
556 #endif
557
558 /*
559  * Setup and switch to ESPFIX stack
560  *
561  * We're returning to userspace with a 16 bit stack. The CPU will not
562  * restore the high word of ESP for us on executing iret... This is an
563  * "official" bug of all the x86-compatible CPUs, which we can work
564  * around to make dosemu and wine happy. We do this by preloading the
565  * high word of ESP with the high word of the userspace ESP while
566  * compensating for the offset by changing to the ESPFIX segment with
567  * a base address that matches for the difference.
568  */
569 #define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
570         mov %esp, %edx                  /* load kernel esp */
571         mov PT_OLDESP(%esp), %eax       /* load userspace esp */
572         mov %dx, %ax                    /* eax: new kernel esp */
573         sub %eax, %edx                  /* offset (low word is 0) */
574         shr $16, %edx
575         mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
576         mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
577         pushl_cfi $__ESPFIX_SS
578         pushl_cfi %eax                  /* new kernel esp */
579         /* Disable interrupts, but do not irqtrace this section: we
580          * will soon execute iret and the tracer was already set to
581          * the irqstate after the iret */
582         DISABLE_INTERRUPTS(CLBR_EAX)
583         lss (%esp), %esp                /* switch to espfix segment */
584         CFI_ADJUST_CFA_OFFSET -8
585         jmp restore_nocheck
586         CFI_ENDPROC
587 ENDPROC(system_call)
588
589         # perform work that needs to be done immediately before resumption
590         ALIGN
591         RING0_PTREGS_FRAME              # can't unwind into user space anyway
592 work_pending:
593         testb $_TIF_NEED_RESCHED, %cl
594         jz work_notifysig
595 work_resched:
596         call schedule
597         LOCKDEP_SYS_EXIT
598         DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt
599                                         # setting need_resched or sigpending
600                                         # between sampling and the iret
601         TRACE_IRQS_OFF
602         movl TI_flags(%ebp), %ecx
603         andl $_TIF_WORK_MASK, %ecx      # is there any work to be done other
604                                         # than syscall tracing?
605         jz restore_all
606         testb $_TIF_NEED_RESCHED, %cl
607         jnz work_resched
608
609 work_notifysig:                         # deal with pending signals and
610                                         # notify-resume requests
611 #ifdef CONFIG_VM86
612         testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
613         movl %esp, %eax
614         jne work_notifysig_v86          # returning to kernel-space or
615                                         # vm86-space
616         TRACE_IRQS_ON
617         ENABLE_INTERRUPTS(CLBR_NONE)
618         xorl %edx, %edx
619         call do_notify_resume
620         jmp resume_userspace_sig
621
622         ALIGN
623 work_notifysig_v86:
624         pushl_cfi %ecx                  # save ti_flags for do_notify_resume
625         call save_v86_state             # %eax contains pt_regs pointer
626         popl_cfi %ecx
627         movl %eax, %esp
628 #else
629         movl %esp, %eax
630 #endif
631         TRACE_IRQS_ON
632         ENABLE_INTERRUPTS(CLBR_NONE)
633         xorl %edx, %edx
634         call do_notify_resume
635         jmp resume_userspace_sig
636 END(work_pending)
637
638         # perform syscall exit tracing
639         ALIGN
640 syscall_trace_entry:
641         movl $-ENOSYS,PT_EAX(%esp)
642         movl %esp, %eax
643         call syscall_trace_enter
644         /* What it returned is what we'll actually use.  */
645         cmpl $(NR_syscalls), %eax
646         jnae syscall_call
647         jmp syscall_exit
648 END(syscall_trace_entry)
649
650         # perform syscall exit tracing
651         ALIGN
652 syscall_exit_work:
653         testl $_TIF_WORK_SYSCALL_EXIT, %ecx
654         jz work_pending
655         TRACE_IRQS_ON
656         ENABLE_INTERRUPTS(CLBR_ANY)     # could let syscall_trace_leave() call
657                                         # schedule() instead
658         movl %esp, %eax
659         call syscall_trace_leave
660         jmp resume_userspace
661 END(syscall_exit_work)
662         CFI_ENDPROC
663
664         RING0_INT_FRAME                 # can't unwind into user space anyway
665 syscall_fault:
666         GET_THREAD_INFO(%ebp)
667         movl $-EFAULT,PT_EAX(%esp)
668         jmp resume_userspace
669 END(syscall_fault)
670
671 syscall_badsys:
672         movl $-ENOSYS,PT_EAX(%esp)
673         jmp resume_userspace
674 END(syscall_badsys)
675         CFI_ENDPROC
676 /*
677  * End of kprobes section
678  */
679         .popsection
680
681 /*
682  * System calls that need a pt_regs pointer.
683  */
684 #define PTREGSCALL0(name) \
685 ENTRY(ptregs_##name) ;  \
686         leal 4(%esp),%eax; \
687         jmp sys_##name; \
688 ENDPROC(ptregs_##name)
689
690 #define PTREGSCALL1(name) \
691 ENTRY(ptregs_##name) ; \
692         leal 4(%esp),%edx; \
693         movl (PT_EBX+4)(%esp),%eax; \
694         jmp sys_##name; \
695 ENDPROC(ptregs_##name)
696
697 #define PTREGSCALL2(name) \
698 ENTRY(ptregs_##name) ; \
699         leal 4(%esp),%ecx; \
700         movl (PT_ECX+4)(%esp),%edx; \
701         movl (PT_EBX+4)(%esp),%eax; \
702         jmp sys_##name; \
703 ENDPROC(ptregs_##name)
704
705 #define PTREGSCALL3(name) \
706 ENTRY(ptregs_##name) ; \
707         CFI_STARTPROC; \
708         leal 4(%esp),%eax; \
709         pushl_cfi %eax; \
710         movl PT_EDX(%eax),%ecx; \
711         movl PT_ECX(%eax),%edx; \
712         movl PT_EBX(%eax),%eax; \
713         call sys_##name; \
714         addl $4,%esp; \
715         CFI_ADJUST_CFA_OFFSET -4; \
716         ret; \
717         CFI_ENDPROC; \
718 ENDPROC(ptregs_##name)
719
720 PTREGSCALL1(iopl)
721 PTREGSCALL0(fork)
722 PTREGSCALL0(vfork)
723 PTREGSCALL3(execve)
724 PTREGSCALL2(sigaltstack)
725 PTREGSCALL0(sigreturn)
726 PTREGSCALL0(rt_sigreturn)
727 PTREGSCALL2(vm86)
728 PTREGSCALL1(vm86old)
729
730 /* Clone is an oddball.  The 4th arg is in %edi */
731 ENTRY(ptregs_clone)
732         CFI_STARTPROC
733         leal 4(%esp),%eax
734         pushl_cfi %eax
735         pushl_cfi PT_EDI(%eax)
736         movl PT_EDX(%eax),%ecx
737         movl PT_ECX(%eax),%edx
738         movl PT_EBX(%eax),%eax
739         call sys_clone
740         addl $8,%esp
741         CFI_ADJUST_CFA_OFFSET -8
742         ret
743         CFI_ENDPROC
744 ENDPROC(ptregs_clone)
745
746 .macro FIXUP_ESPFIX_STACK
747 /*
748  * Switch back for ESPFIX stack to the normal zerobased stack
749  *
750  * We can't call C functions using the ESPFIX stack. This code reads
751  * the high word of the segment base from the GDT and swiches to the
752  * normal stack and adjusts ESP with the matching offset.
753  */
754         /* fixup the stack */
755         mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
756         mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
757         shl $16, %eax
758         addl %esp, %eax                 /* the adjusted stack pointer */
759         pushl_cfi $__KERNEL_DS
760         pushl_cfi %eax
761         lss (%esp), %esp                /* switch to the normal stack segment */
762         CFI_ADJUST_CFA_OFFSET -8
763 .endm
764 .macro UNWIND_ESPFIX_STACK
765         movl %ss, %eax
766         /* see if on espfix stack */
767         cmpw $__ESPFIX_SS, %ax
768         jne 27f
769         movl $__KERNEL_DS, %eax
770         movl %eax, %ds
771         movl %eax, %es
772         /* switch to normal stack */
773         FIXUP_ESPFIX_STACK
774 27:
775 .endm
776
777 /*
778  * Build the entry stubs and pointer table with some assembler magic.
779  * We pack 7 stubs into a single 32-byte chunk, which will fit in a
780  * single cache line on all modern x86 implementations.
781  */
782 .section .init.rodata,"a"
783 ENTRY(interrupt)
784 .section .entry.text, "ax"
785         .p2align 5
786         .p2align CONFIG_X86_L1_CACHE_SHIFT
787 ENTRY(irq_entries_start)
788         RING0_INT_FRAME
789 vector=FIRST_EXTERNAL_VECTOR
790 .rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
791         .balign 32
792   .rept 7
793     .if vector < NR_VECTORS
794       .if vector <> FIRST_EXTERNAL_VECTOR
795         CFI_ADJUST_CFA_OFFSET -4
796       .endif
797 1:      pushl_cfi $(~vector+0x80)       /* Note: always in signed byte range */
798       .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
799         jmp 2f
800       .endif
801       .previous
802         .long 1b
803       .section .entry.text, "ax"
804 vector=vector+1
805     .endif
806   .endr
807 2:      jmp common_interrupt
808 .endr
809 END(irq_entries_start)
810
811 .previous
812 END(interrupt)
813 .previous
814
815 /*
816  * the CPU automatically disables interrupts when executing an IRQ vector,
817  * so IRQ-flags tracing has to follow that:
818  */
819         .p2align CONFIG_X86_L1_CACHE_SHIFT
820 common_interrupt:
821         addl $-0x80,(%esp)      /* Adjust vector into the [-256,-1] range */
822         SAVE_ALL
823         TRACE_IRQS_OFF
824         movl %esp,%eax
825         call do_IRQ
826         jmp ret_from_intr
827 ENDPROC(common_interrupt)
828         CFI_ENDPROC
829
830 /*
831  *  Irq entries should be protected against kprobes
832  */
833         .pushsection .kprobes.text, "ax"
834 #define BUILD_INTERRUPT3(name, nr, fn)  \
835 ENTRY(name)                             \
836         RING0_INT_FRAME;                \
837         pushl_cfi $~(nr);               \
838         SAVE_ALL;                       \
839         TRACE_IRQS_OFF                  \
840         movl %esp,%eax;                 \
841         call fn;                        \
842         jmp ret_from_intr;              \
843         CFI_ENDPROC;                    \
844 ENDPROC(name)
845
846 #define BUILD_INTERRUPT(name, nr)       BUILD_INTERRUPT3(name, nr, smp_##name)
847
848 /* The include is where all of the SMP etc. interrupts come from */
849 #include <asm/entry_arch.h>
850
851 ENTRY(coprocessor_error)
852         RING0_INT_FRAME
853         pushl_cfi $0
854         pushl_cfi $do_coprocessor_error
855         jmp error_code
856         CFI_ENDPROC
857 END(coprocessor_error)
858
859 ENTRY(simd_coprocessor_error)
860         RING0_INT_FRAME
861         pushl_cfi $0
862 #ifdef CONFIG_X86_INVD_BUG
863         /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
864 661:    pushl_cfi $do_general_protection
865 662:
866 .section .altinstructions,"a"
867         altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
868 .previous
869 .section .altinstr_replacement,"ax"
870 663:    pushl $do_simd_coprocessor_error
871 664:
872 .previous
873 #else
874         pushl_cfi $do_simd_coprocessor_error
875 #endif
876         jmp error_code
877         CFI_ENDPROC
878 END(simd_coprocessor_error)
879
880 ENTRY(device_not_available)
881         RING0_INT_FRAME
882         pushl_cfi $-1                   # mark this as an int
883         pushl_cfi $do_device_not_available
884         jmp error_code
885         CFI_ENDPROC
886 END(device_not_available)
887
888 #ifdef CONFIG_PARAVIRT
889 ENTRY(native_iret)
890         iret
891         _ASM_EXTABLE(native_iret, iret_exc)
892 END(native_iret)
893
894 ENTRY(native_irq_enable_sysexit)
895         sti
896         sysexit
897 END(native_irq_enable_sysexit)
898 #endif
899
900 ENTRY(overflow)
901         RING0_INT_FRAME
902         pushl_cfi $0
903         pushl_cfi $do_overflow
904         jmp error_code
905         CFI_ENDPROC
906 END(overflow)
907
908 ENTRY(bounds)
909         RING0_INT_FRAME
910         pushl_cfi $0
911         pushl_cfi $do_bounds
912         jmp error_code
913         CFI_ENDPROC
914 END(bounds)
915
916 ENTRY(invalid_op)
917         RING0_INT_FRAME
918         pushl_cfi $0
919         pushl_cfi $do_invalid_op
920         jmp error_code
921         CFI_ENDPROC
922 END(invalid_op)
923
924 ENTRY(coprocessor_segment_overrun)
925         RING0_INT_FRAME
926         pushl_cfi $0
927         pushl_cfi $do_coprocessor_segment_overrun
928         jmp error_code
929         CFI_ENDPROC
930 END(coprocessor_segment_overrun)
931
932 ENTRY(invalid_TSS)
933         RING0_EC_FRAME
934         pushl_cfi $do_invalid_TSS
935         jmp error_code
936         CFI_ENDPROC
937 END(invalid_TSS)
938
939 ENTRY(segment_not_present)
940         RING0_EC_FRAME
941         pushl_cfi $do_segment_not_present
942         jmp error_code
943         CFI_ENDPROC
944 END(segment_not_present)
945
946 ENTRY(stack_segment)
947         RING0_EC_FRAME
948         pushl_cfi $do_stack_segment
949         jmp error_code
950         CFI_ENDPROC
951 END(stack_segment)
952
953 ENTRY(alignment_check)
954         RING0_EC_FRAME
955         pushl_cfi $do_alignment_check
956         jmp error_code
957         CFI_ENDPROC
958 END(alignment_check)
959
960 ENTRY(divide_error)
961         RING0_INT_FRAME
962         pushl_cfi $0                    # no error code
963         pushl_cfi $do_divide_error
964         jmp error_code
965         CFI_ENDPROC
966 END(divide_error)
967
968 #ifdef CONFIG_X86_MCE
969 ENTRY(machine_check)
970         RING0_INT_FRAME
971         pushl_cfi $0
972         pushl_cfi machine_check_vector
973         jmp error_code
974         CFI_ENDPROC
975 END(machine_check)
976 #endif
977
978 ENTRY(spurious_interrupt_bug)
979         RING0_INT_FRAME
980         pushl_cfi $0
981         pushl_cfi $do_spurious_interrupt_bug
982         jmp error_code
983         CFI_ENDPROC
984 END(spurious_interrupt_bug)
985 /*
986  * End of kprobes section
987  */
988         .popsection
989
990 ENTRY(kernel_thread_helper)
991         pushl $0                # fake return address for unwinder
992         CFI_STARTPROC
993         movl %edi,%eax
994         call *%esi
995         call do_exit
996         ud2                     # padding for call trace
997         CFI_ENDPROC
998 ENDPROC(kernel_thread_helper)
999
1000 #ifdef CONFIG_XEN
1001 /* Xen doesn't set %esp to be precisely what the normal sysenter
1002    entrypoint expects, so fix it up before using the normal path. */
1003 ENTRY(xen_sysenter_target)
1004         RING0_INT_FRAME
1005         addl $5*4, %esp         /* remove xen-provided frame */
1006         CFI_ADJUST_CFA_OFFSET -5*4
1007         jmp sysenter_past_esp
1008         CFI_ENDPROC
1009
1010 ENTRY(xen_hypervisor_callback)
1011         CFI_STARTPROC
1012         pushl_cfi $0
1013         SAVE_ALL
1014         TRACE_IRQS_OFF
1015
1016         /* Check to see if we got the event in the critical
1017            region in xen_iret_direct, after we've reenabled
1018            events and checked for pending events.  This simulates
1019            iret instruction's behaviour where it delivers a
1020            pending interrupt when enabling interrupts. */
1021         movl PT_EIP(%esp),%eax
1022         cmpl $xen_iret_start_crit,%eax
1023         jb   1f
1024         cmpl $xen_iret_end_crit,%eax
1025         jae  1f
1026
1027         jmp  xen_iret_crit_fixup
1028
1029 ENTRY(xen_do_upcall)
1030 1:      mov %esp, %eax
1031         call xen_evtchn_do_upcall
1032         jmp  ret_from_intr
1033         CFI_ENDPROC
1034 ENDPROC(xen_hypervisor_callback)
1035
1036 # Hypervisor uses this for application faults while it executes.
1037 # We get here for two reasons:
1038 #  1. Fault while reloading DS, ES, FS or GS
1039 #  2. Fault while executing IRET
1040 # Category 1 we fix up by reattempting the load, and zeroing the segment
1041 # register if the load fails.
1042 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1043 # normal Linux return path in this case because if we use the IRET hypercall
1044 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1045 # We distinguish between categories by maintaining a status value in EAX.
1046 ENTRY(xen_failsafe_callback)
1047         CFI_STARTPROC
1048         pushl_cfi %eax
1049         movl $1,%eax
1050 1:      mov 4(%esp),%ds
1051 2:      mov 8(%esp),%es
1052 3:      mov 12(%esp),%fs
1053 4:      mov 16(%esp),%gs
1054         testl %eax,%eax
1055         popl_cfi %eax
1056         lea 16(%esp),%esp
1057         CFI_ADJUST_CFA_OFFSET -16
1058         jz 5f
1059         addl $16,%esp
1060         jmp iret_exc            # EAX != 0 => Category 2 (Bad IRET)
1061 5:      pushl_cfi $0            # EAX == 0 => Category 1 (Bad segment)
1062         SAVE_ALL
1063         jmp ret_from_exception
1064         CFI_ENDPROC
1065
1066 .section .fixup,"ax"
1067 6:      xorl %eax,%eax
1068         movl %eax,4(%esp)
1069         jmp 1b
1070 7:      xorl %eax,%eax
1071         movl %eax,8(%esp)
1072         jmp 2b
1073 8:      xorl %eax,%eax
1074         movl %eax,12(%esp)
1075         jmp 3b
1076 9:      xorl %eax,%eax
1077         movl %eax,16(%esp)
1078         jmp 4b
1079 .previous
1080         _ASM_EXTABLE(1b,6b)
1081         _ASM_EXTABLE(2b,7b)
1082         _ASM_EXTABLE(3b,8b)
1083         _ASM_EXTABLE(4b,9b)
1084 ENDPROC(xen_failsafe_callback)
1085
1086 BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1087                 xen_evtchn_do_upcall)
1088
1089 #endif  /* CONFIG_XEN */
1090
1091 #ifdef CONFIG_FUNCTION_TRACER
1092 #ifdef CONFIG_DYNAMIC_FTRACE
1093
1094 ENTRY(mcount)
1095         ret
1096 END(mcount)
1097
1098 ENTRY(ftrace_caller)
1099         cmpl $0, function_trace_stop
1100         jne  ftrace_stub
1101
1102         pushl %eax
1103         pushl %ecx
1104         pushl %edx
1105         movl 0xc(%esp), %eax
1106         movl 0x4(%ebp), %edx
1107         subl $MCOUNT_INSN_SIZE, %eax
1108
1109 .globl ftrace_call
1110 ftrace_call:
1111         call ftrace_stub
1112
1113         popl %edx
1114         popl %ecx
1115         popl %eax
1116 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1117 .globl ftrace_graph_call
1118 ftrace_graph_call:
1119         jmp ftrace_stub
1120 #endif
1121
1122 .globl ftrace_stub
1123 ftrace_stub:
1124         ret
1125 END(ftrace_caller)
1126
1127 #else /* ! CONFIG_DYNAMIC_FTRACE */
1128
1129 ENTRY(mcount)
1130         cmpl $0, function_trace_stop
1131         jne  ftrace_stub
1132
1133         cmpl $ftrace_stub, ftrace_trace_function
1134         jnz trace
1135 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1136         cmpl $ftrace_stub, ftrace_graph_return
1137         jnz ftrace_graph_caller
1138
1139         cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1140         jnz ftrace_graph_caller
1141 #endif
1142 .globl ftrace_stub
1143 ftrace_stub:
1144         ret
1145
1146         /* taken from glibc */
1147 trace:
1148         pushl %eax
1149         pushl %ecx
1150         pushl %edx
1151         movl 0xc(%esp), %eax
1152         movl 0x4(%ebp), %edx
1153         subl $MCOUNT_INSN_SIZE, %eax
1154
1155         call *ftrace_trace_function
1156
1157         popl %edx
1158         popl %ecx
1159         popl %eax
1160         jmp ftrace_stub
1161 END(mcount)
1162 #endif /* CONFIG_DYNAMIC_FTRACE */
1163 #endif /* CONFIG_FUNCTION_TRACER */
1164
1165 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
1166 ENTRY(ftrace_graph_caller)
1167         cmpl $0, function_trace_stop
1168         jne ftrace_stub
1169
1170         pushl %eax
1171         pushl %ecx
1172         pushl %edx
1173         movl 0xc(%esp), %edx
1174         lea 0x4(%ebp), %eax
1175         movl (%ebp), %ecx
1176         subl $MCOUNT_INSN_SIZE, %edx
1177         call prepare_ftrace_return
1178         popl %edx
1179         popl %ecx
1180         popl %eax
1181         ret
1182 END(ftrace_graph_caller)
1183
1184 .globl return_to_handler
1185 return_to_handler:
1186         pushl %eax
1187         pushl %edx
1188         movl %ebp, %eax
1189         call ftrace_return_to_handler
1190         movl %eax, %ecx
1191         popl %edx
1192         popl %eax
1193         jmp *%ecx
1194 #endif
1195
1196 /*
1197  * Some functions should be protected against kprobes
1198  */
1199         .pushsection .kprobes.text, "ax"
1200
1201 ENTRY(page_fault)
1202         RING0_EC_FRAME
1203         pushl_cfi $do_page_fault
1204         ALIGN
1205 error_code:
1206         /* the function address is in %gs's slot on the stack */
1207         pushl_cfi %fs
1208         /*CFI_REL_OFFSET fs, 0*/
1209         pushl_cfi %es
1210         /*CFI_REL_OFFSET es, 0*/
1211         pushl_cfi %ds
1212         /*CFI_REL_OFFSET ds, 0*/
1213         pushl_cfi %eax
1214         CFI_REL_OFFSET eax, 0
1215         pushl_cfi %ebp
1216         CFI_REL_OFFSET ebp, 0
1217         pushl_cfi %edi
1218         CFI_REL_OFFSET edi, 0
1219         pushl_cfi %esi
1220         CFI_REL_OFFSET esi, 0
1221         pushl_cfi %edx
1222         CFI_REL_OFFSET edx, 0
1223         pushl_cfi %ecx
1224         CFI_REL_OFFSET ecx, 0
1225         pushl_cfi %ebx
1226         CFI_REL_OFFSET ebx, 0
1227         cld
1228         movl $(__KERNEL_PERCPU), %ecx
1229         movl %ecx, %fs
1230         UNWIND_ESPFIX_STACK
1231         GS_TO_REG %ecx
1232         movl PT_GS(%esp), %edi          # get the function address
1233         movl PT_ORIG_EAX(%esp), %edx    # get the error code
1234         movl $-1, PT_ORIG_EAX(%esp)     # no syscall to restart
1235         REG_TO_PTGS %ecx
1236         SET_KERNEL_GS %ecx
1237         movl $(__USER_DS), %ecx
1238         movl %ecx, %ds
1239         movl %ecx, %es
1240         TRACE_IRQS_OFF
1241         movl %esp,%eax                  # pt_regs pointer
1242         call *%edi
1243         jmp ret_from_exception
1244         CFI_ENDPROC
1245 END(page_fault)
1246
1247 /*
1248  * Debug traps and NMI can happen at the one SYSENTER instruction
1249  * that sets up the real kernel stack. Check here, since we can't
1250  * allow the wrong stack to be used.
1251  *
1252  * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1253  * already pushed 3 words if it hits on the sysenter instruction:
1254  * eflags, cs and eip.
1255  *
1256  * We just load the right stack, and push the three (known) values
1257  * by hand onto the new stack - while updating the return eip past
1258  * the instruction that would have done it for sysenter.
1259  */
1260 .macro FIX_STACK offset ok label
1261         cmpw $__KERNEL_CS, 4(%esp)
1262         jne \ok
1263 \label:
1264         movl TSS_sysenter_sp0 + \offset(%esp), %esp
1265         CFI_DEF_CFA esp, 0
1266         CFI_UNDEFINED eip
1267         pushfl_cfi
1268         pushl_cfi $__KERNEL_CS
1269         pushl_cfi $sysenter_past_esp
1270         CFI_REL_OFFSET eip, 0
1271 .endm
1272
1273 ENTRY(debug)
1274         RING0_INT_FRAME
1275         cmpl $ia32_sysenter_target,(%esp)
1276         jne debug_stack_correct
1277         FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
1278 debug_stack_correct:
1279         pushl_cfi $-1                   # mark this as an int
1280         SAVE_ALL
1281         TRACE_IRQS_OFF
1282         xorl %edx,%edx                  # error code 0
1283         movl %esp,%eax                  # pt_regs pointer
1284         call do_debug
1285         jmp ret_from_exception
1286         CFI_ENDPROC
1287 END(debug)
1288
1289 /*
1290  * NMI is doubly nasty. It can happen _while_ we're handling
1291  * a debug fault, and the debug fault hasn't yet been able to
1292  * clear up the stack. So we first check whether we got  an
1293  * NMI on the sysenter entry path, but after that we need to
1294  * check whether we got an NMI on the debug path where the debug
1295  * fault happened on the sysenter path.
1296  */
1297 ENTRY(nmi)
1298         RING0_INT_FRAME
1299         pushl_cfi %eax
1300         movl %ss, %eax
1301         cmpw $__ESPFIX_SS, %ax
1302         popl_cfi %eax
1303         je nmi_espfix_stack
1304         cmpl $ia32_sysenter_target,(%esp)
1305         je nmi_stack_fixup
1306         pushl_cfi %eax
1307         movl %esp,%eax
1308         /* Do not access memory above the end of our stack page,
1309          * it might not exist.
1310          */
1311         andl $(THREAD_SIZE-1),%eax
1312         cmpl $(THREAD_SIZE-20),%eax
1313         popl_cfi %eax
1314         jae nmi_stack_correct
1315         cmpl $ia32_sysenter_target,12(%esp)
1316         je nmi_debug_stack_check
1317 nmi_stack_correct:
1318         /* We have a RING0_INT_FRAME here */
1319         pushl_cfi %eax
1320         SAVE_ALL
1321         xorl %edx,%edx          # zero error code
1322         movl %esp,%eax          # pt_regs pointer
1323         call do_nmi
1324         jmp restore_all_notrace
1325         CFI_ENDPROC
1326
1327 nmi_stack_fixup:
1328         RING0_INT_FRAME
1329         FIX_STACK 12, nmi_stack_correct, 1
1330         jmp nmi_stack_correct
1331
1332 nmi_debug_stack_check:
1333         /* We have a RING0_INT_FRAME here */
1334         cmpw $__KERNEL_CS,16(%esp)
1335         jne nmi_stack_correct
1336         cmpl $debug,(%esp)
1337         jb nmi_stack_correct
1338         cmpl $debug_esp_fix_insn,(%esp)
1339         ja nmi_stack_correct
1340         FIX_STACK 24, nmi_stack_correct, 1
1341         jmp nmi_stack_correct
1342
1343 nmi_espfix_stack:
1344         /* We have a RING0_INT_FRAME here.
1345          *
1346          * create the pointer to lss back
1347          */
1348         pushl_cfi %ss
1349         pushl_cfi %esp
1350         addl $4, (%esp)
1351         /* copy the iret frame of 12 bytes */
1352         .rept 3
1353         pushl_cfi 16(%esp)
1354         .endr
1355         pushl_cfi %eax
1356         SAVE_ALL
1357         FIXUP_ESPFIX_STACK              # %eax == %esp
1358         xorl %edx,%edx                  # zero error code
1359         call do_nmi
1360         RESTORE_REGS
1361         lss 12+4(%esp), %esp            # back to espfix stack
1362         CFI_ADJUST_CFA_OFFSET -24
1363         jmp irq_return
1364         CFI_ENDPROC
1365 END(nmi)
1366
1367 ENTRY(int3)
1368         RING0_INT_FRAME
1369         pushl_cfi $-1                   # mark this as an int
1370         SAVE_ALL
1371         TRACE_IRQS_OFF
1372         xorl %edx,%edx          # zero error code
1373         movl %esp,%eax          # pt_regs pointer
1374         call do_int3
1375         jmp ret_from_exception
1376         CFI_ENDPROC
1377 END(int3)
1378
1379 ENTRY(general_protection)
1380         RING0_EC_FRAME
1381         pushl_cfi $do_general_protection
1382         jmp error_code
1383         CFI_ENDPROC
1384 END(general_protection)
1385
1386 #ifdef CONFIG_KVM_GUEST
1387 ENTRY(async_page_fault)
1388         RING0_EC_FRAME
1389         pushl_cfi $do_async_page_fault
1390         jmp error_code
1391         CFI_ENDPROC
1392 END(async_page_fault)
1393 #endif
1394
1395 /*
1396  * End of kprobes section
1397  */
1398         .popsection