aboutsummaryrefslogtreecommitdiff
path: root/libffi/src
diff options
context:
space:
mode:
Diffstat (limited to 'libffi/src')
-rw-r--r--libffi/src/arm/ffi.c119
-rw-r--r--libffi/src/arm/ffitarget.h3
-rw-r--r--libffi/src/arm/sysv.S48
3 files changed, 169 insertions, 1 deletions
diff --git a/libffi/src/arm/ffi.c b/libffi/src/arm/ffi.c
index 4a5edd3..f3cd506 100644
--- a/libffi/src/arm/ffi.c
+++ b/libffi/src/arm/ffi.c
@@ -168,3 +168,122 @@ void ffi_call(ffi_cif *cif, void (*fn)(), void *rvalue, void **avalue)
break;
}
}
+
+/** private members **/
+
+static void ffi_prep_incoming_args_SYSV (char *stack, void **ret,
+ void** args, ffi_cif* cif);
+
+void ffi_closure_SYSV (ffi_closure *);
+
+/* This function is jumped to by the trampoline */
+
+unsigned int
+ffi_closure_SYSV_inner (closure, respp, args)
+ ffi_closure *closure;
+ void **respp;
+ void *args;
+{
+ // our various things...
+ ffi_cif *cif;
+ void **arg_area;
+
+ cif = closure->cif;
+ arg_area = (void**) alloca (cif->nargs * sizeof (void*));
+
+ /* this call will initialize ARG_AREA, such that each
+ * element in that array points to the corresponding
+ * value on the stack; and if the function returns
+ * a structure, it will re-set RESP to point to the
+ * structure return address. */
+
+ ffi_prep_incoming_args_SYSV(args, respp, arg_area, cif);
+
+ (closure->fun) (cif, *respp, arg_area, closure->user_data);
+
+ return cif->flags;
+}
+
+/*@-exportheader@*/
+static void
+ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
+ void **avalue, ffi_cif *cif)
+/*@=exportheader@*/
+{
+ register unsigned int i;
+ register void **p_argv;
+ register char *argp;
+ register ffi_type **p_arg;
+
+ argp = stack;
+
+ if ( cif->flags == FFI_TYPE_STRUCT ) {
+ *rvalue = *(void **) argp;
+ argp += 4;
+ }
+
+ p_argv = avalue;
+
+ for (i = cif->nargs, p_arg = cif->arg_types; (i != 0); i--, p_arg++)
+ {
+ size_t z;
+
+ /* Align if necessary */
+ if ((sizeof(int) - 1) & (unsigned) argp) {
+ argp = (char *) ALIGN(argp, sizeof(int));
+ }
+
+ z = (*p_arg)->size;
+
+ /* because we're little endian, this is what it turns into. */
+
+ *p_argv = (void*) argp;
+
+ p_argv++;
+ argp += z;
+ }
+
+ return;
+}
+
+/* How to make a trampoline. */
+
+#define FFI_INIT_TRAMPOLINE(TRAMP,FUN,CTX) \
+({ unsigned char *__tramp = (unsigned char*)(TRAMP); \
+ unsigned int __fun = (unsigned int)(FUN); \
+ unsigned int __ctx = (unsigned int)(CTX); \
+ *(unsigned int*) &__tramp[0] = 0xe92d000f; /* stmfd sp!, {r0-r3} */ \
+ *(unsigned int*) &__tramp[4] = 0xe59f0000; /* ldr r0, [pc] */ \
+ *(unsigned int*) &__tramp[8] = 0xe59ff000; /* ldr pc, [pc] */ \
+ *(unsigned int*) &__tramp[12] = __ctx; \
+ *(unsigned int*) &__tramp[16] = __fun; \
+ register unsigned long _beg __asm ("a1") = (unsigned long) (&__tramp[0]); \
+ register unsigned long _end __asm ("a2") = (unsigned long) (&__tramp[19]); \
+ register unsigned long _flg __asm ("a3") = 0; \
+ __asm __volatile ("swi 0x9f0002 @ sys_cacheflush" \
+ : "=r" (_beg) \
+ : "0" (_beg), "r" (_end), "r" (_flg)); \
+ })
+
+
+/* the cif must already be prep'ed */
+
+ffi_status
+ffi_prep_closure_loc (ffi_closure* closure,
+ ffi_cif* cif,
+ void (*fun)(ffi_cif*,void*,void**,void*),
+ void *user_data,
+ void *codeloc)
+{
+ FFI_ASSERT (cif->abi == FFI_SYSV);
+
+ FFI_INIT_TRAMPOLINE (&closure->tramp[0], \
+ &ffi_closure_SYSV, \
+ codeloc);
+
+ closure->cif = cif;
+ closure->user_data = user_data;
+ closure->fun = fun;
+
+ return FFI_OK;
+}
diff --git a/libffi/src/arm/ffitarget.h b/libffi/src/arm/ffitarget.h
index 96f4bb2..7ba0446 100644
--- a/libffi/src/arm/ffitarget.h
+++ b/libffi/src/arm/ffitarget.h
@@ -40,7 +40,8 @@ typedef enum ffi_abi {
/* ---- Definitions for closures ----------------------------------------- */
-#define FFI_CLOSURES 0
+#define FFI_CLOSURES 1
+#define FFI_TRAMPOLINE_SIZE 20
#define FFI_NATIVE_RAW_API 0
#endif
diff --git a/libffi/src/arm/sysv.S b/libffi/src/arm/sysv.S
index c3471a8..00f43b2 100644
--- a/libffi/src/arm/sysv.S
+++ b/libffi/src/arm/sysv.S
@@ -207,3 +207,51 @@ LSYM(Lepilogue):
.ffi_call_SYSV_end:
.size CNAME(ffi_call_SYSV),.ffi_call_SYSV_end-CNAME(ffi_call_SYSV)
+/*
+ unsigned int FFI_HIDDEN
+ ffi_closure_SYSV_inner (closure, respp, args)
+ ffi_closure *closure;
+ void **respp;
+ void *args;
+*/
+
+ARM_FUNC_START ffi_closure_SYSV
+ add ip, sp, #16
+ stmfd sp!, {ip, lr}
+ add r2, sp, #8
+ sub sp, sp, #16
+ str sp, [sp, #8]
+ add r1, sp, #8
+ bl ffi_closure_SYSV_inner
+ cmp r0, #FFI_TYPE_INT
+ beq .Lretint
+ cmp r0, #FFI_TYPE_FLOAT
+ beq .Lretfloat
+ cmp r0, #FFI_TYPE_DOUBLE
+ beq .Lretdouble
+ cmp r0, #FFI_TYPE_LONGDOUBLE
+ beq .Lretlongdouble
+ cmp r0, #FFI_TYPE_SINT64
+ beq .Lretlonglong
+.Lclosure_epilogue:
+ add sp, sp, #16
+ ldmfd sp, {sp, pc}
+.Lretint:
+ ldr r0, [sp]
+ b .Lclosure_epilogue
+.Lretlonglong:
+ ldr r0, [sp]
+ ldr r1, [sp, #4]
+ b .Lclosure_epilogue
+.Lretfloat:
+ ldfs f0, [sp]
+ b .Lclosure_epilogue
+.Lretdouble:
+ ldfd f0, [sp]
+ b .Lclosure_epilogue
+.Lretlongdouble:
+ ldfd f0, [sp]
+ b .Lclosure_epilogue
+.ffi_closure_SYSV_end:
+ .size CNAME(ffi_closure_SYSV),.ffi_closure_SYSV_end-CNAME(ffi_closure_SYSV)
+