entry.S 19 KB

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