entry_32.S 34 KB

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