Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 1 | /* |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 2 | * PowerPC version |
| 3 | * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) |
| 4 | * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP |
| 5 | * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> |
| 6 | * Adapted for Power Macintosh by Paul Mackerras. |
| 7 | * Low-level exception handlers and MMU support |
| 8 | * rewritten by Paul Mackerras. |
| 9 | * Copyright (C) 1996 Paul Mackerras. |
| 10 | * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net). |
| 11 | * |
| 12 | * This file contains the system call entry code, context switch |
| 13 | * code, and exception/interrupt return code for PowerPC. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ |
| 20 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 21 | #include <linux/errno.h> |
| 22 | #include <asm/unistd.h> |
| 23 | #include <asm/processor.h> |
| 24 | #include <asm/page.h> |
| 25 | #include <asm/mmu.h> |
| 26 | #include <asm/thread_info.h> |
| 27 | #include <asm/ppc_asm.h> |
| 28 | #include <asm/asm-offsets.h> |
| 29 | #include <asm/cputable.h> |
Stephen Rothwell | 3f639ee | 2006-09-25 18:19:00 +1000 | [diff] [blame] | 30 | #include <asm/firmware.h> |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 31 | #include <asm/bug.h> |
Benjamin Herrenschmidt | ec2b36b | 2008-04-17 14:34:59 +1000 | [diff] [blame] | 32 | #include <asm/ptrace.h> |
Benjamin Herrenschmidt | 945feb1 | 2008-04-17 14:35:01 +1000 | [diff] [blame] | 33 | #include <asm/irqflags.h> |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 34 | #include <asm/ftrace.h> |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 35 | #include <asm/hw_irq.h> |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * System calls. |
| 39 | */ |
| 40 | .section ".toc","aw" |
| 41 | .SYS_CALL_TABLE: |
| 42 | .tc .sys_call_table[TC],.sys_call_table |
| 43 | |
| 44 | /* This value is used to mark exception frames on the stack. */ |
| 45 | exception_marker: |
Benjamin Herrenschmidt | ec2b36b | 2008-04-17 14:34:59 +1000 | [diff] [blame] | 46 | .tc ID_EXC_MARKER[TC],STACK_FRAME_REGS_MARKER |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 47 | |
| 48 | .section ".text" |
| 49 | .align 7 |
| 50 | |
| 51 | #undef SHOW_SYSCALLS |
| 52 | |
| 53 | .globl system_call_common |
| 54 | system_call_common: |
| 55 | andi. r10,r12,MSR_PR |
| 56 | mr r10,r1 |
| 57 | addi r1,r1,-INT_FRAME_SIZE |
| 58 | beq- 1f |
| 59 | ld r1,PACAKSAVE(r13) |
| 60 | 1: std r10,0(r1) |
| 61 | std r11,_NIP(r1) |
| 62 | std r12,_MSR(r1) |
| 63 | std r0,GPR0(r1) |
| 64 | std r10,GPR1(r1) |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 65 | ACCOUNT_CPU_USER_ENTRY(r10, r11) |
Paul Mackerras | ab598b6 | 2008-11-30 11:49:45 +0000 | [diff] [blame] | 66 | /* |
| 67 | * This "crclr so" clears CR0.SO, which is the error indication on |
| 68 | * return from this system call. There must be no cmp instruction |
| 69 | * between it and the "mfcr r9" below, otherwise if XER.SO is set, |
| 70 | * CR0.SO will get set, causing all system calls to appear to fail. |
| 71 | */ |
| 72 | crclr so |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 73 | std r2,GPR2(r1) |
| 74 | std r3,GPR3(r1) |
| 75 | std r4,GPR4(r1) |
| 76 | std r5,GPR5(r1) |
| 77 | std r6,GPR6(r1) |
| 78 | std r7,GPR7(r1) |
| 79 | std r8,GPR8(r1) |
| 80 | li r11,0 |
| 81 | std r11,GPR9(r1) |
| 82 | std r11,GPR10(r1) |
| 83 | std r11,GPR11(r1) |
| 84 | std r11,GPR12(r1) |
Anton Blanchard | 823df43 | 2012-04-04 18:24:29 +0000 | [diff] [blame] | 85 | std r11,_XER(r1) |
Anton Blanchard | 8208741 | 2012-04-04 18:26:39 +0000 | [diff] [blame^] | 86 | std r11,_CTR(r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 87 | std r9,GPR13(r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 88 | mfcr r9 |
| 89 | mflr r10 |
| 90 | li r11,0xc01 |
| 91 | std r9,_CCR(r1) |
| 92 | std r10,_LINK(r1) |
| 93 | std r11,_TRAP(r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 94 | std r3,ORIG_GPR3(r1) |
| 95 | ld r2,PACATOC(r13) |
| 96 | addi r9,r1,STACK_FRAME_OVERHEAD |
| 97 | ld r11,exception_marker@toc(r2) |
| 98 | std r11,-16(r9) /* "regshere" marker */ |
Paul Mackerras | cf9efce | 2010-08-26 19:56:43 +0000 | [diff] [blame] | 99 | #if defined(CONFIG_VIRT_CPU_ACCOUNTING) && defined(CONFIG_PPC_SPLPAR) |
| 100 | BEGIN_FW_FTR_SECTION |
| 101 | beq 33f |
| 102 | /* if from user, see if there are any DTL entries to process */ |
| 103 | ld r10,PACALPPACAPTR(r13) /* get ptr to VPA */ |
| 104 | ld r11,PACA_DTL_RIDX(r13) /* get log read index */ |
| 105 | ld r10,LPPACA_DTLIDX(r10) /* get log write index */ |
| 106 | cmpd cr1,r11,r10 |
| 107 | beq+ cr1,33f |
| 108 | bl .accumulate_stolen_time |
| 109 | REST_GPR(0,r1) |
| 110 | REST_4GPRS(3,r1) |
| 111 | REST_2GPRS(7,r1) |
| 112 | addi r9,r1,STACK_FRAME_OVERHEAD |
| 113 | 33: |
| 114 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) |
| 115 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING && CONFIG_PPC_SPLPAR */ |
| 116 | |
Benjamin Herrenschmidt | 1421ae0 | 2012-03-01 15:40:23 +1100 | [diff] [blame] | 117 | /* |
| 118 | * A syscall should always be called with interrupts enabled |
| 119 | * so we just unconditionally hard-enable here. When some kind |
| 120 | * of irq tracing is used, we additionally check that condition |
| 121 | * is correct |
| 122 | */ |
| 123 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_BUG) |
| 124 | lbz r10,PACASOFTIRQEN(r13) |
| 125 | xori r10,r10,1 |
| 126 | 1: tdnei r10,0 |
| 127 | EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING |
| 128 | #endif |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 129 | |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 130 | #ifdef CONFIG_PPC_BOOK3E |
| 131 | wrteei 1 |
| 132 | #else |
Benjamin Herrenschmidt | 1421ae0 | 2012-03-01 15:40:23 +1100 | [diff] [blame] | 133 | ld r11,PACAKMSR(r13) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 134 | ori r11,r11,MSR_EE |
| 135 | mtmsrd r11,1 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 136 | #endif /* CONFIG_PPC_BOOK3E */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 137 | |
Benjamin Herrenschmidt | 1421ae0 | 2012-03-01 15:40:23 +1100 | [diff] [blame] | 138 | /* We do need to set SOFTE in the stack frame or the return |
| 139 | * from interrupt will be painful |
| 140 | */ |
| 141 | li r10,1 |
| 142 | std r10,SOFTE(r1) |
| 143 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 144 | #ifdef SHOW_SYSCALLS |
| 145 | bl .do_show_syscall |
| 146 | REST_GPR(0,r1) |
| 147 | REST_4GPRS(3,r1) |
| 148 | REST_2GPRS(7,r1) |
| 149 | addi r9,r1,STACK_FRAME_OVERHEAD |
| 150 | #endif |
| 151 | clrrdi r11,r1,THREAD_SHIFT |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 152 | ld r10,TI_FLAGS(r11) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 153 | andi. r11,r10,_TIF_SYSCALL_T_OR_A |
| 154 | bne- syscall_dotrace |
Anton Blanchard | d14299d | 2012-04-04 18:23:27 +0000 | [diff] [blame] | 155 | .Lsyscall_dotrace_cont: |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 156 | cmpldi 0,r0,NR_syscalls |
| 157 | bge- syscall_enosys |
| 158 | |
| 159 | system_call: /* label this so stack traces look sane */ |
| 160 | /* |
| 161 | * Need to vector to 32 Bit or default sys_call_table here, |
| 162 | * based on caller's run-mode / personality. |
| 163 | */ |
| 164 | ld r11,.SYS_CALL_TABLE@toc(2) |
| 165 | andi. r10,r10,_TIF_32BIT |
| 166 | beq 15f |
| 167 | addi r11,r11,8 /* use 32-bit syscall entries */ |
| 168 | clrldi r3,r3,32 |
| 169 | clrldi r4,r4,32 |
| 170 | clrldi r5,r5,32 |
| 171 | clrldi r6,r6,32 |
| 172 | clrldi r7,r7,32 |
| 173 | clrldi r8,r8,32 |
| 174 | 15: |
| 175 | slwi r0,r0,4 |
| 176 | ldx r10,r11,r0 /* Fetch system call handler [ptr] */ |
| 177 | mtctr r10 |
| 178 | bctrl /* Call handler */ |
| 179 | |
| 180 | syscall_exit: |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 181 | std r3,RESULT(r1) |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 182 | #ifdef SHOW_SYSCALLS |
| 183 | bl .do_show_syscall_exit |
| 184 | ld r3,RESULT(r1) |
| 185 | #endif |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 186 | clrrdi r12,r1,THREAD_SHIFT |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 187 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 188 | ld r8,_MSR(r1) |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 189 | #ifdef CONFIG_PPC_BOOK3S |
| 190 | /* No MSR:RI on BookE */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 191 | andi. r10,r8,MSR_RI |
| 192 | beq- unrecov_restore |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 193 | #endif |
Benjamin Herrenschmidt | 1421ae0 | 2012-03-01 15:40:23 +1100 | [diff] [blame] | 194 | /* |
| 195 | * Disable interrupts so current_thread_info()->flags can't change, |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 196 | * and so that we don't get interrupted after loading SRR0/1. |
| 197 | */ |
| 198 | #ifdef CONFIG_PPC_BOOK3E |
| 199 | wrteei 0 |
| 200 | #else |
Benjamin Herrenschmidt | 1421ae0 | 2012-03-01 15:40:23 +1100 | [diff] [blame] | 201 | ld r10,PACAKMSR(r13) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 202 | mtmsrd r10,1 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 203 | #endif /* CONFIG_PPC_BOOK3E */ |
| 204 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 205 | ld r9,TI_FLAGS(r12) |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 206 | li r11,-_LAST_ERRNO |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 207 | andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 208 | bne- syscall_exit_work |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 209 | cmpld r3,r11 |
| 210 | ld r5,_CCR(r1) |
| 211 | bge- syscall_error |
Anton Blanchard | d14299d | 2012-04-04 18:23:27 +0000 | [diff] [blame] | 212 | .Lsyscall_error_cont: |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 213 | ld r7,_NIP(r1) |
Anton Blanchard | f89451f | 2010-08-11 01:40:27 +0000 | [diff] [blame] | 214 | BEGIN_FTR_SECTION |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 215 | stdcx. r0,0,r1 /* to clear the reservation */ |
Anton Blanchard | f89451f | 2010-08-11 01:40:27 +0000 | [diff] [blame] | 216 | END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 217 | andi. r6,r8,MSR_PR |
| 218 | ld r4,_LINK(r1) |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 219 | /* |
| 220 | * Clear RI before restoring r13. If we are returning to |
| 221 | * userspace and we take an exception after restoring r13, |
| 222 | * we end up corrupting the userspace r13 value. |
| 223 | */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 224 | #ifdef CONFIG_PPC_BOOK3S |
| 225 | /* No MSR:RI on BookE */ |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 226 | li r12,MSR_RI |
| 227 | andc r11,r10,r12 |
| 228 | mtmsrd r11,1 /* clear MSR.RI */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 229 | #endif /* CONFIG_PPC_BOOK3S */ |
| 230 | |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 231 | beq- 1f |
| 232 | ACCOUNT_CPU_USER_EXIT(r11, r12) |
| 233 | ld r13,GPR13(r1) /* only restore r13 if returning to usermode */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 234 | 1: ld r2,GPR2(r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 235 | ld r1,GPR1(r1) |
| 236 | mtlr r4 |
| 237 | mtcr r5 |
| 238 | mtspr SPRN_SRR0,r7 |
| 239 | mtspr SPRN_SRR1,r8 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 240 | RFI |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 241 | b . /* prevent speculative execution */ |
| 242 | |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 243 | syscall_error: |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 244 | oris r5,r5,0x1000 /* Set SO bit in CR */ |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 245 | neg r3,r3 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 246 | std r5,_CCR(r1) |
Anton Blanchard | d14299d | 2012-04-04 18:23:27 +0000 | [diff] [blame] | 247 | b .Lsyscall_error_cont |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 248 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 249 | /* Traced system call support */ |
| 250 | syscall_dotrace: |
| 251 | bl .save_nvgprs |
| 252 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 253 | bl .do_syscall_trace_enter |
Roland McGrath | 4f72c42 | 2008-07-27 16:51:03 +1000 | [diff] [blame] | 254 | /* |
| 255 | * Restore argument registers possibly just changed. |
| 256 | * We use the return value of do_syscall_trace_enter |
| 257 | * for the call number to look up in the table (r0). |
| 258 | */ |
| 259 | mr r0,r3 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 260 | ld r3,GPR3(r1) |
| 261 | ld r4,GPR4(r1) |
| 262 | ld r5,GPR5(r1) |
| 263 | ld r6,GPR6(r1) |
| 264 | ld r7,GPR7(r1) |
| 265 | ld r8,GPR8(r1) |
| 266 | addi r9,r1,STACK_FRAME_OVERHEAD |
| 267 | clrrdi r10,r1,THREAD_SHIFT |
| 268 | ld r10,TI_FLAGS(r10) |
Anton Blanchard | d14299d | 2012-04-04 18:23:27 +0000 | [diff] [blame] | 269 | b .Lsyscall_dotrace_cont |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 270 | |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 271 | syscall_enosys: |
| 272 | li r3,-ENOSYS |
| 273 | b syscall_exit |
| 274 | |
| 275 | syscall_exit_work: |
| 276 | /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr. |
| 277 | If TIF_NOERROR is set, just save r3 as it is. */ |
| 278 | |
| 279 | andi. r0,r9,_TIF_RESTOREALL |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 280 | beq+ 0f |
| 281 | REST_NVGPRS(r1) |
| 282 | b 2f |
| 283 | 0: cmpld r3,r11 /* r10 is -LAST_ERRNO */ |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 284 | blt+ 1f |
| 285 | andi. r0,r9,_TIF_NOERROR |
| 286 | bne- 1f |
| 287 | ld r5,_CCR(r1) |
| 288 | neg r3,r3 |
| 289 | oris r5,r5,0x1000 /* Set SO bit in CR */ |
| 290 | std r5,_CCR(r1) |
| 291 | 1: std r3,GPR3(r1) |
| 292 | 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK) |
| 293 | beq 4f |
| 294 | |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 295 | /* Clear per-syscall TIF flags if any are set. */ |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 296 | |
| 297 | li r11,_TIF_PERSYSCALL_MASK |
| 298 | addi r12,r12,TI_FLAGS |
| 299 | 3: ldarx r10,0,r12 |
| 300 | andc r10,r10,r11 |
| 301 | stdcx. r10,0,r12 |
| 302 | bne- 3b |
| 303 | subi r12,r12,TI_FLAGS |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 304 | |
| 305 | 4: /* Anything else left to do? */ |
| 306 | andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP) |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 307 | beq .ret_from_except_lite |
| 308 | |
| 309 | /* Re-enable interrupts */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 310 | #ifdef CONFIG_PPC_BOOK3E |
| 311 | wrteei 1 |
| 312 | #else |
Benjamin Herrenschmidt | 1421ae0 | 2012-03-01 15:40:23 +1100 | [diff] [blame] | 313 | ld r10,PACAKMSR(r13) |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 314 | ori r10,r10,MSR_EE |
| 315 | mtmsrd r10,1 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 316 | #endif /* CONFIG_PPC_BOOK3E */ |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 317 | |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 318 | bl .save_nvgprs |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 319 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 320 | bl .do_syscall_trace_leave |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 321 | b .ret_from_except |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 322 | |
| 323 | /* Save non-volatile GPRs, if not already saved. */ |
| 324 | _GLOBAL(save_nvgprs) |
| 325 | ld r11,_TRAP(r1) |
| 326 | andi. r0,r11,1 |
| 327 | beqlr- |
| 328 | SAVE_NVGPRS(r1) |
| 329 | clrrdi r0,r11,1 |
| 330 | std r0,_TRAP(r1) |
| 331 | blr |
| 332 | |
David Woodhouse | 401d1f0 | 2005-11-15 18:52:18 +0000 | [diff] [blame] | 333 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 334 | /* |
| 335 | * The sigsuspend and rt_sigsuspend system calls can call do_signal |
| 336 | * and thus put the process into the stopped state where we might |
| 337 | * want to examine its user state with ptrace. Therefore we need |
| 338 | * to save all the nonvolatile registers (r14 - r31) before calling |
| 339 | * the C code. Similarly, fork, vfork and clone need the full |
| 340 | * register state on the stack so that it can be copied to the child. |
| 341 | */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 342 | |
| 343 | _GLOBAL(ppc_fork) |
| 344 | bl .save_nvgprs |
| 345 | bl .sys_fork |
| 346 | b syscall_exit |
| 347 | |
| 348 | _GLOBAL(ppc_vfork) |
| 349 | bl .save_nvgprs |
| 350 | bl .sys_vfork |
| 351 | b syscall_exit |
| 352 | |
| 353 | _GLOBAL(ppc_clone) |
| 354 | bl .save_nvgprs |
| 355 | bl .sys_clone |
| 356 | b syscall_exit |
| 357 | |
Paul Mackerras | 1bd7933 | 2006-03-08 13:24:22 +1100 | [diff] [blame] | 358 | _GLOBAL(ppc32_swapcontext) |
| 359 | bl .save_nvgprs |
| 360 | bl .compat_sys_swapcontext |
| 361 | b syscall_exit |
| 362 | |
| 363 | _GLOBAL(ppc64_swapcontext) |
| 364 | bl .save_nvgprs |
| 365 | bl .sys_swapcontext |
| 366 | b syscall_exit |
| 367 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 368 | _GLOBAL(ret_from_fork) |
| 369 | bl .schedule_tail |
| 370 | REST_NVGPRS(r1) |
| 371 | li r3,0 |
| 372 | b syscall_exit |
| 373 | |
| 374 | /* |
| 375 | * This routine switches between two different tasks. The process |
| 376 | * state of one is saved on its kernel stack. Then the state |
| 377 | * of the other is restored from its kernel stack. The memory |
| 378 | * management hardware is updated to the second process's state. |
| 379 | * Finally, we can return to the second process, via ret_from_except. |
| 380 | * On entry, r3 points to the THREAD for the current task, r4 |
| 381 | * points to the THREAD for the new task. |
| 382 | * |
| 383 | * Note: there are two ways to get to the "going out" portion |
| 384 | * of this code; either by coming in via the entry (_switch) |
| 385 | * or via "fork" which must set up an environment equivalent |
| 386 | * to the "_switch" path. If you change this you'll have to change |
| 387 | * the fork code also. |
| 388 | * |
| 389 | * The code which creates the new task context is in 'copy_thread' |
Jon Mason | 2ef9481 | 2006-01-23 10:58:20 -0600 | [diff] [blame] | 390 | * in arch/powerpc/kernel/process.c |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 391 | */ |
| 392 | .align 7 |
| 393 | _GLOBAL(_switch) |
| 394 | mflr r0 |
| 395 | std r0,16(r1) |
| 396 | stdu r1,-SWITCH_FRAME_SIZE(r1) |
| 397 | /* r3-r13 are caller saved -- Cort */ |
| 398 | SAVE_8GPRS(14, r1) |
| 399 | SAVE_10GPRS(22, r1) |
| 400 | mflr r20 /* Return to switch caller */ |
| 401 | mfmsr r22 |
| 402 | li r0, MSR_FP |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 403 | #ifdef CONFIG_VSX |
| 404 | BEGIN_FTR_SECTION |
| 405 | oris r0,r0,MSR_VSX@h /* Disable VSX */ |
| 406 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 407 | #endif /* CONFIG_VSX */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 408 | #ifdef CONFIG_ALTIVEC |
| 409 | BEGIN_FTR_SECTION |
| 410 | oris r0,r0,MSR_VEC@h /* Disable altivec */ |
| 411 | mfspr r24,SPRN_VRSAVE /* save vrsave register value */ |
| 412 | std r24,THREAD_VRSAVE(r3) |
| 413 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 414 | #endif /* CONFIG_ALTIVEC */ |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 415 | #ifdef CONFIG_PPC64 |
| 416 | BEGIN_FTR_SECTION |
| 417 | mfspr r25,SPRN_DSCR |
| 418 | std r25,THREAD_DSCR(r3) |
| 419 | END_FTR_SECTION_IFSET(CPU_FTR_DSCR) |
| 420 | #endif |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 421 | and. r0,r0,r22 |
| 422 | beq+ 1f |
| 423 | andc r22,r22,r0 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 424 | MTMSRD(r22) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 425 | isync |
| 426 | 1: std r20,_NIP(r1) |
| 427 | mfcr r23 |
| 428 | std r23,_CCR(r1) |
| 429 | std r1,KSP(r3) /* Set old stack pointer */ |
| 430 | |
| 431 | #ifdef CONFIG_SMP |
| 432 | /* We need a sync somewhere here to make sure that if the |
| 433 | * previous task gets rescheduled on another CPU, it sees all |
| 434 | * stores it has performed on this one. |
| 435 | */ |
| 436 | sync |
| 437 | #endif /* CONFIG_SMP */ |
| 438 | |
Anton Blanchard | f89451f | 2010-08-11 01:40:27 +0000 | [diff] [blame] | 439 | /* |
| 440 | * If we optimise away the clear of the reservation in system |
| 441 | * calls because we know the CPU tracks the address of the |
| 442 | * reservation, then we need to clear it here to cover the |
| 443 | * case that the kernel context switch path has no larx |
| 444 | * instructions. |
| 445 | */ |
| 446 | BEGIN_FTR_SECTION |
| 447 | ldarx r6,0,r1 |
| 448 | END_FTR_SECTION_IFSET(CPU_FTR_STCX_CHECKS_ADDRESS) |
| 449 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 450 | addi r6,r4,-THREAD /* Convert THREAD to 'current' */ |
| 451 | std r6,PACACURRENT(r13) /* Set new 'current' */ |
| 452 | |
| 453 | ld r8,KSP(r4) /* new stack pointer */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 454 | #ifdef CONFIG_PPC_BOOK3S |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 455 | BEGIN_FTR_SECTION |
Michael Ellerman | c230328 | 2008-06-24 11:33:05 +1000 | [diff] [blame] | 456 | BEGIN_FTR_SECTION_NESTED(95) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 457 | clrrdi r6,r8,28 /* get its ESID */ |
| 458 | clrrdi r9,r1,28 /* get current sp ESID */ |
Michael Ellerman | c230328 | 2008-06-24 11:33:05 +1000 | [diff] [blame] | 459 | FTR_SECTION_ELSE_NESTED(95) |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 460 | clrrdi r6,r8,40 /* get its 1T ESID */ |
| 461 | clrrdi r9,r1,40 /* get current sp 1T ESID */ |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 462 | ALT_MMU_FTR_SECTION_END_NESTED_IFCLR(MMU_FTR_1T_SEGMENT, 95) |
Michael Ellerman | c230328 | 2008-06-24 11:33:05 +1000 | [diff] [blame] | 463 | FTR_SECTION_ELSE |
| 464 | b 2f |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 465 | ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_SLB) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 466 | clrldi. r0,r6,2 /* is new ESID c00000000? */ |
| 467 | cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */ |
| 468 | cror eq,4*cr1+eq,eq |
| 469 | beq 2f /* if yes, don't slbie it */ |
| 470 | |
| 471 | /* Bolt in the new stack SLB entry */ |
| 472 | ld r7,KSP_VSID(r4) /* Get new stack's VSID */ |
| 473 | oris r0,r6,(SLB_ESID_V)@h |
| 474 | ori r0,r0,(SLB_NUM_BOLTED-1)@l |
Paul Mackerras | 1189be6 | 2007-10-11 20:37:10 +1000 | [diff] [blame] | 475 | BEGIN_FTR_SECTION |
| 476 | li r9,MMU_SEGSIZE_1T /* insert B field */ |
| 477 | oris r6,r6,(MMU_SEGSIZE_1T << SLBIE_SSIZE_SHIFT)@h |
| 478 | rldimi r7,r9,SLB_VSID_SSIZE_SHIFT,0 |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 479 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT) |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 480 | |
Michael Neuling | 00efee7 | 2007-08-24 16:58:37 +1000 | [diff] [blame] | 481 | /* Update the last bolted SLB. No write barriers are needed |
| 482 | * here, provided we only update the current CPU's SLB shadow |
| 483 | * buffer. |
| 484 | */ |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 485 | ld r9,PACA_SLBSHADOWPTR(r13) |
Michael Neuling | 11a27ad | 2006-08-09 17:00:30 +1000 | [diff] [blame] | 486 | li r12,0 |
| 487 | std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */ |
| 488 | std r7,SLBSHADOW_STACKVSID(r9) /* Save VSID */ |
| 489 | std r0,SLBSHADOW_STACKESID(r9) /* Save ESID */ |
Michael Neuling | 2f6093c | 2006-08-07 16:19:19 +1000 | [diff] [blame] | 490 | |
Matt Evans | 44ae3ab | 2011-04-06 19:48:50 +0000 | [diff] [blame] | 491 | /* No need to check for MMU_FTR_NO_SLBIE_B here, since when |
Olof Johansson | f66bce5 | 2007-10-16 00:58:59 +1000 | [diff] [blame] | 492 | * we have 1TB segments, the only CPUs known to have the errata |
| 493 | * only support less than 1TB of system memory and we'll never |
| 494 | * actually hit this code path. |
| 495 | */ |
| 496 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 497 | slbie r6 |
| 498 | slbie r6 /* Workaround POWER5 < DD2.1 issue */ |
| 499 | slbmte r7,r0 |
| 500 | isync |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 501 | 2: |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 502 | #endif /* !CONFIG_PPC_BOOK3S */ |
| 503 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 504 | clrrdi r7,r8,THREAD_SHIFT /* base of new stack */ |
| 505 | /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE |
| 506 | because we don't need to leave the 288-byte ABI gap at the |
| 507 | top of the kernel stack. */ |
| 508 | addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE |
| 509 | |
| 510 | mr r1,r8 /* start using new stack pointer */ |
| 511 | std r7,PACAKSAVE(r13) |
| 512 | |
| 513 | ld r6,_CCR(r1) |
| 514 | mtcrf 0xFF,r6 |
| 515 | |
| 516 | #ifdef CONFIG_ALTIVEC |
| 517 | BEGIN_FTR_SECTION |
| 518 | ld r0,THREAD_VRSAVE(r4) |
| 519 | mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */ |
| 520 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 521 | #endif /* CONFIG_ALTIVEC */ |
Alexey Kardashevskiy | efcac65 | 2011-03-02 15:18:48 +0000 | [diff] [blame] | 522 | #ifdef CONFIG_PPC64 |
| 523 | BEGIN_FTR_SECTION |
| 524 | ld r0,THREAD_DSCR(r4) |
| 525 | cmpd r0,r25 |
| 526 | beq 1f |
| 527 | mtspr SPRN_DSCR,r0 |
| 528 | 1: |
| 529 | END_FTR_SECTION_IFSET(CPU_FTR_DSCR) |
| 530 | #endif |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 531 | |
| 532 | /* r3-r13 are destroyed -- Cort */ |
| 533 | REST_8GPRS(14, r1) |
| 534 | REST_10GPRS(22, r1) |
| 535 | |
| 536 | /* convert old thread to its task_struct for return value */ |
| 537 | addi r3,r3,-THREAD |
| 538 | ld r7,_NIP(r1) /* Return to _switch caller in new task */ |
| 539 | mtlr r7 |
| 540 | addi r1,r1,SWITCH_FRAME_SIZE |
| 541 | blr |
| 542 | |
| 543 | .align 7 |
| 544 | _GLOBAL(ret_from_except) |
| 545 | ld r11,_TRAP(r1) |
| 546 | andi. r0,r11,1 |
| 547 | bne .ret_from_except_lite |
| 548 | REST_NVGPRS(r1) |
| 549 | |
| 550 | _GLOBAL(ret_from_except_lite) |
| 551 | /* |
| 552 | * Disable interrupts so that current_thread_info()->flags |
| 553 | * can't change between when we test it and when we return |
| 554 | * from the interrupt. |
| 555 | */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 556 | #ifdef CONFIG_PPC_BOOK3E |
| 557 | wrteei 0 |
| 558 | #else |
Benjamin Herrenschmidt | d9ada91 | 2012-03-02 11:33:52 +1100 | [diff] [blame] | 559 | ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */ |
| 560 | mtmsrd r10,1 /* Update machine state */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 561 | #endif /* CONFIG_PPC_BOOK3E */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 562 | |
| 563 | #ifdef CONFIG_PREEMPT |
| 564 | clrrdi r9,r1,THREAD_SHIFT /* current_thread_info() */ |
| 565 | li r0,_TIF_NEED_RESCHED /* bits to check */ |
| 566 | ld r3,_MSR(r1) |
| 567 | ld r4,TI_FLAGS(r9) |
| 568 | /* Move MSR_PR bit in r3 to _TIF_SIGPENDING position in r0 */ |
| 569 | rlwimi r0,r3,32+TIF_SIGPENDING-MSR_PR_LG,_TIF_SIGPENDING |
| 570 | and. r0,r4,r0 /* check NEED_RESCHED and maybe SIGPENDING */ |
| 571 | bne do_work |
| 572 | |
| 573 | #else /* !CONFIG_PREEMPT */ |
| 574 | ld r3,_MSR(r1) /* Returning to user mode? */ |
| 575 | andi. r3,r3,MSR_PR |
| 576 | beq restore /* if not, just restore regs and return */ |
| 577 | |
| 578 | /* Check current_thread_info()->flags */ |
| 579 | clrrdi r9,r1,THREAD_SHIFT |
| 580 | ld r4,TI_FLAGS(r9) |
| 581 | andi. r0,r4,_TIF_USER_WORK_MASK |
| 582 | bne do_work |
Benjamin Herrenschmidt | 4f8cf36 | 2012-02-28 13:44:58 +1100 | [diff] [blame] | 583 | #endif /* !CONFIG_PREEMPT */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 584 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 585 | .globl fast_exc_return_irq |
| 586 | fast_exc_return_irq: |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 587 | restore: |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 588 | /* |
| 589 | * This is the main kernel exit path, we first check if we |
| 590 | * have to change our interrupt state. |
| 591 | */ |
Michael Ellerman | 01f3880d | 2008-07-16 14:21:34 +1000 | [diff] [blame] | 592 | ld r5,SOFTE(r1) |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 593 | lbz r6,PACASOFTIRQEN(r13) |
| 594 | cmpwi cr1,r5,0 |
| 595 | cmpw cr0,r5,r6 |
| 596 | beq cr0,4f |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 597 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 598 | /* We do, handle disable first, which is easy */ |
| 599 | bne cr1,3f; |
| 600 | li r0,0 |
| 601 | stb r0,PACASOFTIRQEN(r13); |
| 602 | TRACE_DISABLE_INTS |
| 603 | b 4f |
Paul Mackerras | b0a779d | 2006-10-18 10:11:22 +1000 | [diff] [blame] | 604 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 605 | 3: /* |
| 606 | * We are about to soft-enable interrupts (we are hard disabled |
| 607 | * at this point). We check if there's anything that needs to |
| 608 | * be replayed first. |
| 609 | */ |
| 610 | lbz r0,PACAIRQHAPPENED(r13) |
| 611 | cmpwi cr0,r0,0 |
| 612 | bne- restore_check_irq_replay |
| 613 | |
| 614 | /* |
| 615 | * Get here when nothing happened while soft-disabled, just |
| 616 | * soft-enable and move-on. We will hard-enable as a side |
| 617 | * effect of rfi |
| 618 | */ |
| 619 | restore_no_replay: |
| 620 | TRACE_ENABLE_INTS |
| 621 | li r0,1 |
| 622 | stb r0,PACASOFTIRQEN(r13); |
| 623 | |
| 624 | /* |
| 625 | * Final return path. BookE is handled in a different file |
| 626 | */ |
| 627 | 4: |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 628 | #ifdef CONFIG_PPC_BOOK3E |
| 629 | b .exception_return_book3e |
| 630 | #else |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 631 | /* |
| 632 | * Clear the reservation. If we know the CPU tracks the address of |
| 633 | * the reservation then we can potentially save some cycles and use |
| 634 | * a larx. On POWER6 and POWER7 this is significantly faster. |
| 635 | */ |
| 636 | BEGIN_FTR_SECTION |
| 637 | stdcx. r0,0,r1 /* to clear the reservation */ |
| 638 | FTR_SECTION_ELSE |
| 639 | ldarx r4,0,r1 |
| 640 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) |
| 641 | |
| 642 | /* |
| 643 | * Some code path such as load_up_fpu or altivec return directly |
| 644 | * here. They run entirely hard disabled and do not alter the |
| 645 | * interrupt state. They also don't use lwarx/stwcx. and thus |
| 646 | * are known not to leave dangling reservations. |
| 647 | */ |
| 648 | .globl fast_exception_return |
| 649 | fast_exception_return: |
| 650 | ld r3,_MSR(r1) |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 651 | ld r4,_CTR(r1) |
| 652 | ld r0,_LINK(r1) |
| 653 | mtctr r4 |
| 654 | mtlr r0 |
| 655 | ld r4,_XER(r1) |
| 656 | mtspr SPRN_XER,r4 |
| 657 | |
| 658 | REST_8GPRS(5, r1) |
| 659 | |
| 660 | andi. r0,r3,MSR_RI |
| 661 | beq- unrecov_restore |
| 662 | |
Anton Blanchard | f89451f | 2010-08-11 01:40:27 +0000 | [diff] [blame] | 663 | /* |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 664 | * Clear RI before restoring r13. If we are returning to |
| 665 | * userspace and we take an exception after restoring r13, |
| 666 | * we end up corrupting the userspace r13 value. |
| 667 | */ |
Benjamin Herrenschmidt | d9ada91 | 2012-03-02 11:33:52 +1100 | [diff] [blame] | 668 | ld r4,PACAKMSR(r13) /* Get kernel MSR without EE */ |
| 669 | andc r4,r4,r0 /* r0 contains MSR_RI here */ |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 670 | mtmsrd r4,1 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 671 | |
| 672 | /* |
| 673 | * r13 is our per cpu area, only restore it if we are returning to |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 674 | * userspace the value stored in the stack frame may belong to |
| 675 | * another CPU. |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 676 | */ |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 677 | andi. r0,r3,MSR_PR |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 678 | beq 1f |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 679 | ACCOUNT_CPU_USER_EXIT(r2, r4) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 680 | REST_GPR(13, r1) |
| 681 | 1: |
Paul Mackerras | e56a6e2 | 2007-02-07 13:13:26 +1100 | [diff] [blame] | 682 | mtspr SPRN_SRR1,r3 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 683 | |
| 684 | ld r2,_CCR(r1) |
| 685 | mtcrf 0xFF,r2 |
| 686 | ld r2,_NIP(r1) |
| 687 | mtspr SPRN_SRR0,r2 |
| 688 | |
| 689 | ld r0,GPR0(r1) |
| 690 | ld r2,GPR2(r1) |
| 691 | ld r3,GPR3(r1) |
| 692 | ld r4,GPR4(r1) |
| 693 | ld r1,GPR1(r1) |
| 694 | |
| 695 | rfid |
| 696 | b . /* prevent speculative execution */ |
| 697 | |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 698 | #endif /* CONFIG_PPC_BOOK3E */ |
| 699 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 700 | /* |
| 701 | * Something did happen, check if a re-emit is needed |
| 702 | * (this also clears paca->irq_happened) |
| 703 | */ |
| 704 | restore_check_irq_replay: |
| 705 | /* XXX: We could implement a fast path here where we check |
| 706 | * for irq_happened being just 0x01, in which case we can |
| 707 | * clear it and return. That means that we would potentially |
| 708 | * miss a decrementer having wrapped all the way around. |
| 709 | * |
| 710 | * Still, this might be useful for things like hash_page |
| 711 | */ |
| 712 | bl .__check_irq_replay |
| 713 | cmpwi cr0,r3,0 |
| 714 | beq restore_no_replay |
| 715 | |
| 716 | /* |
| 717 | * We need to re-emit an interrupt. We do so by re-using our |
| 718 | * existing exception frame. We first change the trap value, |
| 719 | * but we need to ensure we preserve the low nibble of it |
| 720 | */ |
| 721 | ld r4,_TRAP(r1) |
| 722 | clrldi r4,r4,60 |
| 723 | or r4,r4,r3 |
| 724 | std r4,_TRAP(r1) |
| 725 | |
| 726 | /* |
| 727 | * Then find the right handler and call it. Interrupts are |
| 728 | * still soft-disabled and we keep them that way. |
| 729 | */ |
| 730 | cmpwi cr0,r3,0x500 |
| 731 | bne 1f |
| 732 | addi r3,r1,STACK_FRAME_OVERHEAD; |
| 733 | bl .do_IRQ |
| 734 | b .ret_from_except |
| 735 | 1: cmpwi cr0,r3,0x900 |
| 736 | bne 1f |
| 737 | addi r3,r1,STACK_FRAME_OVERHEAD; |
| 738 | bl .timer_interrupt |
| 739 | b .ret_from_except |
| 740 | #ifdef CONFIG_PPC_BOOK3E |
| 741 | 1: cmpwi cr0,r3,0x280 |
| 742 | bne 1f |
| 743 | addi r3,r1,STACK_FRAME_OVERHEAD; |
| 744 | bl .doorbell_exception |
| 745 | b .ret_from_except |
| 746 | #endif /* CONFIG_PPC_BOOK3E */ |
| 747 | 1: b .ret_from_except /* What else to do here ? */ |
| 748 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 749 | do_work: |
| 750 | #ifdef CONFIG_PREEMPT |
| 751 | andi. r0,r3,MSR_PR /* Returning to user mode? */ |
| 752 | bne user_work |
| 753 | /* Check that preempt_count() == 0 and interrupts are enabled */ |
| 754 | lwz r8,TI_PREEMPT(r9) |
| 755 | cmpwi cr1,r8,0 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 756 | ld r0,SOFTE(r1) |
| 757 | cmpdi r0,0 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 758 | crandc eq,cr1*4+eq,eq |
| 759 | bne restore |
Benjamin Herrenschmidt | 4f917ba | 2009-10-26 19:41:17 +0000 | [diff] [blame] | 760 | |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 761 | /* |
| 762 | * Here we are preempting the current task. We want to make |
| 763 | * sure we are soft-disabled first |
Benjamin Herrenschmidt | 945feb1 | 2008-04-17 14:35:01 +1000 | [diff] [blame] | 764 | */ |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 765 | SOFT_DISABLE_INTS(r3,r4) |
Benjamin Herrenschmidt | 4f917ba | 2009-10-26 19:41:17 +0000 | [diff] [blame] | 766 | 1: bl .preempt_schedule_irq |
| 767 | |
| 768 | /* Hard-disable interrupts again (and update PACA) */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 769 | #ifdef CONFIG_PPC_BOOK3E |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 770 | wrteei 0 |
| 771 | #else |
Benjamin Herrenschmidt | d9ada91 | 2012-03-02 11:33:52 +1100 | [diff] [blame] | 772 | ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 773 | mtmsrd r10,1 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 774 | #endif /* CONFIG_PPC_BOOK3E */ |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 775 | li r0,PACA_IRQ_HARD_DIS |
| 776 | stb r0,PACAIRQHAPPENED(r13) |
Benjamin Herrenschmidt | 4f917ba | 2009-10-26 19:41:17 +0000 | [diff] [blame] | 777 | |
| 778 | /* Re-test flags and eventually loop */ |
| 779 | clrrdi r9,r1,THREAD_SHIFT |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 780 | ld r4,TI_FLAGS(r9) |
| 781 | andi. r0,r4,_TIF_NEED_RESCHED |
| 782 | bne 1b |
| 783 | b restore |
| 784 | |
| 785 | user_work: |
Benjamin Herrenschmidt | 4f917ba | 2009-10-26 19:41:17 +0000 | [diff] [blame] | 786 | #endif /* CONFIG_PREEMPT */ |
| 787 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 788 | /* Enable interrupts */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 789 | #ifdef CONFIG_PPC_BOOK3E |
| 790 | wrteei 1 |
| 791 | #else |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 792 | ori r10,r10,MSR_EE |
| 793 | mtmsrd r10,1 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 794 | #endif /* CONFIG_PPC_BOOK3E */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 795 | |
| 796 | andi. r0,r4,_TIF_NEED_RESCHED |
| 797 | beq 1f |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 798 | bl .restore_interrupts |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 799 | bl .schedule |
| 800 | b .ret_from_except_lite |
| 801 | |
| 802 | 1: bl .save_nvgprs |
Benjamin Herrenschmidt | 7230c56 | 2012-03-06 18:27:59 +1100 | [diff] [blame] | 803 | bl .restore_interrupts |
Roland McGrath | 7d6d637 | 2008-07-27 16:52:52 +1000 | [diff] [blame] | 804 | addi r3,r1,STACK_FRAME_OVERHEAD |
Benjamin Herrenschmidt | 18b246f | 2012-02-22 16:48:32 +1100 | [diff] [blame] | 805 | bl .do_notify_resume |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 806 | b .ret_from_except |
| 807 | |
| 808 | unrecov_restore: |
| 809 | addi r3,r1,STACK_FRAME_OVERHEAD |
| 810 | bl .unrecoverable_exception |
| 811 | b unrecov_restore |
| 812 | |
| 813 | #ifdef CONFIG_PPC_RTAS |
| 814 | /* |
| 815 | * On CHRP, the Run-Time Abstraction Services (RTAS) have to be |
| 816 | * called with the MMU off. |
| 817 | * |
| 818 | * In addition, we need to be in 32b mode, at least for now. |
| 819 | * |
| 820 | * Note: r3 is an input parameter to rtas, so don't trash it... |
| 821 | */ |
| 822 | _GLOBAL(enter_rtas) |
| 823 | mflr r0 |
| 824 | std r0,16(r1) |
| 825 | stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */ |
| 826 | |
| 827 | /* Because RTAS is running in 32b mode, it clobbers the high order half |
| 828 | * of all registers that it saves. We therefore save those registers |
| 829 | * RTAS might touch to the stack. (r0, r3-r13 are caller saved) |
| 830 | */ |
| 831 | SAVE_GPR(2, r1) /* Save the TOC */ |
| 832 | SAVE_GPR(13, r1) /* Save paca */ |
| 833 | SAVE_8GPRS(14, r1) /* Save the non-volatiles */ |
| 834 | SAVE_10GPRS(22, r1) /* ditto */ |
| 835 | |
| 836 | mfcr r4 |
| 837 | std r4,_CCR(r1) |
| 838 | mfctr r5 |
| 839 | std r5,_CTR(r1) |
| 840 | mfspr r6,SPRN_XER |
| 841 | std r6,_XER(r1) |
| 842 | mfdar r7 |
| 843 | std r7,_DAR(r1) |
| 844 | mfdsisr r8 |
| 845 | std r8,_DSISR(r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 846 | |
Mike Kravetz | 9fe901d | 2006-03-27 15:20:00 -0800 | [diff] [blame] | 847 | /* Temporary workaround to clear CR until RTAS can be modified to |
| 848 | * ignore all bits. |
| 849 | */ |
| 850 | li r0,0 |
| 851 | mtcr r0 |
| 852 | |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 853 | #ifdef CONFIG_BUG |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 854 | /* There is no way it is acceptable to get here with interrupts enabled, |
| 855 | * check it with the asm equivalent of WARN_ON |
| 856 | */ |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 857 | lbz r0,PACASOFTIRQEN(r13) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 858 | 1: tdnei r0,0 |
David Woodhouse | 007d88d | 2007-01-01 18:45:34 +0000 | [diff] [blame] | 859 | EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING |
| 860 | #endif |
| 861 | |
Paul Mackerras | d04c56f | 2006-10-04 16:47:49 +1000 | [diff] [blame] | 862 | /* Hard-disable interrupts */ |
| 863 | mfmsr r6 |
| 864 | rldicl r7,r6,48,1 |
| 865 | rotldi r7,r7,16 |
| 866 | mtmsrd r7,1 |
| 867 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 868 | /* Unfortunately, the stack pointer and the MSR are also clobbered, |
| 869 | * so they are saved in the PACA which allows us to restore |
| 870 | * our original state after RTAS returns. |
| 871 | */ |
| 872 | std r1,PACAR1(r13) |
| 873 | std r6,PACASAVEDMSR(r13) |
| 874 | |
| 875 | /* Setup our real return addr */ |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 876 | LOAD_REG_ADDR(r4,.rtas_return_loc) |
| 877 | clrldi r4,r4,2 /* convert to realmode address */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 878 | mtlr r4 |
| 879 | |
| 880 | li r0,0 |
| 881 | ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI |
| 882 | andc r0,r6,r0 |
| 883 | |
| 884 | li r9,1 |
| 885 | rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG) |
Anton Blanchard | 44c9f3c | 2010-02-07 19:37:29 +0000 | [diff] [blame] | 886 | ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 887 | andc r6,r0,r9 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 888 | sync /* disable interrupts so SRR0/1 */ |
| 889 | mtmsrd r0 /* don't get trashed */ |
| 890 | |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 891 | LOAD_REG_ADDR(r4, rtas) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 892 | ld r5,RTASENTRY(r4) /* get the rtas->entry value */ |
| 893 | ld r4,RTASBASE(r4) /* get the rtas->base value */ |
| 894 | |
| 895 | mtspr SPRN_SRR0,r5 |
| 896 | mtspr SPRN_SRR1,r6 |
| 897 | rfid |
| 898 | b . /* prevent speculative execution */ |
| 899 | |
| 900 | _STATIC(rtas_return_loc) |
| 901 | /* relocation is off at this point */ |
Benjamin Herrenschmidt | 2dd60d7 | 2011-01-20 17:50:21 +1100 | [diff] [blame] | 902 | GET_PACA(r4) |
David Gibson | e58c349 | 2006-01-13 14:56:25 +1100 | [diff] [blame] | 903 | clrldi r4,r4,2 /* convert to realmode address */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 904 | |
Paul Mackerras | e31aa45 | 2008-08-30 11:41:12 +1000 | [diff] [blame] | 905 | bcl 20,31,$+4 |
| 906 | 0: mflr r3 |
| 907 | ld r3,(1f-0b)(r3) /* get &.rtas_restore_regs */ |
| 908 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 909 | mfmsr r6 |
| 910 | li r0,MSR_RI |
| 911 | andc r6,r6,r0 |
| 912 | sync |
| 913 | mtmsrd r6 |
| 914 | |
| 915 | ld r1,PACAR1(r4) /* Restore our SP */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 916 | ld r4,PACASAVEDMSR(r4) /* Restore our MSR */ |
| 917 | |
| 918 | mtspr SPRN_SRR0,r3 |
| 919 | mtspr SPRN_SRR1,r4 |
| 920 | rfid |
| 921 | b . /* prevent speculative execution */ |
| 922 | |
Paul Mackerras | e31aa45 | 2008-08-30 11:41:12 +1000 | [diff] [blame] | 923 | .align 3 |
| 924 | 1: .llong .rtas_restore_regs |
| 925 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 926 | _STATIC(rtas_restore_regs) |
| 927 | /* relocation is on at this point */ |
| 928 | REST_GPR(2, r1) /* Restore the TOC */ |
| 929 | REST_GPR(13, r1) /* Restore paca */ |
| 930 | REST_8GPRS(14, r1) /* Restore the non-volatiles */ |
| 931 | REST_10GPRS(22, r1) /* ditto */ |
| 932 | |
Benjamin Herrenschmidt | 2dd60d7 | 2011-01-20 17:50:21 +1100 | [diff] [blame] | 933 | GET_PACA(r13) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 934 | |
| 935 | ld r4,_CCR(r1) |
| 936 | mtcr r4 |
| 937 | ld r5,_CTR(r1) |
| 938 | mtctr r5 |
| 939 | ld r6,_XER(r1) |
| 940 | mtspr SPRN_XER,r6 |
| 941 | ld r7,_DAR(r1) |
| 942 | mtdar r7 |
| 943 | ld r8,_DSISR(r1) |
| 944 | mtdsisr r8 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 945 | |
| 946 | addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */ |
| 947 | ld r0,16(r1) /* get return address */ |
| 948 | |
| 949 | mtlr r0 |
| 950 | blr /* return to caller */ |
| 951 | |
| 952 | #endif /* CONFIG_PPC_RTAS */ |
| 953 | |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 954 | _GLOBAL(enter_prom) |
| 955 | mflr r0 |
| 956 | std r0,16(r1) |
| 957 | stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */ |
| 958 | |
| 959 | /* Because PROM is running in 32b mode, it clobbers the high order half |
| 960 | * of all registers that it saves. We therefore save those registers |
| 961 | * PROM might touch to the stack. (r0, r3-r13 are caller saved) |
| 962 | */ |
Benjamin Herrenschmidt | 6c17199 | 2009-07-23 23:15:07 +0000 | [diff] [blame] | 963 | SAVE_GPR(2, r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 964 | SAVE_GPR(13, r1) |
| 965 | SAVE_8GPRS(14, r1) |
| 966 | SAVE_10GPRS(22, r1) |
Benjamin Herrenschmidt | 6c17199 | 2009-07-23 23:15:07 +0000 | [diff] [blame] | 967 | mfcr r10 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 968 | mfmsr r11 |
Benjamin Herrenschmidt | 6c17199 | 2009-07-23 23:15:07 +0000 | [diff] [blame] | 969 | std r10,_CCR(r1) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 970 | std r11,_MSR(r1) |
| 971 | |
| 972 | /* Get the PROM entrypoint */ |
Benjamin Herrenschmidt | 6c17199 | 2009-07-23 23:15:07 +0000 | [diff] [blame] | 973 | mtlr r4 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 974 | |
| 975 | /* Switch MSR to 32 bits mode |
| 976 | */ |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 977 | #ifdef CONFIG_PPC_BOOK3E |
| 978 | rlwinm r11,r11,0,1,31 |
| 979 | mtmsr r11 |
| 980 | #else /* CONFIG_PPC_BOOK3E */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 981 | mfmsr r11 |
| 982 | li r12,1 |
| 983 | rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG) |
| 984 | andc r11,r11,r12 |
| 985 | li r12,1 |
| 986 | rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG) |
| 987 | andc r11,r11,r12 |
| 988 | mtmsrd r11 |
Benjamin Herrenschmidt | 2d27cfd | 2009-07-23 23:15:59 +0000 | [diff] [blame] | 989 | #endif /* CONFIG_PPC_BOOK3E */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 990 | isync |
| 991 | |
Benjamin Herrenschmidt | 6c17199 | 2009-07-23 23:15:07 +0000 | [diff] [blame] | 992 | /* Enter PROM here... */ |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 993 | blrl |
| 994 | |
| 995 | /* Just make sure that r1 top 32 bits didn't get |
| 996 | * corrupt by OF |
| 997 | */ |
| 998 | rldicl r1,r1,0,32 |
| 999 | |
| 1000 | /* Restore the MSR (back to 64 bits) */ |
| 1001 | ld r0,_MSR(r1) |
Benjamin Herrenschmidt | 6c17199 | 2009-07-23 23:15:07 +0000 | [diff] [blame] | 1002 | MTMSRD(r0) |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 1003 | isync |
| 1004 | |
| 1005 | /* Restore other registers */ |
| 1006 | REST_GPR(2, r1) |
| 1007 | REST_GPR(13, r1) |
| 1008 | REST_8GPRS(14, r1) |
| 1009 | REST_10GPRS(22, r1) |
| 1010 | ld r4,_CCR(r1) |
| 1011 | mtcr r4 |
Paul Mackerras | 9994a33 | 2005-10-10 22:36:14 +1000 | [diff] [blame] | 1012 | |
| 1013 | addi r1,r1,PROM_FRAME_SIZE |
| 1014 | ld r0,16(r1) |
| 1015 | mtlr r0 |
| 1016 | blr |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1017 | |
Steven Rostedt | 606576c | 2008-10-06 19:06:12 -0400 | [diff] [blame] | 1018 | #ifdef CONFIG_FUNCTION_TRACER |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1019 | #ifdef CONFIG_DYNAMIC_FTRACE |
| 1020 | _GLOBAL(mcount) |
| 1021 | _GLOBAL(_mcount) |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1022 | blr |
| 1023 | |
| 1024 | _GLOBAL(ftrace_caller) |
| 1025 | /* Taken from output of objdump from lib64/glibc */ |
| 1026 | mflr r3 |
| 1027 | ld r11, 0(r1) |
| 1028 | stdu r1, -112(r1) |
| 1029 | std r3, 128(r1) |
| 1030 | ld r4, 16(r11) |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 1031 | subi r3, r3, MCOUNT_INSN_SIZE |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1032 | .globl ftrace_call |
| 1033 | ftrace_call: |
| 1034 | bl ftrace_stub |
| 1035 | nop |
Steven Rostedt | 4654288 | 2009-02-10 22:19:54 -0800 | [diff] [blame] | 1036 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 1037 | .globl ftrace_graph_call |
| 1038 | ftrace_graph_call: |
| 1039 | b ftrace_graph_stub |
| 1040 | _GLOBAL(ftrace_graph_stub) |
| 1041 | #endif |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1042 | ld r0, 128(r1) |
| 1043 | mtlr r0 |
| 1044 | addi r1, r1, 112 |
| 1045 | _GLOBAL(ftrace_stub) |
| 1046 | blr |
| 1047 | #else |
| 1048 | _GLOBAL(mcount) |
| 1049 | blr |
| 1050 | |
| 1051 | _GLOBAL(_mcount) |
| 1052 | /* Taken from output of objdump from lib64/glibc */ |
| 1053 | mflr r3 |
| 1054 | ld r11, 0(r1) |
| 1055 | stdu r1, -112(r1) |
| 1056 | std r3, 128(r1) |
| 1057 | ld r4, 16(r11) |
| 1058 | |
Abhishek Sagar | 395a59d | 2008-06-21 23:47:27 +0530 | [diff] [blame] | 1059 | subi r3, r3, MCOUNT_INSN_SIZE |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1060 | LOAD_REG_ADDR(r5,ftrace_trace_function) |
| 1061 | ld r5,0(r5) |
| 1062 | ld r5,0(r5) |
| 1063 | mtctr r5 |
| 1064 | bctrl |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1065 | nop |
Steven Rostedt | 6794c78 | 2009-02-09 21:10:27 -0800 | [diff] [blame] | 1066 | |
| 1067 | |
| 1068 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
| 1069 | b ftrace_graph_caller |
| 1070 | #endif |
Steven Rostedt | 4e491d1 | 2008-05-14 23:49:44 -0400 | [diff] [blame] | 1071 | ld r0, 128(r1) |
| 1072 | mtlr r0 |
| 1073 | addi r1, r1, 112 |
| 1074 | _GLOBAL(ftrace_stub) |
| 1075 | blr |
| 1076 | |
Steven Rostedt | 6794c78 | 2009-02-09 21:10:27 -0800 | [diff] [blame] | 1077 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
| 1078 | |
| 1079 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
Steven Rostedt | 4654288 | 2009-02-10 22:19:54 -0800 | [diff] [blame] | 1080 | _GLOBAL(ftrace_graph_caller) |
Steven Rostedt | 6794c78 | 2009-02-09 21:10:27 -0800 | [diff] [blame] | 1081 | /* load r4 with local address */ |
| 1082 | ld r4, 128(r1) |
| 1083 | subi r4, r4, MCOUNT_INSN_SIZE |
| 1084 | |
| 1085 | /* get the parent address */ |
| 1086 | ld r11, 112(r1) |
| 1087 | addi r3, r11, 16 |
| 1088 | |
| 1089 | bl .prepare_ftrace_return |
| 1090 | nop |
| 1091 | |
| 1092 | ld r0, 128(r1) |
| 1093 | mtlr r0 |
| 1094 | addi r1, r1, 112 |
| 1095 | blr |
| 1096 | |
| 1097 | _GLOBAL(return_to_handler) |
| 1098 | /* need to save return values */ |
Steven Rostedt | bb72534 | 2009-02-11 12:45:49 -0800 | [diff] [blame] | 1099 | std r4, -24(r1) |
| 1100 | std r3, -16(r1) |
| 1101 | std r31, -8(r1) |
| 1102 | mr r31, r1 |
| 1103 | stdu r1, -112(r1) |
| 1104 | |
| 1105 | bl .ftrace_return_to_handler |
| 1106 | nop |
| 1107 | |
| 1108 | /* return value has real return address */ |
| 1109 | mtlr r3 |
| 1110 | |
| 1111 | ld r1, 0(r1) |
| 1112 | ld r4, -24(r1) |
| 1113 | ld r3, -16(r1) |
| 1114 | ld r31, -8(r1) |
| 1115 | |
| 1116 | /* Jump back to real return address */ |
| 1117 | blr |
| 1118 | |
| 1119 | _GLOBAL(mod_return_to_handler) |
| 1120 | /* need to save return values */ |
Steven Rostedt | 6794c78 | 2009-02-09 21:10:27 -0800 | [diff] [blame] | 1121 | std r4, -32(r1) |
| 1122 | std r3, -24(r1) |
| 1123 | /* save TOC */ |
| 1124 | std r2, -16(r1) |
| 1125 | std r31, -8(r1) |
| 1126 | mr r31, r1 |
| 1127 | stdu r1, -112(r1) |
| 1128 | |
Steven Rostedt | bb72534 | 2009-02-11 12:45:49 -0800 | [diff] [blame] | 1129 | /* |
| 1130 | * We are in a module using the module's TOC. |
| 1131 | * Switch to our TOC to run inside the core kernel. |
| 1132 | */ |
Steven Rostedt | be10ab1 | 2009-09-15 08:30:14 -0700 | [diff] [blame] | 1133 | ld r2, PACATOC(r13) |
Steven Rostedt | 6794c78 | 2009-02-09 21:10:27 -0800 | [diff] [blame] | 1134 | |
| 1135 | bl .ftrace_return_to_handler |
| 1136 | nop |
| 1137 | |
| 1138 | /* return value has real return address */ |
| 1139 | mtlr r3 |
| 1140 | |
| 1141 | ld r1, 0(r1) |
| 1142 | ld r4, -32(r1) |
| 1143 | ld r3, -24(r1) |
| 1144 | ld r2, -16(r1) |
| 1145 | ld r31, -8(r1) |
| 1146 | |
| 1147 | /* Jump back to real return address */ |
| 1148 | blr |
| 1149 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ |
| 1150 | #endif /* CONFIG_FUNCTION_TRACER */ |