entry_64.S 19 KB

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