blob: 0dd45859a7a863c64e95b62ed1891a8738f13f0c [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.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +010014 *
15 * Normal syscalls and interrupts don't save a full stack frame, this is
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * only done for syscall tracing, signals or fork/exec et.al.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +010017 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 * - partial stack frame: partially saved registers upto R11.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +010022 * - 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>
Abhishek Sagar395a59d2008-06-21 23:47:27 +053054#include <asm/ftrace.h>
Tejun Heo9939dda2009-01-13 20:41:35 +090055#include <asm/percpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Roland McGrath86a1c342008-06-23 15:37:04 -070057/* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
58#include <linux/elf-em.h>
59#define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
60#define __AUDIT_ARCH_64BIT 0x80000000
61#define __AUDIT_ARCH_LE 0x40000000
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 .code64
Steven Rostedt606576c2008-10-06 19:06:12 -040064#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtd61f82d2008-05-12 21:20:43 +020065#ifdef CONFIG_DYNAMIC_FTRACE
66ENTRY(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +020067 retq
68END(mcount)
69
70ENTRY(ftrace_caller)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -050071 cmpl $0, function_trace_stop
72 jne ftrace_stub
Steven Rostedtd61f82d2008-05-12 21:20:43 +020073
Cyrill Gorcunovd680fe42008-12-13 00:09:08 +030074 MCOUNT_SAVE_FRAME
Steven Rostedtd61f82d2008-05-12 21:20:43 +020075
76 movq 0x38(%rsp), %rdi
77 movq 8(%rbp), %rsi
Abhishek Sagar395a59d2008-06-21 23:47:27 +053078 subq $MCOUNT_INSN_SIZE, %rdi
Steven Rostedtd61f82d2008-05-12 21:20:43 +020079
80.globl ftrace_call
81ftrace_call:
82 call ftrace_stub
83
Cyrill Gorcunovd680fe42008-12-13 00:09:08 +030084 MCOUNT_RESTORE_FRAME
Steven Rostedtd61f82d2008-05-12 21:20:43 +020085
Frederic Weisbecker48d68b22008-12-02 00:20:39 +010086#ifdef CONFIG_FUNCTION_GRAPH_TRACER
87.globl ftrace_graph_call
88ftrace_graph_call:
89 jmp ftrace_stub
90#endif
Steven Rostedtd61f82d2008-05-12 21:20:43 +020091
92.globl ftrace_stub
93ftrace_stub:
94 retq
95END(ftrace_caller)
96
97#else /* ! CONFIG_DYNAMIC_FTRACE */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +020098ENTRY(mcount)
Steven Rostedt60a7ecf2008-11-05 16:05:44 -050099 cmpl $0, function_trace_stop
100 jne ftrace_stub
101
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200102 cmpq $ftrace_stub, ftrace_trace_function
103 jnz trace
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100104
105#ifdef CONFIG_FUNCTION_GRAPH_TRACER
106 cmpq $ftrace_stub, ftrace_graph_return
107 jnz ftrace_graph_caller
Steven Rostedte49dc192008-12-02 23:50:05 -0500108
109 cmpq $ftrace_graph_entry_stub, ftrace_graph_entry
110 jnz ftrace_graph_caller
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100111#endif
112
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200113.globl ftrace_stub
114ftrace_stub:
115 retq
116
117trace:
Cyrill Gorcunovd680fe42008-12-13 00:09:08 +0300118 MCOUNT_SAVE_FRAME
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200119
120 movq 0x38(%rsp), %rdi
121 movq 8(%rbp), %rsi
Abhishek Sagar395a59d2008-06-21 23:47:27 +0530122 subq $MCOUNT_INSN_SIZE, %rdi
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200123
124 call *ftrace_trace_function
125
Cyrill Gorcunovd680fe42008-12-13 00:09:08 +0300126 MCOUNT_RESTORE_FRAME
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200127
128 jmp ftrace_stub
129END(mcount)
Steven Rostedtd61f82d2008-05-12 21:20:43 +0200130#endif /* CONFIG_DYNAMIC_FTRACE */
Steven Rostedt606576c2008-10-06 19:06:12 -0400131#endif /* CONFIG_FUNCTION_TRACER */
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200132
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100133#ifdef CONFIG_FUNCTION_GRAPH_TRACER
134ENTRY(ftrace_graph_caller)
135 cmpl $0, function_trace_stop
136 jne ftrace_stub
137
Cyrill Gorcunovd680fe42008-12-13 00:09:08 +0300138 MCOUNT_SAVE_FRAME
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100139
140 leaq 8(%rbp), %rdi
141 movq 0x38(%rsp), %rsi
Steven Rostedtbb4304c2008-12-02 15:34:09 -0500142 subq $MCOUNT_INSN_SIZE, %rsi
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100143
144 call prepare_ftrace_return
145
Cyrill Gorcunovd680fe42008-12-13 00:09:08 +0300146 MCOUNT_RESTORE_FRAME
147
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100148 retq
149END(ftrace_graph_caller)
150
151
152.globl return_to_handler
153return_to_handler:
154 subq $80, %rsp
155
156 movq %rax, (%rsp)
157 movq %rcx, 8(%rsp)
158 movq %rdx, 16(%rsp)
159 movq %rsi, 24(%rsp)
160 movq %rdi, 32(%rsp)
161 movq %r8, 40(%rsp)
162 movq %r9, 48(%rsp)
163 movq %r10, 56(%rsp)
164 movq %r11, 64(%rsp)
165
166 call ftrace_return_to_handler
167
168 movq %rax, 72(%rsp)
169 movq 64(%rsp), %r11
170 movq 56(%rsp), %r10
Jan Beulich7effaa82005-09-12 18:49:24 +0200171 movq 48(%rsp), %r9
172 movq 40(%rsp), %r8
173 movq 32(%rsp), %rdi
174 movq 24(%rsp), %rsi
175 movq 16(%rsp), %rdx
176 movq 8(%rsp), %rcx
177 movq (%rsp), %rax
Frederic Weisbecker48d68b22008-12-02 00:20:39 +0100178 addq $72, %rsp
179 retq
180#endif
Jan Beulich7effaa82005-09-12 18:49:24 +0200181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183#ifndef CONFIG_PREEMPT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#define retint_kernel retint_restore_args
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100185#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187#ifdef CONFIG_PARAVIRT
188ENTRY(native_usergs_sysret64)
189 swapgs
190 sysretq
191#endif /* CONFIG_PARAVIRT */
192
193
194.macro TRACE_IRQS_IRETQ offset=ARGOFFSET
195#ifdef CONFIG_TRACE_IRQFLAGS
196 bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
197 jnc 1f
198 TRACE_IRQS_ON
1991:
200#endif
201.endm
202
203/*
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100204 * C code is not supposed to know about undefined top of stack. Every time
205 * a C function with an pt_regs argument is called from the SYSCALL based
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 * fast path FIXUP_TOP_OF_STACK is needed.
207 * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs
208 * manipulation.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100209 */
210
211 /* %rsp:at FRAMEEND */
Alexander van Heukelumc002a1e2008-11-21 16:41:55 +0100212 .macro FIXUP_TOP_OF_STACK tmp offset=0
213 movq %gs:pda_oldrsp,\tmp
214 movq \tmp,RSP+\offset(%rsp)
215 movq $__USER_DS,SS+\offset(%rsp)
216 movq $__USER_CS,CS+\offset(%rsp)
217 movq $-1,RCX+\offset(%rsp)
218 movq R11+\offset(%rsp),\tmp /* get eflags */
219 movq \tmp,EFLAGS+\offset(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 .endm
221
Alexander van Heukelumc002a1e2008-11-21 16:41:55 +0100222 .macro RESTORE_TOP_OF_STACK tmp offset=0
223 movq RSP+\offset(%rsp),\tmp
224 movq \tmp,%gs:pda_oldrsp
225 movq EFLAGS+\offset(%rsp),\tmp
226 movq \tmp,R11+\offset(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 .endm
228
229 .macro FAKE_STACK_FRAME child_rip
230 /* push in order ss, rsp, eflags, cs, rip */
231 xorl %eax, %eax
232 pushq $__KERNEL_DS /* ss */
233 CFI_ADJUST_CFA_OFFSET 8
234 /*CFI_REL_OFFSET ss,0*/
235 pushq %rax /* rsp */
236 CFI_ADJUST_CFA_OFFSET 8
237 CFI_REL_OFFSET rsp,0
gorcunov@gmail.com33454532008-11-26 22:17:02 +0300238 pushq $X86_EFLAGS_IF /* eflags - interrupts on */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 CFI_ADJUST_CFA_OFFSET 8
240 /*CFI_REL_OFFSET rflags,0*/
241 pushq $__KERNEL_CS /* cs */
242 CFI_ADJUST_CFA_OFFSET 8
243 /*CFI_REL_OFFSET cs,0*/
244 pushq \child_rip /* rip */
245 CFI_ADJUST_CFA_OFFSET 8
246 CFI_REL_OFFSET rip,0
247 pushq %rax /* orig rax */
248 CFI_ADJUST_CFA_OFFSET 8
249 .endm
250
251 .macro UNFAKE_STACK_FRAME
252 addq $8*6, %rsp
253 CFI_ADJUST_CFA_OFFSET -(6*8)
254 .endm
255
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100256/*
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100257 * initial frame state for interrupts (and exceptions without error code)
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100258 */
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100259 .macro EMPTY_FRAME start=1 offset=0
260 .if \start
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100261 CFI_STARTPROC simple
262 CFI_SIGNAL_FRAME
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100263 CFI_DEF_CFA rsp,8+\offset
264 .else
265 CFI_DEF_CFA_OFFSET 8+\offset
266 .endif
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100267 .endm
268
269/*
270 * initial frame state for interrupts (and exceptions without error code)
271 */
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100272 .macro INTR_FRAME start=1 offset=0
Ingo Molnare8a0e272008-11-21 15:11:32 +0100273 EMPTY_FRAME \start, SS+8+\offset-RIP
274 /*CFI_REL_OFFSET ss, SS+\offset-RIP*/
275 CFI_REL_OFFSET rsp, RSP+\offset-RIP
276 /*CFI_REL_OFFSET rflags, EFLAGS+\offset-RIP*/
277 /*CFI_REL_OFFSET cs, CS+\offset-RIP*/
278 CFI_REL_OFFSET rip, RIP+\offset-RIP
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100279 .endm
280
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100281/*
282 * initial frame state for exceptions with error code (and interrupts
283 * with vector already pushed)
284 */
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100285 .macro XCPT_FRAME start=1 offset=0
Ingo Molnare8a0e272008-11-21 15:11:32 +0100286 INTR_FRAME \start, RIP+\offset-ORIG_RAX
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100287 /*CFI_REL_OFFSET orig_rax, ORIG_RAX-ORIG_RAX*/
288 .endm
289
290/*
291 * frame that enables calling into C.
292 */
293 .macro PARTIAL_FRAME start=1 offset=0
Ingo Molnare8a0e272008-11-21 15:11:32 +0100294 XCPT_FRAME \start, ORIG_RAX+\offset-ARGOFFSET
295 CFI_REL_OFFSET rdi, RDI+\offset-ARGOFFSET
296 CFI_REL_OFFSET rsi, RSI+\offset-ARGOFFSET
297 CFI_REL_OFFSET rdx, RDX+\offset-ARGOFFSET
298 CFI_REL_OFFSET rcx, RCX+\offset-ARGOFFSET
299 CFI_REL_OFFSET rax, RAX+\offset-ARGOFFSET
300 CFI_REL_OFFSET r8, R8+\offset-ARGOFFSET
301 CFI_REL_OFFSET r9, R9+\offset-ARGOFFSET
302 CFI_REL_OFFSET r10, R10+\offset-ARGOFFSET
303 CFI_REL_OFFSET r11, R11+\offset-ARGOFFSET
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100304 .endm
305
306/*
307 * frame that enables passing a complete pt_regs to a C function.
308 */
309 .macro DEFAULT_FRAME start=1 offset=0
Ingo Molnare8a0e272008-11-21 15:11:32 +0100310 PARTIAL_FRAME \start, R11+\offset-R15
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100311 CFI_REL_OFFSET rbx, RBX+\offset
312 CFI_REL_OFFSET rbp, RBP+\offset
313 CFI_REL_OFFSET r12, R12+\offset
314 CFI_REL_OFFSET r13, R13+\offset
315 CFI_REL_OFFSET r14, R14+\offset
316 CFI_REL_OFFSET r15, R15+\offset
317 .endm
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100318
319/* save partial stack frame */
320ENTRY(save_args)
321 XCPT_FRAME
322 cld
Ingo Molnar14ae22b2008-11-21 15:20:47 +0100323 movq_cfi rdi, RDI+16-ARGOFFSET
324 movq_cfi rsi, RSI+16-ARGOFFSET
325 movq_cfi rdx, RDX+16-ARGOFFSET
326 movq_cfi rcx, RCX+16-ARGOFFSET
327 movq_cfi rax, RAX+16-ARGOFFSET
328 movq_cfi r8, R8+16-ARGOFFSET
329 movq_cfi r9, R9+16-ARGOFFSET
330 movq_cfi r10, R10+16-ARGOFFSET
331 movq_cfi r11, R11+16-ARGOFFSET
332
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100333 leaq -ARGOFFSET+16(%rsp),%rdi /* arg1 for handler */
Ingo Molnar14ae22b2008-11-21 15:20:47 +0100334 movq_cfi rbp, 8 /* push %rbp */
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100335 leaq 8(%rsp), %rbp /* mov %rsp, %ebp */
336 testl $3, CS(%rdi)
337 je 1f
338 SWAPGS
339 /*
340 * irqcount is used to check if a CPU is already on an interrupt stack
341 * or not. While this is essentially redundant with preempt_count it is
342 * a little cheaper to use a separate counter in the PDA (short of
343 * moving irq_enter into assembly, which would be too much work)
344 */
3451: incl %gs:pda_irqcount
346 jne 2f
Ingo Molnar14ae22b2008-11-21 15:20:47 +0100347 popq_cfi %rax /* move return address... */
Brian Gerst26f80bd2009-01-19 00:38:58 +0900348 mov PER_CPU_VAR(irq_stack_ptr),%rsp
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100349 EMPTY_FRAME 0
Ingo Molnar14ae22b2008-11-21 15:20:47 +0100350 pushq_cfi %rax /* ... to the new stack */
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100351 /*
352 * We entered an interrupt context - irqs are off:
353 */
3542: TRACE_IRQS_OFF
355 ret
356 CFI_ENDPROC
357END(save_args)
358
Alexander van Heukelumc002a1e2008-11-21 16:41:55 +0100359ENTRY(save_rest)
360 PARTIAL_FRAME 1 REST_SKIP+8
361 movq 5*8+16(%rsp), %r11 /* save return address */
362 movq_cfi rbx, RBX+16
363 movq_cfi rbp, RBP+16
364 movq_cfi r12, R12+16
365 movq_cfi r13, R13+16
366 movq_cfi r14, R14+16
367 movq_cfi r15, R15+16
368 movq %r11, 8(%rsp) /* return address */
369 FIXUP_TOP_OF_STACK %r11, 16
370 ret
371 CFI_ENDPROC
372END(save_rest)
373
Alexander van Heukelume2f6bc22008-11-21 16:43:18 +0100374/* save complete stack frame */
375ENTRY(save_paranoid)
376 XCPT_FRAME 1 RDI+8
377 cld
378 movq_cfi rdi, RDI+8
379 movq_cfi rsi, RSI+8
380 movq_cfi rdx, RDX+8
381 movq_cfi rcx, RCX+8
382 movq_cfi rax, RAX+8
383 movq_cfi r8, R8+8
384 movq_cfi r9, R9+8
385 movq_cfi r10, R10+8
386 movq_cfi r11, R11+8
387 movq_cfi rbx, RBX+8
388 movq_cfi rbp, RBP+8
389 movq_cfi r12, R12+8
390 movq_cfi r13, R13+8
391 movq_cfi r14, R14+8
392 movq_cfi r15, R15+8
393 movl $1,%ebx
394 movl $MSR_GS_BASE,%ecx
395 rdmsr
396 testl %edx,%edx
397 js 1f /* negative -> in kernel */
398 SWAPGS
399 xorl %ebx,%ebx
4001: ret
401 CFI_ENDPROC
402END(save_paranoid)
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404/*
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100405 * A newly forked process directly context switches into this address.
406 *
407 * rdi: prev task we switched from
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100408 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409ENTRY(ret_from_fork)
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100410 DEFAULT_FRAME
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100411
Andi Kleen658fdbe2006-09-26 10:52:41 +0200412 push kernel_eflags(%rip)
Alexander van Heukelume0a5a5d2008-07-22 18:14:16 +0200413 CFI_ADJUST_CFA_OFFSET 8
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100414 popf # reset kernel eflags
Alexander van Heukelume0a5a5d2008-07-22 18:14:16 +0200415 CFI_ADJUST_CFA_OFFSET -8
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100416
417 call schedule_tail # rdi: 'prev' task parameter
418
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 GET_THREAD_INFO(%rcx)
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100420
Jan Beulich1cbd8b32008-10-30 10:45:36 +0000421 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 RESTORE_REST
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100423
424 testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 je int_ret_from_sys_call
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100426
427 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 jnz int_ret_from_sys_call
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100429
Alexander van Heukelumc002a1e2008-11-21 16:41:55 +0100430 RESTORE_TOP_OF_STACK %rdi, -ARGOFFSET
Ingo Molnar5b3eec02008-11-27 14:41:21 +0100431 jmp ret_from_sys_call # go to the SYSRET fastpath
432
Jan Beulich1cbd8b32008-10-30 10:45:36 +0000433 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200435END(ret_from_fork)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437/*
438 * System call entry. Upto 6 arguments in registers are supported.
439 *
440 * SYSCALL does not save anything on the stack and does not change the
441 * stack pointer.
442 */
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444/*
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100445 * Register setup:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 * rax system call number
447 * rdi arg0
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100448 * rcx return address for syscall/sysret, C arg3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 * rsi arg1
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100450 * rdx arg2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 * r10 arg3 (--> moved to rcx for C)
452 * r8 arg4
453 * r9 arg5
454 * r11 eflags for syscall/sysret, temporary for C
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100455 * r12-r15,rbp,rbx saved by C code, not touched.
456 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 * Interrupts are off on entry.
458 * Only called from user space.
459 *
460 * XXX if we had a free scratch register we could save the RSP into the stack frame
461 * and report it properly in ps. Unfortunately we haven't.
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200462 *
463 * When user can change the frames always force IRET. That is because
464 * it deals with uncanonical addresses better. SYSRET has trouble
465 * with them due to bugs in both AMD and Intel CPUs.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100466 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468ENTRY(system_call)
Jan Beulich7effaa82005-09-12 18:49:24 +0200469 CFI_STARTPROC simple
Jan Beulichadf14232006-09-26 10:52:41 +0200470 CFI_SIGNAL_FRAME
Brian Gerst9af45652009-01-19 00:38:58 +0900471 CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
Jan Beulich7effaa82005-09-12 18:49:24 +0200472 CFI_REGISTER rip,rcx
473 /*CFI_REGISTER rflags,r11*/
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100474 SWAPGS_UNSAFE_STACK
475 /*
476 * A hypervisor implementation might want to use a label
477 * after the swapgs, so that it can do the swapgs
478 * for the guest and jump here on syscall.
479 */
480ENTRY(system_call_after_swapgs)
481
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100482 movq %rsp,%gs:pda_oldrsp
Brian Gerst9af45652009-01-19 00:38:58 +0900483 movq PER_CPU_VAR(kernel_stack),%rsp
Ingo Molnar2601e642006-07-03 00:24:45 -0700484 /*
485 * No need to follow this irqs off/on section - it's straight
486 * and short:
487 */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100488 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 SAVE_ARGS 8,1
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100490 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
Jan Beulich7effaa82005-09-12 18:49:24 +0200491 movq %rcx,RIP-ARGOFFSET(%rsp)
492 CFI_REL_OFFSET rip,RIP-ARGOFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 GET_THREAD_INFO(%rcx)
Roland McGrathd4d67152008-07-09 02:38:07 -0700494 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 jnz tracesys
Roland McGrath86a1c342008-06-23 15:37:04 -0700496system_call_fastpath:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 cmpq $__NR_syscall_max,%rax
498 ja badsys
499 movq %r10,%rcx
500 call *sys_call_table(,%rax,8) # XXX: rip relative
501 movq %rax,RAX-ARGOFFSET(%rsp)
502/*
503 * Syscall return path ending with SYSRET (fast path)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100504 * Has incomplete stack frame and undefined top of stack.
505 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506ret_from_sys_call:
Andi Kleen11b854b2005-04-16 15:25:02 -0700507 movl $_TIF_ALLWORK_MASK,%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 /* edi: flagmask */
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100509sysret_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200510 LOCKDEP_SYS_EXIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 GET_THREAD_INFO(%rcx)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100512 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700513 TRACE_IRQS_OFF
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300514 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 andl %edi,%edx
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100516 jnz sysret_careful
Jan Beulichbcddc012006-12-07 02:14:02 +0100517 CFI_REMEMBER_STATE
Ingo Molnar2601e642006-07-03 00:24:45 -0700518 /*
519 * sysretq will re-enable interrupts:
520 */
521 TRACE_IRQS_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 movq RIP-ARGOFFSET(%rsp),%rcx
Jan Beulich7effaa82005-09-12 18:49:24 +0200523 CFI_REGISTER rip,rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 RESTORE_ARGS 0,-ARG_SKIP,1
Jan Beulich7effaa82005-09-12 18:49:24 +0200525 /*CFI_REGISTER rflags,r11*/
Jeremy Fitzhardingec7245da2008-06-25 00:19:27 -0400526 movq %gs:pda_oldrsp, %rsp
Jeremy Fitzhardinge2be29982008-06-25 00:19:28 -0400527 USERGS_SYSRET64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Jan Beulichbcddc012006-12-07 02:14:02 +0100529 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* Handle reschedules */
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100531 /* edx: work, edi: workmask */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532sysret_careful:
533 bt $TIF_NEED_RESCHED,%edx
534 jnc sysret_signal
Ingo Molnar2601e642006-07-03 00:24:45 -0700535 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100536 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200538 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 call schedule
540 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200541 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 jmp sysret_check
543
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100544 /* Handle a signal */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545sysret_signal:
Ingo Molnar2601e642006-07-03 00:24:45 -0700546 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100547 ENABLE_INTERRUPTS(CLBR_NONE)
Roland McGrath86a1c342008-06-23 15:37:04 -0700548#ifdef CONFIG_AUDITSYSCALL
549 bt $TIF_SYSCALL_AUDIT,%edx
550 jc sysret_audit
551#endif
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700552 /* edx: work flags (arg3) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1
554 xorl %esi,%esi # oldset -> arg2
Alexander van Heukelumc8108412008-11-21 22:59:52 +0100555 SAVE_REST
556 FIXUP_TOP_OF_STACK %r11
557 call do_notify_resume
558 RESTORE_TOP_OF_STACK %r11
559 RESTORE_REST
Roland McGrath15e8f342008-06-23 20:41:12 -0700560 movl $_TIF_WORK_MASK,%edi
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200561 /* Use IRET because user could have changed frame. This
562 works because ptregscall_common has called FIXUP_TOP_OF_STACK. */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100563 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700564 TRACE_IRQS_OFF
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200565 jmp int_with_check
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100566
Jan Beulich7effaa82005-09-12 18:49:24 +0200567badsys:
568 movq $-ENOSYS,RAX-ARGOFFSET(%rsp)
569 jmp ret_from_sys_call
570
Roland McGrath86a1c342008-06-23 15:37:04 -0700571#ifdef CONFIG_AUDITSYSCALL
572 /*
573 * Fast path for syscall audit without full syscall trace.
574 * We just call audit_syscall_entry() directly, and then
575 * jump back to the normal fast path.
576 */
577auditsys:
578 movq %r10,%r9 /* 6th arg: 4th syscall arg */
579 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
580 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
581 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
582 movq %rax,%rsi /* 2nd arg: syscall number */
583 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
584 call audit_syscall_entry
585 LOAD_ARGS 0 /* reload call-clobbered registers */
586 jmp system_call_fastpath
587
588 /*
589 * Return fast path for syscall audit. Call audit_syscall_exit()
590 * directly and then jump back to the fast path with TIF_SYSCALL_AUDIT
591 * masked off.
592 */
593sysret_audit:
594 movq %rax,%rsi /* second arg, syscall return value */
595 cmpq $0,%rax /* is it < 0? */
596 setl %al /* 1 if so, 0 if not */
597 movzbl %al,%edi /* zero-extend that into %edi */
598 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
599 call audit_syscall_exit
600 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
601 jmp sysret_check
602#endif /* CONFIG_AUDITSYSCALL */
603
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 /* Do syscall tracing */
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100605tracesys:
Roland McGrath86a1c342008-06-23 15:37:04 -0700606#ifdef CONFIG_AUDITSYSCALL
607 testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
608 jz auditsys
609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 SAVE_REST
Roland McGratha31f8dd2008-03-16 21:59:11 -0700611 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 FIXUP_TOP_OF_STACK %rdi
613 movq %rsp,%rdi
614 call syscall_trace_enter
Roland McGrathd4d67152008-07-09 02:38:07 -0700615 /*
616 * Reload arg registers from stack in case ptrace changed them.
617 * We don't reload %rax because syscall_trace_enter() returned
618 * the value it wants us to use in the table lookup.
619 */
620 LOAD_ARGS ARGOFFSET, 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 RESTORE_REST
622 cmpq $__NR_syscall_max,%rax
Roland McGratha31f8dd2008-03-16 21:59:11 -0700623 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 movq %r10,%rcx /* fixup for C */
625 call *sys_call_table(,%rax,8)
Roland McGratha31f8dd2008-03-16 21:59:11 -0700626 movq %rax,RAX-ARGOFFSET(%rsp)
Andi Kleen7bf36bb2006-04-07 19:50:00 +0200627 /* Use IRET because user could have changed frame */
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100628
629/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 * Syscall return path ending with IRET.
631 * Has correct top of stack, but partial stack frame.
Jan Beulichbcddc012006-12-07 02:14:02 +0100632 */
633 .globl int_ret_from_sys_call
Roland McGrath5cbf1562008-06-24 01:13:31 -0700634 .globl int_with_check
Jan Beulichbcddc012006-12-07 02:14:02 +0100635int_ret_from_sys_call:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100636 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700637 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 testl $3,CS-ARGOFFSET(%rsp)
639 je retint_restore_args
640 movl $_TIF_ALLWORK_MASK,%edi
641 /* edi: mask to check */
642int_with_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200643 LOCKDEP_SYS_EXIT_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 GET_THREAD_INFO(%rcx)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300645 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 andl %edi,%edx
647 jnz int_careful
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300648 andl $~TS_COMPAT,TI_status(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 jmp retint_swapgs
650
651 /* Either reschedule or signal or syscall exit tracking needed. */
652 /* First do a reschedule test. */
653 /* edx: work, edi: workmask */
654int_careful:
655 bt $TIF_NEED_RESCHED,%edx
656 jnc int_very_careful
Ingo Molnar2601e642006-07-03 00:24:45 -0700657 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100658 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200660 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 call schedule
662 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200663 CFI_ADJUST_CFA_OFFSET -8
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100664 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700665 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 jmp int_with_check
667
668 /* handle signals and tracing -- both require a full stack frame */
669int_very_careful:
Ingo Molnar2601e642006-07-03 00:24:45 -0700670 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100671 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 SAVE_REST
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100673 /* Check for syscall exit trace */
Roland McGrathd4d67152008-07-09 02:38:07 -0700674 testl $_TIF_WORK_SYSCALL_EXIT,%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 jz int_signal
676 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200677 CFI_ADJUST_CFA_OFFSET 8
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100678 leaq 8(%rsp),%rdi # &ptregs -> arg1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 call syscall_trace_leave
680 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200681 CFI_ADJUST_CFA_OFFSET -8
Roland McGrathd4d67152008-07-09 02:38:07 -0700682 andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 jmp int_restore_rest
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100684
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685int_signal:
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100686 testl $_TIF_DO_NOTIFY_MASK,%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 jz 1f
688 movq %rsp,%rdi # &ptregs -> arg1
689 xorl %esi,%esi # oldset -> arg2
690 call do_notify_resume
Roland McGratheca91e72008-07-10 14:50:39 -07006911: movl $_TIF_WORK_MASK,%edi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692int_restore_rest:
693 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100694 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700695 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 jmp int_with_check
697 CFI_ENDPROC
Jan Beulichbcddc012006-12-07 02:14:02 +0100698END(system_call)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100699
700/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 * Certain special system calls that need to save a complete full stack frame.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100702 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 .macro PTREGSCALL label,func,arg
Alexander van Heukelumc002a1e2008-11-21 16:41:55 +0100704ENTRY(\label)
705 PARTIAL_FRAME 1 8 /* offset 8: return address */
706 subq $REST_SKIP, %rsp
707 CFI_ADJUST_CFA_OFFSET REST_SKIP
708 call save_rest
709 DEFAULT_FRAME 0 8 /* offset 8: return address */
710 leaq 8(%rsp), \arg /* pt_regs pointer */
711 call \func
712 jmp ptregscall_common
713 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200714END(\label)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 .endm
716
717 PTREGSCALL stub_clone, sys_clone, %r8
718 PTREGSCALL stub_fork, sys_fork, %rdi
719 PTREGSCALL stub_vfork, sys_vfork, %rdi
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx
721 PTREGSCALL stub_iopl, sys_iopl, %rsi
722
723ENTRY(ptregscall_common)
Alexander van Heukelumc002a1e2008-11-21 16:41:55 +0100724 DEFAULT_FRAME 1 8 /* offset 8: return address */
725 RESTORE_TOP_OF_STACK %r11, 8
726 movq_cfi_restore R15+8, r15
727 movq_cfi_restore R14+8, r14
728 movq_cfi_restore R13+8, r13
729 movq_cfi_restore R12+8, r12
730 movq_cfi_restore RBP+8, rbp
731 movq_cfi_restore RBX+8, rbx
732 ret $REST_SKIP /* pop extended registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200734END(ptregscall_common)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736ENTRY(stub_execve)
737 CFI_STARTPROC
738 popq %r11
Jan Beulich7effaa82005-09-12 18:49:24 +0200739 CFI_ADJUST_CFA_OFFSET -8
740 CFI_REGISTER rip, r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 SAVE_REST
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 FIXUP_TOP_OF_STACK %r11
Ingo Molnar5d119b22008-02-26 12:55:57 +0100743 movq %rsp, %rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 call sys_execve
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 RESTORE_TOP_OF_STACK %r11
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 movq %rax,RAX(%rsp)
747 RESTORE_REST
748 jmp int_ret_from_sys_call
749 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200750END(stub_execve)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752/*
753 * sigreturn is special because it needs to restore all registers on return.
754 * This cannot be done with SYSRET, so use the IRET return path instead.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100755 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756ENTRY(stub_rt_sigreturn)
757 CFI_STARTPROC
Jan Beulich7effaa82005-09-12 18:49:24 +0200758 addq $8, %rsp
759 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 SAVE_REST
761 movq %rsp,%rdi
762 FIXUP_TOP_OF_STACK %r11
763 call sys_rt_sigreturn
764 movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer
765 RESTORE_REST
766 jmp int_ret_from_sys_call
767 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200768END(stub_rt_sigreturn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Jan Beulich7effaa82005-09-12 18:49:24 +0200770/*
H. Peter Anvin939b7872008-11-11 13:51:52 -0800771 * Build the entry stubs and pointer table with some assembler magic.
772 * We pack 7 stubs into a single 32-byte chunk, which will fit in a
773 * single cache line on all modern x86 implementations.
774 */
775 .section .init.rodata,"a"
776ENTRY(interrupt)
777 .text
778 .p2align 5
779 .p2align CONFIG_X86_L1_CACHE_SHIFT
780ENTRY(irq_entries_start)
781 INTR_FRAME
782vector=FIRST_EXTERNAL_VECTOR
783.rept (NR_VECTORS-FIRST_EXTERNAL_VECTOR+6)/7
784 .balign 32
785 .rept 7
786 .if vector < NR_VECTORS
H. Peter Anvin86655962008-11-12 10:27:35 -0800787 .if vector <> FIRST_EXTERNAL_VECTOR
H. Peter Anvin939b7872008-11-11 13:51:52 -0800788 CFI_ADJUST_CFA_OFFSET -8
789 .endif
7901: pushq $(~vector+0x80) /* Note: always in signed byte range */
791 CFI_ADJUST_CFA_OFFSET 8
H. Peter Anvin86655962008-11-12 10:27:35 -0800792 .if ((vector-FIRST_EXTERNAL_VECTOR)%7) <> 6
H. Peter Anvin939b7872008-11-11 13:51:52 -0800793 jmp 2f
794 .endif
795 .previous
796 .quad 1b
797 .text
798vector=vector+1
799 .endif
800 .endr
8012: jmp common_interrupt
802.endr
803 CFI_ENDPROC
804END(irq_entries_start)
805
806.previous
807END(interrupt)
808.previous
809
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100810/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 * Interrupt entry/exit.
812 *
813 * Interrupt entry points save only callee clobbered registers in fast path.
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100814 *
815 * Entry runs with interrupts off.
816 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Alexander van Heukelum722024d2008-11-13 13:50:20 +0100818/* 0(%rsp): ~(interrupt number) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .macro interrupt func
Alexander van Heukelumd99015b2008-11-19 01:18:11 +0100820 subq $10*8, %rsp
821 CFI_ADJUST_CFA_OFFSET 10*8
822 call save_args
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +0100823 PARTIAL_FRAME 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 call \func
825 .endm
826
Alexander van Heukelum722024d2008-11-13 13:50:20 +0100827 /*
828 * The interrupt stubs push (~vector+0x80) onto the stack and
829 * then jump to common_interrupt.
830 */
H. Peter Anvin939b7872008-11-11 13:51:52 -0800831 .p2align CONFIG_X86_L1_CACHE_SHIFT
832common_interrupt:
Jan Beulich7effaa82005-09-12 18:49:24 +0200833 XCPT_FRAME
Alexander van Heukelum722024d2008-11-13 13:50:20 +0100834 addq $-0x80,(%rsp) /* Adjust vector to [-256,-1] range */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 interrupt do_IRQ
836 /* 0(%rsp): oldrsp-ARGOFFSET */
Jan Beulich7effaa82005-09-12 18:49:24 +0200837ret_from_intr:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100838 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700839 TRACE_IRQS_OFF
Andi Kleen3829ee62005-07-28 21:15:48 -0700840 decl %gs:pda_irqcount
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200841 leaveq
Jan Beulich7effaa82005-09-12 18:49:24 +0200842 CFI_DEF_CFA_REGISTER rsp
Jan Beulich1de9c3f2006-06-26 13:57:35 +0200843 CFI_ADJUST_CFA_OFFSET -8
Jan Beulich7effaa82005-09-12 18:49:24 +0200844exit_intr:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 GET_THREAD_INFO(%rcx)
846 testl $3,CS-ARGOFFSET(%rsp)
847 je retint_kernel
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 /* Interrupt came from user space */
850 /*
851 * Has a correct top of stack, but a partial stack frame
852 * %rcx: thread info. Interrupts off.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100853 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854retint_with_reschedule:
855 movl $_TIF_WORK_MASK,%edi
Jan Beulich7effaa82005-09-12 18:49:24 +0200856retint_check:
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200857 LOCKDEP_SYS_EXIT_IRQ
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300858 movl TI_flags(%rcx),%edx
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 andl %edi,%edx
Jan Beulich7effaa82005-09-12 18:49:24 +0200860 CFI_REMEMBER_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 jnz retint_careful
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200862
863retint_swapgs: /* return to user-space */
Ingo Molnar2601e642006-07-03 00:24:45 -0700864 /*
865 * The iretq could re-enable interrupts:
866 */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100867 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700868 TRACE_IRQS_IRETQ
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100869 SWAPGS
Ingo Molnar2601e642006-07-03 00:24:45 -0700870 jmp restore_args
871
Peter Zijlstra10cd7062007-10-11 22:11:12 +0200872retint_restore_args: /* return to kernel space */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100873 DISABLE_INTERRUPTS(CLBR_ANY)
Ingo Molnar2601e642006-07-03 00:24:45 -0700874 /*
875 * The iretq could re-enable interrupts:
876 */
877 TRACE_IRQS_IRETQ
878restore_args:
Ingo Molnar3701d8632008-02-09 23:24:08 +0100879 RESTORE_ARGS 0,8,0
880
Adrian Bunkf7f3d792008-02-13 23:29:53 +0200881irq_return:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100882 INTERRUPT_RETURN
Ingo Molnar3701d8632008-02-09 23:24:08 +0100883
884 .section __ex_table, "a"
885 .quad irq_return, bad_iret
886 .previous
887
888#ifdef CONFIG_PARAVIRT
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100889ENTRY(native_iret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 iretq
891
892 .section __ex_table,"a"
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100893 .quad native_iret, bad_iret
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 .previous
Ingo Molnar3701d8632008-02-09 23:24:08 +0100895#endif
896
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 .section .fixup,"ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898bad_iret:
Roland McGrath3aa4b372008-02-06 22:39:43 +0100899 /*
900 * The iret traps when the %cs or %ss being restored is bogus.
901 * We've lost the original trap vector and error code.
902 * #GPF is the most likely one to get for an invalid selector.
903 * So pretend we completed the iret and took the #GPF in user mode.
904 *
905 * We are now running with the kernel GS after exception recovery.
906 * But error_entry expects us to have user GS to match the user %cs,
907 * so swap back.
908 */
909 pushq $0
910
911 SWAPGS
912 jmp general_protection
913
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100914 .previous
915
Jan Beulich7effaa82005-09-12 18:49:24 +0200916 /* edi: workmask, edx: work */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917retint_careful:
Jan Beulich7effaa82005-09-12 18:49:24 +0200918 CFI_RESTORE_STATE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 bt $TIF_NEED_RESCHED,%edx
920 jnc retint_signal
Ingo Molnar2601e642006-07-03 00:24:45 -0700921 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100922 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 pushq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200924 CFI_ADJUST_CFA_OFFSET 8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 call schedule
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100926 popq %rdi
Jan Beulich7effaa82005-09-12 18:49:24 +0200927 CFI_ADJUST_CFA_OFFSET -8
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 GET_THREAD_INFO(%rcx)
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100929 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700930 TRACE_IRQS_OFF
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 jmp retint_check
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933retint_signal:
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +0100934 testl $_TIF_DO_NOTIFY_MASK,%edx
Andi Kleen10ffdbb2005-05-16 21:53:19 -0700935 jz retint_swapgs
Ingo Molnar2601e642006-07-03 00:24:45 -0700936 TRACE_IRQS_ON
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100937 ENABLE_INTERRUPTS(CLBR_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 SAVE_REST
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100939 movq $-1,ORIG_RAX(%rsp)
Andi Kleen3829ee62005-07-28 21:15:48 -0700940 xorl %esi,%esi # oldset
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 movq %rsp,%rdi # &pt_regs
942 call do_notify_resume
943 RESTORE_REST
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +0100944 DISABLE_INTERRUPTS(CLBR_NONE)
Ingo Molnar2601e642006-07-03 00:24:45 -0700945 TRACE_IRQS_OFF
Andi Kleenbe9e6872005-05-01 08:58:51 -0700946 GET_THREAD_INFO(%rcx)
Roland McGratheca91e72008-07-10 14:50:39 -0700947 jmp retint_with_reschedule
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949#ifdef CONFIG_PREEMPT
950 /* Returning to kernel space. Check if we need preemption */
951 /* rcx: threadinfo. interrupts off. */
Andi Kleenb06baba2006-09-26 10:52:29 +0200952ENTRY(retint_kernel)
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300953 cmpl $0,TI_preempt_count(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 jnz retint_restore_args
Glauber Costa26ccb8a2008-06-24 11:19:35 -0300955 bt $TIF_NEED_RESCHED,TI_flags(%rcx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 jnc retint_restore_args
957 bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */
958 jnc retint_restore_args
959 call preempt_schedule_irq
960 jmp exit_intr
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100961#endif
Jan Beulich4b787e02006-06-26 13:56:55 +0200962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 CFI_ENDPROC
Jan Beulich4b787e02006-06-26 13:56:55 +0200964END(common_interrupt)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100965
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966/*
967 * APIC interrupts.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100968 */
Alexander van Heukelum322648d2008-11-23 10:08:28 +0100969.macro apicinterrupt num sym do_sym
970ENTRY(\sym)
Jan Beulich7effaa82005-09-12 18:49:24 +0200971 INTR_FRAME
Rusty Russell19eadf92006-06-27 02:53:44 -0700972 pushq $~(\num)
Jan Beulich7effaa82005-09-12 18:49:24 +0200973 CFI_ADJUST_CFA_OFFSET 8
Alexander van Heukelum322648d2008-11-23 10:08:28 +0100974 interrupt \do_sym
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 jmp ret_from_intr
976 CFI_ENDPROC
Alexander van Heukelum322648d2008-11-23 10:08:28 +0100977END(\sym)
978.endm
Jacob Shin89b831e2005-11-05 17:25:53 +0100979
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +0100980#ifdef CONFIG_SMP
Alexander van Heukelum322648d2008-11-23 10:08:28 +0100981apicinterrupt IRQ_MOVE_CLEANUP_VECTOR \
982 irq_move_cleanup_interrupt smp_irq_move_cleanup_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983#endif
984
Cyrill Gorcunov5ae3a132008-11-27 00:02:10 +0300985apicinterrupt UV_BAU_MESSAGE \
Alexander van Heukelum322648d2008-11-23 10:08:28 +0100986 uv_bau_message_intr1 uv_bau_message_interrupt
987apicinterrupt LOCAL_TIMER_VECTOR \
988 apic_timer_interrupt smp_apic_timer_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Alexander van Heukelum322648d2008-11-23 10:08:28 +0100990#ifdef CONFIG_SMP
991apicinterrupt INVALIDATE_TLB_VECTOR_START+0 \
992 invalidate_interrupt0 smp_invalidate_interrupt
993apicinterrupt INVALIDATE_TLB_VECTOR_START+1 \
994 invalidate_interrupt1 smp_invalidate_interrupt
995apicinterrupt INVALIDATE_TLB_VECTOR_START+2 \
996 invalidate_interrupt2 smp_invalidate_interrupt
997apicinterrupt INVALIDATE_TLB_VECTOR_START+3 \
998 invalidate_interrupt3 smp_invalidate_interrupt
999apicinterrupt INVALIDATE_TLB_VECTOR_START+4 \
1000 invalidate_interrupt4 smp_invalidate_interrupt
1001apicinterrupt INVALIDATE_TLB_VECTOR_START+5 \
1002 invalidate_interrupt5 smp_invalidate_interrupt
1003apicinterrupt INVALIDATE_TLB_VECTOR_START+6 \
1004 invalidate_interrupt6 smp_invalidate_interrupt
1005apicinterrupt INVALIDATE_TLB_VECTOR_START+7 \
1006 invalidate_interrupt7 smp_invalidate_interrupt
1007#endif
Cliff Wickman18129242008-06-02 08:56:14 -05001008
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001009apicinterrupt THRESHOLD_APIC_VECTOR \
1010 threshold_interrupt mce_threshold_interrupt
1011apicinterrupt THERMAL_APIC_VECTOR \
1012 thermal_interrupt smp_thermal_interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001014#ifdef CONFIG_SMP
1015apicinterrupt CALL_FUNCTION_SINGLE_VECTOR \
1016 call_function_single_interrupt smp_call_function_single_interrupt
1017apicinterrupt CALL_FUNCTION_VECTOR \
1018 call_function_interrupt smp_call_function_interrupt
1019apicinterrupt RESCHEDULE_VECTOR \
1020 reschedule_interrupt smp_reschedule_interrupt
1021#endif
1022
1023apicinterrupt ERROR_APIC_VECTOR \
1024 error_interrupt smp_error_interrupt
1025apicinterrupt SPURIOUS_APIC_VECTOR \
1026 spurious_interrupt smp_spurious_interrupt
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028/*
1029 * Exception entry points.
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001030 */
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001031.macro zeroentry sym do_sym
1032ENTRY(\sym)
Jan Beulich7effaa82005-09-12 18:49:24 +02001033 INTR_FRAME
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -04001034 PARAVIRT_ADJUST_EXCEPTION_FRAME
Ingo Molnar14ae22b2008-11-21 15:20:47 +01001035 pushq_cfi $-1 /* ORIG_RAX: no syscall to restart */
Alexander van Heukelumd99015b2008-11-19 01:18:11 +01001036 subq $15*8,%rsp
1037 CFI_ADJUST_CFA_OFFSET 15*8
1038 call error_entry
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +01001039 DEFAULT_FRAME 0
Alexander van Heukelumd99015b2008-11-19 01:18:11 +01001040 movq %rsp,%rdi /* pt_regs pointer */
1041 xorl %esi,%esi /* no error code */
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001042 call \do_sym
Alexander van Heukelumd99015b2008-11-19 01:18:11 +01001043 jmp error_exit /* %ebx: no swapgs flag */
Jan Beulich7effaa82005-09-12 18:49:24 +02001044 CFI_ENDPROC
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001045END(\sym)
1046.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001048.macro paranoidzeroentry sym do_sym
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001049ENTRY(\sym)
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001050 INTR_FRAME
1051 PARAVIRT_ADJUST_EXCEPTION_FRAME
1052 pushq $-1 /* ORIG_RAX: no syscall to restart */
1053 CFI_ADJUST_CFA_OFFSET 8
1054 subq $15*8, %rsp
1055 call save_paranoid
1056 TRACE_IRQS_OFF
1057 movq %rsp,%rdi /* pt_regs pointer */
1058 xorl %esi,%esi /* no error code */
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001059 call \do_sym
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001060 jmp paranoid_exit /* %ebx: no swapgs flag */
1061 CFI_ENDPROC
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001062END(\sym)
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001063.endm
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001064
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001065.macro paranoidzeroentry_ist sym do_sym ist
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001066ENTRY(\sym)
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001067 INTR_FRAME
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001068 PARAVIRT_ADJUST_EXCEPTION_FRAME
1069 pushq $-1 /* ORIG_RAX: no syscall to restart */
1070 CFI_ADJUST_CFA_OFFSET 8
1071 subq $15*8, %rsp
1072 call save_paranoid
1073 TRACE_IRQS_OFF
1074 movq %rsp,%rdi /* pt_regs pointer */
1075 xorl %esi,%esi /* no error code */
Tejun Heo9939dda2009-01-13 20:41:35 +09001076 PER_CPU(init_tss, %rbp)
1077 subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001078 call \do_sym
Tejun Heo9939dda2009-01-13 20:41:35 +09001079 addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001080 jmp paranoid_exit /* %ebx: no swapgs flag */
1081 CFI_ENDPROC
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001082END(\sym)
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001083.endm
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001084
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001085.macro errorentry sym do_sym
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001086ENTRY(\sym)
Jan Beulich7effaa82005-09-12 18:49:24 +02001087 XCPT_FRAME
Jeremy Fitzhardingefab58422008-06-25 00:19:31 -04001088 PARAVIRT_ADJUST_EXCEPTION_FRAME
Alexander van Heukelumd99015b2008-11-19 01:18:11 +01001089 subq $15*8,%rsp
1090 CFI_ADJUST_CFA_OFFSET 15*8
1091 call error_entry
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +01001092 DEFAULT_FRAME 0
Alexander van Heukelumd99015b2008-11-19 01:18:11 +01001093 movq %rsp,%rdi /* pt_regs pointer */
1094 movq ORIG_RAX(%rsp),%rsi /* get error code */
1095 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001096 call \do_sym
Alexander van Heukelumd99015b2008-11-19 01:18:11 +01001097 jmp error_exit /* %ebx: no swapgs flag */
Jan Beulich7effaa82005-09-12 18:49:24 +02001098 CFI_ENDPROC
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001099END(\sym)
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001100.endm
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 /* error code is on the stack already */
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001103.macro paranoiderrorentry sym do_sym
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001104ENTRY(\sym)
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001105 XCPT_FRAME
1106 PARAVIRT_ADJUST_EXCEPTION_FRAME
1107 subq $15*8,%rsp
Alexander van Heukelume2f6bc22008-11-21 16:43:18 +01001108 CFI_ADJUST_CFA_OFFSET 15*8
1109 call save_paranoid
1110 DEFAULT_FRAME 0
Alexander van Heukelum7e61a792008-09-26 14:03:03 +02001111 TRACE_IRQS_OFF
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001112 movq %rsp,%rdi /* pt_regs pointer */
1113 movq ORIG_RAX(%rsp),%rsi /* get error code */
1114 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001115 call \do_sym
Alexander van Heukelumb8b1d082008-11-21 16:44:28 +01001116 jmp paranoid_exit /* %ebx: no swapgs flag */
1117 CFI_ENDPROC
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001118END(\sym)
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001119.endm
1120
1121zeroentry divide_error do_divide_error
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001122zeroentry overflow do_overflow
1123zeroentry bounds do_bounds
1124zeroentry invalid_op do_invalid_op
1125zeroentry device_not_available do_device_not_available
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001126paranoiderrorentry double_fault do_double_fault
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001127zeroentry coprocessor_segment_overrun do_coprocessor_segment_overrun
1128errorentry invalid_TSS do_invalid_TSS
1129errorentry segment_not_present do_segment_not_present
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001130zeroentry spurious_interrupt_bug do_spurious_interrupt_bug
1131zeroentry coprocessor_error do_coprocessor_error
1132errorentry alignment_check do_alignment_check
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001133zeroentry simd_coprocessor_error do_simd_coprocessor_error
Ingo Molnar2601e642006-07-03 00:24:45 -07001134
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001135 /* Reload gs selector with exception handling */
1136 /* edi: new selector */
Jeremy Fitzhardinge9f9d4892008-06-25 00:19:32 -04001137ENTRY(native_load_gs_index)
Jan Beulich7effaa82005-09-12 18:49:24 +02001138 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 pushf
Jan Beulich7effaa82005-09-12 18:49:24 +02001140 CFI_ADJUST_CFA_OFFSET 8
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +01001141 DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI))
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001142 SWAPGS
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001143gs_change:
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001144 movl %edi,%gs
Linus Torvalds1da177e2005-04-16 15:20:36 -070011452: mfence /* workaround */
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +01001146 SWAPGS
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001147 popf
Jan Beulich7effaa82005-09-12 18:49:24 +02001148 CFI_ADJUST_CFA_OFFSET -8
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001149 ret
Jan Beulich7effaa82005-09-12 18:49:24 +02001150 CFI_ENDPROC
Alexander van Heukelum6efdcfa2008-11-23 10:15:32 +01001151END(native_load_gs_index)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001152
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001153 .section __ex_table,"a"
1154 .align 8
1155 .quad gs_change,bad_gs
1156 .previous
1157 .section .fixup,"ax"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 /* running with kernelgs */
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001159bad_gs:
Glauber de Oliveira Costa72fe4852008-01-30 13:32:08 +01001160 SWAPGS /* switch back to user gs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 xorl %eax,%eax
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001162 movl %eax,%gs
1163 jmp 2b
1164 .previous
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001165
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166/*
1167 * Create a kernel thread.
1168 *
1169 * C extern interface:
1170 * extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
1171 *
1172 * asm input arguments:
1173 * rdi: fn, rsi: arg, rdx: flags
1174 */
1175ENTRY(kernel_thread)
1176 CFI_STARTPROC
1177 FAKE_STACK_FRAME $child_rip
1178 SAVE_ALL
1179
1180 # rdi: flags, rsi: usp, rdx: will be &pt_regs
1181 movq %rdx,%rdi
1182 orq kernel_thread_flags(%rip),%rdi
1183 movq $-1, %rsi
1184 movq %rsp, %rdx
1185
1186 xorl %r8d,%r8d
1187 xorl %r9d,%r9d
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 # clone now
1190 call do_fork
1191 movq %rax,RAX(%rsp)
1192 xorl %edi,%edi
1193
1194 /*
1195 * It isn't worth to check for reschedule here,
1196 * so internally to the x86_64 port you can rely on kernel_thread()
1197 * not to reschedule the child before returning, this avoids the need
1198 * of hacks for example to fork off the per-CPU idle tasks.
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001199 * [Hopefully no generic code relies on the reschedule -AK]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 */
1201 RESTORE_ALL
1202 UNFAKE_STACK_FRAME
1203 ret
1204 CFI_ENDPROC
Alexander van Heukelum6efdcfa2008-11-23 10:15:32 +01001205END(kernel_thread)
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001206
Cyrill Gorcunovc2c631e2008-11-26 22:17:00 +03001207ENTRY(child_rip)
Andi Kleenc05991e2006-08-30 19:37:08 +02001208 pushq $0 # fake return address
1209 CFI_STARTPROC
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 /*
1211 * Here we are in the child and the registers are set as they were
1212 * at kernel_thread() invocation in the parent.
1213 */
1214 movq %rdi, %rax
1215 movq %rsi, %rdi
1216 call *%rax
1217 # exit
Andrey Mirkin1c5b5cf2007-10-17 18:04:33 +02001218 mov %eax, %edi
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 call do_exit
jia zhang5f5db592008-11-23 22:47:10 +08001220 ud2 # padding for call trace
Andi Kleenc05991e2006-08-30 19:37:08 +02001221 CFI_ENDPROC
Alexander van Heukelum6efdcfa2008-11-23 10:15:32 +01001222END(child_rip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
1224/*
1225 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
1226 *
1227 * C extern interface:
1228 * extern long execve(char *name, char **argv, char **envp)
1229 *
1230 * asm input arguments:
1231 * rdi: name, rsi: argv, rdx: envp
1232 *
1233 * We want to fallback into:
Ingo Molnar5d119b22008-02-26 12:55:57 +01001234 * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 *
1236 * do_sys_execve asm fallback arguments:
Ingo Molnar5d119b22008-02-26 12:55:57 +01001237 * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 */
Arnd Bergmann3db03b42006-10-02 02:18:31 -07001239ENTRY(kernel_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 CFI_STARTPROC
1241 FAKE_STACK_FRAME $0
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001242 SAVE_ALL
Ingo Molnar5d119b22008-02-26 12:55:57 +01001243 movq %rsp,%rcx
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 call sys_execve
Alexander van Heukelum0bd7b792008-11-16 15:29:00 +01001245 movq %rax, RAX(%rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 RESTORE_REST
1247 testq %rax,%rax
1248 je int_ret_from_sys_call
1249 RESTORE_ARGS
1250 UNFAKE_STACK_FRAME
1251 ret
1252 CFI_ENDPROC
Alexander van Heukelum6efdcfa2008-11-23 10:15:32 +01001253END(kernel_execve)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Andi Kleen26995002006-08-02 22:37:28 +02001255/* Call softirq on interrupt stack. Interrupts are off. */
Andi Kleened6b6762005-07-28 21:15:49 -07001256ENTRY(call_softirq)
Jan Beulich7effaa82005-09-12 18:49:24 +02001257 CFI_STARTPROC
Andi Kleen26995002006-08-02 22:37:28 +02001258 push %rbp
1259 CFI_ADJUST_CFA_OFFSET 8
1260 CFI_REL_OFFSET rbp,0
1261 mov %rsp,%rbp
1262 CFI_DEF_CFA_REGISTER rbp
Andi Kleened6b6762005-07-28 21:15:49 -07001263 incl %gs:pda_irqcount
Brian Gerst26f80bd2009-01-19 00:38:58 +09001264 cmove PER_CPU_VAR(irq_stack_ptr),%rsp
Andi Kleen26995002006-08-02 22:37:28 +02001265 push %rbp # backlink for old unwinder
Andi Kleened6b6762005-07-28 21:15:49 -07001266 call __do_softirq
Andi Kleen26995002006-08-02 22:37:28 +02001267 leaveq
Jan Beulich7effaa82005-09-12 18:49:24 +02001268 CFI_DEF_CFA_REGISTER rsp
Andi Kleen26995002006-08-02 22:37:28 +02001269 CFI_ADJUST_CFA_OFFSET -8
Andi Kleened6b6762005-07-28 21:15:49 -07001270 decl %gs:pda_irqcount
Andi Kleened6b6762005-07-28 21:15:49 -07001271 ret
Jan Beulich7effaa82005-09-12 18:49:24 +02001272 CFI_ENDPROC
Alexander van Heukelum6efdcfa2008-11-23 10:15:32 +01001273END(call_softirq)
Andi Kleen75154f42007-06-23 02:29:25 +02001274
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001275#ifdef CONFIG_XEN
Alexander van Heukelum322648d2008-11-23 10:08:28 +01001276zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001277
1278/*
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001279 * A note on the "critical region" in our callback handler.
1280 * We want to avoid stacking callback handlers due to events occurring
1281 * during handling of the last event. To do this, we keep events disabled
1282 * until we've done all processing. HOWEVER, we must enable events before
1283 * popping the stack frame (can't be done atomically) and so it would still
1284 * be possible to get enough handler activations to overflow the stack.
1285 * Although unlikely, bugs of that kind are hard to track down, so we'd
1286 * like to avoid the possibility.
1287 * So, on entry to the handler we detect whether we interrupted an
1288 * existing activation in its critical region -- if so, we pop the current
1289 * activation and restart the handler using the previous one.
1290 */
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001291ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
1292 CFI_STARTPROC
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001293/*
1294 * Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will
1295 * see the correct pointer to the pt_regs
1296 */
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001297 movq %rdi, %rsp # we don't return, adjust the stack frame
1298 CFI_ENDPROC
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +01001299 DEFAULT_FRAME
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -0700130011: incl %gs:pda_irqcount
1301 movq %rsp,%rbp
1302 CFI_DEF_CFA_REGISTER rbp
Brian Gerst26f80bd2009-01-19 00:38:58 +09001303 cmovzq PER_CPU_VAR(irq_stack_ptr),%rsp
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001304 pushq %rbp # backlink for old unwinder
1305 call xen_evtchn_do_upcall
1306 popq %rsp
1307 CFI_DEF_CFA_REGISTER rsp
1308 decl %gs:pda_irqcount
1309 jmp error_exit
1310 CFI_ENDPROC
1311END(do_hypervisor_callback)
1312
1313/*
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001314 * Hypervisor uses this for application faults while it executes.
1315 * We get here for two reasons:
1316 * 1. Fault while reloading DS, ES, FS or GS
1317 * 2. Fault while executing IRET
1318 * Category 1 we do not need to fix up as Xen has already reloaded all segment
1319 * registers that could be reloaded and zeroed the others.
1320 * Category 2 we fix up by killing the current process. We cannot use the
1321 * normal Linux return path in this case because if we use the IRET hypercall
1322 * to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1323 * We distinguish between categories by comparing each saved segment register
1324 * with its current contents: any discrepancy means we in category 1.
1325 */
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001326ENTRY(xen_failsafe_callback)
Alexander van Heukelumdcd072e2008-11-20 14:40:11 +01001327 INTR_FRAME 1 (6*8)
1328 /*CFI_REL_OFFSET gs,GS*/
1329 /*CFI_REL_OFFSET fs,FS*/
1330 /*CFI_REL_OFFSET es,ES*/
1331 /*CFI_REL_OFFSET ds,DS*/
1332 CFI_REL_OFFSET r11,8
1333 CFI_REL_OFFSET rcx,0
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001334 movw %ds,%cx
1335 cmpw %cx,0x10(%rsp)
1336 CFI_REMEMBER_STATE
1337 jne 1f
1338 movw %es,%cx
1339 cmpw %cx,0x18(%rsp)
1340 jne 1f
1341 movw %fs,%cx
1342 cmpw %cx,0x20(%rsp)
1343 jne 1f
1344 movw %gs,%cx
1345 cmpw %cx,0x28(%rsp)
1346 jne 1f
1347 /* All segments match their saved values => Category 2 (Bad IRET). */
1348 movq (%rsp),%rcx
1349 CFI_RESTORE rcx
1350 movq 8(%rsp),%r11
1351 CFI_RESTORE r11
1352 addq $0x30,%rsp
1353 CFI_ADJUST_CFA_OFFSET -0x30
Ingo Molnar14ae22b2008-11-21 15:20:47 +01001354 pushq_cfi $0 /* RIP */
1355 pushq_cfi %r11
1356 pushq_cfi %rcx
Jeremy Fitzhardinge4a5c3e72008-07-08 15:07:09 -07001357 jmp general_protection
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001358 CFI_RESTORE_STATE
13591: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */
1360 movq (%rsp),%rcx
1361 CFI_RESTORE rcx
1362 movq 8(%rsp),%r11
1363 CFI_RESTORE r11
1364 addq $0x30,%rsp
1365 CFI_ADJUST_CFA_OFFSET -0x30
Ingo Molnar14ae22b2008-11-21 15:20:47 +01001366 pushq_cfi $0
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001367 SAVE_ALL
1368 jmp error_exit
1369 CFI_ENDPROC
Jeremy Fitzhardinge3d75e1b2008-07-08 15:06:49 -07001370END(xen_failsafe_callback)
1371
1372#endif /* CONFIG_XEN */
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001373
1374/*
1375 * Some functions should be protected against kprobes
1376 */
1377 .pushsection .kprobes.text, "ax"
1378
1379paranoidzeroentry_ist debug do_debug DEBUG_STACK
1380paranoidzeroentry_ist int3 do_int3 DEBUG_STACK
1381paranoiderrorentry stack_segment do_stack_segment
1382errorentry general_protection do_general_protection
1383errorentry page_fault do_page_fault
1384#ifdef CONFIG_X86_MCE
1385paranoidzeroentry machine_check do_machine_check
1386#endif
1387
1388 /*
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001389 * "Paranoid" exit path from exception stack.
1390 * Paranoid because this is used by NMIs and cannot take
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001391 * any kernel state for granted.
1392 * We don't do kernel preemption checks here, because only
1393 * NMI should be common and it does not enable IRQs and
1394 * cannot get reschedule ticks.
1395 *
1396 * "trace" is 0 for the NMI handler only, because irq-tracing
1397 * is fundamentally NMI-unsafe. (we cannot change the soft and
1398 * hard flags at once, atomically)
1399 */
1400
1401 /* ebx: no swapgs flag */
1402ENTRY(paranoid_exit)
1403 INTR_FRAME
1404 DISABLE_INTERRUPTS(CLBR_NONE)
1405 TRACE_IRQS_OFF
1406 testl %ebx,%ebx /* swapgs needed? */
1407 jnz paranoid_restore
1408 testl $3,CS(%rsp)
1409 jnz paranoid_userspace
1410paranoid_swapgs:
1411 TRACE_IRQS_IRETQ 0
1412 SWAPGS_UNSAFE_STACK
1413paranoid_restore:
1414 RESTORE_ALL 8
1415 jmp irq_return
1416paranoid_userspace:
1417 GET_THREAD_INFO(%rcx)
1418 movl TI_flags(%rcx),%ebx
1419 andl $_TIF_WORK_MASK,%ebx
1420 jz paranoid_swapgs
1421 movq %rsp,%rdi /* &pt_regs */
1422 call sync_regs
1423 movq %rax,%rsp /* switch stack for scheduling */
1424 testl $_TIF_NEED_RESCHED,%ebx
1425 jnz paranoid_schedule
1426 movl %ebx,%edx /* arg3: thread flags */
1427 TRACE_IRQS_ON
1428 ENABLE_INTERRUPTS(CLBR_NONE)
1429 xorl %esi,%esi /* arg2: oldset */
1430 movq %rsp,%rdi /* arg1: &pt_regs */
1431 call do_notify_resume
1432 DISABLE_INTERRUPTS(CLBR_NONE)
1433 TRACE_IRQS_OFF
1434 jmp paranoid_userspace
1435paranoid_schedule:
1436 TRACE_IRQS_ON
1437 ENABLE_INTERRUPTS(CLBR_ANY)
1438 call schedule
1439 DISABLE_INTERRUPTS(CLBR_ANY)
1440 TRACE_IRQS_OFF
1441 jmp paranoid_userspace
1442 CFI_ENDPROC
1443END(paranoid_exit)
1444
1445/*
1446 * Exception entry point. This expects an error code/orig_rax on the stack.
1447 * returns in "no swapgs flag" in %ebx.
1448 */
1449ENTRY(error_entry)
1450 XCPT_FRAME
1451 CFI_ADJUST_CFA_OFFSET 15*8
1452 /* oldrax contains error code */
1453 cld
1454 movq_cfi rdi, RDI+8
1455 movq_cfi rsi, RSI+8
1456 movq_cfi rdx, RDX+8
1457 movq_cfi rcx, RCX+8
1458 movq_cfi rax, RAX+8
1459 movq_cfi r8, R8+8
1460 movq_cfi r9, R9+8
1461 movq_cfi r10, R10+8
1462 movq_cfi r11, R11+8
1463 movq_cfi rbx, RBX+8
1464 movq_cfi rbp, RBP+8
1465 movq_cfi r12, R12+8
1466 movq_cfi r13, R13+8
1467 movq_cfi r14, R14+8
1468 movq_cfi r15, R15+8
1469 xorl %ebx,%ebx
1470 testl $3,CS+8(%rsp)
1471 je error_kernelspace
1472error_swapgs:
1473 SWAPGS
1474error_sti:
1475 TRACE_IRQS_OFF
1476 ret
1477 CFI_ENDPROC
1478
1479/*
1480 * There are two places in the kernel that can potentially fault with
1481 * usergs. Handle them here. The exception handlers after iret run with
1482 * kernel gs again, so don't set the user space flag. B stepping K8s
1483 * sometimes report an truncated RIP for IRET exceptions returning to
1484 * compat mode. Check for these here too.
1485 */
1486error_kernelspace:
1487 incl %ebx
1488 leaq irq_return(%rip),%rcx
1489 cmpq %rcx,RIP+8(%rsp)
1490 je error_swapgs
1491 movl %ecx,%ecx /* zero extend */
1492 cmpq %rcx,RIP+8(%rsp)
1493 je error_swapgs
1494 cmpq $gs_change,RIP+8(%rsp)
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001495 je error_swapgs
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001496 jmp error_sti
1497END(error_entry)
1498
1499
1500/* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
1501ENTRY(error_exit)
1502 DEFAULT_FRAME
1503 movl %ebx,%eax
1504 RESTORE_REST
1505 DISABLE_INTERRUPTS(CLBR_NONE)
1506 TRACE_IRQS_OFF
1507 GET_THREAD_INFO(%rcx)
1508 testl %eax,%eax
1509 jne retint_kernel
1510 LOCKDEP_SYS_EXIT_IRQ
1511 movl TI_flags(%rcx),%edx
1512 movl $_TIF_WORK_MASK,%edi
1513 andl %edi,%edx
1514 jnz retint_careful
1515 jmp retint_swapgs
1516 CFI_ENDPROC
1517END(error_exit)
1518
1519
1520 /* runs on exception stack */
1521ENTRY(nmi)
1522 INTR_FRAME
1523 PARAVIRT_ADJUST_EXCEPTION_FRAME
1524 pushq_cfi $-1
1525 subq $15*8, %rsp
1526 CFI_ADJUST_CFA_OFFSET 15*8
1527 call save_paranoid
1528 DEFAULT_FRAME 0
1529 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
1530 movq %rsp,%rdi
1531 movq $-1,%rsi
1532 call do_nmi
1533#ifdef CONFIG_TRACE_IRQFLAGS
1534 /* paranoidexit; without TRACE_IRQS_OFF */
1535 /* ebx: no swapgs flag */
1536 DISABLE_INTERRUPTS(CLBR_NONE)
1537 testl %ebx,%ebx /* swapgs needed? */
1538 jnz nmi_restore
1539 testl $3,CS(%rsp)
1540 jnz nmi_userspace
1541nmi_swapgs:
1542 SWAPGS_UNSAFE_STACK
1543nmi_restore:
1544 RESTORE_ALL 8
1545 jmp irq_return
1546nmi_userspace:
1547 GET_THREAD_INFO(%rcx)
1548 movl TI_flags(%rcx),%ebx
1549 andl $_TIF_WORK_MASK,%ebx
1550 jz nmi_swapgs
1551 movq %rsp,%rdi /* &pt_regs */
1552 call sync_regs
1553 movq %rax,%rsp /* switch stack for scheduling */
1554 testl $_TIF_NEED_RESCHED,%ebx
1555 jnz nmi_schedule
1556 movl %ebx,%edx /* arg3: thread flags */
1557 ENABLE_INTERRUPTS(CLBR_NONE)
1558 xorl %esi,%esi /* arg2: oldset */
1559 movq %rsp,%rdi /* arg1: &pt_regs */
1560 call do_notify_resume
1561 DISABLE_INTERRUPTS(CLBR_NONE)
1562 jmp nmi_userspace
1563nmi_schedule:
1564 ENABLE_INTERRUPTS(CLBR_ANY)
1565 call schedule
1566 DISABLE_INTERRUPTS(CLBR_ANY)
1567 jmp nmi_userspace
1568 CFI_ENDPROC
1569#else
1570 jmp paranoid_exit
Cyrill Gorcunov9f1e87e2008-11-27 21:10:08 +03001571 CFI_ENDPROC
Alexander van Heukelumddeb8f22008-11-24 13:24:28 +01001572#endif
1573END(nmi)
1574
1575ENTRY(ignore_sysret)
1576 CFI_STARTPROC
1577 mov $-ENOSYS,%eax
1578 sysret
1579 CFI_ENDPROC
1580END(ignore_sysret)
1581
1582/*
1583 * End of kprobes section
1584 */
1585 .popsection