16cda32c0SRodney W. Grimes /* 26cda32c0SRodney W. Grimes * Copyright (c) 1992, 1993 36cda32c0SRodney W. Grimes * The Regents of the University of California. All rights reserved. 46cda32c0SRodney W. Grimes * 56cda32c0SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 66cda32c0SRodney W. Grimes * modification, are permitted provided that the following conditions 76cda32c0SRodney W. Grimes * are met: 86cda32c0SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 96cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 106cda32c0SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 116cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 126cda32c0SRodney W. Grimes * documentation and/or other materials provided with the distribution. 136cda32c0SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 146cda32c0SRodney W. Grimes * may be used to endorse or promote products derived from this software 156cda32c0SRodney W. Grimes * without specific prior written permission. 166cda32c0SRodney W. Grimes * 176cda32c0SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 186cda32c0SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196cda32c0SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206cda32c0SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 216cda32c0SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226cda32c0SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236cda32c0SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246cda32c0SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256cda32c0SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266cda32c0SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276cda32c0SRodney W. Grimes * SUCH DAMAGE. 286cda32c0SRodney W. Grimes * 296cda32c0SRodney W. Grimes * @(#)profile.h 8.1 (Berkeley) 6/11/93 30c3aac50fSPeter Wemm * $FreeBSD$ 316cda32c0SRodney W. Grimes */ 326cda32c0SRodney W. Grimes 33912e6037SBruce Evans #ifndef _MACHINE_PROFILE_H_ 34912e6037SBruce Evans #define _MACHINE_PROFILE_H_ 35836dc83bSPaul Richards 36664a31e4SPeter Wemm #ifdef _KERNEL 37930a6423SBruce Evans 38e5171bbeSBruce Evans /* 39a7d00b5bSBruce Evans * Config generates something to tell the compiler to align functions on 16 40a7d00b5bSBruce Evans * byte boundaries. A strict alignment is good for keeping the tables small. 41a7d00b5bSBruce Evans */ 42a7d00b5bSBruce Evans #define FUNCTION_ALIGNMENT 16 43a7d00b5bSBruce Evans 44a7d00b5bSBruce Evans /* 45e5171bbeSBruce Evans * The kernel uses assembler stubs instead of unportable inlines. 46e5171bbeSBruce Evans * This is mainly to save a little time when profiling is not enabled, 47e5171bbeSBruce Evans * which is the usual case for the kernel. 48e5171bbeSBruce Evans */ 49e5171bbeSBruce Evans #define _MCOUNT_DECL void mcount 50e5171bbeSBruce Evans #define MCOUNT 51e5171bbeSBruce Evans 521f403fcfSBruce Evans #ifdef GUPROF 531f403fcfSBruce Evans #define MCOUNT_DECL(s) 541f403fcfSBruce Evans #define MCOUNT_ENTER(s) 551f403fcfSBruce Evans #define MCOUNT_EXIT(s) 561f403fcfSBruce Evans #else 571f403fcfSBruce Evans #define MCOUNT_DECL(s) u_long s; 5878292efeSSteve Passe #ifdef SMP 5992fd4795SBruce Evans extern int mcount_lock; 6025142c5eSJohn Baldwin #define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); \ 61ce11a18fSJohn Baldwin while (!atomic_cmpset_acq_int(&mcount_lock, 0, 1)) \ 6225142c5eSJohn Baldwin /* nothing */ ; } 6325142c5eSJohn Baldwin #define MCOUNT_EXIT(s) { atomic_store_rel_int(&mcount_lock, 0); \ 6425142c5eSJohn Baldwin write_eflags(s); } 6578292efeSSteve Passe #else 665c623cb6STor Egge #define MCOUNT_ENTER(s) { s = read_eflags(); disable_intr(); } 671f403fcfSBruce Evans #define MCOUNT_EXIT(s) (write_eflags(s)) 6878292efeSSteve Passe #endif 691f403fcfSBruce Evans #endif /* GUPROF */ 701f403fcfSBruce Evans 71664a31e4SPeter Wemm #else /* !_KERNEL */ 72e5171bbeSBruce Evans 73a7d00b5bSBruce Evans #define FUNCTION_ALIGNMENT 4 74a7d00b5bSBruce Evans 75e5171bbeSBruce Evans #define _MCOUNT_DECL static __inline void _mcount 766cda32c0SRodney W. Grimes 77a122cca9STom Rhodes #if defined(__GNUC__) || defined(__INTEL_COMPILER) 786cda32c0SRodney W. Grimes #define MCOUNT \ 79e5171bbeSBruce Evans void \ 80e5171bbeSBruce Evans mcount() \ 81e5171bbeSBruce Evans { \ 8237889b39SBruce Evans uintfptr_t selfpc, frompc; \ 836cda32c0SRodney W. Grimes /* \ 84912e6037SBruce Evans * Find the return address for mcount, \ 856cda32c0SRodney W. Grimes * and the return address for mcount's caller. \ 866cda32c0SRodney W. Grimes * \ 87912e6037SBruce Evans * selfpc = pc pushed by call to mcount \ 886cda32c0SRodney W. Grimes */ \ 8969bb4041SDavid E. O'Brien __asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \ 906cda32c0SRodney W. Grimes /* \ 91912e6037SBruce Evans * frompc = pc pushed by call to mcount's caller. \ 92912e6037SBruce Evans * The caller's stack frame has already been built, so %ebp is \ 93912e6037SBruce Evans * the caller's frame pointer. The caller's raddr is in the \ 94912e6037SBruce Evans * caller's frame following the caller's caller's frame pointer.\ 956cda32c0SRodney W. Grimes */ \ 9669bb4041SDavid E. O'Brien __asm("movl (%%ebp),%0" : "=r" (frompc)); \ 9737889b39SBruce Evans frompc = ((uintfptr_t *)frompc)[1]; \ 98912e6037SBruce Evans _mcount(frompc, selfpc); \ 996cda32c0SRodney W. Grimes } 100a122cca9STom Rhodes #else /* !(__GNUC__ || __INTEL_COMPILER) */ 101db8f2e32SMark Murray void \ 10219b5915aSBruce Evans #define MCOUNT \ 103db8f2e32SMark Murray mcount() \ 104db8f2e32SMark Murray { \ 105db8f2e32SMark Murray } 106a122cca9STom Rhodes #endif /* __GNUC__ || __INTEL_COMPILER */ 107930a6423SBruce Evans 10819b5915aSBruce Evans typedef u_int uintfptr_t; 109930a6423SBruce Evans 110664a31e4SPeter Wemm #endif /* _KERNEL */ 111912e6037SBruce Evans 112912e6037SBruce Evans /* 113912e6037SBruce Evans * An unsigned integral type that can hold non-negative difference between 114912e6037SBruce Evans * function pointers. 115912e6037SBruce Evans */ 1165c623cb6STor Egge typedef u_int fptrdiff_t; 117912e6037SBruce Evans 118664a31e4SPeter Wemm #ifdef _KERNEL 119d6b9e17eSBruce Evans 120b63dc6adSAlfred Perlstein void mcount(uintfptr_t frompc, uintfptr_t selfpc); 121d6b9e17eSBruce Evans 122664a31e4SPeter Wemm #else /* !_KERNEL */ 123d6b9e17eSBruce Evans 124d6b9e17eSBruce Evans #include <sys/cdefs.h> 125d6b9e17eSBruce Evans 126d6b9e17eSBruce Evans __BEGIN_DECLS 127a122cca9STom Rhodes #if defined(__GNUC__) || defined(__INTEL_COMPILER) 128b63dc6adSAlfred Perlstein void mcount(void) __asm(".mcount"); 1295584f22bSJohn Polstra #endif 130e5171bbeSBruce Evans __END_DECLS 131e5171bbeSBruce Evans 132664a31e4SPeter Wemm #endif /* _KERNEL */ 133d6b9e17eSBruce Evans 134e5171bbeSBruce Evans #endif /* !_MACHINE_PROFILE_H_ */ 135