entry_64.S 30 KB

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