diff --git a/build/devices/linemb/manifest.json b/build/devices/linemb/manifest.json new file mode 100644 index 0000000000..7c20fb4d86 --- /dev/null +++ b/build/devices/linemb/manifest.json @@ -0,0 +1,14 @@ +{ + "modules": { + "*": [ + "$(MODULES)/base/timer/*" + , "$(MODULES)/base/timer/lin/*" + , "$(MODULES)/base/time/*" + , "$(MODULES)/base/time/lin/*" + ] + }, + "preload": [ + "timer", + "time" + ] +} diff --git a/build/devices/linemb/xsProj-glib/main.c b/build/devices/linemb/xsProj-glib/main.c new file mode 100644 index 0000000000..39766a4fea --- /dev/null +++ b/build/devices/linemb/xsProj-glib/main.c @@ -0,0 +1,220 @@ +#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 +#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" +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) { + + 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(); +} + +// 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; + txPreparation *preparation = xsPreparation(); + + txMachine *the = fxPrepareMachine(NULL, preparation, "linemb", NULL, NULL); + + setvbuf(stdout, NULL, _IONBF, 0); + + 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(); + 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); + 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); + + // 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); + } + + xsDeleteMachine(the); + + return error; +} + + +void fxAbort(xsMachine *the, int 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); + { + 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 + xsLog("XS abort: %s\n", msg); + + fatal_error_exit(); +} \ No newline at end of file diff --git a/documentation/devices/linemb.md b/documentation/devices/linemb.md new file mode 100644 index 0000000000..128c2f7708 --- /dev/null +++ b/documentation/devices/linemb.md @@ -0,0 +1,129 @@ +# Using the Moddable SDK with embedded Linux (Raspberry Pi Zero) +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) +Notice this is only tested with Ubuntu 22.04 for the host machine. + +Key steps: +```bash +sudo +export MODDABLE=[your moddalbe root folder] +export PATH=$PATH:$MODDABLE/build/bin/lin/release +cd $MODDABLE/build/makefiles/lin +make +``` + +# Install toolchain +There are several CPU types supported. Use the following commands to install the corresponding toolchain: + +## ARM(32-bit) - armhf +```bash +sudo apt-get update +sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf +``` + +## 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) - x86_64 +```bash +sudo apt-get install build-essential +``` + +# 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 can be found at: +`$MODDABLE/build/bin/linemb/x86_64/debug/helloworld/helloworld` + +## Running on ARM devices +### ARM(32-bit) +```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) +```bash +cd $MODDABLE/examples/helloworld +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 +scp $MODDABLE/build/bin/linemb/armhf/debug/helloworld/helloworld root@172.32.0.93:/root/ +``` + +You should see output like this: +``` +# ./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 +``` + +# 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. + 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": [] } } } 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 05fcae8155..0e5f29edb9 100644 --- a/modules/network/ethernet/manifest.json +++ b/modules/network/ethernet/manifest.json @@ -33,6 +33,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": { "*": [ diff --git a/tools/mcconfig/make.linemb.mk b/tools/mcconfig/make.linemb.mk new file mode 100644 index 0000000000..a8b62e2234 --- /dev/null +++ b/tools/mcconfig/make.linemb.mk @@ -0,0 +1,191 @@ +# ==================== START OF make.linemb.mk ==================== +all: build + +ifeq ("$(SUBPLATFORM)","arm64") # ARM64 toolchain +ARCH_PREFIX = aarch64-linux-gnu- +endif + +ifeq ("$(SUBPLATFORM)","armhf") # ARM toolchain +ARCH_PREFIX = arm-linux-gnueabihf- +endif + +ifeq ("$(SUBPLATFORM)","rv1106") # ARM toolchain +ARCH_PREFIX = arm-rockchip830-linux-uclibcgnueabihf- +endif + +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=1 \ + -DXSPLATFORM=\"lin_xs.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 + +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)/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 \ + $(XS_DIR)/includes/xsmc.h \ + $(XS_DIR)/sources/xsCommon.h \ + $(XS_DIR)/sources/xsAll.h \ + $(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 \ + $(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 \ + +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