profile.h revision 202031
1178172Simp/*	$OpenBSD: profile.h,v 1.2 1999/01/27 04:46:05 imp Exp $ */
2178172Simp/*-
3178172Simp * Copyright (c) 1992, 1993
4178172Simp *	The Regents of the University of California.  All rights reserved.
5178172Simp *
6178172Simp * This code is derived from software contributed to Berkeley by
7178172Simp * Ralph Campbell.
8178172Simp *
9178172Simp * Redistribution and use in source and binary forms, with or without
10178172Simp * modification, are permitted provided that the following conditions
11178172Simp * are met:
12178172Simp * 1. Redistributions of source code must retain the above copyright
13178172Simp *    notice, this list of conditions and the following disclaimer.
14178172Simp * 2. Redistributions in binary form must reproduce the above copyright
15178172Simp *    notice, this list of conditions and the following disclaimer in the
16178172Simp *    documentation and/or other materials provided with the distribution.
17178172Simp * 4. Neither the name of the University nor the names of its contributors
18178172Simp *    may be used to endorse or promote products derived from this software
19178172Simp *    without specific prior written permission.
20178172Simp *
21178172Simp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31178172Simp * SUCH DAMAGE.
32178172Simp *
33178172Simp *	from: @(#)profile.h	8.1 (Berkeley) 6/10/93
34178172Simp *	JNPR: profile.h,v 1.4 2006/12/02 09:53:41 katta
35178172Simp * $FreeBSD: head/sys/mips/include/profile.h 202031 2010-01-10 19:50:24Z imp $
36178172Simp */
37178172Simp#ifndef _MACHINE_PROFILE_H_
38178172Simp#define	_MACHINE_PROFILE_H_
39178172Simp
40178172Simp#define	_MCOUNT_DECL void ___mcount
41178172Simp
42178172Simp/*XXX The cprestore instruction is a "dummy" to shut up as(1). */
43178172Simp
44202031Simp/*XXX This is not MIPS64 safe. */
45202031Simp
46178172Simp#define	MCOUNT \
47178172Simp	__asm(".globl _mcount;"		\
48178172Simp	".type _mcount,@function;"	\
49178172Simp	"_mcount:;"			\
50178172Simp	".set noreorder;"		\
51178172Simp	".set noat;"			\
52178172Simp	".cpload $25;"			\
53178172Simp	".cprestore 4;"			\
54178172Simp	"sw $4,8($29);"			\
55178172Simp	"sw $5,12($29);"		\
56178172Simp	"sw $6,16($29);"		\
57178172Simp	"sw $7,20($29);"		\
58178172Simp	"sw $1,0($29);"			\
59178172Simp	"sw $31,4($29);"		\
60178172Simp	"move $5,$31;"			\
61178172Simp	"jal ___mcount;"		\
62178172Simp	"move $4,$1;"			\
63178172Simp	"lw $4,8($29);"			\
64178172Simp	"lw $5,12($29);"		\
65178172Simp	"lw $6,16($29);"		\
66178172Simp	"lw $7,20($29);"		\
67178172Simp	"lw $31,4($29);"		\
68178172Simp	"lw $1,0($29);"			\
69178172Simp	"addu $29,$29,8;"		\
70178172Simp	"j $31;"			\
71178172Simp	"move $31,$1;"			\
72178172Simp	".set reorder;"			\
73178172Simp	".set at");
74178172Simp
75178172Simp#ifdef _KERNEL
76178172Simp/*
77178172Simp * The following two macros do splhigh and splx respectively.
78178172Simp * They have to be defined this way because these are real
79178172Simp * functions on the MIPS, and we do not want to invoke mcount
80178172Simp * recursively.
81178172Simp */
82178172Simp
83178172Simp#define	MCOUNT_DECL(s)	u_long s;
84178172Simp#ifdef SMP
85178172Simpextern int	mcount_lock;
86178172Simp#define	MCOUNT_ENTER(s)	{					\
87178172Simp	s = disable_intr();					\
88178172Simp	while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1))	\
89178172Simp		/* nothing */ ;					\
90178172Simp}
91178172Simp#define	MCOUNT_EXIT(s)	{					\
92178172Simp	atomic_store_rel_int(&mcount_lock, 0);			\
93178172Simp	enableintr(s);						\
94178172Simp}
95178172Simp#else
96178172Simp#define	MCOUNT_ENTER(s)	{ s = disable_intr(); }
97178172Simp#define	MCOUNT_EXIT(s)	(enableintr(s))
98178172Simp#endif
99178172Simp
100178172Simp/* REVISIT for mips */
101178172Simp/*
102178172Simp * Config generates something to tell the compiler to align functions on 16
103178172Simp * byte boundaries.  A strict alignment is good for keeping the tables small.
104178172Simp */
105178172Simp#define	FUNCTION_ALIGNMENT	16
106178172Simp
107178172Simp#ifdef GUPROF
108178172Simpstruct gmonparam;
109178172Simpvoid	stopguprof __P((struct gmonparam *p));
110178172Simp#else
111178172Simp#define	stopguprof(p)
112178172Simp#endif /* GUPROF */
113178172Simp
114178172Simp#else	/* !_KERNEL */
115178172Simp
116178172Simp#define	FUNCTION_ALIGNMENT	4
117178172Simp
118178172Simptypedef unsigned int	uintfptr_t;
119178172Simp
120178172Simp#endif /* _KERNEL */
121178172Simp
122178172Simp/*
123178172Simp * An unsigned integral type that can hold non-negative difference between
124178172Simp * function pointers.
125178172Simp */
126178172Simptypedef u_int	fptrdiff_t;
127178172Simp
128178172Simp#ifdef _KERNEL
129178172Simp
130178172Simpvoid	mcount(uintfptr_t frompc, uintfptr_t selfpc);
131178172Simp
132178172Simp#ifdef GUPROF
133178172Simpstruct gmonparam;
134178172Simp
135178172Simpvoid	nullfunc_loop_profiled(void);
136178172Simpvoid	nullfunc_profiled(void);
137178172Simpvoid	startguprof(struct gmonparam *p);
138178172Simpvoid	stopguprof(struct gmonparam *p);
139178172Simp#else
140178172Simp#define	startguprof(p)
141178172Simp#define	stopguprof(p)
142178172Simp#endif /* GUPROF */
143178172Simp
144178172Simp#else /* !_KERNEL */
145178172Simp
146178172Simp#include <sys/cdefs.h>
147178172Simp
148178172Simp__BEGIN_DECLS
149178172Simp#ifdef __GNUC__
150178172Simp#ifdef __ELF__
151178172Simpvoid	mcount(void) __asm(".mcount");
152178172Simp#else
153178172Simpvoid	mcount(void) __asm("mcount");
154178172Simp#endif
155178172Simp#endif
156178172Simpvoid	_mcount(uintfptr_t frompc, uintfptr_t selfpc);
157178172Simp__END_DECLS
158178172Simp
159178172Simp#endif /* _KERNEL */
160178172Simp
161178172Simp#ifdef GUPROF
162178172Simp/* XXX doesn't quite work outside kernel yet. */
163178172Simpextern int	cputime_bias;
164178172Simp
165178172Simp__BEGIN_DECLS
166178172Simpint	cputime(void);
167178172Simpvoid	empty_loop(void);
168178172Simpvoid	mexitcount(uintfptr_t selfpc);
169178172Simpvoid	nullfunc(void);
170178172Simpvoid	nullfunc_loop(void);
171178172Simp__END_DECLS
172178172Simp#endif
173178172Simp
174178172Simp#endif /* !_MACHINE_PROFILE_H_ */
175