profile.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*-
  2. * SPDX-License-Identifier: MIT-CMU
  3. *
  4. * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
  5. * All rights reserved.
  6. *
  7. * Author: Chris G. Demetriou
  8. *
  9. * Permission to use, copy, modify and distribute this software and
  10. * its documentation is hereby granted, provided that both the copyright
  11. * notice and this permission notice appear in all copies of the
  12. * software, derivative works or modified versions, and any portions
  13. * thereof, and that both notices appear in supporting documentation.
  14. *
  15. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  16. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
  17. * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  18. *
  19. * Carnegie Mellon requests users of this software to return to
  20. *
  21. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  22. * School of Computer Science
  23. * Carnegie Mellon University
  24. * Pittsburgh PA 15213-3890
  25. *
  26. * any improvements or extensions that they make and grant Carnegie the
  27. * rights to redistribute these changes.
  28. *
  29. * from: NetBSD: profile.h,v 1.9 1997/04/06 08:47:37 cgd Exp
  30. * from: FreeBSD: src/sys/alpha/include/profile.h,v 1.4 1999/12/29
  31. * $FreeBSD$
  32. */
  33. #ifndef _MACHINE_PROFILE_H_
  34. #define _MACHINE_PROFILE_H_
  35. #define _MCOUNT_DECL void __mcount
  36. #define FUNCTION_ALIGNMENT 4
  37. typedef __ptrdiff_t fptrdiff_t;
  38. /*
  39. * The mcount trampoline macro, expanded in libc/gmon/mcount.c
  40. *
  41. * For PowerPC SVR4 ABI profiling, the compiler will insert
  42. * a data declaration and code sequence at the start of a routine of the form
  43. *
  44. * .function_mc: .data
  45. * .align 2
  46. * .long 0
  47. * .text
  48. *
  49. * function: mflr %r0
  50. * addis %r11,%r0, .function_mc@ha
  51. * stw %r0,4(%r1)
  52. * addi %r0,%r11, .function_mc@l
  53. * bl _mcount
  54. *
  55. * The link register is saved in the LR save word in the caller's
  56. * stack frame, r0 is set up to point to the allocated longword,
  57. * and control is transferred to _mcount.
  58. *
  59. * On return from _mcount, the routine should function as it would
  60. * with no profiling so _mcount must restore register state to that upon
  61. * entry. Any routine called by the _mcount trampoline will save
  62. * callee-save registers, so _mcount must make sure it saves volatile
  63. * registers that may have state after it returns i.e. parameter registers.
  64. *
  65. * The FreeBSD libc mcount routine ignores the r0 longword pointer, but
  66. * instead requires as parameters the current PC and called PC. The current
  67. * PC is obtained from the link register, as a result of "bl _mcount" in
  68. * the stub, while the caller's PC is obtained from the LR save word.
  69. *
  70. * On return from libc mcount, the return is done indirectly with the
  71. * ctr register rather than the link register, to allow the link register
  72. * to be restored to what it was on entry to the profiled routine.
  73. */
  74. #if defined(__powerpc64__)
  75. #if !defined(_CALL_ELF) || _CALL_ELF == 1
  76. #define MCOUNT_PREAMBLE \
  77. " .align 2 \n" \
  78. " .globl _mcount \n" \
  79. " .section \".opd\",\"aw\" \n" \
  80. " .align 3 \n" \
  81. "_mcount: \n" \
  82. " .quad .L._mcount,.TOC.@tocbase,0\n" \
  83. " .previous \n" \
  84. " .size _mcount,24 \n" \
  85. " .type _mcount,@function \n" \
  86. " .align 4 \n" \
  87. ".L._mcount: \n"
  88. #else
  89. #define MCOUNT_PREAMBLE \
  90. " .globl _mcount \n" \
  91. " .type _mcount,@function \n" \
  92. " .align 4 \n" \
  93. "_mcount: \n"
  94. #endif
  95. #define MCOUNT \
  96. __asm( MCOUNT_PREAMBLE \
  97. " stdu %r1,-(288+128)(%r1) \n" \
  98. " std %r3,48(%r1) \n" \
  99. " std %r4,56(%r1) \n" \
  100. " std %r5,64(%r1) \n" \
  101. " std %r6,72(%r1) \n" \
  102. " std %r7,80(%r1) \n" \
  103. " std %r8,88(%r1) \n" \
  104. " std %r9,96(%r1) \n" \
  105. " std %r10,104(%r1) \n" \
  106. " mflr %r4 \n" \
  107. " std %r4,112(%r1) \n" \
  108. " ld %r3,0(%r1) \n" \
  109. " ld %r3,0(%r3) \n" \
  110. " ld %r3,16(%r3) \n" \
  111. " bl __mcount \n" \
  112. " nop \n" \
  113. " ld %r4,112(%r1) \n" \
  114. " mtlr %r4 \n" \
  115. " ld %r3,48(%r1) \n" \
  116. " ld %r4,56(%r1) \n" \
  117. " ld %r5,64(%r1) \n" \
  118. " ld %r6,72(%r1) \n" \
  119. " ld %r7,80(%r1) \n" \
  120. " ld %r8,88(%r1) \n" \
  121. " ld %r9,96(%r1) \n" \
  122. " ld %r10,104(%r1) \n" \
  123. " addi %r1,%r1,(288+128) \n" \
  124. " blr \n");
  125. #else
  126. #ifdef PIC
  127. #define _PLT "@plt"
  128. #else
  129. #define _PLT
  130. #endif
  131. #define MCOUNT \
  132. __asm( " .globl _mcount \n" \
  133. " .type _mcount,@function \n" \
  134. " .align 4 \n" \
  135. "_mcount: \n" \
  136. " stwu %r1,-64(%r1) \n" \
  137. " stw %r3,16(%r1) \n" \
  138. " stw %r4,20(%r1) \n" \
  139. " stw %r5,24(%r1) \n" \
  140. " stw %r6,28(%r1) \n" \
  141. " stw %r7,32(%r1) \n" \
  142. " stw %r8,36(%r1) \n" \
  143. " stw %r9,40(%r1) \n" \
  144. " stw %r10,44(%r1) \n" \
  145. " mflr %r4 \n" \
  146. " stw %r4,48(%r1) \n" \
  147. " lwz %r3,68(%r1) \n" \
  148. " bl __mcount" _PLT " \n" \
  149. " lwz %r3,68(%r1) \n" \
  150. " mtlr %r3 \n" \
  151. " lwz %r4,48(%r1) \n" \
  152. " mtctr %r4 \n" \
  153. " lwz %r3,16(%r1) \n" \
  154. " lwz %r4,20(%r1) \n" \
  155. " lwz %r5,24(%r1) \n" \
  156. " lwz %r6,28(%r1) \n" \
  157. " lwz %r7,32(%r1) \n" \
  158. " lwz %r8,36(%r1) \n" \
  159. " lwz %r9,40(%r1) \n" \
  160. " lwz %r10,44(%r1) \n" \
  161. " addi %r1,%r1,64 \n" \
  162. " bctr \n" \
  163. "_mcount_end: \n" \
  164. " .size _mcount,_mcount_end-_mcount");
  165. #endif
  166. #ifdef _KERNEL
  167. #define MCOUNT_ENTER(s) s = intr_disable()
  168. #define MCOUNT_EXIT(s) intr_restore(s)
  169. #define MCOUNT_DECL(s) register_t s;
  170. #ifndef COMPILING_LINT
  171. #ifdef AIM
  172. #include <machine/trap.h>
  173. #define __PROFILE_VECTOR_BASE EXC_RST
  174. #define __PROFILE_VECTOR_TOP (EXC_LAST + 0x100)
  175. #endif /* AIM */
  176. #if defined(BOOKE)
  177. extern char interrupt_vector_base[];
  178. extern char interrupt_vector_top[];
  179. #define __PROFILE_VECTOR_BASE (uintfptr_t)interrupt_vector_base
  180. #define __PROFILE_VECTOR_TOP (uintfptr_t)interrupt_vector_top
  181. #endif /* BOOKE_E500 */
  182. #endif /* !COMPILING_LINT */
  183. #ifndef __PROFILE_VECTOR_BASE
  184. #define __PROFILE_VECTOR_BASE 0
  185. #endif
  186. #ifndef __PROFILE_VECTOR_TOP
  187. #define __PROFILE_VECTOR_TOP 1
  188. #endif
  189. static __inline void
  190. powerpc_profile_interrupt(void)
  191. {
  192. }
  193. static __inline void
  194. powerpc_profile_userspace(void)
  195. {
  196. }
  197. #define MCOUNT_FROMPC_USER(pc) \
  198. ((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? \
  199. (uintfptr_t)powerpc_profile_userspace : pc)
  200. #define MCOUNT_FROMPC_INTR(pc) \
  201. ((pc >= __PROFILE_VECTOR_BASE && \
  202. pc < __PROFILE_VECTOR_TOP) ? \
  203. (uintfptr_t)powerpc_profile_interrupt : ~0U)
  204. void __mcount(uintfptr_t frompc, uintfptr_t selfpc);
  205. #else /* !_KERNEL */
  206. #ifdef __powerpc64__
  207. typedef u_long uintfptr_t;
  208. #else
  209. typedef u_int uintfptr_t;
  210. #endif
  211. #endif /* _KERNEL */
  212. #endif /* !_MACHINE_PROFILE_H_ */