entry_64.S 19 KB

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