entry_64.S 30 KB

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