17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate *
227c478bdstevel@tonic-gate * Copyright 2000 Sun Microsystems, Inc.  All rights reserved.
237c478bdstevel@tonic-gate * Use is subject to license terms.
247c478bdstevel@tonic-gate */
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/* This is just like the default gvarargs.h
277c478bdstevel@tonic-gate   except for differences described below.  */
287c478bdstevel@tonic-gate
297c478bdstevel@tonic-gate/* Define __gnuc_va_list.  */
307c478bdstevel@tonic-gate
317c478bdstevel@tonic-gate#ifndef __GNUC_VA_LIST
327c478bdstevel@tonic-gate#define __GNUC_VA_LIST
337c478bdstevel@tonic-gate
347c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#ifdef __sparc_v9__
377c478bdstevel@tonic-gatetypedef long long __va_greg;
387c478bdstevel@tonic-gatetypedef double __va_freg;
397c478bdstevel@tonic-gatetypedef struct {
407c478bdstevel@tonic-gate  __va_greg * __va_next_o;		/* next available %o* register */
417c478bdstevel@tonic-gate  __va_greg * __va_next_o_limit;	/* past last available %o* register */
427c478bdstevel@tonic-gate  __va_freg * __va_next_fp;		/* next available %f* register */
437c478bdstevel@tonic-gate  __va_freg * __va_next_fp_limit;	/* last available %f* register */
447c478bdstevel@tonic-gate  __va_greg * __va_next_stack;		/* next extended word on stack */
457c478bdstevel@tonic-gate} __gnuc_va_list;
467c478bdstevel@tonic-gate#else
477c478bdstevel@tonic-gate#ifndef __svr4__
487c478bdstevel@tonic-gate/* This has to be a char * to be compatible with Sun.
497c478bdstevel@tonic-gate   i.e., we have to pass a `va_list' to vsprintf.  */
507c478bdstevel@tonic-gatetypedef char * __gnuc_va_list;
517c478bdstevel@tonic-gate#else
527c478bdstevel@tonic-gate/* This has to be a void * to be compatible with Sun svr4.
537c478bdstevel@tonic-gate   i.e., we have to pass a `va_list' to vsprintf.  */
547c478bdstevel@tonic-gatetypedef void * __gnuc_va_list;
557c478bdstevel@tonic-gate#endif
567c478bdstevel@tonic-gate#endif /* not __sparc_v9__ */
577c478bdstevel@tonic-gate#endif /* not __GNUC_VA_LIST */
587c478bdstevel@tonic-gate
597c478bdstevel@tonic-gate/* If this is for internal libc use, don't define anything but
607c478bdstevel@tonic-gate   __gnuc_va_list.  */
617c478bdstevel@tonic-gate#if defined (_STDARG_H) || defined (_VARARGS_H)
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gate#ifdef	_KERNEL
647c478bdstevel@tonic-gate/*
657c478bdstevel@tonic-gate * The Solaris kernel stdarg style va_start() even though it includes
667c478bdstevel@tonic-gate * <sys/varargs.h>.
677c478bdstevel@tonic-gate */
687c478bdstevel@tonic-gate#define	_STDARG_H
697c478bdstevel@tonic-gate#undef	_VARARGS_H
707c478bdstevel@tonic-gate#endif	/* _KERNEL */
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#ifdef _STDARG_H
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate#ifdef __sparc_v9__
757c478bdstevel@tonic-gate#define va_start(AP, LASTARG) \
767c478bdstevel@tonic-gate__extension__ \
777c478bdstevel@tonic-gate  ({ \
787c478bdstevel@tonic-gate     AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
797c478bdstevel@tonic-gate     AP.__va_next_o_limit = (AP.__va_next_o + \
807c478bdstevel@tonic-gate			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
817c478bdstevel@tonic-gate     AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
827c478bdstevel@tonic-gate     AP.__va_next_fp_limit = (AP.__va_next_fp + \
837c478bdstevel@tonic-gate			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
847c478bdstevel@tonic-gate     AP.__va_next_stack = (__va_greg *) __builtin_next_arg (LASTARG); \
857c478bdstevel@tonic-gate  })
867c478bdstevel@tonic-gate#else
877c478bdstevel@tonic-gate/* Call __builtin_next_arg even though we aren't using its value, so that
887c478bdstevel@tonic-gate   we can verify that LASTARG is correct.  */
897c478bdstevel@tonic-gate#ifdef __GCC_NEW_VARARGS__
907c478bdstevel@tonic-gate#define va_start(AP, LASTARG) \
917c478bdstevel@tonic-gate  (__builtin_next_arg (LASTARG), AP = (char *) __builtin_saveregs ())
927c478bdstevel@tonic-gate#else
937c478bdstevel@tonic-gate#define va_start(AP, LASTARG)					\
947c478bdstevel@tonic-gate  (__builtin_saveregs (), AP = ((char *) __builtin_next_arg (LASTARG)))
957c478bdstevel@tonic-gate#endif
967c478bdstevel@tonic-gate#endif /* not __sparc_v9__ */
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate#else
997c478bdstevel@tonic-gate
1007c478bdstevel@tonic-gate#define va_alist  __builtin_va_alist
1017c478bdstevel@tonic-gate#define va_dcl    int __builtin_va_alist;...
1027c478bdstevel@tonic-gate
1037c478bdstevel@tonic-gate#ifdef __sparc_v9__
1047c478bdstevel@tonic-gate#ifdef __sparcv9
1057c478bdstevel@tonic-gate#define va_start(AP) \
1067c478bdstevel@tonic-gate__extension__ \
1077c478bdstevel@tonic-gate  ({ \
1087c478bdstevel@tonic-gate     AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
1097c478bdstevel@tonic-gate     AP.__va_next_o_limit = (AP.__va_next_o + \
1107c478bdstevel@tonic-gate			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
1117c478bdstevel@tonic-gate     AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
1127c478bdstevel@tonic-gate     AP.__va_next_fp_limit = (AP.__va_next_fp + \
1137c478bdstevel@tonic-gate			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
1147c478bdstevel@tonic-gate     /* CYGNUS LOCAL dje/sparc64 */ \
1157c478bdstevel@tonic-gate     AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
1167c478bdstevel@tonic-gate       - (__builtin_args_info (0) >= 6 || __builtin_args_info (1) >= 16 ? 1 : 0); \
1177c478bdstevel@tonic-gate  })
1187c478bdstevel@tonic-gate#else	/* __sparcv9 */
1197c478bdstevel@tonic-gate#define va_start(AP) \
1207c478bdstevel@tonic-gate__extension__ \
1217c478bdstevel@tonic-gate  ({ \
1227c478bdstevel@tonic-gate     AP.__va_next_o = (__va_greg *) __builtin_saveregs (); \
1237c478bdstevel@tonic-gate     AP.__va_next_o_limit = (AP.__va_next_o + \
1247c478bdstevel@tonic-gate			     (__builtin_args_info (0) < 6 ? 6 - __builtin_args_info (0) : 0)); \
1257c478bdstevel@tonic-gate     AP.__va_next_fp = (__va_freg *) AP.__va_next_o_limit; \
1267c478bdstevel@tonic-gate     AP.__va_next_fp_limit = (AP.__va_next_fp + \
1277c478bdstevel@tonic-gate			      (__builtin_args_info (1) < 16 ? (16 - __builtin_args_info (1) + 1) / 2 : 0)); \
1287c478bdstevel@tonic-gate     /* CYGNUS LOCAL dje/sparc64 */ \
1297c478bdstevel@tonic-gate     AP.__va_next_stack = (__va_greg *) __builtin_next_arg (__builtin_va_alist) \
1307c478bdstevel@tonic-gate       - (__builtin_args_info (0) >= 6 || __builtin_args_info (1) >= 16 ? 1 : 0); \
1317c478bdstevel@tonic-gate  })
1327c478bdstevel@tonic-gate#endif	/* __sparcv9 */
1337c478bdstevel@tonic-gate#else
1347c478bdstevel@tonic-gate#ifdef __GCC_NEW_VARARGS__
1357c478bdstevel@tonic-gate#define va_start(AP)		((AP) = (char *) __builtin_saveregs ())
1367c478bdstevel@tonic-gate#else
1377c478bdstevel@tonic-gate#define va_start(AP) 						\
1387c478bdstevel@tonic-gate (__builtin_saveregs (), (AP) = ((char *) &__builtin_va_alist))
1397c478bdstevel@tonic-gate#endif
1407c478bdstevel@tonic-gate#endif /* not __sparc_v9__ */
1417c478bdstevel@tonic-gate
1427c478bdstevel@tonic-gate#endif
1437c478bdstevel@tonic-gate
1447c478bdstevel@tonic-gate#ifndef va_end
1457c478bdstevel@tonic-gatevoid va_end (__gnuc_va_list);		/* Defined in libgcc.a */
1467c478bdstevel@tonic-gate
1477c478bdstevel@tonic-gate/* Values returned by __builtin_classify_type.  */
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gateenum __va_type_classes {
1507c478bdstevel@tonic-gate  __no_type_class = -1,
1517c478bdstevel@tonic-gate  __void_type_class,
1527c478bdstevel@tonic-gate  __integer_type_class,
1537c478bdstevel@tonic-gate  __char_type_class,
1547c478bdstevel@tonic-gate  __enumeral_type_class,
1557c478bdstevel@tonic-gate  __boolean_type_class,
1567c478bdstevel@tonic-gate  __pointer_type_class,
1577c478bdstevel@tonic-gate  __reference_type_class,
1587c478bdstevel@tonic-gate  __offset_type_class,
1597c478bdstevel@tonic-gate  __real_type_class,
1607c478bdstevel@tonic-gate  __complex_type_class,
1617c478bdstevel@tonic-gate  __function_type_class,
1627c478bdstevel@tonic-gate  __method_type_class,
1637c478bdstevel@tonic-gate  __record_type_class,
1647c478bdstevel@tonic-gate  __union_type_class,
1657c478bdstevel@tonic-gate  __array_type_class,
1667c478bdstevel@tonic-gate  __string_type_class,
1677c478bdstevel@tonic-gate  __set_type_class,
1687c478bdstevel@tonic-gate  __file_type_class,
1697c478bdstevel@tonic-gate  __lang_type_class
1707c478bdstevel@tonic-gate};
1717c478bdstevel@tonic-gate
1727c478bdstevel@tonic-gate#endif
1737c478bdstevel@tonic-gate#define va_end(pvar)	((void)0)
1747c478bdstevel@tonic-gate
1757c478bdstevel@tonic-gate/* Avoid errors if compiling GCC v2 with GCC v1.  */
1767c478bdstevel@tonic-gate#if __GNUC__ == 1
1777c478bdstevel@tonic-gate#define __extension__
1787c478bdstevel@tonic-gate#endif
1797c478bdstevel@tonic-gate
1807c478bdstevel@tonic-gate/* RECORD_TYPE args passed using the C calling convention are
1817c478bdstevel@tonic-gate   passed by invisible reference.  ??? RECORD_TYPE args passed
1827c478bdstevel@tonic-gate   in the stack are made to be word-aligned; for an aggregate that is
1837c478bdstevel@tonic-gate   not word-aligned, we advance the pointer to the first non-reg slot.  */
1847c478bdstevel@tonic-gate
1857c478bdstevel@tonic-gate#ifdef __sparc_v9__
1867c478bdstevel@tonic-gate
1877c478bdstevel@tonic-gate#define va_arg(pvar,TYPE)					\
1887c478bdstevel@tonic-gate__extension__							\
1897c478bdstevel@tonic-gate(*({int __type = __builtin_classify_type (* (TYPE *) 0);	\
1907c478bdstevel@tonic-gate  void * __result;						\
1917c478bdstevel@tonic-gate  if (__type == __real_type_class)		/* float? */	\
1927c478bdstevel@tonic-gate    {								\
1937c478bdstevel@tonic-gate      __va_freg *__r;						\
1947c478bdstevel@tonic-gate      /* see PASS_IN_REG_P in gcc's sparc.h */			\
1957c478bdstevel@tonic-gate      if (pvar.__va_next_fp < pvar.__va_next_fp_limit		\
1967c478bdstevel@tonic-gate	  && ((__r = (__va_freg *) (((__va_greg) pvar.__va_next_fp + sizeof (TYPE) - 1) & ~(__va_greg) (sizeof (TYPE) - 1))) \
1977c478bdstevel@tonic-gate	      < pvar.__va_next_fp_limit))			\
1987c478bdstevel@tonic-gate	{							\
1997c478bdstevel@tonic-gate	  pvar.__va_next_fp = __r + (sizeof (TYPE) + 7) / 8;	\
2007c478bdstevel@tonic-gate	}							\
2017c478bdstevel@tonic-gate      else							\
2027c478bdstevel@tonic-gate	{							\
2037c478bdstevel@tonic-gate	  __r = (__va_freg *) pvar.__va_next_stack;		\
2047c478bdstevel@tonic-gate	  pvar.__va_next_stack += (sizeof (TYPE) + 7) / 8;	\
2057c478bdstevel@tonic-gate	}							\
2067c478bdstevel@tonic-gate      __result = __r;						\
2077c478bdstevel@tonic-gate    }								\
2087c478bdstevel@tonic-gate  else if (__type < __record_type_class)	/* integer? */	\
2097c478bdstevel@tonic-gate    {								\
2107c478bdstevel@tonic-gate      __va_greg *__r;						\
2117c478bdstevel@tonic-gate      if (pvar.__va_next_o < pvar.__va_next_o_limit)		\
2127c478bdstevel@tonic-gate	__r = pvar.__va_next_o++;				\
2137c478bdstevel@tonic-gate      else							\
2147c478bdstevel@tonic-gate	__r = pvar.__va_next_stack++;				\
2157c478bdstevel@tonic-gate      /* adjust for 4 byte ints */				\
2167c478bdstevel@tonic-gate      __result = (char *) __r + 8 - sizeof (TYPE);		\
2177c478bdstevel@tonic-gate    }								\
2187c478bdstevel@tonic-gate  else /* aggregate object */					\
2197c478bdstevel@tonic-gate    {								\
2207c478bdstevel@tonic-gate      void **__r;						\
2217c478bdstevel@tonic-gate      if (pvar.__va_next_o < pvar.__va_next_o_limit)		\
2227c478bdstevel@tonic-gate	__r = (void **) pvar.__va_next_o++;			\
2237c478bdstevel@tonic-gate      else							\
2247c478bdstevel@tonic-gate	__r = (void **) pvar.__va_next_stack++;			\
2257c478bdstevel@tonic-gate      __result = *__r;						\
2267c478bdstevel@tonic-gate    }								\
2277c478bdstevel@tonic-gate  (TYPE *) __result;}))
2287c478bdstevel@tonic-gate
2297c478bdstevel@tonic-gate#else /* not __sparc_v9__ */
2307c478bdstevel@tonic-gate
2317c478bdstevel@tonic-gate#define __va_rounded_size(TYPE)  \
2327c478bdstevel@tonic-gate  (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
2337c478bdstevel@tonic-gate
2347c478bdstevel@tonic-gate/* We don't declare the union member `d' to have type TYPE
2357c478bdstevel@tonic-gate   because that would lose in C++ if TYPE has a constructor.  */
2367c478bdstevel@tonic-gate/* We cast to void * and then to TYPE * because this avoids
2377c478bdstevel@tonic-gate   a warning about increasing the alignment requirement.
2387c478bdstevel@tonic-gate   The casts to char * avoid warnings about invalid pointer arithmetic.  */
2397c478bdstevel@tonic-gate#define va_arg(pvar,TYPE)					\
2407c478bdstevel@tonic-gate__extension__							\
2417c478bdstevel@tonic-gate(*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \
2427c478bdstevel@tonic-gate      || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \
2437c478bdstevel@tonic-gate	  && sizeof (TYPE) == 16))				\
2447c478bdstevel@tonic-gate    ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *),	\
2457c478bdstevel@tonic-gate       *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \
2467c478bdstevel@tonic-gate    : __va_rounded_size (TYPE) == 8				\
2477c478bdstevel@tonic-gate    ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u;	\
2487c478bdstevel@tonic-gate	 __u.__i[0] = ((int *) (void *) (pvar))[0];		\
2497c478bdstevel@tonic-gate	 __u.__i[1] = ((int *) (void *) (pvar))[1];		\
2507c478bdstevel@tonic-gate	 (pvar) = (char *)(pvar) + 8;				\
2517c478bdstevel@tonic-gate	 (TYPE *) (void *) __u.__d; })				\
2527c478bdstevel@tonic-gate    : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE),	\
2537c478bdstevel@tonic-gate       ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));}))
2547c478bdstevel@tonic-gate#endif /* not __sparc_v9__ */
2557c478bdstevel@tonic-gate
2567c478bdstevel@tonic-gate#endif /* defined (_STDARG_H) || defined (_VARARGS_H) */
257