mcount.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/ptrace.h>
  9. #include <asm/thread_info.h>
  10. /*
  11. * This is the main variant and is called by C code. GCC's -pg option
  12. * automatically instruments every C function with a call to this.
  13. */
  14. #ifdef CONFIG_STACK_DEBUG
  15. #define OVSTACKSIZE 4096 /* lets hope this is enough */
  16. .data
  17. .align 8
  18. panicstring:
  19. .asciz "Stack overflow\n"
  20. .align 8
  21. ovstack:
  22. .skip OVSTACKSIZE
  23. #endif
  24. .text
  25. .align 32
  26. .globl _mcount
  27. .type _mcount,#function
  28. .globl mcount
  29. .type mcount,#function
  30. _mcount:
  31. mcount:
  32. #ifdef CONFIG_STACK_DEBUG
  33. /*
  34. * Check whether %sp is dangerously low.
  35. */
  36. ldub [%g6 + TI_FPDEPTH], %g1
  37. srl %g1, 1, %g3
  38. add %g3, 1, %g3
  39. sllx %g3, 8, %g3 ! each fpregs frame is 256b
  40. add %g3, 192, %g3
  41. add %g6, %g3, %g3 ! where does task_struct+frame end?
  42. sub %g3, STACK_BIAS, %g3
  43. cmp %sp, %g3
  44. bg,pt %xcc, 1f
  45. nop
  46. lduh [%g6 + TI_CPU], %g1
  47. sethi %hi(hardirq_stack), %g3
  48. or %g3, %lo(hardirq_stack), %g3
  49. sllx %g1, 3, %g1
  50. ldx [%g3 + %g1], %g7
  51. sub %g7, STACK_BIAS, %g7
  52. cmp %sp, %g7
  53. bleu,pt %xcc, 2f
  54. sethi %hi(THREAD_SIZE), %g3
  55. add %g7, %g3, %g7
  56. cmp %sp, %g7
  57. blu,pn %xcc, 1f
  58. 2: sethi %hi(softirq_stack), %g3
  59. or %g3, %lo(softirq_stack), %g3
  60. ldx [%g3 + %g1], %g7
  61. cmp %sp, %g7
  62. bleu,pt %xcc, 2f
  63. sethi %hi(THREAD_SIZE), %g3
  64. add %g7, %g3, %g7
  65. cmp %sp, %g7
  66. blu,pn %xcc, 1f
  67. nop
  68. /* If we are already on ovstack, don't hop onto it
  69. * again, we are already trying to output the stack overflow
  70. * message.
  71. */
  72. sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
  73. or %g7, %lo(ovstack), %g7
  74. add %g7, OVSTACKSIZE, %g3
  75. sub %g3, STACK_BIAS + 192, %g3
  76. sub %g7, STACK_BIAS, %g7
  77. cmp %sp, %g7
  78. blu,pn %xcc, 2f
  79. cmp %sp, %g3
  80. bleu,pn %xcc, 1f
  81. nop
  82. 2: mov %g3, %sp
  83. sethi %hi(panicstring), %g3
  84. call prom_printf
  85. or %g3, %lo(panicstring), %o0
  86. call prom_halt
  87. nop
  88. 1:
  89. #endif
  90. #ifdef CONFIG_FUNCTION_TRACER
  91. #ifdef CONFIG_DYNAMIC_FTRACE
  92. mov %o7, %o0
  93. .globl mcount_call
  94. mcount_call:
  95. call ftrace_stub
  96. mov %o0, %o7
  97. #else
  98. sethi %hi(ftrace_trace_function), %g1
  99. sethi %hi(ftrace_stub), %g2
  100. ldx [%g1 + %lo(ftrace_trace_function)], %g1
  101. or %g2, %lo(ftrace_stub), %g2
  102. cmp %g1, %g2
  103. be,pn %icc, 1f
  104. mov %i7, %o1
  105. jmpl %g1, %g0
  106. mov %o7, %o0
  107. /* not reached */
  108. 1:
  109. #endif
  110. #endif
  111. retl
  112. nop
  113. .size _mcount,.-_mcount
  114. .size mcount,.-mcount
  115. #ifdef CONFIG_FUNCTION_TRACER
  116. .globl ftrace_stub
  117. .type ftrace_stub,#function
  118. ftrace_stub:
  119. retl
  120. nop
  121. .size ftrace_stub,.-ftrace_stub
  122. #ifdef CONFIG_DYNAMIC_FTRACE
  123. .globl ftrace_caller
  124. .type ftrace_caller,#function
  125. ftrace_caller:
  126. mov %i7, %o1
  127. mov %o7, %o0
  128. .globl ftrace_call
  129. ftrace_call:
  130. call ftrace_stub
  131. mov %o0, %o7
  132. retl
  133. nop
  134. .size ftrace_caller,.-ftrace_caller
  135. #endif
  136. #endif