entry_32.S 34 KB

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