xref: /illumos-gate/usr/src/uts/common/sys/va-sparc.h (revision e3ae4b35c024af1196582063ecee3ab79367227d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  *
22  * Copyright 2000 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /* This is just like the default gvarargs.h
27    except for differences described below.  */
28 
29 /* Define __gnuc_va_list.  */
30 
31 #ifndef __GNUC_VA_LIST
32 #define __GNUC_VA_LIST
33 
34 #ifdef __sparc_v9__
35 typedef long long __va_greg;
36 typedef double __va_freg;
37 typedef struct {
38   __va_greg * __va_next_o;		/* next available %o* register */
39   __va_greg * __va_next_o_limit;	/* past last available %o* register */
40   __va_freg * __va_next_fp;		/* next available %f* register */
41   __va_freg * __va_next_fp_limit;	/* last available %f* register */
42   __va_greg * __va_next_stack;		/* next extended word on stack */
43 } __gnuc_va_list;
44 #else
45 #ifndef __svr4__
46 /* This has to be a char * to be compatible with Sun.
47    i.e., we have to pass a `va_list' to vsprintf.  */
48 typedef char * __gnuc_va_list;
49 #else
50 /* This has to be a void * to be compatible with Sun svr4.
51    i.e., we have to pass a `va_list' to vsprintf.  */
52 typedef void * __gnuc_va_list;
53 #endif
54 #endif /* not __sparc_v9__ */
55 #endif /* not __GNUC_VA_LIST */
56 
57 /* If this is for internal libc use, don't define anything but
58    __gnuc_va_list.  */
59 #if defined (_STDARG_H) || defined (_VARARGS_H)
60 
61 #ifdef	_KERNEL
62 /*
63  * The Solaris kernel stdarg style va_start() even though it includes
64  * <sys/varargs.h>.
65  */
66 #define	_STDARG_H
67 #undef	_VARARGS_H
68 #endif	/* _KERNEL */
69 
70 #ifdef _STDARG_H
71 
72 #ifdef __sparc_v9__
73 #define va_start(AP, LASTARG) \
74 __extension__ \
75   ({ \
76      AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
77      AP.__va_next_o_limit = (AP.__va_next_o + \
78 			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
79      AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
80      AP.__va_next_fp_limit = (AP.__va_next_fp + \
81 			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
82      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (LASTARG); \
83   })
84 #else
85 /* Call __builtin_next_arg even though we aren't using its value, so that
86    we can verify that LASTARG is correct.  */
87 #ifdef __GCC_NEW_VARARGS__
88 #define va_start(AP, LASTARG) \
89   (__builtin_next_arg (LASTARG), AP = (char *) __builtin_saveregs ())
90 #else
91 #define va_start(AP, LASTARG)					\
92   (__builtin_saveregs (), AP = ((char *) __builtin_next_arg (LASTARG)))
93 #endif
94 #endif /* not __sparc_v9__ */
95 
96 #else
97 
98 #define va_alist  __builtin_va_alist
99 #define va_dcl    int __builtin_va_alist;...
100 
101 #ifdef __sparc_v9__
102 #ifdef __sparcv9
103 #define va_start(AP) \
104 __extension__ \
105   ({ \
106      AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
107      AP.__va_next_o_limit = (AP.__va_next_o + \
108 			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
109      AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
110      AP.__va_next_fp_limit = (AP.__va_next_fp + \
111 			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
112      /* CYGNUS LOCAL dje/sparc64 */ \
113      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
114        - (__builtin_args_info (0) >= 6 || __builtin_args_info (1) >= 16 ? 1 : 0); \
115   })
116 #else	/* __sparcv9 */
117 #define va_start(AP) \
118 __extension__ \
119   ({ \
120      AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
121      AP.__va_next_o_limit = (AP.__va_next_o + \
122 			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
123      AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
124      AP.__va_next_fp_limit = (AP.__va_next_fp + \
125 			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
126      /* CYGNUS LOCAL dje/sparc64 */ \
127      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
128        - (__builtin_args_info (0) >= 6 || __builtin_args_info (1) >= 16 ? 1 : 0); \
129   })
130 #endif	/* __sparcv9 */
131 #else
132 #ifdef __GCC_NEW_VARARGS__
133 #define va_start(AP)		((AP) = (char *) __builtin_saveregs ())
134 #else
135 #define va_start(AP) 						\
136  (__builtin_saveregs (), (AP) = ((char *) &__builtin_va_alist))
137 #endif
138 #endif /* not __sparc_v9__ */
139 
140 #endif
141 
142 #ifndef va_end
143 void va_end (__gnuc_va_list);		/* Defined in libgcc.a */
144 
145 /* Values returned by __builtin_classify_type.  */
146 
147 enum __va_type_classes {
148   __no_type_class = -1,
149   __void_type_class,
150   __integer_type_class,
151   __char_type_class,
152   __enumeral_type_class,
153   __boolean_type_class,
154   __pointer_type_class,
155   __reference_type_class,
156   __offset_type_class,
157   __real_type_class,
158   __complex_type_class,
159   __function_type_class,
160   __method_type_class,
161   __record_type_class,
162   __union_type_class,
163   __array_type_class,
164   __string_type_class,
165   __set_type_class,
166   __file_type_class,
167   __lang_type_class
168 };
169 
170 #endif
171 #define va_end(pvar)	((void)0)
172 
173 /* Avoid errors if compiling GCC v2 with GCC v1.  */
174 #if __GNUC__ == 1
175 #define __extension__
176 #endif
177 
178 /* RECORD_TYPE args passed using the C calling convention are
179    passed by invisible reference.  ??? RECORD_TYPE args passed
180    in the stack are made to be word-aligned; for an aggregate that is
181    not word-aligned, we advance the pointer to the first non-reg slot.  */
182 
183 #ifdef __sparc_v9__
184 
185 #define va_arg(pvar,TYPE)					\
186 __extension__							\
187 (*({int __type = __builtin_classify_type (* (TYPE *) 0);	\
188   void * __result;						\
189   if (__type == __real_type_class)		/* float? */	\
190     {								\
191       __va_freg *__r;						\
192       /* see PASS_IN_REG_P in gcc's sparc.h */			\
193       if (pvar.__va_next_fp < pvar.__va_next_fp_limit		\
194 	  && ((__r = (__va_freg *) (((__va_greg) pvar.__va_next_fp + sizeof (TYPE) - 1) & ~(__va_greg) (sizeof (TYPE) - 1))) \
195 	      < pvar.__va_next_fp_limit))			\
196 	{							\
197 	  pvar.__va_next_fp = __r + (sizeof (TYPE) + 7) / 8;	\
198 	}							\
199       else							\
200 	{							\
201 	  __r = (__va_freg *) pvar.__va_next_stack;		\
202 	  pvar.__va_next_stack += (sizeof (TYPE) + 7) / 8;	\
203 	}							\
204       __result = __r;						\
205     }								\
206   else if (__type < __record_type_class)	/* integer? */	\
207     {								\
208       __va_greg *__r;						\
209       if (pvar.__va_next_o < pvar.__va_next_o_limit)		\
210 	__r = pvar.__va_next_o++;				\
211       else							\
212 	__r = pvar.__va_next_stack++;				\
213       /* adjust for 4 byte ints */				\
214       __result = (char *) __r + 8 - sizeof (TYPE);		\
215     }								\
216   else /* aggregate object */					\
217     {								\
218       void **__r;						\
219       if (pvar.__va_next_o < pvar.__va_next_o_limit)		\
220 	__r = (void **) pvar.__va_next_o++;			\
221       else							\
222 	__r = (void **) pvar.__va_next_stack++;			\
223       __result = *__r;						\
224     }								\
225   (TYPE *) __result;}))
226 
227 #else /* not __sparc_v9__ */
228 
229 #define __va_rounded_size(TYPE)  \
230   (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
231 
232 /* We don't declare the union member `d' to have type TYPE
233    because that would lose in C++ if TYPE has a constructor.  */
234 /* We cast to void * and then to TYPE * because this avoids
235    a warning about increasing the alignment requirement.
236    The casts to char * avoid warnings about invalid pointer arithmetic.  */
237 #define va_arg(pvar,TYPE)					\
238 __extension__							\
239 (*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \
240       || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \
241 	  && sizeof (TYPE) == 16))				\
242     ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *),	\
243        *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \
244     : __va_rounded_size (TYPE) == 8				\
245     ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u;	\
246 	 __u.__i[0] = ((int *) (void *) (pvar))[0];		\
247 	 __u.__i[1] = ((int *) (void *) (pvar))[1];		\
248 	 (pvar) = (char *)(pvar) + 8;				\
249 	 (TYPE *) (void *) __u.__d; })				\
250     : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE),	\
251        ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));}))
252 #endif /* not __sparc_v9__ */
253 
254 #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */
255