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