profile.h revision 1544
1224133Sdim/*
2224133Sdim * Copyright (c) 1992, 1993
3224133Sdim *	The Regents of the University of California.  All rights reserved.
4224133Sdim *
5224133Sdim * Redistribution and use in source and binary forms, with or without
6224133Sdim * modification, are permitted provided that the following conditions
7224133Sdim * are met:
8224133Sdim * 1. Redistributions of source code must retain the above copyright
9224133Sdim *    notice, this list of conditions and the following disclaimer.
10224133Sdim * 2. Redistributions in binary form must reproduce the above copyright
11224133Sdim *    notice, this list of conditions and the following disclaimer in the
12224133Sdim *    documentation and/or other materials provided with the distribution.
13224133Sdim * 3. All advertising materials mentioning features or use of this software
14224133Sdim *    must display the following acknowledgement:
15224133Sdim *	This product includes software developed by the University of
16224133Sdim *	California, Berkeley and its contributors.
17224133Sdim * 4. Neither the name of the University nor the names of its contributors
18224133Sdim *    may be used to endorse or promote products derived from this software
19243830Sdim *    without specific prior written permission.
20224133Sdim *
21224133Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22224133Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23224133Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24224133Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25224133Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26234353Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27224133Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28224133Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29224133Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30224133Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31224133Sdim * SUCH DAMAGE.
32224133Sdim *
33224133Sdim *	@(#)profile.h	8.1 (Berkeley) 6/11/93
34224133Sdim */
35224133Sdim
36224133Sdim#define	_MCOUNT_DECL static inline void _mcount
37224133Sdim
38224133Sdim#define	MCOUNT \
39224133Sdimextern void mcount() asm("mcount"); void mcount() { \
40224133Sdim	int selfpc, frompcindex; \
41224133Sdim	/* \
42224133Sdim	 * find the return address for mcount, \
43224133Sdim	 * and the return address for mcount's caller. \
44224133Sdim	 * \
45224133Sdim	 * selfpc = pc pushed by mcount call \
46224133Sdim	 */ \
47224133Sdim	asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \
48224133Sdim	/* \
49224133Sdim	 * frompcindex = pc pushed by jsr into self. \
50234353Sdim	 * In GCC the caller's stack frame has already been built so we \
51234353Sdim	 * have to chase a6 to find caller's raddr. \
52224133Sdim	 */ \
53243830Sdim	asm("movl (%%ebp),%0" : "=r" (frompcindex)); \
54243830Sdim	frompcindex = ((int *)frompcindex)[1]; \
55243830Sdim	_mcount(frompcindex, selfpc); \
56243830Sdim}
57243830Sdim