entry_64.S 29 KB

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