entry_64.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. #include <asm/firmware.h>
  30. /*
  31. * System calls.
  32. */
  33. .section ".toc","aw"
  34. .SYS_CALL_TABLE:
  35. .tc .sys_call_table[TC],.sys_call_table
  36. /* This value is used to mark exception frames on the stack. */
  37. exception_marker:
  38. .tc ID_72656773_68657265[TC],0x7265677368657265
  39. .section ".text"
  40. .align 7
  41. #undef SHOW_SYSCALLS
  42. .globl system_call_common
  43. system_call_common:
  44. andi. r10,r12,MSR_PR
  45. mr r10,r1
  46. addi r1,r1,-INT_FRAME_SIZE
  47. beq- 1f
  48. ld r1,PACAKSAVE(r13)
  49. 1: std r10,0(r1)
  50. crclr so
  51. std r11,_NIP(r1)
  52. std r12,_MSR(r1)
  53. std r0,GPR0(r1)
  54. std r10,GPR1(r1)
  55. ACCOUNT_CPU_USER_ENTRY(r10, r11)
  56. std r2,GPR2(r1)
  57. std r3,GPR3(r1)
  58. std r4,GPR4(r1)
  59. std r5,GPR5(r1)
  60. std r6,GPR6(r1)
  61. std r7,GPR7(r1)
  62. std r8,GPR8(r1)
  63. li r11,0
  64. std r11,GPR9(r1)
  65. std r11,GPR10(r1)
  66. std r11,GPR11(r1)
  67. std r11,GPR12(r1)
  68. std r9,GPR13(r1)
  69. mfcr r9
  70. mflr r10
  71. li r11,0xc01
  72. std r9,_CCR(r1)
  73. std r10,_LINK(r1)
  74. std r11,_TRAP(r1)
  75. mfxer r9
  76. mfctr r10
  77. std r9,_XER(r1)
  78. std r10,_CTR(r1)
  79. std r3,ORIG_GPR3(r1)
  80. ld r2,PACATOC(r13)
  81. addi r9,r1,STACK_FRAME_OVERHEAD
  82. ld r11,exception_marker@toc(r2)
  83. std r11,-16(r9) /* "regshere" marker */
  84. #ifdef CONFIG_PPC_ISERIES
  85. BEGIN_FW_FTR_SECTION
  86. /* Hack for handling interrupts when soft-enabling on iSeries */
  87. cmpdi cr1,r0,0x5555 /* syscall 0x5555 */
  88. andi. r10,r12,MSR_PR /* from kernel */
  89. crand 4*cr0+eq,4*cr1+eq,4*cr0+eq
  90. beq hardware_interrupt_entry
  91. lbz r10,PACAPROCENABLED(r13)
  92. std r10,SOFTE(r1)
  93. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  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. /* Update the last bolted SLB */
  344. ld r9,PACA_SLBSHADOWPTR(r13)
  345. li r12,0
  346. std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */
  347. std r7,SLBSHADOW_STACKVSID(r9) /* Save VSID */
  348. std r0,SLBSHADOW_STACKESID(r9) /* Save ESID */
  349. slbie r6
  350. slbie r6 /* Workaround POWER5 < DD2.1 issue */
  351. slbmte r7,r0
  352. isync
  353. 2:
  354. END_FTR_SECTION_IFSET(CPU_FTR_SLB)
  355. clrrdi r7,r8,THREAD_SHIFT /* base of new stack */
  356. /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
  357. because we don't need to leave the 288-byte ABI gap at the
  358. top of the kernel stack. */
  359. addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
  360. mr r1,r8 /* start using new stack pointer */
  361. std r7,PACAKSAVE(r13)
  362. ld r6,_CCR(r1)
  363. mtcrf 0xFF,r6
  364. #ifdef CONFIG_ALTIVEC
  365. BEGIN_FTR_SECTION
  366. ld r0,THREAD_VRSAVE(r4)
  367. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  368. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  369. #endif /* CONFIG_ALTIVEC */
  370. /* r3-r13 are destroyed -- Cort */
  371. REST_8GPRS(14, r1)
  372. REST_10GPRS(22, r1)
  373. /* convert old thread to its task_struct for return value */
  374. addi r3,r3,-THREAD
  375. ld r7,_NIP(r1) /* Return to _switch caller in new task */
  376. mtlr r7
  377. addi r1,r1,SWITCH_FRAME_SIZE
  378. blr
  379. .align 7
  380. _GLOBAL(ret_from_except)
  381. ld r11,_TRAP(r1)
  382. andi. r0,r11,1
  383. bne .ret_from_except_lite
  384. REST_NVGPRS(r1)
  385. _GLOBAL(ret_from_except_lite)
  386. /*
  387. * Disable interrupts so that current_thread_info()->flags
  388. * can't change between when we test it and when we return
  389. * from the interrupt.
  390. */
  391. mfmsr r10 /* Get current interrupt state */
  392. rldicl r9,r10,48,1 /* clear MSR_EE */
  393. rotldi r9,r9,16
  394. mtmsrd r9,1 /* Update machine state */
  395. #ifdef CONFIG_PREEMPT
  396. clrrdi r9,r1,THREAD_SHIFT /* current_thread_info() */
  397. li r0,_TIF_NEED_RESCHED /* bits to check */
  398. ld r3,_MSR(r1)
  399. ld r4,TI_FLAGS(r9)
  400. /* Move MSR_PR bit in r3 to _TIF_SIGPENDING position in r0 */
  401. rlwimi r0,r3,32+TIF_SIGPENDING-MSR_PR_LG,_TIF_SIGPENDING
  402. and. r0,r4,r0 /* check NEED_RESCHED and maybe SIGPENDING */
  403. bne do_work
  404. #else /* !CONFIG_PREEMPT */
  405. ld r3,_MSR(r1) /* Returning to user mode? */
  406. andi. r3,r3,MSR_PR
  407. beq restore /* if not, just restore regs and return */
  408. /* Check current_thread_info()->flags */
  409. clrrdi r9,r1,THREAD_SHIFT
  410. ld r4,TI_FLAGS(r9)
  411. andi. r0,r4,_TIF_USER_WORK_MASK
  412. bne do_work
  413. #endif
  414. restore:
  415. #ifdef CONFIG_PPC_ISERIES
  416. BEGIN_FW_FTR_SECTION
  417. ld r5,SOFTE(r1)
  418. cmpdi 0,r5,0
  419. beq 4f
  420. /* Check for pending interrupts (iSeries) */
  421. ld r3,PACALPPACAPTR(r13)
  422. ld r3,LPPACAANYINT(r3)
  423. cmpdi r3,0
  424. beq+ 4f /* skip do_IRQ if no interrupts */
  425. li r3,0
  426. stb r3,PACAPROCENABLED(r13) /* ensure we are soft-disabled */
  427. ori r10,r10,MSR_EE
  428. mtmsrd r10 /* hard-enable again */
  429. addi r3,r1,STACK_FRAME_OVERHEAD
  430. bl .do_IRQ
  431. b .ret_from_except_lite /* loop back and handle more */
  432. 4: stb r5,PACAPROCENABLED(r13)
  433. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  434. #endif
  435. ld r3,_MSR(r1)
  436. andi. r0,r3,MSR_RI
  437. beq- unrecov_restore
  438. andi. r0,r3,MSR_PR
  439. /*
  440. * r13 is our per cpu area, only restore it if we are returning to
  441. * userspace
  442. */
  443. beq 1f
  444. ACCOUNT_CPU_USER_EXIT(r3, r4)
  445. REST_GPR(13, r1)
  446. 1:
  447. ld r3,_CTR(r1)
  448. ld r0,_LINK(r1)
  449. mtctr r3
  450. mtlr r0
  451. ld r3,_XER(r1)
  452. mtspr SPRN_XER,r3
  453. REST_8GPRS(5, r1)
  454. stdcx. r0,0,r1 /* to clear the reservation */
  455. mfmsr r0
  456. li r2, MSR_RI
  457. andc r0,r0,r2
  458. mtmsrd r0,1
  459. ld r0,_MSR(r1)
  460. mtspr SPRN_SRR1,r0
  461. ld r2,_CCR(r1)
  462. mtcrf 0xFF,r2
  463. ld r2,_NIP(r1)
  464. mtspr SPRN_SRR0,r2
  465. ld r0,GPR0(r1)
  466. ld r2,GPR2(r1)
  467. ld r3,GPR3(r1)
  468. ld r4,GPR4(r1)
  469. ld r1,GPR1(r1)
  470. rfid
  471. b . /* prevent speculative execution */
  472. /* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
  473. do_work:
  474. #ifdef CONFIG_PREEMPT
  475. andi. r0,r3,MSR_PR /* Returning to user mode? */
  476. bne user_work
  477. /* Check that preempt_count() == 0 and interrupts are enabled */
  478. lwz r8,TI_PREEMPT(r9)
  479. cmpwi cr1,r8,0
  480. #ifdef CONFIG_PPC_ISERIES
  481. BEGIN_FW_FTR_SECTION
  482. ld r0,SOFTE(r1)
  483. cmpdi r0,0
  484. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  485. #endif
  486. BEGIN_FW_FTR_SECTION
  487. andi. r0,r3,MSR_EE
  488. END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
  489. crandc eq,cr1*4+eq,eq
  490. bne restore
  491. /* here we are preempting the current task */
  492. 1:
  493. #ifdef CONFIG_PPC_ISERIES
  494. BEGIN_FW_FTR_SECTION
  495. li r0,1
  496. stb r0,PACAPROCENABLED(r13)
  497. END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
  498. #endif
  499. ori r10,r10,MSR_EE
  500. mtmsrd r10,1 /* reenable interrupts */
  501. bl .preempt_schedule
  502. mfmsr r10
  503. clrrdi r9,r1,THREAD_SHIFT
  504. rldicl r10,r10,48,1 /* disable interrupts again */
  505. rotldi r10,r10,16
  506. mtmsrd r10,1
  507. ld r4,TI_FLAGS(r9)
  508. andi. r0,r4,_TIF_NEED_RESCHED
  509. bne 1b
  510. b restore
  511. user_work:
  512. #endif
  513. /* Enable interrupts */
  514. ori r10,r10,MSR_EE
  515. mtmsrd r10,1
  516. andi. r0,r4,_TIF_NEED_RESCHED
  517. beq 1f
  518. bl .schedule
  519. b .ret_from_except_lite
  520. 1: bl .save_nvgprs
  521. li r3,0
  522. addi r4,r1,STACK_FRAME_OVERHEAD
  523. bl .do_signal
  524. b .ret_from_except
  525. unrecov_restore:
  526. addi r3,r1,STACK_FRAME_OVERHEAD
  527. bl .unrecoverable_exception
  528. b unrecov_restore
  529. #ifdef CONFIG_PPC_RTAS
  530. /*
  531. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  532. * called with the MMU off.
  533. *
  534. * In addition, we need to be in 32b mode, at least for now.
  535. *
  536. * Note: r3 is an input parameter to rtas, so don't trash it...
  537. */
  538. _GLOBAL(enter_rtas)
  539. mflr r0
  540. std r0,16(r1)
  541. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  542. /* Because RTAS is running in 32b mode, it clobbers the high order half
  543. * of all registers that it saves. We therefore save those registers
  544. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  545. */
  546. SAVE_GPR(2, r1) /* Save the TOC */
  547. SAVE_GPR(13, r1) /* Save paca */
  548. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  549. SAVE_10GPRS(22, r1) /* ditto */
  550. mfcr r4
  551. std r4,_CCR(r1)
  552. mfctr r5
  553. std r5,_CTR(r1)
  554. mfspr r6,SPRN_XER
  555. std r6,_XER(r1)
  556. mfdar r7
  557. std r7,_DAR(r1)
  558. mfdsisr r8
  559. std r8,_DSISR(r1)
  560. mfsrr0 r9
  561. std r9,_SRR0(r1)
  562. mfsrr1 r10
  563. std r10,_SRR1(r1)
  564. /* Temporary workaround to clear CR until RTAS can be modified to
  565. * ignore all bits.
  566. */
  567. li r0,0
  568. mtcr r0
  569. /* There is no way it is acceptable to get here with interrupts enabled,
  570. * check it with the asm equivalent of WARN_ON
  571. */
  572. mfmsr r6
  573. andi. r0,r6,MSR_EE
  574. 1: tdnei r0,0
  575. .section __bug_table,"a"
  576. .llong 1b,__LINE__ + 0x1000000, 1f, 2f
  577. .previous
  578. .section .rodata,"a"
  579. 1: .asciz __FILE__
  580. 2: .asciz "enter_rtas"
  581. .previous
  582. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  583. * so they are saved in the PACA which allows us to restore
  584. * our original state after RTAS returns.
  585. */
  586. std r1,PACAR1(r13)
  587. std r6,PACASAVEDMSR(r13)
  588. /* Setup our real return addr */
  589. LOAD_REG_ADDR(r4,.rtas_return_loc)
  590. clrldi r4,r4,2 /* convert to realmode address */
  591. mtlr r4
  592. li r0,0
  593. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  594. andc r0,r6,r0
  595. li r9,1
  596. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  597. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
  598. andc r6,r0,r9
  599. ori r6,r6,MSR_RI
  600. sync /* disable interrupts so SRR0/1 */
  601. mtmsrd r0 /* don't get trashed */
  602. LOAD_REG_ADDR(r4, rtas)
  603. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  604. ld r4,RTASBASE(r4) /* get the rtas->base value */
  605. mtspr SPRN_SRR0,r5
  606. mtspr SPRN_SRR1,r6
  607. rfid
  608. b . /* prevent speculative execution */
  609. _STATIC(rtas_return_loc)
  610. /* relocation is off at this point */
  611. mfspr r4,SPRN_SPRG3 /* Get PACA */
  612. clrldi r4,r4,2 /* convert to realmode address */
  613. mfmsr r6
  614. li r0,MSR_RI
  615. andc r6,r6,r0
  616. sync
  617. mtmsrd r6
  618. ld r1,PACAR1(r4) /* Restore our SP */
  619. LOAD_REG_IMMEDIATE(r3,.rtas_restore_regs)
  620. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  621. mtspr SPRN_SRR0,r3
  622. mtspr SPRN_SRR1,r4
  623. rfid
  624. b . /* prevent speculative execution */
  625. _STATIC(rtas_restore_regs)
  626. /* relocation is on at this point */
  627. REST_GPR(2, r1) /* Restore the TOC */
  628. REST_GPR(13, r1) /* Restore paca */
  629. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  630. REST_10GPRS(22, r1) /* ditto */
  631. mfspr r13,SPRN_SPRG3
  632. ld r4,_CCR(r1)
  633. mtcr r4
  634. ld r5,_CTR(r1)
  635. mtctr r5
  636. ld r6,_XER(r1)
  637. mtspr SPRN_XER,r6
  638. ld r7,_DAR(r1)
  639. mtdar r7
  640. ld r8,_DSISR(r1)
  641. mtdsisr r8
  642. ld r9,_SRR0(r1)
  643. mtsrr0 r9
  644. ld r10,_SRR1(r1)
  645. mtsrr1 r10
  646. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  647. ld r0,16(r1) /* get return address */
  648. mtlr r0
  649. blr /* return to caller */
  650. #endif /* CONFIG_PPC_RTAS */
  651. #ifdef CONFIG_PPC_MULTIPLATFORM
  652. _GLOBAL(enter_prom)
  653. mflr r0
  654. std r0,16(r1)
  655. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  656. /* Because PROM is running in 32b mode, it clobbers the high order half
  657. * of all registers that it saves. We therefore save those registers
  658. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  659. */
  660. SAVE_8GPRS(2, r1)
  661. SAVE_GPR(13, r1)
  662. SAVE_8GPRS(14, r1)
  663. SAVE_10GPRS(22, r1)
  664. mfcr r4
  665. std r4,_CCR(r1)
  666. mfctr r5
  667. std r5,_CTR(r1)
  668. mfspr r6,SPRN_XER
  669. std r6,_XER(r1)
  670. mfdar r7
  671. std r7,_DAR(r1)
  672. mfdsisr r8
  673. std r8,_DSISR(r1)
  674. mfsrr0 r9
  675. std r9,_SRR0(r1)
  676. mfsrr1 r10
  677. std r10,_SRR1(r1)
  678. mfmsr r11
  679. std r11,_MSR(r1)
  680. /* Get the PROM entrypoint */
  681. ld r0,GPR4(r1)
  682. mtlr r0
  683. /* Switch MSR to 32 bits mode
  684. */
  685. mfmsr r11
  686. li r12,1
  687. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  688. andc r11,r11,r12
  689. li r12,1
  690. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  691. andc r11,r11,r12
  692. mtmsrd r11
  693. isync
  694. /* Restore arguments & enter PROM here... */
  695. ld r3,GPR3(r1)
  696. blrl
  697. /* Just make sure that r1 top 32 bits didn't get
  698. * corrupt by OF
  699. */
  700. rldicl r1,r1,0,32
  701. /* Restore the MSR (back to 64 bits) */
  702. ld r0,_MSR(r1)
  703. mtmsrd r0
  704. isync
  705. /* Restore other registers */
  706. REST_GPR(2, r1)
  707. REST_GPR(13, r1)
  708. REST_8GPRS(14, r1)
  709. REST_10GPRS(22, r1)
  710. ld r4,_CCR(r1)
  711. mtcr r4
  712. ld r5,_CTR(r1)
  713. mtctr r5
  714. ld r6,_XER(r1)
  715. mtspr SPRN_XER,r6
  716. ld r7,_DAR(r1)
  717. mtdar r7
  718. ld r8,_DSISR(r1)
  719. mtdsisr r8
  720. ld r9,_SRR0(r1)
  721. mtsrr0 r9
  722. ld r10,_SRR1(r1)
  723. mtsrr1 r10
  724. addi r1,r1,PROM_FRAME_SIZE
  725. ld r0,16(r1)
  726. mtlr r0
  727. blr
  728. #endif /* CONFIG_PPC_MULTIPLATFORM */