Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.27.8.1
      1  1.27.8.1      yamt /*	$NetBSD: asm.h,v 1.27.8.1 2014/05/22 11:40:07 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.21       uwe #define SET_ENTRY_SIZE(y) \
     95      1.21       uwe 	.size	_C_LABEL(y), . - _C_LABEL(y)
     96      1.21       uwe 
     97      1.21       uwe #define SET_ASENTRY_SIZE(y) \
     98      1.21       uwe 	.size	_ASM_LABEL(y), . - _ASM_LABEL(y)
     99      1.21       uwe 
    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.20       uwe 
    112      1.20       uwe /*
    113      1.20       uwe  * Hide the gory details of PIC calls vs. normal calls.  Use as in the
    114      1.20       uwe  * following example:
    115      1.20       uwe  *
    116      1.20       uwe  *	sts.l	pr, @-sp
    117      1.20       uwe  *	PIC_PROLOGUE(.L_got, r0)	! saves old r12 on stack
    118      1.20       uwe  *	...
    119      1.20       uwe  *	mov.l	.L_function_1, r0
    120      1.20       uwe  * 1:	CALL	r0			! each call site needs a label
    121      1.20       uwe  *	 nop
    122      1.20       uwe  *      ...
    123      1.20       uwe  *	mov.l	.L_function_2, r0
    124      1.20       uwe  * 2:	CALL	r0
    125      1.20       uwe  *	 nop
    126      1.20       uwe  *	...
    127      1.20       uwe  *	PIC_EPILOGUE			! restores r12 from stack
    128      1.20       uwe  *	lds.l	@sp+, pr		!  so call in right order
    129      1.20       uwe  *	rts
    130      1.20       uwe  *	 nop
    131      1.20       uwe  *
    132      1.20       uwe  *	.align 2
    133      1.20       uwe  * .L_got:
    134      1.20       uwe  *	PIC_GOT_DATUM
    135      1.20       uwe  * .L_function_1:			! if you call the same function twice
    136      1.20       uwe  *	CALL_DATUM(function, 1b)	!  provide call datum for each call
    137      1.20       uwe  * .L_function_2:
    138      1.20       uwe  * 	CALL_DATUM(function, 2b)
    139      1.20       uwe  */
    140      1.20       uwe 
    141  1.27.8.1      yamt #ifdef __PIC__
    142      1.20       uwe 
    143      1.20       uwe #define	PIC_PLT(x)	x@PLT
    144      1.20       uwe #define	PIC_GOT(x)	x@GOT
    145      1.20       uwe #define	PIC_GOTOFF(x)	x@GOTOFF
    146      1.20       uwe 
    147      1.22       uwe #define	PIC_PROLOGUE(got)			\
    148      1.20       uwe         	mov.l	r12, @-sp;		\
    149      1.23       uwe 		PIC_PROLOGUE_NOSAVE(got)
    150      1.23       uwe 
    151      1.23       uwe /*
    152      1.23       uwe  * Functions that do non local jumps don't need to preserve r12,
    153      1.23       uwe  * so we can shave off two instructions to save/restore it.
    154      1.23       uwe  */
    155      1.23       uwe #define	PIC_PROLOGUE_NOSAVE(got)		\
    156      1.20       uwe         	mov.l	got, r12;		\
    157      1.22       uwe         	mova	got, r0;		\
    158      1.22       uwe         	add	r0, r12
    159      1.20       uwe 
    160      1.20       uwe #define	PIC_EPILOGUE				\
    161      1.20       uwe 		mov.l	@sp+, r12
    162      1.20       uwe 
    163      1.24       uwe #define PIC_EPILOGUE_SLOT 			\
    164      1.24       uwe 		PIC_EPILOGUE
    165      1.24       uwe 
    166      1.20       uwe #define PIC_GOT_DATUM \
    167      1.20       uwe 		.long	_GLOBAL_OFFSET_TABLE_
    168      1.20       uwe 
    169      1.20       uwe #define CALL	bsrf
    170      1.20       uwe #define JUMP	braf
    171      1.20       uwe 
    172      1.20       uwe #define CALL_DATUM(function, lpcs) \
    173      1.20       uwe 		.long	PIC_PLT(function) - ((lpcs) + 4 - (.))
    174      1.20       uwe 
    175      1.20       uwe /*
    176      1.20       uwe  * This will result in text relocations in the shared library,
    177      1.20       uwe  * unless the function is local or has hidden or protected visibility.
    178      1.20       uwe  * Does not require PIC prologue.
    179      1.20       uwe  */
    180      1.20       uwe #define CALL_DATUM_LOCAL(function, lpcs) \
    181      1.20       uwe 		.long	function - ((lpcs) + 4)
    182      1.20       uwe 
    183  1.27.8.1      yamt #else  /* !__PIC__ */
    184      1.20       uwe 
    185      1.22       uwe #define	PIC_PROLOGUE(label)
    186      1.23       uwe #define	PIC_PROLOGUE_NOSAVE(label)
    187      1.20       uwe #define	PIC_EPILOGUE
    188      1.24       uwe #define	PIC_EPILOGUE_SLOT	nop
    189      1.20       uwe #define PIC_GOT_DATUM
    190      1.20       uwe 
    191      1.20       uwe #define CALL	jsr @
    192      1.20       uwe #define JUMP	jmp @
    193      1.20       uwe 
    194      1.20       uwe #define CALL_DATUM(function, lpcs) \
    195      1.20       uwe 		.long	function
    196      1.20       uwe 
    197      1.20       uwe #define CALL_DATUM_LOCAL(function, lpcs) \
    198      1.20       uwe 		.long	function
    199      1.20       uwe 
    200  1.27.8.1      yamt #endif /* !__PIC__ */
    201      1.20       uwe 
    202      1.20       uwe 
    203       1.1    itojun #define	ASMSTR		.asciz
    204       1.1    itojun 
    205      1.12       uwe #ifdef __ELF__
    206      1.26       uwe #define RCSID(x)	.pushsection ".ident"; .asciz x; .popsection
    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.25  christos /*
    224      1.25  christos  * STRONG_ALIAS: create a strong alias.
    225      1.25  christos  */
    226      1.25  christos #define STRONG_ALIAS(alias,sym)						\
    227      1.25  christos 	.globl _C_LABEL(alias);						\
    228      1.25  christos 	_C_LABEL(alias) = _C_LABEL(sym)
    229      1.25  christos 
    230      1.27     joerg #ifdef __STDC__
    231      1.27     joerg #define	WARN_REFERENCES(sym,msg)					\
    232      1.27     joerg 	.pushsection .gnu.warning. ## sym;				\
    233      1.27     joerg 	.ascii msg;							\
    234      1.27     joerg 	.popsection
    235      1.27     joerg #else
    236      1.27     joerg #define	WARN_REFERENCES(sym,msg)					\
    237      1.27     joerg 	.pushsection .gnu.warning./**/sym;				\
    238      1.27     joerg 	.ascii msg;							\
    239      1.27     joerg 	.popsection
    240      1.27     joerg #endif /* __STDC__ */
    241       1.1    itojun 
    242       1.1    itojun #endif /* !_SH3_ASM_H_ */
    243