mcount.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* If we are already on ovstack, don't hop onto it
  47. * again, we are already trying to output the stack overflow
  48. * message.
  49. */
  50. sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
  51. or %g7, %lo(ovstack), %g7
  52. add %g7, OVSTACKSIZE, %g3
  53. sub %g3, STACK_BIAS + 192, %g3
  54. sub %g7, STACK_BIAS, %g7
  55. cmp %sp, %g7
  56. blu,pn %xcc, 2f
  57. cmp %sp, %g3
  58. bleu,pn %xcc, 1f
  59. nop
  60. 2: mov %g3, %sp
  61. sethi %hi(panicstring), %g3
  62. call prom_printf
  63. or %g3, %lo(panicstring), %o0
  64. call prom_halt
  65. nop
  66. 1:
  67. #endif
  68. #ifdef CONFIG_FTRACE
  69. #ifdef CONFIG_DYNAMIC_FTRACE
  70. mov %o7, %o0
  71. .globl mcount_call
  72. mcount_call:
  73. call ftrace_stub
  74. mov %o0, %o7
  75. #else
  76. sethi %hi(ftrace_trace_function), %g1
  77. sethi %hi(ftrace_stub), %g2
  78. ldx [%g1 + %lo(ftrace_trace_function)], %g1
  79. or %g2, %lo(ftrace_stub), %g2
  80. cmp %g1, %g2
  81. be,pn %icc, 1f
  82. mov %i7, %o1
  83. jmpl %g1, %g0
  84. mov %o7, %o0
  85. /* not reached */
  86. 1:
  87. #endif
  88. #endif
  89. retl
  90. nop
  91. .size _mcount,.-_mcount
  92. .size mcount,.-mcount
  93. #ifdef CONFIG_FTRACE
  94. .globl ftrace_stub
  95. .type ftrace_stub,#function
  96. ftrace_stub:
  97. retl
  98. nop
  99. .size ftrace_stub,.-ftrace_stub
  100. #ifdef CONFIG_DYNAMIC_FTRACE
  101. .globl ftrace_caller
  102. .type ftrace_caller,#function
  103. ftrace_caller:
  104. mov %i7, %o1
  105. mov %o7, %o0
  106. .globl ftrace_call
  107. ftrace_call:
  108. call ftrace_stub
  109. mov %o0, %o7
  110. retl
  111. nop
  112. .size ftrace_caller,.-ftrace_caller
  113. #endif
  114. #endif