entry_64.S 30 KB

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