xref: /freebsd/sys/arm/include/asm.h (revision cef367e6a15b6e3e2aca88d453c74962cf1f94e7)
16fc729afSOlivier Houchard /*	$NetBSD: asm.h,v 1.5 2003/08/07 16:26:53 agc Exp $	*/
26fc729afSOlivier Houchard 
3d8315c79SWarner Losh /*-
46fc729afSOlivier Houchard  * Copyright (c) 1990 The Regents of the University of California.
56fc729afSOlivier Houchard  * All rights reserved.
66fc729afSOlivier Houchard  *
76fc729afSOlivier Houchard  * This code is derived from software contributed to Berkeley by
86fc729afSOlivier Houchard  * William Jolitz.
96fc729afSOlivier Houchard  *
106fc729afSOlivier Houchard  * Redistribution and use in source and binary forms, with or without
116fc729afSOlivier Houchard  * modification, are permitted provided that the following conditions
126fc729afSOlivier Houchard  * are met:
136fc729afSOlivier Houchard  * 1. Redistributions of source code must retain the above copyright
146fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer.
156fc729afSOlivier Houchard  * 2. Redistributions in binary form must reproduce the above copyright
166fc729afSOlivier Houchard  *    notice, this list of conditions and the following disclaimer in the
176fc729afSOlivier Houchard  *    documentation and/or other materials provided with the distribution.
186fc729afSOlivier Houchard  * 3. Neither the name of the University nor the names of its contributors
196fc729afSOlivier Houchard  *    may be used to endorse or promote products derived from this software
206fc729afSOlivier Houchard  *    without specific prior written permission.
216fc729afSOlivier Houchard  *
226fc729afSOlivier Houchard  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
236fc729afSOlivier Houchard  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
246fc729afSOlivier Houchard  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
256fc729afSOlivier Houchard  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
266fc729afSOlivier Houchard  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
276fc729afSOlivier Houchard  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
286fc729afSOlivier Houchard  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
296fc729afSOlivier Houchard  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
306fc729afSOlivier Houchard  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
316fc729afSOlivier Houchard  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
326fc729afSOlivier Houchard  * SUCH DAMAGE.
336fc729afSOlivier Houchard  *
346fc729afSOlivier Houchard  *	from: @(#)asm.h	5.5 (Berkeley) 5/7/91
356fc729afSOlivier Houchard  *
366fc729afSOlivier Houchard  * $FreeBSD$
376fc729afSOlivier Houchard  */
386fc729afSOlivier Houchard 
396fc729afSOlivier Houchard #ifndef _MACHINE_ASM_H_
406fc729afSOlivier Houchard #define _MACHINE_ASM_H_
416fc729afSOlivier Houchard #include <sys/cdefs.h>
42efa8bab7SIan Lepore #include <machine/acle-compat.h>
43eb4585bcSIan Lepore #include <machine/sysreg.h>
446fc729afSOlivier Houchard 
456fc729afSOlivier Houchard #define	_C_LABEL(x)	x
466fc729afSOlivier Houchard #define	_ASM_LABEL(x)	x
476fc729afSOlivier Houchard 
486fc729afSOlivier Houchard #ifndef _ALIGN_TEXT
49301e1601SIan Lepore # define _ALIGN_TEXT .align 2
506fc729afSOlivier Houchard #endif
516fc729afSOlivier Houchard 
52ae160b23SAndrew Turner #ifndef _STANDALONE
53573447b6SAndrew Turner #define	STOP_UNWINDING	.cantunwind
54573447b6SAndrew Turner #define	_FNSTART	.fnstart
55573447b6SAndrew Turner #define	_FNEND		.fnend
56ba2f5f5eSRobert Watson #define	_SAVE(...)	.save __VA_ARGS__
57573447b6SAndrew Turner #else
58573447b6SAndrew Turner #define	STOP_UNWINDING
59573447b6SAndrew Turner #define	_FNSTART
60573447b6SAndrew Turner #define	_FNEND
61ba2f5f5eSRobert Watson #define	_SAVE(...)
62573447b6SAndrew Turner #endif
63573447b6SAndrew Turner 
646fc729afSOlivier Houchard /*
65de064ce4SIan Lepore  * gas/arm uses @ as a single comment character and thus cannot be used here.
66de064ce4SIan Lepore  * It recognises the # instead of an @ symbol in .type directives.
67de064ce4SIan Lepore  */
68de064ce4SIan Lepore #define	_ASM_TYPE_FUNCTION	#function
69de064ce4SIan Lepore #define	_ASM_TYPE_OBJECT	#object
70de064ce4SIan Lepore 
71de064ce4SIan Lepore /* XXX Is this still the right prologue for profiling? */
72de064ce4SIan Lepore #ifdef GPROF
73de064ce4SIan Lepore #define	_PROF_PROLOGUE	\
74de064ce4SIan Lepore 	mov ip, lr;	\
75de064ce4SIan Lepore 	bl __mcount
76de064ce4SIan Lepore #else
77de064ce4SIan Lepore #define	_PROF_PROLOGUE
78de064ce4SIan Lepore #endif
79de064ce4SIan Lepore 
80de064ce4SIan Lepore /*
8125166187SIan Lepore  * EENTRY()/EEND() mark "extra" entry/exit points from a function.
82*cef367e6SEitan Adler  * LEENTRY()/LEEND() are the same for local symbols.
8325166187SIan Lepore  * The unwind info cannot handle the concept of a nested function, or a function
8425166187SIan Lepore  * with multiple .fnstart directives, but some of our assembler code is written
8525166187SIan Lepore  * with multiple labels to allow entry at several points.  The EENTRY() macro
8625166187SIan Lepore  * defines such an extra entry point without a new .fnstart, so that it's
8725166187SIan Lepore  * basically just a label that you can jump to.  The EEND() macro does nothing
8825166187SIan Lepore  * at all, except document the exit point associated with the same-named entry.
8925166187SIan Lepore  */
9071442935SIan Lepore #define	GLOBAL(x)	.global x
9171442935SIan Lepore 
928465de8eSAndrew Turner #ifdef __thumb__
938465de8eSAndrew Turner #define	_FUNC_MODE	.code 16; .thumb_func
948465de8eSAndrew Turner #else
958465de8eSAndrew Turner #define	_FUNC_MODE	.code 32
968465de8eSAndrew Turner #endif
978465de8eSAndrew Turner 
988465de8eSAndrew Turner #define	_LEENTRY(x) 	.type x,_ASM_TYPE_FUNCTION; _FUNC_MODE; x:
99b05d247eSIan Lepore #define	_LEEND(x)	/* nothing */
100b05d247eSIan Lepore #define	_EENTRY(x) 	GLOBAL(x); _LEENTRY(x)
101b05d247eSIan Lepore #define	_EEND(x)	_LEEND(x)
10225166187SIan Lepore 
103b05d247eSIan Lepore #define	_LENTRY(x)	.text; _ALIGN_TEXT; _LEENTRY(x); _FNSTART
104b05d247eSIan Lepore #define	_LEND(x)	.size x, . - x; _FNEND
105b05d247eSIan Lepore #define	_ENTRY(x)	.text; _ALIGN_TEXT; _EENTRY(x); _FNSTART
106b05d247eSIan Lepore #define	_END(x)		_LEND(x)
107b643b934SAndrew Turner 
1086fc729afSOlivier Houchard #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
109be483be8SIan Lepore #define	EENTRY(y)	_EENTRY(_C_LABEL(y));
1106fc729afSOlivier Houchard #define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
11125166187SIan Lepore #define	EENTRY_NP(y)	_EENTRY(_C_LABEL(y))
1120a794529SAndrew Turner #define	END(y)		_END(_C_LABEL(y))
113be483be8SIan Lepore #define	EEND(y)		_EEND(_C_LABEL(y))
1146fc729afSOlivier Houchard #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
115b05d247eSIan Lepore #define	ASLENTRY(y)	_LENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
116be483be8SIan Lepore #define	ASEENTRY(y)	_EENTRY(_ASM_LABEL(y));
117b05d247eSIan Lepore #define	ASLEENTRY(y)	_LEENTRY(_ASM_LABEL(y));
1186fc729afSOlivier Houchard #define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
119b05d247eSIan Lepore #define	ASLENTRY_NP(y)	_LENTRY(_ASM_LABEL(y))
12025166187SIan Lepore #define	ASEENTRY_NP(y)	_EENTRY(_ASM_LABEL(y))
121b05d247eSIan Lepore #define	ASLEENTRY_NP(y)	_LEENTRY(_ASM_LABEL(y))
1220a794529SAndrew Turner #define	ASEND(y)	_END(_ASM_LABEL(y))
123b05d247eSIan Lepore #define	ASLEND(y)	_LEND(_ASM_LABEL(y))
124be483be8SIan Lepore #define	ASEEND(y)	_EEND(_ASM_LABEL(y))
125b05d247eSIan Lepore #define	ASLEEND(y)	_LEEND(_ASM_LABEL(y))
1266fc729afSOlivier Houchard 
1276fc729afSOlivier Houchard #define	ASMSTR		.asciz
1286fc729afSOlivier Houchard 
129294246bbSEd Maste #if defined(PIC)
1300a794529SAndrew Turner #define	PLT_SYM(x)	PIC_SYM(x, PLT)
1310a794529SAndrew Turner #define	GOT_SYM(x)	PIC_SYM(x, GOT)
1320a794529SAndrew Turner #define	GOT_GET(x,got,sym)	\
1330a794529SAndrew Turner 	ldr	x, sym;		\
1340a794529SAndrew Turner 	ldr	x, [x, got]
1350a794529SAndrew Turner #define	GOT_INIT(got,gotsym,pclabel) \
1360a794529SAndrew Turner 	ldr	got, gotsym;	\
137827422e3SAndrew Turner 	pclabel: add	got, pc
1387f9b314fSAndrew Turner #ifdef __thumb__
1390a794529SAndrew Turner #define	GOT_INITSYM(gotsym,pclabel) \
140301e1601SIan Lepore 	.align 2;		\
1417f9b314fSAndrew Turner 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4)
1427f9b314fSAndrew Turner #else
1437f9b314fSAndrew Turner #define	GOT_INITSYM(gotsym,pclabel) \
144301e1601SIan Lepore 	.align 2;		\
1457f9b314fSAndrew Turner 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8)
1467f9b314fSAndrew Turner #endif
1470a794529SAndrew Turner 
1486fc729afSOlivier Houchard #ifdef __STDC__
1496fc729afSOlivier Houchard #define	PIC_SYM(x,y)	x ## ( ## y ## )
1506fc729afSOlivier Houchard #else
1516fc729afSOlivier Houchard #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
1526fc729afSOlivier Houchard #endif
1530a794529SAndrew Turner 
1546fc729afSOlivier Houchard #else
1550a794529SAndrew Turner #define	PLT_SYM(x)	x
1560a794529SAndrew Turner #define	GOT_SYM(x)	x
1570a794529SAndrew Turner #define	GOT_GET(x,got,sym)	\
1580a794529SAndrew Turner 	ldr	x, sym;
1590a794529SAndrew Turner #define	GOT_INIT(got,gotsym,pclabel)
1600a794529SAndrew Turner #define	GOT_INITSYM(gotsym,pclabel)
1616fc729afSOlivier Houchard #define	PIC_SYM(x,y)	x
162294246bbSEd Maste #endif	/* PIC */
1636fc729afSOlivier Houchard 
1646fc729afSOlivier Houchard #undef __FBSDID
1656fc729afSOlivier Houchard #if !defined(lint) && !defined(STRIP_FBSDID)
1666fc729afSOlivier Houchard #define __FBSDID(s)     .ident s
1676fc729afSOlivier Houchard #else
1686fc729afSOlivier Houchard #define __FBSDID(s)     /* nothing */
1696fc729afSOlivier Houchard #endif
1706fc729afSOlivier Houchard 
1716fc729afSOlivier Houchard 
1726fc729afSOlivier Houchard #define	WEAK_ALIAS(alias,sym)						\
1736fc729afSOlivier Houchard 	.weak alias;							\
1746fc729afSOlivier Houchard 	alias = sym
1756fc729afSOlivier Houchard 
1766fc729afSOlivier Houchard #ifdef __STDC__
1776fc729afSOlivier Houchard #define	WARN_REFERENCES(sym,msg)					\
1786fc729afSOlivier Houchard 	.stabs msg ## ,30,0,0,0 ;					\
1796fc729afSOlivier Houchard 	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
1806fc729afSOlivier Houchard #else
1816fc729afSOlivier Houchard #define	WARN_REFERENCES(sym,msg)					\
1826fc729afSOlivier Houchard 	.stabs msg,30,0,0,0 ;						\
1830a794529SAndrew Turner 	.stabs __STRING(sym),1,0,0,0
1846fc729afSOlivier Houchard #endif /* __STDC__ */
1856fc729afSOlivier Houchard 
186cf1a573fSOleksandr Tymoshenko /* Exactly one of the __ARM_ARCH_*__ macros will be defined by the compiler. */
187cf1a573fSOleksandr Tymoshenko /* The _ARM_ARCH_* macros are deprecated and will be removed soon. */
188cf1a573fSOleksandr Tymoshenko /* This should be moved into another header so it can be used in
189cf1a573fSOleksandr Tymoshenko  * both asm and C code. machine/asm.h cannot be included in C code. */
190cf1a573fSOleksandr Tymoshenko #if defined (__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
191cf1a573fSOleksandr Tymoshenko #define _ARM_ARCH_7
192cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv7_INSTRUCTIONS 1
193cf1a573fSOleksandr Tymoshenko #endif
1945f2c6402SOlivier Houchard 
195cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv7_INSTRUCTIONS) || defined (__ARM_ARCH_6__) || \
196cf1a573fSOleksandr Tymoshenko 	defined (__ARM_ARCH_6J__) || defined (__ARM_ARCH_6K__) || \
197cf1a573fSOleksandr Tymoshenko 	defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__)
1985f2c6402SOlivier Houchard #define _ARM_ARCH_6
199cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv6_INSTRUCTIONS 1
2005f2c6402SOlivier Houchard #endif
2015f2c6402SOlivier Houchard 
202cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv6_INSTRUCTIONS) || defined (__ARM_ARCH_5TE__) || \
203258f866cSOlivier Houchard     defined (__ARM_ARCH_5TEJ__) || defined (__ARM_ARCH_5E__)
204258f866cSOlivier Houchard #define _ARM_ARCH_5E
205cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv5E_INSTRUCTIONS 1
206258f866cSOlivier Houchard #endif
207258f866cSOlivier Houchard 
208cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv5E_INSTRUCTIONS) || defined (__ARM_ARCH_5__) || \
209cf1a573fSOleksandr Tymoshenko     defined (__ARM_ARCH_5T__)
210cf1a573fSOleksandr Tymoshenko #define _ARM_ARCH_5
211cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv5_INSTRUCTIONS 1
212cf1a573fSOleksandr Tymoshenko #endif
213cf1a573fSOleksandr Tymoshenko 
214cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv5_INSTRUCTIONS) || defined (__ARM_ARCH_4T__)
2155f2c6402SOlivier Houchard #define _ARM_ARCH_4T
216cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv4T_INSTRUCTIONS 1
2175f2c6402SOlivier Houchard #endif
2185f2c6402SOlivier Houchard 
219cf1a573fSOleksandr Tymoshenko /* FreeBSD requires ARMv4, so this is always set. */
220cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv4_INSTRUCTIONS 1
2215f2c6402SOlivier Houchard 
222cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv4T_INSTRUCTIONS)
2235f2c6402SOlivier Houchard # define RET	bx	lr
2245f2c6402SOlivier Houchard # define RETeq	bxeq	lr
2255f2c6402SOlivier Houchard # define RETne	bxne	lr
2265f2c6402SOlivier Houchard # define RETc(c) bx##c	lr
2275f2c6402SOlivier Houchard #else
2285f2c6402SOlivier Houchard # define RET	mov	pc, lr
2295f2c6402SOlivier Houchard # define RETeq	moveq	pc, lr
2305f2c6402SOlivier Houchard # define RETne	movne	pc, lr
2315f2c6402SOlivier Houchard # define RETc(c) mov##c	pc, lr
2325f2c6402SOlivier Houchard #endif
2335f2c6402SOlivier Houchard 
234eb4585bcSIan Lepore #if __ARM_ARCH >= 7
235eb4585bcSIan Lepore #define ISB	isb
236eb4585bcSIan Lepore #define DSB	dsb
237eb4585bcSIan Lepore #define DMB	dmb
23854f9ec88SIan Lepore #define WFI	wfi
239eb4585bcSIan Lepore #elif __ARM_ARCH == 6
240eb4585bcSIan Lepore #define ISB	mcr CP15_CP15ISB
241eb4585bcSIan Lepore #define DSB	mcr CP15_CP15DSB
242eb4585bcSIan Lepore #define DMB	mcr CP15_CP15DMB
24354f9ec88SIan Lepore #define WFI	mcr CP15_CP15WFI
244eb4585bcSIan Lepore #else
245eb4585bcSIan Lepore #define ISB	mcr CP15_CP15ISB
246eb4585bcSIan Lepore #define DSB	mcr CP15_CP15DSB	/* DSB and DMB are the */
247eb4585bcSIan Lepore #define DMB	mcr CP15_CP15DSB	/* same prior to v6.*/
24854f9ec88SIan Lepore /* No form of WFI available on v4, define nothing to get an error on use. */
249eb4585bcSIan Lepore #endif
250eb4585bcSIan Lepore 
2516fc729afSOlivier Houchard #endif /* !_MACHINE_ASM_H_ */
252