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