entry_64.S 29 KB

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