mcount.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. sethi %hi(panicstring), %g3
  46. sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
  47. or %g7, %lo(ovstack), %g7
  48. add %g7, OVSTACKSIZE, %g7
  49. sub %g7, STACK_BIAS, %g7
  50. mov %g7, %sp
  51. call prom_printf
  52. or %g3, %lo(panicstring), %o0
  53. call prom_halt
  54. nop
  55. 1:
  56. #endif
  57. #ifdef CONFIG_FTRACE
  58. #ifdef CONFIG_DYNAMIC_FTRACE
  59. mov %o7, %o0
  60. .globl mcount_call
  61. mcount_call:
  62. call ftrace_stub
  63. mov %o0, %o7
  64. #else
  65. sethi %hi(ftrace_trace_function), %g1
  66. sethi %hi(ftrace_stub), %g2
  67. ldx [%g1 + %lo(ftrace_trace_function)], %g1
  68. or %g2, %lo(ftrace_stub), %g2
  69. cmp %g1, %g2
  70. be,pn %icc, 1f
  71. mov %i7, %o1
  72. jmpl %g1, %g0
  73. mov %o7, %o0
  74. /* not reached */
  75. 1:
  76. #endif
  77. #endif
  78. retl
  79. nop
  80. .size _mcount,.-_mcount
  81. .size mcount,.-mcount
  82. #ifdef CONFIG_FTRACE
  83. .globl ftrace_stub
  84. .type ftrace_stub,#function
  85. ftrace_stub:
  86. retl
  87. nop
  88. .size ftrace_stub,.-ftrace_stub
  89. #ifdef CONFIG_DYNAMIC_FTRACE
  90. .globl ftrace_caller
  91. .type ftrace_caller,#function
  92. ftrace_caller:
  93. mov %i7, %o1
  94. mov %o7, %o0
  95. .globl ftrace_call
  96. ftrace_call:
  97. call ftrace_stub
  98. mov %o0, %o7
  99. retl
  100. nop
  101. .size ftrace_caller,.-ftrace_caller
  102. #endif
  103. #endif