mcount_64.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright 2012 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * TILE-Gx specific __mcount support
  15. */
  16. #include <linux/linkage.h>
  17. #include <asm/ftrace.h>
  18. #define REGSIZE 8
  19. .text
  20. .global __mcount
  21. .macro MCOUNT_SAVE_REGS
  22. addli sp, sp, -REGSIZE
  23. {
  24. st sp, lr
  25. addli r29, sp, - (12 * REGSIZE)
  26. }
  27. {
  28. addli sp, sp, - (13 * REGSIZE)
  29. st r29, sp
  30. }
  31. addli r29, r29, REGSIZE
  32. { st r29, r0; addli r29, r29, REGSIZE }
  33. { st r29, r1; addli r29, r29, REGSIZE }
  34. { st r29, r2; addli r29, r29, REGSIZE }
  35. { st r29, r3; addli r29, r29, REGSIZE }
  36. { st r29, r4; addli r29, r29, REGSIZE }
  37. { st r29, r5; addli r29, r29, REGSIZE }
  38. { st r29, r6; addli r29, r29, REGSIZE }
  39. { st r29, r7; addli r29, r29, REGSIZE }
  40. { st r29, r8; addli r29, r29, REGSIZE }
  41. { st r29, r9; addli r29, r29, REGSIZE }
  42. { st r29, r10; addli r29, r29, REGSIZE }
  43. .endm
  44. .macro MCOUNT_RESTORE_REGS
  45. addli r29, sp, (2 * REGSIZE)
  46. { ld r0, r29; addli r29, r29, REGSIZE }
  47. { ld r1, r29; addli r29, r29, REGSIZE }
  48. { ld r2, r29; addli r29, r29, REGSIZE }
  49. { ld r3, r29; addli r29, r29, REGSIZE }
  50. { ld r4, r29; addli r29, r29, REGSIZE }
  51. { ld r5, r29; addli r29, r29, REGSIZE }
  52. { ld r6, r29; addli r29, r29, REGSIZE }
  53. { ld r7, r29; addli r29, r29, REGSIZE }
  54. { ld r8, r29; addli r29, r29, REGSIZE }
  55. { ld r9, r29; addli r29, r29, REGSIZE }
  56. { ld r10, r29; addli lr, sp, (13 * REGSIZE) }
  57. { ld lr, lr; addli sp, sp, (14 * REGSIZE) }
  58. .endm
  59. .macro RETURN_BACK
  60. { move r12, lr; move lr, r10 }
  61. jrp r12
  62. .endm
  63. #ifdef CONFIG_DYNAMIC_FTRACE
  64. .align 64
  65. STD_ENTRY(__mcount)
  66. __mcount:
  67. j ftrace_stub
  68. STD_ENDPROC(__mcount)
  69. .align 64
  70. STD_ENTRY(ftrace_caller)
  71. MCOUNT_SAVE_REGS
  72. /* arg1: self return address */
  73. /* arg2: parent's return address */
  74. /* arg3: ftrace_ops */
  75. /* arg4: regs (but make it NULL) */
  76. { move r0, lr; moveli r2, hw2_last(function_trace_op) }
  77. { move r1, r10; shl16insli r2, r2, hw1(function_trace_op) }
  78. { movei r3, 0; shl16insli r2, r2, hw0(function_trace_op) }
  79. ld r2,r2
  80. .global ftrace_call
  81. ftrace_call:
  82. /*
  83. * a placeholder for the call to a real tracing function, i.e.
  84. * ftrace_trace_function()
  85. */
  86. nop
  87. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  88. .global ftrace_graph_call
  89. ftrace_graph_call:
  90. /*
  91. * a placeholder for the call to a real tracing function, i.e.
  92. * ftrace_graph_caller()
  93. */
  94. nop
  95. #endif
  96. MCOUNT_RESTORE_REGS
  97. .global ftrace_stub
  98. ftrace_stub:
  99. RETURN_BACK
  100. STD_ENDPROC(ftrace_caller)
  101. #else /* ! CONFIG_DYNAMIC_FTRACE */
  102. .align 64
  103. STD_ENTRY(__mcount)
  104. {
  105. moveli r11, hw2_last(ftrace_trace_function)
  106. moveli r13, hw2_last(ftrace_stub)
  107. }
  108. {
  109. shl16insli r11, r11, hw1(ftrace_trace_function)
  110. shl16insli r13, r13, hw1(ftrace_stub)
  111. }
  112. {
  113. shl16insli r11, r11, hw0(ftrace_trace_function)
  114. shl16insli r13, r13, hw0(ftrace_stub)
  115. }
  116. ld r11, r11
  117. sub r14, r13, r11
  118. bnez r14, static_trace
  119. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  120. moveli r15, hw2_last(ftrace_graph_return)
  121. shl16insli r15, r15, hw1(ftrace_graph_return)
  122. shl16insli r15, r15, hw0(ftrace_graph_return)
  123. ld r15, r15
  124. sub r15, r15, r13
  125. bnez r15, ftrace_graph_caller
  126. {
  127. moveli r16, hw2_last(ftrace_graph_entry)
  128. moveli r17, hw2_last(ftrace_graph_entry_stub)
  129. }
  130. {
  131. shl16insli r16, r16, hw1(ftrace_graph_entry)
  132. shl16insli r17, r17, hw1(ftrace_graph_entry_stub)
  133. }
  134. {
  135. shl16insli r16, r16, hw0(ftrace_graph_entry)
  136. shl16insli r17, r17, hw0(ftrace_graph_entry_stub)
  137. }
  138. ld r16, r16
  139. sub r17, r16, r17
  140. bnez r17, ftrace_graph_caller
  141. #endif
  142. RETURN_BACK
  143. static_trace:
  144. MCOUNT_SAVE_REGS
  145. /* arg1: self return address */
  146. /* arg2: parent's return address */
  147. { move r0, lr; move r1, r10 }
  148. /* call ftrace_trace_function() */
  149. jalr r11
  150. MCOUNT_RESTORE_REGS
  151. .global ftrace_stub
  152. ftrace_stub:
  153. RETURN_BACK
  154. STD_ENDPROC(__mcount)
  155. #endif /* ! CONFIG_DYNAMIC_FTRACE */
  156. #ifdef CONFIG_FUNCTION_GRAPH_TRACER
  157. STD_ENTRY(ftrace_graph_caller)
  158. ftrace_graph_caller:
  159. #ifndef CONFIG_DYNAMIC_FTRACE
  160. MCOUNT_SAVE_REGS
  161. #endif
  162. /* arg1: Get the location of the parent's return address */
  163. addi r0, sp, 12 * REGSIZE
  164. /* arg2: Get self return address */
  165. move r1, lr
  166. jal prepare_ftrace_return
  167. MCOUNT_RESTORE_REGS
  168. RETURN_BACK
  169. STD_ENDPROC(ftrace_graph_caller)
  170. .global return_to_handler
  171. return_to_handler:
  172. MCOUNT_SAVE_REGS
  173. jal ftrace_return_to_handler
  174. /* restore the real parent address */
  175. move r11, r0
  176. MCOUNT_RESTORE_REGS
  177. jr r11
  178. #endif /* CONFIG_FUNCTION_GRAPH_TRACER */