| 1 | /* $OpenBSD: profile.h,v 1.2 2021/02/17 12:11:45 kettenis Exp $ */ |
| 2 | /* |
| 3 | * Copyright (c) 2015 Dale Rahn <drahn@dalerahn.com> |
| 4 | * |
| 5 | * Permission to use, copy, modify, and distribute this software for any |
| 6 | * purpose with or without fee is hereby granted, provided that the above |
| 7 | * copyright notice and this permission notice appear in all copies. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 16 | */ |
| 17 | |
| 18 | #define	_MCOUNT_DECL void _mcount |
| 19 | |
| 20 | #define MCOUNT_ASM_NAME "__mcount" |
| 21 | |
| 22 | #ifdef __PIC__ |
| 23 | #define	PLTSYM		"" /* XXX -aarch64 defaults to PLT? */ |
| 24 | #else |
| 25 | #define	PLTSYM		"" |
| 26 | #endif |
| 27 | |
| 28 | #define MCOUNT							\ |
| 29 | __asm__ (".text;"						\ |
| 30 | 	 ".align 3;"						\ |
| 31 | 	 ".globl " MCOUNT_ASM_NAME ";"				\ |
| 32 | 	 ".type " MCOUNT_ASM_NAME ",@function;"			\ |
| 33 | 	 MCOUNT_ASM_NAME ":;"					\ |
| 34 | 	 "	stp	x0, x1, [sp, #-160]!;"			\ |
| 35 | 	 "	stp	x2, x3, [sp, #16];"			\ |
| 36 | 	 "	stp	x4, x5, [sp, #32];"			\ |
| 37 | 	 "	stp	x6, x7, [sp, #48];"			\ |
| 38 | 	 "	stp	x8, x9, [sp, #64];"			\ |
| 39 | 	 "	stp	x10,x11,[sp, #80];"			\ |
| 40 | 	 "	stp	x12,x13,[sp, #96];"			\ |
| 41 | 	 "	stp	x14,x15,[sp, #112];"			\ |
| 42 | 	 "	stp	x16,x17,[sp, #128];"			\ |
| 43 | 	 "	stp	x29,lr, [sp, #144];"			\ |
| 44 | 	 /* load from pc at 8 off frame pointer */		\ |
| 45 | 	 "	ldr	x0, [x29, #8];"				\ |
| 46 | 	 "	mov	x1, lr;"				\ |
| 47 | 	 "	bl	" __STRING(_mcount) PLTSYM ";"		\ |
| 48 | 	 /* restore argument registers */			\ |
| 49 | 	 "	ldp	x2, x3, [sp, #16];"			\ |
| 50 | 	 "	ldp	x4, x5, [sp, #32];"			\ |
| 51 | 	 "	ldp	x6, x7, [sp, #48];"			\ |
| 52 | 	 "	ldp	x8, x9, [sp, #64];"			\ |
| 53 | 	 "	ldp	x10,x11,[sp, #80];"			\ |
| 54 | 	 "	ldp	x12,x13,[sp, #96];"			\ |
| 55 | 	 "	ldp	x14,x15,[sp, #112];"			\ |
| 56 | 	 "	ldp	x16,x17,[sp, #128];"			\ |
| 57 | 	 "	ldp	x29,lr, [sp, #144];"			\ |
| 58 | 	 "	ldp	x0, x1, [sp], #160;"			\ |
| 59 | 	 "	ret;"); |
| 60 | |
| 61 | #ifdef _KERNEL |
| 62 | // Change this to dair read/set, then restore. |
| 63 | #define MCOUNT_ENTER						\ |
| 64 | __asm__ ("mrs %x0, daif; msr daifset, #0x3": "=r"(s)); |
| 65 | #define	MCOUNT_EXIT						\ |
| 66 | __asm__ ("msr daif, %x0":: "r"(s)); |
| 67 | 	 |
| 68 | #endif // _KERNEL |