entry_64.S 18 KB

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