Skip to content

Commit

Permalink
Revise the ARM32 thunkEntry code to
Browse files Browse the repository at this point in the history
- compute thunkEntry from the supplied parameter in ARM32 thunks, which is the
  thunk's address plus 16.  See Alien-eem.35 FFICallbackThunk>>initializeARM32.
- change the return type to long long to allow returning doubles and long longs.
This plus Alien-eem.35 provide functional ARM32 callbacks.
  • Loading branch information
eliotmiranda committed Jun 23, 2016
1 parent 1b1c25e commit da3fafd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
33 changes: 12 additions & 21 deletions platforms/Cross/plugins/IA32ABI/arm32ia32abicc.c
Expand Up @@ -147,14 +147,14 @@ extern void error(char *s);
* return to it, to correct C stack pointer alignment if necessary (see
* STACK_ALIGN_HACK), and to return any of the various values from the callback.
*/
long
long long
thunkEntry(long r0, long r1, long r2, long r3,
double d0, double d1, double d2, double d3,
double d4, double d5, double d6, double d7,
void* thunkp, long* stackp)
void *thunkpPlus16, long *stackp)
{
VMCallbackContext vmcc;
VMCallbackContext* previousCallbackContext;
VMCallbackContext *previousCallbackContext;
int flags;
int returnType;
long regArgs[NUM_REG_ARGS];
Expand Down Expand Up @@ -183,8 +183,8 @@ thunkEntry(long r0, long r1, long r2, long r3,
if ((returnType = setjmp(vmcc.trampoline)) == 0) {
previousCallbackContext = getRMCC();
setRMCC(&vmcc);
vmcc.thunkp = thunkp;
vmcc.stackp = stackp + 2; /* skip address of retpc & retpc (thunk) */
vmcc.thunkp = (void *)((char *)thunkpPlus16 - 16);
vmcc.stackp = stackp;
vmcc.intregargsp = regArgs;
vmcc.floatregargsp = dregArgs;
interpreterProxy->sendInvokeCallbackContext(&vmcc);
Expand All @@ -198,23 +198,14 @@ thunkEntry(long r0, long r1, long r2, long r3,
interpreterProxy->disownVM(flags);

switch (returnType) {
case retword: {
case retword:
return vmcc.rvs.valword;
}
case retword64: {
long long* valint64Ptr = (long long*)&vmcc.rvs.valleint64;
return *valint64Ptr;
}
case retdouble: {
double valflt64 = vmcc.rvs.valflt64;
error("Callback return double unimplemented");
return 0;
}
case retstruct: {
// wrong
memcpy( (void *)(stackp[1]), vmcc.rvs.valstruct.addr, vmcc.rvs.valstruct.size);
return stackp[1];
}
case retword64:
case retdouble:
return *(long long *)&vmcc.rvs.valword;
case retstruct:
memcpy((void *)r0, vmcc.rvs.valstruct.addr, vmcc.rvs.valstruct.size);
return r0;
}

fprintf(stderr, "Warning; invalid callback return type\n");
Expand Down
6 changes: 5 additions & 1 deletion platforms/Cross/plugins/IA32ABI/ia32abi.h
Expand Up @@ -34,6 +34,7 @@ extern sqInt callIA32IntegralReturn(SIGNATURE);
extern sqInt callIA32FloatReturn (SIGNATURE);
extern sqInt callIA32DoubleReturn (SIGNATURE);

#define thunkEntryType long
#if defined(i386) || defined(__i386) || defined(__i386__)
# define INT_REG_ARGS /* none */
# define DBL_REG_ARGS /* none */
Expand All @@ -49,12 +50,15 @@ extern sqInt callIA32DoubleReturn (SIGNATURE);
# define INT_REG_ARGS long,long,long,long,long,long,long,long,
# define DBL_REG_ARGS /* none */
#elif defined(__ARM_ARCH__) || defined(__arm__) || defined(__arm32__) || defined(ARM32)
# undef thunkEntryType
# define thunkEntryType long long
# define INT_REG_ARGS long,long,long,long,
# define DBL_REG_ARGS double,double,double,double,double,double,double,double,
#endif
extern long thunkEntry (INT_REG_ARGS DBL_REG_ARGS void *,long *);
extern thunkEntryType thunkEntry (INT_REG_ARGS DBL_REG_ARGS void *,long *);
extern void *allocateExecutablePage(long *pagesize);
extern VMCallbackContext *getMostRecentCallbackContext(void);
#undef thunkEntryType

/* Use the most minimal setjmp/longjmp pair available; no signal handling
* wanted or necessary.
Expand Down

0 comments on commit da3fafd

Please sign in to comment.