diff --git a/build-scripts/SConscript_config b/build-scripts/SConscript_config index 1626086e..37f59df9 100644 --- a/build-scripts/SConscript_config +++ b/build-scripts/SConscript_config @@ -32,24 +32,23 @@ if rtconfig.ARCH == 'arm': if re.match('^cortex-m.*', rtconfig.CPU): print('[WAMR] using thumbv4t') CPPDEFINES += ['BUILD_TARGET_THUMB'] - CPPDEFINES += [r'BUILD_TARGET=\"thumbv4t\"'] + CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_THUMB'] elif re.match('^cortex-a.*', rtconfig.CPU): print('[WAMR] using armv7') CPPDEFINES += ['BUILD_TARGET_ARM'] - CPPDEFINES += [r'BUILD_TARGET=\"armv7\"'] + CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV7'] elif re.match('^cortex-r.*', rtconfig.CPU): print('[WAMR] using armv7') CPPDEFINES += ['BUILD_TARGET_ARM'] - CPPDEFINES += [r'BUILD_TARGET=\"armv7\"'] + CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV7'] elif rtconfig.CPU == 'armv6': print('[WAMR] using armv6') CPPDEFINES += ['BUILD_TARGET_ARM'] - CPPDEFINES += [r'BUILD_TARGET=\"armv6\"'] + CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV6'] elif re.match('^arm9*', rtconfig.CPU): print('[WAMR] using armv4') CPPDEFINES += ['BUILD_TARGET_ARM'] - CPPDEFINES += [r'BUILD_TARGET=\"armv4\"'] - + CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV4'] else: print("[WAMR] unknown arch", rtconfig.ARCH) diff --git a/core/shared/platform/rt-thread/platform_internal.h b/core/shared/platform/rt-thread/platform_internal.h index 9ca34422..1480a9e4 100644 --- a/core/shared/platform/rt-thread/platform_internal.h +++ b/core/shared/platform/rt-thread/platform_internal.h @@ -16,6 +16,20 @@ #include #include +#if defined(WASM_ENABLE_AOT) +#if defined(RTT_WAMR_BUILD_TARGET_THUMB) +#define BUILD_TARGET "thumbv4t" +#elif defined(RTT_WAMR_BUILD_TARGET_ARMV7) +#define BUILD_TARGET "armv7" +#elif defined(RTT_WAMR_BUILD_TARGET_ARMV6) +#define BUILD_TARGET "armv6" +#elif defined(RTT_WAMR_BUILD_TARGET_ARMV4) +#define BUILD_TARGET "armv4" +#else +#error "unsupported aot platform." +#endif +#endif /* WASM_ENABLE_AOT */ + typedef rt_thread_t korp_tid; typedef struct rt_mutex korp_mutex; typedef struct rt_thread korp_cond; diff --git a/product-mini/platforms/rt-thread/rtt_wamr_entry.c b/product-mini/platforms/rt-thread/rtt_wamr_entry.c index 0b9b25e2..799fd44d 100644 --- a/product-mini/platforms/rt-thread/rtt_wamr_entry.c +++ b/product-mini/platforms/rt-thread/rtt_wamr_entry.c @@ -12,6 +12,9 @@ #include #include +#ifdef WAMR_ENABLE_RTT_EXPORT + +#ifdef WAMR_RTT_EXPORT_VPRINTF static int wasm_vprintf(wasm_exec_env_t env, const char* fmt, va_list va) { return vprintf(fmt, va); @@ -27,6 +30,9 @@ static int wasm_vsnprintf(wasm_exec_env_t env, char *buf, int n, const char *fmt return vsnprintf(buf, n, fmt, va); } +#endif /* WAMR_RTT_EXPORT_VPRINTF */ + +#ifdef WAMR_RTT_EXPORT_DEVICE_OPS static rt_device_t wasm_rt_device_find(wasm_exec_env_t env, const char *name) { return rt_device_find(name); @@ -57,7 +63,11 @@ static rt_err_t wasm_rt_device_control(wasm_exec_env_t env, rt_device_t dev, in return rt_device_control(dev, cmd, arg); } +#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */ + static NativeSymbol native_export_symbols[] = { + +#ifdef WAMR_RTT_EXPORT_VPRINTF { "vprintf", wasm_vprintf, @@ -73,6 +83,9 @@ static NativeSymbol native_export_symbols[] = { wasm_vsnprintf, "($i$*)i" }, +#endif /* WAMR_RTT_EXPORT_VPRINTF */ + +#ifdef WAMR_RTT_EXPORT_DEVICE_OPS { "rt_device_find", wasm_rt_device_find, @@ -102,9 +115,39 @@ static NativeSymbol native_export_symbols[] = { "rt_device_control", wasm_rt_device_control, "(ii*)i" - } + }, +#ifdef WAMR_RTT_EXPORT_DEVICE_OPS_CPP + { + "_Z15rt_device_closeP9rt_device", + wasm_rt_device_close, + "(i)i" + }, + { + "_Z14rt_device_readP9rt_devicejPvj", + wasm_rt_device_read, + "(ii*~)i" + }, + { + "_Z15rt_device_writeP9rt_devicejPKvj", + wasm_rt_device_write, + "(ii*~)i" + }, + { + "_Z14rt_device_openP9rt_devicet", + wasm_rt_device_open, + "(ii)i" + }, + { + "_Z14rt_device_findPKc", + wasm_rt_device_find, + "($)i" + }, +#endif /* WAMR_RTT_EXPORT_DEVICE_OPS_CPP */ +#endif /* WAMR_RTT_EXPORT_DEVICE_OPS */ }; +#endif /* WAMR_ENABLE_RTT_EXPORT */ + /** * run WASM module instance. * @param module_inst instance of wasm module @@ -236,9 +279,11 @@ int iwasm(int argc, char **argv) init_args.mem_alloc_option.allocator.malloc_func = os_malloc; init_args.mem_alloc_option.allocator.realloc_func = os_realloc; init_args.mem_alloc_option.allocator.free_func = os_free; +#ifdef WAMR_ENABLE_RTT_EXPORT init_args.native_symbols = native_export_symbols; init_args.n_native_symbols = sizeof(native_export_symbols) / sizeof(NativeSymbol); init_args.native_module_name = "env"; +#endif /* WAMR_ENABLE_RTT_EXPORT */ #ifdef WAMR_ENABLE_IWASM_PARAMS #if defined(RT_USING_HEAP) && defined(RT_USING_MEMHEAP_AS_HEAP)