Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.36
      1 /*	$NetBSD: asm.h,v 1.36 2025/01/04 19:17:58 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Copyright (c) 1994 Allen Briggs
     34  * All rights reserved.
     35  *
     36  * Gleaned from locore.s and sun3 asm.h which had the following copyrights:
     37  * locore.s:
     38  * Copyright (c) 1988 University of Utah.
     39  * Copyright (c) 1982, 1990 The Regents of the University of California.
     40  * sun3/include/asm.h:
     41  * Copyright (c) 1993 Adam Glass
     42  * Copyright (c) 1990 The Regents of the University of California.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions and the following disclaimer.
     49  * 2. Redistributions in binary form must reproduce the above copyright
     50  *    notice, this list of conditions and the following disclaimer in the
     51  *    documentation and/or other materials provided with the distribution.
     52  * 3. All advertising materials mentioning features or use of this software
     53  *    must display the following acknowledgement:
     54  *	This product includes software developed by the University of
     55  *	California, Berkeley and its contributors.
     56  * 4. Neither the name of the University nor the names of its contributors
     57  *    may be used to endorse or promote products derived from this software
     58  *    without specific prior written permission.
     59  *
     60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70  * SUCH DAMAGE.
     71  */
     72 
     73 #ifndef _M68K_ASM_H_
     74 #define _M68K_ASM_H_
     75 
     76 #define __IMMEDIATE		#
     77 
     78 #ifdef __PIC__
     79 #define PIC_PLT(name)		name@PLTPC
     80 #ifdef __mcoldfire__
     81 #define LEA_LCL(name,reg) \
     82 	movl	__IMMEDIATE name - .,reg ; \
     83 	lea	(-6,%pc,reg),reg
     84 #define GOT_SETUP(reg) \
     85 	movl	__IMMEDIATE _GLOBAL_OFFSET_TABLE_@GOTPC,reg ; \
     86 	lea	(-6,%pc,reg),reg
     87 #else
     88 #define LEA_LCL(name,reg)	lea	(name,%pc),reg
     89 #define GOT_SETUP(reg)		lea	(_GLOBAL_OFFSET_TABLE_@GOTPC,%pc),reg
     90 #endif
     91 #else
     92 #define PIC_PLT(name)		name
     93 #define LEA_LCL(name,reg)	movl	__IMMEDIATE name,reg
     94 #define GOT_SETUP(reg)		/* nothing */
     95 #endif
     96 
     97 #if __STDC__
     98 # define _C_LABEL(name)	name
     99 #else
    100 # define _C_LABEL(name)	name
    101 #endif /* __STDC__ */
    102 
    103 #define	_ASM_LABEL(name)	name
    104 
    105 #define	_ENTRY(name) \
    106 	.text; .even; .globl name; .type name,@function; name:
    107 #define	END(name)	.size name,.-name
    108 
    109 #define	MCOUNT_ENTRY	__mcount
    110 
    111 #ifdef GPROF
    112 #define _PROF_PROLOG	link %a6,#0; jbsr MCOUNT_ENTRY; unlk %a6
    113 #else
    114 #define _PROF_PROLOG
    115 #endif
    116 
    117 #define ENTRY(name)		_ENTRY(_C_LABEL(name)) _PROF_PROLOG
    118 #define	ASENTRY(name)		_ENTRY(_ASM_LABEL(name)) _PROF_PROLOG
    119 
    120 #define	ENTRY_NOPROFILE(name)	_ENTRY(_C_LABEL(name))
    121 #define	ASENTRY_NOPROFILE(name)	_ENTRY(_ASM_LABEL(name))
    122 
    123 /*
    124  * The m68k ALTENTRY macro is very different than the traditional
    125  * implementation used by other NetBSD ports.  Usually ALTENTRY
    126  * simply provides an alternate function entry point.  The m68k
    127  * definition takes a second argument and jumps inside the second
    128  * function when profiling is enabled.
    129  *
    130  * The m68k behavior is similar to the ENTRY2 macro found in
    131  * solaris' asm_linkage.h.
    132  *
    133  * Providing ENTRY2 and changing all the code that uses ALTENTRY
    134  * to use it would be a desirable change.
    135  */
    136 #ifdef PROF
    137 #define ALTENTRY(name, rname)	ENTRY(name); jra rname+12
    138 #else
    139 #define ALTENTRY(name, rname)	_ENTRY(_C_LABEL(name))
    140 #endif
    141 
    142 #ifdef _NETBSD_REVISIONID
    143 #define RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
    144 			.asciz "$" "NetBSD: " __FILE__ 			\
    145 			    " " _NETBSD_REVISIONID " $";		\
    146 			.popsection
    147 #else
    148 #define RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
    149 			.asciz x;					\
    150 			.popsection
    151 #endif
    152 
    153 /*
    154  * Global variables of whatever sort.
    155  */
    156 #define	GLOBAL(x)					\
    157 		.globl	_C_LABEL(x)		;	\
    158 	_C_LABEL(x):
    159 
    160 #define	ASGLOBAL(x)					\
    161 		.globl	_ASM_LABEL(x)		;	\
    162 	_ASM_LABEL(x):
    163 
    164 /*
    165  * ...and local variables.
    166  */
    167 #define	LOCAL(x)					\
    168 	_C_LABEL(x):
    169 
    170 #define	ASLOCAL(x)					\
    171 	_ASM_LABEL(x):
    172 
    173 /*
    174  * Items in the BSS segment.
    175  */
    176 #define	BSS(name, size)					\
    177 	.comm	_C_LABEL(name),size
    178 
    179 #define	ASBSS(name, size)				\
    180 	.comm	_ASM_LABEL(name),size
    181 
    182 /*
    183  * Need a better place for these but these are common across
    184  * all m68k ports so let's define just once.
    185  */
    186 #ifdef __mcoldfire__
    187 #define INTERRUPT_SAVEREG	lea -16(%sp),%sp; moveml #0xC0C0,(%sp)
    188 #define INTERRUPT_RESTOREREG	moveml (%sp),#0x0303; lea 16(%sp),%sp
    189 #else
    190 #define INTERRUPT_SAVEREG	moveml	#0xC0C0,-(%sp)
    191 #define INTERRUPT_RESTOREREG	moveml	(%sp)+,#0x0303
    192 #endif
    193 
    194 #ifdef _KERNEL
    195 /*
    196  * Shorthand for calling panic().
    197  * Note the side-effect: it uses up the 9: label, so be careful!
    198  */
    199 #define	PANIC(x)					\
    200 		pea	9f			;	\
    201 		jbsr	_C_LABEL(panic)		;	\
    202 	9:	.asciz	x			;	\
    203 		.even
    204 
    205 /* 64-bit counter increments */
    206 #define CPUINFO_INCREMENT(n)					\
    207 	lea	_C_LABEL(cpu_info_store)+(n)+4,%a1;		\
    208 	addq.l	#1,(%a1);					\
    209 	clr.l	%d0;		/* doesn't change CCR[X] */	\
    210 	move.l	-(%a1),%d1;	/* doesn't change CCR[X] */	\
    211 	addx.l	%d0,%d1;					\
    212 	move.l	%d1,(%a1)
    213 
    214 /* 64-bit counter increments */
    215 #define CPUINFO_ADD(n, addend)					\
    216 	lea	_C_LABEL(cpu_info_store)+(n)+4,%a1;		\
    217 	add.l	addend,(%a1);					\
    218 	clr.l	%d0;		/* doesn't change CCR[X] */	\
    219 	move.l	-(%a1),%d1;	/* doesn't change CCR[X] */	\
    220 	addx.l	%d0,%d1;					\
    221 	move.l	%d1,(%a1)
    222 
    223 #endif /* _KERNEL */
    224 
    225 /*
    226  * Shorthand for defining vectors for the vector table.
    227  */
    228 #define	VECTOR(x)					\
    229 	.long	_C_LABEL(x)
    230 
    231 #define	ASVECTOR(x)					\
    232 	.long	_ASM_LABEL(x)
    233 
    234 #define	VECTOR_UNUSED					\
    235 	.long	0
    236 
    237 #define	WEAK_ALIAS(alias,sym)						\
    238 	.weak alias;							\
    239 	alias = sym
    240 
    241 /*
    242  * STRONG_ALIAS: create a strong alias.
    243  */
    244 #define STRONG_ALIAS(alias,sym)						\
    245 	.globl alias;							\
    246 	alias = sym
    247 
    248 #ifdef __STDC__
    249 #define	WARN_REFERENCES(sym,msg)					\
    250 	.pushsection .gnu.warning. ## sym;				\
    251 	.ascii msg;							\
    252 	.popsection
    253 #else
    254 #define	WARN_REFERENCES(sym,msg)					\
    255 	.pushsection .gnu.warning./**/sym;				\
    256 	.ascii msg;							\
    257 	.popsection
    258 #endif /* __STDC__ */
    259 
    260 /*
    261  * Macros to hide shortcomings in the 68010.
    262  */
    263 #ifdef __mc68010__
    264 #define	EXTBL(reg)					\
    265 	extw	reg		;			\
    266 	extl	reg
    267 #else	/* __mc68010__ */
    268 #define	EXTBL(reg)					\
    269 	extbl	reg
    270 #endif	/* __mc68010__ */
    271 
    272 #endif /* _M68K_ASM_H_ */
    273