entry_64.S 19 KB

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