entry_32.S 35 KB

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