xref: /netbsd/sys/arch/i386/include/asm.h (revision c4a72b64)
1 /*	$NetBSD: asm.h,v 1.22 2002/11/22 15:23:45 fvdl Exp $	*/
2 
3 /*-
4  * Copyright (c) 1990 The Regents of the University of California.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * William Jolitz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)asm.h	5.5 (Berkeley) 5/7/91
39  */
40 
41 #ifndef _I386_ASM_H_
42 #define _I386_ASM_H_
43 
44 #ifdef _KERNEL_OPT
45 #include "opt_multiprocessor.h"
46 #endif
47 
48 #ifdef PIC
49 #define PIC_PROLOGUE	\
50 	pushl	%ebx;	\
51 	call	1f;	\
52 1:			\
53 	popl	%ebx;	\
54 	addl	$_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
55 #define PIC_EPILOGUE	\
56 	popl	%ebx
57 #define PIC_PLT(x)	x@PLT
58 #define PIC_GOT(x)	x@GOT(%ebx)
59 #define PIC_GOTOFF(x)	x@GOTOFF(%ebx)
60 #else
61 #define PIC_PROLOGUE
62 #define PIC_EPILOGUE
63 #define PIC_PLT(x)	x
64 #define PIC_GOT(x)	x
65 #define PIC_GOTOFF(x)	x
66 #endif
67 
68 #ifdef __ELF__
69 # define _C_LABEL(x)	x
70 #else
71 # ifdef __STDC__
72 #  define _C_LABEL(x)	_ ## x
73 # else
74 #  define _C_LABEL(x)	_/**/x
75 # endif
76 #endif
77 #define	_ASM_LABEL(x)	x
78 
79 #ifdef __STDC__
80 # define __CONCAT(x,y)	x ## y
81 # define __STRING(x)	#x
82 #else
83 # define __CONCAT(x,y)	x/**/y
84 # define __STRING(x)	"x"
85 #endif
86 
87 /* let kernels and others override entrypoint alignment */
88 #if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
89 # ifdef __ELF__
90 #  define _ALIGN_TEXT .align 4
91 # else
92 #  define _ALIGN_TEXT .align 2
93 # endif
94 #endif
95 
96 #define _ENTRY(x) \
97 	.text; _ALIGN_TEXT; .globl x; .type x,@function; x:
98 
99 #ifdef _KERNEL
100 
101 #if defined(MULTIPROCESSOR)
102 #define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
103 #else
104 #define CPUVAR(off) _C_LABEL(cpu_info_primary)+__CONCAT(CPU_INFO_,off)
105 #endif /* MULTIPROCESSOR */
106 
107 /* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
108 #ifdef __ELF__
109 #ifdef __STDC__
110 #define	IDTVEC(name)	ALIGN_TEXT; .globl X ## name; X ## name:
111 #else
112 #define	IDTVEC(name)	ALIGN_TEXT; .globl X/**/name; X/**/name:
113 #endif /* __STDC__ */
114 #else
115 #ifdef __STDC__
116 #define	IDTVEC(name)	ALIGN_TEXT; .globl _X ## name; _X ## name:
117 #else
118 #define	IDTVEC(name)	ALIGN_TEXT; .globl _X/**/name; _X/**/name:
119 #endif /* __STDC__ */
120 #endif /* __ELF__ */
121 
122 #ifdef __ELF__
123 #define ALIGN_DATA	.align	4
124 #define ALIGN_TEXT	.align	4,0x90  /* 4-byte boundaries, NOP-filled */
125 #define SUPERALIGN_TEXT	.align	16,0x90 /* 16-byte boundaries better for 486 */
126 #else
127 #define ALIGN_DATA	.align	2
128 #define ALIGN_TEXT	.align	2,0x90  /* 4-byte boundaries, NOP-filled */
129 #define SUPERALIGN_TEXT	.align	4,0x90  /* 16-byte boundaries better for 486 */
130 #endif /* __ELF__ */
131 
132 #define _ALIGN_TEXT ALIGN_TEXT
133 
134 #endif /* _KERNEL */
135 
136 
137 
138 #ifdef GPROF
139 # ifdef __ELF__
140 #  define _PROF_PROLOGUE	\
141 	pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
142 # else
143 #  define _PROF_PROLOGUE	\
144 	pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
145 # endif
146 #else
147 # define _PROF_PROLOGUE
148 #endif
149 
150 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
151 #define	NENTRY(y)	_ENTRY(_C_LABEL(y))
152 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
153 
154 #define	ASMSTR		.asciz
155 
156 #ifdef __ELF__
157 #define RCSID(x)	.section ".ident"; .asciz x
158 #else
159 #define RCSID(x)	.text; .asciz x
160 #endif
161 
162 #ifdef NO_KERNEL_RCSIDS
163 #define	__KERNEL_RCSID(_n, _s)	/* nothing */
164 #else
165 #define	__KERNEL_RCSID(_n, _s)	RCSID(_s)
166 #endif
167 
168 #ifdef __ELF__
169 #define	WEAK_ALIAS(alias,sym)						\
170 	.weak alias;							\
171 	alias = sym
172 #endif
173 
174 #ifdef __STDC__
175 #define	WARN_REFERENCES(sym,msg)					\
176 	.stabs msg ## ,30,0,0,0 ;					\
177 	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
178 #elif defined(__ELF__)
179 #define	WARN_REFERENCES(sym,msg)					\
180 	.stabs msg,30,0,0,0 ;						\
181 	.stabs __STRING(sym),1,0,0,0
182 #else
183 #define	WARN_REFERENCES(sym,msg)					\
184 	.stabs msg,30,0,0,0 ;						\
185 	.stabs __STRING(_/**/sym),1,0,0,0
186 #endif /* __STDC__ */
187 
188 
189 
190 #endif /* !_I386_ASM_H_ */
191