Annotation of sys/arch/mips64/include/stdarg.h, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: stdarg.h,v 1.6 2006/05/14 21:11:07 robert Exp $ */
2:
3: /*-
4: * Copyright (c) 1992, 1993
5: * The Regents of the University of California. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. Neither the name of the University nor the names of its contributors
16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: *
31: * @(#)stdarg.h 8.1 (Berkeley) 6/10/93
32: */
33:
34: #ifndef _MIPS_STDARG_H_
35: #define _MIPS_STDARG_H_
36:
37: #include <sys/cdefs.h>
38: #include <machine/_types.h>
39:
40: typedef __va_list va_list;
41:
42: #ifndef __GNUC_VA_LIST
43: #define __GNUC_VA_LIST
44: #if defined (__mips_eabi) && ! defined (__mips_soft_float) && ! defined (__mips_single_float)
45:
46: typedef struct {
47: /* Pointer to FP regs. */
48: char *__fp_regs;
49: /* Number of FP regs remaining. */
50: int __fp_left;
51: /* Pointer to GP regs followed by stack parameters. */
52: char *__gp_regs;
53: } __gnuc_va_list;
54:
55: #else /* ! (defined (__mips_eabi) && ! defined (__mips_soft_float) && ! defined (__mips_single_float)) */
56:
57: typedef char * __gnuc_va_list;
58:
59: #endif /* ! (defined (__mips_eabi) && ! defined (__mips_soft_float) && ! defined (__mips_single_float)) */
60: #endif /* not __GNUC_VA_LIST */
61:
62: /* If this is for internal libc use, don't define anything but __gnuc_va_list */
63:
64: #ifndef _VA_MIPS_H_ENUM
65: #define _VA_MIPS_H_ENUM
66: enum {
67: __no_type_class = -1,
68: __void_type_class,
69: __integer_type_class,
70: __char_type_class,
71: __enumeral_type_class,
72: __boolean_type_class,
73: __pointer_type_class,
74: __reference_type_class,
75: __offset_type_class,
76: __real_type_class,
77: __complex_type_class,
78: __function_type_class,
79: __method_type_class,
80: __record_type_class,
81: __union_type_class,
82: __array_type_class,
83: __string_type_class,
84: __set_type_class,
85: __file_type_class,
86: __lang_type_class
87: };
88: #endif
89:
90: #define __va_ellipsis ...
91:
92: #ifdef __mips64__
93: #define __va_rounded_size(__TYPE) \
94: (((sizeof (__TYPE) + 8 - 1) / 8) * 8)
95: #else
96: #define __va_rounded_size(__TYPE) \
97: (((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
98: #endif
99:
100: #ifdef __mips64__
101: #define __va_reg_size 8
102: #else
103: #define __va_reg_size 4
104: #endif
105:
106: #if defined (__mips_eabi)
107: #if ! defined (__mips_soft_float) && ! defined (__mips_single_float)
108: #ifdef __mips64__
109: #define va_start(__AP, __LASTARG) \
110: (__AP.__gp_regs = ((char *) __builtin_next_arg (__LASTARG) \
111: - (__builtin_args_info (2) < 8 \
112: ? (8 - __builtin_args_info (2)) * __va_reg_size \
113: : 0)), \
114: __AP.__fp_left = 8 - __builtin_args_info (3), \
115: __AP.__fp_regs = __AP.__gp_regs - __AP.__fp_left * __va_reg_size)
116: #else /* ! defined (__mips64__) */
117: #define va_start(__AP, __LASTARG) \
118: (__AP.__gp_regs = ((char *) __builtin_next_arg (__LASTARG) \
119: - (__builtin_args_info (2) < 8 \
120: ? (8 - __builtin_args_info (2)) * __va_reg_size \
121: : 0)), \
122: __AP.__fp_left = (8 - __builtin_args_info (3)) / 2, \
123: __AP.__fp_regs = __AP.__gp_regs - __AP.__fp_left * 8, \
124: __AP.__fp_regs = (char *) ((int) __AP.__fp_regs & -8))
125: #endif /* ! defined (__mips64__) */
126: #else /* ! (! defined (__mips_soft_float) && ! defined (__mips_single_float) ) */
127: #define va_start(__AP, __LASTARG) \
128: (__AP = ((__gnuc_va_list) __builtin_next_arg (__LASTARG) \
129: - (__builtin_args_info (2) >= 8 ? 0 \
130: : (8 - __builtin_args_info (2)) * __va_reg_size)))
131: #endif /* ! (! defined (__mips_soft_float) && ! defined (__mips_single_float) ) */
132: #else /* ! defined (__mips_eabi) */
133: #define va_start(__AP, __LASTARG) \
134: (__AP = (__gnuc_va_list) __builtin_next_arg (__LASTARG))
135: #endif /* ! (defined (__mips_eabi) && ! defined (__mips_soft_float) && ! defined (__mips_single_float)) */
136:
137: #ifndef va_end
138: void va_end (__gnuc_va_list); /* Defined in libgcc.a */
139: #endif
140: #define va_end(__AP)
141:
142: #if defined (__mips_eabi)
143:
144: #if ! defined (__mips_soft_float) && ! defined (__mips_single_float)
145: #ifdef __mips64__
146: #define __va_next_addr(__AP, __type) \
147: ((__builtin_classify_type (*(__type *) 0) == __real_type_class \
148: && __AP.__fp_left > 0) \
149: ? (--__AP.__fp_left, (__AP.__fp_regs += 8) - 8) \
150: : (__AP.__gp_regs += __va_reg_size) - __va_reg_size)
151: #else
152: #define __va_next_addr(__AP, __type) \
153: ((__builtin_classify_type (*(__type *) 0) == __real_type_class \
154: && __AP.__fp_left > 0) \
155: ? (--__AP.__fp_left, (__AP.__fp_regs += 8) - 8) \
156: : (((__builtin_classify_type (* (__type *) 0) < __record_type_class \
157: && __alignof__ (__type) > 4) \
158: ? __AP.__gp_regs = (char *) (((int) __AP.__gp_regs + 8 - 1) & -8) \
159: : (char *) 0), \
160: (__builtin_classify_type (* (__type *) 0) >= __record_type_class \
161: ? (__AP.__gp_regs += __va_reg_size) - __va_reg_size \
162: : ((__AP.__gp_regs += __va_rounded_size (__type)) \
163: - __va_rounded_size (__type)))))
164: #endif
165: #else /* ! (! defined (__mips_soft_float) && ! defined (__mips_single_float)) */
166: #ifdef __mips64__
167: #define __va_next_addr(__AP, __type) \
168: ((__AP += __va_reg_size) - __va_reg_size)
169: #else
170: #define __va_next_addr(__AP, __type) \
171: (((__builtin_classify_type (* (__type *) 0) < __record_type_class \
172: && __alignof__ (__type) > 4) \
173: ? __AP = (char *) (((__PTRDIFF_TYPE__) __AP + 8 - 1) & -8) \
174: : (char *) 0), \
175: (__builtin_classify_type (* (__type *) 0) >= __record_type_class \
176: ? (__AP += __va_reg_size) - __va_reg_size \
177: : ((__AP += __va_rounded_size (__type)) \
178: - __va_rounded_size (__type))))
179: #endif
180: #endif /* ! (! defined (__mips_soft_float) && ! defined (__mips_single_float)) */
181:
182: #ifdef __MIPSEB__
183: #define va_arg(__AP, __type) \
184: ((__va_rounded_size (__type) <= __va_reg_size) \
185: ? *(__type *) (void *) (__va_next_addr (__AP, __type) \
186: + __va_reg_size \
187: - sizeof (__type)) \
188: : (__builtin_classify_type (*(__type *) 0) >= __record_type_class \
189: ? **(__type **) (void *) (__va_next_addr (__AP, __type) \
190: + __va_reg_size \
191: - sizeof (char *)) \
192: : *(__type *) (void *) __va_next_addr (__AP, __type)))
193: #else
194: #define va_arg(__AP, __type) \
195: ((__va_rounded_size (__type) <= __va_reg_size) \
196: ? *(__type *) (void *) __va_next_addr (__AP, __type) \
197: : (__builtin_classify_type (* (__type *) 0) >= __record_type_class \
198: ? **(__type **) (void *) __va_next_addr (__AP, __type) \
199: : *(__type *) (void *) __va_next_addr (__AP, __type)))
200: #endif
201:
202: #else /* ! defined (__mips_eabi) */
203:
204: /* We cast to void * and then to TYPE * because this avoids
205: a warning about increasing the alignment requirement. */
206: /* The __mips64__ cases are reversed from the 32 bit cases, because the standard
207: 32 bit calling convention left-aligns all parameters smaller than a word,
208: whereas the __mips64__ calling convention does not (and hence they are
209: right aligned). */
210: #ifdef __mips64__
211: #ifdef __MIPSEB__
212: #define va_arg(__AP, __type) \
213: ((__type *) (void *) (__AP = (char *) \
214: ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \
215: + __va_rounded_size (__type))))[-1]
216: #else
217: #define va_arg(__AP, __type) \
218: ((__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \
219: + __va_rounded_size (__type))), \
220: *(__type *) (void *) (__AP - __va_rounded_size (__type)))
221: #endif
222:
223: #else /* not __mips64__ */
224:
225: #ifdef __MIPSEB__
226: /* For big-endian machines. */
227: #define va_arg(__AP, __type) \
228: ((__AP = (char *) ((__alignof__ (__type) > 4 \
229: ? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
230: : ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
231: + __va_rounded_size (__type))), \
232: *(__type *) (void *) (__AP - __va_rounded_size (__type)))
233: #else
234: /* For little-endian machines. */
235: #define va_arg(__AP, __type) \
236: ((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \
237: ? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \
238: : ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \
239: + __va_rounded_size(__type))))[-1]
240: #endif
241: #endif
242: #endif /* ! defined (__mips_eabi) */
243:
244: /* Copy __gnuc_va_list into another variable of this type. */
245: #define __va_copy(dest, src) (dest) = (src)
246: #if __ISO_C_VISIBLE >= 1999
247: #define va_copy __va_copy
248: #endif
249:
250: #endif /* !_MIPS_STDARG_H_ */
CVSweb