entry_64.S 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  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) && 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 && 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. /*
  709. * r13 is our per cpu area, only restore it if we are returning to
  710. * userspace the value stored in the stack frame may belong to
  711. * another CPU.
  712. */
  713. andi. r0,r3,MSR_PR
  714. beq 1f
  715. ACCOUNT_CPU_USER_EXIT(r2, r4)
  716. RESTORE_PPR(r2, r4)
  717. REST_GPR(13, r1)
  718. 1:
  719. mtspr SPRN_SRR1,r3
  720. ld r2,_CCR(r1)
  721. mtcrf 0xFF,r2
  722. ld r2,_NIP(r1)
  723. mtspr SPRN_SRR0,r2
  724. ld r0,GPR0(r1)
  725. ld r2,GPR2(r1)
  726. ld r3,GPR3(r1)
  727. ld r4,GPR4(r1)
  728. ld r1,GPR1(r1)
  729. rfid
  730. b . /* prevent speculative execution */
  731. #endif /* CONFIG_PPC_BOOK3E */
  732. /*
  733. * We are returning to a context with interrupts soft disabled.
  734. *
  735. * However, we may also about to hard enable, so we need to
  736. * make sure that in this case, we also clear PACA_IRQ_HARD_DIS
  737. * or that bit can get out of sync and bad things will happen
  738. */
  739. restore_irq_off:
  740. ld r3,_MSR(r1)
  741. lbz r7,PACAIRQHAPPENED(r13)
  742. andi. r0,r3,MSR_EE
  743. beq 1f
  744. rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS
  745. stb r7,PACAIRQHAPPENED(r13)
  746. 1: li r0,0
  747. stb r0,PACASOFTIRQEN(r13);
  748. TRACE_DISABLE_INTS
  749. b do_restore
  750. /*
  751. * Something did happen, check if a re-emit is needed
  752. * (this also clears paca->irq_happened)
  753. */
  754. restore_check_irq_replay:
  755. /* XXX: We could implement a fast path here where we check
  756. * for irq_happened being just 0x01, in which case we can
  757. * clear it and return. That means that we would potentially
  758. * miss a decrementer having wrapped all the way around.
  759. *
  760. * Still, this might be useful for things like hash_page
  761. */
  762. bl .__check_irq_replay
  763. cmpwi cr0,r3,0
  764. beq restore_no_replay
  765. /*
  766. * We need to re-emit an interrupt. We do so by re-using our
  767. * existing exception frame. We first change the trap value,
  768. * but we need to ensure we preserve the low nibble of it
  769. */
  770. ld r4,_TRAP(r1)
  771. clrldi r4,r4,60
  772. or r4,r4,r3
  773. std r4,_TRAP(r1)
  774. /*
  775. * Then find the right handler and call it. Interrupts are
  776. * still soft-disabled and we keep them that way.
  777. */
  778. cmpwi cr0,r3,0x500
  779. bne 1f
  780. addi r3,r1,STACK_FRAME_OVERHEAD;
  781. bl .do_IRQ
  782. b .ret_from_except
  783. 1: cmpwi cr0,r3,0x900
  784. bne 1f
  785. addi r3,r1,STACK_FRAME_OVERHEAD;
  786. bl .timer_interrupt
  787. b .ret_from_except
  788. #ifdef CONFIG_PPC_DOORBELL
  789. 1:
  790. #ifdef CONFIG_PPC_BOOK3E
  791. cmpwi cr0,r3,0x280
  792. #else
  793. BEGIN_FTR_SECTION
  794. cmpwi cr0,r3,0xe80
  795. FTR_SECTION_ELSE
  796. cmpwi cr0,r3,0xa00
  797. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  798. #endif /* CONFIG_PPC_BOOK3E */
  799. bne 1f
  800. addi r3,r1,STACK_FRAME_OVERHEAD;
  801. bl .doorbell_exception
  802. b .ret_from_except
  803. #endif /* CONFIG_PPC_DOORBELL */
  804. 1: b .ret_from_except /* What else to do here ? */
  805. unrecov_restore:
  806. addi r3,r1,STACK_FRAME_OVERHEAD
  807. bl .unrecoverable_exception
  808. b unrecov_restore
  809. #ifdef CONFIG_PPC_RTAS
  810. /*
  811. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  812. * called with the MMU off.
  813. *
  814. * In addition, we need to be in 32b mode, at least for now.
  815. *
  816. * Note: r3 is an input parameter to rtas, so don't trash it...
  817. */
  818. _GLOBAL(enter_rtas)
  819. mflr r0
  820. std r0,16(r1)
  821. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  822. /* Because RTAS is running in 32b mode, it clobbers the high order half
  823. * of all registers that it saves. We therefore save those registers
  824. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  825. */
  826. SAVE_GPR(2, r1) /* Save the TOC */
  827. SAVE_GPR(13, r1) /* Save paca */
  828. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  829. SAVE_10GPRS(22, r1) /* ditto */
  830. mfcr r4
  831. std r4,_CCR(r1)
  832. mfctr r5
  833. std r5,_CTR(r1)
  834. mfspr r6,SPRN_XER
  835. std r6,_XER(r1)
  836. mfdar r7
  837. std r7,_DAR(r1)
  838. mfdsisr r8
  839. std r8,_DSISR(r1)
  840. /* Temporary workaround to clear CR until RTAS can be modified to
  841. * ignore all bits.
  842. */
  843. li r0,0
  844. mtcr r0
  845. #ifdef CONFIG_BUG
  846. /* There is no way it is acceptable to get here with interrupts enabled,
  847. * check it with the asm equivalent of WARN_ON
  848. */
  849. lbz r0,PACASOFTIRQEN(r13)
  850. 1: tdnei r0,0
  851. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  852. #endif
  853. /* Hard-disable interrupts */
  854. mfmsr r6
  855. rldicl r7,r6,48,1
  856. rotldi r7,r7,16
  857. mtmsrd r7,1
  858. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  859. * so they are saved in the PACA which allows us to restore
  860. * our original state after RTAS returns.
  861. */
  862. std r1,PACAR1(r13)
  863. std r6,PACASAVEDMSR(r13)
  864. /* Setup our real return addr */
  865. LOAD_REG_ADDR(r4,.rtas_return_loc)
  866. clrldi r4,r4,2 /* convert to realmode address */
  867. mtlr r4
  868. li r0,0
  869. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  870. andc r0,r6,r0
  871. li r9,1
  872. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  873. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI
  874. andc r6,r0,r9
  875. sync /* disable interrupts so SRR0/1 */
  876. mtmsrd r0 /* don't get trashed */
  877. LOAD_REG_ADDR(r4, rtas)
  878. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  879. ld r4,RTASBASE(r4) /* get the rtas->base value */
  880. mtspr SPRN_SRR0,r5
  881. mtspr SPRN_SRR1,r6
  882. rfid
  883. b . /* prevent speculative execution */
  884. _STATIC(rtas_return_loc)
  885. /* relocation is off at this point */
  886. GET_PACA(r4)
  887. clrldi r4,r4,2 /* convert to realmode address */
  888. bcl 20,31,$+4
  889. 0: mflr r3
  890. ld r3,(1f-0b)(r3) /* get &.rtas_restore_regs */
  891. mfmsr r6
  892. li r0,MSR_RI
  893. andc r6,r6,r0
  894. sync
  895. mtmsrd r6
  896. ld r1,PACAR1(r4) /* Restore our SP */
  897. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  898. mtspr SPRN_SRR0,r3
  899. mtspr SPRN_SRR1,r4
  900. rfid
  901. b . /* prevent speculative execution */
  902. .align 3
  903. 1: .llong .rtas_restore_regs
  904. _STATIC(rtas_restore_regs)
  905. /* relocation is on at this point */
  906. REST_GPR(2, r1) /* Restore the TOC */
  907. REST_GPR(13, r1) /* Restore paca */
  908. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  909. REST_10GPRS(22, r1) /* ditto */
  910. GET_PACA(r13)
  911. ld r4,_CCR(r1)
  912. mtcr r4
  913. ld r5,_CTR(r1)
  914. mtctr r5
  915. ld r6,_XER(r1)
  916. mtspr SPRN_XER,r6
  917. ld r7,_DAR(r1)
  918. mtdar r7
  919. ld r8,_DSISR(r1)
  920. mtdsisr r8
  921. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  922. ld r0,16(r1) /* get return address */
  923. mtlr r0
  924. blr /* return to caller */
  925. #endif /* CONFIG_PPC_RTAS */
  926. _GLOBAL(enter_prom)
  927. mflr r0
  928. std r0,16(r1)
  929. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  930. /* Because PROM is running in 32b mode, it clobbers the high order half
  931. * of all registers that it saves. We therefore save those registers
  932. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  933. */
  934. SAVE_GPR(2, r1)
  935. SAVE_GPR(13, r1)
  936. SAVE_8GPRS(14, r1)
  937. SAVE_10GPRS(22, r1)
  938. mfcr r10
  939. mfmsr r11
  940. std r10,_CCR(r1)
  941. std r11,_MSR(r1)
  942. /* Get the PROM entrypoint */
  943. mtlr r4
  944. /* Switch MSR to 32 bits mode
  945. */
  946. #ifdef CONFIG_PPC_BOOK3E
  947. rlwinm r11,r11,0,1,31
  948. mtmsr r11
  949. #else /* CONFIG_PPC_BOOK3E */
  950. mfmsr r11
  951. li r12,1
  952. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  953. andc r11,r11,r12
  954. li r12,1
  955. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  956. andc r11,r11,r12
  957. mtmsrd r11
  958. #endif /* CONFIG_PPC_BOOK3E */
  959. isync
  960. /* Enter PROM here... */
  961. blrl
  962. /* Just make sure that r1 top 32 bits didn't get
  963. * corrupt by OF
  964. */
  965. rldicl r1,r1,0,32
  966. /* Restore the MSR (back to 64 bits) */
  967. ld r0,_MSR(r1)
  968. MTMSRD(r0)
  969. isync
  970. /* Restore other registers */
  971. REST_GPR(2, r1)
  972. REST_GPR(13, r1)
  973. REST_8GPRS(14, r1)
  974. REST_10GPRS(22, r1)
  975. ld r4,_CCR(r1)
  976. mtcr r4
  977. addi r1,r1,PROM_FRAME_SIZE
  978. ld r0,16(r1)
  979. mtlr r0
  980. blr
  981. #ifdef CONFIG_FUNCTION_TRACER
  982. #ifdef CONFIG_DYNAMIC_FTRACE
  983. _GLOBAL(mcount)
  984. _GLOBAL(_mcount)
  985. blr
  986. _GLOBAL(ftrace_caller)
  987. /* Taken from output of objdump from lib64/glibc */
  988. mflr r3
  989. ld r11, 0(r1)
  990. stdu r1, -112(r1)
  991. std r3, 128(r1)
  992. ld r4, 16(r11)
  993. subi r3, r3, MCOUNT_INSN_SIZE
  994. .globl ftrace_call
  995. ftrace_call:
  996. bl ftrace_stub
  997. nop
  998. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  999. .globl ftrace_graph_call
  1000. ftrace_graph_call:
  1001. b ftrace_graph_stub
  1002. _GLOBAL(ftrace_graph_stub)
  1003. #endif
  1004. ld r0, 128(r1)
  1005. mtlr r0
  1006. addi r1, r1, 112
  1007. _GLOBAL(ftrace_stub)
  1008. blr
  1009. #else
  1010. _GLOBAL(mcount)
  1011. blr
  1012. _GLOBAL(_mcount)
  1013. /* Taken from output of objdump from lib64/glibc */
  1014. mflr r3
  1015. ld r11, 0(r1)
  1016. stdu r1, -112(r1)
  1017. std r3, 128(r1)
  1018. ld r4, 16(r11)
  1019. subi r3, r3, MCOUNT_INSN_SIZE
  1020. LOAD_REG_ADDR(r5,ftrace_trace_function)
  1021. ld r5,0(r5)
  1022. ld r5,0(r5)
  1023. mtctr r5
  1024. bctrl
  1025. nop
  1026. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1027. b ftrace_graph_caller
  1028. #endif
  1029. ld r0, 128(r1)
  1030. mtlr r0
  1031. addi r1, r1, 112
  1032. _GLOBAL(ftrace_stub)
  1033. blr
  1034. #endif /* CONFIG_DYNAMIC_FTRACE */
  1035. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1036. _GLOBAL(ftrace_graph_caller)
  1037. /* load r4 with local address */
  1038. ld r4, 128(r1)
  1039. subi r4, r4, MCOUNT_INSN_SIZE
  1040. /* get the parent address */
  1041. ld r11, 112(r1)
  1042. addi r3, r11, 16
  1043. bl .prepare_ftrace_return
  1044. nop
  1045. ld r0, 128(r1)
  1046. mtlr r0
  1047. addi r1, r1, 112
  1048. blr
  1049. _GLOBAL(return_to_handler)
  1050. /* need to save return values */
  1051. std r4, -24(r1)
  1052. std r3, -16(r1)
  1053. std r31, -8(r1)
  1054. mr r31, r1
  1055. stdu r1, -112(r1)
  1056. bl .ftrace_return_to_handler
  1057. nop
  1058. /* return value has real return address */
  1059. mtlr r3
  1060. ld r1, 0(r1)
  1061. ld r4, -24(r1)
  1062. ld r3, -16(r1)
  1063. ld r31, -8(r1)
  1064. /* Jump back to real return address */
  1065. blr
  1066. _GLOBAL(mod_return_to_handler)
  1067. /* need to save return values */
  1068. std r4, -32(r1)
  1069. std r3, -24(r1)
  1070. /* save TOC */
  1071. std r2, -16(r1)
  1072. std r31, -8(r1)
  1073. mr r31, r1
  1074. stdu r1, -112(r1)
  1075. /*
  1076. * We are in a module using the module's TOC.
  1077. * Switch to our TOC to run inside the core kernel.
  1078. */
  1079. ld r2, PACATOC(r13)
  1080. bl .ftrace_return_to_handler
  1081. nop
  1082. /* return value has real return address */
  1083. mtlr r3
  1084. ld r1, 0(r1)
  1085. ld r4, -32(r1)
  1086. ld r3, -24(r1)
  1087. ld r2, -16(r1)
  1088. ld r31, -8(r1)
  1089. /* Jump back to real return address */
  1090. blr
  1091. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  1092. #endif /* CONFIG_FUNCTION_TRACER */