entry.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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/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 SRR0,r7
  182. mtspr 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 .sys32_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 .sys32_rt_sigsuspend
  257. /* If sigsuspend() returns zero, we are going into a signal handler */
  258. 70: cmpdi 0,r3,0
  259. beq .ret_from_except
  260. /* If it returned -EINTR, we need to return via syscall_exit to set
  261. the SO bit in cr0 and potentially stop for ptrace. */
  262. b syscall_exit
  263. _GLOBAL(ppc_fork)
  264. bl .save_nvgprs
  265. bl .sys_fork
  266. b syscall_exit
  267. _GLOBAL(ppc_vfork)
  268. bl .save_nvgprs
  269. bl .sys_vfork
  270. b syscall_exit
  271. _GLOBAL(ppc_clone)
  272. bl .save_nvgprs
  273. bl .sys_clone
  274. b syscall_exit
  275. _GLOBAL(ppc32_swapcontext)
  276. bl .save_nvgprs
  277. bl .sys32_swapcontext
  278. b 80f
  279. _GLOBAL(ppc64_swapcontext)
  280. bl .save_nvgprs
  281. bl .sys_swapcontext
  282. b 80f
  283. _GLOBAL(ppc32_sigreturn)
  284. bl .sys32_sigreturn
  285. b 80f
  286. _GLOBAL(ppc32_rt_sigreturn)
  287. bl .sys32_rt_sigreturn
  288. b 80f
  289. _GLOBAL(ppc64_rt_sigreturn)
  290. bl .sys_rt_sigreturn
  291. 80: cmpdi 0,r3,0
  292. blt syscall_exit
  293. clrrdi r4,r1,THREAD_SHIFT
  294. ld r4,TI_FLAGS(r4)
  295. andi. r4,r4,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP)
  296. beq+ 81f
  297. addi r3,r1,STACK_FRAME_OVERHEAD
  298. bl .do_syscall_trace_leave
  299. 81: b .ret_from_except
  300. _GLOBAL(ret_from_fork)
  301. bl .schedule_tail
  302. REST_NVGPRS(r1)
  303. li r3,0
  304. b syscall_exit
  305. /*
  306. * This routine switches between two different tasks. The process
  307. * state of one is saved on its kernel stack. Then the state
  308. * of the other is restored from its kernel stack. The memory
  309. * management hardware is updated to the second process's state.
  310. * Finally, we can return to the second process, via ret_from_except.
  311. * On entry, r3 points to the THREAD for the current task, r4
  312. * points to the THREAD for the new task.
  313. *
  314. * Note: there are two ways to get to the "going out" portion
  315. * of this code; either by coming in via the entry (_switch)
  316. * or via "fork" which must set up an environment equivalent
  317. * to the "_switch" path. If you change this you'll have to change
  318. * the fork code also.
  319. *
  320. * The code which creates the new task context is in 'copy_thread'
  321. * in arch/ppc64/kernel/process.c
  322. */
  323. .align 7
  324. _GLOBAL(_switch)
  325. mflr r0
  326. std r0,16(r1)
  327. stdu r1,-SWITCH_FRAME_SIZE(r1)
  328. /* r3-r13 are caller saved -- Cort */
  329. SAVE_8GPRS(14, r1)
  330. SAVE_10GPRS(22, r1)
  331. mflr r20 /* Return to switch caller */
  332. mfmsr r22
  333. li r0, MSR_FP
  334. #ifdef CONFIG_ALTIVEC
  335. BEGIN_FTR_SECTION
  336. oris r0,r0,MSR_VEC@h /* Disable altivec */
  337. mfspr r24,SPRN_VRSAVE /* save vrsave register value */
  338. std r24,THREAD_VRSAVE(r3)
  339. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  340. #endif /* CONFIG_ALTIVEC */
  341. and. r0,r0,r22
  342. beq+ 1f
  343. andc r22,r22,r0
  344. mtmsrd r22
  345. isync
  346. 1: std r20,_NIP(r1)
  347. mfcr r23
  348. std r23,_CCR(r1)
  349. std r1,KSP(r3) /* Set old stack pointer */
  350. #ifdef CONFIG_SMP
  351. /* We need a sync somewhere here to make sure that if the
  352. * previous task gets rescheduled on another CPU, it sees all
  353. * stores it has performed on this one.
  354. */
  355. sync
  356. #endif /* CONFIG_SMP */
  357. addi r6,r4,-THREAD /* Convert THREAD to 'current' */
  358. std r6,PACACURRENT(r13) /* Set new 'current' */
  359. ld r8,KSP(r4) /* new stack pointer */
  360. BEGIN_FTR_SECTION
  361. clrrdi r6,r8,28 /* get its ESID */
  362. clrrdi r9,r1,28 /* get current sp ESID */
  363. clrldi. r0,r6,2 /* is new ESID c00000000? */
  364. cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
  365. cror eq,4*cr1+eq,eq
  366. beq 2f /* if yes, don't slbie it */
  367. /* Bolt in the new stack SLB entry */
  368. ld r7,KSP_VSID(r4) /* Get new stack's VSID */
  369. oris r0,r6,(SLB_ESID_V)@h
  370. ori r0,r0,(SLB_NUM_BOLTED-1)@l
  371. slbie r6
  372. slbie r6 /* Workaround POWER5 < DD2.1 issue */
  373. slbmte r7,r0
  374. isync
  375. 2:
  376. END_FTR_SECTION_IFSET(CPU_FTR_SLB)
  377. clrrdi r7,r8,THREAD_SHIFT /* base of new stack */
  378. /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
  379. because we don't need to leave the 288-byte ABI gap at the
  380. top of the kernel stack. */
  381. addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
  382. mr r1,r8 /* start using new stack pointer */
  383. std r7,PACAKSAVE(r13)
  384. ld r6,_CCR(r1)
  385. mtcrf 0xFF,r6
  386. #ifdef CONFIG_ALTIVEC
  387. BEGIN_FTR_SECTION
  388. ld r0,THREAD_VRSAVE(r4)
  389. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  390. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  391. #endif /* CONFIG_ALTIVEC */
  392. /* r3-r13 are destroyed -- Cort */
  393. REST_8GPRS(14, r1)
  394. REST_10GPRS(22, r1)
  395. /* convert old thread to its task_struct for return value */
  396. addi r3,r3,-THREAD
  397. ld r7,_NIP(r1) /* Return to _switch caller in new task */
  398. mtlr r7
  399. addi r1,r1,SWITCH_FRAME_SIZE
  400. blr
  401. .align 7
  402. _GLOBAL(ret_from_except)
  403. ld r11,_TRAP(r1)
  404. andi. r0,r11,1
  405. bne .ret_from_except_lite
  406. REST_NVGPRS(r1)
  407. _GLOBAL(ret_from_except_lite)
  408. /*
  409. * Disable interrupts so that current_thread_info()->flags
  410. * can't change between when we test it and when we return
  411. * from the interrupt.
  412. */
  413. mfmsr r10 /* Get current interrupt state */
  414. rldicl r9,r10,48,1 /* clear MSR_EE */
  415. rotldi r9,r9,16
  416. mtmsrd r9,1 /* Update machine state */
  417. #ifdef CONFIG_PREEMPT
  418. clrrdi r9,r1,THREAD_SHIFT /* current_thread_info() */
  419. li r0,_TIF_NEED_RESCHED /* bits to check */
  420. ld r3,_MSR(r1)
  421. ld r4,TI_FLAGS(r9)
  422. /* Move MSR_PR bit in r3 to _TIF_SIGPENDING position in r0 */
  423. rlwimi r0,r3,32+TIF_SIGPENDING-MSR_PR_LG,_TIF_SIGPENDING
  424. and. r0,r4,r0 /* check NEED_RESCHED and maybe SIGPENDING */
  425. bne do_work
  426. #else /* !CONFIG_PREEMPT */
  427. ld r3,_MSR(r1) /* Returning to user mode? */
  428. andi. r3,r3,MSR_PR
  429. beq restore /* if not, just restore regs and return */
  430. /* Check current_thread_info()->flags */
  431. clrrdi r9,r1,THREAD_SHIFT
  432. ld r4,TI_FLAGS(r9)
  433. andi. r0,r4,_TIF_USER_WORK_MASK
  434. bne do_work
  435. #endif
  436. restore:
  437. #ifdef CONFIG_PPC_ISERIES
  438. ld r5,SOFTE(r1)
  439. cmpdi 0,r5,0
  440. beq 4f
  441. /* Check for pending interrupts (iSeries) */
  442. ld r3,PACALPPACA+LPPACAANYINT(r13)
  443. cmpdi r3,0
  444. beq+ 4f /* skip do_IRQ if no interrupts */
  445. li r3,0
  446. stb r3,PACAPROCENABLED(r13) /* ensure we are soft-disabled */
  447. ori r10,r10,MSR_EE
  448. mtmsrd r10 /* hard-enable again */
  449. addi r3,r1,STACK_FRAME_OVERHEAD
  450. bl .do_IRQ
  451. b .ret_from_except_lite /* loop back and handle more */
  452. 4: stb r5,PACAPROCENABLED(r13)
  453. #endif
  454. ld r3,_MSR(r1)
  455. andi. r0,r3,MSR_RI
  456. beq- unrecov_restore
  457. andi. r0,r3,MSR_PR
  458. /*
  459. * r13 is our per cpu area, only restore it if we are returning to
  460. * userspace
  461. */
  462. beq 1f
  463. REST_GPR(13, r1)
  464. 1:
  465. ld r3,_CTR(r1)
  466. ld r0,_LINK(r1)
  467. mtctr r3
  468. mtlr r0
  469. ld r3,_XER(r1)
  470. mtspr XER,r3
  471. REST_8GPRS(5, r1)
  472. stdcx. r0,0,r1 /* to clear the reservation */
  473. mfmsr r0
  474. li r2, MSR_RI
  475. andc r0,r0,r2
  476. mtmsrd r0,1
  477. ld r0,_MSR(r1)
  478. mtspr SRR1,r0
  479. ld r2,_CCR(r1)
  480. mtcrf 0xFF,r2
  481. ld r2,_NIP(r1)
  482. mtspr SRR0,r2
  483. ld r0,GPR0(r1)
  484. ld r2,GPR2(r1)
  485. ld r3,GPR3(r1)
  486. ld r4,GPR4(r1)
  487. ld r1,GPR1(r1)
  488. rfid
  489. b . /* prevent speculative execution */
  490. /* Note: this must change if we start using the TIF_NOTIFY_RESUME bit */
  491. do_work:
  492. #ifdef CONFIG_PREEMPT
  493. andi. r0,r3,MSR_PR /* Returning to user mode? */
  494. bne user_work
  495. /* Check that preempt_count() == 0 and interrupts are enabled */
  496. lwz r8,TI_PREEMPT(r9)
  497. cmpwi cr1,r8,0
  498. #ifdef CONFIG_PPC_ISERIES
  499. ld r0,SOFTE(r1)
  500. cmpdi r0,0
  501. #else
  502. andi. r0,r3,MSR_EE
  503. #endif
  504. crandc eq,cr1*4+eq,eq
  505. bne restore
  506. /* here we are preempting the current task */
  507. 1:
  508. #ifdef CONFIG_PPC_ISERIES
  509. li r0,1
  510. stb r0,PACAPROCENABLED(r13)
  511. #endif
  512. ori r10,r10,MSR_EE
  513. mtmsrd r10,1 /* reenable interrupts */
  514. bl .preempt_schedule
  515. mfmsr r10
  516. clrrdi r9,r1,THREAD_SHIFT
  517. rldicl r10,r10,48,1 /* disable interrupts again */
  518. rotldi r10,r10,16
  519. mtmsrd r10,1
  520. ld r4,TI_FLAGS(r9)
  521. andi. r0,r4,_TIF_NEED_RESCHED
  522. bne 1b
  523. b restore
  524. user_work:
  525. #endif
  526. /* Enable interrupts */
  527. ori r10,r10,MSR_EE
  528. mtmsrd r10,1
  529. andi. r0,r4,_TIF_NEED_RESCHED
  530. beq 1f
  531. bl .schedule
  532. b .ret_from_except_lite
  533. 1: bl .save_nvgprs
  534. li r3,0
  535. addi r4,r1,STACK_FRAME_OVERHEAD
  536. bl .do_signal
  537. b .ret_from_except
  538. unrecov_restore:
  539. addi r3,r1,STACK_FRAME_OVERHEAD
  540. bl .unrecoverable_exception
  541. b unrecov_restore
  542. #ifdef CONFIG_PPC_RTAS
  543. /*
  544. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  545. * called with the MMU off.
  546. *
  547. * In addition, we need to be in 32b mode, at least for now.
  548. *
  549. * Note: r3 is an input parameter to rtas, so don't trash it...
  550. */
  551. _GLOBAL(enter_rtas)
  552. mflr r0
  553. std r0,16(r1)
  554. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  555. /* Because RTAS is running in 32b mode, it clobbers the high order half
  556. * of all registers that it saves. We therefore save those registers
  557. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  558. */
  559. SAVE_GPR(2, r1) /* Save the TOC */
  560. SAVE_GPR(13, r1) /* Save paca */
  561. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  562. SAVE_10GPRS(22, r1) /* ditto */
  563. mfcr r4
  564. std r4,_CCR(r1)
  565. mfctr r5
  566. std r5,_CTR(r1)
  567. mfspr r6,XER
  568. std r6,_XER(r1)
  569. mfdar r7
  570. std r7,_DAR(r1)
  571. mfdsisr r8
  572. std r8,_DSISR(r1)
  573. mfsrr0 r9
  574. std r9,_SRR0(r1)
  575. mfsrr1 r10
  576. std r10,_SRR1(r1)
  577. /* There is no way it is acceptable to get here with interrupts enabled,
  578. * check it with the asm equivalent of WARN_ON
  579. */
  580. mfmsr r6
  581. andi. r0,r6,MSR_EE
  582. 1: tdnei r0,0
  583. .section __bug_table,"a"
  584. .llong 1b,__LINE__ + 0x1000000, 1f, 2f
  585. .previous
  586. .section .rodata,"a"
  587. 1: .asciz __FILE__
  588. 2: .asciz "enter_rtas"
  589. .previous
  590. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  591. * so they are saved in the PACA which allows us to restore
  592. * our original state after RTAS returns.
  593. */
  594. std r1,PACAR1(r13)
  595. std r6,PACASAVEDMSR(r13)
  596. /* Setup our real return addr */
  597. SET_REG_TO_LABEL(r4,.rtas_return_loc)
  598. SET_REG_TO_CONST(r9,KERNELBASE)
  599. sub r4,r4,r9
  600. mtlr r4
  601. li r0,0
  602. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  603. andc r0,r6,r0
  604. li r9,1
  605. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  606. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP
  607. andc r6,r0,r9
  608. ori r6,r6,MSR_RI
  609. sync /* disable interrupts so SRR0/1 */
  610. mtmsrd r0 /* don't get trashed */
  611. SET_REG_TO_LABEL(r4,rtas)
  612. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  613. ld r4,RTASBASE(r4) /* get the rtas->base value */
  614. mtspr SRR0,r5
  615. mtspr SRR1,r6
  616. rfid
  617. b . /* prevent speculative execution */
  618. _STATIC(rtas_return_loc)
  619. /* relocation is off at this point */
  620. mfspr r4,SPRG3 /* Get PACA */
  621. SET_REG_TO_CONST(r5, KERNELBASE)
  622. sub r4,r4,r5 /* RELOC the PACA base pointer */
  623. mfmsr r6
  624. li r0,MSR_RI
  625. andc r6,r6,r0
  626. sync
  627. mtmsrd r6
  628. ld r1,PACAR1(r4) /* Restore our SP */
  629. LOADADDR(r3,.rtas_restore_regs)
  630. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  631. mtspr SRR0,r3
  632. mtspr SRR1,r4
  633. rfid
  634. b . /* prevent speculative execution */
  635. _STATIC(rtas_restore_regs)
  636. /* relocation is on at this point */
  637. REST_GPR(2, r1) /* Restore the TOC */
  638. REST_GPR(13, r1) /* Restore paca */
  639. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  640. REST_10GPRS(22, r1) /* ditto */
  641. mfspr r13,SPRG3
  642. ld r4,_CCR(r1)
  643. mtcr r4
  644. ld r5,_CTR(r1)
  645. mtctr r5
  646. ld r6,_XER(r1)
  647. mtspr XER,r6
  648. ld r7,_DAR(r1)
  649. mtdar r7
  650. ld r8,_DSISR(r1)
  651. mtdsisr r8
  652. ld r9,_SRR0(r1)
  653. mtsrr0 r9
  654. ld r10,_SRR1(r1)
  655. mtsrr1 r10
  656. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  657. ld r0,16(r1) /* get return address */
  658. mtlr r0
  659. blr /* return to caller */
  660. #endif /* CONFIG_PPC_RTAS */
  661. #ifdef CONFIG_PPC_MULTIPLATFORM
  662. _GLOBAL(enter_prom)
  663. mflr r0
  664. std r0,16(r1)
  665. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  666. /* Because PROM is running in 32b mode, it clobbers the high order half
  667. * of all registers that it saves. We therefore save those registers
  668. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  669. */
  670. SAVE_8GPRS(2, r1)
  671. SAVE_GPR(13, r1)
  672. SAVE_8GPRS(14, r1)
  673. SAVE_10GPRS(22, r1)
  674. mfcr r4
  675. std r4,_CCR(r1)
  676. mfctr r5
  677. std r5,_CTR(r1)
  678. mfspr r6,XER
  679. std r6,_XER(r1)
  680. mfdar r7
  681. std r7,_DAR(r1)
  682. mfdsisr r8
  683. std r8,_DSISR(r1)
  684. mfsrr0 r9
  685. std r9,_SRR0(r1)
  686. mfsrr1 r10
  687. std r10,_SRR1(r1)
  688. mfmsr r11
  689. std r11,_MSR(r1)
  690. /* Get the PROM entrypoint */
  691. ld r0,GPR4(r1)
  692. mtlr r0
  693. /* Switch MSR to 32 bits mode
  694. */
  695. mfmsr r11
  696. li r12,1
  697. rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
  698. andc r11,r11,r12
  699. li r12,1
  700. rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
  701. andc r11,r11,r12
  702. mtmsrd r11
  703. isync
  704. /* Restore arguments & enter PROM here... */
  705. ld r3,GPR3(r1)
  706. blrl
  707. /* Just make sure that r1 top 32 bits didn't get
  708. * corrupt by OF
  709. */
  710. rldicl r1,r1,0,32
  711. /* Restore the MSR (back to 64 bits) */
  712. ld r0,_MSR(r1)
  713. mtmsrd r0
  714. isync
  715. /* Restore other registers */
  716. REST_GPR(2, r1)
  717. REST_GPR(13, r1)
  718. REST_8GPRS(14, r1)
  719. REST_10GPRS(22, r1)
  720. ld r4,_CCR(r1)
  721. mtcr r4
  722. ld r5,_CTR(r1)
  723. mtctr r5
  724. ld r6,_XER(r1)
  725. mtspr XER,r6
  726. ld r7,_DAR(r1)
  727. mtdar r7
  728. ld r8,_DSISR(r1)
  729. mtdsisr r8
  730. ld r9,_SRR0(r1)
  731. mtsrr0 r9
  732. ld r10,_SRR1(r1)
  733. mtsrr1 r10
  734. addi r1,r1,PROM_FRAME_SIZE
  735. ld r0,16(r1)
  736. mtlr r0
  737. blr
  738. #endif /* CONFIG_PPC_MULTIPLATFORM */