From e82b47a9e73ee31ba3d493b18c4705a7edcf2657 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 22 Dec 2023 13:13:32 -0800 Subject: [PATCH 1/6] Give emcc link-time flags only to the link phase not the compile phase --- bin/makefile-emscripten.wasm-wasm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/makefile-emscripten.wasm-wasm b/bin/makefile-emscripten.wasm-wasm index 2007eec..f092375 100644 --- a/bin/makefile-emscripten.wasm-wasm +++ b/bin/makefile-emscripten.wasm-wasm @@ -1,6 +1,6 @@ # Options for Emscripten, WASM and SDL -CC = emcc -sUSE_SDL=2 -sASYNCIFY -sALLOW_MEMORY_GROWTH $(CLANG_CFLAGS) +CC = emcc $(CLANG_CFLAGS) XFILES = $(OBJECTDIR)sdl.o @@ -11,9 +11,9 @@ OPTFLAGS = -O2 -g3 DFLAGS = $(XFLAGS) -DRELEASE=351 LD = emcc -LDFLAGS = -sUSE_SDL=2 --preload-file $(SYSOUT)@full.sysout +LDFLAGS = -sUSE_SDL=2 -sASYNCIFY -sALLOW_MEMORY_GROWTH --preload-file $(SYSOUT)@full.sysout LDELDFLAGS = OBJECTDIR = ../$(RELEASENAME)/ -default : ../$(OSARCHNAME)/lde ../$(OSARCHNAME)/ldesdl.js +default : ../$(OSARCHNAME)/ldesdl.js From f208fd33028d25220ea43916dccc371ff05fe83a Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 22 Dec 2023 13:18:20 -0800 Subject: [PATCH 2/6] Rename/move ldesdl.html out of emscripten.wasm (which gets cleared on rebuild) to src/lde.html --- emscripten.wasm/ldesdl.html => src/lde.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename emscripten.wasm/ldesdl.html => src/lde.html (100%) diff --git a/emscripten.wasm/ldesdl.html b/src/lde.html similarity index 100% rename from emscripten.wasm/ldesdl.html rename to src/lde.html From 0cc8e4d71c51663590537d92466b5b1c0d9b0f81 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 22 Dec 2023 13:35:33 -0800 Subject: [PATCH 4/6] Revert/update unixfork.c since it is no longer used in emscripten based builds --- src/unixfork.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/unixfork.c b/src/unixfork.c index b35f1ef..366495f 100644 --- a/src/unixfork.c +++ b/src/unixfork.c @@ -45,11 +45,6 @@ int flushing = 0; #endif -#ifdef MAIKO_OS_EMSCRIPTEN -/* We don't have any shell */ -#define getusershell() NULL -#endif - /* Used to communicate between Unix subprocesses and LISP */ static long StartTime; /* Time, for creating pipe filenames */ @@ -103,7 +98,7 @@ static int ForkUnixShell(int slot, char *PtySlave, char *termtype, char *shellar if (SlaveFD == -1) { perror("Slave Open"); perror(PtySlave); - exit(0); + exit(1); } #ifdef OS5 @@ -137,7 +132,7 @@ static int ForkUnixShell(int slot, char *PtySlave, char *termtype, char *shellar for (userShell = getusershell(); userShell != NULL && strcmp(shell, userShell) != 0; userShell = getusershell()); if (userShell == NULL) { perror("$(SHELL) not found in /etc/shells"); - exit(0); + exit(1); } /* argvec entries initialized to NULL */ @@ -151,7 +146,7 @@ static int ForkUnixShell(int slot, char *PtySlave, char *termtype, char *shellar /* Should never get here */ perror("execv"); - exit(0); + exit(1); } /* fork_Unix is the secondary process spawned right after LISP is @@ -269,12 +264,14 @@ int fork_Unix(void) { while (1) { ssize_t len; len = SAFEREAD(LispPipeIn, IOBuf, 6); + if (len == 0) + exit(0); if (len < 0) { perror("Error reading packet by slave"); - exit(0); + exit(1); } else if (len != 6) { DBPRINT(("Input packet wrong length: %zd", len)); - exit(0); + exit(1); } slot = IOBuf[3]; IOBuf[3] = 1; /* Start by signalling success in return-code */ @@ -350,7 +347,7 @@ int fork_Unix(void) { sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { perror("slave socket"); - exit(0); + exit(1); } sprintf(PipeName, "/tmp/LPU%ld-%d", StartTime, slot); memset(&addr, 0, sizeof(struct sockaddr_un)); @@ -362,7 +359,7 @@ int fork_Unix(void) { perror("slave connect"); printf("Name = %s.\n", PipeName); fflush(stdout); - exit(0); + exit(1); } else { DBPRINT(("Slave connected on %s.\n", PipeName)); } From b21fbcbcb1ad5907675b59cf1001c5a9f4f3928f Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 22 Dec 2023 18:15:18 -0800 Subject: [PATCH 5/6] subr_settime should avoid settimeofday() completely in Emscripten environment --- src/timer.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/timer.c b/src/timer.c index 2cb14c2..08a5874 100644 --- a/src/timer.c +++ b/src/timer.c @@ -73,11 +73,6 @@ extern int ether_fd; extern DspInterface currentdsp; #endif /* XWINDOW */ -#ifdef MAIKO_OS_EMSCRIPTEN -/* We can't touch the system clock */ -#define settimeofday(tv, tz) -#endif - #define LISP_UNIX_TIME_DIFF 29969152 #define LISP_ALTO_TIME_MASK 0x80000000 #define UNIX_ALTO_TIME_DIFF 2177452800U @@ -293,6 +288,8 @@ void subr_settime(LispPTR args[]) dosday.year = uxtime.tm_year; dosday.dayofweek = uxtime.tm_wday; _dos_setdate(&dosday); +#elif defined(MAIKO_OS_EMSCRIPTEN) + (void)args[0]; #else struct timeval timev; timev.tv_sec = *((int *)NativeAligned4FromLAddr(args[0])) - UNIX_ALTO_TIME_DIFF; From 4b0032e1b60ac191d23beb072ac7c5fdea31d826 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Fri, 22 Dec 2023 18:17:02 -0800 Subject: [PATCH 6/6] Piggyback on existing async timer emulation instruction countdown for periodic emscripten_sleep() call. There is no need for an additional Emscripten-specific counter to periodically call emscripten_sleep(). Make test for Emscripten environment check MAIKO_OS_EMSCRIPTEN rather than checking __EMSCRIPTEN__, which is localized in the maiko/platform.h include. --- src/xc.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/xc.c b/src/xc.c index 644e00d..907b16b 100644 --- a/src/xc.c +++ b/src/xc.c @@ -20,6 +20,9 @@ /* */ /************************************************************************/ +#ifdef MAIKO_OS_EMSCRIPTEN +#include +#endif #include #include #include @@ -33,10 +36,6 @@ #include #endif /* DOS */ -#ifdef __EMSCRIPTEN__ -#include /* Defines emscripten_sleep */ -#endif /* __EMSCRIPTEN__ */ - #include "lispemul.h" #include "emlglob.h" #include "address.h" @@ -187,9 +186,6 @@ static int pseudoTimerAsyncCountdown = MAIKO_TIMER_ASYNC_EMULATION_INSNS_COUNTDO void dispatch(void) { InstPtr pccache; -#ifdef __EMSCRIPTEN__ - int cycles = 0; -#endif #if defined(OPDISP) static const void* optable[256] = { @@ -268,9 +264,6 @@ op_ufn : { /* DISPATCH "LOOP" */ nextopcode: -#ifdef __EMSCRIPTEN__ - if (++cycles % 1000000 == 0) emscripten_sleep(1); -#endif #ifdef MYOPTRACE if ((struct fnhead *)NativeAligned4FromLAddr(0x2ed600) == FuncObj) { quick_stack_check(); @@ -296,6 +289,9 @@ nextopcode: Irq_Stk_End = 0; #if defined(MAIKO_EMULATE_ASYNC_INTERRUPTS) IO_Signalled = TRUE; +#endif +#ifdef MAIKO_OS_EMSCRIPTEN + emscripten_sleep(1); #endif pseudoTimerAsyncCountdown = insnsCountdownForTimerAsyncEmulation; }