entry_64.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  6. * Adapted for Power Macintosh by Paul Mackerras.
  7. * Low-level exception handlers and MMU support
  8. * rewritten by Paul Mackerras.
  9. * Copyright (C) 1996 Paul Mackerras.
  10. * MPC8xx modifications Copyright (C) 1997 Dan Malek (dmalek@jlc.net).
  11. *
  12. * This file contains the system call entry code, context switch
  13. * code, and exception/interrupt return code for PowerPC.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/errno.h>
  21. #include <asm/unistd.h>
  22. #include <asm/processor.h>
  23. #include <asm/page.h>
  24. #include <asm/mmu.h>
  25. #include <asm/thread_info.h>
  26. #include <asm/ppc_asm.h>
  27. #include <asm/asm-offsets.h>
  28. #include <asm/cputable.h>
  29. #ifdef CONFIG_PPC_ISERIES
  30. #define DO_SOFT_DISABLE
  31. #endif
  32. /*
  33. * System calls.
  34. */
  35. .section ".toc","aw"
  36. .SYS_CALL_TABLE:
  37. .tc .sys_call_table[TC],.sys_call_table
  38. /* This value is used to mark exception frames on the stack. */
  39. exception_marker:
  40. .tc ID_72656773_68657265[TC],0x7265677368657265
  41. .section ".text"
  42. .align 7
  43. #undef SHOW_SYSCALLS
  44. .globl system_call_common
  45. system_call_common:
  46. andi. r10,r12,MSR_PR
  47. mr r10,r1
  48. addi r1,r1,-INT_FRAME_SIZE
  49. beq- 1f
  50. ld r1,PACAKSAVE(r13)
  51. 1: std r10,0(r1)
  52. crclr so
  53. std r11,_NIP(r1)
  54. std r12,_MSR(r1)
  55. std r0,GPR0(r1)
  56. std r10,GPR1(r1)
  57. ACCOUNT_CPU_USER_ENTRY(r10, r11)
  58. std r2,GPR2(r1)
  59. std r3,GPR3(r1)
  60. std r4,GPR4(r1)
  61. std r5,GPR5(r1)
  62. std r6,GPR6(r1)
  63. std r7,GPR7(r1)
  64. std r8,GPR8(r1)
  65. li r11,0
  66. std r11,GPR9(r1)
  67. std r11,GPR10(r1)
  68. std r11,GPR11(r1)
  69. std r11,GPR12(r1)
  70. std r9,GPR13(r1)
  71. mfcr r9
  72. mflr r10
  73. li r11,0xc01
  74. std r9,_CCR(r1)
  75. std r10,_LINK(r1)
  76. std r11,_TRAP(r1)
  77. mfxer r9
  78. mfctr r10
  79. std r9,_XER(r1)
  80. std r10,_CTR(r1)
  81. std r3,ORIG_GPR3(r1)
  82. ld r2,PACATOC(r13)
  83. addi r9,r1,STACK_FRAME_OVERHEAD
  84. ld r11,exception_marker@toc(r2)
  85. std r11,-16(r9) /* "regshere" marker */
  86. #ifdef CONFIG_PPC_ISERIES
  87. /* Hack for handling interrupts when soft-enabling on iSeries */
  88. cmpdi cr1,r0,0x5555 /* syscall 0x5555 */
  89. andi. r10,r12,MSR_PR /* from kernel */
  90. crand 4*cr0+eq,4*cr1+eq,4*cr0+eq
  91. beq hardware_interrupt_entry
  92. lbz r10,PACAPROCENABLED(r13)
  93. std r10,SOFTE(r1)
  94. #endif
  95. mfmsr r11
  96. ori r11,r11,MSR_EE
  97. mtmsrd r11,1
  98. #ifdef SHOW_SYSCALLS
  99. bl .do_show_syscall
  100. REST_GPR(0,r1)
  101. REST_4GPRS(3,r1)
  102. REST_2GPRS(7,r1)
  103. addi r9,r1,STACK_FRAME_OVERHEAD
  104. #endif
  105. clrrdi r11,r1,THREAD_SHIFT
  106. ld r10,TI_FLAGS(r11)
  107. andi. r11,r10,_TIF_SYSCALL_T_OR_A
  108. bne- syscall_dotrace
  109. syscall_dotrace_cont:
  110. cmpldi 0,r0,NR_syscalls
  111. bge- syscall_enosys
  112. system_call: /* label this so stack traces look sane */
  113. /*
  114. * Need to vector to 32 Bit or default sys_call_table here,
  115. * based on caller's run-mode / personality.
  116. */
  117. ld r11,.SYS_CALL_TABLE@toc(2)
  118. andi. r10,r10,_TIF_32BIT
  119. beq 15f
  120. addi r11,r11,8 /* use 32-bit syscall entries */
  121. clrldi r3,r3,32
  122. clrldi r4,r4,32
  123. clrldi r5,r5,32
  124. clrldi r6,r6,32
  125. clrldi r7,r7,32
  126. clrldi r8,r8,32
  127. 15:
  128. slwi r0,r0,4
  129. ldx r10,r11,r0 /* Fetch system call handler [ptr] */
  130. mtctr r10
  131. bctrl /* Call handler */
  132. syscall_exit:
  133. std r3,RESULT(r1)
  134. #ifdef SHOW_SYSCALLS
  135. bl .do_show_syscall_exit
  136. ld r3,RESULT(r1)
  137. #endif
  138. clrrdi r12,r1,THREAD_SHIFT
  139. /* disable interrupts so current_thread_info()->flags can't change,
  140. and so that we don't get interrupted after loading SRR0/1. */
  141. ld r8,_MSR(r1)
  142. andi. r10,r8,MSR_RI
  143. beq- unrecov_restore
  144. mfmsr r10
  145. rldicl r10,r10,48,1
  146. rotldi r10,r10,16
  147. mtmsrd r10,1
  148. ld r9,TI_FLAGS(r12)
  149. li r11,-_LAST_ERRNO
  150. andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
  151. bne- syscall_exit_work
  152. cmpld r3,r11
  153. ld r5,_CCR(r1)
  154. bge- syscall_error
  155. syscall_error_cont:
  156. ld r7,_NIP(r1)
  157. stdcx. r0,0,r1 /* to clear the reservation */
  158. andi. r6,r8,MSR_PR
  159. ld r4,_LINK(r1)
  160. beq- 1f
  161. ACCOUNT_CPU_USER_EXIT(r11, r12)
  162. ld r13,GPR13(r1) /* only restore r13 if returning to usermode */
  163. 1: ld r2,GPR2(r1)
  164. li r12,MSR_RI
  165. andc r11,r10,r12
  166. mtmsrd r11,1 /* clear MSR.RI */
  167. ld r1,GPR1(r1)
  168. mtlr r4
  169. mtcr r5
  170. mtspr SPRN_SRR0,r7
  171. mtspr SPRN_SRR1,r8
  172. rfid
  173. b . /* prevent speculative execution */
  174. syscall_error:
  175. oris r5,r5,0x1000 /* Set SO bit in CR */
  176. neg r3,r3
  177. std r5,_CCR(r1)
  178. b syscall_error_cont
  179. /* Traced system call support */
  180. syscall_dotrace:
  181. bl .save_nvgprs
  182. addi r3,r1,STACK_FRAME_OVERHEAD
  183. bl .do_syscall_trace_enter
  184. ld r0,GPR0(r1) /* Restore original registers */
  185. ld r3,GPR3(r1)
  186. ld r4,GPR4(r1)
  187. ld r5,GPR5(r1)
  188. ld r6,GPR6(r1)
  189. ld r7,GPR7(r1)
  190. ld r8,GPR8(r1)
  191. addi r9,r1,STACK_FRAME_OVERHEAD
  192. clrrdi r10,r1,THREAD_SHIFT
  193. ld r10,TI_FLAGS(r10)
  194. b syscall_dotrace_cont
  195. syscall_enosys:
  196. li r3,-ENOSYS
  197. b syscall_exit
  198. syscall_exit_work:
  199. /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
  200. If TIF_NOERROR is set, just save r3 as it is. */
  201. andi. r0,r9,_TIF_RESTOREALL
  202. beq+ 0f
  203. REST_NVGPRS(r1)
  204. b 2f
  205. 0: cmpld r3,r11 /* r10 is -LAST_ERRNO */
  206. blt+ 1f
  207. andi. r0,r9,_TIF_NOERROR
  208. bne- 1f
  209. ld r5,_CCR(r1)
  210. neg r3,r3
  211. oris r5,r5,0x1000 /* Set SO bit in CR */
  212. std r5,_CCR(r1)
  213. 1: std r3,GPR3(r1)
  214. 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
  215. beq 4f
  216. /* Clear per-syscall TIF flags if any are set. */
  217. li r11,_TIF_PERSYSCALL_MASK
  218. addi r12,r12,TI_FLAGS
  219. 3: ldarx r10,0,r12
  220. andc r10,r10,r11
  221. stdcx. r10,0,r12
  222. bne- 3b
  223. subi r12,r12,TI_FLAGS
  224. 4: /* Anything else left to do? */
  225. andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP)
  226. beq .ret_from_except_lite
  227. /* Re-enable interrupts */
  228. mfmsr r10
  229. ori r10,r10,MSR_EE
  230. mtmsrd r10,1
  231. bl .save_nvgprs
  232. addi r3,r1,STACK_FRAME_OVERHEAD
  233. bl .do_syscall_trace_leave
  234. b .ret_from_except
  235. /* Save non-volatile GPRs, if not already saved. */
  236. _GLOBAL(save_nvgprs)
  237. ld r11,_TRAP(r1)
  238. andi. r0,r11,1
  239. beqlr-
  240. SAVE_NVGPRS(r1)
  241. clrrdi r0,r11,1
  242. std r0,_TRAP(r1)
  243. blr
  244. /*
  245. * The sigsuspend and rt_sigsuspend system calls can call do_signal
  246. * and thus put the process into the stopped state where we might
  247. * want to examine its user state with ptrace. Therefore we need
  248. * to save all the nonvolatile registers (r14 - r31) before calling
  249. * the C code. Similarly, fork, vfork and clone need the full
  250. * register state on the stack so that it can be copied to the child.
  251. */
  252. _GLOBAL(ppc_fork)
  253. bl .save_nvgprs
  254. bl .sys_fork
  255. b syscall_exit
  256. _GLOBAL(ppc_vfork)
  257. bl .save_nvgprs
  258. bl .sys_vfork
  259. b syscall_exit
  260. _GLOBAL(ppc_clone)
  261. bl .save_nvgprs
  262. bl .sys_clone
  263. b syscall_exit
  264. _GLOBAL(ppc32_swapcontext)
  265. bl .save_nvgprs
  266. bl .compat_sys_swapcontext
  267. b syscall_exit
  268. _GLOBAL(ppc64_swapcontext)
  269. bl .save_nvgprs
  270. bl .sys_swapcontext
  271. b syscall_exit
  272. _GLOBAL(ret_from_fork)
  273. bl .schedule_tail
  274. REST_NVGPRS(r1)
  275. li r3,0
  276. b syscall_exit
  277. /*
  278. * This routine switches between two different tasks. The process
  279. * state of one is saved on its kernel stack. Then the state
  280. * of the other is restored from its kernel stack. The memory
  281. * management hardware is updated to the second process's state.
  282. * Finally, we can return to the second process, via ret_from_except.
  283. * On entry, r3 points to the THREAD for the current task, r4
  284. * points to the THREAD for the new task.
  285. *
  286. * Note: there are two ways to get to the "going out" portion
  287. * of this code; either by coming in via the entry (_switch)
  288. * or via "fork" which must set up an environment equivalent
  289. * to the "_switch" path. If you change this you'll have to change
  290. * the fork code also.
  291. *
  292. * The code which creates the new task context is in 'copy_thread'
  293. * in arch/powerpc/kernel/process.c
  294. */
  295. .align 7
  296. _GLOBAL(_switch)
  297. mflr r0
  298. std r0,16(r1)
  299. stdu r1,-SWITCH_FRAME_SIZE(r1)
  300. /* r3-r13 are caller saved -- Cort */
  301. SAVE_8GPRS(14, r1)
  302. SAVE_10GPRS(22, r1)
  303. mflr r20 /* Return to switch caller */
  304. mfmsr r22
  305. li r0, MSR_FP
  306. #ifdef CONFIG_ALTIVEC
  307. BEGIN_FTR_SECTION
  308. oris r0,r0,MSR_VEC@h /* Disable altivec */
  309. mfspr r24,SPRN_VRSAVE /* save vrsave register value */
  310. std r24,THREAD_VRSAVE(r3)
  311. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  312. #endif /* CONFIG_ALTIVEC */
  313. and. r0,r0,r22
  314. beq+ 1f
  315. andc r22,r22,r0
  316. mtmsrd r22
  317. isync
  318. 1: std r20,_NIP(r1)
  319. mfcr r23
  320. std r23,_CCR(r1)
  321. std r1,KSP(r3) /* Set old stack pointer */
  322. #ifdef CONFIG_SMP
  323. /* We need a sync somewhere here to make sure that if the
  324. * previous task gets rescheduled on another CPU, it sees all
  325. * stores it has performed on this one.
  326. */
  327. sync
  328. #endif /* CONFIG_SMP */
  329. addi r6,r4,-THREAD /* Convert THREAD to 'current' */
  330. std r6,PACACURRENT(r13) /* Set new 'current' */
  331. ld r8,KSP(r4) /* new stack pointer */
  332. BEGIN_FTR_SECTION
  333. clrrdi r6,r8,28 /* get its ESID */
  334. clrrdi r9,r1,28 /* get current sp ESID */
  335. clrldi. r0,r6,2 /* is new ESID c00000000? */
  336. cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
  337. cror eq,4*cr1+eq,eq
  338. beq 2f /* if yes, don't slbie it */
  339. /* Bolt in the new stack SLB entry */
  340. ld r7,KSP_VSID(r4) /* Get new stack's VSID */
  341. oris r0,r6,(SLB_ESID_V)@h
  342. ori r0,r0,(SLB_NUM_BOLTED-1)@l
  343. slbie r6
  344. slbie r6 /* Workaround POWER5 < DD2.1 issue */
  345. slbmte r7,r0
  346. isync
  347. 2:
  348. END_FTR_SECTION_IFSET(CPU_FTR_SLB)
  349. clrrdi r7,r8,THREAD_SHIFT /* base of new stack */
  350. /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
  351. because we don't need to leave the 288-byte ABI gap at the
  352. top of the kernel stack. */
  353. addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
  354. mr r1,r8 /* start using new stack pointer */
  355. std r7,PACAKSAVE(r13)
  356. ld r6,_CCR(r1)
  357. mtcrf 0xFF,r6
  358. #ifdef CONFIG_ALTIVEC
  359. BEGIN_FTR_SECTION
  360. ld r0,THREAD_VRSAVE(r4)
  361. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  362. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  363. #endif /* CONFIG_ALTIVEC */
  364. /* r3-r13 are destroyed -- Cort */
  365. REST_8GPRS(14, r1)
  366. REST_10GPRS(22, r1)
  367. /* convert old thread to its task_struct for return value */
  368. addi r3,r3,-THREAD
  369. ld r7,_NIP(r1) /* Return to _switch caller in new task */
  370. mtlr r7
  371. addi r1,r1,SWITCH_FRAME_SIZE
  372. blr
  373. .align 7
  374. _GLOBAL(ret_from_except)
  375. ld r11,_TRAP(r1)
  376. andi. r0,r11,1
  377. bne .ret_from_except_lite
  378. REST_NVGPRS(r1)
  379. _GLOBAL(ret_from_except_lite)
  380. /*
  381. * Disable interrupts so that current_thread_info()->flags
  382. * can't change between when we test it and when we return
  383. * from the interrupt.
  384. */
  385. mfmsr r10 /* Get current interrupt state */
  386. rldicl r9,r10,48,1 /* clear MSR_EE */
  387. rotldi r9,r9,16
  388. mtmsrd r9,1 /* Update machine state */
  389. #ifdef CONFIG_PREEMPT
  390. clrrdi r9,r1,THREAD_SHIFT /* current_thread_info() */
  391. li r0,_TIF_NEED_RESCHED /* bits to check */
  392. ld r3,_MSR(r1)
  393. ld r4,TI_FLAGS(r9)
  394. /* Move MSR_PR bit in r3 to _TIF_SIGPENDING position in r0 */
  395. rlwimi r0,r3,32+TIF_SIGPENDING-MSR_PR_LG,_TIF_SIGPENDING
  396. and. r0,r4,r0 /* check NEED_RESCHED and maybe SIGPENDING */
  397. bne do_work
  398. #else /* !CONFIG_PREEMPT */
  399. ld r3,_MSR(r1) /* Returning to user mode? */
  400. andi. r3,r3,MSR_PR
  401. beq restore /* if not, just restore regs and return */
  402. /* Check current_thread_info()->flags */
  403. clrrdi r9,r1,THREAD_SHIFT
  404. ld r4,TI_FLAGS(r9)
  405. andi. r0,r4,_TIF_USER_WORK_MASK
  406. bne do_work
  407. #endif
  408. restore:
  409. #ifdef CONFIG_PPC_ISERIES
  410. ld r5,SOFTE(r1)
  411. cmpdi 0,r5,0
  412. beq 4f
  413. /* Check for pending interrupts (iSeries) */
  414. ld r3,PACALPPACAPTR(r13)
  415. ld r3,LPPACAANYINT(r3)
  416. cmpdi r3,0
  417. beq+ 4f /* skip do_IRQ if no interrupts */
  418. li r3,0
  419. stb r3,PACAPROCENABLED(r13) /* ensure we are soft-disabled */
  420. ori r10,r10,MSR_EE
  421. mtmsrd r10 /* hard-enable again */
  422. addi r3,r1,STACK_FRAME_OVERHEAD
  423. bl .do_IRQ
  424. b .ret_from_except_lite /* loop back and handle more */
  425. 4: stb r5,PACAPROCENABLED(r13)
  426. #endif
  427. ld r3,_MSR(r1)
  428. andi. r0,r3,MSR_RI
  429. beq- unrecov_restore
  430. andi. r0,r3,MSR_PR
  431. /*
  432. * r13 is our per cpu area, only restore it if we are returning to
  433. * userspace
  434. */
  435. beq 1f
  436. ACCOUNT_CPU_USER_EXIT(r3, r4)
  437. REST_GPR(13, r1)
  438. 1:
  439. ld r3,_CTR(r1)
  440. ld r0,_LINK(r1)
  441. mtctr r3
  442. mtlr r0
  443. ld r3,_XER(r1)
  444. mtspr SPRN_XER,r3
  445. REST_8GPRS(5, r1)
  446. stdcx. r0,0,r1 /* to clear the reservation */
  447. mfmsr r0
  448. li r2, MSR_RI
  449. andc r0,r0,r2
  450. mtmsrd r0,1
  451. ld r0,_MSR(r1)
  452. mtspr SPRN_SRR1,r0
  453. ld r2,_CCR(r1)
  454. mtcrf 0xFF,r2
  455. ld r2,_NIP(r1)
  456. mtspr SPRN_SRR0,r2
  457. ld r0,GPR0(r1)
  458. ld r2,GPR2(r1)
  459. ld r3,GPR3(r1)
  460. ld r4,GPR4(r1)
  461. ld r1,GPR1(r1)
  462. rfid
  463. b . /* prevent speculative execution */
  464. /* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
  465. do_work:
  466. #ifdef CONFIG_PREEMPT
  467. andi. r0,r3,MSR_PR /* Returning to user mode? */
  468. bne user_work
  469. /* Check that preempt_count() == 0 and interrupts are enabled */
  470. lwz r8,TI_PREEMPT(r9)
  471. cmpwi cr1,r8,0
  472. #ifdef CONFIG_PPC_ISERIES
  473. ld r0,SOFTE(r1)
  474. cmpdi r0,0
  475. #else
  476. andi. r0,r3,MSR_EE
  477. #endif
  478. crandc eq,cr1*4+eq,eq
  479. bne restore
  480. /* here we are preempting the current task */
  481. 1:
  482. #ifdef CONFIG_PPC_ISERIES
  483. li r0,1
  484. stb r0,PACAPROCENABLED(r13)
  485. #endif
  486. ori r10,r10,MSR_EE
  487. mtmsrd r10,1 /* reenable interrupts */
  488. bl .preempt_schedule
  489. mfmsr r10
  490. clrrdi r9,r1,THREAD_SHIFT
  491. rldicl r10,r10,48,1 /* disable interrupts again */
  492. rotldi r10,r10,16
  493. mtmsrd r10,1
  494. ld r4,TI_FLAGS(r9)
  495. andi. r0,r4,_TIF_NEED_RESCHED
  496. bne 1b
  497. b restore
  498. user_work:
  499. #endif
  500. /* Enable interrupts */
  501. ori r10,r10,MSR_EE
  502. mtmsrd r10,1
  503. andi. r0,r4,_TIF_NEED_RESCHED
  504. beq 1f
  505. bl .schedule
  506. b .ret_from_except_lite
  507. 1: bl .save_nvgprs
  508. li r3,0
  509. addi r4,r1,STACK_FRAME_OVERHEAD
  510. bl .do_signal
  511. b .ret_from_except
  512. unrecov_restore:
  513. addi r3,r1,STACK_FRAME_OVERHEAD
  514. bl .unrecoverable_exception
  515. b unrecov_restore
  516. #ifdef CONFIG_PPC_RTAS
  517. /*
  518. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  519. * called with the MMU off.
  520. *
  521. * In addition, we need to be in 32b mode, at least for now.
  522. *
  523. * Note: r3 is an input parameter to rtas, so don't trash it...
  524. */
  525. _GLOBAL(enter_rtas)
  526. mflr r0
  527. std r0,16(r1)
  528. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  529. /* Because RTAS is running in 32b mode, it clobbers the high order half
  530. * of all registers that it saves. We therefore save those registers
  531. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  532. */
  533. SAVE_GPR(2, r1) /* Save the TOC */
  534. SAVE_GPR(13, r1) /* Save paca */
  535. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  536. SAVE_10GPRS(22, r1) /* ditto */
  537. mfcr r4
  538. std r4,_CCR(r1)
  539. mfctr r5
  540. std r5,_CTR(r1)
  541. mfspr r6,SPRN_XER
  542. std r6,_XER(r1)
  543. mfdar r7
  544. std r7,_DAR(r1)
  545. mfdsisr r8
  546. std r8,_DSISR(r1)
  547. mfsrr0 r9
  548. std r9,_SRR0(r1)
  549. mfsrr1 r10
  550. std r10,_SRR1(r1)
  551. /* Temporary workaround to clear CR until RTAS can be modified to
  552. * ignore all bits.
  553. */
  554. li r0,0
  555. mtcr r0
  556. /* There is no way it is acceptable to get here with interrupts enabled,
  557. * check it with the asm equivalent of WARN_ON
  558. */
  559. mfmsr r6
  560. andi. r0,r6,MSR_EE
  561. 1: tdnei r0,0
  562. .section __bug_table,"a"
  563. .llong 1b,__LINE__ + 0x1000000, 1f, 2f
  564. .previous
  565. .section .rodata,"a"
  566. 1: .asciz __FILE__
  567. 2: .asciz "enter_rtas"
  568. .previous
  569. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  570. * so they are saved in the PACA which allows us to restore
  571. * our original state after RTAS returns.
  572. */
  573. std r1,PACAR1(r13)
  574. std r6,PACASAVEDMSR(r13)
  575. /* Setup our real return addr */
  576. LOAD_REG_ADDR(r4,.rtas_return_loc)
  577. clrldi r4,r4,2 /* convert to realmode address */
  578. mtlr r4
  579. li r0,0
  580. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  581. andc r0,r6,r0
  582. li r9,1
  583. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  584. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
  585. andc r6,r0,r9
  586. ori r6,r6,MSR_RI
  587. sync /* disable interrupts so SRR0/1 */
  588. mtmsrd r0 /* don't get trashed */
  589. LOAD_REG_ADDR(r4, rtas)
  590. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  591. ld r4,RTASBASE(r4) /* get the rtas->base value */
  592. mtspr SPRN_SRR0,r5
  593. mtspr SPRN_SRR1,r6
  594. rfid
  595. b . /* prevent speculative execution */
  596. _STATIC(rtas_return_loc)
  597. /* relocation is off at this point */
  598. mfspr r4,SPRN_SPRG3 /* Get PACA */
  599. clrldi r4,r4,2 /* convert to realmode address */
  600. mfmsr r6
  601. li r0,MSR_RI
  602. andc r6,r6,r0
  603. sync
  604. mtmsrd r6
  605. ld r1,PACAR1(r4) /* Restore our SP */
  606. LOAD_REG_IMMEDIATE(r3,.rtas_restore_regs)
  607. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  608. mtspr SPRN_SRR0,r3
  609. mtspr SPRN_SRR1,r4
  610. rfid
  611. b . /* prevent speculative execution */
  612. _STATIC(rtas_restore_regs)
  613. /* relocation is on at this point */
  614. REST_GPR(2, r1) /* Restore the TOC */
  615. REST_GPR(13, r1) /* Restore paca */
  616. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  617. REST_10GPRS(22, r1) /* ditto */
  618. mfspr r13,SPRN_SPRG3
  619. ld r4,_CCR(r1)
  620. mtcr r4
  621. ld r5,_CTR(r1)
  622. mtctr r5
  623. ld r6,_XER(r1)
  624. mtspr SPRN_XER,r6
  625. ld r7,_DAR(r1)
  626. mtdar r7
  627. ld r8,_DSISR(r1)
  628. mtdsisr r8
  629. ld r9,_SRR0(r1)
  630. mtsrr0 r9
  631. ld r10,_SRR1(r1)
  632. mtsrr1 r10
  633. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  634. ld r0,16(r1) /* get return address */
  635. mtlr r0
  636. blr /* return to caller */
  637. #endif /* CONFIG_PPC_RTAS */
  638. #ifdef CONFIG_PPC_MULTIPLATFORM
  639. _GLOBAL(enter_prom)
  640. mflr r0
  641. std r0,16(r1)
  642. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  643. /* Because PROM is running in 32b mode, it clobbers the high order half
  644. * of all registers that it saves. We therefore save those registers
  645. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  646. */
  647. SAVE_8GPRS(2, r1)
  648. SAVE_GPR(13, r1)
  649. SAVE_8GPRS(14, r1)
  650. SAVE_10GPRS(22, r1)
  651. mfcr r4
  652. std r4,_CCR(r1)
  653. mfctr r5
  654. std r5,_CTR(r1)
  655. mfspr r6,SPRN_XER
  656. std r6,_XER(r1)
  657. mfdar r7
  658. std r7,_DAR(r1)
  659. mfdsisr r8
  660. std r8,_DSISR(r1)
  661. mfsrr0 r9
  662. std r9,_SRR0(r1)
  663. mfsrr1 r10
  664. std r10,_SRR1(r1)
  665. mfmsr r11
  666. std r11,_MSR(r1)
  667. /* Get the PROM entrypoint */
  668. ld r0,GPR4(r1)
  669. mtlr r0
  670. /* Switch MSR to 32 bits mode
  671. */
  672. mfmsr r11
  673. li r12,1
  674. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  675. andc r11,r11,r12
  676. li r12,1
  677. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  678. andc r11,r11,r12
  679. mtmsrd r11
  680. isync
  681. /* Restore arguments & enter PROM here... */
  682. ld r3,GPR3(r1)
  683. blrl
  684. /* Just make sure that r1 top 32 bits didn't get
  685. * corrupt by OF
  686. */
  687. rldicl r1,r1,0,32
  688. /* Restore the MSR (back to 64 bits) */
  689. ld r0,_MSR(r1)
  690. mtmsrd r0
  691. isync
  692. /* Restore other registers */
  693. REST_GPR(2, r1)
  694. REST_GPR(13, r1)
  695. REST_8GPRS(14, r1)
  696. REST_10GPRS(22, r1)
  697. ld r4,_CCR(r1)
  698. mtcr r4
  699. ld r5,_CTR(r1)
  700. mtctr r5
  701. ld r6,_XER(r1)
  702. mtspr SPRN_XER,r6
  703. ld r7,_DAR(r1)
  704. mtdar r7
  705. ld r8,_DSISR(r1)
  706. mtdsisr r8
  707. ld r9,_SRR0(r1)
  708. mtsrr0 r9
  709. ld r10,_SRR1(r1)
  710. mtsrr1 r10
  711. addi r1,r1,PROM_FRAME_SIZE
  712. ld r0,16(r1)
  713. mtlr r0
  714. blr
  715. #endif /* CONFIG_PPC_MULTIPLATFORM */