entry_32.S 34 KB

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