Commit d7b07cc7 by Andreas Tobler Committed by Andreas Tobler

re PR testsuite/32843 (libffi.call/return_sc.c)

2008-01-05  Andreas Tobler  <a.tobler@schweiz.org>

	PR testsuite/32843
	* src/x86/ffi.c (ffi_prep_cif_machdep): Add code for
	signed/unsigned int8/16 for X86_DARWIN.
	Updated copyright info.
	Handle one and two byte structs with special cif->flags.
	* src/x86/ffitarget.h: Add special types for one and two byte structs.
	Updated copyright info.
	* src/x86/darwin.S (ffi_call_SYSV): Rewrite to use a jump table like
	sysv.S
	Remove code to pop args from the stack after call.
	Special-case signed/unsigned for int8/16, one and two byte structs.
	(ffi_closure_raw_SYSV): Handle FFI_TYPE_UINT8,
	FFI_TYPE_SINT8, FFI_TYPE_UINT16, FFI_TYPE_SINT16, FFI_TYPE_UINT32,
	FFI_TYPE_SINT32.
	Updated copyright info.

From-SVN: r131343
parent 5a37a60c
2008-01-05 Andreas Tobler <a.tobler@schweiz.org>
PR testsuite/32843
* src/x86/ffi.c (ffi_prep_cif_machdep): Add code for
signed/unsigned int8/16 for X86_DARWIN.
Updated copyright info.
Handle one and two byte structs with special cif->flags.
* src/x86/ffitarget.h: Add special types for one and two byte structs.
Updated copyright info.
* src/x86/darwin.S (ffi_call_SYSV): Rewrite to use a jump table like
sysv.S
Remove code to pop args from the stack after call.
Special-case signed/unsigned for int8/16, one and two byte structs.
(ffi_closure_raw_SYSV): Handle FFI_TYPE_UINT8,
FFI_TYPE_SINT8, FFI_TYPE_UINT16, FFI_TYPE_SINT16, FFI_TYPE_UINT32,
FFI_TYPE_SINT32.
Updated copyright info.
2007-12-08 David Daney <ddaney@avtrex.com> 2007-12-08 David Daney <ddaney@avtrex.com>
* src/mips/n32.S (ffi_call_N32): Replace dadd with ADDU, dsub with * src/mips/n32.S (ffi_call_N32): Replace dadd with ADDU, dsub with
......
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
sysv.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005 Red Hat, Inc. darwin.S - Copyright (c) 1996, 1998, 2001, 2002, 2003, 2005 Red Hat, Inc.
Copyright (C) 2008 Free Software Foundation, Inc.
X86 Foreign Function Interface X86 Foreign Function Interface
...@@ -60,16 +61,15 @@ _ffi_call_SYSV: ...@@ -60,16 +61,15 @@ _ffi_call_SYSV:
call *28(%ebp) call *28(%ebp)
/* Remove the space we pushed for the args */
movl 16(%ebp),%ecx
addl %ecx,%esp
/* Load %ecx with the return type code */ /* Load %ecx with the return type code */
movl 20(%ebp),%ecx movl 20(%ebp),%ecx
/* Protect %esi. We're going to pop it in the epilogue. */
pushl %esi
/* If the return value pointer is NULL, assume no return value. */ /* If the return value pointer is NULL, assume no return value. */
cmpl $0,24(%ebp) cmpl $0,24(%ebp)
jne retint jne 0f
/* Even if there is no space for the return value, we are /* Even if there is no space for the return value, we are
obliged to handle floating-point values. */ obliged to handle floating-point values. */
...@@ -78,42 +78,68 @@ _ffi_call_SYSV: ...@@ -78,42 +78,68 @@ _ffi_call_SYSV:
fstp %st(0) fstp %st(0)
jmp epilogue jmp epilogue
0:
retint: .align 4
cmpl $FFI_TYPE_INT,%ecx call 1f
jne retfloat .Lstore_table:
/* Load %ecx with the pointer to storage for the return value */ .long noretval-.Lstore_table /* FFI_TYPE_VOID */
movl 24(%ebp),%ecx .long retint-.Lstore_table /* FFI_TYPE_INT */
movl %eax,0(%ecx) .long retfloat-.Lstore_table /* FFI_TYPE_FLOAT */
jmp epilogue .long retdouble-.Lstore_table /* FFI_TYPE_DOUBLE */
.long retlongdouble-.Lstore_table /* FFI_TYPE_LONGDOUBLE */
.long retuint8-.Lstore_table /* FFI_TYPE_UINT8 */
.long retsint8-.Lstore_table /* FFI_TYPE_SINT8 */
.long retuint16-.Lstore_table /* FFI_TYPE_UINT16 */
.long retsint16-.Lstore_table /* FFI_TYPE_SINT16 */
.long retint-.Lstore_table /* FFI_TYPE_UINT32 */
.long retint-.Lstore_table /* FFI_TYPE_SINT32 */
.long retint64-.Lstore_table /* FFI_TYPE_UINT64 */
.long retint64-.Lstore_table /* FFI_TYPE_SINT64 */
.long retstruct-.Lstore_table /* FFI_TYPE_STRUCT */
.long retint-.Lstore_table /* FFI_TYPE_POINTER */
.long retstruct1b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_1B */
.long retstruct2b-.Lstore_table /* FFI_TYPE_SMALL_STRUCT_2B */
1:
pop %esi
add (%esi, %ecx, 4), %esi
jmp *%esi
/* Sign/zero extend as appropriate. */
retsint8:
movsbl %al, %eax
jmp retint
retsint16:
movswl %ax, %eax
jmp retint
retuint8:
movzbl %al, %eax
jmp retint
retuint16:
movzwl %ax, %eax
jmp retint
retfloat: retfloat:
cmpl $FFI_TYPE_FLOAT,%ecx
jne retdouble
/* 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
fstps (%ecx) fstps (%ecx)
jmp epilogue jmp epilogue
retdouble: retdouble:
cmpl $FFI_TYPE_DOUBLE,%ecx
jne retlongdouble
/* 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
fstpl (%ecx) fstpl (%ecx)
jmp epilogue jmp epilogue
retlongdouble: retlongdouble:
cmpl $FFI_TYPE_LONGDOUBLE,%ecx
jne retint64
/* 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
fstpt (%ecx) fstpt (%ecx)
jmp epilogue jmp epilogue
retint64: retint64:
cmpl $FFI_TYPE_SINT64,%ecx
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)
...@@ -121,35 +147,32 @@ retint64: ...@@ -121,35 +147,32 @@ retint64:
jmp epilogue jmp epilogue
retstruct1b: retstruct1b:
cmpl $FFI_TYPE_SINT8,%ecx
jne retstruct2b
/* 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
movb %al,0(%ecx) movb %al,0(%ecx)
jmp epilogue jmp epilogue
retstruct2b: retstruct2b:
cmpl $FFI_TYPE_SINT16,%ecx
jne retstruct
/* 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
movw %ax,0(%ecx) movw %ax,0(%ecx)
jmp epilogue jmp epilogue
retint:
/* Load %ecx with the pointer to storage for the return value */
movl 24(%ebp),%ecx
movl %eax,0(%ecx)
retstruct: retstruct:
cmpl $FFI_TYPE_STRUCT,%ecx
jne noretval
/* Nothing to do! */ /* Nothing to do! */
addl $4,%esp
popl %ebp
ret
noretval: noretval:
epilogue: epilogue:
addl $8,%esp popl %esi
movl %ebp,%esp movl %ebp,%esp
popl %ebp popl %ebp
ret ret
.LFE1: .LFE1:
.ffi_call_SYSV_end: .ffi_call_SYSV_end:
...@@ -177,7 +200,15 @@ _ffi_closure_SYSV: ...@@ -177,7 +200,15 @@ _ffi_closure_SYSV:
movl -12(%ebp), %ecx movl -12(%ebp), %ecx
cmpl $FFI_TYPE_INT, %eax cmpl $FFI_TYPE_INT, %eax
je .Lcls_retint je .Lcls_retint
cmpl $FFI_TYPE_FLOAT, %eax
/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
cmpl $FFI_TYPE_UINT64, %eax
jge 0f
cmpl $FFI_TYPE_UINT8, %eax
jge .Lcls_retint
0: cmpl $FFI_TYPE_FLOAT, %eax
je .Lcls_retfloat je .Lcls_retfloat
cmpl $FFI_TYPE_DOUBLE, %eax cmpl $FFI_TYPE_DOUBLE, %eax
je .Lcls_retdouble je .Lcls_retdouble
...@@ -185,10 +216,10 @@ _ffi_closure_SYSV: ...@@ -185,10 +216,10 @@ _ffi_closure_SYSV:
je .Lcls_retldouble je .Lcls_retldouble
cmpl $FFI_TYPE_SINT64, %eax cmpl $FFI_TYPE_SINT64, %eax
je .Lcls_retllong je .Lcls_retllong
cmpl $FFI_TYPE_SINT8, %eax cmpl $FFI_TYPE_SMALL_STRUCT_1B, %eax
je .Lcls_retstruct1 je .Lcls_retstruct1b
cmpl $FFI_TYPE_SINT16, %eax cmpl $FFI_TYPE_SMALL_STRUCT_2B, %eax
je .Lcls_retstruct2 je .Lcls_retstruct2b
cmpl $FFI_TYPE_STRUCT, %eax cmpl $FFI_TYPE_STRUCT, %eax
je .Lcls_retstruct je .Lcls_retstruct
.Lcls_epilogue: .Lcls_epilogue:
...@@ -211,10 +242,10 @@ _ffi_closure_SYSV: ...@@ -211,10 +242,10 @@ _ffi_closure_SYSV:
movl (%ecx), %eax movl (%ecx), %eax
movl 4(%ecx), %edx movl 4(%ecx), %edx
jmp .Lcls_epilogue jmp .Lcls_epilogue
.Lcls_retstruct1: .Lcls_retstruct1b:
movsbl (%ecx), %eax movsbl (%ecx), %eax
jmp .Lcls_epilogue jmp .Lcls_epilogue
.Lcls_retstruct2: .Lcls_retstruct2b:
movswl (%ecx), %eax movswl (%ecx), %eax
jmp .Lcls_epilogue jmp .Lcls_epilogue
.Lcls_retstruct: .Lcls_retstruct:
...@@ -256,6 +287,14 @@ _ffi_closure_raw_SYSV: ...@@ -256,6 +287,14 @@ _ffi_closure_raw_SYSV:
movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */ movl CIF_FLAGS_OFFSET(%esi), %eax /* rtype */
cmpl $FFI_TYPE_INT, %eax cmpl $FFI_TYPE_INT, %eax
je .Lrcls_retint je .Lrcls_retint
/* Handle FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16,
FFI_TYPE_SINT16, FFI_TYPE_UINT32, FFI_TYPE_SINT32. */
cmpl $FFI_TYPE_UINT64, %eax
jge 0f
cmpl $FFI_TYPE_UINT8, %eax
jge .Lrcls_retint
0:
cmpl $FFI_TYPE_FLOAT, %eax cmpl $FFI_TYPE_FLOAT, %eax
je .Lrcls_retfloat je .Lrcls_retfloat
cmpl $FFI_TYPE_DOUBLE, %eax cmpl $FFI_TYPE_DOUBLE, %eax
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
Copyright (c) 2002 Ranjit Mathew Copyright (c) 2002 Ranjit Mathew
Copyright (c) 2002 Bo Thorsen Copyright (c) 2002 Bo Thorsen
Copyright (c) 2002 Roger Sayle Copyright (c) 2002 Roger Sayle
Copyright (C) 2008 Free Software Foundation, Inc.
x86 Foreign Function Interface x86 Foreign Function Interface
...@@ -121,10 +122,13 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) ...@@ -121,10 +122,13 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
case FFI_TYPE_VOID: case FFI_TYPE_VOID:
#ifdef X86 #ifdef X86
case FFI_TYPE_STRUCT: case FFI_TYPE_STRUCT:
#else
# if defined(X86) || defined(X86_DARWIN)
case FFI_TYPE_UINT8: case FFI_TYPE_UINT8:
case FFI_TYPE_UINT16: case FFI_TYPE_UINT16:
case FFI_TYPE_SINT8: case FFI_TYPE_SINT8:
case FFI_TYPE_SINT16: case FFI_TYPE_SINT16:
# endif
#endif #endif
case FFI_TYPE_SINT64: case FFI_TYPE_SINT64:
...@@ -142,11 +146,11 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif) ...@@ -142,11 +146,11 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
case FFI_TYPE_STRUCT: case FFI_TYPE_STRUCT:
if (cif->rtype->size == 1) if (cif->rtype->size == 1)
{ {
cif->flags = FFI_TYPE_SINT8; /* same as char size */ cif->flags = FFI_TYPE_SMALL_STRUCT_1B; /* same as char size */
} }
else if (cif->rtype->size == 2) else if (cif->rtype->size == 2)
{ {
cif->flags = FFI_TYPE_SINT16; /* same as short size */ cif->flags = FFI_TYPE_SMALL_STRUCT_2B; /* same as short size */
} }
else if (cif->rtype->size == 4) else if (cif->rtype->size == 4)
{ {
......
/* -----------------------------------------------------------------*-C-*- /* -----------------------------------------------------------------*-C-*-
ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc. ffitarget.h - Copyright (c) 1996-2003 Red Hat, Inc.
Copyright (C) 2008 Free Software Foundation, Inc.
Target configuration macros for x86 and x86-64. Target configuration macros for x86 and x86-64.
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining
...@@ -68,6 +70,8 @@ typedef enum ffi_abi { ...@@ -68,6 +70,8 @@ typedef enum ffi_abi {
/* ---- Definitions for closures ----------------------------------------- */ /* ---- Definitions for closures ----------------------------------------- */
#define FFI_CLOSURES 1 #define FFI_CLOSURES 1
#define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
#define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)
#if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN)) #if defined (X86_64) || (defined (__x86_64__) && defined (X86_DARWIN))
#define FFI_TRAMPOLINE_SIZE 24 #define FFI_TRAMPOLINE_SIZE 24
......
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