From cd41c847e78ec5063fbc47a8ddfebc9e53451fff Mon Sep 17 00:00:00 2001 From: Zdenek Dvorak Date: Fri, 21 Mar 2003 14:43:20 +0100 Subject: ffi.h.in: Define X86 instead of X86_64 in 32 bit mode. * libffi/include/ffi.h.in: Define X86 instead of X86_64 in 32 bit mode. * libffi/src/x86/ffi.c (ffi_closure_SYSV, ffi_closure_raw_SYSV): Receive closure pointer through parameter, read args using __builtin_dwarf_cfa. (FFI_INIT_TRAMPOLINE): Send closure reference through eax. From-SVN: r64663 --- libffi/ChangeLog | 9 +++++++++ libffi/include/ffi.h.in | 7 +++++++ libffi/src/x86/ffi.c | 45 ++++++++++++++++----------------------------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libffi/ChangeLog b/libffi/ChangeLog index 89dded9..01517c1 100644 --- a/libffi/ChangeLog +++ b/libffi/ChangeLog @@ -1,3 +1,12 @@ +2003-03-21 Zdenek Dvorak + + * libffi/include/ffi.h.in: Define X86 instead of X86_64 in 32 + bit mode. + * libffi/src/x86/ffi.c (ffi_closure_SYSV, ffi_closure_raw_SYSV): + Receive closure pointer through parameter, read args using + __builtin_dwarf_cfa. + (FFI_INIT_TRAMPOLINE): Send closure reference through eax. + 2003-03-03 Andreas Tobler * src/powerpc/darwin_closure.S: Recode to fit dynamic libraries. diff --git a/libffi/include/ffi.h.in b/libffi/include/ffi.h.in index 0285384..fe91ecd 100644 --- a/libffi/include/ffi.h.in +++ b/libffi/include/ffi.h.in @@ -170,6 +170,13 @@ extern "C" { #endif #endif +#ifdef X86_64 +#if defined (__i386__) +#undef X86_64 +#define X86 +#endif +#endif + #ifndef LIBFFI_ASM /* ---- Generic type definitions ----------------------------------------- */ diff --git a/libffi/src/x86/ffi.c b/libffi/src/x86/ffi.c index 68135f9..bd0874f 100644 --- a/libffi/src/x86/ffi.c +++ b/libffi/src/x86/ffi.c @@ -214,35 +214,29 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif, static void ffi_prep_incoming_args_SYSV (char *stack, void **ret, void** args, ffi_cif* cif); -static void ffi_closure_SYSV (); -static void ffi_closure_raw_SYSV (); +static void ffi_closure_SYSV (ffi_closure *) + __attribute__ ((regparm(1))); +static void ffi_closure_raw_SYSV (ffi_raw_closure *) + __attribute__ ((regparm(1))); -/* This function is jumped to by the trampoline, on entry, %ecx (a - * caller-save register) holds the address of the closure. - * Clearly, this requires __GNUC__, so perhaps we should translate this - * into an assembly file if this is to be distributed with ffi. - */ +/* This function is jumped to by the trampoline */ static void -ffi_closure_SYSV () +ffi_closure_SYSV (closure) + ffi_closure *closure; { // this is our return value storage long double res; // our various things... - void *args; ffi_cif *cif; void **arg_area; - ffi_closure *closure; unsigned short rtype; void *resp = (void*)&res; + void *args = __builtin_dwarf_cfa (); - /* grab the trampoline context pointer */ - asm ("movl %%ecx,%0" : "=r" (closure)); - cif = closure->cif; arg_area = (void**) alloca (cif->nargs * sizeof (void*)); - asm ("leal 8(%%ebp),%0" : "=q" (args)); /* this call will initialize ARG_AREA, such that each * element in that array points to the corresponding @@ -330,11 +324,11 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, ({ unsigned char *__tramp = (unsigned char*)(TRAMP); \ unsigned int __fun = (unsigned int)(FUN); \ unsigned int __ctx = (unsigned int)(CTX); \ - unsigned int __dis = __fun - ((unsigned int) __tramp + 10); \ - *(unsigned char*) &__tramp[0] = 0xb9; \ - *(unsigned int*) &__tramp[1] = __ctx; \ - *(unsigned char*) &__tramp[5] = 0xe9; \ - *(unsigned int*) &__tramp[6] = __dis; \ + unsigned int __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \ + *(unsigned char*) &__tramp[0] = 0xb8; \ + *(unsigned int*) &__tramp[1] = __ctx; /* movl __ctx, %eax */ \ + *(unsigned char *) &__tramp[5] = 0xe9; \ + *(unsigned int*) &__tramp[6] = __dis; /* jmp __fun */ \ }) @@ -364,30 +358,23 @@ ffi_prep_closure (ffi_closure* closure, #if !FFI_NO_RAW_API static void -ffi_closure_raw_SYSV () +ffi_closure_raw_SYSV (closure) + ffi_raw_closure *closure; { // this is our return value storage long double res; // our various things... - void *args; ffi_raw *raw_args; ffi_cif *cif; - ffi_raw_closure *closure; unsigned short rtype; void *resp = (void*)&res; - /* grab the trampoline context pointer */ - asm ("movl %%ecx,%0" : "=r" (closure)); - - /* take the argument pointer */ - asm ("leal 8(%%ebp),%0" : "=q" (args)); - /* get the cif */ cif = closure->cif; /* the SYSV/X86 abi matches the RAW API exactly, well.. almost */ - raw_args = (ffi_raw*) args; + raw_args = (ffi_raw*) __builtin_dwarf_cfa (); (closure->fun) (cif, resp, raw_args, closure->user_data); -- cgit v1.1