blob: f3f6f5344001ee47b17eb0ff029179751dfd5171 [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 McGrath0aa97fb2008-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 Fitzhardinged93c8702008-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 Fitzhardinged93c8702008-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 Fitzhardinged93c8702008-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 Fitzhardinged93c8702008-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 McGrath0aa97fb2008-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
628 xorl %edx, %edx
629 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700630 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 ALIGN
633work_notifysig_v86:
Jan Beulichdf5d1872010-09-02 14:07:16 +0100634 pushl_cfi %ecx # save ti_flags for do_notify_resume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 call save_v86_state # %eax contains pt_regs pointer
Jan Beulichdf5d1872010-09-02 14:07:16 +0100636 popl_cfi %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100638#else
639 movl %esp, %eax
640#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 xorl %edx, %edx
642 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700643 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100644END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 # perform syscall exit tracing
647 ALIGN
648syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100649 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700651 call syscall_trace_enter
652 /* What it returned is what we'll actually use. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 cmpl $(nr_syscalls), %eax
654 jnae syscall_call
655 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100656END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 # perform syscall exit tracing
659 ALIGN
660syscall_exit_work:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530661 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700663 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700664 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 # schedule() instead
666 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700667 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100669END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200670 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200672 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100675 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100677END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100680 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100682END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200683 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400684/*
685 * End of kprobes section
686 */
687 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Brian Gerst253f29a2009-02-10 09:51:46 -0500689/*
690 * System calls that need a pt_regs pointer.
691 */
Brian Gerste258e4e2009-12-09 19:01:51 -0500692#define PTREGSCALL0(name) \
Brian Gerst253f29a2009-02-10 09:51:46 -0500693 ALIGN; \
694ptregs_##name: \
695 leal 4(%esp),%eax; \
696 jmp sys_##name;
697
Brian Gerste258e4e2009-12-09 19:01:51 -0500698#define PTREGSCALL1(name) \
699 ALIGN; \
700ptregs_##name: \
701 leal 4(%esp),%edx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800702 movl (PT_EBX+4)(%esp),%eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500703 jmp sys_##name;
704
705#define PTREGSCALL2(name) \
706 ALIGN; \
707ptregs_##name: \
708 leal 4(%esp),%ecx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800709 movl (PT_ECX+4)(%esp),%edx; \
710 movl (PT_EBX+4)(%esp),%eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500711 jmp sys_##name;
712
713#define PTREGSCALL3(name) \
714 ALIGN; \
715ptregs_##name: \
Jan Beulicha34107b2010-09-02 14:04:16 +0100716 CFI_STARTPROC; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500717 leal 4(%esp),%eax; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100718 pushl_cfi %eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500719 movl PT_EDX(%eax),%ecx; \
720 movl PT_ECX(%eax),%edx; \
721 movl PT_EBX(%eax),%eax; \
722 call sys_##name; \
723 addl $4,%esp; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100724 CFI_ADJUST_CFA_OFFSET -4; \
725 ret; \
726 CFI_ENDPROC; \
727ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500728
Brian Gerst27f59552009-12-09 19:01:52 -0500729PTREGSCALL1(iopl)
Brian Gerste258e4e2009-12-09 19:01:51 -0500730PTREGSCALL0(fork)
Brian Gerste258e4e2009-12-09 19:01:51 -0500731PTREGSCALL0(vfork)
Brian Gerst11cf88b2009-12-09 19:01:53 -0500732PTREGSCALL3(execve)
Brian Gerst052acad2009-12-09 19:01:54 -0500733PTREGSCALL2(sigaltstack)
Brian Gerste258e4e2009-12-09 19:01:51 -0500734PTREGSCALL0(sigreturn)
735PTREGSCALL0(rt_sigreturn)
Brian Gerstf1382f12009-12-09 19:01:55 -0500736PTREGSCALL2(vm86)
737PTREGSCALL1(vm86old)
Brian Gerst253f29a2009-02-10 09:51:46 -0500738
Brian Gerstf839bbc2009-12-09 19:01:56 -0500739/* Clone is an oddball. The 4th arg is in %edi */
740 ALIGN;
741ptregs_clone:
Jan Beulicha34107b2010-09-02 14:04:16 +0100742 CFI_STARTPROC
Brian Gerstf839bbc2009-12-09 19:01:56 -0500743 leal 4(%esp),%eax
Jan Beulicha34107b2010-09-02 14:04:16 +0100744 pushl_cfi %eax
745 pushl_cfi PT_EDI(%eax)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500746 movl PT_EDX(%eax),%ecx
747 movl PT_ECX(%eax),%edx
748 movl PT_EBX(%eax),%eax
749 call sys_clone
750 addl $8,%esp
Jan Beulicha34107b2010-09-02 14:04:16 +0100751 CFI_ADJUST_CFA_OFFSET -8
Brian Gerstf839bbc2009-12-09 19:01:56 -0500752 ret
Jan Beulicha34107b2010-09-02 14:04:16 +0100753 CFI_ENDPROC
754ENDPROC(ptregs_clone)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500755
Tejun Heof0d96112009-02-09 22:17:40 +0900756.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200757/*
758 * Switch back for ESPFIX stack to the normal zerobased stack
759 *
760 * We can't call C functions using the ESPFIX stack. This code reads
761 * the high word of the segment base from the GDT and swiches to the
762 * normal stack and adjusts ESP with the matching offset.
763 */
764 /* fixup the stack */
Brian Gerst72c511d2010-07-31 12:48:23 -0400765 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
766 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200767 shl $16, %eax
768 addl %esp, %eax /* the adjusted stack pointer */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100769 pushl_cfi $__KERNEL_DS
770 pushl_cfi %eax
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200771 lss (%esp), %esp /* switch to the normal stack segment */
Tejun Heof0d96112009-02-09 22:17:40 +0900772 CFI_ADJUST_CFA_OFFSET -8
773.endm
774.macro UNWIND_ESPFIX_STACK
775 movl %ss, %eax
776 /* see if on espfix stack */
777 cmpw $__ESPFIX_SS, %ax
778 jne 27f
779 movl $__KERNEL_DS, %eax
780 movl %eax, %ds
781 movl %eax, %es
782 /* switch to normal stack */
783 FIXUP_ESPFIX_STACK
78427:
785.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800788 * Build the entry stubs and pointer table with some assembler magic.
789 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
790 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800792.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793ENTRY(interrupt)
Jiri Olsaea714542011-03-07 19:10:39 +0100794.section .entry.text, "ax"
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800795 .p2align 5
796 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200798 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800799vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800800.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
801 .balign 32
802 .rept 7
803 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800804 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200805 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800806 .endif
Jan Beulichdf5d1872010-09-02 14:07:16 +01008071: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
H. Peter Anvin86655962008-11-12 10:27:35 -0800808 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800809 jmp 2f
810 .endif
811 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .long 1b
Jiri Olsaea714542011-03-07 19:10:39 +0100813 .section .entry.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800815 .endif
816 .endr
8172: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100819END(irq_entries_start)
820
821.previous
822END(interrupt)
823.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Ingo Molnar55f327f2006-07-03 00:24:43 -0700825/*
826 * the CPU automatically disables interrupts when executing an IRQ vector,
827 * so IRQ-flags tracing has to follow that:
828 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800829 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800831 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700833 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 movl %esp,%eax
835 call do_IRQ
836 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100837ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200838 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400840/*
841 * Irq entries should be protected against kprobes
842 */
843 .pushsection .kprobes.text, "ax"
Tejun Heo02cf94c2009-01-21 17:26:06 +0900844#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200846 RING0_INT_FRAME; \
Jan Beulichdf5d1872010-09-02 14:07:16 +0100847 pushl_cfi $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200848 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700849 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900851 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700852 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100853 CFI_ENDPROC; \
854ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Tejun Heo02cf94c2009-01-21 17:26:06 +0900856#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100859#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200862 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100863 pushl_cfi $0
864 pushl_cfi $do_coprocessor_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200866 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100867END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200870 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100871 pushl_cfi $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400872#ifdef CONFIG_X86_INVD_BUG
873 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100874661: pushl_cfi $do_general_protection
Brian Gerst40d2e762010-03-21 09:00:43 -0400875662:
876.section .altinstructions,"a"
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -0400877 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
Brian Gerst40d2e762010-03-21 09:00:43 -0400878.previous
879.section .altinstr_replacement,"ax"
880663: pushl $do_simd_coprocessor_error
881664:
882.previous
883#else
Jan Beulichdf5d1872010-09-02 14:07:16 +0100884 pushl_cfi $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400885#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200887 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100888END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100892 pushl_cfi $-1 # mark this as an int
893 pushl_cfi $do_device_not_available
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200894 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200895 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100896END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Rusty Russelld3561b72006-12-07 02:14:07 +0100898#ifdef CONFIG_PARAVIRT
899ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100900 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100901.section __ex_table,"a"
902 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100903 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100904.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100905END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100906
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400907ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100908 sti
909 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400910END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100911#endif
912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200914 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100915 pushl_cfi $0
916 pushl_cfi $do_overflow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200918 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100919END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100923 pushl_cfi $0
924 pushl_cfi $do_bounds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200926 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100927END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200930 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100931 pushl_cfi $0
932 pushl_cfi $do_invalid_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200934 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100935END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200938 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100939 pushl_cfi $0
940 pushl_cfi $do_coprocessor_segment_overrun
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200942 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100943END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200946 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100947 pushl_cfi $do_invalid_TSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200949 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100950END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100954 pushl_cfi $do_segment_not_present
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200956 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100957END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200960 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100961 pushl_cfi $do_stack_segment
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100964END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100968 pushl_cfi $do_alignment_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200970 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100971END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200973ENTRY(divide_error)
974 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100975 pushl_cfi $0 # no error code
976 pushl_cfi $do_divide_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200978 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100979END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981#ifdef CONFIG_X86_MCE
982ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200983 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100984 pushl_cfi $0
985 pushl_cfi machine_check_vector
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200987 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100988END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989#endif
990
991ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200992 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100993 pushl_cfi $0
994 pushl_cfi $do_spurious_interrupt_bug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200996 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100997END(spurious_interrupt_bug)
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400998/*
999 * End of kprobes section
1000 */
1001 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Andi Kleen02ba1a32006-09-26 10:52:35 +02001003ENTRY(kernel_thread_helper)
1004 pushl $0 # fake return address for unwinder
1005 CFI_STARTPROC
Brian Gerste8402272009-12-09 12:34:42 -05001006 movl %edi,%eax
1007 call *%esi
Andi Kleen02ba1a32006-09-26 10:52:35 +02001008 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001009 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +02001010 CFI_ENDPROC
1011ENDPROC(kernel_thread_helper)
1012
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001013#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001014/* Xen doesn't set %esp to be precisely what the normal sysenter
1015 entrypoint expects, so fix it up before using the normal path. */
1016ENTRY(xen_sysenter_target)
1017 RING0_INT_FRAME
1018 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001019 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001020 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001021 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001022
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001023ENTRY(xen_hypervisor_callback)
1024 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001025 pushl_cfi $0
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001026 SAVE_ALL
1027 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001028
1029 /* Check to see if we got the event in the critical
1030 region in xen_iret_direct, after we've reenabled
1031 events and checked for pending events. This simulates
1032 iret instruction's behaviour where it delivers a
1033 pending interrupt when enabling interrupts. */
1034 movl PT_EIP(%esp),%eax
1035 cmpl $xen_iret_start_crit,%eax
1036 jb 1f
1037 cmpl $xen_iret_end_crit,%eax
1038 jae 1f
1039
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001040 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001041
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001042ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010431: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001044 call xen_evtchn_do_upcall
1045 jmp ret_from_intr
1046 CFI_ENDPROC
1047ENDPROC(xen_hypervisor_callback)
1048
1049# Hypervisor uses this for application faults while it executes.
1050# We get here for two reasons:
1051# 1. Fault while reloading DS, ES, FS or GS
1052# 2. Fault while executing IRET
1053# Category 1 we fix up by reattempting the load, and zeroing the segment
1054# register if the load fails.
1055# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1056# normal Linux return path in this case because if we use the IRET hypercall
1057# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1058# We distinguish between categories by maintaining a status value in EAX.
1059ENTRY(xen_failsafe_callback)
1060 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001061 pushl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001062 movl $1,%eax
10631: mov 4(%esp),%ds
10642: mov 8(%esp),%es
10653: mov 12(%esp),%fs
10664: mov 16(%esp),%gs
1067 testl %eax,%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001068 popl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001069 lea 16(%esp),%esp
1070 CFI_ADJUST_CFA_OFFSET -16
1071 jz 5f
1072 addl $16,%esp
1073 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
Jan Beulichdf5d1872010-09-02 14:07:16 +010010745: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001075 SAVE_ALL
1076 jmp ret_from_exception
1077 CFI_ENDPROC
1078
1079.section .fixup,"ax"
10806: xorl %eax,%eax
1081 movl %eax,4(%esp)
1082 jmp 1b
10837: xorl %eax,%eax
1084 movl %eax,8(%esp)
1085 jmp 2b
10868: xorl %eax,%eax
1087 movl %eax,12(%esp)
1088 jmp 3b
10899: xorl %eax,%eax
1090 movl %eax,16(%esp)
1091 jmp 4b
1092.previous
1093.section __ex_table,"a"
1094 .align 4
1095 .long 1b,6b
1096 .long 2b,7b
1097 .long 3b,8b
1098 .long 4b,9b
1099.previous
1100ENDPROC(xen_failsafe_callback)
1101
Sheng Yang38e20b02010-05-14 12:40:51 +01001102BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1103 xen_evtchn_do_upcall)
1104
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001105#endif /* CONFIG_XEN */
1106
Steven Rostedt606576c2008-10-06 19:06:12 -04001107#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001108#ifdef CONFIG_DYNAMIC_FTRACE
1109
1110ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001111 ret
1112END(mcount)
1113
1114ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001115 cmpl $0, function_trace_stop
1116 jne ftrace_stub
1117
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001118 pushl %eax
1119 pushl %ecx
1120 pushl %edx
1121 movl 0xc(%esp), %eax
1122 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301123 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001124
1125.globl ftrace_call
1126ftrace_call:
1127 call ftrace_stub
1128
1129 popl %edx
1130 popl %ecx
1131 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001132#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1133.globl ftrace_graph_call
1134ftrace_graph_call:
1135 jmp ftrace_stub
1136#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001137
1138.globl ftrace_stub
1139ftrace_stub:
1140 ret
1141END(ftrace_caller)
1142
1143#else /* ! CONFIG_DYNAMIC_FTRACE */
1144
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001145ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001146 cmpl $0, function_trace_stop
1147 jne ftrace_stub
1148
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001149 cmpl $ftrace_stub, ftrace_trace_function
1150 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001151#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001152 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001153 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001154
1155 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1156 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001157#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001158.globl ftrace_stub
1159ftrace_stub:
1160 ret
1161
1162 /* taken from glibc */
1163trace:
1164 pushl %eax
1165 pushl %ecx
1166 pushl %edx
1167 movl 0xc(%esp), %eax
1168 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301169 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001170
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001171 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001172
1173 popl %edx
1174 popl %ecx
1175 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001176 jmp ftrace_stub
1177END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001178#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001179#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001180
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001181#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1182ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001183 cmpl $0, function_trace_stop
1184 jne ftrace_stub
1185
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001186 pushl %eax
1187 pushl %ecx
1188 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001189 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001190 lea 0x4(%ebp), %eax
Steven Rostedt71e308a2009-06-18 12:45:08 -04001191 movl (%ebp), %ecx
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001192 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001193 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001194 popl %edx
1195 popl %ecx
1196 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001197 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001198END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001199
1200.globl return_to_handler
1201return_to_handler:
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001202 pushl %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001203 pushl %edx
Steven Rostedt71e308a2009-06-18 12:45:08 -04001204 movl %ebp, %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001205 call ftrace_return_to_handler
Steven Rostedt194ec342009-10-13 16:33:50 -04001206 movl %eax, %ecx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001207 popl %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001208 popl %eax
Steven Rostedt194ec342009-10-13 16:33:50 -04001209 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001210#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212.section .rodata,"a"
1213#include "syscall_table_32.S"
1214
1215syscall_table_size=(.-sys_call_table)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001216
1217/*
1218 * Some functions should be protected against kprobes
1219 */
1220 .pushsection .kprobes.text, "ax"
1221
1222ENTRY(page_fault)
1223 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001224 pushl_cfi $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001225 ALIGN
1226error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001227 /* the function address is in %gs's slot on the stack */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001228 pushl_cfi %fs
Tejun Heoccbeed32009-02-09 22:17:40 +09001229 /*CFI_REL_OFFSET fs, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001230 pushl_cfi %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001231 /*CFI_REL_OFFSET es, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001232 pushl_cfi %ds
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001233 /*CFI_REL_OFFSET ds, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001234 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001235 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001236 pushl_cfi %ebp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001237 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001238 pushl_cfi %edi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001239 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001240 pushl_cfi %esi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001241 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001242 pushl_cfi %edx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001243 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001244 pushl_cfi %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001245 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001246 pushl_cfi %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001247 CFI_REL_OFFSET ebx, 0
1248 cld
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001249 movl $(__KERNEL_PERCPU), %ecx
1250 movl %ecx, %fs
1251 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001252 GS_TO_REG %ecx
1253 movl PT_GS(%esp), %edi # get the function address
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001254 movl PT_ORIG_EAX(%esp), %edx # get the error code
1255 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001256 REG_TO_PTGS %ecx
1257 SET_KERNEL_GS %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001258 movl $(__USER_DS), %ecx
1259 movl %ecx, %ds
1260 movl %ecx, %es
1261 TRACE_IRQS_OFF
1262 movl %esp,%eax # pt_regs pointer
1263 call *%edi
1264 jmp ret_from_exception
1265 CFI_ENDPROC
1266END(page_fault)
1267
1268/*
1269 * Debug traps and NMI can happen at the one SYSENTER instruction
1270 * that sets up the real kernel stack. Check here, since we can't
1271 * allow the wrong stack to be used.
1272 *
1273 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1274 * already pushed 3 words if it hits on the sysenter instruction:
1275 * eflags, cs and eip.
1276 *
1277 * We just load the right stack, and push the three (known) values
1278 * by hand onto the new stack - while updating the return eip past
1279 * the instruction that would have done it for sysenter.
1280 */
Tejun Heof0d96112009-02-09 22:17:40 +09001281.macro FIX_STACK offset ok label
1282 cmpw $__KERNEL_CS, 4(%esp)
1283 jne \ok
1284\label:
1285 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1286 CFI_DEF_CFA esp, 0
1287 CFI_UNDEFINED eip
Jan Beulichdf5d1872010-09-02 14:07:16 +01001288 pushfl_cfi
1289 pushl_cfi $__KERNEL_CS
1290 pushl_cfi $sysenter_past_esp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001291 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001292.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001293
1294ENTRY(debug)
1295 RING0_INT_FRAME
1296 cmpl $ia32_sysenter_target,(%esp)
1297 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001298 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001299debug_stack_correct:
Jan Beulichdf5d1872010-09-02 14:07:16 +01001300 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001301 SAVE_ALL
1302 TRACE_IRQS_OFF
1303 xorl %edx,%edx # error code 0
1304 movl %esp,%eax # pt_regs pointer
1305 call do_debug
1306 jmp ret_from_exception
1307 CFI_ENDPROC
1308END(debug)
1309
1310/*
1311 * NMI is doubly nasty. It can happen _while_ we're handling
1312 * a debug fault, and the debug fault hasn't yet been able to
1313 * clear up the stack. So we first check whether we got an
1314 * NMI on the sysenter entry path, but after that we need to
1315 * check whether we got an NMI on the debug path where the debug
1316 * fault happened on the sysenter path.
1317 */
1318ENTRY(nmi)
1319 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001320 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001321 movl %ss, %eax
1322 cmpw $__ESPFIX_SS, %ax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001323 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001324 je nmi_espfix_stack
1325 cmpl $ia32_sysenter_target,(%esp)
1326 je nmi_stack_fixup
Jan Beulichdf5d1872010-09-02 14:07:16 +01001327 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001328 movl %esp,%eax
1329 /* Do not access memory above the end of our stack page,
1330 * it might not exist.
1331 */
1332 andl $(THREAD_SIZE-1),%eax
1333 cmpl $(THREAD_SIZE-20),%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001334 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001335 jae nmi_stack_correct
1336 cmpl $ia32_sysenter_target,12(%esp)
1337 je nmi_debug_stack_check
1338nmi_stack_correct:
1339 /* We have a RING0_INT_FRAME here */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001340 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001341 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001342 xorl %edx,%edx # zero error code
1343 movl %esp,%eax # pt_regs pointer
1344 call do_nmi
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +02001345 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001346 CFI_ENDPROC
1347
1348nmi_stack_fixup:
1349 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001350 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001351 jmp nmi_stack_correct
1352
1353nmi_debug_stack_check:
1354 /* We have a RING0_INT_FRAME here */
1355 cmpw $__KERNEL_CS,16(%esp)
1356 jne nmi_stack_correct
1357 cmpl $debug,(%esp)
1358 jb nmi_stack_correct
1359 cmpl $debug_esp_fix_insn,(%esp)
1360 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001361 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001362 jmp nmi_stack_correct
1363
1364nmi_espfix_stack:
1365 /* We have a RING0_INT_FRAME here.
1366 *
1367 * create the pointer to lss back
1368 */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001369 pushl_cfi %ss
1370 pushl_cfi %esp
Stas Sergeevbda3a892009-02-23 19:13:07 +03001371 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001372 /* copy the iret frame of 12 bytes */
1373 .rept 3
Jan Beulichdf5d1872010-09-02 14:07:16 +01001374 pushl_cfi 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001375 .endr
Jan Beulichdf5d1872010-09-02 14:07:16 +01001376 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001377 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001378 FIXUP_ESPFIX_STACK # %eax == %esp
1379 xorl %edx,%edx # zero error code
1380 call do_nmi
1381 RESTORE_REGS
1382 lss 12+4(%esp), %esp # back to espfix stack
1383 CFI_ADJUST_CFA_OFFSET -24
1384 jmp irq_return
1385 CFI_ENDPROC
1386END(nmi)
1387
1388ENTRY(int3)
1389 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001390 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001391 SAVE_ALL
1392 TRACE_IRQS_OFF
1393 xorl %edx,%edx # zero error code
1394 movl %esp,%eax # pt_regs pointer
1395 call do_int3
1396 jmp ret_from_exception
1397 CFI_ENDPROC
1398END(int3)
1399
1400ENTRY(general_protection)
1401 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001402 pushl_cfi $do_general_protection
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001403 jmp error_code
1404 CFI_ENDPROC
1405END(general_protection)
1406
Gleb Natapov631bc482010-10-14 11:22:52 +02001407#ifdef CONFIG_KVM_GUEST
1408ENTRY(async_page_fault)
1409 RING0_EC_FRAME
Jan Beulich60cf6372011-02-28 15:54:40 +00001410 pushl_cfi $do_async_page_fault
Gleb Natapov631bc482010-10-14 11:22:52 +02001411 jmp error_code
1412 CFI_ENDPROC
Sedat Dilek2ae9d292011-03-08 22:39:24 +01001413END(async_page_fault)
Gleb Natapov631bc482010-10-14 11:22:52 +02001414#endif
1415
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001416/*
1417 * End of kprobes section
1418 */
1419 .popsection