xref: /freebsd/sys/amd64/include/asmacros.h (revision 912e60377833803e8c89e2cbfd4c8eb8a6d90280)
13c4dd356SDavid Greenman /*-
23c4dd356SDavid Greenman  * Copyright (c) 1993 The Regents of the University of California.
33c4dd356SDavid Greenman  * All rights reserved.
43c4dd356SDavid Greenman  *
53c4dd356SDavid Greenman  * Redistribution and use in source and binary forms, with or without
63c4dd356SDavid Greenman  * modification, are permitted provided that the following conditions
73c4dd356SDavid Greenman  * are met:
83c4dd356SDavid Greenman  * 1. Redistributions of source code must retain the above copyright
93c4dd356SDavid Greenman  *    notice, this list of conditions and the following disclaimer.
103c4dd356SDavid Greenman  * 2. Redistributions in binary form must reproduce the above copyright
113c4dd356SDavid Greenman  *    notice, this list of conditions and the following disclaimer in the
123c4dd356SDavid Greenman  *    documentation and/or other materials provided with the distribution.
133c4dd356SDavid Greenman  * 3. All advertising materials mentioning features or use of this software
143c4dd356SDavid Greenman  *    must display the following acknowledgement:
153c4dd356SDavid Greenman  *	This product includes software developed by the University of
163c4dd356SDavid Greenman  *	California, Berkeley and its contributors.
173c4dd356SDavid Greenman  * 4. Neither the name of the University nor the names of its contributors
183c4dd356SDavid Greenman  *    may be used to endorse or promote products derived from this software
193c4dd356SDavid Greenman  *    without specific prior written permission.
203c4dd356SDavid Greenman  *
213c4dd356SDavid Greenman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
223c4dd356SDavid Greenman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
233c4dd356SDavid Greenman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
243c4dd356SDavid Greenman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
253c4dd356SDavid Greenman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
263c4dd356SDavid Greenman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
273c4dd356SDavid Greenman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
283c4dd356SDavid Greenman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
293c4dd356SDavid Greenman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
303c4dd356SDavid Greenman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313c4dd356SDavid Greenman  * SUCH DAMAGE.
323c4dd356SDavid Greenman  *
33912e6037SBruce Evans  *	$Id: asmacros.h,v 1.5 1994/09/08 12:25:18 bde Exp $
343c4dd356SDavid Greenman  */
353c4dd356SDavid Greenman 
36ab9678acSBruce Evans #ifndef _MACHINE_ASMACROS_H_
37ab9678acSBruce Evans #define _MACHINE_ASMACROS_H_
38ab9678acSBruce Evans 
39ab9678acSBruce Evans #ifdef KERNEL
406605d9f3SJordan K. Hubbard 
41912e6037SBruce Evans /* XXX too much duplication in various asm*.h's and gprof.h's */
42912e6037SBruce Evans 
430967373eSDavid Greenman #define ALIGN_DATA	.align	2	/* 4 byte alignment, zero filled */
440967373eSDavid Greenman #define ALIGN_TEXT	.align	2,0x90	/* 4-byte alignment, nop filled */
450967373eSDavid Greenman #define SUPERALIGN_TEXT	.align	4,0x90	/* 16-byte alignment (better for 486), nop filled */
460967373eSDavid Greenman 
47912e6037SBruce Evans #define GEN_ENTRY(name)		ALIGN_TEXT; .globl _/**/name; _/**/name:
48912e6037SBruce Evans #define NON_GPROF_ENTRY(name)	GEN_ENTRY(name)
49d2306226SDavid Greenman 
500967373eSDavid Greenman #ifdef GPROF
510967373eSDavid Greenman /*
52912e6037SBruce Evans  * __mcount is like mcount except that doesn't require its caller to set
53912e6037SBruce Evans  * up a frame pointer.  It must be called before pushing anything onto the
54912e6037SBruce Evans  * stack.  gcc should eventually generate code to call __mcount in most
55912e6037SBruce Evans  * cases.  This would make -pg in combination with -fomit-frame-pointer
56912e6037SBruce Evans  * useful.  gcc has a configuration variable PROFILE_BEFORE_PROLOGUE to
57912e6037SBruce Evans  * allow profiling before setting up the frame pointer, but this is
58912e6037SBruce Evans  * inadequate for good handling of special cases, e.g., -fpic works best
59912e6037SBruce Evans  * with profiling after the prologue.
60912e6037SBruce Evans  *
61912e6037SBruce Evans  * Neither __mcount nor mcount requires %eax to point to 4 bytes of data,
62912e6037SBruce Evans  * so don't waste space allocating the data or time setting it up.  Changes
63912e6037SBruce Evans  * to avoid the wastage in gcc-2.4.5-compiled code are available.
64912e6037SBruce Evans  *
65912e6037SBruce Evans  * mexitcount is a new profiling feature to allow accurate timing of all
66912e6037SBruce Evans  * functions if an accurate clock is available.  Changes to gcc-2.4.5 to
67912e6037SBruce Evans  * support it are are available.  The changes currently don't allow not
68912e6037SBruce Evans  * generating mexitcounts for non-kernel code.  It is best to call
69912e6037SBruce Evans  * mexitcount right at the end of a function like the MEXITCOUNT macro
70912e6037SBruce Evans  * does, but the changes to gcc only implement calling it as the first
71912e6037SBruce Evans  * thing in the epilogue to avoid problems with -fpic.
72912e6037SBruce Evans  *
73912e6037SBruce Evans  * mcount and __mexitcount may clobber the call-used registers and %ef.
74912e6037SBruce Evans  * mexitcount may clobber %ecx and %ef.
75912e6037SBruce Evans  *
76912e6037SBruce Evans  * Cross-jumping makes accurate timing more difficult.  It is handled in
77912e6037SBruce Evans  * many cases by calling mexitcount before jumping.  It is not handled
78912e6037SBruce Evans  * for some conditional jumps (e.g., in bcopyx) or for some fault-handling
79912e6037SBruce Evans  * jumps.  It is handled for some fault-handling jumps by not sharing the
80912e6037SBruce Evans  * exit routine.
81912e6037SBruce Evans  *
82912e6037SBruce Evans  * ALTENTRY() must be before a corresponding ENTRY() so that it can jump to
83912e6037SBruce Evans  * the main entry point.  Note that alt entries are counted twice.  They
84912e6037SBruce Evans  * have to be counted as ordinary entries for gprof to get the call times
85912e6037SBruce Evans  * right for the ordinary entries.
86912e6037SBruce Evans  *
87912e6037SBruce Evans  * High local labels are used in macros to avoid clashes with local labels
88912e6037SBruce Evans  * in functions.
89912e6037SBruce Evans  *
90912e6037SBruce Evans  * "ret" is used instead of "RET" because there are a lot of "ret"s.
91912e6037SBruce Evans  * 0xc3 is the opcode for "ret" (#define ret ... ret fails because this
92912e6037SBruce Evans  * file is preprocessed in traditional mode).  "ret" clobbers eflags
93912e6037SBruce Evans  * but this doesn't matter.
940967373eSDavid Greenman  */
95912e6037SBruce Evans #define ALTENTRY(name)		GEN_ENTRY(name) ; MCOUNT ; MEXITCOUNT ; jmp 9f
96912e6037SBruce Evans #define ENTRY(name)		GEN_ENTRY(name) ; 9: ; MCOUNT
97912e6037SBruce Evans #define FAKE_MCOUNT(caller)	pushl caller ; call __mcount ; popl %ecx
98912e6037SBruce Evans #define MCOUNT			call __mcount
99912e6037SBruce Evans #define MCOUNT_LABEL(name)	GEN_ENTRY(name) ; nop ; ALIGN_TEXT
100912e6037SBruce Evans #define MEXITCOUNT		call mexitcount
101912e6037SBruce Evans #define ret			MEXITCOUNT ; .byte 0xc3
102912e6037SBruce Evans #else /* not GPROF */
1030967373eSDavid Greenman /*
1040967373eSDavid Greenman  * ALTENTRY() has to align because it is before a corresponding ENTRY().
1050967373eSDavid Greenman  * ENTRY() has to align to because there may be no ALTENTRY() before it.
106912e6037SBruce Evans  * If there is a previous ALTENTRY() then the alignment code for ENTRY()
107912e6037SBruce Evans  * is empty.
1080967373eSDavid Greenman  */
109912e6037SBruce Evans #define ALTENTRY(name)		GEN_ENTRY(name)
110912e6037SBruce Evans #define ENTRY(name)		GEN_ENTRY(name)
111912e6037SBruce Evans #define FAKE_MCOUNT(caller)
112d2306226SDavid Greenman #define MCOUNT
113912e6037SBruce Evans #define MCOUNT_LABEL(name)
114912e6037SBruce Evans #define MEXITCOUNT
115912e6037SBruce Evans #endif /* GPROF */
1160967373eSDavid Greenman 
117912e6037SBruce Evans /* XXX NOP and FASTER_NOP are misleadingly named */
1180967373eSDavid Greenman #ifdef DUMMY_NOPS			/* this will break some older machines */
1190967373eSDavid Greenman #define FASTER_NOP
1200967373eSDavid Greenman #define NOP
1210967373eSDavid Greenman #else
1220967373eSDavid Greenman #define FASTER_NOP	pushl %eax ; inb $0x84,%al ; popl %eax
1230967373eSDavid Greenman #define NOP		pushl %eax ; inb $0x84,%al ; inb $0x84,%al ; popl %eax
1240967373eSDavid Greenman #endif
1250967373eSDavid Greenman 
126ab9678acSBruce Evans #else /* !KERNEL */
127ab9678acSBruce Evans 
128ab9678acSBruce Evans #include "/usr/src/lib/libc/i386/DEFS.h"	/* XXX blech */
129ab9678acSBruce Evans 
1306605d9f3SJordan K. Hubbard #ifndef RCSID
1316605d9f3SJordan K. Hubbard #define RCSID(a)
1326605d9f3SJordan K. Hubbard #endif
1336605d9f3SJordan K. Hubbard 
134ab9678acSBruce Evans #endif /* KERNEL */
135ab9678acSBruce Evans 
136ab9678acSBruce Evans #endif /* !_MACHINE_ASMACROS_H_ */
137