From 09cababc5fb4d3efcd88a769b4b6fa34d4db2a74 Mon Sep 17 00:00:00 2001 From: Hosaka Yuji Date: Tue, 16 Mar 2004 19:17:33 +0000 Subject: [PATCH] types.c: Fix alignment size of X86_WIN32 case int64 and double. 2004-03-16 Hosaka Yuji * src/types.c: Fix alignment size of X86_WIN32 case int64 and double. * src/x86/ffi.c (ffi_prep_args): Replace ecif->cif->rtype->type with ecif->cif->flags. (ffi_call, ffi_prep_incoming_args_SYSV): Replace cif->rtype->type with cif->flags. (ffi_prep_cif_machdep): Add X86_WIN32 struct case. (ffi_closure_SYSV): Add 1 or 2-bytes struct case for X86_WIN32. * src/x86/win32.S (retstruct1b, retstruct2b, sc_retstruct1b, sc_retstruct2b): Add for 1 or 2-bytes struct case. From-SVN: r79542 --- libffi/ChangeLog | 15 ++++++++++++++- libffi/src/types.c | 6 +++++- libffi/src/x86/ffi.c | 43 ++++++++++++++++++++++++++++++++++++++++--- libffi/src/x86/win32.S | 36 ++++++++++++++++++++++++++++++++++-- 4 files changed, 93 insertions(+), 7 deletions(-) diff --git a/libffi/ChangeLog b/libffi/ChangeLog index ed7e130..b9da246 100644 --- a/libffi/ChangeLog +++ b/libffi/ChangeLog @@ -1,3 +1,16 @@ +2004-03-16 Hosaka Yuji + + * src/types.c: Fix alignment size of X86_WIN32 case int64 and + double. + * src/x86/ffi.c (ffi_prep_args): Replace ecif->cif->rtype->type + with ecif->cif->flags. + (ffi_call, ffi_prep_incoming_args_SYSV): Replace cif->rtype->type + with cif->flags. + (ffi_prep_cif_machdep): Add X86_WIN32 struct case. + (ffi_closure_SYSV): Add 1 or 2-bytes struct case for X86_WIN32. + * src/x86/win32.S (retstruct1b, retstruct2b, sc_retstruct1b, + sc_retstruct2b): Add for 1 or 2-bytes struct case. + 2004-03-15 Kelley Cook * configure.in: Rename file to ... @@ -12,7 +25,7 @@ * src/powerpc/darwin.S: Fix EH information so it corresponds to changes in EH format resulting from addition of linkonce support. * src/powerpc/darwin_closure.S: Likewise. - + 2004-03-11 Andreas Tobler Paolo Bonzini diff --git a/libffi/src/types.c b/libffi/src/types.c index 27fee3b..2b31c26 100644 --- a/libffi/src/types.c +++ b/libffi/src/types.c @@ -53,7 +53,7 @@ FFI_INTEGRAL_TYPEDEF(pointer, 4, 4, FFI_TYPE_POINTER); #endif -#if defined X86 || defined X86_WIN32 || defined ARM || defined M68K +#if defined X86 || defined ARM || defined M68K FFI_INTEGRAL_TYPEDEF(uint64, 8, 4, FFI_TYPE_UINT64); FFI_INTEGRAL_TYPEDEF(sint64, 8, 4, FFI_TYPE_SINT64); @@ -73,7 +73,11 @@ FFI_INTEGRAL_TYPEDEF(sint64, 8, 8, FFI_TYPE_SINT64); #if defined X86 || defined X86_WIN32 || defined M68K +#ifdef X86_WIN32 +FFI_INTEGRAL_TYPEDEF(double, 8, 8, FFI_TYPE_DOUBLE); +#else FFI_INTEGRAL_TYPEDEF(double, 8, 4, FFI_TYPE_DOUBLE); +#endif FFI_INTEGRAL_TYPEDEF(longdouble, 12, 4, FFI_TYPE_LONGDOUBLE); #elif defined ARM || defined SH || defined POWERPC_AIX || defined POWERPC_DARWIN diff --git a/libffi/src/x86/ffi.c b/libffi/src/x86/ffi.c index 14b0295..633e549 100644 --- a/libffi/src/x86/ffi.c +++ b/libffi/src/x86/ffi.c @@ -47,7 +47,7 @@ void ffi_prep_args(char *stack, extended_cif *ecif) argp = stack; - if (ecif->cif->rtype->type == FFI_TYPE_STRUCT) + if (ecif->cif->flags == FFI_TYPE_STRUCT) { *(void **) argp = ecif->rvalue; argp += 4; @@ -121,7 +121,9 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) switch (cif->rtype->type) { case FFI_TYPE_VOID: +#ifndef X86_WIN32 case FFI_TYPE_STRUCT: +#endif case FFI_TYPE_SINT64: case FFI_TYPE_FLOAT: case FFI_TYPE_DOUBLE: @@ -133,6 +135,31 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) cif->flags = FFI_TYPE_SINT64; break; +#ifdef X86_WIN32 + case FFI_TYPE_STRUCT: + if (cif->rtype->size == 1) + { + cif->flags = FFI_TYPE_SINT8; /* same as char size */ + } + else if (cif->rtype->size == 2) + { + cif->flags = FFI_TYPE_SINT16; /* same as short size */ + } + else if (cif->rtype->size == 4) + { + cif->flags = FFI_TYPE_INT; /* same as int type */ + } + else if (cif->rtype->size == 8) + { + cif->flags = FFI_TYPE_SINT64; /* same as int64 type */ + } + else + { + cif->flags = FFI_TYPE_STRUCT; + } + break; +#endif + default: cif->flags = FFI_TYPE_INT; break; @@ -177,7 +204,7 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif, /* value address then we need to make one */ if ((rvalue == NULL) && - (cif->rtype->type == FFI_TYPE_STRUCT)) + (cif->flags == FFI_TYPE_STRUCT)) { /*@-sysunrecog@*/ ecif.rvalue = alloca(cif->rtype->size); @@ -274,6 +301,16 @@ ffi_closure_SYSV (closure) : : "r"(resp) : "eax", "edx"); } +#ifdef X86_WIN32 + else if (rtype == FFI_TYPE_SINT8) /* 1-byte struct */ + { + asm ("movsbl (%0),%%eax" : : "r" (resp) : "eax"); + } + else if (rtype == FFI_TYPE_SINT16) /* 2-bytes struct */ + { + asm ("movswl (%0),%%eax" : : "r" (resp) : "eax"); + } +#endif } /*@-exportheader@*/ @@ -289,7 +326,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, argp = stack; - if ( cif->rtype->type == FFI_TYPE_STRUCT ) { + if ( cif->flags == FFI_TYPE_STRUCT ) { *rvalue = *(void **) argp; argp += 4; } diff --git a/libffi/src/x86/win32.S b/libffi/src/x86/win32.S index 40743af..bc2812c 100644 --- a/libffi/src/x86/win32.S +++ b/libffi/src/x86/win32.S @@ -114,12 +114,28 @@ retlongdouble: retint64: cmpl $FFI_TYPE_SINT64,%ecx - jne retstruct + jne retstruct1b # Load %ecx with the pointer to storage for the return value movl 24(%ebp),%ecx movl %eax,0(%ecx) movl %edx,4(%ecx) +retstruct1b: + cmpl $FFI_TYPE_SINT8,%ecx + jne retstruct2b + # Load %ecx with the pointer to storage for the return value + movl 24(%ebp),%ecx + movb %al,0(%ecx) + jmp epilogue + +retstruct2b: + cmpl $FFI_TYPE_SINT16,%ecx + jne retstruct + # Load %ecx with the pointer to storage for the return value + movl 24(%ebp),%ecx + movw %ax,0(%ecx) + jmp epilogue + retstruct: # Nothing to do! @@ -209,12 +225,28 @@ sc_retlongdouble: sc_retint64: cmpl $FFI_TYPE_SINT64,%ecx - jne sc_retstruct + jne sc_retstruct1b # Load %ecx with the pointer to storage for the return value movl 24(%ebp),%ecx movl %eax,0(%ecx) movl %edx,4(%ecx) +sc_retstruct1b: + cmpl $FFI_TYPE_SINT8,%ecx + jne sc_retstruct2b + # Load %ecx with the pointer to storage for the return value + movl 24(%ebp),%ecx + movb %al,0(%ecx) + jmp sc_epilogue + +sc_retstruct2b: + cmpl $FFI_TYPE_SINT16,%ecx + jne sc_retstruct + # Load %ecx with the pointer to storage for the return value + movl 24(%ebp),%ecx + movw %ax,0(%ecx) + jmp sc_epilogue + sc_retstruct: # Nothing to do! -- 2.7.4