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