Home | History | Annotate | Line # | Download | only in include
      1  1.11    martin /*	$NetBSD: asm.h,v 1.11 2025/01/06 10:46:44 martin Exp $	*/
      2   1.1    cherry 
      3   1.1    cherry /* -
      4   1.1    cherry  * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
      5   1.1    cherry  * All Rights Reserved.
      6   1.9     skrll  *
      7   1.1    cherry  * Permission to use, copy, modify and distribute this software and its
      8   1.1    cherry  * documentation is hereby granted, provided that both the copyright
      9   1.1    cherry  * notice and this permission notice appear in all copies of the
     10   1.1    cherry  * software, derivative works or modified versions, and any portions
     11   1.1    cherry  * thereof, and that both notices appear in supporting documentation.
     12   1.9     skrll  *
     13   1.1    cherry  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     14   1.1    cherry  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     15   1.1    cherry  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     16   1.9     skrll  *
     17   1.1    cherry  * Carnegie Mellon requests users of this software to return to
     18   1.9     skrll  *
     19   1.1    cherry  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     20   1.1    cherry  *  School of Computer Science
     21   1.1    cherry  *  Carnegie Mellon University
     22   1.1    cherry  *  Pittsburgh PA 15213-3890
     23   1.9     skrll  *
     24   1.1    cherry  * any improvements or extensions that they make and grant Carnegie Mellon
     25   1.1    cherry  * the rights to redistribute these changes.
     26   1.1    cherry  */
     27   1.1    cherry 
     28   1.1    cherry /*
     29   1.1    cherry  *	Assembly coding style
     30   1.1    cherry  *
     31   1.1    cherry  *	This file contains macros and register defines to
     32   1.1    cherry  *	aid in writing more readable assembly code.
     33   1.1    cherry  *	Some rules to make assembly code understandable by
     34   1.1    cherry  *	a debugger are also noted.
     35   1.1    cherry  */
     36   1.1    cherry 
     37   1.6  kiyohara #define _C_LABEL(x)	x
     38   1.6  kiyohara 
     39   1.1    cherry /*
     40   1.1    cherry  * Macro to make a local label name.
     41   1.1    cherry  */
     42   1.1    cherry #define	LLABEL(name,num)	L ## name ## num
     43   1.1    cherry 
     44   1.1    cherry /*
     45   1.1    cherry  * MCOUNT
     46   1.1    cherry  */
     47   1.1    cherry #if defined(GPROF)
     48   1.1    cherry #define	MCOUNT					\
     49   1.1    cherry 	alloc	out0 = ar.pfs, 8, 0, 4, 0;	\
     50   1.1    cherry 	mov	out1 = r1;			\
     51   1.1    cherry 	mov	out2 = b0;;			\
     52   1.1    cherry 	mov	out3 = r0;			\
     53   1.1    cherry 	br.call.sptk b0 = _mcount;;
     54   1.1    cherry #else
     55   1.1    cherry #define	MCOUNT	/* nothing */
     56   1.1    cherry #endif
     57   1.1    cherry 
     58   1.1    cherry /*
     59   1.1    cherry  * ENTRY
     60   1.1    cherry  *	Declare a global leaf function.
     61   1.1    cherry  *	A leaf function does not call other functions.
     62   1.1    cherry  */
     63   1.1    cherry #define	ENTRY(_name_, _n_args_)			\
     64   1.1    cherry 	.global	_name_;				\
     65   1.1    cherry 	.align	16;				\
     66   1.1    cherry 	.proc	_name_;				\
     67   1.1    cherry _name_:;					\
     68   1.1    cherry 	.regstk	_n_args_, 0, 0, 0;		\
     69   1.1    cherry 	MCOUNT
     70   1.1    cherry 
     71   1.1    cherry #define	ENTRY_NOPROFILE(_name_, _n_args_)	\
     72   1.1    cherry 	.global	_name_;				\
     73   1.1    cherry 	.align	16;				\
     74   1.1    cherry 	.proc	_name_;				\
     75   1.1    cherry _name_:;					\
     76   1.1    cherry 	.regstk	_n_args_, 0, 0, 0
     77   1.1    cherry 
     78   1.1    cherry /*
     79   1.1    cherry  * STATIC_ENTRY
     80   1.1    cherry  *	Declare a local leaf function.
     81   1.1    cherry  */
     82   1.1    cherry #define STATIC_ENTRY(_name_, _n_args_)		\
     83   1.1    cherry 	.align	16;				\
     84   1.1    cherry 	.proc	_name_;				\
     85   1.1    cherry _name_:;					\
     86   1.1    cherry 	.regstk	_n_args_, 0, 0, 0		\
     87   1.1    cherry 	MCOUNT
     88   1.1    cherry /*
     89   1.1    cherry  * XENTRY
     90   1.1    cherry  *	Global alias for a leaf function, or alternate entry point
     91   1.1    cherry  */
     92   1.1    cherry #define	XENTRY(_name_)				\
     93   1.1    cherry 	.globl	_name_;				\
     94   1.1    cherry _name_:
     95   1.1    cherry 
     96   1.1    cherry /*
     97   1.1    cherry  * STATIC_XENTRY
     98   1.1    cherry  *	Local alias for a leaf function, or alternate entry point
     99   1.1    cherry  */
    100   1.1    cherry #define	STATIC_XENTRY(_name_)			\
    101   1.1    cherry _name_:
    102   1.1    cherry 
    103   1.1    cherry 
    104   1.1    cherry /*
    105   1.1    cherry  * END
    106   1.1    cherry  *	Function delimiter
    107   1.1    cherry  */
    108   1.1    cherry #define	END(_name_)						\
    109   1.1    cherry 	.endp	_name_
    110   1.1    cherry 
    111   1.1    cherry 
    112   1.1    cherry /*
    113   1.1    cherry  * EXPORT
    114   1.1    cherry  *	Export a symbol
    115   1.1    cherry  */
    116   1.1    cherry #define	EXPORT(_name_)						\
    117   1.1    cherry 	.global	_name_;						\
    118   1.1    cherry _name_:
    119   1.1    cherry 
    120   1.1    cherry 
    121   1.1    cherry /*
    122   1.1    cherry  * IMPORT
    123   1.1    cherry  *	Make an external name visible, typecheck the size
    124   1.1    cherry  */
    125   1.1    cherry #define	IMPORT(_name_, _size_)					\
    126   1.1    cherry 	/* .extern	_name_,_size_ */
    127   1.1    cherry 
    128   1.1    cherry 
    129   1.1    cherry /*
    130   1.1    cherry  * ABS
    131   1.1    cherry  *	Define an absolute symbol
    132   1.1    cherry  */
    133   1.1    cherry #define	ABS(_name_, _value_)					\
    134   1.1    cherry 	.globl	_name_;						\
    135   1.1    cherry _name_	=	_value_
    136   1.1    cherry 
    137   1.1    cherry 
    138   1.1    cherry /*
    139   1.1    cherry  * BSS
    140   1.1    cherry  *	Allocate un-initialized space for a global symbol
    141   1.1    cherry  */
    142   1.1    cherry #define	BSS(_name_,_numbytes_)					\
    143   1.1    cherry 	.comm	_name_,_numbytes_
    144   1.1    cherry 
    145   1.1    cherry 
    146   1.1    cherry /*
    147   1.1    cherry  * MSG
    148   1.1    cherry  *	Allocate space for a message (a read-only ascii string)
    149   1.1    cherry  */
    150   1.1    cherry #define	ASCIZ	.asciz
    151   1.1    cherry #define	MSG(msg,reg,label)			\
    152   1.1    cherry 	addl reg,@ltoff(label),gp;;		\
    153   1.1    cherry 	ld8 reg=[reg];;				\
    154   1.1    cherry 	.data;					\
    155   1.1    cherry label:	ASCIZ msg;				\
    156   1.1    cherry 	.text;
    157   1.1    cherry 
    158   1.1    cherry 
    159   1.1    cherry /*
    160   1.1    cherry  * System call glue.
    161   1.1    cherry  */
    162   1.3    cherry #define	SYSCALLNUM(name)	___CONCAT(SYS_,name)
    163   1.1    cherry 
    164   1.1    cherry #define	CALLSYS_NOERROR(name)					\
    165   1.1    cherry {	.mmi ;							\
    166   1.1    cherry 	alloc		r9 = ar.pfs, 0, 0, 8, 0 ;		\
    167   1.1    cherry 	mov		r31 = ar.k5 ;				\
    168   1.1    cherry 	mov		r10 = b0 ;; }				\
    169   1.1    cherry {	.mib ;							\
    170   1.1    cherry 	mov		r8 = SYSCALLNUM(name) ;			\
    171   1.1    cherry 	mov		b7 = r31 ; 				\
    172   1.1    cherry 	br.call.sptk	b0 = b7 ;; }
    173   1.1    cherry 
    174   1.1    cherry 
    175   1.1    cherry /*
    176   1.1    cherry  * WEAK_ALIAS: create a weak alias (ELF only).
    177   1.1    cherry  */
    178   1.1    cherry #define WEAK_ALIAS(alias,sym)					\
    179   1.1    cherry 	.weak alias;						\
    180   1.1    cherry 	alias = sym
    181   1.1    cherry 
    182   1.3    cherry /*
    183   1.3    cherry  * STRONG_ALIAS: create a strong alias.
    184   1.3    cherry  */
    185   1.3    cherry #define STRONG_ALIAS(alias,sym)					\
    186   1.3    cherry 	.globl alias;						\
    187   1.3    cherry 	alias = sym
    188   1.5    martin 
    189   1.5    martin /*
    190   1.5    martin  * WARN_REFERENCES: create a warning if the specified symbol is referenced.
    191   1.5    martin  */
    192   1.5    martin #ifdef __STDC__
    193   1.5    martin #define	WARN_REFERENCES(sym,msg)					\
    194   1.5    martin 	.pushsection .gnu.warning. ## sym;				\
    195   1.5    martin 	.ascii msg;							\
    196   1.5    martin 	.popsection
    197   1.5    martin #else
    198   1.5    martin #define	WARN_REFERENCES(sym,msg)					\
    199   1.5    martin 	.pushsection .gnu.warning./**/sym;				\
    200   1.5    martin 	.ascii msg;							\
    201   1.5    martin 	.popsection
    202   1.5    martin #endif /* __STDC__ */
    203   1.5    martin 
    204   1.5    martin 
    205   1.7    cherry #ifdef __ELF__
    206  1.10    martin #ifdef _NETBSD_REVISIONID
    207  1.10    martin #define RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
    208  1.11    martin 			.asciz x;					\
    209  1.11    martin 			.ascii "$"; .ascii "NetBSD: "; .ascii __FILE__;	\
    210  1.11    martin 			.ascii " "; .ascii _NETBSD_REVISIONID;		\
    211  1.11    martin 			.asciz " $";					\
    212  1.10    martin 			.popsection
    213  1.10    martin #else
    214   1.8     joerg #define RCSID(x)	.pushsection ".ident","MS",@progbits,1;		\
    215   1.8     joerg 			.asciz x;					\
    216   1.8     joerg 			.popsection
    217  1.10    martin #endif
    218   1.7    cherry #else
    219   1.7    cherry #define RCSID(name)		.asciz name
    220   1.7    cherry #endif
    221   1.7    cherry 
    222   1.5    martin /*
    223   1.5    martin  * Kernel RCS ID tag and copyright macros
    224   1.5    martin  */
    225   1.5    martin 
    226   1.5    martin #ifdef _KERNEL
    227   1.5    martin 
    228   1.5    martin #define	__KERNEL_SECTIONSTRING(_sec, _str)				\
    229   1.5    martin 	.pushsection _sec ; .asciz _str ; .popsection
    230   1.5    martin 
    231  1.10    martin #ifdef _NETBSD_REVISIONID
    232  1.10    martin #define	__KERNEL_RCSID(_n, _s)		__KERNEL_SECTIONSTRING(.ident,	\
    233  1.10    martin 					"$" "NetBSD: " __FILE__ " "	\
    234  1.10    martin 					_NETBSD_REVISIONID " $")
    235  1.10    martin #else
    236   1.5    martin #define	__KERNEL_RCSID(_n, _s)		__KERNEL_SECTIONSTRING(.ident, _s)
    237  1.10    martin #endif
    238   1.5    martin #define	__KERNEL_COPYRIGHT(_n, _s)	__KERNEL_SECTIONSTRING(.copyright, _s)
    239   1.5    martin 
    240   1.5    martin #ifdef NO_KERNEL_RCSIDS
    241   1.5    martin #undef __KERNEL_RCSID
    242   1.5    martin #define	__KERNEL_RCSID(_n, _s)		/* nothing */
    243   1.5    martin #endif
    244   1.5    martin 
    245   1.5    martin #endif /* _KERNEL */
    246