Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 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 Kleen | 2e91a17 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 23 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/linkage.h> |
| 41 | #include <asm/segment.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <asm/cache.h> |
| 43 | #include <asm/errno.h> |
| 44 | #include <asm/dwarf2.h> |
| 45 | #include <asm/calling.h> |
Sam Ravnborg | e2d5df9 | 2005-09-09 21:28:48 +0200 | [diff] [blame] | 46 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/msr.h> |
| 48 | #include <asm/unistd.h> |
| 49 | #include <asm/thread_info.h> |
| 50 | #include <asm/hw_irq.h> |
Andi Kleen | 5f8efbb | 2006-01-16 01:56:39 +0100 | [diff] [blame] | 51 | #include <asm/page.h> |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 52 | #include <asm/irqflags.h> |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 53 | #include <asm/paravirt.h> |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 54 | #include <asm/ftrace.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 56 | /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */ |
| 57 | #include <linux/elf-em.h> |
| 58 | #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) |
| 59 | #define __AUDIT_ARCH_64BIT 0x80000000 |
| 60 | #define __AUDIT_ARCH_LE 0x40000000 |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | .code64 |
| 63 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 64 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 65 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 66 | ENTRY(mcount) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 67 | retq |
| 68 | END(mcount) |
| 69 | |
| 70 | ENTRY(ftrace_caller) |
| 71 | |
| 72 | /* taken from glibc */ |
| 73 | subq $0x38, %rsp |
| 74 | movq %rax, (%rsp) |
| 75 | movq %rcx, 8(%rsp) |
| 76 | movq %rdx, 16(%rsp) |
| 77 | movq %rsi, 24(%rsp) |
| 78 | movq %rdi, 32(%rsp) |
| 79 | movq %r8, 40(%rsp) |
| 80 | movq %r9, 48(%rsp) |
| 81 | |
| 82 | movq 0x38(%rsp), %rdi |
| 83 | movq 8(%rbp), %rsi |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 84 | subq $MCOUNT_INSN_SIZE, %rdi |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 85 | |
| 86 | .globl ftrace_call |
| 87 | ftrace_call: |
| 88 | call ftrace_stub |
| 89 | |
| 90 | movq 48(%rsp), %r9 |
| 91 | movq 40(%rsp), %r8 |
| 92 | movq 32(%rsp), %rdi |
| 93 | movq 24(%rsp), %rsi |
| 94 | movq 16(%rsp), %rdx |
| 95 | movq 8(%rsp), %rcx |
| 96 | movq (%rsp), %rax |
| 97 | addq $0x38, %rsp |
| 98 | |
| 99 | .globl ftrace_stub |
| 100 | ftrace_stub: |
| 101 | retq |
| 102 | END(ftrace_caller) |
| 103 | |
| 104 | #else /* ! CONFIG_DYNAMIC_FTRACE */ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 105 | ENTRY(mcount) |
| 106 | cmpq $ftrace_stub, ftrace_trace_function |
| 107 | jnz trace |
| 108 | .globl ftrace_stub |
| 109 | ftrace_stub: |
| 110 | retq |
| 111 | |
| 112 | trace: |
| 113 | /* taken from glibc */ |
| 114 | subq $0x38, %rsp |
| 115 | movq %rax, (%rsp) |
| 116 | movq %rcx, 8(%rsp) |
| 117 | movq %rdx, 16(%rsp) |
| 118 | movq %rsi, 24(%rsp) |
| 119 | movq %rdi, 32(%rsp) |
| 120 | movq %r8, 40(%rsp) |
| 121 | movq %r9, 48(%rsp) |
| 122 | |
| 123 | movq 0x38(%rsp), %rdi |
| 124 | movq 8(%rbp), %rsi |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 125 | subq $MCOUNT_INSN_SIZE, %rdi |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 126 | |
| 127 | call *ftrace_trace_function |
| 128 | |
| 129 | movq 48(%rsp), %r9 |
| 130 | movq 40(%rsp), %r8 |
| 131 | movq 32(%rsp), %rdi |
| 132 | movq 24(%rsp), %rsi |
| 133 | movq 16(%rsp), %rdx |
| 134 | movq 8(%rsp), %rcx |
| 135 | movq (%rsp), %rax |
| 136 | addq $0x38, %rsp |
| 137 | |
| 138 | jmp ftrace_stub |
| 139 | END(mcount) |
Steven Rostedt | d61f82d | 2008-05-12 21:20:43 +0200 | [diff] [blame] | 140 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 141 | #endif /* CONFIG_FUNCTION_TRACER */ |
Arnaldo Carvalho de Melo | 16444a8 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 142 | |
Andi Kleen | dc37db4 | 2005-04-16 15:25:05 -0700 | [diff] [blame] | 143 | #ifndef CONFIG_PREEMPT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define retint_kernel retint_restore_args |
| 145 | #endif |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 146 | |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 147 | #ifdef CONFIG_PARAVIRT |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 148 | ENTRY(native_usergs_sysret64) |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 149 | swapgs |
| 150 | sysretq |
| 151 | #endif /* CONFIG_PARAVIRT */ |
| 152 | |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 153 | |
| 154 | .macro TRACE_IRQS_IRETQ offset=ARGOFFSET |
| 155 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 156 | bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */ |
| 157 | jnc 1f |
| 158 | TRACE_IRQS_ON |
| 159 | 1: |
| 160 | #endif |
| 161 | .endm |
| 162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | /* |
| 164 | * C code is not supposed to know about undefined top of stack. Every time |
| 165 | * a C function with an pt_regs argument is called from the SYSCALL based |
| 166 | * fast path FIXUP_TOP_OF_STACK is needed. |
| 167 | * RESTORE_TOP_OF_STACK syncs the syscall state after any possible ptregs |
| 168 | * manipulation. |
| 169 | */ |
| 170 | |
| 171 | /* %rsp:at FRAMEEND */ |
| 172 | .macro FIXUP_TOP_OF_STACK tmp |
| 173 | movq %gs:pda_oldrsp,\tmp |
| 174 | movq \tmp,RSP(%rsp) |
| 175 | movq $__USER_DS,SS(%rsp) |
| 176 | movq $__USER_CS,CS(%rsp) |
| 177 | movq $-1,RCX(%rsp) |
| 178 | movq R11(%rsp),\tmp /* get eflags */ |
| 179 | movq \tmp,EFLAGS(%rsp) |
| 180 | .endm |
| 181 | |
| 182 | .macro RESTORE_TOP_OF_STACK tmp,offset=0 |
| 183 | movq RSP-\offset(%rsp),\tmp |
| 184 | movq \tmp,%gs:pda_oldrsp |
| 185 | movq EFLAGS-\offset(%rsp),\tmp |
| 186 | movq \tmp,R11-\offset(%rsp) |
| 187 | .endm |
| 188 | |
| 189 | .macro FAKE_STACK_FRAME child_rip |
| 190 | /* push in order ss, rsp, eflags, cs, rip */ |
Andi Kleen | 3829ee6 | 2005-07-28 21:15:48 -0700 | [diff] [blame] | 191 | xorl %eax, %eax |
Jeremy Fitzhardinge | e04e0a6 | 2008-06-25 00:19:25 -0400 | [diff] [blame] | 192 | pushq $__KERNEL_DS /* ss */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 194 | /*CFI_REL_OFFSET ss,0*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | pushq %rax /* rsp */ |
| 196 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 197 | CFI_REL_OFFSET rsp,0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | pushq $(1<<9) /* eflags - interrupts on */ |
| 199 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 200 | /*CFI_REL_OFFSET rflags,0*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | pushq $__KERNEL_CS /* cs */ |
| 202 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 203 | /*CFI_REL_OFFSET cs,0*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | pushq \child_rip /* rip */ |
| 205 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 206 | CFI_REL_OFFSET rip,0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | pushq %rax /* orig rax */ |
| 208 | CFI_ADJUST_CFA_OFFSET 8 |
| 209 | .endm |
| 210 | |
| 211 | .macro UNFAKE_STACK_FRAME |
| 212 | addq $8*6, %rsp |
| 213 | CFI_ADJUST_CFA_OFFSET -(6*8) |
| 214 | .endm |
| 215 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 216 | .macro CFI_DEFAULT_STACK start=1 |
| 217 | .if \start |
| 218 | CFI_STARTPROC simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 219 | CFI_SIGNAL_FRAME |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 220 | CFI_DEF_CFA rsp,SS+8 |
| 221 | .else |
| 222 | CFI_DEF_CFA_OFFSET SS+8 |
| 223 | .endif |
| 224 | CFI_REL_OFFSET r15,R15 |
| 225 | CFI_REL_OFFSET r14,R14 |
| 226 | CFI_REL_OFFSET r13,R13 |
| 227 | CFI_REL_OFFSET r12,R12 |
| 228 | CFI_REL_OFFSET rbp,RBP |
| 229 | CFI_REL_OFFSET rbx,RBX |
| 230 | CFI_REL_OFFSET r11,R11 |
| 231 | CFI_REL_OFFSET r10,R10 |
| 232 | CFI_REL_OFFSET r9,R9 |
| 233 | CFI_REL_OFFSET r8,R8 |
| 234 | CFI_REL_OFFSET rax,RAX |
| 235 | CFI_REL_OFFSET rcx,RCX |
| 236 | CFI_REL_OFFSET rdx,RDX |
| 237 | CFI_REL_OFFSET rsi,RSI |
| 238 | CFI_REL_OFFSET rdi,RDI |
| 239 | CFI_REL_OFFSET rip,RIP |
| 240 | /*CFI_REL_OFFSET cs,CS*/ |
| 241 | /*CFI_REL_OFFSET rflags,EFLAGS*/ |
| 242 | CFI_REL_OFFSET rsp,RSP |
| 243 | /*CFI_REL_OFFSET ss,SS*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | .endm |
| 245 | /* |
| 246 | * A newly forked process directly context switches into this. |
| 247 | */ |
| 248 | /* rdi: prev */ |
| 249 | ENTRY(ret_from_fork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | CFI_DEFAULT_STACK |
Andi Kleen | 658fdbe | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 251 | push kernel_eflags(%rip) |
Alexander van Heukelum | e0a5a5d | 2008-07-22 18:14:16 +0200 | [diff] [blame] | 252 | CFI_ADJUST_CFA_OFFSET 8 |
Andi Kleen | 658fdbe | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 253 | popf # reset kernel eflags |
Alexander van Heukelum | e0a5a5d | 2008-07-22 18:14:16 +0200 | [diff] [blame] | 254 | CFI_ADJUST_CFA_OFFSET -8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | call schedule_tail |
| 256 | GET_THREAD_INFO(%rcx) |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 257 | testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),TI_flags(%rcx) |
Jan Beulich | 1cbd8b3 | 2008-10-30 10:45:36 +0000 | [diff] [blame] | 258 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | jnz rff_trace |
| 260 | rff_action: |
| 261 | RESTORE_REST |
| 262 | testl $3,CS-ARGOFFSET(%rsp) # from kernel_thread? |
| 263 | je int_ret_from_sys_call |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 264 | testl $_TIF_IA32,TI_flags(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | jnz int_ret_from_sys_call |
| 266 | RESTORE_TOP_OF_STACK %rdi,ARGOFFSET |
| 267 | jmp ret_from_sys_call |
Jan Beulich | 1cbd8b3 | 2008-10-30 10:45:36 +0000 | [diff] [blame] | 268 | CFI_RESTORE_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | rff_trace: |
| 270 | movq %rsp,%rdi |
| 271 | call syscall_trace_leave |
| 272 | GET_THREAD_INFO(%rcx) |
| 273 | jmp rff_action |
| 274 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 275 | END(ret_from_fork) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
| 277 | /* |
| 278 | * System call entry. Upto 6 arguments in registers are supported. |
| 279 | * |
| 280 | * SYSCALL does not save anything on the stack and does not change the |
| 281 | * stack pointer. |
| 282 | */ |
| 283 | |
| 284 | /* |
| 285 | * Register setup: |
| 286 | * rax system call number |
| 287 | * rdi arg0 |
| 288 | * rcx return address for syscall/sysret, C arg3 |
| 289 | * rsi arg1 |
| 290 | * rdx arg2 |
| 291 | * r10 arg3 (--> moved to rcx for C) |
| 292 | * r8 arg4 |
| 293 | * r9 arg5 |
| 294 | * r11 eflags for syscall/sysret, temporary for C |
| 295 | * r12-r15,rbp,rbx saved by C code, not touched. |
| 296 | * |
| 297 | * Interrupts are off on entry. |
| 298 | * Only called from user space. |
| 299 | * |
| 300 | * XXX if we had a free scratch register we could save the RSP into the stack frame |
| 301 | * and report it properly in ps. Unfortunately we haven't. |
Andi Kleen | 7bf36bb | 2006-04-07 19:50:00 +0200 | [diff] [blame] | 302 | * |
| 303 | * When user can change the frames always force IRET. That is because |
| 304 | * it deals with uncanonical addresses better. SYSRET has trouble |
| 305 | * with them due to bugs in both AMD and Intel CPUs. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | */ |
| 307 | |
| 308 | ENTRY(system_call) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 309 | CFI_STARTPROC simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 310 | CFI_SIGNAL_FRAME |
Jan Beulich | dffead4 | 2006-06-26 13:57:38 +0200 | [diff] [blame] | 311 | CFI_DEF_CFA rsp,PDA_STACKOFFSET |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 312 | CFI_REGISTER rip,rcx |
| 313 | /*CFI_REGISTER rflags,r11*/ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 314 | SWAPGS_UNSAFE_STACK |
| 315 | /* |
| 316 | * A hypervisor implementation might want to use a label |
| 317 | * after the swapgs, so that it can do the swapgs |
| 318 | * for the guest and jump here on syscall. |
| 319 | */ |
| 320 | ENTRY(system_call_after_swapgs) |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | movq %rsp,%gs:pda_oldrsp |
| 323 | movq %gs:pda_kernelstack,%rsp |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 324 | /* |
| 325 | * No need to follow this irqs off/on section - it's straight |
| 326 | * and short: |
| 327 | */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 328 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | SAVE_ARGS 8,1 |
| 330 | movq %rax,ORIG_RAX-ARGOFFSET(%rsp) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 331 | movq %rcx,RIP-ARGOFFSET(%rsp) |
| 332 | CFI_REL_OFFSET rip,RIP-ARGOFFSET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | GET_THREAD_INFO(%rcx) |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 334 | testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | jnz tracesys |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 336 | system_call_fastpath: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | cmpq $__NR_syscall_max,%rax |
| 338 | ja badsys |
| 339 | movq %r10,%rcx |
| 340 | call *sys_call_table(,%rax,8) # XXX: rip relative |
| 341 | movq %rax,RAX-ARGOFFSET(%rsp) |
| 342 | /* |
| 343 | * Syscall return path ending with SYSRET (fast path) |
| 344 | * Has incomplete stack frame and undefined top of stack. |
| 345 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | ret_from_sys_call: |
Andi Kleen | 11b854b | 2005-04-16 15:25:02 -0700 | [diff] [blame] | 347 | movl $_TIF_ALLWORK_MASK,%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | /* edi: flagmask */ |
| 349 | sysret_check: |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 350 | LOCKDEP_SYS_EXIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | GET_THREAD_INFO(%rcx) |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 352 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 353 | TRACE_IRQS_OFF |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 354 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | andl %edi,%edx |
| 356 | jnz sysret_careful |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 357 | CFI_REMEMBER_STATE |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 358 | /* |
| 359 | * sysretq will re-enable interrupts: |
| 360 | */ |
| 361 | TRACE_IRQS_ON |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | movq RIP-ARGOFFSET(%rsp),%rcx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 363 | CFI_REGISTER rip,rcx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | RESTORE_ARGS 0,-ARG_SKIP,1 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 365 | /*CFI_REGISTER rflags,r11*/ |
Jeremy Fitzhardinge | c7245da | 2008-06-25 00:19:27 -0400 | [diff] [blame] | 366 | movq %gs:pda_oldrsp, %rsp |
Jeremy Fitzhardinge | 2be2998 | 2008-06-25 00:19:28 -0400 | [diff] [blame] | 367 | USERGS_SYSRET64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 369 | CFI_RESTORE_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* Handle reschedules */ |
| 371 | /* edx: work, edi: workmask */ |
| 372 | sysret_careful: |
| 373 | bt $TIF_NEED_RESCHED,%edx |
| 374 | jnc sysret_signal |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 375 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 376 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | pushq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 378 | CFI_ADJUST_CFA_OFFSET 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | call schedule |
| 380 | popq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 381 | CFI_ADJUST_CFA_OFFSET -8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | jmp sysret_check |
| 383 | |
| 384 | /* Handle a signal */ |
| 385 | sysret_signal: |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 386 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 387 | ENABLE_INTERRUPTS(CLBR_NONE) |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 388 | #ifdef CONFIG_AUDITSYSCALL |
| 389 | bt $TIF_SYSCALL_AUDIT,%edx |
| 390 | jc sysret_audit |
| 391 | #endif |
Andi Kleen | 10ffdbb | 2005-05-16 21:53:19 -0700 | [diff] [blame] | 392 | /* edx: work flags (arg3) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | leaq do_notify_resume(%rip),%rax |
| 394 | leaq -ARGOFFSET(%rsp),%rdi # &pt_regs -> arg1 |
| 395 | xorl %esi,%esi # oldset -> arg2 |
| 396 | call ptregscall_common |
Roland McGrath | 15e8f34 | 2008-06-23 20:41:12 -0700 | [diff] [blame] | 397 | movl $_TIF_WORK_MASK,%edi |
Andi Kleen | 7bf36bb | 2006-04-07 19:50:00 +0200 | [diff] [blame] | 398 | /* Use IRET because user could have changed frame. This |
| 399 | works because ptregscall_common has called FIXUP_TOP_OF_STACK. */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 400 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 401 | TRACE_IRQS_OFF |
Andi Kleen | 7bf36bb | 2006-04-07 19:50:00 +0200 | [diff] [blame] | 402 | jmp int_with_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 404 | badsys: |
| 405 | movq $-ENOSYS,RAX-ARGOFFSET(%rsp) |
| 406 | jmp ret_from_sys_call |
| 407 | |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 408 | #ifdef CONFIG_AUDITSYSCALL |
| 409 | /* |
| 410 | * Fast path for syscall audit without full syscall trace. |
| 411 | * We just call audit_syscall_entry() directly, and then |
| 412 | * jump back to the normal fast path. |
| 413 | */ |
| 414 | auditsys: |
| 415 | movq %r10,%r9 /* 6th arg: 4th syscall arg */ |
| 416 | movq %rdx,%r8 /* 5th arg: 3rd syscall arg */ |
| 417 | movq %rsi,%rcx /* 4th arg: 2nd syscall arg */ |
| 418 | movq %rdi,%rdx /* 3rd arg: 1st syscall arg */ |
| 419 | movq %rax,%rsi /* 2nd arg: syscall number */ |
| 420 | movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */ |
| 421 | call audit_syscall_entry |
| 422 | LOAD_ARGS 0 /* reload call-clobbered registers */ |
| 423 | jmp system_call_fastpath |
| 424 | |
| 425 | /* |
| 426 | * Return fast path for syscall audit. Call audit_syscall_exit() |
| 427 | * directly and then jump back to the fast path with TIF_SYSCALL_AUDIT |
| 428 | * masked off. |
| 429 | */ |
| 430 | sysret_audit: |
| 431 | movq %rax,%rsi /* second arg, syscall return value */ |
| 432 | cmpq $0,%rax /* is it < 0? */ |
| 433 | setl %al /* 1 if so, 0 if not */ |
| 434 | movzbl %al,%edi /* zero-extend that into %edi */ |
| 435 | inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */ |
| 436 | call audit_syscall_exit |
| 437 | movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi |
| 438 | jmp sysret_check |
| 439 | #endif /* CONFIG_AUDITSYSCALL */ |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | /* Do syscall tracing */ |
| 442 | tracesys: |
Roland McGrath | 86a1c34 | 2008-06-23 15:37:04 -0700 | [diff] [blame] | 443 | #ifdef CONFIG_AUDITSYSCALL |
| 444 | testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx) |
| 445 | jz auditsys |
| 446 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | SAVE_REST |
Roland McGrath | a31f8dd | 2008-03-16 21:59:11 -0700 | [diff] [blame] | 448 | movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | FIXUP_TOP_OF_STACK %rdi |
| 450 | movq %rsp,%rdi |
| 451 | call syscall_trace_enter |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 452 | /* |
| 453 | * Reload arg registers from stack in case ptrace changed them. |
| 454 | * We don't reload %rax because syscall_trace_enter() returned |
| 455 | * the value it wants us to use in the table lookup. |
| 456 | */ |
| 457 | LOAD_ARGS ARGOFFSET, 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | RESTORE_REST |
| 459 | cmpq $__NR_syscall_max,%rax |
Roland McGrath | a31f8dd | 2008-03-16 21:59:11 -0700 | [diff] [blame] | 460 | ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | movq %r10,%rcx /* fixup for C */ |
| 462 | call *sys_call_table(,%rax,8) |
Roland McGrath | a31f8dd | 2008-03-16 21:59:11 -0700 | [diff] [blame] | 463 | movq %rax,RAX-ARGOFFSET(%rsp) |
Andi Kleen | 7bf36bb | 2006-04-07 19:50:00 +0200 | [diff] [blame] | 464 | /* Use IRET because user could have changed frame */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* |
| 467 | * Syscall return path ending with IRET. |
| 468 | * Has correct top of stack, but partial stack frame. |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 469 | */ |
| 470 | .globl int_ret_from_sys_call |
Roland McGrath | 5cbf156 | 2008-06-24 01:13:31 -0700 | [diff] [blame] | 471 | .globl int_with_check |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 472 | int_ret_from_sys_call: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 473 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 474 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | testl $3,CS-ARGOFFSET(%rsp) |
| 476 | je retint_restore_args |
| 477 | movl $_TIF_ALLWORK_MASK,%edi |
| 478 | /* edi: mask to check */ |
| 479 | int_with_check: |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 480 | LOCKDEP_SYS_EXIT_IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | GET_THREAD_INFO(%rcx) |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 482 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | andl %edi,%edx |
| 484 | jnz int_careful |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 485 | andl $~TS_COMPAT,TI_status(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | jmp retint_swapgs |
| 487 | |
| 488 | /* Either reschedule or signal or syscall exit tracking needed. */ |
| 489 | /* First do a reschedule test. */ |
| 490 | /* edx: work, edi: workmask */ |
| 491 | int_careful: |
| 492 | bt $TIF_NEED_RESCHED,%edx |
| 493 | jnc int_very_careful |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 494 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 495 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | pushq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 497 | CFI_ADJUST_CFA_OFFSET 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | call schedule |
| 499 | popq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 500 | CFI_ADJUST_CFA_OFFSET -8 |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 501 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 502 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | jmp int_with_check |
| 504 | |
| 505 | /* handle signals and tracing -- both require a full stack frame */ |
| 506 | int_very_careful: |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 507 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 508 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | SAVE_REST |
| 510 | /* Check for syscall exit trace */ |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 511 | testl $_TIF_WORK_SYSCALL_EXIT,%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | jz int_signal |
| 513 | pushq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 514 | CFI_ADJUST_CFA_OFFSET 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | leaq 8(%rsp),%rdi # &ptregs -> arg1 |
| 516 | call syscall_trace_leave |
| 517 | popq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 518 | CFI_ADJUST_CFA_OFFSET -8 |
Roland McGrath | d4d6715 | 2008-07-09 02:38:07 -0700 | [diff] [blame] | 519 | andl $~(_TIF_WORK_SYSCALL_EXIT|_TIF_SYSCALL_EMU),%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | jmp int_restore_rest |
| 521 | |
| 522 | int_signal: |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 523 | testl $_TIF_DO_NOTIFY_MASK,%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | jz 1f |
| 525 | movq %rsp,%rdi # &ptregs -> arg1 |
| 526 | xorl %esi,%esi # oldset -> arg2 |
| 527 | call do_notify_resume |
Roland McGrath | eca91e7 | 2008-07-10 14:50:39 -0700 | [diff] [blame] | 528 | 1: movl $_TIF_WORK_MASK,%edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | int_restore_rest: |
| 530 | RESTORE_REST |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 531 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 532 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | jmp int_with_check |
| 534 | CFI_ENDPROC |
Jan Beulich | bcddc01 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 535 | END(system_call) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | /* |
| 538 | * Certain special system calls that need to save a complete full stack frame. |
| 539 | */ |
| 540 | |
| 541 | .macro PTREGSCALL label,func,arg |
| 542 | .globl \label |
| 543 | \label: |
| 544 | leaq \func(%rip),%rax |
| 545 | leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */ |
| 546 | jmp ptregscall_common |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 547 | END(\label) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | .endm |
| 549 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 550 | CFI_STARTPROC |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | PTREGSCALL stub_clone, sys_clone, %r8 |
| 553 | PTREGSCALL stub_fork, sys_fork, %rdi |
| 554 | PTREGSCALL stub_vfork, sys_vfork, %rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx |
| 556 | PTREGSCALL stub_iopl, sys_iopl, %rsi |
| 557 | |
| 558 | ENTRY(ptregscall_common) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | popq %r11 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 560 | CFI_ADJUST_CFA_OFFSET -8 |
| 561 | CFI_REGISTER rip, r11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | SAVE_REST |
| 563 | movq %r11, %r15 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 564 | CFI_REGISTER rip, r15 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | FIXUP_TOP_OF_STACK %r11 |
| 566 | call *%rax |
| 567 | RESTORE_TOP_OF_STACK %r11 |
| 568 | movq %r15, %r11 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 569 | CFI_REGISTER rip, r11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | RESTORE_REST |
| 571 | pushq %r11 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 572 | CFI_ADJUST_CFA_OFFSET 8 |
| 573 | CFI_REL_OFFSET rip, 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | ret |
| 575 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 576 | END(ptregscall_common) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | ENTRY(stub_execve) |
| 579 | CFI_STARTPROC |
| 580 | popq %r11 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 581 | CFI_ADJUST_CFA_OFFSET -8 |
| 582 | CFI_REGISTER rip, r11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | SAVE_REST |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | FIXUP_TOP_OF_STACK %r11 |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 585 | movq %rsp, %rcx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | call sys_execve |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | RESTORE_TOP_OF_STACK %r11 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | movq %rax,RAX(%rsp) |
| 589 | RESTORE_REST |
| 590 | jmp int_ret_from_sys_call |
| 591 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 592 | END(stub_execve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | /* |
| 595 | * sigreturn is special because it needs to restore all registers on return. |
| 596 | * This cannot be done with SYSRET, so use the IRET return path instead. |
| 597 | */ |
| 598 | ENTRY(stub_rt_sigreturn) |
| 599 | CFI_STARTPROC |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 600 | addq $8, %rsp |
| 601 | CFI_ADJUST_CFA_OFFSET -8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | SAVE_REST |
| 603 | movq %rsp,%rdi |
| 604 | FIXUP_TOP_OF_STACK %r11 |
| 605 | call sys_rt_sigreturn |
| 606 | movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer |
| 607 | RESTORE_REST |
| 608 | jmp int_ret_from_sys_call |
| 609 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 610 | END(stub_rt_sigreturn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 612 | /* |
| 613 | * initial frame state for interrupts and exceptions |
| 614 | */ |
| 615 | .macro _frame ref |
| 616 | CFI_STARTPROC simple |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 617 | CFI_SIGNAL_FRAME |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 618 | CFI_DEF_CFA rsp,SS+8-\ref |
| 619 | /*CFI_REL_OFFSET ss,SS-\ref*/ |
| 620 | CFI_REL_OFFSET rsp,RSP-\ref |
| 621 | /*CFI_REL_OFFSET rflags,EFLAGS-\ref*/ |
| 622 | /*CFI_REL_OFFSET cs,CS-\ref*/ |
| 623 | CFI_REL_OFFSET rip,RIP-\ref |
| 624 | .endm |
| 625 | |
| 626 | /* initial frame state for interrupts (and exceptions without error code) */ |
| 627 | #define INTR_FRAME _frame RIP |
| 628 | /* initial frame state for exceptions with error code (and interrupts with |
| 629 | vector already pushed) */ |
| 630 | #define XCPT_FRAME _frame ORIG_RAX |
| 631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | /* |
| 633 | * Interrupt entry/exit. |
| 634 | * |
| 635 | * Interrupt entry points save only callee clobbered registers in fast path. |
| 636 | * |
| 637 | * Entry runs with interrupts off. |
| 638 | */ |
| 639 | |
| 640 | /* 0(%rsp): interrupt number */ |
| 641 | .macro interrupt func |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | cld |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | SAVE_ARGS |
| 644 | leaq -ARGOFFSET(%rsp),%rdi # arg1 for handler |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 645 | pushq %rbp |
Glauber Costa | 097a078 | 2008-08-14 17:33:12 -0300 | [diff] [blame] | 646 | /* |
| 647 | * Save rbp twice: One is for marking the stack frame, as usual, and the |
| 648 | * other, to fill pt_regs properly. This is because bx comes right |
| 649 | * before the last saved register in that structure, and not bp. If the |
| 650 | * base pointer were in the place bx is today, this would not be needed. |
| 651 | */ |
| 652 | movq %rbp, -8(%rsp) |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 653 | CFI_ADJUST_CFA_OFFSET 8 |
| 654 | CFI_REL_OFFSET rbp, 0 |
| 655 | movq %rsp,%rbp |
| 656 | CFI_DEF_CFA_REGISTER rbp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | testl $3,CS(%rdi) |
| 658 | je 1f |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 659 | SWAPGS |
Andi Kleen | 96e5404 | 2006-09-26 10:52:39 +0200 | [diff] [blame] | 660 | /* irqcount is used to check if a CPU is already on an interrupt |
| 661 | stack or not. While this is essentially redundant with preempt_count |
| 662 | it is a little cheaper to use a separate counter in the PDA |
| 663 | (short of moving irq_enter into assembly, which would be too |
| 664 | much work) */ |
| 665 | 1: incl %gs:pda_irqcount |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 666 | cmoveq %gs:pda_irqstackptr,%rsp |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 667 | push %rbp # backlink for old unwinder |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 668 | /* |
| 669 | * We entered an interrupt context - irqs are off: |
| 670 | */ |
| 671 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | call \func |
| 673 | .endm |
| 674 | |
| 675 | ENTRY(common_interrupt) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 676 | XCPT_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | interrupt do_IRQ |
| 678 | /* 0(%rsp): oldrsp-ARGOFFSET */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 679 | ret_from_intr: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 680 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 681 | TRACE_IRQS_OFF |
Andi Kleen | 3829ee6 | 2005-07-28 21:15:48 -0700 | [diff] [blame] | 682 | decl %gs:pda_irqcount |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 683 | leaveq |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 684 | CFI_DEF_CFA_REGISTER rsp |
Jan Beulich | 1de9c3f | 2006-06-26 13:57:35 +0200 | [diff] [blame] | 685 | CFI_ADJUST_CFA_OFFSET -8 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 686 | exit_intr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | GET_THREAD_INFO(%rcx) |
| 688 | testl $3,CS-ARGOFFSET(%rsp) |
| 689 | je retint_kernel |
| 690 | |
| 691 | /* Interrupt came from user space */ |
| 692 | /* |
| 693 | * Has a correct top of stack, but a partial stack frame |
| 694 | * %rcx: thread info. Interrupts off. |
| 695 | */ |
| 696 | retint_with_reschedule: |
| 697 | movl $_TIF_WORK_MASK,%edi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 698 | retint_check: |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 699 | LOCKDEP_SYS_EXIT_IRQ |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 700 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | andl %edi,%edx |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 702 | CFI_REMEMBER_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | jnz retint_careful |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 704 | |
| 705 | retint_swapgs: /* return to user-space */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 706 | /* |
| 707 | * The iretq could re-enable interrupts: |
| 708 | */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 709 | DISABLE_INTERRUPTS(CLBR_ANY) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 710 | TRACE_IRQS_IRETQ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 711 | SWAPGS |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 712 | jmp restore_args |
| 713 | |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 714 | retint_restore_args: /* return to kernel space */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 715 | DISABLE_INTERRUPTS(CLBR_ANY) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 716 | /* |
| 717 | * The iretq could re-enable interrupts: |
| 718 | */ |
| 719 | TRACE_IRQS_IRETQ |
| 720 | restore_args: |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 721 | RESTORE_ARGS 0,8,0 |
| 722 | |
Adrian Bunk | f7f3d79 | 2008-02-13 23:29:53 +0200 | [diff] [blame] | 723 | irq_return: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 724 | INTERRUPT_RETURN |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 725 | |
| 726 | .section __ex_table, "a" |
| 727 | .quad irq_return, bad_iret |
| 728 | .previous |
| 729 | |
| 730 | #ifdef CONFIG_PARAVIRT |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 731 | ENTRY(native_iret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | iretq |
| 733 | |
| 734 | .section __ex_table,"a" |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 735 | .quad native_iret, bad_iret |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | .previous |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 737 | #endif |
| 738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | .section .fixup,"ax" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | bad_iret: |
Roland McGrath | 3aa4b37 | 2008-02-06 22:39:43 +0100 | [diff] [blame] | 741 | /* |
| 742 | * The iret traps when the %cs or %ss being restored is bogus. |
| 743 | * We've lost the original trap vector and error code. |
| 744 | * #GPF is the most likely one to get for an invalid selector. |
| 745 | * So pretend we completed the iret and took the #GPF in user mode. |
| 746 | * |
| 747 | * We are now running with the kernel GS after exception recovery. |
| 748 | * But error_entry expects us to have user GS to match the user %cs, |
| 749 | * so swap back. |
| 750 | */ |
| 751 | pushq $0 |
| 752 | |
| 753 | SWAPGS |
| 754 | jmp general_protection |
| 755 | |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 756 | .previous |
| 757 | |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 758 | /* edi: workmask, edx: work */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | retint_careful: |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 760 | CFI_RESTORE_STATE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | bt $TIF_NEED_RESCHED,%edx |
| 762 | jnc retint_signal |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 763 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 764 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | pushq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 766 | CFI_ADJUST_CFA_OFFSET 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | call schedule |
| 768 | popq %rdi |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 769 | CFI_ADJUST_CFA_OFFSET -8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | GET_THREAD_INFO(%rcx) |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 771 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 772 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | jmp retint_check |
| 774 | |
| 775 | retint_signal: |
Peter Zijlstra | 8f4d37e | 2008-01-25 21:08:29 +0100 | [diff] [blame] | 776 | testl $_TIF_DO_NOTIFY_MASK,%edx |
Andi Kleen | 10ffdbb | 2005-05-16 21:53:19 -0700 | [diff] [blame] | 777 | jz retint_swapgs |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 778 | TRACE_IRQS_ON |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 779 | ENABLE_INTERRUPTS(CLBR_NONE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | SAVE_REST |
| 781 | movq $-1,ORIG_RAX(%rsp) |
Andi Kleen | 3829ee6 | 2005-07-28 21:15:48 -0700 | [diff] [blame] | 782 | xorl %esi,%esi # oldset |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | movq %rsp,%rdi # &pt_regs |
| 784 | call do_notify_resume |
| 785 | RESTORE_REST |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 786 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 787 | TRACE_IRQS_OFF |
Andi Kleen | be9e687 | 2005-05-01 08:58:51 -0700 | [diff] [blame] | 788 | GET_THREAD_INFO(%rcx) |
Roland McGrath | eca91e7 | 2008-07-10 14:50:39 -0700 | [diff] [blame] | 789 | jmp retint_with_reschedule |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | #ifdef CONFIG_PREEMPT |
| 792 | /* Returning to kernel space. Check if we need preemption */ |
| 793 | /* rcx: threadinfo. interrupts off. */ |
Andi Kleen | b06baba | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 794 | ENTRY(retint_kernel) |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 795 | cmpl $0,TI_preempt_count(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | jnz retint_restore_args |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 797 | bt $TIF_NEED_RESCHED,TI_flags(%rcx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | jnc retint_restore_args |
| 799 | bt $9,EFLAGS-ARGOFFSET(%rsp) /* interrupts off? */ |
| 800 | jnc retint_restore_args |
| 801 | call preempt_schedule_irq |
| 802 | jmp exit_intr |
| 803 | #endif |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 806 | END(common_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | |
| 808 | /* |
| 809 | * APIC interrupts. |
| 810 | */ |
| 811 | .macro apicinterrupt num,func |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 812 | INTR_FRAME |
Rusty Russell | 19eadf9 | 2006-06-27 02:53:44 -0700 | [diff] [blame] | 813 | pushq $~(\num) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 814 | CFI_ADJUST_CFA_OFFSET 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | interrupt \func |
| 816 | jmp ret_from_intr |
| 817 | CFI_ENDPROC |
| 818 | .endm |
| 819 | |
| 820 | ENTRY(thermal_interrupt) |
| 821 | apicinterrupt THERMAL_APIC_VECTOR,smp_thermal_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 822 | END(thermal_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 824 | ENTRY(threshold_interrupt) |
| 825 | apicinterrupt THRESHOLD_APIC_VECTOR,mce_threshold_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 826 | END(threshold_interrupt) |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | #ifdef CONFIG_SMP |
| 829 | ENTRY(reschedule_interrupt) |
| 830 | apicinterrupt RESCHEDULE_VECTOR,smp_reschedule_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 831 | END(reschedule_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Andi Kleen | e5bc8b6 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 833 | .macro INVALIDATE_ENTRY num |
| 834 | ENTRY(invalidate_interrupt\num) |
| 835 | apicinterrupt INVALIDATE_TLB_VECTOR_START+\num,smp_invalidate_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 836 | END(invalidate_interrupt\num) |
Andi Kleen | e5bc8b6 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 837 | .endm |
| 838 | |
| 839 | INVALIDATE_ENTRY 0 |
| 840 | INVALIDATE_ENTRY 1 |
| 841 | INVALIDATE_ENTRY 2 |
| 842 | INVALIDATE_ENTRY 3 |
| 843 | INVALIDATE_ENTRY 4 |
| 844 | INVALIDATE_ENTRY 5 |
| 845 | INVALIDATE_ENTRY 6 |
| 846 | INVALIDATE_ENTRY 7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
| 848 | ENTRY(call_function_interrupt) |
| 849 | apicinterrupt CALL_FUNCTION_VECTOR,smp_call_function_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 850 | END(call_function_interrupt) |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 851 | ENTRY(call_function_single_interrupt) |
| 852 | apicinterrupt CALL_FUNCTION_SINGLE_VECTOR,smp_call_function_single_interrupt |
| 853 | END(call_function_single_interrupt) |
Eric W. Biederman | 6101429 | 2007-02-23 04:40:58 -0700 | [diff] [blame] | 854 | ENTRY(irq_move_cleanup_interrupt) |
| 855 | apicinterrupt IRQ_MOVE_CLEANUP_VECTOR,smp_irq_move_cleanup_interrupt |
| 856 | END(irq_move_cleanup_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | #endif |
| 858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | ENTRY(apic_timer_interrupt) |
| 860 | apicinterrupt LOCAL_TIMER_VECTOR,smp_apic_timer_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 861 | END(apic_timer_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Cliff Wickman | 1812924 | 2008-06-02 08:56:14 -0500 | [diff] [blame] | 863 | ENTRY(uv_bau_message_intr1) |
| 864 | apicinterrupt 220,uv_bau_message_interrupt |
| 865 | END(uv_bau_message_intr1) |
| 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | ENTRY(error_interrupt) |
| 868 | apicinterrupt ERROR_APIC_VECTOR,smp_error_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 869 | END(error_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | ENTRY(spurious_interrupt) |
| 872 | apicinterrupt SPURIOUS_APIC_VECTOR,smp_spurious_interrupt |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 873 | END(spurious_interrupt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | /* |
| 876 | * Exception entry points. |
| 877 | */ |
| 878 | .macro zeroentry sym |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 879 | INTR_FRAME |
Jeremy Fitzhardinge | fab5842 | 2008-06-25 00:19:31 -0400 | [diff] [blame] | 880 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | pushq $0 /* push error code/oldrax */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 882 | CFI_ADJUST_CFA_OFFSET 8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | pushq %rax /* push real oldrax to the rdi slot */ |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 884 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 3755090 | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 885 | CFI_REL_OFFSET rax,0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | leaq \sym(%rip),%rax |
| 887 | jmp error_entry |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 888 | CFI_ENDPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | .endm |
| 890 | |
| 891 | .macro errorentry sym |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 892 | XCPT_FRAME |
Jeremy Fitzhardinge | fab5842 | 2008-06-25 00:19:31 -0400 | [diff] [blame] | 893 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | pushq %rax |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 895 | CFI_ADJUST_CFA_OFFSET 8 |
Jan Beulich | 3755090 | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 896 | CFI_REL_OFFSET rax,0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | leaq \sym(%rip),%rax |
| 898 | jmp error_entry |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 899 | CFI_ENDPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | .endm |
| 901 | |
| 902 | /* error code is on the stack already */ |
| 903 | /* handle NMI like exceptions that can happen everywhere */ |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 904 | .macro paranoidentry sym, ist=0, irqtrace=1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | SAVE_ALL |
| 906 | cld |
| 907 | movl $1,%ebx |
| 908 | movl $MSR_GS_BASE,%ecx |
| 909 | rdmsr |
| 910 | testl %edx,%edx |
| 911 | js 1f |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 912 | SWAPGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | xorl %ebx,%ebx |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 914 | 1: |
| 915 | .if \ist |
| 916 | movq %gs:pda_data_offset, %rbp |
| 917 | .endif |
Alexander van Heukelum | 7e61a79 | 2008-09-26 14:03:03 +0200 | [diff] [blame] | 918 | .if \irqtrace |
| 919 | TRACE_IRQS_OFF |
| 920 | .endif |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 921 | movq %rsp,%rdi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | movq ORIG_RAX(%rsp),%rsi |
| 923 | movq $-1,ORIG_RAX(%rsp) |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 924 | .if \ist |
Andi Kleen | 5f8efbb | 2006-01-16 01:56:39 +0100 | [diff] [blame] | 925 | subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 926 | .endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | call \sym |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 928 | .if \ist |
Andi Kleen | 5f8efbb | 2006-01-16 01:56:39 +0100 | [diff] [blame] | 929 | addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp) |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 930 | .endif |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 931 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 932 | .if \irqtrace |
| 933 | TRACE_IRQS_OFF |
| 934 | .endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | .endm |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 936 | |
| 937 | /* |
| 938 | * "Paranoid" exit path from exception stack. |
| 939 | * Paranoid because this is used by NMIs and cannot take |
| 940 | * any kernel state for granted. |
| 941 | * We don't do kernel preemption checks here, because only |
| 942 | * NMI should be common and it does not enable IRQs and |
| 943 | * cannot get reschedule ticks. |
| 944 | * |
| 945 | * "trace" is 0 for the NMI handler only, because irq-tracing |
| 946 | * is fundamentally NMI-unsafe. (we cannot change the soft and |
| 947 | * hard flags at once, atomically) |
| 948 | */ |
| 949 | .macro paranoidexit trace=1 |
| 950 | /* ebx: no swapgs flag */ |
| 951 | paranoid_exit\trace: |
| 952 | testl %ebx,%ebx /* swapgs needed? */ |
| 953 | jnz paranoid_restore\trace |
| 954 | testl $3,CS(%rsp) |
| 955 | jnz paranoid_userspace\trace |
| 956 | paranoid_swapgs\trace: |
Andi Kleen | 7a0a2df | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 957 | .if \trace |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 958 | TRACE_IRQS_IRETQ 0 |
Andi Kleen | 7a0a2df | 2006-09-26 10:52:37 +0200 | [diff] [blame] | 959 | .endif |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 960 | SWAPGS_UNSAFE_STACK |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 961 | paranoid_restore\trace: |
| 962 | RESTORE_ALL 8 |
Ingo Molnar | 3701d863 | 2008-02-09 23:24:08 +0100 | [diff] [blame] | 963 | jmp irq_return |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 964 | paranoid_userspace\trace: |
| 965 | GET_THREAD_INFO(%rcx) |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 966 | movl TI_flags(%rcx),%ebx |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 967 | andl $_TIF_WORK_MASK,%ebx |
| 968 | jz paranoid_swapgs\trace |
| 969 | movq %rsp,%rdi /* &pt_regs */ |
| 970 | call sync_regs |
| 971 | movq %rax,%rsp /* switch stack for scheduling */ |
| 972 | testl $_TIF_NEED_RESCHED,%ebx |
| 973 | jnz paranoid_schedule\trace |
| 974 | movl %ebx,%edx /* arg3: thread flags */ |
| 975 | .if \trace |
| 976 | TRACE_IRQS_ON |
| 977 | .endif |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 978 | ENABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 979 | xorl %esi,%esi /* arg2: oldset */ |
| 980 | movq %rsp,%rdi /* arg1: &pt_regs */ |
| 981 | call do_notify_resume |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 982 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 983 | .if \trace |
| 984 | TRACE_IRQS_OFF |
| 985 | .endif |
| 986 | jmp paranoid_userspace\trace |
| 987 | paranoid_schedule\trace: |
| 988 | .if \trace |
| 989 | TRACE_IRQS_ON |
| 990 | .endif |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 991 | ENABLE_INTERRUPTS(CLBR_ANY) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 992 | call schedule |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 993 | DISABLE_INTERRUPTS(CLBR_ANY) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 994 | .if \trace |
| 995 | TRACE_IRQS_OFF |
| 996 | .endif |
| 997 | jmp paranoid_userspace\trace |
| 998 | CFI_ENDPROC |
| 999 | .endm |
| 1000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | /* |
| 1002 | * Exception entry point. This expects an error code/orig_rax on the stack |
| 1003 | * and the exception handler in %rax. |
| 1004 | */ |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1005 | KPROBE_ENTRY(error_entry) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1006 | _frame RDI |
Jan Beulich | 3755090 | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 1007 | CFI_REL_OFFSET rax,0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | /* rdi slot contains rax, oldrax contains error code */ |
| 1009 | cld |
| 1010 | subq $14*8,%rsp |
| 1011 | CFI_ADJUST_CFA_OFFSET (14*8) |
| 1012 | movq %rsi,13*8(%rsp) |
| 1013 | CFI_REL_OFFSET rsi,RSI |
| 1014 | movq 14*8(%rsp),%rsi /* load rax from rdi slot */ |
Jan Beulich | 3755090 | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 1015 | CFI_REGISTER rax,rsi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | movq %rdx,12*8(%rsp) |
| 1017 | CFI_REL_OFFSET rdx,RDX |
| 1018 | movq %rcx,11*8(%rsp) |
| 1019 | CFI_REL_OFFSET rcx,RCX |
| 1020 | movq %rsi,10*8(%rsp) /* store rax */ |
| 1021 | CFI_REL_OFFSET rax,RAX |
| 1022 | movq %r8, 9*8(%rsp) |
| 1023 | CFI_REL_OFFSET r8,R8 |
| 1024 | movq %r9, 8*8(%rsp) |
| 1025 | CFI_REL_OFFSET r9,R9 |
| 1026 | movq %r10,7*8(%rsp) |
| 1027 | CFI_REL_OFFSET r10,R10 |
| 1028 | movq %r11,6*8(%rsp) |
| 1029 | CFI_REL_OFFSET r11,R11 |
| 1030 | movq %rbx,5*8(%rsp) |
| 1031 | CFI_REL_OFFSET rbx,RBX |
| 1032 | movq %rbp,4*8(%rsp) |
| 1033 | CFI_REL_OFFSET rbp,RBP |
| 1034 | movq %r12,3*8(%rsp) |
| 1035 | CFI_REL_OFFSET r12,R12 |
| 1036 | movq %r13,2*8(%rsp) |
| 1037 | CFI_REL_OFFSET r13,R13 |
| 1038 | movq %r14,1*8(%rsp) |
| 1039 | CFI_REL_OFFSET r14,R14 |
| 1040 | movq %r15,(%rsp) |
| 1041 | CFI_REL_OFFSET r15,R15 |
| 1042 | xorl %ebx,%ebx |
| 1043 | testl $3,CS(%rsp) |
| 1044 | je error_kernelspace |
| 1045 | error_swapgs: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1046 | SWAPGS |
Alexander van Heukelum | 6b11d4e | 2008-09-26 14:03:02 +0200 | [diff] [blame] | 1047 | error_sti: |
| 1048 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | movq %rdi,RDI(%rsp) |
Jan Beulich | 3755090 | 2007-05-02 19:27:05 +0200 | [diff] [blame] | 1050 | CFI_REL_OFFSET rdi,RDI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | movq %rsp,%rdi |
| 1052 | movq ORIG_RAX(%rsp),%rsi /* get error code */ |
| 1053 | movq $-1,ORIG_RAX(%rsp) |
| 1054 | call *%rax |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 1055 | /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */ |
| 1056 | error_exit: |
| 1057 | movl %ebx,%eax |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | RESTORE_REST |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1059 | DISABLE_INTERRUPTS(CLBR_NONE) |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1060 | TRACE_IRQS_OFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | GET_THREAD_INFO(%rcx) |
| 1062 | testl %eax,%eax |
| 1063 | jne retint_kernel |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 1064 | LOCKDEP_SYS_EXIT_IRQ |
Glauber Costa | 26ccb8a | 2008-06-24 11:19:35 -0300 | [diff] [blame] | 1065 | movl TI_flags(%rcx),%edx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | movl $_TIF_WORK_MASK,%edi |
| 1067 | andl %edi,%edx |
| 1068 | jnz retint_careful |
Peter Zijlstra | 10cd706 | 2007-10-11 22:11:12 +0200 | [diff] [blame] | 1069 | jmp retint_swapgs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | CFI_ENDPROC |
| 1071 | |
| 1072 | error_kernelspace: |
| 1073 | incl %ebx |
| 1074 | /* There are two places in the kernel that can potentially fault with |
| 1075 | usergs. Handle them here. The exception handlers after |
| 1076 | iret run with kernel gs again, so don't set the user space flag. |
| 1077 | B stepping K8s sometimes report an truncated RIP for IRET |
| 1078 | exceptions returning to compat mode. Check for these here too. */ |
Vegard Nossum | 9d8ad5d | 2008-06-27 17:22:17 +0200 | [diff] [blame] | 1079 | leaq irq_return(%rip),%rcx |
| 1080 | cmpq %rcx,RIP(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | je error_swapgs |
Vegard Nossum | 9d8ad5d | 2008-06-27 17:22:17 +0200 | [diff] [blame] | 1082 | movl %ecx,%ecx /* zero extend */ |
| 1083 | cmpq %rcx,RIP(%rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | je error_swapgs |
| 1085 | cmpq $gs_change,RIP(%rsp) |
| 1086 | je error_swapgs |
| 1087 | jmp error_sti |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1088 | KPROBE_END(error_entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | /* Reload gs selector with exception handling */ |
| 1091 | /* edi: new selector */ |
Jeremy Fitzhardinge | 9f9d489 | 2008-06-25 00:19:32 -0400 | [diff] [blame] | 1092 | ENTRY(native_load_gs_index) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1093 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | pushf |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1095 | CFI_ADJUST_CFA_OFFSET 8 |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1096 | DISABLE_INTERRUPTS(CLBR_ANY | ~(CLBR_RDI)) |
| 1097 | SWAPGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | gs_change: |
| 1099 | movl %edi,%gs |
| 1100 | 2: mfence /* workaround */ |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1101 | SWAPGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | popf |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1103 | CFI_ADJUST_CFA_OFFSET -8 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | ret |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1105 | CFI_ENDPROC |
Jeremy Fitzhardinge | 9f9d489 | 2008-06-25 00:19:32 -0400 | [diff] [blame] | 1106 | ENDPROC(native_load_gs_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | |
| 1108 | .section __ex_table,"a" |
| 1109 | .align 8 |
| 1110 | .quad gs_change,bad_gs |
| 1111 | .previous |
| 1112 | .section .fixup,"ax" |
| 1113 | /* running with kernelgs */ |
| 1114 | bad_gs: |
Glauber de Oliveira Costa | 72fe485 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 1115 | SWAPGS /* switch back to user gs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | xorl %eax,%eax |
| 1117 | movl %eax,%gs |
| 1118 | jmp 2b |
| 1119 | .previous |
| 1120 | |
| 1121 | /* |
| 1122 | * Create a kernel thread. |
| 1123 | * |
| 1124 | * C extern interface: |
| 1125 | * extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) |
| 1126 | * |
| 1127 | * asm input arguments: |
| 1128 | * rdi: fn, rsi: arg, rdx: flags |
| 1129 | */ |
| 1130 | ENTRY(kernel_thread) |
| 1131 | CFI_STARTPROC |
| 1132 | FAKE_STACK_FRAME $child_rip |
| 1133 | SAVE_ALL |
| 1134 | |
| 1135 | # rdi: flags, rsi: usp, rdx: will be &pt_regs |
| 1136 | movq %rdx,%rdi |
| 1137 | orq kernel_thread_flags(%rip),%rdi |
| 1138 | movq $-1, %rsi |
| 1139 | movq %rsp, %rdx |
| 1140 | |
| 1141 | xorl %r8d,%r8d |
| 1142 | xorl %r9d,%r9d |
| 1143 | |
| 1144 | # clone now |
| 1145 | call do_fork |
| 1146 | movq %rax,RAX(%rsp) |
| 1147 | xorl %edi,%edi |
| 1148 | |
| 1149 | /* |
| 1150 | * It isn't worth to check for reschedule here, |
| 1151 | * so internally to the x86_64 port you can rely on kernel_thread() |
| 1152 | * not to reschedule the child before returning, this avoids the need |
| 1153 | * of hacks for example to fork off the per-CPU idle tasks. |
| 1154 | * [Hopefully no generic code relies on the reschedule -AK] |
| 1155 | */ |
| 1156 | RESTORE_ALL |
| 1157 | UNFAKE_STACK_FRAME |
| 1158 | ret |
| 1159 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1160 | ENDPROC(kernel_thread) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | |
| 1162 | child_rip: |
Andi Kleen | c05991e | 2006-08-30 19:37:08 +0200 | [diff] [blame] | 1163 | pushq $0 # fake return address |
| 1164 | CFI_STARTPROC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | /* |
| 1166 | * Here we are in the child and the registers are set as they were |
| 1167 | * at kernel_thread() invocation in the parent. |
| 1168 | */ |
| 1169 | movq %rdi, %rax |
| 1170 | movq %rsi, %rdi |
| 1171 | call *%rax |
| 1172 | # exit |
Andrey Mirkin | 1c5b5cf | 2007-10-17 18:04:33 +0200 | [diff] [blame] | 1173 | mov %eax, %edi |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | call do_exit |
jia zhang | 5f5db59 | 2008-11-23 22:47:10 +0800 | [diff] [blame^] | 1175 | ud2 # padding for call trace |
Andi Kleen | c05991e | 2006-08-30 19:37:08 +0200 | [diff] [blame] | 1176 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1177 | ENDPROC(child_rip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
| 1179 | /* |
| 1180 | * execve(). This function needs to use IRET, not SYSRET, to set up all state properly. |
| 1181 | * |
| 1182 | * C extern interface: |
| 1183 | * extern long execve(char *name, char **argv, char **envp) |
| 1184 | * |
| 1185 | * asm input arguments: |
| 1186 | * rdi: name, rsi: argv, rdx: envp |
| 1187 | * |
| 1188 | * We want to fallback into: |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 1189 | * extern long sys_execve(char *name, char **argv,char **envp, struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | * |
| 1191 | * do_sys_execve asm fallback arguments: |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 1192 | * rdi: name, rsi: argv, rdx: envp, rcx: fake frame on the stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | */ |
Arnd Bergmann | 3db03b4 | 2006-10-02 02:18:31 -0700 | [diff] [blame] | 1194 | ENTRY(kernel_execve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | CFI_STARTPROC |
| 1196 | FAKE_STACK_FRAME $0 |
| 1197 | SAVE_ALL |
Ingo Molnar | 5d119b2 | 2008-02-26 12:55:57 +0100 | [diff] [blame] | 1198 | movq %rsp,%rcx |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | call sys_execve |
| 1200 | movq %rax, RAX(%rsp) |
| 1201 | RESTORE_REST |
| 1202 | testq %rax,%rax |
| 1203 | je int_ret_from_sys_call |
| 1204 | RESTORE_ARGS |
| 1205 | UNFAKE_STACK_FRAME |
| 1206 | ret |
| 1207 | CFI_ENDPROC |
Arnd Bergmann | 3db03b4 | 2006-10-02 02:18:31 -0700 | [diff] [blame] | 1208 | ENDPROC(kernel_execve) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 1210 | KPROBE_ENTRY(page_fault) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | errorentry do_page_fault |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1212 | KPROBE_END(page_fault) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | |
| 1214 | ENTRY(coprocessor_error) |
| 1215 | zeroentry do_coprocessor_error |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1216 | END(coprocessor_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
| 1218 | ENTRY(simd_coprocessor_error) |
| 1219 | zeroentry do_simd_coprocessor_error |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1220 | END(simd_coprocessor_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | |
| 1222 | ENTRY(device_not_available) |
Alexander van Heukelum | e407d620 | 2008-09-30 18:41:36 +0200 | [diff] [blame] | 1223 | zeroentry do_device_not_available |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1224 | END(device_not_available) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | |
| 1226 | /* runs on exception stack */ |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 1227 | KPROBE_ENTRY(debug) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1228 | INTR_FRAME |
Jeremy Fitzhardinge | 0940294 | 2008-07-12 02:22:12 -0700 | [diff] [blame] | 1229 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | pushq $0 |
| 1231 | CFI_ADJUST_CFA_OFFSET 8 |
Andi Kleen | 5f8efbb | 2006-01-16 01:56:39 +0100 | [diff] [blame] | 1232 | paranoidentry do_debug, DEBUG_STACK |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1233 | paranoidexit |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1234 | KPROBE_END(debug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
| 1236 | /* runs on exception stack */ |
Andi Kleen | eddb6fb | 2006-02-03 21:50:41 +0100 | [diff] [blame] | 1237 | KPROBE_ENTRY(nmi) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1238 | INTR_FRAME |
Jeremy Fitzhardinge | 0940294 | 2008-07-12 02:22:12 -0700 | [diff] [blame] | 1239 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | pushq $-1 |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1241 | CFI_ADJUST_CFA_OFFSET 8 |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1242 | paranoidentry do_nmi, 0, 0 |
| 1243 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 1244 | paranoidexit 0 |
| 1245 | #else |
| 1246 | jmp paranoid_exit1 |
| 1247 | CFI_ENDPROC |
| 1248 | #endif |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1249 | KPROBE_END(nmi) |
Andi Kleen | 6fefb0d | 2005-04-16 15:25:03 -0700 | [diff] [blame] | 1250 | |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 1251 | KPROBE_ENTRY(int3) |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 1252 | INTR_FRAME |
Jeremy Fitzhardinge | 0940294 | 2008-07-12 02:22:12 -0700 | [diff] [blame] | 1253 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 1254 | pushq $0 |
| 1255 | CFI_ADJUST_CFA_OFFSET 8 |
Andi Kleen | 5f8efbb | 2006-01-16 01:56:39 +0100 | [diff] [blame] | 1256 | paranoidentry do_int3, DEBUG_STACK |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1257 | jmp paranoid_exit1 |
Jan Beulich | b556b35 | 2006-01-11 22:43:00 +0100 | [diff] [blame] | 1258 | CFI_ENDPROC |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1259 | KPROBE_END(int3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | |
| 1261 | ENTRY(overflow) |
| 1262 | zeroentry do_overflow |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1263 | END(overflow) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
| 1265 | ENTRY(bounds) |
| 1266 | zeroentry do_bounds |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1267 | END(bounds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | ENTRY(invalid_op) |
| 1270 | zeroentry do_invalid_op |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1271 | END(invalid_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
| 1273 | ENTRY(coprocessor_segment_overrun) |
| 1274 | zeroentry do_coprocessor_segment_overrun |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1275 | END(coprocessor_segment_overrun) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | /* runs on exception stack */ |
| 1278 | ENTRY(double_fault) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1279 | XCPT_FRAME |
Jeremy Fitzhardinge | 0940294 | 2008-07-12 02:22:12 -0700 | [diff] [blame] | 1280 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | paranoidentry do_double_fault |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1282 | jmp paranoid_exit1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1284 | END(double_fault) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
| 1286 | ENTRY(invalid_TSS) |
| 1287 | errorentry do_invalid_TSS |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1288 | END(invalid_TSS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1289 | |
| 1290 | ENTRY(segment_not_present) |
| 1291 | errorentry do_segment_not_present |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1292 | END(segment_not_present) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* runs on exception stack */ |
| 1295 | ENTRY(stack_segment) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1296 | XCPT_FRAME |
Jeremy Fitzhardinge | 0940294 | 2008-07-12 02:22:12 -0700 | [diff] [blame] | 1297 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | paranoidentry do_stack_segment |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1299 | jmp paranoid_exit1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1301 | END(stack_segment) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
Prasanna S Panchamukhi | 0f2fbdc | 2005-09-06 15:19:28 -0700 | [diff] [blame] | 1303 | KPROBE_ENTRY(general_protection) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | errorentry do_general_protection |
Prasanna S.P | d28c439 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 1305 | KPROBE_END(general_protection) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | |
| 1307 | ENTRY(alignment_check) |
| 1308 | errorentry do_alignment_check |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1309 | END(alignment_check) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | |
| 1311 | ENTRY(divide_error) |
| 1312 | zeroentry do_divide_error |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1313 | END(divide_error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | |
| 1315 | ENTRY(spurious_interrupt_bug) |
| 1316 | zeroentry do_spurious_interrupt_bug |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1317 | END(spurious_interrupt_bug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
| 1319 | #ifdef CONFIG_X86_MCE |
| 1320 | /* runs on exception stack */ |
| 1321 | ENTRY(machine_check) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1322 | INTR_FRAME |
Jeremy Fitzhardinge | 0940294 | 2008-07-12 02:22:12 -0700 | [diff] [blame] | 1323 | PARAVIRT_ADJUST_EXCEPTION_FRAME |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | pushq $0 |
| 1325 | CFI_ADJUST_CFA_OFFSET 8 |
| 1326 | paranoidentry do_machine_check |
Ingo Molnar | 2601e64 | 2006-07-03 00:24:45 -0700 | [diff] [blame] | 1327 | jmp paranoid_exit1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1329 | END(machine_check) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | #endif |
| 1331 | |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1332 | /* Call softirq on interrupt stack. Interrupts are off. */ |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1333 | ENTRY(call_softirq) |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1334 | CFI_STARTPROC |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1335 | push %rbp |
| 1336 | CFI_ADJUST_CFA_OFFSET 8 |
| 1337 | CFI_REL_OFFSET rbp,0 |
| 1338 | mov %rsp,%rbp |
| 1339 | CFI_DEF_CFA_REGISTER rbp |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1340 | incl %gs:pda_irqcount |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1341 | cmove %gs:pda_irqstackptr,%rsp |
| 1342 | push %rbp # backlink for old unwinder |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1343 | call __do_softirq |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1344 | leaveq |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1345 | CFI_DEF_CFA_REGISTER rsp |
Andi Kleen | 2699500 | 2006-08-02 22:37:28 +0200 | [diff] [blame] | 1346 | CFI_ADJUST_CFA_OFFSET -8 |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1347 | decl %gs:pda_irqcount |
Andi Kleen | ed6b676 | 2005-07-28 21:15:49 -0700 | [diff] [blame] | 1348 | ret |
Jan Beulich | 7effaa8 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1349 | CFI_ENDPROC |
Jan Beulich | 4b787e0 | 2006-06-26 13:56:55 +0200 | [diff] [blame] | 1350 | ENDPROC(call_softirq) |
Andi Kleen | 75154f4 | 2007-06-23 02:29:25 +0200 | [diff] [blame] | 1351 | |
| 1352 | KPROBE_ENTRY(ignore_sysret) |
| 1353 | CFI_STARTPROC |
| 1354 | mov $-ENOSYS,%eax |
| 1355 | sysret |
| 1356 | CFI_ENDPROC |
| 1357 | ENDPROC(ignore_sysret) |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1358 | |
| 1359 | #ifdef CONFIG_XEN |
| 1360 | ENTRY(xen_hypervisor_callback) |
| 1361 | zeroentry xen_do_hypervisor_callback |
| 1362 | END(xen_hypervisor_callback) |
| 1363 | |
| 1364 | /* |
| 1365 | # A note on the "critical region" in our callback handler. |
| 1366 | # We want to avoid stacking callback handlers due to events occurring |
| 1367 | # during handling of the last event. To do this, we keep events disabled |
| 1368 | # until we've done all processing. HOWEVER, we must enable events before |
| 1369 | # popping the stack frame (can't be done atomically) and so it would still |
| 1370 | # be possible to get enough handler activations to overflow the stack. |
| 1371 | # Although unlikely, bugs of that kind are hard to track down, so we'd |
| 1372 | # like to avoid the possibility. |
| 1373 | # So, on entry to the handler we detect whether we interrupted an |
| 1374 | # existing activation in its critical region -- if so, we pop the current |
| 1375 | # activation and restart the handler using the previous one. |
| 1376 | */ |
| 1377 | ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs) |
| 1378 | CFI_STARTPROC |
| 1379 | /* Since we don't modify %rdi, evtchn_do_upall(struct *pt_regs) will |
| 1380 | see the correct pointer to the pt_regs */ |
| 1381 | movq %rdi, %rsp # we don't return, adjust the stack frame |
| 1382 | CFI_ENDPROC |
| 1383 | CFI_DEFAULT_STACK |
| 1384 | 11: incl %gs:pda_irqcount |
| 1385 | movq %rsp,%rbp |
| 1386 | CFI_DEF_CFA_REGISTER rbp |
| 1387 | cmovzq %gs:pda_irqstackptr,%rsp |
| 1388 | pushq %rbp # backlink for old unwinder |
| 1389 | call xen_evtchn_do_upcall |
| 1390 | popq %rsp |
| 1391 | CFI_DEF_CFA_REGISTER rsp |
| 1392 | decl %gs:pda_irqcount |
| 1393 | jmp error_exit |
| 1394 | CFI_ENDPROC |
| 1395 | END(do_hypervisor_callback) |
| 1396 | |
| 1397 | /* |
| 1398 | # Hypervisor uses this for application faults while it executes. |
| 1399 | # We get here for two reasons: |
| 1400 | # 1. Fault while reloading DS, ES, FS or GS |
| 1401 | # 2. Fault while executing IRET |
| 1402 | # Category 1 we do not need to fix up as Xen has already reloaded all segment |
| 1403 | # registers that could be reloaded and zeroed the others. |
| 1404 | # Category 2 we fix up by killing the current process. We cannot use the |
| 1405 | # normal Linux return path in this case because if we use the IRET hypercall |
| 1406 | # to pop the stack frame we end up in an infinite loop of failsafe callbacks. |
| 1407 | # We distinguish between categories by comparing each saved segment register |
| 1408 | # with its current contents: any discrepancy means we in category 1. |
| 1409 | */ |
| 1410 | ENTRY(xen_failsafe_callback) |
Jeremy Fitzhardinge | 4a5c3e7 | 2008-07-08 15:07:09 -0700 | [diff] [blame] | 1411 | framesz = (RIP-0x30) /* workaround buggy gas */ |
| 1412 | _frame framesz |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1413 | CFI_REL_OFFSET rcx, 0 |
| 1414 | CFI_REL_OFFSET r11, 8 |
| 1415 | movw %ds,%cx |
| 1416 | cmpw %cx,0x10(%rsp) |
| 1417 | CFI_REMEMBER_STATE |
| 1418 | jne 1f |
| 1419 | movw %es,%cx |
| 1420 | cmpw %cx,0x18(%rsp) |
| 1421 | jne 1f |
| 1422 | movw %fs,%cx |
| 1423 | cmpw %cx,0x20(%rsp) |
| 1424 | jne 1f |
| 1425 | movw %gs,%cx |
| 1426 | cmpw %cx,0x28(%rsp) |
| 1427 | jne 1f |
| 1428 | /* All segments match their saved values => Category 2 (Bad IRET). */ |
| 1429 | movq (%rsp),%rcx |
| 1430 | CFI_RESTORE rcx |
| 1431 | movq 8(%rsp),%r11 |
| 1432 | CFI_RESTORE r11 |
| 1433 | addq $0x30,%rsp |
| 1434 | CFI_ADJUST_CFA_OFFSET -0x30 |
Jeremy Fitzhardinge | 4a5c3e7 | 2008-07-08 15:07:09 -0700 | [diff] [blame] | 1435 | pushq $0 |
| 1436 | CFI_ADJUST_CFA_OFFSET 8 |
| 1437 | pushq %r11 |
| 1438 | CFI_ADJUST_CFA_OFFSET 8 |
| 1439 | pushq %rcx |
| 1440 | CFI_ADJUST_CFA_OFFSET 8 |
| 1441 | jmp general_protection |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1442 | CFI_RESTORE_STATE |
| 1443 | 1: /* Segment mismatch => Category 1 (Bad segment). Retry the IRET. */ |
| 1444 | movq (%rsp),%rcx |
| 1445 | CFI_RESTORE rcx |
| 1446 | movq 8(%rsp),%r11 |
| 1447 | CFI_RESTORE r11 |
| 1448 | addq $0x30,%rsp |
| 1449 | CFI_ADJUST_CFA_OFFSET -0x30 |
| 1450 | pushq $0 |
| 1451 | CFI_ADJUST_CFA_OFFSET 8 |
| 1452 | SAVE_ALL |
| 1453 | jmp error_exit |
| 1454 | CFI_ENDPROC |
Jeremy Fitzhardinge | 3d75e1b | 2008-07-08 15:06:49 -0700 | [diff] [blame] | 1455 | END(xen_failsafe_callback) |
| 1456 | |
| 1457 | #endif /* CONFIG_XEN */ |