xref: /freebsd/sys/i386/include/asm.h (revision 78599c32efed3247d165302a1fbe8d9203e38974)
1644ba7e8SBruce Evans /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4644ba7e8SBruce Evans  * Copyright (c) 1990 The Regents of the University of California.
5644ba7e8SBruce Evans  * All rights reserved.
6644ba7e8SBruce Evans  *
7644ba7e8SBruce Evans  * This code is derived from software contributed to Berkeley by
8644ba7e8SBruce Evans  * William Jolitz.
9644ba7e8SBruce Evans  *
10644ba7e8SBruce Evans  * Redistribution and use in source and binary forms, with or without
11644ba7e8SBruce Evans  * modification, are permitted provided that the following conditions
12644ba7e8SBruce Evans  * are met:
13644ba7e8SBruce Evans  * 1. Redistributions of source code must retain the above copyright
14644ba7e8SBruce Evans  *    notice, this list of conditions and the following disclaimer.
15644ba7e8SBruce Evans  * 2. Redistributions in binary form must reproduce the above copyright
16644ba7e8SBruce Evans  *    notice, this list of conditions and the following disclaimer in the
17644ba7e8SBruce Evans  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
19644ba7e8SBruce Evans  *    may be used to endorse or promote products derived from this software
20644ba7e8SBruce Evans  *    without specific prior written permission.
21644ba7e8SBruce Evans  *
22644ba7e8SBruce Evans  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23644ba7e8SBruce Evans  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24644ba7e8SBruce Evans  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25644ba7e8SBruce Evans  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26644ba7e8SBruce Evans  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27644ba7e8SBruce Evans  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28644ba7e8SBruce Evans  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29644ba7e8SBruce Evans  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30644ba7e8SBruce Evans  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31644ba7e8SBruce Evans  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32644ba7e8SBruce Evans  * SUCH DAMAGE.
33644ba7e8SBruce Evans  *
34644ba7e8SBruce Evans  *	from: @(#)DEFS.h	5.1 (Berkeley) 4/23/90
35c3aac50fSPeter Wemm  * $FreeBSD$
36644ba7e8SBruce Evans  */
37644ba7e8SBruce Evans 
38a8626855SBruce Evans #ifndef _MACHINE_ASM_H_
39a8626855SBruce Evans #define	_MACHINE_ASM_H_
40a8626855SBruce Evans 
41644ba7e8SBruce Evans #include <sys/cdefs.h>
42644ba7e8SBruce Evans 
43294246bbSEd Maste #ifdef PIC
44644ba7e8SBruce Evans #define	PIC_PROLOGUE	\
45644ba7e8SBruce Evans 	pushl	%ebx;	\
46644ba7e8SBruce Evans 	call	1f;	\
47644ba7e8SBruce Evans 1:			\
48644ba7e8SBruce Evans 	popl	%ebx;	\
49644ba7e8SBruce Evans 	addl	$_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx
50644ba7e8SBruce Evans #define	PIC_EPILOGUE	\
51644ba7e8SBruce Evans 	popl	%ebx
52644ba7e8SBruce Evans #define	PIC_PLT(x)	x@PLT
53644ba7e8SBruce Evans #define	PIC_GOT(x)	x@GOT(%ebx)
540f3a4d80SJilles Tjoelker #define	PIC_GOTOFF(x)	x@GOTOFF(%ebx)
55644ba7e8SBruce Evans #else
56644ba7e8SBruce Evans #define	PIC_PROLOGUE
57644ba7e8SBruce Evans #define	PIC_EPILOGUE
58644ba7e8SBruce Evans #define	PIC_PLT(x)	x
590f3a4d80SJilles Tjoelker #define	PIC_GOTOFF(x)	x
60644ba7e8SBruce Evans #endif
61644ba7e8SBruce Evans 
62644ba7e8SBruce Evans /*
63644ba7e8SBruce Evans  * CNAME and HIDENAME manage the relationship between symbol names in C
64644ba7e8SBruce Evans  * and the equivalent assembly language names.  CNAME is given a name as
65644ba7e8SBruce Evans  * it would be used in a C program.  It expands to the equivalent assembly
66644ba7e8SBruce Evans  * language name.  HIDENAME is given an assembly-language name, and expands
67644ba7e8SBruce Evans  * to a possibly-modified form that will be invisible to C programs.
68644ba7e8SBruce Evans  */
69644ba7e8SBruce Evans #define CNAME(csym)		csym
708d19a058SDavid E. O'Brien #define HIDENAME(asmsym)	.asmsym
71644ba7e8SBruce Evans 
72a8626855SBruce Evans /* XXX should use .p2align 4,0x90 for -m486. */
73a8626855SBruce Evans #define _START_ENTRY	.text; .p2align 2,0x90
74a8626855SBruce Evans 
75a8626855SBruce Evans #define _ENTRY(x)	_START_ENTRY; \
76*78599c32SConrad Meyer 			.globl CNAME(x); .type CNAME(x),@function; CNAME(x): \
77*78599c32SConrad Meyer 			.cfi_startproc
78*78599c32SConrad Meyer #define	END(x)		.cfi_endproc; .size x, . - x
79a8626855SBruce Evans 
80644ba7e8SBruce Evans #ifdef PROF
81be16a3abSBruce Evans #define	ALTENTRY(x)	_ENTRY(x); \
82*78599c32SConrad Meyer 			pushl %ebp; \
83*78599c32SConrad Meyer 			.cfi_def_cfa_offset 8; \
84*78599c32SConrad Meyer 			.cfi_offset %ebp, -8; \
85*78599c32SConrad Meyer 			movl %esp,%ebp; \
86a8626855SBruce Evans 			call PIC_PLT(HIDENAME(mcount)); \
87be16a3abSBruce Evans 			popl %ebp; \
88*78599c32SConrad Meyer 			.cfi_restore %ebp; \
89*78599c32SConrad Meyer 			.cfi_def_cfa_offset 4; \
90be16a3abSBruce Evans 			jmp 9f
91be16a3abSBruce Evans #define	ENTRY(x)	_ENTRY(x); \
92*78599c32SConrad Meyer 			pushl %ebp; \
93*78599c32SConrad Meyer 			.cfi_def_cfa_offset 8; \
94*78599c32SConrad Meyer 			.cfi_offset %ebp, -8; \
95*78599c32SConrad Meyer 			movl %esp,%ebp; \
96be16a3abSBruce Evans 			call PIC_PLT(HIDENAME(mcount)); \
97be16a3abSBruce Evans 			popl %ebp; \
98*78599c32SConrad Meyer 			.cfi_restore %ebp; \
99*78599c32SConrad Meyer 			.cfi_def_cfa_offset 4; \
100be16a3abSBruce Evans 			9:
101a8626855SBruce Evans #else
102ed253219SJason Evans #define	ALTENTRY(x)	_ENTRY(x)
103be16a3abSBruce Evans #define	ENTRY(x)	_ENTRY(x)
104644ba7e8SBruce Evans #endif
10513a44161SBruce Evans 
106766992d7SEd Schouten /*
107646c5b48SAndreas Tobler  * WEAK_REFERENCE(): create a weak reference alias from sym.
108646c5b48SAndreas Tobler  * The macro is not a general asm macro that takes arbitrary names,
109646c5b48SAndreas Tobler  * but one that takes only C names. It does the non-null name
110646c5b48SAndreas Tobler  * translation inside the macro.
11130b42655SEd Schouten  */
112646c5b48SAndreas Tobler 
113646c5b48SAndreas Tobler #define	WEAK_REFERENCE(sym, alias)					\
114646c5b48SAndreas Tobler 	.weak CNAME(alias);						\
115646c5b48SAndreas Tobler 	.equ CNAME(alias),CNAME(sym)
11630b42655SEd Schouten 
11730b42655SEd Schouten /*
118766992d7SEd Schouten  * STRONG_ALIAS: create a strong alias.
119766992d7SEd Schouten  */
120766992d7SEd Schouten #define	STRONG_ALIAS(alias,sym)						\
121766992d7SEd Schouten 	.globl alias;							\
122766992d7SEd Schouten 	alias = sym
123766992d7SEd Schouten 
124a8626855SBruce Evans #define RCSID(x)	.text; .asciz x
125a8626855SBruce Evans 
126439a4003SDavid E. O'Brien #undef __FBSDID
127383f241dSKonstantin Belousov #if !defined(STRIP_FBSDID)
128439a4003SDavid E. O'Brien #define __FBSDID(s)	.ident s
129439a4003SDavid E. O'Brien #else
130439a4003SDavid E. O'Brien #define __FBSDID(s)	/* nothing */
131383f241dSKonstantin Belousov #endif /* not STRIP_FBSDID */
132439a4003SDavid E. O'Brien 
133a8626855SBruce Evans #endif /* !_MACHINE_ASM_H_ */
134