entry_32.S 33 KB

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