asmacros.h revision 16029
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 * 3316029Speter * $Id: asmacros.h,v 1.7 1996/03/31 04:17:25 bde Exp $ 341817Sdg */ 351817Sdg 362579Sbde#ifndef _MACHINE_ASMACROS_H_ 372579Sbde#define _MACHINE_ASMACROS_H_ 382123Sjkh 392579Sbde#ifdef KERNEL 4016029Speter#include <sys/cdefs.h> 412579Sbde 4213107Sbde/* XXX too much duplication in various asm*.h's and gprof.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 */ 46757Sdg#define SUPERALIGN_TEXT .align 4,0x90 /* 16-byte alignment (better for 486), nop filled */ 47757Sdg 4816029Speter#define GEN_ENTRY(name) ALIGN_TEXT; .globl __CONCAT(_,name); __CONCAT(_,name): 4913107Sbde#define NON_GPROF_ENTRY(name) GEN_ENTRY(name) 50757Sdg 51757Sdg#ifdef GPROF 52757Sdg/* 5313107Sbde * __mcount is like mcount except that doesn't require its caller to set 5413107Sbde * up a frame pointer. It must be called before pushing anything onto the 5513107Sbde * stack. gcc should eventually generate code to call __mcount in most 5613107Sbde * cases. This would make -pg in combination with -fomit-frame-pointer 5713107Sbde * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to 5813107Sbde * allow profiling before setting up the frame pointer, but this is 5913107Sbde * inadequate for good handling of special cases, e.g., -fpic works best 6013107Sbde * with profiling after the prologue. 6113107Sbde * 6213107Sbde * Neither __mcount nor mcount requires %eax to point to 4 bytes of data, 6313107Sbde * so don't waste space allocating the data or time setting it up. Changes 6413107Sbde * to avoid the wastage in gcc-2.4.5-compiled code are available. 6513107Sbde * 6613107Sbde * mexitcount is a new profiling feature to allow accurate timing of all 6713107Sbde * functions if an accurate clock is available. Changes to gcc-2.4.5 to 6813107Sbde * support it are are available. The changes currently don't allow not 6913107Sbde * generating mexitcounts for non-kernel code. It is best to call 7013107Sbde * mexitcount right at the end of a function like the MEXITCOUNT macro 7113107Sbde * does, but the changes to gcc only implement calling it as the first 7213107Sbde * thing in the epilogue to avoid problems with -fpic. 7313107Sbde * 7413107Sbde * mcount and __mexitcount may clobber the call-used registers and %ef. 7513107Sbde * mexitcount may clobber %ecx and %ef. 7613107Sbde * 7713107Sbde * Cross-jumping makes accurate timing more difficult. It is handled in 7813107Sbde * many cases by calling mexitcount before jumping. It is not handled 7913107Sbde * for some conditional jumps (e.g., in bcopyx) or for some fault-handling 8013107Sbde * jumps. It is handled for some fault-handling jumps by not sharing the 8113107Sbde * exit routine. 8213107Sbde * 8313107Sbde * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to 8413107Sbde * the main entry point. Note that alt entries are counted twice. They 8513107Sbde * have to be counted as ordinary entries for gprof to get the call times 8613107Sbde * right for the ordinary entries. 8713107Sbde * 8813107Sbde * High local labels are used in macros to avoid clashes with local labels 8913107Sbde * in functions. 9013107Sbde * 9113107Sbde * "ret" is used instead of "RET" because there are a lot of "ret"s. 9213107Sbde * 0xc3 is the opcode for "ret" (#define ret ... ret fails because this 9313107Sbde * file is preprocessed in traditional mode). "ret" clobbers eflags 9413107Sbde * but this doesn't matter. 95757Sdg */ 9613107Sbde#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f 9713107Sbde#define ENTRY(name) GEN_ENTRY(name) ; 9: ; MCOUNT 9813107Sbde#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx 9913107Sbde#define MCOUNT call __mcount 10013107Sbde#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT 10113107Sbde#define MEXITCOUNT call mexitcount 10213107Sbde#define ret MEXITCOUNT ; .byte 0xc3 10313107Sbde#else /* not GPROF */ 104757Sdg/* 105757Sdg * ALTENTRY() has to align because it is before a corresponding ENTRY(). 106757Sdg * ENTRY() has to align to because there may be no ALTENTRY() before it. 10713107Sbde * If there is a previous ALTENTRY() then the alignment code for ENTRY() 10813107Sbde * is empty. 109757Sdg */ 11013107Sbde#define ALTENTRY(name) GEN_ENTRY(name) 11113107Sbde#define ENTRY(name) GEN_ENTRY(name) 11213107Sbde#define FAKE_MCOUNT(caller) 1131321Sdg#define MCOUNT 11413107Sbde#define MCOUNT_LABEL(name) 11513107Sbde#define MEXITCOUNT 11613107Sbde#endif /* GPROF */ 117757Sdg 1182579Sbde#else /* !KERNEL */ 1192579Sbde 1202579Sbde#include "/usr/src/lib/libc/i386/DEFS.h" /* XXX blech */ 1212579Sbde 1222123Sjkh#ifndef RCSID 1232123Sjkh#define RCSID(a) 1242123Sjkh#endif 1252123Sjkh 1262579Sbde#endif /* KERNEL */ 1272579Sbde 1282579Sbde#endif /* !_MACHINE_ASMACROS_H_ */ 129