blob: c461925d3b6485721a7b037d2cb28a90ed289fd2 [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
Tejun Heof0d96112009-02-09 22:17:40 +0900104.macro SAVE_ALL
105 cld
106 pushl %fs
107 CFI_ADJUST_CFA_OFFSET 4
108 /*CFI_REL_OFFSET fs, 0;*/
109 pushl %es
110 CFI_ADJUST_CFA_OFFSET 4
111 /*CFI_REL_OFFSET es, 0;*/
112 pushl %ds
113 CFI_ADJUST_CFA_OFFSET 4
114 /*CFI_REL_OFFSET ds, 0;*/
115 pushl %eax
116 CFI_ADJUST_CFA_OFFSET 4
117 CFI_REL_OFFSET eax, 0
118 pushl %ebp
119 CFI_ADJUST_CFA_OFFSET 4
120 CFI_REL_OFFSET ebp, 0
121 pushl %edi
122 CFI_ADJUST_CFA_OFFSET 4
123 CFI_REL_OFFSET edi, 0
124 pushl %esi
125 CFI_ADJUST_CFA_OFFSET 4
126 CFI_REL_OFFSET esi, 0
127 pushl %edx
128 CFI_ADJUST_CFA_OFFSET 4
129 CFI_REL_OFFSET edx, 0
130 pushl %ecx
131 CFI_ADJUST_CFA_OFFSET 4
132 CFI_REL_OFFSET ecx, 0
133 pushl %ebx
134 CFI_ADJUST_CFA_OFFSET 4
135 CFI_REL_OFFSET ebx, 0
136 movl $(__USER_DS), %edx
137 movl %edx, %ds
138 movl %edx, %es
139 movl $(__KERNEL_PERCPU), %edx
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +0100140 movl %edx, %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900141.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Tejun Heof0d96112009-02-09 22:17:40 +0900143.macro RESTORE_INT_REGS
144 popl %ebx
145 CFI_ADJUST_CFA_OFFSET -4
146 CFI_RESTORE ebx
147 popl %ecx
148 CFI_ADJUST_CFA_OFFSET -4
149 CFI_RESTORE ecx
150 popl %edx
151 CFI_ADJUST_CFA_OFFSET -4
152 CFI_RESTORE edx
153 popl %esi
154 CFI_ADJUST_CFA_OFFSET -4
155 CFI_RESTORE esi
156 popl %edi
157 CFI_ADJUST_CFA_OFFSET -4
158 CFI_RESTORE edi
159 popl %ebp
160 CFI_ADJUST_CFA_OFFSET -4
161 CFI_RESTORE ebp
162 popl %eax
163 CFI_ADJUST_CFA_OFFSET -4
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200164 CFI_RESTORE eax
Tejun Heof0d96112009-02-09 22:17:40 +0900165.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Tejun Heof0d96112009-02-09 22:17:40 +0900167.macro RESTORE_REGS
168 RESTORE_INT_REGS
1691: popl %ds
170 CFI_ADJUST_CFA_OFFSET -4
171 /*CFI_RESTORE ds;*/
1722: popl %es
173 CFI_ADJUST_CFA_OFFSET -4
174 /*CFI_RESTORE es;*/
1753: popl %fs
176 CFI_ADJUST_CFA_OFFSET -4
177 /*CFI_RESTORE fs;*/
178.pushsection .fixup, "ax"
1794: movl $0, (%esp)
180 jmp 1b
1815: movl $0, (%esp)
182 jmp 2b
1836: movl $0, (%esp)
184 jmp 3b
185.section __ex_table, "a"
186 .align 4
187 .long 1b, 4b
188 .long 2b, 5b
189 .long 3b, 6b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100190.popsection
Tejun Heof0d96112009-02-09 22:17:40 +0900191.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Tejun Heof0d96112009-02-09 22:17:40 +0900193.macro RING0_INT_FRAME
194 CFI_STARTPROC simple
195 CFI_SIGNAL_FRAME
196 CFI_DEF_CFA esp, 3*4
197 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200198 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900199.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200200
Tejun Heof0d96112009-02-09 22:17:40 +0900201.macro RING0_EC_FRAME
202 CFI_STARTPROC simple
203 CFI_SIGNAL_FRAME
204 CFI_DEF_CFA esp, 4*4
205 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200206 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900207.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200208
Tejun Heof0d96112009-02-09 22:17:40 +0900209.macro RING0_PTREGS_FRAME
210 CFI_STARTPROC simple
211 CFI_SIGNAL_FRAME
212 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
213 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
214 CFI_OFFSET eip, PT_EIP-PT_OLDESP
215 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
216 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
217 CFI_OFFSET eax, PT_EAX-PT_OLDESP
218 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
219 CFI_OFFSET edi, PT_EDI-PT_OLDESP
220 CFI_OFFSET esi, PT_ESI-PT_OLDESP
221 CFI_OFFSET edx, PT_EDX-PT_OLDESP
222 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100223 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Tejun Heof0d96112009-02-09 22:17:40 +0900224.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200227 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 pushl %eax
Markus Armbruster25d7dfd2006-07-30 03:04:08 -0700229 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 call schedule_tail
231 GET_THREAD_INFO(%ebp)
232 popl %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200233 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds47a5c6f2006-09-18 16:20:40 -0700234 pushl $0x0202 # Reset kernel eflags
235 CFI_ADJUST_CFA_OFFSET 4
236 popfl
237 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200239 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100240END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242/*
243 * Return to user mode is not as complex as all this looks,
244 * but we want the default path for a system call return to
245 * go as quickly as possible which is why some of this is
246 * less clear than it otherwise should be.
247 */
248
249 # userspace resumption stub bypassing syscall exit tracing
250 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200251 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100253 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254ret_from_intr:
255 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700256check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100257 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
258 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300259 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200260 cmpl $USER_RPL, %eax
261 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200264 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100265 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 # setting need_resched or sigpending
267 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200268 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 movl TI_flags(%ebp), %ecx
270 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
271 # int/exception return?
272 jne work_pending
273 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100274END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276#ifdef CONFIG_PREEMPT
277ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100278 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
280 jnz restore_nocheck
281need_resched:
282 movl TI_flags(%ebp), %ecx # need_resched set ?
283 testb $_TIF_NEED_RESCHED, %cl
284 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300285 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 jz restore_all
287 call preempt_schedule_irq
288 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100289END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200291 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293/* SYSENTER_RETURN points to after the "sysenter" instruction in
294 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
295
296 # sysenter call handler stub
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100297ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200298 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200299 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200300 CFI_DEF_CFA esp, 0
301 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100302 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700304 /*
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700305 * Interrupts are disabled here, but we can't trace it until
306 * enough kernel state to call TRACE_IRQS_OFF can be called - but
307 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700308 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 pushl $(__USER_DS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200310 CFI_ADJUST_CFA_OFFSET 4
311 /*CFI_REL_OFFSET ss, 0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 pushl %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200313 CFI_ADJUST_CFA_OFFSET 4
314 CFI_REL_OFFSET esp, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 pushfl
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700316 orl $X86_EFLAGS_IF, (%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200317 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 pushl $(__USER_CS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200319 CFI_ADJUST_CFA_OFFSET 4
320 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700321 /*
322 * Push current_thread_info()->sysenter_return to the stack.
323 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
324 * pushed above; +8 corresponds to copy_thread's esp0 setting.
325 */
326 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200327 CFI_ADJUST_CFA_OFFSET 4
328 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700330 pushl %eax
331 CFI_ADJUST_CFA_OFFSET 4
332 SAVE_ALL
333 ENABLE_INTERRUPTS(CLBR_NONE)
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335/*
336 * Load the potential sixth argument from user stack.
337 * Careful about security.
338 */
339 cmpl $__PAGE_OFFSET-3,%ebp
340 jae syscall_fault
3411: movl (%ebp),%ebp
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700342 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343.section __ex_table,"a"
344 .align 4
345 .long 1b,syscall_fault
346.previous
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 GET_THREAD_INFO(%ebp)
349
350 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Roland McGrathd4d67152008-07-09 02:38:07 -0700351 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700352 jnz sysenter_audit
353sysenter_do_call:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 cmpl $(nr_syscalls), %eax
355 jae syscall_badsys
356 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100357 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200358 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200359 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700360 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 movl TI_flags(%ebp), %ecx
362 testw $_TIF_ALLWORK_MASK, %cx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700363 jne sysexit_audit
364sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100366 movl PT_EIP(%esp), %edx
367 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700369 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01003701: mov PT_FS(%esp), %fs
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400371 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700372
373#ifdef CONFIG_AUDITSYSCALL
374sysenter_audit:
375 testw $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
376 jnz syscall_trace_entry
377 addl $4,%esp
378 CFI_ADJUST_CFA_OFFSET -4
379 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
380 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
381 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
382 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
383 movl %eax,%edx /* 2nd arg: syscall number */
384 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
385 call audit_syscall_entry
386 pushl %ebx
387 CFI_ADJUST_CFA_OFFSET 4
388 movl PT_EAX(%esp),%eax /* reload syscall number */
389 jmp sysenter_do_call
390
391sysexit_audit:
392 testw $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %cx
393 jne syscall_exit_work
394 TRACE_IRQS_ON
395 ENABLE_INTERRUPTS(CLBR_ANY)
396 movl %eax,%edx /* second arg, syscall return value */
397 cmpl $0,%eax /* is it < 0? */
398 setl %al /* 1 if so, 0 if not */
399 movzbl %al,%eax /* zero-extend that */
400 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
401 call audit_syscall_exit
402 DISABLE_INTERRUPTS(CLBR_ANY)
403 TRACE_IRQS_OFF
404 movl TI_flags(%ebp), %ecx
405 testw $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %cx
406 jne syscall_exit_work
407 movl PT_EAX(%esp),%eax /* reload syscall return value */
408 jmp sysenter_exit
409#endif
410
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200411 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100412.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004132: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100414 jmp 1b
415.section __ex_table,"a"
416 .align 4
417 .long 1b,2b
418.popsection
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100419ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
421 # system call handler stub
422ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200423 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 pushl %eax # save orig_eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200425 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 SAVE_ALL
427 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700428 # system call tracing in operation / emulation
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
Roland McGrathd4d67152008-07-09 02:38:07 -0700430 testw $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 jnz syscall_trace_entry
432 cmpl $(nr_syscalls), %eax
433 jae syscall_badsys
434syscall_call:
435 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100436 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200438 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100439 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 # setting need_resched or sigpending
441 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700442 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 movl TI_flags(%ebp), %ecx
444 testw $_TIF_ALLWORK_MASK, %cx # current->work
445 jne syscall_exit_work
446
447restore_all:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100448 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
449 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700450 # are returning to the kernel.
451 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100452 movb PT_OLDSS(%esp), %ah
453 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300454 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200455 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200456 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 je ldt_ss # returning to user-space with LDT SS
458restore_nocheck:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700459 TRACE_IRQS_IRET
460restore_nocheck_notrace:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 RESTORE_REGS
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100462 addl $4, %esp # skip orig_eax/error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200463 CFI_ADJUST_CFA_OFFSET -4
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200464irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100465 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700467ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700468 pushl $0 # no error code
469 pushl $do_iret_error
470 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471.previous
472.section __ex_table,"a"
473 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100474 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475.previous
476
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200477 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100479 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 jnz restore_nocheck
481 testl $0x00400000, %eax # returning to 32bit stack?
482 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100483
484#ifdef CONFIG_PARAVIRT
485 /*
486 * The kernel can't run on a non-flat stack if paravirt mode
487 * is active. Rather than try to fixup the high bits of
488 * ESP, bypass this code entirely. This may break DOSemu
489 * and/or Wine support in a paravirt VM, although the option
490 * is still available to implement the setting of the high
491 * 16-bits in the INTERRUPT_RETURN paravirt-op.
492 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700493 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100494 jne restore_nocheck
495#endif
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 /* If returning to userspace with 16bit stack,
498 * try to fix the higher word of ESP, as the CPU
499 * won't restore it.
500 * This is an "official" bug of all the x86-compatible
501 * CPUs, which we can try to work around to make
502 * dosemu and wine happy. */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100503 movl PT_OLDESP(%esp), %eax
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100504 movl %esp, %edx
505 call patch_espfix_desc
506 pushl $__ESPFIX_SS
507 CFI_ADJUST_CFA_OFFSET 4
508 pushl %eax
509 CFI_ADJUST_CFA_OFFSET 4
Rusty Russell139ec7c2006-12-07 02:14:08 +0100510 DISABLE_INTERRUPTS(CLBR_EAX)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700511 TRACE_IRQS_OFF
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100512 lss (%esp), %esp
513 CFI_ADJUST_CFA_OFFSET -8
514 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200515 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100516ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
518 # perform work that needs to be done immediately before resumption
519 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200520 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521work_pending:
522 testb $_TIF_NEED_RESCHED, %cl
523 jz work_notifysig
524work_resched:
525 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200526 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100527 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 # setting need_resched or sigpending
529 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700530 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 movl TI_flags(%ebp), %ecx
532 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
533 # than syscall tracing?
534 jz restore_all
535 testb $_TIF_NEED_RESCHED, %cl
536 jnz work_resched
537
538work_notifysig: # deal with pending signals and
539 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100540#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300541 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 movl %esp, %eax
543 jne work_notifysig_v86 # returning to kernel-space or
544 # vm86-space
545 xorl %edx, %edx
546 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700547 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 ALIGN
550work_notifysig_v86:
551 pushl %ecx # save ti_flags for do_notify_resume
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200552 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 call save_v86_state # %eax contains pt_regs pointer
554 popl %ecx
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200555 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100557#else
558 movl %esp, %eax
559#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 xorl %edx, %edx
561 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700562 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100563END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 # perform syscall exit tracing
566 ALIGN
567syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100568 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700570 call syscall_trace_enter
571 /* What it returned is what we'll actually use. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 cmpl $(nr_syscalls), %eax
573 jnae syscall_call
574 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100575END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 # perform syscall exit tracing
578 ALIGN
579syscall_exit_work:
Roland McGrathd4d67152008-07-09 02:38:07 -0700580 testb $_TIF_WORK_SYSCALL_EXIT, %cl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700582 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700583 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 # schedule() instead
585 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700586 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100588END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200589 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200591 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100594 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100596END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100599 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100601END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200602 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Tejun Heof0d96112009-02-09 22:17:40 +0900604.macro FIXUP_ESPFIX_STACK
605 /* since we are on a wrong stack, we cant make it a C code :( */
606 PER_CPU(gdt_page, %ebx)
607 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
608 addl %esp, %eax
609 pushl $__KERNEL_DS
610 CFI_ADJUST_CFA_OFFSET 4
611 pushl %eax
612 CFI_ADJUST_CFA_OFFSET 4
613 lss (%esp), %esp
614 CFI_ADJUST_CFA_OFFSET -8
615.endm
616.macro UNWIND_ESPFIX_STACK
617 movl %ss, %eax
618 /* see if on espfix stack */
619 cmpw $__ESPFIX_SS, %ax
620 jne 27f
621 movl $__KERNEL_DS, %eax
622 movl %eax, %ds
623 movl %eax, %es
624 /* switch to normal stack */
625 FIXUP_ESPFIX_STACK
62627:
627.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800630 * Build the entry stubs and pointer table with some assembler magic.
631 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
632 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800634.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635ENTRY(interrupt)
636.text
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800637 .p2align 5
638 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200640 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800641vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800642.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
643 .balign 32
644 .rept 7
645 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800646 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200647 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800648 .endif
6491: pushl $(~vector+0x80) /* Note: always in signed byte range */
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200650 CFI_ADJUST_CFA_OFFSET 4
H. Peter Anvin86655962008-11-12 10:27:35 -0800651 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800652 jmp 2f
653 .endif
654 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 .long 1b
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800656 .text
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800658 .endif
659 .endr
6602: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100662END(irq_entries_start)
663
664.previous
665END(interrupt)
666.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Ingo Molnar55f327f2006-07-03 00:24:43 -0700668/*
669 * the CPU automatically disables interrupts when executing an IRQ vector,
670 * so IRQ-flags tracing has to follow that:
671 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800672 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800674 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700676 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 movl %esp,%eax
678 call do_IRQ
679 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100680ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200681 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Tejun Heo02cf94c2009-01-21 17:26:06 +0900683#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200685 RING0_INT_FRAME; \
Rusty Russell19eadf92006-06-27 02:53:44 -0700686 pushl $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200687 CFI_ADJUST_CFA_OFFSET 4; \
688 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700689 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900691 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700692 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100693 CFI_ENDPROC; \
694ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Tejun Heo02cf94c2009-01-21 17:26:06 +0900696#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698/* The include is where all of the SMP etc. interrupts come from */
699#include "entry_arch.h"
700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200702 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200704 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 pushl $do_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200706 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200708 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100709END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200712 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200714 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 pushl $do_simd_coprocessor_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200716 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200718 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100719END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
721ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200722 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 pushl $-1 # mark this as an int
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200724 CFI_ADJUST_CFA_OFFSET 4
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200725 pushl $do_device_not_available
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200726 CFI_ADJUST_CFA_OFFSET 4
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200727 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200728 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100729END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Rusty Russelld3561b72006-12-07 02:14:07 +0100731#ifdef CONFIG_PARAVIRT
732ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100733 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100734.section __ex_table,"a"
735 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100736 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100737.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100738END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100739
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400740ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100741 sti
742 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400743END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100744#endif
745
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200747 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200749 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 pushl $do_overflow
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200751 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200753 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100754END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200757 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200759 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 pushl $do_bounds
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200761 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200763 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100764END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
766ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200767 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200769 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 pushl $do_invalid_op
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200771 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200773 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100774END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200777 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200779 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 pushl $do_coprocessor_segment_overrun
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200781 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200783 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100784END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200787 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 pushl $do_invalid_TSS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200789 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200791 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100792END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200795 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 pushl $do_segment_not_present
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200797 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200799 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100800END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200803 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 pushl $do_stack_segment
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200805 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200807 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100808END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200811 RING0_EC_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 pushl $do_alignment_check
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200813 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200815 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100816END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200818ENTRY(divide_error)
819 RING0_INT_FRAME
820 pushl $0 # no error code
821 CFI_ADJUST_CFA_OFFSET 4
822 pushl $do_divide_error
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200823 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200825 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100826END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828#ifdef CONFIG_X86_MCE
829ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200830 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200832 CFI_ADJUST_CFA_OFFSET 4
Andi Kleend2f6f7a2008-10-21 22:45:22 +0200833 pushl machine_check_vector
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200834 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200836 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100837END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838#endif
839
840ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200841 RING0_INT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 pushl $0
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200843 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 pushl $do_spurious_interrupt_bug
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200845 CFI_ADJUST_CFA_OFFSET 4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200847 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100848END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Andi Kleen02ba1a32006-09-26 10:52:35 +0200850ENTRY(kernel_thread_helper)
851 pushl $0 # fake return address for unwinder
852 CFI_STARTPROC
853 movl %edx,%eax
854 push %edx
855 CFI_ADJUST_CFA_OFFSET 4
856 call *%ebx
857 push %eax
858 CFI_ADJUST_CFA_OFFSET 4
859 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +0800860 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +0200861 CFI_ENDPROC
862ENDPROC(kernel_thread_helper)
863
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700864#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700865/* Xen doesn't set %esp to be precisely what the normal sysenter
866 entrypoint expects, so fix it up before using the normal path. */
867ENTRY(xen_sysenter_target)
868 RING0_INT_FRAME
869 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +0100870 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700871 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -0300872 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700873
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700874ENTRY(xen_hypervisor_callback)
875 CFI_STARTPROC
876 pushl $0
877 CFI_ADJUST_CFA_OFFSET 4
878 SAVE_ALL
879 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -0700880
881 /* Check to see if we got the event in the critical
882 region in xen_iret_direct, after we've reenabled
883 events and checked for pending events. This simulates
884 iret instruction's behaviour where it delivers a
885 pending interrupt when enabling interrupts. */
886 movl PT_EIP(%esp),%eax
887 cmpl $xen_iret_start_crit,%eax
888 jb 1f
889 cmpl $xen_iret_end_crit,%eax
890 jae 1f
891
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -0700892 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -0700893
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -0700894ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -07008951: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -0700896 call xen_evtchn_do_upcall
897 jmp ret_from_intr
898 CFI_ENDPROC
899ENDPROC(xen_hypervisor_callback)
900
901# Hypervisor uses this for application faults while it executes.
902# We get here for two reasons:
903# 1. Fault while reloading DS, ES, FS or GS
904# 2. Fault while executing IRET
905# Category 1 we fix up by reattempting the load, and zeroing the segment
906# register if the load fails.
907# Category 2 we fix up by jumping to do_iret_error. We cannot use the
908# normal Linux return path in this case because if we use the IRET hypercall
909# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
910# We distinguish between categories by maintaining a status value in EAX.
911ENTRY(xen_failsafe_callback)
912 CFI_STARTPROC
913 pushl %eax
914 CFI_ADJUST_CFA_OFFSET 4
915 movl $1,%eax
9161: mov 4(%esp),%ds
9172: mov 8(%esp),%es
9183: mov 12(%esp),%fs
9194: mov 16(%esp),%gs
920 testl %eax,%eax
921 popl %eax
922 CFI_ADJUST_CFA_OFFSET -4
923 lea 16(%esp),%esp
924 CFI_ADJUST_CFA_OFFSET -16
925 jz 5f
926 addl $16,%esp
927 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
9285: pushl $0 # EAX == 0 => Category 1 (Bad segment)
929 CFI_ADJUST_CFA_OFFSET 4
930 SAVE_ALL
931 jmp ret_from_exception
932 CFI_ENDPROC
933
934.section .fixup,"ax"
9356: xorl %eax,%eax
936 movl %eax,4(%esp)
937 jmp 1b
9387: xorl %eax,%eax
939 movl %eax,8(%esp)
940 jmp 2b
9418: xorl %eax,%eax
942 movl %eax,12(%esp)
943 jmp 3b
9449: xorl %eax,%eax
945 movl %eax,16(%esp)
946 jmp 4b
947.previous
948.section __ex_table,"a"
949 .align 4
950 .long 1b,6b
951 .long 2b,7b
952 .long 3b,8b
953 .long 4b,9b
954.previous
955ENDPROC(xen_failsafe_callback)
956
957#endif /* CONFIG_XEN */
958
Steven Rostedt606576c2008-10-06 19:06:12 -0400959#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200960#ifdef CONFIG_DYNAMIC_FTRACE
961
962ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200963 ret
964END(mcount)
965
966ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -0500967 cmpl $0, function_trace_stop
968 jne ftrace_stub
969
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200970 pushl %eax
971 pushl %ecx
972 pushl %edx
973 movl 0xc(%esp), %eax
974 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +0530975 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200976
977.globl ftrace_call
978ftrace_call:
979 call ftrace_stub
980
981 popl %edx
982 popl %ecx
983 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -0500984#ifdef CONFIG_FUNCTION_GRAPH_TRACER
985.globl ftrace_graph_call
986ftrace_graph_call:
987 jmp ftrace_stub
988#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200989
990.globl ftrace_stub
991ftrace_stub:
992 ret
993END(ftrace_caller)
994
995#else /* ! CONFIG_DYNAMIC_FTRACE */
996
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200997ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -0500998 cmpl $0, function_trace_stop
999 jne ftrace_stub
1000
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001001 cmpl $ftrace_stub, ftrace_trace_function
1002 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001003#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001004 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001005 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001006
1007 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1008 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001009#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001010.globl ftrace_stub
1011ftrace_stub:
1012 ret
1013
1014 /* taken from glibc */
1015trace:
1016 pushl %eax
1017 pushl %ecx
1018 pushl %edx
1019 movl 0xc(%esp), %eax
1020 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301021 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001022
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001023 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001024
1025 popl %edx
1026 popl %ecx
1027 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001028 jmp ftrace_stub
1029END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001030#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001031#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001032
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001033#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1034ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001035 cmpl $0, function_trace_stop
1036 jne ftrace_stub
1037
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001038 pushl %eax
1039 pushl %ecx
1040 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001041 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001042 lea 0x4(%ebp), %eax
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001043 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001044 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001045 popl %edx
1046 popl %ecx
1047 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001048 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001049END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001050
1051.globl return_to_handler
1052return_to_handler:
1053 pushl $0
1054 pushl %eax
1055 pushl %ecx
1056 pushl %edx
1057 call ftrace_return_to_handler
1058 movl %eax, 0xc(%esp)
1059 popl %edx
1060 popl %ecx
1061 popl %eax
1062 ret
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001063#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065.section .rodata,"a"
1066#include "syscall_table_32.S"
1067
1068syscall_table_size=(.-sys_call_table)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001069
1070/*
1071 * Some functions should be protected against kprobes
1072 */
1073 .pushsection .kprobes.text, "ax"
1074
1075ENTRY(page_fault)
1076 RING0_EC_FRAME
1077 pushl $do_page_fault
1078 CFI_ADJUST_CFA_OFFSET 4
1079 ALIGN
1080error_code:
1081 /* the function address is in %fs's slot on the stack */
1082 pushl %es
1083 CFI_ADJUST_CFA_OFFSET 4
1084 /*CFI_REL_OFFSET es, 0*/
1085 pushl %ds
1086 CFI_ADJUST_CFA_OFFSET 4
1087 /*CFI_REL_OFFSET ds, 0*/
1088 pushl %eax
1089 CFI_ADJUST_CFA_OFFSET 4
1090 CFI_REL_OFFSET eax, 0
1091 pushl %ebp
1092 CFI_ADJUST_CFA_OFFSET 4
1093 CFI_REL_OFFSET ebp, 0
1094 pushl %edi
1095 CFI_ADJUST_CFA_OFFSET 4
1096 CFI_REL_OFFSET edi, 0
1097 pushl %esi
1098 CFI_ADJUST_CFA_OFFSET 4
1099 CFI_REL_OFFSET esi, 0
1100 pushl %edx
1101 CFI_ADJUST_CFA_OFFSET 4
1102 CFI_REL_OFFSET edx, 0
1103 pushl %ecx
1104 CFI_ADJUST_CFA_OFFSET 4
1105 CFI_REL_OFFSET ecx, 0
1106 pushl %ebx
1107 CFI_ADJUST_CFA_OFFSET 4
1108 CFI_REL_OFFSET ebx, 0
1109 cld
1110 pushl %fs
1111 CFI_ADJUST_CFA_OFFSET 4
1112 /*CFI_REL_OFFSET fs, 0*/
1113 movl $(__KERNEL_PERCPU), %ecx
1114 movl %ecx, %fs
1115 UNWIND_ESPFIX_STACK
1116 popl %ecx
1117 CFI_ADJUST_CFA_OFFSET -4
1118 /*CFI_REGISTER es, ecx*/
1119 movl PT_FS(%esp), %edi # get the function address
1120 movl PT_ORIG_EAX(%esp), %edx # get the error code
1121 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
1122 mov %ecx, PT_FS(%esp)
1123 /*CFI_REL_OFFSET fs, ES*/
1124 movl $(__USER_DS), %ecx
1125 movl %ecx, %ds
1126 movl %ecx, %es
1127 TRACE_IRQS_OFF
1128 movl %esp,%eax # pt_regs pointer
1129 call *%edi
1130 jmp ret_from_exception
1131 CFI_ENDPROC
1132END(page_fault)
1133
1134/*
1135 * Debug traps and NMI can happen at the one SYSENTER instruction
1136 * that sets up the real kernel stack. Check here, since we can't
1137 * allow the wrong stack to be used.
1138 *
1139 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1140 * already pushed 3 words if it hits on the sysenter instruction:
1141 * eflags, cs and eip.
1142 *
1143 * We just load the right stack, and push the three (known) values
1144 * by hand onto the new stack - while updating the return eip past
1145 * the instruction that would have done it for sysenter.
1146 */
Tejun Heof0d96112009-02-09 22:17:40 +09001147.macro FIX_STACK offset ok label
1148 cmpw $__KERNEL_CS, 4(%esp)
1149 jne \ok
1150\label:
1151 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1152 CFI_DEF_CFA esp, 0
1153 CFI_UNDEFINED eip
1154 pushfl
1155 CFI_ADJUST_CFA_OFFSET 4
1156 pushl $__KERNEL_CS
1157 CFI_ADJUST_CFA_OFFSET 4
1158 pushl $sysenter_past_esp
1159 CFI_ADJUST_CFA_OFFSET 4
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001160 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001161.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001162
1163ENTRY(debug)
1164 RING0_INT_FRAME
1165 cmpl $ia32_sysenter_target,(%esp)
1166 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001167 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001168debug_stack_correct:
1169 pushl $-1 # mark this as an int
1170 CFI_ADJUST_CFA_OFFSET 4
1171 SAVE_ALL
1172 TRACE_IRQS_OFF
1173 xorl %edx,%edx # error code 0
1174 movl %esp,%eax # pt_regs pointer
1175 call do_debug
1176 jmp ret_from_exception
1177 CFI_ENDPROC
1178END(debug)
1179
1180/*
1181 * NMI is doubly nasty. It can happen _while_ we're handling
1182 * a debug fault, and the debug fault hasn't yet been able to
1183 * clear up the stack. So we first check whether we got an
1184 * NMI on the sysenter entry path, but after that we need to
1185 * check whether we got an NMI on the debug path where the debug
1186 * fault happened on the sysenter path.
1187 */
1188ENTRY(nmi)
1189 RING0_INT_FRAME
1190 pushl %eax
1191 CFI_ADJUST_CFA_OFFSET 4
1192 movl %ss, %eax
1193 cmpw $__ESPFIX_SS, %ax
1194 popl %eax
1195 CFI_ADJUST_CFA_OFFSET -4
1196 je nmi_espfix_stack
1197 cmpl $ia32_sysenter_target,(%esp)
1198 je nmi_stack_fixup
1199 pushl %eax
1200 CFI_ADJUST_CFA_OFFSET 4
1201 movl %esp,%eax
1202 /* Do not access memory above the end of our stack page,
1203 * it might not exist.
1204 */
1205 andl $(THREAD_SIZE-1),%eax
1206 cmpl $(THREAD_SIZE-20),%eax
1207 popl %eax
1208 CFI_ADJUST_CFA_OFFSET -4
1209 jae nmi_stack_correct
1210 cmpl $ia32_sysenter_target,12(%esp)
1211 je nmi_debug_stack_check
1212nmi_stack_correct:
1213 /* We have a RING0_INT_FRAME here */
1214 pushl %eax
1215 CFI_ADJUST_CFA_OFFSET 4
1216 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001217 xorl %edx,%edx # zero error code
1218 movl %esp,%eax # pt_regs pointer
1219 call do_nmi
1220 jmp restore_nocheck_notrace
1221 CFI_ENDPROC
1222
1223nmi_stack_fixup:
1224 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001225 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001226 jmp nmi_stack_correct
1227
1228nmi_debug_stack_check:
1229 /* We have a RING0_INT_FRAME here */
1230 cmpw $__KERNEL_CS,16(%esp)
1231 jne nmi_stack_correct
1232 cmpl $debug,(%esp)
1233 jb nmi_stack_correct
1234 cmpl $debug_esp_fix_insn,(%esp)
1235 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001236 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001237 jmp nmi_stack_correct
1238
1239nmi_espfix_stack:
1240 /* We have a RING0_INT_FRAME here.
1241 *
1242 * create the pointer to lss back
1243 */
1244 pushl %ss
1245 CFI_ADJUST_CFA_OFFSET 4
1246 pushl %esp
1247 CFI_ADJUST_CFA_OFFSET 4
1248 addw $4, (%esp)
1249 /* copy the iret frame of 12 bytes */
1250 .rept 3
1251 pushl 16(%esp)
1252 CFI_ADJUST_CFA_OFFSET 4
1253 .endr
1254 pushl %eax
1255 CFI_ADJUST_CFA_OFFSET 4
1256 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001257 FIXUP_ESPFIX_STACK # %eax == %esp
1258 xorl %edx,%edx # zero error code
1259 call do_nmi
1260 RESTORE_REGS
1261 lss 12+4(%esp), %esp # back to espfix stack
1262 CFI_ADJUST_CFA_OFFSET -24
1263 jmp irq_return
1264 CFI_ENDPROC
1265END(nmi)
1266
1267ENTRY(int3)
1268 RING0_INT_FRAME
1269 pushl $-1 # mark this as an int
1270 CFI_ADJUST_CFA_OFFSET 4
1271 SAVE_ALL
1272 TRACE_IRQS_OFF
1273 xorl %edx,%edx # zero error code
1274 movl %esp,%eax # pt_regs pointer
1275 call do_int3
1276 jmp ret_from_exception
1277 CFI_ENDPROC
1278END(int3)
1279
1280ENTRY(general_protection)
1281 RING0_EC_FRAME
1282 pushl $do_general_protection
1283 CFI_ADJUST_CFA_OFFSET 4
1284 jmp error_code
1285 CFI_ENDPROC
1286END(general_protection)
1287
1288/*
1289 * End of kprobes section
1290 */
1291 .popsection