From 90e13360626d22a3c41e40e146cb8aaf193725b9 Mon Sep 17 00:00:00 2001 From: Fan LIN Date: Tue, 14 May 2024 06:15:39 +0000 Subject: [PATCH 1/8] Linux Embeded demo --- build/devices/linemb/manifest.json | 15 +++ build/devices/linemb/xsProj/main.c | 20 +++ documentation/devices/linemb.md | 62 +++++++++ examples/devices/linemb/main.js | 13 ++ examples/devices/linemb/manifest.json | 15 +++ tools/mcconfig/make.linemb.mk | 160 ++++++++++++++++++++++++ xs/platforms/linemb/xsPlatform_linemb.h | 111 ++++++++++++++++ xs/platforms/xsHost.h | 2 +- 8 files changed, 397 insertions(+), 1 deletion(-) create mode 100644 build/devices/linemb/manifest.json create mode 100644 build/devices/linemb/xsProj/main.c create mode 100644 documentation/devices/linemb.md create mode 100644 examples/devices/linemb/main.js create mode 100644 examples/devices/linemb/manifest.json create mode 100644 tools/mcconfig/make.linemb.mk create mode 100644 xs/platforms/linemb/xsPlatform_linemb.h diff --git a/build/devices/linemb/manifest.json b/build/devices/linemb/manifest.json new file mode 100644 index 0000000000..de78649347 --- /dev/null +++ b/build/devices/linemb/manifest.json @@ -0,0 +1,15 @@ +{ + "modules": { + "*": [ + "$(MODULES)/base/timer/*", + "$(MODULES)/base/timer/mc/*" + ] + }, + "preload": [ + "timer" + ], + "platforms": { + "linarm/*": { + } + } +} diff --git a/build/devices/linemb/xsProj/main.c b/build/devices/linemb/xsProj/main.c new file mode 100644 index 0000000000..7934f9bc1b --- /dev/null +++ b/build/devices/linemb/xsProj/main.c @@ -0,0 +1,20 @@ +#include "xsAll.h" +#include "mc.xs.h" +#include "xs.h" +#include "xsHost.h" +#include "xsHosts.h" + +int main(int argc, char *argv[]) +{ + xsMachine *the = NULL; + while (true) { + the = modCloneMachine(NULL, NULL); + + modRunMachineSetup(the); + while (true) + { + modTimersExecute(); + } + } + return 0; +} diff --git a/documentation/devices/linemb.md b/documentation/devices/linemb.md new file mode 100644 index 0000000000..b0740bbf08 --- /dev/null +++ b/documentation/devices/linemb.md @@ -0,0 +1,62 @@ +# Using the Moddable SDK with embedded Linux (Raspberry Pi Zero) +This is a demo document to demostration how to bring up an embedded Linux device with the Moddable SDK. + +# Prepare +check the general get started guide [Moddable SDK - Getting Started](../Moddable SDK - Getting Started.md) +Notice this is only tested with Ubuntu 22.04 for the host machine. + +Key steps: +```bash +sudo +export MODDABLE=/workspaces/linfan/moddable +export PATH=$PATH:$MODDABLE/build/bin/lin/release +cd $MODDABLE/build/makefiles/lin +make +``` + +# Intall tool chain +There are 3 types of CPU supported by linemb (Linux Embedded), and use the following command to install the tool chain for each CPU type. + +## ARM(32-bit) +``` +sudo apt-get update +sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf + +``` +## ARM(64-bit) +sudo apt-get update +sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + +## amd64(x86_64, the host) +sudo apt-get install build-essential + +# The sample project +this is sample project for ARM32 CPU: +``` +cd $MODDABLE/examples/devices/linemb +mcconfig -m -p linemb +``` + +The generated executable is here: +`$MODDABLE/build/bin/linemb/release/hello-linemb/hello-linemb` + +Find a way to copy this file to the target board (like scp): + +``` +scp $MODDABLE/build/bin/linemb/release/hello-linemb/hello-linemb root@172.32.0.93:/root/ +``` + +should see output like this: +``` +# ./hello-linemb +Hello, Linux Embedded!!! +immediate +oneshot +repeat 0 +repeat 1 +repeat 2 +repeat 3 +repeat 4 + + +``` \ No newline at end of file diff --git a/examples/devices/linemb/main.js b/examples/devices/linemb/main.js new file mode 100644 index 0000000000..4f67de3d7f --- /dev/null +++ b/examples/devices/linemb/main.js @@ -0,0 +1,13 @@ +import Timer from 'timer' + +trace('Hello, Linux Embedded!!!\n') + +Timer.set(id => trace('immediate\n')) + +Timer.set(id => trace('oneshot\n'), 1000) + +let count = 0 +Timer.repeat(id => { + trace(`repeat ${count} \n`) + 5 == ++count && Timer.clear(id) +}, 1000) diff --git a/examples/devices/linemb/manifest.json b/examples/devices/linemb/manifest.json new file mode 100644 index 0000000000..64020e4d90 --- /dev/null +++ b/examples/devices/linemb/manifest.json @@ -0,0 +1,15 @@ +{ + "build": { + "NAME": "hello-linemb", + "CPU": "arm" + }, + "include": [ + "$(MODDABLE)/examples/manifest_base.json", + "$(MODDABLE)/build/devices/linemb/manifest.json" + ], + "modules": { + "*": [ + "./*" + ] + } +} \ No newline at end of file diff --git a/tools/mcconfig/make.linemb.mk b/tools/mcconfig/make.linemb.mk new file mode 100644 index 0000000000..223651acf8 --- /dev/null +++ b/tools/mcconfig/make.linemb.mk @@ -0,0 +1,160 @@ +# ==================== START OF make.linemb.mk ==================== +all: build + +ifeq ("$(CPU)","arm64") # ARM64 toolchain +CC = /usr/bin/aarch64-linux-gnu-gcc +CXX = /usr/bin/aarch64-linux-gnu-g++ +endif + +ifeq ("$(CPU)","arm") # ARM toolchain +CC = /usr/bin/arm-linux-gnueabihf-gcc +CXX = /usr/bin/arm-linux-gnueabihf-g++ +endif + +ifeq ("$(CPU)","x86") # x86 toolchain +CC = gcc +CXX = g++ +endif + +ifndef CC # check if the toolchain is set +$(error CPU is not set. Please set CPU to arm, arm64 or x86) +endif + +# -DINCLUDE_XSPLATFORM=1 \ +# -DXSPLATFORM=\"linarm_xs.h\" + +C_DEFINES = \ + -DINCLUDE_XSPLATFORM \ + -DXSPLATFORM=\"xsPlatform_linemb.h\" \ + -DXS_ARCHIVE=1 \ + -DmxRun=1 \ + -DmxNoFunctionLength=1 \ + -DmxNoFunctionName=1 \ + -DmxHostFunctionPrimitive=1 \ + -DmxFewGlobalsTable=1 \ + -DkCommodettoBitmapFormat=$(COMMODETTOBITMAPFORMAT) \ + -DkPocoRotation=$(POCOROTATION) + +C_DEFINES += \ + -Wno-misleading-indentation \ + -Wno-implicit-fallthrough + +C_FLAGS = -fPIC -c +LINK_LIBRARIES = -lpthread -lm -lc -ldl -latomic +LINK_OPTIONS = -fPIC + + +# +# Include the XS engine +# +XS_DIRECTORIES = \ + $(XS_DIR)/includes \ + $(XS_DIR)/sources \ + $(XS_DIR)/platforms/linemb \ + $(XS_DIR)/platforms/mc \ + $(XS_DIR)/platforms + +XS_HEADERS = \ + $(XS_DIR)/platforms/mc/xsHosts.h \ + $(XS_DIR)/platforms/xsPlatform.h \ + $(XS_DIR)/includes/xs.h \ + $(XS_DIR)/includes/xsmc.h \ + $(XS_DIR)/sources/xsCommon.h \ + $(XS_DIR)/sources/xsAll.h \ + $(XS_DIR)/sources/xsScript.h + +XS_OBJECTS = \ + $(LIB_DIR)/xsAll.c.o \ + $(LIB_DIR)/xsAPI.c.o \ + $(LIB_DIR)/xsArguments.c.o \ + $(LIB_DIR)/xsArray.c.o \ + $(LIB_DIR)/xsAtomics.c.o \ + $(LIB_DIR)/xsBigInt.c.o \ + $(LIB_DIR)/xsBoolean.c.o \ + $(LIB_DIR)/xsCode.c.o \ + $(LIB_DIR)/xsCommon.c.o \ + $(LIB_DIR)/xsDataView.c.o \ + $(LIB_DIR)/xsDate.c.o \ + $(LIB_DIR)/xsDebug.c.o \ + $(LIB_DIR)/xsError.c.o \ + $(LIB_DIR)/xsFunction.c.o \ + $(LIB_DIR)/xsGenerator.c.o \ + $(LIB_DIR)/xsGlobal.c.o \ + $(LIB_DIR)/xsJSON.c.o \ + $(LIB_DIR)/xsLexical.c.o \ + $(LIB_DIR)/xsMapSet.c.o \ + $(LIB_DIR)/xsMarshall.c.o \ + $(LIB_DIR)/xsMath.c.o \ + $(LIB_DIR)/xsMemory.c.o \ + $(LIB_DIR)/xsModule.c.o \ + $(LIB_DIR)/xsNumber.c.o \ + $(LIB_DIR)/xsObject.c.o \ + $(LIB_DIR)/xsPlatforms.c.o \ + $(LIB_DIR)/xsPromise.c.o \ + $(LIB_DIR)/xsProperty.c.o \ + $(LIB_DIR)/xsProxy.c.o \ + $(LIB_DIR)/xsRegExp.c.o \ + $(LIB_DIR)/xsRun.c.o \ + $(LIB_DIR)/xsScope.c.o \ + $(LIB_DIR)/xsScript.c.o \ + $(LIB_DIR)/xsSourceMap.c.o \ + $(LIB_DIR)/xsString.c.o \ + $(LIB_DIR)/xsSymbol.c.o \ + $(LIB_DIR)/xsSyntaxical.c.o \ + $(LIB_DIR)/xsTree.c.o \ + $(LIB_DIR)/xsType.c.o \ + $(LIB_DIR)/xsdtoa.c.o \ + $(LIB_DIR)/xsmc.c.o \ + $(LIB_DIR)/xsre.c.o \ + $(LIB_DIR)/xsHosts.c.o + +MODULE_DIRS = \ + $(MODDABLE)/modules/base/timer\ + $(MODDABLE)/modules/base/instrumentation + +C_INCLUDES += $(DIRECTORIES) +C_INCLUDES += $(foreach dir,$(XS_DIRECTORIES) $(TMP_DIR) $(MODULE_DIRS),-I$(dir)) + +# XS related targets +VPATH += $(XS_DIRECTORIES) + +$(XS_OBJECTS) : $(XS_HEADERS) + +$(LIB_DIR)/%.c.o: %.c + @echo "# cc" $(/dev/null + -rm -rf $(TMP_DIR) 2>/dev/null + -rm -rf $(LIB_DIR) 2>/dev/null + +# ==================== END OF make.linemb.mk ==================== \ No newline at end of file diff --git a/xs/platforms/linemb/xsPlatform_linemb.h b/xs/platforms/linemb/xsPlatform_linemb.h new file mode 100644 index 0000000000..b9413b953f --- /dev/null +++ b/xs/platforms/linemb/xsPlatform_linemb.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016-2017 Moddable Tech, Inc. + * + * This file is part of the Moddable SDK Runtime. + * + * The Moddable SDK Runtime is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * The Moddable SDK Runtime is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with the Moddable SDK Runtime. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright (C) 2010-2016 Marvell International Ltd. + * Copyright (C) 2002-2010 Kinoma, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __XSPLATFORM_LINEMB__ +#define __XSPLATFORM_LINEMB__ + + +#undef mxLinux +#define mxLinux 1 +#define XS_FUNCTION_NORETURN __attribute__((noreturn)) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#define mxUseGCCAtomics 1 +#define mxUsePOSIXThreads 1 + +#define mxMachinePlatform \ + uint8_t *heap; \ + uint8_t *heap_ptr; \ + uint8_t *heap_pend; \ + void *msgQueue; \ + void *dbgQueue; \ + void *queues; \ + void *task; \ + void* waiterCondition; \ + void* waiterData; \ + void* waiterLink; \ + mxMachineDebug \ + mxMachineInstrument + +#define mxUseDefaultMachinePlatform 1 +#define mxUseDefaultBuildKeys 0 +#define mxUseDefaultChunkAllocation 0 +#define mxUseDefaultSlotAllocation 0 +#define mxUseDefaultFindModule 0 +#define mxUseDefaultLoadModule 0 +#define mxUseDefaultParseScript 0 +#define mxUseDefaultQueuePromiseJobs 1 +#define mxUseDefaultSharedChunks 1 +#define mxUseDefaultAbort 1 +#define mxUseDefaultDebug 1 + +#ifdef mxDebug // TODO + #define mxMachineDebug +#else + #define mxMachineDebug +#endif + +#ifdef mxInstrument + #define mxMachineInstrument \ + void *instrumentationTimer; \ + void *instrumentationCallback; +#else + #define mxMachineInstrument +#endif + +#define modCriticalSectionDeclare +#define modCriticalSectionBegin() // TODO +#define modCriticalSectionEnd() // TODO + +extern void modTimersExecute(void); +extern int modTimersNext(void); + +#endif /* __XSPLATFORM_LINEMB__ */ diff --git a/xs/platforms/xsHost.h b/xs/platforms/xsHost.h index c72de40fb4..97017da4c8 100644 --- a/xs/platforms/xsHost.h +++ b/xs/platforms/xsHost.h @@ -71,7 +71,7 @@ uint32_t modMilliseconds(void); #define modDelayMicroseconds(us) modDelayMilliseconds((((us) + 500) / 1000)) #else #define modDelayMicroseconds(us) usleep(us) - #define modDelayMilliseconds(ms) uleep((ms) * 1000) + #define modDelayMilliseconds(ms) usleep((ms) * 1000) #endif #endif From f5aec722475752c1719372ae954357c11f20a1e0 Mon Sep 17 00:00:00 2001 From: Fan Lin Date: Thu, 3 Apr 2025 15:32:52 +0000 Subject: [PATCH 2/8] adding linemb support and documents --- build/devices/linemb/manifest.json | 8 +- build/devices/linemb/xsProj-glib/main.c | 271 ++++++++++++++++++++++++ build/devices/linemb/xsProj/main.c | 20 -- documentation/devices/linemb.md | 73 ++++--- examples/devices/linemb/main.js | 13 -- examples/devices/linemb/manifest.json | 15 -- examples/helloworld/manifest.json | 5 + tools/mcconfig/make.linemb.mk | 77 +++++-- 8 files changed, 382 insertions(+), 100 deletions(-) create mode 100644 build/devices/linemb/xsProj-glib/main.c delete mode 100644 build/devices/linemb/xsProj/main.c delete mode 100644 examples/devices/linemb/main.js delete mode 100644 examples/devices/linemb/manifest.json diff --git a/build/devices/linemb/manifest.json b/build/devices/linemb/manifest.json index de78649347..1161ceca25 100644 --- a/build/devices/linemb/manifest.json +++ b/build/devices/linemb/manifest.json @@ -1,15 +1,17 @@ { "modules": { "*": [ - "$(MODULES)/base/timer/*", - "$(MODULES)/base/timer/mc/*" + "$(MODULES)/base/timer/*" + , "$(MODULES)/base/timer/lin/*" + , "$(MODULES)/base/time/*" + , "$(MODULES)/base/time/lin/*" ] }, "preload": [ "timer" ], "platforms": { - "linarm/*": { + "linemb/*": { } } } diff --git a/build/devices/linemb/xsProj-glib/main.c b/build/devices/linemb/xsProj-glib/main.c new file mode 100644 index 0000000000..92d02557b7 --- /dev/null +++ b/build/devices/linemb/xsProj-glib/main.c @@ -0,0 +1,271 @@ +#include "xsAll.h" +#include "mc.xs.h" +#include "xs.h" +#include "xsAll.h" +#include "xsHost.h" +#include +#include +#include // Add header file for retrieving call stack +#include // Add header file for signal handling +#include // Add pthread header file + +#define ITERATION_TIMEOUT_US 5000000 // Set 5 second timeout threshold +#define FATAL_ERROR_TOKEN "\n\n!!!FATAL ERROR!!!\n\n" +extern txPreparation *xsPreparation; + +// Use thread-local storage to save txMachine pointer +static __thread txMachine *gxMachine = NULL; + +#if mxInstrument +gboolean on_instrumentation_timeout(gpointer data) +{ + // Execute your code here + // Return TRUE if you want to continue calling, or FALSE if you want to stop after executing once + txMachine *the = (void *)data; + fxSampleInstrumentation(the, 0, NULL); + // Reset + the->garbageCollectionCount = 0; + the->stackPeak = the->stack; + the->peakParserSize = 0; + the->floatingPointOps = 0; + the->promisesSettledCount = 0; + + return TRUE; // Continue calling +} +#endif + +// Modify dump_js_stack function, add thread check +void dump_js_stack(txMachine* the) { + fprintf(stderr, "JavaScript stack trace:\n"); + txSlot *aFrame = the->frame; + while (aFrame) { + char name[128] = ""; + fxBufferFrameName(the, name, sizeof(name), aFrame, ""); + + txSlot* environment = mxFrameToEnvironment(aFrame); + if (environment->ID != XS_NO_ID) + printf("%s: %s:%d\n", name, fxGetKeyName(the, environment->ID), environment->value.environment.line); + else + printf("%s\n", name); + + aFrame = aFrame->next; + } +} + +static void fatal_error_exit() { + void *buffer[50]; + int nptrs = backtrace(buffer, 50); + char **strings = backtrace_symbols(buffer, nptrs); + printf("==== Native stack trace: =====\n"); + for (int i = 0; i < nptrs; i++) + { + printf("%s\n", strings[i]); + } + free(strings); + printf("==============================\n"); + printf(FATAL_ERROR_TOKEN); + + signal(SIGQUIT, SIG_DFL); + exit(1); +} + +static void fatal_error_handler(int signum) { + const char* signame = "UNKNOWN"; + switch(signum) { + case SIGABRT: signame = "SIGABRT"; break; + case SIGFPE: signame = "SIGFPE"; break; + case SIGILL: signame = "SIGILL"; break; + case SIGINT: signame = "SIGINT"; break; + case SIGQUIT: signame = "SIGQUIT"; break; + case SIGSEGV: signame = "SIGSEGV"; break; + case SIGTERM: signame = "SIGTERM"; break; + case SIGBUS: signame = "SIGBUS"; break; + case SIGPIPE: signame = "SIGPIPE"; break; + } + + printf("!!!! Signal %s (%d) caught. Stack trace:\n", signame, signum); + // Reset signal handler to allow default behavior to terminate program + signal(signum, SIG_DFL); + fatal_error_exit(); +} + +// Modified: Unified signal handling function +static void signal_handler(int signum) { + fatal_error_handler(signum); +} + +static void timeout_handler(int signum) { + if (gxMachine) { + printf("!!!! Execution timeout !!!!\n"); + dump_js_stack(gxMachine); + fatal_error_exit(); + } +} + +int main(int argc, char *argv[]) { + // Use setvbuf to disable buffering + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); + + // Register all signals to be captured + signal(SIGABRT, signal_handler); + signal(SIGFPE, signal_handler); + signal(SIGILL, signal_handler); + signal(SIGQUIT, signal_handler); + signal(SIGSEGV, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGBUS, signal_handler); + signal(SIGPIPE, signal_handler); + signal(SIGALRM, timeout_handler); // Used for timeout + + int error = 0; + static txMachine _root; + txMachine *the = &_root; + txPreparation *preparation = xsPreparation(); + + c_memset(the, 0, sizeof(txMachine)); + the->preparation = preparation; + the->keyArray = preparation->keys; + the->keyCount = (txID)preparation->keyCount + (txID)preparation->creation.initialKeyCount; + the->keyIndex = (txID)preparation->keyCount; + the->nameModulo = preparation->nameModulo; + the->nameTable = preparation->names; + the->symbolModulo = preparation->symbolModulo; + the->symbolTable = preparation->symbols; + + the->stack = &preparation->stack[0]; + the->stackBottom = &preparation->stack[0]; + the->stackTop = &preparation->stack[preparation->stackCount]; + + the->firstHeap = &preparation->heap[0]; + the->freeHeap = &preparation->heap[preparation->heapCount - 1]; + the->aliasCount = (txID)preparation->aliasCount; + + setvbuf(stdout, NULL, _IONBF, 0); + the = fxCloneMachine(&preparation->creation, the, "linemb", NULL); + gxMachine = the; // Save to thread-local storage +#if mxInstrument + fxDescribeInstrumentation(the, 0, NULL, NULL); +#endif + xsBeginHost(the); + { + xsVars(2); + { + // XS: set global string array argv, and put input string into it + xsTry + { + xsResult = xsNewArray(0); + xsSet(xsGlobal, xsID("argv"), xsResult); + for (int i = 0; i < argc; i++) + { + xsVar(0) = xsString(argv[i]); + xsCall1(xsResult, xsID("push"), xsVar(0)); + } + } + xsCatch + { + xsStringValue message = xsToString(xsException); + fprintf(stderr, "### %s\n", message); + error = 1; + } + } + { + xsResult = xsAwaitImport("main", XS_IMPORT_NAMESPACE); + } + } + xsEndHost(the); + + // Start event loop + GMainContext *main_context = g_main_context_default(); + GMainLoop *main_loop = g_main_loop_new(main_context, FALSE); + +#if mxInstrument + g_timeout_add_seconds(1, on_instrumentation_timeout, (void *)the); +#endif + + // g_main_loop_run(main_loop); + int testTime = 0; + while (TRUE) + { + // Set timer: trigger SIGALRM on timeout + struct itimerval timer; + timer.it_value.tv_sec = ITERATION_TIMEOUT_US / 1000000; + timer.it_value.tv_usec = ITERATION_TIMEOUT_US % 1000000; + timer.it_interval.tv_sec = 0; + timer.it_interval.tv_usec = 0; + setitimer(ITIMER_REAL, &timer, NULL); + + // Record time before event handling + guint64 start = g_get_monotonic_time(); + // Process one event non-blocking + gboolean processed = g_main_context_iteration(NULL, FALSE); + // Record time after event handling + guint64 end = g_get_monotonic_time(); + + // Disable timer + timer.it_value.tv_sec = 0; + timer.it_value.tv_usec = 0; + setitimer(ITIMER_REAL, &timer, NULL); + + if (processed) + { + // printf("process time: %" G_GUINT64_FORMAT " us\n", end - start); + } + } + + xsDeleteMachine(the); + + return error; +} + +const char *gXSAbortStrings[] ICACHE_FLASH_ATTR = { + "debugger", + "memory full", + "stack overflow", + "fatal", + "dead strip", + "unhandled exception", + "not enough keys", + "too much computation", + "unhandled rejection" +}; + +void fxAbort(xsMachine *the, int status) +{ + const char *msg = (status <= XS_UNHANDLED_REJECTION_EXIT) ? gXSAbortStrings[status] : "unknown"; +#if 0 // MODDEF_XS_ABORTHOOK + + if ((XS_STACK_OVERFLOW_EXIT != status) && (XS_DEBUGGER_EXIT != status)) { + xsBooleanValue ignore = false; + + fxBeginHost(the); + { + mxPush(mxException); + txSlot *exception = the->stack; + mxException = xsUndefined; + mxTry(the) { + txID abortID = fxFindName(the, "abort"); + mxOverflow(-8); + mxPush(mxGlobal); + if (fxHasID(the, abortID)) { + mxPush(mxGlobal); + fxCallID(the, abortID); + mxPushStringC((char *)msg); + mxPushSlot(exception); + fxRunCount(the, 2); + ignore = (XS_BOOLEAN_KIND == the->stack->kind) && !the->stack->value.boolean; + mxPop(); + } + } + mxCatch(the) { + } + } + fxEndHost(the); + if (ignore) + return; + } +#endif + printf("Aborting with status %d, %s\n", status, msg); + + fatal_error_exit(); +} \ No newline at end of file diff --git a/build/devices/linemb/xsProj/main.c b/build/devices/linemb/xsProj/main.c deleted file mode 100644 index 7934f9bc1b..0000000000 --- a/build/devices/linemb/xsProj/main.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "xsAll.h" -#include "mc.xs.h" -#include "xs.h" -#include "xsHost.h" -#include "xsHosts.h" - -int main(int argc, char *argv[]) -{ - xsMachine *the = NULL; - while (true) { - the = modCloneMachine(NULL, NULL); - - modRunMachineSetup(the); - while (true) - { - modTimersExecute(); - } - } - return 0; -} diff --git a/documentation/devices/linemb.md b/documentation/devices/linemb.md index b0740bbf08..ddcef5e89c 100644 --- a/documentation/devices/linemb.md +++ b/documentation/devices/linemb.md @@ -14,49 +14,70 @@ cd $MODDABLE/build/makefiles/lin make ``` -# Intall tool chain -There are 3 types of CPU supported by linemb (Linux Embedded), and use the following command to install the tool chain for each CPU type. +# Install toolchain +There are several CPU types supported. Use the following commands to install the corresponding toolchain: -## ARM(32-bit) -``` +## ARM(32-bit) - armhf +```bash sudo apt-get update sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf - ``` -## ARM(64-bit) + +## ARM(64-bit) - arm64 +```bash sudo apt-get update sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu +``` -## amd64(x86_64, the host) +## amd64(x86_64, the host) - x86_64 +```bash sudo apt-get install build-essential - -# The sample project -this is sample project for ARM32 CPU: ``` -cd $MODDABLE/examples/devices/linemb -mcconfig -m -p linemb + +# Sample project +Below are the build commands for different CPU types: + +## x86_64 example +```bash +cd $MODDABLE/examples/helloworld +mcconfig -d -m -p linemb/x86_64 ``` -The generated executable is here: -`$MODDABLE/build/bin/linemb/release/hello-linemb/hello-linemb` +The generated executable can be found at: +`$MODDABLE/build/bin/linemb/x86_64/debug/helloworld/helloworld` -Find a way to copy this file to the target board (like scp): +## ARM(32-bit) example +```bash +cd $MODDABLE/examples/helloworld +mcconfig -d -m -p linemb/armhf +``` +The generated executable can be found at: +`$MODDABLE/build/bin/linemb/armhf/debug/helloworld/helloworld` + +## ARM(64-bit) example +```bash +cd $MODDABLE/examples/helloworld +mcconfig -d -m -p linemb/arm64 ``` -scp $MODDABLE/build/bin/linemb/release/hello-linemb/hello-linemb root@172.32.0.93:/root/ + +The generated executable can be found at: +`$MODDABLE/build/bin/linemb/arm64/debug/helloworld/helloworld` + +Find a way to copy this file to the target board (e.g., using scp): + +```bash +scp $MODDABLE/build/bin/linemb/armhf/debug/helloworld/helloworld root@172.32.0.93:/root/ ``` -should see output like this: +You should see output like this: ``` -# ./hello-linemb -Hello, Linux Embedded!!! -immediate -oneshot -repeat 0 -repeat 1 -repeat 2 -repeat 3 -repeat 4 +# ./helloworld +instruments key: Chunk used,Chunk available,Slot used,Slot available,Stack used,Stack available,Garbage collections,Keys used,Modules loaded,Parser used,Floating Point,Promises settled +Hello, world - sample +instruments: 248,32768,2432,65504,1344,12288,0,2,1,0,0,0 +instruments: 248,32768,2432,65504,416,12288,0,2,1,0,0,0 +instruments: 248,32768,2432,65504,416,12288,0,2,1,0,0,0 ``` \ No newline at end of file diff --git a/examples/devices/linemb/main.js b/examples/devices/linemb/main.js deleted file mode 100644 index 4f67de3d7f..0000000000 --- a/examples/devices/linemb/main.js +++ /dev/null @@ -1,13 +0,0 @@ -import Timer from 'timer' - -trace('Hello, Linux Embedded!!!\n') - -Timer.set(id => trace('immediate\n')) - -Timer.set(id => trace('oneshot\n'), 1000) - -let count = 0 -Timer.repeat(id => { - trace(`repeat ${count} \n`) - 5 == ++count && Timer.clear(id) -}, 1000) diff --git a/examples/devices/linemb/manifest.json b/examples/devices/linemb/manifest.json deleted file mode 100644 index 64020e4d90..0000000000 --- a/examples/devices/linemb/manifest.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "build": { - "NAME": "hello-linemb", - "CPU": "arm" - }, - "include": [ - "$(MODDABLE)/examples/manifest_base.json", - "$(MODDABLE)/build/devices/linemb/manifest.json" - ], - "modules": { - "*": [ - "./*" - ] - } -} \ No newline at end of file diff --git a/examples/helloworld/manifest.json b/examples/helloworld/manifest.json index c79a80c629..2e9f4437b0 100644 --- a/examples/helloworld/manifest.json +++ b/examples/helloworld/manifest.json @@ -4,5 +4,10 @@ "*": [ "./main" ] + }, + "platforms": { + "linemb/*": { + "strip": [] + } } } diff --git a/tools/mcconfig/make.linemb.mk b/tools/mcconfig/make.linemb.mk index 223651acf8..a8b62e2234 100644 --- a/tools/mcconfig/make.linemb.mk +++ b/tools/mcconfig/make.linemb.mk @@ -1,31 +1,41 @@ # ==================== START OF make.linemb.mk ==================== all: build -ifeq ("$(CPU)","arm64") # ARM64 toolchain -CC = /usr/bin/aarch64-linux-gnu-gcc -CXX = /usr/bin/aarch64-linux-gnu-g++ +ifeq ("$(SUBPLATFORM)","arm64") # ARM64 toolchain +ARCH_PREFIX = aarch64-linux-gnu- endif -ifeq ("$(CPU)","arm") # ARM toolchain -CC = /usr/bin/arm-linux-gnueabihf-gcc -CXX = /usr/bin/arm-linux-gnueabihf-g++ +ifeq ("$(SUBPLATFORM)","armhf") # ARM toolchain +ARCH_PREFIX = arm-linux-gnueabihf- endif -ifeq ("$(CPU)","x86") # x86 toolchain -CC = gcc -CXX = g++ +ifeq ("$(SUBPLATFORM)","rv1106") # ARM toolchain +ARCH_PREFIX = arm-rockchip830-linux-uclibcgnueabihf- endif -ifndef CC # check if the toolchain is set -$(error CPU is not set. Please set CPU to arm, arm64 or x86) +ifeq ("$(SUBPLATFORM)","x86_64") # x86 toolchain +ARCH_PREFIX = "" +endif + +ifndef ARCH_PREFIX # check if the toolchain is set +$(error SUBPLATFORM is not set. Please set SUBPLATFORM to arm, arm64 or x86) +endif + +ifeq ("$(SUBPLATFORM)","rv1106") # ARM toolchain +CC = $(ARCH_PREFIX)gcc +CXX = $(ARCH_PREFIX)g++ +LD = $(ARCH_PREFIX)gcc +else +CC = /usr/bin/$(ARCH_PREFIX)gcc +CXX = /usr/bin/$(ARCH_PREFIX)g++ endif # -DINCLUDE_XSPLATFORM=1 \ # -DXSPLATFORM=\"linarm_xs.h\" C_DEFINES = \ - -DINCLUDE_XSPLATFORM \ - -DXSPLATFORM=\"xsPlatform_linemb.h\" \ + -DINCLUDE_XSPLATFORM=1 \ + -DXSPLATFORM=\"lin_xs.h\" \ -DXS_ARCHIVE=1 \ -DmxRun=1 \ -DmxNoFunctionLength=1 \ @@ -39,22 +49,43 @@ C_DEFINES += \ -Wno-misleading-indentation \ -Wno-implicit-fallthrough -C_FLAGS = -fPIC -c -LINK_LIBRARIES = -lpthread -lm -lc -ldl -latomic -LINK_OPTIONS = -fPIC +PKGCONFIG = $(shell which $(ARCH_PREFIX)pkg-config) + +ifeq ("$(SUBPLATFORM)","rv1106") # ARM toolchain + INCLUDE_PATH = /opt/arm-rockchip830-linux-uclibcgnueabihf/arm-rockchip830-linux-uclibcgnueabihf/include + C_FLAGS = -fPIC -c -I$(INCLUDE_PATH)/libmount -I$(INCLUDE_PATH)/blkid -I$(INCLUDE_PATH)/glib-2.0 + LINK_LIBRARIES = -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lpthread -lm -lc -ldl -lffi +else + C_FLAGS = -fPIC -c $(shell $(PKGCONFIG) --cflags glib-2.0 gio-2.0 gmodule-2.0) + LINK_LIBRARIES = $(shell $(PKGCONFIG) --libs glib-2.0 gio-2.0 gmodule-2.0) -lpthread -lm -lc -ldl -latomic -lresolv -lz -lmount -lblkid -lffi -lselinux -lpcre +endif +ifeq ("$(SUBPLATFORM)","armhf") # ARM toolchain + LINK_OPTIONS += -static +endif + +# DEBUG and INSTRUMENT +ifeq ($(DEBUG),) + C_FLAGS += -D_RELEASE=1 -O3 +else + C_FLAGS += -D_DEBUG=1 -DmxDebug=1 -g -O0 -Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter +# C_FLAGS += -DMC_MEMORY_DEBUG=1 +endif + +ifeq ($(INSTRUMENT),1) + C_DEFINES += -DMODINSTRUMENTATION=1 -DmxInstrument=1 +endif # # Include the XS engine # XS_DIRECTORIES = \ $(XS_DIR)/includes \ - $(XS_DIR)/sources \ - $(XS_DIR)/platforms/linemb \ - $(XS_DIR)/platforms/mc \ - $(XS_DIR)/platforms + $(XS_DIR)/platforms \ + $(XS_DIR)/sources XS_HEADERS = \ + $(XS_DIR)/platforms/lin_xs.h \ $(XS_DIR)/platforms/mc/xsHosts.h \ $(XS_DIR)/platforms/xsPlatform.h \ $(XS_DIR)/includes/xs.h \ @@ -64,6 +95,7 @@ XS_HEADERS = \ $(XS_DIR)/sources/xsScript.h XS_OBJECTS = \ + $(LIB_DIR)/lin_xs.c.o \ $(LIB_DIR)/xsAll.c.o \ $(LIB_DIR)/xsAPI.c.o \ $(LIB_DIR)/xsArguments.c.o \ @@ -106,7 +138,6 @@ XS_OBJECTS = \ $(LIB_DIR)/xsdtoa.c.o \ $(LIB_DIR)/xsmc.c.o \ $(LIB_DIR)/xsre.c.o \ - $(LIB_DIR)/xsHosts.c.o MODULE_DIRS = \ $(MODDABLE)/modules/base/timer\ @@ -141,13 +172,13 @@ $(TMP_DIR)/mc.resources.c: $(DATA) $(RESOURCES) $(MANIFEST) $(SDKCONFIG_H) @mcrez $(DATA) $(RESOURCES) -o $(TMP_DIR) -r mc.resources.c # The exectuable -$(TMP_DIR)/xs_main.o: $(BUILD_DIR)/devices/linemb/xsProj/main.c +$(TMP_DIR)/xs_main.o: $(BUILD_DIR)/devices/linemb/xsProj-glib/main.c @echo "# cc" $( Date: Thu, 3 Apr 2025 15:52:38 +0000 Subject: [PATCH 3/8] Guide for handling "module not found" issue. And add support for tested modules. --- documentation/devices/linemb.md | 54 ++++++++++++++++++++++++-- examples/manifest_net.json | 1 + modules/files/file/manifest.json | 10 +++++ modules/io/manifest.json | 3 ++ modules/network/ethernet/manifest.json | 3 ++ modules/network/net/manifest.json | 8 ++++ modules/network/socket/manifest.json | 8 ++++ modules/network/wifi/manifest.json | 7 ++++ 8 files changed, 90 insertions(+), 4 deletions(-) diff --git a/documentation/devices/linemb.md b/documentation/devices/linemb.md index ddcef5e89c..e2efc094af 100644 --- a/documentation/devices/linemb.md +++ b/documentation/devices/linemb.md @@ -8,7 +8,7 @@ Notice this is only tested with Ubuntu 22.04 for the host machine. Key steps: ```bash sudo -export MODDABLE=/workspaces/linfan/moddable +export MODDABLE=[your moddalbe root folder] export PATH=$PATH:$MODDABLE/build/bin/lin/release cd $MODDABLE/build/makefiles/lin make @@ -46,7 +46,8 @@ mcconfig -d -m -p linemb/x86_64 The generated executable can be found at: `$MODDABLE/build/bin/linemb/x86_64/debug/helloworld/helloworld` -## ARM(32-bit) example +## Running on ARM devices +### ARM(32-bit) ```bash cd $MODDABLE/examples/helloworld mcconfig -d -m -p linemb/armhf @@ -55,7 +56,7 @@ mcconfig -d -m -p linemb/armhf The generated executable can be found at: `$MODDABLE/build/bin/linemb/armhf/debug/helloworld/helloworld` -## ARM(64-bit) example +### ARM(64-bit) ```bash cd $MODDABLE/examples/helloworld mcconfig -d -m -p linemb/arm64 @@ -64,6 +65,7 @@ mcconfig -d -m -p linemb/arm64 The generated executable can be found at: `$MODDABLE/build/bin/linemb/arm64/debug/helloworld/helloworld` +### Copy to device Find a way to copy this file to the target board (e.g., using scp): ```bash @@ -78,6 +80,50 @@ Hello, world - sample instruments: 248,32768,2432,65504,1344,12288,0,2,1,0,0,0 instruments: 248,32768,2432,65504,416,12288,0,2,1,0,0,0 instruments: 248,32768,2432,65504,416,12288,0,2,1,0,0,0 +``` + +# Fix "module unsupported" issue + +If you encounter an error like "XXX module unsupported" when using the linemb platform, it's because the module's `manifest.json` file doesn't specify a C language implementation for the linemb platform. + +The simplest solution is to copy the implementation from the "lin" platform. Follow these steps: + +1. Open the module's `manifest.json` file (e.g., `modules/files/file/manifest.json` for file module) +2. Ensure the linemb platform configuration includes the module implementation, for example: + +```json +"linemb": { + "modules": { + "*": "$(MODULES)/files/file/lin/*" + }, + "config": { + "file": { + "root": "/tmp/" + } + } +} +``` + +Please note that many modules for the `lin` platform (especially hardware-related ones) have not been thoroughly tested. It's recommended to enable modules according to your specific needs and perform adequate testing to ensure proper functionality. + +If you encounter issues with the `lin` platform implementation, a better approach is to create a linemb-specific implementation: + +1. Create a new folder for the linemb platform implementation (e.g., `modules/files/file/linemb/`) +2. Implement the necessary C files specifically for the linemb platform +3. Update the manifest.json to use this implementation: + +```json +"linemb": { + "modules": { + "*": "$(MODULES)/files/file/linemb/*" + }, + "config": { + "file": { + "root": "/tmp/" + } + } +} +``` +This approach allows you to create optimized implementations tailored to the linemb platform. -``` \ No newline at end of file diff --git a/examples/manifest_net.json b/examples/manifest_net.json index 97982a8c16..04fe29d1fe 100644 --- a/examples/manifest_net.json +++ b/examples/manifest_net.json @@ -47,6 +47,7 @@ }, "mac": {}, "lin": {}, + "linemb": {}, "win": {}, "...": { "error": "manifest_net - unsupported platform" diff --git a/modules/files/file/manifest.json b/modules/files/file/manifest.json index 6c4ef4ca66..df081f577b 100644 --- a/modules/files/file/manifest.json +++ b/modules/files/file/manifest.json @@ -69,6 +69,16 @@ } } }, + "linemb": { + "modules": { + "*": "$(MODULES)/files/file/lin/*" + }, + "config": { + "file": { + "root": "/tmp/" + } + } + }, "qca4020": { "modules": { "*": "$(MODULES)/files/file/qca4020/*" diff --git a/modules/io/manifest.json b/modules/io/manifest.json index 00d13b8184..5f4f22d0dc 100644 --- a/modules/io/manifest.json +++ b/modules/io/manifest.json @@ -26,6 +26,9 @@ "lin": { "include": "./manifests/lin/manifest.json" }, + "linemb": { + "include": "./manifests/lin/manifest.json" + }, "win": { "include": "./manifests/win/manifest.json" } diff --git a/modules/network/ethernet/manifest.json b/modules/network/ethernet/manifest.json index b41292be97..f34b831332 100644 --- a/modules/network/ethernet/manifest.json +++ b/modules/network/ethernet/manifest.json @@ -25,6 +25,9 @@ "lin": { "include": "$(MODULES)/network/wifi/manifest.json" }, + "linemb": { + "include": "$(MODULES)/network/wifi/manifest.json" + }, "mac": { "include": "$(MODULES)/network/wifi/manifest.json" }, diff --git a/modules/network/net/manifest.json b/modules/network/net/manifest.json index 969f926c9e..01a0480e58 100644 --- a/modules/network/net/manifest.json +++ b/modules/network/net/manifest.json @@ -45,6 +45,14 @@ ] } }, + "linemb": { + "modules": { + "*": [ + "$(MODULES)/network/net/net", + "$(MODULES)/network/net/lin/*" + ] + } + }, "mac": { "modules": { "*": [ diff --git a/modules/network/socket/manifest.json b/modules/network/socket/manifest.json index 09e37c3ffe..ba2a3cef23 100644 --- a/modules/network/socket/manifest.json +++ b/modules/network/socket/manifest.json @@ -40,6 +40,14 @@ ] } }, + "linemb": { + "modules": { + "*": [ + "$(MODULES)/network/socket/*", + "$(MODULES)/network/socket/lin/*" + ] + } + }, "mac": { "modules": { "*": [ diff --git a/modules/network/wifi/manifest.json b/modules/network/wifi/manifest.json index ab240c4ffb..1676135920 100644 --- a/modules/network/wifi/manifest.json +++ b/modules/network/wifi/manifest.json @@ -37,6 +37,13 @@ ] } }, + "linemb": { + "modules": { + "*": [ + "$(MODULES)/network/wifi/sim/*" + ] + } + }, "mac": { "modules": { "*": [ From 665228439fbbb10078fe99a47b285749794cbb48 Mon Sep 17 00:00:00 2001 From: Fan Lin Date: Mon, 12 May 2025 16:41:58 +0000 Subject: [PATCH 4/8] using fxPrepareMachine --- build/devices/linemb/xsProj-glib/main.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/build/devices/linemb/xsProj-glib/main.c b/build/devices/linemb/xsProj-glib/main.c index 92d02557b7..ede6cc0efd 100644 --- a/build/devices/linemb/xsProj-glib/main.c +++ b/build/devices/linemb/xsProj-glib/main.c @@ -119,30 +119,12 @@ int main(int argc, char *argv[]) { signal(SIGALRM, timeout_handler); // Used for timeout int error = 0; - static txMachine _root; - txMachine *the = &_root; txPreparation *preparation = xsPreparation(); - c_memset(the, 0, sizeof(txMachine)); - the->preparation = preparation; - the->keyArray = preparation->keys; - the->keyCount = (txID)preparation->keyCount + (txID)preparation->creation.initialKeyCount; - the->keyIndex = (txID)preparation->keyCount; - the->nameModulo = preparation->nameModulo; - the->nameTable = preparation->names; - the->symbolModulo = preparation->symbolModulo; - the->symbolTable = preparation->symbols; - - the->stack = &preparation->stack[0]; - the->stackBottom = &preparation->stack[0]; - the->stackTop = &preparation->stack[preparation->stackCount]; - - the->firstHeap = &preparation->heap[0]; - the->freeHeap = &preparation->heap[preparation->heapCount - 1]; - the->aliasCount = (txID)preparation->aliasCount; + txMachine *the = fxPrepareMachine(NULL, preparation, "linemb", NULL, NULL); setvbuf(stdout, NULL, _IONBF, 0); - the = fxCloneMachine(&preparation->creation, the, "linemb", NULL); + gxMachine = the; // Save to thread-local storage #if mxInstrument fxDescribeInstrumentation(the, 0, NULL, NULL); From faeec84bd66b3175b89e0619cc2fe852485a093f Mon Sep 17 00:00:00 2001 From: Fan Lin Date: Mon, 12 May 2025 16:42:34 +0000 Subject: [PATCH 5/8] Fixed busy waiting issue by using blocked g_main_context_iteration() call --- build/devices/linemb/xsProj-glib/main.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/build/devices/linemb/xsProj-glib/main.c b/build/devices/linemb/xsProj-glib/main.c index ede6cc0efd..2d2bdbb1c8 100644 --- a/build/devices/linemb/xsProj-glib/main.c +++ b/build/devices/linemb/xsProj-glib/main.c @@ -159,14 +159,13 @@ int main(int argc, char *argv[]) { // Start event loop GMainContext *main_context = g_main_context_default(); - GMainLoop *main_loop = g_main_loop_new(main_context, FALSE); + g_main_loop_new(main_context, FALSE); #if mxInstrument g_timeout_add_seconds(1, on_instrumentation_timeout, (void *)the); #endif // g_main_loop_run(main_loop); - int testTime = 0; while (TRUE) { // Set timer: trigger SIGALRM on timeout @@ -177,22 +176,13 @@ int main(int argc, char *argv[]) { timer.it_interval.tv_usec = 0; setitimer(ITIMER_REAL, &timer, NULL); - // Record time before event handling - guint64 start = g_get_monotonic_time(); - // Process one event non-blocking - gboolean processed = g_main_context_iteration(NULL, FALSE); - // Record time after event handling - guint64 end = g_get_monotonic_time(); + // Process one event blocking + g_main_context_iteration(NULL, TRUE); // Disable timer timer.it_value.tv_sec = 0; timer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &timer, NULL); - - if (processed) - { - // printf("process time: %" G_GUINT64_FORMAT " us\n", end - start); - } } xsDeleteMachine(the); From 63a8c40ca1ac83da7210dd0660bd803addb6c8e6 Mon Sep 17 00:00:00 2001 From: Fan Lin Date: Mon, 12 May 2025 16:58:12 +0000 Subject: [PATCH 6/8] move "strip": [] into manifest_base.json --- build/devices/linemb/manifest.json | 9 +++------ examples/helloworld/manifest.json | 5 ----- examples/manifest_base.json | 4 ++++ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/build/devices/linemb/manifest.json b/build/devices/linemb/manifest.json index 1161ceca25..7c20fb4d86 100644 --- a/build/devices/linemb/manifest.json +++ b/build/devices/linemb/manifest.json @@ -8,10 +8,7 @@ ] }, "preload": [ - "timer" - ], - "platforms": { - "linemb/*": { - } - } + "timer", + "time" + ] } diff --git a/examples/helloworld/manifest.json b/examples/helloworld/manifest.json index 2e9f4437b0..c79a80c629 100644 --- a/examples/helloworld/manifest.json +++ b/examples/helloworld/manifest.json @@ -4,10 +4,5 @@ "*": [ "./main" ] - }, - "platforms": { - "linemb/*": { - "strip": [] - } } } diff --git a/examples/manifest_base.json b/examples/manifest_base.json index 17ee186905..b285b81b1a 100644 --- a/examples/manifest_base.json +++ b/examples/manifest_base.json @@ -86,6 +86,10 @@ }, "wasm": { "include": "$(BUILD_SIMULATOR)/manifest.json" + }, + "linemb/*": { + "include": "$(BUILD)/devices/linemb/manifest.json", + "strip": [] } } } From d0925258572d55499ed6a7fcaa647b3c776f4965 Mon Sep 17 00:00:00 2001 From: Fan Lin Date: Mon, 12 May 2025 17:05:19 +0000 Subject: [PATCH 7/8] using strsignal() --- build/devices/linemb/xsProj-glib/main.c | 37 +++++-------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/build/devices/linemb/xsProj-glib/main.c b/build/devices/linemb/xsProj-glib/main.c index 2d2bdbb1c8..39766a4fea 100644 --- a/build/devices/linemb/xsProj-glib/main.c +++ b/build/devices/linemb/xsProj-glib/main.c @@ -8,6 +8,7 @@ #include // Add header file for retrieving call stack #include // Add header file for signal handling #include // Add pthread header file +#include // Add string.h for strsignal #define ITERATION_TIMEOUT_US 5000000 // Set 5 second timeout threshold #define FATAL_ERROR_TOKEN "\n\n!!!FATAL ERROR!!!\n\n" @@ -70,20 +71,8 @@ static void fatal_error_exit() { } static void fatal_error_handler(int signum) { - const char* signame = "UNKNOWN"; - switch(signum) { - case SIGABRT: signame = "SIGABRT"; break; - case SIGFPE: signame = "SIGFPE"; break; - case SIGILL: signame = "SIGILL"; break; - case SIGINT: signame = "SIGINT"; break; - case SIGQUIT: signame = "SIGQUIT"; break; - case SIGSEGV: signame = "SIGSEGV"; break; - case SIGTERM: signame = "SIGTERM"; break; - case SIGBUS: signame = "SIGBUS"; break; - case SIGPIPE: signame = "SIGPIPE"; break; - } - - printf("!!!! Signal %s (%d) caught. Stack trace:\n", signame, signum); + + printf("!!!! Signal %s (%d) caught. Stack trace:\n", strsignal(signum), signum); // Reset signal handler to allow default behavior to terminate program signal(signum, SIG_DFL); fatal_error_exit(); @@ -190,24 +179,12 @@ int main(int argc, char *argv[]) { return error; } -const char *gXSAbortStrings[] ICACHE_FLASH_ATTR = { - "debugger", - "memory full", - "stack overflow", - "fatal", - "dead strip", - "unhandled exception", - "not enough keys", - "too much computation", - "unhandled rejection" -}; void fxAbort(xsMachine *the, int status) { - const char *msg = (status <= XS_UNHANDLED_REJECTION_EXIT) ? gXSAbortStrings[status] : "unknown"; -#if 0 // MODDEF_XS_ABORTHOOK - - if ((XS_STACK_OVERFLOW_EXIT != status) && (XS_DEBUGGER_EXIT != status)) { + xsStringValue msg = (char*)fxAbortString(status); +#if MODDEF_XS_ABORTHOOK + if ((XS_JAVASCRIPT_STACK_OVERFLOW_EXIT != status) && (XS_NATIVE_STACK_OVERFLOW_EXIT != status) & (XS_DEBUGGER_EXIT != status)) { xsBooleanValue ignore = false; fxBeginHost(the); @@ -237,7 +214,7 @@ void fxAbort(xsMachine *the, int status) return; } #endif - printf("Aborting with status %d, %s\n", status, msg); + xsLog("XS abort: %s\n", msg); fatal_error_exit(); } \ No newline at end of file From 71209e508c9be1625da244a5c5e39e718d6aceaa Mon Sep 17 00:00:00 2001 From: Fan Lin Date: Mon, 12 May 2025 17:06:28 +0000 Subject: [PATCH 8/8] typo in linemb.md --- documentation/devices/linemb.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/devices/linemb.md b/documentation/devices/linemb.md index e2efc094af..128c2f7708 100644 --- a/documentation/devices/linemb.md +++ b/documentation/devices/linemb.md @@ -1,5 +1,5 @@ # Using the Moddable SDK with embedded Linux (Raspberry Pi Zero) -This is a demo document to demostration how to bring up an embedded Linux device with the Moddable SDK. +This is a demo document to demostrate how to bring up an embedded Linux device with the Moddable SDK. # Prepare check the general get started guide [Moddable SDK - Getting Started](../Moddable SDK - Getting Started.md)