mcount.S 2.5 KB

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