Commit cd41c847 by Zdenek Dvorak Committed by Zdenek Dvorak

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
parent 731458a4
2003-03-21 Zdenek Dvorak <rakdver@atrey.karlin.mff.cuni.cz>
* 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 <a.tobler@schweiz.ch> 2003-03-03 Andreas Tobler <a.tobler@schweiz.ch>
* src/powerpc/darwin_closure.S: Recode to fit dynamic libraries. * src/powerpc/darwin_closure.S: Recode to fit dynamic libraries.
......
...@@ -170,6 +170,13 @@ extern "C" { ...@@ -170,6 +170,13 @@ extern "C" {
#endif #endif
#endif #endif
#ifdef X86_64
#if defined (__i386__)
#undef X86_64
#define X86
#endif
#endif
#ifndef LIBFFI_ASM #ifndef LIBFFI_ASM
/* ---- Generic type definitions ----------------------------------------- */ /* ---- Generic type definitions ----------------------------------------- */
......
...@@ -214,35 +214,29 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif, ...@@ -214,35 +214,29 @@ void ffi_call(/*@dependent@*/ ffi_cif *cif,
static void ffi_prep_incoming_args_SYSV (char *stack, void **ret, static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
void** args, ffi_cif* cif); void** args, ffi_cif* cif);
static void ffi_closure_SYSV (); static void ffi_closure_SYSV (ffi_closure *)
static void ffi_closure_raw_SYSV (); __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 /* This function is jumped to by the trampoline */
* 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.
*/
static void static void
ffi_closure_SYSV () ffi_closure_SYSV (closure)
ffi_closure *closure;
{ {
// this is our return value storage // this is our return value storage
long double res; long double res;
// our various things... // our various things...
void *args;
ffi_cif *cif; ffi_cif *cif;
void **arg_area; void **arg_area;
ffi_closure *closure;
unsigned short rtype; unsigned short rtype;
void *resp = (void*)&res; void *resp = (void*)&res;
void *args = __builtin_dwarf_cfa ();
/* grab the trampoline context pointer */
asm ("movl %%ecx,%0" : "=r" (closure));
cif = closure->cif; cif = closure->cif;
arg_area = (void**) alloca (cif->nargs * sizeof (void*)); arg_area = (void**) alloca (cif->nargs * sizeof (void*));
asm ("leal 8(%%ebp),%0" : "=q" (args));
/* this call will initialize ARG_AREA, such that each /* this call will initialize ARG_AREA, such that each
* element in that array points to the corresponding * element in that array points to the corresponding
...@@ -330,11 +324,11 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, ...@@ -330,11 +324,11 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
({ unsigned char *__tramp = (unsigned char*)(TRAMP); \ ({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
unsigned int __fun = (unsigned int)(FUN); \ unsigned int __fun = (unsigned int)(FUN); \
unsigned int __ctx = (unsigned int)(CTX); \ unsigned int __ctx = (unsigned int)(CTX); \
unsigned int __dis = __fun - ((unsigned int) __tramp + 10); \ unsigned int __dis = __fun - ((unsigned int) __tramp + FFI_TRAMPOLINE_SIZE); \
*(unsigned char*) &__tramp[0] = 0xb9; \ *(unsigned char*) &__tramp[0] = 0xb8; \
*(unsigned int*) &__tramp[1] = __ctx; \ *(unsigned int*) &__tramp[1] = __ctx; /* movl __ctx, %eax */ \
*(unsigned char*) &__tramp[5] = 0xe9; \ *(unsigned char *) &__tramp[5] = 0xe9; \
*(unsigned int*) &__tramp[6] = __dis; \ *(unsigned int*) &__tramp[6] = __dis; /* jmp __fun */ \
}) })
...@@ -364,30 +358,23 @@ ffi_prep_closure (ffi_closure* closure, ...@@ -364,30 +358,23 @@ ffi_prep_closure (ffi_closure* closure,
#if !FFI_NO_RAW_API #if !FFI_NO_RAW_API
static void static void
ffi_closure_raw_SYSV () ffi_closure_raw_SYSV (closure)
ffi_raw_closure *closure;
{ {
// this is our return value storage // this is our return value storage
long double res; long double res;
// our various things... // our various things...
void *args;
ffi_raw *raw_args; ffi_raw *raw_args;
ffi_cif *cif; ffi_cif *cif;
ffi_raw_closure *closure;
unsigned short rtype; unsigned short rtype;
void *resp = (void*)&res; 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 */ /* get the cif */
cif = closure->cif; cif = closure->cif;
/* the SYSV/X86 abi matches the RAW API exactly, well.. almost */ /* 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); (closure->fun) (cif, resp, raw_args, closure->user_data);
......
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