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