xref: /original-bsd/sys/sparc/include/stdarg.h (revision 6afd9275)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * 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 Laboratories.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)stdarg.h	7.3 (Berkeley) 10/15/92
17  *
18  * from: $Header: stdarg.h,v 1.6 92/10/02 00:08:01 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 #define va_start(ap, l)	(__builtin_saveregs(), \
38 			 ap = (char *)__builtin_next_arg())
39 #define va_end(ap)	/* empty */
40 
41 #if __GNUC__ == 1
42 #define __extension__	/* hack for bootstrapping via gcc 1.x */
43 #endif
44 
45 /*
46  * va_arg picks up the next argument of type `ty'.  Appending an
47  * asterisk to ty must produce a pointer to ty (i.e., ty may not be,
48  * e.g., `int (*)()').  In addition, ty must not be any type which
49  * undergoes promotion to some other type (e.g., char): it must
50  * be the promoted type instead.
51  *
52  * Gcc-2.x tries to use ldd/std for double and quad_t values, but Sun's
53  * brain-damaged calling convention does not quad-align these.  Thus,
54  * for 8-byte arguments, we have to pick up the actual value four bytes
55  * at a time, and use type punning (i.e., a union) to produce the result.
56  * (We could also do this with a libc function, actually, by returning
57  * 8 byte integers in %o0+%o1 and the same 8 bytes as a double in %f0+%f1.)
58  */
59 #define va_arg(ap, ty) \
60     (sizeof(ty) == 8 ? __extension__ ({ \
61 	union { ty __d; int __i[2]; } __u; \
62 	__u.__i[0] = ((int *)(ap))[0]; \
63 	__u.__i[1] = ((int *)(ap))[1]; \
64 	(ap) += 8; \
65 	__u.__d; }) : \
66     ((ty *)(ap += sizeof(ty)))[-1])
67 
68 #endif /* _MACHINE_STDARG_H */
69