xref: /NextBSD/sys/sparc64/include/profile.h (revision eb1a5f8de9f7ea602c373a710f531abbf81141c4)
1 /*-
2  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
3  * All rights reserved.
4  *
5  * Author: Chris G. Demetriou
6  *
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.
12  *
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.
16  *
17  * Carnegie Mellon requests users of this software to return to
18  *
19  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
20  *  School of Computer Science
21  *  Carnegie Mellon University
22  *  Pittsburgh PA 15213-3890
23  *
24  * any improvements or extensions that they make and grant Carnegie the
25  * rights to redistribute these changes.
26  *
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
29  * $FreeBSD$
30  */
31 
32 #ifndef _MACHINE_PROFILE_H_
33 #define	_MACHINE_PROFILE_H_
34 
35 #if !defined(_KERNEL) && !defined(_SYS_CDEFS_H_)
36 #error this file needs sys/cdefs.h as a prerequisite
37 #endif
38 
39 #define	FUNCTION_ALIGNMENT	32
40 
41 typedef u_long	fptrdiff_t;
42 
43 #ifdef _KERNEL
44 
45 #include <machine/cpufunc.h>
46 #include <machine/intr_machdep.h>
47 
48 #define	_MCOUNT_DECL	void mcount
49 #define	MCOUNT
50 
51 #define	MCOUNT_DECL(s)	register_t s;
52 #define	MCOUNT_ENTER(s)	s = rdpr(pil); wrpr(pil, 0, PIL_TICK)
53 #define	MCOUNT_EXIT(s)	wrpr(pil, 0, s)
54 
55 void bintr(void);
56 void btrap(void);
57 void eintr(void);
58 void user(void);
59 
60 #define	MCOUNT_FROMPC_USER(pc)					\
61 	((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
62 
63 #define	MCOUNT_FROMPC_INTR(pc)					\
64 	((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ?	\
65 	    ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr :	\
66 		(uintfptr_t)btrap) : ~0UL)
67 
68 void	mcount(uintfptr_t frompc, uintfptr_t selfpc);
69 
70 #else /* !_KERNEL */
71 
72 typedef u_long	uintfptr_t;
73 
74 #define	_MCOUNT_DECL	static __inline void __mcount
75 
76 #ifdef __GNUCLIKE_ASM
77 #define	MCOUNT								\
78 void									\
79 _mcount()								\
80 {									\
81 	uintfptr_t frompc, selfpc;					\
82 									\
83 	/*								\
84 	 * Find the return address for mcount,				\
85 	 * and the return address for mcount's caller.			\
86 	 *								\
87 	 * selfpc = pc pushed by call to mcount				\
88 	 */								\
89 	__asm("add %%o7, 8, %0" : "=r" (selfpc));			\
90 	/*								\
91 	 * frompc = pc pushed by call to mcount's caller.		\
92 	 */								\
93 	__asm("add %%i7, 8, %0" : "=r" (frompc));			\
94 	__mcount(frompc, selfpc);					\
95 }
96 #else /* !__GNUCLIKE_ASM */
97 #define	MCOUNT
98 #endif /* __GNUCLIKE_ASM */
99 
100 #endif /* _KERNEL */
101 
102 #endif /* !_MACHINE_PROFILE_H_ */
103