entry_64.S 18 KB

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