xref: /freebsd/sys/arm/include/asm.h (revision b643b9341c4eb33930d92cfd36ddeaef2f1df824)
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>
426fc729afSOlivier Houchard 
436fc729afSOlivier Houchard #define	_C_LABEL(x)	x
446fc729afSOlivier Houchard #define	_ASM_LABEL(x)	x
456fc729afSOlivier Houchard 
466fc729afSOlivier Houchard #ifndef _ALIGN_TEXT
476fc729afSOlivier Houchard # define _ALIGN_TEXT .align 0
486fc729afSOlivier Houchard #endif
496fc729afSOlivier Houchard 
5015668837SIan Lepore #if defined(__ARM_EABI__) && !defined(_STANDALONE)
51573447b6SAndrew Turner #define	STOP_UNWINDING	.cantunwind
52573447b6SAndrew Turner #define	_FNSTART	.fnstart
53573447b6SAndrew Turner #define	_FNEND		.fnend
54573447b6SAndrew Turner #else
55573447b6SAndrew Turner #define	STOP_UNWINDING
56573447b6SAndrew Turner #define	_FNSTART
57573447b6SAndrew Turner #define	_FNEND
58573447b6SAndrew Turner #endif
59573447b6SAndrew Turner 
606fc729afSOlivier Houchard /*
6125166187SIan Lepore  * EENTRY()/EEND() mark "extra" entry/exit points from a function.
6225166187SIan Lepore  * The unwind info cannot handle the concept of a nested function, or a function
6325166187SIan Lepore  * with multiple .fnstart directives, but some of our assembler code is written
6425166187SIan Lepore  * with multiple labels to allow entry at several points.  The EENTRY() macro
6525166187SIan Lepore  * defines such an extra entry point without a new .fnstart, so that it's
6625166187SIan Lepore  * basically just a label that you can jump to.  The EEND() macro does nothing
6725166187SIan Lepore  * at all, except document the exit point associated with the same-named entry.
6825166187SIan Lepore  */
6925166187SIan Lepore #define	_EENTRY(x) 	.globl x; .type x,_ASM_TYPE_FUNCTION; x:
7025166187SIan Lepore #define	_EEND(x)	/* nothing */
7125166187SIan Lepore 
72*b643b934SAndrew Turner /*
73*b643b934SAndrew Turner  * gas/arm uses @ as a single comment character and thus cannot be used here
74*b643b934SAndrew Turner  * Instead it recognised the # instead of an @ symbols in .type directives
75*b643b934SAndrew Turner  * We define a couple of macros so that assembly code will not be dependent
76*b643b934SAndrew Turner  * on one or the other.
77*b643b934SAndrew Turner  */
78*b643b934SAndrew Turner #define _ASM_TYPE_FUNCTION	#function
79*b643b934SAndrew Turner #define _ASM_TYPE_OBJECT	#object
80*b643b934SAndrew Turner #define GLOBAL(X) .globl x
81*b643b934SAndrew Turner #define	_ENTRY(x) \
82*b643b934SAndrew Turner 	.text; _ALIGN_TEXT; _EENTRY(x) _FNSTART
83*b643b934SAndrew Turner #define	_END(x)	.size x, . - x; _FNEND
84*b643b934SAndrew Turner 
856fc729afSOlivier Houchard #ifdef GPROF
866fc729afSOlivier Houchard #  define _PROF_PROLOGUE	\
87705fda84SOlivier Houchard 	mov ip, lr; bl __mcount
886fc729afSOlivier Houchard #else
896fc729afSOlivier Houchard # define _PROF_PROLOGUE
906fc729afSOlivier Houchard #endif
916fc729afSOlivier Houchard 
926fc729afSOlivier Houchard #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
9325166187SIan Lepore #define	EENTRY(y)	_EENTRY(_C_LABEL(y)); _PROF_PROLOGUE
946fc729afSOlivier Houchard #define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
9525166187SIan Lepore #define	EENTRY_NP(y)	_EENTRY(_C_LABEL(y))
960a794529SAndrew Turner #define	END(y)		_END(_C_LABEL(y))
9725166187SIan Lepore #define	EEND(y)
986fc729afSOlivier Houchard #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
9925166187SIan Lepore #define	ASEENTRY(y)	_EENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
1006fc729afSOlivier Houchard #define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
10125166187SIan Lepore #define	ASEENTRY_NP(y)	_EENTRY(_ASM_LABEL(y))
1020a794529SAndrew Turner #define	ASEND(y)	_END(_ASM_LABEL(y))
10325166187SIan Lepore #define	ASEEND(y)
1046fc729afSOlivier Houchard 
1056fc729afSOlivier Houchard #define	ASMSTR		.asciz
1066fc729afSOlivier Houchard 
107294246bbSEd Maste #if defined(PIC)
1080a794529SAndrew Turner #define	PLT_SYM(x)	PIC_SYM(x, PLT)
1090a794529SAndrew Turner #define	GOT_SYM(x)	PIC_SYM(x, GOT)
1100a794529SAndrew Turner #define	GOT_GET(x,got,sym)	\
1110a794529SAndrew Turner 	ldr	x, sym;		\
1120a794529SAndrew Turner 	ldr	x, [x, got]
1130a794529SAndrew Turner #define	GOT_INIT(got,gotsym,pclabel) \
1140a794529SAndrew Turner 	ldr	got, gotsym;	\
1150a794529SAndrew Turner 	add	got, got, pc;	\
1160a794529SAndrew Turner 	pclabel:
1170a794529SAndrew Turner #define	GOT_INITSYM(gotsym,pclabel) \
1180a794529SAndrew Turner 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) + (. - (pclabel+4))
1190a794529SAndrew Turner 
1206fc729afSOlivier Houchard #ifdef __STDC__
1216fc729afSOlivier Houchard #define	PIC_SYM(x,y)	x ## ( ## y ## )
1226fc729afSOlivier Houchard #else
1236fc729afSOlivier Houchard #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
1246fc729afSOlivier Houchard #endif
1250a794529SAndrew Turner 
1266fc729afSOlivier Houchard #else
1270a794529SAndrew Turner #define	PLT_SYM(x)	x
1280a794529SAndrew Turner #define	GOT_SYM(x)	x
1290a794529SAndrew Turner #define	GOT_GET(x,got,sym)	\
1300a794529SAndrew Turner 	ldr	x, sym;
1310a794529SAndrew Turner #define	GOT_INIT(got,gotsym,pclabel)
1320a794529SAndrew Turner #define	GOT_INITSYM(gotsym,pclabel)
1336fc729afSOlivier Houchard #define	PIC_SYM(x,y)	x
134294246bbSEd Maste #endif	/* PIC */
1356fc729afSOlivier Houchard 
1366fc729afSOlivier Houchard #undef __FBSDID
1376fc729afSOlivier Houchard #if !defined(lint) && !defined(STRIP_FBSDID)
1386fc729afSOlivier Houchard #define __FBSDID(s)     .ident s
1396fc729afSOlivier Houchard #else
1406fc729afSOlivier Houchard #define __FBSDID(s)     /* nothing */
1416fc729afSOlivier Houchard #endif
1426fc729afSOlivier Houchard 
1436fc729afSOlivier Houchard 
1446fc729afSOlivier Houchard #define	WEAK_ALIAS(alias,sym)						\
1456fc729afSOlivier Houchard 	.weak alias;							\
1466fc729afSOlivier Houchard 	alias = sym
1476fc729afSOlivier Houchard 
1486fc729afSOlivier Houchard #ifdef __STDC__
1496fc729afSOlivier Houchard #define	WARN_REFERENCES(sym,msg)					\
1506fc729afSOlivier Houchard 	.stabs msg ## ,30,0,0,0 ;					\
1516fc729afSOlivier Houchard 	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
1526fc729afSOlivier Houchard #else
1536fc729afSOlivier Houchard #define	WARN_REFERENCES(sym,msg)					\
1546fc729afSOlivier Houchard 	.stabs msg,30,0,0,0 ;						\
1550a794529SAndrew Turner 	.stabs __STRING(sym),1,0,0,0
1566fc729afSOlivier Houchard #endif /* __STDC__ */
1576fc729afSOlivier Houchard 
158cf1a573fSOleksandr Tymoshenko /* Exactly one of the __ARM_ARCH_*__ macros will be defined by the compiler. */
159cf1a573fSOleksandr Tymoshenko /* The _ARM_ARCH_* macros are deprecated and will be removed soon. */
160cf1a573fSOleksandr Tymoshenko /* This should be moved into another header so it can be used in
161cf1a573fSOleksandr Tymoshenko  * both asm and C code. machine/asm.h cannot be included in C code. */
162cf1a573fSOleksandr Tymoshenko #if defined (__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
163cf1a573fSOleksandr Tymoshenko #define _ARM_ARCH_7
164cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv7_INSTRUCTIONS 1
165cf1a573fSOleksandr Tymoshenko #endif
1665f2c6402SOlivier Houchard 
167cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv7_INSTRUCTIONS) || defined (__ARM_ARCH_6__) || \
168cf1a573fSOleksandr Tymoshenko 	defined (__ARM_ARCH_6J__) || defined (__ARM_ARCH_6K__) || \
169cf1a573fSOleksandr Tymoshenko 	defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__)
1705f2c6402SOlivier Houchard #define _ARM_ARCH_6
171cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv6_INSTRUCTIONS 1
1725f2c6402SOlivier Houchard #endif
1735f2c6402SOlivier Houchard 
174cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv6_INSTRUCTIONS) || defined (__ARM_ARCH_5TE__) || \
175258f866cSOlivier Houchard     defined (__ARM_ARCH_5TEJ__) || defined (__ARM_ARCH_5E__)
176258f866cSOlivier Houchard #define _ARM_ARCH_5E
177cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv5E_INSTRUCTIONS 1
178258f866cSOlivier Houchard #endif
179258f866cSOlivier Houchard 
180cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv5E_INSTRUCTIONS) || defined (__ARM_ARCH_5__) || \
181cf1a573fSOleksandr Tymoshenko     defined (__ARM_ARCH_5T__)
182cf1a573fSOleksandr Tymoshenko #define _ARM_ARCH_5
183cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv5_INSTRUCTIONS 1
184cf1a573fSOleksandr Tymoshenko #endif
185cf1a573fSOleksandr Tymoshenko 
186cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv5_INSTRUCTIONS) || defined (__ARM_ARCH_4T__)
1875f2c6402SOlivier Houchard #define _ARM_ARCH_4T
188cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv4T_INSTRUCTIONS 1
1895f2c6402SOlivier Houchard #endif
1905f2c6402SOlivier Houchard 
191cf1a573fSOleksandr Tymoshenko /* FreeBSD requires ARMv4, so this is always set. */
192cf1a573fSOleksandr Tymoshenko #define _HAVE_ARMv4_INSTRUCTIONS 1
1935f2c6402SOlivier Houchard 
194cf1a573fSOleksandr Tymoshenko #if defined (_HAVE_ARMv4T_INSTRUCTIONS)
1955f2c6402SOlivier Houchard # define RET	bx	lr
1965f2c6402SOlivier Houchard # define RETeq	bxeq	lr
1975f2c6402SOlivier Houchard # define RETne	bxne	lr
1985f2c6402SOlivier Houchard # define RETc(c) bx##c	lr
1995f2c6402SOlivier Houchard #else
2005f2c6402SOlivier Houchard # define RET	mov	pc, lr
2015f2c6402SOlivier Houchard # define RETeq	moveq	pc, lr
2025f2c6402SOlivier Houchard # define RETne	movne	pc, lr
2035f2c6402SOlivier Houchard # define RETc(c) mov##c	pc, lr
2045f2c6402SOlivier Houchard #endif
2055f2c6402SOlivier Houchard 
2066fc729afSOlivier Houchard #endif /* !_MACHINE_ASM_H_ */
207