entry_32.S 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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. /* Clear the exception_marker on the stack to avoid confusing stacktrace */
  701. li r10, 0
  702. stw r10, 8(r11)
  703. REST_GPR(10, r11)
  704. #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
  705. mtspr SPRN_NRI, r0
  706. #endif
  707. mtspr SPRN_SRR1,r9
  708. mtspr SPRN_SRR0,r12
  709. REST_GPR(9, r11)
  710. REST_GPR(12, r11)
  711. lwz r11,GPR11(r11)
  712. SYNC
  713. RFI
  714. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  715. /* check if the exception happened in a restartable section */
  716. 1: lis r3,exc_exit_restart_end@ha
  717. addi r3,r3,exc_exit_restart_end@l
  718. cmplw r12,r3
  719. bge 3f
  720. lis r4,exc_exit_restart@ha
  721. addi r4,r4,exc_exit_restart@l
  722. cmplw r12,r4
  723. blt 3f
  724. lis r3,fee_restarts@ha
  725. tophys(r3,r3)
  726. lwz r5,fee_restarts@l(r3)
  727. addi r5,r5,1
  728. stw r5,fee_restarts@l(r3)
  729. mr r12,r4 /* restart at exc_exit_restart */
  730. b 2b
  731. .section .bss
  732. .align 2
  733. fee_restarts:
  734. .space 4
  735. .previous
  736. /* aargh, a nonrecoverable interrupt, panic */
  737. /* aargh, we don't know which trap this is */
  738. /* but the 601 doesn't implement the RI bit, so assume it's OK */
  739. 3:
  740. BEGIN_FTR_SECTION
  741. b 2b
  742. END_FTR_SECTION_IFSET(CPU_FTR_601)
  743. li r10,-1
  744. stw r10,_TRAP(r11)
  745. addi r3,r1,STACK_FRAME_OVERHEAD
  746. lis r10,MSR_KERNEL@h
  747. ori r10,r10,MSR_KERNEL@l
  748. bl transfer_to_handler_full
  749. .long nonrecoverable_exception
  750. .long ret_from_except
  751. #endif
  752. .globl ret_from_except_full
  753. ret_from_except_full:
  754. REST_NVGPRS(r1)
  755. /* fall through */
  756. .globl ret_from_except
  757. ret_from_except:
  758. /* Hard-disable interrupts so that current_thread_info()->flags
  759. * can't change between when we test it and when we return
  760. * from the interrupt. */
  761. /* Note: We don't bother telling lockdep about it */
  762. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  763. SYNC /* Some chip revs have problems here... */
  764. MTMSRD(r10) /* disable interrupts */
  765. lwz r3,_MSR(r1) /* Returning to user mode? */
  766. andi. r0,r3,MSR_PR
  767. beq resume_kernel
  768. user_exc_return: /* r10 contains MSR_KERNEL here */
  769. /* Check current_thread_info()->flags */
  770. CURRENT_THREAD_INFO(r9, r1)
  771. lwz r9,TI_FLAGS(r9)
  772. andi. r0,r9,_TIF_USER_WORK_MASK
  773. bne do_work
  774. restore_user:
  775. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  776. /* Check whether this process has its own DBCR0 value. The internal
  777. debug mode bit tells us that dbcr0 should be loaded. */
  778. lwz r0,THREAD+THREAD_DBCR0(r2)
  779. andis. r10,r0,DBCR0_IDM@h
  780. bnel- load_dbcr0
  781. #endif
  782. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
  783. CURRENT_THREAD_INFO(r9, r1)
  784. ACCOUNT_CPU_USER_EXIT(r9, r10, r11)
  785. #endif
  786. b restore
  787. /* N.B. the only way to get here is from the beq following ret_from_except. */
  788. resume_kernel:
  789. /* check current_thread_info, _TIF_EMULATE_STACK_STORE */
  790. CURRENT_THREAD_INFO(r9, r1)
  791. lwz r8,TI_FLAGS(r9)
  792. andis. r0,r8,_TIF_EMULATE_STACK_STORE@h
  793. beq+ 1f
  794. addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
  795. lwz r3,GPR1(r1)
  796. subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
  797. mr r4,r1 /* src: current exception frame */
  798. mr r1,r3 /* Reroute the trampoline frame to r1 */
  799. /* Copy from the original to the trampoline. */
  800. li r5,INT_FRAME_SIZE/4 /* size: INT_FRAME_SIZE */
  801. li r6,0 /* start offset: 0 */
  802. mtctr r5
  803. 2: lwzx r0,r6,r4
  804. stwx r0,r6,r3
  805. addi r6,r6,4
  806. bdnz 2b
  807. /* Do real store operation to complete stwu */
  808. lwz r5,GPR1(r1)
  809. stw r8,0(r5)
  810. /* Clear _TIF_EMULATE_STACK_STORE flag */
  811. lis r11,_TIF_EMULATE_STACK_STORE@h
  812. addi r5,r9,TI_FLAGS
  813. 0: lwarx r8,0,r5
  814. andc r8,r8,r11
  815. #ifdef CONFIG_IBM405_ERR77
  816. dcbt 0,r5
  817. #endif
  818. stwcx. r8,0,r5
  819. bne- 0b
  820. 1:
  821. #ifdef CONFIG_PREEMPT
  822. /* check current_thread_info->preempt_count */
  823. lwz r0,TI_PREEMPT(r9)
  824. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  825. bne restore
  826. andi. r8,r8,_TIF_NEED_RESCHED
  827. beq+ restore
  828. lwz r3,_MSR(r1)
  829. andi. r0,r3,MSR_EE /* interrupts off? */
  830. beq restore /* don't schedule if so */
  831. #ifdef CONFIG_TRACE_IRQFLAGS
  832. /* Lockdep thinks irqs are enabled, we need to call
  833. * preempt_schedule_irq with IRQs off, so we inform lockdep
  834. * now that we -did- turn them off already
  835. */
  836. bl trace_hardirqs_off
  837. #endif
  838. 1: bl preempt_schedule_irq
  839. CURRENT_THREAD_INFO(r9, r1)
  840. lwz r3,TI_FLAGS(r9)
  841. andi. r0,r3,_TIF_NEED_RESCHED
  842. bne- 1b
  843. #ifdef CONFIG_TRACE_IRQFLAGS
  844. /* And now, to properly rebalance the above, we tell lockdep they
  845. * are being turned back on, which will happen when we return
  846. */
  847. bl trace_hardirqs_on
  848. #endif
  849. #endif /* CONFIG_PREEMPT */
  850. /* interrupts are hard-disabled at this point */
  851. restore:
  852. #ifdef CONFIG_44x
  853. BEGIN_MMU_FTR_SECTION
  854. b 1f
  855. END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_47x)
  856. lis r4,icache_44x_need_flush@ha
  857. lwz r5,icache_44x_need_flush@l(r4)
  858. cmplwi cr0,r5,0
  859. beq+ 1f
  860. li r6,0
  861. iccci r0,r0
  862. stw r6,icache_44x_need_flush@l(r4)
  863. 1:
  864. #endif /* CONFIG_44x */
  865. lwz r9,_MSR(r1)
  866. #ifdef CONFIG_TRACE_IRQFLAGS
  867. /* Lockdep doesn't know about the fact that IRQs are temporarily turned
  868. * off in this assembly code while peeking at TI_FLAGS() and such. However
  869. * we need to inform it if the exception turned interrupts off, and we
  870. * are about to trun them back on.
  871. *
  872. * The problem here sadly is that we don't know whether the exceptions was
  873. * one that turned interrupts off or not. So we always tell lockdep about
  874. * turning them on here when we go back to wherever we came from with EE
  875. * on, even if that may meen some redudant calls being tracked. Maybe later
  876. * we could encode what the exception did somewhere or test the exception
  877. * type in the pt_regs but that sounds overkill
  878. */
  879. andi. r10,r9,MSR_EE
  880. beq 1f
  881. /*
  882. * Since the ftrace irqsoff latency trace checks CALLER_ADDR1,
  883. * which is the stack frame here, we need to force a stack frame
  884. * in case we came from user space.
  885. */
  886. stwu r1,-32(r1)
  887. mflr r0
  888. stw r0,4(r1)
  889. stwu r1,-32(r1)
  890. bl trace_hardirqs_on
  891. lwz r1,0(r1)
  892. lwz r1,0(r1)
  893. lwz r9,_MSR(r1)
  894. 1:
  895. #endif /* CONFIG_TRACE_IRQFLAGS */
  896. lwz r0,GPR0(r1)
  897. lwz r2,GPR2(r1)
  898. REST_4GPRS(3, r1)
  899. REST_2GPRS(7, r1)
  900. lwz r10,_XER(r1)
  901. lwz r11,_CTR(r1)
  902. mtspr SPRN_XER,r10
  903. mtctr r11
  904. PPC405_ERR77(0,r1)
  905. BEGIN_FTR_SECTION
  906. lwarx r11,0,r1
  907. END_FTR_SECTION_IFSET(CPU_FTR_NEED_PAIRED_STWCX)
  908. stwcx. r0,0,r1 /* to clear the reservation */
  909. #if !(defined(CONFIG_4xx) || defined(CONFIG_BOOKE))
  910. andi. r10,r9,MSR_RI /* check if this exception occurred */
  911. beql nonrecoverable /* at a bad place (MSR:RI = 0) */
  912. lwz r10,_CCR(r1)
  913. lwz r11,_LINK(r1)
  914. mtcrf 0xFF,r10
  915. mtlr r11
  916. /* Clear the exception_marker on the stack to avoid confusing stacktrace */
  917. li r10, 0
  918. stw r10, 8(r1)
  919. /*
  920. * Once we put values in SRR0 and SRR1, we are in a state
  921. * where exceptions are not recoverable, since taking an
  922. * exception will trash SRR0 and SRR1. Therefore we clear the
  923. * MSR:RI bit to indicate this. If we do take an exception,
  924. * we can't return to the point of the exception but we
  925. * can restart the exception exit path at the label
  926. * exc_exit_restart below. -- paulus
  927. */
  928. LOAD_MSR_KERNEL(r10,MSR_KERNEL & ~MSR_RI)
  929. SYNC
  930. MTMSRD(r10) /* clear the RI bit */
  931. .globl exc_exit_restart
  932. exc_exit_restart:
  933. lwz r12,_NIP(r1)
  934. #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PERF_EVENTS)
  935. mtspr SPRN_NRI, r0
  936. #endif
  937. mtspr SPRN_SRR0,r12
  938. mtspr SPRN_SRR1,r9
  939. REST_4GPRS(9, r1)
  940. lwz r1,GPR1(r1)
  941. .globl exc_exit_restart_end
  942. exc_exit_restart_end:
  943. SYNC
  944. RFI
  945. #else /* !(CONFIG_4xx || CONFIG_BOOKE) */
  946. /*
  947. * This is a bit different on 4xx/Book-E because it doesn't have
  948. * the RI bit in the MSR.
  949. * The TLB miss handler checks if we have interrupted
  950. * the exception exit path and restarts it if so
  951. * (well maybe one day it will... :).
  952. */
  953. lwz r11,_LINK(r1)
  954. mtlr r11
  955. lwz r10,_CCR(r1)
  956. mtcrf 0xff,r10
  957. /* Clear the exception_marker on the stack to avoid confusing stacktrace */
  958. li r10, 0
  959. stw r10, 8(r1)
  960. REST_2GPRS(9, r1)
  961. .globl exc_exit_restart
  962. exc_exit_restart:
  963. lwz r11,_NIP(r1)
  964. lwz r12,_MSR(r1)
  965. exc_exit_start:
  966. mtspr SPRN_SRR0,r11
  967. mtspr SPRN_SRR1,r12
  968. REST_2GPRS(11, r1)
  969. lwz r1,GPR1(r1)
  970. .globl exc_exit_restart_end
  971. exc_exit_restart_end:
  972. PPC405_ERR77_SYNC
  973. rfi
  974. b . /* prevent prefetch past rfi */
  975. /*
  976. * Returning from a critical interrupt in user mode doesn't need
  977. * to be any different from a normal exception. For a critical
  978. * interrupt in the kernel, we just return (without checking for
  979. * preemption) since the interrupt may have happened at some crucial
  980. * place (e.g. inside the TLB miss handler), and because we will be
  981. * running with r1 pointing into critical_stack, not the current
  982. * process's kernel stack (and therefore current_thread_info() will
  983. * give the wrong answer).
  984. * We have to restore various SPRs that may have been in use at the
  985. * time of the critical interrupt.
  986. *
  987. */
  988. #ifdef CONFIG_40x
  989. #define PPC_40x_TURN_OFF_MSR_DR \
  990. /* avoid any possible TLB misses here by turning off MSR.DR, we \
  991. * assume the instructions here are mapped by a pinned TLB entry */ \
  992. li r10,MSR_IR; \
  993. mtmsr r10; \
  994. isync; \
  995. tophys(r1, r1);
  996. #else
  997. #define PPC_40x_TURN_OFF_MSR_DR
  998. #endif
  999. #define RET_FROM_EXC_LEVEL(exc_lvl_srr0, exc_lvl_srr1, exc_lvl_rfi) \
  1000. REST_NVGPRS(r1); \
  1001. lwz r3,_MSR(r1); \
  1002. andi. r3,r3,MSR_PR; \
  1003. LOAD_MSR_KERNEL(r10,MSR_KERNEL); \
  1004. bne user_exc_return; \
  1005. lwz r0,GPR0(r1); \
  1006. lwz r2,GPR2(r1); \
  1007. REST_4GPRS(3, r1); \
  1008. REST_2GPRS(7, r1); \
  1009. lwz r10,_XER(r1); \
  1010. lwz r11,_CTR(r1); \
  1011. mtspr SPRN_XER,r10; \
  1012. mtctr r11; \
  1013. PPC405_ERR77(0,r1); \
  1014. stwcx. r0,0,r1; /* to clear the reservation */ \
  1015. lwz r11,_LINK(r1); \
  1016. mtlr r11; \
  1017. lwz r10,_CCR(r1); \
  1018. mtcrf 0xff,r10; \
  1019. PPC_40x_TURN_OFF_MSR_DR; \
  1020. lwz r9,_DEAR(r1); \
  1021. lwz r10,_ESR(r1); \
  1022. mtspr SPRN_DEAR,r9; \
  1023. mtspr SPRN_ESR,r10; \
  1024. lwz r11,_NIP(r1); \
  1025. lwz r12,_MSR(r1); \
  1026. mtspr exc_lvl_srr0,r11; \
  1027. mtspr exc_lvl_srr1,r12; \
  1028. lwz r9,GPR9(r1); \
  1029. lwz r12,GPR12(r1); \
  1030. lwz r10,GPR10(r1); \
  1031. lwz r11,GPR11(r1); \
  1032. lwz r1,GPR1(r1); \
  1033. PPC405_ERR77_SYNC; \
  1034. exc_lvl_rfi; \
  1035. b .; /* prevent prefetch past exc_lvl_rfi */
  1036. #define RESTORE_xSRR(exc_lvl_srr0, exc_lvl_srr1) \
  1037. lwz r9,_##exc_lvl_srr0(r1); \
  1038. lwz r10,_##exc_lvl_srr1(r1); \
  1039. mtspr SPRN_##exc_lvl_srr0,r9; \
  1040. mtspr SPRN_##exc_lvl_srr1,r10;
  1041. #if defined(CONFIG_PPC_BOOK3E_MMU)
  1042. #ifdef CONFIG_PHYS_64BIT
  1043. #define RESTORE_MAS7 \
  1044. lwz r11,MAS7(r1); \
  1045. mtspr SPRN_MAS7,r11;
  1046. #else
  1047. #define RESTORE_MAS7
  1048. #endif /* CONFIG_PHYS_64BIT */
  1049. #define RESTORE_MMU_REGS \
  1050. lwz r9,MAS0(r1); \
  1051. lwz r10,MAS1(r1); \
  1052. lwz r11,MAS2(r1); \
  1053. mtspr SPRN_MAS0,r9; \
  1054. lwz r9,MAS3(r1); \
  1055. mtspr SPRN_MAS1,r10; \
  1056. lwz r10,MAS6(r1); \
  1057. mtspr SPRN_MAS2,r11; \
  1058. mtspr SPRN_MAS3,r9; \
  1059. mtspr SPRN_MAS6,r10; \
  1060. RESTORE_MAS7;
  1061. #elif defined(CONFIG_44x)
  1062. #define RESTORE_MMU_REGS \
  1063. lwz r9,MMUCR(r1); \
  1064. mtspr SPRN_MMUCR,r9;
  1065. #else
  1066. #define RESTORE_MMU_REGS
  1067. #endif
  1068. #ifdef CONFIG_40x
  1069. .globl ret_from_crit_exc
  1070. ret_from_crit_exc:
  1071. mfspr r9,SPRN_SPRG_THREAD
  1072. lis r10,saved_ksp_limit@ha;
  1073. lwz r10,saved_ksp_limit@l(r10);
  1074. tovirt(r9,r9);
  1075. stw r10,KSP_LIMIT(r9)
  1076. lis r9,crit_srr0@ha;
  1077. lwz r9,crit_srr0@l(r9);
  1078. lis r10,crit_srr1@ha;
  1079. lwz r10,crit_srr1@l(r10);
  1080. mtspr SPRN_SRR0,r9;
  1081. mtspr SPRN_SRR1,r10;
  1082. RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
  1083. #endif /* CONFIG_40x */
  1084. #ifdef CONFIG_BOOKE
  1085. .globl ret_from_crit_exc
  1086. ret_from_crit_exc:
  1087. mfspr r9,SPRN_SPRG_THREAD
  1088. lwz r10,SAVED_KSP_LIMIT(r1)
  1089. stw r10,KSP_LIMIT(r9)
  1090. RESTORE_xSRR(SRR0,SRR1);
  1091. RESTORE_MMU_REGS;
  1092. RET_FROM_EXC_LEVEL(SPRN_CSRR0, SPRN_CSRR1, PPC_RFCI)
  1093. .globl ret_from_debug_exc
  1094. ret_from_debug_exc:
  1095. mfspr r9,SPRN_SPRG_THREAD
  1096. lwz r10,SAVED_KSP_LIMIT(r1)
  1097. stw r10,KSP_LIMIT(r9)
  1098. lwz r9,THREAD_INFO-THREAD(r9)
  1099. CURRENT_THREAD_INFO(r10, r1)
  1100. lwz r10,TI_PREEMPT(r10)
  1101. stw r10,TI_PREEMPT(r9)
  1102. RESTORE_xSRR(SRR0,SRR1);
  1103. RESTORE_xSRR(CSRR0,CSRR1);
  1104. RESTORE_MMU_REGS;
  1105. RET_FROM_EXC_LEVEL(SPRN_DSRR0, SPRN_DSRR1, PPC_RFDI)
  1106. .globl ret_from_mcheck_exc
  1107. ret_from_mcheck_exc:
  1108. mfspr r9,SPRN_SPRG_THREAD
  1109. lwz r10,SAVED_KSP_LIMIT(r1)
  1110. stw r10,KSP_LIMIT(r9)
  1111. RESTORE_xSRR(SRR0,SRR1);
  1112. RESTORE_xSRR(CSRR0,CSRR1);
  1113. RESTORE_xSRR(DSRR0,DSRR1);
  1114. RESTORE_MMU_REGS;
  1115. RET_FROM_EXC_LEVEL(SPRN_MCSRR0, SPRN_MCSRR1, PPC_RFMCI)
  1116. #endif /* CONFIG_BOOKE */
  1117. /*
  1118. * Load the DBCR0 value for a task that is being ptraced,
  1119. * having first saved away the global DBCR0. Note that r0
  1120. * has the dbcr0 value to set upon entry to this.
  1121. */
  1122. load_dbcr0:
  1123. mfmsr r10 /* first disable debug exceptions */
  1124. rlwinm r10,r10,0,~MSR_DE
  1125. mtmsr r10
  1126. isync
  1127. mfspr r10,SPRN_DBCR0
  1128. lis r11,global_dbcr0@ha
  1129. addi r11,r11,global_dbcr0@l
  1130. #ifdef CONFIG_SMP
  1131. CURRENT_THREAD_INFO(r9, r1)
  1132. lwz r9,TI_CPU(r9)
  1133. slwi r9,r9,3
  1134. add r11,r11,r9
  1135. #endif
  1136. stw r10,0(r11)
  1137. mtspr SPRN_DBCR0,r0
  1138. lwz r10,4(r11)
  1139. addi r10,r10,1
  1140. stw r10,4(r11)
  1141. li r11,-1
  1142. mtspr SPRN_DBSR,r11 /* clear all pending debug events */
  1143. blr
  1144. .section .bss
  1145. .align 4
  1146. global_dbcr0:
  1147. .space 8*NR_CPUS
  1148. .previous
  1149. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  1150. do_work: /* r10 contains MSR_KERNEL here */
  1151. andi. r0,r9,_TIF_NEED_RESCHED
  1152. beq do_user_signal
  1153. do_resched: /* r10 contains MSR_KERNEL here */
  1154. /* Note: We don't need to inform lockdep that we are enabling
  1155. * interrupts here. As far as it knows, they are already enabled
  1156. */
  1157. ori r10,r10,MSR_EE
  1158. SYNC
  1159. MTMSRD(r10) /* hard-enable interrupts */
  1160. bl schedule
  1161. recheck:
  1162. /* Note: And we don't tell it we are disabling them again
  1163. * neither. Those disable/enable cycles used to peek at
  1164. * TI_FLAGS aren't advertised.
  1165. */
  1166. LOAD_MSR_KERNEL(r10,MSR_KERNEL)
  1167. SYNC
  1168. MTMSRD(r10) /* disable interrupts */
  1169. CURRENT_THREAD_INFO(r9, r1)
  1170. lwz r9,TI_FLAGS(r9)
  1171. andi. r0,r9,_TIF_NEED_RESCHED
  1172. bne- do_resched
  1173. andi. r0,r9,_TIF_USER_WORK_MASK
  1174. beq restore_user
  1175. do_user_signal: /* r10 contains MSR_KERNEL here */
  1176. ori r10,r10,MSR_EE
  1177. SYNC
  1178. MTMSRD(r10) /* hard-enable interrupts */
  1179. /* save r13-r31 in the exception frame, if not already done */
  1180. lwz r3,_TRAP(r1)
  1181. andi. r0,r3,1
  1182. beq 2f
  1183. SAVE_NVGPRS(r1)
  1184. rlwinm r3,r3,0,0,30
  1185. stw r3,_TRAP(r1)
  1186. 2: addi r3,r1,STACK_FRAME_OVERHEAD
  1187. mr r4,r9
  1188. bl do_notify_resume
  1189. REST_NVGPRS(r1)
  1190. b recheck
  1191. /*
  1192. * We come here when we are at the end of handling an exception
  1193. * that occurred at a place where taking an exception will lose
  1194. * state information, such as the contents of SRR0 and SRR1.
  1195. */
  1196. nonrecoverable:
  1197. lis r10,exc_exit_restart_end@ha
  1198. addi r10,r10,exc_exit_restart_end@l
  1199. cmplw r12,r10
  1200. bge 3f
  1201. lis r11,exc_exit_restart@ha
  1202. addi r11,r11,exc_exit_restart@l
  1203. cmplw r12,r11
  1204. blt 3f
  1205. lis r10,ee_restarts@ha
  1206. lwz r12,ee_restarts@l(r10)
  1207. addi r12,r12,1
  1208. stw r12,ee_restarts@l(r10)
  1209. mr r12,r11 /* restart at exc_exit_restart */
  1210. blr
  1211. 3: /* OK, we can't recover, kill this process */
  1212. /* but the 601 doesn't implement the RI bit, so assume it's OK */
  1213. BEGIN_FTR_SECTION
  1214. blr
  1215. END_FTR_SECTION_IFSET(CPU_FTR_601)
  1216. lwz r3,_TRAP(r1)
  1217. andi. r0,r3,1
  1218. beq 4f
  1219. SAVE_NVGPRS(r1)
  1220. rlwinm r3,r3,0,0,30
  1221. stw r3,_TRAP(r1)
  1222. 4: addi r3,r1,STACK_FRAME_OVERHEAD
  1223. bl nonrecoverable_exception
  1224. /* shouldn't return */
  1225. b 4b
  1226. .section .bss
  1227. .align 2
  1228. ee_restarts:
  1229. .space 4
  1230. .previous
  1231. /*
  1232. * PROM code for specific machines follows. Put it
  1233. * here so it's easy to add arch-specific sections later.
  1234. * -- Cort
  1235. */
  1236. #ifdef CONFIG_PPC_RTAS
  1237. /*
  1238. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  1239. * called with the MMU off.
  1240. */
  1241. _GLOBAL(enter_rtas)
  1242. stwu r1,-INT_FRAME_SIZE(r1)
  1243. mflr r0
  1244. stw r0,INT_FRAME_SIZE+4(r1)
  1245. LOAD_REG_ADDR(r4, rtas)
  1246. lis r6,1f@ha /* physical return address for rtas */
  1247. addi r6,r6,1f@l
  1248. tophys(r6,r6)
  1249. tophys(r7,r1)
  1250. lwz r8,RTASENTRY(r4)
  1251. lwz r4,RTASBASE(r4)
  1252. mfmsr r9
  1253. stw r9,8(r1)
  1254. LOAD_MSR_KERNEL(r0,MSR_KERNEL)
  1255. SYNC /* disable interrupts so SRR0/1 */
  1256. MTMSRD(r0) /* don't get trashed */
  1257. li r9,MSR_KERNEL & ~(MSR_IR|MSR_DR)
  1258. mtlr r6
  1259. mtspr SPRN_SPRG_RTAS,r7
  1260. mtspr SPRN_SRR0,r8
  1261. mtspr SPRN_SRR1,r9
  1262. RFI
  1263. 1: tophys(r9,r1)
  1264. lwz r8,INT_FRAME_SIZE+4(r9) /* get return address */
  1265. lwz r9,8(r9) /* original msr value */
  1266. addi r1,r1,INT_FRAME_SIZE
  1267. li r0,0
  1268. mtspr SPRN_SPRG_RTAS,r0
  1269. mtspr SPRN_SRR0,r8
  1270. mtspr SPRN_SRR1,r9
  1271. RFI /* return to caller */
  1272. .globl machine_check_in_rtas
  1273. machine_check_in_rtas:
  1274. twi 31,0,0
  1275. /* XXX load up BATs and panic */
  1276. #endif /* CONFIG_PPC_RTAS */