entry_32.S 33 KB

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