entry_64.S 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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, r10) /* 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. ld r14, 0(r14)
  345. mtlr r14
  346. mr r3,r15
  347. blrl
  348. li r3,0
  349. b syscall_exit
  350. .section ".toc","aw"
  351. DSCR_DEFAULT:
  352. .tc dscr_default[TC],dscr_default
  353. .section ".text"
  354. /*
  355. * This routine switches between two different tasks. The process
  356. * state of one is saved on its kernel stack. Then the state
  357. * of the other is restored from its kernel stack. The memory
  358. * management hardware is updated to the second process's state.
  359. * Finally, we can return to the second process, via ret_from_except.
  360. * On entry, r3 points to the THREAD for the current task, r4
  361. * points to the THREAD for the new task.
  362. *
  363. * Note: there are two ways to get to the "going out" portion
  364. * of this code; either by coming in via the entry (_switch)
  365. * or via "fork" which must set up an environment equivalent
  366. * to the "_switch" path. If you change this you'll have to change
  367. * the fork code also.
  368. *
  369. * The code which creates the new task context is in 'copy_thread'
  370. * in arch/powerpc/kernel/process.c
  371. */
  372. .align 7
  373. _GLOBAL(_switch)
  374. mflr r0
  375. std r0,16(r1)
  376. stdu r1,-SWITCH_FRAME_SIZE(r1)
  377. /* r3-r13 are caller saved -- Cort */
  378. SAVE_8GPRS(14, r1)
  379. SAVE_10GPRS(22, r1)
  380. mflr r20 /* Return to switch caller */
  381. mfmsr r22
  382. li r0, MSR_FP
  383. #ifdef CONFIG_VSX
  384. BEGIN_FTR_SECTION
  385. oris r0,r0,MSR_VSX@h /* Disable VSX */
  386. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  387. #endif /* CONFIG_VSX */
  388. #ifdef CONFIG_ALTIVEC
  389. BEGIN_FTR_SECTION
  390. oris r0,r0,MSR_VEC@h /* Disable altivec */
  391. mfspr r24,SPRN_VRSAVE /* save vrsave register value */
  392. std r24,THREAD_VRSAVE(r3)
  393. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  394. #endif /* CONFIG_ALTIVEC */
  395. #ifdef CONFIG_PPC64
  396. BEGIN_FTR_SECTION
  397. mfspr r25,SPRN_DSCR
  398. std r25,THREAD_DSCR(r3)
  399. END_FTR_SECTION_IFSET(CPU_FTR_DSCR)
  400. #endif
  401. and. r0,r0,r22
  402. beq+ 1f
  403. andc r22,r22,r0
  404. MTMSRD(r22)
  405. isync
  406. 1: std r20,_NIP(r1)
  407. mfcr r23
  408. std r23,_CCR(r1)
  409. std r1,KSP(r3) /* Set old stack pointer */
  410. #ifdef CONFIG_PPC_BOOK3S_64
  411. BEGIN_FTR_SECTION
  412. /*
  413. * Back up the TAR across context switches. Note that the TAR is not
  414. * available for use in the kernel. (To provide this, the TAR should
  415. * be backed up/restored on exception entry/exit instead, and be in
  416. * pt_regs. FIXME, this should be in pt_regs anyway (for debug).)
  417. */
  418. mfspr r0,SPRN_TAR
  419. std r0,THREAD_TAR(r3)
  420. /* Event based branch registers */
  421. mfspr r0, SPRN_BESCR
  422. std r0, THREAD_BESCR(r3)
  423. mfspr r0, SPRN_EBBHR
  424. std r0, THREAD_EBBHR(r3)
  425. mfspr r0, SPRN_EBBRR
  426. std r0, THREAD_EBBRR(r3)
  427. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  428. #endif
  429. #ifdef CONFIG_SMP
  430. /* We need a sync somewhere here to make sure that if the
  431. * previous task gets rescheduled on another CPU, it sees all
  432. * stores it has performed on this one.
  433. */
  434. sync
  435. #endif /* CONFIG_SMP */
  436. /*
  437. * If we optimise away the clear of the reservation in system
  438. * calls because we know the CPU tracks the address of the
  439. * reservation, then we need to clear it here to cover the
  440. * case that the kernel context switch path has no larx
  441. * instructions.
  442. */
  443. BEGIN_FTR_SECTION
  444. ldarx r6,0,r1
  445. END_FTR_SECTION_IFSET(CPU_FTR_STCX_CHECKS_ADDRESS)
  446. addi r6,r4,-THREAD /* Convert THREAD to 'current' */
  447. std r6,PACACURRENT(r13) /* Set new 'current' */
  448. ld r8,KSP(r4) /* new stack pointer */
  449. #ifdef CONFIG_PPC_BOOK3S
  450. BEGIN_FTR_SECTION
  451. BEGIN_FTR_SECTION_NESTED(95)
  452. clrrdi r6,r8,28 /* get its ESID */
  453. clrrdi r9,r1,28 /* get current sp ESID */
  454. FTR_SECTION_ELSE_NESTED(95)
  455. clrrdi r6,r8,40 /* get its 1T ESID */
  456. clrrdi r9,r1,40 /* get current sp 1T ESID */
  457. ALT_MMU_FTR_SECTION_END_NESTED_IFCLR(MMU_FTR_1T_SEGMENT, 95)
  458. FTR_SECTION_ELSE
  459. b 2f
  460. ALT_MMU_FTR_SECTION_END_IFSET(MMU_FTR_SLB)
  461. clrldi. r0,r6,2 /* is new ESID c00000000? */
  462. cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
  463. cror eq,4*cr1+eq,eq
  464. beq 2f /* if yes, don't slbie it */
  465. /* Bolt in the new stack SLB entry */
  466. ld r7,KSP_VSID(r4) /* Get new stack's VSID */
  467. oris r0,r6,(SLB_ESID_V)@h
  468. ori r0,r0,(SLB_NUM_BOLTED-1)@l
  469. BEGIN_FTR_SECTION
  470. li r9,MMU_SEGSIZE_1T /* insert B field */
  471. oris r6,r6,(MMU_SEGSIZE_1T << SLBIE_SSIZE_SHIFT)@h
  472. rldimi r7,r9,SLB_VSID_SSIZE_SHIFT,0
  473. END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  474. /* Update the last bolted SLB. No write barriers are needed
  475. * here, provided we only update the current CPU's SLB shadow
  476. * buffer.
  477. */
  478. ld r9,PACA_SLBSHADOWPTR(r13)
  479. li r12,0
  480. std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */
  481. std r7,SLBSHADOW_STACKVSID(r9) /* Save VSID */
  482. std r0,SLBSHADOW_STACKESID(r9) /* Save ESID */
  483. /* No need to check for MMU_FTR_NO_SLBIE_B here, since when
  484. * we have 1TB segments, the only CPUs known to have the errata
  485. * only support less than 1TB of system memory and we'll never
  486. * actually hit this code path.
  487. */
  488. slbie r6
  489. slbie r6 /* Workaround POWER5 < DD2.1 issue */
  490. slbmte r7,r0
  491. isync
  492. 2:
  493. #endif /* !CONFIG_PPC_BOOK3S */
  494. CURRENT_THREAD_INFO(r7, r8) /* base of new stack */
  495. /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
  496. because we don't need to leave the 288-byte ABI gap at the
  497. top of the kernel stack. */
  498. addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
  499. mr r1,r8 /* start using new stack pointer */
  500. std r7,PACAKSAVE(r13)
  501. #ifdef CONFIG_PPC_BOOK3S_64
  502. BEGIN_FTR_SECTION
  503. /* Event based branch registers */
  504. ld r0, THREAD_BESCR(r4)
  505. mtspr SPRN_BESCR, r0
  506. ld r0, THREAD_EBBHR(r4)
  507. mtspr SPRN_EBBHR, r0
  508. ld r0, THREAD_EBBRR(r4)
  509. mtspr SPRN_EBBRR, r0
  510. ld r0,THREAD_TAR(r4)
  511. mtspr SPRN_TAR,r0
  512. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  513. #endif
  514. #ifdef CONFIG_ALTIVEC
  515. BEGIN_FTR_SECTION
  516. ld r0,THREAD_VRSAVE(r4)
  517. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  518. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  519. #endif /* CONFIG_ALTIVEC */
  520. #ifdef CONFIG_PPC64
  521. BEGIN_FTR_SECTION
  522. lwz r6,THREAD_DSCR_INHERIT(r4)
  523. ld r7,DSCR_DEFAULT@toc(2)
  524. ld r0,THREAD_DSCR(r4)
  525. cmpwi r6,0
  526. bne 1f
  527. ld r0,0(r7)
  528. 1: cmpd r0,r25
  529. beq 2f
  530. mtspr SPRN_DSCR,r0
  531. 2:
  532. END_FTR_SECTION_IFSET(CPU_FTR_DSCR)
  533. #endif
  534. ld r6,_CCR(r1)
  535. mtcrf 0xFF,r6
  536. /* r3-r13 are destroyed -- Cort */
  537. REST_8GPRS(14, r1)
  538. REST_10GPRS(22, r1)
  539. /* convert old thread to its task_struct for return value */
  540. addi r3,r3,-THREAD
  541. ld r7,_NIP(r1) /* Return to _switch caller in new task */
  542. mtlr r7
  543. addi r1,r1,SWITCH_FRAME_SIZE
  544. blr
  545. .align 7
  546. _GLOBAL(ret_from_except)
  547. ld r11,_TRAP(r1)
  548. andi. r0,r11,1
  549. bne .ret_from_except_lite
  550. REST_NVGPRS(r1)
  551. _GLOBAL(ret_from_except_lite)
  552. /*
  553. * Disable interrupts so that current_thread_info()->flags
  554. * can't change between when we test it and when we return
  555. * from the interrupt.
  556. */
  557. #ifdef CONFIG_PPC_BOOK3E
  558. wrteei 0
  559. #else
  560. ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
  561. mtmsrd r10,1 /* Update machine state */
  562. #endif /* CONFIG_PPC_BOOK3E */
  563. CURRENT_THREAD_INFO(r9, r1)
  564. ld r3,_MSR(r1)
  565. ld r4,TI_FLAGS(r9)
  566. andi. r3,r3,MSR_PR
  567. beq resume_kernel
  568. /* Check current_thread_info()->flags */
  569. andi. r0,r4,_TIF_USER_WORK_MASK
  570. beq restore
  571. andi. r0,r4,_TIF_NEED_RESCHED
  572. beq 1f
  573. bl .restore_interrupts
  574. bl .schedule
  575. b .ret_from_except_lite
  576. 1: bl .save_nvgprs
  577. bl .restore_interrupts
  578. addi r3,r1,STACK_FRAME_OVERHEAD
  579. bl .do_notify_resume
  580. b .ret_from_except
  581. resume_kernel:
  582. /* check current_thread_info, _TIF_EMULATE_STACK_STORE */
  583. CURRENT_THREAD_INFO(r9, r1)
  584. ld r8,TI_FLAGS(r9)
  585. andis. r8,r8,_TIF_EMULATE_STACK_STORE@h
  586. beq+ 1f
  587. addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
  588. lwz r3,GPR1(r1)
  589. subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
  590. mr r4,r1 /* src: current exception frame */
  591. mr r1,r3 /* Reroute the trampoline frame to r1 */
  592. /* Copy from the original to the trampoline. */
  593. li r5,INT_FRAME_SIZE/8 /* size: INT_FRAME_SIZE */
  594. li r6,0 /* start offset: 0 */
  595. mtctr r5
  596. 2: ldx r0,r6,r4
  597. stdx r0,r6,r3
  598. addi r6,r6,8
  599. bdnz 2b
  600. /* Do real store operation to complete stwu */
  601. lwz r5,GPR1(r1)
  602. std r8,0(r5)
  603. /* Clear _TIF_EMULATE_STACK_STORE flag */
  604. lis r11,_TIF_EMULATE_STACK_STORE@h
  605. addi r5,r9,TI_FLAGS
  606. 0: ldarx r4,0,r5
  607. andc r4,r4,r11
  608. stdcx. r4,0,r5
  609. bne- 0b
  610. 1:
  611. #ifdef CONFIG_PREEMPT
  612. /* Check if we need to preempt */
  613. andi. r0,r4,_TIF_NEED_RESCHED
  614. beq+ restore
  615. /* Check that preempt_count() == 0 and interrupts are enabled */
  616. lwz r8,TI_PREEMPT(r9)
  617. cmpwi cr1,r8,0
  618. ld r0,SOFTE(r1)
  619. cmpdi r0,0
  620. crandc eq,cr1*4+eq,eq
  621. bne restore
  622. /*
  623. * Here we are preempting the current task. We want to make
  624. * sure we are soft-disabled first
  625. */
  626. SOFT_DISABLE_INTS(r3,r4)
  627. 1: bl .preempt_schedule_irq
  628. /* Re-test flags and eventually loop */
  629. CURRENT_THREAD_INFO(r9, r1)
  630. ld r4,TI_FLAGS(r9)
  631. andi. r0,r4,_TIF_NEED_RESCHED
  632. bne 1b
  633. /*
  634. * arch_local_irq_restore() from preempt_schedule_irq above may
  635. * enable hard interrupt but we really should disable interrupts
  636. * when we return from the interrupt, and so that we don't get
  637. * interrupted after loading SRR0/1.
  638. */
  639. #ifdef CONFIG_PPC_BOOK3E
  640. wrteei 0
  641. #else
  642. ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
  643. mtmsrd r10,1 /* Update machine state */
  644. #endif /* CONFIG_PPC_BOOK3E */
  645. #endif /* CONFIG_PREEMPT */
  646. .globl fast_exc_return_irq
  647. fast_exc_return_irq:
  648. restore:
  649. /*
  650. * This is the main kernel exit path. First we check if we
  651. * are about to re-enable interrupts
  652. */
  653. ld r5,SOFTE(r1)
  654. lbz r6,PACASOFTIRQEN(r13)
  655. cmpwi cr0,r5,0
  656. beq restore_irq_off
  657. /* We are enabling, were we already enabled ? Yes, just return */
  658. cmpwi cr0,r6,1
  659. beq cr0,do_restore
  660. /*
  661. * We are about to soft-enable interrupts (we are hard disabled
  662. * at this point). We check if there's anything that needs to
  663. * be replayed first.
  664. */
  665. lbz r0,PACAIRQHAPPENED(r13)
  666. cmpwi cr0,r0,0
  667. bne- restore_check_irq_replay
  668. /*
  669. * Get here when nothing happened while soft-disabled, just
  670. * soft-enable and move-on. We will hard-enable as a side
  671. * effect of rfi
  672. */
  673. restore_no_replay:
  674. TRACE_ENABLE_INTS
  675. li r0,1
  676. stb r0,PACASOFTIRQEN(r13);
  677. /*
  678. * Final return path. BookE is handled in a different file
  679. */
  680. do_restore:
  681. #ifdef CONFIG_PPC_BOOK3E
  682. b .exception_return_book3e
  683. #else
  684. /*
  685. * Clear the reservation. If we know the CPU tracks the address of
  686. * the reservation then we can potentially save some cycles and use
  687. * a larx. On POWER6 and POWER7 this is significantly faster.
  688. */
  689. BEGIN_FTR_SECTION
  690. stdcx. r0,0,r1 /* to clear the reservation */
  691. FTR_SECTION_ELSE
  692. ldarx r4,0,r1
  693. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
  694. /*
  695. * Some code path such as load_up_fpu or altivec return directly
  696. * here. They run entirely hard disabled and do not alter the
  697. * interrupt state. They also don't use lwarx/stwcx. and thus
  698. * are known not to leave dangling reservations.
  699. */
  700. .globl fast_exception_return
  701. fast_exception_return:
  702. ld r3,_MSR(r1)
  703. ld r4,_CTR(r1)
  704. ld r0,_LINK(r1)
  705. mtctr r4
  706. mtlr r0
  707. ld r4,_XER(r1)
  708. mtspr SPRN_XER,r4
  709. REST_8GPRS(5, r1)
  710. andi. r0,r3,MSR_RI
  711. beq- unrecov_restore
  712. /*
  713. * Clear RI before restoring r13. If we are returning to
  714. * userspace and we take an exception after restoring r13,
  715. * we end up corrupting the userspace r13 value.
  716. */
  717. ld r4,PACAKMSR(r13) /* Get kernel MSR without EE */
  718. andc r4,r4,r0 /* r0 contains MSR_RI here */
  719. mtmsrd r4,1
  720. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  721. /* TM debug */
  722. std r3, PACATMSCRATCH(r13) /* Stash returned-to MSR */
  723. #endif
  724. /*
  725. * r13 is our per cpu area, only restore it if we are returning to
  726. * userspace the value stored in the stack frame may belong to
  727. * another CPU.
  728. */
  729. andi. r0,r3,MSR_PR
  730. beq 1f
  731. ACCOUNT_CPU_USER_EXIT(r2, r4)
  732. RESTORE_PPR(r2, r4)
  733. REST_GPR(13, r1)
  734. 1:
  735. mtspr SPRN_SRR1,r3
  736. ld r2,_CCR(r1)
  737. mtcrf 0xFF,r2
  738. ld r2,_NIP(r1)
  739. mtspr SPRN_SRR0,r2
  740. ld r0,GPR0(r1)
  741. ld r2,GPR2(r1)
  742. ld r3,GPR3(r1)
  743. ld r4,GPR4(r1)
  744. ld r1,GPR1(r1)
  745. rfid
  746. b . /* prevent speculative execution */
  747. #endif /* CONFIG_PPC_BOOK3E */
  748. /*
  749. * We are returning to a context with interrupts soft disabled.
  750. *
  751. * However, we may also about to hard enable, so we need to
  752. * make sure that in this case, we also clear PACA_IRQ_HARD_DIS
  753. * or that bit can get out of sync and bad things will happen
  754. */
  755. restore_irq_off:
  756. ld r3,_MSR(r1)
  757. lbz r7,PACAIRQHAPPENED(r13)
  758. andi. r0,r3,MSR_EE
  759. beq 1f
  760. rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS
  761. stb r7,PACAIRQHAPPENED(r13)
  762. 1: li r0,0
  763. stb r0,PACASOFTIRQEN(r13);
  764. TRACE_DISABLE_INTS
  765. b do_restore
  766. /*
  767. * Something did happen, check if a re-emit is needed
  768. * (this also clears paca->irq_happened)
  769. */
  770. restore_check_irq_replay:
  771. /* XXX: We could implement a fast path here where we check
  772. * for irq_happened being just 0x01, in which case we can
  773. * clear it and return. That means that we would potentially
  774. * miss a decrementer having wrapped all the way around.
  775. *
  776. * Still, this might be useful for things like hash_page
  777. */
  778. bl .__check_irq_replay
  779. cmpwi cr0,r3,0
  780. beq restore_no_replay
  781. /*
  782. * We need to re-emit an interrupt. We do so by re-using our
  783. * existing exception frame. We first change the trap value,
  784. * but we need to ensure we preserve the low nibble of it
  785. */
  786. ld r4,_TRAP(r1)
  787. clrldi r4,r4,60
  788. or r4,r4,r3
  789. std r4,_TRAP(r1)
  790. /*
  791. * Then find the right handler and call it. Interrupts are
  792. * still soft-disabled and we keep them that way.
  793. */
  794. cmpwi cr0,r3,0x500
  795. bne 1f
  796. addi r3,r1,STACK_FRAME_OVERHEAD;
  797. bl .do_IRQ
  798. b .ret_from_except
  799. 1: cmpwi cr0,r3,0x900
  800. bne 1f
  801. addi r3,r1,STACK_FRAME_OVERHEAD;
  802. bl .timer_interrupt
  803. b .ret_from_except
  804. #ifdef CONFIG_PPC_DOORBELL
  805. 1:
  806. #ifdef CONFIG_PPC_BOOK3E
  807. cmpwi cr0,r3,0x280
  808. #else
  809. BEGIN_FTR_SECTION
  810. cmpwi cr0,r3,0xe80
  811. FTR_SECTION_ELSE
  812. cmpwi cr0,r3,0xa00
  813. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  814. #endif /* CONFIG_PPC_BOOK3E */
  815. bne 1f
  816. addi r3,r1,STACK_FRAME_OVERHEAD;
  817. bl .doorbell_exception
  818. b .ret_from_except
  819. #endif /* CONFIG_PPC_DOORBELL */
  820. 1: b .ret_from_except /* What else to do here ? */
  821. unrecov_restore:
  822. addi r3,r1,STACK_FRAME_OVERHEAD
  823. bl .unrecoverable_exception
  824. b unrecov_restore
  825. #ifdef CONFIG_PPC_RTAS
  826. /*
  827. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  828. * called with the MMU off.
  829. *
  830. * In addition, we need to be in 32b mode, at least for now.
  831. *
  832. * Note: r3 is an input parameter to rtas, so don't trash it...
  833. */
  834. _GLOBAL(enter_rtas)
  835. mflr r0
  836. std r0,16(r1)
  837. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  838. /* Because RTAS is running in 32b mode, it clobbers the high order half
  839. * of all registers that it saves. We therefore save those registers
  840. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  841. */
  842. SAVE_GPR(2, r1) /* Save the TOC */
  843. SAVE_GPR(13, r1) /* Save paca */
  844. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  845. SAVE_10GPRS(22, r1) /* ditto */
  846. mfcr r4
  847. std r4,_CCR(r1)
  848. mfctr r5
  849. std r5,_CTR(r1)
  850. mfspr r6,SPRN_XER
  851. std r6,_XER(r1)
  852. mfdar r7
  853. std r7,_DAR(r1)
  854. mfdsisr r8
  855. std r8,_DSISR(r1)
  856. /* Temporary workaround to clear CR until RTAS can be modified to
  857. * ignore all bits.
  858. */
  859. li r0,0
  860. mtcr r0
  861. #ifdef CONFIG_BUG
  862. /* There is no way it is acceptable to get here with interrupts enabled,
  863. * check it with the asm equivalent of WARN_ON
  864. */
  865. lbz r0,PACASOFTIRQEN(r13)
  866. 1: tdnei r0,0
  867. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  868. #endif
  869. /* Hard-disable interrupts */
  870. mfmsr r6
  871. rldicl r7,r6,48,1
  872. rotldi r7,r7,16
  873. mtmsrd r7,1
  874. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  875. * so they are saved in the PACA which allows us to restore
  876. * our original state after RTAS returns.
  877. */
  878. std r1,PACAR1(r13)
  879. std r6,PACASAVEDMSR(r13)
  880. /* Setup our real return addr */
  881. LOAD_REG_ADDR(r4,.rtas_return_loc)
  882. clrldi r4,r4,2 /* convert to realmode address */
  883. mtlr r4
  884. li r0,0
  885. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  886. andc r0,r6,r0
  887. li r9,1
  888. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  889. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI
  890. andc r6,r0,r9
  891. sync /* disable interrupts so SRR0/1 */
  892. mtmsrd r0 /* don't get trashed */
  893. LOAD_REG_ADDR(r4, rtas)
  894. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  895. ld r4,RTASBASE(r4) /* get the rtas->base value */
  896. mtspr SPRN_SRR0,r5
  897. mtspr SPRN_SRR1,r6
  898. rfid
  899. b . /* prevent speculative execution */
  900. _STATIC(rtas_return_loc)
  901. /* relocation is off at this point */
  902. GET_PACA(r4)
  903. clrldi r4,r4,2 /* convert to realmode address */
  904. bcl 20,31,$+4
  905. 0: mflr r3
  906. ld r3,(1f-0b)(r3) /* get &.rtas_restore_regs */
  907. mfmsr r6
  908. li r0,MSR_RI
  909. andc r6,r6,r0
  910. sync
  911. mtmsrd r6
  912. ld r1,PACAR1(r4) /* Restore our SP */
  913. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  914. mtspr SPRN_SRR0,r3
  915. mtspr SPRN_SRR1,r4
  916. rfid
  917. b . /* prevent speculative execution */
  918. .align 3
  919. 1: .llong .rtas_restore_regs
  920. _STATIC(rtas_restore_regs)
  921. /* relocation is on at this point */
  922. REST_GPR(2, r1) /* Restore the TOC */
  923. REST_GPR(13, r1) /* Restore paca */
  924. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  925. REST_10GPRS(22, r1) /* ditto */
  926. GET_PACA(r13)
  927. ld r4,_CCR(r1)
  928. mtcr r4
  929. ld r5,_CTR(r1)
  930. mtctr r5
  931. ld r6,_XER(r1)
  932. mtspr SPRN_XER,r6
  933. ld r7,_DAR(r1)
  934. mtdar r7
  935. ld r8,_DSISR(r1)
  936. mtdsisr r8
  937. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  938. ld r0,16(r1) /* get return address */
  939. mtlr r0
  940. blr /* return to caller */
  941. #endif /* CONFIG_PPC_RTAS */
  942. _GLOBAL(enter_prom)
  943. mflr r0
  944. std r0,16(r1)
  945. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  946. /* Because PROM is running in 32b mode, it clobbers the high order half
  947. * of all registers that it saves. We therefore save those registers
  948. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  949. */
  950. SAVE_GPR(2, r1)
  951. SAVE_GPR(13, r1)
  952. SAVE_8GPRS(14, r1)
  953. SAVE_10GPRS(22, r1)
  954. mfcr r10
  955. mfmsr r11
  956. std r10,_CCR(r1)
  957. std r11,_MSR(r1)
  958. /* Get the PROM entrypoint */
  959. mtlr r4
  960. /* Switch MSR to 32 bits mode
  961. */
  962. #ifdef CONFIG_PPC_BOOK3E
  963. rlwinm r11,r11,0,1,31
  964. mtmsr r11
  965. #else /* CONFIG_PPC_BOOK3E */
  966. mfmsr r11
  967. li r12,1
  968. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  969. andc r11,r11,r12
  970. li r12,1
  971. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  972. andc r11,r11,r12
  973. mtmsrd r11
  974. #endif /* CONFIG_PPC_BOOK3E */
  975. isync
  976. /* Enter PROM here... */
  977. blrl
  978. /* Just make sure that r1 top 32 bits didn't get
  979. * corrupt by OF
  980. */
  981. rldicl r1,r1,0,32
  982. /* Restore the MSR (back to 64 bits) */
  983. ld r0,_MSR(r1)
  984. MTMSRD(r0)
  985. isync
  986. /* Restore other registers */
  987. REST_GPR(2, r1)
  988. REST_GPR(13, r1)
  989. REST_8GPRS(14, r1)
  990. REST_10GPRS(22, r1)
  991. ld r4,_CCR(r1)
  992. mtcr r4
  993. addi r1,r1,PROM_FRAME_SIZE
  994. ld r0,16(r1)
  995. mtlr r0
  996. blr
  997. #ifdef CONFIG_FUNCTION_TRACER
  998. #ifdef CONFIG_DYNAMIC_FTRACE
  999. _GLOBAL(mcount)
  1000. _GLOBAL(_mcount)
  1001. blr
  1002. _GLOBAL(ftrace_caller)
  1003. /* Taken from output of objdump from lib64/glibc */
  1004. mflr r3
  1005. ld r11, 0(r1)
  1006. stdu r1, -112(r1)
  1007. std r3, 128(r1)
  1008. ld r4, 16(r11)
  1009. subi r3, r3, MCOUNT_INSN_SIZE
  1010. .globl ftrace_call
  1011. ftrace_call:
  1012. bl ftrace_stub
  1013. nop
  1014. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1015. .globl ftrace_graph_call
  1016. ftrace_graph_call:
  1017. b ftrace_graph_stub
  1018. _GLOBAL(ftrace_graph_stub)
  1019. #endif
  1020. ld r0, 128(r1)
  1021. mtlr r0
  1022. addi r1, r1, 112
  1023. _GLOBAL(ftrace_stub)
  1024. blr
  1025. #else
  1026. _GLOBAL(mcount)
  1027. blr
  1028. _GLOBAL(_mcount)
  1029. /* Taken from output of objdump from lib64/glibc */
  1030. mflr r3
  1031. ld r11, 0(r1)
  1032. stdu r1, -112(r1)
  1033. std r3, 128(r1)
  1034. ld r4, 16(r11)
  1035. subi r3, r3, MCOUNT_INSN_SIZE
  1036. LOAD_REG_ADDR(r5,ftrace_trace_function)
  1037. ld r5,0(r5)
  1038. ld r5,0(r5)
  1039. mtctr r5
  1040. bctrl
  1041. nop
  1042. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1043. b ftrace_graph_caller
  1044. #endif
  1045. ld r0, 128(r1)
  1046. mtlr r0
  1047. addi r1, r1, 112
  1048. _GLOBAL(ftrace_stub)
  1049. blr
  1050. #endif /* CONFIG_DYNAMIC_FTRACE */
  1051. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1052. _GLOBAL(ftrace_graph_caller)
  1053. /* load r4 with local address */
  1054. ld r4, 128(r1)
  1055. subi r4, r4, MCOUNT_INSN_SIZE
  1056. /* get the parent address */
  1057. ld r11, 112(r1)
  1058. addi r3, r11, 16
  1059. bl .prepare_ftrace_return
  1060. nop
  1061. ld r0, 128(r1)
  1062. mtlr r0
  1063. addi r1, r1, 112
  1064. blr
  1065. _GLOBAL(return_to_handler)
  1066. /* need to save return values */
  1067. std r4, -24(r1)
  1068. std r3, -16(r1)
  1069. std r31, -8(r1)
  1070. mr r31, r1
  1071. stdu r1, -112(r1)
  1072. bl .ftrace_return_to_handler
  1073. nop
  1074. /* return value has real return address */
  1075. mtlr r3
  1076. ld r1, 0(r1)
  1077. ld r4, -24(r1)
  1078. ld r3, -16(r1)
  1079. ld r31, -8(r1)
  1080. /* Jump back to real return address */
  1081. blr
  1082. _GLOBAL(mod_return_to_handler)
  1083. /* need to save return values */
  1084. std r4, -32(r1)
  1085. std r3, -24(r1)
  1086. /* save TOC */
  1087. std r2, -16(r1)
  1088. std r31, -8(r1)
  1089. mr r31, r1
  1090. stdu r1, -112(r1)
  1091. /*
  1092. * We are in a module using the module's TOC.
  1093. * Switch to our TOC to run inside the core kernel.
  1094. */
  1095. ld r2, PACATOC(r13)
  1096. bl .ftrace_return_to_handler
  1097. nop
  1098. /* return value has real return address */
  1099. mtlr r3
  1100. ld r1, 0(r1)
  1101. ld r4, -32(r1)
  1102. ld r3, -24(r1)
  1103. ld r2, -16(r1)
  1104. ld r31, -8(r1)
  1105. /* Jump back to real return address */
  1106. blr
  1107. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  1108. #endif /* CONFIG_FUNCTION_TRACER */