entry_64.S 28 KB

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