asmacros.h revision 97721
12619Sihse/*- 22619Sihse * Copyright (c) 1993 The Regents of the University of California. 32619Sihse * All rights reserved. 42619Sihse * 52619Sihse * Redistribution and use in source and binary forms, with or without 62619Sihse * modification, are permitted provided that the following conditions 72619Sihse * are met: 82619Sihse * 1. Redistributions of source code must retain the above copyright 92619Sihse * notice, this list of conditions and the following disclaimer. 102619Sihse * 2. Redistributions in binary form must reproduce the above copyright 112619Sihse * notice, this list of conditions and the following disclaimer in the 122619Sihse * documentation and/or other materials provided with the distribution. 132619Sihse * 3. All advertising materials mentioning features or use of this software 141680SN/A * must display the following acknowledgement: 152619Sihse * This product includes software developed by the University of 162619Sihse * California, Berkeley and its contributors. 172619Sihse * 4. Neither the name of the University nor the names of its contributors 182619Sihse * may be used to endorse or promote products derived from this software 192619Sihse * without specific prior written permission. 202619Sihse * 211680SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 222619Sihse * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 232619Sihse * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 242619Sihse * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 252619Sihse * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 262619Sihse * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 272619Sihse * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 282619Sihse * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 292619Sihse * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 302619Sihse * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 312619Sihse * SUCH DAMAGE. 322619Sihse * 332520Sihse * $FreeBSD: head/sys/amd64/include/asmacros.h 97721 2002-06-01 20:22:33Z alfred $ 341680SN/A */ 351680SN/A 362619Sihse#ifndef _MACHINE_ASMACROS_H_ 372619Sihse#define _MACHINE_ASMACROS_H_ 382619Sihse 391680SN/A#include <sys/cdefs.h> 402619Sihse 412619Sihse/* XXX too much duplication in various asm*.h's. */ 422619Sihse 431680SN/A/* 441680SN/A * CNAME and HIDENAME manage the relationship between symbol names in C 452619Sihse * and the equivalent assembly language names. CNAME is given a name as 462619Sihse * it would be used in a C program. It expands to the equivalent assembly 472619Sihse * language name. HIDENAME is given an assembly-language name, and expands 482619Sihse * to a possibly-modified form that will be invisible to C programs. 492619Sihse */ 502619Sihse#define CNAME(csym) csym 512619Sihse#define HIDENAME(asmsym) .asmsym 522619Sihse 532619Sihse#define ALIGN_DATA .p2align 2 /* 4 byte alignment, zero filled */ 542619Sihse#ifdef GPROF 552619Sihse#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ 562619Sihse#else 572619Sihse#define ALIGN_TEXT .p2align 2,0x90 /* 4-byte alignment, nop filled */ 582619Sihse#endif 592619Sihse#define SUPERALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */ 602619Sihse 612619Sihse#define GEN_ENTRY(name) ALIGN_TEXT; .globl CNAME(name); \ 622619Sihse .type CNAME(name),@function; CNAME(name): 632619Sihse#define NON_GPROF_ENTRY(name) GEN_ENTRY(name) 642619Sihse#define NON_GPROF_RET .byte 0xc3 /* opcode for `ret' */ 652619Sihse 662619Sihse#ifdef LOCORE 672619Sihse#define PCPU(member) %fs:PC_ ## member 682619Sihse#define PCPU_ADDR(member, reg) movl %fs:PC_PRVSPACE,reg; \ 692619Sihse addl $PC_ ## member,reg 702619Sihse#endif 712619Sihse 722619Sihse#ifdef GPROF 732619Sihse/* 742619Sihse * __mcount is like [.]mcount except that doesn't require its caller to set 752619Sihse * up a frame pointer. It must be called before pushing anything onto the 762619Sihse * stack. gcc should eventually generate code to call __mcount in most 772619Sihse * cases. This would make -pg in combination with -fomit-frame-pointer 782619Sihse * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to 792619Sihse * allow profiling before setting up the frame pointer, but this is 802619Sihse * inadequate for good handling of special cases, e.g., -fpic works best 812619Sihse * with profiling after the prologue. 822619Sihse * 832619Sihse * [.]mexitcount is a new function to support non-statistical profiling if an 842619Sihse * accurate clock is available. For C sources, calls to it are generated 852619Sihse * by the FreeBSD extension `-mprofiler-epilogue' to gcc. It is best to 862619Sihse * call [.]mexitcount at the end of a function like the MEXITCOUNT macro does, 872619Sihse * but gcc currently generates calls to it at the start of the epilogue to 882619Sihse * avoid problems with -fpic. 892619Sihse * 902619Sihse * [.]mcount and __mcount may clobber the call-used registers and %ef. 912619Sihse * [.]mexitcount may clobber %ecx and %ef. 922619Sihse * 932619Sihse * Cross-jumping makes non-statistical profiling timing more complicated. 942619Sihse * It is handled in many cases by calling [.]mexitcount before jumping. It 952619Sihse * is handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL(). 962619Sihse * It is handled for some fault-handling jumps by not sharing the exit 972619Sihse * routine. 982619Sihse * 992619Sihse * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to 1002619Sihse * the main entry point. Note that alt entries are counted twice. They 1012619Sihse * have to be counted as ordinary entries for gprof to get the call times 1022619Sihse * right for the ordinary entries. 1032619Sihse * 1042619Sihse * High local labels are used in macros to avoid clashes with local labels 1052619Sihse * in functions. 1062619Sihse * 1072619Sihse * Ordinary `ret' is used instead of a macro `RET' because there are a lot 1082619Sihse * of `ret's. 0xc3 is the opcode for `ret' (`#define ret ... ret' can't 1092619Sihse * be used because this file is sometimes preprocessed in traditional mode). 1102619Sihse * `ret' clobbers eflags but this doesn't matter. 1112619Sihse */ 1122619Sihse#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f 1132619Sihse#define CROSSJUMP(jtrue, label, jfalse) \ 1142619Sihse jfalse 8f; MEXITCOUNT; jmp __CONCAT(to,label); 8: 1152619Sihse#define CROSSJUMPTARGET(label) \ 1162619Sihse ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label 1172619Sihse#define ENTRY(name) GEN_ENTRY(name) ; 9: ; MCOUNT 1182619Sihse#define FAKE_MCOUNT(caller) pushl caller ; call __mcount ; popl %ecx 1192619Sihse#define MCOUNT call __mcount 1202619Sihse#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT 1212619Sihse#define MEXITCOUNT call HIDENAME(mexitcount) 1222619Sihse#define ret MEXITCOUNT ; NON_GPROF_RET 1232619Sihse 1242619Sihse#else /* !GPROF */ 1252619Sihse/* 1262619Sihse * ALTENTRY() has to align because it is before a corresponding ENTRY(). 1272619Sihse * ENTRY() has to align to because there may be no ALTENTRY() before it. 1282619Sihse * If there is a previous ALTENTRY() then the alignment code for ENTRY() 1292619Sihse * is empty. 1302619Sihse */ 1312619Sihse#define ALTENTRY(name) GEN_ENTRY(name) 1322619Sihse#define CROSSJUMP(jtrue, label, jfalse) jtrue label 1332619Sihse#define CROSSJUMPTARGET(label) 1342619Sihse#define ENTRY(name) GEN_ENTRY(name) 1352619Sihse#define FAKE_MCOUNT(caller) 1362619Sihse#define MCOUNT 1372619Sihse#define MCOUNT_LABEL(name) 1382619Sihse#define MEXITCOUNT 1392619Sihse#endif /* GPROF */ 1402619Sihse 1412619Sihse#endif /* !_MACHINE_ASMACROS_H_ */ 1421680SN/A