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