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