entry_64.S 19 KB

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