asm.h revision 141085
166458Sdfr/* $FreeBSD: head/sys/ia64/include/asm.h 141085 2005-01-31 08:16:45Z imp $ */
266458Sdfr/* From: NetBSD: asm.h,v 1.18 1997/11/03 04:22:06 ross Exp */
366458Sdfr
4141085Simp/*-
566458Sdfr * Copyright (c) 1991,1990,1989,1994,1995,1996 Carnegie Mellon University
666458Sdfr * All Rights Reserved.
766458Sdfr *
866458Sdfr * Permission to use, copy, modify and distribute this software and its
966458Sdfr * documentation is hereby granted, provided that both the copyright
1066458Sdfr * notice and this permission notice appear in all copies of the
1166458Sdfr * software, derivative works or modified versions, and any portions
1266458Sdfr * thereof, and that both notices appear in supporting documentation.
1366458Sdfr *
1466458Sdfr * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
1566458Sdfr * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
1666458Sdfr * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1766458Sdfr *
1866458Sdfr * Carnegie Mellon requests users of this software to return to
1966458Sdfr *
2066458Sdfr *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
2166458Sdfr *  School of Computer Science
2266458Sdfr *  Carnegie Mellon University
2366458Sdfr *  Pittsburgh PA 15213-3890
2466458Sdfr *
2566458Sdfr * any improvements or extensions that they make and grant Carnegie Mellon
2666458Sdfr * the rights to redistribute these changes.
2766458Sdfr */
2866458Sdfr
2966458Sdfr/*
3066458Sdfr *	Assembly coding style
3166458Sdfr *
3266458Sdfr *	This file contains macros and register defines to
3366458Sdfr *	aid in writing more readable assembly code.
3466458Sdfr *	Some rules to make assembly code understandable by
3566458Sdfr *	a debugger are also noted.
3666458Sdfr */
3766458Sdfr
3866458Sdfr/*
3966458Sdfr * Macro to make a local label name.
4066458Sdfr */
4166458Sdfr#define	LLABEL(name,num)	L ## name ## num
4266458Sdfr
4366458Sdfr/*
4466458Sdfr * MCOUNT
4566458Sdfr */
46134287Smarcel#if defined(GPROF)
47134287Smarcel#define	MCOUNT					\
48134287Smarcel	alloc	out0 = ar.pfs, 8, 0, 4, 0;	\
49134287Smarcel	mov	out1 = r1;			\
50134287Smarcel	mov	out2 = b0;;			\
51134287Smarcel	mov	out3 = r0;			\
52134287Smarcel	br.call.sptk b0 = _mcount;;
5366458Sdfr#else
54134287Smarcel#define	MCOUNT	/* nothing */
5566458Sdfr#endif
5666458Sdfr
5766458Sdfr/*
5866633Sdfr * ENTRY
5966458Sdfr *	Declare a global leaf function.
6066458Sdfr *	A leaf function does not call other functions.
6166458Sdfr */
6266633Sdfr#define	ENTRY(_name_, _n_args_)			\
6366458Sdfr	.global	_name_;				\
6466633Sdfr	.align	16;				\
6566458Sdfr	.proc	_name_;				\
6666458Sdfr_name_:;					\
67134287Smarcel	.regstk	_n_args_, 0, 0, 0;		\
6866458Sdfr	MCOUNT
6966458Sdfr
7066633Sdfr#define	ENTRY_NOPROFILE(_name_, _n_args_)	\
7166458Sdfr	.global	_name_;				\
7266633Sdfr	.align	16;				\
7366458Sdfr	.proc	_name_;				\
7466458Sdfr_name_:;					\
7566458Sdfr	.regstk	_n_args_, 0, 0, 0
7666458Sdfr
7766458Sdfr/*
7866633Sdfr * STATIC_ENTRY
7966458Sdfr *	Declare a local leaf function.
8066458Sdfr */
8166633Sdfr#define STATIC_ENTRY(_name_, _n_args_)		\
8266633Sdfr	.align	16;				\
8366458Sdfr	.proc	_name_;				\
8466458Sdfr_name_:;					\
8566458Sdfr	.regstk	_n_args_, 0, 0, 0		\
8666458Sdfr	MCOUNT
8766458Sdfr/*
8866633Sdfr * XENTRY
8966458Sdfr *	Global alias for a leaf function, or alternate entry point
9066458Sdfr */
9166633Sdfr#define	XENTRY(_name_)				\
9266458Sdfr	.globl	_name_;				\
9366458Sdfr_name_:
9466458Sdfr
9566458Sdfr/*
9666633Sdfr * STATIC_XENTRY
9766458Sdfr *	Local alias for a leaf function, or alternate entry point
9866458Sdfr */
9966633Sdfr#define	STATIC_XENTRY(_name_)			\
10066458Sdfr_name_:
10166458Sdfr
10266458Sdfr
10366458Sdfr/*
10466458Sdfr * END
10566458Sdfr *	Function delimiter
10666458Sdfr */
10766458Sdfr#define	END(_name_)						\
10866458Sdfr	.endp	_name_
10966458Sdfr
11066458Sdfr
11166458Sdfr/*
11266458Sdfr * EXPORT
11366458Sdfr *	Export a symbol
11466458Sdfr */
11566458Sdfr#define	EXPORT(_name_)						\
11666458Sdfr	.global	_name_;						\
11766458Sdfr_name_:
11866458Sdfr
11966458Sdfr
12066458Sdfr/*
12166458Sdfr * IMPORT
12266458Sdfr *	Make an external name visible, typecheck the size
12366458Sdfr */
12466458Sdfr#define	IMPORT(_name_, _size_)					\
12566458Sdfr	/* .extern	_name_,_size_ */
12666458Sdfr
12766458Sdfr
12866458Sdfr/*
12966458Sdfr * ABS
13066458Sdfr *	Define an absolute symbol
13166458Sdfr */
13266458Sdfr#define	ABS(_name_, _value_)					\
13366458Sdfr	.globl	_name_;						\
13466458Sdfr_name_	=	_value_
13566458Sdfr
13666458Sdfr
13766458Sdfr/*
13866458Sdfr * BSS
13966458Sdfr *	Allocate un-initialized space for a global symbol
14066458Sdfr */
14166458Sdfr#define	BSS(_name_,_numbytes_)					\
14266458Sdfr	.comm	_name_,_numbytes_
14366458Sdfr
14466458Sdfr
14566458Sdfr/*
14666458Sdfr * MSG
14766458Sdfr *	Allocate space for a message (a read-only ascii string)
14866458Sdfr */
14966458Sdfr#define	ASCIZ	.asciz
15066633Sdfr#define	MSG(msg,reg,label)			\
15166633Sdfr	addl reg,@ltoff(label),gp;;		\
15266633Sdfr	ld8 reg=[reg];;				\
15366633Sdfr	.data;					\
15466633Sdfrlabel:	ASCIZ msg;				\
15566458Sdfr	.text;
15666458Sdfr
157115084Smarcel
15866458Sdfr/*
15966458Sdfr * System call glue.
16066458Sdfr */
161115084Smarcel#define	SYSCALLNUM(name)	SYS_ ## name
16266458Sdfr
163115084Smarcel#define	CALLSYS_NOERROR(name)					\
164115084Smarcel{	.mmi ;							\
165115084Smarcel	alloc		r9 = ar.pfs, 0, 0, 8, 0 ;		\
166115084Smarcel	mov		r31 = ar.k5 ;				\
167115084Smarcel	mov		r10 = b0 ;; }				\
168115084Smarcel{	.mib ;							\
169115084Smarcel	mov		r8 = SYSCALLNUM(name) ;			\
170115084Smarcel	mov		b7 = r31 ; 				\
171115084Smarcel	br.call.sptk	b0 = b7 ;; }
17266458Sdfr
173115084Smarcel
17466458Sdfr/*
17566458Sdfr * WEAK_ALIAS: create a weak alias (ELF only).
17666458Sdfr */
17766458Sdfr#define WEAK_ALIAS(alias,sym)					\
17866458Sdfr	.weak alias;						\
17966458Sdfr	alias = sym
18066458Sdfr
18166458Sdfr/*
182103436Speter * ID tag macros
18366458Sdfr */
18492998Sobrien#if !defined(lint) && !defined(STRIP_FBSDID)
18592998Sobrien#define __FBSDID(s)	.ident s
18692998Sobrien#else
18792998Sobrien#define __FBSDID(s)	/* nothing */
18892998Sobrien#endif /* not lint and not STRIP_FBSDID */
189