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