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