| 1 | /*	$OpenBSD: profile.h,v 1.1 2020/06/25 01:55:14 drahn Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2020 Dale Rahn drahn@openbsd.org |
| 5 | * |
| 6 | * Permission to use, copy, modify, and distribute this software for any |
| 7 | * purpose with or without fee is hereby granted, provided that the above |
| 8 | * copyright notice and this permission notice appear in all copies. |
| 9 | * |
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * mcount frame size skips over the red zone (288B) (calling function may use) |
| 21 | * and 128 bytes of local storage (32 bytes of reserved and 96 of our storage |
| 22 | * this function assumes it will only every call the local __mcount function |
| 23 | */ |
| 24 | #define MCOUNT \ |
| 25 | __asm__(" 								\n"\ |
| 26 | 	"	.section \".text\"					\n"\ |
| 27 | 	"	.p2align 2						\n"\ |
| 28 | 	"	.globl _mcount						\n"\ |
| 29 | 	"	.local __mcount						\n"\ |
| 30 | 	"	.type	_mcount,@function				\n"\ |
| 31 | 	"_mcount:							\n"\ |
| 32 | 	".L_mcount_gep0:						\n"\ |
| 33 | 	"	addis %r2, %r12, .TOC.-.L_mcount_gep0@ha;		\n"\ |
| 34 | 	"	addi %r2, %r2, .TOC.-.L_mcount_gep0@l;			\n"\ |
| 35 | 	".L_mcount_lep0:						\n"\ |
| 36 | 	".localentry _mcount, .L_mcount_lep0-.L_mcount_gep0;	\n"\ |
| 37 | 	"	ld	%r11,16(%r1)					\n"\ |
| 38 | 	"	mflr	%r0						\n"\ |
| 39 | 	"	std	%r0, 16(%r1)					\n"\ |
| 40 | 	"	stdu	%r1,-(288+128)(%r1)				\n"\ |
| 41 | 	"	std	%r3, 32(%r1)					\n"\ |
| 42 | 	"	std	%r4, 40(%r1)					\n"\ |
| 43 | 	"	std	%r5, 48(%r1)					\n"\ |
| 44 | 	"	std	%r6, 56(%r1)					\n"\ |
| 45 | 	"	std	%r7, 64(%r1)					\n"\ |
| 46 | 	"	std	%r8, 72(%r1)					\n"\ |
| 47 | 	"	std	%r9, 80(%r1)					\n"\ |
| 48 | 	"	std	%r10,88(%r1)					\n"\ |
| 49 | 	"	std	%r11,96(%r1)					\n"\ |
| 50 | 	"	mr	%r4, %r0					\n"\ |
| 51 | 	"	mr 	%r3, %r11					\n"\ |
| 52 | 	"	bl __mcount 						\n"\ |
| 53 | 	"	nop 							\n"\ |
| 54 | 	"	ld	%r3, 32(%r1)					\n"\ |
| 55 | 	"	ld	%r4, 40(%r1)					\n"\ |
| 56 | 	"	ld	%r5, 48(%r1)					\n"\ |
| 57 | 	"	ld	%r6, 56(%r1)					\n"\ |
| 58 | 	"	ld	%r7, 64(%r1)					\n"\ |
| 59 | 	"	ld	%r8, 72(%r1)					\n"\ |
| 60 | 	"	ld	%r9, 80(%r1)					\n"\ |
| 61 | 	"	ld	%r10,88(%r1)					\n"\ |
| 62 | 	"	ld	%r11,96(%r1)					\n"\ |
| 63 | 	"	addi	%r1, %r1, (288+128)				\n"\ |
| 64 | 	"	ld	%r0, 16(%r1)					\n"\ |
| 65 | 	"	std	%r11,16(%r1)					\n"\ |
| 66 | 	"	mtlr	%r0						\n"\ |
| 67 | 	"	blr							\n"\ |
| 68 | 	"	.size _mcount, .-_mcount				\n"\ |
| 69 | 	); |
| 70 | #define _MCOUNT_DECL static void __mcount |