entry_32.S 29 KB

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