stdarg.h revision 85169
1/*- 2 * Copyright (c) 2000 Tsubai Masanari. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. The name of the author may not be used to endorse or promote products 13 * derived from this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $NetBSD: stdarg.h,v 1.5 2000/02/27 17:50:21 tsubai Exp $ 27 * $FreeBSD: head/sys/powerpc/include/stdarg.h 85169 2001-10-19 16:15:46Z mp $ 28 */ 29 30#ifndef _POWERPC_STDARG_H_ 31#define _POWERPC_STDARG_H_ 32 33#include <machine/ansi.h> 34 35typedef _BSD_VA_LIST_ va_list; 36 37#ifdef __lint__ 38 39#define va_start(ap, last) ((ap) = *(va_list *)0) 40#define va_arg(ap, type) (*(type *)(void *)&(ap)) 41 42#else 43 44#if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 95) 45#define va_start(ap, last) \ 46 (__builtin_next_arg(last), \ 47 __builtin_memcpy((void *)&(ap), __builtin_saveregs (), \ 48 sizeof(__gnuc_va_list))) 49#else 50#define va_start(ap, last) \ 51 (__builtin_next_arg(last), \ 52 (ap).__stack = __va_stack_args, \ 53 (ap).__base = __va_reg_args, \ 54 (ap).__gpr = __va_first_gpr, \ 55 (ap).__fpr = __va_first_fpr) 56#endif 57 58#define __va_first_gpr (__builtin_args_info(0)) 59#define __va_first_fpr (__builtin_args_info(1) - 32 - 1) 60#define __va_stack_args \ 61 ((char *)__builtin_saveregs() + \ 62 (__va_first_gpr >= 8 ? __va_first_gpr - 8 : 0) * sizeof(int)) 63#define __va_reg_args \ 64 ((char *)__builtin_frame_address(0) + __builtin_args_info(4)) 65 66#define __INTEGER_TYPE_CLASS 1 67#define __REAL_TYPE_CLASS 8 68#define __RECORD_TYPE_CLASS 12 69 70#define __va_longlong(type) \ 71 (__builtin_classify_type(*(type *)0) == __INTEGER_TYPE_CLASS && \ 72 sizeof(type) == 8) 73 74#define __va_double(type) \ 75 (__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS) 76 77#define __va_struct(type) \ 78 (__builtin_classify_type(*(type *)0) >= __RECORD_TYPE_CLASS) 79 80#define __va_size(type) \ 81 ((sizeof(type) + sizeof(int) - 1) / sizeof(int) * sizeof(int)) 82 83#define __va_savedgpr(ap, type) \ 84 ((ap).__base + (ap).__gpr * sizeof(int) - sizeof(type)) 85 86#define __va_savedfpr(ap, type) \ 87 ((ap).__base + 8 * sizeof(int) + (ap).__fpr * sizeof(double) - \ 88 sizeof(type)) 89 90#define __va_stack(ap, type) \ 91 ((ap).__stack += __va_size(type) + \ 92 (__va_longlong(type) ? (int)(ap).__stack & 4 : 0), \ 93 (ap).__stack - sizeof(type)) 94 95#define __va_gpr(ap, type) \ 96 ((ap).__gpr += __va_size(type) / sizeof(int) + \ 97 (__va_longlong(type) ? (ap).__gpr & 1 : 0), \ 98 (ap).__gpr <= 8 ? __va_savedgpr(ap, type) : __va_stack(ap, type)) 99 100#define __va_fpr(ap, type) \ 101 ((ap).__fpr++, \ 102 (ap).__fpr <= 8 ? __va_savedfpr(ap, type) : __va_stack(ap, type)) 103 104#define va_arg(ap, type) \ 105 (*(type *)(__va_struct(type) ? (*(void **)__va_gpr(ap, void *)) : \ 106 __va_double(type) ? __va_fpr(ap, type) : \ 107 __va_gpr(ap, type))) 108 109#endif /* __lint__ */ 110 111#define va_end(ap) 112 113#if !defined(_ANSI_SOURCE) && \ 114 (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \ 115 defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L) 116#define va_copy(dest, src) \ 117 ((dest) = (src)) 118#endif 119 120#endif /* _POWERPC_STDARG_H_ */ 121