Pull bugzilla-5737 into release branch
[pandora-kernel.git] / arch / i386 / kernel / entry.S
1 /*
2  *  linux/arch/i386/entry.S
3  *
4  *  Copyright (C) 1991, 1992  Linus Torvalds
5  */
6
7 /*
8  * entry.S contains the system-call and fault low-level handling routines.
9  * This also contains the timer-interrupt handler, as well as all interrupts
10  * and faults that can result in a task-switch.
11  *
12  * NOTE: This code handles signal-recognition, which happens every time
13  * after a timer-interrupt and after each system call.
14  *
15  * I changed all the .align's to 4 (16 byte alignment), as that's faster
16  * on a 486.
17  *
18  * Stack layout in 'ret_from_system_call':
19  *      ptrace needs to have all regs on the stack.
20  *      if the order here is changed, it needs to be
21  *      updated in fork.c:copy_process, signal.c:do_signal,
22  *      ptrace.c and ptrace.h
23  *
24  *       0(%esp) - %ebx
25  *       4(%esp) - %ecx
26  *       8(%esp) - %edx
27  *       C(%esp) - %esi
28  *      10(%esp) - %edi
29  *      14(%esp) - %ebp
30  *      18(%esp) - %eax
31  *      1C(%esp) - %ds
32  *      20(%esp) - %es
33  *      24(%esp) - orig_eax
34  *      28(%esp) - %eip
35  *      2C(%esp) - %cs
36  *      30(%esp) - %eflags
37  *      34(%esp) - %oldesp
38  *      38(%esp) - %oldss
39  *
40  * "current" is in register %ebx during any slow entries.
41  */
42
43 #include <linux/config.h>
44 #include <linux/linkage.h>
45 #include <asm/thread_info.h>
46 #include <asm/errno.h>
47 #include <asm/segment.h>
48 #include <asm/smp.h>
49 #include <asm/page.h>
50 #include <asm/desc.h>
51 #include <asm/dwarf2.h>
52 #include "irq_vectors.h"
53
54 #define nr_syscalls ((syscall_table_size)/4)
55
56 EBX             = 0x00
57 ECX             = 0x04
58 EDX             = 0x08
59 ESI             = 0x0C
60 EDI             = 0x10
61 EBP             = 0x14
62 EAX             = 0x18
63 DS              = 0x1C
64 ES              = 0x20
65 ORIG_EAX        = 0x24
66 EIP             = 0x28
67 CS              = 0x2C
68 EFLAGS          = 0x30
69 OLDESP          = 0x34
70 OLDSS           = 0x38
71
72 CF_MASK         = 0x00000001
73 TF_MASK         = 0x00000100
74 IF_MASK         = 0x00000200
75 DF_MASK         = 0x00000400 
76 NT_MASK         = 0x00004000
77 VM_MASK         = 0x00020000
78
79 #ifdef CONFIG_PREEMPT
80 #define preempt_stop            cli
81 #else
82 #define preempt_stop
83 #define resume_kernel           restore_nocheck
84 #endif
85
86 #define SAVE_ALL \
87         cld; \
88         pushl %es; \
89         CFI_ADJUST_CFA_OFFSET 4;\
90         /*CFI_REL_OFFSET es, 0;*/\
91         pushl %ds; \
92         CFI_ADJUST_CFA_OFFSET 4;\
93         /*CFI_REL_OFFSET ds, 0;*/\
94         pushl %eax; \
95         CFI_ADJUST_CFA_OFFSET 4;\
96         CFI_REL_OFFSET eax, 0;\
97         pushl %ebp; \
98         CFI_ADJUST_CFA_OFFSET 4;\
99         CFI_REL_OFFSET ebp, 0;\
100         pushl %edi; \
101         CFI_ADJUST_CFA_OFFSET 4;\
102         CFI_REL_OFFSET edi, 0;\
103         pushl %esi; \
104         CFI_ADJUST_CFA_OFFSET 4;\
105         CFI_REL_OFFSET esi, 0;\
106         pushl %edx; \
107         CFI_ADJUST_CFA_OFFSET 4;\
108         CFI_REL_OFFSET edx, 0;\
109         pushl %ecx; \
110         CFI_ADJUST_CFA_OFFSET 4;\
111         CFI_REL_OFFSET ecx, 0;\
112         pushl %ebx; \
113         CFI_ADJUST_CFA_OFFSET 4;\
114         CFI_REL_OFFSET ebx, 0;\
115         movl $(__USER_DS), %edx; \
116         movl %edx, %ds; \
117         movl %edx, %es;
118
119 #define RESTORE_INT_REGS \
120         popl %ebx;      \
121         CFI_ADJUST_CFA_OFFSET -4;\
122         CFI_RESTORE ebx;\
123         popl %ecx;      \
124         CFI_ADJUST_CFA_OFFSET -4;\
125         CFI_RESTORE ecx;\
126         popl %edx;      \
127         CFI_ADJUST_CFA_OFFSET -4;\
128         CFI_RESTORE edx;\
129         popl %esi;      \
130         CFI_ADJUST_CFA_OFFSET -4;\
131         CFI_RESTORE esi;\
132         popl %edi;      \
133         CFI_ADJUST_CFA_OFFSET -4;\
134         CFI_RESTORE edi;\
135         popl %ebp;      \
136         CFI_ADJUST_CFA_OFFSET -4;\
137         CFI_RESTORE ebp;\
138         popl %eax;      \
139         CFI_ADJUST_CFA_OFFSET -4;\
140         CFI_RESTORE eax
141
142 #define RESTORE_REGS    \
143         RESTORE_INT_REGS; \
144 1:      popl %ds;       \
145         CFI_ADJUST_CFA_OFFSET -4;\
146         /*CFI_RESTORE ds;*/\
147 2:      popl %es;       \
148         CFI_ADJUST_CFA_OFFSET -4;\
149         /*CFI_RESTORE es;*/\
150 .section .fixup,"ax";   \
151 3:      movl $0,(%esp); \
152         jmp 1b;         \
153 4:      movl $0,(%esp); \
154         jmp 2b;         \
155 .previous;              \
156 .section __ex_table,"a";\
157         .align 4;       \
158         .long 1b,3b;    \
159         .long 2b,4b;    \
160 .previous
161
162 #define RING0_INT_FRAME \
163         CFI_STARTPROC simple;\
164         CFI_DEF_CFA esp, 3*4;\
165         /*CFI_OFFSET cs, -2*4;*/\
166         CFI_OFFSET eip, -3*4
167
168 #define RING0_EC_FRAME \
169         CFI_STARTPROC simple;\
170         CFI_DEF_CFA esp, 4*4;\
171         /*CFI_OFFSET cs, -2*4;*/\
172         CFI_OFFSET eip, -3*4
173
174 #define RING0_PTREGS_FRAME \
175         CFI_STARTPROC simple;\
176         CFI_DEF_CFA esp, OLDESP-EBX;\
177         /*CFI_OFFSET cs, CS-OLDESP;*/\
178         CFI_OFFSET eip, EIP-OLDESP;\
179         /*CFI_OFFSET es, ES-OLDESP;*/\
180         /*CFI_OFFSET ds, DS-OLDESP;*/\
181         CFI_OFFSET eax, EAX-OLDESP;\
182         CFI_OFFSET ebp, EBP-OLDESP;\
183         CFI_OFFSET edi, EDI-OLDESP;\
184         CFI_OFFSET esi, ESI-OLDESP;\
185         CFI_OFFSET edx, EDX-OLDESP;\
186         CFI_OFFSET ecx, ECX-OLDESP;\
187         CFI_OFFSET ebx, EBX-OLDESP
188
189 ENTRY(ret_from_fork)
190         CFI_STARTPROC
191         pushl %eax
192         CFI_ADJUST_CFA_OFFSET -4
193         call schedule_tail
194         GET_THREAD_INFO(%ebp)
195         popl %eax
196         CFI_ADJUST_CFA_OFFSET -4
197         jmp syscall_exit
198         CFI_ENDPROC
199
200 /*
201  * Return to user mode is not as complex as all this looks,
202  * but we want the default path for a system call return to
203  * go as quickly as possible which is why some of this is
204  * less clear than it otherwise should be.
205  */
206
207         # userspace resumption stub bypassing syscall exit tracing
208         ALIGN
209         RING0_PTREGS_FRAME
210 ret_from_exception:
211         preempt_stop
212 ret_from_intr:
213         GET_THREAD_INFO(%ebp)
214         movl EFLAGS(%esp), %eax         # mix EFLAGS and CS
215         movb CS(%esp), %al
216         testl $(VM_MASK | 3), %eax
217         jz resume_kernel
218 ENTRY(resume_userspace)
219         cli                             # make sure we don't miss an interrupt
220                                         # setting need_resched or sigpending
221                                         # between sampling and the iret
222         movl TI_flags(%ebp), %ecx
223         andl $_TIF_WORK_MASK, %ecx      # is there any work to be done on
224                                         # int/exception return?
225         jne work_pending
226         jmp restore_all
227
228 #ifdef CONFIG_PREEMPT
229 ENTRY(resume_kernel)
230         cli
231         cmpl $0,TI_preempt_count(%ebp)  # non-zero preempt_count ?
232         jnz restore_nocheck
233 need_resched:
234         movl TI_flags(%ebp), %ecx       # need_resched set ?
235         testb $_TIF_NEED_RESCHED, %cl
236         jz restore_all
237         testl $IF_MASK,EFLAGS(%esp)     # interrupts off (exception path) ?
238         jz restore_all
239         call preempt_schedule_irq
240         jmp need_resched
241 #endif
242         CFI_ENDPROC
243
244 /* SYSENTER_RETURN points to after the "sysenter" instruction in
245    the vsyscall page.  See vsyscall-sysentry.S, which defines the symbol.  */
246
247         # sysenter call handler stub
248 ENTRY(sysenter_entry)
249         CFI_STARTPROC simple
250         CFI_DEF_CFA esp, 0
251         CFI_REGISTER esp, ebp
252         movl TSS_sysenter_esp0(%esp),%esp
253 sysenter_past_esp:
254         sti
255         pushl $(__USER_DS)
256         CFI_ADJUST_CFA_OFFSET 4
257         /*CFI_REL_OFFSET ss, 0*/
258         pushl %ebp
259         CFI_ADJUST_CFA_OFFSET 4
260         CFI_REL_OFFSET esp, 0
261         pushfl
262         CFI_ADJUST_CFA_OFFSET 4
263         pushl $(__USER_CS)
264         CFI_ADJUST_CFA_OFFSET 4
265         /*CFI_REL_OFFSET cs, 0*/
266         pushl $SYSENTER_RETURN
267         CFI_ADJUST_CFA_OFFSET 4
268         CFI_REL_OFFSET eip, 0
269
270 /*
271  * Load the potential sixth argument from user stack.
272  * Careful about security.
273  */
274         cmpl $__PAGE_OFFSET-3,%ebp
275         jae syscall_fault
276 1:      movl (%ebp),%ebp
277 .section __ex_table,"a"
278         .align 4
279         .long 1b,syscall_fault
280 .previous
281
282         pushl %eax
283         CFI_ADJUST_CFA_OFFSET 4
284         SAVE_ALL
285         GET_THREAD_INFO(%ebp)
286
287         /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
288         testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
289         jnz syscall_trace_entry
290         cmpl $(nr_syscalls), %eax
291         jae syscall_badsys
292         call *sys_call_table(,%eax,4)
293         movl %eax,EAX(%esp)
294         cli
295         movl TI_flags(%ebp), %ecx
296         testw $_TIF_ALLWORK_MASK, %cx
297         jne syscall_exit_work
298 /* if something modifies registers it must also disable sysexit */
299         movl EIP(%esp), %edx
300         movl OLDESP(%esp), %ecx
301         xorl %ebp,%ebp
302         sti
303         sysexit
304         CFI_ENDPROC
305
306
307         # system call handler stub
308 ENTRY(system_call)
309         RING0_INT_FRAME                 # can't unwind into user space anyway
310         pushl %eax                      # save orig_eax
311         CFI_ADJUST_CFA_OFFSET 4
312         SAVE_ALL
313         GET_THREAD_INFO(%ebp)
314         testl $TF_MASK,EFLAGS(%esp)
315         jz no_singlestep
316         orl $_TIF_SINGLESTEP,TI_flags(%ebp)
317 no_singlestep:
318                                         # system call tracing in operation / emulation
319         /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
320         testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
321         jnz syscall_trace_entry
322         cmpl $(nr_syscalls), %eax
323         jae syscall_badsys
324 syscall_call:
325         call *sys_call_table(,%eax,4)
326         movl %eax,EAX(%esp)             # store the return value
327 syscall_exit:
328         cli                             # make sure we don't miss an interrupt
329                                         # setting need_resched or sigpending
330                                         # between sampling and the iret
331         movl TI_flags(%ebp), %ecx
332         testw $_TIF_ALLWORK_MASK, %cx   # current->work
333         jne syscall_exit_work
334
335 restore_all:
336         movl EFLAGS(%esp), %eax         # mix EFLAGS, SS and CS
337         # Warning: OLDSS(%esp) contains the wrong/random values if we
338         # are returning to the kernel.
339         # See comments in process.c:copy_thread() for details.
340         movb OLDSS(%esp), %ah
341         movb CS(%esp), %al
342         andl $(VM_MASK | (4 << 8) | 3), %eax
343         cmpl $((4 << 8) | 3), %eax
344         CFI_REMEMBER_STATE
345         je ldt_ss                       # returning to user-space with LDT SS
346 restore_nocheck:
347         RESTORE_REGS
348         addl $4, %esp
349         CFI_ADJUST_CFA_OFFSET -4
350 1:      iret
351 .section .fixup,"ax"
352 iret_exc:
353         sti
354         pushl $0                        # no error code
355         pushl $do_iret_error
356         jmp error_code
357 .previous
358 .section __ex_table,"a"
359         .align 4
360         .long 1b,iret_exc
361 .previous
362
363         CFI_RESTORE_STATE
364 ldt_ss:
365         larl OLDSS(%esp), %eax
366         jnz restore_nocheck
367         testl $0x00400000, %eax         # returning to 32bit stack?
368         jnz restore_nocheck             # allright, normal return
369         /* If returning to userspace with 16bit stack,
370          * try to fix the higher word of ESP, as the CPU
371          * won't restore it.
372          * This is an "official" bug of all the x86-compatible
373          * CPUs, which we can try to work around to make
374          * dosemu and wine happy. */
375         subl $8, %esp           # reserve space for switch16 pointer
376         CFI_ADJUST_CFA_OFFSET 8
377         cli
378         movl %esp, %eax
379         /* Set up the 16bit stack frame with switch32 pointer on top,
380          * and a switch16 pointer on top of the current frame. */
381         call setup_x86_bogus_stack
382         CFI_ADJUST_CFA_OFFSET -8        # frame has moved
383         RESTORE_REGS
384         lss 20+4(%esp), %esp    # switch to 16bit stack
385 1:      iret
386 .section __ex_table,"a"
387         .align 4
388         .long 1b,iret_exc
389 .previous
390         CFI_ENDPROC
391
392         # perform work that needs to be done immediately before resumption
393         ALIGN
394         RING0_PTREGS_FRAME              # can't unwind into user space anyway
395 work_pending:
396         testb $_TIF_NEED_RESCHED, %cl
397         jz work_notifysig
398 work_resched:
399         call schedule
400         cli                             # make sure we don't miss an interrupt
401                                         # setting need_resched or sigpending
402                                         # between sampling and the iret
403         movl TI_flags(%ebp), %ecx
404         andl $_TIF_WORK_MASK, %ecx      # is there any work to be done other
405                                         # than syscall tracing?
406         jz restore_all
407         testb $_TIF_NEED_RESCHED, %cl
408         jnz work_resched
409
410 work_notifysig:                         # deal with pending signals and
411                                         # notify-resume requests
412         testl $VM_MASK, EFLAGS(%esp)
413         movl %esp, %eax
414         jne work_notifysig_v86          # returning to kernel-space or
415                                         # vm86-space
416         xorl %edx, %edx
417         call do_notify_resume
418         jmp resume_userspace
419
420         ALIGN
421 work_notifysig_v86:
422 #ifdef CONFIG_VM86
423         pushl %ecx                      # save ti_flags for do_notify_resume
424         CFI_ADJUST_CFA_OFFSET 4
425         call save_v86_state             # %eax contains pt_regs pointer
426         popl %ecx
427         CFI_ADJUST_CFA_OFFSET -4
428         movl %eax, %esp
429         xorl %edx, %edx
430         call do_notify_resume
431         jmp resume_userspace
432 #endif
433
434         # perform syscall exit tracing
435         ALIGN
436 syscall_trace_entry:
437         movl $-ENOSYS,EAX(%esp)
438         movl %esp, %eax
439         xorl %edx,%edx
440         call do_syscall_trace
441         cmpl $0, %eax
442         jne resume_userspace            # ret != 0 -> running under PTRACE_SYSEMU,
443                                         # so must skip actual syscall
444         movl ORIG_EAX(%esp), %eax
445         cmpl $(nr_syscalls), %eax
446         jnae syscall_call
447         jmp syscall_exit
448
449         # perform syscall exit tracing
450         ALIGN
451 syscall_exit_work:
452         testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
453         jz work_pending
454         sti                             # could let do_syscall_trace() call
455                                         # schedule() instead
456         movl %esp, %eax
457         movl $1, %edx
458         call do_syscall_trace
459         jmp resume_userspace
460         CFI_ENDPROC
461
462         RING0_INT_FRAME                 # can't unwind into user space anyway
463 syscall_fault:
464         pushl %eax                      # save orig_eax
465         CFI_ADJUST_CFA_OFFSET 4
466         SAVE_ALL
467         GET_THREAD_INFO(%ebp)
468         movl $-EFAULT,EAX(%esp)
469         jmp resume_userspace
470
471 syscall_badsys:
472         movl $-ENOSYS,EAX(%esp)
473         jmp resume_userspace
474         CFI_ENDPROC
475
476 #define FIXUP_ESPFIX_STACK \
477         movl %esp, %eax; \
478         /* switch to 32bit stack using the pointer on top of 16bit stack */ \
479         lss %ss:CPU_16BIT_STACK_SIZE-8, %esp; \
480         /* copy data from 16bit stack to 32bit stack */ \
481         call fixup_x86_bogus_stack; \
482         /* put ESP to the proper location */ \
483         movl %eax, %esp;
484 #define UNWIND_ESPFIX_STACK \
485         pushl %eax; \
486         CFI_ADJUST_CFA_OFFSET 4; \
487         movl %ss, %eax; \
488         /* see if on 16bit stack */ \
489         cmpw $__ESPFIX_SS, %ax; \
490         je 28f; \
491 27:     popl %eax; \
492         CFI_ADJUST_CFA_OFFSET -4; \
493 .section .fixup,"ax"; \
494 28:     movl $__KERNEL_DS, %eax; \
495         movl %eax, %ds; \
496         movl %eax, %es; \
497         /* switch to 32bit stack */ \
498         FIXUP_ESPFIX_STACK; \
499         jmp 27b; \
500 .previous
501
502 /*
503  * Build the entry stubs and pointer table with
504  * some assembler magic.
505  */
506 .data
507 ENTRY(interrupt)
508 .text
509
510 vector=0
511 ENTRY(irq_entries_start)
512         RING0_INT_FRAME
513 .rept NR_IRQS
514         ALIGN
515  .if vector
516         CFI_ADJUST_CFA_OFFSET -4
517  .endif
518 1:      pushl $vector-256
519         CFI_ADJUST_CFA_OFFSET 4
520         jmp common_interrupt
521 .data
522         .long 1b
523 .text
524 vector=vector+1
525 .endr
526
527         ALIGN
528 common_interrupt:
529         SAVE_ALL
530         movl %esp,%eax
531         call do_IRQ
532         jmp ret_from_intr
533         CFI_ENDPROC
534
535 #define BUILD_INTERRUPT(name, nr)       \
536 ENTRY(name)                             \
537         RING0_INT_FRAME;                \
538         pushl $nr-256;                  \
539         CFI_ADJUST_CFA_OFFSET 4;        \
540         SAVE_ALL;                       \
541         movl %esp,%eax;                 \
542         call smp_/**/name;              \
543         jmp ret_from_intr;      \
544         CFI_ENDPROC
545
546 /* The include is where all of the SMP etc. interrupts come from */
547 #include "entry_arch.h"
548
549 ENTRY(divide_error)
550         RING0_INT_FRAME
551         pushl $0                        # no error code
552         CFI_ADJUST_CFA_OFFSET 4
553         pushl $do_divide_error
554         CFI_ADJUST_CFA_OFFSET 4
555         ALIGN
556 error_code:
557         pushl %ds
558         CFI_ADJUST_CFA_OFFSET 4
559         /*CFI_REL_OFFSET ds, 0*/
560         pushl %eax
561         CFI_ADJUST_CFA_OFFSET 4
562         CFI_REL_OFFSET eax, 0
563         xorl %eax, %eax
564         pushl %ebp
565         CFI_ADJUST_CFA_OFFSET 4
566         CFI_REL_OFFSET ebp, 0
567         pushl %edi
568         CFI_ADJUST_CFA_OFFSET 4
569         CFI_REL_OFFSET edi, 0
570         pushl %esi
571         CFI_ADJUST_CFA_OFFSET 4
572         CFI_REL_OFFSET esi, 0
573         pushl %edx
574         CFI_ADJUST_CFA_OFFSET 4
575         CFI_REL_OFFSET edx, 0
576         decl %eax                       # eax = -1
577         pushl %ecx
578         CFI_ADJUST_CFA_OFFSET 4
579         CFI_REL_OFFSET ecx, 0
580         pushl %ebx
581         CFI_ADJUST_CFA_OFFSET 4
582         CFI_REL_OFFSET ebx, 0
583         cld
584         pushl %es
585         CFI_ADJUST_CFA_OFFSET 4
586         /*CFI_REL_OFFSET es, 0*/
587         UNWIND_ESPFIX_STACK
588         popl %ecx
589         CFI_ADJUST_CFA_OFFSET -4
590         /*CFI_REGISTER es, ecx*/
591         movl ES(%esp), %edi             # get the function address
592         movl ORIG_EAX(%esp), %edx       # get the error code
593         movl %eax, ORIG_EAX(%esp)
594         movl %ecx, ES(%esp)
595         /*CFI_REL_OFFSET es, ES*/
596         movl $(__USER_DS), %ecx
597         movl %ecx, %ds
598         movl %ecx, %es
599         movl %esp,%eax                  # pt_regs pointer
600         call *%edi
601         jmp ret_from_exception
602         CFI_ENDPROC
603
604 ENTRY(coprocessor_error)
605         RING0_INT_FRAME
606         pushl $0
607         CFI_ADJUST_CFA_OFFSET 4
608         pushl $do_coprocessor_error
609         CFI_ADJUST_CFA_OFFSET 4
610         jmp error_code
611         CFI_ENDPROC
612
613 ENTRY(simd_coprocessor_error)
614         RING0_INT_FRAME
615         pushl $0
616         CFI_ADJUST_CFA_OFFSET 4
617         pushl $do_simd_coprocessor_error
618         CFI_ADJUST_CFA_OFFSET 4
619         jmp error_code
620         CFI_ENDPROC
621
622 ENTRY(device_not_available)
623         RING0_INT_FRAME
624         pushl $-1                       # mark this as an int
625         CFI_ADJUST_CFA_OFFSET 4
626         SAVE_ALL
627         movl %cr0, %eax
628         testl $0x4, %eax                # EM (math emulation bit)
629         jne device_not_available_emulate
630         preempt_stop
631         call math_state_restore
632         jmp ret_from_exception
633 device_not_available_emulate:
634         pushl $0                        # temporary storage for ORIG_EIP
635         CFI_ADJUST_CFA_OFFSET 4
636         call math_emulate
637         addl $4, %esp
638         CFI_ADJUST_CFA_OFFSET -4
639         jmp ret_from_exception
640         CFI_ENDPROC
641
642 /*
643  * Debug traps and NMI can happen at the one SYSENTER instruction
644  * that sets up the real kernel stack. Check here, since we can't
645  * allow the wrong stack to be used.
646  *
647  * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
648  * already pushed 3 words if it hits on the sysenter instruction:
649  * eflags, cs and eip.
650  *
651  * We just load the right stack, and push the three (known) values
652  * by hand onto the new stack - while updating the return eip past
653  * the instruction that would have done it for sysenter.
654  */
655 #define FIX_STACK(offset, ok, label)            \
656         cmpw $__KERNEL_CS,4(%esp);              \
657         jne ok;                                 \
658 label:                                          \
659         movl TSS_sysenter_esp0+offset(%esp),%esp;       \
660         pushfl;                                 \
661         pushl $__KERNEL_CS;                     \
662         pushl $sysenter_past_esp
663
664 KPROBE_ENTRY(debug)
665         RING0_INT_FRAME
666         cmpl $sysenter_entry,(%esp)
667         jne debug_stack_correct
668         FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
669 debug_stack_correct:
670         pushl $-1                       # mark this as an int
671         CFI_ADJUST_CFA_OFFSET 4
672         SAVE_ALL
673         xorl %edx,%edx                  # error code 0
674         movl %esp,%eax                  # pt_regs pointer
675         call do_debug
676         jmp ret_from_exception
677         CFI_ENDPROC
678         .previous .text
679 /*
680  * NMI is doubly nasty. It can happen _while_ we're handling
681  * a debug fault, and the debug fault hasn't yet been able to
682  * clear up the stack. So we first check whether we got  an
683  * NMI on the sysenter entry path, but after that we need to
684  * check whether we got an NMI on the debug path where the debug
685  * fault happened on the sysenter path.
686  */
687 ENTRY(nmi)
688         RING0_INT_FRAME
689         pushl %eax
690         CFI_ADJUST_CFA_OFFSET 4
691         movl %ss, %eax
692         cmpw $__ESPFIX_SS, %ax
693         popl %eax
694         CFI_ADJUST_CFA_OFFSET -4
695         je nmi_16bit_stack
696         cmpl $sysenter_entry,(%esp)
697         je nmi_stack_fixup
698         pushl %eax
699         CFI_ADJUST_CFA_OFFSET 4
700         movl %esp,%eax
701         /* Do not access memory above the end of our stack page,
702          * it might not exist.
703          */
704         andl $(THREAD_SIZE-1),%eax
705         cmpl $(THREAD_SIZE-20),%eax
706         popl %eax
707         CFI_ADJUST_CFA_OFFSET -4
708         jae nmi_stack_correct
709         cmpl $sysenter_entry,12(%esp)
710         je nmi_debug_stack_check
711 nmi_stack_correct:
712         pushl %eax
713         CFI_ADJUST_CFA_OFFSET 4
714         SAVE_ALL
715         xorl %edx,%edx          # zero error code
716         movl %esp,%eax          # pt_regs pointer
717         call do_nmi
718         jmp restore_all
719         CFI_ENDPROC
720
721 nmi_stack_fixup:
722         FIX_STACK(12,nmi_stack_correct, 1)
723         jmp nmi_stack_correct
724 nmi_debug_stack_check:
725         cmpw $__KERNEL_CS,16(%esp)
726         jne nmi_stack_correct
727         cmpl $debug,(%esp)
728         jb nmi_stack_correct
729         cmpl $debug_esp_fix_insn,(%esp)
730         ja nmi_stack_correct
731         FIX_STACK(24,nmi_stack_correct, 1)
732         jmp nmi_stack_correct
733
734 nmi_16bit_stack:
735         RING0_INT_FRAME
736         /* create the pointer to lss back */
737         pushl %ss
738         CFI_ADJUST_CFA_OFFSET 4
739         pushl %esp
740         CFI_ADJUST_CFA_OFFSET 4
741         movzwl %sp, %esp
742         addw $4, (%esp)
743         /* copy the iret frame of 12 bytes */
744         .rept 3
745         pushl 16(%esp)
746         CFI_ADJUST_CFA_OFFSET 4
747         .endr
748         pushl %eax
749         CFI_ADJUST_CFA_OFFSET 4
750         SAVE_ALL
751         FIXUP_ESPFIX_STACK              # %eax == %esp
752         CFI_ADJUST_CFA_OFFSET -20       # the frame has now moved
753         xorl %edx,%edx                  # zero error code
754         call do_nmi
755         RESTORE_REGS
756         lss 12+4(%esp), %esp            # back to 16bit stack
757 1:      iret
758         CFI_ENDPROC
759 .section __ex_table,"a"
760         .align 4
761         .long 1b,iret_exc
762 .previous
763
764 KPROBE_ENTRY(int3)
765         RING0_INT_FRAME
766         pushl $-1                       # mark this as an int
767         CFI_ADJUST_CFA_OFFSET 4
768         SAVE_ALL
769         xorl %edx,%edx          # zero error code
770         movl %esp,%eax          # pt_regs pointer
771         call do_int3
772         jmp ret_from_exception
773         CFI_ENDPROC
774         .previous .text
775
776 ENTRY(overflow)
777         RING0_INT_FRAME
778         pushl $0
779         CFI_ADJUST_CFA_OFFSET 4
780         pushl $do_overflow
781         CFI_ADJUST_CFA_OFFSET 4
782         jmp error_code
783         CFI_ENDPROC
784
785 ENTRY(bounds)
786         RING0_INT_FRAME
787         pushl $0
788         CFI_ADJUST_CFA_OFFSET 4
789         pushl $do_bounds
790         CFI_ADJUST_CFA_OFFSET 4
791         jmp error_code
792         CFI_ENDPROC
793
794 ENTRY(invalid_op)
795         RING0_INT_FRAME
796         pushl $0
797         CFI_ADJUST_CFA_OFFSET 4
798         pushl $do_invalid_op
799         CFI_ADJUST_CFA_OFFSET 4
800         jmp error_code
801         CFI_ENDPROC
802
803 ENTRY(coprocessor_segment_overrun)
804         RING0_INT_FRAME
805         pushl $0
806         CFI_ADJUST_CFA_OFFSET 4
807         pushl $do_coprocessor_segment_overrun
808         CFI_ADJUST_CFA_OFFSET 4
809         jmp error_code
810         CFI_ENDPROC
811
812 ENTRY(invalid_TSS)
813         RING0_EC_FRAME
814         pushl $do_invalid_TSS
815         CFI_ADJUST_CFA_OFFSET 4
816         jmp error_code
817         CFI_ENDPROC
818
819 ENTRY(segment_not_present)
820         RING0_EC_FRAME
821         pushl $do_segment_not_present
822         CFI_ADJUST_CFA_OFFSET 4
823         jmp error_code
824         CFI_ENDPROC
825
826 ENTRY(stack_segment)
827         RING0_EC_FRAME
828         pushl $do_stack_segment
829         CFI_ADJUST_CFA_OFFSET 4
830         jmp error_code
831         CFI_ENDPROC
832
833 KPROBE_ENTRY(general_protection)
834         RING0_EC_FRAME
835         pushl $do_general_protection
836         CFI_ADJUST_CFA_OFFSET 4
837         jmp error_code
838         CFI_ENDPROC
839         .previous .text
840
841 ENTRY(alignment_check)
842         RING0_EC_FRAME
843         pushl $do_alignment_check
844         CFI_ADJUST_CFA_OFFSET 4
845         jmp error_code
846         CFI_ENDPROC
847
848 KPROBE_ENTRY(page_fault)
849         RING0_EC_FRAME
850         pushl $do_page_fault
851         CFI_ADJUST_CFA_OFFSET 4
852         jmp error_code
853         CFI_ENDPROC
854         .previous .text
855
856 #ifdef CONFIG_X86_MCE
857 ENTRY(machine_check)
858         RING0_INT_FRAME
859         pushl $0
860         CFI_ADJUST_CFA_OFFSET 4
861         pushl machine_check_vector
862         CFI_ADJUST_CFA_OFFSET 4
863         jmp error_code
864         CFI_ENDPROC
865 #endif
866
867 ENTRY(spurious_interrupt_bug)
868         RING0_INT_FRAME
869         pushl $0
870         CFI_ADJUST_CFA_OFFSET 4
871         pushl $do_spurious_interrupt_bug
872         CFI_ADJUST_CFA_OFFSET 4
873         jmp error_code
874         CFI_ENDPROC
875
876 #ifdef CONFIG_STACK_UNWIND
877 ENTRY(arch_unwind_init_running)
878         CFI_STARTPROC
879         movl    4(%esp), %edx
880         movl    (%esp), %ecx
881         leal    4(%esp), %eax
882         movl    %ebx, EBX(%edx)
883         xorl    %ebx, %ebx
884         movl    %ebx, ECX(%edx)
885         movl    %ebx, EDX(%edx)
886         movl    %esi, ESI(%edx)
887         movl    %edi, EDI(%edx)
888         movl    %ebp, EBP(%edx)
889         movl    %ebx, EAX(%edx)
890         movl    $__USER_DS, DS(%edx)
891         movl    $__USER_DS, ES(%edx)
892         movl    %ebx, ORIG_EAX(%edx)
893         movl    %ecx, EIP(%edx)
894         movl    12(%esp), %ecx
895         movl    $__KERNEL_CS, CS(%edx)
896         movl    %ebx, EFLAGS(%edx)
897         movl    %eax, OLDESP(%edx)
898         movl    8(%esp), %eax
899         movl    %ecx, 8(%esp)
900         movl    EBX(%edx), %ebx
901         movl    $__KERNEL_DS, OLDSS(%edx)
902         jmpl    *%eax
903         CFI_ENDPROC
904 ENDPROC(arch_unwind_init_running)
905 #endif
906
907 .section .rodata,"a"
908 #include "syscall_table.S"
909
910 syscall_table_size=(.-sys_call_table)