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