blob: 5ccf78f13badeac45eda49514886eadc87a6cedf [file] [log] [blame]
Elliott Hughes7582a9c2013-02-06 17:08:15 -08001/* $NetBSD: asm.h,v 1.40 2011/06/16 13:16:20 joerg Exp $ */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08002
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
Elliott Hughes7582a9c2013-02-06 17:08:15 -080040#ifdef _KERNEL_OPT
41#include "opt_multiprocessor.h"
42#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080043
44#ifdef PIC
45#define PIC_PROLOGUE \
46 pushl %ebx; \
Elliott Hughes7582a9c2013-02-06 17:08:15 -080047 call 1f; \
481: \
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049 popl %ebx; \
Elliott Hughes7582a9c2013-02-06 17:08:15 -080050 addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080051#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
Elliott Hughes7582a9c2013-02-06 17:08:15 -080064#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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080073#define _ASM_LABEL(x) x
74
Elliott Hughes7582a9c2013-02-06 17:08:15 -080075#define CVAROFF(x, y) _C_LABEL(x) + y
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080076
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
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080085/* let kernels and others override entrypoint alignment */
Elliott Hughes7582a9c2013-02-06 17:08:15 -080086#if !defined(_ALIGN_TEXT) && !defined(_KERNEL)
87# ifdef _STANDALONE
88# define _ALIGN_TEXT .align 1
89# elif defined __ELF__
90# define _ALIGN_TEXT .align 16
91# else
92# define _ALIGN_TEXT .align 4
93# endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080094#endif
95
96#define _ENTRY(x) \
Christopher Ferris507cfe22013-11-19 13:45:27 -080097 .text; _ALIGN_TEXT; .globl x; .type x,@function; x: .cfi_startproc;
Elliott Hughes7582a9c2013-02-06 17:08:15 -080098#define _LABEL(x) \
99 .globl x; x:
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800100
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800101#ifdef _KERNEL
David 'Digit' Turner5fbf2e02012-01-23 15:15:30 +0100102
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800103#define CPUVAR(off) %fs:__CONCAT(CPU_INFO_,off)
104
105/* XXX Can't use __CONCAT() here, as it would be evaluated incorrectly. */
106#ifdef __ELF__
107#ifdef __STDC__
108#define IDTVEC(name) \
109 ALIGN_TEXT; .globl X ## name; .type X ## name,@function; X ## name:
110#define IDTVEC_END(name) \
111 .size X ## name, . - X ## name
112#else
113#define IDTVEC(name) \
114 ALIGN_TEXT; .globl X/**/name; .type X/**/name,@function; X/**/name:
115#define IDTVEC_END(name) \
116 .size X/**/name, . - X/**/name
117#endif /* __STDC__ */
118#else
119#ifdef __STDC__
120#define IDTVEC(name) \
121 ALIGN_TEXT; .globl _X ## name; .type _X ## name,@function; _X ## name:
122#define IDTVEC_END(name) \
123 .size _X ## name, . - _X ## name
124#else
125#define IDTVEC(name) \
126 ALIGN_TEXT; .globl _X/**/name; .type _X/**/name,@function; _X/**/name:
127#define IDTVEC_END(name) \
128 .size _X/**/name, . - _X/**/name
129#endif /* __STDC__ */
130#endif /* __ELF__ */
131
132#ifdef _STANDALONE
133#define ALIGN_DATA .align 4
134#define ALIGN_TEXT .align 4 /* 4-byte boundaries */
135#define SUPERALIGN_TEXT .align 16 /* 15-byte boundaries */
136#elif defined __ELF__
137#define ALIGN_DATA .align 4
138#define ALIGN_TEXT .align 16 /* 16-byte boundaries */
139#define SUPERALIGN_TEXT .align 16 /* 16-byte boundaries */
140#else
141#define ALIGN_DATA .align 2
142#define ALIGN_TEXT .align 4 /* 16-byte boundaries */
143#define SUPERALIGN_TEXT .align 4 /* 16-byte boundaries */
144#endif /* __ELF__ */
145
146#define _ALIGN_TEXT ALIGN_TEXT
David 'Digit' Turner5fbf2e02012-01-23 15:15:30 +0100147
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800148#ifdef GPROF
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800149#ifdef __ELF__
150#define MCOUNT_ASM call _C_LABEL(__mcount)
151#else /* __ELF__ */
152#define MCOUNT_ASM call _C_LABEL(mcount)
153#endif /* __ELF__ */
154#else /* GPROF */
155#define MCOUNT_ASM /* nothing */
156#endif /* GPROF */
157
158#endif /* _KERNEL */
159
160
161
162#ifdef GPROF
163# ifdef __ELF__
164# define _PROF_PROLOGUE \
165 pushl %ebp; movl %esp,%ebp; call PIC_PLT(__mcount); popl %ebp
166# else
167# define _PROF_PROLOGUE \
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800168 pushl %ebp; movl %esp,%ebp; call PIC_PLT(mcount); popl %ebp
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800169# endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800170#else
171# define _PROF_PROLOGUE
172#endif
173
174#define ENTRY(y) _ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
175#define NENTRY(y) _ENTRY(_C_LABEL(y))
176#define ASENTRY(y) _ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800177#define LABEL(y) _LABEL(_C_LABEL(y))
Christopher Ferris507cfe22013-11-19 13:45:27 -0800178#define END(y) .cfi_endproc; .size y, . - y
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800179
180#define ASMSTR .asciz
181
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800182#ifdef __ELF__
183#define RCSID(x) .pushsection ".ident"; .asciz x; .popsection
184#else
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800185#define RCSID(x) .text; .asciz x
Elliott Hughes7582a9c2013-02-06 17:08:15 -0800186#endif
187
188#ifdef NO_KERNEL_RCSIDS
189#define __KERNEL_RCSID(_n, _s) /* nothing */
190#else
191#define __KERNEL_RCSID(_n, _s) RCSID(_s)
192#endif
193
194#ifdef __ELF__
195#define WEAK_ALIAS(alias,sym) \
196 .weak alias; \
197 alias = sym
198#endif
199/*
200 * STRONG_ALIAS: create a strong alias.
201 */
202#define STRONG_ALIAS(alias,sym) \
203 .globl alias; \
204 alias = sym
205
206#ifdef __STDC__
207#define WARN_REFERENCES(sym,msg) \
208 .pushsection .gnu.warning. ## sym; \
209 .ascii msg; \
210 .popsection
211#else
212#define WARN_REFERENCES(sym,msg) \
213 .pushsection .gnu.warning./**/sym; \
214 .ascii msg; \
215 .popsection
216#endif /* __STDC__ */
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800217
218#endif /* !_I386_ASM_H_ */