entry_64.S 19 KB

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