blob: 1ffcda22c2f675f15cff9825e96bf21f9d9f5985 [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#ifdef CONFIG_PREEMPT
Rusty Russell139ec7c2006-12-07 02:14:08 +010085#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#else
Rusty Russell139ec7c2006-12-07 02:14:08 +010087#define preempt_stop(clobbers)
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +020088#define resume_kernel restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#endif
90
Ingo Molnar55f327f2006-07-03 00:24:43 -070091.macro TRACE_IRQS_IRET
92#ifdef CONFIG_TRACE_IRQFLAGS
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030093 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070094 jz 1f
95 TRACE_IRQS_ON
961:
97#endif
98.endm
99
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700100#ifdef CONFIG_VM86
101#define resume_userspace_sig check_userspace
102#else
103#define resume_userspace_sig resume_userspace
104#endif
105
Tejun Heoccbeed32009-02-09 22:17:40 +0900106/*
107 * User gs save/restore
108 *
109 * %gs is used for userland TLS and kernel only uses it for stack
110 * canary which is required to be at %gs:20 by gcc. Read the comment
111 * at the top of stackprotector.h for more info.
112 *
113 * Local labels 98 and 99 are used.
114 */
115#ifdef CONFIG_X86_32_LAZY_GS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Tejun Heoccbeed32009-02-09 22:17:40 +0900117 /* unfortunately push/pop can't be no-op */
118.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100119 pushl_cfi $0
Tejun Heoccbeed32009-02-09 22:17:40 +0900120.endm
121.macro POP_GS pop=0
122 addl $(4 + \pop), %esp
123 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
124.endm
125.macro POP_GS_EX
126.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Tejun Heoccbeed32009-02-09 22:17:40 +0900128 /* all the rest are no-op */
129.macro PTGS_TO_GS
130.endm
131.macro PTGS_TO_GS_EX
132.endm
133.macro GS_TO_REG reg
134.endm
135.macro REG_TO_PTGS reg
136.endm
137.macro SET_KERNEL_GS reg
138.endm
139
140#else /* CONFIG_X86_32_LAZY_GS */
141
142.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100143 pushl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900144 /*CFI_REL_OFFSET gs, 0*/
145.endm
146
147.macro POP_GS pop=0
Jan Beulichdf5d1872010-09-02 14:07:16 +010014898: popl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900149 /*CFI_RESTORE gs*/
150 .if \pop <> 0
151 add $\pop, %esp
152 CFI_ADJUST_CFA_OFFSET -\pop
153 .endif
154.endm
155.macro POP_GS_EX
156.pushsection .fixup, "ax"
15799: movl $0, (%esp)
158 jmp 98b
159.section __ex_table, "a"
160 .align 4
161 .long 98b, 99b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100162.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900163.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Tejun Heoccbeed32009-02-09 22:17:40 +0900165.macro PTGS_TO_GS
16698: mov PT_GS(%esp), %gs
167.endm
168.macro PTGS_TO_GS_EX
169.pushsection .fixup, "ax"
17099: movl $0, PT_GS(%esp)
171 jmp 98b
172.section __ex_table, "a"
173 .align 4
174 .long 98b, 99b
175.popsection
176.endm
177
178.macro GS_TO_REG reg
179 movl %gs, \reg
180 /*CFI_REGISTER gs, \reg*/
181.endm
182.macro REG_TO_PTGS reg
183 movl \reg, PT_GS(%esp)
184 /*CFI_REL_OFFSET gs, PT_GS*/
185.endm
186.macro SET_KERNEL_GS reg
Tejun Heo60a53172009-02-09 22:17:40 +0900187 movl $(__KERNEL_STACK_CANARY), \reg
Tejun Heoccbeed32009-02-09 22:17:40 +0900188 movl \reg, %gs
189.endm
190
191#endif /* CONFIG_X86_32_LAZY_GS */
192
Tejun Heof0d96112009-02-09 22:17:40 +0900193.macro SAVE_ALL
194 cld
Tejun Heoccbeed32009-02-09 22:17:40 +0900195 PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100196 pushl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900197 /*CFI_REL_OFFSET fs, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100198 pushl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900199 /*CFI_REL_OFFSET es, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100200 pushl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900201 /*CFI_REL_OFFSET ds, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100202 pushl_cfi %eax
Tejun Heof0d96112009-02-09 22:17:40 +0900203 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100204 pushl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900205 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100206 pushl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900207 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100208 pushl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900209 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100210 pushl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900211 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100212 pushl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900213 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100214 pushl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900215 CFI_REL_OFFSET ebx, 0
216 movl $(__USER_DS), %edx
217 movl %edx, %ds
218 movl %edx, %es
219 movl $(__KERNEL_PERCPU), %edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 movl %edx, %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900221 SET_KERNEL_GS %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900222.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
Tejun Heof0d96112009-02-09 22:17:40 +0900224.macro RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100225 popl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900226 CFI_RESTORE ebx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100227 popl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900228 CFI_RESTORE ecx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100229 popl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900230 CFI_RESTORE edx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100231 popl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900232 CFI_RESTORE esi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100233 popl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900234 CFI_RESTORE edi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100235 popl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900236 CFI_RESTORE ebp
Jan Beulichdf5d1872010-09-02 14:07:16 +0100237 popl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 CFI_RESTORE eax
Tejun Heof0d96112009-02-09 22:17:40 +0900239.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Tejun Heoccbeed32009-02-09 22:17:40 +0900241.macro RESTORE_REGS pop=0
Tejun Heof0d96112009-02-09 22:17:40 +0900242 RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +01002431: popl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900244 /*CFI_RESTORE ds;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002452: popl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900246 /*CFI_RESTORE es;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002473: popl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900248 /*CFI_RESTORE fs;*/
Tejun Heoccbeed32009-02-09 22:17:40 +0900249 POP_GS \pop
Tejun Heof0d96112009-02-09 22:17:40 +0900250.pushsection .fixup, "ax"
2514: movl $0, (%esp)
252 jmp 1b
2535: movl $0, (%esp)
254 jmp 2b
2556: movl $0, (%esp)
256 jmp 3b
257.section __ex_table, "a"
258 .align 4
259 .long 1b, 4b
260 .long 2b, 5b
261 .long 3b, 6b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900263 POP_GS_EX
Tejun Heof0d96112009-02-09 22:17:40 +0900264.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Tejun Heof0d96112009-02-09 22:17:40 +0900266.macro RING0_INT_FRAME
267 CFI_STARTPROC simple
268 CFI_SIGNAL_FRAME
269 CFI_DEF_CFA esp, 3*4
270 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200271 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900272.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200273
Tejun Heof0d96112009-02-09 22:17:40 +0900274.macro RING0_EC_FRAME
275 CFI_STARTPROC simple
276 CFI_SIGNAL_FRAME
277 CFI_DEF_CFA esp, 4*4
278 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200279 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900280.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200281
Tejun Heof0d96112009-02-09 22:17:40 +0900282.macro RING0_PTREGS_FRAME
283 CFI_STARTPROC simple
284 CFI_SIGNAL_FRAME
285 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
286 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
287 CFI_OFFSET eip, PT_EIP-PT_OLDESP
288 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
289 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
290 CFI_OFFSET eax, PT_EAX-PT_OLDESP
291 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
292 CFI_OFFSET edi, PT_EDI-PT_OLDESP
293 CFI_OFFSET esi, PT_ESI-PT_OLDESP
294 CFI_OFFSET edx, PT_EDX-PT_OLDESP
295 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100296 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Tejun Heof0d96112009-02-09 22:17:40 +0900297.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
299ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200300 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +0100301 pushl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 call schedule_tail
303 GET_THREAD_INFO(%ebp)
Jan Beulichdf5d1872010-09-02 14:07:16 +0100304 popl_cfi %eax
305 pushl_cfi $0x0202 # Reset kernel eflags
306 popfl_cfi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200308 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100309END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311/*
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400312 * Interrupt exit functions should be protected against kprobes
313 */
314 .pushsection .kprobes.text, "ax"
315/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 * Return to user mode is not as complex as all this looks,
317 * but we want the default path for a system call return to
318 * go as quickly as possible which is why some of this is
319 * less clear than it otherwise should be.
320 */
321
322 # userspace resumption stub bypassing syscall exit tracing
323 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200324 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100326 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327ret_from_intr:
328 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700329check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100330 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
331 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300332 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200333 cmpl $USER_RPL, %eax
334 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200337 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100338 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 # setting need_resched or sigpending
340 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200341 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 movl TI_flags(%ebp), %ecx
343 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
344 # int/exception return?
345 jne work_pending
346 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100347END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349#ifdef CONFIG_PREEMPT
350ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100351 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200353 jnz restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354need_resched:
355 movl TI_flags(%ebp), %ecx # need_resched set ?
356 testb $_TIF_NEED_RESCHED, %cl
357 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300358 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 jz restore_all
360 call preempt_schedule_irq
361 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100362END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200364 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400365/*
366 * End of kprobes section
367 */
368 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370/* SYSENTER_RETURN points to after the "sysenter" instruction in
371 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
372
373 # sysenter call handler stub
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100374ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200375 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200376 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200377 CFI_DEF_CFA esp, 0
378 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100379 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700381 /*
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700382 * Interrupts are disabled here, but we can't trace it until
383 * enough kernel state to call TRACE_IRQS_OFF can be called - but
384 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700385 */
Jan Beulich32342822010-10-19 14:52:26 +0100386 pushl_cfi $__USER_DS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200387 /*CFI_REL_OFFSET ss, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100388 pushl_cfi %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200389 CFI_REL_OFFSET esp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100390 pushfl_cfi
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700391 orl $X86_EFLAGS_IF, (%esp)
Jan Beulich32342822010-10-19 14:52:26 +0100392 pushl_cfi $__USER_CS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200393 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700394 /*
395 * Push current_thread_info()->sysenter_return to the stack.
396 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
397 * pushed above; +8 corresponds to copy_thread's esp0 setting.
398 */
Stratos Psomadakis7bf04be2011-02-25 22:46:13 +0200399 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200400 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Jan Beulichdf5d1872010-09-02 14:07:16 +0100402 pushl_cfi %eax
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700403 SAVE_ALL
404 ENABLE_INTERRUPTS(CLBR_NONE)
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406/*
407 * Load the potential sixth argument from user stack.
408 * Careful about security.
409 */
410 cmpl $__PAGE_OFFSET-3,%ebp
411 jae syscall_fault
4121: movl (%ebp),%ebp
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700413 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414.section __ex_table,"a"
415 .align 4
416 .long 1b,syscall_fault
417.previous
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 GET_THREAD_INFO(%ebp)
420
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530421 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700422 jnz sysenter_audit
423sysenter_do_call:
H. Peter Anvin303395a2011-11-11 16:07:41 -0800424 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 jae syscall_badsys
426 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100427 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200428 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200429 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700430 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530432 testl $_TIF_ALLWORK_MASK, %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700433 jne sysexit_audit
434sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100436 movl PT_EIP(%esp), %edx
437 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700439 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004401: mov PT_FS(%esp), %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900441 PTGS_TO_GS
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400442 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700443
444#ifdef CONFIG_AUDITSYSCALL
445sysenter_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530446 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700447 jnz syscall_trace_entry
448 addl $4,%esp
449 CFI_ADJUST_CFA_OFFSET -4
450 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
451 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
452 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
453 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
454 movl %eax,%edx /* 2nd arg: syscall number */
455 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
456 call audit_syscall_entry
Jan Beulichdf5d1872010-09-02 14:07:16 +0100457 pushl_cfi %ebx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700458 movl PT_EAX(%esp),%eax /* reload syscall number */
459 jmp sysenter_do_call
460
461sysexit_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530462 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700463 jne syscall_exit_work
464 TRACE_IRQS_ON
465 ENABLE_INTERRUPTS(CLBR_ANY)
466 movl %eax,%edx /* second arg, syscall return value */
467 cmpl $0,%eax /* is it < 0? */
468 setl %al /* 1 if so, 0 if not */
469 movzbl %al,%eax /* zero-extend that */
470 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
471 call audit_syscall_exit
472 DISABLE_INTERRUPTS(CLBR_ANY)
473 TRACE_IRQS_OFF
474 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530475 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700476 jne syscall_exit_work
477 movl PT_EAX(%esp),%eax /* reload syscall return value */
478 jmp sysenter_exit
479#endif
480
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200481 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100482.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004832: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100484 jmp 1b
485.section __ex_table,"a"
486 .align 4
487 .long 1b,2b
488.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900489 PTGS_TO_GS_EX
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100490ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400492/*
493 * syscall stub including irq exit should be protected against kprobes
494 */
495 .pushsection .kprobes.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 # system call handler stub
497ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200498 RING0_INT_FRAME # can't unwind into user space anyway
Jan Beulichdf5d1872010-09-02 14:07:16 +0100499 pushl_cfi %eax # save orig_eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 SAVE_ALL
501 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700502 # system call tracing in operation / emulation
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530503 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 jnz syscall_trace_entry
H. Peter Anvin303395a2011-11-11 16:07:41 -0800505 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 jae syscall_badsys
507syscall_call:
508 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100509 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200511 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100512 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 # setting need_resched or sigpending
514 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700515 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530517 testl $_TIF_ALLWORK_MASK, %ecx # current->work
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 jne syscall_exit_work
519
520restore_all:
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200521 TRACE_IRQS_IRET
522restore_all_notrace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100523 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
524 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700525 # are returning to the kernel.
526 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100527 movb PT_OLDSS(%esp), %ah
528 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300529 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200530 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200531 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 je ldt_ss # returning to user-space with LDT SS
533restore_nocheck:
Tejun Heoccbeed32009-02-09 22:17:40 +0900534 RESTORE_REGS 4 # skip orig_eax/error_code
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200535irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100536 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700538ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700539 pushl $0 # no error code
540 pushl $do_iret_error
541 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542.previous
543.section __ex_table,"a"
544 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100545 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546.previous
547
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200548 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100550 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 jnz restore_nocheck
552 testl $0x00400000, %eax # returning to 32bit stack?
553 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100554
555#ifdef CONFIG_PARAVIRT
556 /*
557 * The kernel can't run on a non-flat stack if paravirt mode
558 * is active. Rather than try to fixup the high bits of
559 * ESP, bypass this code entirely. This may break DOSemu
560 * and/or Wine support in a paravirt VM, although the option
561 * is still available to implement the setting of the high
562 * 16-bits in the INTERRUPT_RETURN paravirt-op.
563 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700564 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100565 jne restore_nocheck
566#endif
567
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200568/*
569 * Setup and switch to ESPFIX stack
570 *
571 * We're returning to userspace with a 16 bit stack. The CPU will not
572 * restore the high word of ESP for us on executing iret... This is an
573 * "official" bug of all the x86-compatible CPUs, which we can work
574 * around to make dosemu and wine happy. We do this by preloading the
575 * high word of ESP with the high word of the userspace ESP while
576 * compensating for the offset by changing to the ESPFIX segment with
577 * a base address that matches for the difference.
578 */
Brian Gerst72c511d2010-07-31 12:48:23 -0400579#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200580 mov %esp, %edx /* load kernel esp */
581 mov PT_OLDESP(%esp), %eax /* load userspace esp */
582 mov %dx, %ax /* eax: new kernel esp */
583 sub %eax, %edx /* offset (low word is 0) */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200584 shr $16, %edx
Brian Gerst72c511d2010-07-31 12:48:23 -0400585 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
586 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100587 pushl_cfi $__ESPFIX_SS
588 pushl_cfi %eax /* new kernel esp */
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200589 /* Disable interrupts, but do not irqtrace this section: we
590 * will soon execute iret and the tracer was already set to
591 * the irqstate after the iret */
Rusty Russell139ec7c2006-12-07 02:14:08 +0100592 DISABLE_INTERRUPTS(CLBR_EAX)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200593 lss (%esp), %esp /* switch to espfix segment */
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100594 CFI_ADJUST_CFA_OFFSET -8
595 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200596 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100597ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599 # perform work that needs to be done immediately before resumption
600 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200601 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602work_pending:
603 testb $_TIF_NEED_RESCHED, %cl
604 jz work_notifysig
605work_resched:
606 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200607 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100608 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 # setting need_resched or sigpending
610 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700611 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 movl TI_flags(%ebp), %ecx
613 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
614 # than syscall tracing?
615 jz restore_all
616 testb $_TIF_NEED_RESCHED, %cl
617 jnz work_resched
618
619work_notifysig: # deal with pending signals and
620 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100621#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300622 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 movl %esp, %eax
624 jne work_notifysig_v86 # returning to kernel-space or
625 # vm86-space
626 xorl %edx, %edx
627 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700628 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
630 ALIGN
631work_notifysig_v86:
Jan Beulichdf5d1872010-09-02 14:07:16 +0100632 pushl_cfi %ecx # save ti_flags for do_notify_resume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 call save_v86_state # %eax contains pt_regs pointer
Jan Beulichdf5d1872010-09-02 14:07:16 +0100634 popl_cfi %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100636#else
637 movl %esp, %eax
638#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 xorl %edx, %edx
640 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700641 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100642END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 # perform syscall exit tracing
645 ALIGN
646syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100647 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700649 call syscall_trace_enter
650 /* What it returned is what we'll actually use. */
H. Peter Anvin303395a2011-11-11 16:07:41 -0800651 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 jnae syscall_call
653 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100654END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656 # perform syscall exit tracing
657 ALIGN
658syscall_exit_work:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530659 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700661 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700662 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 # schedule() instead
664 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700665 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100667END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200668 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200670 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100673 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100675END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100678 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100680END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200681 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400682/*
683 * End of kprobes section
684 */
685 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Brian Gerst253f29a2009-02-10 09:51:46 -0500687/*
688 * System calls that need a pt_regs pointer.
689 */
Brian Gerste258e4e2009-12-09 19:01:51 -0500690#define PTREGSCALL0(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800691ENTRY(ptregs_##name) ; \
Brian Gerst253f29a2009-02-10 09:51:46 -0500692 leal 4(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800693 jmp sys_##name; \
694ENDPROC(ptregs_##name)
Brian Gerst253f29a2009-02-10 09:51:46 -0500695
Brian Gerste258e4e2009-12-09 19:01:51 -0500696#define PTREGSCALL1(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800697ENTRY(ptregs_##name) ; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500698 leal 4(%esp),%edx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800699 movl (PT_EBX+4)(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800700 jmp sys_##name; \
701ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500702
703#define PTREGSCALL2(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800704ENTRY(ptregs_##name) ; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500705 leal 4(%esp),%ecx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800706 movl (PT_ECX+4)(%esp),%edx; \
707 movl (PT_EBX+4)(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800708 jmp sys_##name; \
709ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500710
711#define PTREGSCALL3(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800712ENTRY(ptregs_##name) ; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100713 CFI_STARTPROC; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500714 leal 4(%esp),%eax; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100715 pushl_cfi %eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500716 movl PT_EDX(%eax),%ecx; \
717 movl PT_ECX(%eax),%edx; \
718 movl PT_EBX(%eax),%eax; \
719 call sys_##name; \
720 addl $4,%esp; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100721 CFI_ADJUST_CFA_OFFSET -4; \
722 ret; \
723 CFI_ENDPROC; \
724ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500725
Brian Gerst27f59552009-12-09 19:01:52 -0500726PTREGSCALL1(iopl)
Brian Gerste258e4e2009-12-09 19:01:51 -0500727PTREGSCALL0(fork)
Brian Gerste258e4e2009-12-09 19:01:51 -0500728PTREGSCALL0(vfork)
Brian Gerst11cf88b2009-12-09 19:01:53 -0500729PTREGSCALL3(execve)
Brian Gerst052acad2009-12-09 19:01:54 -0500730PTREGSCALL2(sigaltstack)
Brian Gerste258e4e2009-12-09 19:01:51 -0500731PTREGSCALL0(sigreturn)
732PTREGSCALL0(rt_sigreturn)
Brian Gerstf1382f12009-12-09 19:01:55 -0500733PTREGSCALL2(vm86)
734PTREGSCALL1(vm86old)
Brian Gerst253f29a2009-02-10 09:51:46 -0500735
Brian Gerstf839bbc2009-12-09 19:01:56 -0500736/* Clone is an oddball. The 4th arg is in %edi */
H. Peter Anvin303395a2011-11-11 16:07:41 -0800737ENTRY(ptregs_clone)
Jan Beulicha34107b2010-09-02 14:04:16 +0100738 CFI_STARTPROC
Brian Gerstf839bbc2009-12-09 19:01:56 -0500739 leal 4(%esp),%eax
Jan Beulicha34107b2010-09-02 14:04:16 +0100740 pushl_cfi %eax
741 pushl_cfi PT_EDI(%eax)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500742 movl PT_EDX(%eax),%ecx
743 movl PT_ECX(%eax),%edx
744 movl PT_EBX(%eax),%eax
745 call sys_clone
746 addl $8,%esp
Jan Beulicha34107b2010-09-02 14:04:16 +0100747 CFI_ADJUST_CFA_OFFSET -8
Brian Gerstf839bbc2009-12-09 19:01:56 -0500748 ret
Jan Beulicha34107b2010-09-02 14:04:16 +0100749 CFI_ENDPROC
750ENDPROC(ptregs_clone)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500751
Tejun Heof0d96112009-02-09 22:17:40 +0900752.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200753/*
754 * Switch back for ESPFIX stack to the normal zerobased stack
755 *
756 * We can't call C functions using the ESPFIX stack. This code reads
757 * the high word of the segment base from the GDT and swiches to the
758 * normal stack and adjusts ESP with the matching offset.
759 */
760 /* fixup the stack */
Brian Gerst72c511d2010-07-31 12:48:23 -0400761 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
762 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200763 shl $16, %eax
764 addl %esp, %eax /* the adjusted stack pointer */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100765 pushl_cfi $__KERNEL_DS
766 pushl_cfi %eax
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200767 lss (%esp), %esp /* switch to the normal stack segment */
Tejun Heof0d96112009-02-09 22:17:40 +0900768 CFI_ADJUST_CFA_OFFSET -8
769.endm
770.macro UNWIND_ESPFIX_STACK
771 movl %ss, %eax
772 /* see if on espfix stack */
773 cmpw $__ESPFIX_SS, %ax
774 jne 27f
775 movl $__KERNEL_DS, %eax
776 movl %eax, %ds
777 movl %eax, %es
778 /* switch to normal stack */
779 FIXUP_ESPFIX_STACK
78027:
781.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800784 * Build the entry stubs and pointer table with some assembler magic.
785 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
786 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800788.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789ENTRY(interrupt)
Jiri Olsaea714542011-03-07 19:10:39 +0100790.section .entry.text, "ax"
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800791 .p2align 5
792 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200794 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800795vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800796.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
797 .balign 32
798 .rept 7
799 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800800 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200801 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800802 .endif
Jan Beulichdf5d1872010-09-02 14:07:16 +01008031: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
H. Peter Anvin86655962008-11-12 10:27:35 -0800804 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800805 jmp 2f
806 .endif
807 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .long 1b
Jiri Olsaea714542011-03-07 19:10:39 +0100809 .section .entry.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800811 .endif
812 .endr
8132: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100815END(irq_entries_start)
816
817.previous
818END(interrupt)
819.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
Ingo Molnar55f327f2006-07-03 00:24:43 -0700821/*
822 * the CPU automatically disables interrupts when executing an IRQ vector,
823 * so IRQ-flags tracing has to follow that:
824 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800825 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800827 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700829 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 movl %esp,%eax
831 call do_IRQ
832 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100833ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200834 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400836/*
837 * Irq entries should be protected against kprobes
838 */
839 .pushsection .kprobes.text, "ax"
Tejun Heo02cf94c2009-01-21 17:26:06 +0900840#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200842 RING0_INT_FRAME; \
Jan Beulichdf5d1872010-09-02 14:07:16 +0100843 pushl_cfi $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200844 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700845 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900847 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700848 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100849 CFI_ENDPROC; \
850ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Tejun Heo02cf94c2009-01-21 17:26:06 +0900852#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
853
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100855#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200858 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100859 pushl_cfi $0
860 pushl_cfi $do_coprocessor_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200862 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100863END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200866 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100867 pushl_cfi $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400868#ifdef CONFIG_X86_INVD_BUG
869 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100870661: pushl_cfi $do_general_protection
Brian Gerst40d2e762010-03-21 09:00:43 -0400871662:
872.section .altinstructions,"a"
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -0400873 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
Brian Gerst40d2e762010-03-21 09:00:43 -0400874.previous
875.section .altinstr_replacement,"ax"
876663: pushl $do_simd_coprocessor_error
877664:
878.previous
879#else
Jan Beulichdf5d1872010-09-02 14:07:16 +0100880 pushl_cfi $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400881#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200883 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100884END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200887 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100888 pushl_cfi $-1 # mark this as an int
889 pushl_cfi $do_device_not_available
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200890 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100892END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Rusty Russelld3561b72006-12-07 02:14:07 +0100894#ifdef CONFIG_PARAVIRT
895ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100896 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100897.section __ex_table,"a"
898 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100899 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100900.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100901END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100902
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400903ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100904 sti
905 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400906END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100907#endif
908
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200910 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100911 pushl_cfi $0
912 pushl_cfi $do_overflow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200914 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100915END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917ENTRY(bounds)
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_bounds
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(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925ENTRY(invalid_op)
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_invalid_op
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(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933ENTRY(coprocessor_segment_overrun)
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_coprocessor_segment_overrun
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(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200942 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100943 pushl_cfi $do_invalid_TSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200945 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100946END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200949 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100950 pushl_cfi $do_segment_not_present
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200952 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100953END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200956 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100957 pushl_cfi $do_stack_segment
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200959 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100960END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100964 pushl_cfi $do_alignment_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200966 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100967END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200969ENTRY(divide_error)
970 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100971 pushl_cfi $0 # no error code
972 pushl_cfi $do_divide_error
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(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977#ifdef CONFIG_X86_MCE
978ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200979 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100980 pushl_cfi $0
981 pushl_cfi machine_check_vector
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200983 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100984END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985#endif
986
987ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200988 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100989 pushl_cfi $0
990 pushl_cfi $do_spurious_interrupt_bug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200992 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100993END(spurious_interrupt_bug)
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400994/*
995 * End of kprobes section
996 */
997 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Andi Kleen02ba1a32006-09-26 10:52:35 +0200999ENTRY(kernel_thread_helper)
1000 pushl $0 # fake return address for unwinder
1001 CFI_STARTPROC
Brian Gerste8402272009-12-09 12:34:42 -05001002 movl %edi,%eax
1003 call *%esi
Andi Kleen02ba1a32006-09-26 10:52:35 +02001004 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001005 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +02001006 CFI_ENDPROC
1007ENDPROC(kernel_thread_helper)
1008
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001009#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001010/* Xen doesn't set %esp to be precisely what the normal sysenter
1011 entrypoint expects, so fix it up before using the normal path. */
1012ENTRY(xen_sysenter_target)
1013 RING0_INT_FRAME
1014 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001015 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001016 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001017 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001018
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001019ENTRY(xen_hypervisor_callback)
1020 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001021 pushl_cfi $0
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001022 SAVE_ALL
1023 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001024
1025 /* Check to see if we got the event in the critical
1026 region in xen_iret_direct, after we've reenabled
1027 events and checked for pending events. This simulates
1028 iret instruction's behaviour where it delivers a
1029 pending interrupt when enabling interrupts. */
1030 movl PT_EIP(%esp),%eax
1031 cmpl $xen_iret_start_crit,%eax
1032 jb 1f
1033 cmpl $xen_iret_end_crit,%eax
1034 jae 1f
1035
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001036 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001037
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001038ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010391: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001040 call xen_evtchn_do_upcall
1041 jmp ret_from_intr
1042 CFI_ENDPROC
1043ENDPROC(xen_hypervisor_callback)
1044
1045# Hypervisor uses this for application faults while it executes.
1046# We get here for two reasons:
1047# 1. Fault while reloading DS, ES, FS or GS
1048# 2. Fault while executing IRET
1049# Category 1 we fix up by reattempting the load, and zeroing the segment
1050# register if the load fails.
1051# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1052# normal Linux return path in this case because if we use the IRET hypercall
1053# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1054# We distinguish between categories by maintaining a status value in EAX.
1055ENTRY(xen_failsafe_callback)
1056 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001057 pushl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001058 movl $1,%eax
10591: mov 4(%esp),%ds
10602: mov 8(%esp),%es
10613: mov 12(%esp),%fs
10624: mov 16(%esp),%gs
1063 testl %eax,%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001064 popl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001065 lea 16(%esp),%esp
1066 CFI_ADJUST_CFA_OFFSET -16
1067 jz 5f
1068 addl $16,%esp
1069 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
Jan Beulichdf5d1872010-09-02 14:07:16 +010010705: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001071 SAVE_ALL
1072 jmp ret_from_exception
1073 CFI_ENDPROC
1074
1075.section .fixup,"ax"
10766: xorl %eax,%eax
1077 movl %eax,4(%esp)
1078 jmp 1b
10797: xorl %eax,%eax
1080 movl %eax,8(%esp)
1081 jmp 2b
10828: xorl %eax,%eax
1083 movl %eax,12(%esp)
1084 jmp 3b
10859: xorl %eax,%eax
1086 movl %eax,16(%esp)
1087 jmp 4b
1088.previous
1089.section __ex_table,"a"
1090 .align 4
1091 .long 1b,6b
1092 .long 2b,7b
1093 .long 3b,8b
1094 .long 4b,9b
1095.previous
1096ENDPROC(xen_failsafe_callback)
1097
Sheng Yang38e20b02010-05-14 12:40:51 +01001098BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1099 xen_evtchn_do_upcall)
1100
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001101#endif /* CONFIG_XEN */
1102
Steven Rostedt606576c2008-10-06 19:06:12 -04001103#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001104#ifdef CONFIG_DYNAMIC_FTRACE
1105
1106ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001107 ret
1108END(mcount)
1109
1110ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001111 cmpl $0, function_trace_stop
1112 jne ftrace_stub
1113
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001114 pushl %eax
1115 pushl %ecx
1116 pushl %edx
1117 movl 0xc(%esp), %eax
1118 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301119 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001120
1121.globl ftrace_call
1122ftrace_call:
1123 call ftrace_stub
1124
1125 popl %edx
1126 popl %ecx
1127 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001128#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1129.globl ftrace_graph_call
1130ftrace_graph_call:
1131 jmp ftrace_stub
1132#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001133
1134.globl ftrace_stub
1135ftrace_stub:
1136 ret
1137END(ftrace_caller)
1138
1139#else /* ! CONFIG_DYNAMIC_FTRACE */
1140
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001141ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001142 cmpl $0, function_trace_stop
1143 jne ftrace_stub
1144
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001145 cmpl $ftrace_stub, ftrace_trace_function
1146 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001147#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001148 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001149 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001150
1151 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1152 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001153#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001154.globl ftrace_stub
1155ftrace_stub:
1156 ret
1157
1158 /* taken from glibc */
1159trace:
1160 pushl %eax
1161 pushl %ecx
1162 pushl %edx
1163 movl 0xc(%esp), %eax
1164 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301165 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001166
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001167 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001168
1169 popl %edx
1170 popl %ecx
1171 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001172 jmp ftrace_stub
1173END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001174#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001175#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001176
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001177#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1178ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001179 cmpl $0, function_trace_stop
1180 jne ftrace_stub
1181
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001182 pushl %eax
1183 pushl %ecx
1184 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001185 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001186 lea 0x4(%ebp), %eax
Steven Rostedt71e308a2009-06-18 12:45:08 -04001187 movl (%ebp), %ecx
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001188 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001189 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001190 popl %edx
1191 popl %ecx
1192 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001193 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001194END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001195
1196.globl return_to_handler
1197return_to_handler:
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001198 pushl %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001199 pushl %edx
Steven Rostedt71e308a2009-06-18 12:45:08 -04001200 movl %ebp, %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001201 call ftrace_return_to_handler
Steven Rostedt194ec342009-10-13 16:33:50 -04001202 movl %eax, %ecx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001203 popl %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001204 popl %eax
Steven Rostedt194ec342009-10-13 16:33:50 -04001205 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001206#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001208/*
1209 * Some functions should be protected against kprobes
1210 */
1211 .pushsection .kprobes.text, "ax"
1212
1213ENTRY(page_fault)
1214 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001215 pushl_cfi $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001216 ALIGN
1217error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001218 /* the function address is in %gs's slot on the stack */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001219 pushl_cfi %fs
Tejun Heoccbeed32009-02-09 22:17:40 +09001220 /*CFI_REL_OFFSET fs, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001221 pushl_cfi %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001222 /*CFI_REL_OFFSET es, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001223 pushl_cfi %ds
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001224 /*CFI_REL_OFFSET ds, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001225 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001226 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001227 pushl_cfi %ebp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001228 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001229 pushl_cfi %edi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001230 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001231 pushl_cfi %esi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001232 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001233 pushl_cfi %edx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001234 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001235 pushl_cfi %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001236 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001237 pushl_cfi %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001238 CFI_REL_OFFSET ebx, 0
1239 cld
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001240 movl $(__KERNEL_PERCPU), %ecx
1241 movl %ecx, %fs
1242 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001243 GS_TO_REG %ecx
1244 movl PT_GS(%esp), %edi # get the function address
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001245 movl PT_ORIG_EAX(%esp), %edx # get the error code
1246 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001247 REG_TO_PTGS %ecx
1248 SET_KERNEL_GS %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001249 movl $(__USER_DS), %ecx
1250 movl %ecx, %ds
1251 movl %ecx, %es
1252 TRACE_IRQS_OFF
1253 movl %esp,%eax # pt_regs pointer
1254 call *%edi
1255 jmp ret_from_exception
1256 CFI_ENDPROC
1257END(page_fault)
1258
1259/*
1260 * Debug traps and NMI can happen at the one SYSENTER instruction
1261 * that sets up the real kernel stack. Check here, since we can't
1262 * allow the wrong stack to be used.
1263 *
1264 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1265 * already pushed 3 words if it hits on the sysenter instruction:
1266 * eflags, cs and eip.
1267 *
1268 * We just load the right stack, and push the three (known) values
1269 * by hand onto the new stack - while updating the return eip past
1270 * the instruction that would have done it for sysenter.
1271 */
Tejun Heof0d96112009-02-09 22:17:40 +09001272.macro FIX_STACK offset ok label
1273 cmpw $__KERNEL_CS, 4(%esp)
1274 jne \ok
1275\label:
1276 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1277 CFI_DEF_CFA esp, 0
1278 CFI_UNDEFINED eip
Jan Beulichdf5d1872010-09-02 14:07:16 +01001279 pushfl_cfi
1280 pushl_cfi $__KERNEL_CS
1281 pushl_cfi $sysenter_past_esp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001282 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001283.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001284
1285ENTRY(debug)
1286 RING0_INT_FRAME
1287 cmpl $ia32_sysenter_target,(%esp)
1288 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001289 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001290debug_stack_correct:
Jan Beulichdf5d1872010-09-02 14:07:16 +01001291 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001292 SAVE_ALL
1293 TRACE_IRQS_OFF
1294 xorl %edx,%edx # error code 0
1295 movl %esp,%eax # pt_regs pointer
1296 call do_debug
1297 jmp ret_from_exception
1298 CFI_ENDPROC
1299END(debug)
1300
1301/*
1302 * NMI is doubly nasty. It can happen _while_ we're handling
1303 * a debug fault, and the debug fault hasn't yet been able to
1304 * clear up the stack. So we first check whether we got an
1305 * NMI on the sysenter entry path, but after that we need to
1306 * check whether we got an NMI on the debug path where the debug
1307 * fault happened on the sysenter path.
1308 */
1309ENTRY(nmi)
1310 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001311 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001312 movl %ss, %eax
1313 cmpw $__ESPFIX_SS, %ax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001314 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001315 je nmi_espfix_stack
1316 cmpl $ia32_sysenter_target,(%esp)
1317 je nmi_stack_fixup
Jan Beulichdf5d1872010-09-02 14:07:16 +01001318 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001319 movl %esp,%eax
1320 /* Do not access memory above the end of our stack page,
1321 * it might not exist.
1322 */
1323 andl $(THREAD_SIZE-1),%eax
1324 cmpl $(THREAD_SIZE-20),%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001325 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001326 jae nmi_stack_correct
1327 cmpl $ia32_sysenter_target,12(%esp)
1328 je nmi_debug_stack_check
1329nmi_stack_correct:
1330 /* We have a RING0_INT_FRAME here */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001331 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001332 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001333 xorl %edx,%edx # zero error code
1334 movl %esp,%eax # pt_regs pointer
1335 call do_nmi
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +02001336 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001337 CFI_ENDPROC
1338
1339nmi_stack_fixup:
1340 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001341 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001342 jmp nmi_stack_correct
1343
1344nmi_debug_stack_check:
1345 /* We have a RING0_INT_FRAME here */
1346 cmpw $__KERNEL_CS,16(%esp)
1347 jne nmi_stack_correct
1348 cmpl $debug,(%esp)
1349 jb nmi_stack_correct
1350 cmpl $debug_esp_fix_insn,(%esp)
1351 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001352 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001353 jmp nmi_stack_correct
1354
1355nmi_espfix_stack:
1356 /* We have a RING0_INT_FRAME here.
1357 *
1358 * create the pointer to lss back
1359 */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001360 pushl_cfi %ss
1361 pushl_cfi %esp
Stas Sergeevbda3a892009-02-23 19:13:07 +03001362 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001363 /* copy the iret frame of 12 bytes */
1364 .rept 3
Jan Beulichdf5d1872010-09-02 14:07:16 +01001365 pushl_cfi 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001366 .endr
Jan Beulichdf5d1872010-09-02 14:07:16 +01001367 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001368 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001369 FIXUP_ESPFIX_STACK # %eax == %esp
1370 xorl %edx,%edx # zero error code
1371 call do_nmi
1372 RESTORE_REGS
1373 lss 12+4(%esp), %esp # back to espfix stack
1374 CFI_ADJUST_CFA_OFFSET -24
1375 jmp irq_return
1376 CFI_ENDPROC
1377END(nmi)
1378
1379ENTRY(int3)
1380 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001381 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001382 SAVE_ALL
1383 TRACE_IRQS_OFF
1384 xorl %edx,%edx # zero error code
1385 movl %esp,%eax # pt_regs pointer
1386 call do_int3
1387 jmp ret_from_exception
1388 CFI_ENDPROC
1389END(int3)
1390
1391ENTRY(general_protection)
1392 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001393 pushl_cfi $do_general_protection
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001394 jmp error_code
1395 CFI_ENDPROC
1396END(general_protection)
1397
Gleb Natapov631bc482010-10-14 11:22:52 +02001398#ifdef CONFIG_KVM_GUEST
1399ENTRY(async_page_fault)
1400 RING0_EC_FRAME
Jan Beulich60cf6372011-02-28 15:54:40 +00001401 pushl_cfi $do_async_page_fault
Gleb Natapov631bc482010-10-14 11:22:52 +02001402 jmp error_code
1403 CFI_ENDPROC
Sedat Dilek2ae9d292011-03-08 22:39:24 +01001404END(async_page_fault)
Gleb Natapov631bc482010-10-14 11:22:52 +02001405#endif
1406
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001407/*
1408 * End of kprobes section
1409 */
1410 .popsection