1139825Simp/*-
286551Sjake * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
386551Sjake * All rights reserved.
486551Sjake *
586551Sjake * Author: Chris G. Demetriou
686551Sjake *
786551Sjake * Permission to use, copy, modify and distribute this software and
886551Sjake * its documentation is hereby granted, provided that both the copyright
986551Sjake * notice and this permission notice appear in all copies of the
1086551Sjake * software, derivative works or modified versions, and any portions
1186551Sjake * thereof, and that both notices appear in supporting documentation.
1286551Sjake *
1386551Sjake * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1486551Sjake * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1586551Sjake * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1686551Sjake *
1786551Sjake * Carnegie Mellon requests users of this software to return to
1886551Sjake *
1986551Sjake *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2086551Sjake *  School of Computer Science
2186551Sjake *  Carnegie Mellon University
2286551Sjake *  Pittsburgh PA 15213-3890
2386551Sjake *
2486551Sjake * any improvements or extensions that they make and grant Carnegie the
2586551Sjake * rights to redistribute these changes.
2686551Sjake *
2786551Sjake *	from: NetBSD: profile.h,v 1.9 1997/04/06 08:47:37 cgd Exp
2886551Sjake *	from: FreeBSD: src/sys/alpha/include/profile.h,v 1.4 1999/12/29
2986551Sjake * $FreeBSD: releng/10.3/sys/sparc64/include/profile.h 169488 2007-05-11 23:43:55Z marius $
3086551Sjake */
3186551Sjake
3286551Sjake#ifndef _MACHINE_PROFILE_H_
3386551Sjake#define	_MACHINE_PROFILE_H_
3486551Sjake
35169488Smarius#if !defined(_KERNEL) && !defined(_SYS_CDEFS_H_)
36169488Smarius#error this file needs sys/cdefs.h as a prerequisite
37169488Smarius#endif
3886551Sjake
39169488Smarius#define	FUNCTION_ALIGNMENT	32
40169488Smarius
4186551Sjaketypedef u_long	fptrdiff_t;
4286551Sjake
43100910Sjake#ifdef _KERNEL
4486551Sjake
45100910Sjake#include <machine/cpufunc.h>
46169488Smarius#include <machine/intr_machdep.h>
47100910Sjake
48169488Smarius#define	_MCOUNT_DECL	void mcount
49169488Smarius#define	MCOUNT
50169488Smarius
51100910Sjake#define	MCOUNT_DECL(s)	register_t s;
52169488Smarius#define	MCOUNT_ENTER(s)	s = rdpr(pil); wrpr(pil, 0, PIL_TICK)
53100910Sjake#define	MCOUNT_EXIT(s)	wrpr(pil, 0, s)
54100910Sjake
55134398Smarcelvoid bintr(void);
56134398Smarcelvoid btrap(void);
57134398Smarcelvoid eintr(void);
58134398Smarcelvoid user(void);
59134398Smarcel
60134398Smarcel#define	MCOUNT_FROMPC_USER(pc)					\
61134398Smarcel	((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
62134398Smarcel
63134398Smarcel#define	MCOUNT_FROMPC_INTR(pc)					\
64134398Smarcel	((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ?	\
65134398Smarcel	    ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr :	\
66134398Smarcel		(uintfptr_t)btrap) : ~0UL)
67134398Smarcel
68100910Sjakevoid	mcount(uintfptr_t frompc, uintfptr_t selfpc);
69100910Sjake
70129444Sbde#else /* !_KERNEL */
71100910Sjake
72100910Sjaketypedef u_long	uintfptr_t;
73100910Sjake
74169488Smarius#define	_MCOUNT_DECL	static __inline void __mcount
75169488Smarius
76169488Smarius#ifdef __GNUCLIKE_ASM
77169488Smarius#define	MCOUNT								\
78169488Smariusvoid									\
79169488Smarius_mcount()								\
80169488Smarius{									\
81169488Smarius	uintfptr_t frompc, selfpc;					\
82169488Smarius									\
83169488Smarius	/*								\
84169488Smarius	 * Find the return address for mcount,				\
85169488Smarius	 * and the return address for mcount's caller.			\
86169488Smarius	 *								\
87169488Smarius	 * selfpc = pc pushed by call to mcount				\
88169488Smarius	 */								\
89169488Smarius	__asm("add %%o7, 8, %0" : "=r" (selfpc));			\
90169488Smarius	/*								\
91169488Smarius	 * frompc = pc pushed by call to mcount's caller.		\
92169488Smarius	 */								\
93169488Smarius	__asm("add %%i7, 8, %0" : "=r" (frompc));			\
94169488Smarius	__mcount(frompc, selfpc);					\
95169488Smarius}
96169488Smarius#else /* !__GNUCLIKE_ASM */
97169488Smarius#define	MCOUNT
98169488Smarius#endif /* __GNUCLIKE_ASM */
99169488Smarius
100100910Sjake#endif /* _KERNEL */
101100910Sjake
10286551Sjake#endif /* !_MACHINE_PROFILE_H_ */
103