Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/Cog' into fix_include_…
Browse files Browse the repository at this point in the history
…order
  • Loading branch information
marceltaeumel committed Jul 23, 2021
2 parents c7d93aa + 95a8bd5 commit 9c9b4f4
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 630 deletions.
12 changes: 9 additions & 3 deletions build.macos32x86/common/Makefile.vm
Expand Up @@ -152,8 +152,9 @@ include ../common/Makefile.rules
svnver:
@-echo $(SVNREV)

# N.B. getversion is *not* cross compiled; it must run here and now
getversion: $(OSXCOMMONDIR)/version.c deps/version.d $(CROSSDIR)/sqSCCSVersion.h
$(CC) -x c -DVERSION_PROGRAM=1 $(ALLFLAGS) $(INCLUDES) $< -o $@
$(CC) -x c -DVERSION_PROGRAM=1 $(INCLUDES) $< -o $@
$(POSTCOMPILE)

-include deps/version.d
Expand Down Expand Up @@ -222,15 +223,20 @@ print-objects:

ignore := $(addsuffix .%, $(basename $(wildcard $(BUILD)/vm/*.ignore)))

LINKNAMEARGS:=-Wl,-headerpad_max_install_names
ifneq ($(wildcard $(VMSRCDIR)/_variable_order),)
LINKNAMEARGS:=$(LINKNAMEARGS),-order_file,$(VMSRCDIR)/_variable_order
endif

$(OBJDIR)/$(VM): $(OBJDIR) $(VMOBJ) $(LIBS)
$(CC) -arch $(TARGET_ARCH) -o $(OBJDIR)/version.o $(CFLAGS) $(INCLUDES) $(DEFS) -c $(OSXCOMMONDIR)/version.c
ifneq ($(LINK_WITH_CXX),)
$(LDCXX) -arch $(TARGET_ARCH) -isysroot $(SDK) $(CXXVERFLAGS) $(LDFLAGS) $(FRAMEWORKS) \
-Wl,-headerpad_max_install_names \
$(LINKNAMEARGS) \
-o $(OBJDIR)/$(VM) $(VMOBJ) $(filter-out $(call ignore), $(LIBS))
else
$(CC) -arch $(TARGET_ARCH) -isysroot $(SDK) $(LDFLAGS) $(FRAMEWORKS) \
-Wl,-headerpad_max_install_names \
$(LINKNAMEARGS) \
-o $(OBJDIR)/$(VM) $(VMOBJ) $(filter-out $(call ignore), $(LIBS))
endif

Expand Down
12 changes: 9 additions & 3 deletions build.macos64ARMv8/common/Makefile.vm
Expand Up @@ -155,8 +155,9 @@ include ../common/Makefile.rules
svnver:
@-echo $(SVNREV)

# N.B. getversion is *not* cross compiled; it must run here and now
getversion: $(OSXCOMMONDIR)/version.c deps/version.d $(CROSSDIR)/sqSCCSVersion.h
$(CC) -x c -DVERSION_PROGRAM=1 $(ALLFLAGS) $(INCLUDES) $< -o $@
$(CC) -x c -DVERSION_PROGRAM=1 $(INCLUDES) $< -o $@
$(POSTCOMPILE)

-include deps/version.d
Expand Down Expand Up @@ -230,17 +231,22 @@ print-objects:

ignore := $(addsuffix .%, $(basename $(wildcard $(BUILD)/vm/*.ignore)))

LINKNAMEARGS:=-Wl,-headerpad_max_install_names
ifneq ($(wildcard $(VMSRCDIR)/_variable_order),)
LINKNAMEARGS:=$(LINKNAMEARGS),-order_file,$(VMSRCDIR)/_variable_order
endif

$(OBJDIR)/$(VM): $(OBJDIR) $(VMOBJ) $(LIBS)
$(CC) -o $(OBJDIR)/version.o $(CFLAGS) $(INCLUDES) $(DEFS) -c $(OSXCOMMONDIR)/version.c
ifneq ($(LINK_WITH_CXX),)
$(LDCXX) -arch $(TARGET_ARCH) -mmacosx-version-min=$(TARGET_VERSION_MIN) \
-isysroot $(SDK) $(CXXVERFLAGS) $(LDFLAGS) $(FRAMEWORKS) \
-Wl,-headerpad_max_install_names,-order_file,$(VMSRCDIR)/_variable_order \
$(LINKNAMEARGS) \
-o $(OBJDIR)/$(VM) $(VMOBJ) $(filter-out $(call ignore), $(LIBS))
else
$(CC) -arch $(TARGET_ARCH) -mmacosx-version-min=$(TARGET_VERSION_MIN) \
-isysroot $(SDK) $(LDFLAGS) $(FRAMEWORKS) \
-Wl,-headerpad_max_install_names,-order_file,$(VMSRCDIR)/_variable_order \
$(LINKNAMEARGS) \
-o $(OBJDIR)/$(VM) $(VMOBJ) $(filter-out $(call ignore), $(LIBS))
endif

Expand Down
12 changes: 9 additions & 3 deletions build.macos64x64/common/Makefile.vm
Expand Up @@ -155,8 +155,9 @@ include ../common/Makefile.rules
svnver:
@-echo $(SVNREV)

# N.B. getversion is *not* cross compiled; it must run here and now
getversion: $(OSXCOMMONDIR)/version.c deps/version.d $(CROSSDIR)/sqSCCSVersion.h
$(CC) -x c -DVERSION_PROGRAM=1 $(ALLFLAGS) $(INCLUDES) $< -o $@
$(CC) -x c -DVERSION_PROGRAM=1 $(INCLUDES) $< -o $@
$(POSTCOMPILE)

-include deps/version.d
Expand Down Expand Up @@ -230,17 +231,22 @@ print-objects:

ignore := $(addsuffix .%, $(basename $(wildcard $(BUILD)/vm/*.ignore)))

LINKNAMEARGS:=-Wl,-headerpad_max_install_names
ifneq ($(wildcard $(VMSRCDIR)/_variable_order),)
LINKNAMEARGS:=$(LINKNAMEARGS),-order_file,$(VMSRCDIR)/_variable_order
endif

$(OBJDIR)/$(VM): $(OBJDIR) $(VMOBJ) $(LIBS)
$(CC) -o $(OBJDIR)/version.o $(CFLAGS) $(INCLUDES) $(DEFS) -c $(OSXCOMMONDIR)/version.c
ifneq ($(LINK_WITH_CXX),)
$(LDCXX) -arch $(TARGET_ARCH) -mmacosx-version-min=$(TARGET_VERSION_MIN) \
-isysroot $(SDK) $(CXXVERFLAGS) $(LDFLAGS) $(FRAMEWORKS) \
-Wl,-headerpad_max_install_names \
$(LINKNAMEARGS) \
-o $(OBJDIR)/$(VM) $(VMOBJ) $(filter-out $(call ignore), $(LIBS))
else
$(CC) -arch $(TARGET_ARCH) -mmacosx-version-min=$(TARGET_VERSION_MIN) \
-isysroot $(SDK) $(LDFLAGS) $(FRAMEWORKS) \
-Wl,-headerpad_max_install_names \
$(LINKNAMEARGS) \
-o $(OBJDIR)/$(VM) $(VMOBJ) $(filter-out $(call ignore), $(LIBS))
endif

Expand Down
43 changes: 3 additions & 40 deletions platforms/Cross/plugins/IA32ABI/arm32abicc.c
Expand Up @@ -24,10 +24,9 @@
#include <setjmp.h>
#include <stdio.h> /* for fprintf(stderr,...) */

#include "sqMemoryAccess.h"
#include "objAccess.h"
#include "vmCallback.h"
#include "sqAssert.h"
#include "sqVirtualMachine.h"
#include "ia32abi.h"

#if !defined(min)
Expand All @@ -47,48 +46,12 @@ struct VirtualMachine* interpreterProxy;
# define alloca _alloca
#endif

#define RoundUpPowerOfTwo(value, modulus) \
#define RoundUpPowerOfTwo(value, modulus) \
(((value) + (modulus) - 1) & ~((modulus) - 1))

#define IsAlignedPowerOfTwo(value, modulus) \
#define IsAlignedPowerOfTwo(value, modulus) \
(((value) & ((modulus) - 1)) == 0)

#define objIsAlien(anOop) \
(interpreterProxy->includesBehaviorThatOf( \
interpreterProxy->fetchClassOf(anOop), \
interpreterProxy->classAlien()))

#define objIsUnsafeAlien(anOop) \
(interpreterProxy->includesBehaviorThatOf( \
interpreterProxy->fetchClassOf(anOop), \
interpreterProxy->classUnsafeAlien()))

#define sizeField(alien) \
(*(long*)pointerForOop((sqInt)(alien) + BaseHeaderSize))

#define dataPtr(alien) \
pointerForOop((sqInt)(alien) + BaseHeaderSize + BytesPerOop)

#define isIndirect(alien) \
(sizeField(alien) < 0)

#define startOfParameterData(alien) \
(isIndirect(alien) ? *(void **)dataPtr(alien) \
: (void *)dataPtr(alien))

#define isIndirectSize(size) \
((size) < 0)

#define startOfDataWithSize(alien, size) \
(isIndirectSize(size) ? *(void **)dataPtr(alien) \
: (void *)dataPtr(alien))

#define isSmallInt(oop) \
((oop)&1)

#define intVal(oop) \
(((long)(oop))>>1)

/*
* Call a foreign function that answers an integral result in r0 according to
* ARM EABI rules.
Expand Down
81 changes: 28 additions & 53 deletions platforms/Cross/plugins/IA32ABI/arm64abicc.c
Expand Up @@ -15,18 +15,20 @@
#include <unistd.h> // for getpagesize/sysconf
#include <stdlib.h> // for valloc
#include <sys/mman.h> // for mprotect
# if defined(MAP_JIT) && __APPLE__ // for pthread_jit_write_protect_np
#if __APPLE__ && __MACH__ /* Mac OS X */
# if defined(MAP_JIT) // for pthread_jit_write_protect_np
# include <pthread.h>
# endif
# endif
# include <libkern/OSCacheControl.h>
#endif

#include <string.h> // for memcpy et al
#include <setjmp.h>
#include <stdio.h> // for fprintf(stderr,...)

#include "sqMemoryAccess.h"
#include "objAccess.h"
#include "vmCallback.h"
#include "sqAssert.h"
#include "sqVirtualMachine.h"
#include "ia32abi.h"

#if !defined(min)
Expand All @@ -46,49 +48,12 @@ struct VirtualMachine* interpreterProxy;
# define alloca _alloca
#endif

#define RoundUpPowerOfTwo(value, modulus) \
#define RoundUpPowerOfTwo(value, modulus) \
(((value) + (modulus) - 1) & ~((modulus) - 1))

#define IsAlignedPowerOfTwo(value, modulus) \
#define IsAlignedPowerOfTwo(value, modulus) \
(((value) & ((modulus) - 1)) == 0)

#define objIsAlien(anOop) \
(interpreterProxy->includesBehaviorThatOf( \
interpreterProxy->fetchClassOf(anOop), \
interpreterProxy->classAlien()))

#define objIsUnsafeAlien(anOop) \
(interpreterProxy->includesBehaviorThatOf( \
interpreterProxy->fetchClassOf(anOop), \
interpreterProxy->classUnsafeAlien()))

#define sizeField(alien) \
(*(long*)pointerForOop((sqLong)(alien) + BaseHeaderSize))

#define dataPtr(alien) \
pointerForOop((sqLong)(alien) + BaseHeaderSize + BytesPerOop)

#define isIndirect(alien) \
(sizeField(alien) < 0)

#define startOfParameterData(alien) \
(isIndirect(alien) ? *(void **)dataPtr(alien) \
: (void *)dataPtr(alien))

#define isIndirectSize(size) \
((size) < 0)

#define startOfDataWithSize(alien, size) \
(isIndirectSize(size) ? *(void **)dataPtr(alien) \
: (void *)dataPtr(alien))

#define isSmallInt(oop) \
((oop)&1)

#define intVal(oop) \
(((long)(oop))>>1)


/*
* Call a foreign function to set x8 structure result address return register
*/
Expand Down Expand Up @@ -125,10 +90,11 @@ extern sqLong returnX1value()
* ARM EABI rules.
*/
sqLong callIA32IntegralReturn(SIGNATURE) {
long (*f)(long r0, long r1, long r2, long r3,
double d0, double d1, double d2, double d3,
double d4, double d5, double d6, double d7);
long r;
sqInt (*f)(long r0, long r1, long r2, long r3,
long r4, long r5, long r6, long r7,
double d0, double d1, double d2, double d3,
double d4, double d5, double d6, double d7);
sqInt r;
#include "dabusinessARM.h"
}

Expand All @@ -138,6 +104,7 @@ sqLong callIA32IntegralReturn(SIGNATURE) {
*/
sqLong callIA32FloatReturn(SIGNATURE) {
float (*f)(long r0, long r1, long r2, long r3,
long r4, long r5, long r6, long r7,
double d0, double d1, double d2, double d3,
double d4, double d5, double d6, double d7);
float r;
Expand All @@ -151,6 +118,7 @@ sqLong callIA32FloatReturn(SIGNATURE) {
sqInt
callIA32DoubleReturn(SIGNATURE) {
double (*f)(long r0, long r1, long r2, long r3,
long r4, long r5, long r6, long r7,
double d0, double d1, double d2, double d3,
double d4, double d5, double d6, double d7);
double r;
Expand Down Expand Up @@ -195,9 +163,8 @@ thunkEntry(long x0, long x1, long x2, long x3,
void *thunkpPlus16, sqIntptr_t *stackp)
{
VMCallbackContext vmcc; /* See, e.g. spurstack64src/vm/vmCallback.h */
int flags;
int returnType;
long regArgs[ NUM_REG_ARGS];
int flags, returnType;
sqIntptr_t regArgs[NUM_REG_ARGS];
double dregArgs[NUM_DREG_ARGS];

regArgs[0] = x0;
Expand Down Expand Up @@ -308,9 +275,13 @@ allocateExecutablePage(sqIntptr_t *size)
# define MAP_FLAGS (MAP_ANON | MAP_PRIVATE)
# endif

void **newAllocatedPages;
if (!pagesize)
# if !defined(_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 200112L
pagesize = getpagesize();
void **newAllocatedPages;
# else
pagesize = sysconf(_SC_PAGESIZE);
# endif

mem = mmap( 0, pagesize,
PROT_READ | PROT_WRITE | PROT_EXEC,
Expand All @@ -322,10 +293,10 @@ allocateExecutablePage(sqIntptr_t *size)
*size = pagesize;

# if defined(MAP_JIT)
++allocatedPagesSize;
newAllocatedPages = realloc(allocatedPages,
allocatedPagesSize * sizeof(void *));
++allocatedPagesSize * sizeof(void *));
if (!newAllocatedPages) {
--allocatedPagesSize;
munmap(mem, pagesize);
perror("Could not realloc allocatedPages");
return 0;
Expand Down Expand Up @@ -378,6 +349,10 @@ void
makePageExecutableAgain(char *address)
{
pthread_jit_write_protect_np(1);
#if __APPLE__ && __MACH__ /* Mac OS X */
sys_dcache_flush(address, 64);
sys_icache_invalidate(address, 64);
#endif
}
#endif // defined(MAP_JIT)
#endif /* defined(__ARM_ARCH_ISA_A64) || defined(__arm64__) || ... */
8 changes: 4 additions & 4 deletions platforms/Cross/plugins/IA32ABI/dabusiness.h
Expand Up @@ -89,10 +89,10 @@
argvec += sizeof(double);
}
else {
long v = interpreterProxy->signed32BitValueOf(arg);
long v = interpreterProxy->signedMachineIntegerValueOf(arg);
if (interpreterProxy->failed()) {
interpreterProxy->primitiveFailFor(0);
v = interpreterProxy->positive32BitValueOf(arg);
v = interpreterProxy->positiveMachineIntegerValueOf(arg);
if (interpreterProxy->failed())
return PrimErrBadArgument;
}
Expand Down Expand Up @@ -130,10 +130,10 @@
argvec += sizeof(double);
}
else {
long v = interpreterProxy->signed32BitValueOf(arg);
long v = interpreterProxy->signedMachineIntegerValueOf(arg);
if (interpreterProxy->failed()) {
interpreterProxy->primitiveFailFor(0);
v = interpreterProxy->positive32BitValueOf(arg);
v = interpreterProxy->positiveMachineIntegerValueOf(arg);
if (interpreterProxy->failed())
return PrimErrBadArgument;
}
Expand Down

0 comments on commit 9c9b4f4

Please sign in to comment.