xref: /freebsd/sys/arm/include/profile.h (revision 29363fb446372cb3f10bc98664e9767c53fbb457)
1d8315c79SWarner Losh /*-
2*df57947fSPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3*df57947fSPedro F. Giffuni  *
46fc729afSOlivier Houchard  * Copyright (c) 1992, 1993
56fc729afSOlivier Houchard  *	The Regents of the University of California.  All rights reserved.
66fc729afSOlivier Houchard  *
76fc729afSOlivier Houchard  * Redistribution and use in source and binary forms, with or without
86fc729afSOlivier Houchard  * modification, are permitted provided that the following conditions
96fc729afSOlivier Houchard  * are met:
106fc729afSOlivier Houchard  * 1. Redistributions of source code must retain the above copyright
116fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer.
126fc729afSOlivier Houchard  * 2. Redistributions in binary form must reproduce the above copyright
136fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer in the
146fc729afSOlivier Houchard  *    documentation and/or other materials provided with the distribution.
156fc729afSOlivier Houchard  * 3. All advertising materials mentioning features or use of this software
166fc729afSOlivier Houchard  *    must display the following acknowledgement:
176fc729afSOlivier Houchard  *	This product includes software developed by the University of
186fc729afSOlivier Houchard  *	California, Berkeley and its contributors.
196fc729afSOlivier Houchard  * 4. Neither the name of the University nor the names of its contributors
206fc729afSOlivier Houchard  *    may be used to endorse or promote products derived from this software
216fc729afSOlivier Houchard  *    without specific prior written permission.
226fc729afSOlivier Houchard  *
236fc729afSOlivier Houchard  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
246fc729afSOlivier Houchard  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
256fc729afSOlivier Houchard  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
266fc729afSOlivier Houchard  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
276fc729afSOlivier Houchard  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
286fc729afSOlivier Houchard  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
296fc729afSOlivier Houchard  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
306fc729afSOlivier Houchard  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
316fc729afSOlivier Houchard  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
326fc729afSOlivier Houchard  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
336fc729afSOlivier Houchard  * SUCH DAMAGE.
346fc729afSOlivier Houchard  */
356fc729afSOlivier Houchard 
366fc729afSOlivier Houchard #ifndef _MACHINE_PROFILE_H_
376fc729afSOlivier Houchard #define	_MACHINE_PROFILE_H_
386fc729afSOlivier Houchard 
396fc729afSOlivier Houchard /*
40ffa589bfSOlivier Houchard  * Config generates something to tell the compiler to align functions on 32
416fc729afSOlivier Houchard  * byte boundaries.  A strict alignment is good for keeping the tables small.
426fc729afSOlivier Houchard  */
436fc729afSOlivier Houchard #define	FUNCTION_ALIGNMENT	16
446fc729afSOlivier Houchard 
456fc729afSOlivier Houchard #define	_MCOUNT_DECL void mcount
466fc729afSOlivier Houchard 
47ffa589bfSOlivier Houchard typedef u_long	fptrdiff_t;
48ffa589bfSOlivier Houchard 
49ffa589bfSOlivier Houchard /*
50ffa589bfSOlivier Houchard  * Cannot implement mcount in C as GCC will trash the ip register when it
51ffa589bfSOlivier Houchard  * pushes a trapframe. Pity we cannot insert assembly before the function
52ffa589bfSOlivier Houchard  * prologue.
53ffa589bfSOlivier Houchard  */
54ffa589bfSOlivier Houchard 
55ffa589bfSOlivier Houchard #ifndef PLTSYM
56ffa589bfSOlivier Houchard #define	PLTSYM
576fc729afSOlivier Houchard #endif
586fc729afSOlivier Houchard 
59ffa589bfSOlivier Houchard #define	MCOUNT								\
60ffa589bfSOlivier Houchard 	__asm__(".text");						\
61301e1601SIan Lepore 	__asm__(".align	2");						\
62705fda84SOlivier Houchard 	__asm__(".type	__mcount ,%function");				\
63705fda84SOlivier Houchard 	__asm__(".global	__mcount");				\
64705fda84SOlivier Houchard 	__asm__("__mcount:");						\
65ffa589bfSOlivier Houchard 	/*								\
66ffa589bfSOlivier Houchard 	 * Preserve registers that are trashed during mcount		\
67ffa589bfSOlivier Houchard 	 */								\
68ffa589bfSOlivier Houchard 	__asm__("stmfd	sp!, {r0-r3, ip, lr}");				\
69ffa589bfSOlivier Houchard 	/*								\
70ffa589bfSOlivier Houchard 	 * find the return address for mcount,				\
71ffa589bfSOlivier Houchard 	 * and the return address for mcount's caller.			\
72ffa589bfSOlivier Houchard 	 *								\
73ffa589bfSOlivier Houchard 	 * frompcindex = pc pushed by call into self.			\
74ffa589bfSOlivier Houchard 	 */								\
75ffa589bfSOlivier Houchard 	__asm__("mov	r0, ip");					\
76ffa589bfSOlivier Houchard 	/*								\
77ffa589bfSOlivier Houchard 	 * selfpc = pc pushed by mcount call				\
78ffa589bfSOlivier Houchard 	 */								\
79ffa589bfSOlivier Houchard 	__asm__("mov	r1, lr");					\
80ffa589bfSOlivier Houchard 	/*								\
81ffa589bfSOlivier Houchard 	 * Call the real mcount code					\
82ffa589bfSOlivier Houchard 	 */								\
83ffa589bfSOlivier Houchard 	__asm__("bl	mcount");					\
84ffa589bfSOlivier Houchard 	/*								\
85ffa589bfSOlivier Houchard 	 * Restore registers that were trashed during mcount		\
86ffa589bfSOlivier Houchard 	 */								\
878e35ef81SAndrew Turner 	__asm__("ldmfd	sp!, {r0-r3, lr}");				\
888e35ef81SAndrew Turner 	/*								\
898e35ef81SAndrew Turner 	 * Return to the caller. Loading lr and pc in one instruction	\
9028323addSBryan Drewery 	 * is deprecated on ARMv7 so we need this on its own.		\
918e35ef81SAndrew Turner 	 */								\
928e35ef81SAndrew Turner 	__asm__("ldmfd	sp!, {pc}");
930f2fe153SMarcel Moolenaar void bintr(void);
940f2fe153SMarcel Moolenaar void btrap(void);
950f2fe153SMarcel Moolenaar void eintr(void);
960f2fe153SMarcel Moolenaar void user(void);
970f2fe153SMarcel Moolenaar 
980f2fe153SMarcel Moolenaar #define	MCOUNT_FROMPC_USER(pc)					\
990f2fe153SMarcel Moolenaar 	((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
1000f2fe153SMarcel Moolenaar 
1010f2fe153SMarcel Moolenaar #define	MCOUNT_FROMPC_INTR(pc)					\
1020f2fe153SMarcel Moolenaar 	((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ?	\
1030f2fe153SMarcel Moolenaar 	    ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr :	\
1040f2fe153SMarcel Moolenaar 		(uintfptr_t)btrap) : ~0U)
1050f2fe153SMarcel Moolenaar 
1066fc729afSOlivier Houchard #ifdef _KERNEL
1076fc729afSOlivier Houchard 
108ffa589bfSOlivier Houchard #define	MCOUNT_DECL(s)	register_t s;
109ffa589bfSOlivier Houchard 
110ffa589bfSOlivier Houchard #include <machine/asm.h>
111ffa589bfSOlivier Houchard #include <machine/cpufunc.h>
112ffa589bfSOlivier Houchard #define	MCOUNT_ENTER(s)	{s = intr_disable(); }	/* kill IRQ */
113ffa589bfSOlivier Houchard #define	MCOUNT_EXIT(s)	{intr_restore(s); }	/* restore old value */
114ffa589bfSOlivier Houchard 
1156fc729afSOlivier Houchard void	mcount(uintfptr_t frompc, uintfptr_t selfpc);
1166fc729afSOlivier Houchard 
117ffa589bfSOlivier Houchard #else
118ffa589bfSOlivier Houchard typedef	u_int	uintfptr_t;
1196fc729afSOlivier Houchard #endif /* _KERNEL */
1206fc729afSOlivier Houchard 
1216fc729afSOlivier Houchard #endif /* !_MACHINE_PROFILE_H_ */
122