Home | History | Annotate | Line # | Download | only in include
asm.h revision 1.3
      1  1.3  cherry /*	$NetBSD: asm.h,v 1.3 2006/07/07 06:42:32 cherry 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.1  cherry  *
      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.1  cherry  *
     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.1  cherry  *
     17  1.1  cherry  * Carnegie Mellon requests users of this software to return to
     18  1.1  cherry  *
     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.1  cherry  *
     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.1  cherry /*
     38  1.3  cherry  * Useful stuff.
     39  1.3  cherry  */
     40  1.3  cherry #ifdef __STDC__
     41  1.3  cherry #define	__CONCAT(a,b)	a ## b
     42  1.3  cherry #else
     43  1.3  cherry #define	__CONCAT(a,b)	a/**/b
     44  1.3  cherry #endif
     45  1.3  cherry #define ___CONCAT(a,b)	__CONCAT(a,b)
     46  1.3  cherry 
     47  1.3  cherry /*
     48  1.1  cherry  * Macro to make a local label name.
     49  1.1  cherry  */
     50  1.1  cherry #define	LLABEL(name,num)	L ## name ## num
     51  1.1  cherry 
     52  1.1  cherry /*
     53  1.1  cherry  * MCOUNT
     54  1.1  cherry  */
     55  1.1  cherry #if defined(GPROF)
     56  1.1  cherry #define	MCOUNT					\
     57  1.1  cherry 	alloc	out0 = ar.pfs, 8, 0, 4, 0;	\
     58  1.1  cherry 	mov	out1 = r1;			\
     59  1.1  cherry 	mov	out2 = b0;;			\
     60  1.1  cherry 	mov	out3 = r0;			\
     61  1.1  cherry 	br.call.sptk b0 = _mcount;;
     62  1.1  cherry #else
     63  1.1  cherry #define	MCOUNT	/* nothing */
     64  1.1  cherry #endif
     65  1.1  cherry 
     66  1.1  cherry /*
     67  1.1  cherry  * ENTRY
     68  1.1  cherry  *	Declare a global leaf function.
     69  1.1  cherry  *	A leaf function does not call other functions.
     70  1.1  cherry  */
     71  1.1  cherry #define	ENTRY(_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 	MCOUNT
     78  1.1  cherry 
     79  1.1  cherry #define	ENTRY_NOPROFILE(_name_, _n_args_)	\
     80  1.1  cherry 	.global	_name_;				\
     81  1.1  cherry 	.align	16;				\
     82  1.1  cherry 	.proc	_name_;				\
     83  1.1  cherry _name_:;					\
     84  1.1  cherry 	.regstk	_n_args_, 0, 0, 0
     85  1.1  cherry 
     86  1.1  cherry /*
     87  1.1  cherry  * STATIC_ENTRY
     88  1.1  cherry  *	Declare a local leaf function.
     89  1.1  cherry  */
     90  1.1  cherry #define STATIC_ENTRY(_name_, _n_args_)		\
     91  1.1  cherry 	.align	16;				\
     92  1.1  cherry 	.proc	_name_;				\
     93  1.1  cherry _name_:;					\
     94  1.1  cherry 	.regstk	_n_args_, 0, 0, 0		\
     95  1.1  cherry 	MCOUNT
     96  1.1  cherry /*
     97  1.1  cherry  * XENTRY
     98  1.1  cherry  *	Global alias for a leaf function, or alternate entry point
     99  1.1  cherry  */
    100  1.1  cherry #define	XENTRY(_name_)				\
    101  1.1  cherry 	.globl	_name_;				\
    102  1.1  cherry _name_:
    103  1.1  cherry 
    104  1.1  cherry /*
    105  1.1  cherry  * STATIC_XENTRY
    106  1.1  cherry  *	Local alias for a leaf function, or alternate entry point
    107  1.1  cherry  */
    108  1.1  cherry #define	STATIC_XENTRY(_name_)			\
    109  1.1  cherry _name_:
    110  1.1  cherry 
    111  1.1  cherry 
    112  1.1  cherry /*
    113  1.1  cherry  * END
    114  1.1  cherry  *	Function delimiter
    115  1.1  cherry  */
    116  1.1  cherry #define	END(_name_)						\
    117  1.1  cherry 	.endp	_name_
    118  1.1  cherry 
    119  1.1  cherry 
    120  1.1  cherry /*
    121  1.1  cherry  * EXPORT
    122  1.1  cherry  *	Export a symbol
    123  1.1  cherry  */
    124  1.1  cherry #define	EXPORT(_name_)						\
    125  1.1  cherry 	.global	_name_;						\
    126  1.1  cherry _name_:
    127  1.1  cherry 
    128  1.1  cherry 
    129  1.1  cherry /*
    130  1.1  cherry  * IMPORT
    131  1.1  cherry  *	Make an external name visible, typecheck the size
    132  1.1  cherry  */
    133  1.1  cherry #define	IMPORT(_name_, _size_)					\
    134  1.1  cherry 	/* .extern	_name_,_size_ */
    135  1.1  cherry 
    136  1.1  cherry 
    137  1.1  cherry /*
    138  1.1  cherry  * ABS
    139  1.1  cherry  *	Define an absolute symbol
    140  1.1  cherry  */
    141  1.1  cherry #define	ABS(_name_, _value_)					\
    142  1.1  cherry 	.globl	_name_;						\
    143  1.1  cherry _name_	=	_value_
    144  1.1  cherry 
    145  1.1  cherry 
    146  1.1  cherry /*
    147  1.1  cherry  * BSS
    148  1.1  cherry  *	Allocate un-initialized space for a global symbol
    149  1.1  cherry  */
    150  1.1  cherry #define	BSS(_name_,_numbytes_)					\
    151  1.1  cherry 	.comm	_name_,_numbytes_
    152  1.1  cherry 
    153  1.1  cherry 
    154  1.1  cherry /*
    155  1.1  cherry  * MSG
    156  1.1  cherry  *	Allocate space for a message (a read-only ascii string)
    157  1.1  cherry  */
    158  1.1  cherry #define	ASCIZ	.asciz
    159  1.1  cherry #define	MSG(msg,reg,label)			\
    160  1.1  cherry 	addl reg,@ltoff(label),gp;;		\
    161  1.1  cherry 	ld8 reg=[reg];;				\
    162  1.1  cherry 	.data;					\
    163  1.1  cherry label:	ASCIZ msg;				\
    164  1.1  cherry 	.text;
    165  1.1  cherry 
    166  1.1  cherry 
    167  1.1  cherry /*
    168  1.1  cherry  * System call glue.
    169  1.1  cherry  */
    170  1.3  cherry #define	SYSCALLNUM(name)	___CONCAT(SYS_,name)
    171  1.1  cherry 
    172  1.1  cherry #define	CALLSYS_NOERROR(name)					\
    173  1.1  cherry {	.mmi ;							\
    174  1.1  cherry 	alloc		r9 = ar.pfs, 0, 0, 8, 0 ;		\
    175  1.1  cherry 	mov		r31 = ar.k5 ;				\
    176  1.1  cherry 	mov		r10 = b0 ;; }				\
    177  1.1  cherry {	.mib ;							\
    178  1.1  cherry 	mov		r8 = SYSCALLNUM(name) ;			\
    179  1.1  cherry 	mov		b7 = r31 ; 				\
    180  1.1  cherry 	br.call.sptk	b0 = b7 ;; }
    181  1.1  cherry 
    182  1.1  cherry 
    183  1.1  cherry /*
    184  1.1  cherry  * WEAK_ALIAS: create a weak alias (ELF only).
    185  1.1  cherry  */
    186  1.1  cherry #define WEAK_ALIAS(alias,sym)					\
    187  1.1  cherry 	.weak alias;						\
    188  1.1  cherry 	alias = sym
    189  1.1  cherry 
    190  1.3  cherry /*
    191  1.3  cherry  * STRONG_ALIAS: create a strong alias.
    192  1.3  cherry  */
    193  1.3  cherry #define STRONG_ALIAS(alias,sym)					\
    194  1.3  cherry 	.globl alias;						\
    195  1.3  cherry 	alias = sym
    196