xref: /original-bsd/sys/sparc/include/stdarg.h (revision 95ecee29)
1 /*
2  * Copyright (c) 1992, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * All advertising materials mentioning features or use of this software
10  * must display the following acknowledgement:
11  *	This product includes software developed by the University of
12  *	California, Lawrence Berkeley Laboratory.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)stdarg.h	8.2 (Berkeley) 09/27/93
17  *
18  * from: $Header: stdarg.h,v 1.9 93/09/27 21:12:38 torek Exp $
19  */
20 
21 /*
22  * SPARC stdarg.h
23  */
24 
25 #ifndef _MACHINE_STDARG_H
26 #define _MACHINE_STDARG_H
27 
28 typedef char *va_list;
29 
30 /*
31  * va_start sets ap to point to the first variable argument.
32  * The `last fixed argument' parameter l is ignored (and should
33  * never have been included in the ANSI standard!).
34  *
35  * va_end cleans up after va_start.  There is nothing to do there.
36  */
37 #ifdef __GCC_NEW_VARARGS__	/* gcc 2.4.5 */
38 #define va_start(ap, l)	((ap) = (char *)__builtin_saveregs())
39 #else				/* gcc 2.3.3 */
40 #define va_start(ap, l)	(__builtin_saveregs(), \
41 			 (ap) = (char *)__builtin_next_arg())
42 #endif
43 #define va_end(ap)	/* empty */
44 
45 #if __GNUC__ == 1
46 #define __extension__	/* hack for bootstrapping via gcc 1.x */
47 #endif
48 
49 /*
50  * va_arg picks up the next argument of type `ty'.  Appending an
51  * asterisk to ty must produce a pointer to ty (i.e., ty may not be,
52  * e.g., `int (*)()').  In addition, ty must not be any type which
53  * undergoes promotion to some other type (e.g., char): it must
54  * be the promoted type instead.
55  *
56  * Gcc-2.x tries to use ldd/std for double and quad_t values, but Sun's
57  * brain-damaged calling convention does not quad-align these.  Thus,
58  * for 8-byte arguments, we have to pick up the actual value four bytes
59  * at a time, and use type punning (i.e., a union) to produce the result.
60  * (We could also do this with a libc function, actually, by returning
61  * 8 byte integers in %o0+%o1 and the same 8 bytes as a double in %f0+%f1.)
62  *
63  * Note: we cannot use the union trick (which generates better code) for
64  * C++, since `ty' might be a type with a constructor (these may not appear
65  * in a union).
66  *
67  * The extraneous casts through `void *' avoid gcc alignment warnings.
68  */
69 #ifdef __cplusplus
70 #define	__va_8byte(ap, ty) ({ \
71 	int __va_i[2]; \
72 	__va_i[0] = ((int *)(void *)(ap))[0]; \
73 	__va_i[1] = ((int *)(void *)(ap))[1]; \
74 	(ap) += 8; *(ty *)(void *)__va_i; })
75 #else
76 #define	__va_8byte(ap, ty) ({ \
77 	union { ty __d; int __i[2]; } __va_u; \
78 	__va_u.__i[0] = ((int *)(void *)(ap))[0]; \
79 	__va_u.__i[1] = ((int *)(void *)(ap))[1]; \
80 	(ap) += 8; __va_u.__d; })
81 #endif /* __cplusplus */
82 
83 #define va_arg(ap, ty) __extension__ ({ \
84     ty __va_temp; /* to check for invisible-ptr struct-valued args */ \
85     __builtin_classify_type(__va_temp) >= 12 ? \
86 	((ty **)(void *)((ap) += sizeof(ty *)))[-1][0] : \
87     sizeof(ty) == 8 ? __va_8byte(ap, ty) : \
88 	((ty *)(void *)(ap += sizeof(ty)))[-1]; })
89 
90 #endif /* _MACHINE_STDARG_H */
91