asm.h revision 1.31 1 /* $NetBSD: asm.h,v 1.31 2007/02/09 21:55:05 ad 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)asm.h 5.5 (Berkeley) 5/7/91
35 */
36
37 #ifndef _I386_ASM_H_
38 #define _I386_ASM_H_
39
40 #ifdef _KERNEL_OPT
41 #include "opt_multiprocessor.h"
42 #endif
43
44 #ifdef PIC
45 #define PIC_PROLOGUE \
46 pushl %ebx; \
47 call 1f; \
48 1: \
49 popl %ebx; \
50 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
51 #define PIC_EPILOGUE \
52 popl %ebx
53 #define PIC_PLT(x) x@PLT
54 #define PIC_GOT(x) x@GOT(%ebx)
55 #define PIC_GOTOFF(x) x@GOTOFF(%ebx)
56 #else
57 #define PIC_PROLOGUE
58 #define PIC_EPILOGUE
59 #define PIC_PLT(x) x
60 #define PIC_GOT(x) x
61 #define PIC_GOTOFF(x) x
62 #endif
63
64 #ifdef __ELF__
65 # define _C_LABEL(x) x
66 #else
67 # ifdef __STDC__
68 # define _C_LABEL(x) _ ## x
69 # else
70 # define _C_LABEL(x) _/**/x
71 # endif
72 #endif
73 #define _ASM_LABEL(x) x
74
75 #define CVAROFF(x, y) _C_LABEL(x) + y
76
77 #ifdef __STDC__
78 # define __CONCAT(x,y) x ## y
79 # define __STRING(x) #x
80 #else
81 # define __CONCAT(x,y) x/**/y
82 # define __STRING(x) "x"
83 #endif
84
85 /* let kernels and others override entrypoint alignment */
86 #if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
87 # ifdef __ELF__
88 # define _ALIGN_TEXT .align 4
89 # else
90 # define _ALIGN_TEXT .align 2
91 # endif
92 #endif
93
94 #define _ENTRY(x) \
95 .text; _ALIGN_TEXT; .globl x; .type x,@function; x:
96 #define _LABEL(x) \
97 .globl x; 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) \
111 ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
112 #else
113 #define IDTVEC(name) \
114 ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
115 #endif /* __STDC__ */
116 #else
117 #ifdef __STDC__
118 #define IDTVEC(name) \
119 ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name:
120 #else
121 #define IDTVEC(name) \
122 ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:
123 #endif /* __STDC__ */
124 #endif /* __ELF__ */
125
126 #ifdef __ELF__
127 #define ALIGN_DATA .align 4
128 #define ALIGN_TEXT .align 4,0x90 /* 4-byte boundaries, NOP-filled */
129 #define SUPERALIGN_TEXT .align 16,0x90 /* 16-byte boundaries better for 486 */
130 #else
131 #define ALIGN_DATA .align 2
132 #define ALIGN_TEXT .align 2,0x90 /* 4-byte boundaries, NOP-filled */
133 #define SUPERALIGN_TEXT .align 4,0x90 /* 16-byte boundaries better for 486 */
134 #endif /* __ELF__ */
135
136 #define _ALIGN_TEXT ALIGN_TEXT
137
138 #ifdef GPROF
139 #ifdef __ELF__
140 #define MCOUNT_ASM call _C_LABEL(__mcount)
141 #else /* __ELF__ */
142 #define MCOUNT_ASM call _C_LABEL(mcount)
143 #endif /* __ELF__ */
144 #else /* GPROF */
145 #define MCOUNT_ASM /* nothing */
146 #endif /* GPROF */
147
148 #endif /* _KERNEL */
149
150
151
152 #ifdef GPROF
153 # ifdef __ELF__
154 # define _PROF_PROLOGUE \
155 pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
156 # else
157 # define _PROF_PROLOGUE \
158 pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
159 # endif
160 #else
161 # define _PROF_PROLOGUE
162 #endif
163
164 #define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
165 #define NENTRY(y) _ENTRY(_C_LABEL(y))
166 #define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
167 #define LABEL(y) _LABEL(_C_LABEL(y))
168
169 #define ASMSTR .asciz
170
171 #ifdef __ELF__
172 #define RCSID(x) .section ".ident"; .asciz x
173 #else
174 #define RCSID(x) .text; .asciz x
175 #endif
176
177 #ifdef NO_KERNEL_RCSIDS
178 #define __KERNEL_RCSID(_n, _s) /* nothing */
179 #else
180 #define __KERNEL_RCSID(_n, _s) RCSID(_s)
181 #endif
182
183 #ifdef __ELF__
184 #define WEAK_ALIAS(alias,sym) \
185 .weak alias; \
186 alias = sym
187 #endif
188 /*
189 * STRONG_ALIAS: create a strong alias.
190 */
191 #define STRONG_ALIAS(alias,sym) \
192 .globl alias; \
193 alias = sym
194
195 #ifdef __STDC__
196 #define WARN_REFERENCES(sym,msg) \
197 .stabs msg ## ,30,0,0,0 ; \
198 .stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
199 #elif defined(__ELF__)
200 #define WARN_REFERENCES(sym,msg) \
201 .stabs msg,30,0,0,0 ; \
202 .stabs __STRING(sym),1,0,0,0
203 #else
204 #define WARN_REFERENCES(sym,msg) \
205 .stabs msg,30,0,0,0 ; \
206 .stabs __STRING(_/**/sym),1,0,0,0
207 #endif /* __STDC__ */
208
209 #endif /* !_I386_ASM_H_ */
210