entry_64.S 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319
  1. /*
  2. * PowerPC version
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
  5. * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
  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. #include <linux/errno.h>
  21. #include <linux/err.h>
  22. #include <asm/unistd.h>
  23. #include <asm/processor.h>
  24. #include <asm/page.h>
  25. #include <asm/mmu.h>
  26. #include <asm/thread_info.h>
  27. #include <asm/ppc_asm.h>
  28. #include <asm/asm-offsets.h>
  29. #include <asm/cputable.h>
  30. #include <asm/firmware.h>
  31. #include <asm/bug.h>
  32. #include <asm/ptrace.h>
  33. #include <asm/irqflags.h>
  34. #include <asm/ftrace.h>
  35. #include <asm/hw_irq.h>
  36. #include <asm/context_tracking.h>
  37. #include <asm/tm.h>
  38. /*
  39. * System calls.
  40. */
  41. .section ".toc","aw"
  42. SYS_CALL_TABLE:
  43. .tc sys_call_table[TC],sys_call_table
  44. /* This value is used to mark exception frames on the stack. */
  45. exception_marker:
  46. .tc ID_EXC_MARKER[TC],STACK_FRAME_REGS_MARKER
  47. .section ".text"
  48. .align 7
  49. .globl system_call_common
  50. system_call_common:
  51. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  52. BEGIN_FTR_SECTION
  53. extrdi. r10, r12, 1, (63-MSR_TS_T_LG) /* transaction active? */
  54. bne tabort_syscall
  55. END_FTR_SECTION_IFSET(CPU_FTR_TM)
  56. #endif
  57. andi. r10,r12,MSR_PR
  58. mr r10,r1
  59. addi r1,r1,-INT_FRAME_SIZE
  60. beq- 1f
  61. ld r1,PACAKSAVE(r13)
  62. 1: std r10,0(r1)
  63. std r11,_NIP(r1)
  64. std r12,_MSR(r1)
  65. std r0,GPR0(r1)
  66. std r10,GPR1(r1)
  67. beq 2f /* if from kernel mode */
  68. ACCOUNT_CPU_USER_ENTRY(r10, r11)
  69. 2: std r2,GPR2(r1)
  70. std r3,GPR3(r1)
  71. mfcr r2
  72. std r4,GPR4(r1)
  73. std r5,GPR5(r1)
  74. std r6,GPR6(r1)
  75. std r7,GPR7(r1)
  76. std r8,GPR8(r1)
  77. li r11,0
  78. std r11,GPR9(r1)
  79. std r11,GPR10(r1)
  80. std r11,GPR11(r1)
  81. std r11,GPR12(r1)
  82. std r11,_XER(r1)
  83. std r11,_CTR(r1)
  84. std r9,GPR13(r1)
  85. mflr r10
  86. /*
  87. * This clears CR0.SO (bit 28), which is the error indication on
  88. * return from this system call.
  89. */
  90. rldimi r2,r11,28,(63-28)
  91. li r11,0xc01
  92. std r10,_LINK(r1)
  93. std r11,_TRAP(r1)
  94. std r3,ORIG_GPR3(r1)
  95. std r2,_CCR(r1)
  96. ld r2,PACATOC(r13)
  97. addi r9,r1,STACK_FRAME_OVERHEAD
  98. ld r11,exception_marker@toc(r2)
  99. std r11,-16(r9) /* "regshere" marker */
  100. #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
  101. BEGIN_FW_FTR_SECTION
  102. beq 33f
  103. /* if from user, see if there are any DTL entries to process */
  104. ld r10,PACALPPACAPTR(r13) /* get ptr to VPA */
  105. ld r11,PACA_DTL_RIDX(r13) /* get log read index */
  106. addi r10,r10,LPPACA_DTLIDX
  107. LDX_BE r10,0,r10 /* get log write index */
  108. cmpd cr1,r11,r10
  109. beq+ cr1,33f
  110. bl accumulate_stolen_time
  111. REST_GPR(0,r1)
  112. REST_4GPRS(3,r1)
  113. REST_2GPRS(7,r1)
  114. addi r9,r1,STACK_FRAME_OVERHEAD
  115. 33:
  116. END_FW_FTR_SECTION_IFSET(FW_FEATURE_SPLPAR)
  117. #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE && CONFIG_PPC_SPLPAR */
  118. /*
  119. * A syscall should always be called with interrupts enabled
  120. * so we just unconditionally hard-enable here. When some kind
  121. * of irq tracing is used, we additionally check that condition
  122. * is correct
  123. */
  124. #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_BUG)
  125. lbz r10,PACASOFTIRQEN(r13)
  126. xori r10,r10,1
  127. 1: tdnei r10,0
  128. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  129. #endif
  130. #ifdef CONFIG_PPC_BOOK3E
  131. wrteei 1
  132. #else
  133. ld r11,PACAKMSR(r13)
  134. ori r11,r11,MSR_EE
  135. mtmsrd r11,1
  136. #endif /* CONFIG_PPC_BOOK3E */
  137. /* We do need to set SOFTE in the stack frame or the return
  138. * from interrupt will be painful
  139. */
  140. li r10,1
  141. std r10,SOFTE(r1)
  142. CURRENT_THREAD_INFO(r11, r1)
  143. ld r10,TI_FLAGS(r11)
  144. andi. r11,r10,_TIF_SYSCALL_DOTRACE
  145. bne syscall_dotrace /* does not return */
  146. cmpldi 0,r0,NR_syscalls
  147. bge- syscall_enosys
  148. system_call: /* label this so stack traces look sane */
  149. /*
  150. * Need to vector to 32 Bit or default sys_call_table here,
  151. * based on caller's run-mode / personality.
  152. */
  153. ld r11,SYS_CALL_TABLE@toc(2)
  154. andi. r10,r10,_TIF_32BIT
  155. beq 15f
  156. addi r11,r11,8 /* use 32-bit syscall entries */
  157. clrldi r3,r3,32
  158. clrldi r4,r4,32
  159. clrldi r5,r5,32
  160. clrldi r6,r6,32
  161. clrldi r7,r7,32
  162. clrldi r8,r8,32
  163. 15:
  164. slwi r0,r0,4
  165. ldx r12,r11,r0 /* Fetch system call handler [ptr] */
  166. mtctr r12
  167. bctrl /* Call handler */
  168. .Lsyscall_exit:
  169. std r3,RESULT(r1)
  170. CURRENT_THREAD_INFO(r12, r1)
  171. ld r8,_MSR(r1)
  172. #ifdef CONFIG_PPC_BOOK3S
  173. /* No MSR:RI on BookE */
  174. andi. r10,r8,MSR_RI
  175. beq- unrecov_restore
  176. #endif
  177. /*
  178. * Disable interrupts so current_thread_info()->flags can't change,
  179. * and so that we don't get interrupted after loading SRR0/1.
  180. */
  181. #ifdef CONFIG_PPC_BOOK3E
  182. wrteei 0
  183. #else
  184. ld r10,PACAKMSR(r13)
  185. /*
  186. * For performance reasons we clear RI the same time that we
  187. * clear EE. We only need to clear RI just before we restore r13
  188. * below, but batching it with EE saves us one expensive mtmsrd call.
  189. * We have to be careful to restore RI if we branch anywhere from
  190. * here (eg syscall_exit_work).
  191. */
  192. li r9,MSR_RI
  193. andc r11,r10,r9
  194. mtmsrd r11,1
  195. #endif /* CONFIG_PPC_BOOK3E */
  196. ld r9,TI_FLAGS(r12)
  197. li r11,-MAX_ERRNO
  198. andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK)
  199. bne- syscall_exit_work
  200. cmpld r3,r11
  201. ld r5,_CCR(r1)
  202. bge- syscall_error
  203. .Lsyscall_error_cont:
  204. ld r7,_NIP(r1)
  205. BEGIN_FTR_SECTION
  206. stdcx. r0,0,r1 /* to clear the reservation */
  207. END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
  208. andi. r6,r8,MSR_PR
  209. ld r4,_LINK(r1)
  210. beq- 1f
  211. ACCOUNT_CPU_USER_EXIT(r11, r12)
  212. HMT_MEDIUM_LOW_HAS_PPR
  213. ld r13,GPR13(r1) /* only restore r13 if returning to usermode */
  214. 1: ld r2,GPR2(r1)
  215. ld r1,GPR1(r1)
  216. mtlr r4
  217. mtcr r5
  218. mtspr SPRN_SRR0,r7
  219. mtspr SPRN_SRR1,r8
  220. RFI
  221. b . /* prevent speculative execution */
  222. syscall_error:
  223. oris r5,r5,0x1000 /* Set SO bit in CR */
  224. neg r3,r3
  225. std r5,_CCR(r1)
  226. b .Lsyscall_error_cont
  227. /* Traced system call support */
  228. syscall_dotrace:
  229. bl save_nvgprs
  230. addi r3,r1,STACK_FRAME_OVERHEAD
  231. bl do_syscall_trace_enter
  232. /*
  233. * We use the return value of do_syscall_trace_enter() as the syscall
  234. * number. If the syscall was rejected for any reason do_syscall_trace_enter()
  235. * returns an invalid syscall number and the test below against
  236. * NR_syscalls will fail.
  237. */
  238. mr r0,r3
  239. /* Restore argument registers just clobbered and/or possibly changed. */
  240. ld r3,GPR3(r1)
  241. ld r4,GPR4(r1)
  242. ld r5,GPR5(r1)
  243. ld r6,GPR6(r1)
  244. ld r7,GPR7(r1)
  245. ld r8,GPR8(r1)
  246. /* Repopulate r9 and r10 for the system_call path */
  247. addi r9,r1,STACK_FRAME_OVERHEAD
  248. CURRENT_THREAD_INFO(r10, r1)
  249. ld r10,TI_FLAGS(r10)
  250. cmpldi r0,NR_syscalls
  251. blt+ system_call
  252. /* Return code is already in r3 thanks to do_syscall_trace_enter() */
  253. b .Lsyscall_exit
  254. syscall_enosys:
  255. li r3,-ENOSYS
  256. b .Lsyscall_exit
  257. syscall_exit_work:
  258. #ifdef CONFIG_PPC_BOOK3S
  259. mtmsrd r10,1 /* Restore RI */
  260. #endif
  261. /* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
  262. If TIF_NOERROR is set, just save r3 as it is. */
  263. andi. r0,r9,_TIF_RESTOREALL
  264. beq+ 0f
  265. REST_NVGPRS(r1)
  266. b 2f
  267. 0: cmpld r3,r11 /* r11 is -MAX_ERRNO */
  268. blt+ 1f
  269. andi. r0,r9,_TIF_NOERROR
  270. bne- 1f
  271. ld r5,_CCR(r1)
  272. neg r3,r3
  273. oris r5,r5,0x1000 /* Set SO bit in CR */
  274. std r5,_CCR(r1)
  275. 1: std r3,GPR3(r1)
  276. 2: andi. r0,r9,(_TIF_PERSYSCALL_MASK)
  277. beq 4f
  278. /* Clear per-syscall TIF flags if any are set. */
  279. li r11,_TIF_PERSYSCALL_MASK
  280. addi r12,r12,TI_FLAGS
  281. 3: ldarx r10,0,r12
  282. andc r10,r10,r11
  283. stdcx. r10,0,r12
  284. bne- 3b
  285. subi r12,r12,TI_FLAGS
  286. 4: /* Anything else left to do? */
  287. SET_DEFAULT_THREAD_PPR(r3, r10) /* Set thread.ppr = 3 */
  288. andi. r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP)
  289. beq ret_from_except_lite
  290. /* Re-enable interrupts */
  291. #ifdef CONFIG_PPC_BOOK3E
  292. wrteei 1
  293. #else
  294. ld r10,PACAKMSR(r13)
  295. ori r10,r10,MSR_EE
  296. mtmsrd r10,1
  297. #endif /* CONFIG_PPC_BOOK3E */
  298. bl save_nvgprs
  299. addi r3,r1,STACK_FRAME_OVERHEAD
  300. bl do_syscall_trace_leave
  301. b ret_from_except
  302. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  303. tabort_syscall:
  304. /* Firstly we need to enable TM in the kernel */
  305. mfmsr r10
  306. li r13, 1
  307. rldimi r10, r13, MSR_TM_LG, 63-MSR_TM_LG
  308. mtmsrd r10, 0
  309. /* tabort, this dooms the transaction, nothing else */
  310. li r13, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT)
  311. TABORT(R13)
  312. /*
  313. * Return directly to userspace. We have corrupted user register state,
  314. * but userspace will never see that register state. Execution will
  315. * resume after the tbegin of the aborted transaction with the
  316. * checkpointed register state.
  317. */
  318. li r13, MSR_RI
  319. andc r10, r10, r13
  320. mtmsrd r10, 1
  321. mtspr SPRN_SRR0, r11
  322. mtspr SPRN_SRR1, r12
  323. rfid
  324. b . /* prevent speculative execution */
  325. #endif
  326. /* Save non-volatile GPRs, if not already saved. */
  327. _GLOBAL(save_nvgprs)
  328. ld r11,_TRAP(r1)
  329. andi. r0,r11,1
  330. beqlr-
  331. SAVE_NVGPRS(r1)
  332. clrrdi r0,r11,1
  333. std r0,_TRAP(r1)
  334. blr
  335. /*
  336. * The sigsuspend and rt_sigsuspend system calls can call do_signal
  337. * and thus put the process into the stopped state where we might
  338. * want to examine its user state with ptrace. Therefore we need
  339. * to save all the nonvolatile registers (r14 - r31) before calling
  340. * the C code. Similarly, fork, vfork and clone need the full
  341. * register state on the stack so that it can be copied to the child.
  342. */
  343. _GLOBAL(ppc_fork)
  344. bl save_nvgprs
  345. bl sys_fork
  346. b .Lsyscall_exit
  347. _GLOBAL(ppc_vfork)
  348. bl save_nvgprs
  349. bl sys_vfork
  350. b .Lsyscall_exit
  351. _GLOBAL(ppc_clone)
  352. bl save_nvgprs
  353. bl sys_clone
  354. b .Lsyscall_exit
  355. _GLOBAL(ppc32_swapcontext)
  356. bl save_nvgprs
  357. bl compat_sys_swapcontext
  358. b .Lsyscall_exit
  359. _GLOBAL(ppc64_swapcontext)
  360. bl save_nvgprs
  361. bl sys_swapcontext
  362. b .Lsyscall_exit
  363. _GLOBAL(ppc_switch_endian)
  364. bl save_nvgprs
  365. bl sys_switch_endian
  366. b .Lsyscall_exit
  367. _GLOBAL(ret_from_fork)
  368. bl schedule_tail
  369. REST_NVGPRS(r1)
  370. li r3,0
  371. b .Lsyscall_exit
  372. _GLOBAL(ret_from_kernel_thread)
  373. bl schedule_tail
  374. REST_NVGPRS(r1)
  375. mtlr r14
  376. mr r3,r15
  377. #if defined(_CALL_ELF) && _CALL_ELF == 2
  378. mr r12,r14
  379. #endif
  380. blrl
  381. li r3,0
  382. b .Lsyscall_exit
  383. /*
  384. * This routine switches between two different tasks. The process
  385. * state of one is saved on its kernel stack. Then the state
  386. * of the other is restored from its kernel stack. The memory
  387. * management hardware is updated to the second process's state.
  388. * Finally, we can return to the second process, via ret_from_except.
  389. * On entry, r3 points to the THREAD for the current task, r4
  390. * points to the THREAD for the new task.
  391. *
  392. * Note: there are two ways to get to the "going out" portion
  393. * of this code; either by coming in via the entry (_switch)
  394. * or via "fork" which must set up an environment equivalent
  395. * to the "_switch" path. If you change this you'll have to change
  396. * the fork code also.
  397. *
  398. * The code which creates the new task context is in 'copy_thread'
  399. * in arch/powerpc/kernel/process.c
  400. */
  401. .align 7
  402. _GLOBAL(_switch)
  403. mflr r0
  404. std r0,16(r1)
  405. stdu r1,-SWITCH_FRAME_SIZE(r1)
  406. /* r3-r13 are caller saved -- Cort */
  407. SAVE_8GPRS(14, r1)
  408. SAVE_10GPRS(22, r1)
  409. mflr r20 /* Return to switch caller */
  410. mfmsr r22
  411. li r0, MSR_FP
  412. #ifdef CONFIG_VSX
  413. BEGIN_FTR_SECTION
  414. oris r0,r0,MSR_VSX@h /* Disable VSX */
  415. END_FTR_SECTION_IFSET(CPU_FTR_VSX)
  416. #endif /* CONFIG_VSX */
  417. #ifdef CONFIG_ALTIVEC
  418. BEGIN_FTR_SECTION
  419. oris r0,r0,MSR_VEC@h /* Disable altivec */
  420. mfspr r24,SPRN_VRSAVE /* save vrsave register value */
  421. std r24,THREAD_VRSAVE(r3)
  422. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  423. #endif /* CONFIG_ALTIVEC */
  424. and. r0,r0,r22
  425. beq+ 1f
  426. andc r22,r22,r0
  427. MTMSRD(r22)
  428. isync
  429. 1: std r20,_NIP(r1)
  430. mfcr r23
  431. std r23,_CCR(r1)
  432. std r1,KSP(r3) /* Set old stack pointer */
  433. #ifdef CONFIG_PPC_BOOK3S_64
  434. BEGIN_FTR_SECTION
  435. /* Event based branch registers */
  436. mfspr r0, SPRN_BESCR
  437. std r0, THREAD_BESCR(r3)
  438. mfspr r0, SPRN_EBBHR
  439. std r0, THREAD_EBBHR(r3)
  440. mfspr r0, SPRN_EBBRR
  441. std r0, THREAD_EBBRR(r3)
  442. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  443. #endif
  444. #ifdef CONFIG_SMP
  445. /* We need a sync somewhere here to make sure that if the
  446. * previous task gets rescheduled on another CPU, it sees all
  447. * stores it has performed on this one.
  448. */
  449. sync
  450. #endif /* CONFIG_SMP */
  451. /*
  452. * If we optimise away the clear of the reservation in system
  453. * calls because we know the CPU tracks the address of the
  454. * reservation, then we need to clear it here to cover the
  455. * case that the kernel context switch path has no larx
  456. * instructions.
  457. */
  458. BEGIN_FTR_SECTION
  459. ldarx r6,0,r1
  460. END_FTR_SECTION_IFSET(CPU_FTR_STCX_CHECKS_ADDRESS)
  461. #ifdef CONFIG_PPC_BOOK3S
  462. /* Cancel all explict user streams as they will have no use after context
  463. * switch and will stop the HW from creating streams itself
  464. */
  465. DCBT_STOP_ALL_STREAM_IDS(r6)
  466. #endif
  467. addi r6,r4,-THREAD /* Convert THREAD to 'current' */
  468. std r6,PACACURRENT(r13) /* Set new 'current' */
  469. ld r8,KSP(r4) /* new stack pointer */
  470. #ifdef CONFIG_PPC_BOOK3S
  471. BEGIN_FTR_SECTION
  472. clrrdi r6,r8,28 /* get its ESID */
  473. clrrdi r9,r1,28 /* get current sp ESID */
  474. FTR_SECTION_ELSE
  475. clrrdi r6,r8,40 /* get its 1T ESID */
  476. clrrdi r9,r1,40 /* get current sp 1T ESID */
  477. ALT_MMU_FTR_SECTION_END_IFCLR(MMU_FTR_1T_SEGMENT)
  478. clrldi. r0,r6,2 /* is new ESID c00000000? */
  479. cmpd cr1,r6,r9 /* or is new ESID the same as current ESID? */
  480. cror eq,4*cr1+eq,eq
  481. beq 2f /* if yes, don't slbie it */
  482. /* Bolt in the new stack SLB entry */
  483. ld r7,KSP_VSID(r4) /* Get new stack's VSID */
  484. oris r0,r6,(SLB_ESID_V)@h
  485. ori r0,r0,(SLB_NUM_BOLTED-1)@l
  486. BEGIN_FTR_SECTION
  487. li r9,MMU_SEGSIZE_1T /* insert B field */
  488. oris r6,r6,(MMU_SEGSIZE_1T << SLBIE_SSIZE_SHIFT)@h
  489. rldimi r7,r9,SLB_VSID_SSIZE_SHIFT,0
  490. END_MMU_FTR_SECTION_IFSET(MMU_FTR_1T_SEGMENT)
  491. /* Update the last bolted SLB. No write barriers are needed
  492. * here, provided we only update the current CPU's SLB shadow
  493. * buffer.
  494. */
  495. ld r9,PACA_SLBSHADOWPTR(r13)
  496. li r12,0
  497. std r12,SLBSHADOW_STACKESID(r9) /* Clear ESID */
  498. li r12,SLBSHADOW_STACKVSID
  499. STDX_BE r7,r12,r9 /* Save VSID */
  500. li r12,SLBSHADOW_STACKESID
  501. STDX_BE r0,r12,r9 /* Save ESID */
  502. /* No need to check for MMU_FTR_NO_SLBIE_B here, since when
  503. * we have 1TB segments, the only CPUs known to have the errata
  504. * only support less than 1TB of system memory and we'll never
  505. * actually hit this code path.
  506. */
  507. slbie r6
  508. slbie r6 /* Workaround POWER5 < DD2.1 issue */
  509. slbmte r7,r0
  510. isync
  511. 2:
  512. #endif /* !CONFIG_PPC_BOOK3S */
  513. CURRENT_THREAD_INFO(r7, r8) /* base of new stack */
  514. /* Note: this uses SWITCH_FRAME_SIZE rather than INT_FRAME_SIZE
  515. because we don't need to leave the 288-byte ABI gap at the
  516. top of the kernel stack. */
  517. addi r7,r7,THREAD_SIZE-SWITCH_FRAME_SIZE
  518. mr r1,r8 /* start using new stack pointer */
  519. std r7,PACAKSAVE(r13)
  520. #ifdef CONFIG_PPC_BOOK3S_64
  521. BEGIN_FTR_SECTION
  522. /* Event based branch registers */
  523. ld r0, THREAD_BESCR(r4)
  524. mtspr SPRN_BESCR, r0
  525. ld r0, THREAD_EBBHR(r4)
  526. mtspr SPRN_EBBHR, r0
  527. ld r0, THREAD_EBBRR(r4)
  528. mtspr SPRN_EBBRR, r0
  529. ld r0,THREAD_TAR(r4)
  530. mtspr SPRN_TAR,r0
  531. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  532. #endif
  533. #ifdef CONFIG_ALTIVEC
  534. BEGIN_FTR_SECTION
  535. ld r0,THREAD_VRSAVE(r4)
  536. mtspr SPRN_VRSAVE,r0 /* if G4, restore VRSAVE reg */
  537. END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
  538. #endif /* CONFIG_ALTIVEC */
  539. #ifdef CONFIG_PPC64
  540. BEGIN_FTR_SECTION
  541. lwz r6,THREAD_DSCR_INHERIT(r4)
  542. ld r0,THREAD_DSCR(r4)
  543. cmpwi r6,0
  544. bne 1f
  545. ld r0,PACA_DSCR_DEFAULT(r13)
  546. 1:
  547. BEGIN_FTR_SECTION_NESTED(70)
  548. mfspr r8, SPRN_FSCR
  549. rldimi r8, r6, FSCR_DSCR_LG, (63 - FSCR_DSCR_LG)
  550. mtspr SPRN_FSCR, r8
  551. END_FTR_SECTION_NESTED(CPU_FTR_ARCH_207S, CPU_FTR_ARCH_207S, 70)
  552. cmpd r0,r25
  553. beq 2f
  554. mtspr SPRN_DSCR,r0
  555. 2:
  556. END_FTR_SECTION_IFSET(CPU_FTR_DSCR)
  557. #endif
  558. ld r6,_CCR(r1)
  559. mtcrf 0xFF,r6
  560. /* r3-r13 are destroyed -- Cort */
  561. REST_8GPRS(14, r1)
  562. REST_10GPRS(22, r1)
  563. /* convert old thread to its task_struct for return value */
  564. addi r3,r3,-THREAD
  565. ld r7,_NIP(r1) /* Return to _switch caller in new task */
  566. mtlr r7
  567. addi r1,r1,SWITCH_FRAME_SIZE
  568. blr
  569. .align 7
  570. _GLOBAL(ret_from_except)
  571. ld r11,_TRAP(r1)
  572. andi. r0,r11,1
  573. bne ret_from_except_lite
  574. REST_NVGPRS(r1)
  575. _GLOBAL(ret_from_except_lite)
  576. /*
  577. * Disable interrupts so that current_thread_info()->flags
  578. * can't change between when we test it and when we return
  579. * from the interrupt.
  580. */
  581. #ifdef CONFIG_PPC_BOOK3E
  582. wrteei 0
  583. #else
  584. ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
  585. mtmsrd r10,1 /* Update machine state */
  586. #endif /* CONFIG_PPC_BOOK3E */
  587. CURRENT_THREAD_INFO(r9, r1)
  588. ld r3,_MSR(r1)
  589. #ifdef CONFIG_PPC_BOOK3E
  590. ld r10,PACACURRENT(r13)
  591. #endif /* CONFIG_PPC_BOOK3E */
  592. ld r4,TI_FLAGS(r9)
  593. andi. r3,r3,MSR_PR
  594. beq resume_kernel
  595. #ifdef CONFIG_PPC_BOOK3E
  596. lwz r3,(THREAD+THREAD_DBCR0)(r10)
  597. #endif /* CONFIG_PPC_BOOK3E */
  598. /* Check current_thread_info()->flags */
  599. andi. r0,r4,_TIF_USER_WORK_MASK
  600. #ifdef CONFIG_PPC_BOOK3E
  601. bne 1f
  602. /*
  603. * Check to see if the dbcr0 register is set up to debug.
  604. * Use the internal debug mode bit to do this.
  605. */
  606. andis. r0,r3,DBCR0_IDM@h
  607. beq restore
  608. mfmsr r0
  609. rlwinm r0,r0,0,~MSR_DE /* Clear MSR.DE */
  610. mtmsr r0
  611. mtspr SPRN_DBCR0,r3
  612. li r10, -1
  613. mtspr SPRN_DBSR,r10
  614. b restore
  615. #else
  616. beq restore
  617. #endif
  618. 1: andi. r0,r4,_TIF_NEED_RESCHED
  619. beq 2f
  620. bl restore_interrupts
  621. SCHEDULE_USER
  622. b ret_from_except_lite
  623. 2:
  624. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  625. andi. r0,r4,_TIF_USER_WORK_MASK & ~_TIF_RESTORE_TM
  626. bne 3f /* only restore TM if nothing else to do */
  627. addi r3,r1,STACK_FRAME_OVERHEAD
  628. bl restore_tm_state
  629. b restore
  630. 3:
  631. #endif
  632. bl save_nvgprs
  633. /*
  634. * Use a non volatile GPR to save and restore our thread_info flags
  635. * across the call to restore_interrupts.
  636. */
  637. mr r30,r4
  638. bl restore_interrupts
  639. mr r4,r30
  640. addi r3,r1,STACK_FRAME_OVERHEAD
  641. bl do_notify_resume
  642. b ret_from_except
  643. resume_kernel:
  644. /* check current_thread_info, _TIF_EMULATE_STACK_STORE */
  645. andis. r8,r4,_TIF_EMULATE_STACK_STORE@h
  646. beq+ 1f
  647. addi r8,r1,INT_FRAME_SIZE /* Get the kprobed function entry */
  648. lwz r3,GPR1(r1)
  649. subi r3,r3,INT_FRAME_SIZE /* dst: Allocate a trampoline exception frame */
  650. mr r4,r1 /* src: current exception frame */
  651. mr r1,r3 /* Reroute the trampoline frame to r1 */
  652. /* Copy from the original to the trampoline. */
  653. li r5,INT_FRAME_SIZE/8 /* size: INT_FRAME_SIZE */
  654. li r6,0 /* start offset: 0 */
  655. mtctr r5
  656. 2: ldx r0,r6,r4
  657. stdx r0,r6,r3
  658. addi r6,r6,8
  659. bdnz 2b
  660. /* Do real store operation to complete stwu */
  661. lwz r5,GPR1(r1)
  662. std r8,0(r5)
  663. /* Clear _TIF_EMULATE_STACK_STORE flag */
  664. lis r11,_TIF_EMULATE_STACK_STORE@h
  665. addi r5,r9,TI_FLAGS
  666. 0: ldarx r4,0,r5
  667. andc r4,r4,r11
  668. stdcx. r4,0,r5
  669. bne- 0b
  670. 1:
  671. #ifdef CONFIG_PREEMPT
  672. /* Check if we need to preempt */
  673. andi. r0,r4,_TIF_NEED_RESCHED
  674. beq+ restore
  675. /* Check that preempt_count() == 0 and interrupts are enabled */
  676. lwz r8,TI_PREEMPT(r9)
  677. cmpwi cr1,r8,0
  678. ld r0,SOFTE(r1)
  679. cmpdi r0,0
  680. crandc eq,cr1*4+eq,eq
  681. bne restore
  682. /*
  683. * Here we are preempting the current task. We want to make
  684. * sure we are soft-disabled first and reconcile irq state.
  685. */
  686. RECONCILE_IRQ_STATE(r3,r4)
  687. 1: bl preempt_schedule_irq
  688. /* Re-test flags and eventually loop */
  689. CURRENT_THREAD_INFO(r9, r1)
  690. ld r4,TI_FLAGS(r9)
  691. andi. r0,r4,_TIF_NEED_RESCHED
  692. bne 1b
  693. /*
  694. * arch_local_irq_restore() from preempt_schedule_irq above may
  695. * enable hard interrupt but we really should disable interrupts
  696. * when we return from the interrupt, and so that we don't get
  697. * interrupted after loading SRR0/1.
  698. */
  699. #ifdef CONFIG_PPC_BOOK3E
  700. wrteei 0
  701. #else
  702. ld r10,PACAKMSR(r13) /* Get kernel MSR without EE */
  703. mtmsrd r10,1 /* Update machine state */
  704. #endif /* CONFIG_PPC_BOOK3E */
  705. #endif /* CONFIG_PREEMPT */
  706. .globl fast_exc_return_irq
  707. fast_exc_return_irq:
  708. restore:
  709. /*
  710. * This is the main kernel exit path. First we check if we
  711. * are about to re-enable interrupts
  712. */
  713. ld r5,SOFTE(r1)
  714. lbz r6,PACASOFTIRQEN(r13)
  715. cmpwi cr0,r5,0
  716. beq restore_irq_off
  717. /* We are enabling, were we already enabled ? Yes, just return */
  718. cmpwi cr0,r6,1
  719. beq cr0,do_restore
  720. /*
  721. * We are about to soft-enable interrupts (we are hard disabled
  722. * at this point). We check if there's anything that needs to
  723. * be replayed first.
  724. */
  725. lbz r0,PACAIRQHAPPENED(r13)
  726. cmpwi cr0,r0,0
  727. bne- restore_check_irq_replay
  728. /*
  729. * Get here when nothing happened while soft-disabled, just
  730. * soft-enable and move-on. We will hard-enable as a side
  731. * effect of rfi
  732. */
  733. restore_no_replay:
  734. TRACE_ENABLE_INTS
  735. li r0,1
  736. stb r0,PACASOFTIRQEN(r13);
  737. /*
  738. * Final return path. BookE is handled in a different file
  739. */
  740. do_restore:
  741. #ifdef CONFIG_PPC_BOOK3E
  742. b exception_return_book3e
  743. #else
  744. /*
  745. * Clear the reservation. If we know the CPU tracks the address of
  746. * the reservation then we can potentially save some cycles and use
  747. * a larx. On POWER6 and POWER7 this is significantly faster.
  748. */
  749. BEGIN_FTR_SECTION
  750. stdcx. r0,0,r1 /* to clear the reservation */
  751. FTR_SECTION_ELSE
  752. ldarx r4,0,r1
  753. ALT_FTR_SECTION_END_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
  754. /*
  755. * Some code path such as load_up_fpu or altivec return directly
  756. * here. They run entirely hard disabled and do not alter the
  757. * interrupt state. They also don't use lwarx/stwcx. and thus
  758. * are known not to leave dangling reservations.
  759. */
  760. .globl fast_exception_return
  761. fast_exception_return:
  762. ld r3,_MSR(r1)
  763. ld r4,_CTR(r1)
  764. ld r0,_LINK(r1)
  765. mtctr r4
  766. mtlr r0
  767. ld r4,_XER(r1)
  768. mtspr SPRN_XER,r4
  769. REST_8GPRS(5, r1)
  770. andi. r0,r3,MSR_RI
  771. beq- unrecov_restore
  772. /* Load PPR from thread struct before we clear MSR:RI */
  773. BEGIN_FTR_SECTION
  774. ld r2,PACACURRENT(r13)
  775. ld r2,TASKTHREADPPR(r2)
  776. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  777. /*
  778. * Clear RI before restoring r13. If we are returning to
  779. * userspace and we take an exception after restoring r13,
  780. * we end up corrupting the userspace r13 value.
  781. */
  782. ld r4,PACAKMSR(r13) /* Get kernel MSR without EE */
  783. andc r4,r4,r0 /* r0 contains MSR_RI here */
  784. mtmsrd r4,1
  785. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  786. /* TM debug */
  787. std r3, PACATMSCRATCH(r13) /* Stash returned-to MSR */
  788. #endif
  789. /*
  790. * r13 is our per cpu area, only restore it if we are returning to
  791. * userspace the value stored in the stack frame may belong to
  792. * another CPU.
  793. */
  794. andi. r0,r3,MSR_PR
  795. beq 1f
  796. BEGIN_FTR_SECTION
  797. mtspr SPRN_PPR,r2 /* Restore PPR */
  798. END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
  799. ACCOUNT_CPU_USER_EXIT(r2, r4)
  800. REST_GPR(13, r1)
  801. 1:
  802. mtspr SPRN_SRR1,r3
  803. ld r2,_CCR(r1)
  804. mtcrf 0xFF,r2
  805. ld r2,_NIP(r1)
  806. mtspr SPRN_SRR0,r2
  807. ld r0,GPR0(r1)
  808. ld r2,GPR2(r1)
  809. ld r3,GPR3(r1)
  810. ld r4,GPR4(r1)
  811. ld r1,GPR1(r1)
  812. rfid
  813. b . /* prevent speculative execution */
  814. #endif /* CONFIG_PPC_BOOK3E */
  815. /*
  816. * We are returning to a context with interrupts soft disabled.
  817. *
  818. * However, we may also about to hard enable, so we need to
  819. * make sure that in this case, we also clear PACA_IRQ_HARD_DIS
  820. * or that bit can get out of sync and bad things will happen
  821. */
  822. restore_irq_off:
  823. ld r3,_MSR(r1)
  824. lbz r7,PACAIRQHAPPENED(r13)
  825. andi. r0,r3,MSR_EE
  826. beq 1f
  827. rlwinm r7,r7,0,~PACA_IRQ_HARD_DIS
  828. stb r7,PACAIRQHAPPENED(r13)
  829. 1: li r0,0
  830. stb r0,PACASOFTIRQEN(r13);
  831. TRACE_DISABLE_INTS
  832. b do_restore
  833. /*
  834. * Something did happen, check if a re-emit is needed
  835. * (this also clears paca->irq_happened)
  836. */
  837. restore_check_irq_replay:
  838. /* XXX: We could implement a fast path here where we check
  839. * for irq_happened being just 0x01, in which case we can
  840. * clear it and return. That means that we would potentially
  841. * miss a decrementer having wrapped all the way around.
  842. *
  843. * Still, this might be useful for things like hash_page
  844. */
  845. bl __check_irq_replay
  846. cmpwi cr0,r3,0
  847. beq restore_no_replay
  848. /*
  849. * We need to re-emit an interrupt. We do so by re-using our
  850. * existing exception frame. We first change the trap value,
  851. * but we need to ensure we preserve the low nibble of it
  852. */
  853. ld r4,_TRAP(r1)
  854. clrldi r4,r4,60
  855. or r4,r4,r3
  856. std r4,_TRAP(r1)
  857. /*
  858. * Then find the right handler and call it. Interrupts are
  859. * still soft-disabled and we keep them that way.
  860. */
  861. cmpwi cr0,r3,0x500
  862. bne 1f
  863. addi r3,r1,STACK_FRAME_OVERHEAD;
  864. bl do_IRQ
  865. b ret_from_except
  866. 1: cmpwi cr0,r3,0xe60
  867. bne 1f
  868. addi r3,r1,STACK_FRAME_OVERHEAD;
  869. bl handle_hmi_exception
  870. b ret_from_except
  871. 1: cmpwi cr0,r3,0x900
  872. bne 1f
  873. addi r3,r1,STACK_FRAME_OVERHEAD;
  874. bl timer_interrupt
  875. b ret_from_except
  876. #ifdef CONFIG_PPC_DOORBELL
  877. 1:
  878. #ifdef CONFIG_PPC_BOOK3E
  879. cmpwi cr0,r3,0x280
  880. #else
  881. BEGIN_FTR_SECTION
  882. cmpwi cr0,r3,0xe80
  883. FTR_SECTION_ELSE
  884. cmpwi cr0,r3,0xa00
  885. ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE)
  886. #endif /* CONFIG_PPC_BOOK3E */
  887. bne 1f
  888. addi r3,r1,STACK_FRAME_OVERHEAD;
  889. bl doorbell_exception
  890. b ret_from_except
  891. #endif /* CONFIG_PPC_DOORBELL */
  892. 1: b ret_from_except /* What else to do here ? */
  893. unrecov_restore:
  894. addi r3,r1,STACK_FRAME_OVERHEAD
  895. bl unrecoverable_exception
  896. b unrecov_restore
  897. #ifdef CONFIG_PPC_RTAS
  898. /*
  899. * On CHRP, the Run-Time Abstraction Services (RTAS) have to be
  900. * called with the MMU off.
  901. *
  902. * In addition, we need to be in 32b mode, at least for now.
  903. *
  904. * Note: r3 is an input parameter to rtas, so don't trash it...
  905. */
  906. _GLOBAL(enter_rtas)
  907. mflr r0
  908. std r0,16(r1)
  909. stdu r1,-RTAS_FRAME_SIZE(r1) /* Save SP and create stack space. */
  910. /* Because RTAS is running in 32b mode, it clobbers the high order half
  911. * of all registers that it saves. We therefore save those registers
  912. * RTAS might touch to the stack. (r0, r3-r13 are caller saved)
  913. */
  914. SAVE_GPR(2, r1) /* Save the TOC */
  915. SAVE_GPR(13, r1) /* Save paca */
  916. SAVE_8GPRS(14, r1) /* Save the non-volatiles */
  917. SAVE_10GPRS(22, r1) /* ditto */
  918. mfcr r4
  919. std r4,_CCR(r1)
  920. mfctr r5
  921. std r5,_CTR(r1)
  922. mfspr r6,SPRN_XER
  923. std r6,_XER(r1)
  924. mfdar r7
  925. std r7,_DAR(r1)
  926. mfdsisr r8
  927. std r8,_DSISR(r1)
  928. /* Temporary workaround to clear CR until RTAS can be modified to
  929. * ignore all bits.
  930. */
  931. li r0,0
  932. mtcr r0
  933. #ifdef CONFIG_BUG
  934. /* There is no way it is acceptable to get here with interrupts enabled,
  935. * check it with the asm equivalent of WARN_ON
  936. */
  937. lbz r0,PACASOFTIRQEN(r13)
  938. 1: tdnei r0,0
  939. EMIT_BUG_ENTRY 1b,__FILE__,__LINE__,BUGFLAG_WARNING
  940. #endif
  941. /* Hard-disable interrupts */
  942. mfmsr r6
  943. rldicl r7,r6,48,1
  944. rotldi r7,r7,16
  945. mtmsrd r7,1
  946. /* Unfortunately, the stack pointer and the MSR are also clobbered,
  947. * so they are saved in the PACA which allows us to restore
  948. * our original state after RTAS returns.
  949. */
  950. std r1,PACAR1(r13)
  951. std r6,PACASAVEDMSR(r13)
  952. /* Setup our real return addr */
  953. LOAD_REG_ADDR(r4,rtas_return_loc)
  954. clrldi r4,r4,2 /* convert to realmode address */
  955. mtlr r4
  956. li r0,0
  957. ori r0,r0,MSR_EE|MSR_SE|MSR_BE|MSR_RI
  958. andc r0,r6,r0
  959. li r9,1
  960. rldicr r9,r9,MSR_SF_LG,(63-MSR_SF_LG)
  961. ori r9,r9,MSR_IR|MSR_DR|MSR_FE0|MSR_FE1|MSR_FP|MSR_RI|MSR_LE
  962. andc r6,r0,r9
  963. sync /* disable interrupts so SRR0/1 */
  964. mtmsrd r0 /* don't get trashed */
  965. LOAD_REG_ADDR(r4, rtas)
  966. ld r5,RTASENTRY(r4) /* get the rtas->entry value */
  967. ld r4,RTASBASE(r4) /* get the rtas->base value */
  968. mtspr SPRN_SRR0,r5
  969. mtspr SPRN_SRR1,r6
  970. rfid
  971. b . /* prevent speculative execution */
  972. rtas_return_loc:
  973. FIXUP_ENDIAN
  974. /* relocation is off at this point */
  975. GET_PACA(r4)
  976. clrldi r4,r4,2 /* convert to realmode address */
  977. bcl 20,31,$+4
  978. 0: mflr r3
  979. ld r3,(1f-0b)(r3) /* get &rtas_restore_regs */
  980. mfmsr r6
  981. li r0,MSR_RI
  982. andc r6,r6,r0
  983. sync
  984. mtmsrd r6
  985. ld r1,PACAR1(r4) /* Restore our SP */
  986. ld r4,PACASAVEDMSR(r4) /* Restore our MSR */
  987. mtspr SPRN_SRR0,r3
  988. mtspr SPRN_SRR1,r4
  989. rfid
  990. b . /* prevent speculative execution */
  991. .align 3
  992. 1: .llong rtas_restore_regs
  993. rtas_restore_regs:
  994. /* relocation is on at this point */
  995. REST_GPR(2, r1) /* Restore the TOC */
  996. REST_GPR(13, r1) /* Restore paca */
  997. REST_8GPRS(14, r1) /* Restore the non-volatiles */
  998. REST_10GPRS(22, r1) /* ditto */
  999. GET_PACA(r13)
  1000. ld r4,_CCR(r1)
  1001. mtcr r4
  1002. ld r5,_CTR(r1)
  1003. mtctr r5
  1004. ld r6,_XER(r1)
  1005. mtspr SPRN_XER,r6
  1006. ld r7,_DAR(r1)
  1007. mtdar r7
  1008. ld r8,_DSISR(r1)
  1009. mtdsisr r8
  1010. addi r1,r1,RTAS_FRAME_SIZE /* Unstack our frame */
  1011. ld r0,16(r1) /* get return address */
  1012. mtlr r0
  1013. blr /* return to caller */
  1014. #endif /* CONFIG_PPC_RTAS */
  1015. _GLOBAL(enter_prom)
  1016. mflr r0
  1017. std r0,16(r1)
  1018. stdu r1,-PROM_FRAME_SIZE(r1) /* Save SP and create stack space */
  1019. /* Because PROM is running in 32b mode, it clobbers the high order half
  1020. * of all registers that it saves. We therefore save those registers
  1021. * PROM might touch to the stack. (r0, r3-r13 are caller saved)
  1022. */
  1023. SAVE_GPR(2, r1)
  1024. SAVE_GPR(13, r1)
  1025. SAVE_8GPRS(14, r1)
  1026. SAVE_10GPRS(22, r1)
  1027. mfcr r10
  1028. mfmsr r11
  1029. std r10,_CCR(r1)
  1030. std r11,_MSR(r1)
  1031. /* Put PROM address in SRR0 */
  1032. mtsrr0 r4
  1033. /* Setup our trampoline return addr in LR */
  1034. bcl 20,31,$+4
  1035. 0: mflr r4
  1036. addi r4,r4,(1f - 0b)
  1037. mtlr r4
  1038. /* Prepare a 32-bit mode big endian MSR
  1039. */
  1040. #ifdef CONFIG_PPC_BOOK3E
  1041. rlwinm r11,r11,0,1,31
  1042. mtsrr1 r11
  1043. rfi
  1044. #else /* CONFIG_PPC_BOOK3E */
  1045. LOAD_REG_IMMEDIATE(r12, MSR_SF | MSR_ISF | MSR_LE)
  1046. andc r11,r11,r12
  1047. mtsrr1 r11
  1048. rfid
  1049. #endif /* CONFIG_PPC_BOOK3E */
  1050. 1: /* Return from OF */
  1051. FIXUP_ENDIAN
  1052. /* Just make sure that r1 top 32 bits didn't get
  1053. * corrupt by OF
  1054. */
  1055. rldicl r1,r1,0,32
  1056. /* Restore the MSR (back to 64 bits) */
  1057. ld r0,_MSR(r1)
  1058. MTMSRD(r0)
  1059. isync
  1060. /* Restore other registers */
  1061. REST_GPR(2, r1)
  1062. REST_GPR(13, r1)
  1063. REST_8GPRS(14, r1)
  1064. REST_10GPRS(22, r1)
  1065. ld r4,_CCR(r1)
  1066. mtcr r4
  1067. addi r1,r1,PROM_FRAME_SIZE
  1068. ld r0,16(r1)
  1069. mtlr r0
  1070. blr
  1071. #ifdef CONFIG_FUNCTION_TRACER
  1072. #ifdef CONFIG_DYNAMIC_FTRACE
  1073. _GLOBAL(mcount)
  1074. _GLOBAL(_mcount)
  1075. blr
  1076. _GLOBAL_TOC(ftrace_caller)
  1077. /* Taken from output of objdump from lib64/glibc */
  1078. mflr r3
  1079. ld r11, 0(r1)
  1080. stdu r1, -112(r1)
  1081. std r3, 128(r1)
  1082. ld r4, 16(r11)
  1083. subi r3, r3, MCOUNT_INSN_SIZE
  1084. .globl ftrace_call
  1085. ftrace_call:
  1086. bl ftrace_stub
  1087. nop
  1088. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1089. .globl ftrace_graph_call
  1090. ftrace_graph_call:
  1091. b ftrace_graph_stub
  1092. _GLOBAL(ftrace_graph_stub)
  1093. #endif
  1094. ld r0, 128(r1)
  1095. mtlr r0
  1096. addi r1, r1, 112
  1097. _GLOBAL(ftrace_stub)
  1098. blr
  1099. #else
  1100. _GLOBAL_TOC(_mcount)
  1101. /* Taken from output of objdump from lib64/glibc */
  1102. mflr r3
  1103. ld r11, 0(r1)
  1104. stdu r1, -112(r1)
  1105. std r3, 128(r1)
  1106. ld r4, 16(r11)
  1107. subi r3, r3, MCOUNT_INSN_SIZE
  1108. LOAD_REG_ADDR(r5,ftrace_trace_function)
  1109. ld r5,0(r5)
  1110. ld r5,0(r5)
  1111. mtctr r5
  1112. bctrl
  1113. nop
  1114. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1115. b ftrace_graph_caller
  1116. #endif
  1117. ld r0, 128(r1)
  1118. mtlr r0
  1119. addi r1, r1, 112
  1120. _GLOBAL(ftrace_stub)
  1121. blr
  1122. #endif /* CONFIG_DYNAMIC_FTRACE */
  1123. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  1124. _GLOBAL(ftrace_graph_caller)
  1125. /* load r4 with local address */
  1126. ld r4, 128(r1)
  1127. subi r4, r4, MCOUNT_INSN_SIZE
  1128. /* Grab the LR out of the caller stack frame */
  1129. ld r11, 112(r1)
  1130. ld r3, 16(r11)
  1131. bl prepare_ftrace_return
  1132. nop
  1133. /*
  1134. * prepare_ftrace_return gives us the address we divert to.
  1135. * Change the LR in the callers stack frame to this.
  1136. */
  1137. ld r11, 112(r1)
  1138. std r3, 16(r11)
  1139. ld r0, 128(r1)
  1140. mtlr r0
  1141. addi r1, r1, 112
  1142. blr
  1143. _GLOBAL(return_to_handler)
  1144. /* need to save return values */
  1145. std r4, -32(r1)
  1146. std r3, -24(r1)
  1147. /* save TOC */
  1148. std r2, -16(r1)
  1149. std r31, -8(r1)
  1150. mr r31, r1
  1151. stdu r1, -112(r1)
  1152. /*
  1153. * We might be called from a module.
  1154. * Switch to our TOC to run inside the core kernel.
  1155. */
  1156. ld r2, PACATOC(r13)
  1157. bl ftrace_return_to_handler
  1158. nop
  1159. /* return value has real return address */
  1160. mtlr r3
  1161. ld r1, 0(r1)
  1162. ld r4, -32(r1)
  1163. ld r3, -24(r1)
  1164. ld r2, -16(r1)
  1165. ld r31, -8(r1)
  1166. /* Jump back to real return address */
  1167. blr
  1168. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  1169. #endif /* CONFIG_FUNCTION_TRACER */