blob: 466b9284ed2f31a1aead9185bbf3d038196eac0f [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)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300171 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 jnz rff_trace
173rff_action:
174 RESTORE_REST
175 testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread?
176 je int_ret_from_sys_call
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300177 testl $_TIF_IA32,TI_flags(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 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)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300246 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP), \
247 TI_flags(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 jnz tracesys
249 cmpq $__NR_syscall_max,%rax
250 ja badsys
251 movq %r10,%rcx
252 call *sys_call_table(,%rax,8) # XXX: rip relative
253 movq %rax,RAX-ARGOFFSET(%rsp)
254/*
255 * Syscall return path ending with SYSRET (fast path)
256 * Has incomplete stack frame and undefined top of stack.
257 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258ret_from_sys_call:
Andi Kleen11b854b2005-04-16 15:25:02 -0700259 movl $_TIF_ALLWORK_MASK,%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 /* edi: flagmask */
261sysret_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200262 LOCKDEP_SYS_EXIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 GET_THREAD_INFO(%rcx)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100264 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700265 TRACE_IRQS_OFF
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300266 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 andl %edi,%edx
268 jnz sysret_careful
Jan Beulichbcddc012006-12-07 02:14:02 +0100269 CFI_REMEMBER_STATE
Ingo Molnar2601e642006-07-03 00:24:45 -0700270 /*
271 * sysretq will re-enable interrupts:
272 */
273 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 movq RIP-ARGOFFSET(%rsp),%rcx
Jan Beulich7effaa82005-09-12 18:49:24 +0200275 CFI_REGISTER rip,rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 RESTORE_ARGS 0,-ARG_SKIP,1
Jan Beulich7effaa82005-09-12 18:49:24 +0200277 /*CFI_REGISTER rflags,r11*/
Jeremy Fitzhardingec7245da2008-06-25 00:19:27 -0400278 movq %gs:pda_oldrsp, %rsp
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400279 USERGS_SYSRET64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
Jan Beulichbcddc012006-12-07 02:14:02 +0100281 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 /* Handle reschedules */
283 /* edx: work, edi: workmask */
284sysret_careful:
285 bt $TIF_NEED_RESCHED,%edx
286 jnc sysret_signal
Ingo Molnar2601e642006-07-03 00:24:45 -0700287 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100288 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200290 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 call schedule
292 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200293 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 jmp sysret_check
295
296 /* Handle a signal */
297sysret_signal:
Ingo Molnar2601e642006-07-03 00:24:45 -0700298 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100299 ENABLE_INTERRUPTS(CLBR_NONE)
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100300 testl $_TIF_DO_NOTIFY_MASK,%edx
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700301 jz 1f
302
303 /* Really a signal */
304 /* edx: work flags (arg3) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 leaq do_notify_resume(%rip),%rax
306 leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
307 xorl %esi,%esi # oldset -> arg2
308 call ptregscall_common
Andi Kleen10ffdbb2005-05-16 21:53:19 -07003091: movl $_TIF_NEED_RESCHED,%edi
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200310 /* Use IRET because user could have changed frame. This
311 works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100312 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700313 TRACE_IRQS_OFF
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200314 jmp int_with_check
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Jan Beulich7effaa82005-09-12 18:49:24 +0200316badsys:
317 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
318 jmp ret_from_sys_call
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 /* Do syscall tracing */
321tracesys:
322 SAVE_REST
Roland McGratha31f8dd2008-03-16 21:59:11 -0700323 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 FIXUP_TOP_OF_STACK %rdi
325 movq %rsp,%rdi
326 call syscall_trace_enter
327 LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */
328 RESTORE_REST
329 cmpq $__NR_syscall_max,%rax
Roland McGratha31f8dd2008-03-16 21:59:11 -0700330 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 movq %r10,%rcx /* fixup for C */
332 call *sys_call_table(,%rax,8)
Roland McGratha31f8dd2008-03-16 21:59:11 -0700333 movq %rax,RAX-ARGOFFSET(%rsp)
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200334 /* Use IRET because user could have changed frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336/*
337 * Syscall return path ending with IRET.
338 * Has correct top of stack, but partial stack frame.
Jan Beulichbcddc012006-12-07 02:14:02 +0100339 */
340 .globl int_ret_from_sys_call
341int_ret_from_sys_call:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100342 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700343 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 testl $3,CS-ARGOFFSET(%rsp)
345 je retint_restore_args
346 movl $_TIF_ALLWORK_MASK,%edi
347 /* edi: mask to check */
348int_with_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200349 LOCKDEP_SYS_EXIT_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 GET_THREAD_INFO(%rcx)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300351 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 andl %edi,%edx
353 jnz int_careful
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300354 andl $~TS_COMPAT,TI_status(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 jmp retint_swapgs
356
357 /* Either reschedule or signal or syscall exit tracking needed. */
358 /* First do a reschedule test. */
359 /* edx: work, edi: workmask */
360int_careful:
361 bt $TIF_NEED_RESCHED,%edx
362 jnc int_very_careful
Ingo Molnar2601e642006-07-03 00:24:45 -0700363 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100364 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200366 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 call schedule
368 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200369 CFI_ADJUST_CFA_OFFSET -8
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100370 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700371 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 jmp int_with_check
373
374 /* handle signals and tracing -- both require a full stack frame */
375int_very_careful:
Ingo Molnar2601e642006-07-03 00:24:45 -0700376 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100377 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 SAVE_REST
379 /* Check for syscall exit trace */
380 testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx
381 jz int_signal
382 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200383 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 leaq 8(%rsp),%rdi # &ptregs -> arg1
385 call syscall_trace_leave
386 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200387 CFI_ADJUST_CFA_OFFSET -8
Andi Kleen36c11042005-04-16 15:25:01 -0700388 andl $~(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 jmp int_restore_rest
390
391int_signal:
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100392 testl $_TIF_DO_NOTIFY_MASK,%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 jz 1f
394 movq %rsp,%rdi # &ptregs -> arg1
395 xorl %esi,%esi # oldset -> arg2
396 call do_notify_resume
3971: movl $_TIF_NEED_RESCHED,%edi
398int_restore_rest:
399 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100400 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700401 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 jmp int_with_check
403 CFI_ENDPROC
Jan Beulichbcddc012006-12-07 02:14:02 +0100404END(system_call)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406/*
407 * Certain special system calls that need to save a complete full stack frame.
408 */
409
410 .macro PTREGSCALL label,func,arg
411 .globl \label
412\label:
413 leaq \func(%rip),%rax
414 leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */
415 jmp ptregscall_common
Jan Beulich4b787e02006-06-26 13:56:55 +0200416END(\label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 .endm
418
Jan Beulich7effaa82005-09-12 18:49:24 +0200419 CFI_STARTPROC
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 PTREGSCALL stub_clone, sys_clone, %r8
422 PTREGSCALL stub_fork, sys_fork, %rdi
423 PTREGSCALL stub_vfork, sys_vfork, %rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
425 PTREGSCALL stub_iopl, sys_iopl, %rsi
426
427ENTRY(ptregscall_common)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 popq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200429 CFI_ADJUST_CFA_OFFSET -8
430 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 SAVE_REST
432 movq %r11, %r15
Jan Beulich7effaa82005-09-12 18:49:24 +0200433 CFI_REGISTER rip, r15
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 FIXUP_TOP_OF_STACK %r11
435 call *%rax
436 RESTORE_TOP_OF_STACK %r11
437 movq %r15, %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200438 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 RESTORE_REST
440 pushq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200441 CFI_ADJUST_CFA_OFFSET 8
442 CFI_REL_OFFSET rip, 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 ret
444 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200445END(ptregscall_common)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447ENTRY(stub_execve)
448 CFI_STARTPROC
449 popq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200450 CFI_ADJUST_CFA_OFFSET -8
451 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 SAVE_REST
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 FIXUP_TOP_OF_STACK %r11
Ingo Molnar5d119b22008-02-26 12:55:57 +0100454 movq %rsp, %rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 call sys_execve
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 RESTORE_TOP_OF_STACK %r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 movq %rax,RAX(%rsp)
458 RESTORE_REST
459 jmp int_ret_from_sys_call
460 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200461END(stub_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463/*
464 * sigreturn is special because it needs to restore all registers on return.
465 * This cannot be done with SYSRET, so use the IRET return path instead.
466 */
467ENTRY(stub_rt_sigreturn)
468 CFI_STARTPROC
Jan Beulich7effaa82005-09-12 18:49:24 +0200469 addq $8, %rsp
470 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 SAVE_REST
472 movq %rsp,%rdi
473 FIXUP_TOP_OF_STACK %r11
474 call sys_rt_sigreturn
475 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
476 RESTORE_REST
477 jmp int_ret_from_sys_call
478 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200479END(stub_rt_sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Jan Beulich7effaa82005-09-12 18:49:24 +0200481/*
482 * initial frame state for interrupts and exceptions
483 */
484 .macro _frame ref
485 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200486 CFI_SIGNAL_FRAME
Jan Beulich7effaa82005-09-12 18:49:24 +0200487 CFI_DEF_CFA rsp,SS+8-\ref
488 /*CFI_REL_OFFSET ss,SS-\ref*/
489 CFI_REL_OFFSET rsp,RSP-\ref
490 /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/
491 /*CFI_REL_OFFSET cs,CS-\ref*/
492 CFI_REL_OFFSET rip,RIP-\ref
493 .endm
494
495/* initial frame state for interrupts (and exceptions without error code) */
496#define INTR_FRAME _frame RIP
497/* initial frame state for exceptions with error code (and interrupts with
498 vector already pushed) */
499#define XCPT_FRAME _frame ORIG_RAX
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501/*
502 * Interrupt entry/exit.
503 *
504 * Interrupt entry points save only callee clobbered registers in fast path.
505 *
506 * Entry runs with interrupts off.
507 */
508
509/* 0(%rsp): interrupt number */
510 .macro interrupt func
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 cld
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 SAVE_ARGS
513 leaq -ARGOFFSET(%rsp),%rdi # arg1 for handler
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200514 pushq %rbp
515 CFI_ADJUST_CFA_OFFSET 8
516 CFI_REL_OFFSET rbp, 0
517 movq %rsp,%rbp
518 CFI_DEF_CFA_REGISTER rbp
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 testl $3,CS(%rdi)
520 je 1f
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100521 SWAPGS
Andi Kleen96e54042006-09-26 10:52:39 +0200522 /* irqcount is used to check if a CPU is already on an interrupt
523 stack or not. While this is essentially redundant with preempt_count
524 it is a little cheaper to use a separate counter in the PDA
525 (short of moving irq_enter into assembly, which would be too
526 much work) */
5271: incl %gs:pda_irqcount
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200528 cmoveq %gs:pda_irqstackptr,%rsp
Andi Kleen26995002006-08-02 22:37:28 +0200529 push %rbp # backlink for old unwinder
Ingo Molnar2601e642006-07-03 00:24:45 -0700530 /*
531 * We entered an interrupt context - irqs are off:
532 */
533 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 call \func
535 .endm
536
537ENTRY(common_interrupt)
Jan Beulich7effaa82005-09-12 18:49:24 +0200538 XCPT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 interrupt do_IRQ
540 /* 0(%rsp): oldrsp-ARGOFFSET */
Jan Beulich7effaa82005-09-12 18:49:24 +0200541ret_from_intr:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100542 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700543 TRACE_IRQS_OFF
Andi Kleen3829ee62005-07-28 21:15:48 -0700544 decl %gs:pda_irqcount
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200545 leaveq
Jan Beulich7effaa82005-09-12 18:49:24 +0200546 CFI_DEF_CFA_REGISTER rsp
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200547 CFI_ADJUST_CFA_OFFSET -8
Jan Beulich7effaa82005-09-12 18:49:24 +0200548exit_intr:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 GET_THREAD_INFO(%rcx)
550 testl $3,CS-ARGOFFSET(%rsp)
551 je retint_kernel
552
553 /* Interrupt came from user space */
554 /*
555 * Has a correct top of stack, but a partial stack frame
556 * %rcx: thread info. Interrupts off.
557 */
558retint_with_reschedule:
559 movl $_TIF_WORK_MASK,%edi
Jan Beulich7effaa82005-09-12 18:49:24 +0200560retint_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200561 LOCKDEP_SYS_EXIT_IRQ
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300562 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 andl %edi,%edx
Jan Beulich7effaa82005-09-12 18:49:24 +0200564 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 jnz retint_careful
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200566
567retint_swapgs: /* return to user-space */
Ingo Molnar2601e642006-07-03 00:24:45 -0700568 /*
569 * The iretq could re-enable interrupts:
570 */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100571 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700572 TRACE_IRQS_IRETQ
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100573 SWAPGS
Ingo Molnar2601e642006-07-03 00:24:45 -0700574 jmp restore_args
575
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200576retint_restore_args: /* return to kernel space */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100577 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700578 /*
579 * The iretq could re-enable interrupts:
580 */
581 TRACE_IRQS_IRETQ
582restore_args:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100583 RESTORE_ARGS 0,8,0
584
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200585irq_return:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100586 INTERRUPT_RETURN
Ingo Molnar3701d8632008-02-09 23:24:08 +0100587
588 .section __ex_table, "a"
589 .quad irq_return, bad_iret
590 .previous
591
592#ifdef CONFIG_PARAVIRT
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100593ENTRY(native_iret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 iretq
595
596 .section __ex_table,"a"
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100597 .quad native_iret, bad_iret
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 .previous
Ingo Molnar3701d8632008-02-09 23:24:08 +0100599#endif
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 .section .fixup,"ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602bad_iret:
Roland McGrath3aa4b372008-02-06 22:39:43 +0100603 /*
604 * The iret traps when the %cs or %ss being restored is bogus.
605 * We've lost the original trap vector and error code.
606 * #GPF is the most likely one to get for an invalid selector.
607 * So pretend we completed the iret and took the #GPF in user mode.
608 *
609 * We are now running with the kernel GS after exception recovery.
610 * But error_entry expects us to have user GS to match the user %cs,
611 * so swap back.
612 */
613 pushq $0
614
615 SWAPGS
616 jmp general_protection
617
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100618 .previous
619
Jan Beulich7effaa82005-09-12 18:49:24 +0200620 /* edi: workmask, edx: work */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621retint_careful:
Jan Beulich7effaa82005-09-12 18:49:24 +0200622 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 bt $TIF_NEED_RESCHED,%edx
624 jnc retint_signal
Ingo Molnar2601e642006-07-03 00:24:45 -0700625 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100626 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200628 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 call schedule
630 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200631 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 GET_THREAD_INFO(%rcx)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100633 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700634 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 jmp retint_check
636
637retint_signal:
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100638 testl $_TIF_DO_NOTIFY_MASK,%edx
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700639 jz retint_swapgs
Ingo Molnar2601e642006-07-03 00:24:45 -0700640 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100641 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 SAVE_REST
643 movq $-1,ORIG_RAX(%rsp)
Andi Kleen3829ee62005-07-28 21:15:48 -0700644 xorl %esi,%esi # oldset
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 movq %rsp,%rdi # &pt_regs
646 call do_notify_resume
647 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100648 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700649 TRACE_IRQS_OFF
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700650 movl $_TIF_NEED_RESCHED,%edi
Andi Kleenbe9e6872005-05-01 08:58:51 -0700651 GET_THREAD_INFO(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 jmp retint_check
653
654#ifdef CONFIG_PREEMPT
655 /* Returning to kernel space. Check if we need preemption */
656 /* rcx: threadinfo. interrupts off. */
Andi Kleenb06baba2006-09-26 10:52:29 +0200657ENTRY(retint_kernel)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300658 cmpl $0,TI_preempt_count(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 jnz retint_restore_args
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300660 bt $TIF_NEED_RESCHED,TI_flags(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 jnc retint_restore_args
662 bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */
663 jnc retint_restore_args
664 call preempt_schedule_irq
665 jmp exit_intr
666#endif
Jan Beulich4b787e02006-06-26 13:56:55 +0200667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200669END(common_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671/*
672 * APIC interrupts.
673 */
674 .macro apicinterrupt num,func
Jan Beulich7effaa82005-09-12 18:49:24 +0200675 INTR_FRAME
Rusty Russell19eadf92006-06-27 02:53:44 -0700676 pushq $~(\num)
Jan Beulich7effaa82005-09-12 18:49:24 +0200677 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 interrupt \func
679 jmp ret_from_intr
680 CFI_ENDPROC
681 .endm
682
683ENTRY(thermal_interrupt)
684 apicinterrupt THERMAL_APIC_VECTOR,smp_thermal_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200685END(thermal_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Jacob Shin89b831e2005-11-05 17:25:53 +0100687ENTRY(threshold_interrupt)
688 apicinterrupt THRESHOLD_APIC_VECTOR,mce_threshold_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200689END(threshold_interrupt)
Jacob Shin89b831e2005-11-05 17:25:53 +0100690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#ifdef CONFIG_SMP
692ENTRY(reschedule_interrupt)
693 apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200694END(reschedule_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Andi Kleene5bc8b62005-09-12 18:49:24 +0200696 .macro INVALIDATE_ENTRY num
697ENTRY(invalidate_interrupt\num)
698 apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200699END(invalidate_interrupt\num)
Andi Kleene5bc8b62005-09-12 18:49:24 +0200700 .endm
701
702 INVALIDATE_ENTRY 0
703 INVALIDATE_ENTRY 1
704 INVALIDATE_ENTRY 2
705 INVALIDATE_ENTRY 3
706 INVALIDATE_ENTRY 4
707 INVALIDATE_ENTRY 5
708 INVALIDATE_ENTRY 6
709 INVALIDATE_ENTRY 7
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711ENTRY(call_function_interrupt)
712 apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200713END(call_function_interrupt)
Eric W. Biederman61014292007-02-23 04:40:58 -0700714ENTRY(irq_move_cleanup_interrupt)
715 apicinterrupt IRQ_MOVE_CLEANUP_VECTOR,smp_irq_move_cleanup_interrupt
716END(irq_move_cleanup_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#endif
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719ENTRY(apic_timer_interrupt)
720 apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200721END(apic_timer_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
Cliff Wickman18129242008-06-02 08:56:14 -0500723ENTRY(uv_bau_message_intr1)
724 apicinterrupt 220,uv_bau_message_interrupt
725END(uv_bau_message_intr1)
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727ENTRY(error_interrupt)
728 apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200729END(error_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731ENTRY(spurious_interrupt)
732 apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt
Jan Beulich4b787e02006-06-26 13:56:55 +0200733END(spurious_interrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734
735/*
736 * Exception entry points.
737 */
738 .macro zeroentry sym
Jan Beulich7effaa82005-09-12 18:49:24 +0200739 INTR_FRAME
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -0400740 PARAVIRT_ADJUST_EXCEPTION_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 pushq $0 /* push error code/oldrax */
Jan Beulich7effaa82005-09-12 18:49:24 +0200742 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 pushq %rax /* push real oldrax to the rdi slot */
Jan Beulich7effaa82005-09-12 18:49:24 +0200744 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich37550902007-05-02 19:27:05 +0200745 CFI_REL_OFFSET rax,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 leaq \sym(%rip),%rax
747 jmp error_entry
Jan Beulich7effaa82005-09-12 18:49:24 +0200748 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 .endm
750
751 .macro errorentry sym
Jan Beulich7effaa82005-09-12 18:49:24 +0200752 XCPT_FRAME
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -0400753 PARAVIRT_ADJUST_EXCEPTION_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 pushq %rax
Jan Beulich7effaa82005-09-12 18:49:24 +0200755 CFI_ADJUST_CFA_OFFSET 8
Jan Beulich37550902007-05-02 19:27:05 +0200756 CFI_REL_OFFSET rax,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 leaq \sym(%rip),%rax
758 jmp error_entry
Jan Beulich7effaa82005-09-12 18:49:24 +0200759 CFI_ENDPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 .endm
761
762 /* error code is on the stack already */
763 /* handle NMI like exceptions that can happen everywhere */
Ingo Molnar2601e642006-07-03 00:24:45 -0700764 .macro paranoidentry sym, ist=0, irqtrace=1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 SAVE_ALL
766 cld
767 movl $1,%ebx
768 movl $MSR_GS_BASE,%ecx
769 rdmsr
770 testl %edx,%edx
771 js 1f
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100772 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 xorl %ebx,%ebx
Jan Beulichb556b352006-01-11 22:43:00 +01007741:
775 .if \ist
776 movq %gs:pda_data_offset, %rbp
777 .endif
778 movq %rsp,%rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 movq ORIG_RAX(%rsp),%rsi
780 movq $-1,ORIG_RAX(%rsp)
Jan Beulichb556b352006-01-11 22:43:00 +0100781 .if \ist
Andi Kleen5f8efbb2006-01-16 01:56:39 +0100782 subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
Jan Beulichb556b352006-01-11 22:43:00 +0100783 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 call \sym
Jan Beulichb556b352006-01-11 22:43:00 +0100785 .if \ist
Andi Kleen5f8efbb2006-01-16 01:56:39 +0100786 addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
Jan Beulichb556b352006-01-11 22:43:00 +0100787 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100788 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700789 .if \irqtrace
790 TRACE_IRQS_OFF
791 .endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .endm
Ingo Molnar2601e642006-07-03 00:24:45 -0700793
794 /*
795 * "Paranoid" exit path from exception stack.
796 * Paranoid because this is used by NMIs and cannot take
797 * any kernel state for granted.
798 * We don't do kernel preemption checks here, because only
799 * NMI should be common and it does not enable IRQs and
800 * cannot get reschedule ticks.
801 *
802 * "trace" is 0 for the NMI handler only, because irq-tracing
803 * is fundamentally NMI-unsafe. (we cannot change the soft and
804 * hard flags at once, atomically)
805 */
806 .macro paranoidexit trace=1
807 /* ebx: no swapgs flag */
808paranoid_exit\trace:
809 testl %ebx,%ebx /* swapgs needed? */
810 jnz paranoid_restore\trace
811 testl $3,CS(%rsp)
812 jnz paranoid_userspace\trace
813paranoid_swapgs\trace:
Andi Kleen7a0a2df2006-09-26 10:52:37 +0200814 .if \trace
Ingo Molnar2601e642006-07-03 00:24:45 -0700815 TRACE_IRQS_IRETQ 0
Andi Kleen7a0a2df2006-09-26 10:52:37 +0200816 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100817 SWAPGS_UNSAFE_STACK
Ingo Molnar2601e642006-07-03 00:24:45 -0700818paranoid_restore\trace:
819 RESTORE_ALL 8
Ingo Molnar3701d8632008-02-09 23:24:08 +0100820 jmp irq_return
Ingo Molnar2601e642006-07-03 00:24:45 -0700821paranoid_userspace\trace:
822 GET_THREAD_INFO(%rcx)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300823 movl TI_flags(%rcx),%ebx
Ingo Molnar2601e642006-07-03 00:24:45 -0700824 andl $_TIF_WORK_MASK,%ebx
825 jz paranoid_swapgs\trace
826 movq %rsp,%rdi /* &pt_regs */
827 call sync_regs
828 movq %rax,%rsp /* switch stack for scheduling */
829 testl $_TIF_NEED_RESCHED,%ebx
830 jnz paranoid_schedule\trace
831 movl %ebx,%edx /* arg3: thread flags */
832 .if \trace
833 TRACE_IRQS_ON
834 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100835 ENABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700836 xorl %esi,%esi /* arg2: oldset */
837 movq %rsp,%rdi /* arg1: &pt_regs */
838 call do_notify_resume
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100839 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700840 .if \trace
841 TRACE_IRQS_OFF
842 .endif
843 jmp paranoid_userspace\trace
844paranoid_schedule\trace:
845 .if \trace
846 TRACE_IRQS_ON
847 .endif
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100848 ENABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700849 call schedule
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100850 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700851 .if \trace
852 TRACE_IRQS_OFF
853 .endif
854 jmp paranoid_userspace\trace
855 CFI_ENDPROC
856 .endm
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858/*
859 * Exception entry point. This expects an error code/orig_rax on the stack
860 * and the exception handler in %rax.
861 */
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200862KPROBE_ENTRY(error_entry)
Jan Beulich7effaa82005-09-12 18:49:24 +0200863 _frame RDI
Jan Beulich37550902007-05-02 19:27:05 +0200864 CFI_REL_OFFSET rax,0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 /* rdi slot contains rax, oldrax contains error code */
866 cld
867 subq $14*8,%rsp
868 CFI_ADJUST_CFA_OFFSET (14*8)
869 movq %rsi,13*8(%rsp)
870 CFI_REL_OFFSET rsi,RSI
871 movq 14*8(%rsp),%rsi /* load rax from rdi slot */
Jan Beulich37550902007-05-02 19:27:05 +0200872 CFI_REGISTER rax,rsi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 movq %rdx,12*8(%rsp)
874 CFI_REL_OFFSET rdx,RDX
875 movq %rcx,11*8(%rsp)
876 CFI_REL_OFFSET rcx,RCX
877 movq %rsi,10*8(%rsp) /* store rax */
878 CFI_REL_OFFSET rax,RAX
879 movq %r8, 9*8(%rsp)
880 CFI_REL_OFFSET r8,R8
881 movq %r9, 8*8(%rsp)
882 CFI_REL_OFFSET r9,R9
883 movq %r10,7*8(%rsp)
884 CFI_REL_OFFSET r10,R10
885 movq %r11,6*8(%rsp)
886 CFI_REL_OFFSET r11,R11
887 movq %rbx,5*8(%rsp)
888 CFI_REL_OFFSET rbx,RBX
889 movq %rbp,4*8(%rsp)
890 CFI_REL_OFFSET rbp,RBP
891 movq %r12,3*8(%rsp)
892 CFI_REL_OFFSET r12,R12
893 movq %r13,2*8(%rsp)
894 CFI_REL_OFFSET r13,R13
895 movq %r14,1*8(%rsp)
896 CFI_REL_OFFSET r14,R14
897 movq %r15,(%rsp)
898 CFI_REL_OFFSET r15,R15
899 xorl %ebx,%ebx
900 testl $3,CS(%rsp)
901 je error_kernelspace
902error_swapgs:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100903 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904error_sti:
905 movq %rdi,RDI(%rsp)
Jan Beulich37550902007-05-02 19:27:05 +0200906 CFI_REL_OFFSET rdi,RDI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 movq %rsp,%rdi
908 movq ORIG_RAX(%rsp),%rsi /* get error code */
909 movq $-1,ORIG_RAX(%rsp)
910 call *%rax
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200911 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
912error_exit:
913 movl %ebx,%eax
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100915 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700916 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 GET_THREAD_INFO(%rcx)
918 testl %eax,%eax
919 jne retint_kernel
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200920 LOCKDEP_SYS_EXIT_IRQ
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300921 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 movl $_TIF_WORK_MASK,%edi
923 andl %edi,%edx
924 jnz retint_careful
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200925 jmp retint_swapgs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 CFI_ENDPROC
927
928error_kernelspace:
929 incl %ebx
930 /* There are two places in the kernel that can potentially fault with
931 usergs. Handle them here. The exception handlers after
932 iret run with kernel gs again, so don't set the user space flag.
933 B stepping K8s sometimes report an truncated RIP for IRET
934 exceptions returning to compat mode. Check for these here too. */
Vegard Nossum9d8ad5d2008-06-27 17:22:17 +0200935 leaq irq_return(%rip),%rcx
936 cmpq %rcx,RIP(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 je error_swapgs
Vegard Nossum9d8ad5d2008-06-27 17:22:17 +0200938 movl %ecx,%ecx /* zero extend */
939 cmpq %rcx,RIP(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 je error_swapgs
941 cmpq $gs_change,RIP(%rsp)
942 je error_swapgs
943 jmp error_sti
Prasanna S.Pd28c4392006-09-26 10:52:34 +0200944KPROBE_END(error_entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 /* Reload gs selector with exception handling */
947 /* edi: new selector */
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400948ENTRY(native_load_gs_index)
Jan Beulich7effaa82005-09-12 18:49:24 +0200949 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 pushf
Jan Beulich7effaa82005-09-12 18:49:24 +0200951 CFI_ADJUST_CFA_OFFSET 8
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100952 DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
953 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954gs_change:
955 movl %edi,%gs
9562: mfence /* workaround */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100957 SWAPGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 popf
Jan Beulich7effaa82005-09-12 18:49:24 +0200959 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 ret
Jan Beulich7effaa82005-09-12 18:49:24 +0200961 CFI_ENDPROC
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -0400962ENDPROC(native_load_gs_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 .section __ex_table,"a"
965 .align 8
966 .quad gs_change,bad_gs
967 .previous
968 .section .fixup,"ax"
969 /* running with kernelgs */
970bad_gs:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100971 SWAPGS /* switch back to user gs */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 xorl %eax,%eax
973 movl %eax,%gs
974 jmp 2b
975 .previous
976
977/*
978 * Create a kernel thread.
979 *
980 * C extern interface:
981 * extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
982 *
983 * asm input arguments:
984 * rdi: fn, rsi: arg, rdx: flags
985 */
986ENTRY(kernel_thread)
987 CFI_STARTPROC
988 FAKE_STACK_FRAME $child_rip
989 SAVE_ALL
990
991 # rdi: flags, rsi: usp, rdx: will be &pt_regs
992 movq %rdx,%rdi
993 orq kernel_thread_flags(%rip),%rdi
994 movq $-1, %rsi
995 movq %rsp, %rdx
996
997 xorl %r8d,%r8d
998 xorl %r9d,%r9d
999
1000 # clone now
1001 call do_fork
1002 movq %rax,RAX(%rsp)
1003 xorl %edi,%edi
1004
1005 /*
1006 * It isn't worth to check for reschedule here,
1007 * so internally to the x86_64 port you can rely on kernel_thread()
1008 * not to reschedule the child before returning, this avoids the need
1009 * of hacks for example to fork off the per-CPU idle tasks.
1010 * [Hopefully no generic code relies on the reschedule -AK]
1011 */
1012 RESTORE_ALL
1013 UNFAKE_STACK_FRAME
1014 ret
1015 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001016ENDPROC(kernel_thread)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018child_rip:
Andi Kleenc05991e2006-08-30 19:37:08 +02001019 pushq $0 # fake return address
1020 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 /*
1022 * Here we are in the child and the registers are set as they were
1023 * at kernel_thread() invocation in the parent.
1024 */
1025 movq %rdi, %rax
1026 movq %rsi, %rdi
1027 call *%rax
1028 # exit
Andrey Mirkin1c5b5cf2007-10-17 18:04:33 +02001029 mov %eax, %edi
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 call do_exit
Andi Kleenc05991e2006-08-30 19:37:08 +02001031 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001032ENDPROC(child_rip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034/*
1035 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
1036 *
1037 * C extern interface:
1038 * extern long execve(char *name, char **argv, char **envp)
1039 *
1040 * asm input arguments:
1041 * rdi: name, rsi: argv, rdx: envp
1042 *
1043 * We want to fallback into:
Ingo Molnar5d119b22008-02-26 12:55:57 +01001044 * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 *
1046 * do_sys_execve asm fallback arguments:
Ingo Molnar5d119b22008-02-26 12:55:57 +01001047 * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 */
Arnd Bergmann3db03b42006-10-02 02:18:31 -07001049ENTRY(kernel_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 CFI_STARTPROC
1051 FAKE_STACK_FRAME $0
1052 SAVE_ALL
Ingo Molnar5d119b22008-02-26 12:55:57 +01001053 movq %rsp,%rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 call sys_execve
1055 movq %rax, RAX(%rsp)
1056 RESTORE_REST
1057 testq %rax,%rax
1058 je int_ret_from_sys_call
1059 RESTORE_ARGS
1060 UNFAKE_STACK_FRAME
1061 ret
1062 CFI_ENDPROC
Arnd Bergmann3db03b42006-10-02 02:18:31 -07001063ENDPROC(kernel_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001065KPROBE_ENTRY(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 errorentry do_page_fault
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001067KPROBE_END(page_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069ENTRY(coprocessor_error)
1070 zeroentry do_coprocessor_error
Jan Beulich4b787e02006-06-26 13:56:55 +02001071END(coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073ENTRY(simd_coprocessor_error)
1074 zeroentry do_simd_coprocessor_error
Jan Beulich4b787e02006-06-26 13:56:55 +02001075END(simd_coprocessor_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077ENTRY(device_not_available)
1078 zeroentry math_state_restore
Jan Beulich4b787e02006-06-26 13:56:55 +02001079END(device_not_available)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080
1081 /* runs on exception stack */
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001082KPROBE_ENTRY(debug)
Jan Beulich7effaa82005-09-12 18:49:24 +02001083 INTR_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 pushq $0
1085 CFI_ADJUST_CFA_OFFSET 8
Andi Kleen5f8efbb2006-01-16 01:56:39 +01001086 paranoidentry do_debug, DEBUG_STACK
Ingo Molnar2601e642006-07-03 00:24:45 -07001087 paranoidexit
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001088KPROBE_END(debug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 /* runs on exception stack */
Andi Kleeneddb6fb2006-02-03 21:50:41 +01001091KPROBE_ENTRY(nmi)
Jan Beulich7effaa82005-09-12 18:49:24 +02001092 INTR_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 pushq $-1
Jan Beulich7effaa82005-09-12 18:49:24 +02001094 CFI_ADJUST_CFA_OFFSET 8
Ingo Molnar2601e642006-07-03 00:24:45 -07001095 paranoidentry do_nmi, 0, 0
1096#ifdef CONFIG_TRACE_IRQFLAGS
1097 paranoidexit 0
1098#else
1099 jmp paranoid_exit1
1100 CFI_ENDPROC
1101#endif
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001102KPROBE_END(nmi)
Andi Kleen6fefb0d2005-04-16 15:25:03 -07001103
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001104KPROBE_ENTRY(int3)
Jan Beulichb556b352006-01-11 22:43:00 +01001105 INTR_FRAME
1106 pushq $0
1107 CFI_ADJUST_CFA_OFFSET 8
Andi Kleen5f8efbb2006-01-16 01:56:39 +01001108 paranoidentry do_int3, DEBUG_STACK
Ingo Molnar2601e642006-07-03 00:24:45 -07001109 jmp paranoid_exit1
Jan Beulichb556b352006-01-11 22:43:00 +01001110 CFI_ENDPROC
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001111KPROBE_END(int3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112
1113ENTRY(overflow)
1114 zeroentry do_overflow
Jan Beulich4b787e02006-06-26 13:56:55 +02001115END(overflow)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117ENTRY(bounds)
1118 zeroentry do_bounds
Jan Beulich4b787e02006-06-26 13:56:55 +02001119END(bounds)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121ENTRY(invalid_op)
1122 zeroentry do_invalid_op
Jan Beulich4b787e02006-06-26 13:56:55 +02001123END(invalid_op)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125ENTRY(coprocessor_segment_overrun)
1126 zeroentry do_coprocessor_segment_overrun
Jan Beulich4b787e02006-06-26 13:56:55 +02001127END(coprocessor_segment_overrun)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 /* runs on exception stack */
1130ENTRY(double_fault)
Jan Beulich7effaa82005-09-12 18:49:24 +02001131 XCPT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 paranoidentry do_double_fault
Ingo Molnar2601e642006-07-03 00:24:45 -07001133 jmp paranoid_exit1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001135END(double_fault)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
1137ENTRY(invalid_TSS)
1138 errorentry do_invalid_TSS
Jan Beulich4b787e02006-06-26 13:56:55 +02001139END(invalid_TSS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141ENTRY(segment_not_present)
1142 errorentry do_segment_not_present
Jan Beulich4b787e02006-06-26 13:56:55 +02001143END(segment_not_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
1145 /* runs on exception stack */
1146ENTRY(stack_segment)
Jan Beulich7effaa82005-09-12 18:49:24 +02001147 XCPT_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 paranoidentry do_stack_segment
Ingo Molnar2601e642006-07-03 00:24:45 -07001149 jmp paranoid_exit1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001151END(stack_segment)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152
Prasanna S Panchamukhi0f2fbdc2005-09-06 15:19:28 -07001153KPROBE_ENTRY(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 errorentry do_general_protection
Prasanna S.Pd28c4392006-09-26 10:52:34 +02001155KPROBE_END(general_protection)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157ENTRY(alignment_check)
1158 errorentry do_alignment_check
Jan Beulich4b787e02006-06-26 13:56:55 +02001159END(alignment_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160
1161ENTRY(divide_error)
1162 zeroentry do_divide_error
Jan Beulich4b787e02006-06-26 13:56:55 +02001163END(divide_error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165ENTRY(spurious_interrupt_bug)
1166 zeroentry do_spurious_interrupt_bug
Jan Beulich4b787e02006-06-26 13:56:55 +02001167END(spurious_interrupt_bug)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169#ifdef CONFIG_X86_MCE
1170 /* runs on exception stack */
1171ENTRY(machine_check)
Jan Beulich7effaa82005-09-12 18:49:24 +02001172 INTR_FRAME
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 pushq $0
1174 CFI_ADJUST_CFA_OFFSET 8
1175 paranoidentry do_machine_check
Ingo Molnar2601e642006-07-03 00:24:45 -07001176 jmp paranoid_exit1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001178END(machine_check)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179#endif
1180
Andi Kleen26995002006-08-02 22:37:28 +02001181/* Call softirq on interrupt stack. Interrupts are off. */
Andi Kleened6b6762005-07-28 21:15:49 -07001182ENTRY(call_softirq)
Jan Beulich7effaa82005-09-12 18:49:24 +02001183 CFI_STARTPROC
Andi Kleen26995002006-08-02 22:37:28 +02001184 push %rbp
1185 CFI_ADJUST_CFA_OFFSET 8
1186 CFI_REL_OFFSET rbp,0
1187 mov %rsp,%rbp
1188 CFI_DEF_CFA_REGISTER rbp
Andi Kleened6b6762005-07-28 21:15:49 -07001189 incl %gs:pda_irqcount
Andi Kleen26995002006-08-02 22:37:28 +02001190 cmove %gs:pda_irqstackptr,%rsp
1191 push %rbp # backlink for old unwinder
Andi Kleened6b6762005-07-28 21:15:49 -07001192 call __do_softirq
Andi Kleen26995002006-08-02 22:37:28 +02001193 leaveq
Jan Beulich7effaa82005-09-12 18:49:24 +02001194 CFI_DEF_CFA_REGISTER rsp
Andi Kleen26995002006-08-02 22:37:28 +02001195 CFI_ADJUST_CFA_OFFSET -8
Andi Kleened6b6762005-07-28 21:15:49 -07001196 decl %gs:pda_irqcount
Andi Kleened6b6762005-07-28 21:15:49 -07001197 ret
Jan Beulich7effaa82005-09-12 18:49:24 +02001198 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +02001199ENDPROC(call_softirq)
Andi Kleen75154f42007-06-23 02:29:25 +02001200
1201KPROBE_ENTRY(ignore_sysret)
1202 CFI_STARTPROC
1203 mov $-ENOSYS,%eax
1204 sysret
1205 CFI_ENDPROC
1206ENDPROC(ignore_sysret)