Commit 09cababc by Hosaka Yuji Committed by Andreas Tobler

types.c: Fix alignment size of X86_WIN32 case int64 and double.

2004-03-16  Hosaka Yuji  <hos@tamanegi.org>

	* 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
parent cd9b7651
2004-03-16 Hosaka Yuji <hos@tamanegi.org>
* 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 <kcook@gcc.gnu.org> 2004-03-15 Kelley Cook <kcook@gcc.gnu.org>
* configure.in: Rename file to ... * configure.in: Rename file to ...
......
...@@ -53,7 +53,7 @@ FFI_INTEGRAL_TYPEDEF(pointer, 4, 4, FFI_TYPE_POINTER); ...@@ -53,7 +53,7 @@ FFI_INTEGRAL_TYPEDEF(pointer, 4, 4, FFI_TYPE_POINTER);
#endif #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(uint64, 8, 4, FFI_TYPE_UINT64);
FFI_INTEGRAL_TYPEDEF(sint64, 8, 4, FFI_TYPE_SINT64); FFI_INTEGRAL_TYPEDEF(sint64, 8, 4, FFI_TYPE_SINT64);
...@@ -73,7 +73,11 @@ FFI_INTEGRAL_TYPEDEF(sint64, 8, 8, FFI_TYPE_SINT64); ...@@ -73,7 +73,11 @@ FFI_INTEGRAL_TYPEDEF(sint64, 8, 8, FFI_TYPE_SINT64);
#if defined X86 || defined X86_WIN32 || defined M68K #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); FFI_INTEGRAL_TYPEDEF(double, 8, 4, FFI_TYPE_DOUBLE);
#endif
FFI_INTEGRAL_TYPEDEF(longdouble, 12, 4, FFI_TYPE_LONGDOUBLE); FFI_INTEGRAL_TYPEDEF(longdouble, 12, 4, FFI_TYPE_LONGDOUBLE);
#elif defined ARM || defined SH || defined POWERPC_AIX || defined POWERPC_DARWIN #elif defined ARM || defined SH || defined POWERPC_AIX || defined POWERPC_DARWIN
......
...@@ -47,7 +47,7 @@ void ffi_prep_args(char *stack, extended_cif *ecif) ...@@ -47,7 +47,7 @@ void ffi_prep_args(char *stack, extended_cif *ecif)
argp = stack; argp = stack;
if (ecif->cif->rtype->type == FFI_TYPE_STRUCT) if (ecif->cif->flags == FFI_TYPE_STRUCT)
{ {
*(void **) argp = ecif->rvalue; *(void **) argp = ecif->rvalue;
argp += 4; argp += 4;
...@@ -121,7 +121,9 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) ...@@ -121,7 +121,9 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
switch (cif->rtype->type) switch (cif->rtype->type)
{ {
case FFI_TYPE_VOID: case FFI_TYPE_VOID:
#ifndef X86_WIN32
case FFI_TYPE_STRUCT: case FFI_TYPE_STRUCT:
#endif
case FFI_TYPE_SINT64: case FFI_TYPE_SINT64:
case FFI_TYPE_FLOAT: case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE: case FFI_TYPE_DOUBLE:
...@@ -133,6 +135,31 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) ...@@ -133,6 +135,31 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
cif->flags = FFI_TYPE_SINT64; cif->flags = FFI_TYPE_SINT64;
break; 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: default:
cif->flags = FFI_TYPE_INT; cif->flags = FFI_TYPE_INT;
break; break;
...@@ -177,7 +204,7 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif, ...@@ -177,7 +204,7 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
/* value address then we need to make one */ /* value address then we need to make one */
if ((rvalue == NULL) && if ((rvalue == NULL) &&
(cif->rtype->type == FFI_TYPE_STRUCT)) (cif->flags == FFI_TYPE_STRUCT))
{ {
/*@-sysunrecog@*/ /*@-sysunrecog@*/
ecif.rvalue = alloca(cif->rtype->size); ecif.rvalue = alloca(cif->rtype->size);
...@@ -274,6 +301,16 @@ ffi_closure_SYSV (closure) ...@@ -274,6 +301,16 @@ ffi_closure_SYSV (closure)
: : "r"(resp) : : "r"(resp)
: "eax", "edx"); : "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@*/ /*@-exportheader@*/
...@@ -289,7 +326,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, ...@@ -289,7 +326,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
argp = stack; argp = stack;
if ( cif->rtype->type == FFI_TYPE_STRUCT ) { if ( cif->flags == FFI_TYPE_STRUCT ) {
*rvalue = *(void **) argp; *rvalue = *(void **) argp;
argp += 4; argp += 4;
} }
......
...@@ -114,12 +114,28 @@ retlongdouble: ...@@ -114,12 +114,28 @@ retlongdouble:
retint64: retint64:
cmpl $FFI_TYPE_SINT64,%ecx cmpl $FFI_TYPE_SINT64,%ecx
jne retstruct jne retstruct1b
# Load %ecx with the pointer to storage for the return value # Load %ecx with the pointer to storage for the return value
movl 24(%ebp),%ecx movl 24(%ebp),%ecx
movl %eax,0(%ecx) movl %eax,0(%ecx)
movl %edx,4(%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: retstruct:
# Nothing to do! # Nothing to do!
...@@ -209,12 +225,28 @@ sc_retlongdouble: ...@@ -209,12 +225,28 @@ sc_retlongdouble:
sc_retint64: sc_retint64:
cmpl $FFI_TYPE_SINT64,%ecx cmpl $FFI_TYPE_SINT64,%ecx
jne sc_retstruct jne sc_retstruct1b
# Load %ecx with the pointer to storage for the return value # Load %ecx with the pointer to storage for the return value
movl 24(%ebp),%ecx movl 24(%ebp),%ecx
movl %eax,0(%ecx) movl %eax,0(%ecx)
movl %edx,4(%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: sc_retstruct:
# Nothing to do! # Nothing to do!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment