Rewrite stdarg/varargs.
This commit is contained in:
parent
74ca33774a
commit
0086d842d5
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.7 2000/02/18 08:50:25 tsubai Exp $
|
||||
# $NetBSD: Makefile,v 1.8 2000/02/27 17:50:20 tsubai Exp $
|
||||
|
||||
KDIR= /sys/arch/powerpc/include
|
||||
INCSDIR= /usr/include/powerpc
|
||||
|
@ -7,6 +7,6 @@ INCS= ansi.h aout_machdep.h asm.h bat.h bswap.h cdefs.h cpu.h db_machdep.h \
|
|||
elf_machdep.h endian.h float.h fpu.h frame.h hid_601.h ieee.h \
|
||||
ieeefp.h ipkdb.h kcore.h limits.h machine_type.h math.h param.h pcb.h \
|
||||
pmap.h proc.h profile.h psl.h pte.h ptrace.h reg.h reloc.h setjmp.h \
|
||||
signal.h stdarg.h trap.h types.h va-ppc.h varargs.h
|
||||
signal.h stdarg.h trap.h types.h varargs.h
|
||||
|
||||
.include <bsd.kinc.mk>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ansi.h,v 1.6 1998/08/16 17:16:56 kleink Exp $ */
|
||||
/* $NetBSD: ansi.h,v 1.7 2000/02/27 17:50:21 tsubai Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
|
@ -52,15 +52,6 @@
|
|||
#define _BSD_SIZE_T_ unsigned int /* sizeof() */
|
||||
#define _BSD_SSIZE_T_ int /* byte count or error */
|
||||
#define _BSD_TIME_T_ long /* time() */
|
||||
|
||||
/*
|
||||
* Actually va_list is an array, but this wouldn't work as a #define.
|
||||
* Fortunately this is used only for formal parameters,
|
||||
* so we can use a pointer instead.
|
||||
*/
|
||||
struct __gnuc_va_list__; /* forward declaration to prohibit gcc warning XXX */
|
||||
#define _BSD_VA_LIST_ struct __gnuc_va_list__ * /* va_list */
|
||||
|
||||
#define _BSD_CLOCKID_T_ int /* clockid_t */
|
||||
#define _BSD_TIMER_T_ int /* timer_t */
|
||||
#define _BSD_SUSECONDS_T_ int /* suseconds_t */
|
||||
|
@ -68,6 +59,12 @@ struct __gnuc_va_list__; /* forward declaration to prohibit gcc warning XXX */
|
|||
#define _BSD_INTPTR_T_ int /* intptr_t */
|
||||
#define _BSD_UINTPTR_T_ unsigned int /* uintptr_t */
|
||||
|
||||
typedef struct {
|
||||
char __gpr, __fpr, __pad[2];
|
||||
char *__stack, *__base;
|
||||
} __va_list;
|
||||
#define _BSD_VA_LIST_ __va_list /* va_list */
|
||||
|
||||
/*
|
||||
* Runes (wchar_t) is declared to be an ``int'' instead of the more natural
|
||||
* ``unsigned long'' or ``long''. Two things are happening here. It is not
|
||||
|
|
|
@ -1,22 +1,123 @@
|
|||
/* $NetBSD: stdarg.h,v 1.4 2000/02/03 16:16:08 kleink Exp $ */
|
||||
/* $NetBSD: stdarg.h,v 1.5 2000/02/27 17:50:21 tsubai Exp $ */
|
||||
|
||||
#ifndef _PPC_STDARG_H_
|
||||
#define _PPC_STDARG_H_
|
||||
/*-
|
||||
* Copyright (c) 2000 Tsubai Masanari. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _POWERPC_STDARG_H_
|
||||
#define _POWERPC_STDARG_H_
|
||||
|
||||
#include <machine/ansi.h>
|
||||
#include <sys/featuretest.h>
|
||||
|
||||
#ifndef _STDARG_H
|
||||
#define _STDARG_H
|
||||
#if 0
|
||||
typedef struct {
|
||||
char __gpr; /* GPR offset */
|
||||
char __fpr; /* FPR offset */
|
||||
char __pad[2];
|
||||
char *__stack; /* args passed on stack */
|
||||
char *__base; /* args passed by registers (r3-r10, f1-f8) */
|
||||
} va_list;
|
||||
#endif
|
||||
#include <powerpc/va-ppc.h>
|
||||
|
||||
typedef __gnuc_va_list va_list;
|
||||
typedef _BSD_VA_LIST_ va_list;
|
||||
|
||||
#if !defined(_ANSI_SOURCE) && \
|
||||
(!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \
|
||||
#ifdef __lint__
|
||||
|
||||
#define va_start(ap, last) ((ap) = *(va_list *)0)
|
||||
#define va_arg(ap, type) (*(type *)(void *)&(ap))
|
||||
|
||||
#else
|
||||
|
||||
#define va_start(ap, last) \
|
||||
(__builtin_next_arg(last), \
|
||||
(ap).__stack = __va_stack_args, \
|
||||
(ap).__base = __va_reg_args, \
|
||||
(ap).__gpr = __va_first_gpr, \
|
||||
(ap).__fpr = __va_first_fpr)
|
||||
|
||||
#define __va_first_gpr (__builtin_args_info(0))
|
||||
#define __va_first_fpr (__builtin_args_info(1) - 32 - 1)
|
||||
#define __va_stack_args \
|
||||
((char *)__builtin_saveregs() + \
|
||||
(__va_first_gpr >= 8 ? __va_first_gpr - 8 : 0) * sizeof(int))
|
||||
#define __va_reg_args \
|
||||
((char *)__builtin_frame_address(0) + __builtin_args_info(4))
|
||||
|
||||
#define __INTEGER_TYPE_CLASS 1
|
||||
#define __REAL_TYPE_CLASS 8
|
||||
#define __RECORD_TYPE_CLASS 12
|
||||
|
||||
#define __va_longlong(type) \
|
||||
(__builtin_classify_type(*(type *)0) == __INTEGER_TYPE_CLASS && \
|
||||
sizeof(type) == 8)
|
||||
|
||||
#define __va_double(type) \
|
||||
(__builtin_classify_type(*(type *)0) == __REAL_TYPE_CLASS)
|
||||
|
||||
#define __va_struct(type) \
|
||||
(__builtin_classify_type(*(type *)0) >= __RECORD_TYPE_CLASS)
|
||||
|
||||
#define __va_size(type) \
|
||||
((sizeof(type) + sizeof(int) - 1) / sizeof(int) * sizeof(int))
|
||||
|
||||
#define __va_savedgpr(ap, type) \
|
||||
((ap).__base + (ap).__gpr * sizeof(int) - sizeof(type))
|
||||
|
||||
#define __va_savedfpr(ap, type) \
|
||||
((ap).__base + 8 * sizeof(int) + (ap).__fpr * sizeof(double) - \
|
||||
sizeof(type))
|
||||
|
||||
#define __va_stack(ap, type) \
|
||||
((ap).__stack += __va_size(type) + \
|
||||
(__va_longlong(type) ? (int)(ap).__stack & 4 : 0), \
|
||||
(ap).__stack - sizeof(type))
|
||||
|
||||
#define __va_gpr(ap, type) \
|
||||
((ap).__gpr += __va_size(type) / sizeof(int) + \
|
||||
(__va_longlong(type) ? (ap).__gpr & 1 : 0), \
|
||||
(ap).__gpr <= 8 ? __va_savedgpr(ap, type) : __va_stack(ap, type))
|
||||
|
||||
#define __va_fpr(ap, type) \
|
||||
((ap).__fpr++, \
|
||||
(ap).__fpr <= 8 ? __va_savedfpr(ap, type) : __va_stack(ap, type))
|
||||
|
||||
#define va_arg(ap, type) \
|
||||
(*(type *)(__va_struct(type) ? (*(void **)__va_gpr(ap, void *)) : \
|
||||
__va_double(type) ? __va_fpr(ap, type) : \
|
||||
__va_gpr(ap, type)))
|
||||
|
||||
#endif /* __lint__ */
|
||||
|
||||
#define va_end(ap)
|
||||
|
||||
#if !defined(_ANSI_SOURCE) && \
|
||||
(!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \
|
||||
defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L)
|
||||
#define va_copy __va_copy
|
||||
#define va_copy(dest, src) \
|
||||
((dest) = (src))
|
||||
#endif
|
||||
|
||||
#endif /* ! _PPC_STDARG_H_ */
|
||||
#endif /* _POWERPC_STDARG_H_ */
|
||||
|
|
|
@ -1,163 +0,0 @@
|
|||
/* $NetBSD: va-ppc.h,v 1.6 2000/02/09 12:54:47 tsubai Exp $ */
|
||||
|
||||
/* GNU C varargs support for the PowerPC with V.4 calling sequence */
|
||||
|
||||
/* Define __gnuc_va_list. */
|
||||
|
||||
#ifndef __GNUC_VA_LIST
|
||||
#define __GNUC_VA_LIST
|
||||
|
||||
#ifdef __lint__
|
||||
#define __extension__(x) (0)
|
||||
#endif
|
||||
|
||||
/* Note that the names in this structure are in the user's namespace, but
|
||||
that the V.4 abi explicitly states that these names should be used. */
|
||||
typedef struct __gnuc_va_list__ {
|
||||
char gpr; /* index into the array of 8 GPRs stored in the
|
||||
register save area gpr=0 corresponds to r3,
|
||||
gpr=1 to r4, etc. */
|
||||
char fpr; /* index into the array of 8 FPRs stored in the
|
||||
register save area fpr=0 corresponds to f1,
|
||||
fpr=1 to f2, etc. */
|
||||
char *overflow_arg_area; /* location on stack that holds the next
|
||||
overflow argument */
|
||||
char *reg_save_area; /* where r3:r10 and f1:f8, if saved are stored */
|
||||
} __gnuc_va_list[1];
|
||||
#endif /* not __GNUC_VA_LIST */
|
||||
|
||||
/* If this is for internal libc use, don't define anything but
|
||||
__gnuc_va_list. */
|
||||
#if defined (_STDARG_H) || defined (_VARARGS_H)
|
||||
|
||||
/* Register save area located below the frame pointer */
|
||||
typedef struct {
|
||||
long __gp_save[8]; /* save area for GP registers */
|
||||
double __fp_save[8]; /* save area for FP registers */
|
||||
} __va_regsave_t;
|
||||
|
||||
/* Macros to access the register save area */
|
||||
/* We cast to void * and then to TYPE * because this avoids
|
||||
a warning about increasing the alignment requirement. */
|
||||
#define __VA_FP_REGSAVE(AP,TYPE) \
|
||||
((TYPE *) (void *) (&(((__va_regsave_t *) \
|
||||
(AP)->reg_save_area)->__fp_save[(int)(AP)->fpr])))
|
||||
|
||||
#define __VA_GP_REGSAVE(AP,TYPE) \
|
||||
((TYPE *) (void *) (&(((__va_regsave_t *) \
|
||||
(AP)->reg_save_area)->__gp_save[(int)(AP)->gpr])))
|
||||
|
||||
/* Common code for va_start for both varargs and stdarg. This depends
|
||||
on the format of rs6000_args in rs6000.h. The fields used are:
|
||||
|
||||
#0 WORDS # words used for GP regs/stack values
|
||||
#1 FREGNO next available FP register
|
||||
#2 NARGS_PROTOTYPE # args left in the current prototype
|
||||
#3 ORIG_NARGS original value of NARGS_PROTOTYPE
|
||||
#4 VARARGS_OFFSET offset from frame pointer of varargs area */
|
||||
|
||||
#define __va_words __builtin_args_info (0)
|
||||
#define __va_fregno __builtin_args_info (1)
|
||||
#define __va_nargs __builtin_args_info (2)
|
||||
#define __va_orig_nargs __builtin_args_info (3)
|
||||
#define __va_varargs_offset __builtin_args_info (4)
|
||||
|
||||
#define __va_start_common(AP, FAKE) \
|
||||
__extension__ ({ \
|
||||
register int __words = __va_words - FAKE; \
|
||||
\
|
||||
(AP)->gpr = (__words < 8) ? __words : 8; \
|
||||
(AP)->fpr = __va_fregno - 33; \
|
||||
(AP)->reg_save_area = (((char *) __builtin_frame_address (0)) \
|
||||
+ __va_varargs_offset); \
|
||||
(AP)->overflow_arg_area = ((char *)__builtin_saveregs () \
|
||||
+ (((__words >= 8) ? __words - 8 : 0) \
|
||||
* sizeof (long))); \
|
||||
(void)0; \
|
||||
})
|
||||
|
||||
#ifdef _STDARG_H /* stdarg.h support */
|
||||
|
||||
/* Calling __builtin_next_arg gives the proper error message if LASTARG is
|
||||
not indeed the last argument. */
|
||||
#define va_start(AP,LASTARG) \
|
||||
(__builtin_next_arg (LASTARG), __va_start_common (AP, 0))
|
||||
|
||||
#else /* varargs.h support */
|
||||
|
||||
#define va_start(AP) __va_start_common (AP, 1)
|
||||
#define va_alist __va_1st_arg
|
||||
#define va_dcl register int va_alist; ...
|
||||
|
||||
#endif /* _STDARG_H */
|
||||
|
||||
#ifdef _SOFT_FLOAT
|
||||
#define __va_float_p(TYPE) 0
|
||||
#else
|
||||
#define __va_float_p(TYPE) (__builtin_classify_type(*(TYPE *)0) == 8)
|
||||
#endif
|
||||
|
||||
#define __va_aggregate_p(TYPE) (__builtin_classify_type(*(TYPE *)0) >= 12)
|
||||
#define __va_size(TYPE) ((sizeof(TYPE) + sizeof (long) - 1) / sizeof (long))
|
||||
#define __va_longlong_p(TYPE) \
|
||||
((__builtin_classify_type(*(TYPE *)0) == 1) && (sizeof(TYPE) == 8))
|
||||
|
||||
#ifdef __lint__
|
||||
#define va_arg(ap, type) (*(type *)(void *)(ap))
|
||||
#else
|
||||
#define va_arg(AP,TYPE) \
|
||||
((TYPE) __extension__ (*({ \
|
||||
register TYPE *__ptr; \
|
||||
\
|
||||
if (__va_float_p (TYPE) && (AP)->fpr < 8) \
|
||||
{ \
|
||||
__ptr = __VA_FP_REGSAVE (AP, TYPE); \
|
||||
(AP)->fpr++; \
|
||||
} \
|
||||
\
|
||||
else if (__va_aggregate_p (TYPE) && (AP)->gpr < 8) \
|
||||
{ \
|
||||
__ptr = * __VA_GP_REGSAVE (AP, TYPE *); \
|
||||
(AP)->gpr++; \
|
||||
} \
|
||||
\
|
||||
else if (!__va_float_p (TYPE) && !__va_aggregate_p (TYPE) \
|
||||
&& (AP)->gpr + __va_size(TYPE) <= 8 \
|
||||
&& (!__va_longlong_p(TYPE) \
|
||||
|| (AP)->gpr + __va_size(TYPE) <= 8)) \
|
||||
{ \
|
||||
if (__va_longlong_p(TYPE) && ((AP)->gpr & 1) != 0) \
|
||||
(AP)->gpr++; \
|
||||
\
|
||||
__ptr = __VA_GP_REGSAVE (AP, TYPE); \
|
||||
(AP)->gpr += __va_size (TYPE); \
|
||||
} \
|
||||
\
|
||||
else if (!__va_float_p (TYPE) && !__va_aggregate_p (TYPE) \
|
||||
&& (AP)->gpr < 8) \
|
||||
{ \
|
||||
(AP)->gpr = 8; \
|
||||
__ptr = (TYPE *) (void *) ((AP)->overflow_arg_area); \
|
||||
(AP)->overflow_arg_area += __va_size (TYPE) * sizeof (long); \
|
||||
} \
|
||||
\
|
||||
else if (__va_aggregate_p (TYPE)) \
|
||||
{ \
|
||||
__ptr = * (TYPE **) (void *) ((AP)->overflow_arg_area); \
|
||||
(AP)->overflow_arg_area += sizeof (TYPE *); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
__ptr = (TYPE *) (void *) ((AP)->overflow_arg_area); \
|
||||
(AP)->overflow_arg_area += __va_size (TYPE) * sizeof (long); \
|
||||
} \
|
||||
\
|
||||
__ptr; \
|
||||
})))
|
||||
#endif /* __lint__ */
|
||||
|
||||
#define __va_copy(dest, src) (*(dest) = *(src))
|
||||
|
||||
#define va_end(AP) ((void)0)
|
||||
|
||||
#endif /* defined (_STDARG_H) || defined (_VARARGS_H) */
|
|
@ -1,24 +1,49 @@
|
|||
/* $NetBSD: varargs.h,v 1.4 2000/02/03 16:16:09 kleink Exp $ */
|
||||
/* $NetBSD: varargs.h,v 1.5 2000/02/27 17:50:22 tsubai Exp $ */
|
||||
|
||||
#ifndef _PPC_VARARGS_H_
|
||||
#define _PPC_VARARGS_H_
|
||||
/*-
|
||||
* Copyright (c) 2000 Tsubai Masanari. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <machine/ansi.h>
|
||||
#include <sys/featuretest.h>
|
||||
#ifndef _POWERPC_VARARGS_H_
|
||||
#define _POWERPC_VARARGS_H_
|
||||
|
||||
#ifndef _VARARGS_H
|
||||
#define _VARARGS_H
|
||||
#endif
|
||||
#include <powerpc/va-ppc.h>
|
||||
#include <machine/stdarg.h>
|
||||
|
||||
typedef __gnuc_va_list va_list;
|
||||
#define va_alist __builtin_va_alist
|
||||
#define va_dcl int __builtin_va_alist; ...
|
||||
|
||||
#undef _BSD_VA_LIST
|
||||
#undef va_start
|
||||
|
||||
#if !defined(_ANSI_SOURCE) && \
|
||||
(!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE) || \
|
||||
defined(_ISOC99_SOURCE) || (__STDC_VERSION__ - 0) >= 199901L)
|
||||
#define va_copy __va_copy
|
||||
#ifdef __lint__
|
||||
#define va_start(ap) ((ap) = *(va_list *)0)
|
||||
#else
|
||||
#define va_start(ap) \
|
||||
((ap).__stack = __va_stack_args, \
|
||||
(ap).__base = __va_reg_args, \
|
||||
(ap).__gpr = __va_first_gpr, \
|
||||
(ap).__fpr = __va_first_fpr)
|
||||
#endif
|
||||
|
||||
#endif /* ! _PPC_VARARGS_H_ */
|
||||
#endif /* _POWERPC_VARARGS_H_ */
|
||||
|
|
Loading…
Reference in New Issue