Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.12.12.1
      1  1.12.12.1      matt /*	$NetBSD: asm.h,v 1.12.12.1 2014/02/15 16:18:36 matt Exp $	*/
      2        1.1     bjh21 
      3        1.1     bjh21 /*
      4        1.1     bjh21  * Copyright (c) 1990 The Regents of the University of California.
      5        1.1     bjh21  * All rights reserved.
      6        1.1     bjh21  *
      7        1.1     bjh21  * This code is derived from software contributed to Berkeley by
      8        1.1     bjh21  * William Jolitz.
      9        1.1     bjh21  *
     10        1.1     bjh21  * Redistribution and use in source and binary forms, with or without
     11        1.1     bjh21  * modification, are permitted provided that the following conditions
     12        1.1     bjh21  * are met:
     13        1.1     bjh21  * 1. Redistributions of source code must retain the above copyright
     14        1.1     bjh21  *    notice, this list of conditions and the following disclaimer.
     15        1.1     bjh21  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1     bjh21  *    notice, this list of conditions and the following disclaimer in the
     17        1.1     bjh21  *    documentation and/or other materials provided with the distribution.
     18        1.5       agc  * 3. Neither the name of the University nor the names of its contributors
     19        1.1     bjh21  *    may be used to endorse or promote products derived from this software
     20        1.1     bjh21  *    without specific prior written permission.
     21        1.1     bjh21  *
     22        1.1     bjh21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23        1.1     bjh21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24        1.1     bjh21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25        1.1     bjh21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26        1.1     bjh21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27        1.1     bjh21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28        1.1     bjh21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29        1.1     bjh21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30        1.1     bjh21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31        1.1     bjh21  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32        1.1     bjh21  * SUCH DAMAGE.
     33        1.1     bjh21  *
     34        1.1     bjh21  *	from: @(#)asm.h	5.5 (Berkeley) 5/7/91
     35        1.1     bjh21  */
     36        1.1     bjh21 
     37        1.1     bjh21 #ifndef _ARM32_ASM_H_
     38        1.1     bjh21 #define _ARM32_ASM_H_
     39        1.1     bjh21 
     40        1.9      matt #include <arm/cdefs.h>
     41        1.9      matt 
     42  1.12.12.1      matt 	/* .syntax		unified */
     43  1.12.12.1      matt 
     44  1.12.12.1      matt #ifdef __thumb__
     45  1.12.12.1      matt #define THUMB_INSN(n)	n
     46  1.12.12.1      matt #else
     47  1.12.12.1      matt #define THUMB_INSN(n)
     48  1.12.12.1      matt #endif
     49  1.12.12.1      matt 
     50  1.12.12.1      matt #define UPPER16(n)	(((n) >> 16) & 0xffff)
     51  1.12.12.1      matt #define LOWER16(n)	((n) & 0xffff)
     52  1.12.12.1      matt 
     53  1.12.12.1      matt #define	__BIT(n)	(1 << (n))
     54  1.12.12.1      matt #define __BITS(hi,lo)	((~((~0)<<((hi)+1)))&((~0)<<(lo)))
     55  1.12.12.1      matt 
     56       1.12      matt #define _C_LABEL(x)	x
     57        1.1     bjh21 #define	_ASM_LABEL(x)	x
     58        1.1     bjh21 
     59        1.1     bjh21 #ifdef __STDC__
     60        1.1     bjh21 # define __CONCAT(x,y)	x ## y
     61        1.1     bjh21 # define __STRING(x)	#x
     62        1.1     bjh21 #else
     63        1.1     bjh21 # define __CONCAT(x,y)	x/**/y
     64        1.1     bjh21 # define __STRING(x)	"x"
     65        1.1     bjh21 #endif
     66        1.1     bjh21 
     67        1.1     bjh21 #ifndef _ALIGN_TEXT
     68  1.12.12.1      matt # define _ALIGN_TEXT .align 2
     69        1.1     bjh21 #endif
     70        1.1     bjh21 
     71  1.12.12.1      matt #ifndef _TEXT_SECTION
     72  1.12.12.1      matt #define _TEXT_SECTION	.text
     73  1.12.12.1      matt #endif
     74        1.1     bjh21 /*
     75        1.1     bjh21  * gas/arm uses @ as a single comment character and thus cannot be used here
     76        1.1     bjh21  * Instead it recognised the # instead of an @ symbols in .type directives
     77  1.12.12.1      matt  * We define a couple of macros so that assembly code will not be dependent
     78        1.1     bjh21  * on one or the other.
     79        1.1     bjh21  */
     80        1.9      matt #define _ASM_TYPE_FUNCTION	%function
     81        1.9      matt #define _ASM_TYPE_OBJECT	%object
     82  1.12.12.1      matt #define _THUMB_ENTRY(x) \
     83  1.12.12.1      matt 	_TEXT_SECTION; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; \
     84  1.12.12.1      matt 	.thumb_func; .code 16; x:
     85  1.12.12.1      matt #define _ARM_ENTRY(x) \
     86  1.12.12.1      matt 	_TEXT_SECTION; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; \
     87  1.12.12.1      matt 	.code 32; x:
     88       1.11      matt #ifdef __thumb__
     89  1.12.12.1      matt #define	_ENTRY(x)	_THUMB_ENTRY(x)
     90       1.11      matt #else
     91  1.12.12.1      matt #define	_ENTRY(x)	_ARM_ENTRY(x)
     92       1.11      matt #endif
     93        1.9      matt #define	_END(x)		.size x,.-x
     94        1.1     bjh21 
     95        1.1     bjh21 #ifdef GPROF
     96       1.12      matt # define _PROF_PROLOGUE	\
     97        1.2     bjh21 	mov ip, lr; bl __mcount
     98        1.1     bjh21 #else
     99        1.1     bjh21 # define _PROF_PROLOGUE
    100        1.1     bjh21 #endif
    101        1.1     bjh21 
    102  1.12.12.1      matt #define	ENTRY(y)		_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
    103  1.12.12.1      matt #define	ENTRY_NP(y)		_ENTRY(_C_LABEL(y))
    104  1.12.12.1      matt #define	END(y)			_END(_C_LABEL(y))
    105  1.12.12.1      matt #define	ARM_ENTRY(y)		_ARM_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
    106  1.12.12.1      matt #define	ARM_ENTRY_NP(y)		_ARM_ENTRY(_C_LABEL(y))
    107  1.12.12.1      matt #define	THUMB_ENTRY(y)		_THUMB_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
    108  1.12.12.1      matt #define	THUMB_ENTRY_NP(y)	_THUMB_ENTRY(_C_LABEL(y))
    109  1.12.12.1      matt #define	END(y)			_END(_C_LABEL(y))
    110  1.12.12.1      matt #define	ASENTRY(y)		_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
    111  1.12.12.1      matt #define	ASENTRY_NP(y)		_ENTRY(_ASM_LABEL(y))
    112  1.12.12.1      matt #define	ASEND(y)		_END(_ASM_LABEL(y))
    113  1.12.12.1      matt #define	ARM_ASENTRY(y)		_ARM_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
    114  1.12.12.1      matt #define	ARM_ASENTRY_NP(y)	_ARM_ENTRY(_ASM_LABEL(y))
    115  1.12.12.1      matt #define	THUMB_ASENTRY(y)	_THUMB_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
    116  1.12.12.1      matt #define	THUMB_ASENTRY_NP(y)	_THUMB_ENTRY(_ASM_LABEL(y))
    117        1.1     bjh21 
    118        1.1     bjh21 #define	ASMSTR		.asciz
    119        1.3      matt 
    120  1.12.12.1      matt #ifdef __PIC__
    121  1.12.12.1      matt #define	REL_SYM(a, b)	((a) - (b))
    122       1.11      matt #define	PLT_SYM(x)	x
    123       1.11      matt #define	GOT_SYM(x)	PIC_SYM(x, GOT)
    124       1.11      matt #define	GOT_GET(x,got,sym)	\
    125       1.11      matt 	ldr	x, sym;		\
    126       1.11      matt 	ldr	x, [x, got]
    127       1.11      matt #define	GOT_INIT(got,gotsym,pclabel) \
    128       1.11      matt 	ldr	got, gotsym;	\
    129  1.12.12.1      matt 	pclabel: add	got, got, pc
    130  1.12.12.1      matt #ifdef __thumb__
    131  1.12.12.1      matt #define	GOT_INITSYM(gotsym,pclabel) \
    132  1.12.12.1      matt 	.align 0;		\
    133  1.12.12.1      matt 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+4)
    134  1.12.12.1      matt #else
    135       1.11      matt #define	GOT_INITSYM(gotsym,pclabel) \
    136  1.12.12.1      matt 	.align 0;		\
    137  1.12.12.1      matt 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) - (pclabel+8)
    138  1.12.12.1      matt #endif
    139       1.11      matt 
    140        1.4      matt #ifdef __STDC__
    141        1.4      matt #define	PIC_SYM(x,y)	x ## ( ## y ## )
    142        1.4      matt #else
    143        1.4      matt #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
    144        1.4      matt #endif
    145       1.11      matt 
    146        1.3      matt #else
    147  1.12.12.1      matt #define	REL_SYM(a, b)	(a)
    148       1.11      matt #define	PLT_SYM(x)	x
    149       1.11      matt #define	GOT_SYM(x)	x
    150       1.11      matt #define	GOT_GET(x,got,sym)	\
    151       1.11      matt 	ldr	x, sym;
    152       1.11      matt #define	GOT_INIT(got,gotsym,pclabel)
    153       1.11      matt #define	GOT_INITSYM(gotsym,pclabel)
    154        1.4      matt #define	PIC_SYM(x,y)	x
    155  1.12.12.1      matt #endif	/* __PIC__ */
    156        1.1     bjh21 
    157       1.12      matt #define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
    158        1.1     bjh21 
    159        1.1     bjh21 #define	WEAK_ALIAS(alias,sym)						\
    160        1.1     bjh21 	.weak alias;							\
    161        1.1     bjh21 	alias = sym
    162        1.1     bjh21 
    163        1.8  christos /*
    164        1.8  christos  * STRONG_ALIAS: create a strong alias.
    165        1.8  christos  */
    166        1.8  christos #define STRONG_ALIAS(alias,sym)						\
    167        1.8  christos 	.globl alias;							\
    168        1.8  christos 	alias = sym
    169        1.8  christos 
    170  1.12.12.1      matt #ifdef __STDC__
    171  1.12.12.1      matt #define	WARN_REFERENCES(sym,msg)					\
    172  1.12.12.1      matt 	.pushsection .gnu.warning. ## sym;				\
    173  1.12.12.1      matt 	.ascii msg;							\
    174  1.12.12.1      matt 	.popsection
    175  1.12.12.1      matt #else
    176        1.1     bjh21 #define	WARN_REFERENCES(sym,msg)					\
    177  1.12.12.1      matt 	.pushsection .gnu.warning./**/sym;				\
    178  1.12.12.1      matt 	.ascii msg;							\
    179  1.12.12.1      matt 	.popsection
    180  1.12.12.1      matt #endif /* __STDC__ */
    181        1.1     bjh21 
    182       1.11      matt #ifdef __thumb__
    183       1.11      matt # define XPUSH		push
    184       1.11      matt # define XPOP		pop
    185       1.11      matt # define XPOPRET	pop	{pc}
    186       1.11      matt #else
    187       1.11      matt # define XPUSH		stmfd	sp!,
    188       1.11      matt # define XPOP		ldmfd	sp!,
    189       1.11      matt # ifdef _ARM_ARCH_5
    190       1.11      matt #  define XPOPRET	ldmfd	sp!, {pc}
    191       1.11      matt # else
    192       1.11      matt #  define XPOPRET	ldmfd	sp!, {lr}; mov pc, lr
    193       1.11      matt # endif
    194        1.6  rearnsha #endif
    195       1.11      matt 
    196        1.6  rearnsha #if defined (_ARM_ARCH_4T)
    197       1.11      matt # define RET		bx		lr
    198  1.12.12.1      matt # define RETr(r)	bx		r
    199  1.12.12.1      matt # if defined(__thumb__)
    200  1.12.12.1      matt #  if defined(_ARM_ARCH_7)
    201  1.12.12.1      matt #   define RETc(c)	it c; __CONCAT(bx,c)	lr
    202  1.12.12.1      matt #  endif
    203  1.12.12.1      matt # else
    204  1.12.12.1      matt #  define RETc(c)	__CONCAT(bx,c)	lr
    205  1.12.12.1      matt # endif
    206        1.6  rearnsha #else
    207       1.11      matt # define RET		mov		pc, lr
    208  1.12.12.1      matt # define RETr(r)	mov		pc, r
    209       1.11      matt # define RETc(c)	__CONCAT(mov,c)	pc, lr
    210        1.6  rearnsha #endif
    211        1.6  rearnsha 
    212  1.12.12.1      matt #ifdef _ARM_ARCH_7
    213  1.12.12.1      matt #define KMODTRAMPOLINE(n)			\
    214  1.12.12.1      matt _ENTRY(__wrap_ ## n)				\
    215  1.12.12.1      matt 	movw	ip, #:lower16:n;	\
    216  1.12.12.1      matt 	movt	ip, #:upper16:n;	\
    217  1.12.12.1      matt 	bx	ip
    218  1.12.12.1      matt #elif defined(_ARM_ARCH_4T)
    219  1.12.12.1      matt #define KMODTRAMPOLINE(n)	\
    220  1.12.12.1      matt _ENTRY(__wrap_ ## n)		\
    221  1.12.12.1      matt 	ldr	ip, [pc];	\
    222  1.12.12.1      matt 	bx	ip;		\
    223  1.12.12.1      matt 	.word	n
    224  1.12.12.1      matt #else
    225  1.12.12.1      matt #define KMODTRAMPOLINE(n)	\
    226  1.12.12.1      matt _ENTRY(__wrap_ ## n)		\
    227  1.12.12.1      matt 	ldr	pc, [pc, #-4];	\
    228  1.12.12.1      matt 	.word	n
    229  1.12.12.1      matt #endif
    230  1.12.12.1      matt 
    231  1.12.12.1      matt .macro	lsls	a,b,c
    232  1.12.12.1      matt 	movs	\a, \b, lsl \c
    233  1.12.12.1      matt .endm
    234  1.12.12.1      matt .macro	lsl	a,b,c
    235  1.12.12.1      matt 	mov	\a, \b, lsl \c
    236  1.12.12.1      matt .endm
    237  1.12.12.1      matt .macro	lsrs	a,b,c
    238  1.12.12.1      matt 	movs	\a, \b, lsr \c
    239  1.12.12.1      matt .endm
    240  1.12.12.1      matt .macro	lsr	a,b,c
    241  1.12.12.1      matt 	mov	\a, \b, lsr \c
    242  1.12.12.1      matt .endm
    243  1.12.12.1      matt .macro	negs	a,b
    244  1.12.12.1      matt 	rsbs	\a, \b, #0
    245  1.12.12.1      matt .endm
    246  1.12.12.1      matt .macro	neg	a,b
    247  1.12.12.1      matt 	rsb	\a, \b, #0
    248  1.12.12.1      matt .endm
    249  1.12.12.1      matt .macro	ldrd	a,b,c,d
    250  1.12.12.1      matt 	ldrald	\a, \c, \d
    251  1.12.12.1      matt .endm
    252  1.12.12.1      matt .macro	strd	a,b,c,d
    253  1.12.12.1      matt 	strald	\a, \c, \d
    254  1.12.12.1      matt .endm
    255  1.12.12.1      matt #define	strbge	strgeb
    256  1.12.12.1      matt #define	strbgt	strgtb
    257  1.12.12.1      matt #define	ldrbge	ldrgeb
    258  1.12.12.1      matt #define	ldrbgt	ldrgtb
    259  1.12.12.1      matt #define ldmdbeq	ldmeqdb
    260  1.12.12.1      matt #define ldrtne	ldrnet
    261  1.12.12.1      matt #define ldrtge	ldrget
    262  1.12.12.1      matt #define ldrtgt	ldrgtt
    263  1.12.12.1      matt #define ldrbtge	ldrgebt
    264  1.12.12.1      matt #define ldrbtgt	ldrgtbt
    265  1.12.12.1      matt #define strtge	strget
    266  1.12.12.1      matt #define strtne	strnet
    267  1.12.12.1      matt #define strbtge	strgebt
    268  1.12.12.1      matt #define strbtgt	strgtbt
    269  1.12.12.1      matt 
    270        1.1     bjh21 #endif /* !_ARM_ASM_H_ */
    271