Commit | Line | Data |
---|---|---|
9994a338 | 1 | /* |
9994a338 PM |
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 | ||
9994a338 | 21 | #include <linux/errno.h> |
c3525940 | 22 | #include <linux/err.h> |
9994a338 PM |
23 | #include <asm/unistd.h> |
24 | #include <asm/processor.h> | |
25 | #include <asm/page.h> | |
26 | #include <asm/mmu.h> | |
27 | #include <asm/thread_info.h> | |
28 | #include <asm/ppc_asm.h> | |
29 | #include <asm/asm-offsets.h> | |
30 | #include <asm/cputable.h> | |
3f639ee8 | 31 | #include <asm/firmware.h> |
007d88d0 | 32 | #include <asm/bug.h> |
ec2b36b9 | 33 | #include <asm/ptrace.h> |
945feb17 | 34 | #include <asm/irqflags.h> |
395a59d0 | 35 | #include <asm/ftrace.h> |
7230c564 | 36 | #include <asm/hw_irq.h> |
5d1c5745 | 37 | #include <asm/context_tracking.h> |
b4b56f9e | 38 | #include <asm/tm.h> |
9994a338 PM |
39 | |
40 | /* | |
41 | * System calls. | |
42 | */ | |
43 | .section ".toc","aw" | |
c857c43b AB |
44 | SYS_CALL_TABLE: |
45 | .tc sys_call_table[TC],sys_call_table | |
9994a338 PM |
46 | |
47 | /* This value is used to mark exception frames on the stack. */ | |
48 | exception_marker: | |
ec2b36b9 | 49 | .tc ID_EXC_MARKER[TC],STACK_FRAME_REGS_MARKER |
9994a338 PM |
50 | |
51 | .section ".text" | |
52 | .align 7 | |
53 | ||
9994a338 PM |
54 | .globl system_call_common |
55 | system_call_common: | |
b4b56f9e S |
56 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
57 | BEGIN_FTR_SECTION | |
58 | extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */ | |
59 | bne tabort_syscall | |
60 | END_FTR_SECTION_IFSET(CPU_FTR_TM) | |
61 | #endif | |
9994a338 PM |
62 | andi. r10,r12,MSR_PR |
63 | mr r10,r1 | |
64 | addi r1,r1,-INT_FRAME_SIZE | |
65 | beq- 1f | |
66 | ld r1,PACAKSAVE(r13) | |
67 | 1: std r10,0(r1) | |
68 | std r11,_NIP(r1) | |
69 | std r12,_MSR(r1) | |
70 | std r0,GPR0(r1) | |
71 | std r10,GPR1(r1) | |
5d75b264 | 72 | beq 2f /* if from kernel mode */ |
c6622f63 | 73 | ACCOUNT_CPU_USER_ENTRY(r10, r11) |
5d75b264 | 74 | 2: std r2,GPR2(r1) |
9994a338 | 75 | std r3,GPR3(r1) |
fd6c40f3 | 76 | mfcr r2 |
9994a338 PM |
77 | std r4,GPR4(r1) |
78 | std r5,GPR5(r1) | |
79 | std r6,GPR6(r1) | |
80 | std r7,GPR7(r1) | |
81 | std r8,GPR8(r1) | |
82 | li r11,0 | |
83 | std r11,GPR9(r1) | |
84 | std r11,GPR10(r1) | |
85 | std r11,GPR11(r1) | |
86 | std r11,GPR12(r1) | |
823df435 | 87 | std r11,_XER(r1) |
82087414 | 88 | std r11,_CTR(r1) |
9994a338 | 89 | std r9,GPR13(r1) |
9994a338 | 90 | mflr r10 |
fd6c40f3 AB |
91 | /* |
92 | * This clears CR0.SO (bit 28), which is the error indication on | |
93 | * return from this system call. | |
94 | */ | |
95 | rldimi r2,r11,28,(63-28) | |
9994a338 | 96 | li r11,0xc01 |
9994a338 PM |
97 | std r10,_LINK(r1) |
98 | std r11,_TRAP(r1) | |
9994a338 | 99 | std r3,ORIG_GPR3(r1) |
fd6c40f3 | 100 | std r2,_CCR(r1) |
9994a338 PM |
101 | ld r2,PACATOC(r13) |
102 | addi r9,r1,STACK_FRAME_OVERHEAD | |
103 | ld r11,exception_marker@toc(r2) | |
104 | std r11,-16(r9) /* "regshere" marker */ | |
abf917cd | 105 | #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR) |
cf9efce0 PM |
106 | BEGIN_FW_FTR_SECTION |
107 | beq 33f | |
108 | /* if from user, see if there are any DTL entries to process */ | |
109 | ld r10,PACALPPACAPTR(r13) /* get ptr to VPA */ | |
110 | ld r11,PACA_DTL_RIDX(r13) /* get log read index */ | |
7ffcf8ec AB |
111 | addi r10,r10,LPPACA_DTLIDX |
112 | LDX_BE r10,0,r10 /* get log write index */ | |
cf9efce0 PM |
113 | cmpd cr1,r11,r10 |
114 | beq+ cr1,33f | |
b1576fec | 115 | bl accumulate_stolen_time |
cf9efce0 PM |
116 | REST_GPR(0,r1) |
117 | REST_4GPRS(3,r1) | |
118 | REST_2GPRS(7,r1) | |
119 | addi r9,r1,STACK_FRAME_OVERHEAD | |
120 | 33: | |
121 | END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR) | |
abf917cd | 122 | #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE && CONFIG_PPC_SPLPAR */ |
cf9efce0 | 123 | |
1421ae0b BH |
124 | /* |
125 | * A syscall should always be called with interrupts enabled | |
126 | * so we just unconditionally hard-enable here. When some kind | |
127 | * of irq tracing is used, we additionally check that condition | |
128 | * is correct | |
129 | */ | |
130 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_BUG) | |
131 | lbz r10,PACASOFTIRQEN(r13) | |
132 | xori r10,r10,1 | |
133 | 1: tdnei r10,0 | |
134 | EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING | |
135 | #endif | |
2d27cfd3 | 136 | |
2d27cfd3 BH |
137 | #ifdef CONFIG_PPC_BOOK3E |
138 | wrteei 1 | |
139 | #else | |
1421ae0b | 140 | ld r11,PACAKMSR(r13) |
9994a338 PM |
141 | ori r11,r11,MSR_EE |
142 | mtmsrd r11,1 | |
2d27cfd3 | 143 | #endif /* CONFIG_PPC_BOOK3E */ |
9994a338 | 144 | |
1421ae0b BH |
145 | /* We do need to set SOFTE in the stack frame or the return |
146 | * from interrupt will be painful | |
147 | */ | |
148 | li r10,1 | |
149 | std r10,SOFTE(r1) | |
150 | ||
9778b696 | 151 | CURRENT_THREAD_INFO(r11, r1) |
9994a338 | 152 | ld r10,TI_FLAGS(r11) |
10ea8343 | 153 | andi. r11,r10,_TIF_SYSCALL_DOTRACE |
d3837414 | 154 | bne syscall_dotrace /* does not return */ |
9994a338 PM |
155 | cmpldi 0,r0,NR_syscalls |
156 | bge- syscall_enosys | |
157 | ||
158 | system_call: /* label this so stack traces look sane */ | |
159 | /* | |
160 | * Need to vector to 32 Bit or default sys_call_table here, | |
161 | * based on caller's run-mode / personality. | |
162 | */ | |
c857c43b | 163 | ld r11,SYS_CALL_TABLE@toc(2) |
9994a338 PM |
164 | andi. r10,r10,_TIF_32BIT |
165 | beq 15f | |
166 | addi r11,r11,8 /* use 32-bit syscall entries */ | |
167 | clrldi r3,r3,32 | |
168 | clrldi r4,r4,32 | |
169 | clrldi r5,r5,32 | |
170 | clrldi r6,r6,32 | |
171 | clrldi r7,r7,32 | |
172 | clrldi r8,r8,32 | |
173 | 15: | |
174 | slwi r0,r0,4 | |
cc7efbf9 AB |
175 | ldx r12,r11,r0 /* Fetch system call handler [ptr] */ |
176 | mtctr r12 | |
9994a338 PM |
177 | bctrl /* Call handler */ |
178 | ||
4c3b2168 | 179 | .Lsyscall_exit: |
401d1f02 | 180 | std r3,RESULT(r1) |
9778b696 | 181 | CURRENT_THREAD_INFO(r12, r1) |
9994a338 | 182 | |
9994a338 | 183 | ld r8,_MSR(r1) |
2d27cfd3 BH |
184 | #ifdef CONFIG_PPC_BOOK3S |
185 | /* No MSR:RI on BookE */ | |
9994a338 PM |
186 | andi. r10,r8,MSR_RI |
187 | beq- unrecov_restore | |
2d27cfd3 | 188 | #endif |
1421ae0b BH |
189 | /* |
190 | * Disable interrupts so current_thread_info()->flags can't change, | |
2d27cfd3 BH |
191 | * and so that we don't get interrupted after loading SRR0/1. |
192 | */ | |
193 | #ifdef CONFIG_PPC_BOOK3E | |
194 | wrteei 0 | |
195 | #else | |
1421ae0b | 196 | ld r10,PACAKMSR(r13) |
ac1dc365 AB |
197 | /* |
198 | * For performance reasons we clear RI the same time that we | |
199 | * clear EE. We only need to clear RI just before we restore r13 | |
200 | * below, but batching it with EE saves us one expensive mtmsrd call. | |
201 | * We have to be careful to restore RI if we branch anywhere from | |
202 | * here (eg syscall_exit_work). | |
203 | */ | |
204 | li r9,MSR_RI | |
205 | andc r11,r10,r9 | |
206 | mtmsrd r11,1 | |
2d27cfd3 BH |
207 | #endif /* CONFIG_PPC_BOOK3E */ |
208 | ||
9994a338 | 209 | ld r9,TI_FLAGS(r12) |
c3525940 | 210 | li r11,-MAX_ERRNO |
10ea8343 | 211 | andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) |
9994a338 | 212 | bne- syscall_exit_work |
401d1f02 DW |
213 | cmpld r3,r11 |
214 | ld r5,_CCR(r1) | |
215 | bge- syscall_error | |
d14299de | 216 | .Lsyscall_error_cont: |
9994a338 | 217 | ld r7,_NIP(r1) |
f89451fb | 218 | BEGIN_FTR_SECTION |
9994a338 | 219 | stdcx. r0,0,r1 /* to clear the reservation */ |
f89451fb | 220 | END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) |
9994a338 PM |
221 | andi. r6,r8,MSR_PR |
222 | ld r4,_LINK(r1) | |
2d27cfd3 | 223 | |
c6622f63 PM |
224 | beq- 1f |
225 | ACCOUNT_CPU_USER_EXIT(r11, r12) | |
44e9309f | 226 | HMT_MEDIUM_LOW_HAS_PPR |
c6622f63 | 227 | ld r13,GPR13(r1) /* only restore r13 if returning to usermode */ |
9994a338 | 228 | 1: ld r2,GPR2(r1) |
9994a338 PM |
229 | ld r1,GPR1(r1) |
230 | mtlr r4 | |
231 | mtcr r5 | |
232 | mtspr SPRN_SRR0,r7 | |
233 | mtspr SPRN_SRR1,r8 | |
2d27cfd3 | 234 | RFI |
9994a338 PM |
235 | b . /* prevent speculative execution */ |
236 | ||
401d1f02 | 237 | syscall_error: |
9994a338 | 238 | oris r5,r5,0x1000 /* Set SO bit in CR */ |
401d1f02 | 239 | neg r3,r3 |
9994a338 | 240 | std r5,_CCR(r1) |
d14299de | 241 | b .Lsyscall_error_cont |
401d1f02 | 242 | |
9994a338 PM |
243 | /* Traced system call support */ |
244 | syscall_dotrace: | |
b1576fec | 245 | bl save_nvgprs |
9994a338 | 246 | addi r3,r1,STACK_FRAME_OVERHEAD |
b1576fec | 247 | bl do_syscall_trace_enter |
d3837414 | 248 | |
4f72c427 | 249 | /* |
d3837414 ME |
250 | * We use the return value of do_syscall_trace_enter() as the syscall |
251 | * number. If the syscall was rejected for any reason do_syscall_trace_enter() | |
252 | * returns an invalid syscall number and the test below against | |
253 | * NR_syscalls will fail. | |
4f72c427 RM |
254 | */ |
255 | mr r0,r3 | |
d3837414 ME |
256 | |
257 | /* Restore argument registers just clobbered and/or possibly changed. */ | |
9994a338 PM |
258 | ld r3,GPR3(r1) |
259 | ld r4,GPR4(r1) | |
260 | ld r5,GPR5(r1) | |
261 | ld r6,GPR6(r1) | |
262 | ld r7,GPR7(r1) | |
263 | ld r8,GPR8(r1) | |
d3837414 ME |
264 | |
265 | /* Repopulate r9 and r10 for the system_call path */ | |
9994a338 | 266 | addi r9,r1,STACK_FRAME_OVERHEAD |
9778b696 | 267 | CURRENT_THREAD_INFO(r10, r1) |
9994a338 | 268 | ld r10,TI_FLAGS(r10) |
d3837414 ME |
269 | |
270 | cmpldi r0,NR_syscalls | |
271 | blt+ system_call | |
272 | ||
273 | /* Return code is already in r3 thanks to do_syscall_trace_enter() */ | |
274 | b .Lsyscall_exit | |
275 | ||
9994a338 | 276 | |
401d1f02 DW |
277 | syscall_enosys: |
278 | li r3,-ENOSYS | |
4c3b2168 | 279 | b .Lsyscall_exit |
401d1f02 DW |
280 | |
281 | syscall_exit_work: | |
ac1dc365 AB |
282 | #ifdef CONFIG_PPC_BOOK3S |
283 | mtmsrd r10,1 /* Restore RI */ | |
284 | #endif | |
401d1f02 DW |
285 | /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr. |
286 | If TIF_NOERROR is set, just save r3 as it is. */ | |
287 | ||
288 | andi. r0,r9,_TIF_RESTOREALL | |
1bd79336 PM |
289 | beq+ 0f |
290 | REST_NVGPRS(r1) | |
291 | b 2f | |
c3525940 | 292 | 0: cmpld r3,r11 /* r11 is -MAX_ERRNO */ |
401d1f02 DW |
293 | blt+ 1f |
294 | andi. r0,r9,_TIF_NOERROR | |
295 | bne- 1f | |
296 | ld r5,_CCR(r1) | |
297 | neg r3,r3 | |
298 | oris r5,r5,0x1000 /* Set SO bit in CR */ | |
299 | std r5,_CCR(r1) | |
300 | 1: std r3,GPR3(r1) | |
301 | 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK) | |
302 | beq 4f | |
303 | ||
1bd79336 | 304 | /* Clear per-syscall TIF flags if any are set. */ |
401d1f02 DW |
305 | |
306 | li r11,_TIF_PERSYSCALL_MASK | |
307 | addi r12,r12,TI_FLAGS | |
308 | 3: ldarx r10,0,r12 | |
309 | andc r10,r10,r11 | |
310 | stdcx. r10,0,r12 | |
311 | bne- 3b | |
312 | subi r12,r12,TI_FLAGS | |
1bd79336 PM |
313 | |
314 | 4: /* Anything else left to do? */ | |
05e38e5d | 315 | SET_DEFAULT_THREAD_PPR(r3, r10) /* Set thread.ppr = 3 */ |
10ea8343 | 316 | andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP) |
b1576fec | 317 | beq ret_from_except_lite |
401d1f02 DW |
318 | |
319 | /* Re-enable interrupts */ | |
2d27cfd3 BH |
320 | #ifdef CONFIG_PPC_BOOK3E |
321 | wrteei 1 | |
322 | #else | |
1421ae0b | 323 | ld r10,PACAKMSR(r13) |
401d1f02 DW |
324 | ori r10,r10,MSR_EE |
325 | mtmsrd r10,1 | |
2d27cfd3 | 326 | #endif /* CONFIG_PPC_BOOK3E */ |
401d1f02 | 327 | |
b1576fec | 328 | bl save_nvgprs |
9994a338 | 329 | addi r3,r1,STACK_FRAME_OVERHEAD |
b1576fec AB |
330 | bl do_syscall_trace_leave |
331 | b ret_from_except | |
9994a338 | 332 | |
b4b56f9e S |
333 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
334 | tabort_syscall: | |
335 | /* Firstly we need to enable TM in the kernel */ | |
336 | mfmsr r10 | |
337 | li r13, 1 | |
338 | rldimi r10, r13, MSR_TM_LG, 63-MSR_TM_LG | |
339 | mtmsrd r10, 0 | |
340 | ||
341 | /* tabort, this dooms the transaction, nothing else */ | |
342 | li r13, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT) | |
343 | TABORT(R13) | |
344 | ||
345 | /* | |
346 | * Return directly to userspace. We have corrupted user register state, | |
347 | * but userspace will never see that register state. Execution will | |
348 | * resume after the tbegin of the aborted transaction with the | |
349 | * checkpointed register state. | |
350 | */ | |
351 | li r13, MSR_RI | |
352 | andc r10, r10, r13 | |
353 | mtmsrd r10, 1 | |
354 | mtspr SPRN_SRR0, r11 | |
355 | mtspr SPRN_SRR1, r12 | |
356 | ||
357 | rfid | |
358 | b . /* prevent speculative execution */ | |
359 | #endif | |
360 | ||
9994a338 PM |
361 | /* Save non-volatile GPRs, if not already saved. */ |
362 | _GLOBAL(save_nvgprs) | |
363 | ld r11,_TRAP(r1) | |
364 | andi. r0,r11,1 | |
365 | beqlr- | |
366 | SAVE_NVGPRS(r1) | |
367 | clrrdi r0,r11,1 | |
368 | std r0,_TRAP(r1) | |
369 | blr | |
370 | ||
401d1f02 | 371 | |
9994a338 PM |
372 | /* |
373 | * The sigsuspend and rt_sigsuspend system calls can call do_signal | |
374 | * and thus put the process into the stopped state where we might | |
375 | * want to examine its user state with ptrace. Therefore we need | |
376 | * to save all the nonvolatile registers (r14 - r31) before calling | |
377 | * the C code. Similarly, fork, vfork and clone need the full | |
378 | * register state on the stack so that it can be copied to the child. | |
379 | */ | |
9994a338 PM |
380 | |
381 | _GLOBAL(ppc_fork) | |
b1576fec AB |
382 | bl save_nvgprs |
383 | bl sys_fork | |
4c3b2168 | 384 | b .Lsyscall_exit |
9994a338 PM |
385 | |
386 | _GLOBAL(ppc_vfork) | |
b1576fec AB |
387 | bl save_nvgprs |
388 | bl sys_vfork | |
4c3b2168 | 389 | b .Lsyscall_exit |
9994a338 PM |
390 | |
391 | _GLOBAL(ppc_clone) | |
b1576fec AB |
392 | bl save_nvgprs |
393 | bl sys_clone | |
4c3b2168 | 394 | b .Lsyscall_exit |
9994a338 | 395 | |
1bd79336 | 396 | _GLOBAL(ppc32_swapcontext) |
b1576fec AB |
397 | bl save_nvgprs |
398 | bl compat_sys_swapcontext | |
4c3b2168 | 399 | b .Lsyscall_exit |
1bd79336 PM |
400 | |
401 | _GLOBAL(ppc64_swapcontext) | |
b1576fec AB |
402 | bl save_nvgprs |
403 | bl sys_swapcontext | |
4c3b2168 | 404 | b .Lsyscall_exit |
1bd79336 | 405 | |
529d235a ME |
406 | _GLOBAL(ppc_switch_endian) |
407 | bl save_nvgprs | |
408 | bl sys_switch_endian | |
409 | b .Lsyscall_exit | |
410 | ||
9994a338 | 411 | _GLOBAL(ret_from_fork) |
b1576fec | 412 | bl schedule_tail |
9994a338 PM |
413 | REST_NVGPRS(r1) |
414 | li r3,0 | |
4c3b2168 | 415 | b .Lsyscall_exit |
9994a338 | 416 | |
58254e10 | 417 | _GLOBAL(ret_from_kernel_thread) |
b1576fec | 418 | bl schedule_tail |
58254e10 | 419 | REST_NVGPRS(r1) |
58254e10 AV |
420 | mtlr r14 |
421 | mr r3,r15 | |
7cedd601 AB |
422 | #if defined(_CALL_ELF) && _CALL_ELF == 2 |
423 | mr r12,r14 | |
424 | #endif | |
58254e10 AV |
425 | blrl |
426 | li r3,0 | |
4c3b2168 | 427 | b .Lsyscall_exit |
be6abfa7 | 428 | |
9994a338 PM |
429 | /* |
430 | * This routine switches between two different tasks. The process | |
431 | * state of one is saved on its kernel stack. Then the state | |
432 | * of the other is restored from its kernel stack. The memory | |
433 | * management hardware is updated to the second process's state. | |
434 | * Finally, we can return to the second process, via ret_from_except. | |
435 | * On entry, r3 points to the THREAD for the current task, r4 | |
436 | * points to the THREAD for the new task. | |
437 | * | |
438 | * Note: there are two ways to get to the "going out" portion | |
439 | * of this code; either by coming in via the entry (_switch) | |
440 | * or via "fork" which must set up an environment equivalent | |
441 | * to the "_switch" path. If you change this you'll have to change | |
442 | * the fork code also. | |
443 | * | |
444 | * The code which creates the new task context is in 'copy_thread' | |
2ef9481e | 445 | * in arch/powerpc/kernel/process.c |
9994a338 PM |
446 | */ |
447 | .align 7 | |
448 | _GLOBAL(_switch) | |
449 | mflr r0 | |
450 | std r0,16(r1) | |
451 | stdu r1,-SWITCH_FRAME_SIZE(r1) | |
452 | /* r3-r13 are caller saved -- Cort */ | |
453 | SAVE_8GPRS(14, r1) | |
454 | SAVE_10GPRS(22, r1) | |
68bfa962 | 455 | std r0,_NIP(r1) /* Return to switch caller */ |
9994a338 PM |
456 | mfcr r23 |
457 | std r23,_CCR(r1) | |
458 | std r1,KSP(r3) /* Set old stack pointer */ | |
459 | ||
460 | #ifdef CONFIG_SMP | |
461 | /* We need a sync somewhere here to make sure that if the | |
462 | * previous task gets rescheduled on another CPU, it sees all | |
463 | * stores it has performed on this one. | |
464 | */ | |
465 | sync | |
466 | #endif /* CONFIG_SMP */ | |
467 | ||
f89451fb AB |
468 | /* |
469 | * If we optimise away the clear of the reservation in system | |
470 | * calls because we know the CPU tracks the address of the | |
471 | * reservation, then we need to clear it here to cover the | |
472 | * case that the kernel context switch path has no larx | |
473 | * instructions. | |
474 | */ | |
475 | BEGIN_FTR_SECTION | |
476 | ldarx r6,0,r1 | |
477 | END_FTR_SECTION_IFSET(CPU_FTR_STCX_CHECKS_ADDRESS) | |
478 | ||
a515348f MN |
479 | #ifdef CONFIG_PPC_BOOK3S |
480 | /* Cancel all explict user streams as they will have no use after context | |
481 | * switch and will stop the HW from creating streams itself | |
482 | */ | |
483 | DCBT_STOP_ALL_STREAM_IDS(r6) | |
484 | #endif | |
485 | ||
9994a338 PM |
486 | addi r6,r4,-THREAD /* Convert THREAD to 'current' */ |
487 | std r6,PACACURRENT(r13) /* Set new 'current' */ | |
488 | ||
489 | ld r8,KSP(r4) /* new stack pointer */ | |
2d27cfd3 | 490 | #ifdef CONFIG_PPC_BOOK3S |
1189be65 | 491 | BEGIN_FTR_SECTION |
9994a338 PM |
492 | clrrdi r6,r8,28 /* get its ESID */ |
493 | clrrdi r9,r1,28 /* get current sp ESID */ | |
13b3d13b | 494 | FTR_SECTION_ELSE |
1189be65 PM |
495 | clrrdi r6,r8,40 /* get its 1T ESID */ |
496 | clrrdi r9,r1,40 /* get current sp 1T ESID */ | |
13b3d13b | 497 | ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_1T_SEGMENT) |
9994a338 PM |
498 | clrldi. r0,r6,2 /* is new ESID c00000000? */ |
499 | cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */ | |
500 | cror eq,4*cr1+eq,eq | |
501 | beq 2f /* if yes, don't slbie it */ | |
502 | ||
503 | /* Bolt in the new stack SLB entry */ | |
504 | ld r7,KSP_VSID(r4) /* Get new stack's VSID */ | |
505 | oris r0,r6,(SLB_ESID_V)@h | |
506 | ori r0,r0,(SLB_NUM_BOLTED-1)@l | |
1189be65 PM |
507 | BEGIN_FTR_SECTION |
508 | li r9,MMU_SEGSIZE_1T /* insert B field */ | |
509 | oris r6,r6,(MMU_SEGSIZE_1T << SLBIE_SSIZE_SHIFT)@h | |
510 | rldimi r7,r9,SLB_VSID_SSIZE_SHIFT,0 | |
44ae3ab3 | 511 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT) |
2f6093c8 | 512 | |
00efee7d MN |
513 | /* Update the last bolted SLB. No write barriers are needed |
514 | * here, provided we only update the current CPU's SLB shadow | |
515 | * buffer. | |
516 | */ | |
2f6093c8 | 517 | ld r9,PACA_SLBSHADOWPTR(r13) |
11a27ad7 | 518 | li r12,0 |
7ffcf8ec AB |
519 | std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */ |
520 | li r12,SLBSHADOW_STACKVSID | |
521 | STDX_BE r7,r12,r9 /* Save VSID */ | |
522 | li r12,SLBSHADOW_STACKESID | |
523 | STDX_BE r0,r12,r9 /* Save ESID */ | |
2f6093c8 | 524 | |
44ae3ab3 | 525 | /* No need to check for MMU_FTR_NO_SLBIE_B here, since when |
f66bce5e OJ |
526 | * we have 1TB segments, the only CPUs known to have the errata |
527 | * only support less than 1TB of system memory and we'll never | |
528 | * actually hit this code path. | |
529 | */ | |
530 | ||
9994a338 PM |
531 | slbie r6 |
532 | slbie r6 /* Workaround POWER5 < DD2.1 issue */ | |
533 | slbmte r7,r0 | |
534 | isync | |
9994a338 | 535 | 2: |
2d27cfd3 BH |
536 | #endif /* !CONFIG_PPC_BOOK3S */ |
537 | ||
9778b696 | 538 | CURRENT_THREAD_INFO(r7, r8) /* base of new stack */ |
9994a338 PM |
539 | /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE |
540 | because we don't need to leave the 288-byte ABI gap at the | |
541 | top of the kernel stack. */ | |
542 | addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE | |
543 | ||
544 | mr r1,r8 /* start using new stack pointer */ | |
545 | std r7,PACAKSAVE(r13) | |
546 | ||
71433285 AB |
547 | ld r6,_CCR(r1) |
548 | mtcrf 0xFF,r6 | |
549 | ||
9994a338 PM |
550 | /* r3-r13 are destroyed -- Cort */ |
551 | REST_8GPRS(14, r1) | |
552 | REST_10GPRS(22, r1) | |
553 | ||
554 | /* convert old thread to its task_struct for return value */ | |
555 | addi r3,r3,-THREAD | |
556 | ld r7,_NIP(r1) /* Return to _switch caller in new task */ | |
557 | mtlr r7 | |
558 | addi r1,r1,SWITCH_FRAME_SIZE | |
559 | blr | |
560 | ||
561 | .align 7 | |
562 | _GLOBAL(ret_from_except) | |
563 | ld r11,_TRAP(r1) | |
564 | andi. r0,r11,1 | |
b1576fec | 565 | bne ret_from_except_lite |
9994a338 PM |
566 | REST_NVGPRS(r1) |
567 | ||
568 | _GLOBAL(ret_from_except_lite) | |
569 | /* | |
570 | * Disable interrupts so that current_thread_info()->flags | |
571 | * can't change between when we test it and when we return | |
572 | * from the interrupt. | |
573 | */ | |
2d27cfd3 BH |
574 | #ifdef CONFIG_PPC_BOOK3E |
575 | wrteei 0 | |
576 | #else | |
d9ada91a BH |
577 | ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */ |
578 | mtmsrd r10,1 /* Update machine state */ | |
2d27cfd3 | 579 | #endif /* CONFIG_PPC_BOOK3E */ |
9994a338 | 580 | |
9778b696 | 581 | CURRENT_THREAD_INFO(r9, r1) |
9994a338 | 582 | ld r3,_MSR(r1) |
13d543cd BB |
583 | #ifdef CONFIG_PPC_BOOK3E |
584 | ld r10,PACACURRENT(r13) | |
585 | #endif /* CONFIG_PPC_BOOK3E */ | |
9994a338 | 586 | ld r4,TI_FLAGS(r9) |
9994a338 | 587 | andi. r3,r3,MSR_PR |
c58ce2b1 | 588 | beq resume_kernel |
13d543cd BB |
589 | #ifdef CONFIG_PPC_BOOK3E |
590 | lwz r3,(THREAD+THREAD_DBCR0)(r10) | |
591 | #endif /* CONFIG_PPC_BOOK3E */ | |
9994a338 PM |
592 | |
593 | /* Check current_thread_info()->flags */ | |
c58ce2b1 | 594 | andi. r0,r4,_TIF_USER_WORK_MASK |
13d543cd BB |
595 | #ifdef CONFIG_PPC_BOOK3E |
596 | bne 1f | |
597 | /* | |
598 | * Check to see if the dbcr0 register is set up to debug. | |
599 | * Use the internal debug mode bit to do this. | |
600 | */ | |
601 | andis. r0,r3,DBCR0_IDM@h | |
c58ce2b1 | 602 | beq restore |
13d543cd BB |
603 | mfmsr r0 |
604 | rlwinm r0,r0,0,~MSR_DE /* Clear MSR.DE */ | |
605 | mtmsr r0 | |
606 | mtspr SPRN_DBCR0,r3 | |
607 | li r10, -1 | |
608 | mtspr SPRN_DBSR,r10 | |
609 | b restore | |
610 | #else | |
611 | beq restore | |
612 | #endif | |
613 | 1: andi. r0,r4,_TIF_NEED_RESCHED | |
614 | beq 2f | |
b1576fec | 615 | bl restore_interrupts |
5d1c5745 | 616 | SCHEDULE_USER |
b1576fec | 617 | b ret_from_except_lite |
d31626f7 PM |
618 | 2: |
619 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM | |
620 | andi. r0,r4,_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM | |
621 | bne 3f /* only restore TM if nothing else to do */ | |
622 | addi r3,r1,STACK_FRAME_OVERHEAD | |
b1576fec | 623 | bl restore_tm_state |
d31626f7 PM |
624 | b restore |
625 | 3: | |
626 | #endif | |
b1576fec | 627 | bl save_nvgprs |
808be314 AB |
628 | /* |
629 | * Use a non volatile GPR to save and restore our thread_info flags | |
630 | * across the call to restore_interrupts. | |
631 | */ | |
632 | mr r30,r4 | |
b1576fec | 633 | bl restore_interrupts |
808be314 | 634 | mr r4,r30 |
c58ce2b1 | 635 | addi r3,r1,STACK_FRAME_OVERHEAD |
b1576fec AB |
636 | bl do_notify_resume |
637 | b ret_from_except | |
c58ce2b1 TC |
638 | |
639 | resume_kernel: | |
a9c4e541 | 640 | /* check current_thread_info, _TIF_EMULATE_STACK_STORE */ |
0edfdd10 | 641 | andis. r8,r4,_TIF_EMULATE_STACK_STORE@h |
a9c4e541 TC |
642 | beq+ 1f |
643 | ||
644 | addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */ | |
645 | ||
646 | lwz r3,GPR1(r1) | |
647 | subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */ | |
648 | mr r4,r1 /* src: current exception frame */ | |
649 | mr r1,r3 /* Reroute the trampoline frame to r1 */ | |
650 | ||
651 | /* Copy from the original to the trampoline. */ | |
652 | li r5,INT_FRAME_SIZE/8 /* size: INT_FRAME_SIZE */ | |
653 | li r6,0 /* start offset: 0 */ | |
654 | mtctr r5 | |
655 | 2: ldx r0,r6,r4 | |
656 | stdx r0,r6,r3 | |
657 | addi r6,r6,8 | |
658 | bdnz 2b | |
659 | ||
660 | /* Do real store operation to complete stwu */ | |
661 | lwz r5,GPR1(r1) | |
662 | std r8,0(r5) | |
663 | ||
664 | /* Clear _TIF_EMULATE_STACK_STORE flag */ | |
665 | lis r11,_TIF_EMULATE_STACK_STORE@h | |
666 | addi r5,r9,TI_FLAGS | |
d8b92292 | 667 | 0: ldarx r4,0,r5 |
a9c4e541 TC |
668 | andc r4,r4,r11 |
669 | stdcx. r4,0,r5 | |
670 | bne- 0b | |
671 | 1: | |
672 | ||
c58ce2b1 TC |
673 | #ifdef CONFIG_PREEMPT |
674 | /* Check if we need to preempt */ | |
675 | andi. r0,r4,_TIF_NEED_RESCHED | |
676 | beq+ restore | |
677 | /* Check that preempt_count() == 0 and interrupts are enabled */ | |
678 | lwz r8,TI_PREEMPT(r9) | |
679 | cmpwi cr1,r8,0 | |
680 | ld r0,SOFTE(r1) | |
681 | cmpdi r0,0 | |
682 | crandc eq,cr1*4+eq,eq | |
683 | bne restore | |
684 | ||
685 | /* | |
686 | * Here we are preempting the current task. We want to make | |
de021bb7 | 687 | * sure we are soft-disabled first and reconcile irq state. |
c58ce2b1 | 688 | */ |
de021bb7 | 689 | RECONCILE_IRQ_STATE(r3,r4) |
b1576fec | 690 | 1: bl preempt_schedule_irq |
c58ce2b1 TC |
691 | |
692 | /* Re-test flags and eventually loop */ | |
9778b696 | 693 | CURRENT_THREAD_INFO(r9, r1) |
9994a338 | 694 | ld r4,TI_FLAGS(r9) |
c58ce2b1 TC |
695 | andi. r0,r4,_TIF_NEED_RESCHED |
696 | bne 1b | |
572177d7 TC |
697 | |
698 | /* | |
699 | * arch_local_irq_restore() from preempt_schedule_irq above may | |
700 | * enable hard interrupt but we really should disable interrupts | |
701 | * when we return from the interrupt, and so that we don't get | |
702 | * interrupted after loading SRR0/1. | |
703 | */ | |
704 | #ifdef CONFIG_PPC_BOOK3E | |
705 | wrteei 0 | |
706 | #else | |
707 | ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */ | |
708 | mtmsrd r10,1 /* Update machine state */ | |
709 | #endif /* CONFIG_PPC_BOOK3E */ | |
c58ce2b1 | 710 | #endif /* CONFIG_PREEMPT */ |
9994a338 | 711 | |
7230c564 BH |
712 | .globl fast_exc_return_irq |
713 | fast_exc_return_irq: | |
9994a338 | 714 | restore: |
7230c564 | 715 | /* |
7c0482e3 BH |
716 | * This is the main kernel exit path. First we check if we |
717 | * are about to re-enable interrupts | |
7230c564 | 718 | */ |
01f3880d | 719 | ld r5,SOFTE(r1) |
7230c564 | 720 | lbz r6,PACASOFTIRQEN(r13) |
7c0482e3 BH |
721 | cmpwi cr0,r5,0 |
722 | beq restore_irq_off | |
7230c564 | 723 | |
7c0482e3 BH |
724 | /* We are enabling, were we already enabled ? Yes, just return */ |
725 | cmpwi cr0,r6,1 | |
726 | beq cr0,do_restore | |
9994a338 | 727 | |
7c0482e3 | 728 | /* |
7230c564 BH |
729 | * We are about to soft-enable interrupts (we are hard disabled |
730 | * at this point). We check if there's anything that needs to | |
731 | * be replayed first. | |
732 | */ | |
733 | lbz r0,PACAIRQHAPPENED(r13) | |
734 | cmpwi cr0,r0,0 | |
735 | bne- restore_check_irq_replay | |
e56a6e20 | 736 | |
7230c564 BH |
737 | /* |
738 | * Get here when nothing happened while soft-disabled, just | |
739 | * soft-enable and move-on. We will hard-enable as a side | |
740 | * effect of rfi | |
741 | */ | |
742 | restore_no_replay: | |
743 | TRACE_ENABLE_INTS | |
744 | li r0,1 | |
745 | stb r0,PACASOFTIRQEN(r13); | |
746 | ||
747 | /* | |
748 | * Final return path. BookE is handled in a different file | |
749 | */ | |
7c0482e3 | 750 | do_restore: |
2d27cfd3 | 751 | #ifdef CONFIG_PPC_BOOK3E |
b1576fec | 752 | b exception_return_book3e |
2d27cfd3 | 753 | #else |
7230c564 BH |
754 | /* |
755 | * Clear the reservation. If we know the CPU tracks the address of | |
756 | * the reservation then we can potentially save some cycles and use | |
757 | * a larx. On POWER6 and POWER7 this is significantly faster. | |
758 | */ | |
759 | BEGIN_FTR_SECTION | |
760 | stdcx. r0,0,r1 /* to clear the reservation */ | |
761 | FTR_SECTION_ELSE | |
762 | ldarx r4,0,r1 | |
763 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS) | |
764 | ||
765 | /* | |
766 | * Some code path such as load_up_fpu or altivec return directly | |
767 | * here. They run entirely hard disabled and do not alter the | |
768 | * interrupt state. They also don't use lwarx/stwcx. and thus | |
769 | * are known not to leave dangling reservations. | |
770 | */ | |
771 | .globl fast_exception_return | |
772 | fast_exception_return: | |
773 | ld r3,_MSR(r1) | |
e56a6e20 PM |
774 | ld r4,_CTR(r1) |
775 | ld r0,_LINK(r1) | |
776 | mtctr r4 | |
777 | mtlr r0 | |
778 | ld r4,_XER(r1) | |
779 | mtspr SPRN_XER,r4 | |
780 | ||
781 | REST_8GPRS(5, r1) | |
782 | ||
9994a338 PM |
783 | andi. r0,r3,MSR_RI |
784 | beq- unrecov_restore | |
785 | ||
0c4888ef BH |
786 | /* Load PPR from thread struct before we clear MSR:RI */ |
787 | BEGIN_FTR_SECTION | |
788 | ld r2,PACACURRENT(r13) | |
789 | ld r2,TASKTHREADPPR(r2) | |
790 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) | |
791 | ||
e56a6e20 PM |
792 | /* |
793 | * Clear RI before restoring r13. If we are returning to | |
794 | * userspace and we take an exception after restoring r13, | |
795 | * we end up corrupting the userspace r13 value. | |
796 | */ | |
d9ada91a BH |
797 | ld r4,PACAKMSR(r13) /* Get kernel MSR without EE */ |
798 | andc r4,r4,r0 /* r0 contains MSR_RI here */ | |
e56a6e20 | 799 | mtmsrd r4,1 |
9994a338 | 800 | |
afc07701 MN |
801 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
802 | /* TM debug */ | |
803 | std r3, PACATMSCRATCH(r13) /* Stash returned-to MSR */ | |
804 | #endif | |
9994a338 PM |
805 | /* |
806 | * r13 is our per cpu area, only restore it if we are returning to | |
7230c564 BH |
807 | * userspace the value stored in the stack frame may belong to |
808 | * another CPU. | |
9994a338 | 809 | */ |
e56a6e20 | 810 | andi. r0,r3,MSR_PR |
9994a338 | 811 | beq 1f |
0c4888ef BH |
812 | BEGIN_FTR_SECTION |
813 | mtspr SPRN_PPR,r2 /* Restore PPR */ | |
814 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) | |
e56a6e20 | 815 | ACCOUNT_CPU_USER_EXIT(r2, r4) |
9994a338 PM |
816 | REST_GPR(13, r1) |
817 | 1: | |
e56a6e20 | 818 | mtspr SPRN_SRR1,r3 |
9994a338 PM |
819 | |
820 | ld r2,_CCR(r1) | |
821 | mtcrf 0xFF,r2 | |
822 | ld r2,_NIP(r1) | |
823 | mtspr SPRN_SRR0,r2 | |
824 | ||
825 | ld r0,GPR0(r1) | |
826 | ld r2,GPR2(r1) | |
827 | ld r3,GPR3(r1) | |
828 | ld r4,GPR4(r1) | |
829 | ld r1,GPR1(r1) | |
830 | ||
831 | rfid | |
832 | b . /* prevent speculative execution */ | |
833 | ||
2d27cfd3 BH |
834 | #endif /* CONFIG_PPC_BOOK3E */ |
835 | ||
7c0482e3 BH |
836 | /* |
837 | * We are returning to a context with interrupts soft disabled. | |
838 | * | |
839 | * However, we may also about to hard enable, so we need to | |
840 | * make sure that in this case, we also clear PACA_IRQ_HARD_DIS | |
841 | * or that bit can get out of sync and bad things will happen | |
842 | */ | |
843 | restore_irq_off: | |
844 | ld r3,_MSR(r1) | |
845 | lbz r7,PACAIRQHAPPENED(r13) | |
846 | andi. r0,r3,MSR_EE | |
847 | beq 1f | |
848 | rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS | |
849 | stb r7,PACAIRQHAPPENED(r13) | |
850 | 1: li r0,0 | |
851 | stb r0,PACASOFTIRQEN(r13); | |
852 | TRACE_DISABLE_INTS | |
853 | b do_restore | |
854 | ||
7230c564 BH |
855 | /* |
856 | * Something did happen, check if a re-emit is needed | |
857 | * (this also clears paca->irq_happened) | |
858 | */ | |
859 | restore_check_irq_replay: | |
860 | /* XXX: We could implement a fast path here where we check | |
861 | * for irq_happened being just 0x01, in which case we can | |
862 | * clear it and return. That means that we would potentially | |
863 | * miss a decrementer having wrapped all the way around. | |
864 | * | |
865 | * Still, this might be useful for things like hash_page | |
866 | */ | |
b1576fec | 867 | bl __check_irq_replay |
7230c564 BH |
868 | cmpwi cr0,r3,0 |
869 | beq restore_no_replay | |
870 | ||
871 | /* | |
872 | * We need to re-emit an interrupt. We do so by re-using our | |
873 | * existing exception frame. We first change the trap value, | |
874 | * but we need to ensure we preserve the low nibble of it | |
875 | */ | |
876 | ld r4,_TRAP(r1) | |
877 | clrldi r4,r4,60 | |
878 | or r4,r4,r3 | |
879 | std r4,_TRAP(r1) | |
880 | ||
881 | /* | |
882 | * Then find the right handler and call it. Interrupts are | |
883 | * still soft-disabled and we keep them that way. | |
884 | */ | |
885 | cmpwi cr0,r3,0x500 | |
886 | bne 1f | |
887 | addi r3,r1,STACK_FRAME_OVERHEAD; | |
b1576fec AB |
888 | bl do_IRQ |
889 | b ret_from_except | |
0869b6fd MS |
890 | 1: cmpwi cr0,r3,0xe60 |
891 | bne 1f | |
892 | addi r3,r1,STACK_FRAME_OVERHEAD; | |
893 | bl handle_hmi_exception | |
894 | b ret_from_except | |
7230c564 BH |
895 | 1: cmpwi cr0,r3,0x900 |
896 | bne 1f | |
897 | addi r3,r1,STACK_FRAME_OVERHEAD; | |
b1576fec AB |
898 | bl timer_interrupt |
899 | b ret_from_except | |
fe9e1d54 IM |
900 | #ifdef CONFIG_PPC_DOORBELL |
901 | 1: | |
7230c564 | 902 | #ifdef CONFIG_PPC_BOOK3E |
fe9e1d54 IM |
903 | cmpwi cr0,r3,0x280 |
904 | #else | |
905 | BEGIN_FTR_SECTION | |
906 | cmpwi cr0,r3,0xe80 | |
907 | FTR_SECTION_ELSE | |
908 | cmpwi cr0,r3,0xa00 | |
909 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) | |
910 | #endif /* CONFIG_PPC_BOOK3E */ | |
7230c564 BH |
911 | bne 1f |
912 | addi r3,r1,STACK_FRAME_OVERHEAD; | |
b1576fec AB |
913 | bl doorbell_exception |
914 | b ret_from_except | |
fe9e1d54 | 915 | #endif /* CONFIG_PPC_DOORBELL */ |
b1576fec | 916 | 1: b ret_from_except /* What else to do here ? */ |
7230c564 | 917 | |
9994a338 PM |
918 | unrecov_restore: |
919 | addi r3,r1,STACK_FRAME_OVERHEAD | |
b1576fec | 920 | bl unrecoverable_exception |
9994a338 PM |
921 | b unrecov_restore |
922 | ||
923 | #ifdef CONFIG_PPC_RTAS | |
924 | /* | |
925 | * On CHRP, the Run-Time Abstraction Services (RTAS) have to be | |
926 | * called with the MMU off. | |
927 | * | |
928 | * In addition, we need to be in 32b mode, at least for now. | |
929 | * | |
930 | * Note: r3 is an input parameter to rtas, so don't trash it... | |
931 | */ | |
932 | _GLOBAL(enter_rtas) | |
933 | mflr r0 | |
934 | std r0,16(r1) | |
935 | stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */ | |
936 | ||
937 | /* Because RTAS is running in 32b mode, it clobbers the high order half | |
938 | * of all registers that it saves. We therefore save those registers | |
939 | * RTAS might touch to the stack. (r0, r3-r13 are caller saved) | |
940 | */ | |
941 | SAVE_GPR(2, r1) /* Save the TOC */ | |
942 | SAVE_GPR(13, r1) /* Save paca */ | |
943 | SAVE_8GPRS(14, r1) /* Save the non-volatiles */ | |
944 | SAVE_10GPRS(22, r1) /* ditto */ | |
945 | ||
946 | mfcr r4 | |
947 | std r4,_CCR(r1) | |
948 | mfctr r5 | |
949 | std r5,_CTR(r1) | |
950 | mfspr r6,SPRN_XER | |
951 | std r6,_XER(r1) | |
952 | mfdar r7 | |
953 | std r7,_DAR(r1) | |
954 | mfdsisr r8 | |
955 | std r8,_DSISR(r1) | |
9994a338 | 956 | |
9fe901d1 MK |
957 | /* Temporary workaround to clear CR until RTAS can be modified to |
958 | * ignore all bits. | |
959 | */ | |
960 | li r0,0 | |
961 | mtcr r0 | |
962 | ||
007d88d0 | 963 | #ifdef CONFIG_BUG |
9994a338 PM |
964 | /* There is no way it is acceptable to get here with interrupts enabled, |
965 | * check it with the asm equivalent of WARN_ON | |
966 | */ | |
d04c56f7 | 967 | lbz r0,PACASOFTIRQEN(r13) |
9994a338 | 968 | 1: tdnei r0,0 |
007d88d0 DW |
969 | EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING |
970 | #endif | |
971 | ||
d04c56f7 PM |
972 | /* Hard-disable interrupts */ |
973 | mfmsr r6 | |
974 | rldicl r7,r6,48,1 | |
975 | rotldi r7,r7,16 | |
976 | mtmsrd r7,1 | |
977 | ||
9994a338 PM |
978 | /* Unfortunately, the stack pointer and the MSR are also clobbered, |
979 | * so they are saved in the PACA which allows us to restore | |
980 | * our original state after RTAS returns. | |
981 | */ | |
982 | std r1,PACAR1(r13) | |
983 | std r6,PACASAVEDMSR(r13) | |
984 | ||
985 | /* Setup our real return addr */ | |
ad0289e4 | 986 | LOAD_REG_ADDR(r4,rtas_return_loc) |
e58c3495 | 987 | clrldi r4,r4,2 /* convert to realmode address */ |
9994a338 PM |
988 | mtlr r4 |
989 | ||
990 | li r0,0 | |
991 | ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI | |
992 | andc r0,r6,r0 | |
993 | ||
994 | li r9,1 | |
995 | rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG) | |
5c0484e2 | 996 | ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI|MSR_LE |
9994a338 | 997 | andc r6,r0,r9 |
9994a338 PM |
998 | sync /* disable interrupts so SRR0/1 */ |
999 | mtmsrd r0 /* don't get trashed */ | |
1000 | ||
e58c3495 | 1001 | LOAD_REG_ADDR(r4, rtas) |
9994a338 PM |
1002 | ld r5,RTASENTRY(r4) /* get the rtas->entry value */ |
1003 | ld r4,RTASBASE(r4) /* get the rtas->base value */ | |
1004 | ||
1005 | mtspr SPRN_SRR0,r5 | |
1006 | mtspr SPRN_SRR1,r6 | |
1007 | rfid | |
1008 | b . /* prevent speculative execution */ | |
1009 | ||
ad0289e4 | 1010 | rtas_return_loc: |
5c0484e2 BH |
1011 | FIXUP_ENDIAN |
1012 | ||
9994a338 | 1013 | /* relocation is off at this point */ |
2dd60d79 | 1014 | GET_PACA(r4) |
e58c3495 | 1015 | clrldi r4,r4,2 /* convert to realmode address */ |
9994a338 | 1016 | |
e31aa453 PM |
1017 | bcl 20,31,$+4 |
1018 | 0: mflr r3 | |
ad0289e4 | 1019 | ld r3,(1f-0b)(r3) /* get &rtas_restore_regs */ |
e31aa453 | 1020 | |
9994a338 PM |
1021 | mfmsr r6 |
1022 | li r0,MSR_RI | |
1023 | andc r6,r6,r0 | |
1024 | sync | |
1025 | mtmsrd r6 | |
1026 | ||
1027 | ld r1,PACAR1(r4) /* Restore our SP */ | |
9994a338 PM |
1028 | ld r4,PACASAVEDMSR(r4) /* Restore our MSR */ |
1029 | ||
1030 | mtspr SPRN_SRR0,r3 | |
1031 | mtspr SPRN_SRR1,r4 | |
1032 | rfid | |
1033 | b . /* prevent speculative execution */ | |
1034 | ||
e31aa453 | 1035 | .align 3 |
ad0289e4 | 1036 | 1: .llong rtas_restore_regs |
e31aa453 | 1037 | |
ad0289e4 | 1038 | rtas_restore_regs: |
9994a338 PM |
1039 | /* relocation is on at this point */ |
1040 | REST_GPR(2, r1) /* Restore the TOC */ | |
1041 | REST_GPR(13, r1) /* Restore paca */ | |
1042 | REST_8GPRS(14, r1) /* Restore the non-volatiles */ | |
1043 | REST_10GPRS(22, r1) /* ditto */ | |
1044 | ||
2dd60d79 | 1045 | GET_PACA(r13) |
9994a338 PM |
1046 | |
1047 | ld r4,_CCR(r1) | |
1048 | mtcr r4 | |
1049 | ld r5,_CTR(r1) | |
1050 | mtctr r5 | |
1051 | ld r6,_XER(r1) | |
1052 | mtspr SPRN_XER,r6 | |
1053 | ld r7,_DAR(r1) | |
1054 | mtdar r7 | |
1055 | ld r8,_DSISR(r1) | |
1056 | mtdsisr r8 | |
9994a338 PM |
1057 | |
1058 | addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */ | |
1059 | ld r0,16(r1) /* get return address */ | |
1060 | ||
1061 | mtlr r0 | |
1062 | blr /* return to caller */ | |
1063 | ||
1064 | #endif /* CONFIG_PPC_RTAS */ | |
1065 | ||
9994a338 PM |
1066 | _GLOBAL(enter_prom) |
1067 | mflr r0 | |
1068 | std r0,16(r1) | |
1069 | stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */ | |
1070 | ||
1071 | /* Because PROM is running in 32b mode, it clobbers the high order half | |
1072 | * of all registers that it saves. We therefore save those registers | |
1073 | * PROM might touch to the stack. (r0, r3-r13 are caller saved) | |
1074 | */ | |
6c171994 | 1075 | SAVE_GPR(2, r1) |
9994a338 PM |
1076 | SAVE_GPR(13, r1) |
1077 | SAVE_8GPRS(14, r1) | |
1078 | SAVE_10GPRS(22, r1) | |
6c171994 | 1079 | mfcr r10 |
9994a338 | 1080 | mfmsr r11 |
6c171994 | 1081 | std r10,_CCR(r1) |
9994a338 PM |
1082 | std r11,_MSR(r1) |
1083 | ||
5c0484e2 BH |
1084 | /* Put PROM address in SRR0 */ |
1085 | mtsrr0 r4 | |
1086 | ||
1087 | /* Setup our trampoline return addr in LR */ | |
1088 | bcl 20,31,$+4 | |
1089 | 0: mflr r4 | |
1090 | addi r4,r4,(1f - 0b) | |
1091 | mtlr r4 | |
9994a338 | 1092 | |
5c0484e2 | 1093 | /* Prepare a 32-bit mode big endian MSR |
9994a338 | 1094 | */ |
2d27cfd3 BH |
1095 | #ifdef CONFIG_PPC_BOOK3E |
1096 | rlwinm r11,r11,0,1,31 | |
5c0484e2 BH |
1097 | mtsrr1 r11 |
1098 | rfi | |
2d27cfd3 | 1099 | #else /* CONFIG_PPC_BOOK3E */ |
5c0484e2 BH |
1100 | LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_ISF | MSR_LE) |
1101 | andc r11,r11,r12 | |
1102 | mtsrr1 r11 | |
1103 | rfid | |
2d27cfd3 | 1104 | #endif /* CONFIG_PPC_BOOK3E */ |
9994a338 | 1105 | |
5c0484e2 BH |
1106 | 1: /* Return from OF */ |
1107 | FIXUP_ENDIAN | |
9994a338 PM |
1108 | |
1109 | /* Just make sure that r1 top 32 bits didn't get | |
1110 | * corrupt by OF | |
1111 | */ | |
1112 | rldicl r1,r1,0,32 | |
1113 | ||
1114 | /* Restore the MSR (back to 64 bits) */ | |
1115 | ld r0,_MSR(r1) | |
6c171994 | 1116 | MTMSRD(r0) |
9994a338 PM |
1117 | isync |
1118 | ||
1119 | /* Restore other registers */ | |
1120 | REST_GPR(2, r1) | |
1121 | REST_GPR(13, r1) | |
1122 | REST_8GPRS(14, r1) | |
1123 | REST_10GPRS(22, r1) | |
1124 | ld r4,_CCR(r1) | |
1125 | mtcr r4 | |
9994a338 PM |
1126 | |
1127 | addi r1,r1,PROM_FRAME_SIZE | |
1128 | ld r0,16(r1) | |
1129 | mtlr r0 | |
1130 | blr | |
4e491d14 | 1131 | |
606576ce | 1132 | #ifdef CONFIG_FUNCTION_TRACER |
4e491d14 SR |
1133 | #ifdef CONFIG_DYNAMIC_FTRACE |
1134 | _GLOBAL(mcount) | |
1135 | _GLOBAL(_mcount) | |
4e491d14 SR |
1136 | blr |
1137 | ||
5e66684f | 1138 | _GLOBAL_TOC(ftrace_caller) |
4e491d14 SR |
1139 | /* Taken from output of objdump from lib64/glibc */ |
1140 | mflr r3 | |
1141 | ld r11, 0(r1) | |
1142 | stdu r1, -112(r1) | |
1143 | std r3, 128(r1) | |
1144 | ld r4, 16(r11) | |
395a59d0 | 1145 | subi r3, r3, MCOUNT_INSN_SIZE |
4e491d14 SR |
1146 | .globl ftrace_call |
1147 | ftrace_call: | |
1148 | bl ftrace_stub | |
1149 | nop | |
46542888 SR |
1150 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER |
1151 | .globl ftrace_graph_call | |
1152 | ftrace_graph_call: | |
1153 | b ftrace_graph_stub | |
1154 | _GLOBAL(ftrace_graph_stub) | |
1155 | #endif | |
4e491d14 SR |
1156 | ld r0, 128(r1) |
1157 | mtlr r0 | |
1158 | addi r1, r1, 112 | |
1159 | _GLOBAL(ftrace_stub) | |
1160 | blr | |
1161 | #else | |
5e66684f | 1162 | _GLOBAL_TOC(_mcount) |
4e491d14 SR |
1163 | /* Taken from output of objdump from lib64/glibc */ |
1164 | mflr r3 | |
1165 | ld r11, 0(r1) | |
1166 | stdu r1, -112(r1) | |
1167 | std r3, 128(r1) | |
1168 | ld r4, 16(r11) | |
1169 | ||
395a59d0 | 1170 | subi r3, r3, MCOUNT_INSN_SIZE |
4e491d14 SR |
1171 | LOAD_REG_ADDR(r5,ftrace_trace_function) |
1172 | ld r5,0(r5) | |
1173 | ld r5,0(r5) | |
1174 | mtctr r5 | |
1175 | bctrl | |
4e491d14 | 1176 | nop |
6794c782 SR |
1177 | |
1178 | ||
1179 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | |
1180 | b ftrace_graph_caller | |
1181 | #endif | |
4e491d14 SR |
1182 | ld r0, 128(r1) |
1183 | mtlr r0 | |
1184 | addi r1, r1, 112 | |
1185 | _GLOBAL(ftrace_stub) | |
1186 | blr | |
1187 | ||
6794c782 SR |
1188 | #endif /* CONFIG_DYNAMIC_FTRACE */ |
1189 | ||
1190 | #ifdef CONFIG_FUNCTION_GRAPH_TRACER | |
46542888 | 1191 | _GLOBAL(ftrace_graph_caller) |
6794c782 SR |
1192 | /* load r4 with local address */ |
1193 | ld r4, 128(r1) | |
1194 | subi r4, r4, MCOUNT_INSN_SIZE | |
1195 | ||
b3c18725 | 1196 | /* Grab the LR out of the caller stack frame */ |
6794c782 | 1197 | ld r11, 112(r1) |
b3c18725 | 1198 | ld r3, 16(r11) |
6794c782 | 1199 | |
b1576fec | 1200 | bl prepare_ftrace_return |
6794c782 SR |
1201 | nop |
1202 | ||
b3c18725 AB |
1203 | /* |
1204 | * prepare_ftrace_return gives us the address we divert to. | |
1205 | * Change the LR in the callers stack frame to this. | |
1206 | */ | |
1207 | ld r11, 112(r1) | |
1208 | std r3, 16(r11) | |
1209 | ||
6794c782 SR |
1210 | ld r0, 128(r1) |
1211 | mtlr r0 | |
1212 | addi r1, r1, 112 | |
1213 | blr | |
1214 | ||
1215 | _GLOBAL(return_to_handler) | |
1216 | /* need to save return values */ | |
1217 | std r4, -32(r1) | |
1218 | std r3, -24(r1) | |
1219 | /* save TOC */ | |
1220 | std r2, -16(r1) | |
1221 | std r31, -8(r1) | |
1222 | mr r31, r1 | |
1223 | stdu r1, -112(r1) | |
1224 | ||
bb725340 | 1225 | /* |
7d56c65a | 1226 | * We might be called from a module. |
bb725340 SR |
1227 | * Switch to our TOC to run inside the core kernel. |
1228 | */ | |
be10ab10 | 1229 | ld r2, PACATOC(r13) |
6794c782 | 1230 | |
b1576fec | 1231 | bl ftrace_return_to_handler |
6794c782 SR |
1232 | nop |
1233 | ||
1234 | /* return value has real return address */ | |
1235 | mtlr r3 | |
1236 | ||
1237 | ld r1, 0(r1) | |
1238 | ld r4, -32(r1) | |
1239 | ld r3, -24(r1) | |
1240 | ld r2, -16(r1) | |
1241 | ld r31, -8(r1) | |
1242 | ||
1243 | /* Jump back to real return address */ | |
1244 | blr | |
1245 | #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ | |
1246 | #endif /* CONFIG_FUNCTION_TRACER */ |