1139735Simp/*-
2129198Scognet * Copyright (c) 1992, 1993
3129198Scognet *	The Regents of the University of California.  All rights reserved.
4129198Scognet *
5129198Scognet * Redistribution and use in source and binary forms, with or without
6129198Scognet * modification, are permitted provided that the following conditions
7129198Scognet * are met:
8129198Scognet * 1. Redistributions of source code must retain the above copyright
9129198Scognet *    notice, this list of conditions and the following disclaimer.
10129198Scognet * 2. Redistributions in binary form must reproduce the above copyright
11129198Scognet *    notice, this list of conditions and the following disclaimer in the
12129198Scognet *    documentation and/or other materials provided with the distribution.
13129198Scognet * 3. All advertising materials mentioning features or use of this software
14129198Scognet *    must display the following acknowledgement:
15129198Scognet *	This product includes software developed by the University of
16129198Scognet *	California, Berkeley and its contributors.
17129198Scognet * 4. Neither the name of the University nor the names of its contributors
18129198Scognet *    may be used to endorse or promote products derived from this software
19129198Scognet *    without specific prior written permission.
20129198Scognet *
21129198Scognet * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22129198Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23129198Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24129198Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25129198Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26129198Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27129198Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31129198Scognet * SUCH DAMAGE.
32129198Scognet *
33129198Scognet *	@(#)profile.h	8.1 (Berkeley) 6/11/93
34129198Scognet * $FreeBSD$
35129198Scognet */
36129198Scognet
37129198Scognet#ifndef _MACHINE_PROFILE_H_
38129198Scognet#define	_MACHINE_PROFILE_H_
39129198Scognet
40129198Scognet/*
41236992Simp * Config generates something to tell the compiler to align functions on 32
42129198Scognet * byte boundaries.  A strict alignment is good for keeping the tables small.
43129198Scognet */
44129198Scognet#define	FUNCTION_ALIGNMENT	16
45129198Scognet
46135661Scognet
47135661Scognet#define	_MCOUNT_DECL void mcount
48135661Scognet
49135661Scognettypedef u_long	fptrdiff_t;
50135661Scognet
51129198Scognet/*
52135661Scognet * Cannot implement mcount in C as GCC will trash the ip register when it
53135661Scognet * pushes a trapframe. Pity we cannot insert assembly before the function
54135661Scognet * prologue.
55129198Scognet */
56129198Scognet
57135661Scognet#ifndef PLTSYM
58135661Scognet#define	PLTSYM
59129198Scognet#endif
60129198Scognet
61135661Scognet#define	MCOUNT								\
62135661Scognet	__asm__(".text");						\
63276596Sian	__asm__(".align	2");						\
64169768Scognet	__asm__(".type	__mcount ,%function");				\
65169768Scognet	__asm__(".global	__mcount");				\
66169768Scognet	__asm__("__mcount:");						\
67135661Scognet	/*								\
68135661Scognet	 * Preserve registers that are trashed during mcount		\
69135661Scognet	 */								\
70135661Scognet	__asm__("stmfd	sp!, {r0-r3, ip, lr}");				\
71135661Scognet	/*								\
72135661Scognet	 * find the return address for mcount,				\
73135661Scognet	 * and the return address for mcount's caller.			\
74135661Scognet	 *								\
75135661Scognet	 * frompcindex = pc pushed by call into self.			\
76135661Scognet	 */								\
77135661Scognet	__asm__("mov	r0, ip");					\
78135661Scognet	/*								\
79135661Scognet	 * selfpc = pc pushed by mcount call				\
80135661Scognet	 */								\
81135661Scognet	__asm__("mov	r1, lr");					\
82135661Scognet	/*								\
83135661Scognet	 * Call the real mcount code					\
84135661Scognet	 */								\
85135661Scognet	__asm__("bl	mcount");					\
86135661Scognet	/*								\
87135661Scognet	 * Restore registers that were trashed during mcount		\
88135661Scognet	 */								\
89277998Sandrew	__asm__("ldmfd	sp!, {r0-r3, lr}");				\
90277998Sandrew	/*								\
91277998Sandrew	 * Return to the caller. Loading lr and pc in one instruction	\
92277998Sandrew	 * is deprecated on ARMv7 so we need this on it's own.		\
93277998Sandrew	 */								\
94277998Sandrew	__asm__("ldmfd	sp!, {pc}");
95134398Smarcelvoid bintr(void);
96134398Smarcelvoid btrap(void);
97134398Smarcelvoid eintr(void);
98134398Smarcelvoid user(void);
99134398Smarcel
100134398Smarcel#define	MCOUNT_FROMPC_USER(pc)					\
101134398Smarcel	((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
102134398Smarcel
103134398Smarcel#define	MCOUNT_FROMPC_INTR(pc)					\
104134398Smarcel	((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ?	\
105134398Smarcel	    ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr :	\
106134398Smarcel		(uintfptr_t)btrap) : ~0U)
107134398Smarcel
108129198Scognet
109135661Scognet#ifdef _KERNEL
110129198Scognet
111135661Scognet#define	MCOUNT_DECL(s)	register_t s;
112129198Scognet
113135661Scognet#include <machine/asm.h>
114135661Scognet#include <machine/cpufunc.h>
115129198Scognet/*
116135661Scognet * splhigh() and splx() are heavyweight, and call mcount().  Therefore
117135661Scognet * we disabled interrupts (IRQ, but not FIQ) directly on the CPU.
118135661Scognet *
119135661Scognet * We're lucky that the CPSR and 's' both happen to be 'int's.
120129198Scognet */
121135661Scognet#define	MCOUNT_ENTER(s)	{s = intr_disable(); }	/* kill IRQ */
122135661Scognet#define	MCOUNT_EXIT(s)	{intr_restore(s); }	/* restore old value */
123129198Scognet
124129198Scognetvoid	mcount(uintfptr_t frompc, uintfptr_t selfpc);
125129198Scognet
126135661Scognet#else
127135661Scognettypedef	u_int	uintfptr_t;
128129198Scognet#endif /* _KERNEL */
129129198Scognet
130129198Scognet#endif /* !_MACHINE_PROFILE_H_ */
131