entry_32.S 35 KB

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