entry_32.S 33 KB

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