blob: 22d0e21b4dd793fa509e52541bf9b57e7778d1d7 [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
Tejun Heoccbeed32009-02-09 22:17:40 +090033 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
34 * 2C(%esp) - orig_eax
35 * 30(%esp) - %eip
36 * 34(%esp) - %cs
37 * 38(%esp) - %eflags
38 * 3C(%esp) - %oldesp
39 * 40(%esp) - %oldss
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/linkage.h>
45#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070046#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/errno.h>
48#include <asm/segment.h>
49#include <asm/smp.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -080050#include <asm/page_types.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>
Brian Gerst40d2e762010-03-21 09:00:43 -040056#include <asm/cpufeature.h>
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -040057#include <asm/alternative-asm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Roland McGrathaf0575b2008-06-24 04:16:52 -070059/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
60#include <linux/elf-em.h>
61#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
62#define __AUDIT_ARCH_LE 0x40000000
63
64#ifndef CONFIG_AUDITSYSCALL
65#define sysenter_audit syscall_trace_entry
66#define sysexit_audit syscall_exit_work
67#endif
68
Jiri Olsaea714542011-03-07 19:10:39 +010069 .section .entry.text, "ax"
70
Rusty Russell139ec7c2006-12-07 02:14:08 +010071/*
72 * We use macros for low-level operations which need to be overridden
73 * for paravirtualization. The following will never clobber any registers:
74 * INTERRUPT_RETURN (aka. "iret")
75 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -040076 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010077 *
78 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
79 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
80 * Allowing a register to be clobbered can shrink the paravirt replacement
81 * enough to patch inline, increasing performance.
82 */
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define nr_syscalls ((syscall_table_size)/4)
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#ifdef CONFIG_PREEMPT
Rusty Russell139ec7c2006-12-07 02:14:08 +010087#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#else
Rusty Russell139ec7c2006-12-07 02:14:08 +010089#define preempt_stop(clobbers)
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +020090#define resume_kernel restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#endif
92
Ingo Molnar55f327f2006-07-03 00:24:43 -070093.macro TRACE_IRQS_IRET
94#ifdef CONFIG_TRACE_IRQFLAGS
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030095 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070096 jz 1f
97 TRACE_IRQS_ON
981:
99#endif
100.endm
101
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700102#ifdef CONFIG_VM86
103#define resume_userspace_sig check_userspace
104#else
105#define resume_userspace_sig resume_userspace
106#endif
107
Tejun Heoccbeed32009-02-09 22:17:40 +0900108/*
109 * User gs save/restore
110 *
111 * %gs is used for userland TLS and kernel only uses it for stack
112 * canary which is required to be at %gs:20 by gcc. Read the comment
113 * at the top of stackprotector.h for more info.
114 *
115 * Local labels 98 and 99 are used.
116 */
117#ifdef CONFIG_X86_32_LAZY_GS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Tejun Heoccbeed32009-02-09 22:17:40 +0900119 /* unfortunately push/pop can't be no-op */
120.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100121 pushl_cfi $0
Tejun Heoccbeed32009-02-09 22:17:40 +0900122.endm
123.macro POP_GS pop=0
124 addl $(4 + \pop), %esp
125 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
126.endm
127.macro POP_GS_EX
128.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Tejun Heoccbeed32009-02-09 22:17:40 +0900130 /* all the rest are no-op */
131.macro PTGS_TO_GS
132.endm
133.macro PTGS_TO_GS_EX
134.endm
135.macro GS_TO_REG reg
136.endm
137.macro REG_TO_PTGS reg
138.endm
139.macro SET_KERNEL_GS reg
140.endm
141
142#else /* CONFIG_X86_32_LAZY_GS */
143
144.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100145 pushl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900146 /*CFI_REL_OFFSET gs, 0*/
147.endm
148
149.macro POP_GS pop=0
Jan Beulichdf5d1872010-09-02 14:07:16 +010015098: popl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900151 /*CFI_RESTORE gs*/
152 .if \pop <> 0
153 add $\pop, %esp
154 CFI_ADJUST_CFA_OFFSET -\pop
155 .endif
156.endm
157.macro POP_GS_EX
158.pushsection .fixup, "ax"
15999: movl $0, (%esp)
160 jmp 98b
161.section __ex_table, "a"
162 .align 4
163 .long 98b, 99b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100164.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900165.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Tejun Heoccbeed32009-02-09 22:17:40 +0900167.macro PTGS_TO_GS
16898: mov PT_GS(%esp), %gs
169.endm
170.macro PTGS_TO_GS_EX
171.pushsection .fixup, "ax"
17299: movl $0, PT_GS(%esp)
173 jmp 98b
174.section __ex_table, "a"
175 .align 4
176 .long 98b, 99b
177.popsection
178.endm
179
180.macro GS_TO_REG reg
181 movl %gs, \reg
182 /*CFI_REGISTER gs, \reg*/
183.endm
184.macro REG_TO_PTGS reg
185 movl \reg, PT_GS(%esp)
186 /*CFI_REL_OFFSET gs, PT_GS*/
187.endm
188.macro SET_KERNEL_GS reg
Tejun Heo60a53172009-02-09 22:17:40 +0900189 movl $(__KERNEL_STACK_CANARY), \reg
Tejun Heoccbeed32009-02-09 22:17:40 +0900190 movl \reg, %gs
191.endm
192
193#endif /* CONFIG_X86_32_LAZY_GS */
194
Tejun Heof0d96112009-02-09 22:17:40 +0900195.macro SAVE_ALL
196 cld
Tejun Heoccbeed32009-02-09 22:17:40 +0900197 PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100198 pushl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900199 /*CFI_REL_OFFSET fs, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100200 pushl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900201 /*CFI_REL_OFFSET es, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100202 pushl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900203 /*CFI_REL_OFFSET ds, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100204 pushl_cfi %eax
Tejun Heof0d96112009-02-09 22:17:40 +0900205 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100206 pushl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900207 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100208 pushl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900209 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100210 pushl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900211 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100212 pushl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900213 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100214 pushl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900215 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100216 pushl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900217 CFI_REL_OFFSET ebx, 0
218 movl $(__USER_DS), %edx
219 movl %edx, %ds
220 movl %edx, %es
221 movl $(__KERNEL_PERCPU), %edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 movl %edx, %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900223 SET_KERNEL_GS %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900224.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Tejun Heof0d96112009-02-09 22:17:40 +0900226.macro RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100227 popl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900228 CFI_RESTORE ebx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100229 popl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900230 CFI_RESTORE ecx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100231 popl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900232 CFI_RESTORE edx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100233 popl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900234 CFI_RESTORE esi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100235 popl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900236 CFI_RESTORE edi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100237 popl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900238 CFI_RESTORE ebp
Jan Beulichdf5d1872010-09-02 14:07:16 +0100239 popl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 CFI_RESTORE eax
Tejun Heof0d96112009-02-09 22:17:40 +0900241.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Tejun Heoccbeed32009-02-09 22:17:40 +0900243.macro RESTORE_REGS pop=0
Tejun Heof0d96112009-02-09 22:17:40 +0900244 RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +01002451: popl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900246 /*CFI_RESTORE ds;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002472: popl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900248 /*CFI_RESTORE es;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002493: popl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900250 /*CFI_RESTORE fs;*/
Tejun Heoccbeed32009-02-09 22:17:40 +0900251 POP_GS \pop
Tejun Heof0d96112009-02-09 22:17:40 +0900252.pushsection .fixup, "ax"
2534: movl $0, (%esp)
254 jmp 1b
2555: movl $0, (%esp)
256 jmp 2b
2576: movl $0, (%esp)
258 jmp 3b
259.section __ex_table, "a"
260 .align 4
261 .long 1b, 4b
262 .long 2b, 5b
263 .long 3b, 6b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900265 POP_GS_EX
Tejun Heof0d96112009-02-09 22:17:40 +0900266.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Tejun Heof0d96112009-02-09 22:17:40 +0900268.macro RING0_INT_FRAME
269 CFI_STARTPROC simple
270 CFI_SIGNAL_FRAME
271 CFI_DEF_CFA esp, 3*4
272 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200273 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900274.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200275
Tejun Heof0d96112009-02-09 22:17:40 +0900276.macro RING0_EC_FRAME
277 CFI_STARTPROC simple
278 CFI_SIGNAL_FRAME
279 CFI_DEF_CFA esp, 4*4
280 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200281 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900282.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200283
Tejun Heof0d96112009-02-09 22:17:40 +0900284.macro RING0_PTREGS_FRAME
285 CFI_STARTPROC simple
286 CFI_SIGNAL_FRAME
287 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
288 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
289 CFI_OFFSET eip, PT_EIP-PT_OLDESP
290 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
291 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
292 CFI_OFFSET eax, PT_EAX-PT_OLDESP
293 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
294 CFI_OFFSET edi, PT_EDI-PT_OLDESP
295 CFI_OFFSET esi, PT_ESI-PT_OLDESP
296 CFI_OFFSET edx, PT_EDX-PT_OLDESP
297 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100298 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Tejun Heof0d96112009-02-09 22:17:40 +0900299.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
301ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200302 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +0100303 pushl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 call schedule_tail
305 GET_THREAD_INFO(%ebp)
Jan Beulichdf5d1872010-09-02 14:07:16 +0100306 popl_cfi %eax
307 pushl_cfi $0x0202 # Reset kernel eflags
308 popfl_cfi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200310 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100311END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313/*
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400314 * Interrupt exit functions should be protected against kprobes
315 */
316 .pushsection .kprobes.text, "ax"
317/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 * Return to user mode is not as complex as all this looks,
319 * but we want the default path for a system call return to
320 * go as quickly as possible which is why some of this is
321 * less clear than it otherwise should be.
322 */
323
324 # userspace resumption stub bypassing syscall exit tracing
325 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200326 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100328 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329ret_from_intr:
330 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700331check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100332 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
333 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300334 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200335 cmpl $USER_RPL, %eax
336 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200339 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100340 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 # setting need_resched or sigpending
342 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200343 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 movl TI_flags(%ebp), %ecx
345 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
346 # int/exception return?
347 jne work_pending
348 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100349END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351#ifdef CONFIG_PREEMPT
352ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100353 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200355 jnz restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356need_resched:
357 movl TI_flags(%ebp), %ecx # need_resched set ?
358 testb $_TIF_NEED_RESCHED, %cl
359 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300360 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 jz restore_all
362 call preempt_schedule_irq
363 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100364END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200366 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400367/*
368 * End of kprobes section
369 */
370 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
372/* SYSENTER_RETURN points to after the "sysenter" instruction in
373 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
374
375 # sysenter call handler stub
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100376ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200377 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200378 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200379 CFI_DEF_CFA esp, 0
380 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100381 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700383 /*
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700384 * Interrupts are disabled here, but we can't trace it until
385 * enough kernel state to call TRACE_IRQS_OFF can be called - but
386 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700387 */
Jan Beulich32342822010-10-19 14:52:26 +0100388 pushl_cfi $__USER_DS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200389 /*CFI_REL_OFFSET ss, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100390 pushl_cfi %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200391 CFI_REL_OFFSET esp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100392 pushfl_cfi
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700393 orl $X86_EFLAGS_IF, (%esp)
Jan Beulich32342822010-10-19 14:52:26 +0100394 pushl_cfi $__USER_CS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200395 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700396 /*
397 * Push current_thread_info()->sysenter_return to the stack.
398 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
399 * pushed above; +8 corresponds to copy_thread's esp0 setting.
400 */
Stratos Psomadakis7bf04be2011-02-25 22:46:13 +0200401 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200402 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Jan Beulichdf5d1872010-09-02 14:07:16 +0100404 pushl_cfi %eax
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700405 SAVE_ALL
406 ENABLE_INTERRUPTS(CLBR_NONE)
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408/*
409 * Load the potential sixth argument from user stack.
410 * Careful about security.
411 */
412 cmpl $__PAGE_OFFSET-3,%ebp
413 jae syscall_fault
4141: movl (%ebp),%ebp
Jeremy Fitzhardinged93c870b2008-03-24 16:43:21 -0700415 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416.section __ex_table,"a"
417 .align 4
418 .long 1b,syscall_fault
419.previous
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 GET_THREAD_INFO(%ebp)
422
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530423 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700424 jnz sysenter_audit
425sysenter_do_call:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 cmpl $(nr_syscalls), %eax
427 jae syscall_badsys
428 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100429 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200430 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200431 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700432 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530434 testl $_TIF_ALLWORK_MASK, %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700435 jne sysexit_audit
436sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100438 movl PT_EIP(%esp), %edx
439 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700441 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004421: mov PT_FS(%esp), %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900443 PTGS_TO_GS
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400444 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700445
446#ifdef CONFIG_AUDITSYSCALL
447sysenter_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530448 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700449 jnz syscall_trace_entry
450 addl $4,%esp
451 CFI_ADJUST_CFA_OFFSET -4
452 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
453 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
454 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
455 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
456 movl %eax,%edx /* 2nd arg: syscall number */
457 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
458 call audit_syscall_entry
Jan Beulichdf5d1872010-09-02 14:07:16 +0100459 pushl_cfi %ebx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700460 movl PT_EAX(%esp),%eax /* reload syscall number */
461 jmp sysenter_do_call
462
463sysexit_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530464 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700465 jne syscall_exit_work
466 TRACE_IRQS_ON
467 ENABLE_INTERRUPTS(CLBR_ANY)
468 movl %eax,%edx /* second arg, syscall return value */
469 cmpl $0,%eax /* is it < 0? */
470 setl %al /* 1 if so, 0 if not */
471 movzbl %al,%eax /* zero-extend that */
472 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
473 call audit_syscall_exit
474 DISABLE_INTERRUPTS(CLBR_ANY)
475 TRACE_IRQS_OFF
476 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530477 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700478 jne syscall_exit_work
479 movl PT_EAX(%esp),%eax /* reload syscall return value */
480 jmp sysenter_exit
481#endif
482
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200483 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100484.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004852: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100486 jmp 1b
487.section __ex_table,"a"
488 .align 4
489 .long 1b,2b
490.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900491 PTGS_TO_GS_EX
Roland McGrath0aa97fb222008-01-30 13:30:43 +0100492ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400494/*
495 * syscall stub including irq exit should be protected against kprobes
496 */
497 .pushsection .kprobes.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 # system call handler stub
499ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200500 RING0_INT_FRAME # can't unwind into user space anyway
Jan Beulichdf5d1872010-09-02 14:07:16 +0100501 pushl_cfi %eax # save orig_eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 SAVE_ALL
503 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700504 # system call tracing in operation / emulation
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530505 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 jnz syscall_trace_entry
507 cmpl $(nr_syscalls), %eax
508 jae syscall_badsys
509syscall_call:
510 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100511 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200513 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100514 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 # setting need_resched or sigpending
516 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700517 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530519 testl $_TIF_ALLWORK_MASK, %ecx # current->work
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 jne syscall_exit_work
521
522restore_all:
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200523 TRACE_IRQS_IRET
524restore_all_notrace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100525 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
526 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700527 # are returning to the kernel.
528 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100529 movb PT_OLDSS(%esp), %ah
530 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300531 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200532 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200533 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 je ldt_ss # returning to user-space with LDT SS
535restore_nocheck:
Tejun Heoccbeed32009-02-09 22:17:40 +0900536 RESTORE_REGS 4 # skip orig_eax/error_code
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200537irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100538 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700540ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700541 pushl $0 # no error code
542 pushl $do_iret_error
543 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544.previous
545.section __ex_table,"a"
546 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100547 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548.previous
549
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200550 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100552 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 jnz restore_nocheck
554 testl $0x00400000, %eax # returning to 32bit stack?
555 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100556
557#ifdef CONFIG_PARAVIRT
558 /*
559 * The kernel can't run on a non-flat stack if paravirt mode
560 * is active. Rather than try to fixup the high bits of
561 * ESP, bypass this code entirely. This may break DOSemu
562 * and/or Wine support in a paravirt VM, although the option
563 * is still available to implement the setting of the high
564 * 16-bits in the INTERRUPT_RETURN paravirt-op.
565 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700566 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100567 jne restore_nocheck
568#endif
569
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200570/*
571 * Setup and switch to ESPFIX stack
572 *
573 * We're returning to userspace with a 16 bit stack. The CPU will not
574 * restore the high word of ESP for us on executing iret... This is an
575 * "official" bug of all the x86-compatible CPUs, which we can work
576 * around to make dosemu and wine happy. We do this by preloading the
577 * high word of ESP with the high word of the userspace ESP while
578 * compensating for the offset by changing to the ESPFIX segment with
579 * a base address that matches for the difference.
580 */
Brian Gerst72c511d2010-07-31 12:48:23 -0400581#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200582 mov %esp, %edx /* load kernel esp */
583 mov PT_OLDESP(%esp), %eax /* load userspace esp */
584 mov %dx, %ax /* eax: new kernel esp */
585 sub %eax, %edx /* offset (low word is 0) */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200586 shr $16, %edx
Brian Gerst72c511d2010-07-31 12:48:23 -0400587 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
588 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100589 pushl_cfi $__ESPFIX_SS
590 pushl_cfi %eax /* new kernel esp */
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200591 /* Disable interrupts, but do not irqtrace this section: we
592 * will soon execute iret and the tracer was already set to
593 * the irqstate after the iret */
Rusty Russell139ec7c2006-12-07 02:14:08 +0100594 DISABLE_INTERRUPTS(CLBR_EAX)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200595 lss (%esp), %esp /* switch to espfix segment */
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100596 CFI_ADJUST_CFA_OFFSET -8
597 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200598 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100599ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 # perform work that needs to be done immediately before resumption
602 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200603 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604work_pending:
605 testb $_TIF_NEED_RESCHED, %cl
606 jz work_notifysig
607work_resched:
608 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200609 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100610 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 # setting need_resched or sigpending
612 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700613 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 movl TI_flags(%ebp), %ecx
615 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
616 # than syscall tracing?
617 jz restore_all
618 testb $_TIF_NEED_RESCHED, %cl
619 jnz work_resched
620
621work_notifysig: # deal with pending signals and
622 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100623#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300624 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 movl %esp, %eax
626 jne work_notifysig_v86 # returning to kernel-space or
627 # vm86-space
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530628 TRACE_IRQS_ON
629 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 xorl %edx, %edx
631 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700632 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 ALIGN
635work_notifysig_v86:
Jan Beulichdf5d1872010-09-02 14:07:16 +0100636 pushl_cfi %ecx # save ti_flags for do_notify_resume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 call save_v86_state # %eax contains pt_regs pointer
Jan Beulichdf5d1872010-09-02 14:07:16 +0100638 popl_cfi %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100640#else
641 movl %esp, %eax
642#endif
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530643 TRACE_IRQS_ON
644 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 xorl %edx, %edx
646 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700647 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100648END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
650 # perform syscall exit tracing
651 ALIGN
652syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100653 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700655 call syscall_trace_enter
656 /* What it returned is what we'll actually use. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 cmpl $(nr_syscalls), %eax
658 jnae syscall_call
659 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100660END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
662 # perform syscall exit tracing
663 ALIGN
664syscall_exit_work:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530665 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700667 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700668 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 # schedule() instead
670 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700671 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100673END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200674 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200676 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100679 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100681END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100684 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100686END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200687 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400688/*
689 * End of kprobes section
690 */
691 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Brian Gerst253f29a2009-02-10 09:51:46 -0500693/*
694 * System calls that need a pt_regs pointer.
695 */
Brian Gerste258e4e2009-12-09 19:01:51 -0500696#define PTREGSCALL0(name) \
Brian Gerst253f29a2009-02-10 09:51:46 -0500697 ALIGN; \
698ptregs_##name: \
699 leal 4(%esp),%eax; \
700 jmp sys_##name;
701
Brian Gerste258e4e2009-12-09 19:01:51 -0500702#define PTREGSCALL1(name) \
703 ALIGN; \
704ptregs_##name: \
705 leal 4(%esp),%edx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800706 movl (PT_EBX+4)(%esp),%eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500707 jmp sys_##name;
708
709#define PTREGSCALL2(name) \
710 ALIGN; \
711ptregs_##name: \
712 leal 4(%esp),%ecx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800713 movl (PT_ECX+4)(%esp),%edx; \
714 movl (PT_EBX+4)(%esp),%eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500715 jmp sys_##name;
716
717#define PTREGSCALL3(name) \
718 ALIGN; \
719ptregs_##name: \
Jan Beulicha34107b2010-09-02 14:04:16 +0100720 CFI_STARTPROC; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500721 leal 4(%esp),%eax; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100722 pushl_cfi %eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500723 movl PT_EDX(%eax),%ecx; \
724 movl PT_ECX(%eax),%edx; \
725 movl PT_EBX(%eax),%eax; \
726 call sys_##name; \
727 addl $4,%esp; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100728 CFI_ADJUST_CFA_OFFSET -4; \
729 ret; \
730 CFI_ENDPROC; \
731ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500732
Brian Gerst27f59552009-12-09 19:01:52 -0500733PTREGSCALL1(iopl)
Brian Gerste258e4e2009-12-09 19:01:51 -0500734PTREGSCALL0(fork)
Brian Gerste258e4e2009-12-09 19:01:51 -0500735PTREGSCALL0(vfork)
Brian Gerst11cf88b2009-12-09 19:01:53 -0500736PTREGSCALL3(execve)
Brian Gerst052acad2009-12-09 19:01:54 -0500737PTREGSCALL2(sigaltstack)
Brian Gerste258e4e2009-12-09 19:01:51 -0500738PTREGSCALL0(sigreturn)
739PTREGSCALL0(rt_sigreturn)
Brian Gerstf1382f12009-12-09 19:01:55 -0500740PTREGSCALL2(vm86)
741PTREGSCALL1(vm86old)
Brian Gerst253f29a2009-02-10 09:51:46 -0500742
Brian Gerstf839bbc2009-12-09 19:01:56 -0500743/* Clone is an oddball. The 4th arg is in %edi */
744 ALIGN;
745ptregs_clone:
Jan Beulicha34107b2010-09-02 14:04:16 +0100746 CFI_STARTPROC
Brian Gerstf839bbc2009-12-09 19:01:56 -0500747 leal 4(%esp),%eax
Jan Beulicha34107b2010-09-02 14:04:16 +0100748 pushl_cfi %eax
749 pushl_cfi PT_EDI(%eax)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500750 movl PT_EDX(%eax),%ecx
751 movl PT_ECX(%eax),%edx
752 movl PT_EBX(%eax),%eax
753 call sys_clone
754 addl $8,%esp
Jan Beulicha34107b2010-09-02 14:04:16 +0100755 CFI_ADJUST_CFA_OFFSET -8
Brian Gerstf839bbc2009-12-09 19:01:56 -0500756 ret
Jan Beulicha34107b2010-09-02 14:04:16 +0100757 CFI_ENDPROC
758ENDPROC(ptregs_clone)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500759
Tejun Heof0d96112009-02-09 22:17:40 +0900760.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200761/*
762 * Switch back for ESPFIX stack to the normal zerobased stack
763 *
764 * We can't call C functions using the ESPFIX stack. This code reads
765 * the high word of the segment base from the GDT and swiches to the
766 * normal stack and adjusts ESP with the matching offset.
767 */
768 /* fixup the stack */
Brian Gerst72c511d2010-07-31 12:48:23 -0400769 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
770 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200771 shl $16, %eax
772 addl %esp, %eax /* the adjusted stack pointer */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100773 pushl_cfi $__KERNEL_DS
774 pushl_cfi %eax
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200775 lss (%esp), %esp /* switch to the normal stack segment */
Tejun Heof0d96112009-02-09 22:17:40 +0900776 CFI_ADJUST_CFA_OFFSET -8
777.endm
778.macro UNWIND_ESPFIX_STACK
779 movl %ss, %eax
780 /* see if on espfix stack */
781 cmpw $__ESPFIX_SS, %ax
782 jne 27f
783 movl $__KERNEL_DS, %eax
784 movl %eax, %ds
785 movl %eax, %es
786 /* switch to normal stack */
787 FIXUP_ESPFIX_STACK
78827:
789.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800792 * Build the entry stubs and pointer table with some assembler magic.
793 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
794 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800796.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797ENTRY(interrupt)
Jiri Olsaea714542011-03-07 19:10:39 +0100798.section .entry.text, "ax"
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800799 .p2align 5
800 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200802 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800803vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800804.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
805 .balign 32
806 .rept 7
807 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800808 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200809 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800810 .endif
Jan Beulichdf5d1872010-09-02 14:07:16 +01008111: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
H. Peter Anvin86655962008-11-12 10:27:35 -0800812 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800813 jmp 2f
814 .endif
815 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 .long 1b
Jiri Olsaea714542011-03-07 19:10:39 +0100817 .section .entry.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800819 .endif
820 .endr
8212: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100823END(irq_entries_start)
824
825.previous
826END(interrupt)
827.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Ingo Molnar55f327f2006-07-03 00:24:43 -0700829/*
830 * the CPU automatically disables interrupts when executing an IRQ vector,
831 * so IRQ-flags tracing has to follow that:
832 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800833 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800835 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700837 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 movl %esp,%eax
839 call do_IRQ
840 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100841ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200842 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400844/*
845 * Irq entries should be protected against kprobes
846 */
847 .pushsection .kprobes.text, "ax"
Tejun Heo02cf94c2009-01-21 17:26:06 +0900848#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200850 RING0_INT_FRAME; \
Jan Beulichdf5d1872010-09-02 14:07:16 +0100851 pushl_cfi $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200852 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700853 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900855 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700856 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100857 CFI_ENDPROC; \
858ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Tejun Heo02cf94c2009-01-21 17:26:06 +0900860#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100863#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200866 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100867 pushl_cfi $0
868 pushl_cfi $do_coprocessor_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200870 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100871END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200874 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100875 pushl_cfi $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400876#ifdef CONFIG_X86_INVD_BUG
877 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100878661: pushl_cfi $do_general_protection
Brian Gerst40d2e762010-03-21 09:00:43 -0400879662:
880.section .altinstructions,"a"
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -0400881 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
Brian Gerst40d2e762010-03-21 09:00:43 -0400882.previous
883.section .altinstr_replacement,"ax"
884663: pushl $do_simd_coprocessor_error
885664:
886.previous
887#else
Jan Beulichdf5d1872010-09-02 14:07:16 +0100888 pushl_cfi $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400889#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100892END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200895 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100896 pushl_cfi $-1 # mark this as an int
897 pushl_cfi $do_device_not_available
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200898 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200899 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100900END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Rusty Russelld3561b72006-12-07 02:14:07 +0100902#ifdef CONFIG_PARAVIRT
903ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100904 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100905.section __ex_table,"a"
906 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100907 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100908.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100909END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100910
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400911ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100912 sti
913 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400914END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100915#endif
916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200918 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100919 pushl_cfi $0
920 pushl_cfi $do_overflow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100923END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200926 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100927 pushl_cfi $0
928 pushl_cfi $do_bounds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200930 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100931END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200934 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100935 pushl_cfi $0
936 pushl_cfi $do_invalid_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200938 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100939END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200942 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100943 pushl_cfi $0
944 pushl_cfi $do_coprocessor_segment_overrun
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200946 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100947END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200950 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100951 pushl_cfi $do_invalid_TSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100954END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200957 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100958 pushl_cfi $do_segment_not_present
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200960 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100961END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200964 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100965 pushl_cfi $do_stack_segment
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100968END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200971 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100972 pushl_cfi $do_alignment_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200974 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100975END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200977ENTRY(divide_error)
978 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100979 pushl_cfi $0 # no error code
980 pushl_cfi $do_divide_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200982 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100983END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985#ifdef CONFIG_X86_MCE
986ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200987 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100988 pushl_cfi $0
989 pushl_cfi machine_check_vector
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200991 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100992END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993#endif
994
995ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200996 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100997 pushl_cfi $0
998 pushl_cfi $do_spurious_interrupt_bug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001000 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001001END(spurious_interrupt_bug)
Masami Hiramatsua00e8172009-09-08 12:47:55 -04001002/*
1003 * End of kprobes section
1004 */
1005 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Andi Kleen02ba1a32006-09-26 10:52:35 +02001007ENTRY(kernel_thread_helper)
1008 pushl $0 # fake return address for unwinder
1009 CFI_STARTPROC
Brian Gerste8402272009-12-09 12:34:42 -05001010 movl %edi,%eax
1011 call *%esi
Andi Kleen02ba1a32006-09-26 10:52:35 +02001012 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001013 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +02001014 CFI_ENDPROC
1015ENDPROC(kernel_thread_helper)
1016
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001017#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001018/* Xen doesn't set %esp to be precisely what the normal sysenter
1019 entrypoint expects, so fix it up before using the normal path. */
1020ENTRY(xen_sysenter_target)
1021 RING0_INT_FRAME
1022 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001023 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001024 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001025 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001026
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001027ENTRY(xen_hypervisor_callback)
1028 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001029 pushl_cfi $0
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001030 SAVE_ALL
1031 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001032
1033 /* Check to see if we got the event in the critical
1034 region in xen_iret_direct, after we've reenabled
1035 events and checked for pending events. This simulates
1036 iret instruction's behaviour where it delivers a
1037 pending interrupt when enabling interrupts. */
1038 movl PT_EIP(%esp),%eax
1039 cmpl $xen_iret_start_crit,%eax
1040 jb 1f
1041 cmpl $xen_iret_end_crit,%eax
1042 jae 1f
1043
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001044 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001045
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001046ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010471: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001048 call xen_evtchn_do_upcall
1049 jmp ret_from_intr
1050 CFI_ENDPROC
1051ENDPROC(xen_hypervisor_callback)
1052
1053# Hypervisor uses this for application faults while it executes.
1054# We get here for two reasons:
1055# 1. Fault while reloading DS, ES, FS or GS
1056# 2. Fault while executing IRET
1057# Category 1 we fix up by reattempting the load, and zeroing the segment
1058# register if the load fails.
1059# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1060# normal Linux return path in this case because if we use the IRET hypercall
1061# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1062# We distinguish between categories by maintaining a status value in EAX.
1063ENTRY(xen_failsafe_callback)
1064 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001065 pushl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001066 movl $1,%eax
10671: mov 4(%esp),%ds
10682: mov 8(%esp),%es
10693: mov 12(%esp),%fs
10704: mov 16(%esp),%gs
1071 testl %eax,%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001072 popl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001073 lea 16(%esp),%esp
1074 CFI_ADJUST_CFA_OFFSET -16
1075 jz 5f
1076 addl $16,%esp
1077 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
Jan Beulichdf5d1872010-09-02 14:07:16 +010010785: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001079 SAVE_ALL
1080 jmp ret_from_exception
1081 CFI_ENDPROC
1082
1083.section .fixup,"ax"
10846: xorl %eax,%eax
1085 movl %eax,4(%esp)
1086 jmp 1b
10877: xorl %eax,%eax
1088 movl %eax,8(%esp)
1089 jmp 2b
10908: xorl %eax,%eax
1091 movl %eax,12(%esp)
1092 jmp 3b
10939: xorl %eax,%eax
1094 movl %eax,16(%esp)
1095 jmp 4b
1096.previous
1097.section __ex_table,"a"
1098 .align 4
1099 .long 1b,6b
1100 .long 2b,7b
1101 .long 3b,8b
1102 .long 4b,9b
1103.previous
1104ENDPROC(xen_failsafe_callback)
1105
Sheng Yang38e20b02010-05-14 12:40:51 +01001106BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1107 xen_evtchn_do_upcall)
1108
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001109#endif /* CONFIG_XEN */
1110
Steven Rostedt606576c2008-10-06 19:06:12 -04001111#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001112#ifdef CONFIG_DYNAMIC_FTRACE
1113
1114ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001115 ret
1116END(mcount)
1117
1118ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001119 cmpl $0, function_trace_stop
1120 jne ftrace_stub
1121
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001122 pushl %eax
1123 pushl %ecx
1124 pushl %edx
1125 movl 0xc(%esp), %eax
1126 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301127 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001128
1129.globl ftrace_call
1130ftrace_call:
1131 call ftrace_stub
1132
1133 popl %edx
1134 popl %ecx
1135 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001136#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1137.globl ftrace_graph_call
1138ftrace_graph_call:
1139 jmp ftrace_stub
1140#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001141
1142.globl ftrace_stub
1143ftrace_stub:
1144 ret
1145END(ftrace_caller)
1146
1147#else /* ! CONFIG_DYNAMIC_FTRACE */
1148
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001149ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001150 cmpl $0, function_trace_stop
1151 jne ftrace_stub
1152
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001153 cmpl $ftrace_stub, ftrace_trace_function
1154 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001155#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001156 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001157 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001158
1159 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1160 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001161#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001162.globl ftrace_stub
1163ftrace_stub:
1164 ret
1165
1166 /* taken from glibc */
1167trace:
1168 pushl %eax
1169 pushl %ecx
1170 pushl %edx
1171 movl 0xc(%esp), %eax
1172 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301173 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001174
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001175 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001176
1177 popl %edx
1178 popl %ecx
1179 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001180 jmp ftrace_stub
1181END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001182#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001183#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001184
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001185#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1186ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001187 cmpl $0, function_trace_stop
1188 jne ftrace_stub
1189
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001190 pushl %eax
1191 pushl %ecx
1192 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001193 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001194 lea 0x4(%ebp), %eax
Steven Rostedt71e308a2009-06-18 12:45:08 -04001195 movl (%ebp), %ecx
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001196 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001197 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001198 popl %edx
1199 popl %ecx
1200 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001201 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001202END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001203
1204.globl return_to_handler
1205return_to_handler:
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001206 pushl %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001207 pushl %edx
Steven Rostedt71e308a2009-06-18 12:45:08 -04001208 movl %ebp, %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001209 call ftrace_return_to_handler
Steven Rostedt194ec342009-10-13 16:33:50 -04001210 movl %eax, %ecx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001211 popl %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001212 popl %eax
Steven Rostedt194ec342009-10-13 16:33:50 -04001213 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001214#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216.section .rodata,"a"
1217#include "syscall_table_32.S"
1218
1219syscall_table_size=(.-sys_call_table)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001220
1221/*
1222 * Some functions should be protected against kprobes
1223 */
1224 .pushsection .kprobes.text, "ax"
1225
1226ENTRY(page_fault)
1227 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001228 pushl_cfi $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001229 ALIGN
1230error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001231 /* the function address is in %gs's slot on the stack */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001232 pushl_cfi %fs
Tejun Heoccbeed32009-02-09 22:17:40 +09001233 /*CFI_REL_OFFSET fs, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001234 pushl_cfi %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001235 /*CFI_REL_OFFSET es, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001236 pushl_cfi %ds
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001237 /*CFI_REL_OFFSET ds, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001238 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001239 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001240 pushl_cfi %ebp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001241 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001242 pushl_cfi %edi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001243 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001244 pushl_cfi %esi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001245 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001246 pushl_cfi %edx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001247 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001248 pushl_cfi %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001249 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001250 pushl_cfi %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001251 CFI_REL_OFFSET ebx, 0
1252 cld
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001253 movl $(__KERNEL_PERCPU), %ecx
1254 movl %ecx, %fs
1255 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001256 GS_TO_REG %ecx
1257 movl PT_GS(%esp), %edi # get the function address
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001258 movl PT_ORIG_EAX(%esp), %edx # get the error code
1259 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001260 REG_TO_PTGS %ecx
1261 SET_KERNEL_GS %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001262 movl $(__USER_DS), %ecx
1263 movl %ecx, %ds
1264 movl %ecx, %es
1265 TRACE_IRQS_OFF
1266 movl %esp,%eax # pt_regs pointer
1267 call *%edi
1268 jmp ret_from_exception
1269 CFI_ENDPROC
1270END(page_fault)
1271
1272/*
1273 * Debug traps and NMI can happen at the one SYSENTER instruction
1274 * that sets up the real kernel stack. Check here, since we can't
1275 * allow the wrong stack to be used.
1276 *
1277 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1278 * already pushed 3 words if it hits on the sysenter instruction:
1279 * eflags, cs and eip.
1280 *
1281 * We just load the right stack, and push the three (known) values
1282 * by hand onto the new stack - while updating the return eip past
1283 * the instruction that would have done it for sysenter.
1284 */
Tejun Heof0d96112009-02-09 22:17:40 +09001285.macro FIX_STACK offset ok label
1286 cmpw $__KERNEL_CS, 4(%esp)
1287 jne \ok
1288\label:
1289 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1290 CFI_DEF_CFA esp, 0
1291 CFI_UNDEFINED eip
Jan Beulichdf5d1872010-09-02 14:07:16 +01001292 pushfl_cfi
1293 pushl_cfi $__KERNEL_CS
1294 pushl_cfi $sysenter_past_esp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001295 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001296.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001297
1298ENTRY(debug)
1299 RING0_INT_FRAME
1300 cmpl $ia32_sysenter_target,(%esp)
1301 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001302 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001303debug_stack_correct:
Jan Beulichdf5d1872010-09-02 14:07:16 +01001304 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001305 SAVE_ALL
1306 TRACE_IRQS_OFF
1307 xorl %edx,%edx # error code 0
1308 movl %esp,%eax # pt_regs pointer
1309 call do_debug
1310 jmp ret_from_exception
1311 CFI_ENDPROC
1312END(debug)
1313
1314/*
1315 * NMI is doubly nasty. It can happen _while_ we're handling
1316 * a debug fault, and the debug fault hasn't yet been able to
1317 * clear up the stack. So we first check whether we got an
1318 * NMI on the sysenter entry path, but after that we need to
1319 * check whether we got an NMI on the debug path where the debug
1320 * fault happened on the sysenter path.
1321 */
1322ENTRY(nmi)
1323 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001324 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001325 movl %ss, %eax
1326 cmpw $__ESPFIX_SS, %ax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001327 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001328 je nmi_espfix_stack
1329 cmpl $ia32_sysenter_target,(%esp)
1330 je nmi_stack_fixup
Jan Beulichdf5d1872010-09-02 14:07:16 +01001331 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001332 movl %esp,%eax
1333 /* Do not access memory above the end of our stack page,
1334 * it might not exist.
1335 */
1336 andl $(THREAD_SIZE-1),%eax
1337 cmpl $(THREAD_SIZE-20),%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001338 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001339 jae nmi_stack_correct
1340 cmpl $ia32_sysenter_target,12(%esp)
1341 je nmi_debug_stack_check
1342nmi_stack_correct:
1343 /* We have a RING0_INT_FRAME here */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001344 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001345 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001346 xorl %edx,%edx # zero error code
1347 movl %esp,%eax # pt_regs pointer
1348 call do_nmi
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +02001349 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001350 CFI_ENDPROC
1351
1352nmi_stack_fixup:
1353 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001354 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001355 jmp nmi_stack_correct
1356
1357nmi_debug_stack_check:
1358 /* We have a RING0_INT_FRAME here */
1359 cmpw $__KERNEL_CS,16(%esp)
1360 jne nmi_stack_correct
1361 cmpl $debug,(%esp)
1362 jb nmi_stack_correct
1363 cmpl $debug_esp_fix_insn,(%esp)
1364 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001365 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001366 jmp nmi_stack_correct
1367
1368nmi_espfix_stack:
1369 /* We have a RING0_INT_FRAME here.
1370 *
1371 * create the pointer to lss back
1372 */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001373 pushl_cfi %ss
1374 pushl_cfi %esp
Stas Sergeevbda3a892009-02-23 19:13:07 +03001375 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001376 /* copy the iret frame of 12 bytes */
1377 .rept 3
Jan Beulichdf5d1872010-09-02 14:07:16 +01001378 pushl_cfi 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001379 .endr
Jan Beulichdf5d1872010-09-02 14:07:16 +01001380 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001381 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001382 FIXUP_ESPFIX_STACK # %eax == %esp
1383 xorl %edx,%edx # zero error code
1384 call do_nmi
1385 RESTORE_REGS
1386 lss 12+4(%esp), %esp # back to espfix stack
1387 CFI_ADJUST_CFA_OFFSET -24
1388 jmp irq_return
1389 CFI_ENDPROC
1390END(nmi)
1391
1392ENTRY(int3)
1393 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001394 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001395 SAVE_ALL
1396 TRACE_IRQS_OFF
1397 xorl %edx,%edx # zero error code
1398 movl %esp,%eax # pt_regs pointer
1399 call do_int3
1400 jmp ret_from_exception
1401 CFI_ENDPROC
1402END(int3)
1403
1404ENTRY(general_protection)
1405 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001406 pushl_cfi $do_general_protection
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001407 jmp error_code
1408 CFI_ENDPROC
1409END(general_protection)
1410
Gleb Natapov631bc482010-10-14 11:22:52 +02001411#ifdef CONFIG_KVM_GUEST
1412ENTRY(async_page_fault)
1413 RING0_EC_FRAME
Jan Beulich60cf6372011-02-28 15:54:40 +00001414 pushl_cfi $do_async_page_fault
Gleb Natapov631bc482010-10-14 11:22:52 +02001415 jmp error_code
1416 CFI_ENDPROC
Sedat Dilek2ae9d292011-03-08 22:39:24 +01001417END(async_page_fault)
Gleb Natapov631bc482010-10-14 11:22:52 +02001418#endif
1419
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001420/*
1421 * End of kprobes section
1422 */
1423 .popsection