asmacros.h revision 13107
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 * 3313107Sbde * $Id: asmacros.h,v 1.5 1994/09/08 12:25:18 bde Exp $ 341817Sdg */ 351817Sdg 362579Sbde#ifndef _MACHINE_ASMACROS_H_ 372579Sbde#define _MACHINE_ASMACROS_H_ 382123Sjkh 392579Sbde#ifdef KERNEL 402579Sbde 4113107Sbde/* XXX too much duplication in various asm*.h's and gprof.h's */ 4213107Sbde 43757Sdg#define ALIGN_DATA .align 2 /* 4 byte alignment, zero filled */ 44757Sdg#define ALIGN_TEXT .align 2,0x90 /* 4-byte alignment, nop filled */ 45757Sdg#define SUPERALIGN_TEXT .align 4,0x90 /* 16-byte alignment (better for 486), nop filled */ 46757Sdg 4713107Sbde#define GEN_ENTRY(name) ALIGN_TEXT; .globl _/**/name; _/**/name: 4813107Sbde#define NON_GPROF_ENTRY(name) GEN_ENTRY(name) 49757Sdg 50757Sdg#ifdef GPROF 51757Sdg/* 5213107Sbde * __mcount is like mcount except that doesn't require its caller to set 5313107Sbde * up a frame pointer. It must be called before pushing anything onto the 5413107Sbde * stack. gcc should eventually generate code to call __mcount in most 5513107Sbde * cases. This would make -pg in combination with -fomit-frame-pointer 5613107Sbde * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to 5713107Sbde * allow profiling before setting up the frame pointer, but this is 5813107Sbde * inadequate for good handling of special cases, e.g., -fpic works best 5913107Sbde * with profiling after the prologue. 6013107Sbde * 6113107Sbde * Neither __mcount nor mcount requires %eax to point to 4 bytes of data, 6213107Sbde * so don't waste space allocating the data or time setting it up. Changes 6313107Sbde * to avoid the wastage in gcc-2.4.5-compiled code are available. 6413107Sbde * 6513107Sbde * mexitcount is a new profiling feature to allow accurate timing of all 6613107Sbde * functions if an accurate clock is available. Changes to gcc-2.4.5 to 6713107Sbde * support it are are available. The changes currently don't allow not 6813107Sbde * generating mexitcounts for non-kernel code. It is best to call 6913107Sbde * mexitcount right at the end of a function like the MEXITCOUNT macro 7013107Sbde * does, but the changes to gcc only implement calling it as the first 7113107Sbde * thing in the epilogue to avoid problems with -fpic. 7213107Sbde * 7313107Sbde * mcount and __mexitcount may clobber the call-used registers and %ef. 7413107Sbde * mexitcount may clobber %ecx and %ef. 7513107Sbde * 7613107Sbde * Cross-jumping makes accurate timing more difficult. It is handled in 7713107Sbde * many cases by calling mexitcount before jumping. It is not handled 7813107Sbde * for some conditional jumps (e.g., in bcopyx) or for some fault-handling 7913107Sbde * jumps. It is handled for some fault-handling jumps by not sharing the 8013107Sbde * exit routine. 8113107Sbde * 8213107Sbde * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to 8313107Sbde * the main entry point. Note that alt entries are counted twice. They 8413107Sbde * have to be counted as ordinary entries for gprof to get the call times 8513107Sbde * right for the ordinary entries. 8613107Sbde * 8713107Sbde * High local labels are used in macros to avoid clashes with local labels 8813107Sbde * in functions. 8913107Sbde * 9013107Sbde * "ret" is used instead of "RET" because there are a lot of "ret"s. 9113107Sbde * 0xc3 is the opcode for "ret" (#define ret ... ret fails because this 9213107Sbde * file is preprocessed in traditional mode). "ret" clobbers eflags 9313107Sbde * but this doesn't matter. 94757Sdg */ 9513107Sbde#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f 9613107Sbde#define ENTRY(name) GEN_ENTRY(name) ; 9: ; MCOUNT 9713107Sbde#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx 9813107Sbde#define MCOUNT call __mcount 9913107Sbde#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT 10013107Sbde#define MEXITCOUNT call mexitcount 10113107Sbde#define ret MEXITCOUNT ; .byte 0xc3 10213107Sbde#else /* not GPROF */ 103757Sdg/* 104757Sdg * ALTENTRY() has to align because it is before a corresponding ENTRY(). 105757Sdg * ENTRY() has to align to because there may be no ALTENTRY() before it. 10613107Sbde * If there is a previous ALTENTRY() then the alignment code for ENTRY() 10713107Sbde * is empty. 108757Sdg */ 10913107Sbde#define ALTENTRY(name) GEN_ENTRY(name) 11013107Sbde#define ENTRY(name) GEN_ENTRY(name) 11113107Sbde#define FAKE_MCOUNT(caller) 1121321Sdg#define MCOUNT 11313107Sbde#define MCOUNT_LABEL(name) 11413107Sbde#define MEXITCOUNT 11513107Sbde#endif /* GPROF */ 116757Sdg 11713107Sbde/* XXX NOP and FASTER_NOP are misleadingly named */ 118757Sdg#ifdef DUMMY_NOPS /* this will break some older machines */ 119757Sdg#define FASTER_NOP 120757Sdg#define NOP 121757Sdg#else 122757Sdg#define FASTER_NOP pushl %eax ; inb $0x84,%al ; popl %eax 123757Sdg#define NOP pushl %eax ; inb $0x84,%al ; inb $0x84,%al ; popl %eax 124757Sdg#endif 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