0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Copyright (c) 1993 The Regents of the University of California.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * All rights reserved.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Redistribution and use in source and binary forms, with or without
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * modification, are permitted provided that the following conditions
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * 1. Redistributions of source code must retain the above copyright
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * notice, this list of conditions and the following disclaimer.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * 2. Redistributions in binary form must reproduce the above copyright
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * notice, this list of conditions and the following disclaimer in the
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * documentation and/or other materials provided with the distribution.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * 4. Neither the name of the University nor the names of its contributors
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * may be used to endorse or promote products derived from this software
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * without specific prior written permission.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2b6c28b8b605a28e1a671f5d6b484cd697e51da6batschul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * SUCH DAMAGE.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * $FreeBSD$
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek/* XXX too much duplication in various asm*.h's. */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * CNAME is used to manage the relationship between symbol names in C
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * and the equivalent assembly language names. CNAME is given a name as
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * it would be used in a C program. It expands to the equivalent assembly
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * language name.
0094b373ead542a342e4250eaf37854ccd3e50c0jv#define ALIGN_DATA .p2align 3 /* 8 byte alignment, zero filled */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */
99653d4ee642c6528e88224f12409a5f23060994eschrock#define ALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define SUPERALIGN_TEXT .p2align 4,0x90 /* 16-byte alignment, nop filled */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define GEN_ENTRY(name) ALIGN_TEXT; .globl CNAME(name); \
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define NON_GPROF_RET .byte 0xc3 /* opcode for `ret' */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * __mcount is like [.]mcount except that doesn't require its caller to set
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * up a frame pointer. It must be called before pushing anything onto the
286822dd6ee35fa0959e7b55e659b92ea1c12f71 * stack. gcc should eventually generate code to call __mcount in most
286822dd6ee35fa0959e7b55e659b92ea1c12f71 * cases. This would make -pg in combination with -fomit-frame-pointer
286822dd6ee35fa0959e7b55e659b92ea1c12f71 * useful. gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to
286822dd6ee35fa0959e7b55e659b92ea1c12f71 * allow profiling before setting up the frame pointer, but this is
286822dd6ee35fa0959e7b55e659b92ea1c12f71 * inadequate for good handling of special cases, e.g., -fpic works best
286822dd6ee35fa0959e7b55e659b92ea1c12f71 * with profiling after the prologue.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * [.]mexitcount is a new function to support non-statistical profiling if an
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * accurate clock is available. For C sources, calls to it are generated
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * by the FreeBSD extension `-mprofiler-epilogue' to gcc. It is best to
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * call [.]mexitcount at the end of a function like the MEXITCOUNT macro does,
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * but gcc currently generates calls to it at the start of the epilogue to
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * avoid problems with -fpic.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * [.]mcount and __mcount may clobber the call-used registers and %ef.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * [.]mexitcount may clobber %ecx and %ef.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Cross-jumping makes non-statistical profiling timing more complicated.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * It is handled in many cases by calling [.]mexitcount before jumping. It
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * is handled for conditional jumps using CROSSJUMP() and CROSSJUMP_LABEL().
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * It is handled for some fault-handling jumps by not sharing the exit
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * the main entry point. Note that alt entries are counted twice. They
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * have to be counted as ordinary entries for gprof to get the call times
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * right for the ordinary entries.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * High local labels are used in macros to avoid clashes with local labels
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * in functions.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Ordinary `ret' is used instead of a macro `RET' because there are a lot
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * of `ret's. 0xc3 is the opcode for `ret' (`#define ret ... ret' can't
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * be used because this file is sometimes preprocessed in traditional mode).
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * `ret' clobbers eflags but this doesn't matter.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define ALTENTRY(name) GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek ALIGN_TEXT; __CONCAT(to,label): ; MCOUNT; jmp label
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define FAKE_MCOUNT(caller) pushq caller ; call __mcount ; popq %rcx
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#define MCOUNT_LABEL(name) GEN_ENTRY(name) ; nop ; ALIGN_TEXT
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek#else /* !GPROF */
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * ALTENTRY() has to align because it is before a corresponding ENTRY().
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * ENTRY() has to align to because there may be no ALTENTRY() before it.
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * If there is a previous ALTENTRY() then the alignment code for ENTRY()
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * is empty.
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek#endif /* GPROF */
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * Convenience for adding frame pointers to hand-coded ASM. Useful for
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * DTrace, HWPMC, and KDB.
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * Convenience macro for declaring interrupt entry points.
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek#define IDTVEC(name) ALIGN_TEXT; .globl __CONCAT(X,name); \
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek .type __CONCAT(X,name),@function; __CONCAT(X,name):
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek * Macros to create and destroy a trap frame.
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek subq $TF_RIP,%rsp ; /* skip dummy tf_err and tf_trapno */ \
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel? */ \
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek testb $SEL_RPL_MASK,TF_CS(%rsp) ; /* come from kernel? */ \
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek1: addq $TF_RIP,%rsp /* skip over tf_err, tf_trapno */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Access per-CPU data.
ff17c8bf86c3e567734be83f90267edee20f580fgjelinek#endif /* LOCORE */
ff17c8bf86c3e567734be83f90267edee20f580fgjelinek#define ELFNOTE(name, type, desctype, descdata...) \
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#else /* !__STDC__, i.e. -traditional */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#endif /* __STDC__ */
c75cc341903ca38e644edfae5357a4020418f9be#endif /* !_MACHINE_ASMACROS_H_ */