blob: 07d69f262337fe03aadfe381a234ceecd2e7fb5b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/x86_64/entry.S
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 2000, 2001, 2002 Andi Kleen SuSE Labs
6 * Copyright (C) 2000 Pavel Machek <pavel@suse.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9/*
10 * entry.S contains the system-call and fault low-level handling routines.
11 *
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after an interrupt and after each system call.
14 *
15 * Normal syscalls and interrupts don't save a full stack frame, this is
16 * only done for syscall tracing, signals or fork/exec et.al.
17 *
18 * A note on terminology:
19 * - top of stack: Architecture defined interrupt frame from SS to RIP
20 * at the top of the kernel process stack.
21 * - partial stack frame: partially saved registers upto R11.
22 * - full stack frame: Like partial stack frame, but all register saved.
Andi Kleen2e91a172006-09-26 10:52:29 +020023 *
24 * Some macro usage:
25 * - CFI macros are used to generate dwarf2 unwind information for better
26 * backtraces. They don't change any code.
27 * - SAVE_ALL/RESTORE_ALL - Save/restore all registers
28 * - SAVE_ARGS/RESTORE_ARGS - Save/restore registers that C functions modify.
29 * There are unfortunately lots of special cases where some registers
30 * not touched. The macro is a big mess that should be cleaned up.
31 * - SAVE_REST/RESTORE_REST - Handle the registers not saved by SAVE_ARGS.
32 * Gives a full stack frame.
33 * - ENTRY/END Define functions in the symbol table.
34 * - FIXUP_TOP_OF_STACK/RESTORE_TOP_OF_STACK - Fix up the hardware stack
35 * frame that is otherwise undefined after a SYSCALL
36 * - TRACE_IRQ_* - Trace hard interrupt state for lock debugging.
37 * - errorentry/paranoidentry/zeroentry - Define exception entry points.
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/linkage.h>
41#include <asm/segment.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042#include <asm/cache.h>
43#include <asm/errno.h>
44#include <asm/dwarf2.h>
45#include <asm/calling.h>
Sam Ravnborge2d5df92005-09-09 21:28:48 +020046#include <asm/asm-offsets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/msr.h>
48#include <asm/unistd.h>
49#include <asm/thread_info.h>
50#include <asm/hw_irq.h>
Andi Kleen5f8efbb2006-01-16 01:56:39 +010051#include <asm/page.h>
Ingo Molnar2601e642006-07-03 00:24:45 -070052#include <asm/irqflags.h>
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +010053#include <asm/paravirt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55 .code64
56
Andi Kleendc37db42005-04-16 15:25:05 -070057#ifndef CONFIG_PREEMPT
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#define retint_kernel retint_restore_args
59#endif
Ingo Molnar2601e642006-07-03 00:24:45 -070060
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +010061#ifdef CONFIG_PARAVIRT
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -040062ENTRY(native_usergs_sysret64)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +010063 swapgs
64 sysretq
65#endif /* CONFIG_PARAVIRT */
66
Ingo Molnar2601e642006-07-03 00:24:45 -070067
68.macro TRACE_IRQS_IRETQ offset=ARGOFFSET
69#ifdef CONFIG_TRACE_IRQFLAGS
70 bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
71 jnc 1f
72 TRACE_IRQS_ON
731:
74#endif
75.endm
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/*
78 * C code is not supposed to know about undefined top of stack. Every time
79 * a C function with an pt_regs argument is called from the SYSCALL based
80 * fast path FIXUP_TOP_OF_STACK is needed.
81 * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs
82 * manipulation.
83 */
84
85 /* %rsp:at FRAMEEND */
86 .macro FIXUP_TOP_OF_STACK tmp
87 movq %gs:pda_oldrsp,\tmp
88 movq \tmp,RSP(%rsp)
89 movq $__USER_DS,SS(%rsp)
90 movq $__USER_CS,CS(%rsp)
91 movq $-1,RCX(%rsp)
92 movq R11(%rsp),\tmp /* get eflags */
93 movq \tmp,EFLAGS(%rsp)
94 .endm
95
96 .macro RESTORE_TOP_OF_STACK tmp,offset=0
97 movq RSP-\offset(%rsp),\tmp
98 movq \tmp,%gs:pda_oldrsp
99 movq EFLAGS-\offset(%rsp),\tmp
100 movq \tmp,R11-\offset(%rsp)
101 .endm
102
103 .macro FAKE_STACK_FRAME child_rip
104 /* push in order ss, rsp, eflags, cs, rip */
Andi Kleen3829ee62005-07-28 21:15:48 -0700105 xorl %eax, %eax
Jeremy Fitzhardingee04e0a62008-06-25 00:19:25 -0400106 pushq $__KERNEL_DS /* ss */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich7effaa82005-09-12 18:49:24 +0200108 /*CFI_REL_OFFSET ss,0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 pushq %rax /* rsp */
110 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich7effaa82005-09-12 18:49:24 +0200111 CFI_REL_OFFSET rsp,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 pushq $(1<<9) /* eflags - interrupts on */
113 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich7effaa82005-09-12 18:49:24 +0200114 /*CFI_REL_OFFSET rflags,0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 pushq $__KERNEL_CS /* cs */
116 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich7effaa82005-09-12 18:49:24 +0200117 /*CFI_REL_OFFSET cs,0*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 pushq \child_rip /* rip */
119 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich7effaa82005-09-12 18:49:24 +0200120 CFI_REL_OFFSET rip,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 pushq %rax /* orig rax */
122 CFI_ADJUST_CFA_OFFSET 8
123 .endm
124
125 .macro UNFAKE_STACK_FRAME
126 addq $8*6, %rsp
127 CFI_ADJUST_CFA_OFFSET -(6*8)
128 .endm
129
Jan Beulich7effaa82005-09-12 18:49:24 +0200130 .macro CFI_DEFAULT_STACK start=1
131 .if \start
132 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200133 CFI_SIGNAL_FRAME
Jan Beulich7effaa82005-09-12 18:49:24 +0200134 CFI_DEF_CFA rsp,SS+8
135 .else
136 CFI_DEF_CFA_OFFSET SS+8
137 .endif
138 CFI_REL_OFFSET r15,R15
139 CFI_REL_OFFSET r14,R14
140 CFI_REL_OFFSET r13,R13
141 CFI_REL_OFFSET r12,R12
142 CFI_REL_OFFSET rbp,RBP
143 CFI_REL_OFFSET rbx,RBX
144 CFI_REL_OFFSET r11,R11
145 CFI_REL_OFFSET r10,R10
146 CFI_REL_OFFSET r9,R9
147 CFI_REL_OFFSET r8,R8
148 CFI_REL_OFFSET rax,RAX
149 CFI_REL_OFFSET rcx,RCX
150 CFI_REL_OFFSET rdx,RDX
151 CFI_REL_OFFSET rsi,RSI
152 CFI_REL_OFFSET rdi,RDI
153 CFI_REL_OFFSET rip,RIP
154 /*CFI_REL_OFFSET cs,CS*/
155 /*CFI_REL_OFFSET rflags,EFLAGS*/
156 CFI_REL_OFFSET rsp,RSP
157 /*CFI_REL_OFFSET ss,SS*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 .endm
159/*
160 * A newly forked process directly context switches into this.
161 */
162/* rdi: prev */
163ENTRY(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 CFI_DEFAULT_STACK
Andi Kleen658fdbe2006-09-26 10:52:41 +0200165 push kernel_eflags(%rip)
166 CFI_ADJUST_CFA_OFFSET 4
167 popf # reset kernel eflags
168 CFI_ADJUST_CFA_OFFSET -4
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 call schedule_tail
170 GET_THREAD_INFO(%rcx)
171 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),threadinfo_flags(%rcx)
172 jnz rff_trace
173rff_action:
174 RESTORE_REST
175 testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread?
176 je int_ret_from_sys_call
177 testl $_TIF_IA32,threadinfo_flags(%rcx)
178 jnz int_ret_from_sys_call
179 RESTORE_TOP_OF_STACK %rdi,ARGOFFSET
180 jmp ret_from_sys_call
181rff_trace:
182 movq %rsp,%rdi
183 call syscall_trace_leave
184 GET_THREAD_INFO(%rcx)
185 jmp rff_action
186 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200187END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189/*
190 * System call entry. Upto 6 arguments in registers are supported.
191 *
192 * SYSCALL does not save anything on the stack and does not change the
193 * stack pointer.
194 */
195
196/*
197 * Register setup:
198 * rax system call number
199 * rdi arg0
200 * rcx return address for syscall/sysret, C arg3
201 * rsi arg1
202 * rdx arg2
203 * r10 arg3 (--> moved to rcx for C)
204 * r8 arg4
205 * r9 arg5
206 * r11 eflags for syscall/sysret, temporary for C
207 * r12-r15,rbp,rbx saved by C code, not touched.
208 *
209 * Interrupts are off on entry.
210 * Only called from user space.
211 *
212 * XXX if we had a free scratch register we could save the RSP into the stack frame
213 * and report it properly in ps. Unfortunately we haven't.
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200214 *
215 * When user can change the frames always force IRET. That is because
216 * it deals with uncanonical addresses better. SYSRET has trouble
217 * with them due to bugs in both AMD and Intel CPUs.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 */
219
220ENTRY(system_call)
Jan Beulich7effaa82005-09-12 18:49:24 +0200221 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200222 CFI_SIGNAL_FRAME
Jan Beulichdffead42006-06-26 13:57:38 +0200223 CFI_DEF_CFA rsp,PDA_STACKOFFSET
Jan Beulich7effaa82005-09-12 18:49:24 +0200224 CFI_REGISTER rip,rcx
225 /*CFI_REGISTER rflags,r11*/
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100226 SWAPGS_UNSAFE_STACK
227 /*
228 * A hypervisor implementation might want to use a label
229 * after the swapgs, so that it can do the swapgs
230 * for the guest and jump here on syscall.
231 */
232ENTRY(system_call_after_swapgs)
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 movq %rsp,%gs:pda_oldrsp
235 movq %gs:pda_kernelstack,%rsp
Ingo Molnar2601e642006-07-03 00:24:45 -0700236 /*
237 * No need to follow this irqs off/on section - it's straight
238 * and short:
239 */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100240 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 SAVE_ARGS 8,1
242 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
Jan Beulich7effaa82005-09-12 18:49:24 +0200243 movq %rcx,RIP-ARGOFFSET(%rsp)
244 CFI_REL_OFFSET rip,RIP-ARGOFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 GET_THREAD_INFO(%rcx)
246 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx)
247 jnz tracesys
248 cmpq $__NR_syscall_max,%rax
249 ja badsys
250 movq %r10,%rcx
251 call *sys_call_table(,%rax,8) # XXX: rip relative
252 movq %rax,RAX-ARGOFFSET(%rsp)
253/*
254 * Syscall return path ending with SYSRET (fast path)
255 * Has incomplete stack frame and undefined top of stack.
256 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257ret_from_sys_call:
Andi Kleen11b854b2005-04-16 15:25:02 -0700258 movl $_TIF_ALLWORK_MASK,%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /* edi: flagmask */
260sysret_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200261 LOCKDEP_SYS_EXIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 GET_THREAD_INFO(%rcx)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100263 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700264 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 movl threadinfo_flags(%rcx),%edx
266 andl %edi,%edx
267 jnz sysret_careful
Jan Beulichbcddc012006-12-07 02:14:02 +0100268 CFI_REMEMBER_STATE
Ingo Molnar2601e642006-07-03 00:24:45 -0700269 /*
270 * sysretq will re-enable interrupts:
271 */
272 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 movq RIP-ARGOFFSET(%rsp),%rcx
Jan Beulich7effaa82005-09-12 18:49:24 +0200274 CFI_REGISTER rip,rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 RESTORE_ARGS 0,-ARG_SKIP,1
Jan Beulich7effaa82005-09-12 18:49:24 +0200276 /*CFI_REGISTER rflags,r11*/
Jeremy Fitzhardingec7245da2008-06-25 00:19:27 -0400277 movq %gs:pda_oldrsp, %rsp
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400278 USERGS_SYSRET64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Jan Beulichbcddc012006-12-07 02:14:02 +0100280 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* Handle reschedules */
282 /* edx: work, edi: workmask */
283sysret_careful:
284 bt $TIF_NEED_RESCHED,%edx
285 jnc sysret_signal
Ingo Molnar2601e642006-07-03 00:24:45 -0700286 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100287 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200289 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 call schedule
291 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200292 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 jmp sysret_check
294
295 /* Handle a signal */
296sysret_signal:
Ingo Molnar2601e642006-07-03 00:24:45 -0700297 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100298 ENABLE_INTERRUPTS(CLBR_NONE)
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100299 testl $_TIF_DO_NOTIFY_MASK,%edx
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700300 jz 1f
301
302 /* Really a signal */
303 /* edx: work flags (arg3) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 leaq do_notify_resume(%rip),%rax
305 leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
306 xorl %esi,%esi # oldset -> arg2
307 call ptregscall_common
Andi Kleen10ffdbb2005-05-16 21:53:19 -07003081: movl $_TIF_NEED_RESCHED,%edi
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200309 /* Use IRET because user could have changed frame. This
310 works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100311 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700312 TRACE_IRQS_OFF
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200313 jmp int_with_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Jan Beulich7effaa82005-09-12 18:49:24 +0200315badsys:
316 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
317 jmp ret_from_sys_call
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 /* Do syscall tracing */
320tracesys:
321 SAVE_REST
Roland McGratha31f8dd2008-03-16 21:59:11 -0700322 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 FIXUP_TOP_OF_STACK %rdi
324 movq %rsp,%rdi
325 call syscall_trace_enter
326 LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */
327 RESTORE_REST
328 cmpq $__NR_syscall_max,%rax
Roland McGratha31f8dd2008-03-16 21:59:11 -0700329 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 movq %r10,%rcx /* fixup for C */
331 call *sys_call_table(,%rax,8)
Roland McGratha31f8dd2008-03-16 21:59:11 -0700332 movq %rax,RAX-ARGOFFSET(%rsp)
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200333 /* Use IRET because user could have changed frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335/*
336 * Syscall return path ending with IRET.
337 * Has correct top of stack, but partial stack frame.
Jan Beulichbcddc012006-12-07 02:14:02 +0100338 */
339 .globl int_ret_from_sys_call
340int_ret_from_sys_call:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100341 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700342 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 testl $3,CS-ARGOFFSET(%rsp)
344 je retint_restore_args
345 movl $_TIF_ALLWORK_MASK,%edi
346 /* edi: mask to check */
347int_with_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200348 LOCKDEP_SYS_EXIT_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 GET_THREAD_INFO(%rcx)
350 movl threadinfo_flags(%rcx),%edx
351 andl %edi,%edx
352 jnz int_careful
Andi Kleenbf2fcc62006-01-11 22:44:06 +0100353 andl $~TS_COMPAT,threadinfo_status(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 jmp retint_swapgs
355
356 /* Either reschedule or signal or syscall exit tracking needed. */
357 /* First do a reschedule test. */
358 /* edx: work, edi: workmask */
359int_careful:
360 bt $TIF_NEED_RESCHED,%edx
361 jnc int_very_careful
Ingo Molnar2601e642006-07-03 00:24:45 -0700362 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100363 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200365 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 call schedule
367 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200368 CFI_ADJUST_CFA_OFFSET -8
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100369 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700370 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 jmp int_with_check
372
373 /* handle signals and tracing -- both require a full stack frame */
374int_very_careful:
Ingo Molnar2601e642006-07-03 00:24:45 -0700375 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100376 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 SAVE_REST
378 /* Check for syscall exit trace */
379 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx
380 jz int_signal
381 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200382 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 leaq 8(%rsp),%rdi # &ptregs -> arg1
384 call syscall_trace_leave
385 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200386 CFI_ADJUST_CFA_OFFSET -8
Andi Kleen36c11042005-04-16 15:25:01 -0700387 andl $~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 jmp int_restore_rest
389
390int_signal:
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100391 testl $_TIF_DO_NOTIFY_MASK,%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 jz 1f
393 movq %rsp,%rdi # &ptregs -> arg1
394 xorl %esi,%esi # oldset -> arg2
395 call do_notify_resume
3961: movl $_TIF_NEED_RESCHED,%edi
397int_restore_rest:
398 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100399 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700400 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 jmp int_with_check
402 CFI_ENDPROC
Jan Beulichbcddc012006-12-07 02:14:02 +0100403END(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405/*
406 * Certain special system calls that need to save a complete full stack frame.
407 */
408
409 .macro PTREGSCALL label,func,arg
410 .globl \label
411\label:
412 leaq \func(%rip),%rax
413 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
414 jmp ptregscall_common
Jan Beulich4b787e02006-06-26 13:56:55 +0200415END(\label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 .endm
417
Jan Beulich7effaa82005-09-12 18:49:24 +0200418 CFI_STARTPROC
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 PTREGSCALL stub_clone, sys_clone, %r8
421 PTREGSCALL stub_fork, sys_fork, %rdi
422 PTREGSCALL stub_vfork, sys_vfork, %rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
424 PTREGSCALL stub_iopl, sys_iopl, %rsi
425
426ENTRY(ptregscall_common)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 popq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200428 CFI_ADJUST_CFA_OFFSET -8
429 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 SAVE_REST
431 movq %r11, %r15
Jan Beulich7effaa82005-09-12 18:49:24 +0200432 CFI_REGISTER rip, r15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 FIXUP_TOP_OF_STACK %r11
434 call *%rax
435 RESTORE_TOP_OF_STACK %r11
436 movq %r15, %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200437 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 RESTORE_REST
439 pushq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200440 CFI_ADJUST_CFA_OFFSET 8
441 CFI_REL_OFFSET rip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 ret
443 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200444END(ptregscall_common)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446ENTRY(stub_execve)
447 CFI_STARTPROC
448 popq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200449 CFI_ADJUST_CFA_OFFSET -8
450 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 SAVE_REST
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 FIXUP_TOP_OF_STACK %r11
Ingo Molnar5d119b22008-02-26 12:55:57 +0100453 movq %rsp, %rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 call sys_execve
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 RESTORE_TOP_OF_STACK %r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 movq %rax,RAX(%rsp)
457 RESTORE_REST
458 jmp int_ret_from_sys_call
459 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200460END(stub_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462/*
463 * sigreturn is special because it needs to restore all registers on return.
464 * This cannot be done with SYSRET, so use the IRET return path instead.
465 */
466ENTRY(stub_rt_sigreturn)
467 CFI_STARTPROC
Jan Beulich7effaa82005-09-12 18:49:24 +0200468 addq $8, %rsp
469 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 SAVE_REST
471 movq %rsp,%rdi
472 FIXUP_TOP_OF_STACK %r11
473 call sys_rt_sigreturn
474 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
475 RESTORE_REST
476 jmp int_ret_from_sys_call
477 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200478END(stub_rt_sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Jan Beulich7effaa82005-09-12 18:49:24 +0200480/*
481 * initial frame state for interrupts and exceptions
482 */
483 .macro _frame ref
484 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200485 CFI_SIGNAL_FRAME
Jan Beulich7effaa82005-09-12 18:49:24 +0200486 CFI_DEF_CFA rsp,SS+8-\ref
487 /*CFI_REL_OFFSET ss,SS-\ref*/
488 CFI_REL_OFFSET rsp,RSP-\ref
489 /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
490 /*CFI_REL_OFFSET cs,CS-\ref*/
491 CFI_REL_OFFSET rip,RIP-\ref
492 .endm
493
494/* initial frame state for interrupts (and exceptions without error code) */
495#define INTR_FRAME _frame RIP
496/* initial frame state for exceptions with error code (and interrupts with
497 vector already pushed) */
498#define XCPT_FRAME _frame ORIG_RAX
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500/*
501 * Interrupt entry/exit.
502 *
503 * Interrupt entry points save only callee clobbered registers in fast path.
504 *
505 * Entry runs with interrupts off.
506 */
507
508/* 0(%rsp): interrupt number */
509 .macro interrupt func
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 cld
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 SAVE_ARGS
512 leaq -ARGOFFSET(%rsp),%rdi # arg1 for handler
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200513 pushq %rbp
514 CFI_ADJUST_CFA_OFFSET 8
515 CFI_REL_OFFSET rbp, 0
516 movq %rsp,%rbp
517 CFI_DEF_CFA_REGISTER rbp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 testl $3,CS(%rdi)
519 je 1f
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100520 SWAPGS
Andi Kleen96e54042006-09-26 10:52:39 +0200521 /* irqcount is used to check if a CPU is already on an interrupt
522 stack or not. While this is essentially redundant with preempt_count
523 it is a little cheaper to use a separate counter in the PDA
524 (short of moving irq_enter into assembly, which would be too
525 much work) */
5261: incl %gs:pda_irqcount
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200527 cmoveq %gs:pda_irqstackptr,%rsp
Andi Kleen26995002006-08-02 22:37:28 +0200528 push %rbp # backlink for old unwinder
Ingo Molnar2601e642006-07-03 00:24:45 -0700529 /*
530 * We entered an interrupt context - irqs are off:
531 */
532 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 call \func
534 .endm
535
536ENTRY(common_interrupt)
Jan Beulich7effaa82005-09-12 18:49:24 +0200537 XCPT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 interrupt do_IRQ
539 /* 0(%rsp): oldrsp-ARGOFFSET */
Jan Beulich7effaa82005-09-12 18:49:24 +0200540ret_from_intr:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100541 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700542 TRACE_IRQS_OFF
Andi Kleen3829ee62005-07-28 21:15:48 -0700543 decl %gs:pda_irqcount
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200544 leaveq
Jan Beulich7effaa82005-09-12 18:49:24 +0200545 CFI_DEF_CFA_REGISTER rsp
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200546 CFI_ADJUST_CFA_OFFSET -8
Jan Beulich7effaa82005-09-12 18:49:24 +0200547exit_intr:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 GET_THREAD_INFO(%rcx)
549 testl $3,CS-ARGOFFSET(%rsp)
550 je retint_kernel
551
552 /* Interrupt came from user space */
553 /*
554 * Has a correct top of stack, but a partial stack frame
555 * %rcx: thread info. Interrupts off.
556 */
557retint_with_reschedule:
558 movl $_TIF_WORK_MASK,%edi
Jan Beulich7effaa82005-09-12 18:49:24 +0200559retint_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200560 LOCKDEP_SYS_EXIT_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 movl threadinfo_flags(%rcx),%edx
562 andl %edi,%edx
Jan Beulich7effaa82005-09-12 18:49:24 +0200563 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 jnz retint_careful
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200565
566retint_swapgs: /* return to user-space */
Ingo Molnar2601e642006-07-03 00:24:45 -0700567 /*
568 * The iretq could re-enable interrupts:
569 */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100570 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700571 TRACE_IRQS_IRETQ
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100572 SWAPGS
Ingo Molnar2601e642006-07-03 00:24:45 -0700573 jmp restore_args
574
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200575retint_restore_args: /* return to kernel space */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100576 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700577 /*
578 * The iretq could re-enable interrupts:
579 */
580 TRACE_IRQS_IRETQ
581restore_args:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100582 RESTORE_ARGS 0,8,0
583
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200584irq_return:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100585 INTERRUPT_RETURN
Ingo Molnar3701d8632008-02-09 23:24:08 +0100586
587 .section __ex_table, "a"
588 .quad irq_return, bad_iret
589 .previous
590
591#ifdef CONFIG_PARAVIRT
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100592ENTRY(native_iret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 iretq
594
595 .section __ex_table,"a"
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100596 .quad native_iret, bad_iret
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 .previous
Ingo Molnar3701d8632008-02-09 23:24:08 +0100598#endif
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 .section .fixup,"ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601bad_iret:
Roland McGrath3aa4b372008-02-06 22:39:43 +0100602 /*
603 * The iret traps when the %cs or %ss being restored is bogus.
604 * We've lost the original trap vector and error code.
605 * #GPF is the most likely one to get for an invalid selector.
606 * So pretend we completed the iret and took the #GPF in user mode.
607 *
608 * We are now running with the kernel GS after exception recovery.
609 * But error_entry expects us to have user GS to match the user %cs,
610 * so swap back.
611 */
612 pushq $0
613
614 SWAPGS
615 jmp general_protection
616
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100617 .previous
618
Jan Beulich7effaa82005-09-12 18:49:24 +0200619 /* edi: workmask, edx: work */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620retint_careful:
Jan Beulich7effaa82005-09-12 18:49:24 +0200621 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 bt $TIF_NEED_RESCHED,%edx
623 jnc retint_signal
Ingo Molnar2601e642006-07-03 00:24:45 -0700624 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100625 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200627 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 call schedule
629 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200630 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 GET_THREAD_INFO(%rcx)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100632 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700633 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 jmp retint_check
635
636retint_signal:
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100637 testl $_TIF_DO_NOTIFY_MASK,%edx
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700638 jz retint_swapgs
Ingo Molnar2601e642006-07-03 00:24:45 -0700639 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100640 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 SAVE_REST
642 movq $-1,ORIG_RAX(%rsp)
Andi Kleen3829ee62005-07-28 21:15:48 -0700643 xorl %esi,%esi # oldset
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 movq %rsp,%rdi # &pt_regs
645 call do_notify_resume
646 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100647 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700648 TRACE_IRQS_OFF
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700649 movl $_TIF_NEED_RESCHED,%edi
Andi Kleenbe9e6872005-05-01 08:58:51 -0700650 GET_THREAD_INFO(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 jmp retint_check
652
653#ifdef CONFIG_PREEMPT
654 /* Returning to kernel space. Check if we need preemption */
655 /* rcx: threadinfo. interrupts off. */
Andi Kleenb06baba2006-09-26 10:52:29 +0200656ENTRY(retint_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 cmpl $0,threadinfo_preempt_count(%rcx)
658 jnz retint_restore_args
659 bt $TIF_NEED_RESCHED,threadinfo_flags(%rcx)
660 jnc retint_restore_args
661 bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */
662 jnc retint_restore_args
663 call preempt_schedule_irq
664 jmp exit_intr
665#endif
Jan Beulich4b787e02006-06-26 13:56:55 +0200666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200668END(common_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
670/*
671 * APIC interrupts.
672 */
673 .macro apicinterrupt num,func
Jan Beulich7effaa82005-09-12 18:49:24 +0200674 INTR_FRAME
Rusty Russell19eadf92006-06-27 02:53:44 -0700675 pushq $~(\num)
Jan Beulich7effaa82005-09-12 18:49:24 +0200676 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 interrupt \func
678 jmp ret_from_intr
679 CFI_ENDPROC
680 .endm
681
682ENTRY(thermal_interrupt)
683 apicinterrupt THERMAL_APIC_VECTOR,smp_thermal_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200684END(thermal_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Jacob Shin89b831e2005-11-05 17:25:53 +0100686ENTRY(threshold_interrupt)
687 apicinterrupt THRESHOLD_APIC_VECTOR,mce_threshold_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200688END(threshold_interrupt)
Jacob Shin89b831e2005-11-05 17:25:53 +0100689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690#ifdef CONFIG_SMP
691ENTRY(reschedule_interrupt)
692 apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200693END(reschedule_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Andi Kleene5bc8b62005-09-12 18:49:24 +0200695 .macro INVALIDATE_ENTRY num
696ENTRY(invalidate_interrupt\num)
697 apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200698END(invalidate_interrupt\num)
Andi Kleene5bc8b62005-09-12 18:49:24 +0200699 .endm
700
701 INVALIDATE_ENTRY 0
702 INVALIDATE_ENTRY 1
703 INVALIDATE_ENTRY 2
704 INVALIDATE_ENTRY 3
705 INVALIDATE_ENTRY 4
706 INVALIDATE_ENTRY 5
707 INVALIDATE_ENTRY 6
708 INVALIDATE_ENTRY 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
710ENTRY(call_function_interrupt)
711 apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200712END(call_function_interrupt)
Eric W. Biederman61014292007-02-23 04:40:58 -0700713ENTRY(irq_move_cleanup_interrupt)
714 apicinterrupt IRQ_MOVE_CLEANUP_VECTOR,smp_irq_move_cleanup_interrupt
715END(irq_move_cleanup_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716#endif
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718ENTRY(apic_timer_interrupt)
719 apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200720END(apic_timer_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Cliff Wickman18129242008-06-02 08:56:14 -0500722ENTRY(uv_bau_message_intr1)
723 apicinterrupt 220,uv_bau_message_interrupt
724END(uv_bau_message_intr1)
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726ENTRY(error_interrupt)
727 apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200728END(error_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730ENTRY(spurious_interrupt)
731 apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200732END(spurious_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
734/*
735 * Exception entry points.
736 */
737 .macro zeroentry sym
Jan Beulich7effaa82005-09-12 18:49:24 +0200738 INTR_FRAME
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -0400739 PARAVIRT_ADJUST_EXCEPTION_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 pushq $0 /* push error code/oldrax */
Jan Beulich7effaa82005-09-12 18:49:24 +0200741 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 pushq %rax /* push real oldrax to the rdi slot */
Jan Beulich7effaa82005-09-12 18:49:24 +0200743 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich37550902007-05-02 19:27:05 +0200744 CFI_REL_OFFSET rax,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 leaq \sym(%rip),%rax
746 jmp error_entry
Jan Beulich7effaa82005-09-12 18:49:24 +0200747 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .endm
749
750 .macro errorentry sym
Jan Beulich7effaa82005-09-12 18:49:24 +0200751 XCPT_FRAME
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -0400752 PARAVIRT_ADJUST_EXCEPTION_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 pushq %rax
Jan Beulich7effaa82005-09-12 18:49:24 +0200754 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich37550902007-05-02 19:27:05 +0200755 CFI_REL_OFFSET rax,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 leaq \sym(%rip),%rax
757 jmp error_entry
Jan Beulich7effaa82005-09-12 18:49:24 +0200758 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 .endm
760
761 /* error code is on the stack already */
762 /* handle NMI like exceptions that can happen everywhere */
Ingo Molnar2601e642006-07-03 00:24:45 -0700763 .macro paranoidentry sym, ist=0, irqtrace=1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 SAVE_ALL
765 cld
766 movl $1,%ebx
767 movl $MSR_GS_BASE,%ecx
768 rdmsr
769 testl %edx,%edx
770 js 1f
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100771 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 xorl %ebx,%ebx
Jan Beulichb556b352006-01-11 22:43:00 +01007731:
774 .if \ist
775 movq %gs:pda_data_offset, %rbp
776 .endif
777 movq %rsp,%rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 movq ORIG_RAX(%rsp),%rsi
779 movq $-1,ORIG_RAX(%rsp)
Jan Beulichb556b352006-01-11 22:43:00 +0100780 .if \ist
Andi Kleen5f8efbb2006-01-16 01:56:39 +0100781 subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
Jan Beulichb556b352006-01-11 22:43:00 +0100782 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 call \sym
Jan Beulichb556b352006-01-11 22:43:00 +0100784 .if \ist
Andi Kleen5f8efbb2006-01-16 01:56:39 +0100785 addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
Jan Beulichb556b352006-01-11 22:43:00 +0100786 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100787 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700788 .if \irqtrace
789 TRACE_IRQS_OFF
790 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 .endm
Ingo Molnar2601e642006-07-03 00:24:45 -0700792
793 /*
794 * "Paranoid" exit path from exception stack.
795 * Paranoid because this is used by NMIs and cannot take
796 * any kernel state for granted.
797 * We don't do kernel preemption checks here, because only
798 * NMI should be common and it does not enable IRQs and
799 * cannot get reschedule ticks.
800 *
801 * "trace" is 0 for the NMI handler only, because irq-tracing
802 * is fundamentally NMI-unsafe. (we cannot change the soft and
803 * hard flags at once, atomically)
804 */
805 .macro paranoidexit trace=1
806 /* ebx: no swapgs flag */
807paranoid_exit\trace:
808 testl %ebx,%ebx /* swapgs needed? */
809 jnz paranoid_restore\trace
810 testl $3,CS(%rsp)
811 jnz paranoid_userspace\trace
812paranoid_swapgs\trace:
Andi Kleen7a0a2df2006-09-26 10:52:37 +0200813 .if \trace
Ingo Molnar2601e642006-07-03 00:24:45 -0700814 TRACE_IRQS_IRETQ 0
Andi Kleen7a0a2df2006-09-26 10:52:37 +0200815 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100816 SWAPGS_UNSAFE_STACK
Ingo Molnar2601e642006-07-03 00:24:45 -0700817paranoid_restore\trace:
818 RESTORE_ALL 8
Ingo Molnar3701d8632008-02-09 23:24:08 +0100819 jmp irq_return
Ingo Molnar2601e642006-07-03 00:24:45 -0700820paranoid_userspace\trace:
821 GET_THREAD_INFO(%rcx)
822 movl threadinfo_flags(%rcx),%ebx
823 andl $_TIF_WORK_MASK,%ebx
824 jz paranoid_swapgs\trace
825 movq %rsp,%rdi /* &pt_regs */
826 call sync_regs
827 movq %rax,%rsp /* switch stack for scheduling */
828 testl $_TIF_NEED_RESCHED,%ebx
829 jnz paranoid_schedule\trace
830 movl %ebx,%edx /* arg3: thread flags */
831 .if \trace
832 TRACE_IRQS_ON
833 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100834 ENABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700835 xorl %esi,%esi /* arg2: oldset */
836 movq %rsp,%rdi /* arg1: &pt_regs */
837 call do_notify_resume
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100838 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700839 .if \trace
840 TRACE_IRQS_OFF
841 .endif
842 jmp paranoid_userspace\trace
843paranoid_schedule\trace:
844 .if \trace
845 TRACE_IRQS_ON
846 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100847 ENABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700848 call schedule
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100849 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700850 .if \trace
851 TRACE_IRQS_OFF
852 .endif
853 jmp paranoid_userspace\trace
854 CFI_ENDPROC
855 .endm
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857/*
858 * Exception entry point. This expects an error code/orig_rax on the stack
859 * and the exception handler in %rax.
860 */
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200861KPROBE_ENTRY(error_entry)
Jan Beulich7effaa82005-09-12 18:49:24 +0200862 _frame RDI
Jan Beulich37550902007-05-02 19:27:05 +0200863 CFI_REL_OFFSET rax,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 /* rdi slot contains rax, oldrax contains error code */
865 cld
866 subq $14*8,%rsp
867 CFI_ADJUST_CFA_OFFSET (14*8)
868 movq %rsi,13*8(%rsp)
869 CFI_REL_OFFSET rsi,RSI
870 movq 14*8(%rsp),%rsi /* load rax from rdi slot */
Jan Beulich37550902007-05-02 19:27:05 +0200871 CFI_REGISTER rax,rsi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 movq %rdx,12*8(%rsp)
873 CFI_REL_OFFSET rdx,RDX
874 movq %rcx,11*8(%rsp)
875 CFI_REL_OFFSET rcx,RCX
876 movq %rsi,10*8(%rsp) /* store rax */
877 CFI_REL_OFFSET rax,RAX
878 movq %r8, 9*8(%rsp)
879 CFI_REL_OFFSET r8,R8
880 movq %r9, 8*8(%rsp)
881 CFI_REL_OFFSET r9,R9
882 movq %r10,7*8(%rsp)
883 CFI_REL_OFFSET r10,R10
884 movq %r11,6*8(%rsp)
885 CFI_REL_OFFSET r11,R11
886 movq %rbx,5*8(%rsp)
887 CFI_REL_OFFSET rbx,RBX
888 movq %rbp,4*8(%rsp)
889 CFI_REL_OFFSET rbp,RBP
890 movq %r12,3*8(%rsp)
891 CFI_REL_OFFSET r12,R12
892 movq %r13,2*8(%rsp)
893 CFI_REL_OFFSET r13,R13
894 movq %r14,1*8(%rsp)
895 CFI_REL_OFFSET r14,R14
896 movq %r15,(%rsp)
897 CFI_REL_OFFSET r15,R15
898 xorl %ebx,%ebx
899 testl $3,CS(%rsp)
900 je error_kernelspace
901error_swapgs:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100902 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903error_sti:
904 movq %rdi,RDI(%rsp)
Jan Beulich37550902007-05-02 19:27:05 +0200905 CFI_REL_OFFSET rdi,RDI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 movq %rsp,%rdi
907 movq ORIG_RAX(%rsp),%rsi /* get error code */
908 movq $-1,ORIG_RAX(%rsp)
909 call *%rax
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200910 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
911error_exit:
912 movl %ebx,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100914 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700915 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 GET_THREAD_INFO(%rcx)
917 testl %eax,%eax
918 jne retint_kernel
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200919 LOCKDEP_SYS_EXIT_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 movl threadinfo_flags(%rcx),%edx
921 movl $_TIF_WORK_MASK,%edi
922 andl %edi,%edx
923 jnz retint_careful
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200924 jmp retint_swapgs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 CFI_ENDPROC
926
927error_kernelspace:
928 incl %ebx
929 /* There are two places in the kernel that can potentially fault with
930 usergs. Handle them here. The exception handlers after
931 iret run with kernel gs again, so don't set the user space flag.
932 B stepping K8s sometimes report an truncated RIP for IRET
933 exceptions returning to compat mode. Check for these here too. */
Vegard Nossum9d8ad5d2008-06-27 17:22:17 +0200934 leaq irq_return(%rip),%rcx
935 cmpq %rcx,RIP(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 je error_swapgs
Vegard Nossum9d8ad5d2008-06-27 17:22:17 +0200937 movl %ecx,%ecx /* zero extend */
938 cmpq %rcx,RIP(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 je error_swapgs
940 cmpq $gs_change,RIP(%rsp)
941 je error_swapgs
942 jmp error_sti
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200943KPROBE_END(error_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
945 /* Reload gs selector with exception handling */
946 /* edi: new selector */
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400947ENTRY(native_load_gs_index)
Jan Beulich7effaa82005-09-12 18:49:24 +0200948 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 pushf
Jan Beulich7effaa82005-09-12 18:49:24 +0200950 CFI_ADJUST_CFA_OFFSET 8
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100951 DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
952 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953gs_change:
954 movl %edi,%gs
9552: mfence /* workaround */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100956 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 popf
Jan Beulich7effaa82005-09-12 18:49:24 +0200958 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 ret
Jan Beulich7effaa82005-09-12 18:49:24 +0200960 CFI_ENDPROC
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400961ENDPROC(native_load_gs_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 .section __ex_table,"a"
964 .align 8
965 .quad gs_change,bad_gs
966 .previous
967 .section .fixup,"ax"
968 /* running with kernelgs */
969bad_gs:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100970 SWAPGS /* switch back to user gs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 xorl %eax,%eax
972 movl %eax,%gs
973 jmp 2b
974 .previous
975
976/*
977 * Create a kernel thread.
978 *
979 * C extern interface:
980 * extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
981 *
982 * asm input arguments:
983 * rdi: fn, rsi: arg, rdx: flags
984 */
985ENTRY(kernel_thread)
986 CFI_STARTPROC
987 FAKE_STACK_FRAME $child_rip
988 SAVE_ALL
989
990 # rdi: flags, rsi: usp, rdx: will be &pt_regs
991 movq %rdx,%rdi
992 orq kernel_thread_flags(%rip),%rdi
993 movq $-1, %rsi
994 movq %rsp, %rdx
995
996 xorl %r8d,%r8d
997 xorl %r9d,%r9d
998
999 # clone now
1000 call do_fork
1001 movq %rax,RAX(%rsp)
1002 xorl %edi,%edi
1003
1004 /*
1005 * It isn't worth to check for reschedule here,
1006 * so internally to the x86_64 port you can rely on kernel_thread()
1007 * not to reschedule the child before returning, this avoids the need
1008 * of hacks for example to fork off the per-CPU idle tasks.
1009 * [Hopefully no generic code relies on the reschedule -AK]
1010 */
1011 RESTORE_ALL
1012 UNFAKE_STACK_FRAME
1013 ret
1014 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001015ENDPROC(kernel_thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017child_rip:
Andi Kleenc05991e2006-08-30 19:37:08 +02001018 pushq $0 # fake return address
1019 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 /*
1021 * Here we are in the child and the registers are set as they were
1022 * at kernel_thread() invocation in the parent.
1023 */
1024 movq %rdi, %rax
1025 movq %rsi, %rdi
1026 call *%rax
1027 # exit
Andrey Mirkin1c5b5cf2007-10-17 18:04:33 +02001028 mov %eax, %edi
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 call do_exit
Andi Kleenc05991e2006-08-30 19:37:08 +02001030 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001031ENDPROC(child_rip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033/*
1034 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
1035 *
1036 * C extern interface:
1037 * extern long execve(char *name, char **argv, char **envp)
1038 *
1039 * asm input arguments:
1040 * rdi: name, rsi: argv, rdx: envp
1041 *
1042 * We want to fallback into:
Ingo Molnar5d119b22008-02-26 12:55:57 +01001043 * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 *
1045 * do_sys_execve asm fallback arguments:
Ingo Molnar5d119b22008-02-26 12:55:57 +01001046 * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 */
Arnd Bergmann3db03b42006-10-02 02:18:31 -07001048ENTRY(kernel_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 CFI_STARTPROC
1050 FAKE_STACK_FRAME $0
1051 SAVE_ALL
Ingo Molnar5d119b22008-02-26 12:55:57 +01001052 movq %rsp,%rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 call sys_execve
1054 movq %rax, RAX(%rsp)
1055 RESTORE_REST
1056 testq %rax,%rax
1057 je int_ret_from_sys_call
1058 RESTORE_ARGS
1059 UNFAKE_STACK_FRAME
1060 ret
1061 CFI_ENDPROC
Arnd Bergmann3db03b42006-10-02 02:18:31 -07001062ENDPROC(kernel_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001064KPROBE_ENTRY(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 errorentry do_page_fault
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001066KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068ENTRY(coprocessor_error)
1069 zeroentry do_coprocessor_error
Jan Beulich4b787e02006-06-26 13:56:55 +02001070END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072ENTRY(simd_coprocessor_error)
1073 zeroentry do_simd_coprocessor_error
Jan Beulich4b787e02006-06-26 13:56:55 +02001074END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076ENTRY(device_not_available)
1077 zeroentry math_state_restore
Jan Beulich4b787e02006-06-26 13:56:55 +02001078END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 /* runs on exception stack */
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001081KPROBE_ENTRY(debug)
Jan Beulich7effaa82005-09-12 18:49:24 +02001082 INTR_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 pushq $0
1084 CFI_ADJUST_CFA_OFFSET 8
Andi Kleen5f8efbb2006-01-16 01:56:39 +01001085 paranoidentry do_debug, DEBUG_STACK
Ingo Molnar2601e642006-07-03 00:24:45 -07001086 paranoidexit
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001087KPROBE_END(debug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 /* runs on exception stack */
Andi Kleeneddb6fb2006-02-03 21:50:41 +01001090KPROBE_ENTRY(nmi)
Jan Beulich7effaa82005-09-12 18:49:24 +02001091 INTR_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 pushq $-1
Jan Beulich7effaa82005-09-12 18:49:24 +02001093 CFI_ADJUST_CFA_OFFSET 8
Ingo Molnar2601e642006-07-03 00:24:45 -07001094 paranoidentry do_nmi, 0, 0
1095#ifdef CONFIG_TRACE_IRQFLAGS
1096 paranoidexit 0
1097#else
1098 jmp paranoid_exit1
1099 CFI_ENDPROC
1100#endif
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001101KPROBE_END(nmi)
Andi Kleen6fefb0d2005-04-16 15:25:03 -07001102
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001103KPROBE_ENTRY(int3)
Jan Beulichb556b352006-01-11 22:43:00 +01001104 INTR_FRAME
1105 pushq $0
1106 CFI_ADJUST_CFA_OFFSET 8
Andi Kleen5f8efbb2006-01-16 01:56:39 +01001107 paranoidentry do_int3, DEBUG_STACK
Ingo Molnar2601e642006-07-03 00:24:45 -07001108 jmp paranoid_exit1
Jan Beulichb556b352006-01-11 22:43:00 +01001109 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001110KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
1112ENTRY(overflow)
1113 zeroentry do_overflow
Jan Beulich4b787e02006-06-26 13:56:55 +02001114END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116ENTRY(bounds)
1117 zeroentry do_bounds
Jan Beulich4b787e02006-06-26 13:56:55 +02001118END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119
1120ENTRY(invalid_op)
1121 zeroentry do_invalid_op
Jan Beulich4b787e02006-06-26 13:56:55 +02001122END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124ENTRY(coprocessor_segment_overrun)
1125 zeroentry do_coprocessor_segment_overrun
Jan Beulich4b787e02006-06-26 13:56:55 +02001126END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 /* runs on exception stack */
1129ENTRY(double_fault)
Jan Beulich7effaa82005-09-12 18:49:24 +02001130 XCPT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 paranoidentry do_double_fault
Ingo Molnar2601e642006-07-03 00:24:45 -07001132 jmp paranoid_exit1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001134END(double_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136ENTRY(invalid_TSS)
1137 errorentry do_invalid_TSS
Jan Beulich4b787e02006-06-26 13:56:55 +02001138END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140ENTRY(segment_not_present)
1141 errorentry do_segment_not_present
Jan Beulich4b787e02006-06-26 13:56:55 +02001142END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 /* runs on exception stack */
1145ENTRY(stack_segment)
Jan Beulich7effaa82005-09-12 18:49:24 +02001146 XCPT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 paranoidentry do_stack_segment
Ingo Molnar2601e642006-07-03 00:24:45 -07001148 jmp paranoid_exit1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001150END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001152KPROBE_ENTRY(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 errorentry do_general_protection
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001154KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
1156ENTRY(alignment_check)
1157 errorentry do_alignment_check
Jan Beulich4b787e02006-06-26 13:56:55 +02001158END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160ENTRY(divide_error)
1161 zeroentry do_divide_error
Jan Beulich4b787e02006-06-26 13:56:55 +02001162END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164ENTRY(spurious_interrupt_bug)
1165 zeroentry do_spurious_interrupt_bug
Jan Beulich4b787e02006-06-26 13:56:55 +02001166END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168#ifdef CONFIG_X86_MCE
1169 /* runs on exception stack */
1170ENTRY(machine_check)
Jan Beulich7effaa82005-09-12 18:49:24 +02001171 INTR_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 pushq $0
1173 CFI_ADJUST_CFA_OFFSET 8
1174 paranoidentry do_machine_check
Ingo Molnar2601e642006-07-03 00:24:45 -07001175 jmp paranoid_exit1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001177END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178#endif
1179
Andi Kleen26995002006-08-02 22:37:28 +02001180/* Call softirq on interrupt stack. Interrupts are off. */
Andi Kleened6b6762005-07-28 21:15:49 -07001181ENTRY(call_softirq)
Jan Beulich7effaa82005-09-12 18:49:24 +02001182 CFI_STARTPROC
Andi Kleen26995002006-08-02 22:37:28 +02001183 push %rbp
1184 CFI_ADJUST_CFA_OFFSET 8
1185 CFI_REL_OFFSET rbp,0
1186 mov %rsp,%rbp
1187 CFI_DEF_CFA_REGISTER rbp
Andi Kleened6b6762005-07-28 21:15:49 -07001188 incl %gs:pda_irqcount
Andi Kleen26995002006-08-02 22:37:28 +02001189 cmove %gs:pda_irqstackptr,%rsp
1190 push %rbp # backlink for old unwinder
Andi Kleened6b6762005-07-28 21:15:49 -07001191 call __do_softirq
Andi Kleen26995002006-08-02 22:37:28 +02001192 leaveq
Jan Beulich7effaa82005-09-12 18:49:24 +02001193 CFI_DEF_CFA_REGISTER rsp
Andi Kleen26995002006-08-02 22:37:28 +02001194 CFI_ADJUST_CFA_OFFSET -8
Andi Kleened6b6762005-07-28 21:15:49 -07001195 decl %gs:pda_irqcount
Andi Kleened6b6762005-07-28 21:15:49 -07001196 ret
Jan Beulich7effaa82005-09-12 18:49:24 +02001197 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001198ENDPROC(call_softirq)
Andi Kleen75154f42007-06-23 02:29:25 +02001199
1200KPROBE_ENTRY(ignore_sysret)
1201 CFI_STARTPROC
1202 mov $-ENOSYS,%eax
1203 sysret
1204 CFI_ENDPROC
1205ENDPROC(ignore_sysret)