blob: 79d97e68f04238ac13993e89c016e67a7b647af6 [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
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700101#ifdef CONFIG_VM86
102#define resume_userspace_sig check_userspace
103#else
104#define resume_userspace_sig resume_userspace
105#endif
106
Tejun Heoccbeed32009-02-09 22:17:40 +0900107/*
108 * User gs save/restore
109 *
110 * %gs is used for userland TLS and kernel only uses it for stack
111 * canary which is required to be at %gs:20 by gcc. Read the comment
112 * at the top of stackprotector.h for more info.
113 *
114 * Local labels 98 and 99 are used.
115 */
116#ifdef CONFIG_X86_32_LAZY_GS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Tejun Heoccbeed32009-02-09 22:17:40 +0900118 /* unfortunately push/pop can't be no-op */
119.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100120 pushl_cfi $0
Tejun Heoccbeed32009-02-09 22:17:40 +0900121.endm
122.macro POP_GS pop=0
123 addl $(4 + \pop), %esp
124 CFI_ADJUST_CFA_OFFSET -(4 + \pop)
125.endm
126.macro POP_GS_EX
127.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Tejun Heoccbeed32009-02-09 22:17:40 +0900129 /* all the rest are no-op */
130.macro PTGS_TO_GS
131.endm
132.macro PTGS_TO_GS_EX
133.endm
134.macro GS_TO_REG reg
135.endm
136.macro REG_TO_PTGS reg
137.endm
138.macro SET_KERNEL_GS reg
139.endm
140
141#else /* CONFIG_X86_32_LAZY_GS */
142
143.macro PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100144 pushl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900145 /*CFI_REL_OFFSET gs, 0*/
146.endm
147
148.macro POP_GS pop=0
Jan Beulichdf5d1872010-09-02 14:07:16 +010014998: popl_cfi %gs
Tejun Heoccbeed32009-02-09 22:17:40 +0900150 /*CFI_RESTORE gs*/
151 .if \pop <> 0
152 add $\pop, %esp
153 CFI_ADJUST_CFA_OFFSET -\pop
154 .endif
155.endm
156.macro POP_GS_EX
157.pushsection .fixup, "ax"
15899: movl $0, (%esp)
159 jmp 98b
160.section __ex_table, "a"
161 .align 4
162 .long 98b, 99b
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100163.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900164.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Tejun Heoccbeed32009-02-09 22:17:40 +0900166.macro PTGS_TO_GS
16798: mov PT_GS(%esp), %gs
168.endm
169.macro PTGS_TO_GS_EX
170.pushsection .fixup, "ax"
17199: movl $0, PT_GS(%esp)
172 jmp 98b
173.section __ex_table, "a"
174 .align 4
175 .long 98b, 99b
176.popsection
177.endm
178
179.macro GS_TO_REG reg
180 movl %gs, \reg
181 /*CFI_REGISTER gs, \reg*/
182.endm
183.macro REG_TO_PTGS reg
184 movl \reg, PT_GS(%esp)
185 /*CFI_REL_OFFSET gs, PT_GS*/
186.endm
187.macro SET_KERNEL_GS reg
Tejun Heo60a53172009-02-09 22:17:40 +0900188 movl $(__KERNEL_STACK_CANARY), \reg
Tejun Heoccbeed32009-02-09 22:17:40 +0900189 movl \reg, %gs
190.endm
191
192#endif /* CONFIG_X86_32_LAZY_GS */
193
Tejun Heof0d96112009-02-09 22:17:40 +0900194.macro SAVE_ALL
195 cld
Tejun Heoccbeed32009-02-09 22:17:40 +0900196 PUSH_GS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100197 pushl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900198 /*CFI_REL_OFFSET fs, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100199 pushl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900200 /*CFI_REL_OFFSET es, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100201 pushl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900202 /*CFI_REL_OFFSET ds, 0;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100203 pushl_cfi %eax
Tejun Heof0d96112009-02-09 22:17:40 +0900204 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100205 pushl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900206 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100207 pushl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900208 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100209 pushl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900210 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100211 pushl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900212 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100213 pushl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900214 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100215 pushl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900216 CFI_REL_OFFSET ebx, 0
217 movl $(__USER_DS), %edx
218 movl %edx, %ds
219 movl %edx, %es
220 movl $(__KERNEL_PERCPU), %edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 movl %edx, %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900222 SET_KERNEL_GS %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900223.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Tejun Heof0d96112009-02-09 22:17:40 +0900225.macro RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +0100226 popl_cfi %ebx
Tejun Heof0d96112009-02-09 22:17:40 +0900227 CFI_RESTORE ebx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100228 popl_cfi %ecx
Tejun Heof0d96112009-02-09 22:17:40 +0900229 CFI_RESTORE ecx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100230 popl_cfi %edx
Tejun Heof0d96112009-02-09 22:17:40 +0900231 CFI_RESTORE edx
Jan Beulichdf5d1872010-09-02 14:07:16 +0100232 popl_cfi %esi
Tejun Heof0d96112009-02-09 22:17:40 +0900233 CFI_RESTORE esi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100234 popl_cfi %edi
Tejun Heof0d96112009-02-09 22:17:40 +0900235 CFI_RESTORE edi
Jan Beulichdf5d1872010-09-02 14:07:16 +0100236 popl_cfi %ebp
Tejun Heof0d96112009-02-09 22:17:40 +0900237 CFI_RESTORE ebp
Jan Beulichdf5d1872010-09-02 14:07:16 +0100238 popl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 CFI_RESTORE eax
Tejun Heof0d96112009-02-09 22:17:40 +0900240.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Tejun Heoccbeed32009-02-09 22:17:40 +0900242.macro RESTORE_REGS pop=0
Tejun Heof0d96112009-02-09 22:17:40 +0900243 RESTORE_INT_REGS
Jan Beulichdf5d1872010-09-02 14:07:16 +01002441: popl_cfi %ds
Tejun Heof0d96112009-02-09 22:17:40 +0900245 /*CFI_RESTORE ds;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002462: popl_cfi %es
Tejun Heof0d96112009-02-09 22:17:40 +0900247 /*CFI_RESTORE es;*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01002483: popl_cfi %fs
Tejun Heof0d96112009-02-09 22:17:40 +0900249 /*CFI_RESTORE fs;*/
Tejun Heoccbeed32009-02-09 22:17:40 +0900250 POP_GS \pop
Tejun Heof0d96112009-02-09 22:17:40 +0900251.pushsection .fixup, "ax"
2524: movl $0, (%esp)
253 jmp 1b
2545: movl $0, (%esp)
255 jmp 2b
2566: movl $0, (%esp)
257 jmp 3b
258.section __ex_table, "a"
259 .align 4
260 .long 1b, 4b
261 .long 2b, 5b
262 .long 3b, 6b
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900264 POP_GS_EX
Tejun Heof0d96112009-02-09 22:17:40 +0900265.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Tejun Heof0d96112009-02-09 22:17:40 +0900267.macro RING0_INT_FRAME
268 CFI_STARTPROC simple
269 CFI_SIGNAL_FRAME
270 CFI_DEF_CFA esp, 3*4
271 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200272 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900273.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200274
Tejun Heof0d96112009-02-09 22:17:40 +0900275.macro RING0_EC_FRAME
276 CFI_STARTPROC simple
277 CFI_SIGNAL_FRAME
278 CFI_DEF_CFA esp, 4*4
279 /*CFI_OFFSET cs, -2*4;*/
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200280 CFI_OFFSET eip, -3*4
Tejun Heof0d96112009-02-09 22:17:40 +0900281.endm
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200282
Tejun Heof0d96112009-02-09 22:17:40 +0900283.macro RING0_PTREGS_FRAME
284 CFI_STARTPROC simple
285 CFI_SIGNAL_FRAME
286 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX
287 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/
288 CFI_OFFSET eip, PT_EIP-PT_OLDESP
289 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/
290 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/
291 CFI_OFFSET eax, PT_EAX-PT_OLDESP
292 CFI_OFFSET ebp, PT_EBP-PT_OLDESP
293 CFI_OFFSET edi, PT_EDI-PT_OLDESP
294 CFI_OFFSET esi, PT_ESI-PT_OLDESP
295 CFI_OFFSET edx, PT_EDX-PT_OLDESP
296 CFI_OFFSET ecx, PT_ECX-PT_OLDESP
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100297 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
Tejun Heof0d96112009-02-09 22:17:40 +0900298.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300ENTRY(ret_from_fork)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200301 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +0100302 pushl_cfi %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 call schedule_tail
304 GET_THREAD_INFO(%ebp)
Jan Beulichdf5d1872010-09-02 14:07:16 +0100305 popl_cfi %eax
306 pushl_cfi $0x0202 # Reset kernel eflags
307 popfl_cfi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 jmp syscall_exit
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200309 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100310END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312/*
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400313 * Interrupt exit functions should be protected against kprobes
314 */
315 .pushsection .kprobes.text, "ax"
316/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 * Return to user mode is not as complex as all this looks,
318 * but we want the default path for a system call return to
319 * go as quickly as possible which is why some of this is
320 * less clear than it otherwise should be.
321 */
322
323 # userspace resumption stub bypassing syscall exit tracing
324 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200325 RING0_PTREGS_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326ret_from_exception:
Rusty Russell139ec7c2006-12-07 02:14:08 +0100327 preempt_stop(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328ret_from_intr:
329 GET_THREAD_INFO(%ebp)
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700330check_userspace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100331 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
332 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300333 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200334 cmpl $USER_RPL, %eax
335 jb resume_kernel # not returning to v8086 or userspace
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337ENTRY(resume_userspace)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200338 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100339 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 # setting need_resched or sigpending
341 # between sampling and the iret
Peter Zijlstrae32e58a2008-06-06 10:14:08 +0200342 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 movl TI_flags(%ebp), %ecx
344 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
345 # int/exception return?
346 jne work_pending
347 jmp restore_all
Jan Beulich47a55cd2007-02-13 13:26:24 +0100348END(ret_from_exception)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
350#ifdef CONFIG_PREEMPT
351ENTRY(resume_kernel)
Rusty Russell139ec7c2006-12-07 02:14:08 +0100352 DISABLE_INTERRUPTS(CLBR_ANY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200354 jnz restore_all
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355need_resched:
356 movl TI_flags(%ebp), %ecx # need_resched set ?
357 testb $_TIF_NEED_RESCHED, %cl
358 jz restore_all
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300359 testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 jz restore_all
361 call preempt_schedule_irq
362 jmp need_resched
Jan Beulich47a55cd2007-02-13 13:26:24 +0100363END(resume_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364#endif
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200365 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400366/*
367 * End of kprobes section
368 */
369 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371/* SYSENTER_RETURN points to after the "sysenter" instruction in
372 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
373
374 # sysenter call handler stub
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100375ENTRY(ia32_sysenter_target)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200376 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200377 CFI_SIGNAL_FRAME
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200378 CFI_DEF_CFA esp, 0
379 CFI_REGISTER esp, ebp
H. Peter Anvinfaca6222008-01-30 13:31:02 +0100380 movl TSS_sysenter_sp0(%esp),%esp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381sysenter_past_esp:
Ingo Molnar55f327f2006-07-03 00:24:43 -0700382 /*
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700383 * Interrupts are disabled here, but we can't trace it until
384 * enough kernel state to call TRACE_IRQS_OFF can be called - but
385 * we immediately enable interrupts at that point anyway.
Ingo Molnar55f327f2006-07-03 00:24:43 -0700386 */
Jan Beulich32342822010-10-19 14:52:26 +0100387 pushl_cfi $__USER_DS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200388 /*CFI_REL_OFFSET ss, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +0100389 pushl_cfi %ebp
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200390 CFI_REL_OFFSET esp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +0100391 pushfl_cfi
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700392 orl $X86_EFLAGS_IF, (%esp)
Jan Beulich32342822010-10-19 14:52:26 +0100393 pushl_cfi $__USER_CS
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200394 /*CFI_REL_OFFSET cs, 0*/
Ingo Molnare6e54942006-06-27 02:53:50 -0700395 /*
396 * Push current_thread_info()->sysenter_return to the stack.
397 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
398 * pushed above; +8 corresponds to copy_thread's esp0 setting.
399 */
Stratos Psomadakis7bf04be2011-02-25 22:46:13 +0200400 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200401 CFI_REL_OFFSET eip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Jan Beulichdf5d1872010-09-02 14:07:16 +0100403 pushl_cfi %eax
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700404 SAVE_ALL
405 ENABLE_INTERRUPTS(CLBR_NONE)
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407/*
408 * Load the potential sixth argument from user stack.
409 * Careful about security.
410 */
411 cmpl $__PAGE_OFFSET-3,%ebp
412 jae syscall_fault
4131: movl (%ebp),%ebp
Jeremy Fitzhardinged93c8702008-03-24 16:43:21 -0700414 movl %ebp,PT_EBP(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415.section __ex_table,"a"
416 .align 4
417 .long 1b,syscall_fault
418.previous
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 GET_THREAD_INFO(%ebp)
421
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530422 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700423 jnz sysenter_audit
424sysenter_do_call:
H. Peter Anvin303395a2011-11-11 16:07:41 -0800425 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 jae syscall_badsys
427 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100428 movl %eax,PT_EAX(%esp)
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200429 LOCKDEP_SYS_EXIT
Jeremy Fitzhardinge42c24fa2007-05-02 19:27:14 +0200430 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar55f327f2006-07-03 00:24:43 -0700431 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530433 testl $_TIF_ALLWORK_MASK, %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700434 jne sysexit_audit
435sysenter_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/* if something modifies registers it must also disable sysexit */
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100437 movl PT_EIP(%esp), %edx
438 movl PT_OLDESP(%esp), %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 xorl %ebp,%ebp
Ingo Molnar55f327f2006-07-03 00:24:43 -0700440 TRACE_IRQS_ON
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004411: mov PT_FS(%esp), %fs
Tejun Heoccbeed32009-02-09 22:17:40 +0900442 PTGS_TO_GS
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400443 ENABLE_INTERRUPTS_SYSEXIT
Roland McGrathaf0575b2008-06-24 04:16:52 -0700444
445#ifdef CONFIG_AUDITSYSCALL
446sysenter_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530447 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
Roland McGrathaf0575b2008-06-24 04:16:52 -0700448 jnz syscall_trace_entry
449 addl $4,%esp
450 CFI_ADJUST_CFA_OFFSET -4
451 /* %esi already in 8(%esp) 6th arg: 4th syscall arg */
452 /* %edx already in 4(%esp) 5th arg: 3rd syscall arg */
453 /* %ecx already in 0(%esp) 4th arg: 2nd syscall arg */
454 movl %ebx,%ecx /* 3rd arg: 1st syscall arg */
455 movl %eax,%edx /* 2nd arg: syscall number */
456 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
Eric Parisb05d8442012-01-03 14:23:06 -0500457 call __audit_syscall_entry
Jan Beulichdf5d1872010-09-02 14:07:16 +0100458 pushl_cfi %ebx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700459 movl PT_EAX(%esp),%eax /* reload syscall number */
460 jmp sysenter_do_call
461
462sysexit_audit:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530463 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700464 jne syscall_exit_work
465 TRACE_IRQS_ON
466 ENABLE_INTERRUPTS(CLBR_ANY)
467 movl %eax,%edx /* second arg, syscall return value */
Eric Parisd7e75282012-01-03 14:23:06 -0500468 cmpl $-MAX_ERRNO,%eax /* is it an error ? */
469 setbe %al /* 1 if so, 0 if not */
Roland McGrathaf0575b2008-06-24 04:16:52 -0700470 movzbl %al,%eax /* zero-extend that */
Eric Parisd7e75282012-01-03 14:23:06 -0500471 call __audit_syscall_exit
Roland McGrathaf0575b2008-06-24 04:16:52 -0700472 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
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530626 TRACE_IRQS_ON
627 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 xorl %edx, %edx
629 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700630 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 ALIGN
633work_notifysig_v86:
Jan Beulichdf5d1872010-09-02 14:07:16 +0100634 pushl_cfi %ecx # save ti_flags for do_notify_resume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 call save_v86_state # %eax contains pt_regs pointer
Jan Beulichdf5d1872010-09-02 14:07:16 +0100636 popl_cfi %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100638#else
639 movl %esp, %eax
640#endif
Srikar Dronamraju3596ff42011-10-25 19:48:12 +0530641 TRACE_IRQS_ON
642 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 xorl %edx, %edx
644 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700645 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100646END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 # perform syscall exit tracing
649 ALIGN
650syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100651 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700653 call syscall_trace_enter
654 /* What it returned is what we'll actually use. */
H. Peter Anvin303395a2011-11-11 16:07:41 -0800655 cmpl $(NR_syscalls), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 jnae syscall_call
657 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100658END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 # perform syscall exit tracing
661 ALIGN
662syscall_exit_work:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530663 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700665 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700666 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 # schedule() instead
668 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700669 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100671END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200672 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200674 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100677 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100679END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100682 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100684END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200685 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400686/*
687 * End of kprobes section
688 */
689 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Brian Gerst253f29a2009-02-10 09:51:46 -0500691/*
692 * System calls that need a pt_regs pointer.
693 */
Brian Gerste258e4e2009-12-09 19:01:51 -0500694#define PTREGSCALL0(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800695ENTRY(ptregs_##name) ; \
Brian Gerst253f29a2009-02-10 09:51:46 -0500696 leal 4(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800697 jmp sys_##name; \
698ENDPROC(ptregs_##name)
Brian Gerst253f29a2009-02-10 09:51:46 -0500699
Brian Gerste258e4e2009-12-09 19:01:51 -0500700#define PTREGSCALL1(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800701ENTRY(ptregs_##name) ; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500702 leal 4(%esp),%edx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800703 movl (PT_EBX+4)(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800704 jmp sys_##name; \
705ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500706
707#define PTREGSCALL2(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800708ENTRY(ptregs_##name) ; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500709 leal 4(%esp),%ecx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800710 movl (PT_ECX+4)(%esp),%edx; \
711 movl (PT_EBX+4)(%esp),%eax; \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800712 jmp sys_##name; \
713ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500714
715#define PTREGSCALL3(name) \
H. Peter Anvin303395a2011-11-11 16:07:41 -0800716ENTRY(ptregs_##name) ; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100717 CFI_STARTPROC; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500718 leal 4(%esp),%eax; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100719 pushl_cfi %eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500720 movl PT_EDX(%eax),%ecx; \
721 movl PT_ECX(%eax),%edx; \
722 movl PT_EBX(%eax),%eax; \
723 call sys_##name; \
724 addl $4,%esp; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100725 CFI_ADJUST_CFA_OFFSET -4; \
726 ret; \
727 CFI_ENDPROC; \
728ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500729
Brian Gerst27f59552009-12-09 19:01:52 -0500730PTREGSCALL1(iopl)
Brian Gerste258e4e2009-12-09 19:01:51 -0500731PTREGSCALL0(fork)
Brian Gerste258e4e2009-12-09 19:01:51 -0500732PTREGSCALL0(vfork)
Brian Gerst11cf88b2009-12-09 19:01:53 -0500733PTREGSCALL3(execve)
Brian Gerst052acad2009-12-09 19:01:54 -0500734PTREGSCALL2(sigaltstack)
Brian Gerste258e4e2009-12-09 19:01:51 -0500735PTREGSCALL0(sigreturn)
736PTREGSCALL0(rt_sigreturn)
Brian Gerstf1382f12009-12-09 19:01:55 -0500737PTREGSCALL2(vm86)
738PTREGSCALL1(vm86old)
Brian Gerst253f29a2009-02-10 09:51:46 -0500739
Brian Gerstf839bbc2009-12-09 19:01:56 -0500740/* Clone is an oddball. The 4th arg is in %edi */
H. Peter Anvin303395a2011-11-11 16:07:41 -0800741ENTRY(ptregs_clone)
Jan Beulicha34107b2010-09-02 14:04:16 +0100742 CFI_STARTPROC
Brian Gerstf839bbc2009-12-09 19:01:56 -0500743 leal 4(%esp),%eax
Jan Beulicha34107b2010-09-02 14:04:16 +0100744 pushl_cfi %eax
745 pushl_cfi PT_EDI(%eax)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500746 movl PT_EDX(%eax),%ecx
747 movl PT_ECX(%eax),%edx
748 movl PT_EBX(%eax),%eax
749 call sys_clone
750 addl $8,%esp
Jan Beulicha34107b2010-09-02 14:04:16 +0100751 CFI_ADJUST_CFA_OFFSET -8
Brian Gerstf839bbc2009-12-09 19:01:56 -0500752 ret
Jan Beulicha34107b2010-09-02 14:04:16 +0100753 CFI_ENDPROC
754ENDPROC(ptregs_clone)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500755
Tejun Heof0d96112009-02-09 22:17:40 +0900756.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200757/*
758 * Switch back for ESPFIX stack to the normal zerobased stack
759 *
760 * We can't call C functions using the ESPFIX stack. This code reads
761 * the high word of the segment base from the GDT and swiches to the
762 * normal stack and adjusts ESP with the matching offset.
763 */
764 /* fixup the stack */
Brian Gerst72c511d2010-07-31 12:48:23 -0400765 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
766 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200767 shl $16, %eax
768 addl %esp, %eax /* the adjusted stack pointer */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100769 pushl_cfi $__KERNEL_DS
770 pushl_cfi %eax
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200771 lss (%esp), %esp /* switch to the normal stack segment */
Tejun Heof0d96112009-02-09 22:17:40 +0900772 CFI_ADJUST_CFA_OFFSET -8
773.endm
774.macro UNWIND_ESPFIX_STACK
775 movl %ss, %eax
776 /* see if on espfix stack */
777 cmpw $__ESPFIX_SS, %ax
778 jne 27f
779 movl $__KERNEL_DS, %eax
780 movl %eax, %ds
781 movl %eax, %es
782 /* switch to normal stack */
783 FIXUP_ESPFIX_STACK
78427:
785.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800788 * Build the entry stubs and pointer table with some assembler magic.
789 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
790 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800792.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793ENTRY(interrupt)
Jiri Olsaea714542011-03-07 19:10:39 +0100794.section .entry.text, "ax"
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800795 .p2align 5
796 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200798 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800799vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800800.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
801 .balign 32
802 .rept 7
803 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800804 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200805 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800806 .endif
Jan Beulichdf5d1872010-09-02 14:07:16 +01008071: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
H. Peter Anvin86655962008-11-12 10:27:35 -0800808 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800809 jmp 2f
810 .endif
811 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 .long 1b
Jiri Olsaea714542011-03-07 19:10:39 +0100813 .section .entry.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800815 .endif
816 .endr
8172: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100819END(irq_entries_start)
820
821.previous
822END(interrupt)
823.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Ingo Molnar55f327f2006-07-03 00:24:43 -0700825/*
826 * the CPU automatically disables interrupts when executing an IRQ vector,
827 * so IRQ-flags tracing has to follow that:
828 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800829 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800831 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700833 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 movl %esp,%eax
835 call do_IRQ
836 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100837ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200838 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400840/*
841 * Irq entries should be protected against kprobes
842 */
843 .pushsection .kprobes.text, "ax"
Tejun Heo02cf94c2009-01-21 17:26:06 +0900844#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200846 RING0_INT_FRAME; \
Jan Beulichdf5d1872010-09-02 14:07:16 +0100847 pushl_cfi $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200848 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700849 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900851 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700852 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100853 CFI_ENDPROC; \
854ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Tejun Heo02cf94c2009-01-21 17:26:06 +0900856#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100859#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200862 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100863 pushl_cfi $0
864 pushl_cfi $do_coprocessor_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200866 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100867END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200870 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100871 pushl_cfi $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400872#ifdef CONFIG_X86_INVD_BUG
873 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100874661: pushl_cfi $do_general_protection
Brian Gerst40d2e762010-03-21 09:00:43 -0400875662:
876.section .altinstructions,"a"
Andy Lutomirskib4ca46e2011-08-25 16:10:33 -0400877 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
Brian Gerst40d2e762010-03-21 09:00:43 -0400878.previous
879.section .altinstr_replacement,"ax"
880663: pushl $do_simd_coprocessor_error
881664:
882.previous
883#else
Jan Beulichdf5d1872010-09-02 14:07:16 +0100884 pushl_cfi $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400885#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200887 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100888END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100892 pushl_cfi $-1 # mark this as an int
893 pushl_cfi $do_device_not_available
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200894 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200895 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100896END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Rusty Russelld3561b72006-12-07 02:14:07 +0100898#ifdef CONFIG_PARAVIRT
899ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100900 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100901.section __ex_table,"a"
902 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100903 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100904.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100905END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100906
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400907ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100908 sti
909 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400910END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100911#endif
912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200914 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100915 pushl_cfi $0
916 pushl_cfi $do_overflow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200918 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100919END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100923 pushl_cfi $0
924 pushl_cfi $do_bounds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200926 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100927END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200930 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100931 pushl_cfi $0
932 pushl_cfi $do_invalid_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200934 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100935END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
937ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200938 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100939 pushl_cfi $0
940 pushl_cfi $do_coprocessor_segment_overrun
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200942 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100943END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200946 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100947 pushl_cfi $do_invalid_TSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200949 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100950END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100954 pushl_cfi $do_segment_not_present
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200956 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100957END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
959ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200960 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100961 pushl_cfi $do_stack_segment
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200963 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100964END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100968 pushl_cfi $do_alignment_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200970 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100971END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200973ENTRY(divide_error)
974 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100975 pushl_cfi $0 # no error code
976 pushl_cfi $do_divide_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200978 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100979END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
981#ifdef CONFIG_X86_MCE
982ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200983 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100984 pushl_cfi $0
985 pushl_cfi machine_check_vector
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200987 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100988END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989#endif
990
991ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200992 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100993 pushl_cfi $0
994 pushl_cfi $do_spurious_interrupt_bug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200996 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100997END(spurious_interrupt_bug)
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400998/*
999 * End of kprobes section
1000 */
1001 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
Andi Kleen02ba1a32006-09-26 10:52:35 +02001003ENTRY(kernel_thread_helper)
1004 pushl $0 # fake return address for unwinder
1005 CFI_STARTPROC
Brian Gerste8402272009-12-09 12:34:42 -05001006 movl %edi,%eax
1007 call *%esi
Andi Kleen02ba1a32006-09-26 10:52:35 +02001008 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001009 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +02001010 CFI_ENDPROC
1011ENDPROC(kernel_thread_helper)
1012
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001013#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001014/* Xen doesn't set %esp to be precisely what the normal sysenter
1015 entrypoint expects, so fix it up before using the normal path. */
1016ENTRY(xen_sysenter_target)
1017 RING0_INT_FRAME
1018 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001019 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001020 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001021 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001022
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001023ENTRY(xen_hypervisor_callback)
1024 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001025 pushl_cfi $0
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001026 SAVE_ALL
1027 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001028
1029 /* Check to see if we got the event in the critical
1030 region in xen_iret_direct, after we've reenabled
1031 events and checked for pending events. This simulates
1032 iret instruction's behaviour where it delivers a
1033 pending interrupt when enabling interrupts. */
1034 movl PT_EIP(%esp),%eax
1035 cmpl $xen_iret_start_crit,%eax
1036 jb 1f
1037 cmpl $xen_iret_end_crit,%eax
1038 jae 1f
1039
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001040 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001041
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001042ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010431: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001044 call xen_evtchn_do_upcall
1045 jmp ret_from_intr
1046 CFI_ENDPROC
1047ENDPROC(xen_hypervisor_callback)
1048
1049# Hypervisor uses this for application faults while it executes.
1050# We get here for two reasons:
1051# 1. Fault while reloading DS, ES, FS or GS
1052# 2. Fault while executing IRET
1053# Category 1 we fix up by reattempting the load, and zeroing the segment
1054# register if the load fails.
1055# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1056# normal Linux return path in this case because if we use the IRET hypercall
1057# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1058# We distinguish between categories by maintaining a status value in EAX.
1059ENTRY(xen_failsafe_callback)
1060 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001061 pushl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001062 movl $1,%eax
10631: mov 4(%esp),%ds
10642: mov 8(%esp),%es
10653: mov 12(%esp),%fs
10664: mov 16(%esp),%gs
1067 testl %eax,%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001068 popl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001069 lea 16(%esp),%esp
1070 CFI_ADJUST_CFA_OFFSET -16
1071 jz 5f
1072 addl $16,%esp
1073 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
Jan Beulichdf5d1872010-09-02 14:07:16 +010010745: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001075 SAVE_ALL
1076 jmp ret_from_exception
1077 CFI_ENDPROC
1078
1079.section .fixup,"ax"
10806: xorl %eax,%eax
1081 movl %eax,4(%esp)
1082 jmp 1b
10837: xorl %eax,%eax
1084 movl %eax,8(%esp)
1085 jmp 2b
10868: xorl %eax,%eax
1087 movl %eax,12(%esp)
1088 jmp 3b
10899: xorl %eax,%eax
1090 movl %eax,16(%esp)
1091 jmp 4b
1092.previous
1093.section __ex_table,"a"
1094 .align 4
1095 .long 1b,6b
1096 .long 2b,7b
1097 .long 3b,8b
1098 .long 4b,9b
1099.previous
1100ENDPROC(xen_failsafe_callback)
1101
Sheng Yang38e20b02010-05-14 12:40:51 +01001102BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1103 xen_evtchn_do_upcall)
1104
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001105#endif /* CONFIG_XEN */
1106
Steven Rostedt606576c2008-10-06 19:06:12 -04001107#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001108#ifdef CONFIG_DYNAMIC_FTRACE
1109
1110ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001111 ret
1112END(mcount)
1113
1114ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001115 cmpl $0, function_trace_stop
1116 jne ftrace_stub
1117
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001118 pushl %eax
1119 pushl %ecx
1120 pushl %edx
1121 movl 0xc(%esp), %eax
1122 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301123 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001124
1125.globl ftrace_call
1126ftrace_call:
1127 call ftrace_stub
1128
1129 popl %edx
1130 popl %ecx
1131 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001132#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1133.globl ftrace_graph_call
1134ftrace_graph_call:
1135 jmp ftrace_stub
1136#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001137
1138.globl ftrace_stub
1139ftrace_stub:
1140 ret
1141END(ftrace_caller)
1142
1143#else /* ! CONFIG_DYNAMIC_FTRACE */
1144
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001145ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001146 cmpl $0, function_trace_stop
1147 jne ftrace_stub
1148
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001149 cmpl $ftrace_stub, ftrace_trace_function
1150 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001151#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001152 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001153 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001154
1155 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1156 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001157#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001158.globl ftrace_stub
1159ftrace_stub:
1160 ret
1161
1162 /* taken from glibc */
1163trace:
1164 pushl %eax
1165 pushl %ecx
1166 pushl %edx
1167 movl 0xc(%esp), %eax
1168 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301169 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001170
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001171 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001172
1173 popl %edx
1174 popl %ecx
1175 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001176 jmp ftrace_stub
1177END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001178#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001179#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001180
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001181#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1182ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001183 cmpl $0, function_trace_stop
1184 jne ftrace_stub
1185
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001186 pushl %eax
1187 pushl %ecx
1188 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001189 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001190 lea 0x4(%ebp), %eax
Steven Rostedt71e308a2009-06-18 12:45:08 -04001191 movl (%ebp), %ecx
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001192 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001193 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001194 popl %edx
1195 popl %ecx
1196 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001197 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001198END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001199
1200.globl return_to_handler
1201return_to_handler:
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001202 pushl %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001203 pushl %edx
Steven Rostedt71e308a2009-06-18 12:45:08 -04001204 movl %ebp, %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001205 call ftrace_return_to_handler
Steven Rostedt194ec342009-10-13 16:33:50 -04001206 movl %eax, %ecx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001207 popl %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001208 popl %eax
Steven Rostedt194ec342009-10-13 16:33:50 -04001209 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001210#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001212/*
1213 * Some functions should be protected against kprobes
1214 */
1215 .pushsection .kprobes.text, "ax"
1216
1217ENTRY(page_fault)
1218 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001219 pushl_cfi $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001220 ALIGN
1221error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001222 /* the function address is in %gs's slot on the stack */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001223 pushl_cfi %fs
Tejun Heoccbeed32009-02-09 22:17:40 +09001224 /*CFI_REL_OFFSET fs, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001225 pushl_cfi %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001226 /*CFI_REL_OFFSET es, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001227 pushl_cfi %ds
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001228 /*CFI_REL_OFFSET ds, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001229 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001230 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001231 pushl_cfi %ebp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001232 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001233 pushl_cfi %edi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001234 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001235 pushl_cfi %esi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001236 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001237 pushl_cfi %edx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001238 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001239 pushl_cfi %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001240 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001241 pushl_cfi %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001242 CFI_REL_OFFSET ebx, 0
1243 cld
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001244 movl $(__KERNEL_PERCPU), %ecx
1245 movl %ecx, %fs
1246 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001247 GS_TO_REG %ecx
1248 movl PT_GS(%esp), %edi # get the function address
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001249 movl PT_ORIG_EAX(%esp), %edx # get the error code
1250 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001251 REG_TO_PTGS %ecx
1252 SET_KERNEL_GS %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001253 movl $(__USER_DS), %ecx
1254 movl %ecx, %ds
1255 movl %ecx, %es
1256 TRACE_IRQS_OFF
1257 movl %esp,%eax # pt_regs pointer
1258 call *%edi
1259 jmp ret_from_exception
1260 CFI_ENDPROC
1261END(page_fault)
1262
1263/*
1264 * Debug traps and NMI can happen at the one SYSENTER instruction
1265 * that sets up the real kernel stack. Check here, since we can't
1266 * allow the wrong stack to be used.
1267 *
1268 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1269 * already pushed 3 words if it hits on the sysenter instruction:
1270 * eflags, cs and eip.
1271 *
1272 * We just load the right stack, and push the three (known) values
1273 * by hand onto the new stack - while updating the return eip past
1274 * the instruction that would have done it for sysenter.
1275 */
Tejun Heof0d96112009-02-09 22:17:40 +09001276.macro FIX_STACK offset ok label
1277 cmpw $__KERNEL_CS, 4(%esp)
1278 jne \ok
1279\label:
1280 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1281 CFI_DEF_CFA esp, 0
1282 CFI_UNDEFINED eip
Jan Beulichdf5d1872010-09-02 14:07:16 +01001283 pushfl_cfi
1284 pushl_cfi $__KERNEL_CS
1285 pushl_cfi $sysenter_past_esp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001286 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001287.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001288
1289ENTRY(debug)
1290 RING0_INT_FRAME
1291 cmpl $ia32_sysenter_target,(%esp)
1292 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001293 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001294debug_stack_correct:
Jan Beulichdf5d1872010-09-02 14:07:16 +01001295 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001296 SAVE_ALL
1297 TRACE_IRQS_OFF
1298 xorl %edx,%edx # error code 0
1299 movl %esp,%eax # pt_regs pointer
1300 call do_debug
1301 jmp ret_from_exception
1302 CFI_ENDPROC
1303END(debug)
1304
1305/*
1306 * NMI is doubly nasty. It can happen _while_ we're handling
1307 * a debug fault, and the debug fault hasn't yet been able to
1308 * clear up the stack. So we first check whether we got an
1309 * NMI on the sysenter entry path, but after that we need to
1310 * check whether we got an NMI on the debug path where the debug
1311 * fault happened on the sysenter path.
1312 */
1313ENTRY(nmi)
1314 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001315 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001316 movl %ss, %eax
1317 cmpw $__ESPFIX_SS, %ax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001318 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001319 je nmi_espfix_stack
1320 cmpl $ia32_sysenter_target,(%esp)
1321 je nmi_stack_fixup
Jan Beulichdf5d1872010-09-02 14:07:16 +01001322 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001323 movl %esp,%eax
1324 /* Do not access memory above the end of our stack page,
1325 * it might not exist.
1326 */
1327 andl $(THREAD_SIZE-1),%eax
1328 cmpl $(THREAD_SIZE-20),%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001329 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001330 jae nmi_stack_correct
1331 cmpl $ia32_sysenter_target,12(%esp)
1332 je nmi_debug_stack_check
1333nmi_stack_correct:
1334 /* We have a RING0_INT_FRAME here */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001335 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001336 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001337 xorl %edx,%edx # zero error code
1338 movl %esp,%eax # pt_regs pointer
1339 call do_nmi
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +02001340 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001341 CFI_ENDPROC
1342
1343nmi_stack_fixup:
1344 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001345 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001346 jmp nmi_stack_correct
1347
1348nmi_debug_stack_check:
1349 /* We have a RING0_INT_FRAME here */
1350 cmpw $__KERNEL_CS,16(%esp)
1351 jne nmi_stack_correct
1352 cmpl $debug,(%esp)
1353 jb nmi_stack_correct
1354 cmpl $debug_esp_fix_insn,(%esp)
1355 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001356 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001357 jmp nmi_stack_correct
1358
1359nmi_espfix_stack:
1360 /* We have a RING0_INT_FRAME here.
1361 *
1362 * create the pointer to lss back
1363 */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001364 pushl_cfi %ss
1365 pushl_cfi %esp
Stas Sergeevbda3a892009-02-23 19:13:07 +03001366 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001367 /* copy the iret frame of 12 bytes */
1368 .rept 3
Jan Beulichdf5d1872010-09-02 14:07:16 +01001369 pushl_cfi 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001370 .endr
Jan Beulichdf5d1872010-09-02 14:07:16 +01001371 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001372 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001373 FIXUP_ESPFIX_STACK # %eax == %esp
1374 xorl %edx,%edx # zero error code
1375 call do_nmi
1376 RESTORE_REGS
1377 lss 12+4(%esp), %esp # back to espfix stack
1378 CFI_ADJUST_CFA_OFFSET -24
1379 jmp irq_return
1380 CFI_ENDPROC
1381END(nmi)
1382
1383ENTRY(int3)
1384 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001385 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001386 SAVE_ALL
1387 TRACE_IRQS_OFF
1388 xorl %edx,%edx # zero error code
1389 movl %esp,%eax # pt_regs pointer
1390 call do_int3
1391 jmp ret_from_exception
1392 CFI_ENDPROC
1393END(int3)
1394
1395ENTRY(general_protection)
1396 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001397 pushl_cfi $do_general_protection
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001398 jmp error_code
1399 CFI_ENDPROC
1400END(general_protection)
1401
Gleb Natapov631bc482010-10-14 11:22:52 +02001402#ifdef CONFIG_KVM_GUEST
1403ENTRY(async_page_fault)
1404 RING0_EC_FRAME
Jan Beulich60cf6372011-02-28 15:54:40 +00001405 pushl_cfi $do_async_page_fault
Gleb Natapov631bc482010-10-14 11:22:52 +02001406 jmp error_code
1407 CFI_ENDPROC
Sedat Dilek2ae9d292011-03-08 22:39:24 +01001408END(async_page_fault)
Gleb Natapov631bc482010-10-14 11:22:52 +02001409#endif
1410
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001411/*
1412 * End of kprobes section
1413 */
1414 .popsection