blob: cadf73f70d336f5716e0f464209492734fd6df58 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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 *
Andi Kleen889f21c2007-05-02 19:27:19 +020017 * Stack layout in 'syscall_exit':
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * 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
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010032 * 24(%esp) - %fs
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010033 * 28(%esp) - orig_eax
34 * 2C(%esp) - %eip
35 * 30(%esp) - %cs
36 * 34(%esp) - %eflags
37 * 38(%esp) - %oldesp
38 * 3C(%esp) - %oldss
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 *
40 * "current" is in register %ebx during any slow entries.
41 */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/linkage.h>
44#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070045#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/errno.h>
47#include <asm/segment.h>
48#include <asm/smp.h>
49#include <asm/page.h>
50#include <asm/desc.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010051#include <asm/percpu.h>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020052#include <asm/dwarf2.h>
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030053#include <asm/processor-flags.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053054#include <asm/ftrace.h>
Thomas Gleixner9b7dc562008-05-02 20:10:09 +020055#include <asm/irq_vectors.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Rusty Russell139ec7c2006-12-07 02:14:08 +010057/*
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")
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -040062 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010063 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070070#define nr_syscalls ((syscall_table_size)/4)
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#ifdef CONFIG_PREEMPT
Rusty Russell139ec7c2006-12-07 02:14:08 +010073#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070074#else
Rusty Russell139ec7c2006-12-07 02:14:08 +010075#define preempt_stop(clobbers)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define resume_kernel restore_nocheck
77#endif
78
Ingo Molnar55f327f2006-07-03 00:24:43 -070079.macro TRACE_IRQS_IRET
80#ifdef CONFIG_TRACE_IRQFLAGS
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030081 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070082 jz 1f
83 TRACE_IRQS_ON
841:
85#endif
86.endm
87
Aleksey Gorelov4031ff32006-06-27 02:53:48 -070088#ifdef CONFIG_VM86
89#define resume_userspace_sig check_userspace
90#else
91#define resume_userspace_sig resume_userspace
92#endif
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define SAVE_ALL \
95 cld; \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010096 pushl %fs; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010097 CFI_ADJUST_CFA_OFFSET 4;\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010098 /*CFI_REL_OFFSET fs, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200100 CFI_ADJUST_CFA_OFFSET 4;\
101 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200103 CFI_ADJUST_CFA_OFFSET 4;\
104 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200106 CFI_ADJUST_CFA_OFFSET 4;\
107 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200109 CFI_ADJUST_CFA_OFFSET 4;\
110 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200112 CFI_ADJUST_CFA_OFFSET 4;\
113 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200115 CFI_ADJUST_CFA_OFFSET 4;\
116 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200118 CFI_ADJUST_CFA_OFFSET 4;\
119 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200121 CFI_ADJUST_CFA_OFFSET 4;\
122 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200124 CFI_ADJUST_CFA_OFFSET 4;\
125 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 movl $(__USER_DS), %edx; \
127 movl %edx, %ds; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100128 movl %edx, %es; \
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200129 movl $(__KERNEL_PERCPU), %edx; \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100130 movl %edx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132#define RESTORE_INT_REGS \
133 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200134 CFI_ADJUST_CFA_OFFSET -4;\
135 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200137 CFI_ADJUST_CFA_OFFSET -4;\
138 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200140 CFI_ADJUST_CFA_OFFSET -4;\
141 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200143 CFI_ADJUST_CFA_OFFSET -4;\
144 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200146 CFI_ADJUST_CFA_OFFSET -4;\
147 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200149 CFI_ADJUST_CFA_OFFSET -4;\
150 CFI_RESTORE ebp;\
151 popl %eax; \
152 CFI_ADJUST_CFA_OFFSET -4;\
153 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155#define RESTORE_REGS \
156 RESTORE_INT_REGS; \
1571: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200158 CFI_ADJUST_CFA_OFFSET -4;\
159 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200161 CFI_ADJUST_CFA_OFFSET -4;\
162 /*CFI_RESTORE es;*/\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01001633: popl %fs; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100164 CFI_ADJUST_CFA_OFFSET -4;\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100165 /*CFI_RESTORE fs;*/\
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100166.pushsection .fixup,"ax"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674: movl $0,(%esp); \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100168 jmp 1b; \
1695: movl $0,(%esp); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 jmp 2b; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +01001716: movl $0,(%esp); \
172 jmp 3b; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173.section __ex_table,"a";\
174 .align 4; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100175 .long 1b,4b; \
176 .long 2b,5b; \
177 .long 3b,6b; \
178.popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200180#define RING0_INT_FRAME \
181 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200182 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200183 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;\
Jan Beulichadf14232006-09-26 10:52:41 +0200189 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200190 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;\
Jan Beulichadf14232006-09-26 10:52:41 +0200196 CFI_SIGNAL_FRAME;\
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100197 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200211 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700213 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 call schedule_tail
215 GET_THREAD_INFO(%ebp)
216 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200217 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700218 pushl $0x0202 # Reset kernel eflags
219 CFI_ADJUST_CFA_OFFSET 4
220 popfl
221 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200223 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100224END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
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
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200235 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100237 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238ret_from_intr:
239 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700240check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100241 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
242 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300243 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200244 cmpl $USER_RPL, %eax
245 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200248 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100249 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 # setting need_resched or sigpending
251 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200252 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 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
Jan Beulich47a55cd2007-02-13 13:26:24 +0100258END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260#ifdef CONFIG_PREEMPT
261ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100262 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
264 jnz restore_nocheck
265need_resched:
266 movl TI_flags(%ebp), %ecx # need_resched set ?
267 testb $_TIF_NEED_RESCHED, %cl
268 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300269 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 jz restore_all
271 call preempt_schedule_irq
272 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100273END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200275 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
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
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100281ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200282 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200283 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200284 CFI_DEF_CFA esp, 0
285 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100286 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700288 /*
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700289 * 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.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700292 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200294 CFI_ADJUST_CFA_OFFSET 4
295 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200297 CFI_ADJUST_CFA_OFFSET 4
298 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 pushfl
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700300 orl $X86_EFLAGS_IF, (%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200301 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200303 CFI_ADJUST_CFA_OFFSET 4
304 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700305 /*
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)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200311 CFI_ADJUST_CFA_OFFSET 4
312 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700314 pushl %eax
315 CFI_ADJUST_CFA_OFFSET 4
316 SAVE_ALL
317 ENABLE_INTERRUPTS(CLBR_NONE)
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/*
320 * Load the potential sixth argument from user stack.
321 * Careful about security.
322 */
323 cmpl $__PAGE_OFFSET-3,%ebp
324 jae syscall_fault
3251: movl (%ebp),%ebp
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700326 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327.section __ex_table,"a"
328 .align 4
329 .long 1b,syscall_fault
330.previous
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 GET_THREAD_INFO(%ebp)
333
334 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Roland McGrathd4d67152008-07-09 02:38:07 -0700335 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 jnz syscall_trace_entry
337 cmpl $(nr_syscalls), %eax
338 jae syscall_badsys
339 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100340 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200341 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200342 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700343 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 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 */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100348 movl PT_EIP(%esp), %edx
349 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700351 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003521: mov PT_FS(%esp), %fs
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400353 ENABLE_INTERRUPTS_SYSEXIT
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200354 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100355.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003562: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100357 jmp 1b
358.section __ex_table,"a"
359 .align 4
360 .long 1b,2b
361.popsection
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100362ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 # system call handler stub
365ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200366 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200368 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 SAVE_ALL
370 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700371 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Roland McGrathd4d67152008-07-09 02:38:07 -0700373 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 jnz syscall_trace_entry
375 cmpl $(nr_syscalls), %eax
376 jae syscall_badsys
377syscall_call:
378 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100379 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200381 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100382 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 # setting need_resched or sigpending
384 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700385 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 movl TI_flags(%ebp), %ecx
387 testw $_TIF_ALLWORK_MASK, %cx # current->work
388 jne syscall_exit_work
389
390restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100391 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
392 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700393 # are returning to the kernel.
394 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100395 movb PT_OLDSS(%esp), %ah
396 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300397 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200398 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200399 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 je ldt_ss # returning to user-space with LDT SS
401restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700402 TRACE_IRQS_IRET
403restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 RESTORE_REGS
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100405 addl $4, %esp # skip orig_eax/error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200406 CFI_ADJUST_CFA_OFFSET -4
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200407irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100408 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700410ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700411 pushl $0 # no error code
412 pushl $do_iret_error
413 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414.previous
415.section __ex_table,"a"
416 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100417 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418.previous
419
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200420 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100422 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 jnz restore_nocheck
424 testl $0x00400000, %eax # returning to 32bit stack?
425 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100426
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 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700436 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100437 jne restore_nocheck
438#endif
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 /* 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. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100446 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100447 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
Rusty Russell139ec7c2006-12-07 02:14:08 +0100453 DISABLE_INTERRUPTS(CLBR_EAX)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700454 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100455 lss (%esp), %esp
456 CFI_ADJUST_CFA_OFFSET -8
457 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200458 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100459ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 # perform work that needs to be done immediately before resumption
462 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200463 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464work_pending:
465 testb $_TIF_NEED_RESCHED, %cl
466 jz work_notifysig
467work_resched:
468 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200469 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100470 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 # setting need_resched or sigpending
472 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700473 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 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
481work_notifysig: # deal with pending signals and
482 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100483#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300484 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 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
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700490 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492 ALIGN
493work_notifysig_v86:
494 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200495 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 call save_v86_state # %eax contains pt_regs pointer
497 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200498 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100500#else
501 movl %esp, %eax
502#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 xorl %edx, %edx
504 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700505 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100506END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 # perform syscall exit tracing
509 ALIGN
510syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100511 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700513 call syscall_trace_enter
514 /* What it returned is what we'll actually use. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 cmpl $(nr_syscalls), %eax
516 jnae syscall_call
517 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100518END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 # perform syscall exit tracing
521 ALIGN
522syscall_exit_work:
Roland McGrathd4d67152008-07-09 02:38:07 -0700523 testb $_TIF_WORK_SYSCALL_EXIT, %cl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700525 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700526 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 # schedule() instead
528 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700529 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100531END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200532 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200534 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100537 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100539END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100542 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100544END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200545 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100548 /* since we are on a wrong stack, we cant make it a C code :( */ \
Jeremy Fitzhardinge7a61d352007-05-02 19:27:15 +0200549 PER_CPU(gdt_page, %ebx); \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100550 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
551 addl %esp, %eax; \
552 pushl $__KERNEL_DS; \
553 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200555 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100556 lss (%esp), %esp; \
557 CFI_ADJUST_CFA_OFFSET -8;
558#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100560 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100562 jne 27f; \
563 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200564 movl %eax, %ds; \
565 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100566 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200567 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010056827:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570/*
571 * Build the entry stubs and pointer table with
572 * some assembler magic.
573 */
Jan Beulich3e7622f2008-01-30 13:31:23 +0100574.section .rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575ENTRY(interrupt)
576.text
577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200579 RING0_INT_FRAME
Jan Beulich47a55cd2007-02-13 13:26:24 +0100580vector=0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581.rept NR_IRQS
582 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200583 .if vector
584 CFI_ADJUST_CFA_OFFSET -4
585 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005861: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200587 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 jmp common_interrupt
Jan Beulich47a55cd2007-02-13 13:26:24 +0100589 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 .long 1b
Jan Beulich47a55cd2007-02-13 13:26:24 +0100591 .text
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592vector=vector+1
593.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100594END(irq_entries_start)
595
596.previous
597END(interrupt)
598.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Ingo Molnar55f327f2006-07-03 00:24:43 -0700600/*
601 * the CPU automatically disables interrupts when executing an IRQ vector,
602 * so IRQ-flags tracing has to follow that:
603 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 ALIGN
605common_interrupt:
606 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700607 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 movl %esp,%eax
609 call do_IRQ
610 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100611ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200612 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614#define BUILD_INTERRUPT(name, nr) \
615ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200616 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700617 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200618 CFI_ADJUST_CFA_OFFSET 4; \
619 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700620 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 movl %esp,%eax; \
Jeremy Fitzhardingef76c3922007-05-02 19:27:05 +0200622 call smp_##name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700623 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100624 CFI_ENDPROC; \
625ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627/* The include is where all of the SMP etc. interrupts come from */
628#include "entry_arch.h"
629
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200630KPROBE_ENTRY(page_fault)
631 RING0_EC_FRAME
632 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200633 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 ALIGN
635error_code:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100636 /* the function address is in %fs's slot on the stack */
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100637 pushl %es
638 CFI_ADJUST_CFA_OFFSET 4
639 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200641 CFI_ADJUST_CFA_OFFSET 4
642 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200644 CFI_ADJUST_CFA_OFFSET 4
645 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200647 CFI_ADJUST_CFA_OFFSET 4
648 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200650 CFI_ADJUST_CFA_OFFSET 4
651 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200653 CFI_ADJUST_CFA_OFFSET 4
654 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200656 CFI_ADJUST_CFA_OFFSET 4
657 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200659 CFI_ADJUST_CFA_OFFSET 4
660 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200662 CFI_ADJUST_CFA_OFFSET 4
663 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 cld
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100665 pushl %fs
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200666 CFI_ADJUST_CFA_OFFSET 4
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100667 /*CFI_REL_OFFSET fs, 0*/
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200668 movl $(__KERNEL_PERCPU), %ecx
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100669 movl %ecx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 UNWIND_ESPFIX_STACK
671 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200672 CFI_ADJUST_CFA_OFFSET -4
673 /*CFI_REGISTER es, ecx*/
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100674 movl PT_FS(%esp), %edi # get the function address
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100675 movl PT_ORIG_EAX(%esp), %edx # get the error code
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100676 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100677 mov %ecx, PT_FS(%esp)
678 /*CFI_REL_OFFSET fs, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 movl $(__USER_DS), %ecx
680 movl %ecx, %ds
681 movl %ecx, %es
682 movl %esp,%eax # pt_regs pointer
683 call *%edi
684 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200685 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200686KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200689 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200691 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200693 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200695 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100696END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200699 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200701 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200703 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200705 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100706END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
708ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200709 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200711 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200713 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 testl $0x4, %eax # EM (math emulation bit)
715 jne device_not_available_emulate
Rusty Russell139ec7c2006-12-07 02:14:08 +0100716 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 call math_state_restore
718 jmp ret_from_exception
719device_not_available_emulate:
720 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200721 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 call math_emulate
723 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200724 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200726 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100727END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729/*
730 * Debug traps and NMI can happen at the one SYSENTER instruction
731 * that sets up the real kernel stack. Check here, since we can't
732 * allow the wrong stack to be used.
733 *
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100734 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 * already pushed 3 words if it hits on the sysenter instruction:
736 * eflags, cs and eip.
737 *
738 * We just load the right stack, and push the three (known) values
739 * by hand onto the new stack - while updating the return eip past
740 * the instruction that would have done it for sysenter.
741 */
742#define FIX_STACK(offset, ok, label) \
743 cmpw $__KERNEL_CS,4(%esp); \
744 jne ok; \
745label: \
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100746 movl TSS_sysenter_sp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200747 CFI_DEF_CFA esp, 0; \
748 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200750 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200752 CFI_ADJUST_CFA_OFFSET 4; \
753 pushl $sysenter_past_esp; \
754 CFI_ADJUST_CFA_OFFSET 4; \
755 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700757KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200758 RING0_INT_FRAME
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100759 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 jne debug_stack_correct
761 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
762debug_stack_correct:
763 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200764 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 SAVE_ALL
766 xorl %edx,%edx # error code 0
767 movl %esp,%eax # pt_regs pointer
768 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200770 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200771KPROBE_END(debug)
772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773/*
774 * NMI is doubly nasty. It can happen _while_ we're handling
775 * a debug fault, and the debug fault hasn't yet been able to
776 * clear up the stack. So we first check whether we got an
777 * NMI on the sysenter entry path, but after that we need to
778 * check whether we got an NMI on the debug path where the debug
779 * fault happened on the sysenter path.
780 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200781KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200782 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200784 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 movl %ss, %eax
786 cmpw $__ESPFIX_SS, %ax
787 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200788 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100789 je nmi_espfix_stack
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100790 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 je nmi_stack_fixup
792 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200793 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 movl %esp,%eax
795 /* Do not access memory above the end of our stack page,
796 * it might not exist.
797 */
798 andl $(THREAD_SIZE-1),%eax
799 cmpl $(THREAD_SIZE-20),%eax
800 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200801 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 jae nmi_stack_correct
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100803 cmpl $ia32_sysenter_target,12(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 je nmi_debug_stack_check
805nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200806 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200808 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 SAVE_ALL
810 xorl %edx,%edx # zero error code
811 movl %esp,%eax # pt_regs pointer
812 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700813 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200814 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
816nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200817 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 FIX_STACK(12,nmi_stack_correct, 1)
819 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200822 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 cmpw $__KERNEL_CS,16(%esp)
824 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800825 cmpl $debug,(%esp)
826 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800828 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 FIX_STACK(24,nmi_stack_correct, 1)
830 jmp nmi_stack_correct
831
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100832nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200833 /* We have a RING0_INT_FRAME here.
834 *
835 * create the pointer to lss back
836 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200838 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200840 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 addw $4, (%esp)
842 /* copy the iret frame of 12 bytes */
843 .rept 3
844 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200845 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 .endr
847 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200848 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 SAVE_ALL
850 FIXUP_ESPFIX_STACK # %eax == %esp
851 xorl %edx,%edx # zero error code
852 call do_nmi
853 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100854 lss 12+4(%esp), %esp # back to espfix stack
855 CFI_ADJUST_CFA_OFFSET -24
Ingo Molnar3701d8632008-02-09 23:24:08 +0100856 jmp irq_return
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200857 CFI_ENDPROC
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200858KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Rusty Russelld3561b72006-12-07 02:14:07 +0100860#ifdef CONFIG_PARAVIRT
861ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100862 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100863.section __ex_table,"a"
864 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100865 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100866.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100867END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100868
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400869ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100870 sti
871 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400872END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100873#endif
874
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700875KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200876 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200878 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 SAVE_ALL
880 xorl %edx,%edx # zero error code
881 movl %esp,%eax # pt_regs pointer
882 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200884 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200885KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200888 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200890 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200892 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200894 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100895END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200898 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200900 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200902 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200904 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100905END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
907ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200908 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200910 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200912 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200914 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100915END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200918 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200920 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200924 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100925END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200928 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200930 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200932 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100933END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
935ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200936 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200938 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200940 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100941END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200944 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 pushl $do_stack_segment
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200946 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200948 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100949END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700951KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200952 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 pushl $do_general_protection
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200954 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200956 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200957KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200960 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200962 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200964 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100965END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200967ENTRY(divide_error)
968 RING0_INT_FRAME
969 pushl $0 # no error code
970 CFI_ADJUST_CFA_OFFSET 4
971 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200972 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200974 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100975END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977#ifdef CONFIG_X86_MCE
978ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200979 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200981 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200983 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200985 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100986END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987#endif
988
989ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200990 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200992 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200994 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200996 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100997END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Andi Kleen02ba1a32006-09-26 10:52:35 +0200999ENTRY(kernel_thread_helper)
1000 pushl $0 # fake return address for unwinder
1001 CFI_STARTPROC
1002 movl %edx,%eax
1003 push %edx
1004 CFI_ADJUST_CFA_OFFSET 4
1005 call *%ebx
1006 push %eax
1007 CFI_ADJUST_CFA_OFFSET 4
1008 call do_exit
1009 CFI_ENDPROC
1010ENDPROC(kernel_thread_helper)
1011
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001012#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001013/* Xen doesn't set %esp to be precisely what the normal sysenter
1014 entrypoint expects, so fix it up before using the normal path. */
1015ENTRY(xen_sysenter_target)
1016 RING0_INT_FRAME
1017 addl $5*4, %esp /* remove xen-provided frame */
1018 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001019 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001020
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001021ENTRY(xen_hypervisor_callback)
1022 CFI_STARTPROC
1023 pushl $0
1024 CFI_ADJUST_CFA_OFFSET 4
1025 SAVE_ALL
1026 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001027
1028 /* Check to see if we got the event in the critical
1029 region in xen_iret_direct, after we've reenabled
1030 events and checked for pending events. This simulates
1031 iret instruction's behaviour where it delivers a
1032 pending interrupt when enabling interrupts. */
1033 movl PT_EIP(%esp),%eax
1034 cmpl $xen_iret_start_crit,%eax
1035 jb 1f
1036 cmpl $xen_iret_end_crit,%eax
1037 jae 1f
1038
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001039 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001040
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001041ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010421: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001043 call xen_evtchn_do_upcall
1044 jmp ret_from_intr
1045 CFI_ENDPROC
1046ENDPROC(xen_hypervisor_callback)
1047
1048# Hypervisor uses this for application faults while it executes.
1049# We get here for two reasons:
1050# 1. Fault while reloading DS, ES, FS or GS
1051# 2. Fault while executing IRET
1052# Category 1 we fix up by reattempting the load, and zeroing the segment
1053# register if the load fails.
1054# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1055# normal Linux return path in this case because if we use the IRET hypercall
1056# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1057# We distinguish between categories by maintaining a status value in EAX.
1058ENTRY(xen_failsafe_callback)
1059 CFI_STARTPROC
1060 pushl %eax
1061 CFI_ADJUST_CFA_OFFSET 4
1062 movl $1,%eax
10631: mov 4(%esp),%ds
10642: mov 8(%esp),%es
10653: mov 12(%esp),%fs
10664: mov 16(%esp),%gs
1067 testl %eax,%eax
1068 popl %eax
1069 CFI_ADJUST_CFA_OFFSET -4
1070 lea 16(%esp),%esp
1071 CFI_ADJUST_CFA_OFFSET -16
1072 jz 5f
1073 addl $16,%esp
1074 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
10755: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1076 CFI_ADJUST_CFA_OFFSET 4
1077 SAVE_ALL
1078 jmp ret_from_exception
1079 CFI_ENDPROC
1080
1081.section .fixup,"ax"
10826: xorl %eax,%eax
1083 movl %eax,4(%esp)
1084 jmp 1b
10857: xorl %eax,%eax
1086 movl %eax,8(%esp)
1087 jmp 2b
10888: xorl %eax,%eax
1089 movl %eax,12(%esp)
1090 jmp 3b
10919: xorl %eax,%eax
1092 movl %eax,16(%esp)
1093 jmp 4b
1094.previous
1095.section __ex_table,"a"
1096 .align 4
1097 .long 1b,6b
1098 .long 2b,7b
1099 .long 3b,8b
1100 .long 4b,9b
1101.previous
1102ENDPROC(xen_failsafe_callback)
1103
1104#endif /* CONFIG_XEN */
1105
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001106#ifdef CONFIG_FTRACE
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001107#ifdef CONFIG_DYNAMIC_FTRACE
1108
1109ENTRY(mcount)
1110 pushl %eax
1111 pushl %ecx
1112 pushl %edx
1113 movl 0xc(%esp), %eax
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301114 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001115
1116.globl mcount_call
1117mcount_call:
1118 call ftrace_stub
1119
1120 popl %edx
1121 popl %ecx
1122 popl %eax
1123
1124 ret
1125END(mcount)
1126
1127ENTRY(ftrace_caller)
1128 pushl %eax
1129 pushl %ecx
1130 pushl %edx
1131 movl 0xc(%esp), %eax
1132 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301133 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001134
1135.globl ftrace_call
1136ftrace_call:
1137 call ftrace_stub
1138
1139 popl %edx
1140 popl %ecx
1141 popl %eax
1142
1143.globl ftrace_stub
1144ftrace_stub:
1145 ret
1146END(ftrace_caller)
1147
1148#else /* ! CONFIG_DYNAMIC_FTRACE */
1149
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001150ENTRY(mcount)
1151 cmpl $ftrace_stub, ftrace_trace_function
1152 jnz trace
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001153.globl ftrace_stub
1154ftrace_stub:
1155 ret
1156
1157 /* taken from glibc */
1158trace:
1159 pushl %eax
1160 pushl %ecx
1161 pushl %edx
1162 movl 0xc(%esp), %eax
1163 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301164 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001165
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001166 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001167
1168 popl %edx
1169 popl %ecx
1170 popl %eax
1171
1172 jmp ftrace_stub
1173END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001174#endif /* CONFIG_DYNAMIC_FTRACE */
1175#endif /* CONFIG_FTRACE */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001176
Arjan van de Venbb152f52006-01-06 00:12:05 -08001177.section .rodata,"a"
Thomas Gleixner541054d2007-10-11 11:12:00 +02001178#include "syscall_table_32.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180syscall_table_size=(.-sys_call_table)