mcount.S
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:1k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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/asm_offsets.h>
  10. #include <asm/ptrace.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 overflown"
  21. .align 8
  22. ovstack:
  23. .skip OVSTACKSIZE
  24. #endif
  25. .text
  26. .align 32
  27. .globl mcount
  28. mcount:
  29. #ifdef CONFIG_STACK_DEBUG
  30. /*
  31.  * Check whether %sp is dangerously low.
  32.  */
  33. ldub [%g6 + AOFF_task_thread + AOFF_thread_fpdepth], %g1
  34. srl %g1, 1, %g5
  35. add %g5, 1, %g5
  36. sllx %g5, 8, %g5 ! each fpregs frame is 256b
  37. add %g5, 192, %g5
  38. add %g6, %g5, %g5 ! where does task_struct+frame end?
  39. sub %g5, STACK_BIAS, %g5
  40. cmp %sp, %g5
  41. bg,pt %xcc, 1f
  42.  sethi %hi(panicstring), %g5
  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 %g5, %lo(panicstring), %o0
  50. call prom_halt
  51.  nop
  52. #endif
  53. 1: retl
  54.  nop