blob: 53393c306e11b553f1691c4ee607873f18c894af [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>
Thomas Gleixner9b7dc562008-05-02 20:10:09 +020054#include <asm/irq_vectors.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Rusty Russell139ec7c2006-12-07 02:14:08 +010056/*
57 * We use macros for low-level operations which need to be overridden
58 * for paravirtualization. The following will never clobber any registers:
59 * INTERRUPT_RETURN (aka. "iret")
60 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -040061 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010062 *
63 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
64 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
65 * Allowing a register to be clobbered can shrink the paravirt replacement
66 * enough to patch inline, increasing performance.
67 */
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define nr_syscalls ((syscall_table_size)/4)
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#ifdef CONFIG_PREEMPT
Rusty Russell139ec7c2006-12-07 02:14:08 +010072#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#else
Rusty Russell139ec7c2006-12-07 02:14:08 +010074#define preempt_stop(clobbers)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define resume_kernel restore_nocheck
76#endif
77
Ingo Molnar55f327f2006-07-03 00:24:43 -070078.macro TRACE_IRQS_IRET
79#ifdef CONFIG_TRACE_IRQFLAGS
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030080 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070081 jz 1f
82 TRACE_IRQS_ON
831:
84#endif
85.endm
86
Aleksey Gorelov4031ff32006-06-27 02:53:48 -070087#ifdef CONFIG_VM86
88#define resume_userspace_sig check_userspace
89#else
90#define resume_userspace_sig resume_userspace
91#endif
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#define SAVE_ALL \
94 cld; \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010095 pushl %fs; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010096 CFI_ADJUST_CFA_OFFSET 4;\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010097 /*CFI_REL_OFFSET fs, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +020099 CFI_ADJUST_CFA_OFFSET 4;\
100 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200102 CFI_ADJUST_CFA_OFFSET 4;\
103 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200105 CFI_ADJUST_CFA_OFFSET 4;\
106 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200108 CFI_ADJUST_CFA_OFFSET 4;\
109 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200111 CFI_ADJUST_CFA_OFFSET 4;\
112 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200114 CFI_ADJUST_CFA_OFFSET 4;\
115 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200117 CFI_ADJUST_CFA_OFFSET 4;\
118 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200120 CFI_ADJUST_CFA_OFFSET 4;\
121 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200123 CFI_ADJUST_CFA_OFFSET 4;\
124 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 movl $(__USER_DS), %edx; \
126 movl %edx, %ds; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100127 movl %edx, %es; \
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200128 movl $(__KERNEL_PERCPU), %edx; \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100129 movl %edx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131#define RESTORE_INT_REGS \
132 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200133 CFI_ADJUST_CFA_OFFSET -4;\
134 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200136 CFI_ADJUST_CFA_OFFSET -4;\
137 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200139 CFI_ADJUST_CFA_OFFSET -4;\
140 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200142 CFI_ADJUST_CFA_OFFSET -4;\
143 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200145 CFI_ADJUST_CFA_OFFSET -4;\
146 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200148 CFI_ADJUST_CFA_OFFSET -4;\
149 CFI_RESTORE ebp;\
150 popl %eax; \
151 CFI_ADJUST_CFA_OFFSET -4;\
152 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#define RESTORE_REGS \
155 RESTORE_INT_REGS; \
1561: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200157 CFI_ADJUST_CFA_OFFSET -4;\
158 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200160 CFI_ADJUST_CFA_OFFSET -4;\
161 /*CFI_RESTORE es;*/\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01001623: popl %fs; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100163 CFI_ADJUST_CFA_OFFSET -4;\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100164 /*CFI_RESTORE fs;*/\
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100165.pushsection .fixup,"ax"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664: movl $0,(%esp); \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100167 jmp 1b; \
1685: movl $0,(%esp); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 jmp 2b; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +01001706: movl $0,(%esp); \
171 jmp 3b; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172.section __ex_table,"a";\
173 .align 4; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100174 .long 1b,4b; \
175 .long 2b,5b; \
176 .long 3b,6b; \
177.popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200179#define RING0_INT_FRAME \
180 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200181 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200182 CFI_DEF_CFA esp, 3*4;\
183 /*CFI_OFFSET cs, -2*4;*/\
184 CFI_OFFSET eip, -3*4
185
186#define RING0_EC_FRAME \
187 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200188 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200189 CFI_DEF_CFA esp, 4*4;\
190 /*CFI_OFFSET cs, -2*4;*/\
191 CFI_OFFSET eip, -3*4
192
193#define RING0_PTREGS_FRAME \
194 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200195 CFI_SIGNAL_FRAME;\
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100196 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
197 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
198 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
199 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
200 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
201 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
202 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
203 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
204 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
205 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
206 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
207 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200210 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700212 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 call schedule_tail
214 GET_THREAD_INFO(%ebp)
215 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200216 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700217 pushl $0x0202 # Reset kernel eflags
218 CFI_ADJUST_CFA_OFFSET 4
219 popfl
220 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200222 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100223END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225/*
226 * Return to user mode is not as complex as all this looks,
227 * but we want the default path for a system call return to
228 * go as quickly as possible which is why some of this is
229 * less clear than it otherwise should be.
230 */
231
232 # userspace resumption stub bypassing syscall exit tracing
233 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200234 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100236 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237ret_from_intr:
238 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700239check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100240 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
241 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300242 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200243 cmpl $USER_RPL, %eax
244 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200247 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100248 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 # setting need_resched or sigpending
250 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200251 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 movl TI_flags(%ebp), %ecx
253 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
254 # int/exception return?
255 jne work_pending
256 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100257END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259#ifdef CONFIG_PREEMPT
260ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100261 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
263 jnz restore_nocheck
264need_resched:
265 movl TI_flags(%ebp), %ecx # need_resched set ?
266 testb $_TIF_NEED_RESCHED, %cl
267 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300268 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 jz restore_all
270 call preempt_schedule_irq
271 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100272END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200274 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276/* SYSENTER_RETURN points to after the "sysenter" instruction in
277 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
278
279 # sysenter call handler stub
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100280ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200281 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200282 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200283 CFI_DEF_CFA esp, 0
284 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100285 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700287 /*
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700288 * Interrupts are disabled here, but we can't trace it until
289 * enough kernel state to call TRACE_IRQS_OFF can be called - but
290 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700291 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200293 CFI_ADJUST_CFA_OFFSET 4
294 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200296 CFI_ADJUST_CFA_OFFSET 4
297 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 pushfl
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700299 orl $X86_EFLAGS_IF, (%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200300 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200302 CFI_ADJUST_CFA_OFFSET 4
303 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700304 /*
305 * Push current_thread_info()->sysenter_return to the stack.
306 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
307 * pushed above; +8 corresponds to copy_thread's esp0 setting.
308 */
309 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200310 CFI_ADJUST_CFA_OFFSET 4
311 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700313 pushl %eax
314 CFI_ADJUST_CFA_OFFSET 4
315 SAVE_ALL
316 ENABLE_INTERRUPTS(CLBR_NONE)
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/*
319 * Load the potential sixth argument from user stack.
320 * Careful about security.
321 */
322 cmpl $__PAGE_OFFSET-3,%ebp
323 jae syscall_fault
3241: movl (%ebp),%ebp
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700325 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326.section __ex_table,"a"
327 .align 4
328 .long 1b,syscall_fault
329.previous
330
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 GET_THREAD_INFO(%ebp)
332
333 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700334 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 jnz syscall_trace_entry
336 cmpl $(nr_syscalls), %eax
337 jae syscall_badsys
338 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100339 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200340 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200341 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700342 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 movl TI_flags(%ebp), %ecx
344 testw $_TIF_ALLWORK_MASK, %cx
345 jne syscall_exit_work
346/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100347 movl PT_EIP(%esp), %edx
348 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700350 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003511: mov PT_FS(%esp), %fs
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400352 ENABLE_INTERRUPTS_SYSEXIT
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200353 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100354.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003552: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100356 jmp 1b
357.section __ex_table,"a"
358 .align 4
359 .long 1b,2b
360.popsection
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100361ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 # system call handler stub
364ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200365 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200367 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 SAVE_ALL
369 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700370 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700372 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 jnz syscall_trace_entry
374 cmpl $(nr_syscalls), %eax
375 jae syscall_badsys
376syscall_call:
377 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100378 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200380 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100381 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 # setting need_resched or sigpending
383 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700384 TRACE_IRQS_OFF
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300385 testl $X86_EFLAGS_TF,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
Jason Wessel1e2e99f2007-07-06 02:39:50 -0700386 jz no_singlestep
387 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
388no_singlestep:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 movl TI_flags(%ebp), %ecx
390 testw $_TIF_ALLWORK_MASK, %cx # current->work
391 jne syscall_exit_work
392
393restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100394 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
395 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700396 # are returning to the kernel.
397 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100398 movb PT_OLDSS(%esp), %ah
399 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300400 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200401 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200402 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 je ldt_ss # returning to user-space with LDT SS
404restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700405 TRACE_IRQS_IRET
406restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 RESTORE_REGS
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100408 addl $4, %esp # skip orig_eax/error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200409 CFI_ADJUST_CFA_OFFSET -4
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200410irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100411 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700413ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700414 pushl $0 # no error code
415 pushl $do_iret_error
416 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417.previous
418.section __ex_table,"a"
419 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100420 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421.previous
422
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200423 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100425 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 jnz restore_nocheck
427 testl $0x00400000, %eax # returning to 32bit stack?
428 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100429
430#ifdef CONFIG_PARAVIRT
431 /*
432 * The kernel can't run on a non-flat stack if paravirt mode
433 * is active. Rather than try to fixup the high bits of
434 * ESP, bypass this code entirely. This may break DOSemu
435 * and/or Wine support in a paravirt VM, although the option
436 * is still available to implement the setting of the high
437 * 16-bits in the INTERRUPT_RETURN paravirt-op.
438 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700439 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100440 jne restore_nocheck
441#endif
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 /* If returning to userspace with 16bit stack,
444 * try to fix the higher word of ESP, as the CPU
445 * won't restore it.
446 * This is an "official" bug of all the x86-compatible
447 * CPUs, which we can try to work around to make
448 * dosemu and wine happy. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100449 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100450 movl %esp, %edx
451 call patch_espfix_desc
452 pushl $__ESPFIX_SS
453 CFI_ADJUST_CFA_OFFSET 4
454 pushl %eax
455 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100456 DISABLE_INTERRUPTS(CLBR_EAX)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700457 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100458 lss (%esp), %esp
459 CFI_ADJUST_CFA_OFFSET -8
460 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200461 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100462ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 # perform work that needs to be done immediately before resumption
465 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200466 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467work_pending:
468 testb $_TIF_NEED_RESCHED, %cl
469 jz work_notifysig
470work_resched:
471 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200472 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100473 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 # setting need_resched or sigpending
475 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700476 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 movl TI_flags(%ebp), %ecx
478 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
479 # than syscall tracing?
480 jz restore_all
481 testb $_TIF_NEED_RESCHED, %cl
482 jnz work_resched
483
484work_notifysig: # deal with pending signals and
485 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100486#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300487 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 movl %esp, %eax
489 jne work_notifysig_v86 # returning to kernel-space or
490 # vm86-space
491 xorl %edx, %edx
492 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700493 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 ALIGN
496work_notifysig_v86:
497 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200498 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 call save_v86_state # %eax contains pt_regs pointer
500 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200501 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100503#else
504 movl %esp, %eax
505#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 xorl %edx, %edx
507 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700508 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100509END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
511 # perform syscall exit tracing
512 ALIGN
513syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100514 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 movl %esp, %eax
516 xorl %edx,%edx
517 call do_syscall_trace
Laurent Viviered75e8d2005-09-03 15:57:18 -0700518 cmpl $0, %eax
Paolo 'Blaisorblade' Giarrusso640aa462005-09-03 15:57:22 -0700519 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
Laurent Viviered75e8d2005-09-03 15:57:18 -0700520 # so must skip actual syscall
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100521 movl PT_ORIG_EAX(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 cmpl $(nr_syscalls), %eax
523 jnae syscall_call
524 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100525END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 # perform syscall exit tracing
528 ALIGN
529syscall_exit_work:
530 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
531 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700532 TRACE_IRQS_ON
Rusty Russell139ec7c2006-12-07 02:14:08 +0100533 ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 # schedule() instead
535 movl %esp, %eax
536 movl $1, %edx
537 call do_syscall_trace
538 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100539END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200540 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200542 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100545 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100547END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100550 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100552END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200553 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100556 /* since we are on a wrong stack, we cant make it a C code :( */ \
Jeremy Fitzhardinge7a61d352007-05-02 19:27:15 +0200557 PER_CPU(gdt_page, %ebx); \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100558 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
559 addl %esp, %eax; \
560 pushl $__KERNEL_DS; \
561 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200563 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100564 lss (%esp), %esp; \
565 CFI_ADJUST_CFA_OFFSET -8;
566#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100568 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100570 jne 27f; \
571 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200572 movl %eax, %ds; \
573 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100574 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200575 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010057627:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578/*
579 * Build the entry stubs and pointer table with
580 * some assembler magic.
581 */
Jan Beulich3e7622f2008-01-30 13:31:23 +0100582.section .rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583ENTRY(interrupt)
584.text
585
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200587 RING0_INT_FRAME
Jan Beulich47a55cd2007-02-13 13:26:24 +0100588vector=0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589.rept NR_IRQS
590 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200591 .if vector
592 CFI_ADJUST_CFA_OFFSET -4
593 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005941: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200595 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 jmp common_interrupt
Jan Beulich47a55cd2007-02-13 13:26:24 +0100597 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .long 1b
Jan Beulich47a55cd2007-02-13 13:26:24 +0100599 .text
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600vector=vector+1
601.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100602END(irq_entries_start)
603
604.previous
605END(interrupt)
606.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Ingo Molnar55f327f2006-07-03 00:24:43 -0700608/*
609 * the CPU automatically disables interrupts when executing an IRQ vector,
610 * so IRQ-flags tracing has to follow that:
611 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 ALIGN
613common_interrupt:
614 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700615 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 movl %esp,%eax
617 call do_IRQ
618 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100619ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200620 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622#define BUILD_INTERRUPT(name, nr) \
623ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200624 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700625 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200626 CFI_ADJUST_CFA_OFFSET 4; \
627 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700628 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 movl %esp,%eax; \
Jeremy Fitzhardingef76c3922007-05-02 19:27:05 +0200630 call smp_##name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700631 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100632 CFI_ENDPROC; \
633ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635/* The include is where all of the SMP etc. interrupts come from */
636#include "entry_arch.h"
637
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200638KPROBE_ENTRY(page_fault)
639 RING0_EC_FRAME
640 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200641 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 ALIGN
643error_code:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100644 /* the function address is in %fs's slot on the stack */
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100645 pushl %es
646 CFI_ADJUST_CFA_OFFSET 4
647 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200649 CFI_ADJUST_CFA_OFFSET 4
650 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200652 CFI_ADJUST_CFA_OFFSET 4
653 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200655 CFI_ADJUST_CFA_OFFSET 4
656 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200658 CFI_ADJUST_CFA_OFFSET 4
659 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200661 CFI_ADJUST_CFA_OFFSET 4
662 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200664 CFI_ADJUST_CFA_OFFSET 4
665 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200667 CFI_ADJUST_CFA_OFFSET 4
668 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200670 CFI_ADJUST_CFA_OFFSET 4
671 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 cld
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100673 pushl %fs
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200674 CFI_ADJUST_CFA_OFFSET 4
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100675 /*CFI_REL_OFFSET fs, 0*/
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200676 movl $(__KERNEL_PERCPU), %ecx
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100677 movl %ecx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 UNWIND_ESPFIX_STACK
679 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200680 CFI_ADJUST_CFA_OFFSET -4
681 /*CFI_REGISTER es, ecx*/
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100682 movl PT_FS(%esp), %edi # get the function address
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100683 movl PT_ORIG_EAX(%esp), %edx # get the error code
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100684 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100685 mov %ecx, PT_FS(%esp)
686 /*CFI_REL_OFFSET fs, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 movl $(__USER_DS), %ecx
688 movl %ecx, %ds
689 movl %ecx, %es
690 movl %esp,%eax # pt_regs pointer
691 call *%edi
692 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200693 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200694KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200697 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200699 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200701 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200703 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100704END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200707 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200709 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200711 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200713 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100714END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200717 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200719 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200721 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 testl $0x4, %eax # EM (math emulation bit)
723 jne device_not_available_emulate
Rusty Russell139ec7c2006-12-07 02:14:08 +0100724 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 call math_state_restore
726 jmp ret_from_exception
727device_not_available_emulate:
728 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200729 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 call math_emulate
731 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200732 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200734 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100735END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736
737/*
738 * Debug traps and NMI can happen at the one SYSENTER instruction
739 * that sets up the real kernel stack. Check here, since we can't
740 * allow the wrong stack to be used.
741 *
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100742 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 * already pushed 3 words if it hits on the sysenter instruction:
744 * eflags, cs and eip.
745 *
746 * We just load the right stack, and push the three (known) values
747 * by hand onto the new stack - while updating the return eip past
748 * the instruction that would have done it for sysenter.
749 */
750#define FIX_STACK(offset, ok, label) \
751 cmpw $__KERNEL_CS,4(%esp); \
752 jne ok; \
753label: \
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100754 movl TSS_sysenter_sp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200755 CFI_DEF_CFA esp, 0; \
756 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200758 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200760 CFI_ADJUST_CFA_OFFSET 4; \
761 pushl $sysenter_past_esp; \
762 CFI_ADJUST_CFA_OFFSET 4; \
763 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700765KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200766 RING0_INT_FRAME
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100767 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 jne debug_stack_correct
769 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
770debug_stack_correct:
771 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200772 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 SAVE_ALL
774 xorl %edx,%edx # error code 0
775 movl %esp,%eax # pt_regs pointer
776 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200778 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200779KPROBE_END(debug)
780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781/*
782 * NMI is doubly nasty. It can happen _while_ we're handling
783 * a debug fault, and the debug fault hasn't yet been able to
784 * clear up the stack. So we first check whether we got an
785 * NMI on the sysenter entry path, but after that we need to
786 * check whether we got an NMI on the debug path where the debug
787 * fault happened on the sysenter path.
788 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200789KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200790 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200792 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 movl %ss, %eax
794 cmpw $__ESPFIX_SS, %ax
795 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200796 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100797 je nmi_espfix_stack
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100798 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 je nmi_stack_fixup
800 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200801 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 movl %esp,%eax
803 /* Do not access memory above the end of our stack page,
804 * it might not exist.
805 */
806 andl $(THREAD_SIZE-1),%eax
807 cmpl $(THREAD_SIZE-20),%eax
808 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200809 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 jae nmi_stack_correct
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100811 cmpl $ia32_sysenter_target,12(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 je nmi_debug_stack_check
813nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200814 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200816 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 SAVE_ALL
818 xorl %edx,%edx # zero error code
819 movl %esp,%eax # pt_regs pointer
820 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700821 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200822 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200825 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 FIX_STACK(12,nmi_stack_correct, 1)
827 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200828
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200830 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 cmpw $__KERNEL_CS,16(%esp)
832 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800833 cmpl $debug,(%esp)
834 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800836 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 FIX_STACK(24,nmi_stack_correct, 1)
838 jmp nmi_stack_correct
839
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100840nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200841 /* We have a RING0_INT_FRAME here.
842 *
843 * create the pointer to lss back
844 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200846 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200848 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 addw $4, (%esp)
850 /* copy the iret frame of 12 bytes */
851 .rept 3
852 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200853 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .endr
855 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200856 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 SAVE_ALL
858 FIXUP_ESPFIX_STACK # %eax == %esp
859 xorl %edx,%edx # zero error code
860 call do_nmi
861 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100862 lss 12+4(%esp), %esp # back to espfix stack
863 CFI_ADJUST_CFA_OFFSET -24
Ingo Molnar3701d8632008-02-09 23:24:08 +0100864 jmp irq_return
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200865 CFI_ENDPROC
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200866KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
Rusty Russelld3561b72006-12-07 02:14:07 +0100868#ifdef CONFIG_PARAVIRT
869ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100870 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100871.section __ex_table,"a"
872 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100873 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100874.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100875END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100876
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400877ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100878 sti
879 sysexit
Jeremy Fitzhardinged75cd22f2008-06-25 00:19:26 -0400880END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100881#endif
882
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700883KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200884 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200886 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 SAVE_ALL
888 xorl %edx,%edx # zero error code
889 movl %esp,%eax # pt_regs pointer
890 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200892 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200893KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200896 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200898 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200900 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200902 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100903END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200906 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200908 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200910 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200912 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100913END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200916 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200918 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200920 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100923END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200926 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200928 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 pushl $do_coprocessor_segment_overrun
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(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
935ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200936 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 pushl $do_invalid_TSS
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(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200944 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 pushl $do_segment_not_present
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(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200952 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 pushl $do_stack_segment
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
Jan Beulich47a55cd2007-02-13 13:26:24 +0100957END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700959KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200960 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 pushl $do_general_protection
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
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200965KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200968 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200970 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200972 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100973END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200975ENTRY(divide_error)
976 RING0_INT_FRAME
977 pushl $0 # no error code
978 CFI_ADJUST_CFA_OFFSET 4
979 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200980 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200982 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100983END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985#ifdef CONFIG_X86_MCE
986ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200987 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200989 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200991 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200993 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100994END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995#endif
996
997ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200998 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001000 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001002 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001004 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001005END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Andi Kleen02ba1a32006-09-26 10:52:35 +02001007ENTRY(kernel_thread_helper)
1008 pushl $0 # fake return address for unwinder
1009 CFI_STARTPROC
1010 movl %edx,%eax
1011 push %edx
1012 CFI_ADJUST_CFA_OFFSET 4
1013 call *%ebx
1014 push %eax
1015 CFI_ADJUST_CFA_OFFSET 4
1016 call do_exit
1017 CFI_ENDPROC
1018ENDPROC(kernel_thread_helper)
1019
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001020#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001021/* Xen doesn't set %esp to be precisely what the normal sysenter
1022 entrypoint expects, so fix it up before using the normal path. */
1023ENTRY(xen_sysenter_target)
1024 RING0_INT_FRAME
1025 addl $5*4, %esp /* remove xen-provided frame */
1026 jmp sysenter_past_esp
1027
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001028ENTRY(xen_hypervisor_callback)
1029 CFI_STARTPROC
1030 pushl $0
1031 CFI_ADJUST_CFA_OFFSET 4
1032 SAVE_ALL
1033 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001034
1035 /* Check to see if we got the event in the critical
1036 region in xen_iret_direct, after we've reenabled
1037 events and checked for pending events. This simulates
1038 iret instruction's behaviour where it delivers a
1039 pending interrupt when enabling interrupts. */
1040 movl PT_EIP(%esp),%eax
1041 cmpl $xen_iret_start_crit,%eax
1042 jb 1f
1043 cmpl $xen_iret_end_crit,%eax
1044 jae 1f
1045
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001046 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001047
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001048ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010491: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001050 call xen_evtchn_do_upcall
1051 jmp ret_from_intr
1052 CFI_ENDPROC
1053ENDPROC(xen_hypervisor_callback)
1054
1055# Hypervisor uses this for application faults while it executes.
1056# We get here for two reasons:
1057# 1. Fault while reloading DS, ES, FS or GS
1058# 2. Fault while executing IRET
1059# Category 1 we fix up by reattempting the load, and zeroing the segment
1060# register if the load fails.
1061# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1062# normal Linux return path in this case because if we use the IRET hypercall
1063# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1064# We distinguish between categories by maintaining a status value in EAX.
1065ENTRY(xen_failsafe_callback)
1066 CFI_STARTPROC
1067 pushl %eax
1068 CFI_ADJUST_CFA_OFFSET 4
1069 movl $1,%eax
10701: mov 4(%esp),%ds
10712: mov 8(%esp),%es
10723: mov 12(%esp),%fs
10734: mov 16(%esp),%gs
1074 testl %eax,%eax
1075 popl %eax
1076 CFI_ADJUST_CFA_OFFSET -4
1077 lea 16(%esp),%esp
1078 CFI_ADJUST_CFA_OFFSET -16
1079 jz 5f
1080 addl $16,%esp
1081 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
10825: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1083 CFI_ADJUST_CFA_OFFSET 4
1084 SAVE_ALL
1085 jmp ret_from_exception
1086 CFI_ENDPROC
1087
1088.section .fixup,"ax"
10896: xorl %eax,%eax
1090 movl %eax,4(%esp)
1091 jmp 1b
10927: xorl %eax,%eax
1093 movl %eax,8(%esp)
1094 jmp 2b
10958: xorl %eax,%eax
1096 movl %eax,12(%esp)
1097 jmp 3b
10989: xorl %eax,%eax
1099 movl %eax,16(%esp)
1100 jmp 4b
1101.previous
1102.section __ex_table,"a"
1103 .align 4
1104 .long 1b,6b
1105 .long 2b,7b
1106 .long 3b,8b
1107 .long 4b,9b
1108.previous
1109ENDPROC(xen_failsafe_callback)
1110
1111#endif /* CONFIG_XEN */
1112
Arjan van de Venbb152f52006-01-06 00:12:05 -08001113.section .rodata,"a"
Thomas Gleixner541054d2007-10-11 11:12:00 +02001114#include "syscall_table_32.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116syscall_table_size=(.-sys_call_table)