entry_32.S 33 KB

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