asm.h revision 248361
1129198Scognet/*	$NetBSD: asm.h,v 1.5 2003/08/07 16:26:53 agc Exp $	*/
2129198Scognet
3139735Simp/*-
4129198Scognet * Copyright (c) 1990 The Regents of the University of California.
5129198Scognet * All rights reserved.
6129198Scognet *
7129198Scognet * This code is derived from software contributed to Berkeley by
8129198Scognet * William Jolitz.
9129198Scognet *
10129198Scognet * Redistribution and use in source and binary forms, with or without
11129198Scognet * modification, are permitted provided that the following conditions
12129198Scognet * are met:
13129198Scognet * 1. Redistributions of source code must retain the above copyright
14129198Scognet *    notice, this list of conditions and the following disclaimer.
15129198Scognet * 2. Redistributions in binary form must reproduce the above copyright
16129198Scognet *    notice, this list of conditions and the following disclaimer in the
17129198Scognet *    documentation and/or other materials provided with the distribution.
18129198Scognet * 3. Neither the name of the University nor the names of its contributors
19129198Scognet *    may be used to endorse or promote products derived from this software
20129198Scognet *    without specific prior written permission.
21129198Scognet *
22129198Scognet * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23129198Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24129198Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25129198Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26129198Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27129198Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28129198Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29129198Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30129198Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31129198Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32129198Scognet * SUCH DAMAGE.
33129198Scognet *
34129198Scognet *	from: @(#)asm.h	5.5 (Berkeley) 5/7/91
35129198Scognet *
36129198Scognet * $FreeBSD: head/sys/arm/include/asm.h 248361 2013-03-16 02:48:49Z andrew $
37129198Scognet */
38129198Scognet
39129198Scognet#ifndef _MACHINE_ASM_H_
40129198Scognet#define _MACHINE_ASM_H_
41129198Scognet#include <sys/cdefs.h>
42129198Scognet
43129198Scognet#ifdef __ELF__
44129198Scognet# define _C_LABEL(x)	x
45129198Scognet#else
46129198Scognet# ifdef __STDC__
47129198Scognet#  define _C_LABEL(x)	_ ## x
48129198Scognet# else
49129198Scognet#  define _C_LABEL(x)	_/**/x
50129198Scognet# endif
51129198Scognet#endif
52129198Scognet#define	_ASM_LABEL(x)	x
53129198Scognet
54129198Scognet#ifndef _JB_MAGIC__SETJMP
55129198Scognet#define _JB_MAGIC__SETJMP       0x4278f500
56129198Scognet#define _JB_MAGIC_SETJMP        0x4278f501
57129198Scognet#endif
58129198Scognet
59129198Scognet#define I32_bit (1 << 7)	/* IRQ disable */
60129198Scognet#define F32_bit (1 << 6)        /* FIQ disable */
61129198Scognet
62129198Scognet#define CPU_CONTROL_32BP_ENABLE 0x00000010 /* P: 32-bit exception handlers */
63129198Scognet#define CPU_CONTROL_32BD_ENABLE 0x00000020 /* D: 32-bit addressing */
64129198Scognet
65129198Scognet#ifndef _ALIGN_TEXT
66129198Scognet# define _ALIGN_TEXT .align 0
67129198Scognet#endif
68129198Scognet
69248361Sandrew#ifdef __ARM_EABI__
70248361Sandrew#define	STOP_UNWINDING	.cantunwind
71248361Sandrew#define	_FNSTART	.fnstart
72248361Sandrew#define	_FNEND		.fnend
73248361Sandrew#else
74248361Sandrew#define	STOP_UNWINDING
75248361Sandrew#define	_FNSTART
76248361Sandrew#define	_FNEND
77248361Sandrew#endif
78248361Sandrew
79129198Scognet/*
80129198Scognet * gas/arm uses @ as a single comment character and thus cannot be used here
81129198Scognet * Instead it recognised the # instead of an @ symbols in .type directives
82129198Scognet * We define a couple of macros so that assembly code will not be dependant
83129198Scognet * on one or the other.
84129198Scognet */
85129198Scognet#define _ASM_TYPE_FUNCTION	#function
86129198Scognet#define _ASM_TYPE_OBJECT	#object
87129198Scognet#define GLOBAL(X) .globl x
88129198Scognet#define _ENTRY(x) \
89248361Sandrew	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x: _FNSTART
90129198Scognet
91248361Sandrew#define	END(x)	.size x, . - x; _FNEND
92248361Sandrew
93129198Scognet#ifdef GPROF
94129198Scognet#  define _PROF_PROLOGUE	\
95169768Scognet	mov ip, lr; bl __mcount
96129198Scognet#else
97129198Scognet# define _PROF_PROLOGUE
98129198Scognet#endif
99129198Scognet
100129198Scognet#define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
101129198Scognet#define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
102129198Scognet#define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
103129198Scognet#define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
104129198Scognet
105129198Scognet#define	ASMSTR		.asciz
106129198Scognet
107129198Scognet#if defined(__ELF__) && defined(PIC)
108129198Scognet#ifdef __STDC__
109129198Scognet#define	PIC_SYM(x,y)	x ## ( ## y ## )
110129198Scognet#else
111129198Scognet#define	PIC_SYM(x,y)	x/**/(/**/y/**/)
112129198Scognet#endif
113129198Scognet#else
114129198Scognet#define	PIC_SYM(x,y)	x
115129198Scognet#endif
116129198Scognet
117129198Scognet#undef __FBSDID
118129198Scognet#if !defined(lint) && !defined(STRIP_FBSDID)
119129198Scognet#define __FBSDID(s)     .ident s
120129198Scognet#else
121129198Scognet#define __FBSDID(s)     /* nothing */
122129198Scognet#endif
123129198Scognet
124129198Scognet
125129198Scognet#ifdef __ELF__
126129198Scognet#define	WEAK_ALIAS(alias,sym)						\
127129198Scognet	.weak alias;							\
128129198Scognet	alias = sym
129129198Scognet#endif
130129198Scognet
131129198Scognet#ifdef __STDC__
132129198Scognet#define	WARN_REFERENCES(sym,msg)					\
133129198Scognet	.stabs msg ## ,30,0,0,0 ;					\
134129198Scognet	.stabs __STRING(_C_LABEL(sym)) ## ,1,0,0,0
135129198Scognet#elif defined(__ELF__)
136129198Scognet#define	WARN_REFERENCES(sym,msg)					\
137129198Scognet	.stabs msg,30,0,0,0 ;						\
138129198Scognet	.stabs __STRING(sym),1,0,0,0
139129198Scognet#else
140129198Scognet#define	WARN_REFERENCES(sym,msg)					\
141129198Scognet	.stabs msg,30,0,0,0 ;						\
142129198Scognet	.stabs __STRING(_/**/sym),1,0,0,0
143129198Scognet#endif /* __STDC__ */
144129198Scognet
145239268Sgonzo/* Exactly one of the __ARM_ARCH_*__ macros will be defined by the compiler. */
146239268Sgonzo/* The _ARM_ARCH_* macros are deprecated and will be removed soon. */
147239268Sgonzo/* This should be moved into another header so it can be used in
148239268Sgonzo * both asm and C code. machine/asm.h cannot be included in C code. */
149239268Sgonzo#if defined (__ARM_ARCH_7__) || defined (__ARM_ARCH_7A__)
150239268Sgonzo#define _ARM_ARCH_7
151239268Sgonzo#define _HAVE_ARMv7_INSTRUCTIONS 1
152239268Sgonzo#endif
153137462Scognet
154239268Sgonzo#if defined (_HAVE_ARMv7_INSTRUCTIONS) || defined (__ARM_ARCH_6__) || \
155239268Sgonzo	defined (__ARM_ARCH_6J__) || defined (__ARM_ARCH_6K__) || \
156239268Sgonzo	defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__)
157137462Scognet#define _ARM_ARCH_6
158239268Sgonzo#define _HAVE_ARMv6_INSTRUCTIONS 1
159137462Scognet#endif
160137462Scognet
161239268Sgonzo#if defined (_HAVE_ARMv6_INSTRUCTIONS) || defined (__ARM_ARCH_5TE__) || \
162172613Scognet    defined (__ARM_ARCH_5TEJ__) || defined (__ARM_ARCH_5E__)
163239268Sgonzo#define _ARM_ARCH_5E
164239268Sgonzo#define _HAVE_ARMv5E_INSTRUCTIONS 1
165137462Scognet#endif
166137462Scognet
167239268Sgonzo#if defined (_HAVE_ARMv5E_INSTRUCTIONS) || defined (__ARM_ARCH_5__) || \
168239268Sgonzo    defined (__ARM_ARCH_5T__)
169239268Sgonzo#define _ARM_ARCH_5
170239268Sgonzo#define _HAVE_ARMv5_INSTRUCTIONS 1
171172613Scognet#endif
172172613Scognet
173239268Sgonzo#if defined (_HAVE_ARMv5_INSTRUCTIONS) || defined (__ARM_ARCH_4T__)
174137462Scognet#define _ARM_ARCH_4T
175239268Sgonzo#define _HAVE_ARMv4T_INSTRUCTIONS 1
176137462Scognet#endif
177137462Scognet
178239268Sgonzo/* FreeBSD requires ARMv4, so this is always set. */
179239268Sgonzo#define _HAVE_ARMv4_INSTRUCTIONS 1
180137462Scognet
181239268Sgonzo#if defined (_HAVE_ARMv4T_INSTRUCTIONS)
182137462Scognet# define RET	bx	lr
183137462Scognet# define RETeq	bxeq	lr
184137462Scognet# define RETne	bxne	lr
185239268Sgonzo# define RETc(c) bx##c	lr
186137462Scognet#else
187137462Scognet# define RET	mov	pc, lr
188137462Scognet# define RETeq	moveq	pc, lr
189137462Scognet# define RETne	movne	pc, lr
190239268Sgonzo# define RETc(c) mov##c	pc, lr
191137462Scognet#endif
192137462Scognet
193129198Scognet#endif /* !_MACHINE_ASM_H_ */
194