Skip to content

Commit

Permalink
Merge branch 'Cog' of github.com:OpenSmalltalk/opensmalltalk-vm into …
Browse files Browse the repository at this point in the history
…merge-with-pharo
  • Loading branch information
estebanlm committed Sep 11, 2016
2 parents e46d32e + ddf2aa4 commit 7bd52ba
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 56 deletions.
2 changes: 2 additions & 0 deletions platforms/Cross/plugins/IA32ABI/ia32abi.h
Expand Up @@ -39,6 +39,8 @@ extern sqInt callIA32DoubleReturn (SIGNATURE);
# define INT_REG_ARGS /* none */
# define DBL_REG_ARGS /* none */
#elif WIN64 || defined(_M_X64) || defined(_M_AMD64) || defined(_WIN64)
# undef thunkEntryType
# define thunkEntryType long long
# define INT_REG_ARGS long long,long long,long long,long long,
# define DBL_REG_ARGS /* double,double,double,double, NOT INCLUDED because only 4 parameters are passed in registers, either int or float */
#elif defined(__amd64__) || defined(__x86_64__) || defined(__amd64) || defined(__x86_64)
Expand Down
68 changes: 14 additions & 54 deletions platforms/Cross/plugins/IA32ABI/x64win64ia32abicc.c
Expand Up @@ -177,7 +177,8 @@ getMostRecentCallbackContext() { return mostRecentCallbackContext; }
* address of retpc-/ <--\
* address of address of ret pc-/
* thunkp
* esp->retpc (thunkEntry)
* space for saving 4 registers rcx,rdx,r8,r9
* rsp->retpc (thunkEntry)
*
* This function's roles are to use setjmp/longjmp to save the call point
* and return to it, and to return any of the various values from the callback.
Expand All @@ -189,7 +190,7 @@ getMostRecentCallbackContext() { return mostRecentCallbackContext; }
* passed as an element of the VMCallbackContext.
*/

long
long long
thunkEntry(long long rcx, long long rdx,
long long r8, long long r9,
void *thunkp, sqIntptr_t *stackp)
Expand All @@ -199,37 +200,14 @@ thunkEntry(long long rcx, long long rdx,
long long flags, returnType;
long long intargs[4];
double fpargs[4];

intargs[0] = rcx;
intargs[1] = rdx;
intargs[2] = r8;
intargs[3] = r9;

int64_or_double regs[4];
regs[0].i = rcx;
regs[1].i = rdx;
regs[2].i = r8;
regs[3].i = r9;

intargs[0] = regs[0].i;
intargs[1] = regs[1].i;
intargs[2] = regs[2].i;
intargs[3] = regs[3].i;

fpargs[0] = regs[0].d;
fpargs[1] = regs[1].d;
fpargs[2] = regs[2].d;
fpargs[3] = regs[3].d;

/* loadFloatRegs(regs[0].d,regs[1].d,regs[2].d,regs[3].d); */
#if _MSC_VER
_asm mov rcx, xmm0;
_asm mov rdx, xmm1;
_asm mov r8 , xmm2;
_asm mov r9 , xmm3;
#elif __GNUC__
asm("movq %rcx,%xmm0");
asm("movq %rdx,%xmm1");
asm("movq %r8 ,%xmm2");
asm("movq %r9 ,%xmm3");
#else
# error need to load edx with vmcc.rvs.valleint64.high on this compiler
#endif
extern void saveFloatRegsWin64(long long xmm0,long long xmm1,long long xmm2, long long xmm3,double *fpargs); /* fake passing long long args */
saveFloatRegsWin64(rcx,rdx,r8,r9,fpargs); /* the callee expects double parameters that it will retrieve thru registers */

if ((flags = interpreterProxy->ownVM(0)) < 0) {
fprintf(stderr,"Warning; callback failed to own the VM\n");
Expand All @@ -256,29 +234,11 @@ thunkEntry(long long rcx, long long rdx,

case retword: return vmcc.rvs.valword;

case retword64: {
long vhigh = vmcc.rvs.valleint64.high;
#if _MSC_VER
_asm mov edx, dword ptr vhigh;
#elif __GNUC__
asm("mov %0,%%edx" : : "m"(vhigh));
#else
# error need to load edx with vmcc.rvs.valleint64.high on this compiler
#endif
return vmcc.rvs.valleint64.low;
}
case retword64: return (((unsigned long long)vmcc.rvs.valleint64.high) << 32) | (unsigned int)vmcc.rvs.valleint64.low;

case retdouble: {
double valflt64 = vmcc.rvs.valflt64;
#if _MSC_VER
_asm fld qword ptr valflt64;
#elif __GNUC__
asm("fldl %0" : : "m"(valflt64));
#else
# error need to load %f0 with vmcc.rvs.valflt64 on this compiler
#endif
return 0;
}
case retdouble:
fakeReturnDouble( vmcc.rvs.valflt64 );
return 0;

case retstruct: memcpy( (void *)(stackp[1]),
vmcc.rvs.valstruct.addr,
Expand Down
22 changes: 22 additions & 0 deletions platforms/Cross/plugins/IA32ABI/x64win64stub.c
@@ -0,0 +1,22 @@
/* Stub for X64 Win64
This function must lie into another file than x64win64abicc
otherwise C Compiler will detect the parameter mismatch and bark,
or worse, optimize the call away.
*/

#if x86_64|x64|__x86_64|__x86_64__|_M_AMD64|_M_X64
#ifdef WIN32
/* Copy the floating point values passed by register into a table fpargs */
void saveFloatRegsWin64(double xmm0,double xmm1,double xmm2, double xmm3,double *fpargs)
{
fpargs[0]=xmm0;
fpargs[1]=xmm1;
fpargs[2]=xmm2;
fpargs[3]=xmm3;
}
double fakeReturnDouble(double xmm0)
{
return xmm0;
}
#endif
#endif
2 changes: 1 addition & 1 deletion platforms/win32/plugins/IA32ABI/Makefile
@@ -1,3 +1,3 @@
LIBOBJ:= xabicc.o IA32ABI.o
LIBOBJ:= xabicc.o IA32ABI.o x64win64stub.o

include ../../Makefile.plugin
2 changes: 1 addition & 1 deletion platforms/win32/plugins/IA32ABI/Makefile.plugin
@@ -1,3 +1,3 @@
LIBOBJ:= xabicc.o IA32ABI.o
LIBOBJ:= xabicc.o IA32ABI.o x64win64stub.o

include ../common/Makefile.plugin

0 comments on commit 7bd52ba

Please sign in to comment.