Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.15
      1 /*	$NetBSD: asm.h,v 1.15 2012/08/29 22:25:05 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 #define	__BIT(n)	(1 << (n))
     43 
     44 #define _C_LABEL(x)	x
     45 #define	_ASM_LABEL(x)	x
     46 
     47 #ifdef __STDC__
     48 # define __CONCAT(x,y)	x ## y
     49 # define __STRING(x)	#x
     50 #else
     51 # define __CONCAT(x,y)	x/**/y
     52 # define __STRING(x)	"x"
     53 #endif
     54 
     55 #ifndef _ALIGN_TEXT
     56 # define _ALIGN_TEXT .align 0
     57 #endif
     58 
     59 /*
     60  * gas/arm uses @ as a single comment character and thus cannot be used here
     61  * Instead it recognised the # instead of an @ symbols in .type directives
     62  * We define a couple of macros so that assembly code will not be dependent
     63  * on one or the other.
     64  */
     65 #define _ASM_TYPE_FUNCTION	%function
     66 #define _ASM_TYPE_OBJECT	%object
     67 #ifdef __thumb__
     68 #define _ENTRY(x) \
     69 	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; .thumb_func; x:
     70 #else
     71 #define _ENTRY(x) \
     72 	.text; _ALIGN_TEXT; .globl x; .type x,_ASM_TYPE_FUNCTION; x:
     73 #endif
     74 #define	_END(x)		.size x,.-x
     75 
     76 #ifdef GPROF
     77 # define _PROF_PROLOGUE	\
     78 	mov ip, lr; bl __mcount
     79 #else
     80 # define _PROF_PROLOGUE
     81 #endif
     82 
     83 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)); _PROF_PROLOGUE
     84 #define	ENTRY_NP(y)	_ENTRY(_C_LABEL(y))
     85 #define	END(y)		_END(_C_LABEL(y))
     86 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)); _PROF_PROLOGUE
     87 #define	ASENTRY_NP(y)	_ENTRY(_ASM_LABEL(y))
     88 #define	ASEND(y)	_END(_ASM_LABEL(y))
     89 
     90 #define	ASMSTR		.asciz
     91 
     92 #if defined(PIC)
     93 #ifdef __thumb__
     94 #define	PLT_SYM(x)	x
     95 #define	GOT_SYM(x)	PIC_SYM(x, GOTOFF)
     96 #define	GOT_GET(x,got,sym)	\
     97 	ldr	x, sym;		\
     98 	add	x, got;		\
     99 	ldr	x, [x]
    100 #else
    101 #define	PLT_SYM(x)	PIC_SYM(x, PLT)
    102 #define	GOT_SYM(x)	PIC_SYM(x, GOT)
    103 #define	GOT_GET(x,got,sym)	\
    104 	ldr	x, sym;		\
    105 	ldr	x, [x, got]
    106 #endif /* __thumb__ */
    107 
    108 #define	GOT_INIT(got,gotsym,pclabel) \
    109 	ldr	got, gotsym;	\
    110 	add	got, got, pc;	\
    111 	pclabel:
    112 #define	GOT_INITSYM(gotsym,pclabel) \
    113 	gotsym: .word _C_LABEL(_GLOBAL_OFFSET_TABLE_) + (. - (pclabel+4))
    114 
    115 #ifdef __STDC__
    116 #define	PIC_SYM(x,y)	x ## ( ## y ## )
    117 #else
    118 #define	PIC_SYM(x,y)	x/**/(/**/y/**/)
    119 #endif
    120 
    121 #else
    122 #define	PLT_SYM(x)	x
    123 #define	GOT_SYM(x)	x
    124 #define	GOT_GET(x,got,sym)	\
    125 	ldr	x, sym;
    126 #define	GOT_INIT(got,gotsym,pclabel)
    127 #define	GOT_INITSYM(gotsym,pclabel)
    128 #define	PIC_SYM(x,y)	x
    129 #endif	/* PIC */
    130 
    131 #define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
    132 
    133 #define	WEAK_ALIAS(alias,sym)						\
    134 	.weak alias;							\
    135 	alias = sym
    136 
    137 /*
    138  * STRONG_ALIAS: create a strong alias.
    139  */
    140 #define STRONG_ALIAS(alias,sym)						\
    141 	.globl alias;							\
    142 	alias = sym
    143 
    144 #ifdef __STDC__
    145 #define	WARN_REFERENCES(sym,msg)					\
    146 	.pushsection .gnu.warning. ## sym;				\
    147 	.ascii msg;							\
    148 	.popsection
    149 #else
    150 #define	WARN_REFERENCES(sym,msg)					\
    151 	.pushsection .gnu.warning./**/sym;				\
    152 	.ascii msg;							\
    153 	.popsection
    154 #endif /* __STDC__ */
    155 
    156 #ifdef __thumb__
    157 # define XPUSH		push
    158 # define XPOP		pop
    159 # define XPOPRET	pop	{pc}
    160 #else
    161 # define XPUSH		stmfd	sp!,
    162 # define XPOP		ldmfd	sp!,
    163 # ifdef _ARM_ARCH_5
    164 #  define XPOPRET	ldmfd	sp!, {pc}
    165 # else
    166 #  define XPOPRET	ldmfd	sp!, {lr}; mov pc, lr
    167 # endif
    168 #endif
    169 
    170 #if defined (_ARM_ARCH_4T)
    171 # define RET		bx		lr
    172 # define RETc(c)	__CONCAT(bx,c)	lr
    173 #else
    174 # define RET		mov		pc, lr
    175 # define RETc(c)	__CONCAT(mov,c)	pc, lr
    176 #endif
    177 
    178 #endif /* !_ARM_ASM_H_ */
    179