2 * SPDX-License-Identifier: MIT-CMU
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
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.
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.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
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
35 #include <arm/profile.h>
38 #ifndef _MACHINE_PROFILE_H_
39 #define _MACHINE_PROFILE_H_
41 #define FUNCTION_ALIGNMENT 32
43 typedef u_long fptrdiff_t;
47 #include <sys/cdefs.h>
49 typedef __uintfptr_t uintfptr_t;
51 #define _MCOUNT_DECL \
52 static void _mcount(uintfptr_t frompc, uintfptr_t selfpc) __used; \
56 * Call into _mcount. On arm64 the .mcount is a function so callers will
57 * handle caller saved registers. As we don't directly touch any callee
58 * saved registers we can just load the two arguments and use a tail call
59 * into the MI _mcount function.
61 * When building with gcc frompc will be in x0, however this is not the
62 * case on clang. As such we need to load it from the stack. As long as
63 * the caller follows the ABI this will load the correct value.
65 #define MCOUNT __asm( \
68 " .type .mcount,#function \n" \
69 " .globl .mcount \n" \
71 " .cfi_startproc \n" \
72 /* Load the caller return address as frompc */ \
73 " ldr x0, [x29, #8] \n" \
74 /* Use our return address as selfpc */ \
78 " .size .mcount, . - .mcount \n" \
82 * If clang passed frompc correctly we could implement it like this, however
83 * all clang versions we care about would need to be fixed before we could
87 mcount(uintfptr_t frompc)
89 _mcount(frompc, __builtin_return_address(0));
95 #endif /* !_MACHINE_PROFILE_H_ */