From 7e60b8608ed8c9e22546193de7e8edcf5b584d53 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Tue, 7 Sep 2021 10:20:14 +0800 Subject: [PATCH] Add ia32 support and fix compiling issue for RT-Thread (#730) --- SConscript | 18 ++------- build-scripts/SConscript | 37 ++----------------- build-scripts/SConscript_config | 14 +++---- core/iwasm/aot/SConscript | 4 +- core/iwasm/common/SConscript | 2 + .../platform/rt-thread/platform_internal.h | 2 + core/shared/platform/rt-thread/rtt_platform.c | 2 - product-mini/platforms/rt-thread/SConscript | 8 +--- .../rt-thread/{rtt_wamr_entry.c => iwasm.c} | 7 ++-- .../{rtt_embed_entry.cmake => iwasm.cmake} | 0 10 files changed, 25 insertions(+), 69 deletions(-) rename product-mini/platforms/rt-thread/{rtt_wamr_entry.c => iwasm.c} (99%) rename product-mini/platforms/rt-thread/{rtt_embed_entry.cmake => iwasm.cmake} (100%) diff --git a/SConscript b/SConscript index af4c3efe..7db27418 100644 --- a/SConscript +++ b/SConscript @@ -14,20 +14,10 @@ cwd = GetCurrentDir() list = os.listdir(cwd) if GetDepend(['PKG_USING_WAMR']): - wamr_entry_sconscript = os.path.join(cwd, "product-mini", "platforms", "rt-thread", 'SConscript') + wamr_entry_sconscript = os.path.join(cwd, "product-mini", "platforms", "rt-thread", 'SConscript') + wamr_runlib_sconscript = os.path.join(cwd, "build-scripts", 'SConscript') - if os.path.isfile(wamr_entry_sconscript): - objs = objs + SConscript(wamr_entry_sconscript) - else: - print("[WAMR] entry script wrong:", wamr_entry_sconscript) - Return('objs') - - wamr_runlib_sconsript = os.path.join(cwd, "build-scripts", 'SConscript') - - if os.path.isfile(wamr_runlib_sconsript): - objs = objs + SConscript(wamr_runlib_sconsript) - else: - print("[WAMR] runtime lib script wrong:", wamr_runlib_sconsript) + objs = objs + SConscript(wamr_entry_sconscript) + objs = objs + SConscript(wamr_runlib_sconscript) Return('objs') - diff --git a/build-scripts/SConscript b/build-scripts/SConscript index a1839642..d2bee958 100644 --- a/build-scripts/SConscript +++ b/build-scripts/SConscript @@ -11,23 +11,16 @@ cwd = GetCurrentDir() objs = [] WAMR_ROOT_DIR = os.path.join(cwd, "..") - - -SHARED_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'shared') - -IWASM_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'iwasm') - -APP_MGR_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-mgr') - +SHARED_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'shared') +IWASM_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'iwasm') +APP_MGR_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-mgr') APP_FRAMEWORK_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'app-framework') - -DEPS_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'deps') +DEPS_DIR = os.path.join(WAMR_ROOT_DIR, 'core', 'deps') if GetDepend(['WAMR_BUILD_INTERP']): script_path = os.path.join(IWASM_DIR, 'interpreter', 'SConscript') objs += SConscript(script_path) - if GetDepend(['WAMR_BUILD_AOT']): script_path = os.path.join(IWASM_DIR, 'aot', 'SConscript') objs += SConscript(script_path) @@ -35,54 +28,32 @@ if GetDepend(['WAMR_BUILD_AOT']): script_path = os.path.join(IWASM_DIR, 'compilation', 'SConscript') objs += SConscript(script_path) - if GetDepend(['WAMR_BUILD_APP_FRAMEWORK']): objs += SConscript(os.path.join(APP_FRAMEWORK_DIR, 'SConscript')) objs += SConscript(os.path.join(SHARED_DIR, 'coap', 'SConscript')) objs += SConscript(os.path.join(APP_MGR_DIR, 'app-manager', 'SConscript')) objs += SConscript(os.path.join(APP_MGR_DIR, 'app-mgr-shared', 'SConscript')) - - if GetDepend(['WAMR_BUILD_LIBC_BUILTIN']): objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-builtin', 'SConscript')) - - if GetDepend(['WAMR_BUILD_LIBC_WASI']): objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-wasi', 'SConscript')) - if GetDepend(['WAMR_BUILD_LIB_PTHREAD']): objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-pthread', 'SConscript')) - # TODO: 这里加一下 - - - -# if (WAMR_BUILD_THREAD_MGR EQUAL 1) -# include (${IWASM_DIR}/libraries/thread-mgr/thread_mgr.cmake) -# endif () if GetDepend(['WAMR_BUILD_THREAD_MGR']): objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'thread-mgr', 'SConscript')) - - -# if (WAMR_BUILD_LIBC_EMCC EQUAL 1) -# include (${IWASM_DIR}/libraries/libc-emcc/libc_emcc.cmake) -# endif() - if GetDepend(['WAMR_BUILD_LIBC_EMCC']): objs += SConscript(os.path.join(IWASM_DIR, 'libraries', 'libc-emmc', 'SConscript')) objs += SConscript(os.path.join(cwd, 'SConscript_config')); - objs += SConscript(os.path.join(SHARED_DIR, 'platform', 'rt-thread', 'SConscript')) objs += SConscript(os.path.join(SHARED_DIR, 'mem-alloc', 'SConscript')) objs += SConscript(os.path.join(IWASM_DIR, 'common', 'SConscript')) objs += SConscript(os.path.join(SHARED_DIR, 'utils', 'SConscript')) - - Return('objs') diff --git a/build-scripts/SConscript_config b/build-scripts/SConscript_config index f5fe373d..df96940e 100644 --- a/build-scripts/SConscript_config +++ b/build-scripts/SConscript_config @@ -11,15 +11,12 @@ from building import * Import('rtconfig') -src = Split(''' -''') +src = [] objs = [] cwd = GetCurrentDir() IWASM_INC_DIR = os.path.join(cwd, '..', 'core', 'iwasm', 'include') -# include_directories (${IWASM_DIR}/include) - CPPPATH = [IWASM_INC_DIR] if rtconfig.BUILD == 'debug': @@ -48,12 +45,11 @@ if rtconfig.ARCH == 'arm': print('[WAMR] using armv4') CPPDEFINES += ['BUILD_TARGET_ARM'] CPPDEFINES += ['RTT_WAMR_BUILD_TARGET_ARMV4'] +elif rtconfig.ARCH == 'ia32': + CPPDEFINES += ['BUILD_TARGET_X86_32', 'RTT_WAMR_BUILD_TARGET_X86_32'] else: print("[WAMR] unknown arch", rtconfig.ARCH) - -LIBS = ['m'] - if GetDepend(['WAMR_BUILD_INTERP']): CPPDEFINES += ['WASM_ENABLE_INTERP=1'] if GetDepend(['WAMR_BUILD_FAST_INTERP']): @@ -114,8 +110,8 @@ if GetDepend(['WAMR_BUILD_TAIL_CALL']): CPPDEFINES += ['WASM_ENABLE_TAIL_CALL=1'] print('[WAMR] Tail call enabledd') +LIBS = ['m'] -group = DefineGroup('wamr_config_common', src, depend = ['PKG_USING_WAMR'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) +group = DefineGroup('wamr', src, depend = ['PKG_USING_WAMR'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) Return('group') - diff --git a/core/iwasm/aot/SConscript b/core/iwasm/aot/SConscript index c1a3c96e..790f2840 100644 --- a/core/iwasm/aot/SConscript +++ b/core/iwasm/aot/SConscript @@ -13,6 +13,7 @@ cwd = GetCurrentDir() src = Split(''' aot_loader.c aot_runtime.c +aot_intrinsic.c ''') if rtconfig.ARCH == 'arm': @@ -20,7 +21,8 @@ if rtconfig.ARCH == 'arm': src += ['arch/aot_reloc_thumb.c'] elif re.match('^cortex-a.*', rtconfig.CPU): src += ['arch/aot_reloc_arm.c'] - +elif rtconfig.ARCH == 'ia32': + src += ['arch/aot_reloc_x86_32.c'] CPPPATH = [cwd, cwd + '/../include'] diff --git a/core/iwasm/common/SConscript b/core/iwasm/common/SConscript index 235b0e88..0a55f244 100644 --- a/core/iwasm/common/SConscript +++ b/core/iwasm/common/SConscript @@ -18,6 +18,8 @@ if rtconfig.ARCH == 'arm': src += ['arch/invokeNative_thumb.s'] elif re.match('^cortex-a.*', rtconfig.CPU): src += ['arch/invokeNative_arm.s'] +elif rtconfig.ARCH == 'ia32': + src += ['arch/invokeNative_ia32.s'] CPPPATH = [cwd, cwd + '/../include'] diff --git a/core/shared/platform/rt-thread/platform_internal.h b/core/shared/platform/rt-thread/platform_internal.h index 1480a9e4..9fe1c9c6 100644 --- a/core/shared/platform/rt-thread/platform_internal.h +++ b/core/shared/platform/rt-thread/platform_internal.h @@ -25,6 +25,8 @@ #define BUILD_TARGET "armv6" #elif defined(RTT_WAMR_BUILD_TARGET_ARMV4) #define BUILD_TARGET "armv4" +#elif defined(RTT_WAMR_BUILD_TARGET_X86_32) +#define BUILD_TARGET "X86_32" #else #error "unsupported aot platform." #endif diff --git a/core/shared/platform/rt-thread/rtt_platform.c b/core/shared/platform/rt-thread/rtt_platform.c index 6ac8c70f..493d766c 100644 --- a/core/shared/platform/rt-thread/rtt_platform.c +++ b/core/shared/platform/rt-thread/rtt_platform.c @@ -180,12 +180,10 @@ void os_munmap(void *addr, size_t size) rt_free(addr); } -#ifdef OS_ENABLE_HW_BOUND_CHECK int os_mprotect(void *addr, size_t size, int prot) { return 0; } -#endif void os_dcache_flush(void) { diff --git a/product-mini/platforms/rt-thread/SConscript b/product-mini/platforms/rt-thread/SConscript index 8f866caf..4f7ffe63 100644 --- a/product-mini/platforms/rt-thread/SConscript +++ b/product-mini/platforms/rt-thread/SConscript @@ -6,13 +6,9 @@ from building import * -cwd = GetCurrentDir() - - +cwd = GetCurrentDir() src = Glob('*.c') -CPPPATH = [cwd] - -group = DefineGroup('iwasm_entry', src, depend = ['PKG_USING_WAMR'], CPPPATH = CPPPATH) +group = DefineGroup('iwasm', src, depend = ['PKG_USING_WAMR']) Return('group') diff --git a/product-mini/platforms/rt-thread/rtt_wamr_entry.c b/product-mini/platforms/rt-thread/iwasm.c similarity index 99% rename from product-mini/platforms/rt-thread/rtt_wamr_entry.c rename to product-mini/platforms/rt-thread/iwasm.c index 799fd44d..c7ab46a8 100644 --- a/product-mini/platforms/rt-thread/rtt_wamr_entry.c +++ b/product-mini/platforms/rt-thread/iwasm.c @@ -373,18 +373,17 @@ int iwasm(int argc, char **argv) /* destroy the module instance */ wasm_runtime_deinstantiate(wasm_module_inst); - fail3: +fail3: /* unload the module */ wasm_runtime_unload(wasm_module); - fail2: +fail2: /* free the file buffer */ rt_free(wasm_file_buf); - fail1: +fail1: /* destroy runtime environment */ wasm_runtime_destroy(); return 0; } MSH_CMD_EXPORT(iwasm, Embeded VM of WebAssembly); - diff --git a/product-mini/platforms/rt-thread/rtt_embed_entry.cmake b/product-mini/platforms/rt-thread/iwasm.cmake similarity index 100% rename from product-mini/platforms/rt-thread/rtt_embed_entry.cmake rename to product-mini/platforms/rt-thread/iwasm.cmake