entry_64.S 30 KB

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