profile.h revision 13107
1177633Sdfr/*
2177633Sdfr * Copyright (c) 1992, 1993
3177633Sdfr *	The Regents of the University of California.  All rights reserved.
4177633Sdfr *
5177633Sdfr * Redistribution and use in source and binary forms, with or without
6177633Sdfr * modification, are permitted provided that the following conditions
7177633Sdfr * are met:
8177633Sdfr * 1. Redistributions of source code must retain the above copyright
9177633Sdfr *    notice, this list of conditions and the following disclaimer.
10177633Sdfr * 2. Redistributions in binary form must reproduce the above copyright
11177633Sdfr *    notice, this list of conditions and the following disclaimer in the
12177633Sdfr *    documentation and/or other materials provided with the distribution.
13177633Sdfr * 3. All advertising materials mentioning features or use of this software
14177633Sdfr *    must display the following acknowledgement:
15177633Sdfr *	This product includes software developed by the University of
16177633Sdfr *	California, Berkeley and its contributors.
17177633Sdfr * 4. Neither the name of the University nor the names of its contributors
18177633Sdfr *    may be used to endorse or promote products derived from this software
19177633Sdfr *    without specific prior written permission.
20177633Sdfr *
21177633Sdfr * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22177633Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23177633Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24177633Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25177633Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26177633Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27177633Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28177633Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29177633Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30177633Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31177633Sdfr * SUCH DAMAGE.
32177633Sdfr *
33177633Sdfr *	@(#)profile.h	8.1 (Berkeley) 6/11/93
34177633Sdfr * $Id: profile.h,v 1.4 1994/09/15 16:27:14 paul Exp $
35177633Sdfr */
36177633Sdfr
37177633Sdfr#ifndef _MACHINE_PROFILE_H_
38177633Sdfr#define	_MACHINE_PROFILE_H_
39177633Sdfr
40177633Sdfr#if 0
41177633Sdfr#define	_MCOUNT_DECL static inline void _mcount
42177633Sdfr
43177633Sdfr#define	MCOUNT \
44177633Sdfrextern void mcount() asm("mcount"); void mcount() { \
45177633Sdfr	fptrint_t selfpc, frompc; \
46177633Sdfr	/* \
47177633Sdfr	 * Find the return address for mcount, \
48177633Sdfr	 * and the return address for mcount's caller. \
49177633Sdfr	 * \
50177633Sdfr	 * selfpc = pc pushed by call to mcount \
51177633Sdfr	 */ \
52177633Sdfr	asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \
53177633Sdfr	/* \
54177633Sdfr	 * frompc = pc pushed by call to mcount's caller. \
55177633Sdfr	 * The caller's stack frame has already been built, so %ebp is \
56177633Sdfr	 * the caller's frame pointer.  The caller's raddr is in the \
57177633Sdfr	 * caller's frame following the caller's caller's frame pointer. \
58177633Sdfr	 */ \
59177633Sdfr	asm("movl (%%ebp),%0" : "=r" (frompc)); \
60177633Sdfr	frompc = ((fptrint_t *)frompc)[1]; \
61177685Sdfr	_mcount(frompc, selfpc); \
62177633Sdfr}
63177633Sdfr#else
64177633Sdfr#define	_MCOUNT_DECL void mcount
65177633Sdfr#define	MCOUNT
66177633Sdfr#endif
67177633Sdfr
68177633Sdfr#define	MCOUNT_ENTER	{ save_eflags = read_eflags(); disable_intr(); }
69177633Sdfr#define	MCOUNT_EXIT	(write_eflags(save_eflags))
70177633Sdfr
71177633Sdfr#define	CALIB_SCALE	1000
72177633Sdfr#define	KCOUNT(p,index)	((p)->kcount[(index) \
73177633Sdfr			 / (HISTFRACTION * sizeof(*(p)->kcount))])
74177633Sdfr#define	PC_TO_I(p, pc)	((fptrint_t)(pc) - (fptrint_t)(p)->lowpc)
75177633Sdfr
76177633Sdfr/* An unsigned integral type that can hold function pointers. */
77177633Sdfrtypedef	u_int	fptrint_t;
78177633Sdfr
79177633Sdfr/*
80177633Sdfr * An unsigned integral type that can hold non-negative difference between
81177633Sdfr * function pointers.
82177633Sdfr */
83177633Sdfrtypedef	int	fptrdiff_t;
84177633Sdfr
85177633Sdfru_int	cputime __P((void));
86177633Sdfrvoid	mcount __P((fptrint_t frompc, fptrint_t selfpc));
87177633Sdfrvoid	mexitcount __P((fptrint_t selfpc));
88177633Sdfr
89177633Sdfr#endif /* !MACHINE_PROFILE_H */
90177633Sdfr