asmacros.h revision 22636
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 *
3321673Sjkh *	$FreeBSD: head/sys/amd64/include/asmacros.h 22636 1997-02-13 08:31:53Z bde $
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 */
4522636Sbde#ifdef GPROF
4622636Sbde#define ALIGN_TEXT	.align	4,0x90	/* 16-byte alignment, nop filled */
4722636Sbde#else
48757Sdg#define ALIGN_TEXT	.align	2,0x90	/* 4-byte alignment, nop filled */
4922636Sbde#endif
5018961Sbde#define SUPERALIGN_TEXT	.align	4,0x90	/* 16-byte alignment, nop filled */
51757Sdg
5218961Sbde#define GEN_ENTRY(name)		ALIGN_TEXT; .globl __CONCAT(_,name); \
5318961Sbde				__CONCAT(_,name):
5413107Sbde#define NON_GPROF_ENTRY(name)	GEN_ENTRY(name)
5518961Sbde#define NON_GPROF_RET		.byte 0xc3	/* opcode for `ret' */
56757Sdg
57757Sdg#ifdef GPROF
58757Sdg/*
5913107Sbde * __mcount is like mcount except that doesn't require its caller to set
6013107Sbde * up a frame pointer.  It must be called before pushing anything onto the
6113107Sbde * stack.  gcc should eventually generate code to call __mcount in most
6213107Sbde * cases.  This would make -pg in combination with -fomit-frame-pointer
6313107Sbde * useful.  gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to
6413107Sbde * allow profiling before setting up the frame pointer, but this is
6513107Sbde * inadequate for good handling of special cases, e.g., -fpic works best
6613107Sbde * with profiling after the prologue.
6713107Sbde *
6818961Sbde * mexitcount is a new function to support non-statistical profiling if an
6918961Sbde * accurate clock is available.  For C sources, calls to it are generated
7018961Sbde * by the FreeBSD extension `-mprofiler-epilogue' to gcc.  It is best to
7118961Sbde * call mexitcount at the end of a function like the MEXITCOUNT macro does,
7218961Sbde * but gcc currently generates calls to it at the start of the epilogue to
7318961Sbde * avoid problems with -fpic.
7413107Sbde *
7513107Sbde * mcount and __mexitcount may clobber the call-used registers and %ef.
7613107Sbde * mexitcount may clobber %ecx and %ef.
7713107Sbde *
7818961Sbde * Cross-jumping makes non-statistical profiling timing more complicated.
7918961Sbde * It is handled in many cases by calling mexitcount before jumping.  It is
8018961Sbde * handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL().
8118961Sbde * It is handled for some fault-handling jumps by not sharing the exit
8218961Sbde * routine.
8313107Sbde *
8413107Sbde * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to
8513107Sbde * the main entry point.  Note that alt entries are counted twice.  They
8613107Sbde * have to be counted as ordinary entries for gprof to get the call times
8713107Sbde * right for the ordinary entries.
8813107Sbde *
8913107Sbde * High local labels are used in macros to avoid clashes with local labels
9013107Sbde * in functions.
9113107Sbde *
9218961Sbde * Ordinary `ret' is used instead of a macro `RET' because there are a lot
9318961Sbde * of `ret's.  0xc3 is the opcode for `ret' (`#define ret ... ret' can't
9418961Sbde * be used because this file is sometimes preprocessed in traditional mode).
9518961Sbde * `ret' clobbers eflags but this doesn't matter.
96757Sdg */
9713107Sbde#define ALTENTRY(name)		GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f
9818961Sbde#define	CROSSJUMP(jtrue, label, jfalse) \
9918961Sbde	jfalse 8f; MEXITCOUNT; jmp __CONCAT(to,label); 8:
10018961Sbde#define CROSSJUMPTARGET(label) \
10118961Sbde	ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label
10213107Sbde#define ENTRY(name)		GEN_ENTRY(name) ; 9: ; MCOUNT
10313107Sbde#define FAKE_MCOUNT(caller)	pushl caller ; call __mcount ; popl %ecx
10413107Sbde#define MCOUNT			call __mcount
10513107Sbde#define MCOUNT_LABEL(name)	GEN_ENTRY(name) ; nop ; ALIGN_TEXT
10613107Sbde#define MEXITCOUNT		call mexitcount
10718961Sbde#define ret			MEXITCOUNT ; NON_GPROF_RET
10818961Sbde
10918961Sbde#else /* !GPROF */
110757Sdg/*
111757Sdg * ALTENTRY() has to align because it is before a corresponding ENTRY().
112757Sdg * ENTRY() has to align to because there may be no ALTENTRY() before it.
11313107Sbde * If there is a previous ALTENTRY() then the alignment code for ENTRY()
11413107Sbde * is empty.
115757Sdg */
11613107Sbde#define ALTENTRY(name)		GEN_ENTRY(name)
11718961Sbde#define	CROSSJUMP(jtrue, label, jfalse)	jtrue label
11818961Sbde#define	CROSSJUMPTARGET(label)
11913107Sbde#define ENTRY(name)		GEN_ENTRY(name)
12013107Sbde#define FAKE_MCOUNT(caller)
1211321Sdg#define MCOUNT
12213107Sbde#define MCOUNT_LABEL(name)
12313107Sbde#define MEXITCOUNT
12413107Sbde#endif /* GPROF */
125757Sdg
1262579Sbde#else /* !KERNEL */
1272579Sbde
1282579Sbde#include "/usr/src/lib/libc/i386/DEFS.h"	/* XXX blech */
1292579Sbde
1302123Sjkh#ifndef RCSID
1312123Sjkh#define RCSID(a)
1322123Sjkh#endif
1332123Sjkh
1342579Sbde#endif /* KERNEL */
1352579Sbde
1362579Sbde#endif /* !_MACHINE_ASMACROS_H_ */
137