xref: /freebsd/sys/arm64/include/profile.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*-
2  * SPDX-License-Identifier: MIT-CMU
3  *
4  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
9  * Permission to use, copy, modify and distribute this software and
10  * its documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  *
29  *	from: NetBSD: profile.h,v 1.9 1997/04/06 08:47:37 cgd Exp
30  *	from: FreeBSD: src/sys/alpha/include/profile.h,v 1.4 1999/12/29
31  */
32 
33 #ifdef __arm__
34 #include <arm/profile.h>
35 #else /* !__arm__ */
36 
37 #ifndef _MACHINE_PROFILE_H_
38 #define	_MACHINE_PROFILE_H_
39 
40 #define	FUNCTION_ALIGNMENT	32
41 
42 typedef u_long	fptrdiff_t;
43 
44 #ifndef _KERNEL
45 
46 #include <sys/cdefs.h>
47 
48 typedef __uintfptr_t    uintfptr_t;
49 
50 #define	_MCOUNT_DECL \
51 static void _mcount(uintfptr_t frompc, uintfptr_t selfpc) __used; \
52 static void _mcount
53 
54 /*
55  * Call into _mcount. On arm64 the .mcount is a function so callers will
56  * handle caller saved registers. As we don't directly touch any callee
57  * saved registers we can just load the two arguments and use a tail call
58  * into the MI _mcount function.
59  *
60  * When building with gcc frompc will be in x0, however this is not the
61  * case on clang. As such we need to load it from the stack. As long as
62  * the caller follows the ABI this will load the correct value.
63  */
64 #define	MCOUNT __asm(					\
65 "	.text					\n"	\
66 "	.align	6				\n"	\
67 "	.type	.mcount,#function		\n"	\
68 "	.globl	.mcount				\n"	\
69 "	.mcount:				\n"	\
70 "	.cfi_startproc				\n"	\
71 	/* Allow this to work with BTI, see BTI_C in asm.h */ \
72 "	hint	#34				\n"	\
73 	/* Load the caller return address as frompc */	\
74 "	ldr	x0, [x29, #8]			\n"	\
75 	/* Use our return address as selfpc */		\
76 "	mov	x1, lr				\n"	\
77 "	b	_mcount				\n"	\
78 "	.cfi_endproc				\n"	\
79 "	.size	.mcount, . - .mcount		\n"	\
80 	);
81 #if 0
82 /*
83  * If clang passed frompc correctly we could implement it like this, however
84  * all clang versions we care about would need to be fixed before we could
85  * make this change.
86  */
87 void
88 mcount(uintfptr_t frompc)
89 {
90 	_mcount(frompc, __builtin_return_address(0));
91 }
92 #endif
93 
94 #endif /* !_KERNEL */
95 
96 #endif /* !_MACHINE_PROFILE_H_ */
97 
98 #endif /* !__arm__ */
99