entry_32.S 35 KB

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