Skip to content

Commit 01e8514

Browse files
authored
Enable aarch64 support, add component test framework and test suite (#211)
and refine aot call indirect op
1 parent 8ae161b commit 01e8514

77 files changed

Lines changed: 3275 additions & 270 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ The iwasm supports the following architectures:
3737

3838
- X86-64, X86-32
3939
- ARM, THUMB (ARMV7 Cortex-M7 and Cortex-A15 are tested)
40+
- AArch64 (Cortex-A57 and Cortex-A53 are tested)
4041
- MIPS
4142
- XTENSA
4243

build-scripts/config_common.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ elseif (WAMR_BUILD_TARGET MATCHES "THUMB.*")
2727
add_definitions(-DBUILD_TARGET_THUMB)
2828
add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
2929
endif ()
30+
elseif (WAMR_BUILD_TARGET MATCHES "AARCH64.*")
31+
add_definitions(-DBUILD_TARGET_AARCH64)
32+
add_definitions(-DBUILD_TARGET="${WAMR_BUILD_TARGET}")
3033
elseif (WAMR_BUILD_TARGET STREQUAL "MIPS")
3134
add_definitions(-DBUILD_TARGET_MIPS)
3235
elseif (WAMR_BUILD_TARGET STREQUAL "XTENSA")
@@ -40,7 +43,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
4043
endif ()
4144

4245
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
43-
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
46+
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64" OR WAMR_BUILD_TARGET MATCHES "AARCH64.*")
4447
# Add -fPIC flag if build as 64-bit
4548
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
4649
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")

build-scripts/runtime_lib.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ endif ()
3131
# Set default options
3232

3333
# Set WAMR_BUILD_TARGET, currently values supported:
34-
# "X86_64", "AMD_64", "X86_32", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
34+
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", "MIPS", "XTENSA"
3535
if (NOT DEFINED WAMR_BUILD_TARGET)
3636
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
3737
# Build as X86_64 by default in 64-bit platform

core/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#if !defined(BUILD_TARGET_X86_64) \
1010
&& !defined(BUILD_TARGET_AMD_64) \
11+
&& !defined(BUILD_TARGET_AARCH64) \
1112
&& !defined(BUILD_TARGET_X86_32) \
1213
&& !defined(BUILD_TARGET_ARM) \
1314
&& !defined(BUILD_TARGET_ARM_VFP) \
@@ -19,6 +20,8 @@
1920
#define BUILD_TARGET_X86_64
2021
#elif defined(__amd64__) || defined(__amd64)
2122
#define BUILD_TARGET_AMD_64
23+
#elif defined(__aarch64__)
24+
#define BUILD_TARGET_AARCH64
2225
#elif defined(__i386__) || defined(__i386) || defined(i386)
2326
#define BUILD_TARGET_X86_32
2427
#elif defined(__thumb__)

core/iwasm/aot/aot_loader.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ GET_U64_FROM_ADDR(uint32 *addr)
140140
#define E_MACHINE_MIPS 8 /* MIPS R3000 big-endian */
141141
#define E_MACHINE_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */
142142
#define E_MACHINE_ARM 40 /* ARM/Thumb */
143+
#define E_MACHINE_AARCH64 183 /* AArch64 */
143144
#define E_MACHINE_ARC 45 /* Argonaut RISC Core */
144145
#define E_MACHINE_IA_64 50 /* Intel Merced */
145146
#define E_MACHINE_MIPS_X 51 /* Stanford MIPS-X */
@@ -196,6 +197,7 @@ get_aot_file_target(AOTTargetInfo *target_info,
196197
machine_type = "i386";
197198
break;
198199
case E_MACHINE_ARM:
200+
case E_MACHINE_AARCH64:
199201
machine_type = target_info->arch;
200202
break;
201203
case E_MACHINE_MIPS:

core/iwasm/aot/aot_reloc.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ typedef struct {
1414

1515
#define REG_COMMON_SYMBOLS \
1616
REG_SYM(aot_set_exception_with_id), \
17-
REG_SYM(aot_get_exception), \
18-
REG_SYM(aot_is_wasm_type_equal), \
1917
REG_SYM(aot_invoke_native), \
18+
REG_SYM(aot_call_indirect), \
2019
REG_SYM(wasm_runtime_enlarge_memory), \
2120
REG_SYM(wasm_runtime_set_exception), \
2221
REG_SYM(fmin), \

core/iwasm/aot/aot_runtime.c

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ aot_is_wasm_type_equal(AOTModuleInstance *module_inst,
811811
return wasm_type_equal(type1, type2);
812812
}
813813

814-
void
814+
bool
815815
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
816816
uint32 *frame_lp, uint32 argc, uint32 *argv_ret)
817817
{
@@ -827,18 +827,76 @@ aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
827827
const char *signature = NULL;
828828
char buf[128];
829829

830+
bh_assert(func_idx < aot_module->import_func_count);
831+
832+
import_func = aot_module->import_funcs + func_idx;
833+
if (!func_ptr) {
834+
snprintf(buf, sizeof(buf),
835+
"fail to call unlinked import function (%s, %s)",
836+
import_func->module_name, import_func->func_name);
837+
aot_set_exception(module_inst, buf);
838+
return false;
839+
}
840+
841+
signature = import_func->signature;
842+
return wasm_runtime_invoke_native(exec_env, func_ptr,
843+
func_type, signature,
844+
frame_lp, argc, argv_ret);
845+
}
846+
847+
bool
848+
aot_call_indirect(WASMExecEnv *exec_env,
849+
uint32 func_type_idx, uint32 table_elem_idx,
850+
uint32 *frame_lp, uint32 argc, uint32 *argv_ret)
851+
{
852+
AOTModuleInstance *module_inst = (AOTModuleInstance*)
853+
wasm_runtime_get_module_inst(exec_env);
854+
AOTModule *aot_module = (AOTModule*)module_inst->aot_module.ptr;
855+
uint32 *func_type_indexes = (uint32*)module_inst->func_type_indexes.ptr;
856+
uint32 *table_data = (uint32*)module_inst->table_data.ptr;
857+
AOTFuncType *func_type = aot_module->func_types[func_type_idx];;
858+
void **func_ptrs = (void**)module_inst->func_ptrs.ptr, *func_ptr;
859+
uint32 table_size = module_inst->table_size;
860+
uint32 func_idx, func_type_idx1;
861+
AOTImportFunc *import_func;
862+
const char *signature = NULL;
863+
char buf[128];
864+
865+
if (table_elem_idx >= table_size) {
866+
aot_set_exception_with_id(module_inst, EXCE_UNDEFINED_ELEMENT);
867+
return false;
868+
}
869+
870+
func_idx = table_data[table_elem_idx];
871+
if (func_idx == (uint32)-1) {
872+
aot_set_exception_with_id(module_inst, EXCE_UNINITIALIZED_ELEMENT);
873+
return false;
874+
}
875+
876+
func_type_idx1 = func_type_indexes[func_idx];
877+
if (!aot_is_wasm_type_equal(module_inst, func_type_idx, func_type_idx1)) {
878+
aot_set_exception_with_id(module_inst, EXCE_INVALID_FUNCTION_TYPE_INDEX);
879+
return false;
880+
}
881+
830882
if (func_idx < aot_module->import_func_count) {
883+
/* Call native function */
831884
import_func = aot_module->import_funcs + func_idx;
832-
if (!func_ptr) {
833-
snprintf(buf, sizeof(buf),
834-
"fail to call unlinked import function (%s, %s)",
835-
import_func->module_name, import_func->func_name);
836-
aot_set_exception(module_inst, buf);
837-
return;
838-
}
839885
signature = import_func->signature;
840886
}
841-
wasm_runtime_invoke_native(exec_env, func_ptr,
842-
func_type, signature, frame_lp, argc, argv_ret);
887+
888+
if (!(func_ptr = func_ptrs[func_idx])) {
889+
bh_assert(func_idx < aot_module->import_func_count);
890+
import_func = aot_module->import_funcs + func_idx;
891+
snprintf(buf, sizeof(buf),
892+
"fail to call unlinked import function (%s, %s)",
893+
import_func->module_name, import_func->func_name);
894+
aot_set_exception(module_inst, buf);
895+
return false;
896+
}
897+
898+
return wasm_runtime_invoke_native(exec_env, func_ptr,
899+
func_type, signature,
900+
frame_lp, argc, argv_ret);
843901
}
844902

core/iwasm/aot/aot_runtime.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,15 @@ aot_is_wasm_type_equal(AOTModuleInstance *module_inst,
435435
/**
436436
* Invoke native function from aot code
437437
*/
438-
void
438+
bool
439439
aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
440440
uint32 *frame_lp, uint32 argc, uint32 *argv_ret);
441441

442+
bool
443+
aot_call_indirect(WASMExecEnv *exec_env,
444+
uint32 func_type_idx, uint32 table_elem_idx,
445+
uint32 *frame_lp, uint32 argc, uint32 *argv_ret);
446+
442447
uint32
443448
aot_get_plt_table_size();
444449

0 commit comments

Comments
 (0)