ftrace_64_pg_entry.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Split from ftrace_64.S
  4. */
  5. #include <linux/export.h>
  6. #include <linux/magic.h>
  7. #include <asm/ppc_asm.h>
  8. #include <asm/asm-offsets.h>
  9. #include <asm/ftrace.h>
  10. #include <asm/ppc-opcode.h>
  11. _GLOBAL_TOC(ftrace_caller)
  12. lbz r3, PACA_FTRACE_ENABLED(r13)
  13. cmpdi r3, 0
  14. beqlr
  15. /* Taken from output of objdump from lib64/glibc */
  16. mflr r3
  17. ld r11, 0(r1)
  18. stdu r1, -112(r1)
  19. std r3, 128(r1)
  20. ld r4, 16(r11)
  21. subi r3, r3, MCOUNT_INSN_SIZE
  22. .globl ftrace_call
  23. ftrace_call:
  24. bl ftrace_stub
  25. nop
  26. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  27. .globl ftrace_graph_call
  28. ftrace_graph_call:
  29. b ftrace_graph_stub
  30. _GLOBAL(ftrace_graph_stub)
  31. #endif
  32. ld r0, 128(r1)
  33. mtlr r0
  34. addi r1, r1, 112
  35. _GLOBAL(ftrace_stub)
  36. blr
  37. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  38. _GLOBAL(ftrace_graph_caller)
  39. addi r5, r1, 112
  40. /* load r4 with local address */
  41. ld r4, 128(r1)
  42. subi r4, r4, MCOUNT_INSN_SIZE
  43. /* Grab the LR out of the caller stack frame */
  44. ld r11, 112(r1)
  45. ld r3, 16(r11)
  46. bl prepare_ftrace_return
  47. nop
  48. /*
  49. * prepare_ftrace_return gives us the address we divert to.
  50. * Change the LR in the callers stack frame to this.
  51. */
  52. ld r11, 112(r1)
  53. std r3, 16(r11)
  54. ld r0, 128(r1)
  55. mtlr r0
  56. addi r1, r1, 112
  57. blr
  58. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */
  59. .pushsection ".tramp.ftrace.text","aw",@progbits;
  60. .globl ftrace_tramp_text
  61. ftrace_tramp_text:
  62. .space 32
  63. .popsection
  64. .pushsection ".tramp.ftrace.init","aw",@progbits;
  65. .globl ftrace_tramp_init
  66. ftrace_tramp_init:
  67. .space 32
  68. .popsection
  69. _GLOBAL(mcount)
  70. _GLOBAL(_mcount)
  71. EXPORT_SYMBOL(_mcount)
  72. mflr r12
  73. mtctr r12
  74. mtlr r0
  75. bctr
  76. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  77. _GLOBAL(return_to_handler)
  78. /* need to save return values */
  79. #ifdef CONFIG_PPC64
  80. std r4, -32(r1)
  81. std r3, -24(r1)
  82. /* save TOC */
  83. std r2, -16(r1)
  84. std r31, -8(r1)
  85. mr r31, r1
  86. stdu r1, -112(r1)
  87. /*
  88. * We might be called from a module.
  89. * Switch to our TOC to run inside the core kernel.
  90. */
  91. LOAD_PACA_TOC()
  92. #else
  93. stwu r1, -16(r1)
  94. stw r3, 8(r1)
  95. stw r4, 12(r1)
  96. #endif
  97. bl ftrace_return_to_handler
  98. nop
  99. /* return value has real return address */
  100. mtlr r3
  101. #ifdef CONFIG_PPC64
  102. ld r1, 0(r1)
  103. ld r4, -32(r1)
  104. ld r3, -24(r1)
  105. ld r2, -16(r1)
  106. ld r31, -8(r1)
  107. #else
  108. lwz r3, 8(r1)
  109. lwz r4, 12(r1)
  110. addi r1, r1, 16
  111. #endif
  112. /* Jump back to real return address */
  113. blr
  114. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */