entry_32.S 34 KB

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