xref: /titanic_50/usr/src/uts/common/sys/va-sparc.h (revision c869993e79c1eafbec61a56bf6cea848fe754c71)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #ifdef __sparc_v9__
37 typedef long long __va_greg;
38 typedef double __va_freg;
39 typedef struct {
40   __va_greg * __va_next_o;		/* next available %o* register */
41   __va_greg * __va_next_o_limit;	/* past last available %o* register */
42   __va_freg * __va_next_fp;		/* next available %f* register */
43   __va_freg * __va_next_fp_limit;	/* last available %f* register */
44   __va_greg * __va_next_stack;		/* next extended word on stack */
45 } __gnuc_va_list;
46 #else
47 #ifndef __svr4__
48 /* This has to be a char * to be compatible with Sun.
49    i.e., we have to pass a `va_list' to vsprintf.  */
50 typedef char * __gnuc_va_list;
51 #else
52 /* This has to be a void * to be compatible with Sun svr4.
53    i.e., we have to pass a `va_list' to vsprintf.  */
54 typedef void * __gnuc_va_list;
55 #endif
56 #endif /* not __sparc_v9__ */
57 #endif /* not __GNUC_VA_LIST */
58 
59 /* If this is for internal libc use, don't define anything but
60    __gnuc_va_list.  */
61 #if defined (_STDARG_H) || defined (_VARARGS_H)
62 
63 #ifdef	_KERNEL
64 /*
65  * The Solaris kernel stdarg style va_start() even though it includes
66  * <sys/varargs.h>.
67  */
68 #define	_STDARG_H
69 #undef	_VARARGS_H
70 #endif	/* _KERNEL */
71 
72 #ifdef _STDARG_H
73 
74 #ifdef __sparc_v9__
75 #define va_start(AP, LASTARG) \
76 __extension__ \
77   ({ \
78      AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
79      AP.__va_next_o_limit = (AP.__va_next_o + \
80 			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
81      AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
82      AP.__va_next_fp_limit = (AP.__va_next_fp + \
83 			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
84      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (LASTARG); \
85   })
86 #else
87 /* Call __builtin_next_arg even though we aren't using its value, so that
88    we can verify that LASTARG is correct.  */
89 #ifdef __GCC_NEW_VARARGS__
90 #define va_start(AP, LASTARG) \
91   (__builtin_next_arg (LASTARG), AP = (char *) __builtin_saveregs ())
92 #else
93 #define va_start(AP, LASTARG)					\
94   (__builtin_saveregs (), AP = ((char *) __builtin_next_arg (LASTARG)))
95 #endif
96 #endif /* not __sparc_v9__ */
97 
98 #else
99 
100 #define va_alist  __builtin_va_alist
101 #define va_dcl    int __builtin_va_alist;...
102 
103 #ifdef __sparc_v9__
104 #ifdef __sparcv9
105 #define va_start(AP) \
106 __extension__ \
107   ({ \
108      AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
109      AP.__va_next_o_limit = (AP.__va_next_o + \
110 			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
111      AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
112      AP.__va_next_fp_limit = (AP.__va_next_fp + \
113 			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
114      /* CYGNUS LOCAL dje/sparc64 */ \
115      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
116        - (__builtin_args_info (0) >= 6 || __builtin_args_info (1) >= 16 ? 1 : 0); \
117   })
118 #else	/* __sparcv9 */
119 #define va_start(AP) \
120 __extension__ \
121   ({ \
122      AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
123      AP.__va_next_o_limit = (AP.__va_next_o + \
124 			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
125      AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
126      AP.__va_next_fp_limit = (AP.__va_next_fp + \
127 			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
128      /* CYGNUS LOCAL dje/sparc64 */ \
129      AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
130        - (__builtin_args_info (0) >= 6 || __builtin_args_info (1) >= 16 ? 1 : 0); \
131   })
132 #endif	/* __sparcv9 */
133 #else
134 #ifdef __GCC_NEW_VARARGS__
135 #define va_start(AP)		((AP) = (char *) __builtin_saveregs ())
136 #else
137 #define va_start(AP) 						\
138  (__builtin_saveregs (), (AP) = ((char *) &__builtin_va_alist))
139 #endif
140 #endif /* not __sparc_v9__ */
141 
142 #endif
143 
144 #ifndef va_end
145 void va_end (__gnuc_va_list);		/* Defined in libgcc.a */
146 
147 /* Values returned by __builtin_classify_type.  */
148 
149 enum __va_type_classes {
150   __no_type_class = -1,
151   __void_type_class,
152   __integer_type_class,
153   __char_type_class,
154   __enumeral_type_class,
155   __boolean_type_class,
156   __pointer_type_class,
157   __reference_type_class,
158   __offset_type_class,
159   __real_type_class,
160   __complex_type_class,
161   __function_type_class,
162   __method_type_class,
163   __record_type_class,
164   __union_type_class,
165   __array_type_class,
166   __string_type_class,
167   __set_type_class,
168   __file_type_class,
169   __lang_type_class
170 };
171 
172 #endif
173 #define va_end(pvar)	((void)0)
174 
175 /* Avoid errors if compiling GCC v2 with GCC v1.  */
176 #if __GNUC__ == 1
177 #define __extension__
178 #endif
179 
180 /* RECORD_TYPE args passed using the C calling convention are
181    passed by invisible reference.  ??? RECORD_TYPE args passed
182    in the stack are made to be word-aligned; for an aggregate that is
183    not word-aligned, we advance the pointer to the first non-reg slot.  */
184 
185 #ifdef __sparc_v9__
186 
187 #define va_arg(pvar,TYPE)					\
188 __extension__							\
189 (*({int __type = __builtin_classify_type (* (TYPE *) 0);	\
190   void * __result;						\
191   if (__type == __real_type_class)		/* float? */	\
192     {								\
193       __va_freg *__r;						\
194       /* see PASS_IN_REG_P in gcc's sparc.h */			\
195       if (pvar.__va_next_fp < pvar.__va_next_fp_limit		\
196 	  && ((__r = (__va_freg *) (((__va_greg) pvar.__va_next_fp + sizeof (TYPE) - 1) & ~(__va_greg) (sizeof (TYPE) - 1))) \
197 	      < pvar.__va_next_fp_limit))			\
198 	{							\
199 	  pvar.__va_next_fp = __r + (sizeof (TYPE) + 7) / 8;	\
200 	}							\
201       else							\
202 	{							\
203 	  __r = (__va_freg *) pvar.__va_next_stack;		\
204 	  pvar.__va_next_stack += (sizeof (TYPE) + 7) / 8;	\
205 	}							\
206       __result = __r;						\
207     }								\
208   else if (__type < __record_type_class)	/* integer? */	\
209     {								\
210       __va_greg *__r;						\
211       if (pvar.__va_next_o < pvar.__va_next_o_limit)		\
212 	__r = pvar.__va_next_o++;				\
213       else							\
214 	__r = pvar.__va_next_stack++;				\
215       /* adjust for 4 byte ints */				\
216       __result = (char *) __r + 8 - sizeof (TYPE);		\
217     }								\
218   else /* aggregate object */					\
219     {								\
220       void **__r;						\
221       if (pvar.__va_next_o < pvar.__va_next_o_limit)		\
222 	__r = (void **) pvar.__va_next_o++;			\
223       else							\
224 	__r = (void **) pvar.__va_next_stack++;			\
225       __result = *__r;						\
226     }								\
227   (TYPE *) __result;}))
228 
229 #else /* not __sparc_v9__ */
230 
231 #define __va_rounded_size(TYPE)  \
232   (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
233 
234 /* We don't declare the union member `d' to have type TYPE
235    because that would lose in C++ if TYPE has a constructor.  */
236 /* We cast to void * and then to TYPE * because this avoids
237    a warning about increasing the alignment requirement.
238    The casts to char * avoid warnings about invalid pointer arithmetic.  */
239 #define va_arg(pvar,TYPE)					\
240 __extension__							\
241 (*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \
242       || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \
243 	  && sizeof (TYPE) == 16))				\
244     ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *),	\
245        *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \
246     : __va_rounded_size (TYPE) == 8				\
247     ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u;	\
248 	 __u.__i[0] = ((int *) (void *) (pvar))[0];		\
249 	 __u.__i[1] = ((int *) (void *) (pvar))[1];		\
250 	 (pvar) = (char *)(pvar) + 8;				\
251 	 (TYPE *) (void *) __u.__d; })				\
252     : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE),	\
253        ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));}))
254 #endif /* not __sparc_v9__ */
255 
256 #endif /* defined (_STDARG_H) || defined (_VARARGS_H) */
257