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