mcount.S 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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, _mcount
  27. mcount:
  28. _mcount:
  29. #ifdef CONFIG_STACK_DEBUG
  30. /*
  31. * Check whether %sp is dangerously low.
  32. */
  33. ldub [%g6 + TI_FPDEPTH], %g1
  34. srl %g1, 1, %g3
  35. add %g3, 1, %g3
  36. sllx %g3, 8, %g3 ! each fpregs frame is 256b
  37. add %g3, 192, %g3
  38. add %g6, %g3, %g3 ! where does task_struct+frame end?
  39. sub %g3, STACK_BIAS, %g3
  40. cmp %sp, %g3
  41. bg,pt %xcc, 1f
  42. sethi %hi(panicstring), %g3
  43. sethi %hi(ovstack), %g7 ! cant move to panic stack fast enough
  44. or %g7, %lo(ovstack), %g7
  45. add %g7, OVSTACKSIZE, %g7
  46. sub %g7, STACK_BIAS, %g7
  47. mov %g7, %sp
  48. call prom_printf
  49. or %g3, %lo(panicstring), %o0
  50. call prom_halt
  51. nop
  52. #endif
  53. 1: retl
  54. nop