blob: 7b784f4ef1e483876ad98e432283d1ba82c890a1 [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>
Eric Parisd7e75282012-01-03 14:23:06 -050045#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070047#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/errno.h>
49#include <asm/segment.h>
50#include <asm/smp.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -080051#include <asm/page_types.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010052#include <asm/percpu.h>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020053#include <asm/dwarf2.h>
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030054#include <asm/processor-flags.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053055#include <asm/ftrace.h>
Thomas Gleixner9b7dc562008-05-02 20:10:09 +020056#include <asm/irq_vectors.h>
Brian Gerst40d2e762010-03-21 09:00:43 -040057#include <asm/cpufeature.h>
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -040058#include <asm/alternative-asm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Roland McGrathaf0575b2008-06-24 04:16:52 -070060/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
61#include <linux/elf-em.h>
62#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
63#define __AUDIT_ARCH_LE 0x40000000
64
65#ifndef CONFIG_AUDITSYSCALL
66#define sysenter_audit syscall_trace_entry
67#define sysexit_audit syscall_exit_work
68#endif
69
Jiri Olsaea714542011-03-07 19:10:39 +010070 .section .entry.text, "ax"
71
Rusty Russell139ec7c2006-12-07 02:14:08 +010072/*
73 * We use macros for low-level operations which need to be overridden
74 * for paravirtualization. The following will never clobber any registers:
75 * INTERRUPT_RETURN (aka. "iret")
76 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -040077 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010078 *
79 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
80 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
81 * Allowing a register to be clobbered can shrink the paravirt replacement
82 * enough to patch inline, increasing performance.
83 */
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#ifdef CONFIG_PREEMPT
Rusty Russell139ec7c2006-12-07 02:14:08 +010086#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#else
Rusty Russell139ec7c2006-12-07 02:14:08 +010088#define preempt_stop(clobbers)
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +020089#define resume_kernel restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#endif
91
Ingo Molnar55f327f2006-07-03 00:24:43 -070092.macro TRACE_IRQS_IRET
93#ifdef CONFIG_TRACE_IRQFLAGS
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030094 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off?
Ingo Molnar55f327f2006-07-03 00:24:43 -070095 jz 1f
96 TRACE_IRQS_ON
971:
98#endif
99.endm
100
Tejun Heoccbeed32009-02-09 22:17:40 +0900101/*
102 * User gs save/restore
103 *
104 * %gs is used for userland TLS and kernel only uses it for stack
105 * canary which is required to be at %gs:20 by gcc. Read the comment
106 * at the top of stackprotector.h for more info.
107 *
108 * Local labels 98 and 99 are used.
109 */
110#ifdef CONFIG_X86_32_LAZY_GS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Tejun Heoccbeed32009-02-09 22:17:40 +0900112 /* unfortunately push/pop can't be no-op */
113.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100114 pushl_cfi $0
Tejun Heoccbeed32009-02-09 22:17:40 +0900115.endm
116.macro POP_GS pop=0
117 addl $(4 + \pop), %esp
118 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
119.endm
120.macro POP_GS_EX
121.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Tejun Heoccbeed32009-02-09 22:17:40 +0900123 /* all the rest are no-op */
124.macro PTGS_TO_GS
125.endm
126.macro PTGS_TO_GS_EX
127.endm
128.macro GS_TO_REG reg
129.endm
130.macro REG_TO_PTGS reg
131.endm
132.macro SET_KERNEL_GS reg
133.endm
134
135#else /* CONFIG_X86_32_LAZY_GS */
136
137.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100138 pushl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900139 /*CFI_REL_OFFSET gs, 0*/
140.endm
141
142.macro POP_GS pop=0
Jan Beulichdf5d1872010-09-02 14:07:16 +010014398: popl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900144 /*CFI_RESTORE gs*/
145 .if \pop <> 0
146 add $\pop, %esp
147 CFI_ADJUST_CFA_OFFSET -\pop
148 .endif
149.endm
150.macro POP_GS_EX
151.pushsection .fixup, "ax"
15299: movl $0, (%esp)
153 jmp 98b
154.section __ex_table, "a"
155 .align 4
156 .long 98b, 99b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100157.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900158.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Tejun Heoccbeed32009-02-09 22:17:40 +0900160.macro PTGS_TO_GS
16198: mov PT_GS(%esp), %gs
162.endm
163.macro PTGS_TO_GS_EX
164.pushsection .fixup, "ax"
16599: movl $0, PT_GS(%esp)
166 jmp 98b
167.section __ex_table, "a"
168 .align 4
169 .long 98b, 99b
170.popsection
171.endm
172
173.macro GS_TO_REG reg
174 movl %gs, \reg
175 /*CFI_REGISTER gs, \reg*/
176.endm
177.macro REG_TO_PTGS reg
178 movl \reg, PT_GS(%esp)
179 /*CFI_REL_OFFSET gs, PT_GS*/
180.endm
181.macro SET_KERNEL_GS reg
Tejun Heo60a53172009-02-09 22:17:40 +0900182 movl $(__KERNEL_STACK_CANARY), \reg
Tejun Heoccbeed32009-02-09 22:17:40 +0900183 movl \reg, %gs
184.endm
185
186#endif /* CONFIG_X86_32_LAZY_GS */
187
Tejun Heof0d96112009-02-09 22:17:40 +0900188.macro SAVE_ALL
189 cld
Tejun Heoccbeed32009-02-09 22:17:40 +0900190 PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100191 pushl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900192 /*CFI_REL_OFFSET fs, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100193 pushl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900194 /*CFI_REL_OFFSET es, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100195 pushl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900196 /*CFI_REL_OFFSET ds, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100197 pushl_cfi %eax
Tejun Heof0d96112009-02-09 22:17:40 +0900198 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100199 pushl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900200 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100201 pushl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900202 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100203 pushl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900204 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100205 pushl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900206 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100207 pushl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900208 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100209 pushl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900210 CFI_REL_OFFSET ebx, 0
211 movl $(__USER_DS), %edx
212 movl %edx, %ds
213 movl %edx, %es
214 movl $(__KERNEL_PERCPU), %edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 movl %edx, %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900216 SET_KERNEL_GS %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900217.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Tejun Heof0d96112009-02-09 22:17:40 +0900219.macro RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100220 popl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900221 CFI_RESTORE ebx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100222 popl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900223 CFI_RESTORE ecx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100224 popl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900225 CFI_RESTORE edx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100226 popl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900227 CFI_RESTORE esi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100228 popl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900229 CFI_RESTORE edi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100230 popl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900231 CFI_RESTORE ebp
Jan Beulichdf5d1872010-09-02 14:07:16 +0100232 popl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 CFI_RESTORE eax
Tejun Heof0d96112009-02-09 22:17:40 +0900234.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Tejun Heoccbeed32009-02-09 22:17:40 +0900236.macro RESTORE_REGS pop=0
Tejun Heof0d96112009-02-09 22:17:40 +0900237 RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +01002381: popl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900239 /*CFI_RESTORE ds;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002402: popl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900241 /*CFI_RESTORE es;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002423: popl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900243 /*CFI_RESTORE fs;*/
Tejun Heoccbeed32009-02-09 22:17:40 +0900244 POP_GS \pop
Tejun Heof0d96112009-02-09 22:17:40 +0900245.pushsection .fixup, "ax"
2464: movl $0, (%esp)
247 jmp 1b
2485: movl $0, (%esp)
249 jmp 2b
2506: movl $0, (%esp)
251 jmp 3b
252.section __ex_table, "a"
253 .align 4
254 .long 1b, 4b
255 .long 2b, 5b
256 .long 3b, 6b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900258 POP_GS_EX
Tejun Heof0d96112009-02-09 22:17:40 +0900259.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Tejun Heof0d96112009-02-09 22:17:40 +0900261.macro RING0_INT_FRAME
262 CFI_STARTPROC simple
263 CFI_SIGNAL_FRAME
264 CFI_DEF_CFA esp, 3*4
265 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200266 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900267.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200268
Tejun Heof0d96112009-02-09 22:17:40 +0900269.macro RING0_EC_FRAME
270 CFI_STARTPROC simple
271 CFI_SIGNAL_FRAME
272 CFI_DEF_CFA esp, 4*4
273 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200274 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900275.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200276
Tejun Heof0d96112009-02-09 22:17:40 +0900277.macro RING0_PTREGS_FRAME
278 CFI_STARTPROC simple
279 CFI_SIGNAL_FRAME
280 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
281 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
282 CFI_OFFSET eip, PT_EIP-PT_OLDESP
283 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
284 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
285 CFI_OFFSET eax, PT_EAX-PT_OLDESP
286 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
287 CFI_OFFSET edi, PT_EDI-PT_OLDESP
288 CFI_OFFSET esi, PT_ESI-PT_OLDESP
289 CFI_OFFSET edx, PT_EDX-PT_OLDESP
290 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100291 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Tejun Heof0d96112009-02-09 22:17:40 +0900292.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200295 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +0100296 pushl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 call schedule_tail
298 GET_THREAD_INFO(%ebp)
Jan Beulichdf5d1872010-09-02 14:07:16 +0100299 popl_cfi %eax
300 pushl_cfi $0x0202 # Reset kernel eflags
301 popfl_cfi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200303 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100304END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306/*
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400307 * Interrupt exit functions should be protected against kprobes
308 */
309 .pushsection .kprobes.text, "ax"
310/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 * Return to user mode is not as complex as all this looks,
312 * but we want the default path for a system call return to
313 * go as quickly as possible which is why some of this is
314 * less clear than it otherwise should be.
315 */
316
317 # userspace resumption stub bypassing syscall exit tracing
318 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200319 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100321 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322ret_from_intr:
323 GET_THREAD_INFO(%ebp)
Dmitry Adamushko29a2e282012-03-22 21:39:25 +0100324resume_userspace_sig:
325#ifdef CONFIG_VM86
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100326 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
327 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300328 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Dmitry Adamushko29a2e282012-03-22 21:39:25 +0100329#else
330 /*
331 * We can be coming here from a syscall done in the kernel space,
332 * e.g. a failed kernel_execve().
333 */
334 movl PT_CS(%esp), %eax
335 andl $SEGMENT_RPL_MASK, %eax
336#endif
Rusty Russell78be3702006-09-26 10:52:39 +0200337 cmpl $USER_RPL, %eax
338 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200341 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100342 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 # setting need_resched or sigpending
344 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200345 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 movl TI_flags(%ebp), %ecx
347 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
348 # int/exception return?
349 jne work_pending
350 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100351END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353#ifdef CONFIG_PREEMPT
354ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100355 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200357 jnz restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358need_resched:
359 movl TI_flags(%ebp), %ecx # need_resched set ?
360 testb $_TIF_NEED_RESCHED, %cl
361 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300362 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 jz restore_all
364 call preempt_schedule_irq
365 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100366END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200368 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400369/*
370 * End of kprobes section
371 */
372 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374/* SYSENTER_RETURN points to after the "sysenter" instruction in
375 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
376
377 # sysenter call handler stub
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100378ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200379 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200380 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200381 CFI_DEF_CFA esp, 0
382 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100383 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700385 /*
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700386 * Interrupts are disabled here, but we can't trace it until
387 * enough kernel state to call TRACE_IRQS_OFF can be called - but
388 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700389 */
Jan Beulich32342822010-10-19 14:52:26 +0100390 pushl_cfi $__USER_DS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200391 /*CFI_REL_OFFSET ss, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100392 pushl_cfi %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200393 CFI_REL_OFFSET esp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100394 pushfl_cfi
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700395 orl $X86_EFLAGS_IF, (%esp)
Jan Beulich32342822010-10-19 14:52:26 +0100396 pushl_cfi $__USER_CS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200397 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700398 /*
399 * Push current_thread_info()->sysenter_return to the stack.
400 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
401 * pushed above; +8 corresponds to copy_thread's esp0 setting.
402 */
Stratos Psomadakis7bf04be2011-02-25 22:46:13 +0200403 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200404 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Jan Beulichdf5d1872010-09-02 14:07:16 +0100406 pushl_cfi %eax
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700407 SAVE_ALL
408 ENABLE_INTERRUPTS(CLBR_NONE)
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410/*
411 * Load the potential sixth argument from user stack.
412 * Careful about security.
413 */
414 cmpl $__PAGE_OFFSET-3,%ebp
415 jae syscall_fault
4161: movl (%ebp),%ebp
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700417 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418.section __ex_table,"a"
419 .align 4
420 .long 1b,syscall_fault
421.previous
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 GET_THREAD_INFO(%ebp)
424
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530425 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700426 jnz sysenter_audit
427sysenter_do_call:
H. Peter Anvin303395a2011-11-11 16:07:41 -0800428 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 jae syscall_badsys
430 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100431 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200432 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200433 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700434 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530436 testl $_TIF_ALLWORK_MASK, %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700437 jne sysexit_audit
438sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100440 movl PT_EIP(%esp), %edx
441 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700443 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004441: mov PT_FS(%esp), %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900445 PTGS_TO_GS
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400446 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700447
448#ifdef CONFIG_AUDITSYSCALL
449sysenter_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530450 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700451 jnz syscall_trace_entry
452 addl $4,%esp
453 CFI_ADJUST_CFA_OFFSET -4
454 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
455 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
456 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
457 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
458 movl %eax,%edx /* 2nd arg: syscall number */
459 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
Eric Parisb05d8442012-01-03 14:23:06 -0500460 call __audit_syscall_entry
Jan Beulichdf5d1872010-09-02 14:07:16 +0100461 pushl_cfi %ebx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700462 movl PT_EAX(%esp),%eax /* reload syscall number */
463 jmp sysenter_do_call
464
465sysexit_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530466 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700467 jne syscall_exit_work
468 TRACE_IRQS_ON
469 ENABLE_INTERRUPTS(CLBR_ANY)
470 movl %eax,%edx /* second arg, syscall return value */
Eric Parisd7e75282012-01-03 14:23:06 -0500471 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
472 setbe %al /* 1 if so, 0 if not */
Roland McGrathaf0575b2008-06-24 04:16:52 -0700473 movzbl %al,%eax /* zero-extend that */
Eric Parisd7e75282012-01-03 14:23:06 -0500474 call __audit_syscall_exit
Roland McGrathaf0575b2008-06-24 04:16:52 -0700475 DISABLE_INTERRUPTS(CLBR_ANY)
476 TRACE_IRQS_OFF
477 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530478 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700479 jne syscall_exit_work
480 movl PT_EAX(%esp),%eax /* reload syscall return value */
481 jmp sysenter_exit
482#endif
483
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200484 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100485.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004862: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100487 jmp 1b
488.section __ex_table,"a"
489 .align 4
490 .long 1b,2b
491.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900492 PTGS_TO_GS_EX
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100493ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400495/*
496 * syscall stub including irq exit should be protected against kprobes
497 */
498 .pushsection .kprobes.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 # system call handler stub
500ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200501 RING0_INT_FRAME # can't unwind into user space anyway
Jan Beulichdf5d1872010-09-02 14:07:16 +0100502 pushl_cfi %eax # save orig_eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 SAVE_ALL
504 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700505 # system call tracing in operation / emulation
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530506 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 jnz syscall_trace_entry
H. Peter Anvin303395a2011-11-11 16:07:41 -0800508 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 jae syscall_badsys
510syscall_call:
511 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100512 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200514 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100515 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 # setting need_resched or sigpending
517 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700518 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530520 testl $_TIF_ALLWORK_MASK, %ecx # current->work
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 jne syscall_exit_work
522
523restore_all:
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200524 TRACE_IRQS_IRET
525restore_all_notrace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100526 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
527 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700528 # are returning to the kernel.
529 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100530 movb PT_OLDSS(%esp), %ah
531 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300532 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200533 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200534 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 je ldt_ss # returning to user-space with LDT SS
536restore_nocheck:
Tejun Heoccbeed32009-02-09 22:17:40 +0900537 RESTORE_REGS 4 # skip orig_eax/error_code
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200538irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100539 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700541ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700542 pushl $0 # no error code
543 pushl $do_iret_error
544 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545.previous
546.section __ex_table,"a"
547 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100548 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549.previous
550
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200551 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100553 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 jnz restore_nocheck
555 testl $0x00400000, %eax # returning to 32bit stack?
556 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100557
558#ifdef CONFIG_PARAVIRT
559 /*
560 * The kernel can't run on a non-flat stack if paravirt mode
561 * is active. Rather than try to fixup the high bits of
562 * ESP, bypass this code entirely. This may break DOSemu
563 * and/or Wine support in a paravirt VM, although the option
564 * is still available to implement the setting of the high
565 * 16-bits in the INTERRUPT_RETURN paravirt-op.
566 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700567 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100568 jne restore_nocheck
569#endif
570
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200571/*
572 * Setup and switch to ESPFIX stack
573 *
574 * We're returning to userspace with a 16 bit stack. The CPU will not
575 * restore the high word of ESP for us on executing iret... This is an
576 * "official" bug of all the x86-compatible CPUs, which we can work
577 * around to make dosemu and wine happy. We do this by preloading the
578 * high word of ESP with the high word of the userspace ESP while
579 * compensating for the offset by changing to the ESPFIX segment with
580 * a base address that matches for the difference.
581 */
Brian Gerst72c511d2010-07-31 12:48:23 -0400582#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200583 mov %esp, %edx /* load kernel esp */
584 mov PT_OLDESP(%esp), %eax /* load userspace esp */
585 mov %dx, %ax /* eax: new kernel esp */
586 sub %eax, %edx /* offset (low word is 0) */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200587 shr $16, %edx
Brian Gerst72c511d2010-07-31 12:48:23 -0400588 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
589 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100590 pushl_cfi $__ESPFIX_SS
591 pushl_cfi %eax /* new kernel esp */
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200592 /* Disable interrupts, but do not irqtrace this section: we
593 * will soon execute iret and the tracer was already set to
594 * the irqstate after the iret */
Rusty Russell139ec7c2006-12-07 02:14:08 +0100595 DISABLE_INTERRUPTS(CLBR_EAX)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200596 lss (%esp), %esp /* switch to espfix segment */
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100597 CFI_ADJUST_CFA_OFFSET -8
598 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200599 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100600ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 # perform work that needs to be done immediately before resumption
603 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200604 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605work_pending:
606 testb $_TIF_NEED_RESCHED, %cl
607 jz work_notifysig
608work_resched:
609 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200610 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100611 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 # setting need_resched or sigpending
613 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700614 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 movl TI_flags(%ebp), %ecx
616 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
617 # than syscall tracing?
618 jz restore_all
619 testb $_TIF_NEED_RESCHED, %cl
620 jnz work_resched
621
622work_notifysig: # deal with pending signals and
623 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100624#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300625 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 movl %esp, %eax
627 jne work_notifysig_v86 # returning to kernel-space or
628 # vm86-space
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530629 TRACE_IRQS_ON
630 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 xorl %edx, %edx
632 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700633 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 ALIGN
636work_notifysig_v86:
Jan Beulichdf5d1872010-09-02 14:07:16 +0100637 pushl_cfi %ecx # save ti_flags for do_notify_resume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 call save_v86_state # %eax contains pt_regs pointer
Jan Beulichdf5d1872010-09-02 14:07:16 +0100639 popl_cfi %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100641#else
642 movl %esp, %eax
643#endif
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530644 TRACE_IRQS_ON
645 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 xorl %edx, %edx
647 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700648 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100649END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 # perform syscall exit tracing
652 ALIGN
653syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100654 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700656 call syscall_trace_enter
657 /* What it returned is what we'll actually use. */
H. Peter Anvin303395a2011-11-11 16:07:41 -0800658 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 jnae syscall_call
660 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100661END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 # perform syscall exit tracing
664 ALIGN
665syscall_exit_work:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530666 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700668 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700669 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 # schedule() instead
671 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700672 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100674END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200675 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200677 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100680 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100682END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100685 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100687END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200688 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400689/*
690 * End of kprobes section
691 */
692 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Brian Gerst253f29a2009-02-10 09:51:46 -0500694/*
695 * System calls that need a pt_regs pointer.
696 */
Brian Gerste258e4e2009-12-09 19:01:51 -0500697#define PTREGSCALL0(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800698ENTRY(ptregs_##name) ; \
Brian Gerst253f29a2009-02-10 09:51:46 -0500699 leal 4(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800700 jmp sys_##name; \
701ENDPROC(ptregs_##name)
Brian Gerst253f29a2009-02-10 09:51:46 -0500702
Brian Gerste258e4e2009-12-09 19:01:51 -0500703#define PTREGSCALL1(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800704ENTRY(ptregs_##name) ; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500705 leal 4(%esp),%edx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800706 movl (PT_EBX+4)(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800707 jmp sys_##name; \
708ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500709
710#define PTREGSCALL2(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800711ENTRY(ptregs_##name) ; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500712 leal 4(%esp),%ecx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800713 movl (PT_ECX+4)(%esp),%edx; \
714 movl (PT_EBX+4)(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800715 jmp sys_##name; \
716ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500717
718#define PTREGSCALL3(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800719ENTRY(ptregs_##name) ; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100720 CFI_STARTPROC; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500721 leal 4(%esp),%eax; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100722 pushl_cfi %eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500723 movl PT_EDX(%eax),%ecx; \
724 movl PT_ECX(%eax),%edx; \
725 movl PT_EBX(%eax),%eax; \
726 call sys_##name; \
727 addl $4,%esp; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100728 CFI_ADJUST_CFA_OFFSET -4; \
729 ret; \
730 CFI_ENDPROC; \
731ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500732
Brian Gerst27f59552009-12-09 19:01:52 -0500733PTREGSCALL1(iopl)
Brian Gerste258e4e2009-12-09 19:01:51 -0500734PTREGSCALL0(fork)
Brian Gerste258e4e2009-12-09 19:01:51 -0500735PTREGSCALL0(vfork)
Brian Gerst11cf88b2009-12-09 19:01:53 -0500736PTREGSCALL3(execve)
Brian Gerst052acad2009-12-09 19:01:54 -0500737PTREGSCALL2(sigaltstack)
Brian Gerste258e4e2009-12-09 19:01:51 -0500738PTREGSCALL0(sigreturn)
739PTREGSCALL0(rt_sigreturn)
Brian Gerstf1382f12009-12-09 19:01:55 -0500740PTREGSCALL2(vm86)
741PTREGSCALL1(vm86old)
Brian Gerst253f29a2009-02-10 09:51:46 -0500742
Brian Gerstf839bbc2009-12-09 19:01:56 -0500743/* Clone is an oddball. The 4th arg is in %edi */
H. Peter Anvin303395a2011-11-11 16:07:41 -0800744ENTRY(ptregs_clone)
Jan Beulicha34107b2010-09-02 14:04:16 +0100745 CFI_STARTPROC
Brian Gerstf839bbc2009-12-09 19:01:56 -0500746 leal 4(%esp),%eax
Jan Beulicha34107b2010-09-02 14:04:16 +0100747 pushl_cfi %eax
748 pushl_cfi PT_EDI(%eax)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500749 movl PT_EDX(%eax),%ecx
750 movl PT_ECX(%eax),%edx
751 movl PT_EBX(%eax),%eax
752 call sys_clone
753 addl $8,%esp
Jan Beulicha34107b2010-09-02 14:04:16 +0100754 CFI_ADJUST_CFA_OFFSET -8
Brian Gerstf839bbc2009-12-09 19:01:56 -0500755 ret
Jan Beulicha34107b2010-09-02 14:04:16 +0100756 CFI_ENDPROC
757ENDPROC(ptregs_clone)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500758
Tejun Heof0d96112009-02-09 22:17:40 +0900759.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200760/*
761 * Switch back for ESPFIX stack to the normal zerobased stack
762 *
763 * We can't call C functions using the ESPFIX stack. This code reads
764 * the high word of the segment base from the GDT and swiches to the
765 * normal stack and adjusts ESP with the matching offset.
766 */
767 /* fixup the stack */
Brian Gerst72c511d2010-07-31 12:48:23 -0400768 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
769 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200770 shl $16, %eax
771 addl %esp, %eax /* the adjusted stack pointer */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100772 pushl_cfi $__KERNEL_DS
773 pushl_cfi %eax
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200774 lss (%esp), %esp /* switch to the normal stack segment */
Tejun Heof0d96112009-02-09 22:17:40 +0900775 CFI_ADJUST_CFA_OFFSET -8
776.endm
777.macro UNWIND_ESPFIX_STACK
778 movl %ss, %eax
779 /* see if on espfix stack */
780 cmpw $__ESPFIX_SS, %ax
781 jne 27f
782 movl $__KERNEL_DS, %eax
783 movl %eax, %ds
784 movl %eax, %es
785 /* switch to normal stack */
786 FIXUP_ESPFIX_STACK
78727:
788.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800791 * Build the entry stubs and pointer table with some assembler magic.
792 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
793 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800795.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796ENTRY(interrupt)
Jiri Olsaea714542011-03-07 19:10:39 +0100797.section .entry.text, "ax"
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800798 .p2align 5
799 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200801 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800802vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800803.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
804 .balign 32
805 .rept 7
806 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800807 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200808 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800809 .endif
Jan Beulichdf5d1872010-09-02 14:07:16 +01008101: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
H. Peter Anvin86655962008-11-12 10:27:35 -0800811 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800812 jmp 2f
813 .endif
814 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 .long 1b
Jiri Olsaea714542011-03-07 19:10:39 +0100816 .section .entry.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800818 .endif
819 .endr
8202: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100822END(irq_entries_start)
823
824.previous
825END(interrupt)
826.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Ingo Molnar55f327f2006-07-03 00:24:43 -0700828/*
829 * the CPU automatically disables interrupts when executing an IRQ vector,
830 * so IRQ-flags tracing has to follow that:
831 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800832 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800834 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700836 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 movl %esp,%eax
838 call do_IRQ
839 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100840ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200841 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400843/*
844 * Irq entries should be protected against kprobes
845 */
846 .pushsection .kprobes.text, "ax"
Tejun Heo02cf94c2009-01-21 17:26:06 +0900847#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200849 RING0_INT_FRAME; \
Jan Beulichdf5d1872010-09-02 14:07:16 +0100850 pushl_cfi $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200851 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700852 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900854 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700855 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100856 CFI_ENDPROC; \
857ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Tejun Heo02cf94c2009-01-21 17:26:06 +0900859#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100862#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200865 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100866 pushl_cfi $0
867 pushl_cfi $do_coprocessor_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200869 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100870END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200873 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100874 pushl_cfi $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400875#ifdef CONFIG_X86_INVD_BUG
876 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100877661: pushl_cfi $do_general_protection
Brian Gerst40d2e762010-03-21 09:00:43 -0400878662:
879.section .altinstructions,"a"
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -0400880 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
Brian Gerst40d2e762010-03-21 09:00:43 -0400881.previous
882.section .altinstr_replacement,"ax"
883663: pushl $do_simd_coprocessor_error
884664:
885.previous
886#else
Jan Beulichdf5d1872010-09-02 14:07:16 +0100887 pushl_cfi $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400888#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200890 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100891END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200894 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100895 pushl_cfi $-1 # mark this as an int
896 pushl_cfi $do_device_not_available
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200897 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200898 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100899END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Rusty Russelld3561b72006-12-07 02:14:07 +0100901#ifdef CONFIG_PARAVIRT
902ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100903 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100904.section __ex_table,"a"
905 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100906 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100907.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100908END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100909
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400910ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100911 sti
912 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400913END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100914#endif
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200917 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100918 pushl_cfi $0
919 pushl_cfi $do_overflow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200921 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100922END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200925 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100926 pushl_cfi $0
927 pushl_cfi $do_bounds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200929 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100930END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200933 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100934 pushl_cfi $0
935 pushl_cfi $do_invalid_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200937 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100938END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200941 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100942 pushl_cfi $0
943 pushl_cfi $do_coprocessor_segment_overrun
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(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
948ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200949 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100950 pushl_cfi $do_invalid_TSS
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(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200956 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100957 pushl_cfi $do_segment_not_present
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(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100964 pushl_cfi $do_stack_segment
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(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200970 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100971 pushl_cfi $do_alignment_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200973 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100974END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200976ENTRY(divide_error)
977 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100978 pushl_cfi $0 # no error code
979 pushl_cfi $do_divide_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200981 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100982END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
984#ifdef CONFIG_X86_MCE
985ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200986 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100987 pushl_cfi $0
988 pushl_cfi machine_check_vector
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200990 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100991END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992#endif
993
994ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200995 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100996 pushl_cfi $0
997 pushl_cfi $do_spurious_interrupt_bug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200999 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001000END(spurious_interrupt_bug)
Masami Hiramatsua00e8172009-09-08 12:47:55 -04001001/*
1002 * End of kprobes section
1003 */
1004 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005
Andi Kleen02ba1a32006-09-26 10:52:35 +02001006ENTRY(kernel_thread_helper)
1007 pushl $0 # fake return address for unwinder
1008 CFI_STARTPROC
Brian Gerste8402272009-12-09 12:34:42 -05001009 movl %edi,%eax
1010 call *%esi
Andi Kleen02ba1a32006-09-26 10:52:35 +02001011 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001012 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +02001013 CFI_ENDPROC
1014ENDPROC(kernel_thread_helper)
1015
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001016#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001017/* Xen doesn't set %esp to be precisely what the normal sysenter
1018 entrypoint expects, so fix it up before using the normal path. */
1019ENTRY(xen_sysenter_target)
1020 RING0_INT_FRAME
1021 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001022 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001023 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001024 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001025
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001026ENTRY(xen_hypervisor_callback)
1027 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001028 pushl_cfi $0
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001029 SAVE_ALL
1030 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001031
1032 /* Check to see if we got the event in the critical
1033 region in xen_iret_direct, after we've reenabled
1034 events and checked for pending events. This simulates
1035 iret instruction's behaviour where it delivers a
1036 pending interrupt when enabling interrupts. */
1037 movl PT_EIP(%esp),%eax
1038 cmpl $xen_iret_start_crit,%eax
1039 jb 1f
1040 cmpl $xen_iret_end_crit,%eax
1041 jae 1f
1042
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001043 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001044
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001045ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010461: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001047 call xen_evtchn_do_upcall
1048 jmp ret_from_intr
1049 CFI_ENDPROC
1050ENDPROC(xen_hypervisor_callback)
1051
1052# Hypervisor uses this for application faults while it executes.
1053# We get here for two reasons:
1054# 1. Fault while reloading DS, ES, FS or GS
1055# 2. Fault while executing IRET
1056# Category 1 we fix up by reattempting the load, and zeroing the segment
1057# register if the load fails.
1058# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1059# normal Linux return path in this case because if we use the IRET hypercall
1060# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1061# We distinguish between categories by maintaining a status value in EAX.
1062ENTRY(xen_failsafe_callback)
1063 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001064 pushl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001065 movl $1,%eax
10661: mov 4(%esp),%ds
10672: mov 8(%esp),%es
10683: mov 12(%esp),%fs
10694: mov 16(%esp),%gs
1070 testl %eax,%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001071 popl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001072 lea 16(%esp),%esp
1073 CFI_ADJUST_CFA_OFFSET -16
1074 jz 5f
1075 addl $16,%esp
1076 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
Jan Beulichdf5d1872010-09-02 14:07:16 +010010775: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001078 SAVE_ALL
1079 jmp ret_from_exception
1080 CFI_ENDPROC
1081
1082.section .fixup,"ax"
10836: xorl %eax,%eax
1084 movl %eax,4(%esp)
1085 jmp 1b
10867: xorl %eax,%eax
1087 movl %eax,8(%esp)
1088 jmp 2b
10898: xorl %eax,%eax
1090 movl %eax,12(%esp)
1091 jmp 3b
10929: xorl %eax,%eax
1093 movl %eax,16(%esp)
1094 jmp 4b
1095.previous
1096.section __ex_table,"a"
1097 .align 4
1098 .long 1b,6b
1099 .long 2b,7b
1100 .long 3b,8b
1101 .long 4b,9b
1102.previous
1103ENDPROC(xen_failsafe_callback)
1104
Sheng Yang38e20b02010-05-14 12:40:51 +01001105BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1106 xen_evtchn_do_upcall)
1107
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001108#endif /* CONFIG_XEN */
1109
Steven Rostedt606576c2008-10-06 19:06:12 -04001110#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001111#ifdef CONFIG_DYNAMIC_FTRACE
1112
1113ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001114 ret
1115END(mcount)
1116
1117ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001118 cmpl $0, function_trace_stop
1119 jne ftrace_stub
1120
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001121 pushl %eax
1122 pushl %ecx
1123 pushl %edx
1124 movl 0xc(%esp), %eax
1125 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301126 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001127
1128.globl ftrace_call
1129ftrace_call:
1130 call ftrace_stub
1131
1132 popl %edx
1133 popl %ecx
1134 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001135#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1136.globl ftrace_graph_call
1137ftrace_graph_call:
1138 jmp ftrace_stub
1139#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001140
1141.globl ftrace_stub
1142ftrace_stub:
1143 ret
1144END(ftrace_caller)
1145
1146#else /* ! CONFIG_DYNAMIC_FTRACE */
1147
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001148ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001149 cmpl $0, function_trace_stop
1150 jne ftrace_stub
1151
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001152 cmpl $ftrace_stub, ftrace_trace_function
1153 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001154#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001155 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001156 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001157
1158 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1159 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001160#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001161.globl ftrace_stub
1162ftrace_stub:
1163 ret
1164
1165 /* taken from glibc */
1166trace:
1167 pushl %eax
1168 pushl %ecx
1169 pushl %edx
1170 movl 0xc(%esp), %eax
1171 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301172 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001173
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001174 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001175
1176 popl %edx
1177 popl %ecx
1178 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001179 jmp ftrace_stub
1180END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001181#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001182#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001183
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001184#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1185ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001186 cmpl $0, function_trace_stop
1187 jne ftrace_stub
1188
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001189 pushl %eax
1190 pushl %ecx
1191 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001192 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001193 lea 0x4(%ebp), %eax
Steven Rostedt71e308a2009-06-18 12:45:08 -04001194 movl (%ebp), %ecx
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001195 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001196 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001197 popl %edx
1198 popl %ecx
1199 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001200 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001201END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001202
1203.globl return_to_handler
1204return_to_handler:
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001205 pushl %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001206 pushl %edx
Steven Rostedt71e308a2009-06-18 12:45:08 -04001207 movl %ebp, %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001208 call ftrace_return_to_handler
Steven Rostedt194ec342009-10-13 16:33:50 -04001209 movl %eax, %ecx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001210 popl %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001211 popl %eax
Steven Rostedt194ec342009-10-13 16:33:50 -04001212 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001213#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001215/*
1216 * Some functions should be protected against kprobes
1217 */
1218 .pushsection .kprobes.text, "ax"
1219
1220ENTRY(page_fault)
1221 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001222 pushl_cfi $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001223 ALIGN
1224error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001225 /* the function address is in %gs's slot on the stack */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001226 pushl_cfi %fs
Tejun Heoccbeed32009-02-09 22:17:40 +09001227 /*CFI_REL_OFFSET fs, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001228 pushl_cfi %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001229 /*CFI_REL_OFFSET es, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001230 pushl_cfi %ds
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001231 /*CFI_REL_OFFSET ds, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001232 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001233 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001234 pushl_cfi %ebp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001235 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001236 pushl_cfi %edi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001237 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001238 pushl_cfi %esi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001239 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001240 pushl_cfi %edx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001241 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001242 pushl_cfi %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001243 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001244 pushl_cfi %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001245 CFI_REL_OFFSET ebx, 0
1246 cld
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001247 movl $(__KERNEL_PERCPU), %ecx
1248 movl %ecx, %fs
1249 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001250 GS_TO_REG %ecx
1251 movl PT_GS(%esp), %edi # get the function address
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001252 movl PT_ORIG_EAX(%esp), %edx # get the error code
1253 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001254 REG_TO_PTGS %ecx
1255 SET_KERNEL_GS %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001256 movl $(__USER_DS), %ecx
1257 movl %ecx, %ds
1258 movl %ecx, %es
1259 TRACE_IRQS_OFF
1260 movl %esp,%eax # pt_regs pointer
1261 call *%edi
1262 jmp ret_from_exception
1263 CFI_ENDPROC
1264END(page_fault)
1265
1266/*
1267 * Debug traps and NMI can happen at the one SYSENTER instruction
1268 * that sets up the real kernel stack. Check here, since we can't
1269 * allow the wrong stack to be used.
1270 *
1271 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1272 * already pushed 3 words if it hits on the sysenter instruction:
1273 * eflags, cs and eip.
1274 *
1275 * We just load the right stack, and push the three (known) values
1276 * by hand onto the new stack - while updating the return eip past
1277 * the instruction that would have done it for sysenter.
1278 */
Tejun Heof0d96112009-02-09 22:17:40 +09001279.macro FIX_STACK offset ok label
1280 cmpw $__KERNEL_CS, 4(%esp)
1281 jne \ok
1282\label:
1283 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1284 CFI_DEF_CFA esp, 0
1285 CFI_UNDEFINED eip
Jan Beulichdf5d1872010-09-02 14:07:16 +01001286 pushfl_cfi
1287 pushl_cfi $__KERNEL_CS
1288 pushl_cfi $sysenter_past_esp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001289 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001290.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001291
1292ENTRY(debug)
1293 RING0_INT_FRAME
1294 cmpl $ia32_sysenter_target,(%esp)
1295 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001296 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001297debug_stack_correct:
Jan Beulichdf5d1872010-09-02 14:07:16 +01001298 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001299 SAVE_ALL
1300 TRACE_IRQS_OFF
1301 xorl %edx,%edx # error code 0
1302 movl %esp,%eax # pt_regs pointer
1303 call do_debug
1304 jmp ret_from_exception
1305 CFI_ENDPROC
1306END(debug)
1307
1308/*
1309 * NMI is doubly nasty. It can happen _while_ we're handling
1310 * a debug fault, and the debug fault hasn't yet been able to
1311 * clear up the stack. So we first check whether we got an
1312 * NMI on the sysenter entry path, but after that we need to
1313 * check whether we got an NMI on the debug path where the debug
1314 * fault happened on the sysenter path.
1315 */
1316ENTRY(nmi)
1317 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001318 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001319 movl %ss, %eax
1320 cmpw $__ESPFIX_SS, %ax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001321 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001322 je nmi_espfix_stack
1323 cmpl $ia32_sysenter_target,(%esp)
1324 je nmi_stack_fixup
Jan Beulichdf5d1872010-09-02 14:07:16 +01001325 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001326 movl %esp,%eax
1327 /* Do not access memory above the end of our stack page,
1328 * it might not exist.
1329 */
1330 andl $(THREAD_SIZE-1),%eax
1331 cmpl $(THREAD_SIZE-20),%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001332 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001333 jae nmi_stack_correct
1334 cmpl $ia32_sysenter_target,12(%esp)
1335 je nmi_debug_stack_check
1336nmi_stack_correct:
1337 /* We have a RING0_INT_FRAME here */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001338 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001339 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001340 xorl %edx,%edx # zero error code
1341 movl %esp,%eax # pt_regs pointer
1342 call do_nmi
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +02001343 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001344 CFI_ENDPROC
1345
1346nmi_stack_fixup:
1347 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001348 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001349 jmp nmi_stack_correct
1350
1351nmi_debug_stack_check:
1352 /* We have a RING0_INT_FRAME here */
1353 cmpw $__KERNEL_CS,16(%esp)
1354 jne nmi_stack_correct
1355 cmpl $debug,(%esp)
1356 jb nmi_stack_correct
1357 cmpl $debug_esp_fix_insn,(%esp)
1358 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001359 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001360 jmp nmi_stack_correct
1361
1362nmi_espfix_stack:
1363 /* We have a RING0_INT_FRAME here.
1364 *
1365 * create the pointer to lss back
1366 */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001367 pushl_cfi %ss
1368 pushl_cfi %esp
Stas Sergeevbda3a892009-02-23 19:13:07 +03001369 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001370 /* copy the iret frame of 12 bytes */
1371 .rept 3
Jan Beulichdf5d1872010-09-02 14:07:16 +01001372 pushl_cfi 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001373 .endr
Jan Beulichdf5d1872010-09-02 14:07:16 +01001374 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001375 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001376 FIXUP_ESPFIX_STACK # %eax == %esp
1377 xorl %edx,%edx # zero error code
1378 call do_nmi
1379 RESTORE_REGS
1380 lss 12+4(%esp), %esp # back to espfix stack
1381 CFI_ADJUST_CFA_OFFSET -24
1382 jmp irq_return
1383 CFI_ENDPROC
1384END(nmi)
1385
1386ENTRY(int3)
1387 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001388 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001389 SAVE_ALL
1390 TRACE_IRQS_OFF
1391 xorl %edx,%edx # zero error code
1392 movl %esp,%eax # pt_regs pointer
1393 call do_int3
1394 jmp ret_from_exception
1395 CFI_ENDPROC
1396END(int3)
1397
1398ENTRY(general_protection)
1399 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001400 pushl_cfi $do_general_protection
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001401 jmp error_code
1402 CFI_ENDPROC
1403END(general_protection)
1404
Gleb Natapov631bc482010-10-14 11:22:52 +02001405#ifdef CONFIG_KVM_GUEST
1406ENTRY(async_page_fault)
1407 RING0_EC_FRAME
Jan Beulich60cf6372011-02-28 15:54:40 +00001408 pushl_cfi $do_async_page_fault
Gleb Natapov631bc482010-10-14 11:22:52 +02001409 jmp error_code
1410 CFI_ENDPROC
Sedat Dilek2ae9d292011-03-08 22:39:24 +01001411END(async_page_fault)
Gleb Natapov631bc482010-10-14 11:22:52 +02001412#endif
1413
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001414/*
1415 * End of kprobes section
1416 */
1417 .popsection