1/*-
2 * SPDX-License-Identifier: MIT-CMU
3 *
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
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.
14 *
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.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22 *  School of Computer Science
23 *  Carnegie Mellon University
24 *  Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 *
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
31 * $FreeBSD$
32 */
33
34#ifndef _MACHINE_PROFILE_H_
35#define	_MACHINE_PROFILE_H_
36
37#if !defined(_KERNEL) && !defined(_SYS_CDEFS_H_)
38#error this file needs sys/cdefs.h as a prerequisite
39#endif
40
41#define	FUNCTION_ALIGNMENT	32
42
43typedef u_long	fptrdiff_t;
44
45#ifdef _KERNEL
46
47#include <machine/cpufunc.h>
48#include <machine/intr_machdep.h>
49
50#define	_MCOUNT_DECL	void mcount
51#define	MCOUNT
52
53#define	MCOUNT_DECL(s)	register_t s;
54#define	MCOUNT_ENTER(s)	s = rdpr(pil); wrpr(pil, 0, PIL_TICK)
55#define	MCOUNT_EXIT(s)	wrpr(pil, 0, s)
56
57void bintr(void);
58void btrap(void);
59void eintr(void);
60void user(void);
61
62#define	MCOUNT_FROMPC_USER(pc)					\
63	((pc < (uintfptr_t)VM_MAXUSER_ADDRESS) ? (uintfptr_t)user : pc)
64
65#define	MCOUNT_FROMPC_INTR(pc)					\
66	((pc >= (uintfptr_t)btrap && pc < (uintfptr_t)eintr) ?	\
67	    ((pc >= (uintfptr_t)bintr) ? (uintfptr_t)bintr :	\
68		(uintfptr_t)btrap) : ~0UL)
69
70void	mcount(uintfptr_t frompc, uintfptr_t selfpc);
71
72#else /* !_KERNEL */
73
74typedef u_long	uintfptr_t;
75
76#define	_MCOUNT_DECL	static __inline void __mcount
77
78#ifdef __GNUCLIKE_ASM
79#define	MCOUNT								\
80void									\
81_mcount()								\
82{									\
83	uintfptr_t frompc, selfpc;					\
84									\
85	/*								\
86	 * Find the return address for mcount,				\
87	 * and the return address for mcount's caller.			\
88	 *								\
89	 * selfpc = pc pushed by call to mcount				\
90	 */								\
91	__asm("add %%o7, 8, %0" : "=r" (selfpc));			\
92	/*								\
93	 * frompc = pc pushed by call to mcount's caller.		\
94	 */								\
95	__asm("add %%i7, 8, %0" : "=r" (frompc));			\
96	__mcount(frompc, selfpc);					\
97}
98#else /* !__GNUCLIKE_ASM */
99#define	MCOUNT
100#endif /* __GNUCLIKE_ASM */
101
102#endif /* _KERNEL */
103
104#endif /* !_MACHINE_PROFILE_H_ */
105