entry_64.S 30 KB

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