entry_32.S 34 KB

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