entry_64.S 29 KB

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