asmacros.h revision 114349
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 * 3350477Speter * $FreeBSD: head/sys/amd64/include/asmacros.h 114349 2003-05-01 01:05:25Z peter $ 341817Sdg */ 351817Sdg 362579Sbde#ifndef _MACHINE_ASMACROS_H_ 372579Sbde#define _MACHINE_ASMACROS_H_ 382123Sjkh 3916029Speter#include <sys/cdefs.h> 402579Sbde 4118961Sbde/* XXX too much duplication in various asm*.h's. */ 4213107Sbde 4325083Sjdp/* 4425083Sjdp * CNAME and HIDENAME manage the relationship between symbol names in C 4525083Sjdp * and the equivalent assembly language names. CNAME is given a name as 4625083Sjdp * it would be used in a C program. It expands to the equivalent assembly 4725083Sjdp * language name. HIDENAME is given an assembly-language name, and expands 4825083Sjdp * to a possibly-modified form that will be invisible to C programs. 4925083Sjdp */ 5025083Sjdp#define CNAME(csym) csym 5197721Salfred#define HIDENAME(asmsym) .asmsym 5225083Sjdp 53114349Speter#define ALIGN_DATA .p2align 3 /* 8 byte alignment, zero filled */ 5422636Sbde#ifdef GPROF 5525083Sjdp#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ 5622636Sbde#else 57114349Speter#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ 5822636Sbde#endif 5925083Sjdp#define SUPERALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ 60757Sdg 6125083Sjdp#define GEN_ENTRY(name) ALIGN_TEXT; .globl CNAME(name); \ 6246548Sbde .type CNAME(name),@function; CNAME(name): 6313107Sbde#define NON_GPROF_ENTRY(name) GEN_ENTRY(name) 6418961Sbde#define NON_GPROF_RET .byte 0xc3 /* opcode for `ret' */ 65757Sdg 6670714Sjake#ifdef LOCORE 67114349Speter#define PCPU(member) %gs:PC_ ## member 68114349Speter#define PCPU_ADDR(member, reg) movq %gs:PC_PRVSPACE,reg; \ 69114349Speter addq $PC_ ## member,reg 7069971Sjake#endif 7169971Sjake 72757Sdg#ifdef GPROF 73757Sdg/* 7446548Sbde * __mcount is like [.]mcount except that doesn't require its caller to set 7513107Sbde * up a frame pointer. It must be called before pushing anything onto the 7613107Sbde * stack. gcc should eventually generate code to call __mcount in most 7713107Sbde * cases. This would make -pg in combination with -fomit-frame-pointer 7813107Sbde * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to 7913107Sbde * allow profiling before setting up the frame pointer, but this is 8013107Sbde * inadequate for good handling of special cases, e.g., -fpic works best 8113107Sbde * with profiling after the prologue. 8213107Sbde * 8346548Sbde * [.]mexitcount is a new function to support non-statistical profiling if an 8418961Sbde * accurate clock is available. For C sources, calls to it are generated 8518961Sbde * by the FreeBSD extension `-mprofiler-epilogue' to gcc. It is best to 8646548Sbde * call [.]mexitcount at the end of a function like the MEXITCOUNT macro does, 8718961Sbde * but gcc currently generates calls to it at the start of the epilogue to 8818961Sbde * avoid problems with -fpic. 8913107Sbde * 9046548Sbde * [.]mcount and __mcount may clobber the call-used registers and %ef. 9146548Sbde * [.]mexitcount may clobber %ecx and %ef. 9213107Sbde * 9318961Sbde * Cross-jumping makes non-statistical profiling timing more complicated. 9446548Sbde * It is handled in many cases by calling [.]mexitcount before jumping. It 9546548Sbde * is handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL(). 9618961Sbde * It is handled for some fault-handling jumps by not sharing the exit 9718961Sbde * routine. 9813107Sbde * 9913107Sbde * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to 10013107Sbde * the main entry point. Note that alt entries are counted twice. They 10113107Sbde * have to be counted as ordinary entries for gprof to get the call times 10213107Sbde * right for the ordinary entries. 10313107Sbde * 10413107Sbde * High local labels are used in macros to avoid clashes with local labels 10513107Sbde * in functions. 10613107Sbde * 10718961Sbde * Ordinary `ret' is used instead of a macro `RET' because there are a lot 10818961Sbde * of `ret's. 0xc3 is the opcode for `ret' (`#define ret ... ret' can't 10918961Sbde * be used because this file is sometimes preprocessed in traditional mode). 11018961Sbde * `ret' clobbers eflags but this doesn't matter. 111757Sdg */ 11213107Sbde#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f 11318961Sbde#define CROSSJUMP(jtrue, label, jfalse) \ 11418961Sbde jfalse 8f; MEXITCOUNT; jmp __CONCAT(to,label); 8: 11518961Sbde#define CROSSJUMPTARGET(label) \ 11618961Sbde ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label 11713107Sbde#define ENTRY(name) GEN_ENTRY(name) ; 9: ; MCOUNT 118114349Speter#define FAKE_MCOUNT(caller) pushq caller ; call __mcount ; popl %ecx 11913107Sbde#define MCOUNT call __mcount 12013107Sbde#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT 12146548Sbde#define MEXITCOUNT call HIDENAME(mexitcount) 12218961Sbde#define ret MEXITCOUNT ; NON_GPROF_RET 12318961Sbde 12418961Sbde#else /* !GPROF */ 125757Sdg/* 126757Sdg * ALTENTRY() has to align because it is before a corresponding ENTRY(). 127757Sdg * ENTRY() has to align to because there may be no ALTENTRY() before it. 12813107Sbde * If there is a previous ALTENTRY() then the alignment code for ENTRY() 12913107Sbde * is empty. 130757Sdg */ 13113107Sbde#define ALTENTRY(name) GEN_ENTRY(name) 13218961Sbde#define CROSSJUMP(jtrue, label, jfalse) jtrue label 13318961Sbde#define CROSSJUMPTARGET(label) 13413107Sbde#define ENTRY(name) GEN_ENTRY(name) 13513107Sbde#define FAKE_MCOUNT(caller) 1361321Sdg#define MCOUNT 13713107Sbde#define MCOUNT_LABEL(name) 13813107Sbde#define MEXITCOUNT 13913107Sbde#endif /* GPROF */ 140757Sdg 1412579Sbde#endif /* !_MACHINE_ASMACROS_H_ */ 142