186cb007fSWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 46cda32c0SRodney W. Grimes * Copyright (c) 1992, 1993 56cda32c0SRodney W. Grimes * The Regents of the University of California. All rights reserved. 66cda32c0SRodney W. Grimes * 76cda32c0SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 86cda32c0SRodney W. Grimes * modification, are permitted provided that the following conditions 96cda32c0SRodney W. Grimes * are met: 106cda32c0SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 116cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 126cda32c0SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 136cda32c0SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 146cda32c0SRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 166cda32c0SRodney W. Grimes * may be used to endorse or promote products derived from this software 176cda32c0SRodney W. Grimes * without specific prior written permission. 186cda32c0SRodney W. Grimes * 196cda32c0SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 206cda32c0SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 216cda32c0SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 226cda32c0SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 236cda32c0SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 246cda32c0SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 256cda32c0SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 266cda32c0SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 276cda32c0SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 286cda32c0SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 296cda32c0SRodney W. Grimes * SUCH DAMAGE. 306cda32c0SRodney W. Grimes */ 316cda32c0SRodney W. Grimes 32912e6037SBruce Evans #ifndef _MACHINE_PROFILE_H_ 33912e6037SBruce Evans #define _MACHINE_PROFILE_H_ 34836dc83bSPaul Richards 35*aa3ea612SKonstantin Belousov #ifndef _KERNEL 36a5f50ef9SJoerg Wunsch 37*aa3ea612SKonstantin Belousov #include <sys/cdefs.h> 38e5171bbeSBruce Evans 39a7d00b5bSBruce Evans #define FUNCTION_ALIGNMENT 4 40a7d00b5bSBruce Evans 41e5171bbeSBruce Evans #define _MCOUNT_DECL static __inline void _mcount 426cda32c0SRodney W. Grimes 436cda32c0SRodney W. Grimes #define MCOUNT \ 44e5171bbeSBruce Evans void \ 45e5171bbeSBruce Evans mcount() \ 46e5171bbeSBruce Evans { \ 47e8f00decSLuoqi Chen uintfptr_t selfpc, frompc, ecx; \ 48e8f00decSLuoqi Chen /* \ 49e8f00decSLuoqi Chen * In gcc 4.2, ecx might be used in the caller as the arg \ 50e8f00decSLuoqi Chen * pointer if the stack realignment option is set (-mstackrealign) \ 51e8f00decSLuoqi Chen * or if the caller has the force_align_arg_pointer attribute \ 52e8f00decSLuoqi Chen * (stack realignment is ALWAYS on for main). Preserve ecx \ 53e8f00decSLuoqi Chen * here. \ 54e8f00decSLuoqi Chen */ \ 55e8f00decSLuoqi Chen __asm("" : "=c" (ecx)); \ 566cda32c0SRodney W. Grimes /* \ 57912e6037SBruce Evans * Find the return address for mcount, \ 586cda32c0SRodney W. Grimes * and the return address for mcount's caller. \ 596cda32c0SRodney W. Grimes * \ 60912e6037SBruce Evans * selfpc = pc pushed by call to mcount \ 616cda32c0SRodney W. Grimes */ \ 6269bb4041SDavid E. O'Brien __asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \ 636cda32c0SRodney W. Grimes /* \ 64912e6037SBruce Evans * frompc = pc pushed by call to mcount's caller. \ 65912e6037SBruce Evans * The caller's stack frame has already been built, so %ebp is \ 66912e6037SBruce Evans * the caller's frame pointer. The caller's raddr is in the \ 67912e6037SBruce Evans * caller's frame following the caller's caller's frame pointer.\ 686cda32c0SRodney W. Grimes */ \ 6969bb4041SDavid E. O'Brien __asm("movl (%%ebp),%0" : "=r" (frompc)); \ 7037889b39SBruce Evans frompc = ((uintfptr_t *)frompc)[1]; \ 71912e6037SBruce Evans _mcount(frompc, selfpc); \ 72e8f00decSLuoqi Chen __asm("" : : "c" (ecx)); \ 736cda32c0SRodney W. Grimes } 74930a6423SBruce Evans 7519b5915aSBruce Evans typedef u_int uintfptr_t; 76930a6423SBruce Evans 77912e6037SBruce Evans /* 78912e6037SBruce Evans * An unsigned integral type that can hold non-negative difference between 79912e6037SBruce Evans * function pointers. 80912e6037SBruce Evans */ 815c623cb6STor Egge typedef u_int fptrdiff_t; 82912e6037SBruce Evans 83d6b9e17eSBruce Evans __BEGIN_DECLS 84b63dc6adSAlfred Perlstein void mcount(void) __asm(".mcount"); 85e5171bbeSBruce Evans __END_DECLS 86e5171bbeSBruce Evans 87*aa3ea612SKonstantin Belousov #endif /* !_KERNEL */ 88d6b9e17eSBruce Evans 89e5171bbeSBruce Evans #endif /* !_MACHINE_PROFILE_H_ */ 90