entry_64.S 19 KB

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