xref: /netbsd-src/sys/arch/arm/include/asm.h (revision cac8e449158efc7261bebc8657cbb0125a2cfdde)
1 /*	$NetBSD: asm.h,v 1.11 2008/04/27 18:58:44 matt 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  *	from: @(#)asm.h	5.5 (Berkeley) 5/7/91
35  */
36 
37 #ifndef _ARM32_ASM_H_
38 #define _ARM32_ASM_H_
39 
40 #include <arm/cdefs.h>
41 
42 #ifdef __ELF__
43 # define _C_LABEL(x)	x
44 #else
45 # ifdef __STDC__
46 #  define _C_LABEL(x)	_ ## x
47 # else
48 #  define _C_LABEL(x)	_/**/x
49 # endif
50 #endif
51 #define	_ASM_LABEL(x)	x
52 
53 #ifdef __STDC__
54 # define __CONCAT(x,y)	x ## y
55 # define __STRING(x)	#x
56 #else
57 # define __CONCAT(x,y)	x/**/y
58 # define __STRING(x)	"x"
59 #endif
60 
61 #ifndef _ALIGN_TEXT
62 # define _ALIGN_TEXT .align 0
63 #endif
64 
65 /*
66  * gas/arm uses @ as a single comment character and thus cannot be used here
67  * Instead it recognised the # instead of an @ symbols in .type directives
68  * We define a couple of macros so that assembly code will not be dependant
69  * on one or the other.
70  */
71 #define _ASM_TYPE_FUNCTION	%function
72 #define _ASM_TYPE_OBJECT	%object
73 #ifdef __thumb__
74 #define _ENTRY(x) \
75 	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; .thumb_func; x:
76 #else
77 #define _ENTRY(x) \
78 	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:
79 #endif
80 #define	_END(x)		.size x,.-x
81 
82 #ifdef GPROF
83 # ifdef __ELF__
84 #  define _PROF_PROLOGUE	\
85 	mov ip, lr; bl __mcount
86 # else
87 #  define _PROF_PROLOGUE	\
88 	mov ip,lr; bl mcount
89 # endif
90 #else
91 # define _PROF_PROLOGUE
92 #endif
93 
94 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
95 #define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
96 #define	END(y)		_END(_C_LABEL(y))
97 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
98 #define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
99 #define	ASEND(y)	_END(_ASM_LABEL(y))
100 
101 #define	ASMSTR		.asciz
102 
103 #if defined(__ELF__) && defined(PIC)
104 #ifdef __thumb__
105 #define	PLT_SYM(x)	x
106 #define	GOT_SYM(x)	PIC_SYM(x, GOTOFF)
107 #define	GOT_GET(x,got,sym)	\
108 	ldr	x, sym;		\
109 	add	x, got;		\
110 	ldr	x, [x]
111 #else
112 #define	PLT_SYM(x)	PIC_SYM(x, PLT)
113 #define	GOT_SYM(x)	PIC_SYM(x, GOT)
114 #define	GOT_GET(x,got,sym)	\
115 	ldr	x, sym;		\
116 	ldr	x, [x, got]
117 #endif /* __thumb__ */
118 
119 #define	GOT_INIT(got,gotsym,pclabel) \
120 	ldr	got, gotsym;	\
121 	add	got, got, pc;	\
122 	pclabel:
123 #define	GOT_INITSYM(gotsym,pclabel) \
124 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) + (. - (pclabel+4))
125 
126 #ifdef __STDC__
127 #define	PIC_SYM(x,y)	x ## ( ## y ## )
128 #else
129 #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
130 #endif
131 
132 #else
133 #define	PLT_SYM(x)	x
134 #define	GOT_SYM(x)	x
135 #define	GOT_GET(x,got,sym)	\
136 	ldr	x, sym;
137 #define	GOT_INIT(got,gotsym,pclabel)
138 #define	GOT_INITSYM(gotsym,pclabel)
139 #define	PIC_SYM(x,y)	x
140 #endif	/* ELF && PIC */
141 
142 #ifdef __ELF__
143 #define RCSID(x)	.section ".ident"; .asciz x
144 #else
145 #define RCSID(x)	.text; .asciz x
146 #endif
147 
148 #ifdef __ELF__
149 #define	WEAK_ALIAS(alias,sym)						\
150 	.weak alias;							\
151 	alias = sym
152 #endif
153 
154 /*
155  * STRONG_ALIAS: create a strong alias.
156  */
157 #define STRONG_ALIAS(alias,sym)						\
158 	.globl alias;							\
159 	alias = sym
160 
161 #ifdef __STDC__
162 #define	WARN_REFERENCES(sym,msg)					\
163 	.stabs msg ## ,30,0,0,0 ;					\
164 	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
165 #elif defined(__ELF__)
166 #define	WARN_REFERENCES(sym,msg)					\
167 	.stabs msg,30,0,0,0 ;						\
168 	.stabs __STRING(sym),1,0,0,0
169 #else
170 #define	WARN_REFERENCES(sym,msg)					\
171 	.stabs msg,30,0,0,0 ;						\
172 	.stabs __STRING(_/**/sym),1,0,0,0
173 #endif /* __STDC__ */
174 
175 #ifdef __thumb__
176 # define XPUSH		push
177 # define XPOP		pop
178 # define XPOPRET	pop	{pc}
179 #else
180 # define XPUSH		stmfd	sp!,
181 # define XPOP		ldmfd	sp!,
182 # ifdef _ARM_ARCH_5
183 #  define XPOPRET	ldmfd	sp!, {pc}
184 # else
185 #  define XPOPRET	ldmfd	sp!, {lr}; mov pc, lr
186 # endif
187 #endif
188 
189 #if defined (_ARM_ARCH_4T)
190 # define RET		bx		lr
191 # define RETc(c)	__CONCAT(bx,c)	lr
192 #else
193 # define RET		mov		pc, lr
194 # define RETc(c)	__CONCAT(mov,c)	pc, lr
195 #endif
196 
197 #endif /* !_ARM_ASM_H_ */
198