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$ 28 */ 29 30 #ifndef _POWERPC_STDARG_H_ 31 #define _POWERPC_STDARG_H_ 32 33 #include <machine/ansi.h> 34 35 #if 0 36 typedef struct { 37 char __gpr; /* GPR offset */ 38 char __fpr; /* FPR offset */ 39 /* char __pad[2]; */ 40 char *__stack; /* args passed on stack */ 41 char *__base; /* args passed by registers (r3-r10, f1-f8) */ 42 } va_list; 43 #endif 44 45 typedef _BSD_VA_LIST_ va_list; 46 47 #ifdef __lint__ 48 49 #define va_start(ap, last) ((ap) = *(va_list *)0) 50 #define va_arg(ap, type) (*(type *)(void *)&(ap)) 51 52 #else 53 54 #define va_start(ap, last) \ 55 (__builtin_next_arg(last), \ 56 (ap).__stack = __va_stack_args, \ 57 (ap).__base = __va_reg_args, \ 58 (ap).__gpr = __va_first_gpr, \ 59 (ap).__fpr = __va_first_fpr) 60 61 #define __va_first_gpr (__builtin_args_info(0)) 62 #define __va_first_fpr (__builtin_args_info(1) - 32 - 1) 63 #define __va_stack_args \ 64 ((char *)__builtin_saveregs() + \ 65 (__va_first_gpr >= 8 ? __va_first_gpr - 8 : 0) * sizeof(int)) 66 #define __va_reg_args \ 67 ((char *)__builtin_frame_address(0) + __builtin_args_info(4)) 68 69 #define __INTEGER_TYPE_CLASS 1 70 #define __REAL_TYPE_CLASS 8 71 #define __RECORD_TYPE_CLASS 12 72 73 #define __va_longlong(type) \ 74 (__builtin_classify_type(*(type *)0) == __INTEGER_TYPE_CLASS && \ 75 sizeof(type) == 8) 76 77 #define __va_double(type) \ 78 (__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS) 79 80 #define __va_struct(type) \ 81 (__builtin_classify_type(*(type *)0) >= __RECORD_TYPE_CLASS) 82 83 #define __va_size(type) \ 84 ((sizeof(type) + sizeof(int) - 1) / sizeof(int) * sizeof(int)) 85 86 #define __va_savedgpr(ap, type) \ 87 ((ap).__base + (ap).__gpr * sizeof(int) - sizeof(type)) 88 89 #define __va_savedfpr(ap, type) \ 90 ((ap).__base + 8 * sizeof(int) + (ap).__fpr * sizeof(double) - \ 91 sizeof(type)) 92 93 #define __va_stack(ap, type) \ 94 ((ap).__stack += __va_size(type) + \ 95 (__va_longlong(type) ? (int)(ap).__stack & 4 : 0), \ 96 (ap).__stack - sizeof(type)) 97 98 #define __va_gpr(ap, type) \ 99 ((ap).__gpr += __va_size(type) / sizeof(int) + \ 100 (__va_longlong(type) ? (ap).__gpr & 1 : 0), \ 101 (ap).__gpr <= 8 ? __va_savedgpr(ap, type) : __va_stack(ap, type)) 102 103 #define __va_fpr(ap, type) \ 104 ((ap).__fpr++, \ 105 (ap).__fpr <= 8 ? __va_savedfpr(ap, type) : __va_stack(ap, type)) 106 107 #define va_arg(ap, type) \ 108 (*(type *)(__va_struct(type) ? (*(void **)__va_gpr(ap, void *)) : \ 109 __va_double(type) ? __va_fpr(ap, type) : \ 110 __va_gpr(ap, type))) 111 112 #endif /* __lint__ */ 113 114 #define va_end(ap) 115 116 #if !defined(_ANSI_SOURCE) && \ 117 (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \ 118 defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L) 119 #define va_copy(dest, src) \ 120 ((dest) = (src)) 121 #endif 122 123 #endif /* _POWERPC_STDARG_H_ */ 124