------- Comment #18 from s_j_newbury at yahoo dot co dot uk  2007-08-03 12:56 
-------
(In reply to comment #17)
> Re comment #16: I've tested this, and it seems to work.  What failures do you
> expect?
> 

/* 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 above swi uses the OABI syscall base.

>From include/asm-arm/unistd.h:
#define __NR_OABI_SYSCALL_BASE  0x900000

#if defined(__thumb__) || defined(__ARM_EABI__)
#define __NR_SYSCALL_BASE       0
#else
#define __NR_SYSCALL_BASE       __NR_OABI_SYSCALL_BASE
#endif

With EABI all syscalls are called as swi 0 with the syscall number passed in a
register rather than encoding it into the instruction (offset from 0x900000).

When the above code from ffi.c is executed on a kernel lacking the OABI syscall
handling it will fail with an illegal instruction trap.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31325

Reply via email to