Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.16.14.5
      1  1.16.14.5     tron /*	$NetBSD: asm.h,v 1.16.14.5 2006/01/11 13:54:13 tron 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.16.14.1     tron #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.16.14.1     tron #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.16.14.1     tron #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.16.14.1     tron #define	ENTRY(y)	_ENTRY(_C_LABEL(y)) _PROF_PROLOGUE
     91        1.1   itojun #define	NENTRY(y)	_ENTRY(_C_LABEL(y))
     92  1.16.14.1     tron #define	ASENTRY(y)	_ENTRY(_ASM_LABEL(y)) _PROF_PROLOGUE
     93        1.1   itojun 
     94  1.16.14.4     tron #define SET_ENTRY_SIZE(y) \
     95  1.16.14.4     tron 	.size	_C_LABEL(y), . - _C_LABEL(y)
     96  1.16.14.4     tron 
     97  1.16.14.4     tron #define SET_ASENTRY_SIZE(y) \
     98  1.16.14.4     tron 	.size	_ASM_LABEL(y), . - _ASM_LABEL(y)
     99  1.16.14.4     tron 
    100        1.7  msaitoh #ifdef __ELF__
    101  1.16.14.1     tron #define	ALTENTRY(name)				 \
    102  1.16.14.1     tron 	.globl _C_LABEL(name)			;\
    103  1.16.14.1     tron 	.type _C_LABEL(name),@function		;\
    104        1.1   itojun 	_C_LABEL(name):
    105        1.7  msaitoh #else
    106  1.16.14.1     tron #define	ALTENTRY(name)				 \
    107  1.16.14.1     tron 	.globl _C_LABEL(name)			;\
    108        1.7  msaitoh 	_C_LABEL(name):
    109        1.7  msaitoh #endif
    110        1.1   itojun 
    111  1.16.14.3     tron 
    112  1.16.14.3     tron /*
    113  1.16.14.3     tron  * Hide the gory details of PIC calls vs. normal calls.  Use as in the
    114  1.16.14.3     tron  * following example:
    115  1.16.14.3     tron  *
    116  1.16.14.3     tron  *	sts.l	pr, @-sp
    117  1.16.14.3     tron  *	PIC_PROLOGUE(.L_got, r0)	! saves old r12 on stack
    118  1.16.14.3     tron  *	...
    119  1.16.14.3     tron  *	mov.l	.L_function_1, r0
    120  1.16.14.3     tron  * 1:	CALL	r0			! each call site needs a label
    121  1.16.14.3     tron  *	 nop
    122  1.16.14.3     tron  *      ...
    123  1.16.14.3     tron  *	mov.l	.L_function_2, r0
    124  1.16.14.3     tron  * 2:	CALL	r0
    125  1.16.14.3     tron  *	 nop
    126  1.16.14.3     tron  *	...
    127  1.16.14.3     tron  *	PIC_EPILOGUE			! restores r12 from stack
    128  1.16.14.3     tron  *	lds.l	@sp+, pr		!  so call in right order
    129  1.16.14.3     tron  *	rts
    130  1.16.14.3     tron  *	 nop
    131  1.16.14.3     tron  *
    132  1.16.14.3     tron  *	.align 2
    133  1.16.14.3     tron  * .L_got:
    134  1.16.14.3     tron  *	PIC_GOT_DATUM
    135  1.16.14.3     tron  * .L_function_1:			! if you call the same function twice
    136  1.16.14.3     tron  *	CALL_DATUM(function, 1b)	!  provide call datum for each call
    137  1.16.14.3     tron  * .L_function_2:
    138  1.16.14.3     tron  * 	CALL_DATUM(function, 2b)
    139  1.16.14.3     tron  */
    140  1.16.14.3     tron 
    141  1.16.14.3     tron #ifdef PIC
    142  1.16.14.3     tron 
    143  1.16.14.3     tron #define	PIC_PLT(x)	x@PLT
    144  1.16.14.3     tron #define	PIC_GOT(x)	x@GOT
    145  1.16.14.3     tron #define	PIC_GOTOFF(x)	x@GOTOFF
    146  1.16.14.3     tron 
    147  1.16.14.5     tron #define	PIC_PROLOGUE(got)			\
    148  1.16.14.3     tron         	mov.l	r12, @-sp;		\
    149  1.16.14.3     tron         	mov.l	got, r12;		\
    150  1.16.14.5     tron         	mova	got, r0;		\
    151  1.16.14.5     tron         	add	r0, r12
    152  1.16.14.3     tron 
    153  1.16.14.3     tron #define	PIC_EPILOGUE				\
    154  1.16.14.3     tron 		mov.l	@sp+, r12
    155  1.16.14.3     tron 
    156  1.16.14.3     tron #define PIC_GOT_DATUM \
    157  1.16.14.3     tron 		.long	_GLOBAL_OFFSET_TABLE_
    158  1.16.14.3     tron 
    159  1.16.14.3     tron #define CALL	bsrf
    160  1.16.14.3     tron #define JUMP	braf
    161  1.16.14.3     tron 
    162  1.16.14.3     tron #define CALL_DATUM(function, lpcs) \
    163  1.16.14.3     tron 		.long	PIC_PLT(function) - ((lpcs) + 4 - (.))
    164  1.16.14.3     tron 
    165  1.16.14.3     tron /*
    166  1.16.14.3     tron  * This will result in text relocations in the shared library,
    167  1.16.14.3     tron  * unless the function is local or has hidden or protected visibility.
    168  1.16.14.3     tron  * Does not require PIC prologue.
    169  1.16.14.3     tron  */
    170  1.16.14.3     tron #define CALL_DATUM_LOCAL(function, lpcs) \
    171  1.16.14.3     tron 		.long	function - ((lpcs) + 4)
    172  1.16.14.3     tron 
    173  1.16.14.3     tron #else  /* !PIC */
    174  1.16.14.3     tron 
    175  1.16.14.5     tron #define	PIC_PROLOGUE(label)
    176  1.16.14.3     tron #define	PIC_EPILOGUE
    177  1.16.14.3     tron #define PIC_GOT_DATUM
    178  1.16.14.3     tron 
    179  1.16.14.3     tron #define CALL	jsr @
    180  1.16.14.3     tron #define JUMP	jmp @
    181  1.16.14.3     tron 
    182  1.16.14.3     tron #define CALL_DATUM(function, lpcs) \
    183  1.16.14.3     tron 		.long	function
    184  1.16.14.3     tron 
    185  1.16.14.3     tron #define CALL_DATUM_LOCAL(function, lpcs) \
    186  1.16.14.3     tron 		.long	function
    187  1.16.14.3     tron 
    188  1.16.14.3     tron #endif /* !PIC */
    189  1.16.14.3     tron 
    190  1.16.14.3     tron 
    191        1.1   itojun #define	ASMSTR		.asciz
    192        1.1   itojun 
    193       1.12      uwe #ifdef __ELF__
    194       1.12      uwe #define RCSID(x)	.section .ident; .asciz x; .previous
    195       1.12      uwe #else
    196       1.10      uch #define	RCSID(x)	.text; .asciz x
    197       1.16      uwe #endif
    198       1.16      uwe 
    199       1.16      uwe #ifdef NO_KERNEL_RCSIDS
    200       1.16      uwe #define	__KERNEL_RCSID(_n, _s)	/* nothing */
    201       1.16      uwe #else
    202       1.16      uwe #define	__KERNEL_RCSID(_n, _s)	RCSID(_s)
    203       1.12      uwe #endif
    204        1.2   kleink 
    205        1.2   kleink #ifdef __ELF__
    206        1.2   kleink #define	WEAK_ALIAS(alias,sym)						\
    207        1.3   marcus 	.weak _C_LABEL(alias);						\
    208        1.3   marcus 	_C_LABEL(alias) = _C_LABEL(sym)
    209        1.2   kleink #endif
    210        1.1   itojun 
    211  1.16.14.2     tron #define	WARN_REFERENCES(_sym,_msg)				\
    212  1.16.14.2     tron 	.section .gnu.warning._sym; .ascii _msg; .previous
    213        1.1   itojun 
    214        1.1   itojun #endif /* !_SH3_ASM_H_ */
    215