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. lgr %r1,%r15
  36. #if !(defined(CC_USING_HOTPATCH) || defined(CC_USING_NOP_MCOUNT))
  37. aghi %r0,MCOUNT_RETURN_FIXUP
  38. #endif
  39. # allocate stack frame for ftrace_caller to contain traced function
  40. aghi %r15,-TRACED_FUNC_FRAME_SIZE
  41. stg %r1,__SF_BACKCHAIN(%r15)
  42. stg %r0,(__SF_GPRS+8*8)(%r15)
  43. stg %r15,(__SF_GPRS+9*8)(%r15)
  44. # allocate pt_regs and stack frame for ftrace_trace_function
  45. aghi %r15,-STACK_FRAME_SIZE
  46. stg %r1,(STACK_PTREGS_GPRS+15*8)(%r15)
  47. aghi %r1,-TRACED_FUNC_FRAME_SIZE
  48. stg %r1,__SF_BACKCHAIN(%r15)
  49. stg %r0,(STACK_PTREGS_PSW+8)(%r15)
  50. stmg %r2,%r14,(STACK_PTREGS_GPRS+2*8)(%r15)
  51. #ifdef CONFIG_HAVE_MARCH_Z196_FEATURES
  52. aghik %r2,%r0,-MCOUNT_INSN_SIZE
  53. lgrl %r4,function_trace_op
  54. lgrl %r1,ftrace_trace_function
  55. #else
  56. lgr %r2,%r0
  57. aghi %r2,-MCOUNT_INSN_SIZE
  58. larl %r4,function_trace_op
  59. lg %r4,0(%r4)
  60. larl %r1,ftrace_trace_function
  61. lg %r1,0(%r1)
  62. #endif
  63. lgr %r3,%r14
  64. la %r5,STACK_PTREGS(%r15)
  65. BASR_EX %r14,%r1
  66. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  67. # The j instruction gets runtime patched to a nop instruction.
  68. # See ftrace_enable_ftrace_graph_caller.
  69. ENTRY(ftrace_graph_caller)
  70. j ftrace_graph_caller_end
  71. lg %r2,(STACK_PTREGS_GPRS+14*8)(%r15)
  72. lg %r3,(STACK_PTREGS_PSW+8)(%r15)
  73. brasl %r14,prepare_ftrace_return
  74. stg %r2,(STACK_PTREGS_GPRS+14*8)(%r15)
  75. ftrace_graph_caller_end:
  76. .globl ftrace_graph_caller_end
  77. #endif
  78. lg %r1,(STACK_PTREGS_PSW+8)(%r15)
  79. lmg %r2,%r15,(STACK_PTREGS_GPRS+2*8)(%r15)
  80. BR_EX %r1
  81. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  82. ENTRY(return_to_handler)
  83. stmg %r2,%r5,32(%r15)
  84. lgr %r1,%r15
  85. aghi %r15,-STACK_FRAME_OVERHEAD
  86. stg %r1,__SF_BACKCHAIN(%r15)
  87. brasl %r14,ftrace_return_to_handler
  88. aghi %r15,STACK_FRAME_OVERHEAD
  89. lgr %r14,%r2
  90. lmg %r2,%r5,32(%r15)
  91. BR_EX %r14
  92. #endif