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