xref: /freebsd/sys/i386/include/profile.h (revision 6cda32c0719e5810f8b3d4cea0790002d44f80a4)
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  * 3. All advertising materials mentioning features or use of this software
146cda32c0SRodney W. Grimes  *    must display the following acknowledgement:
156cda32c0SRodney W. Grimes  *	This product includes software developed by the University of
166cda32c0SRodney W. Grimes  *	California, Berkeley and its contributors.
176cda32c0SRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
186cda32c0SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
196cda32c0SRodney W. Grimes  *    without specific prior written permission.
206cda32c0SRodney W. Grimes  *
216cda32c0SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
226cda32c0SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
236cda32c0SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
246cda32c0SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
256cda32c0SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
266cda32c0SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
276cda32c0SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286cda32c0SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
296cda32c0SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
306cda32c0SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
316cda32c0SRodney W. Grimes  * SUCH DAMAGE.
326cda32c0SRodney W. Grimes  *
336cda32c0SRodney W. Grimes  *	@(#)profile.h	8.1 (Berkeley) 6/11/93
346cda32c0SRodney W. Grimes  */
356cda32c0SRodney W. Grimes 
366cda32c0SRodney W. Grimes #define	_MCOUNT_DECL static inline void _mcount
376cda32c0SRodney W. Grimes 
386cda32c0SRodney W. Grimes #define	MCOUNT \
396cda32c0SRodney W. Grimes extern void mcount() asm("mcount"); void mcount() { \
406cda32c0SRodney W. Grimes 	int selfpc, frompcindex; \
416cda32c0SRodney W. Grimes 	/* \
426cda32c0SRodney W. Grimes 	 * find the return address for mcount, \
436cda32c0SRodney W. Grimes 	 * and the return address for mcount's caller. \
446cda32c0SRodney W. Grimes 	 * \
456cda32c0SRodney W. Grimes 	 * selfpc = pc pushed by mcount call \
466cda32c0SRodney W. Grimes 	 */ \
476cda32c0SRodney W. Grimes 	asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \
486cda32c0SRodney W. Grimes 	/* \
496cda32c0SRodney W. Grimes 	 * frompcindex = pc pushed by jsr into self. \
506cda32c0SRodney W. Grimes 	 * In GCC the caller's stack frame has already been built so we \
516cda32c0SRodney W. Grimes 	 * have to chase a6 to find caller's raddr. \
526cda32c0SRodney W. Grimes 	 */ \
536cda32c0SRodney W. Grimes 	asm("movl (%%ebp),%0" : "=r" (frompcindex)); \
546cda32c0SRodney W. Grimes 	frompcindex = ((int *)frompcindex)[1]; \
556cda32c0SRodney W. Grimes 	_mcount(frompcindex, selfpc); \
566cda32c0SRodney W. Grimes }
57