xref: /freebsd/sys/arm/include/profile.h (revision d8315c79d932951f2db396014e28ffa03a31b850)
1d8315c79SWarner Losh /*-
26fc729afSOlivier Houchard  * Copyright (c) 1992, 1993
36fc729afSOlivier Houchard  *	The Regents of the University of California.  All rights reserved.
46fc729afSOlivier Houchard  *
56fc729afSOlivier Houchard  * Redistribution and use in source and binary forms, with or without
66fc729afSOlivier Houchard  * modification, are permitted provided that the following conditions
76fc729afSOlivier Houchard  * are met:
86fc729afSOlivier Houchard  * 1. Redistributions of source code must retain the above copyright
96fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer.
106fc729afSOlivier Houchard  * 2. Redistributions in binary form must reproduce the above copyright
116fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer in the
126fc729afSOlivier Houchard  *    documentation and/or other materials provided with the distribution.
136fc729afSOlivier Houchard  * 3. All advertising materials mentioning features or use of this software
146fc729afSOlivier Houchard  *    must display the following acknowledgement:
156fc729afSOlivier Houchard  *	This product includes software developed by the University of
166fc729afSOlivier Houchard  *	California, Berkeley and its contributors.
176fc729afSOlivier Houchard  * 4. Neither the name of the University nor the names of its contributors
186fc729afSOlivier Houchard  *    may be used to endorse or promote products derived from this software
196fc729afSOlivier Houchard  *    without specific prior written permission.
206fc729afSOlivier Houchard  *
216fc729afSOlivier Houchard  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
226fc729afSOlivier Houchard  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
236fc729afSOlivier Houchard  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
246fc729afSOlivier Houchard  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
256fc729afSOlivier Houchard  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
266fc729afSOlivier Houchard  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
276fc729afSOlivier Houchard  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286fc729afSOlivier Houchard  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
296fc729afSOlivier Houchard  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
306fc729afSOlivier Houchard  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
316fc729afSOlivier Houchard  * SUCH DAMAGE.
326fc729afSOlivier Houchard  *
336fc729afSOlivier Houchard  *	@(#)profile.h	8.1 (Berkeley) 6/11/93
346fc729afSOlivier Houchard  * $FreeBSD$
356fc729afSOlivier Houchard  */
366fc729afSOlivier Houchard 
376fc729afSOlivier Houchard #ifndef _MACHINE_PROFILE_H_
386fc729afSOlivier Houchard #define	_MACHINE_PROFILE_H_
396fc729afSOlivier Houchard 
406fc729afSOlivier Houchard /*
41ffa589bfSOlivier Houchard  * Config generates something to tell the compiler to align functions on 32
426fc729afSOlivier Houchard  * byte boundaries.  A strict alignment is good for keeping the tables small.
436fc729afSOlivier Houchard  */
446fc729afSOlivier Houchard #define	FUNCTION_ALIGNMENT	16
456fc729afSOlivier Houchard 
46ffa589bfSOlivier Houchard 
476fc729afSOlivier Houchard #define	_MCOUNT_DECL void mcount
486fc729afSOlivier Houchard 
49ffa589bfSOlivier Houchard typedef u_long	fptrdiff_t;
50ffa589bfSOlivier Houchard 
51ffa589bfSOlivier Houchard /*
52ffa589bfSOlivier Houchard  * Cannot implement mcount in C as GCC will trash the ip register when it
53ffa589bfSOlivier Houchard  * pushes a trapframe. Pity we cannot insert assembly before the function
54ffa589bfSOlivier Houchard  * prologue.
55ffa589bfSOlivier Houchard  */
56ffa589bfSOlivier Houchard 
57ffa589bfSOlivier Houchard #ifndef PLTSYM
58ffa589bfSOlivier Houchard #define	PLTSYM
596fc729afSOlivier Houchard #endif
606fc729afSOlivier Houchard 
61ffa589bfSOlivier Houchard #define	MCOUNT								\
62ffa589bfSOlivier Houchard 	__asm__(".text");						\
63ffa589bfSOlivier Houchard 	__asm__(".align	0");						\
64ffa589bfSOlivier Houchard 	__asm__(".type	_mcount ,%function");				\
65ffa589bfSOlivier Houchard 	__asm__(".global	_mcount");				\
66ffa589bfSOlivier Houchard 	__asm__("_mcount:");						\
67ffa589bfSOlivier Houchard 	/*								\
68ffa589bfSOlivier Houchard 	 * Preserve registers that are trashed during mcount		\
69ffa589bfSOlivier Houchard 	 */								\
70ffa589bfSOlivier Houchard 	__asm__("stmfd	sp!, {r0-r3, ip, lr}");				\
71ffa589bfSOlivier Houchard 	/*								\
72ffa589bfSOlivier Houchard 	 * find the return address for mcount,				\
73ffa589bfSOlivier Houchard 	 * and the return address for mcount's caller.			\
74ffa589bfSOlivier Houchard 	 *								\
75ffa589bfSOlivier Houchard 	 * frompcindex = pc pushed by call into self.			\
76ffa589bfSOlivier Houchard 	 */								\
77ffa589bfSOlivier Houchard 	__asm__("mov	r0, ip");					\
78ffa589bfSOlivier Houchard 	/*								\
79ffa589bfSOlivier Houchard 	 * selfpc = pc pushed by mcount call				\
80ffa589bfSOlivier Houchard 	 */								\
81ffa589bfSOlivier Houchard 	__asm__("mov	r1, lr");					\
82ffa589bfSOlivier Houchard 	/*								\
83ffa589bfSOlivier Houchard 	 * Call the real mcount code					\
84ffa589bfSOlivier Houchard 	 */								\
85ffa589bfSOlivier Houchard 	__asm__("bl	mcount");					\
86ffa589bfSOlivier Houchard 	/*								\
87ffa589bfSOlivier Houchard 	 * Restore registers that were trashed during mcount		\
88ffa589bfSOlivier Houchard 	 */								\
89ffa589bfSOlivier Houchard 	__asm__("ldmfd	sp!, {r0-r3, lr, pc}");
900f2fe153SMarcel Moolenaar void bintr(void);
910f2fe153SMarcel Moolenaar void btrap(void);
920f2fe153SMarcel Moolenaar void eintr(void);
930f2fe153SMarcel Moolenaar void user(void);
940f2fe153SMarcel Moolenaar 
950f2fe153SMarcel Moolenaar #define	MCOUNT_FROMPC_USER(pc)					\
960f2fe153SMarcel Moolenaar 	((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
970f2fe153SMarcel Moolenaar 
980f2fe153SMarcel Moolenaar #define	MCOUNT_FROMPC_INTR(pc)					\
990f2fe153SMarcel Moolenaar 	((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ?	\
1000f2fe153SMarcel Moolenaar 	    ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr :	\
1010f2fe153SMarcel Moolenaar 		(uintfptr_t)btrap) : ~0U)
1020f2fe153SMarcel Moolenaar 
1036fc729afSOlivier Houchard 
1046fc729afSOlivier Houchard #ifdef _KERNEL
1056fc729afSOlivier Houchard 
106ffa589bfSOlivier Houchard #define	MCOUNT_DECL(s)	register_t s;
107ffa589bfSOlivier Houchard 
108ffa589bfSOlivier Houchard #include <machine/asm.h>
109ffa589bfSOlivier Houchard #include <machine/cpufunc.h>
110ffa589bfSOlivier Houchard /*
111ffa589bfSOlivier Houchard  * splhigh() and splx() are heavyweight, and call mcount().  Therefore
112ffa589bfSOlivier Houchard  * we disabled interrupts (IRQ, but not FIQ) directly on the CPU.
113ffa589bfSOlivier Houchard  *
114ffa589bfSOlivier Houchard  * We're lucky that the CPSR and 's' both happen to be 'int's.
115ffa589bfSOlivier Houchard  */
116ffa589bfSOlivier Houchard #define	MCOUNT_ENTER(s)	{s = intr_disable(); }	/* kill IRQ */
117ffa589bfSOlivier Houchard #define	MCOUNT_EXIT(s)	{intr_restore(s); }	/* restore old value */
118ffa589bfSOlivier Houchard 
1196fc729afSOlivier Houchard void	mcount(uintfptr_t frompc, uintfptr_t selfpc);
1206fc729afSOlivier Houchard 
121ffa589bfSOlivier Houchard #else
122ffa589bfSOlivier Houchard typedef	u_int	uintfptr_t;
1236fc729afSOlivier Houchard #endif /* _KERNEL */
1246fc729afSOlivier Houchard 
1256fc729afSOlivier Houchard #endif /* !_MACHINE_PROFILE_H_ */
126