mcount.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com)
  3. *
  4. * This file implements mcount(), which is used to collect profiling data.
  5. * This can also be tweaked for kernel stack overflow detection.
  6. */
  7. #include <linux/linkage.h>
  8. #include <asm/export.h>
  9. /*
  10. * This is the main variant and is called by C code. GCC's -pg option
  11. * automatically instruments every C function with a call to this.
  12. */
  13. .text
  14. .align 32
  15. .globl _mcount
  16. .type _mcount,#function
  17. EXPORT_SYMBOL(_mcount)
  18. .globl mcount
  19. .type mcount,#function
  20. _mcount:
  21. mcount:
  22. #ifdef CONFIG_FUNCTION_TRACER
  23. #ifdef CONFIG_DYNAMIC_FTRACE
  24. /* Do nothing, the retl/nop below is all we need. */
  25. #else
  26. sethi %hi(ftrace_trace_function), %g1
  27. sethi %hi(ftrace_stub), %g2
  28. ldx [%g1 + %lo(ftrace_trace_function)], %g1
  29. or %g2, %lo(ftrace_stub), %g2
  30. cmp %g1, %g2
  31. be,pn %icc, 1f
  32. mov %i7, %g3
  33. save %sp, -176, %sp
  34. mov %g3, %o1
  35. jmpl %g1, %o7
  36. mov %i7, %o0
  37. ret
  38. restore
  39. /* not reached */
  40. 1:
  41. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  42. sethi %hi(ftrace_graph_return), %g1
  43. ldx [%g1 + %lo(ftrace_graph_return)], %g3
  44. cmp %g2, %g3
  45. bne,pn %xcc, 5f
  46. sethi %hi(ftrace_graph_entry_stub), %g2
  47. sethi %hi(ftrace_graph_entry), %g1
  48. or %g2, %lo(ftrace_graph_entry_stub), %g2
  49. ldx [%g1 + %lo(ftrace_graph_entry)], %g1
  50. cmp %g1, %g2
  51. be,pt %xcc, 2f
  52. nop
  53. 5: mov %i7, %g2
  54. mov %fp, %g3
  55. save %sp, -176, %sp
  56. mov %g2, %l0
  57. ba,pt %xcc, ftrace_graph_caller
  58. mov %g3, %l1
  59. #endif
  60. 2:
  61. #endif
  62. #endif
  63. retl
  64. nop
  65. .size _mcount,.-_mcount
  66. .size mcount,.-mcount
  67. #ifdef CONFIG_FUNCTION_TRACER
  68. .globl ftrace_stub
  69. .type ftrace_stub,#function
  70. ftrace_stub:
  71. retl
  72. nop
  73. .size ftrace_stub,.-ftrace_stub
  74. #ifdef CONFIG_DYNAMIC_FTRACE
  75. .globl ftrace_caller
  76. .type ftrace_caller,#function
  77. ftrace_caller:
  78. mov %i7, %g2
  79. mov %fp, %g3
  80. save %sp, -176, %sp
  81. mov %g2, %o1
  82. mov %g2, %l0
  83. mov %g3, %l1
  84. .globl ftrace_call
  85. ftrace_call:
  86. call ftrace_stub
  87. mov %i7, %o0
  88. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  89. .globl ftrace_graph_call
  90. ftrace_graph_call:
  91. call ftrace_stub
  92. nop
  93. #endif
  94. ret
  95. restore
  96. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  97. .size ftrace_graph_call,.-ftrace_graph_call
  98. #endif
  99. .size ftrace_call,.-ftrace_call
  100. .size ftrace_caller,.-ftrace_caller
  101. #endif
  102. #endif
  103. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  104. ENTRY(ftrace_graph_caller)
  105. mov %l0, %o0
  106. mov %i7, %o1
  107. call prepare_ftrace_return
  108. mov %l1, %o2
  109. ret
  110. restore %o0, -8, %i7
  111. END(ftrace_graph_caller)
  112. ENTRY(return_to_handler)
  113. save %sp, -176, %sp
  114. call ftrace_return_to_handler
  115. mov %fp, %o0
  116. jmpl %o0 + 8, %g0
  117. restore
  118. END(return_to_handler)
  119. #endif