xref: /openbsd-src/sys/arch/riscv64/include/profile.h (revision 338e733618f4e9c7d2a0c1d992cc644fafcc48b1)
1*338e7336Sderaadt /*	$OpenBSD: profile.h,v 1.4 2021/05/21 16:49:57 deraadt Exp $	*/
2380aa7b9Sjsg 
3baed8f06Sdrahn /*
4baed8f06Sdrahn  * Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com>
5baed8f06Sdrahn  *
6baed8f06Sdrahn  * Permission to use, copy, modify, and distribute this software for any
7baed8f06Sdrahn  * purpose with or without fee is hereby granted, provided that the above
8baed8f06Sdrahn  * copyright notice and this permission notice appear in all copies.
9baed8f06Sdrahn  *
10baed8f06Sdrahn  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11baed8f06Sdrahn  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12baed8f06Sdrahn  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13baed8f06Sdrahn  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14baed8f06Sdrahn  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15baed8f06Sdrahn  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16baed8f06Sdrahn  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17baed8f06Sdrahn  */
18baed8f06Sdrahn 
19baed8f06Sdrahn #define	_MCOUNT_DECL void _mcount
20baed8f06Sdrahn 
21baed8f06Sdrahn #define MCOUNT_ASM_NAME "__mcount"
22baed8f06Sdrahn 
23baed8f06Sdrahn #ifdef __PIC__
24baed8f06Sdrahn #define	PLTSYM		"" /* XXX -aarch64 defaults to PLT? */
25baed8f06Sdrahn #else
26baed8f06Sdrahn #define	PLTSYM		""
27baed8f06Sdrahn #endif
28baed8f06Sdrahn 
29baed8f06Sdrahn #define MCOUNT							\
30baed8f06Sdrahn __asm__ (".text						\n;"	\
31baed8f06Sdrahn 	 ".align 3					\n;"	\
32baed8f06Sdrahn 	 ".globl " MCOUNT_ASM_NAME "			\n;"	\
33baed8f06Sdrahn 	 ".type " MCOUNT_ASM_NAME ",@function		\n;"	\
34baed8f06Sdrahn 	 MCOUNT_ASM_NAME ":				\n;"	\
35baed8f06Sdrahn 	 "	addi	sp, sp, -176			\n"	\
36baed8f06Sdrahn 	 "	sd	fp, 0(sp)			\n"	\
37baed8f06Sdrahn 	 "	sd	ra, 8(sp)			\n"	\
38baed8f06Sdrahn 	 "	sd	s1, 24(sp)			\n"	\
39baed8f06Sdrahn 	 "	sd	a0, 32(sp)			\n"	\
40baed8f06Sdrahn 	 "	sd	a1, 40(sp)			\n"	\
41baed8f06Sdrahn 	 "	sd	a2, 48(sp)			\n"	\
42baed8f06Sdrahn 	 "	sd	a3, 56(sp)			\n"	\
43baed8f06Sdrahn 	 "	sd	a4, 64(sp)			\n"	\
44baed8f06Sdrahn 	 "	sd	a5, 72(sp)			\n"	\
45baed8f06Sdrahn 	 "	sd	a6, 80(sp)			\n"	\
46baed8f06Sdrahn 	 "	sd	a7, 88(sp)			\n"	\
47baed8f06Sdrahn 	 "	sd	s2, 96(sp)			\n"	\
48baed8f06Sdrahn 	 "	sd	s3, 104(sp)			\n"	\
49baed8f06Sdrahn 	 "	sd	s4, 112(sp)			\n"	\
50baed8f06Sdrahn 	 "	sd	s5, 120(sp)			\n"	\
51baed8f06Sdrahn 	 "	sd	s6, 128(sp)			\n"	\
52baed8f06Sdrahn 	 "	sd	s7, 136(sp)			\n"	\
53baed8f06Sdrahn 	 "	sd	s8, 144(sp)			\n"	\
54baed8f06Sdrahn 	 "	sd	s9, 152(sp)			\n"	\
55baed8f06Sdrahn 	 "	sd	s10, 160(sp)			\n"	\
56baed8f06Sdrahn 	 "	sd	s11, 168(sp)			\n"	\
57baed8f06Sdrahn 	 "	ld	a0, 8(fp)			\n"	\
58baed8f06Sdrahn 	 "	mv	a1, x1				\n"	\
59baed8f06Sdrahn 	 "	call	" __STRING(_mcount) PLTSYM "	\n"	\
60baed8f06Sdrahn 	 /* restore argument registers */			\
61baed8f06Sdrahn 	 "	ld	fp, 0(sp)			\n"	\
62baed8f06Sdrahn 	 "	ld	ra, 8(sp)			\n"	\
63baed8f06Sdrahn 	 "	ld	s1, 24(sp)			\n"	\
64baed8f06Sdrahn 	 "	ld	a0, 32(sp)			\n"	\
65baed8f06Sdrahn 	 "	ld	a1, 40(sp)			\n"	\
66baed8f06Sdrahn 	 "	ld	a2, 48(sp)			\n"	\
67baed8f06Sdrahn 	 "	ld	a3, 56(sp)			\n"	\
68baed8f06Sdrahn 	 "	ld	a4, 64(sp)			\n"	\
69baed8f06Sdrahn 	 "	ld	a5, 72(sp)			\n"	\
70baed8f06Sdrahn 	 "	ld	a6, 80(sp)			\n"	\
71baed8f06Sdrahn 	 "	ld	a7, 88(sp)			\n"	\
72baed8f06Sdrahn 	 "	ld	s2, 96(sp)			\n"	\
73baed8f06Sdrahn 	 "	ld	s3, 104(sp)			\n"	\
74baed8f06Sdrahn 	 "	ld	s4, 112(sp)			\n"	\
75baed8f06Sdrahn 	 "	ld	s5, 120(sp)			\n"	\
76baed8f06Sdrahn 	 "	ld	s6, 128(sp)			\n"	\
77baed8f06Sdrahn 	 "	ld	s7, 136(sp)			\n"	\
78baed8f06Sdrahn 	 "	ld	s8, 144(sp)			\n"	\
79baed8f06Sdrahn 	 "	ld	s9, 152(sp)			\n"	\
80baed8f06Sdrahn 	 "	ld	s10, 160(sp)			\n"	\
81baed8f06Sdrahn 	 "	ld	s11, 168(sp)			\n"	\
82baed8f06Sdrahn 	 "	addi	sp, sp, 176			\n"	\
83baed8f06Sdrahn 	 "	jr	ra				\n");
84baed8f06Sdrahn 
85baed8f06Sdrahn #ifdef _KERNEL
86baed8f06Sdrahn // Change this to dair read/set, then restore.
87baed8f06Sdrahn #define MCOUNT_ENTER						\
88baed8f06Sdrahn __asm__ ("mrs %x0,daif; msr daifset, #0x2": "=r"(s));
89baed8f06Sdrahn #define	MCOUNT_EXIT						\
90baed8f06Sdrahn __asm__ ("msr daif, %x0":: "r"(s));
91baed8f06Sdrahn 
92*338e7336Sderaadt #endif
93