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