xref: /csrg-svn/sys/sparc/include/stdarg.h (revision 64667)
155126Storek /*
263320Sbostic  * Copyright (c) 1992, 1993
363320Sbostic  *	The Regents of the University of California.  All rights reserved.
455126Storek  *
555126Storek  * This software was developed by the Computer Systems Engineering group
655126Storek  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
755126Storek  * contributed to Berkeley.
855126Storek  *
955501Sbostic  * All advertising materials mentioning features or use of this software
1055501Sbostic  * must display the following acknowledgement:
1155501Sbostic  *	This product includes software developed by the University of
1259210Storek  *	California, Lawrence Berkeley Laboratory.
1355501Sbostic  *
1455126Storek  * %sccs.include.redist.c%
1555126Storek  *
16*64667Storek  *	@(#)stdarg.h	8.2 (Berkeley) 09/27/93
1755126Storek  *
18*64667Storek  * from: $Header: stdarg.h,v 1.9 93/09/27 21:12:38 torek Exp $
1955126Storek  */
2055126Storek 
2155126Storek /*
2255126Storek  * SPARC stdarg.h
2355126Storek  */
2455126Storek 
2555126Storek #ifndef _MACHINE_STDARG_H
2655126Storek #define _MACHINE_STDARG_H
2755126Storek 
2855126Storek typedef char *va_list;
2955126Storek 
3055126Storek /*
3155126Storek  * va_start sets ap to point to the first variable argument.
3255126Storek  * The `last fixed argument' parameter l is ignored (and should
3355126Storek  * never have been included in the ANSI standard!).
3455126Storek  *
3555126Storek  * va_end cleans up after va_start.  There is nothing to do there.
3655126Storek  */
37*64667Storek #ifdef __GCC_NEW_VARARGS__	/* gcc 2.4.5 */
38*64667Storek #define va_start(ap, l)	((ap) = (char *)__builtin_saveregs())
39*64667Storek #else				/* gcc 2.3.3 */
4055126Storek #define va_start(ap, l)	(__builtin_saveregs(), \
41*64667Storek 			 (ap) = (char *)__builtin_next_arg())
42*64667Storek #endif
4355126Storek #define va_end(ap)	/* empty */
4455126Storek 
4556566Storek #if __GNUC__ == 1
4656566Storek #define __extension__	/* hack for bootstrapping via gcc 1.x */
4756566Storek #endif
4856566Storek 
4955126Storek /*
5056566Storek  * va_arg picks up the next argument of type `ty'.  Appending an
5156566Storek  * asterisk to ty must produce a pointer to ty (i.e., ty may not be,
5256566Storek  * e.g., `int (*)()').  In addition, ty must not be any type which
5355126Storek  * undergoes promotion to some other type (e.g., char): it must
5455126Storek  * be the promoted type instead.
5556566Storek  *
5656566Storek  * Gcc-2.x tries to use ldd/std for double and quad_t values, but Sun's
5756566Storek  * brain-damaged calling convention does not quad-align these.  Thus,
5856566Storek  * for 8-byte arguments, we have to pick up the actual value four bytes
5956566Storek  * at a time, and use type punning (i.e., a union) to produce the result.
6056566Storek  * (We could also do this with a libc function, actually, by returning
6156566Storek  * 8 byte integers in %o0+%o1 and the same 8 bytes as a double in %f0+%f1.)
6259792Storek  *
6359792Storek  * Note: we cannot use the union trick (which generates better code) for
6459792Storek  * C++, since `ty' might be a type with a constructor (these may not appear
6559792Storek  * in a union).
6659792Storek  *
6759792Storek  * The extraneous casts through `void *' avoid gcc alignment warnings.
6855126Storek  */
6959792Storek #ifdef __cplusplus
7059792Storek #define	__va_8byte(ap, ty) ({ \
7159792Storek 	int __va_i[2]; \
7259792Storek 	__va_i[0] = ((int *)(void *)(ap))[0]; \
7359792Storek 	__va_i[1] = ((int *)(void *)(ap))[1]; \
7459792Storek 	(ap) += 8; *(ty *)(void *)__va_i; })
7559792Storek #else
7659792Storek #define	__va_8byte(ap, ty) ({ \
7759792Storek 	union { ty __d; int __i[2]; } __va_u; \
7859792Storek 	__va_u.__i[0] = ((int *)(void *)(ap))[0]; \
7959792Storek 	__va_u.__i[1] = ((int *)(void *)(ap))[1]; \
8059792Storek 	(ap) += 8; __va_u.__d; })
8159792Storek #endif /* __cplusplus */
8255126Storek 
8359792Storek #define va_arg(ap, ty) __extension__ ({ \
8459792Storek     ty __va_temp; /* to check for invisible-ptr struct-valued args */ \
8559792Storek     __builtin_classify_type(__va_temp) >= 12 ? \
8659792Storek 	((ty **)(void *)((ap) += sizeof(ty *)))[-1][0] : \
8759792Storek     sizeof(ty) == 8 ? __va_8byte(ap, ty) : \
8859792Storek 	((ty *)(void *)(ap += sizeof(ty)))[-1]; })
8959792Storek 
9055126Storek #endif /* _MACHINE_STDARG_H */
91