blob: 43ceb3f454bfce00386eeaaf377014871272a809 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 */
5
6/*
7 * entry.S contains the system-call and fault low-level handling routines.
8 * This also contains the timer-interrupt handler, as well as all interrupts
9 * and faults that can result in a task-switch.
10 *
11 * NOTE: This code handles signal-recognition, which happens every time
12 * after a timer-interrupt and after each system call.
13 *
14 * I changed all the .align's to 4 (16 byte alignment), as that's faster
15 * on a 486.
16 *
Andi Kleen889f21c2007-05-02 19:27:19 +020017 * Stack layout in 'syscall_exit':
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * ptrace needs to have all regs on the stack.
19 * if the order here is changed, it needs to be
20 * updated in fork.c:copy_process, signal.c:do_signal,
21 * ptrace.c and ptrace.h
22 *
23 * 0(%esp) - %ebx
24 * 4(%esp) - %ecx
25 * 8(%esp) - %edx
26 * C(%esp) - %esi
27 * 10(%esp) - %edi
28 * 14(%esp) - %ebp
29 * 18(%esp) - %eax
30 * 1C(%esp) - %ds
31 * 20(%esp) - %es
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010032 * 24(%esp) - %fs
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +010033 * 28(%esp) - orig_eax
34 * 2C(%esp) - %eip
35 * 30(%esp) - %cs
36 * 34(%esp) - %eflags
37 * 38(%esp) - %oldesp
38 * 3C(%esp) - %oldss
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 *
40 * "current" is in register %ebx during any slow entries.
41 */
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/linkage.h>
44#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070045#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/errno.h>
47#include <asm/segment.h>
48#include <asm/smp.h>
49#include <asm/page.h>
50#include <asm/desc.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010051#include <asm/percpu.h>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020052#include <asm/dwarf2.h>
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030053#include <asm/processor-flags.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053054#include <asm/ftrace.h>
Thomas Gleixner9b7dc562008-05-02 20:10:09 +020055#include <asm/irq_vectors.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Roland McGrathaf0575b2008-06-24 04:16:52 -070057/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
58#include <linux/elf-em.h>
59#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
60#define __AUDIT_ARCH_LE 0x40000000
61
62#ifndef CONFIG_AUDITSYSCALL
63#define sysenter_audit syscall_trace_entry
64#define sysexit_audit syscall_exit_work
65#endif
66
Rusty Russell139ec7c2006-12-07 02:14:08 +010067/*
68 * We use macros for low-level operations which need to be overridden
69 * for paravirtualization. The following will never clobber any registers:
70 * INTERRUPT_RETURN (aka. "iret")
71 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -040072 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010073 *
74 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
75 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
76 * Allowing a register to be clobbered can shrink the paravirt replacement
77 * enough to patch inline, increasing performance.
78 */
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define nr_syscalls ((syscall_table_size)/4)
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#ifdef CONFIG_PREEMPT
Rusty Russell139ec7c2006-12-07 02:14:08 +010083#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#else
Rusty Russell139ec7c2006-12-07 02:14:08 +010085#define preempt_stop(clobbers)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#define resume_kernel restore_nocheck
87#endif
88
Ingo Molnar55f327f2006-07-03 00:24:43 -070089.macro TRACE_IRQS_IRET
90#ifdef CONFIG_TRACE_IRQFLAGS
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030091 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070092 jz 1f
93 TRACE_IRQS_ON
941:
95#endif
96.endm
97
Aleksey Gorelov4031ff32006-06-27 02:53:48 -070098#ifdef CONFIG_VM86
99#define resume_userspace_sig check_userspace
100#else
101#define resume_userspace_sig resume_userspace
102#endif
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#define SAVE_ALL \
105 cld; \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100106 pushl %fs; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100107 CFI_ADJUST_CFA_OFFSET 4;\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100108 /*CFI_REL_OFFSET fs, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 pushl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200110 CFI_ADJUST_CFA_OFFSET 4;\
111 /*CFI_REL_OFFSET es, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 pushl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200113 CFI_ADJUST_CFA_OFFSET 4;\
114 /*CFI_REL_OFFSET ds, 0;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200116 CFI_ADJUST_CFA_OFFSET 4;\
117 CFI_REL_OFFSET eax, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 pushl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200119 CFI_ADJUST_CFA_OFFSET 4;\
120 CFI_REL_OFFSET ebp, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 pushl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200122 CFI_ADJUST_CFA_OFFSET 4;\
123 CFI_REL_OFFSET edi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 pushl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200125 CFI_ADJUST_CFA_OFFSET 4;\
126 CFI_REL_OFFSET esi, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 pushl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200128 CFI_ADJUST_CFA_OFFSET 4;\
129 CFI_REL_OFFSET edx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 pushl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200131 CFI_ADJUST_CFA_OFFSET 4;\
132 CFI_REL_OFFSET ecx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 pushl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200134 CFI_ADJUST_CFA_OFFSET 4;\
135 CFI_REL_OFFSET ebx, 0;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 movl $(__USER_DS), %edx; \
137 movl %edx, %ds; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100138 movl %edx, %es; \
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200139 movl $(__KERNEL_PERCPU), %edx; \
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100140 movl %edx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142#define RESTORE_INT_REGS \
143 popl %ebx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200144 CFI_ADJUST_CFA_OFFSET -4;\
145 CFI_RESTORE ebx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 popl %ecx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200147 CFI_ADJUST_CFA_OFFSET -4;\
148 CFI_RESTORE ecx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 popl %edx; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200150 CFI_ADJUST_CFA_OFFSET -4;\
151 CFI_RESTORE edx;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 popl %esi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200153 CFI_ADJUST_CFA_OFFSET -4;\
154 CFI_RESTORE esi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 popl %edi; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200156 CFI_ADJUST_CFA_OFFSET -4;\
157 CFI_RESTORE edi;\
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 popl %ebp; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200159 CFI_ADJUST_CFA_OFFSET -4;\
160 CFI_RESTORE ebp;\
161 popl %eax; \
162 CFI_ADJUST_CFA_OFFSET -4;\
163 CFI_RESTORE eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165#define RESTORE_REGS \
166 RESTORE_INT_REGS; \
1671: popl %ds; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200168 CFI_ADJUST_CFA_OFFSET -4;\
169 /*CFI_RESTORE ds;*/\
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702: popl %es; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200171 CFI_ADJUST_CFA_OFFSET -4;\
172 /*CFI_RESTORE es;*/\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01001733: popl %fs; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100174 CFI_ADJUST_CFA_OFFSET -4;\
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100175 /*CFI_RESTORE fs;*/\
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100176.pushsection .fixup,"ax"; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774: movl $0,(%esp); \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100178 jmp 1b; \
1795: movl $0,(%esp); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 jmp 2b; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +01001816: movl $0,(%esp); \
182 jmp 3b; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183.section __ex_table,"a";\
184 .align 4; \
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100185 .long 1b,4b; \
186 .long 2b,5b; \
187 .long 3b,6b; \
188.popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200190#define RING0_INT_FRAME \
191 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200192 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200193 CFI_DEF_CFA esp, 3*4;\
194 /*CFI_OFFSET cs, -2*4;*/\
195 CFI_OFFSET eip, -3*4
196
197#define RING0_EC_FRAME \
198 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200199 CFI_SIGNAL_FRAME;\
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200200 CFI_DEF_CFA esp, 4*4;\
201 /*CFI_OFFSET cs, -2*4;*/\
202 CFI_OFFSET eip, -3*4
203
204#define RING0_PTREGS_FRAME \
205 CFI_STARTPROC simple;\
Jan Beulichadf14232006-09-26 10:52:41 +0200206 CFI_SIGNAL_FRAME;\
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100207 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
208 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
209 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
210 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
211 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
212 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
213 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
214 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
215 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
216 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
217 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
218 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200221 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700223 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 call schedule_tail
225 GET_THREAD_INFO(%ebp)
226 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200227 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700228 pushl $0x0202 # Reset kernel eflags
229 CFI_ADJUST_CFA_OFFSET 4
230 popfl
231 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200233 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100234END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
236/*
237 * Return to user mode is not as complex as all this looks,
238 * but we want the default path for a system call return to
239 * go as quickly as possible which is why some of this is
240 * less clear than it otherwise should be.
241 */
242
243 # userspace resumption stub bypassing syscall exit tracing
244 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200245 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100247 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248ret_from_intr:
249 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700250check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100251 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
252 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300253 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200254 cmpl $USER_RPL, %eax
255 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200258 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100259 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 # setting need_resched or sigpending
261 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200262 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 movl TI_flags(%ebp), %ecx
264 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
265 # int/exception return?
266 jne work_pending
267 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100268END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270#ifdef CONFIG_PREEMPT
271ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100272 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
274 jnz restore_nocheck
275need_resched:
276 movl TI_flags(%ebp), %ecx # need_resched set ?
277 testb $_TIF_NEED_RESCHED, %cl
278 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300279 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 jz restore_all
281 call preempt_schedule_irq
282 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100283END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200285 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287/* SYSENTER_RETURN points to after the "sysenter" instruction in
288 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
289
290 # sysenter call handler stub
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100291ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200292 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200293 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200294 CFI_DEF_CFA esp, 0
295 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100296 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700298 /*
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700299 * Interrupts are disabled here, but we can't trace it until
300 * enough kernel state to call TRACE_IRQS_OFF can be called - but
301 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700302 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200304 CFI_ADJUST_CFA_OFFSET 4
305 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200307 CFI_ADJUST_CFA_OFFSET 4
308 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 pushfl
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700310 orl $X86_EFLAGS_IF, (%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200311 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200313 CFI_ADJUST_CFA_OFFSET 4
314 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700315 /*
316 * Push current_thread_info()->sysenter_return to the stack.
317 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
318 * pushed above; +8 corresponds to copy_thread's esp0 setting.
319 */
320 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200321 CFI_ADJUST_CFA_OFFSET 4
322 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700324 pushl %eax
325 CFI_ADJUST_CFA_OFFSET 4
326 SAVE_ALL
327 ENABLE_INTERRUPTS(CLBR_NONE)
328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329/*
330 * Load the potential sixth argument from user stack.
331 * Careful about security.
332 */
333 cmpl $__PAGE_OFFSET-3,%ebp
334 jae syscall_fault
3351: movl (%ebp),%ebp
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700336 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337.section __ex_table,"a"
338 .align 4
339 .long 1b,syscall_fault
340.previous
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 GET_THREAD_INFO(%ebp)
343
344 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Roland McGrathd4d67152008-07-09 02:38:07 -0700345 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700346 jnz sysenter_audit
347sysenter_do_call:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 cmpl $(nr_syscalls), %eax
349 jae syscall_badsys
350 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100351 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200352 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200353 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700354 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 movl TI_flags(%ebp), %ecx
356 testw $_TIF_ALLWORK_MASK, %cx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700357 jne sysexit_audit
358sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100360 movl PT_EIP(%esp), %edx
361 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700363 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003641: mov PT_FS(%esp), %fs
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400365 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700366
367#ifdef CONFIG_AUDITSYSCALL
368sysenter_audit:
369 testw $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
370 jnz syscall_trace_entry
371 addl $4,%esp
372 CFI_ADJUST_CFA_OFFSET -4
373 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
374 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
375 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
376 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
377 movl %eax,%edx /* 2nd arg: syscall number */
378 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
379 call audit_syscall_entry
380 pushl %ebx
381 CFI_ADJUST_CFA_OFFSET 4
382 movl PT_EAX(%esp),%eax /* reload syscall number */
383 jmp sysenter_do_call
384
385sysexit_audit:
386 testw $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %cx
387 jne syscall_exit_work
388 TRACE_IRQS_ON
389 ENABLE_INTERRUPTS(CLBR_ANY)
390 movl %eax,%edx /* second arg, syscall return value */
391 cmpl $0,%eax /* is it < 0? */
392 setl %al /* 1 if so, 0 if not */
393 movzbl %al,%eax /* zero-extend that */
394 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
395 call audit_syscall_exit
396 DISABLE_INTERRUPTS(CLBR_ANY)
397 TRACE_IRQS_OFF
398 movl TI_flags(%ebp), %ecx
399 testw $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %cx
400 jne syscall_exit_work
401 movl PT_EAX(%esp),%eax /* reload syscall return value */
402 jmp sysenter_exit
403#endif
404
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200405 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100406.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004072: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100408 jmp 1b
409.section __ex_table,"a"
410 .align 4
411 .long 1b,2b
412.popsection
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100413ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 # system call handler stub
416ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200417 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200419 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 SAVE_ALL
421 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700422 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Roland McGrathd4d67152008-07-09 02:38:07 -0700424 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 jnz syscall_trace_entry
426 cmpl $(nr_syscalls), %eax
427 jae syscall_badsys
428syscall_call:
429 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100430 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200432 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100433 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 # setting need_resched or sigpending
435 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700436 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 movl TI_flags(%ebp), %ecx
438 testw $_TIF_ALLWORK_MASK, %cx # current->work
439 jne syscall_exit_work
440
441restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100442 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
443 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700444 # are returning to the kernel.
445 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100446 movb PT_OLDSS(%esp), %ah
447 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300448 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200449 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200450 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 je ldt_ss # returning to user-space with LDT SS
452restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700453 TRACE_IRQS_IRET
454restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 RESTORE_REGS
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100456 addl $4, %esp # skip orig_eax/error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200457 CFI_ADJUST_CFA_OFFSET -4
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200458irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100459 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700461ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700462 pushl $0 # no error code
463 pushl $do_iret_error
464 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465.previous
466.section __ex_table,"a"
467 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100468 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469.previous
470
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200471 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100473 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 jnz restore_nocheck
475 testl $0x00400000, %eax # returning to 32bit stack?
476 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100477
478#ifdef CONFIG_PARAVIRT
479 /*
480 * The kernel can't run on a non-flat stack if paravirt mode
481 * is active. Rather than try to fixup the high bits of
482 * ESP, bypass this code entirely. This may break DOSemu
483 * and/or Wine support in a paravirt VM, although the option
484 * is still available to implement the setting of the high
485 * 16-bits in the INTERRUPT_RETURN paravirt-op.
486 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700487 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100488 jne restore_nocheck
489#endif
490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 /* If returning to userspace with 16bit stack,
492 * try to fix the higher word of ESP, as the CPU
493 * won't restore it.
494 * This is an "official" bug of all the x86-compatible
495 * CPUs, which we can try to work around to make
496 * dosemu and wine happy. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100497 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100498 movl %esp, %edx
499 call patch_espfix_desc
500 pushl $__ESPFIX_SS
501 CFI_ADJUST_CFA_OFFSET 4
502 pushl %eax
503 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100504 DISABLE_INTERRUPTS(CLBR_EAX)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700505 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100506 lss (%esp), %esp
507 CFI_ADJUST_CFA_OFFSET -8
508 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200509 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100510ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 # perform work that needs to be done immediately before resumption
513 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200514 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515work_pending:
516 testb $_TIF_NEED_RESCHED, %cl
517 jz work_notifysig
518work_resched:
519 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200520 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100521 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 # setting need_resched or sigpending
523 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700524 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 movl TI_flags(%ebp), %ecx
526 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
527 # than syscall tracing?
528 jz restore_all
529 testb $_TIF_NEED_RESCHED, %cl
530 jnz work_resched
531
532work_notifysig: # deal with pending signals and
533 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100534#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300535 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 movl %esp, %eax
537 jne work_notifysig_v86 # returning to kernel-space or
538 # vm86-space
539 xorl %edx, %edx
540 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700541 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543 ALIGN
544work_notifysig_v86:
545 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200546 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 call save_v86_state # %eax contains pt_regs pointer
548 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200549 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100551#else
552 movl %esp, %eax
553#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 xorl %edx, %edx
555 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700556 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100557END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 # perform syscall exit tracing
560 ALIGN
561syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100562 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700564 call syscall_trace_enter
565 /* What it returned is what we'll actually use. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 cmpl $(nr_syscalls), %eax
567 jnae syscall_call
568 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100569END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 # perform syscall exit tracing
572 ALIGN
573syscall_exit_work:
Roland McGrathd4d67152008-07-09 02:38:07 -0700574 testb $_TIF_WORK_SYSCALL_EXIT, %cl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700576 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700577 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 # schedule() instead
579 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700580 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100582END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200583 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200585 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100588 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100590END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100593 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100595END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200596 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
598#define FIXUP_ESPFIX_STACK \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100599 /* since we are on a wrong stack, we cant make it a C code :( */ \
Jeremy Fitzhardinge7a61d352007-05-02 19:27:15 +0200600 PER_CPU(gdt_page, %ebx); \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100601 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
602 addl %esp, %eax; \
603 pushl $__KERNEL_DS; \
604 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 pushl %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200606 CFI_ADJUST_CFA_OFFSET 4; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100607 lss (%esp), %esp; \
608 CFI_ADJUST_CFA_OFFSET -8;
609#define UNWIND_ESPFIX_STACK \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 movl %ss, %eax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100611 /* see if on espfix stack */ \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 cmpw $__ESPFIX_SS, %ax; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100613 jne 27f; \
614 movl $__KERNEL_DS, %eax; \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200615 movl %eax, %ds; \
616 movl %eax, %es; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100617 /* switch to normal stack */ \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200618 FIXUP_ESPFIX_STACK; \
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010061927:;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621/*
622 * Build the entry stubs and pointer table with
623 * some assembler magic.
624 */
Jan Beulich3e7622f2008-01-30 13:31:23 +0100625.section .rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626ENTRY(interrupt)
627.text
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200630 RING0_INT_FRAME
Jan Beulich47a55cd2007-02-13 13:26:24 +0100631vector=0
Yinghai Lu497c9a12008-08-19 20:50:28 -0700632.rept NR_VECTORS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200634 .if vector
635 CFI_ADJUST_CFA_OFFSET -4
636 .endif
Rusty Russell19eadf92006-06-27 02:53:44 -07006371: pushl $~(vector)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200638 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 jmp common_interrupt
Jan Beulich47a55cd2007-02-13 13:26:24 +0100640 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 .long 1b
Jan Beulich47a55cd2007-02-13 13:26:24 +0100642 .text
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643vector=vector+1
644.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100645END(irq_entries_start)
646
647.previous
648END(interrupt)
649.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Ingo Molnar55f327f2006-07-03 00:24:43 -0700651/*
652 * the CPU automatically disables interrupts when executing an IRQ vector,
653 * so IRQ-flags tracing has to follow that:
654 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 ALIGN
656common_interrupt:
657 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700658 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 movl %esp,%eax
660 call do_IRQ
661 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100662ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200663 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665#define BUILD_INTERRUPT(name, nr) \
666ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200667 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700668 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200669 CFI_ADJUST_CFA_OFFSET 4; \
670 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700671 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 movl %esp,%eax; \
Jeremy Fitzhardingef76c3922007-05-02 19:27:05 +0200673 call smp_##name; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700674 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100675 CFI_ENDPROC; \
676ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678/* The include is where all of the SMP etc. interrupts come from */
679#include "entry_arch.h"
680
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200681KPROBE_ENTRY(page_fault)
682 RING0_EC_FRAME
683 pushl $do_page_fault
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200684 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 ALIGN
686error_code:
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100687 /* the function address is in %fs's slot on the stack */
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100688 pushl %es
689 CFI_ADJUST_CFA_OFFSET 4
690 /*CFI_REL_OFFSET es, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 pushl %ds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200692 CFI_ADJUST_CFA_OFFSET 4
693 /*CFI_REL_OFFSET ds, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200695 CFI_ADJUST_CFA_OFFSET 4
696 CFI_REL_OFFSET eax, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200698 CFI_ADJUST_CFA_OFFSET 4
699 CFI_REL_OFFSET ebp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 pushl %edi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200701 CFI_ADJUST_CFA_OFFSET 4
702 CFI_REL_OFFSET edi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 pushl %esi
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200704 CFI_ADJUST_CFA_OFFSET 4
705 CFI_REL_OFFSET esi, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 pushl %edx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200707 CFI_ADJUST_CFA_OFFSET 4
708 CFI_REL_OFFSET edx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 pushl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200710 CFI_ADJUST_CFA_OFFSET 4
711 CFI_REL_OFFSET ecx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 pushl %ebx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200713 CFI_ADJUST_CFA_OFFSET 4
714 CFI_REL_OFFSET ebx, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 cld
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100716 pushl %fs
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200717 CFI_ADJUST_CFA_OFFSET 4
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100718 /*CFI_REL_OFFSET fs, 0*/
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200719 movl $(__KERNEL_PERCPU), %ecx
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100720 movl %ecx, %fs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 UNWIND_ESPFIX_STACK
722 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200723 CFI_ADJUST_CFA_OFFSET -4
724 /*CFI_REGISTER es, ecx*/
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100725 movl PT_FS(%esp), %edi # get the function address
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100726 movl PT_ORIG_EAX(%esp), %edx # get the error code
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100727 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100728 mov %ecx, PT_FS(%esp)
729 /*CFI_REL_OFFSET fs, ES*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 movl $(__USER_DS), %ecx
731 movl %ecx, %ds
732 movl %ecx, %es
Alexander van Heukelum85cea512008-09-09 21:56:14 +0200733 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 movl %esp,%eax # pt_regs pointer
735 call *%edi
736 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200737 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200738KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200741 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200743 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200745 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200747 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100748END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200751 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200753 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200755 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200757 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100758END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200761 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200763 CFI_ADJUST_CFA_OFFSET 4
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200764 pushl $do_device_not_available
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200765 CFI_ADJUST_CFA_OFFSET 4
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200766 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200767 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100768END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
770/*
771 * Debug traps and NMI can happen at the one SYSENTER instruction
772 * that sets up the real kernel stack. Check here, since we can't
773 * allow the wrong stack to be used.
774 *
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100775 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 * already pushed 3 words if it hits on the sysenter instruction:
777 * eflags, cs and eip.
778 *
779 * We just load the right stack, and push the three (known) values
780 * by hand onto the new stack - while updating the return eip past
781 * the instruction that would have done it for sysenter.
782 */
783#define FIX_STACK(offset, ok, label) \
784 cmpw $__KERNEL_CS,4(%esp); \
785 jne ok; \
786label: \
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100787 movl TSS_sysenter_sp0+offset(%esp),%esp; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200788 CFI_DEF_CFA esp, 0; \
789 CFI_UNDEFINED eip; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 pushfl; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200791 CFI_ADJUST_CFA_OFFSET 4; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 pushl $__KERNEL_CS; \
Chuck Ebberta549b862006-09-26 10:52:37 +0200793 CFI_ADJUST_CFA_OFFSET 4; \
794 pushl $sysenter_past_esp; \
795 CFI_ADJUST_CFA_OFFSET 4; \
796 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700798KPROBE_ENTRY(debug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200799 RING0_INT_FRAME
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100800 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 jne debug_stack_correct
802 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
803debug_stack_correct:
804 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200805 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 SAVE_ALL
Alexander van Heukelum43024a82008-09-09 21:56:15 +0200807 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 xorl %edx,%edx # error code 0
809 movl %esp,%eax # pt_regs pointer
810 call do_debug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200812 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200813KPROBE_END(debug)
814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815/*
816 * NMI is doubly nasty. It can happen _while_ we're handling
817 * a debug fault, and the debug fault hasn't yet been able to
818 * clear up the stack. So we first check whether we got an
819 * NMI on the sysenter entry path, but after that we need to
820 * check whether we got an NMI on the debug path where the debug
821 * fault happened on the sysenter path.
822 */
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200823KPROBE_ENTRY(nmi)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200824 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200826 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 movl %ss, %eax
828 cmpw $__ESPFIX_SS, %ax
829 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200830 CFI_ADJUST_CFA_OFFSET -4
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100831 je nmi_espfix_stack
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100832 cmpl $ia32_sysenter_target,(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 je nmi_stack_fixup
834 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200835 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 movl %esp,%eax
837 /* Do not access memory above the end of our stack page,
838 * it might not exist.
839 */
840 andl $(THREAD_SIZE-1),%eax
841 cmpl $(THREAD_SIZE-20),%eax
842 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200843 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 jae nmi_stack_correct
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100845 cmpl $ia32_sysenter_target,12(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 je nmi_debug_stack_check
847nmi_stack_correct:
Chuck Ebberta549b862006-09-26 10:52:37 +0200848 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200850 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 SAVE_ALL
Alexander van Heukelume0c73172008-09-09 21:56:16 +0200852 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 xorl %edx,%edx # zero error code
854 movl %esp,%eax # pt_regs pointer
855 call do_nmi
Ingo Molnar55f327f2006-07-03 00:24:43 -0700856 jmp restore_nocheck_notrace
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200857 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859nmi_stack_fixup:
Chuck Ebberta549b862006-09-26 10:52:37 +0200860 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 FIX_STACK(12,nmi_stack_correct, 1)
862 jmp nmi_stack_correct
Chuck Ebberta549b862006-09-26 10:52:37 +0200863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864nmi_debug_stack_check:
Chuck Ebberta549b862006-09-26 10:52:37 +0200865 /* We have a RING0_INT_FRAME here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 cmpw $__KERNEL_CS,16(%esp)
867 jne nmi_stack_correct
Jan Beuliche2718202005-11-13 16:06:52 -0800868 cmpl $debug,(%esp)
869 jb nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 cmpl $debug_esp_fix_insn,(%esp)
Jan Beuliche2718202005-11-13 16:06:52 -0800871 ja nmi_stack_correct
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 FIX_STACK(24,nmi_stack_correct, 1)
873 jmp nmi_stack_correct
874
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100875nmi_espfix_stack:
Chuck Ebberta549b862006-09-26 10:52:37 +0200876 /* We have a RING0_INT_FRAME here.
877 *
878 * create the pointer to lss back
879 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 pushl %ss
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200881 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 pushl %esp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200883 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 addw $4, (%esp)
885 /* copy the iret frame of 12 bytes */
886 .rept 3
887 pushl 16(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200888 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 .endr
890 pushl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 SAVE_ALL
Alexander van Heukelume0c73172008-09-09 21:56:16 +0200893 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 FIXUP_ESPFIX_STACK # %eax == %esp
895 xorl %edx,%edx # zero error code
896 call do_nmi
897 RESTORE_REGS
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100898 lss 12+4(%esp), %esp # back to espfix stack
899 CFI_ADJUST_CFA_OFFSET -24
Ingo Molnar3701d8632008-02-09 23:24:08 +0100900 jmp irq_return
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200901 CFI_ENDPROC
Fernando Luis Vázquez Cao06039752006-09-26 10:52:36 +0200902KPROBE_END(nmi)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Rusty Russelld3561b72006-12-07 02:14:07 +0100904#ifdef CONFIG_PARAVIRT
905ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100906 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100907.section __ex_table,"a"
908 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100909 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100910.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100911END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100912
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400913ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100914 sti
915 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400916END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100917#endif
918
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700919KPROBE_ENTRY(int3)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200920 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 SAVE_ALL
Alexander van Heukeluma7903922008-09-09 21:56:17 +0200924 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 xorl %edx,%edx # zero error code
926 movl %esp,%eax # pt_regs pointer
927 call do_int3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 jmp ret_from_exception
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200929 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200930KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200933 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200935 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 pushl $do_overflow
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(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200943 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200945 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200947 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200949 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100950END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200955 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200957 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200959 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100960END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200965 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200969 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100970END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200973 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200975 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200977 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100978END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200981 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200983 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200985 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100986END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200989 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 pushl $do_stack_segment
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(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
Prasanna S Panchamukhi3d97ae52005-09-06 15:19:27 -0700996KPROBE_ENTRY(general_protection)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200997 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 pushl $do_general_protection
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200999 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001001 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001002KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001005 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001007 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001009 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001010END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001012ENTRY(divide_error)
1013 RING0_INT_FRAME
1014 pushl $0 # no error code
1015 CFI_ADJUST_CFA_OFFSET 4
1016 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001017 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001019 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001020END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022#ifdef CONFIG_X86_MCE
1023ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001024 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001026 CFI_ADJUST_CFA_OFFSET 4
Andi Kleend2f6f7a2008-10-21 22:45:22 +02001027 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001028 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001030 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001031END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032#endif
1033
1034ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001035 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001037 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001039 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001041 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001042END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
Andi Kleen02ba1a32006-09-26 10:52:35 +02001044ENTRY(kernel_thread_helper)
1045 pushl $0 # fake return address for unwinder
1046 CFI_STARTPROC
1047 movl %edx,%eax
1048 push %edx
1049 CFI_ADJUST_CFA_OFFSET 4
1050 call *%ebx
1051 push %eax
1052 CFI_ADJUST_CFA_OFFSET 4
1053 call do_exit
1054 CFI_ENDPROC
1055ENDPROC(kernel_thread_helper)
1056
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001057#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001058/* Xen doesn't set %esp to be precisely what the normal sysenter
1059 entrypoint expects, so fix it up before using the normal path. */
1060ENTRY(xen_sysenter_target)
1061 RING0_INT_FRAME
1062 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001063 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001064 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001065 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001066
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001067ENTRY(xen_hypervisor_callback)
1068 CFI_STARTPROC
1069 pushl $0
1070 CFI_ADJUST_CFA_OFFSET 4
1071 SAVE_ALL
1072 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001073
1074 /* Check to see if we got the event in the critical
1075 region in xen_iret_direct, after we've reenabled
1076 events and checked for pending events. This simulates
1077 iret instruction's behaviour where it delivers a
1078 pending interrupt when enabling interrupts. */
1079 movl PT_EIP(%esp),%eax
1080 cmpl $xen_iret_start_crit,%eax
1081 jb 1f
1082 cmpl $xen_iret_end_crit,%eax
1083 jae 1f
1084
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001085 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001086
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001087ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010881: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001089 call xen_evtchn_do_upcall
1090 jmp ret_from_intr
1091 CFI_ENDPROC
1092ENDPROC(xen_hypervisor_callback)
1093
1094# Hypervisor uses this for application faults while it executes.
1095# We get here for two reasons:
1096# 1. Fault while reloading DS, ES, FS or GS
1097# 2. Fault while executing IRET
1098# Category 1 we fix up by reattempting the load, and zeroing the segment
1099# register if the load fails.
1100# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1101# normal Linux return path in this case because if we use the IRET hypercall
1102# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1103# We distinguish between categories by maintaining a status value in EAX.
1104ENTRY(xen_failsafe_callback)
1105 CFI_STARTPROC
1106 pushl %eax
1107 CFI_ADJUST_CFA_OFFSET 4
1108 movl $1,%eax
11091: mov 4(%esp),%ds
11102: mov 8(%esp),%es
11113: mov 12(%esp),%fs
11124: mov 16(%esp),%gs
1113 testl %eax,%eax
1114 popl %eax
1115 CFI_ADJUST_CFA_OFFSET -4
1116 lea 16(%esp),%esp
1117 CFI_ADJUST_CFA_OFFSET -16
1118 jz 5f
1119 addl $16,%esp
1120 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
11215: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1122 CFI_ADJUST_CFA_OFFSET 4
1123 SAVE_ALL
1124 jmp ret_from_exception
1125 CFI_ENDPROC
1126
1127.section .fixup,"ax"
11286: xorl %eax,%eax
1129 movl %eax,4(%esp)
1130 jmp 1b
11317: xorl %eax,%eax
1132 movl %eax,8(%esp)
1133 jmp 2b
11348: xorl %eax,%eax
1135 movl %eax,12(%esp)
1136 jmp 3b
11379: xorl %eax,%eax
1138 movl %eax,16(%esp)
1139 jmp 4b
1140.previous
1141.section __ex_table,"a"
1142 .align 4
1143 .long 1b,6b
1144 .long 2b,7b
1145 .long 3b,8b
1146 .long 4b,9b
1147.previous
1148ENDPROC(xen_failsafe_callback)
1149
1150#endif /* CONFIG_XEN */
1151
Steven Rostedt606576c2008-10-06 19:06:12 -04001152#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001153#ifdef CONFIG_DYNAMIC_FTRACE
1154
1155ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001156 ret
1157END(mcount)
1158
1159ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001160 cmpl $0, function_trace_stop
1161 jne ftrace_stub
1162
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001163 pushl %eax
1164 pushl %ecx
1165 pushl %edx
1166 movl 0xc(%esp), %eax
1167 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301168 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001169
1170.globl ftrace_call
1171ftrace_call:
1172 call ftrace_stub
1173
1174 popl %edx
1175 popl %ecx
1176 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001177#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1178.globl ftrace_graph_call
1179ftrace_graph_call:
1180 jmp ftrace_stub
1181#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001182
1183.globl ftrace_stub
1184ftrace_stub:
1185 ret
1186END(ftrace_caller)
1187
1188#else /* ! CONFIG_DYNAMIC_FTRACE */
1189
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001190ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001191 cmpl $0, function_trace_stop
1192 jne ftrace_stub
1193
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001194 cmpl $ftrace_stub, ftrace_trace_function
1195 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001196#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001197 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001198 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001199
1200 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1201 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001202#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001203.globl ftrace_stub
1204ftrace_stub:
1205 ret
1206
1207 /* taken from glibc */
1208trace:
1209 pushl %eax
1210 pushl %ecx
1211 pushl %edx
1212 movl 0xc(%esp), %eax
1213 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301214 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001215
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001216 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001217
1218 popl %edx
1219 popl %ecx
1220 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001221 jmp ftrace_stub
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001222END(mcount)
1223#endif /* CONFIG_DYNAMIC_FTRACE */
1224#endif /* CONFIG_FUNCTION_TRACER */
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001225
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001226#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1227ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001228 cmpl $0, function_trace_stop
1229 jne ftrace_stub
1230
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001231 pushl %eax
1232 pushl %ecx
1233 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001234 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001235 lea 0x4(%ebp), %eax
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001236 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001237 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001238 popl %edx
1239 popl %ecx
1240 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001241 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001242END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001243
1244.globl return_to_handler
1245return_to_handler:
1246 pushl $0
1247 pushl %eax
1248 pushl %ecx
1249 pushl %edx
1250 call ftrace_return_to_handler
1251 movl %eax, 0xc(%esp)
1252 popl %edx
1253 popl %ecx
1254 popl %eax
1255 ret
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001256#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001257
Arjan van de Venbb152f52006-01-06 00:12:05 -08001258.section .rodata,"a"
Thomas Gleixner541054d2007-10-11 11:12:00 +02001259#include "syscall_table_32.S"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261syscall_table_size=(.-sys_call_table)