Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / powerpc / include / stdarg.h
blobce55666c3de1e3910169bbac90116b4577396e30
1 /* $NetBSD: stdarg.h,v 1.15 2005/12/11 12:18:43 christos Exp $ */
3 /*-
4 * Copyright (c) 2000 Tsubai Masanari. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef _POWERPC_STDARG_H_
30 #define _POWERPC_STDARG_H_
32 #include <machine/ansi.h>
33 #include <sys/featuretest.h>
35 #if 0
36 typedef struct {
37 char __gpr; /* GPR offset */
38 char __fpr; /* FPR offset */
39 char __pad[2];
40 char *__stack; /* args passed on stack */
41 char *__base; /* args passed by registers (r3-r10, f1-f8) */
42 } va_list;
43 #endif
45 typedef _BSD_VA_LIST_ va_list;
47 #ifdef __lint__
49 #define va_start(ap, last) ((ap) = *(va_list *)0)
50 #define va_arg(ap, type) (*(type *)(void *)&(ap))
51 #define va_end(ap)
52 #define __va_copy(dest, src) ((dest) = (src))
54 #elif __GNUC_PREREQ__(3, 0)
56 #define va_start(ap, last) __builtin_stdarg_start((ap), last)
57 #define va_arg(ap, type) __builtin_va_arg((ap), type)
58 #define va_end(ap) __builtin_va_end((ap))
59 #define __va_copy(dest, src) __builtin_va_copy((dest), (src))
61 #elif defined(__PCC__)
63 #define va_start(ap, last) __builtin_stdarg_start((ap), last)
64 #define va_arg(ap, type) __builtin_va_arg((ap), type)
65 #define va_end(ap) __builtin_va_end((ap))
66 #define __va_copy(dest, src) __builtin_va_copy((dest), (src))
68 #else
70 #if __GNUC_PREREQ__(2, 95)
71 #define va_start(ap, last) \
72 (__builtin_next_arg(last), \
73 (ap) = *(va_list *)__builtin_saveregs())
74 #else
75 #define va_start(ap, last) \
76 (__builtin_next_arg(last), \
77 (ap).__stack = __va_stack_args, \
78 (ap).__base = __va_reg_args, \
79 (ap).__gpr = __va_first_gpr, \
80 (ap).__fpr = __va_first_fpr)
82 #define __va_first_gpr (__builtin_args_info(0))
83 #define __va_first_fpr (__builtin_args_info(1) - 32 - 1)
84 #define __va_stack_args \
85 ((char *)__builtin_saveregs() + \
86 (__va_first_gpr >= 8 ? __va_first_gpr - 8 : 0) * sizeof(int))
87 #define __va_reg_args \
88 ((char *)__builtin_frame_address(0) + __builtin_args_info(4))
89 #endif /* 2.95 */
91 /* From gcc/typeclass.h */
92 #define __INTEGER_TYPE_CLASS 1
93 #define __REAL_TYPE_CLASS 8
94 #define __RECORD_TYPE_CLASS 12
96 #if __GNUC_PREREQ__(2, 95)
97 #define __va_longlong(type) \
98 (sizeof(type) == 8 && \
99 (__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS || \
100 __builtin_classify_type(*(type *)0) == __INTEGER_TYPE_CLASS))
101 #else
102 /* XXX gcc bug compatibility */
103 #define __va_longlong(type) \
104 (__builtin_classify_type(*(type *)0) == __INTEGER_TYPE_CLASS && \
105 sizeof(type) == 8)
106 #endif
108 #ifdef _SOFT_FLOAT
109 #define __va_double(type) 0
110 #else
111 #define __va_double(type) \
112 (__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS)
113 #endif
115 #define __va_struct(type) \
116 (__builtin_classify_type(*(type *)0) >= __RECORD_TYPE_CLASS)
118 #define __va_size(type) \
119 ((sizeof(type) + sizeof(int) - 1) / sizeof(int) * sizeof(int))
121 #define __va_savedgpr(ap, type) \
122 ((ap).__base + (ap).__gpr * sizeof(int) - sizeof(type))
124 #define __va_savedfpr(ap, type) \
125 ((ap).__base + 8 * sizeof(int) + (ap).__fpr * sizeof(double) - \
126 sizeof(type))
128 #define __va_stack(ap, type) \
129 ((ap).__stack += __va_size(type) + \
130 (__va_longlong(type) ? (int)(ap).__stack & 4 : 0), \
131 (ap).__stack - sizeof(type))
133 #define __va_gpr(ap, type) \
134 ((ap).__gpr += __va_size(type) / sizeof(int) + \
135 (__va_longlong(type) ? (ap).__gpr & 1 : 0), \
136 (ap).__gpr <= 8 ? __va_savedgpr(ap, type) : __va_stack(ap, type))
138 #define __va_fpr(ap, type) \
139 ((ap).__fpr++, \
140 (ap).__fpr <= 8 ? __va_savedfpr(ap, type) : __va_stack(ap, type))
142 #define va_arg(ap, type) \
143 (*(type *)(__va_struct(type) ? (*(void **)__va_gpr(ap, void *)) : \
144 __va_double(type) ? __va_fpr(ap, type) : \
145 __va_gpr(ap, type)))
147 #define va_end(ap)
148 #define __va_copy(dest, src) ((dest) = (src))
150 #endif /* __lint__ */
152 #if !defined(_ANSI_SOURCE) && \
153 (defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L || \
154 defined(_NETBSD_SOURCE))
155 #define va_copy(dest, src) __va_copy(dest, src)
156 #endif
158 #endif /* _POWERPC_STDARG_H_ */