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