asm.h revision 1.24 1 /* $NetBSD: asm.h,v 1.24 2003/03/03 22:12:22 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 #define CVAROFF(x, y) _C_LABEL(x) + y
80
81 #ifdef __STDC__
82 # define __CONCAT(x,y) x ## y
83 # define __STRING(x) #x
84 #else
85 # define __CONCAT(x,y) x/**/y
86 # define __STRING(x) "x"
87 #endif
88
89 /* let kernels and others override entrypoint alignment */
90 #if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
91 # ifdef __ELF__
92 # define _ALIGN_TEXT .align 4
93 # else
94 # define _ALIGN_TEXT .align 2
95 # endif
96 #endif
97
98 #define _ENTRY(x) \
99 .text; _ALIGN_TEXT; .globl x; .type x,@function; x:
100
101 #ifdef _KERNEL
102
103 #if defined(MULTIPROCESSOR)
104 #define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
105 #else
106 #define CPUVAR(off) _C_LABEL(cpu_info_primary)+__CONCAT(CPU_INFO_,off)
107 #endif /* MULTIPROCESSOR */
108
109 /* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
110 #ifdef __ELF__
111 #ifdef __STDC__
112 #define IDTVEC(name) ALIGN_TEXT; .globl X ## name; X ## name:
113 #else
114 #define IDTVEC(name) ALIGN_TEXT; .globl X/**/name; X/**/name:
115 #endif /* __STDC__ */
116 #else
117 #ifdef __STDC__
118 #define IDTVEC(name) ALIGN_TEXT; .globl _X ## name; _X ## name:
119 #else
120 #define IDTVEC(name) ALIGN_TEXT; .globl _X/**/name; _X/**/name:
121 #endif /* __STDC__ */
122 #endif /* __ELF__ */
123
124 #ifdef __ELF__
125 #define ALIGN_DATA .align 4
126 #define ALIGN_TEXT .align 4,0x90 /* 4-byte boundaries, NOP-filled */
127 #define SUPERALIGN_TEXT .align 16,0x90 /* 16-byte boundaries better for 486 */
128 #else
129 #define ALIGN_DATA .align 2
130 #define ALIGN_TEXT .align 2,0x90 /* 4-byte boundaries, NOP-filled */
131 #define SUPERALIGN_TEXT .align 4,0x90 /* 16-byte boundaries better for 486 */
132 #endif /* __ELF__ */
133
134 #define _ALIGN_TEXT ALIGN_TEXT
135
136 #endif /* _KERNEL */
137
138
139
140 #ifdef GPROF
141 # ifdef __ELF__
142 # define _PROF_PROLOGUE \
143 pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
144 # else
145 # define _PROF_PROLOGUE \
146 pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
147 # endif
148 #else
149 # define _PROF_PROLOGUE
150 #endif
151
152 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
153 #define NENTRY(y) _ENTRY(_C_LABEL(y))
154 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
155
156 #define ASMSTR .asciz
157
158 #ifdef __ELF__
159 #define RCSID(x) .section ".ident"; .asciz x
160 #else
161 #define RCSID(x) .text; .asciz x
162 #endif
163
164 #ifdef NO_KERNEL_RCSIDS
165 #define __KERNEL_RCSID(_n, _s) /* nothing */
166 #else
167 #define __KERNEL_RCSID(_n, _s) RCSID(_s)
168 #endif
169
170 #ifdef __ELF__
171 #define WEAK_ALIAS(alias,sym) \
172 .weak alias; \
173 alias = sym
174 #endif
175
176 #ifdef __STDC__
177 #define WARN_REFERENCES(sym,msg) \
178 .stabs msg ## ,30,0,0,0 ; \
179 .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
180 #elif defined(__ELF__)
181 #define WARN_REFERENCES(sym,msg) \
182 .stabs msg,30,0,0,0 ; \
183 .stabs __STRING(sym),1,0,0,0
184 #else
185 #define WARN_REFERENCES(sym,msg) \
186 .stabs msg,30,0,0,0 ; \
187 .stabs __STRING(_/**/sym),1,0,0,0
188 #endif /* __STDC__ */
189
190
191
192 #endif /* !_I386_ASM_H_ */
193