mcount.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 2008, 2009
  4. *
  5. * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>,
  6. *
  7. */
  8. #include <linux/linkage.h>
  9. #include <asm/asm-offsets.h>
  10. #include <asm/ftrace.h>
  11. #include <asm/nospec-insn.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/export.h>
  14. GEN_BR_THUNK %r1
  15. GEN_BR_THUNK %r14
  16. .section .kprobes.text, "ax"
  17. ENTRY(ftrace_stub)
  18. BR_EX %r14
  19. #define STACK_FRAME_SIZE (STACK_FRAME_OVERHEAD + __PT_SIZE)
  20. #define STACK_PTREGS (STACK_FRAME_OVERHEAD)
  21. #define STACK_PTREGS_GPRS (STACK_PTREGS + __PT_GPRS)
  22. #define STACK_PTREGS_PSW (STACK_PTREGS + __PT_PSW)
  23. #ifdef __PACK_STACK
  24. /* allocate just enough for r14, r15 and backchain */
  25. #define TRACED_FUNC_FRAME_SIZE 24
  26. #else
  27. #define TRACED_FUNC_FRAME_SIZE STACK_FRAME_OVERHEAD
  28. #endif
  29. ENTRY(_mcount)
  30. BR_EX %r14
  31. EXPORT_SYMBOL(_mcount)
  32. ENTRY(ftrace_caller)
  33. .globl ftrace_regs_caller
  34. .set ftrace_regs_caller,ftrace_caller
  35. stg %r14,(__SF_GPRS+8*8)(%r15) # save traced function caller
  36. lgr %r1,%r15
  37. #if !(defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT))
  38. aghi %r0,MCOUNT_RETURN_FIXUP
  39. #endif
  40. # allocate stack frame for ftrace_caller to contain traced function
  41. aghi %r15,-TRACED_FUNC_FRAME_SIZE
  42. stg %r1,__SF_BACKCHAIN(%r15)
  43. stg %r0,(__SF_GPRS+8*8)(%r15)
  44. stg %r15,(__SF_GPRS+9*8)(%r15)
  45. # allocate pt_regs and stack frame for ftrace_trace_function
  46. aghi %r15,-STACK_FRAME_SIZE
  47. stg %r1,(STACK_PTREGS_GPRS+15*8)(%r15)
  48. aghi %r1,-TRACED_FUNC_FRAME_SIZE
  49. stg %r1,__SF_BACKCHAIN(%r15)
  50. stg %r0,(STACK_PTREGS_PSW+8)(%r15)
  51. stmg %r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15)
  52. #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
  53. aghik %r2,%r0,-MCOUNT_INSN_SIZE
  54. lgrl %r4,function_trace_op
  55. lgrl %r1,ftrace_trace_function
  56. #else
  57. lgr %r2,%r0
  58. aghi %r2,-MCOUNT_INSN_SIZE
  59. larl %r4,function_trace_op
  60. lg %r4,0(%r4)
  61. larl %r1,ftrace_trace_function
  62. lg %r1,0(%r1)
  63. #endif
  64. lgr %r3,%r14
  65. la %r5,STACK_PTREGS(%r15)
  66. BASR_EX %r14,%r1
  67. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  68. # The j instruction gets runtime patched to a nop instruction.
  69. # See ftrace_enable_ftrace_graph_caller.
  70. ENTRY(ftrace_graph_caller)
  71. j ftrace_graph_caller_end
  72. lg %r2,(STACK_PTREGS_GPRS+14*8)(%r15)
  73. lg %r3,(STACK_PTREGS_PSW+8)(%r15)
  74. brasl %r14,prepare_ftrace_return
  75. stg %r2,(STACK_PTREGS_GPRS+14*8)(%r15)
  76. ftrace_graph_caller_end:
  77. .globl ftrace_graph_caller_end
  78. #endif
  79. lg %r1,(STACK_PTREGS_PSW+8)(%r15)
  80. lmg %r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15)
  81. BR_EX %r1
  82. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  83. ENTRY(return_to_handler)
  84. stmg %r2,%r5,32(%r15)
  85. lgr %r1,%r15
  86. aghi %r15,-STACK_FRAME_OVERHEAD
  87. stg %r1,__SF_BACKCHAIN(%r15)
  88. brasl %r14,ftrace_return_to_handler
  89. aghi %r15,STACK_FRAME_OVERHEAD
  90. lgr %r14,%r2
  91. lmg %r2,%r5,32(%r15)
  92. BR_EX %r14
  93. #endif