blob: f5accf8eaa7850ad37cd052b4146e1e0cf3c688e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 */
5
6/*
7 * entry.S contains the system-call and fault low-level handling routines.
8 * This also contains the timer-interrupt handler, as well as all interrupts
9 * and faults that can result in a task-switch.
10 *
11 * NOTE: This code handles signal-recognition, which happens every time
12 * after a timer-interrupt and after each system call.
13 *
14 * I changed all the .align's to 4 (16 byte alignment), as that's faster
15 * on a 486.
16 *
Andi Kleen889f21c2007-05-02 19:27:19 +020017 * Stack layout in 'syscall_exit':
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 * ptrace needs to have all regs on the stack.
19 * if the order here is changed, it needs to be
20 * updated in fork.c:copy_process, signal.c:do_signal,
21 * ptrace.c and ptrace.h
22 *
23 * 0(%esp) - %ebx
24 * 4(%esp) - %ecx
25 * 8(%esp) - %edx
26 * C(%esp) - %esi
27 * 10(%esp) - %edi
28 * 14(%esp) - %ebp
29 * 18(%esp) - %eax
30 * 1C(%esp) - %ds
31 * 20(%esp) - %es
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +010032 * 24(%esp) - %fs
Tejun Heoccbeed32009-02-09 22:17:40 +090033 * 28(%esp) - %gs saved iff !CONFIG_X86_32_LAZY_GS
34 * 2C(%esp) - orig_eax
35 * 30(%esp) - %eip
36 * 34(%esp) - %cs
37 * 38(%esp) - %eflags
38 * 3C(%esp) - %oldesp
39 * 40(%esp) - %oldss
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/linkage.h>
45#include <asm/thread_info.h>
Ingo Molnar55f327f2006-07-03 00:24:43 -070046#include <asm/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/errno.h>
48#include <asm/segment.h>
49#include <asm/smp.h>
Jeremy Fitzhardinge0341c142009-02-13 11:14:01 -080050#include <asm/page_types.h>
Stas Sergeevbe44d2a2006-12-07 02:14:01 +010051#include <asm/percpu.h>
Jan Beulichfe7cacc2006-06-26 13:57:44 +020052#include <asm/dwarf2.h>
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +030053#include <asm/processor-flags.h>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053054#include <asm/ftrace.h>
Thomas Gleixner9b7dc562008-05-02 20:10:09 +020055#include <asm/irq_vectors.h>
Brian Gerst40d2e762010-03-21 09:00:43 -040056#include <asm/cpufeature.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Roland McGrathaf0575b2008-06-24 04:16:52 -070058/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
59#include <linux/elf-em.h>
60#define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE)
61#define __AUDIT_ARCH_LE 0x40000000
62
63#ifndef CONFIG_AUDITSYSCALL
64#define sysenter_audit syscall_trace_entry
65#define sysexit_audit syscall_exit_work
66#endif
67
Jiri Olsaea714542011-03-07 19:10:39 +010068 .section .entry.text, "ax"
69
Rusty Russell139ec7c2006-12-07 02:14:08 +010070/*
71 * We use macros for low-level operations which need to be overridden
72 * for paravirtualization. The following will never clobber any registers:
73 * INTERRUPT_RETURN (aka. "iret")
74 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -040075 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
Rusty Russell139ec7c2006-12-07 02:14:08 +010076 *
77 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
78 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
79 * Allowing a register to be clobbered can shrink the paravirt replacement
80 * enough to patch inline, increasing performance.
81 */
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define nr_syscalls ((syscall_table_size)/4)
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 */
Tetsuo Handa96e612f2010-11-16 13:45:16 +0900400 pushl_cfi ((TI_sysenter_return)-THREAD_SIZE_asm+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:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 cmpl $(nr_syscalls), %eax
426 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 */
457 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 */
468 cmpl $0,%eax /* is it < 0? */
469 setl %al /* 1 if so, 0 if not */
470 movzbl %al,%eax /* zero-extend that */
471 inc %eax /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
472 call audit_syscall_exit
473 DISABLE_INTERRUPTS(CLBR_ANY)
474 TRACE_IRQS_OFF
475 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530476 testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT), %ecx
Roland McGrathaf0575b2008-06-24 04:16:52 -0700477 jne syscall_exit_work
478 movl PT_EAX(%esp),%eax /* reload syscall return value */
479 jmp sysenter_exit
480#endif
481
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200482 CFI_ENDPROC
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100483.pushsection .fixup,"ax"
Jeremy Fitzhardinge464d1a72007-02-13 13:26:20 +01004842: movl $0,PT_FS(%esp)
Jeremy Fitzhardingef95d47c2006-12-07 02:14:02 +0100485 jmp 1b
486.section __ex_table,"a"
487 .align 4
488 .long 1b,2b
489.popsection
Tejun Heoccbeed32009-02-09 22:17:40 +0900490 PTGS_TO_GS_EX
Roland McGrath0aa97fb2008-01-30 13:30:43 +0100491ENDPROC(ia32_sysenter_target)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400493/*
494 * syscall stub including irq exit should be protected against kprobes
495 */
496 .pushsection .kprobes.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 # system call handler stub
498ENTRY(system_call)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200499 RING0_INT_FRAME # can't unwind into user space anyway
Jan Beulichdf5d1872010-09-02 14:07:16 +0100500 pushl_cfi %eax # save orig_eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 SAVE_ALL
502 GET_THREAD_INFO(%ebp)
Laurent Viviered75e8d2005-09-03 15:57:18 -0700503 # system call tracing in operation / emulation
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530504 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 jnz syscall_trace_entry
506 cmpl $(nr_syscalls), %eax
507 jae syscall_badsys
508syscall_call:
509 call *sys_call_table(,%eax,4)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100510 movl %eax,PT_EAX(%esp) # store the return value
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511syscall_exit:
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200512 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100513 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 # setting need_resched or sigpending
515 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700516 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 movl TI_flags(%ebp), %ecx
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530518 testl $_TIF_ALLWORK_MASK, %ecx # current->work
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 jne syscall_exit_work
520
521restore_all:
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200522 TRACE_IRQS_IRET
523restore_all_notrace:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100524 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
525 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
Stas Sergeev5df24082005-04-16 15:24:01 -0700526 # are returning to the kernel.
527 # See comments in process.c:copy_thread() for details.
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100528 movb PT_OLDSS(%esp), %ah
529 movb PT_CS(%esp), %al
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300530 andl $(X86_EFLAGS_VM | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
Rusty Russell78be3702006-09-26 10:52:39 +0200531 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200532 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 je ldt_ss # returning to user-space with LDT SS
534restore_nocheck:
Tejun Heoccbeed32009-02-09 22:17:40 +0900535 RESTORE_REGS 4 # skip orig_eax/error_code
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200536irq_return:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100537 INTERRUPT_RETURN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538.section .fixup,"ax"
Jeremy Fitzhardinge90e9f532008-03-17 16:37:12 -0700539ENTRY(iret_exc)
Linus Torvaldsa879cbb2005-04-29 09:38:44 -0700540 pushl $0 # no error code
541 pushl $do_iret_error
542 jmp error_code
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543.previous
544.section __ex_table,"a"
545 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100546 .long irq_return,iret_exc
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547.previous
548
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200549 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550ldt_ss:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100551 larl PT_OLDSS(%esp), %eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 jnz restore_nocheck
553 testl $0x00400000, %eax # returning to 32bit stack?
554 jnz restore_nocheck # allright, normal return
Rusty Russelld3561b72006-12-07 02:14:07 +0100555
556#ifdef CONFIG_PARAVIRT
557 /*
558 * The kernel can't run on a non-flat stack if paravirt mode
559 * is active. Rather than try to fixup the high bits of
560 * ESP, bypass this code entirely. This may break DOSemu
561 * and/or Wine support in a paravirt VM, although the option
562 * is still available to implement the setting of the high
563 * 16-bits in the INTERRUPT_RETURN paravirt-op.
564 */
Jeremy Fitzhardinge93b1eab2007-10-16 11:51:29 -0700565 cmpl $0, pv_info+PARAVIRT_enabled
Rusty Russelld3561b72006-12-07 02:14:07 +0100566 jne restore_nocheck
567#endif
568
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200569/*
570 * Setup and switch to ESPFIX stack
571 *
572 * We're returning to userspace with a 16 bit stack. The CPU will not
573 * restore the high word of ESP for us on executing iret... This is an
574 * "official" bug of all the x86-compatible CPUs, which we can work
575 * around to make dosemu and wine happy. We do this by preloading the
576 * high word of ESP with the high word of the userspace ESP while
577 * compensating for the offset by changing to the ESPFIX segment with
578 * a base address that matches for the difference.
579 */
Brian Gerst72c511d2010-07-31 12:48:23 -0400580#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200581 mov %esp, %edx /* load kernel esp */
582 mov PT_OLDESP(%esp), %eax /* load userspace esp */
583 mov %dx, %ax /* eax: new kernel esp */
584 sub %eax, %edx /* offset (low word is 0) */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200585 shr $16, %edx
Brian Gerst72c511d2010-07-31 12:48:23 -0400586 mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
587 mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100588 pushl_cfi $__ESPFIX_SS
589 pushl_cfi %eax /* new kernel esp */
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +0200590 /* Disable interrupts, but do not irqtrace this section: we
591 * will soon execute iret and the tracer was already set to
592 * the irqstate after the iret */
Rusty Russell139ec7c2006-12-07 02:14:08 +0100593 DISABLE_INTERRUPTS(CLBR_EAX)
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200594 lss (%esp), %esp /* switch to espfix segment */
Stas Sergeevbe44d2a2006-12-07 02:14:01 +0100595 CFI_ADJUST_CFA_OFFSET -8
596 jmp restore_nocheck
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200597 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100598ENDPROC(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 # perform work that needs to be done immediately before resumption
601 ALIGN
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200602 RING0_PTREGS_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603work_pending:
604 testb $_TIF_NEED_RESCHED, %cl
605 jz work_notifysig
606work_resched:
607 call schedule
Peter Zijlstrac7e872e2007-10-11 22:11:12 +0200608 LOCKDEP_SYS_EXIT
Rusty Russell139ec7c2006-12-07 02:14:08 +0100609 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 # setting need_resched or sigpending
611 # between sampling and the iret
Ingo Molnar55f327f2006-07-03 00:24:43 -0700612 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 movl TI_flags(%ebp), %ecx
614 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
615 # than syscall tracing?
616 jz restore_all
617 testb $_TIF_NEED_RESCHED, %cl
618 jnz work_resched
619
620work_notifysig: # deal with pending signals and
621 # notify-resume requests
Joe Korty74b47a72006-12-07 02:14:04 +0100622#ifdef CONFIG_VM86
Cyrill Gorcunovab68ed92008-03-25 22:16:32 +0300623 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 movl %esp, %eax
625 jne work_notifysig_v86 # returning to kernel-space or
626 # vm86-space
627 xorl %edx, %edx
628 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700629 jmp resume_userspace_sig
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 ALIGN
632work_notifysig_v86:
Jan Beulichdf5d1872010-09-02 14:07:16 +0100633 pushl_cfi %ecx # save ti_flags for do_notify_resume
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 call save_v86_state # %eax contains pt_regs pointer
Jan Beulichdf5d1872010-09-02 14:07:16 +0100635 popl_cfi %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 movl %eax, %esp
Joe Korty74b47a72006-12-07 02:14:04 +0100637#else
638 movl %esp, %eax
639#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 xorl %edx, %edx
641 call do_notify_resume
Aleksey Gorelov4031ff32006-06-27 02:53:48 -0700642 jmp resume_userspace_sig
Jan Beulich47a55cd2007-02-13 13:26:24 +0100643END(work_pending)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644
645 # perform syscall exit tracing
646 ALIGN
647syscall_trace_entry:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100648 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700650 call syscall_trace_enter
651 /* What it returned is what we'll actually use. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 cmpl $(nr_syscalls), %eax
653 jnae syscall_call
654 jmp syscall_exit
Jan Beulich47a55cd2007-02-13 13:26:24 +0100655END(syscall_trace_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657 # perform syscall exit tracing
658 ALIGN
659syscall_exit_work:
Jaswinder Singh Rajput88200bc2009-03-14 12:08:13 +0530660 testl $_TIF_WORK_SYSCALL_EXIT, %ecx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 jz work_pending
Ingo Molnar55f327f2006-07-03 00:24:43 -0700662 TRACE_IRQS_ON
Roland McGrathd4d67152008-07-09 02:38:07 -0700663 ENABLE_INTERRUPTS(CLBR_ANY) # could let syscall_trace_leave() call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 # schedule() instead
665 movl %esp, %eax
Roland McGrathd4d67152008-07-09 02:38:07 -0700666 call syscall_trace_leave
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100668END(syscall_exit_work)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200669 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200671 RING0_INT_FRAME # can't unwind into user space anyway
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672syscall_fault:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 GET_THREAD_INFO(%ebp)
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100674 movl $-EFAULT,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100676END(syscall_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678syscall_badsys:
Jeremy Fitzhardingeeb5b7b92006-12-07 02:14:02 +0100679 movl $-ENOSYS,PT_EAX(%esp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 jmp resume_userspace
Jan Beulich47a55cd2007-02-13 13:26:24 +0100681END(syscall_badsys)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200682 CFI_ENDPROC
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400683/*
684 * End of kprobes section
685 */
686 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Brian Gerst253f29a2009-02-10 09:51:46 -0500688/*
689 * System calls that need a pt_regs pointer.
690 */
Brian Gerste258e4e2009-12-09 19:01:51 -0500691#define PTREGSCALL0(name) \
Brian Gerst253f29a2009-02-10 09:51:46 -0500692 ALIGN; \
693ptregs_##name: \
694 leal 4(%esp),%eax; \
695 jmp sys_##name;
696
Brian Gerste258e4e2009-12-09 19:01:51 -0500697#define PTREGSCALL1(name) \
698 ALIGN; \
699ptregs_##name: \
700 leal 4(%esp),%edx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800701 movl (PT_EBX+4)(%esp),%eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500702 jmp sys_##name;
703
704#define PTREGSCALL2(name) \
705 ALIGN; \
706ptregs_##name: \
707 leal 4(%esp),%ecx; \
H. Peter Anvince9119a2009-12-09 16:33:44 -0800708 movl (PT_ECX+4)(%esp),%edx; \
709 movl (PT_EBX+4)(%esp),%eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500710 jmp sys_##name;
711
712#define PTREGSCALL3(name) \
713 ALIGN; \
714ptregs_##name: \
Jan Beulicha34107b2010-09-02 14:04:16 +0100715 CFI_STARTPROC; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500716 leal 4(%esp),%eax; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100717 pushl_cfi %eax; \
Brian Gerste258e4e2009-12-09 19:01:51 -0500718 movl PT_EDX(%eax),%ecx; \
719 movl PT_ECX(%eax),%edx; \
720 movl PT_EBX(%eax),%eax; \
721 call sys_##name; \
722 addl $4,%esp; \
Jan Beulicha34107b2010-09-02 14:04:16 +0100723 CFI_ADJUST_CFA_OFFSET -4; \
724 ret; \
725 CFI_ENDPROC; \
726ENDPROC(ptregs_##name)
Brian Gerste258e4e2009-12-09 19:01:51 -0500727
Brian Gerst27f59552009-12-09 19:01:52 -0500728PTREGSCALL1(iopl)
Brian Gerste258e4e2009-12-09 19:01:51 -0500729PTREGSCALL0(fork)
Brian Gerste258e4e2009-12-09 19:01:51 -0500730PTREGSCALL0(vfork)
Brian Gerst11cf88b2009-12-09 19:01:53 -0500731PTREGSCALL3(execve)
Brian Gerst052acad2009-12-09 19:01:54 -0500732PTREGSCALL2(sigaltstack)
Brian Gerste258e4e2009-12-09 19:01:51 -0500733PTREGSCALL0(sigreturn)
734PTREGSCALL0(rt_sigreturn)
Brian Gerstf1382f12009-12-09 19:01:55 -0500735PTREGSCALL2(vm86)
736PTREGSCALL1(vm86old)
Brian Gerst253f29a2009-02-10 09:51:46 -0500737
Brian Gerstf839bbc2009-12-09 19:01:56 -0500738/* Clone is an oddball. The 4th arg is in %edi */
739 ALIGN;
740ptregs_clone:
Jan Beulicha34107b2010-09-02 14:04:16 +0100741 CFI_STARTPROC
Brian Gerstf839bbc2009-12-09 19:01:56 -0500742 leal 4(%esp),%eax
Jan Beulicha34107b2010-09-02 14:04:16 +0100743 pushl_cfi %eax
744 pushl_cfi PT_EDI(%eax)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500745 movl PT_EDX(%eax),%ecx
746 movl PT_ECX(%eax),%edx
747 movl PT_EBX(%eax),%eax
748 call sys_clone
749 addl $8,%esp
Jan Beulicha34107b2010-09-02 14:04:16 +0100750 CFI_ADJUST_CFA_OFFSET -8
Brian Gerstf839bbc2009-12-09 19:01:56 -0500751 ret
Jan Beulicha34107b2010-09-02 14:04:16 +0100752 CFI_ENDPROC
753ENDPROC(ptregs_clone)
Brian Gerstf839bbc2009-12-09 19:01:56 -0500754
Tejun Heof0d96112009-02-09 22:17:40 +0900755.macro FIXUP_ESPFIX_STACK
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200756/*
757 * Switch back for ESPFIX stack to the normal zerobased stack
758 *
759 * We can't call C functions using the ESPFIX stack. This code reads
760 * the high word of the segment base from the GDT and swiches to the
761 * normal stack and adjusts ESP with the matching offset.
762 */
763 /* fixup the stack */
Brian Gerst72c511d2010-07-31 12:48:23 -0400764 mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
765 mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200766 shl $16, %eax
767 addl %esp, %eax /* the adjusted stack pointer */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100768 pushl_cfi $__KERNEL_DS
769 pushl_cfi %eax
Alexander van Heukelumdc4c2a02009-06-18 00:35:58 +0200770 lss (%esp), %esp /* switch to the normal stack segment */
Tejun Heof0d96112009-02-09 22:17:40 +0900771 CFI_ADJUST_CFA_OFFSET -8
772.endm
773.macro UNWIND_ESPFIX_STACK
774 movl %ss, %eax
775 /* see if on espfix stack */
776 cmpw $__ESPFIX_SS, %ax
777 jne 27f
778 movl $__KERNEL_DS, %eax
779 movl %eax, %ds
780 movl %eax, %es
781 /* switch to normal stack */
782 FIXUP_ESPFIX_STACK
78327:
784.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786/*
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800787 * Build the entry stubs and pointer table with some assembler magic.
788 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
789 * single cache line on all modern x86 implementations.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 */
H. Peter Anvin46875182008-11-11 13:03:07 -0800791.section .init.rodata,"a"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792ENTRY(interrupt)
Jiri Olsaea714542011-03-07 19:10:39 +0100793.section .entry.text, "ax"
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800794 .p2align 5
795 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796ENTRY(irq_entries_start)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200797 RING0_INT_FRAME
H. Peter Anvin46875182008-11-11 13:03:07 -0800798vector=FIRST_EXTERNAL_VECTOR
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800799.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
800 .balign 32
801 .rept 7
802 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800803 .if vector <> FIRST_EXTERNAL_VECTOR
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200804 CFI_ADJUST_CFA_OFFSET -4
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800805 .endif
Jan Beulichdf5d1872010-09-02 14:07:16 +01008061: pushl_cfi $(~vector+0x80) /* Note: always in signed byte range */
H. Peter Anvin86655962008-11-12 10:27:35 -0800807 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800808 jmp 2f
809 .endif
810 .previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 .long 1b
Jiri Olsaea714542011-03-07 19:10:39 +0100812 .section .entry.text, "ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813vector=vector+1
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800814 .endif
815 .endr
8162: jmp common_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817.endr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100818END(irq_entries_start)
819
820.previous
821END(interrupt)
822.previous
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Ingo Molnar55f327f2006-07-03 00:24:43 -0700824/*
825 * the CPU automatically disables interrupts when executing an IRQ vector,
826 * so IRQ-flags tracing has to follow that:
827 */
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800828 .p2align CONFIG_X86_L1_CACHE_SHIFT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829common_interrupt:
H. Peter Anvinb7c62442008-11-11 13:24:58 -0800830 addl $-0x80,(%esp) /* Adjust vector into the [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 SAVE_ALL
Ingo Molnar55f327f2006-07-03 00:24:43 -0700832 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 movl %esp,%eax
834 call do_IRQ
835 jmp ret_from_intr
Jan Beulich47a55cd2007-02-13 13:26:24 +0100836ENDPROC(common_interrupt)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200837 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
Masami Hiramatsua00e8172009-09-08 12:47:55 -0400839/*
840 * Irq entries should be protected against kprobes
841 */
842 .pushsection .kprobes.text, "ax"
Tejun Heo02cf94c2009-01-21 17:26:06 +0900843#define BUILD_INTERRUPT3(name, nr, fn) \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844ENTRY(name) \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200845 RING0_INT_FRAME; \
Jan Beulichdf5d1872010-09-02 14:07:16 +0100846 pushl_cfi $~(nr); \
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200847 SAVE_ALL; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700848 TRACE_IRQS_OFF \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 movl %esp,%eax; \
Tejun Heo02cf94c2009-01-21 17:26:06 +0900850 call fn; \
Ingo Molnar55f327f2006-07-03 00:24:43 -0700851 jmp ret_from_intr; \
Jan Beulich47a55cd2007-02-13 13:26:24 +0100852 CFI_ENDPROC; \
853ENDPROC(name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Tejun Heo02cf94c2009-01-21 17:26:06 +0900855#define BUILD_INTERRUPT(name, nr) BUILD_INTERRUPT3(name, nr, smp_##name)
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857/* The include is where all of the SMP etc. interrupts come from */
Ingo Molnar1164dd02009-01-28 19:34:09 +0100858#include <asm/entry_arch.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860ENTRY(coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200861 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100862 pushl_cfi $0
863 pushl_cfi $do_coprocessor_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200865 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100866END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868ENTRY(simd_coprocessor_error)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200869 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100870 pushl_cfi $0
Brian Gerst40d2e762010-03-21 09:00:43 -0400871#ifdef CONFIG_X86_INVD_BUG
872 /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
Jan Beulichdf5d1872010-09-02 14:07:16 +0100873661: pushl_cfi $do_general_protection
Brian Gerst40d2e762010-03-21 09:00:43 -0400874662:
875.section .altinstructions,"a"
876 .balign 4
877 .long 661b
878 .long 663f
H. Peter Anvin83a7a2a2010-06-10 00:10:43 +0000879 .word X86_FEATURE_XMM
Brian Gerst40d2e762010-03-21 09:00:43 -0400880 .byte 662b-661b
881 .byte 664f-663f
882.previous
883.section .altinstr_replacement,"ax"
884663: pushl $do_simd_coprocessor_error
885664:
886.previous
887#else
Jan Beulichdf5d1872010-09-02 14:07:16 +0100888 pushl_cfi $do_simd_coprocessor_error
Brian Gerst40d2e762010-03-21 09:00:43 -0400889#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200891 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100892END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894ENTRY(device_not_available)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200895 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100896 pushl_cfi $-1 # mark this as an int
897 pushl_cfi $do_device_not_available
Alexander van Heukelum7643e9b2008-09-09 21:56:02 +0200898 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200899 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100900END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Rusty Russelld3561b72006-12-07 02:14:07 +0100902#ifdef CONFIG_PARAVIRT
903ENTRY(native_iret)
Ingo Molnar3701d8632008-02-09 23:24:08 +0100904 iret
Rusty Russelld3561b72006-12-07 02:14:07 +0100905.section __ex_table,"a"
906 .align 4
Ingo Molnar3701d8632008-02-09 23:24:08 +0100907 .long native_iret, iret_exc
Rusty Russelld3561b72006-12-07 02:14:07 +0100908.previous
Jan Beulich47a55cd2007-02-13 13:26:24 +0100909END(native_iret)
Rusty Russelld3561b72006-12-07 02:14:07 +0100910
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400911ENTRY(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100912 sti
913 sysexit
Jeremy Fitzhardinged75cd222008-06-25 00:19:26 -0400914END(native_irq_enable_sysexit)
Rusty Russelld3561b72006-12-07 02:14:07 +0100915#endif
916
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917ENTRY(overflow)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200918 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100919 pushl_cfi $0
920 pushl_cfi $do_overflow
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200922 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100923END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925ENTRY(bounds)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200926 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100927 pushl_cfi $0
928 pushl_cfi $do_bounds
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200930 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100931END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933ENTRY(invalid_op)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200934 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100935 pushl_cfi $0
936 pushl_cfi $do_invalid_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200938 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100939END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941ENTRY(coprocessor_segment_overrun)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200942 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100943 pushl_cfi $0
944 pushl_cfi $do_coprocessor_segment_overrun
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200946 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100947END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949ENTRY(invalid_TSS)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200950 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100951 pushl_cfi $do_invalid_TSS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200953 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100954END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
956ENTRY(segment_not_present)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200957 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100958 pushl_cfi $do_segment_not_present
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200960 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100961END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963ENTRY(stack_segment)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200964 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100965 pushl_cfi $do_stack_segment
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200967 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100968END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970ENTRY(alignment_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200971 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100972 pushl_cfi $do_alignment_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200974 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100975END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200977ENTRY(divide_error)
978 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100979 pushl_cfi $0 # no error code
980 pushl_cfi $do_divide_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200982 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100983END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
985#ifdef CONFIG_X86_MCE
986ENTRY(machine_check)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200987 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100988 pushl_cfi $0
989 pushl_cfi machine_check_vector
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200991 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +0100992END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993#endif
994
995ENTRY(spurious_interrupt_bug)
Jan Beulichfe7cacc2006-06-26 13:57:44 +0200996 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +0100997 pushl_cfi $0
998 pushl_cfi $do_spurious_interrupt_bug
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 jmp error_code
Jan Beulichfe7cacc2006-06-26 13:57:44 +02001000 CFI_ENDPROC
Jan Beulich47a55cd2007-02-13 13:26:24 +01001001END(spurious_interrupt_bug)
Masami Hiramatsua00e8172009-09-08 12:47:55 -04001002/*
1003 * End of kprobes section
1004 */
1005 .popsection
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Andi Kleen02ba1a32006-09-26 10:52:35 +02001007ENTRY(kernel_thread_helper)
1008 pushl $0 # fake return address for unwinder
1009 CFI_STARTPROC
Brian Gerste8402272009-12-09 12:34:42 -05001010 movl %edi,%eax
1011 call *%esi
Andi Kleen02ba1a32006-09-26 10:52:35 +02001012 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001013 ud2 # padding for call trace
Andi Kleen02ba1a32006-09-26 10:52:35 +02001014 CFI_ENDPROC
1015ENDPROC(kernel_thread_helper)
1016
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001017#ifdef CONFIG_XEN
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001018/* Xen doesn't set %esp to be precisely what the normal sysenter
1019 entrypoint expects, so fix it up before using the normal path. */
1020ENTRY(xen_sysenter_target)
1021 RING0_INT_FRAME
1022 addl $5*4, %esp /* remove xen-provided frame */
Jan Beulich2ddf9b72008-07-18 13:32:23 +01001023 CFI_ADJUST_CFA_OFFSET -5*4
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001024 jmp sysenter_past_esp
Glauber Costa557d7d42008-07-10 15:09:20 -03001025 CFI_ENDPROC
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001026
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001027ENTRY(xen_hypervisor_callback)
1028 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001029 pushl_cfi $0
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001030 SAVE_ALL
1031 TRACE_IRQS_OFF
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001032
1033 /* Check to see if we got the event in the critical
1034 region in xen_iret_direct, after we've reenabled
1035 events and checked for pending events. This simulates
1036 iret instruction's behaviour where it delivers a
1037 pending interrupt when enabling interrupts. */
1038 movl PT_EIP(%esp),%eax
1039 cmpl $xen_iret_start_crit,%eax
1040 jb 1f
1041 cmpl $xen_iret_end_crit,%eax
1042 jae 1f
1043
Jeremy Fitzhardinge0f2c8762008-03-17 16:37:22 -07001044 jmp xen_iret_crit_fixup
Jeremy Fitzhardinge9ec2b802007-07-17 18:37:07 -07001045
Jeremy Fitzhardingee2a81ba2008-03-17 16:37:17 -07001046ENTRY(xen_do_upcall)
Jeremy Fitzhardingeb77797f2008-04-02 10:54:11 -070010471: mov %esp, %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001048 call xen_evtchn_do_upcall
1049 jmp ret_from_intr
1050 CFI_ENDPROC
1051ENDPROC(xen_hypervisor_callback)
1052
1053# Hypervisor uses this for application faults while it executes.
1054# We get here for two reasons:
1055# 1. Fault while reloading DS, ES, FS or GS
1056# 2. Fault while executing IRET
1057# Category 1 we fix up by reattempting the load, and zeroing the segment
1058# register if the load fails.
1059# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1060# normal Linux return path in this case because if we use the IRET hypercall
1061# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1062# We distinguish between categories by maintaining a status value in EAX.
1063ENTRY(xen_failsafe_callback)
1064 CFI_STARTPROC
Jan Beulichdf5d1872010-09-02 14:07:16 +01001065 pushl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001066 movl $1,%eax
10671: mov 4(%esp),%ds
10682: mov 8(%esp),%es
10693: mov 12(%esp),%fs
10704: mov 16(%esp),%gs
1071 testl %eax,%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001072 popl_cfi %eax
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001073 lea 16(%esp),%esp
1074 CFI_ADJUST_CFA_OFFSET -16
1075 jz 5f
1076 addl $16,%esp
1077 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
Jan Beulichdf5d1872010-09-02 14:07:16 +010010785: pushl_cfi $0 # EAX == 0 => Category 1 (Bad segment)
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001079 SAVE_ALL
1080 jmp ret_from_exception
1081 CFI_ENDPROC
1082
1083.section .fixup,"ax"
10846: xorl %eax,%eax
1085 movl %eax,4(%esp)
1086 jmp 1b
10877: xorl %eax,%eax
1088 movl %eax,8(%esp)
1089 jmp 2b
10908: xorl %eax,%eax
1091 movl %eax,12(%esp)
1092 jmp 3b
10939: xorl %eax,%eax
1094 movl %eax,16(%esp)
1095 jmp 4b
1096.previous
1097.section __ex_table,"a"
1098 .align 4
1099 .long 1b,6b
1100 .long 2b,7b
1101 .long 3b,8b
1102 .long 4b,9b
1103.previous
1104ENDPROC(xen_failsafe_callback)
1105
Sheng Yang38e20b02010-05-14 12:40:51 +01001106BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
1107 xen_evtchn_do_upcall)
1108
Jeremy Fitzhardinge5ead97c2007-07-17 18:37:04 -07001109#endif /* CONFIG_XEN */
1110
Steven Rostedt606576c2008-10-06 19:06:12 -04001111#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001112#ifdef CONFIG_DYNAMIC_FTRACE
1113
1114ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001115 ret
1116END(mcount)
1117
1118ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001119 cmpl $0, function_trace_stop
1120 jne ftrace_stub
1121
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001122 pushl %eax
1123 pushl %ecx
1124 pushl %edx
1125 movl 0xc(%esp), %eax
1126 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301127 subl $MCOUNT_INSN_SIZE, %eax
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001128
1129.globl ftrace_call
1130ftrace_call:
1131 call ftrace_stub
1132
1133 popl %edx
1134 popl %ecx
1135 popl %eax
Steven Rostedt5a45cfe2008-11-26 00:16:24 -05001136#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1137.globl ftrace_graph_call
1138ftrace_graph_call:
1139 jmp ftrace_stub
1140#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001141
1142.globl ftrace_stub
1143ftrace_stub:
1144 ret
1145END(ftrace_caller)
1146
1147#else /* ! CONFIG_DYNAMIC_FTRACE */
1148
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001149ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -05001150 cmpl $0, function_trace_stop
1151 jne ftrace_stub
1152
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001153 cmpl $ftrace_stub, ftrace_trace_function
1154 jnz trace
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001155#ifdef CONFIG_FUNCTION_GRAPH_TRACER
Ingo Molnarc2324b62008-11-26 03:10:01 +01001156 cmpl $ftrace_stub, ftrace_graph_return
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001157 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -05001158
1159 cmpl $ftrace_graph_entry_stub, ftrace_graph_entry
1160 jnz ftrace_graph_caller
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001161#endif
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001162.globl ftrace_stub
1163ftrace_stub:
1164 ret
1165
1166 /* taken from glibc */
1167trace:
1168 pushl %eax
1169 pushl %ecx
1170 pushl %edx
1171 movl 0xc(%esp), %eax
1172 movl 0x4(%ebp), %edx
Abhishek Sagar395a59d2008-06-21 23:47:27 +05301173 subl $MCOUNT_INSN_SIZE, %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001174
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001175 call *ftrace_trace_function
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001176
1177 popl %edx
1178 popl %ecx
1179 popl %eax
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001180 jmp ftrace_stub
1181END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +02001182#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -04001183#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +02001184
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001185#ifdef CONFIG_FUNCTION_GRAPH_TRACER
1186ENTRY(ftrace_graph_caller)
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001187 cmpl $0, function_trace_stop
1188 jne ftrace_stub
1189
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001190 pushl %eax
1191 pushl %ecx
1192 pushl %edx
Frederic Weisbecker1dc1c6a2008-11-12 22:49:23 +01001193 movl 0xc(%esp), %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001194 lea 0x4(%ebp), %eax
Steven Rostedt71e308a2009-06-18 12:45:08 -04001195 movl (%ebp), %ecx
Steven Rostedtbb4304c2008-12-02 15:34:09 -05001196 subl $MCOUNT_INSN_SIZE, %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001197 call prepare_ftrace_return
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001198 popl %edx
1199 popl %ecx
1200 popl %eax
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001201 ret
Frederic Weisbeckerfb526072008-11-25 21:07:04 +01001202END(ftrace_graph_caller)
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001203
1204.globl return_to_handler
1205return_to_handler:
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001206 pushl %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001207 pushl %edx
Steven Rostedt71e308a2009-06-18 12:45:08 -04001208 movl %ebp, %eax
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001209 call ftrace_return_to_handler
Steven Rostedt194ec342009-10-13 16:33:50 -04001210 movl %eax, %ecx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001211 popl %edx
Frederic Weisbeckercaf4b322008-11-11 07:03:45 +01001212 popl %eax
Steven Rostedt194ec342009-10-13 16:33:50 -04001213 jmp *%ecx
Frederic Weisbeckere7d37372008-11-16 06:02:06 +01001214#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216.section .rodata,"a"
1217#include "syscall_table_32.S"
1218
1219syscall_table_size=(.-sys_call_table)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001220
1221/*
1222 * Some functions should be protected against kprobes
1223 */
1224 .pushsection .kprobes.text, "ax"
1225
1226ENTRY(page_fault)
1227 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001228 pushl_cfi $do_page_fault
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001229 ALIGN
1230error_code:
Tejun Heoccbeed32009-02-09 22:17:40 +09001231 /* the function address is in %gs's slot on the stack */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001232 pushl_cfi %fs
Tejun Heoccbeed32009-02-09 22:17:40 +09001233 /*CFI_REL_OFFSET fs, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001234 pushl_cfi %es
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001235 /*CFI_REL_OFFSET es, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001236 pushl_cfi %ds
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001237 /*CFI_REL_OFFSET ds, 0*/
Jan Beulichdf5d1872010-09-02 14:07:16 +01001238 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001239 CFI_REL_OFFSET eax, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001240 pushl_cfi %ebp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001241 CFI_REL_OFFSET ebp, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001242 pushl_cfi %edi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001243 CFI_REL_OFFSET edi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001244 pushl_cfi %esi
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001245 CFI_REL_OFFSET esi, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001246 pushl_cfi %edx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001247 CFI_REL_OFFSET edx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001248 pushl_cfi %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001249 CFI_REL_OFFSET ecx, 0
Jan Beulichdf5d1872010-09-02 14:07:16 +01001250 pushl_cfi %ebx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001251 CFI_REL_OFFSET ebx, 0
1252 cld
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001253 movl $(__KERNEL_PERCPU), %ecx
1254 movl %ecx, %fs
1255 UNWIND_ESPFIX_STACK
Tejun Heoccbeed32009-02-09 22:17:40 +09001256 GS_TO_REG %ecx
1257 movl PT_GS(%esp), %edi # get the function address
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001258 movl PT_ORIG_EAX(%esp), %edx # get the error code
1259 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
Tejun Heoccbeed32009-02-09 22:17:40 +09001260 REG_TO_PTGS %ecx
1261 SET_KERNEL_GS %ecx
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001262 movl $(__USER_DS), %ecx
1263 movl %ecx, %ds
1264 movl %ecx, %es
1265 TRACE_IRQS_OFF
1266 movl %esp,%eax # pt_regs pointer
1267 call *%edi
1268 jmp ret_from_exception
1269 CFI_ENDPROC
1270END(page_fault)
1271
1272/*
1273 * Debug traps and NMI can happen at the one SYSENTER instruction
1274 * that sets up the real kernel stack. Check here, since we can't
1275 * allow the wrong stack to be used.
1276 *
1277 * "TSS_sysenter_sp0+12" is because the NMI/debug handler will have
1278 * already pushed 3 words if it hits on the sysenter instruction:
1279 * eflags, cs and eip.
1280 *
1281 * We just load the right stack, and push the three (known) values
1282 * by hand onto the new stack - while updating the return eip past
1283 * the instruction that would have done it for sysenter.
1284 */
Tejun Heof0d96112009-02-09 22:17:40 +09001285.macro FIX_STACK offset ok label
1286 cmpw $__KERNEL_CS, 4(%esp)
1287 jne \ok
1288\label:
1289 movl TSS_sysenter_sp0 + \offset(%esp), %esp
1290 CFI_DEF_CFA esp, 0
1291 CFI_UNDEFINED eip
Jan Beulichdf5d1872010-09-02 14:07:16 +01001292 pushfl_cfi
1293 pushl_cfi $__KERNEL_CS
1294 pushl_cfi $sysenter_past_esp
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001295 CFI_REL_OFFSET eip, 0
Tejun Heof0d96112009-02-09 22:17:40 +09001296.endm
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001297
1298ENTRY(debug)
1299 RING0_INT_FRAME
1300 cmpl $ia32_sysenter_target,(%esp)
1301 jne debug_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001302 FIX_STACK 12, debug_stack_correct, debug_esp_fix_insn
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001303debug_stack_correct:
Jan Beulichdf5d1872010-09-02 14:07:16 +01001304 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001305 SAVE_ALL
1306 TRACE_IRQS_OFF
1307 xorl %edx,%edx # error code 0
1308 movl %esp,%eax # pt_regs pointer
1309 call do_debug
1310 jmp ret_from_exception
1311 CFI_ENDPROC
1312END(debug)
1313
1314/*
1315 * NMI is doubly nasty. It can happen _while_ we're handling
1316 * a debug fault, and the debug fault hasn't yet been able to
1317 * clear up the stack. So we first check whether we got an
1318 * NMI on the sysenter entry path, but after that we need to
1319 * check whether we got an NMI on the debug path where the debug
1320 * fault happened on the sysenter path.
1321 */
1322ENTRY(nmi)
1323 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001324 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001325 movl %ss, %eax
1326 cmpw $__ESPFIX_SS, %ax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001327 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001328 je nmi_espfix_stack
1329 cmpl $ia32_sysenter_target,(%esp)
1330 je nmi_stack_fixup
Jan Beulichdf5d1872010-09-02 14:07:16 +01001331 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001332 movl %esp,%eax
1333 /* Do not access memory above the end of our stack page,
1334 * it might not exist.
1335 */
1336 andl $(THREAD_SIZE-1),%eax
1337 cmpl $(THREAD_SIZE-20),%eax
Jan Beulichdf5d1872010-09-02 14:07:16 +01001338 popl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001339 jae nmi_stack_correct
1340 cmpl $ia32_sysenter_target,12(%esp)
1341 je nmi_debug_stack_check
1342nmi_stack_correct:
1343 /* We have a RING0_INT_FRAME here */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001344 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001345 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001346 xorl %edx,%edx # zero error code
1347 movl %esp,%eax # pt_regs pointer
1348 call do_nmi
Alexander van Heukelum2e04bc72009-06-18 00:35:57 +02001349 jmp restore_all_notrace
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001350 CFI_ENDPROC
1351
1352nmi_stack_fixup:
1353 RING0_INT_FRAME
Tejun Heof0d96112009-02-09 22:17:40 +09001354 FIX_STACK 12, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001355 jmp nmi_stack_correct
1356
1357nmi_debug_stack_check:
1358 /* We have a RING0_INT_FRAME here */
1359 cmpw $__KERNEL_CS,16(%esp)
1360 jne nmi_stack_correct
1361 cmpl $debug,(%esp)
1362 jb nmi_stack_correct
1363 cmpl $debug_esp_fix_insn,(%esp)
1364 ja nmi_stack_correct
Tejun Heof0d96112009-02-09 22:17:40 +09001365 FIX_STACK 24, nmi_stack_correct, 1
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001366 jmp nmi_stack_correct
1367
1368nmi_espfix_stack:
1369 /* We have a RING0_INT_FRAME here.
1370 *
1371 * create the pointer to lss back
1372 */
Jan Beulichdf5d1872010-09-02 14:07:16 +01001373 pushl_cfi %ss
1374 pushl_cfi %esp
Stas Sergeevbda3a892009-02-23 19:13:07 +03001375 addl $4, (%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001376 /* copy the iret frame of 12 bytes */
1377 .rept 3
Jan Beulichdf5d1872010-09-02 14:07:16 +01001378 pushl_cfi 16(%esp)
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001379 .endr
Jan Beulichdf5d1872010-09-02 14:07:16 +01001380 pushl_cfi %eax
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001381 SAVE_ALL
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001382 FIXUP_ESPFIX_STACK # %eax == %esp
1383 xorl %edx,%edx # zero error code
1384 call do_nmi
1385 RESTORE_REGS
1386 lss 12+4(%esp), %esp # back to espfix stack
1387 CFI_ADJUST_CFA_OFFSET -24
1388 jmp irq_return
1389 CFI_ENDPROC
1390END(nmi)
1391
1392ENTRY(int3)
1393 RING0_INT_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001394 pushl_cfi $-1 # mark this as an int
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001395 SAVE_ALL
1396 TRACE_IRQS_OFF
1397 xorl %edx,%edx # zero error code
1398 movl %esp,%eax # pt_regs pointer
1399 call do_int3
1400 jmp ret_from_exception
1401 CFI_ENDPROC
1402END(int3)
1403
1404ENTRY(general_protection)
1405 RING0_EC_FRAME
Jan Beulichdf5d1872010-09-02 14:07:16 +01001406 pushl_cfi $do_general_protection
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001407 jmp error_code
1408 CFI_ENDPROC
1409END(general_protection)
1410
Gleb Natapov631bc482010-10-14 11:22:52 +02001411#ifdef CONFIG_KVM_GUEST
1412ENTRY(async_page_fault)
1413 RING0_EC_FRAME
1414 pushl $do_async_page_fault
1415 CFI_ADJUST_CFA_OFFSET 4
1416 jmp error_code
1417 CFI_ENDPROC
1418END(apf_page_fault)
1419#endif
1420
Alexander van Heukelumd211af02008-11-24 15:38:45 +01001421/*
1422 * End of kprobes section
1423 */
1424 .popsection