2 * SPDX-License-Identifier: MIT-CMU
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
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.
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.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
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
34 #ifndef _MACHINE_PROFILE_H_
35 #define _MACHINE_PROFILE_H_
37 #define _MCOUNT_DECL void __mcount
39 #define FUNCTION_ALIGNMENT 4
41 typedef __ptrdiff_t fptrdiff_t;
44 * The mcount trampoline macro, expanded in libc/gmon/mcount.c
46 * For PowerPC SVR4 ABI profiling, the compiler will insert
47 * a data declaration and code sequence at the start of a routine of the form
55 * addis %r11,%r0, .function_mc@ha
57 * addi %r0,%r11, .function_mc@l
60 * The link register is saved in the LR save word in the caller's
61 * stack frame, r0 is set up to point to the allocated longword,
62 * and control is transferred to _mcount.
64 * On return from _mcount, the routine should function as it would
65 * with no profiling so _mcount must restore register state to that upon
66 * entry. Any routine called by the _mcount trampoline will save
67 * callee-save registers, so _mcount must make sure it saves volatile
68 * registers that may have state after it returns i.e. parameter registers.
70 * The FreeBSD libc mcount routine ignores the r0 longword pointer, but
71 * instead requires as parameters the current PC and called PC. The current
72 * PC is obtained from the link register, as a result of "bl _mcount" in
73 * the stub, while the caller's PC is obtained from the LR save word.
75 * On return from libc mcount, the return is done indirectly with the
76 * ctr register rather than the link register, to allow the link register
77 * to be restored to what it was on entry to the profiled routine.
80 #if defined(__powerpc64__)
82 #if !defined(_CALL_ELF) || _CALL_ELF == 1
83 #define MCOUNT_PREAMBLE \
85 " .globl _mcount \n" \
86 " .section \".opd\",\"aw\" \n" \
89 " .quad .L._mcount,.TOC.@tocbase,0\n" \
91 " .size _mcount,24 \n" \
92 " .type _mcount,@function \n" \
96 #define MCOUNT_PREAMBLE \
97 " .globl _mcount \n" \
98 " .type _mcount,@function \n" \
104 __asm( MCOUNT_PREAMBLE \
105 " stdu %r1,-(288+128)(%r1) \n" \
106 " std %r3,48(%r1) \n" \
107 " std %r4,56(%r1) \n" \
108 " std %r5,64(%r1) \n" \
109 " std %r6,72(%r1) \n" \
110 " std %r7,80(%r1) \n" \
111 " std %r8,88(%r1) \n" \
112 " std %r9,96(%r1) \n" \
113 " std %r10,104(%r1) \n" \
115 " std %r4,112(%r1) \n" \
116 " ld %r3,0(%r1) \n" \
117 " ld %r3,0(%r3) \n" \
118 " ld %r3,16(%r3) \n" \
121 " ld %r4,112(%r1) \n" \
123 " ld %r3,48(%r1) \n" \
124 " ld %r4,56(%r1) \n" \
125 " ld %r5,64(%r1) \n" \
126 " ld %r6,72(%r1) \n" \
127 " ld %r7,80(%r1) \n" \
128 " ld %r8,88(%r1) \n" \
129 " ld %r9,96(%r1) \n" \
130 " ld %r10,104(%r1) \n" \
131 " addi %r1,%r1,(288+128) \n" \
142 __asm( " .globl _mcount \n" \
143 " .type _mcount,@function \n" \
146 " stwu %r1,-64(%r1) \n" \
147 " stw %r3,16(%r1) \n" \
148 " stw %r4,20(%r1) \n" \
149 " stw %r5,24(%r1) \n" \
150 " stw %r6,28(%r1) \n" \
151 " stw %r7,32(%r1) \n" \
152 " stw %r8,36(%r1) \n" \
153 " stw %r9,40(%r1) \n" \
154 " stw %r10,44(%r1) \n" \
156 " stw %r4,48(%r1) \n" \
157 " lwz %r3,68(%r1) \n" \
158 " bl __mcount" _PLT " \n" \
159 " lwz %r3,68(%r1) \n" \
161 " lwz %r4,48(%r1) \n" \
163 " lwz %r3,16(%r1) \n" \
164 " lwz %r4,20(%r1) \n" \
165 " lwz %r5,24(%r1) \n" \
166 " lwz %r6,28(%r1) \n" \
167 " lwz %r7,32(%r1) \n" \
168 " lwz %r8,36(%r1) \n" \
169 " lwz %r9,40(%r1) \n" \
170 " lwz %r10,44(%r1) \n" \
171 " addi %r1,%r1,64 \n" \
174 " .size _mcount,_mcount_end-_mcount");
178 #define MCOUNT_ENTER(s) s = intr_disable()
179 #define MCOUNT_EXIT(s) intr_restore(s)
180 #define MCOUNT_DECL(s) register_t s;
182 #ifndef COMPILING_LINT
184 #include <machine/trap.h>
185 #define __PROFILE_VECTOR_BASE EXC_RST
186 #define __PROFILE_VECTOR_TOP (EXC_LAST + 0x100)
189 extern char interrupt_vector_base[];
190 extern char interrupt_vector_top[];
191 #define __PROFILE_VECTOR_BASE (uintfptr_t)interrupt_vector_base
192 #define __PROFILE_VECTOR_TOP (uintfptr_t)interrupt_vector_top
193 #endif /* BOOKE_E500 */
195 #endif /* !COMPILING_LINT */
197 #ifndef __PROFILE_VECTOR_BASE
198 #define __PROFILE_VECTOR_BASE 0
200 #ifndef __PROFILE_VECTOR_TOP
201 #define __PROFILE_VECTOR_TOP 1
205 powerpc_profile_interrupt(void)
210 powerpc_profile_userspace(void)
214 #define MCOUNT_FROMPC_USER(pc) \
215 ((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? \
216 (uintfptr_t)powerpc_profile_userspace : pc)
218 #define MCOUNT_FROMPC_INTR(pc) \
219 ((pc >= __PROFILE_VECTOR_BASE && \
220 pc < __PROFILE_VECTOR_TOP) ? \
221 (uintfptr_t)powerpc_profile_interrupt : ~0U)
223 void __mcount(uintfptr_t frompc, uintfptr_t selfpc);
228 typedef u_long uintfptr_t;
230 typedef u_int uintfptr_t;
235 #endif /* !_MACHINE_PROFILE_H_ */