blob: e6517ce0b8249bde9d6028bcd3d9966d2002fb5c [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "irq_vectors.h"
55
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")
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +010061 * ENABLE_INTERRUPTS_SYSCALL_RET (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
251 movl TI_flags(%ebp), %ecx
252 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
253 # int/exception return?
254 jne work_pending
255 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100256END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258#ifdef CONFIG_PREEMPT
259ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100260 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
262 jnz restore_nocheck
263need_resched:
264 movl TI_flags(%ebp), %ecx # need_resched set ?
265 testb $_TIF_NEED_RESCHED, %cl
266 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300267 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 jz restore_all
269 call preempt_schedule_irq
270 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100271END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200273 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275/* SYSENTER_RETURN points to after the "sysenter" instruction in
276 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
277
278 # sysenter call handler stub
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100279ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200280 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200281 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200282 CFI_DEF_CFA esp, 0
283 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100284 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700286 /*
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700287 * Interrupts are disabled here, but we can't trace it until
288 * enough kernel state to call TRACE_IRQS_OFF can be called - but
289 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700290 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200292 CFI_ADJUST_CFA_OFFSET 4
293 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200295 CFI_ADJUST_CFA_OFFSET 4
296 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 pushfl
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700298 orl $X86_EFLAGS_IF, (%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200299 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200301 CFI_ADJUST_CFA_OFFSET 4
302 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700303 /*
304 * Push current_thread_info()->sysenter_return to the stack.
305 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
306 * pushed above; +8 corresponds to copy_thread's esp0 setting.
307 */
308 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200309 CFI_ADJUST_CFA_OFFSET 4
310 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700312 pushl %eax
313 CFI_ADJUST_CFA_OFFSET 4
314 SAVE_ALL
315 ENABLE_INTERRUPTS(CLBR_NONE)
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317/*
318 * Load the potential sixth argument from user stack.
319 * Careful about security.
320 */
321 cmpl $__PAGE_OFFSET-3,%ebp
322 jae syscall_fault
3231: movl (%ebp),%ebp
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700324 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325.section __ex_table,"a"
326 .align 4
327 .long 1b,syscall_fault
328.previous
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 GET_THREAD_INFO(%ebp)
331
332 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700333 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 jnz syscall_trace_entry
335 cmpl $(nr_syscalls), %eax
336 jae syscall_badsys
337 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100338 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200339 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200340 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700341 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 movl TI_flags(%ebp), %ecx
343 testw $_TIF_ALLWORK_MASK, %cx
344 jne syscall_exit_work
345/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100346 movl PT_EIP(%esp), %edx
347 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700349 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003501: mov PT_FS(%esp), %fs
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100351 ENABLE_INTERRUPTS_SYSCALL_RET
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200352 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100353.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003542: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100355 jmp 1b
356.section __ex_table,"a"
357 .align 4
358 .long 1b,2b
359.popsection
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100360ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 # system call handler stub
363ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200364 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200366 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 SAVE_ALL
368 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700369 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Laurent Viviered75e8d2005-09-03 15:57:18 -0700371 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 jnz syscall_trace_entry
373 cmpl $(nr_syscalls), %eax
374 jae syscall_badsys
375syscall_call:
376 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100377 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200379 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100380 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 # setting need_resched or sigpending
382 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700383 TRACE_IRQS_OFF
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300384 testl $X86_EFLAGS_TF,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
Jason Wessel1e2e99f2007-07-06 02:39:50 -0700385 jz no_singlestep
386 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
387no_singlestep:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 movl TI_flags(%ebp), %ecx
389 testw $_TIF_ALLWORK_MASK, %cx # current->work
390 jne syscall_exit_work
391
392restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100393 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
394 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700395 # are returning to the kernel.
396 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100397 movb PT_OLDSS(%esp), %ah
398 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300399 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200400 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200401 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 je ldt_ss # returning to user-space with LDT SS
403restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700404 TRACE_IRQS_IRET
405restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 RESTORE_REGS
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100407 addl $4, %esp # skip orig_eax/error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200408 CFI_ADJUST_CFA_OFFSET -4
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200409irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100410 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700412ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700413 pushl $0 # no error code
414 pushl $do_iret_error
415 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416.previous
417.section __ex_table,"a"
418 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100419 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420.previous
421
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200422 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100424 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 jnz restore_nocheck
426 testl $0x00400000, %eax # returning to 32bit stack?
427 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100428
429#ifdef CONFIG_PARAVIRT
430 /*
431 * The kernel can't run on a non-flat stack if paravirt mode
432 * is active. Rather than try to fixup the high bits of
433 * ESP, bypass this code entirely. This may break DOSemu
434 * and/or Wine support in a paravirt VM, although the option
435 * is still available to implement the setting of the high
436 * 16-bits in the INTERRUPT_RETURN paravirt-op.
437 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700438 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100439 jne restore_nocheck
440#endif
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 /* If returning to userspace with 16bit stack,
443 * try to fix the higher word of ESP, as the CPU
444 * won't restore it.
445 * This is an "official" bug of all the x86-compatible
446 * CPUs, which we can try to work around to make
447 * dosemu and wine happy. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100448 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100449 movl %esp, %edx
450 call patch_espfix_desc
451 pushl $__ESPFIX_SS
452 CFI_ADJUST_CFA_OFFSET 4
453 pushl %eax
454 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100455 DISABLE_INTERRUPTS(CLBR_EAX)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700456 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100457 lss (%esp), %esp
458 CFI_ADJUST_CFA_OFFSET -8
459 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200460 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100461ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 # perform work that needs to be done immediately before resumption
464 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200465 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466work_pending:
467 testb $_TIF_NEED_RESCHED, %cl
468 jz work_notifysig
469work_resched:
470 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200471 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100472 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 # setting need_resched or sigpending
474 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700475 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 movl TI_flags(%ebp), %ecx
477 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
478 # than syscall tracing?
479 jz restore_all
480 testb $_TIF_NEED_RESCHED, %cl
481 jnz work_resched
482
483work_notifysig: # deal with pending signals and
484 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100485#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300486 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 movl %esp, %eax
488 jne work_notifysig_v86 # returning to kernel-space or
489 # vm86-space
490 xorl %edx, %edx
491 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700492 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 ALIGN
495work_notifysig_v86:
496 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200497 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 call save_v86_state # %eax contains pt_regs pointer
499 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200500 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100502#else
503 movl %esp, %eax
504#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 xorl %edx, %edx
506 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700507 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100508END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 # perform syscall exit tracing
511 ALIGN
512syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100513 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 movl %esp, %eax
515 xorl %edx,%edx
516 call do_syscall_trace
Laurent Viviered75e8d2005-09-03 15:57:18 -0700517 cmpl $0, %eax
Paolo 'Blaisorblade' Giarrusso640aa462005-09-03 15:57:22 -0700518 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
Laurent Viviered75e8d2005-09-03 15:57:18 -0700519 # so must skip actual syscall
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100520 movl PT_ORIG_EAX(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 cmpl $(nr_syscalls), %eax
522 jnae syscall_call
523 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100524END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 # perform syscall exit tracing
527 ALIGN
528syscall_exit_work:
529 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
530 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700531 TRACE_IRQS_ON
Rusty Russell139ec7c2006-12-07 02:14:08 +0100532 ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 # schedule() instead
534 movl %esp, %eax
535 movl $1, %edx
536 call do_syscall_trace
537 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100538END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200539 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200541 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100544 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100546END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100549 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100551END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200552 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100555 /* since we are on a wrong stack, we cant make it a C code :( */ \
Jeremy Fitzhardinge7a61d352007-05-02 19:27:15 +0200556 PER_CPU(gdt_page, %ebx); \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100557 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
558 addl %esp, %eax; \
559 pushl $__KERNEL_DS; \
560 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200562 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100563 lss (%esp), %esp; \
564 CFI_ADJUST_CFA_OFFSET -8;
565#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100567 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100569 jne 27f; \
570 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200571 movl %eax, %ds; \
572 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100573 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200574 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010057527:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577/*
578 * Build the entry stubs and pointer table with
579 * some assembler magic.
580 */
Jan Beulich3e7622f2008-01-30 13:31:23 +0100581.section .rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582ENTRY(interrupt)
583.text
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200586 RING0_INT_FRAME
Jan Beulich47a55cd2007-02-13 13:26:24 +0100587vector=0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588.rept NR_IRQS
589 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200590 .if vector
591 CFI_ADJUST_CFA_OFFSET -4
592 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07005931: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200594 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 jmp common_interrupt
Jan Beulich47a55cd2007-02-13 13:26:24 +0100596 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .long 1b
Jan Beulich47a55cd2007-02-13 13:26:24 +0100598 .text
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599vector=vector+1
600.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100601END(irq_entries_start)
602
603.previous
604END(interrupt)
605.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Ingo Molnar55f327f2006-07-03 00:24:43 -0700607/*
608 * the CPU automatically disables interrupts when executing an IRQ vector,
609 * so IRQ-flags tracing has to follow that:
610 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 ALIGN
612common_interrupt:
613 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700614 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 movl %esp,%eax
616 call do_IRQ
617 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100618ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200619 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621#define BUILD_INTERRUPT(name, nr) \
622ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200623 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700624 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200625 CFI_ADJUST_CFA_OFFSET 4; \
626 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700627 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 movl %esp,%eax; \
Jeremy Fitzhardingef76c3922007-05-02 19:27:05 +0200629 call smp_##name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700630 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100631 CFI_ENDPROC; \
632ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634/* The include is where all of the SMP etc. interrupts come from */
635#include "entry_arch.h"
636
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200637KPROBE_ENTRY(page_fault)
638 RING0_EC_FRAME
639 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200640 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 ALIGN
642error_code:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100643 /* the function address is in %fs's slot on the stack */
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100644 pushl %es
645 CFI_ADJUST_CFA_OFFSET 4
646 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200648 CFI_ADJUST_CFA_OFFSET 4
649 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200651 CFI_ADJUST_CFA_OFFSET 4
652 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200654 CFI_ADJUST_CFA_OFFSET 4
655 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200657 CFI_ADJUST_CFA_OFFSET 4
658 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200660 CFI_ADJUST_CFA_OFFSET 4
661 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200663 CFI_ADJUST_CFA_OFFSET 4
664 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200666 CFI_ADJUST_CFA_OFFSET 4
667 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200669 CFI_ADJUST_CFA_OFFSET 4
670 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 cld
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100672 pushl %fs
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200673 CFI_ADJUST_CFA_OFFSET 4
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100674 /*CFI_REL_OFFSET fs, 0*/
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200675 movl $(__KERNEL_PERCPU), %ecx
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100676 movl %ecx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 UNWIND_ESPFIX_STACK
678 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200679 CFI_ADJUST_CFA_OFFSET -4
680 /*CFI_REGISTER es, ecx*/
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100681 movl PT_FS(%esp), %edi # get the function address
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100682 movl PT_ORIG_EAX(%esp), %edx # get the error code
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100683 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100684 mov %ecx, PT_FS(%esp)
685 /*CFI_REL_OFFSET fs, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 movl $(__USER_DS), %ecx
687 movl %ecx, %ds
688 movl %ecx, %es
689 movl %esp,%eax # pt_regs pointer
690 call *%edi
691 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200692 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200693KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200696 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200698 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200700 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200702 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100703END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
705ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200706 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200708 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200710 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200712 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100713END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200716 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200718 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 SAVE_ALL
Rusty Russell0da5db32006-09-26 10:52:39 +0200720 GET_CR0_INTO_EAX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 testl $0x4, %eax # EM (math emulation bit)
722 jne device_not_available_emulate
Rusty Russell139ec7c2006-12-07 02:14:08 +0100723 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 call math_state_restore
725 jmp ret_from_exception
726device_not_available_emulate:
727 pushl $0 # temporary storage for ORIG_EIP
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200728 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 call math_emulate
730 addl $4, %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200731 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200733 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100734END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736/*
737 * Debug traps and NMI can happen at the one SYSENTER instruction
738 * that sets up the real kernel stack. Check here, since we can't
739 * allow the wrong stack to be used.
740 *
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100741 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 * already pushed 3 words if it hits on the sysenter instruction:
743 * eflags, cs and eip.
744 *
745 * We just load the right stack, and push the three (known) values
746 * by hand onto the new stack - while updating the return eip past
747 * the instruction that would have done it for sysenter.
748 */
749#define FIX_STACK(offset, ok, label) \
750 cmpw $__KERNEL_CS,4(%esp); \
751 jne ok; \
752label: \
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100753 movl TSS_sysenter_sp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200754 CFI_DEF_CFA esp, 0; \
755 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200757 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200759 CFI_ADJUST_CFA_OFFSET 4; \
760 pushl $sysenter_past_esp; \
761 CFI_ADJUST_CFA_OFFSET 4; \
762 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700764KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200765 RING0_INT_FRAME
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100766 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 jne debug_stack_correct
768 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
769debug_stack_correct:
770 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200771 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 SAVE_ALL
773 xorl %edx,%edx # error code 0
774 movl %esp,%eax # pt_regs pointer
775 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200777 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200778KPROBE_END(debug)
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780/*
781 * NMI is doubly nasty. It can happen _while_ we're handling
782 * a debug fault, and the debug fault hasn't yet been able to
783 * clear up the stack. So we first check whether we got an
784 * NMI on the sysenter entry path, but after that we need to
785 * check whether we got an NMI on the debug path where the debug
786 * fault happened on the sysenter path.
787 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200788KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200789 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200791 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 movl %ss, %eax
793 cmpw $__ESPFIX_SS, %ax
794 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200795 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100796 je nmi_espfix_stack
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100797 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 je nmi_stack_fixup
799 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200800 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 movl %esp,%eax
802 /* Do not access memory above the end of our stack page,
803 * it might not exist.
804 */
805 andl $(THREAD_SIZE-1),%eax
806 cmpl $(THREAD_SIZE-20),%eax
807 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200808 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 jae nmi_stack_correct
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100810 cmpl $ia32_sysenter_target,12(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 je nmi_debug_stack_check
812nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200813 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200815 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 SAVE_ALL
817 xorl %edx,%edx # zero error code
818 movl %esp,%eax # pt_regs pointer
819 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700820 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200821 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200824 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 FIX_STACK(12,nmi_stack_correct, 1)
826 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200829 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 cmpw $__KERNEL_CS,16(%esp)
831 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800832 cmpl $debug,(%esp)
833 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800835 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 FIX_STACK(24,nmi_stack_correct, 1)
837 jmp nmi_stack_correct
838
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100839nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200840 /* We have a RING0_INT_FRAME here.
841 *
842 * create the pointer to lss back
843 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200845 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200847 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 addw $4, (%esp)
849 /* copy the iret frame of 12 bytes */
850 .rept 3
851 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200852 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 .endr
854 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200855 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 SAVE_ALL
857 FIXUP_ESPFIX_STACK # %eax == %esp
858 xorl %edx,%edx # zero error code
859 call do_nmi
860 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100861 lss 12+4(%esp), %esp # back to espfix stack
862 CFI_ADJUST_CFA_OFFSET -24
Ingo Molnar3701d8632008-02-09 23:24:08 +0100863 jmp irq_return
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200864 CFI_ENDPROC
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200865KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866
Rusty Russelld3561b72006-12-07 02:14:07 +0100867#ifdef CONFIG_PARAVIRT
868ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100869 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100870.section __ex_table,"a"
871 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100872 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100873.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100874END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100875
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100876ENTRY(native_irq_enable_syscall_ret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100877 sti
878 sysexit
Glauber de Oliveira Costa6abcd982008-01-30 13:30:33 +0100879END(native_irq_enable_syscall_ret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100880#endif
881
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700882KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200883 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200885 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 SAVE_ALL
887 xorl %edx,%edx # zero error code
888 movl %esp,%eax # pt_regs pointer
889 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200892KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200895 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200897 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200899 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200901 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100902END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200905 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200907 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200909 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200911 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100912END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200915 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200917 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200919 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200921 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100922END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200925 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200927 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200929 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200931 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100932END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200935 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200937 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200939 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100940END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200943 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200945 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200947 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100948END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200951 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 pushl $do_stack_segment
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200955 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100956END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700958KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200959 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 pushl $do_general_protection
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200961 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200964KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200969 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200971 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100972END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200974ENTRY(divide_error)
975 RING0_INT_FRAME
976 pushl $0 # no error code
977 CFI_ADJUST_CFA_OFFSET 4
978 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200979 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200981 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100982END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984#ifdef CONFIG_X86_MCE
985ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200986 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200988 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200990 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200992 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100993END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994#endif
995
996ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200997 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200999 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001001 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001003 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001004END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andi Kleen02ba1a32006-09-26 10:52:35 +02001006ENTRY(kernel_thread_helper)
1007 pushl $0 # fake return address for unwinder
1008 CFI_STARTPROC
1009 movl %edx,%eax
1010 push %edx
1011 CFI_ADJUST_CFA_OFFSET 4
1012 call *%ebx
1013 push %eax
1014 CFI_ADJUST_CFA_OFFSET 4
1015 call do_exit
1016 CFI_ENDPROC
1017ENDPROC(kernel_thread_helper)
1018
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001019#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001020/* Xen doesn't set %esp to be precisely what the normal sysenter
1021 entrypoint expects, so fix it up before using the normal path. */
1022ENTRY(xen_sysenter_target)
1023 RING0_INT_FRAME
1024 addl $5*4, %esp /* remove xen-provided frame */
1025 jmp sysenter_past_esp
1026
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001027ENTRY(xen_hypervisor_callback)
1028 CFI_STARTPROC
1029 pushl $0
1030 CFI_ADJUST_CFA_OFFSET 4
1031 SAVE_ALL
1032 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001033
1034 /* Check to see if we got the event in the critical
1035 region in xen_iret_direct, after we've reenabled
1036 events and checked for pending events. This simulates
1037 iret instruction's behaviour where it delivers a
1038 pending interrupt when enabling interrupts. */
1039 movl PT_EIP(%esp),%eax
1040 cmpl $xen_iret_start_crit,%eax
1041 jb 1f
1042 cmpl $xen_iret_end_crit,%eax
1043 jae 1f
1044
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001045 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001046
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001047ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010481: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001049 call xen_evtchn_do_upcall
1050 jmp ret_from_intr
1051 CFI_ENDPROC
1052ENDPROC(xen_hypervisor_callback)
1053
1054# Hypervisor uses this for application faults while it executes.
1055# We get here for two reasons:
1056# 1. Fault while reloading DS, ES, FS or GS
1057# 2. Fault while executing IRET
1058# Category 1 we fix up by reattempting the load, and zeroing the segment
1059# register if the load fails.
1060# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1061# normal Linux return path in this case because if we use the IRET hypercall
1062# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1063# We distinguish between categories by maintaining a status value in EAX.
1064ENTRY(xen_failsafe_callback)
1065 CFI_STARTPROC
1066 pushl %eax
1067 CFI_ADJUST_CFA_OFFSET 4
1068 movl $1,%eax
10691: mov 4(%esp),%ds
10702: mov 8(%esp),%es
10713: mov 12(%esp),%fs
10724: mov 16(%esp),%gs
1073 testl %eax,%eax
1074 popl %eax
1075 CFI_ADJUST_CFA_OFFSET -4
1076 lea 16(%esp),%esp
1077 CFI_ADJUST_CFA_OFFSET -16
1078 jz 5f
1079 addl $16,%esp
1080 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
10815: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1082 CFI_ADJUST_CFA_OFFSET 4
1083 SAVE_ALL
1084 jmp ret_from_exception
1085 CFI_ENDPROC
1086
1087.section .fixup,"ax"
10886: xorl %eax,%eax
1089 movl %eax,4(%esp)
1090 jmp 1b
10917: xorl %eax,%eax
1092 movl %eax,8(%esp)
1093 jmp 2b
10948: xorl %eax,%eax
1095 movl %eax,12(%esp)
1096 jmp 3b
10979: xorl %eax,%eax
1098 movl %eax,16(%esp)
1099 jmp 4b
1100.previous
1101.section __ex_table,"a"
1102 .align 4
1103 .long 1b,6b
1104 .long 2b,7b
1105 .long 3b,8b
1106 .long 4b,9b
1107.previous
1108ENDPROC(xen_failsafe_callback)
1109
1110#endif /* CONFIG_XEN */
1111
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001112#ifdef CONFIG_FTRACE
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001113#ifdef CONFIG_DYNAMIC_FTRACE
1114
1115ENTRY(mcount)
1116 pushl %eax
1117 pushl %ecx
1118 pushl %edx
1119 movl 0xc(%esp), %eax
1120
1121.globl mcount_call
1122mcount_call:
1123 call ftrace_stub
1124
1125 popl %edx
1126 popl %ecx
1127 popl %eax
1128
1129 ret
1130END(mcount)
1131
1132ENTRY(ftrace_caller)
1133 pushl %eax
1134 pushl %ecx
1135 pushl %edx
1136 movl 0xc(%esp), %eax
1137 movl 0x4(%ebp), %edx
1138
1139.globl ftrace_call
1140ftrace_call:
1141 call ftrace_stub
1142
1143 popl %edx
1144 popl %ecx
1145 popl %eax
1146
1147.globl ftrace_stub
1148ftrace_stub:
1149 ret
1150END(ftrace_caller)
1151
1152#else /* ! CONFIG_DYNAMIC_FTRACE */
1153
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001154ENTRY(mcount)
1155 cmpl $ftrace_stub, ftrace_trace_function
1156 jnz trace
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001157.globl ftrace_stub
1158ftrace_stub:
1159 ret
1160
1161 /* taken from glibc */
1162trace:
1163 pushl %eax
1164 pushl %ecx
1165 pushl %edx
1166 movl 0xc(%esp), %eax
1167 movl 0x4(%ebp), %edx
1168
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001169 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001170
1171 popl %edx
1172 popl %ecx
1173 popl %eax
1174
1175 jmp ftrace_stub
1176END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001177#endif /* CONFIG_DYNAMIC_FTRACE */
1178#endif /* CONFIG_FTRACE */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001179
Arjan van de Venbb152f52006-01-06 00:12:05 -08001180.section .rodata,"a"
Thomas Gleixner541054d2007-10-11 11:12:00 +02001181#include "syscall_table_32.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183syscall_table_size=(.-sys_call_table)