]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/kernel/entry_32.S
0ad987d02b722c8dfab8077990ca24fd3b70d732
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / entry_32.S
1 /*
2  *
3  *  Copyright (C) 1991, 1992  Linus Torvalds
4  */
5
6 /*
7  * entry.S contains the system-call and fault low-level handling routines.
8  * This also contains the timer-interrupt handler, as well as all interrupts
9  * and faults that can result in a task-switch.
10  *
11  * NOTE: This code handles signal-recognition, which happens every time
12  * after a timer-interrupt and after each system call.
13  *
14  * I changed all the .align's to 4 (16 byte alignment), as that's faster
15  * on a 486.
16  *
17  * Stack layout in 'syscall_exit':
18  *      ptrace needs to have all regs on the stack.
19  *      if the order here is changed, it needs to be
20  *      updated in fork.c:copy_process, signal.c:do_signal,
21  *      ptrace.c and ptrace.h
22  *
23  *       0(%esp) - %ebx
24  *       4(%esp) - %ecx
25  *       8(%esp) - %edx
26  *       C(%esp) - %esi
27  *      10(%esp) - %edi
28  *      14(%esp) - %ebp
29  *      18(%esp) - %eax
30  *      1C(%esp) - %ds
31  *      20(%esp) - %es
32  *      24(%esp) - %fs
33  *      28(%esp) - orig_eax
34  *      2C(%esp) - %eip
35  *      30(%esp) - %cs
36  *      34(%esp) - %eflags
37  *      38(%esp) - %oldesp
38  *      3C(%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/percpu.h>
52 #include <asm/dwarf2.h>
53 #include <asm/processor-flags.h>
54 #include <asm/ftrace.h>
55 #include <asm/irq_vectors.h>
56
57 /*
58  * We use macros for low-level operations which need to be overridden
59  * for paravirtualization.  The following will never clobber any registers:
60  *   INTERRUPT_RETURN (aka. "iret")
61  *   GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
62  *   ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
63  *
64  * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
65  * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
66  * Allowing a register to be clobbered can shrink the paravirt replacement
67  * enough to patch inline, increasing performance.
68  */
69
70 #define nr_syscalls ((syscall_table_size)/4)
71
72 #ifdef CONFIG_PREEMPT
73 #define preempt_stop(clobbers)  DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
74 #else
75 #define preempt_stop(clobbers)
76 #define resume_kernel           restore_nocheck
77 #endif
78
79 .macro TRACE_IRQS_IRET
80 #ifdef CONFIG_TRACE_IRQFLAGS
81         testl $X86_EFLAGS_IF,PT_EFLAGS(%esp)     # interrupts off?
82         jz 1f
83         TRACE_IRQS_ON
84 1:
85 #endif
86 .endm
87
88 #ifdef CONFIG_VM86
89 #define resume_userspace_sig    check_userspace
90 #else
91 #define resume_userspace_sig    resume_userspace
92 #endif
93
94 #define SAVE_ALL \
95         cld; \
96         pushl %fs; \
97         CFI_ADJUST_CFA_OFFSET 4;\
98         /*CFI_REL_OFFSET fs, 0;*/\
99         pushl %es; \
100         CFI_ADJUST_CFA_OFFSET 4;\
101         /*CFI_REL_OFFSET es, 0;*/\
102         pushl %ds; \
103         CFI_ADJUST_CFA_OFFSET 4;\
104         /*CFI_REL_OFFSET ds, 0;*/\
105         pushl %eax; \
106         CFI_ADJUST_CFA_OFFSET 4;\
107         CFI_REL_OFFSET eax, 0;\
108         pushl %ebp; \
109         CFI_ADJUST_CFA_OFFSET 4;\
110         CFI_REL_OFFSET ebp, 0;\
111         pushl %edi; \
112         CFI_ADJUST_CFA_OFFSET 4;\
113         CFI_REL_OFFSET edi, 0;\
114         pushl %esi; \
115         CFI_ADJUST_CFA_OFFSET 4;\
116         CFI_REL_OFFSET esi, 0;\
117         pushl %edx; \
118         CFI_ADJUST_CFA_OFFSET 4;\
119         CFI_REL_OFFSET edx, 0;\
120         pushl %ecx; \
121         CFI_ADJUST_CFA_OFFSET 4;\
122         CFI_REL_OFFSET ecx, 0;\
123         pushl %ebx; \
124         CFI_ADJUST_CFA_OFFSET 4;\
125         CFI_REL_OFFSET ebx, 0;\
126         movl $(__USER_DS), %edx; \
127         movl %edx, %ds; \
128         movl %edx, %es; \
129         movl $(__KERNEL_PERCPU), %edx; \
130         movl %edx, %fs
131
132 #define RESTORE_INT_REGS \
133         popl %ebx;      \
134         CFI_ADJUST_CFA_OFFSET -4;\
135         CFI_RESTORE ebx;\
136         popl %ecx;      \
137         CFI_ADJUST_CFA_OFFSET -4;\
138         CFI_RESTORE ecx;\
139         popl %edx;      \
140         CFI_ADJUST_CFA_OFFSET -4;\
141         CFI_RESTORE edx;\
142         popl %esi;      \
143         CFI_ADJUST_CFA_OFFSET -4;\
144         CFI_RESTORE esi;\
145         popl %edi;      \
146         CFI_ADJUST_CFA_OFFSET -4;\
147         CFI_RESTORE edi;\
148         popl %ebp;      \
149         CFI_ADJUST_CFA_OFFSET -4;\
150         CFI_RESTORE ebp;\
151         popl %eax;      \
152         CFI_ADJUST_CFA_OFFSET -4;\
153         CFI_RESTORE eax
154
155 #define RESTORE_REGS    \
156         RESTORE_INT_REGS; \
157 1:      popl %ds;       \
158         CFI_ADJUST_CFA_OFFSET -4;\
159         /*CFI_RESTORE ds;*/\
160 2:      popl %es;       \
161         CFI_ADJUST_CFA_OFFSET -4;\
162         /*CFI_RESTORE es;*/\
163 3:      popl %fs;       \
164         CFI_ADJUST_CFA_OFFSET -4;\
165         /*CFI_RESTORE fs;*/\
166 .pushsection .fixup,"ax";       \
167 4:      movl $0,(%esp); \
168         jmp 1b;         \
169 5:      movl $0,(%esp); \
170         jmp 2b;         \
171 6:      movl $0,(%esp); \
172         jmp 3b;         \
173 .section __ex_table,"a";\
174         .align 4;       \
175         .long 1b,4b;    \
176         .long 2b,5b;    \
177         .long 3b,6b;    \
178 .popsection
179
180 #define RING0_INT_FRAME \
181         CFI_STARTPROC simple;\
182         CFI_SIGNAL_FRAME;\
183         CFI_DEF_CFA esp, 3*4;\
184         /*CFI_OFFSET cs, -2*4;*/\
185         CFI_OFFSET eip, -3*4
186
187 #define RING0_EC_FRAME \
188         CFI_STARTPROC simple;\
189         CFI_SIGNAL_FRAME;\
190         CFI_DEF_CFA esp, 4*4;\
191         /*CFI_OFFSET cs, -2*4;*/\
192         CFI_OFFSET eip, -3*4
193
194 #define RING0_PTREGS_FRAME \
195         CFI_STARTPROC simple;\
196         CFI_SIGNAL_FRAME;\
197         CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
198         /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
199         CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
200         /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
201         /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
202         CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
203         CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
204         CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
205         CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
206         CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
207         CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
208         CFI_OFFSET ebx, PT_EBX-PT_OLDESP
209
210 ENTRY(ret_from_fork)
211         CFI_STARTPROC
212         pushl %eax
213         CFI_ADJUST_CFA_OFFSET 4
214         call schedule_tail
215         GET_THREAD_INFO(%ebp)
216         popl %eax
217         CFI_ADJUST_CFA_OFFSET -4
218         pushl $0x0202                   # Reset kernel eflags
219         CFI_ADJUST_CFA_OFFSET 4
220         popfl
221         CFI_ADJUST_CFA_OFFSET -4
222         jmp syscall_exit
223         CFI_ENDPROC
224 END(ret_from_fork)
225
226 /*
227  * Return to user mode is not as complex as all this looks,
228  * but we want the default path for a system call return to
229  * go as quickly as possible which is why some of this is
230  * less clear than it otherwise should be.
231  */
232
233         # userspace resumption stub bypassing syscall exit tracing
234         ALIGN
235         RING0_PTREGS_FRAME
236 ret_from_exception:
237         preempt_stop(CLBR_ANY)
238 ret_from_intr:
239         GET_THREAD_INFO(%ebp)
240 check_userspace:
241         movl PT_EFLAGS(%esp), %eax      # mix EFLAGS and CS
242         movb PT_CS(%esp), %al
243         andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
244         cmpl $USER_RPL, %eax
245         jb resume_kernel                # not returning to v8086 or userspace
246
247 ENTRY(resume_userspace)
248         LOCKDEP_SYS_EXIT
249         DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt
250                                         # setting need_resched or sigpending
251                                         # between sampling and the iret
252         TRACE_IRQS_OFF
253         movl TI_flags(%ebp), %ecx
254         andl $_TIF_WORK_MASK, %ecx      # is there any work to be done on
255                                         # int/exception return?
256         jne work_pending
257         jmp restore_all
258 END(ret_from_exception)
259
260 #ifdef CONFIG_PREEMPT
261 ENTRY(resume_kernel)
262         DISABLE_INTERRUPTS(CLBR_ANY)
263         cmpl $0,TI_preempt_count(%ebp)  # non-zero preempt_count ?
264         jnz restore_nocheck
265 need_resched:
266         movl TI_flags(%ebp), %ecx       # need_resched set ?
267         testb $_TIF_NEED_RESCHED, %cl
268         jz restore_all
269         testl $X86_EFLAGS_IF,PT_EFLAGS(%esp)    # interrupts off (exception path) ?
270         jz restore_all
271         call preempt_schedule_irq
272         jmp need_resched
273 END(resume_kernel)
274 #endif
275         CFI_ENDPROC
276
277 /* SYSENTER_RETURN points to after the "sysenter" instruction in
278    the vsyscall page.  See vsyscall-sysentry.S, which defines the symbol.  */
279
280         # sysenter call handler stub
281 ENTRY(ia32_sysenter_target)
282         CFI_STARTPROC simple
283         CFI_SIGNAL_FRAME
284         CFI_DEF_CFA esp, 0
285         CFI_REGISTER esp, ebp
286         movl TSS_sysenter_sp0(%esp),%esp
287 sysenter_past_esp:
288         /*
289          * Interrupts are disabled here, but we can't trace it until
290          * enough kernel state to call TRACE_IRQS_OFF can be called - but
291          * we immediately enable interrupts at that point anyway.
292          */
293         pushl $(__USER_DS)
294         CFI_ADJUST_CFA_OFFSET 4
295         /*CFI_REL_OFFSET ss, 0*/
296         pushl %ebp
297         CFI_ADJUST_CFA_OFFSET 4
298         CFI_REL_OFFSET esp, 0
299         pushfl
300         orl $X86_EFLAGS_IF, (%esp)
301         CFI_ADJUST_CFA_OFFSET 4
302         pushl $(__USER_CS)
303         CFI_ADJUST_CFA_OFFSET 4
304         /*CFI_REL_OFFSET cs, 0*/
305         /*
306          * Push current_thread_info()->sysenter_return to the stack.
307          * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
308          * pushed above; +8 corresponds to copy_thread's esp0 setting.
309          */
310         pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
311         CFI_ADJUST_CFA_OFFSET 4
312         CFI_REL_OFFSET eip, 0
313
314         pushl %eax
315         CFI_ADJUST_CFA_OFFSET 4
316         SAVE_ALL
317         ENABLE_INTERRUPTS(CLBR_NONE)
318
319 /*
320  * Load the potential sixth argument from user stack.
321  * Careful about security.
322  */
323         cmpl $__PAGE_OFFSET-3,%ebp
324         jae syscall_fault
325 1:      movl (%ebp),%ebp
326         movl %ebp,PT_EBP(%esp)
327 .section __ex_table,"a"
328         .align 4
329         .long 1b,syscall_fault
330 .previous
331
332         GET_THREAD_INFO(%ebp)
333
334         /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
335         testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
336         jnz syscall_trace_entry
337         cmpl $(nr_syscalls), %eax
338         jae syscall_badsys
339         call *sys_call_table(,%eax,4)
340         movl %eax,PT_EAX(%esp)
341         LOCKDEP_SYS_EXIT
342         DISABLE_INTERRUPTS(CLBR_ANY)
343         TRACE_IRQS_OFF
344         movl TI_flags(%ebp), %ecx
345         testw $_TIF_ALLWORK_MASK, %cx
346         jne syscall_exit_work
347 /* if something modifies registers it must also disable sysexit */
348         movl PT_EIP(%esp), %edx
349         movl PT_OLDESP(%esp), %ecx
350         xorl %ebp,%ebp
351         TRACE_IRQS_ON
352 1:      mov  PT_FS(%esp), %fs
353         ENABLE_INTERRUPTS_SYSEXIT
354         CFI_ENDPROC
355 .pushsection .fixup,"ax"
356 2:      movl $0,PT_FS(%esp)
357         jmp 1b
358 .section __ex_table,"a"
359         .align 4
360         .long 1b,2b
361 .popsection
362 ENDPROC(ia32_sysenter_target)
363
364         # system call handler stub
365 ENTRY(system_call)
366         RING0_INT_FRAME                 # can't unwind into user space anyway
367         pushl %eax                      # save orig_eax
368         CFI_ADJUST_CFA_OFFSET 4
369         SAVE_ALL
370         GET_THREAD_INFO(%ebp)
371                                         # system call tracing in operation / emulation
372         /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
373         testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
374         jnz syscall_trace_entry
375         cmpl $(nr_syscalls), %eax
376         jae syscall_badsys
377 syscall_call:
378         call *sys_call_table(,%eax,4)
379         movl %eax,PT_EAX(%esp)          # store the return value
380 syscall_exit:
381         LOCKDEP_SYS_EXIT
382         DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt
383                                         # setting need_resched or sigpending
384                                         # between sampling and the iret
385         TRACE_IRQS_OFF
386         movl TI_flags(%ebp), %ecx
387         testw $_TIF_ALLWORK_MASK, %cx   # current->work
388         jne syscall_exit_work
389
390 restore_all:
391         movl PT_EFLAGS(%esp), %eax      # mix EFLAGS, SS and CS
392         # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
393         # are returning to the kernel.
394         # See comments in process.c:copy_thread() for details.
395         movb PT_OLDSS(%esp), %ah
396         movb PT_CS(%esp), %al
397         andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
398         cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
399         CFI_REMEMBER_STATE
400         je ldt_ss                       # returning to user-space with LDT SS
401 restore_nocheck:
402         TRACE_IRQS_IRET
403 restore_nocheck_notrace:
404         RESTORE_REGS
405         addl $4, %esp                   # skip orig_eax/error_code
406         CFI_ADJUST_CFA_OFFSET -4
407 irq_return:
408         INTERRUPT_RETURN
409 .section .fixup,"ax"
410 ENTRY(iret_exc)
411         pushl $0                        # no error code
412         pushl $do_iret_error
413         jmp error_code
414 .previous
415 .section __ex_table,"a"
416         .align 4
417         .long irq_return,iret_exc
418 .previous
419
420         CFI_RESTORE_STATE
421 ldt_ss:
422         larl PT_OLDSS(%esp), %eax
423         jnz restore_nocheck
424         testl $0x00400000, %eax         # returning to 32bit stack?
425         jnz restore_nocheck             # allright, normal return
426
427 #ifdef CONFIG_PARAVIRT
428         /*
429          * The kernel can't run on a non-flat stack if paravirt mode
430          * is active.  Rather than try to fixup the high bits of
431          * ESP, bypass this code entirely.  This may break DOSemu
432          * and/or Wine support in a paravirt VM, although the option
433          * is still available to implement the setting of the high
434          * 16-bits in the INTERRUPT_RETURN paravirt-op.
435          */
436         cmpl $0, pv_info+PARAVIRT_enabled
437         jne restore_nocheck
438 #endif
439
440         /* If returning to userspace with 16bit stack,
441          * try to fix the higher word of ESP, as the CPU
442          * won't restore it.
443          * This is an "official" bug of all the x86-compatible
444          * CPUs, which we can try to work around to make
445          * dosemu and wine happy. */
446         movl PT_OLDESP(%esp), %eax
447         movl %esp, %edx
448         call patch_espfix_desc
449         pushl $__ESPFIX_SS
450         CFI_ADJUST_CFA_OFFSET 4
451         pushl %eax
452         CFI_ADJUST_CFA_OFFSET 4
453         DISABLE_INTERRUPTS(CLBR_EAX)
454         TRACE_IRQS_OFF
455         lss (%esp), %esp
456         CFI_ADJUST_CFA_OFFSET -8
457         jmp restore_nocheck
458         CFI_ENDPROC
459 ENDPROC(system_call)
460
461         # perform work that needs to be done immediately before resumption
462         ALIGN
463         RING0_PTREGS_FRAME              # can't unwind into user space anyway
464 work_pending:
465         testb $_TIF_NEED_RESCHED, %cl
466         jz work_notifysig
467 work_resched:
468         call schedule
469         LOCKDEP_SYS_EXIT
470         DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt
471                                         # setting need_resched or sigpending
472                                         # between sampling and the iret
473         TRACE_IRQS_OFF
474         movl TI_flags(%ebp), %ecx
475         andl $_TIF_WORK_MASK, %ecx      # is there any work to be done other
476                                         # than syscall tracing?
477         jz restore_all
478         testb $_TIF_NEED_RESCHED, %cl
479         jnz work_resched
480
481 work_notifysig:                         # deal with pending signals and
482                                         # notify-resume requests
483 #ifdef CONFIG_VM86
484         testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
485         movl %esp, %eax
486         jne work_notifysig_v86          # returning to kernel-space or
487                                         # vm86-space
488         xorl %edx, %edx
489         call do_notify_resume
490         jmp resume_userspace_sig
491
492         ALIGN
493 work_notifysig_v86:
494         pushl %ecx                      # save ti_flags for do_notify_resume
495         CFI_ADJUST_CFA_OFFSET 4
496         call save_v86_state             # %eax contains pt_regs pointer
497         popl %ecx
498         CFI_ADJUST_CFA_OFFSET -4
499         movl %eax, %esp
500 #else
501         movl %esp, %eax
502 #endif
503         xorl %edx, %edx
504         call do_notify_resume
505         jmp resume_userspace_sig
506 END(work_pending)
507
508         # perform syscall exit tracing
509         ALIGN
510 syscall_trace_entry:
511         movl $-ENOSYS,PT_EAX(%esp)
512         movl %esp, %eax
513         xorl %edx,%edx
514         call do_syscall_trace
515         cmpl $0, %eax
516         jne resume_userspace            # ret != 0 -> running under PTRACE_SYSEMU,
517                                         # so must skip actual syscall
518         movl PT_ORIG_EAX(%esp), %eax
519         cmpl $(nr_syscalls), %eax
520         jnae syscall_call
521         jmp syscall_exit
522 END(syscall_trace_entry)
523
524         # perform syscall exit tracing
525         ALIGN
526 syscall_exit_work:
527         testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
528         jz work_pending
529         TRACE_IRQS_ON
530         ENABLE_INTERRUPTS(CLBR_ANY)     # could let do_syscall_trace() call
531                                         # schedule() instead
532         movl %esp, %eax
533         movl $1, %edx
534         call do_syscall_trace
535         jmp resume_userspace
536 END(syscall_exit_work)
537         CFI_ENDPROC
538
539         RING0_INT_FRAME                 # can't unwind into user space anyway
540 syscall_fault:
541         GET_THREAD_INFO(%ebp)
542         movl $-EFAULT,PT_EAX(%esp)
543         jmp resume_userspace
544 END(syscall_fault)
545
546 syscall_badsys:
547         movl $-ENOSYS,PT_EAX(%esp)
548         jmp resume_userspace
549 END(syscall_badsys)
550         CFI_ENDPROC
551
552 #define FIXUP_ESPFIX_STACK \
553         /* since we are on a wrong stack, we cant make it a C code :( */ \
554         PER_CPU(gdt_page, %ebx); \
555         GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
556         addl %esp, %eax; \
557         pushl $__KERNEL_DS; \
558         CFI_ADJUST_CFA_OFFSET 4; \
559         pushl %eax; \
560         CFI_ADJUST_CFA_OFFSET 4; \
561         lss (%esp), %esp; \
562         CFI_ADJUST_CFA_OFFSET -8;
563 #define UNWIND_ESPFIX_STACK \
564         movl %ss, %eax; \
565         /* see if on espfix stack */ \
566         cmpw $__ESPFIX_SS, %ax; \
567         jne 27f; \
568         movl $__KERNEL_DS, %eax; \
569         movl %eax, %ds; \
570         movl %eax, %es; \
571         /* switch to normal stack */ \
572         FIXUP_ESPFIX_STACK; \
573 27:;
574
575 /*
576  * Build the entry stubs and pointer table with
577  * some assembler magic.
578  */
579 .section .rodata,"a"
580 ENTRY(interrupt)
581 .text
582
583 ENTRY(irq_entries_start)
584         RING0_INT_FRAME
585 vector=0
586 .rept NR_IRQS
587         ALIGN
588  .if vector
589         CFI_ADJUST_CFA_OFFSET -4
590  .endif
591 1:      pushl $~(vector)
592         CFI_ADJUST_CFA_OFFSET 4
593         jmp common_interrupt
594  .previous
595         .long 1b
596  .text
597 vector=vector+1
598 .endr
599 END(irq_entries_start)
600
601 .previous
602 END(interrupt)
603 .previous
604
605 /*
606  * the CPU automatically disables interrupts when executing an IRQ vector,
607  * so IRQ-flags tracing has to follow that:
608  */
609         ALIGN
610 common_interrupt:
611         SAVE_ALL
612         TRACE_IRQS_OFF
613         movl %esp,%eax
614         call do_IRQ
615         jmp ret_from_intr
616 ENDPROC(common_interrupt)
617         CFI_ENDPROC
618
619 #define BUILD_INTERRUPT(name, nr)       \
620 ENTRY(name)                             \
621         RING0_INT_FRAME;                \
622         pushl $~(nr);                   \
623         CFI_ADJUST_CFA_OFFSET 4;        \
624         SAVE_ALL;                       \
625         TRACE_IRQS_OFF                  \
626         movl %esp,%eax;                 \
627         call smp_##name;                \
628         jmp ret_from_intr;              \
629         CFI_ENDPROC;                    \
630 ENDPROC(name)
631
632 /* The include is where all of the SMP etc. interrupts come from */
633 #include "entry_arch.h"
634
635 KPROBE_ENTRY(page_fault)
636         RING0_EC_FRAME
637         pushl $do_page_fault
638         CFI_ADJUST_CFA_OFFSET 4
639         ALIGN
640 error_code:
641         /* the function address is in %fs's slot on the stack */
642         pushl %es
643         CFI_ADJUST_CFA_OFFSET 4
644         /*CFI_REL_OFFSET es, 0*/
645         pushl %ds
646         CFI_ADJUST_CFA_OFFSET 4
647         /*CFI_REL_OFFSET ds, 0*/
648         pushl %eax
649         CFI_ADJUST_CFA_OFFSET 4
650         CFI_REL_OFFSET eax, 0
651         pushl %ebp
652         CFI_ADJUST_CFA_OFFSET 4
653         CFI_REL_OFFSET ebp, 0
654         pushl %edi
655         CFI_ADJUST_CFA_OFFSET 4
656         CFI_REL_OFFSET edi, 0
657         pushl %esi
658         CFI_ADJUST_CFA_OFFSET 4
659         CFI_REL_OFFSET esi, 0
660         pushl %edx
661         CFI_ADJUST_CFA_OFFSET 4
662         CFI_REL_OFFSET edx, 0
663         pushl %ecx
664         CFI_ADJUST_CFA_OFFSET 4
665         CFI_REL_OFFSET ecx, 0
666         pushl %ebx
667         CFI_ADJUST_CFA_OFFSET 4
668         CFI_REL_OFFSET ebx, 0
669         cld
670         pushl %fs
671         CFI_ADJUST_CFA_OFFSET 4
672         /*CFI_REL_OFFSET fs, 0*/
673         movl $(__KERNEL_PERCPU), %ecx
674         movl %ecx, %fs
675         UNWIND_ESPFIX_STACK
676         popl %ecx
677         CFI_ADJUST_CFA_OFFSET -4
678         /*CFI_REGISTER es, ecx*/
679         movl PT_FS(%esp), %edi          # get the function address
680         movl PT_ORIG_EAX(%esp), %edx    # get the error code
681         movl $-1, PT_ORIG_EAX(%esp)     # no syscall to restart
682         mov  %ecx, PT_FS(%esp)
683         /*CFI_REL_OFFSET fs, ES*/
684         movl $(__USER_DS), %ecx
685         movl %ecx, %ds
686         movl %ecx, %es
687         movl %esp,%eax                  # pt_regs pointer
688         call *%edi
689         jmp ret_from_exception
690         CFI_ENDPROC
691 KPROBE_END(page_fault)
692
693 ENTRY(coprocessor_error)
694         RING0_INT_FRAME
695         pushl $0
696         CFI_ADJUST_CFA_OFFSET 4
697         pushl $do_coprocessor_error
698         CFI_ADJUST_CFA_OFFSET 4
699         jmp error_code
700         CFI_ENDPROC
701 END(coprocessor_error)
702
703 ENTRY(simd_coprocessor_error)
704         RING0_INT_FRAME
705         pushl $0
706         CFI_ADJUST_CFA_OFFSET 4
707         pushl $do_simd_coprocessor_error
708         CFI_ADJUST_CFA_OFFSET 4
709         jmp error_code
710         CFI_ENDPROC
711 END(simd_coprocessor_error)
712
713 ENTRY(device_not_available)
714         RING0_INT_FRAME
715         pushl $-1                       # mark this as an int
716         CFI_ADJUST_CFA_OFFSET 4
717         SAVE_ALL
718         GET_CR0_INTO_EAX
719         testl $0x4, %eax                # EM (math emulation bit)
720         jne device_not_available_emulate
721         preempt_stop(CLBR_ANY)
722         call math_state_restore
723         jmp ret_from_exception
724 device_not_available_emulate:
725         pushl $0                        # temporary storage for ORIG_EIP
726         CFI_ADJUST_CFA_OFFSET 4
727         call math_emulate
728         addl $4, %esp
729         CFI_ADJUST_CFA_OFFSET -4
730         jmp ret_from_exception
731         CFI_ENDPROC
732 END(device_not_available)
733
734 /*
735  * Debug traps and NMI can happen at the one SYSENTER instruction
736  * that sets up the real kernel stack. Check here, since we can't
737  * allow the wrong stack to be used.
738  *
739  * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
740  * already pushed 3 words if it hits on the sysenter instruction:
741  * eflags, cs and eip.
742  *
743  * We just load the right stack, and push the three (known) values
744  * by hand onto the new stack - while updating the return eip past
745  * the instruction that would have done it for sysenter.
746  */
747 #define FIX_STACK(offset, ok, label)            \
748         cmpw $__KERNEL_CS,4(%esp);              \
749         jne ok;                                 \
750 label:                                          \
751         movl TSS_sysenter_sp0+offset(%esp),%esp;        \
752         CFI_DEF_CFA esp, 0;                     \
753         CFI_UNDEFINED eip;                      \
754         pushfl;                                 \
755         CFI_ADJUST_CFA_OFFSET 4;                \
756         pushl $__KERNEL_CS;                     \
757         CFI_ADJUST_CFA_OFFSET 4;                \
758         pushl $sysenter_past_esp;               \
759         CFI_ADJUST_CFA_OFFSET 4;                \
760         CFI_REL_OFFSET eip, 0
761
762 KPROBE_ENTRY(debug)
763         RING0_INT_FRAME
764         cmpl $ia32_sysenter_target,(%esp)
765         jne debug_stack_correct
766         FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
767 debug_stack_correct:
768         pushl $-1                       # mark this as an int
769         CFI_ADJUST_CFA_OFFSET 4
770         SAVE_ALL
771         xorl %edx,%edx                  # error code 0
772         movl %esp,%eax                  # pt_regs pointer
773         call do_debug
774         jmp ret_from_exception
775         CFI_ENDPROC
776 KPROBE_END(debug)
777
778 /*
779  * NMI is doubly nasty. It can happen _while_ we're handling
780  * a debug fault, and the debug fault hasn't yet been able to
781  * clear up the stack. So we first check whether we got  an
782  * NMI on the sysenter entry path, but after that we need to
783  * check whether we got an NMI on the debug path where the debug
784  * fault happened on the sysenter path.
785  */
786 KPROBE_ENTRY(nmi)
787         RING0_INT_FRAME
788         pushl %eax
789         CFI_ADJUST_CFA_OFFSET 4
790         movl %ss, %eax
791         cmpw $__ESPFIX_SS, %ax
792         popl %eax
793         CFI_ADJUST_CFA_OFFSET -4
794         je nmi_espfix_stack
795         cmpl $ia32_sysenter_target,(%esp)
796         je nmi_stack_fixup
797         pushl %eax
798         CFI_ADJUST_CFA_OFFSET 4
799         movl %esp,%eax
800         /* Do not access memory above the end of our stack page,
801          * it might not exist.
802          */
803         andl $(THREAD_SIZE-1),%eax
804         cmpl $(THREAD_SIZE-20),%eax
805         popl %eax
806         CFI_ADJUST_CFA_OFFSET -4
807         jae nmi_stack_correct
808         cmpl $ia32_sysenter_target,12(%esp)
809         je nmi_debug_stack_check
810 nmi_stack_correct:
811         /* We have a RING0_INT_FRAME here */
812         pushl %eax
813         CFI_ADJUST_CFA_OFFSET 4
814         SAVE_ALL
815         xorl %edx,%edx          # zero error code
816         movl %esp,%eax          # pt_regs pointer
817         call do_nmi
818         jmp restore_nocheck_notrace
819         CFI_ENDPROC
820
821 nmi_stack_fixup:
822         RING0_INT_FRAME
823         FIX_STACK(12,nmi_stack_correct, 1)
824         jmp nmi_stack_correct
825
826 nmi_debug_stack_check:
827         /* We have a RING0_INT_FRAME here */
828         cmpw $__KERNEL_CS,16(%esp)
829         jne nmi_stack_correct
830         cmpl $debug,(%esp)
831         jb nmi_stack_correct
832         cmpl $debug_esp_fix_insn,(%esp)
833         ja nmi_stack_correct
834         FIX_STACK(24,nmi_stack_correct, 1)
835         jmp nmi_stack_correct
836
837 nmi_espfix_stack:
838         /* We have a RING0_INT_FRAME here.
839          *
840          * create the pointer to lss back
841          */
842         pushl %ss
843         CFI_ADJUST_CFA_OFFSET 4
844         pushl %esp
845         CFI_ADJUST_CFA_OFFSET 4
846         addw $4, (%esp)
847         /* copy the iret frame of 12 bytes */
848         .rept 3
849         pushl 16(%esp)
850         CFI_ADJUST_CFA_OFFSET 4
851         .endr
852         pushl %eax
853         CFI_ADJUST_CFA_OFFSET 4
854         SAVE_ALL
855         FIXUP_ESPFIX_STACK              # %eax == %esp
856         xorl %edx,%edx                  # zero error code
857         call do_nmi
858         RESTORE_REGS
859         lss 12+4(%esp), %esp            # back to espfix stack
860         CFI_ADJUST_CFA_OFFSET -24
861         jmp irq_return
862         CFI_ENDPROC
863 KPROBE_END(nmi)
864
865 #ifdef CONFIG_PARAVIRT
866 ENTRY(native_iret)
867         iret
868 .section __ex_table,"a"
869         .align 4
870         .long native_iret, iret_exc
871 .previous
872 END(native_iret)
873
874 ENTRY(native_irq_enable_sysexit)
875         sti
876         sysexit
877 END(native_irq_enable_sysexit)
878 #endif
879
880 KPROBE_ENTRY(int3)
881         RING0_INT_FRAME
882         pushl $-1                       # mark this as an int
883         CFI_ADJUST_CFA_OFFSET 4
884         SAVE_ALL
885         xorl %edx,%edx          # zero error code
886         movl %esp,%eax          # pt_regs pointer
887         call do_int3
888         jmp ret_from_exception
889         CFI_ENDPROC
890 KPROBE_END(int3)
891
892 ENTRY(overflow)
893         RING0_INT_FRAME
894         pushl $0
895         CFI_ADJUST_CFA_OFFSET 4
896         pushl $do_overflow
897         CFI_ADJUST_CFA_OFFSET 4
898         jmp error_code
899         CFI_ENDPROC
900 END(overflow)
901
902 ENTRY(bounds)
903         RING0_INT_FRAME
904         pushl $0
905         CFI_ADJUST_CFA_OFFSET 4
906         pushl $do_bounds
907         CFI_ADJUST_CFA_OFFSET 4
908         jmp error_code
909         CFI_ENDPROC
910 END(bounds)
911
912 ENTRY(invalid_op)
913         RING0_INT_FRAME
914         pushl $0
915         CFI_ADJUST_CFA_OFFSET 4
916         pushl $do_invalid_op
917         CFI_ADJUST_CFA_OFFSET 4
918         jmp error_code
919         CFI_ENDPROC
920 END(invalid_op)
921
922 ENTRY(coprocessor_segment_overrun)
923         RING0_INT_FRAME
924         pushl $0
925         CFI_ADJUST_CFA_OFFSET 4
926         pushl $do_coprocessor_segment_overrun
927         CFI_ADJUST_CFA_OFFSET 4
928         jmp error_code
929         CFI_ENDPROC
930 END(coprocessor_segment_overrun)
931
932 ENTRY(invalid_TSS)
933         RING0_EC_FRAME
934         pushl $do_invalid_TSS
935         CFI_ADJUST_CFA_OFFSET 4
936         jmp error_code
937         CFI_ENDPROC
938 END(invalid_TSS)
939
940 ENTRY(segment_not_present)
941         RING0_EC_FRAME
942         pushl $do_segment_not_present
943         CFI_ADJUST_CFA_OFFSET 4
944         jmp error_code
945         CFI_ENDPROC
946 END(segment_not_present)
947
948 ENTRY(stack_segment)
949         RING0_EC_FRAME
950         pushl $do_stack_segment
951         CFI_ADJUST_CFA_OFFSET 4
952         jmp error_code
953         CFI_ENDPROC
954 END(stack_segment)
955
956 KPROBE_ENTRY(general_protection)
957         RING0_EC_FRAME
958         pushl $do_general_protection
959         CFI_ADJUST_CFA_OFFSET 4
960         jmp error_code
961         CFI_ENDPROC
962 KPROBE_END(general_protection)
963
964 ENTRY(alignment_check)
965         RING0_EC_FRAME
966         pushl $do_alignment_check
967         CFI_ADJUST_CFA_OFFSET 4
968         jmp error_code
969         CFI_ENDPROC
970 END(alignment_check)
971
972 ENTRY(divide_error)
973         RING0_INT_FRAME
974         pushl $0                        # no error code
975         CFI_ADJUST_CFA_OFFSET 4
976         pushl $do_divide_error
977         CFI_ADJUST_CFA_OFFSET 4
978         jmp error_code
979         CFI_ENDPROC
980 END(divide_error)
981
982 #ifdef CONFIG_X86_MCE
983 ENTRY(machine_check)
984         RING0_INT_FRAME
985         pushl $0
986         CFI_ADJUST_CFA_OFFSET 4
987         pushl machine_check_vector
988         CFI_ADJUST_CFA_OFFSET 4
989         jmp error_code
990         CFI_ENDPROC
991 END(machine_check)
992 #endif
993
994 ENTRY(spurious_interrupt_bug)
995         RING0_INT_FRAME
996         pushl $0
997         CFI_ADJUST_CFA_OFFSET 4
998         pushl $do_spurious_interrupt_bug
999         CFI_ADJUST_CFA_OFFSET 4
1000         jmp error_code
1001         CFI_ENDPROC
1002 END(spurious_interrupt_bug)
1003
1004 ENTRY(kernel_thread_helper)
1005         pushl $0                # fake return address for unwinder
1006         CFI_STARTPROC
1007         movl %edx,%eax
1008         push %edx
1009         CFI_ADJUST_CFA_OFFSET 4
1010         call *%ebx
1011         push %eax
1012         CFI_ADJUST_CFA_OFFSET 4
1013         call do_exit
1014         CFI_ENDPROC
1015 ENDPROC(kernel_thread_helper)
1016
1017 #ifdef CONFIG_XEN
1018 /* Xen doesn't set %esp to be precisely what the normal sysenter
1019    entrypoint expects, so fix it up before using the normal path. */
1020 ENTRY(xen_sysenter_target)
1021         RING0_INT_FRAME
1022         addl $5*4, %esp         /* remove xen-provided frame */
1023         jmp sysenter_past_esp
1024         CFI_ENDPROC
1025
1026 ENTRY(xen_hypervisor_callback)
1027         CFI_STARTPROC
1028         pushl $0
1029         CFI_ADJUST_CFA_OFFSET 4
1030         SAVE_ALL
1031         TRACE_IRQS_OFF
1032
1033         /* Check to see if we got the event in the critical
1034            region in xen_iret_direct, after we've reenabled
1035            events and checked for pending events.  This simulates
1036            iret instruction's behaviour where it delivers a
1037            pending interrupt when enabling interrupts. */
1038         movl PT_EIP(%esp),%eax
1039         cmpl $xen_iret_start_crit,%eax
1040         jb   1f
1041         cmpl $xen_iret_end_crit,%eax
1042         jae  1f
1043
1044         jmp  xen_iret_crit_fixup
1045
1046 ENTRY(xen_do_upcall)
1047 1:      mov %esp, %eax
1048         call xen_evtchn_do_upcall
1049         jmp  ret_from_intr
1050         CFI_ENDPROC
1051 ENDPROC(xen_hypervisor_callback)
1052
1053 # Hypervisor uses this for application faults while it executes.
1054 # We get here for two reasons:
1055 #  1. Fault while reloading DS, ES, FS or GS
1056 #  2. Fault while executing IRET
1057 # Category 1 we fix up by reattempting the load, and zeroing the segment
1058 # register if the load fails.
1059 # Category 2 we fix up by jumping to do_iret_error. We cannot use the
1060 # normal Linux return path in this case because if we use the IRET hypercall
1061 # to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1062 # We distinguish between categories by maintaining a status value in EAX.
1063 ENTRY(xen_failsafe_callback)
1064         CFI_STARTPROC
1065         pushl %eax
1066         CFI_ADJUST_CFA_OFFSET 4
1067         movl $1,%eax
1068 1:      mov 4(%esp),%ds
1069 2:      mov 8(%esp),%es
1070 3:      mov 12(%esp),%fs
1071 4:      mov 16(%esp),%gs
1072         testl %eax,%eax
1073         popl %eax
1074         CFI_ADJUST_CFA_OFFSET -4
1075         lea 16(%esp),%esp
1076         CFI_ADJUST_CFA_OFFSET -16
1077         jz 5f
1078         addl $16,%esp
1079         jmp iret_exc            # EAX != 0 => Category 2 (Bad IRET)
1080 5:      pushl $0                # EAX == 0 => Category 1 (Bad segment)
1081         CFI_ADJUST_CFA_OFFSET 4
1082         SAVE_ALL
1083         jmp ret_from_exception
1084         CFI_ENDPROC
1085
1086 .section .fixup,"ax"
1087 6:      xorl %eax,%eax
1088         movl %eax,4(%esp)
1089         jmp 1b
1090 7:      xorl %eax,%eax
1091         movl %eax,8(%esp)
1092         jmp 2b
1093 8:      xorl %eax,%eax
1094         movl %eax,12(%esp)
1095         jmp 3b
1096 9:      xorl %eax,%eax
1097         movl %eax,16(%esp)
1098         jmp 4b
1099 .previous
1100 .section __ex_table,"a"
1101         .align 4
1102         .long 1b,6b
1103         .long 2b,7b
1104         .long 3b,8b
1105         .long 4b,9b
1106 .previous
1107 ENDPROC(xen_failsafe_callback)
1108
1109 #endif  /* CONFIG_XEN */
1110
1111 #ifdef CONFIG_FTRACE
1112 #ifdef CONFIG_DYNAMIC_FTRACE
1113
1114 ENTRY(mcount)
1115         pushl %eax
1116         pushl %ecx
1117         pushl %edx
1118         movl 0xc(%esp), %eax
1119         subl $MCOUNT_INSN_SIZE, %eax
1120
1121 .globl mcount_call
1122 mcount_call:
1123         call ftrace_stub
1124
1125         popl %edx
1126         popl %ecx
1127         popl %eax
1128
1129         ret
1130 END(mcount)
1131
1132 ENTRY(ftrace_caller)
1133         pushl %eax
1134         pushl %ecx
1135         pushl %edx
1136         movl 0xc(%esp), %eax
1137         movl 0x4(%ebp), %edx
1138         subl $MCOUNT_INSN_SIZE, %eax
1139
1140 .globl ftrace_call
1141 ftrace_call:
1142         call ftrace_stub
1143
1144         popl %edx
1145         popl %ecx
1146         popl %eax
1147
1148 .globl ftrace_stub
1149 ftrace_stub:
1150         ret
1151 END(ftrace_caller)
1152
1153 #else /* ! CONFIG_DYNAMIC_FTRACE */
1154
1155 ENTRY(mcount)
1156         cmpl $ftrace_stub, ftrace_trace_function
1157         jnz trace
1158 .globl ftrace_stub
1159 ftrace_stub:
1160         ret
1161
1162         /* taken from glibc */
1163 trace:
1164         pushl %eax
1165         pushl %ecx
1166         pushl %edx
1167         movl 0xc(%esp), %eax
1168         movl 0x4(%ebp), %edx
1169         subl $MCOUNT_INSN_SIZE, %eax
1170
1171         call *ftrace_trace_function
1172
1173         popl %edx
1174         popl %ecx
1175         popl %eax
1176
1177         jmp ftrace_stub
1178 END(mcount)
1179 #endif /* CONFIG_DYNAMIC_FTRACE */
1180 #endif /* CONFIG_FTRACE */
1181
1182 .section .rodata,"a"
1183 #include "syscall_table_32.S"
1184
1185 syscall_table_size=(.-sys_call_table)