entry_64.S 20 KB

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