entry_64.S 30 KB

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