entry_32.S 29 KB

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