entry_32.S 35 KB

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