entry_64.S 31 KB

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