Home | History | Annotate | Download | only in machine
      1 /*	$OpenBSD: asm.h,v 1.1.1.1 2006/10/06 21:02:55 miod Exp $	*/
      2 /*	$NetBSD: asm.h,v 1.25 2006/01/20 22:02:40 christos Exp $	*/
      3 
      4 /*-
      5  * Copyright (c) 1990 The Regents of the University of California.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * William Jolitz.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)asm.h	5.5 (Berkeley) 5/7/91
     36  */
     37 
     38 #ifndef _SH_ASM_H_
     39 #define	_SH_ASM_H_
     40 
     41 #ifdef __ELF__
     42 # define _C_LABEL(x)	x
     43 #else
     44 #ifdef __STDC__
     45 # define _C_LABEL(x)	_ ## x
     46 #else
     47 # define _C_LABEL(x)	_/**/x
     48 #endif
     49 #endif
     50 #define	_ASM_LABEL(x)	x
     51 
     52 #ifdef __STDC__
     53 # define __CONCAT(x,y)	x ## y
     54 # define __STRING(x)	#x
     55 #else
     56 # define __CONCAT(x,y)	x/**/y
     57 # define __STRING(x)	"x"
     58 #endif
     59 
     60 /* let kernels and others override entrypoint alignment */
     61 #ifndef _ALIGN_TEXT
     62 # define _ALIGN_TEXT .align 2
     63 #endif
     64 
     65 #ifdef __ELF__
     66 #define	_ENTRY(x)							\
     67 	.text								;\
     68 	_ALIGN_TEXT							;\
     69 	.globl x							;\
     70 	.type x,@function						;\
     71 	x:
     72 #else /* !__ELF__ */
     73 #define	_ENTRY(x)							\
     74 	.text								;\
     75 	_ALIGN_TEXT							;\
     76 	.globl x							;\
     77 	x:
     78 #endif /* !__ELF__ */
     79 
     80 #ifdef GPROF
     81 #define	_PROF_PROLOGUE				  \
     82 	mov.l	1f,r1				; \
     83 	mova	2f,r0				; \
     84 	jmp	@r1				; \
     85 	 nop					; \
     86 	.align	2				; \
     87 1:	.long	__mcount			; \
     88 2:
     89 #else  /* !GPROF */
     90 #define	_PROF_PROLOGUE
     91 #endif /* !GPROF */
     92 
     93 #define	ENTRY(y)	_ENTRY(_C_LABEL(y)) _PROF_PROLOGUE
     94 #define	NENTRY(y)	_ENTRY(_C_LABEL(y))
     95 #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)) _PROF_PROLOGUE
     96 
     97 #define SET_ENTRY_SIZE(y) \
     98 	.size	_C_LABEL(y), . - _C_LABEL(y)
     99 
    100 #define SET_ASENTRY_SIZE(y) \
    101 	.size	_ASM_LABEL(y), . - _ASM_LABEL(y)
    102 
    103 #ifdef __ELF__
    104 #define	ALTENTRY(name)				 \
    105 	.globl _C_LABEL(name)			;\
    106 	.type _C_LABEL(name),@function		;\
    107 	_C_LABEL(name):
    108 #else
    109 #define	ALTENTRY(name)				 \
    110 	.globl _C_LABEL(name)			;\
    111 	_C_LABEL(name):
    112 #endif
    113 
    114 
    115 /*
    116  * Hide the gory details of PIC calls vs. normal calls.  Use as in the
    117  * following example:
    118  *
    119  *	sts.l	pr, @-sp
    120  *	PIC_PROLOGUE(.L_got, r0)	! saves old r12 on stack
    121  *	...
    122  *	mov.l	.L_function_1, r0
    123  * 1:	CALL	r0			! each call site needs a label
    124  *	 nop
    125  *      ...
    126  *	mov.l	.L_function_2, r0
    127  * 2:	CALL	r0
    128  *	 nop
    129  *	...
    130  *	PIC_EPILOGUE			! restores r12 from stack
    131  *	lds.l	@sp+, pr		!  so call in right order
    132  *	rts
    133  *	 nop
    134  *
    135  *	.align 2
    136  * .L_got:
    137  *	PIC_GOT_DATUM
    138  * .L_function_1:			! if you call the same function twice
    139  *	CALL_DATUM(function, 1b)	!  provide call datum for each call
    140  * .L_function_2:
    141  * 	CALL_DATUM(function, 2b)
    142  */
    143 
    144 #ifdef PIC
    145 
    146 #define	PIC_PLT(x)	x@PLT
    147 #define	PIC_GOT(x)	x@GOT
    148 #define	PIC_GOTOFF(x)	x@GOTOFF
    149 
    150 #define	PIC_PROLOGUE(got)			\
    151         	mov.l	r12, @-sp;		\
    152 		PIC_PROLOGUE_NOSAVE(got)
    153 
    154 /*
    155  * Functions that do non local jumps don't need to preserve r12,
    156  * so we can shave off two instructions to save/restore it.
    157  */
    158 #define	PIC_PROLOGUE_NOSAVE(got)		\
    159         	mov.l	got, r12;		\
    160         	mova	got, r0;		\
    161         	add	r0, r12
    162 
    163 #define	PIC_EPILOGUE				\
    164 		mov.l	@sp+, r12
    165 
    166 #define PIC_EPILOGUE_SLOT 			\
    167 		PIC_EPILOGUE
    168 
    169 #define PIC_GOT_DATUM \
    170 		.long	_GLOBAL_OFFSET_TABLE_
    171 
    172 #define CALL	bsrf
    173 #define JUMP	braf
    174 
    175 #define CALL_DATUM(function, lpcs) \
    176 		.long	PIC_PLT(function) - ((lpcs) + 4 - (.))
    177 
    178 /*
    179  * This will result in text relocations in the shared library,
    180  * unless the function is local or has hidden or protected visibility.
    181  * Does not require PIC prologue.
    182  */
    183 #define CALL_DATUM_LOCAL(function, lpcs) \
    184 		.long	function - ((lpcs) + 4)
    185 
    186 #else  /* !PIC */
    187 
    188 #define	PIC_PROLOGUE(label)
    189 #define	PIC_PROLOGUE_NOSAVE(label)
    190 #define	PIC_EPILOGUE
    191 #define	PIC_EPILOGUE_SLOT	nop
    192 #define PIC_GOT_DATUM
    193 
    194 #define CALL	jsr @
    195 #define JUMP	jmp @
    196 
    197 #define CALL_DATUM(function, lpcs) \
    198 		.long	function
    199 
    200 #define CALL_DATUM_LOCAL(function, lpcs) \
    201 		.long	function
    202 
    203 #endif /* !PIC */
    204 
    205 
    206 #define	ASMSTR		.asciz
    207 
    208 #ifdef __ELF__
    209 #define	WEAK_ALIAS(alias,sym)						\
    210 	.weak _C_LABEL(alias);						\
    211 	_C_LABEL(alias) = _C_LABEL(sym)
    212 #endif
    213 
    214 #define	WARN_REFERENCES(_sym,_msg)				\
    215 	.section .gnu.warning._sym; .ascii _msg; .previous
    216 
    217 #endif /* !_SH_ASM_H_ */
    218