xref: /openbsd-src/sys/arch/amd64/include/profile.h (revision 08cf7c3f88334cf737af7753d1b04496aca85a86)
1*08cf7c3fScheloha /*	$OpenBSD: profile.h,v 1.6 2023/06/27 10:11:15 cheloha Exp $	*/
230e52abaSdrahn /*	$NetBSD: profile.h,v 1.3 2003/11/28 23:22:45 fvdl Exp $	*/
3f5df1827Smickey 
4f5df1827Smickey /*
5f5df1827Smickey  * Copyright (c) 1992, 1993
6f5df1827Smickey  *	The Regents of the University of California.  All rights reserved.
7f5df1827Smickey  *
8f5df1827Smickey  * Redistribution and use in source and binary forms, with or without
9f5df1827Smickey  * modification, are permitted provided that the following conditions
10f5df1827Smickey  * are met:
11f5df1827Smickey  * 1. Redistributions of source code must retain the above copyright
12f5df1827Smickey  *    notice, this list of conditions and the following disclaimer.
13f5df1827Smickey  * 2. Redistributions in binary form must reproduce the above copyright
14f5df1827Smickey  *    notice, this list of conditions and the following disclaimer in the
15f5df1827Smickey  *    documentation and/or other materials provided with the distribution.
1630e52abaSdrahn  * 3. Neither the name of the University nor the names of its contributors
17f5df1827Smickey  *    may be used to endorse or promote products derived from this software
18f5df1827Smickey  *    without specific prior written permission.
19f5df1827Smickey  *
20f5df1827Smickey  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21f5df1827Smickey  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22f5df1827Smickey  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23f5df1827Smickey  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24f5df1827Smickey  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25f5df1827Smickey  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26f5df1827Smickey  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27f5df1827Smickey  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28f5df1827Smickey  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29f5df1827Smickey  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30f5df1827Smickey  * SUCH DAMAGE.
31f5df1827Smickey  *
32f5df1827Smickey  *	@(#)profile.h	8.1 (Berkeley) 6/11/93
33f5df1827Smickey  */
34f5df1827Smickey 
3530e52abaSdrahn #define	_MCOUNT_DECL void _mcount
36f5df1827Smickey 
3732b97dedSpascal #ifdef __PIC__
3830e52abaSdrahn #define __MCPLT	"@PLT"
3930e52abaSdrahn #else
4030e52abaSdrahn #define __MCPLT
4130e52abaSdrahn #endif
42f5df1827Smickey 
43f5df1827Smickey #define	MCOUNT						\
4430e52abaSdrahn __asm(" .globl __mcount		\n"			\
4530e52abaSdrahn "	.type __mcount,@function\n"			\
4630e52abaSdrahn "__mcount:			\n"			\
4730e52abaSdrahn "	pushq	%rbp		\n"			\
4830e52abaSdrahn "	movq	%rsp,%rbp	\n"			\
4930e52abaSdrahn "	subq	$56,%rsp	\n"			\
5030e52abaSdrahn "	movq	%rdi,0(%rsp)	\n"			\
5130e52abaSdrahn "	movq	%rsi,8(%rsp)	\n"			\
5230e52abaSdrahn "	movq	%rdx,16(%rsp)	\n"			\
5330e52abaSdrahn "	movq	%rcx,24(%rsp)	\n"			\
5430e52abaSdrahn "	movq	%r8,32(%rsp)	\n"			\
5530e52abaSdrahn "	movq	%r9,40(%rsp)	\n"			\
5630e52abaSdrahn "	movq	%rax,48(%rsp)	\n"			\
5730e52abaSdrahn "	movq	0(%rbp),%r11	\n"			\
5830e52abaSdrahn "	movq	8(%r11),%rdi	\n"			\
5930e52abaSdrahn "	movq	8(%rbp),%rsi	\n"			\
608f9d0e9dSkettenis "	call	_mcount"__MCPLT"\n"			\
6130e52abaSdrahn "	movq	0(%rsp),%rdi	\n"			\
6230e52abaSdrahn "	movq	8(%rsp),%rsi	\n"			\
6330e52abaSdrahn "	movq	16(%rsp),%rdx	\n"			\
6430e52abaSdrahn "	movq	24(%rsp),%rcx	\n"			\
6530e52abaSdrahn "	movq	32(%rsp),%r8	\n"			\
6630e52abaSdrahn "	movq	40(%rsp),%r9	\n"			\
6730e52abaSdrahn "	movq	48(%rsp),%rax	\n"			\
6830e52abaSdrahn "	leave			\n"			\
6930e52abaSdrahn "	ret			\n"			\
703dd0809fSbluhm "	lfence			\n"			\
7130e52abaSdrahn "	.size __mcount,.-__mcount");
72f5df1827Smickey 
73f5df1827Smickey 
74f5df1827Smickey #ifdef _KERNEL
75*08cf7c3fScheloha #define MCOUNT_ENTER	s = intr_disable()
76*08cf7c3fScheloha #define MCOUNT_EXIT	intr_restore(s)
77f5df1827Smickey #endif /* _KERNEL */
78