11/* -----------------------------------------------------------------------
2- ffi.c - Copyright (c) 2011 Anthony Green
2+ ffi.c - Copyright (c) 2011, 2013 Anthony Green
33 Copyright (c) 1996, 2003-2004, 2007-2008 Red Hat, Inc.
44
55 SPARC Foreign Function Interface
@@ -376,6 +376,10 @@ extern int ffi_call_v8(void *, extended_cif *, unsigned,
376376 unsigned , unsigned * , void (* fn )(void ));
377377#endif
378378
379+ #ifndef __GNUC__
380+ void ffi_flush_icache (void * , size_t );
381+ #endif
382+
379383void ffi_call (ffi_cif * cif , void (* fn )(void ), void * rvalue , void * * avalue )
380384{
381385 extended_cif ecif ;
@@ -417,7 +421,7 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
417421 /* behind "call", so we alloc some executable space for it. */
418422 /* l7 is used, we need to make sure v8.S doesn't use %l7. */
419423 unsigned int * call_struct = NULL ;
420- ffi_closure_alloc (32 , & call_struct );
424+ ffi_closure_alloc (32 , ( void * * ) & call_struct );
421425 if (call_struct )
422426 {
423427 unsigned long f = (unsigned long )fn ;
@@ -432,10 +436,14 @@ void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
432436 call_struct [5 ] = 0x01000000 ; /* nop */
433437 call_struct [6 ] = 0x81c7e008 ; /* ret */
434438 call_struct [7 ] = 0xbe100017 ; /* mov %l7, %i7 */
439+ #ifdef __GNUC__
435440 asm volatile ("iflush %0; iflush %0+8; iflush %0+16; iflush %0+24" : :
436441 "r" (call_struct ) : "memory" );
437442 /* SPARC v8 requires 5 instructions for flush to be visible */
438443 asm volatile ("nop; nop; nop; nop; nop" );
444+ #else
445+ ffi_flush_icache (call_struct , 32 );
446+ #endif
439447 ffi_call_v8 (ffi_prep_args_v8 , & ecif , cif -> bytes ,
440448 cif -> flags , rvalue , call_struct );
441449 ffi_closure_free (call_struct );
@@ -513,13 +521,17 @@ ffi_prep_closure_loc (ffi_closure* closure,
513521 closure -> user_data = user_data ;
514522
515523 /* Flush the Icache. closure is 8 bytes aligned. */
524+ #ifdef __GNUC__
516525#ifdef SPARC64
517526 asm volatile ("flush %0; flush %0+8" : : "r" (closure ) : "memory" );
518527#else
519528 asm volatile ("iflush %0; iflush %0+8" : : "r" (closure ) : "memory" );
520529 /* SPARC v8 requires 5 instructions for flush to be visible */
521530 asm volatile ("nop; nop; nop; nop; nop" );
522531#endif
532+ #else
533+ ffi_flush_icache (closure , 16 );
534+ #endif
523535
524536 return FFI_OK ;
525537}
0 commit comments