mcount.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/config.h>
  8. #include <linux/linkage.h>
  9. #include <asm/ptrace.h>
  10. #include <asm/thread_info.h>
  11. /*
  12. * This is the main variant and is called by C code. GCC's -pg option
  13. * automatically instruments every C function with a call to this.
  14. */
  15. #ifdef CONFIG_STACK_DEBUG
  16. #define OVSTACKSIZE 4096 /* lets hope this is enough */
  17. .data
  18. .align 8
  19. panicstring:
  20. .asciz "Stack overflow\n"
  21. .align 8
  22. ovstack:
  23. .skip OVSTACKSIZE
  24. #endif
  25. .text
  26. .align 32
  27. .globl mcount, _mcount
  28. mcount:
  29. _mcount:
  30. #ifdef CONFIG_STACK_DEBUG
  31. /*
  32. * Check whether %sp is dangerously low.
  33. */
  34. ldub [%g6 + TI_FPDEPTH], %g1
  35. srl %g1, 1, %g3
  36. add %g3, 1, %g3
  37. sllx %g3, 8, %g3 ! each fpregs frame is 256b
  38. add %g3, 192, %g3
  39. add %g6, %g3, %g3 ! where does task_struct+frame end?
  40. sub %g3, STACK_BIAS, %g3
  41. cmp %sp, %g3
  42. bg,pt %xcc, 1f
  43. sethi %hi(panicstring), %g3
  44. sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
  45. or %g7, %lo(ovstack), %g7
  46. add %g7, OVSTACKSIZE, %g7
  47. sub %g7, STACK_BIAS, %g7
  48. mov %g7, %sp
  49. call prom_printf
  50. or %g3, %lo(panicstring), %o0
  51. call prom_halt
  52. nop
  53. #endif
  54. 1: retl
  55. nop