mcount.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* PowerPC-specific implementation of profiling support.
  2. Copyright (C) 1997, 1999 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <features.h>
  17. #include "ppc_asm.h"
  18. /* This would be bad. */
  19. #ifdef PROF
  20. #undef PROF
  21. #endif
  22. /* We do profiling as described in the SYSV ELF ABI, _mcount is called
  23. with the address of a data word in r0 (that is different for every
  24. routine, initialised to 0, and otherwise unused). The caller has put
  25. the address the caller will return to in the usual place on the stack,
  26. 4(r1). _mcount is responsible for ensuring that when it returns no
  27. argument-passing registers are disturbed, and that the LR is set back
  28. to (what the caller sees as) 4(r1).
  29. This is intended so that the following code can be inserted at the
  30. front of any routine without changing the routine:
  31. .data
  32. .align 2
  33. 0: .long 0
  34. .previous
  35. mflr r0
  36. lis r11,0b@ha
  37. stw r0,4(r1)
  38. addi r0,r11,0b@l
  39. bl _mcount
  40. */
  41. .globl _mcount;
  42. .type _mcount, @function;
  43. .align 2;
  44. _mcount:
  45. stwu r1,-48(r1)
  46. /* We need to save the parameter-passing registers. */
  47. stw r3, 12(r1)
  48. stw r4, 16(r1)
  49. stw r5, 20(r1)
  50. stw r6, 24(r1)
  51. mflr r4
  52. lwz r3, 52(r1)
  53. mfcr r5
  54. stw r7, 28(r1)
  55. stw r8, 32(r1)
  56. stw r9, 36(r1)
  57. stw r10,40(r1)
  58. stw r4, 44(r1)
  59. stw r5, 8(r1)
  60. #ifdef __PIC__
  61. bl __mcount_internal@plt
  62. #else
  63. bl __mcount_internal
  64. #endif
  65. nop
  66. /* Restore the registers... */
  67. lwz r6, 8(r1)
  68. lwz r0, 44(r1)
  69. lwz r3, 12(r1)
  70. mtctr r0
  71. lwz r4, 16(r1)
  72. mtcrf 0xff,r6
  73. lwz r5, 20(r1)
  74. lwz r6, 24(r1)
  75. lwz r0, 52(r1)
  76. lwz r7, 28(r1)
  77. lwz r8, 32(r1)
  78. mtlr r0
  79. lwz r9, 36(r1)
  80. lwz r10,40(r1)
  81. /* ...unwind the stack frame, and return to your usual programming. */
  82. addi r1,r1,48
  83. bctr
  84. .size _mcount,.-_mcount;
  85. #undef mcount
  86. .weak mcount ; mcount = _mcount