xref: /csrg-svn/sys/i386/include/profile.h (revision 55306)
1*55306Smckusick /*
2*55306Smckusick  * Copyright (c) 1992 The Regents of the University of California.
3*55306Smckusick  * All rights reserved.
4*55306Smckusick  *
5*55306Smckusick  * %sccs.include.redist.c%
6*55306Smckusick  *
7*55306Smckusick  *	@(#)profile.h	7.1 (Berkeley) 07/16/92
8*55306Smckusick  */
9*55306Smckusick 
10*55306Smckusick #define	_MCOUNT_DECL static inline void _mcount
11*55306Smckusick 
12*55306Smckusick #define	MCOUNT \
13*55306Smckusick extern void mcount() asm("mcount"); void mcount() { \
14*55306Smckusick 	int selfpc, frompcindex; \
15*55306Smckusick 	/* \
16*55306Smckusick 	 * find the return address for mcount, \
17*55306Smckusick 	 * and the return address for mcount's caller. \
18*55306Smckusick 	 * \
19*55306Smckusick 	 * selfpc = pc pushed by mcount call \
20*55306Smckusick 	 */ \
21*55306Smckusick 	asm("movl 4(%%ebp),%0" : "=r" (selfpc)); \
22*55306Smckusick 	/* \
23*55306Smckusick 	 * frompcindex = pc pushed by jsr into self. \
24*55306Smckusick 	 * In GCC the caller's stack frame has already been built so we \
25*55306Smckusick 	 * have to chase a6 to find caller's raddr. \
26*55306Smckusick 	 */ \
27*55306Smckusick 	asm("movl (%%ebp),%0" : "=r" (frompcindex)); \
28*55306Smckusick 	frompcindex = ((unsigned short **)frompcindex)[1]; \
29*55306Smckusick 	_mcount(frompcindex, selfpc); \
30*55306Smckusick }
31