asmacros.h revision 18961
11817Sdg/*-
21817Sdg * Copyright (c) 1993 The Regents of the University of California.
31817Sdg * All rights reserved.
41817Sdg *
51817Sdg * Redistribution and use in source and binary forms, with or without
61817Sdg * modification, are permitted provided that the following conditions
71817Sdg * are met:
81817Sdg * 1. Redistributions of source code must retain the above copyright
91817Sdg *    notice, this list of conditions and the following disclaimer.
101817Sdg * 2. Redistributions in binary form must reproduce the above copyright
111817Sdg *    notice, this list of conditions and the following disclaimer in the
121817Sdg *    documentation and/or other materials provided with the distribution.
131817Sdg * 3. All advertising materials mentioning features or use of this software
141817Sdg *    must display the following acknowledgement:
151817Sdg *	This product includes software developed by the University of
161817Sdg *	California, Berkeley and its contributors.
171817Sdg * 4. Neither the name of the University nor the names of its contributors
181817Sdg *    may be used to endorse or promote products derived from this software
191817Sdg *    without specific prior written permission.
201817Sdg *
211817Sdg * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221817Sdg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231817Sdg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241817Sdg * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251817Sdg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261817Sdg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271817Sdg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281817Sdg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291817Sdg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301817Sdg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311817Sdg * SUCH DAMAGE.
321817Sdg *
3318961Sbde *	$Id: asmacros.h,v 1.8 1996/05/31 01:08:05 peter Exp $
341817Sdg */
351817Sdg
362579Sbde#ifndef _MACHINE_ASMACROS_H_
372579Sbde#define _MACHINE_ASMACROS_H_
382123Sjkh
392579Sbde#ifdef KERNEL
4016029Speter#include <sys/cdefs.h>
412579Sbde
4218961Sbde/* XXX too much duplication in various asm*.h's. */
4313107Sbde
44757Sdg#define ALIGN_DATA	.align	2	/* 4 byte alignment, zero filled */
45757Sdg#define ALIGN_TEXT	.align	2,0x90	/* 4-byte alignment, nop filled */
4618961Sbde#define SUPERALIGN_TEXT	.align	4,0x90	/* 16-byte alignment, nop filled */
47757Sdg
4818961Sbde#define GEN_ENTRY(name)		ALIGN_TEXT; .globl __CONCAT(_,name); \
4918961Sbde				__CONCAT(_,name):
5013107Sbde#define NON_GPROF_ENTRY(name)	GEN_ENTRY(name)
5118961Sbde#define NON_GPROF_RET		.byte 0xc3	/* opcode for `ret' */
52757Sdg
53757Sdg#ifdef GPROF
54757Sdg/*
5513107Sbde * __mcount is like mcount except that doesn't require its caller to set
5613107Sbde * up a frame pointer.  It must be called before pushing anything onto the
5713107Sbde * stack.  gcc should eventually generate code to call __mcount in most
5813107Sbde * cases.  This would make -pg in combination with -fomit-frame-pointer
5913107Sbde * useful.  gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to
6013107Sbde * allow profiling before setting up the frame pointer, but this is
6113107Sbde * inadequate for good handling of special cases, e.g., -fpic works best
6213107Sbde * with profiling after the prologue.
6313107Sbde *
6418961Sbde * mexitcount is a new function to support non-statistical profiling if an
6518961Sbde * accurate clock is available.  For C sources, calls to it are generated
6618961Sbde * by the FreeBSD extension `-mprofiler-epilogue' to gcc.  It is best to
6718961Sbde * call mexitcount at the end of a function like the MEXITCOUNT macro does,
6818961Sbde * but gcc currently generates calls to it at the start of the epilogue to
6918961Sbde * avoid problems with -fpic.
7013107Sbde *
7113107Sbde * mcount and __mexitcount may clobber the call-used registers and %ef.
7213107Sbde * mexitcount may clobber %ecx and %ef.
7313107Sbde *
7418961Sbde * Cross-jumping makes non-statistical profiling timing more complicated.
7518961Sbde * It is handled in many cases by calling mexitcount before jumping.  It is
7618961Sbde * handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL().
7718961Sbde * It is handled for some fault-handling jumps by not sharing the exit
7818961Sbde * routine.
7913107Sbde *
8013107Sbde * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to
8113107Sbde * the main entry point.  Note that alt entries are counted twice.  They
8213107Sbde * have to be counted as ordinary entries for gprof to get the call times
8313107Sbde * right for the ordinary entries.
8413107Sbde *
8513107Sbde * High local labels are used in macros to avoid clashes with local labels
8613107Sbde * in functions.
8713107Sbde *
8818961Sbde * Ordinary `ret' is used instead of a macro `RET' because there are a lot
8918961Sbde * of `ret's.  0xc3 is the opcode for `ret' (`#define ret ... ret' can't
9018961Sbde * be used because this file is sometimes preprocessed in traditional mode).
9118961Sbde * `ret' clobbers eflags but this doesn't matter.
92757Sdg */
9313107Sbde#define ALTENTRY(name)		GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f
9418961Sbde#define	CROSSJUMP(jtrue, label, jfalse) \
9518961Sbde	jfalse 8f; MEXITCOUNT; jmp __CONCAT(to,label); 8:
9618961Sbde#define CROSSJUMPTARGET(label) \
9718961Sbde	ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label
9813107Sbde#define ENTRY(name)		GEN_ENTRY(name) ; 9: ; MCOUNT
9913107Sbde#define FAKE_MCOUNT(caller)	pushl caller ; call __mcount ; popl %ecx
10013107Sbde#define MCOUNT			call __mcount
10113107Sbde#define MCOUNT_LABEL(name)	GEN_ENTRY(name) ; nop ; ALIGN_TEXT
10213107Sbde#define MEXITCOUNT		call mexitcount
10318961Sbde#define ret			MEXITCOUNT ; NON_GPROF_RET
10418961Sbde
10518961Sbde#else /* !GPROF */
106757Sdg/*
107757Sdg * ALTENTRY() has to align because it is before a corresponding ENTRY().
108757Sdg * ENTRY() has to align to because there may be no ALTENTRY() before it.
10913107Sbde * If there is a previous ALTENTRY() then the alignment code for ENTRY()
11013107Sbde * is empty.
111757Sdg */
11213107Sbde#define ALTENTRY(name)		GEN_ENTRY(name)
11318961Sbde#define	CROSSJUMP(jtrue, label, jfalse)	jtrue label
11418961Sbde#define	CROSSJUMPTARGET(label)
11513107Sbde#define ENTRY(name)		GEN_ENTRY(name)
11613107Sbde#define FAKE_MCOUNT(caller)
1171321Sdg#define MCOUNT
11813107Sbde#define MCOUNT_LABEL(name)
11913107Sbde#define MEXITCOUNT
12013107Sbde#endif /* GPROF */
121757Sdg
1222579Sbde#else /* !KERNEL */
1232579Sbde
1242579Sbde#include "/usr/src/lib/libc/i386/DEFS.h"	/* XXX blech */
1252579Sbde
1262123Sjkh#ifndef RCSID
1272123Sjkh#define RCSID(a)
1282123Sjkh#endif
1292123Sjkh
1302579Sbde#endif /* KERNEL */
1312579Sbde
1322579Sbde#endif /* !_MACHINE_ASMACROS_H_ */
133