profile.h revision 13107
11543Srgrimes/*
21543Srgrimes * Copyright (c) 1992, 1993
31543Srgrimes *	The Regents of the University of California.  All rights reserved.
41543Srgrimes *
51543Srgrimes * Redistribution and use in source and binary forms, with or without
61543Srgrimes * modification, are permitted provided that the following conditions
71543Srgrimes * are met:
81543Srgrimes * 1. Redistributions of source code must retain the above copyright
91543Srgrimes *    notice, this list of conditions and the following disclaimer.
101543Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111543Srgrimes *    notice, this list of conditions and the following disclaimer in the
121543Srgrimes *    documentation and/or other materials provided with the distribution.
131543Srgrimes * 3. All advertising materials mentioning features or use of this software
141543Srgrimes *    must display the following acknowledgement:
151543Srgrimes *	This product includes software developed by the University of
161543Srgrimes *	California, Berkeley and its contributors.
171543Srgrimes * 4. Neither the name of the University nor the names of its contributors
181543Srgrimes *    may be used to endorse or promote products derived from this software
191543Srgrimes *    without specific prior written permission.
201543Srgrimes *
211543Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221543Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231543Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241543Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251543Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261543Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271543Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281543Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291543Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301543Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311543Srgrimes * SUCH DAMAGE.
321543Srgrimes *
331543Srgrimes *	@(#)profile.h	8.1 (Berkeley) 6/11/93
3413107Sbde * $Id: profile.h,v 1.4 1994/09/15 16:27:14 paul Exp $
351543Srgrimes */
361543Srgrimes
3713107Sbde#ifndef _MACHINE_PROFILE_H_
3813107Sbde#define	_MACHINE_PROFILE_H_
392166Spaul
4013107Sbde#if 0
411543Srgrimes#define	_MCOUNT_DECL static inline void _mcount
421543Srgrimes
431543Srgrimes#define	MCOUNT \
441543Srgrimesextern void mcount() asm("mcount"); void mcount() { \
4513107Sbde	fptrint_t selfpc, frompc; \
461543Srgrimes	/* \
4713107Sbde	 * Find the return address for mcount, \
481543Srgrimes	 * and the return address for mcount's caller. \
491543Srgrimes	 * \
5013107Sbde	 * selfpc = pc pushed by call to mcount \
511543Srgrimes	 */ \
521543Srgrimes	asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \
531543Srgrimes	/* \
5413107Sbde	 * frompc = pc pushed by call to mcount's caller. \
5513107Sbde	 * The caller's stack frame has already been built, so %ebp is \
5613107Sbde	 * the caller's frame pointer.  The caller's raddr is in the \
5713107Sbde	 * caller's frame following the caller's caller's frame pointer. \
581543Srgrimes	 */ \
5913107Sbde	asm("movl (%%ebp),%0" : "=r" (frompc)); \
6013107Sbde	frompc = ((fptrint_t *)frompc)[1]; \
6113107Sbde	_mcount(frompc, selfpc); \
621543Srgrimes}
6313107Sbde#else
6413107Sbde#define	_MCOUNT_DECL void mcount
6513107Sbde#define	MCOUNT
6613107Sbde#endif
672166Spaul
6813107Sbde#define	MCOUNT_ENTER	{ save_eflags = read_eflags(); disable_intr(); }
6913107Sbde#define	MCOUNT_EXIT	(write_eflags(save_eflags))
702801Spaul
7113107Sbde#define	CALIB_SCALE	1000
7213107Sbde#define	KCOUNT(p,index)	((p)->kcount[(index) \
7313107Sbde			 / (HISTFRACTION * sizeof(*(p)->kcount))])
7413107Sbde#define	PC_TO_I(p, pc)	((fptrint_t)(pc) - (fptrint_t)(p)->lowpc)
7513107Sbde
7613107Sbde/* An unsigned integral type that can hold function pointers. */
7713107Sbdetypedef	u_int	fptrint_t;
7813107Sbde
7913107Sbde/*
8013107Sbde * An unsigned integral type that can hold non-negative difference between
8113107Sbde * function pointers.
8213107Sbde */
8313107Sbdetypedef	int	fptrdiff_t;
8413107Sbde
8513107Sbdeu_int	cputime __P((void));
8613107Sbdevoid	mcount __P((fptrint_t frompc, fptrint_t selfpc));
8713107Sbdevoid	mexitcount __P((fptrint_t selfpc));
8813107Sbde
8913107Sbde#endif /* !MACHINE_PROFILE_H */
90