Skip to content

Commit

Permalink
CogVM source as per VMMaker.oscog-eem.3156
Browse files Browse the repository at this point in the history
CoInterpreter: Fix issues with the PrimCallXXX flags. PrimCallIsInternalPrim
wasn't initialized!! PrimCallIsExternalCall isn't used.  PrimCallIsInternalPrim
should be set on all numbered primitives except the FFI & named prim primitives.

ThreadedFFI ARM64 plugin:
Apple diverges significantly from the standard.  In particular, stacked
arguments are packed like a struct (char takes one byte, short is aligned
on a doublebyte boundary and takes two bytes, etc). Hence introduce
ThreadedARM64AppleFFIPlugin as a subclass of ThreadedARM64FFIPlugin.

Have ThreadedARM64FFIPlugin inherit from ThreadedFFIPlugin; it inherits nothing
from ThreadedARM32FFIPlugin. Rename the ThreadedFFIX64SixteenByteReturnXX
classes since they are more generally useful.  In particular use
ThreadedFFI64Bit16ByteReturnII to implement struct (and integer) return
on ARM64.  Hence get rid of getX1register (& returnX1value from arm64abicc.c).

Fix two typos in primitiveSignedInt32At et al.

Unix aio.c: rename epollEventsByFileDescriptorSize to epollEventsDescriptorCount
and improve commenting of #if#then#else chains.

unix/plugins/FileDialogPlugin/sqUnixFileDialog.c apply the fix for include files
from Bruce; thanks!!
  • Loading branch information
eliotmiranda committed Feb 16, 2022
1 parent 6bd78bc commit 1bb9679
Show file tree
Hide file tree
Showing 36 changed files with 6,528 additions and 794 deletions.
23 changes: 7 additions & 16 deletions platforms/Cross/plugins/IA32ABI/arm64abicc.c
Expand Up @@ -57,7 +57,8 @@ struct VirtualMachine* interpreterProxy;
/*
* Call a foreign function to set x8 structure result address return register
*/
extern void callAndReturnWithStructAddr(sqLong structAddr, sqLong procAddr, sqLong regValuesArrayAddr)
void
callAndReturnWithStructAddr(sqLong structAddr, sqLong procAddr, sqLong regValuesArrayAddr)
{ /* Any float regs already loaded
Place alloca'd struct address in x8 for results.
Spread int args into int registers.
Expand All @@ -75,21 +76,12 @@ extern void callAndReturnWithStructAddr(sqLong structAddr, sqLong procAddr, sqLo
);
}

/*
* Call a foreign function to get structure value from X1
* (x0's value already returned as result of ffi call)
*/
extern sqLong returnX1value()
{
asm volatile ("mov x0, x1");
}


/*
* Call a foreign function that answers an integral result in r0 according to
* ARM EABI rules.
*/
sqLong callIA32IntegralReturn(SIGNATURE) {
sqLong
callIA32IntegralReturn(SIGNATURE) {
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,
Expand All @@ -102,7 +94,8 @@ sqLong callIA32IntegralReturn(SIGNATURE) {
* Call a foreign function that answers a single-precision floating-point
* result in VFP's s0 according to ARM EABI rules.
*/
sqLong callIA32FloatReturn(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,
Expand Down Expand Up @@ -213,9 +206,7 @@ thunkEntry(long x0, long x1, long x2, long x3,
case retword64:
return *(long *)&vmcc.rvs.valword;
case retdouble:
/* memcpy(d0, vmcc.rvs.valflt64, sizeof(double)); */
d0 = vmcc.rvs.valflt64;
return d0;
return vmcc.rvs.valflt64;
case retstruct: /*@@ FIXME:: x8 @@*/
memcpy((void *)x0, vmcc.rvs.valstruct.addr, vmcc.rvs.valstruct.size);
return x0;
Expand Down
12 changes: 7 additions & 5 deletions platforms/unix/plugins/FileDialogPlugin/sqUnixFileDialog.c
Expand Up @@ -20,14 +20,16 @@
*
* This is a shell that only implements fileDialogGetLocation
*/

#include "sq.h"
#include "sqVirtualMachine.h"
#include "FileDialogPlugin.h"
#include "sqUnixCharConv.h"

#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>

#include "sqVirtualMachine.h"
#include "sqConfig.h"
#include "sqPlatformSpecific.h"
#include "FileDialogPlugin.h"

extern struct VirtualMachine *interpreterProxy; /* signalSemaphoreWithIndex */

Expand Down Expand Up @@ -184,7 +186,7 @@ char *fileDialogGetLocation(char *location){
return path;
}
}
#if 0
#if 0 // this is for reference, listing the full set of names
if (strcmp("preferences", location) == 0) {
err = FSFindFolder(kUserDomain, kPreferencesFolderType, 1, &fsRef);
}
Expand Down
73 changes: 36 additions & 37 deletions platforms/unix/vm/aio.c
Expand Up @@ -115,7 +115,7 @@ long aioDebugLogging = 0;
#if HAVE_CONFIG_H && HAVE_EPOLL
static int epollFd= -1;
static struct epoll_event** epollEventsByFileDescriptor;
static size_t epollEventsByFileDescriptorSize;
static size_t epollEventsDescriptorCount;

struct epollEventData {
int fd;
Expand All @@ -137,7 +137,7 @@ const static int epollFlagsForAIOFlags[] = {
EPOLLIN | EPOLLOUT | EPOLLPRI // AIO_RWX
};

#else
#else // HAVE_CONFIG_H && HAVE_EPOLL

# define _DO_FLAG_TYPE() do { _DO(AIO_R, rd) _DO(AIO_W, wr) _DO(AIO_X, ex) } while (0)

Expand All @@ -153,7 +153,7 @@ static fd_set rdMask; /* handle read */
static fd_set wrMask; /* handle write */
static fd_set exMask; /* handle exception */
static fd_set xdMask; /* external descriptor */
#endif
#endif // HAVE_CONFIG_H && HAVE_EPOLL

static void
undefinedHandler(int fd, void *clientData, int flags)
Expand Down Expand Up @@ -218,17 +218,17 @@ static int stderrIsAFile = 0; // for pollpip to avoid cluttering logs

#if HAVE_CONFIG_H && HAVE_EPOLL
static void
growEpollEventsByFileDescriptorTo(size_t newSize) {
FPRINTF((stderr, "growEpollEventsByFileDescriptorTo(%lu)\n", newSize));
if (newSize <= epollEventsByFileDescriptorSize) return;
struct epoll_event** newEpollEventsByFileDescriptor = (struct epoll_event**)realloc(epollEventsByFileDescriptor, newSize * sizeof(*epollEventsByFileDescriptor));
growEpollEventsDescriptorCountTo(size_t newCount) {
FPRINTF((stderr, "growEpollEventsDescriptorCountTo(%lu)\n", newCount));
if (newCount <= epollEventsDescriptorCount) return;
struct epoll_event** newEpollEventsByFileDescriptor = (struct epoll_event**)realloc(epollEventsByFileDescriptor, newCount * sizeof(*epollEventsByFileDescriptor));
if (!newEpollEventsByFileDescriptor) {
perror("growEpollEventsByFileDescriptorTo realloc");
perror("growEpollEventsDescriptorCountTo realloc");
exit(1); // Cannot recover from here
}
epollEventsByFileDescriptor = newEpollEventsByFileDescriptor;
memset(epollEventsByFileDescriptor + epollEventsByFileDescriptorSize, 0, (newSize - epollEventsByFileDescriptorSize) * sizeof(*epollEventsByFileDescriptor));
epollEventsByFileDescriptorSize = newSize;
memset(epollEventsByFileDescriptor + epollEventsDescriptorCount, 0, (newCount - epollEventsDescriptorCount) * sizeof(*epollEventsByFileDescriptor));
epollEventsDescriptorCount = newCount;
}

static void
Expand All @@ -241,10 +241,10 @@ epollInit(void)
perror("epoll_create1 failed");
exit(1);
}
epollEventsByFileDescriptorSize = 0;
epollEventsDescriptorCount = 0;
epollEventsByFileDescriptor = NULL;
}
#endif
#endif // HAVE_CONFIG_H && HAVE_EPOLL


void
Expand Down Expand Up @@ -303,7 +303,7 @@ void
aioFini(void)
{
#if HAVE_CONFIG_H && HAVE_EPOLL
for (int index = 0; index < epollEventsByFileDescriptorSize; ++index) {
for (int index = 0; index < epollEventsDescriptorCount; ++index) {
struct epoll_event* event = epollEventsByFileDescriptor[index];
if (event) {
struct epollEventData* data = event->data.ptr;
Expand Down Expand Up @@ -370,34 +370,27 @@ aioPoll(long microSeconds)
{
#if HAVE_CONFIG_H && HAVE_EPOLL

# if AIO_DEBUG
struct sigaction current_sigio_action;
extern void forceInterruptCheck(int); /* not really, but hey */
# endif

DO_TICK(SHOULD_TICK());

# if defined(AIO_DEBUG)
# if AIO_DEBUG >= 2
FPRINTF((stderr, "aioPoll(%ld)\n", microSeconds));
# endif
{ extern void forceInterruptCheck(int);
struct sigaction current_sigio_action;
// check that our signal handler is in place.
// If it isn't, things aren't right.
sigaction(SIGIO, NULL, &current_sigio_action);
assert(current_sigio_action.sa_handler == forceInterruptCheck);
}
# endif
/*
* get out early if there is no pending i/o and no need to relinquish
* cpu
*/

# ifdef TARGET_OS_IS_IPHONE
if (epollEventsByFileDescriptorSize == 0)
if (epollEventsDescriptorCount == 0 && microSeconds == 0)
return 0;
# else
if (epollEventsByFileDescriptorSize == 0 && microSeconds == 0)
return 0;
# endif

do {
const unsigned long long start = ioUTCMicroseconds();
Expand Down Expand Up @@ -446,7 +439,9 @@ aioPoll(long microSeconds)
microSeconds -= max(ioUTCMicroseconds() - start, 1);
} while(microSeconds > 0);
return 0;
#else

#else // HAVE_CONFIG_H && HAVE_EPOLL

int fd;
fd_set rd, wr, ex;
unsigned long long us;
Expand Down Expand Up @@ -523,7 +518,7 @@ aioPoll(long microSeconds)
_DO_FLAG_TYPE();
}
return 1;
#endif
#endif // HAVE_CONFIG_H && HAVE_EPOLL
}


Expand Down Expand Up @@ -611,10 +606,11 @@ aioEnable(int fd, void *data, int flags)
return;
}
#if HAVE_CONFIG_H && HAVE_EPOLL
if (fd >= epollEventsByFileDescriptorSize) {
if (fd >= epollEventsDescriptorCount) {
FPRINTF((stderr, "aioEnable(%d): fd too large\n", fd));
growEpollEventsByFileDescriptorTo(max(epollEventsByFileDescriptorSize * 2, (size_t)fd + 1));
} else if (epollEventsByFileDescriptor[fd]) {
growEpollEventsDescriptorCountTo(max(epollEventsDescriptorCount * 2, (size_t)fd + 1));
}
else if (epollEventsByFileDescriptor[fd]) {
FPRINTF((stderr, "aioEnable: descriptor %d already enabled\n", fd));
return;
}
Expand Down Expand Up @@ -643,15 +639,16 @@ aioEnable(int fd, void *data, int flags)
if (flags & AIO_EXT) {
/* we should not set NBIO ourselves on external descriptors! */
FPRINTF((stderr, "aioEnable(%d, %p, %d): external\n", fd, data, flags));
} else {
}
else {
FPRINTF((stderr, "aioEnable(%d, %p, %d): enable non-blocking io and sigio\n", fd, data, flags));
/*
* enable non-blocking asynchronous i/o and delivery of SIGIO
* to the active process
*/
makeFileDescriptorNonBlockingAndSetupSigio(fd);
}
#else
#else // HAVE_CONFIG_H && HAVE_EPOLL
if (fd >= FD_SETSIZE) {
FPRINTF((stderr, "aioEnable(%d): fd too large\n", fd));
return;
Expand Down Expand Up @@ -682,7 +679,7 @@ aioEnable(int fd, void *data, int flags)
FD_CLR(fd, &xdMask);
makeFileDescriptorNonBlockingAndSetupSigio(fd);
}
#endif
#endif // HAVE_CONFIG_H && HAVE_EPOLL
}

#if defined(AIO_DEBUG)
Expand Down Expand Up @@ -731,7 +728,7 @@ aioHandle(int fd, aioHandler handlerFn, int mask)
return;
}
#if HAVE_CONFIG_H && HAVE_EPOLL
if (fd >= epollEventsByFileDescriptorSize || !epollEventsByFileDescriptor[fd]) {
if (fd >= epollEventsDescriptorCount || !epollEventsByFileDescriptor[fd]) {
FPRINTF((stderr, "aioHandle(%d): NOT ENABLED\n", fd));
return;
}
Expand All @@ -750,7 +747,8 @@ aioHandle(int fd, aioHandler handlerFn, int mask)
if (epoll_ctl(epollFd, epoll_operation, fd, event) == -1) {
perror("epoll_ctl");
FPRINTF((stderr, "aioHandle(%d, %p, %d): epoll_ctl(%d, %d, %d, %p) failed\n", fd, handlerFn, mask, epollFd, epoll_operation, fd, event));
} else {
}
else {
FPRINTF((stderr, "aioHandle(%d, %p, %d): epoll_ctl(%d, %d, %d, %p) succeeded\n", fd, handlerFn, mask, epollFd, epoll_operation, fd, event));
}
#else
Expand All @@ -775,7 +773,7 @@ aioSuspend(int fd, int mask)
}
FPRINTF((stderr, "aioSuspend(%d)\n", fd));
#if HAVE_CONFIG_H && HAVE_EPOLL
if (fd >= epollEventsByFileDescriptorSize || !epollEventsByFileDescriptor[fd]) {
if (fd >= epollEventsDescriptorCount || !epollEventsByFileDescriptor[fd]) {
FPRINTF((stderr, "aioSuspend(%d): NOT ENABLED\n", fd));
return;
}
Expand All @@ -788,7 +786,8 @@ aioSuspend(int fd, int mask)
perror("epoll_ctl");
}
FPRINTF((stderr, "aioSuspend(%d, %d): SUSPENDED\n", fd, mask));
} else {
}
else {
FPRINTF((stderr, "aioSuspend(%d, %d): NOTHING TO SUSPEND\n", fd, mask));
}
#else
Expand All @@ -814,7 +813,7 @@ aioDisable(int fd)
}
FPRINTF((stderr, "aioDisable(%d)\n", fd));
#if HAVE_CONFIG_H && HAVE_EPOLL
if (fd >= epollEventsByFileDescriptorSize || !epollEventsByFileDescriptor[fd]) {
if (fd >= epollEventsDescriptorCount || !epollEventsByFileDescriptor[fd]) {
FPRINTF((stderr, "aioDisable(%d): NOT ENABLED\n", fd));
return;
}
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/SqueakFFIPrims/ARM32FFIPlugin.c
@@ -1,9 +1,9 @@
/* Automatically generated by
VMPluginCodeGenerator VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
VMPluginCodeGenerator VMMaker.oscog-eem.3156 uuid: 1000a975-b96e-40bb-8c41-47dbd0a06e3e
from
ThreadedARM32FFIPlugin VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc
ThreadedARM32FFIPlugin VMMaker.oscog-eem.3156 uuid: 1000a975-b96e-40bb-8c41-47dbd0a06e3e
*/
static char __buildInfo[] = "ThreadedARM32FFIPlugin VMMaker.oscog-eem.3090 uuid: 3e2b8343-01bb-4169-ba4c-aecf82b4dcfc " __DATE__ ;
static char __buildInfo[] = "ThreadedARM32FFIPlugin VMMaker.oscog-eem.3156 uuid: 1000a975-b96e-40bb-8c41-47dbd0a06e3e " __DATE__ ;


#include "config.h"
Expand Down Expand Up @@ -174,7 +174,7 @@ static char __buildInfo[] = "ThreadedARM32FFIPlugin VMMaker.oscog-eem.3090 uuid:
#define MaxNumArgs 15
#define NumFloatRegArgs 16
#define NumIntRegArgs 4
#define PluginVersionInfo " VMMaker.oscog-eem.3090"
#define PluginVersionInfo " VMMaker.oscog-eem.3156"
#define PrimErrBadArgument 3
#define PrimErrBadIndex 4
#define PrimErrBadMethod 12
Expand Down Expand Up @@ -551,7 +551,7 @@ extern sqInt trueObject(void);
extern
#endif
struct VirtualMachine* interpreterProxy;
static const char *moduleName = "ARM32FFIPlugin VMMaker.oscog-eem.3090 " INT_EXT;
static const char *moduleName = "ARM32FFIPlugin VMMaker.oscog-eem.3156 " INT_EXT;


/*** Macros ***/
Expand Down Expand Up @@ -6334,7 +6334,7 @@ primitiveSignedInt16AtPut(void)
}


/* Answer the signed 16-bit integer starting at the given byte offset (native
/* Answer the signed 32-bit integer starting at the given byte offset (native
endian).
*/

Expand Down Expand Up @@ -6604,8 +6604,8 @@ primitiveUnsignedInt16At(void)
}


/* Store the signed 16-bit integer starting at the given byte offset (native
endian).
/* Store the unsigned 16-bit integer starting at the given byte offset
(native endian).
*/

/* ThreadedFFIPlugin>>#primitiveUnsignedInt16AtPut */
Expand Down

0 comments on commit 1bb9679

Please sign in to comment.