entry_64.S 29 KB

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