entry_32.S 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@fsmlabs.com) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@fsmlabs.com>
  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. */
  21. #include <linux/errno.h>
  22. #include <linux/sys.h>
  23. #include <linux/threads.h>
  24. #include <asm/reg.h>
  25. #include <asm/page.h>
  26. #include <asm/mmu.h>
  27. #include <asm/cputable.h>
  28. #include <asm/thread_info.h>
  29. #include <asm/ppc_asm.h>
  30. #include <asm/asm-offsets.h>
  31. #include <asm/unistd.h>
  32. #undef SHOW_SYSCALLS
  33. #undef SHOW_SYSCALLS_TASK
  34. /*
  35. * MSR_KERNEL is > 0x10000 on 4xx/Book-E since it include MSR_CE.
  36. */
  37. #if MSR_KERNEL >= 0x10000
  38. #define LOAD_MSR_KERNEL(r, x) lis r,(x)@h; ori r,r,(x)@l
  39. #else
  40. #define LOAD_MSR_KERNEL(r, x) li r,(x)
  41. #endif
  42. #ifdef CONFIG_BOOKE
  43. .globl mcheck_transfer_to_handler
  44. mcheck_transfer_to_handler:
  45. mfspr r0,SPRN_DSRR0
  46. stw r0,_DSRR0(r11)
  47. mfspr r0,SPRN_DSRR1
  48. stw r0,_DSRR1(r11)
  49. /* fall through */
  50. .globl debug_transfer_to_handler
  51. debug_transfer_to_handler:
  52. mfspr r0,SPRN_CSRR0
  53. stw r0,_CSRR0(r11)
  54. mfspr r0,SPRN_CSRR1
  55. stw r0,_CSRR1(r11)
  56. /* fall through */
  57. .globl crit_transfer_to_handler
  58. crit_transfer_to_handler:
  59. #ifdef CONFIG_FSL_BOOKE
  60. mfspr r0,SPRN_MAS0
  61. stw r0,MAS0(r11)
  62. mfspr r0,SPRN_MAS1
  63. stw r0,MAS1(r11)
  64. mfspr r0,SPRN_MAS2
  65. stw r0,MAS2(r11)
  66. mfspr r0,SPRN_MAS3
  67. stw r0,MAS3(r11)
  68. mfspr r0,SPRN_MAS6
  69. stw r0,MAS6(r11)
  70. #ifdef CONFIG_PHYS_64BIT
  71. mfspr r0,SPRN_MAS7
  72. stw r0,MAS7(r11)
  73. #endif /* CONFIG_PHYS_64BIT */
  74. #endif /* CONFIG_FSL_BOOKE */
  75. #ifdef CONFIG_44x
  76. mfspr r0,SPRN_MMUCR
  77. stw r0,MMUCR(r11)
  78. #endif
  79. mfspr r0,SPRN_SRR0
  80. stw r0,_SRR0(r11)
  81. mfspr r0,SPRN_SRR1
  82. stw r0,_SRR1(r11)
  83. mfspr r8,SPRN_SPRG3
  84. lwz r0,KSP_LIMIT(r8)
  85. stw r0,SAVED_KSP_LIMIT(r11)
  86. rlwimi r0,r1,0,0,(31-THREAD_SHIFT)
  87. stw r0,KSP_LIMIT(r8)
  88. /* fall through */
  89. #endif
  90. #ifdef CONFIG_40x
  91. .globl crit_transfer_to_handler
  92. crit_transfer_to_handler:
  93. lwz r0,crit_r10@l(0)
  94. stw r0,GPR10(r11)
  95. lwz r0,crit_r11@l(0)
  96. stw r0,GPR11(r11)
  97. mfspr r0,SPRN_SRR0
  98. stw r0,crit_srr0@l(0)
  99. mfspr r0,SPRN_SRR1
  100. stw r0,crit_srr1@l(0)
  101. mfspr r8,SPRN_SPRG3
  102. lwz r0,KSP_LIMIT(r8)
  103. stw r0,saved_ksp_limit@l(0)
  104. rlwimi r0,r1,0,0,(31-THREAD_SHIFT)
  105. stw r0,KSP_LIMIT(r8)
  106. /* fall through */
  107. #endif
  108. /*
  109. * This code finishes saving the registers to the exception frame
  110. * and jumps to the appropriate handler for the exception, turning
  111. * on address translation.
  112. * Note that we rely on the caller having set cr0.eq iff the exception
  113. * occurred in kernel mode (i.e. MSR:PR = 0).
  114. */
  115. .globl transfer_to_handler_full
  116. transfer_to_handler_full:
  117. SAVE_NVGPRS(r11)
  118. /* fall through */
  119. .globl transfer_to_handler
  120. transfer_to_handler:
  121. stw r2,GPR2(r11)
  122. stw r12,_NIP(r11)
  123. stw r9,_MSR(r11)
  124. andi. r2,r9,MSR_PR
  125. mfctr r12
  126. mfspr r2,SPRN_XER
  127. stw r12,_CTR(r11)
  128. stw r2,_XER(r11)
  129. mfspr r12,SPRN_SPRG3
  130. addi r2,r12,-THREAD
  131. tovirt(r2,r2) /* set r2 to current */
  132. beq 2f /* if from user, fix up THREAD.regs */
  133. addi r11,r1,STACK_FRAME_OVERHEAD
  134. stw r11,PT_REGS(r12)
  135. #if defined(CONFIG_40x) || defined(CONFIG_BOOKE)
  136. /* Check to see if the dbcr0 register is set up to debug. Use the
  137. internal debug mode bit to do this. */
  138. lwz r12,THREAD_DBCR0(r12)
  139. andis. r12,r12,DBCR0_IDM@h
  140. beq+ 3f
  141. /* From user and task is ptraced - load up global dbcr0 */
  142. li r12,-1 /* clear all pending debug events */
  143. mtspr SPRN_DBSR,r12
  144. lis r11,global_dbcr0@ha
  145. tophys(r11,r11)
  146. addi r11,r11,global_dbcr0@l
  147. #ifdef CONFIG_SMP
  148. rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
  149. lwz r9,TI_CPU(r9)
  150. slwi r9,r9,3
  151. add r11,r11,r9
  152. #endif
  153. lwz r12,0(r11)
  154. mtspr SPRN_DBCR0,r12
  155. lwz r12,4(r11)
  156. addi r12,r12,-1
  157. stw r12,4(r11)
  158. #endif
  159. b 3f
  160. 2: /* if from kernel, check interrupted DOZE/NAP mode and
  161. * check for stack overflow
  162. */
  163. lwz r9,KSP_LIMIT(r12)
  164. cmplw r1,r9 /* if r1 <= ksp_limit */
  165. ble- stack_ovf /* then the kernel stack overflowed */
  166. 5:
  167. #if defined(CONFIG_6xx) || defined(CONFIG_E500)
  168. rlwinm r9,r1,0,0,31-THREAD_SHIFT
  169. tophys(r9,r9) /* check local flags */
  170. lwz r12,TI_LOCAL_FLAGS(r9)
  171. mtcrf 0x01,r12
  172. bt- 31-TLF_NAPPING,4f
  173. bt- 31-TLF_SLEEPING,7f
  174. #endif /* CONFIG_6xx || CONFIG_E500 */
  175. .globl transfer_to_handler_cont
  176. transfer_to_handler_cont:
  177. 3:
  178. mflr r9
  179. lwz r11,0(r9) /* virtual address of handler */
  180. lwz r9,4(r9) /* where to go when done */
  181. mtspr SPRN_SRR0,r11
  182. mtspr SPRN_SRR1,r10
  183. mtlr r9
  184. SYNC
  185. RFI /* jump to handler, enable MMU */
  186. #if defined (CONFIG_6xx) || defined(CONFIG_E500)
  187. 4: rlwinm r12,r12,0,~_TLF_NAPPING
  188. stw r12,TI_LOCAL_FLAGS(r9)
  189. b power_save_ppc32_restore
  190. 7: rlwinm r12,r12,0,~_TLF_SLEEPING
  191. stw r12,TI_LOCAL_FLAGS(r9)
  192. lwz r9,_MSR(r11) /* if sleeping, clear MSR.EE */
  193. rlwinm r9,r9,0,~MSR_EE
  194. lwz r12,_LINK(r11) /* and return to address in LR */
  195. b fast_exception_return
  196. #endif
  197. /*
  198. * On kernel stack overflow, load up an initial stack pointer
  199. * and call StackOverflow(regs), which should not return.
  200. */
  201. stack_ovf:
  202. /* sometimes we use a statically-allocated stack, which is OK. */
  203. lis r12,_end@h
  204. ori r12,r12,_end@l
  205. cmplw r1,r12
  206. ble 5b /* r1 <= &_end is OK */
  207. SAVE_NVGPRS(r11)
  208. addi r3,r1,STACK_FRAME_OVERHEAD
  209. lis r1,init_thread_union@ha
  210. addi r1,r1,init_thread_union@l
  211. addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
  212. lis r9,StackOverflow@ha
  213. addi r9,r9,StackOverflow@l
  214. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  215. FIX_SRR1(r10,r12)
  216. mtspr SPRN_SRR0,r9
  217. mtspr SPRN_SRR1,r10
  218. SYNC
  219. RFI
  220. /*
  221. * Handle a system call.
  222. */
  223. .stabs "arch/powerpc/kernel/",N_SO,0,0,0f
  224. .stabs "entry_32.S",N_SO,0,0,0f
  225. 0:
  226. _GLOBAL(DoSyscall)
  227. stw r3,ORIG_GPR3(r1)
  228. li r12,0
  229. stw r12,RESULT(r1)
  230. lwz r11,_CCR(r1) /* Clear SO bit in CR */
  231. rlwinm r11,r11,0,4,2
  232. stw r11,_CCR(r1)
  233. #ifdef SHOW_SYSCALLS
  234. bl do_show_syscall
  235. #endif /* SHOW_SYSCALLS */
  236. rlwinm r10,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */
  237. lwz r11,TI_FLAGS(r10)
  238. andi. r11,r11,_TIF_SYSCALL_T_OR_A
  239. bne- syscall_dotrace
  240. syscall_dotrace_cont:
  241. cmplwi 0,r0,NR_syscalls
  242. lis r10,sys_call_table@h
  243. ori r10,r10,sys_call_table@l
  244. slwi r0,r0,2
  245. bge- 66f
  246. lwzx r10,r10,r0 /* Fetch system call handler [ptr] */
  247. mtlr r10
  248. addi r9,r1,STACK_FRAME_OVERHEAD
  249. PPC440EP_ERR42
  250. blrl /* Call handler */
  251. .globl ret_from_syscall
  252. ret_from_syscall:
  253. #ifdef SHOW_SYSCALLS
  254. bl do_show_syscall_exit
  255. #endif
  256. mr r6,r3
  257. rlwinm r12,r1,0,0,(31-THREAD_SHIFT) /* current_thread_info() */
  258. /* disable interrupts so current_thread_info()->flags can't change */
  259. LOAD_MSR_KERNEL(r10,MSR_KERNEL) /* doesn't include MSR_EE */
  260. SYNC
  261. MTMSRD(r10)
  262. lwz r9,TI_FLAGS(r12)
  263. li r8,-_LAST_ERRNO
  264. andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
  265. bne- syscall_exit_work
  266. cmplw 0,r3,r8
  267. blt+ syscall_exit_cont
  268. lwz r11,_CCR(r1) /* Load CR */
  269. neg r3,r3
  270. oris r11,r11,0x1000 /* Set SO bit in CR */
  271. stw r11,_CCR(r1)
  272. syscall_exit_cont:
  273. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  274. /* If the process has its own DBCR0 value, load it up. The internal
  275. debug mode bit tells us that dbcr0 should be loaded. */
  276. lwz r0,THREAD+THREAD_DBCR0(r2)
  277. andis. r10,r0,DBCR0_IDM@h
  278. bnel- load_dbcr0
  279. #endif
  280. #ifdef CONFIG_44x
  281. lis r4,icache_44x_need_flush@ha
  282. lwz r5,icache_44x_need_flush@l(r4)
  283. cmplwi cr0,r5,0
  284. bne- 2f
  285. 1:
  286. #endif /* CONFIG_44x */
  287. BEGIN_FTR_SECTION
  288. lwarx r7,0,r1
  289. END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
  290. stwcx. r0,0,r1 /* to clear the reservation */
  291. lwz r4,_LINK(r1)
  292. lwz r5,_CCR(r1)
  293. mtlr r4
  294. mtcr r5
  295. lwz r7,_NIP(r1)
  296. lwz r8,_MSR(r1)
  297. FIX_SRR1(r8, r0)
  298. lwz r2,GPR2(r1)
  299. lwz r1,GPR1(r1)
  300. mtspr SPRN_SRR0,r7
  301. mtspr SPRN_SRR1,r8
  302. SYNC
  303. RFI
  304. #ifdef CONFIG_44x
  305. 2: li r7,0
  306. iccci r0,r0
  307. stw r7,icache_44x_need_flush@l(r4)
  308. b 1b
  309. #endif /* CONFIG_44x */
  310. 66: li r3,-ENOSYS
  311. b ret_from_syscall
  312. .globl ret_from_fork
  313. ret_from_fork:
  314. REST_NVGPRS(r1)
  315. bl schedule_tail
  316. li r3,0
  317. b ret_from_syscall
  318. /* Traced system call support */
  319. syscall_dotrace:
  320. SAVE_NVGPRS(r1)
  321. li r0,0xc00
  322. stw r0,_TRAP(r1)
  323. addi r3,r1,STACK_FRAME_OVERHEAD
  324. bl do_syscall_trace_enter
  325. lwz r0,GPR0(r1) /* Restore original registers */
  326. lwz r3,GPR3(r1)
  327. lwz r4,GPR4(r1)
  328. lwz r5,GPR5(r1)
  329. lwz r6,GPR6(r1)
  330. lwz r7,GPR7(r1)
  331. lwz r8,GPR8(r1)
  332. REST_NVGPRS(r1)
  333. b syscall_dotrace_cont
  334. syscall_exit_work:
  335. andi. r0,r9,_TIF_RESTOREALL
  336. beq+ 0f
  337. REST_NVGPRS(r1)
  338. b 2f
  339. 0: cmplw 0,r3,r8
  340. blt+ 1f
  341. andi. r0,r9,_TIF_NOERROR
  342. bne- 1f
  343. lwz r11,_CCR(r1) /* Load CR */
  344. neg r3,r3
  345. oris r11,r11,0x1000 /* Set SO bit in CR */
  346. stw r11,_CCR(r1)
  347. 1: stw r6,RESULT(r1) /* Save result */
  348. stw r3,GPR3(r1) /* Update return value */
  349. 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
  350. beq 4f
  351. /* Clear per-syscall TIF flags if any are set. */
  352. li r11,_TIF_PERSYSCALL_MASK
  353. addi r12,r12,TI_FLAGS
  354. 3: lwarx r8,0,r12
  355. andc r8,r8,r11
  356. #ifdef CONFIG_IBM405_ERR77
  357. dcbt 0,r12
  358. #endif
  359. stwcx. r8,0,r12
  360. bne- 3b
  361. subi r12,r12,TI_FLAGS
  362. 4: /* Anything which requires enabling interrupts? */
  363. andi. r0,r9,(_TIF_SYSCALL_T_OR_A|_TIF_SINGLESTEP)
  364. beq ret_from_except
  365. /* Re-enable interrupts */
  366. ori r10,r10,MSR_EE
  367. SYNC
  368. MTMSRD(r10)
  369. /* Save NVGPRS if they're not saved already */
  370. lwz r4,_TRAP(r1)
  371. andi. r4,r4,1
  372. beq 5f
  373. SAVE_NVGPRS(r1)
  374. li r4,0xc00
  375. stw r4,_TRAP(r1)
  376. 5:
  377. addi r3,r1,STACK_FRAME_OVERHEAD
  378. bl do_syscall_trace_leave
  379. b ret_from_except_full
  380. #ifdef SHOW_SYSCALLS
  381. do_show_syscall:
  382. #ifdef SHOW_SYSCALLS_TASK
  383. lis r11,show_syscalls_task@ha
  384. lwz r11,show_syscalls_task@l(r11)
  385. cmp 0,r2,r11
  386. bnelr
  387. #endif
  388. stw r31,GPR31(r1)
  389. mflr r31
  390. lis r3,7f@ha
  391. addi r3,r3,7f@l
  392. lwz r4,GPR0(r1)
  393. lwz r5,GPR3(r1)
  394. lwz r6,GPR4(r1)
  395. lwz r7,GPR5(r1)
  396. lwz r8,GPR6(r1)
  397. lwz r9,GPR7(r1)
  398. bl printk
  399. lis r3,77f@ha
  400. addi r3,r3,77f@l
  401. lwz r4,GPR8(r1)
  402. mr r5,r2
  403. bl printk
  404. lwz r0,GPR0(r1)
  405. lwz r3,GPR3(r1)
  406. lwz r4,GPR4(r1)
  407. lwz r5,GPR5(r1)
  408. lwz r6,GPR6(r1)
  409. lwz r7,GPR7(r1)
  410. lwz r8,GPR8(r1)
  411. mtlr r31
  412. lwz r31,GPR31(r1)
  413. blr
  414. do_show_syscall_exit:
  415. #ifdef SHOW_SYSCALLS_TASK
  416. lis r11,show_syscalls_task@ha
  417. lwz r11,show_syscalls_task@l(r11)
  418. cmp 0,r2,r11
  419. bnelr
  420. #endif
  421. stw r31,GPR31(r1)
  422. mflr r31
  423. stw r3,RESULT(r1) /* Save result */
  424. mr r4,r3
  425. lis r3,79f@ha
  426. addi r3,r3,79f@l
  427. bl printk
  428. lwz r3,RESULT(r1)
  429. mtlr r31
  430. lwz r31,GPR31(r1)
  431. blr
  432. 7: .string "syscall %d(%x, %x, %x, %x, %x, "
  433. 77: .string "%x), current=%p\n"
  434. 79: .string " -> %x\n"
  435. .align 2,0
  436. #ifdef SHOW_SYSCALLS_TASK
  437. .data
  438. .globl show_syscalls_task
  439. show_syscalls_task:
  440. .long -1
  441. .text
  442. #endif
  443. #endif /* SHOW_SYSCALLS */
  444. /*
  445. * The fork/clone functions need to copy the full register set into
  446. * the child process. Therefore we need to save all the nonvolatile
  447. * registers (r13 - r31) before calling the C code.
  448. */
  449. .globl ppc_fork
  450. ppc_fork:
  451. SAVE_NVGPRS(r1)
  452. lwz r0,_TRAP(r1)
  453. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  454. stw r0,_TRAP(r1) /* register set saved */
  455. b sys_fork
  456. .globl ppc_vfork
  457. ppc_vfork:
  458. SAVE_NVGPRS(r1)
  459. lwz r0,_TRAP(r1)
  460. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  461. stw r0,_TRAP(r1) /* register set saved */
  462. b sys_vfork
  463. .globl ppc_clone
  464. ppc_clone:
  465. SAVE_NVGPRS(r1)
  466. lwz r0,_TRAP(r1)
  467. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  468. stw r0,_TRAP(r1) /* register set saved */
  469. b sys_clone
  470. .globl ppc_swapcontext
  471. ppc_swapcontext:
  472. SAVE_NVGPRS(r1)
  473. lwz r0,_TRAP(r1)
  474. rlwinm r0,r0,0,0,30 /* clear LSB to indicate full */
  475. stw r0,_TRAP(r1) /* register set saved */
  476. b sys_swapcontext
  477. /*
  478. * Top-level page fault handling.
  479. * This is in assembler because if do_page_fault tells us that
  480. * it is a bad kernel page fault, we want to save the non-volatile
  481. * registers before calling bad_page_fault.
  482. */
  483. .globl handle_page_fault
  484. handle_page_fault:
  485. stw r4,_DAR(r1)
  486. addi r3,r1,STACK_FRAME_OVERHEAD
  487. bl do_page_fault
  488. cmpwi r3,0
  489. beq+ ret_from_except
  490. SAVE_NVGPRS(r1)
  491. lwz r0,_TRAP(r1)
  492. clrrwi r0,r0,1
  493. stw r0,_TRAP(r1)
  494. mr r5,r3
  495. addi r3,r1,STACK_FRAME_OVERHEAD
  496. lwz r4,_DAR(r1)
  497. bl bad_page_fault
  498. b ret_from_except_full
  499. /*
  500. * This routine switches between two different tasks. The process
  501. * state of one is saved on its kernel stack. Then the state
  502. * of the other is restored from its kernel stack. The memory
  503. * management hardware is updated to the second process's state.
  504. * Finally, we can return to the second process.
  505. * On entry, r3 points to the THREAD for the current task, r4
  506. * points to the THREAD for the new task.
  507. *
  508. * This routine is always called with interrupts disabled.
  509. *
  510. * Note: there are two ways to get to the "going out" portion
  511. * of this code; either by coming in via the entry (_switch)
  512. * or via "fork" which must set up an environment equivalent
  513. * to the "_switch" path. If you change this , you'll have to
  514. * change the fork code also.
  515. *
  516. * The code which creates the new task context is in 'copy_thread'
  517. * in arch/ppc/kernel/process.c
  518. */
  519. _GLOBAL(_switch)
  520. stwu r1,-INT_FRAME_SIZE(r1)
  521. mflr r0
  522. stw r0,INT_FRAME_SIZE+4(r1)
  523. /* r3-r12 are caller saved -- Cort */
  524. SAVE_NVGPRS(r1)
  525. stw r0,_NIP(r1) /* Return to switch caller */
  526. mfmsr r11
  527. li r0,MSR_FP /* Disable floating-point */
  528. #ifdef CONFIG_ALTIVEC
  529. BEGIN_FTR_SECTION
  530. oris r0,r0,MSR_VEC@h /* Disable altivec */
  531. mfspr r12,SPRN_VRSAVE /* save vrsave register value */
  532. stw r12,THREAD+THREAD_VRSAVE(r2)
  533. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  534. #endif /* CONFIG_ALTIVEC */
  535. #ifdef CONFIG_SPE
  536. BEGIN_FTR_SECTION
  537. oris r0,r0,MSR_SPE@h /* Disable SPE */
  538. mfspr r12,SPRN_SPEFSCR /* save spefscr register value */
  539. stw r12,THREAD+THREAD_SPEFSCR(r2)
  540. END_FTR_SECTION_IFSET(CPU_FTR_SPE)
  541. #endif /* CONFIG_SPE */
  542. and. r0,r0,r11 /* FP or altivec or SPE enabled? */
  543. beq+ 1f
  544. andc r11,r11,r0
  545. MTMSRD(r11)
  546. isync
  547. 1: stw r11,_MSR(r1)
  548. mfcr r10
  549. stw r10,_CCR(r1)
  550. stw r1,KSP(r3) /* Set old stack pointer */
  551. #ifdef CONFIG_SMP
  552. /* We need a sync somewhere here to make sure that if the
  553. * previous task gets rescheduled on another CPU, it sees all
  554. * stores it has performed on this one.
  555. */
  556. sync
  557. #endif /* CONFIG_SMP */
  558. tophys(r0,r4)
  559. CLR_TOP32(r0)
  560. mtspr SPRN_SPRG3,r0 /* Update current THREAD phys addr */
  561. lwz r1,KSP(r4) /* Load new stack pointer */
  562. /* save the old current 'last' for return value */
  563. mr r3,r2
  564. addi r2,r4,-THREAD /* Update current */
  565. #ifdef CONFIG_ALTIVEC
  566. BEGIN_FTR_SECTION
  567. lwz r0,THREAD+THREAD_VRSAVE(r2)
  568. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  569. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  570. #endif /* CONFIG_ALTIVEC */
  571. #ifdef CONFIG_SPE
  572. BEGIN_FTR_SECTION
  573. lwz r0,THREAD+THREAD_SPEFSCR(r2)
  574. mtspr SPRN_SPEFSCR,r0 /* restore SPEFSCR reg */
  575. END_FTR_SECTION_IFSET(CPU_FTR_SPE)
  576. #endif /* CONFIG_SPE */
  577. lwz r0,_CCR(r1)
  578. mtcrf 0xFF,r0
  579. /* r3-r12 are destroyed -- Cort */
  580. REST_NVGPRS(r1)
  581. lwz r4,_NIP(r1) /* Return to _switch caller in new task */
  582. mtlr r4
  583. addi r1,r1,INT_FRAME_SIZE
  584. blr
  585. .globl fast_exception_return
  586. fast_exception_return:
  587. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  588. andi. r10,r9,MSR_RI /* check for recoverable interrupt */
  589. beq 1f /* if not, we've got problems */
  590. #endif
  591. 2: REST_4GPRS(3, r11)
  592. lwz r10,_CCR(r11)
  593. REST_GPR(1, r11)
  594. mtcr r10
  595. lwz r10,_LINK(r11)
  596. mtlr r10
  597. REST_GPR(10, r11)
  598. mtspr SPRN_SRR1,r9
  599. mtspr SPRN_SRR0,r12
  600. REST_GPR(9, r11)
  601. REST_GPR(12, r11)
  602. lwz r11,GPR11(r11)
  603. SYNC
  604. RFI
  605. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  606. /* check if the exception happened in a restartable section */
  607. 1: lis r3,exc_exit_restart_end@ha
  608. addi r3,r3,exc_exit_restart_end@l
  609. cmplw r12,r3
  610. bge 3f
  611. lis r4,exc_exit_restart@ha
  612. addi r4,r4,exc_exit_restart@l
  613. cmplw r12,r4
  614. blt 3f
  615. lis r3,fee_restarts@ha
  616. tophys(r3,r3)
  617. lwz r5,fee_restarts@l(r3)
  618. addi r5,r5,1
  619. stw r5,fee_restarts@l(r3)
  620. mr r12,r4 /* restart at exc_exit_restart */
  621. b 2b
  622. .section .bss
  623. .align 2
  624. fee_restarts:
  625. .space 4
  626. .previous
  627. /* aargh, a nonrecoverable interrupt, panic */
  628. /* aargh, we don't know which trap this is */
  629. /* but the 601 doesn't implement the RI bit, so assume it's OK */
  630. 3:
  631. BEGIN_FTR_SECTION
  632. b 2b
  633. END_FTR_SECTION_IFSET(CPU_FTR_601)
  634. li r10,-1
  635. stw r10,_TRAP(r11)
  636. addi r3,r1,STACK_FRAME_OVERHEAD
  637. lis r10,MSR_KERNEL@h
  638. ori r10,r10,MSR_KERNEL@l
  639. bl transfer_to_handler_full
  640. .long nonrecoverable_exception
  641. .long ret_from_except
  642. #endif
  643. .globl ret_from_except_full
  644. ret_from_except_full:
  645. REST_NVGPRS(r1)
  646. /* fall through */
  647. .globl ret_from_except
  648. ret_from_except:
  649. /* Hard-disable interrupts so that current_thread_info()->flags
  650. * can't change between when we test it and when we return
  651. * from the interrupt. */
  652. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  653. SYNC /* Some chip revs have problems here... */
  654. MTMSRD(r10) /* disable interrupts */
  655. lwz r3,_MSR(r1) /* Returning to user mode? */
  656. andi. r0,r3,MSR_PR
  657. beq resume_kernel
  658. user_exc_return: /* r10 contains MSR_KERNEL here */
  659. /* Check current_thread_info()->flags */
  660. rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
  661. lwz r9,TI_FLAGS(r9)
  662. andi. r0,r9,_TIF_USER_WORK_MASK
  663. bne do_work
  664. restore_user:
  665. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  666. /* Check whether this process has its own DBCR0 value. The internal
  667. debug mode bit tells us that dbcr0 should be loaded. */
  668. lwz r0,THREAD+THREAD_DBCR0(r2)
  669. andis. r10,r0,DBCR0_IDM@h
  670. bnel- load_dbcr0
  671. #endif
  672. #ifdef CONFIG_PREEMPT
  673. b restore
  674. /* N.B. the only way to get here is from the beq following ret_from_except. */
  675. resume_kernel:
  676. /* check current_thread_info->preempt_count */
  677. rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
  678. lwz r0,TI_PREEMPT(r9)
  679. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  680. bne restore
  681. lwz r0,TI_FLAGS(r9)
  682. andi. r0,r0,_TIF_NEED_RESCHED
  683. beq+ restore
  684. andi. r0,r3,MSR_EE /* interrupts off? */
  685. beq restore /* don't schedule if so */
  686. 1: bl preempt_schedule_irq
  687. rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
  688. lwz r3,TI_FLAGS(r9)
  689. andi. r0,r3,_TIF_NEED_RESCHED
  690. bne- 1b
  691. #else
  692. resume_kernel:
  693. #endif /* CONFIG_PREEMPT */
  694. /* interrupts are hard-disabled at this point */
  695. restore:
  696. #ifdef CONFIG_44x
  697. lis r4,icache_44x_need_flush@ha
  698. lwz r5,icache_44x_need_flush@l(r4)
  699. cmplwi cr0,r5,0
  700. beq+ 1f
  701. li r6,0
  702. iccci r0,r0
  703. stw r6,icache_44x_need_flush@l(r4)
  704. 1:
  705. #endif /* CONFIG_44x */
  706. lwz r0,GPR0(r1)
  707. lwz r2,GPR2(r1)
  708. REST_4GPRS(3, r1)
  709. REST_2GPRS(7, r1)
  710. lwz r10,_XER(r1)
  711. lwz r11,_CTR(r1)
  712. mtspr SPRN_XER,r10
  713. mtctr r11
  714. PPC405_ERR77(0,r1)
  715. BEGIN_FTR_SECTION
  716. lwarx r11,0,r1
  717. END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
  718. stwcx. r0,0,r1 /* to clear the reservation */
  719. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  720. lwz r9,_MSR(r1)
  721. andi. r10,r9,MSR_RI /* check if this exception occurred */
  722. beql nonrecoverable /* at a bad place (MSR:RI = 0) */
  723. lwz r10,_CCR(r1)
  724. lwz r11,_LINK(r1)
  725. mtcrf 0xFF,r10
  726. mtlr r11
  727. /*
  728. * Once we put values in SRR0 and SRR1, we are in a state
  729. * where exceptions are not recoverable, since taking an
  730. * exception will trash SRR0 and SRR1. Therefore we clear the
  731. * MSR:RI bit to indicate this. If we do take an exception,
  732. * we can't return to the point of the exception but we
  733. * can restart the exception exit path at the label
  734. * exc_exit_restart below. -- paulus
  735. */
  736. LOAD_MSR_KERNEL(r10,MSR_KERNEL & ~MSR_RI)
  737. SYNC
  738. MTMSRD(r10) /* clear the RI bit */
  739. .globl exc_exit_restart
  740. exc_exit_restart:
  741. lwz r9,_MSR(r1)
  742. lwz r12,_NIP(r1)
  743. FIX_SRR1(r9,r10)
  744. mtspr SPRN_SRR0,r12
  745. mtspr SPRN_SRR1,r9
  746. REST_4GPRS(9, r1)
  747. lwz r1,GPR1(r1)
  748. .globl exc_exit_restart_end
  749. exc_exit_restart_end:
  750. SYNC
  751. RFI
  752. #else /* !(CONFIG_4xx || CONFIG_BOOKE) */
  753. /*
  754. * This is a bit different on 4xx/Book-E because it doesn't have
  755. * the RI bit in the MSR.
  756. * The TLB miss handler checks if we have interrupted
  757. * the exception exit path and restarts it if so
  758. * (well maybe one day it will... :).
  759. */
  760. lwz r11,_LINK(r1)
  761. mtlr r11
  762. lwz r10,_CCR(r1)
  763. mtcrf 0xff,r10
  764. REST_2GPRS(9, r1)
  765. .globl exc_exit_restart
  766. exc_exit_restart:
  767. lwz r11,_NIP(r1)
  768. lwz r12,_MSR(r1)
  769. exc_exit_start:
  770. mtspr SPRN_SRR0,r11
  771. mtspr SPRN_SRR1,r12
  772. REST_2GPRS(11, r1)
  773. lwz r1,GPR1(r1)
  774. .globl exc_exit_restart_end
  775. exc_exit_restart_end:
  776. PPC405_ERR77_SYNC
  777. rfi
  778. b . /* prevent prefetch past rfi */
  779. /*
  780. * Returning from a critical interrupt in user mode doesn't need
  781. * to be any different from a normal exception. For a critical
  782. * interrupt in the kernel, we just return (without checking for
  783. * preemption) since the interrupt may have happened at some crucial
  784. * place (e.g. inside the TLB miss handler), and because we will be
  785. * running with r1 pointing into critical_stack, not the current
  786. * process's kernel stack (and therefore current_thread_info() will
  787. * give the wrong answer).
  788. * We have to restore various SPRs that may have been in use at the
  789. * time of the critical interrupt.
  790. *
  791. */
  792. #ifdef CONFIG_40x
  793. #define PPC_40x_TURN_OFF_MSR_DR \
  794. /* avoid any possible TLB misses here by turning off MSR.DR, we \
  795. * assume the instructions here are mapped by a pinned TLB entry */ \
  796. li r10,MSR_IR; \
  797. mtmsr r10; \
  798. isync; \
  799. tophys(r1, r1);
  800. #else
  801. #define PPC_40x_TURN_OFF_MSR_DR
  802. #endif
  803. #define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \
  804. REST_NVGPRS(r1); \
  805. lwz r3,_MSR(r1); \
  806. andi. r3,r3,MSR_PR; \
  807. LOAD_MSR_KERNEL(r10,MSR_KERNEL); \
  808. bne user_exc_return; \
  809. lwz r0,GPR0(r1); \
  810. lwz r2,GPR2(r1); \
  811. REST_4GPRS(3, r1); \
  812. REST_2GPRS(7, r1); \
  813. lwz r10,_XER(r1); \
  814. lwz r11,_CTR(r1); \
  815. mtspr SPRN_XER,r10; \
  816. mtctr r11; \
  817. PPC405_ERR77(0,r1); \
  818. stwcx. r0,0,r1; /* to clear the reservation */ \
  819. lwz r11,_LINK(r1); \
  820. mtlr r11; \
  821. lwz r10,_CCR(r1); \
  822. mtcrf 0xff,r10; \
  823. PPC_40x_TURN_OFF_MSR_DR; \
  824. lwz r9,_DEAR(r1); \
  825. lwz r10,_ESR(r1); \
  826. mtspr SPRN_DEAR,r9; \
  827. mtspr SPRN_ESR,r10; \
  828. lwz r11,_NIP(r1); \
  829. lwz r12,_MSR(r1); \
  830. mtspr exc_lvl_srr0,r11; \
  831. mtspr exc_lvl_srr1,r12; \
  832. lwz r9,GPR9(r1); \
  833. lwz r12,GPR12(r1); \
  834. lwz r10,GPR10(r1); \
  835. lwz r11,GPR11(r1); \
  836. lwz r1,GPR1(r1); \
  837. PPC405_ERR77_SYNC; \
  838. exc_lvl_rfi; \
  839. b .; /* prevent prefetch past exc_lvl_rfi */
  840. #define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \
  841. lwz r9,_##exc_lvl_srr0(r1); \
  842. lwz r10,_##exc_lvl_srr1(r1); \
  843. mtspr SPRN_##exc_lvl_srr0,r9; \
  844. mtspr SPRN_##exc_lvl_srr1,r10;
  845. #if defined(CONFIG_FSL_BOOKE)
  846. #ifdef CONFIG_PHYS_64BIT
  847. #define RESTORE_MAS7 \
  848. lwz r11,MAS7(r1); \
  849. mtspr SPRN_MAS7,r11;
  850. #else
  851. #define RESTORE_MAS7
  852. #endif /* CONFIG_PHYS_64BIT */
  853. #define RESTORE_MMU_REGS \
  854. lwz r9,MAS0(r1); \
  855. lwz r10,MAS1(r1); \
  856. lwz r11,MAS2(r1); \
  857. mtspr SPRN_MAS0,r9; \
  858. lwz r9,MAS3(r1); \
  859. mtspr SPRN_MAS1,r10; \
  860. lwz r10,MAS6(r1); \
  861. mtspr SPRN_MAS2,r11; \
  862. mtspr SPRN_MAS3,r9; \
  863. mtspr SPRN_MAS6,r10; \
  864. RESTORE_MAS7;
  865. #elif defined(CONFIG_44x)
  866. #define RESTORE_MMU_REGS \
  867. lwz r9,MMUCR(r1); \
  868. mtspr SPRN_MMUCR,r9;
  869. #else
  870. #define RESTORE_MMU_REGS
  871. #endif
  872. #ifdef CONFIG_40x
  873. .globl ret_from_crit_exc
  874. ret_from_crit_exc:
  875. mfspr r9,SPRN_SPRG3
  876. lis r10,saved_ksp_limit@ha;
  877. lwz r10,saved_ksp_limit@l(r10);
  878. tovirt(r9,r9);
  879. stw r10,KSP_LIMIT(r9)
  880. lis r9,crit_srr0@ha;
  881. lwz r9,crit_srr0@l(r9);
  882. lis r10,crit_srr1@ha;
  883. lwz r10,crit_srr1@l(r10);
  884. mtspr SPRN_SRR0,r9;
  885. mtspr SPRN_SRR1,r10;
  886. RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, RFCI)
  887. #endif /* CONFIG_40x */
  888. #ifdef CONFIG_BOOKE
  889. .globl ret_from_crit_exc
  890. ret_from_crit_exc:
  891. mfspr r9,SPRN_SPRG3
  892. lwz r10,SAVED_KSP_LIMIT(r1)
  893. stw r10,KSP_LIMIT(r9)
  894. RESTORE_xSRR(SRR0,SRR1);
  895. RESTORE_MMU_REGS;
  896. RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, RFCI)
  897. .globl ret_from_debug_exc
  898. ret_from_debug_exc:
  899. mfspr r9,SPRN_SPRG3
  900. lwz r10,SAVED_KSP_LIMIT(r1)
  901. stw r10,KSP_LIMIT(r9)
  902. lwz r9,THREAD_INFO-THREAD(r9)
  903. rlwinm r10,r1,0,0,(31-THREAD_SHIFT)
  904. lwz r10,TI_PREEMPT(r10)
  905. stw r10,TI_PREEMPT(r9)
  906. RESTORE_xSRR(SRR0,SRR1);
  907. RESTORE_xSRR(CSRR0,CSRR1);
  908. RESTORE_MMU_REGS;
  909. RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, RFDI)
  910. .globl ret_from_mcheck_exc
  911. ret_from_mcheck_exc:
  912. mfspr r9,SPRN_SPRG3
  913. lwz r10,SAVED_KSP_LIMIT(r1)
  914. stw r10,KSP_LIMIT(r9)
  915. RESTORE_xSRR(SRR0,SRR1);
  916. RESTORE_xSRR(CSRR0,CSRR1);
  917. RESTORE_xSRR(DSRR0,DSRR1);
  918. RESTORE_MMU_REGS;
  919. RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, RFMCI)
  920. #endif /* CONFIG_BOOKE */
  921. /*
  922. * Load the DBCR0 value for a task that is being ptraced,
  923. * having first saved away the global DBCR0. Note that r0
  924. * has the dbcr0 value to set upon entry to this.
  925. */
  926. load_dbcr0:
  927. mfmsr r10 /* first disable debug exceptions */
  928. rlwinm r10,r10,0,~MSR_DE
  929. mtmsr r10
  930. isync
  931. mfspr r10,SPRN_DBCR0
  932. lis r11,global_dbcr0@ha
  933. addi r11,r11,global_dbcr0@l
  934. #ifdef CONFIG_SMP
  935. rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
  936. lwz r9,TI_CPU(r9)
  937. slwi r9,r9,3
  938. add r11,r11,r9
  939. #endif
  940. stw r10,0(r11)
  941. mtspr SPRN_DBCR0,r0
  942. lwz r10,4(r11)
  943. addi r10,r10,1
  944. stw r10,4(r11)
  945. li r11,-1
  946. mtspr SPRN_DBSR,r11 /* clear all pending debug events */
  947. blr
  948. .section .bss
  949. .align 4
  950. global_dbcr0:
  951. .space 8*NR_CPUS
  952. .previous
  953. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  954. do_work: /* r10 contains MSR_KERNEL here */
  955. andi. r0,r9,_TIF_NEED_RESCHED
  956. beq do_user_signal
  957. do_resched: /* r10 contains MSR_KERNEL here */
  958. ori r10,r10,MSR_EE
  959. SYNC
  960. MTMSRD(r10) /* hard-enable interrupts */
  961. bl schedule
  962. recheck:
  963. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  964. SYNC
  965. MTMSRD(r10) /* disable interrupts */
  966. rlwinm r9,r1,0,0,(31-THREAD_SHIFT)
  967. lwz r9,TI_FLAGS(r9)
  968. andi. r0,r9,_TIF_NEED_RESCHED
  969. bne- do_resched
  970. andi. r0,r9,_TIF_USER_WORK_MASK
  971. beq restore_user
  972. do_user_signal: /* r10 contains MSR_KERNEL here */
  973. ori r10,r10,MSR_EE
  974. SYNC
  975. MTMSRD(r10) /* hard-enable interrupts */
  976. /* save r13-r31 in the exception frame, if not already done */
  977. lwz r3,_TRAP(r1)
  978. andi. r0,r3,1
  979. beq 2f
  980. SAVE_NVGPRS(r1)
  981. rlwinm r3,r3,0,0,30
  982. stw r3,_TRAP(r1)
  983. 2: li r3,0
  984. addi r4,r1,STACK_FRAME_OVERHEAD
  985. bl do_signal
  986. REST_NVGPRS(r1)
  987. b recheck
  988. /*
  989. * We come here when we are at the end of handling an exception
  990. * that occurred at a place where taking an exception will lose
  991. * state information, such as the contents of SRR0 and SRR1.
  992. */
  993. nonrecoverable:
  994. lis r10,exc_exit_restart_end@ha
  995. addi r10,r10,exc_exit_restart_end@l
  996. cmplw r12,r10
  997. bge 3f
  998. lis r11,exc_exit_restart@ha
  999. addi r11,r11,exc_exit_restart@l
  1000. cmplw r12,r11
  1001. blt 3f
  1002. lis r10,ee_restarts@ha
  1003. lwz r12,ee_restarts@l(r10)
  1004. addi r12,r12,1
  1005. stw r12,ee_restarts@l(r10)
  1006. mr r12,r11 /* restart at exc_exit_restart */
  1007. blr
  1008. 3: /* OK, we can't recover, kill this process */
  1009. /* but the 601 doesn't implement the RI bit, so assume it's OK */
  1010. BEGIN_FTR_SECTION
  1011. blr
  1012. END_FTR_SECTION_IFSET(CPU_FTR_601)
  1013. lwz r3,_TRAP(r1)
  1014. andi. r0,r3,1
  1015. beq 4f
  1016. SAVE_NVGPRS(r1)
  1017. rlwinm r3,r3,0,0,30
  1018. stw r3,_TRAP(r1)
  1019. 4: addi r3,r1,STACK_FRAME_OVERHEAD
  1020. bl nonrecoverable_exception
  1021. /* shouldn't return */
  1022. b 4b
  1023. .section .bss
  1024. .align 2
  1025. ee_restarts:
  1026. .space 4
  1027. .previous
  1028. /*
  1029. * PROM code for specific machines follows. Put it
  1030. * here so it's easy to add arch-specific sections later.
  1031. * -- Cort
  1032. */
  1033. #ifdef CONFIG_PPC_RTAS
  1034. /*
  1035. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  1036. * called with the MMU off.
  1037. */
  1038. _GLOBAL(enter_rtas)
  1039. stwu r1,-INT_FRAME_SIZE(r1)
  1040. mflr r0
  1041. stw r0,INT_FRAME_SIZE+4(r1)
  1042. LOAD_REG_ADDR(r4, rtas)
  1043. lis r6,1f@ha /* physical return address for rtas */
  1044. addi r6,r6,1f@l
  1045. tophys(r6,r6)
  1046. tophys(r7,r1)
  1047. lwz r8,RTASENTRY(r4)
  1048. lwz r4,RTASBASE(r4)
  1049. mfmsr r9
  1050. stw r9,8(r1)
  1051. LOAD_MSR_KERNEL(r0,MSR_KERNEL)
  1052. SYNC /* disable interrupts so SRR0/1 */
  1053. MTMSRD(r0) /* don't get trashed */
  1054. li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  1055. mtlr r6
  1056. mtspr SPRN_SPRG2,r7
  1057. mtspr SPRN_SRR0,r8
  1058. mtspr SPRN_SRR1,r9
  1059. RFI
  1060. 1: tophys(r9,r1)
  1061. lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
  1062. lwz r9,8(r9) /* original msr value */
  1063. FIX_SRR1(r9,r0)
  1064. addi r1,r1,INT_FRAME_SIZE
  1065. li r0,0
  1066. mtspr SPRN_SPRG2,r0
  1067. mtspr SPRN_SRR0,r8
  1068. mtspr SPRN_SRR1,r9
  1069. RFI /* return to caller */
  1070. .globl machine_check_in_rtas
  1071. machine_check_in_rtas:
  1072. twi 31,0,0
  1073. /* XXX load up BATs and panic */
  1074. #endif /* CONFIG_PPC_RTAS */