Skip to content

Commit 93670b3

Browse files
authored
Merge pull request #1 from bytecodealliance/master
sync with upstream
2 parents 03f2e5c + 01e8514 commit 93670b3

File tree

101 files changed

+3907
-357
lines changed

Some content is hidden

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

101 files changed

+3907
-357
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
.vscode
22
**/*build/
3+
core/deps/lv_drivers
4+
core/deps/llvm
5+
core/deps/lvgl
6+
core/shared/mem-alloc/tlsf

README.md

Lines changed: 4 additions & 1 deletion
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

@@ -99,7 +100,9 @@ The **[WAMR SDK](./wamr-sdk)** tools is helpful to finish the two tasks quickly.
99100
Samples
100101
=================
101102

102-
The WAMR [samples](./samples) integrate the iwasm VM core, application manager and selected application framework components.
103+
The WAMR [samples](./samples) integrate the iwasm VM core, application manager and selected application framework components.
104+
105+
- [**Basic**](./samples/basic): Demonstrating how host runtime calls WASM function as well as WASM function calls native function.
103106
- **[Simple](./samples/simple/README.md)**: The runtime is integrated with most of the WAMR APP libraries, and a few WASM applications are provided for testing the WAMR APP API set. It uses **built-in libc** and executes apps in **interpreter** mode by default.
104107
- **[littlevgl](./samples/littlevgl/README.md)**: Demonstrating the graphic user interface application usage on WAMR. The whole [LittlevGL](https://github.com/littlevgl/) 2D user graphic library and the UI application is built into WASM application. It uses **WASI libc** and executes apps in **AoT mode** by default.
105108
- **[gui](./samples/gui/README.md)**: Moved the [LittlevGL](https://github.com/littlevgl/) library into the runtime and defined a WASM application interface by wrapping the littlevgl API. It uses **WASI libc** and executes apps in **interpreter** mode by default.

assembly-script/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build:request_handler": "asc samples/request_handler.ts -b build/request_handler.wasm -t build/request_handler.wat --sourceMap --validate --optimize",
9-
"build:request_sender": "asc samples/request_sender.ts -b build/request_sender.wasm -t build/request_sender.wat --sourceMap --validate --optimize",
10-
"build:timer": "asc samples/timer.ts -b build/timer.wasm -t build/timer.wat --sourceMap --validate --optimize",
11-
"build:publisher": "asc samples/event_publisher.ts -b build/event_publisher.wasm -t build/event_publisher.wat --sourceMap --validate --optimize",
12-
"build:subscriber": "asc samples/event_subscriber.ts -b build/event_subscriber.wasm -t build/event_subscriber.wat --sourceMap --validate --optimize",
8+
"build:request_handler": "asc samples/request_handler.ts -b build/request_handler.wasm -t build/request_handler.wat --sourceMap --validate --optimize --use abort=",
9+
"build:request_sender": "asc samples/request_sender.ts -b build/request_sender.wasm -t build/request_sender.wat --sourceMap --validate --optimize --use abort=",
10+
"build:timer": "asc samples/timer.ts -b build/timer.wasm -t build/timer.wat --sourceMap --validate --optimize --use abort=",
11+
"build:publisher": "asc samples/event_publisher.ts -b build/event_publisher.wasm -t build/event_publisher.wat --sourceMap --validate --optimize --use abort=",
12+
"build:subscriber": "asc samples/event_subscriber.ts -b build/event_subscriber.wasm -t build/event_subscriber.wat --sourceMap --validate --optimize --use abort=",
1313
"build:all": "npm run build:request_handler; npm run build:request_sender; npm run build:timer; npm run build:subscriber; npm run build:publisher"
1414
},
1515
"author": "",

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: 8 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__)
@@ -109,6 +112,11 @@ enum {
109112
#define WASM_ENABLE_ABS_LABEL_ADDR 0
110113
#endif
111114

115+
/* Enable opcode counter or not */
116+
#ifndef WASM_ENABLE_OPCODE_COUNTER
117+
#define WASM_ENABLE_OPCODE_COUNTER 0
118+
#endif
119+
112120
/* Heap and stack profiling */
113121
#define BEIHAI_ENABLE_MEMORY_PROFILING 0
114122

core/iwasm/aot/aot_loader.c

Lines changed: 3 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:
@@ -614,6 +616,7 @@ load_import_globals(const uint8 **p_buf, const uint8 *buf_end,
614616

615617
/* Create each import global */
616618
for (i = 0; i < module->import_global_count; i++) {
619+
buf = (uint8*)align_ptr(buf, 2);
617620
read_uint8(buf, buf_end, import_globals[i].type);
618621
read_uint8(buf, buf_end, import_globals[i].is_mutable);
619622
read_string(buf, buf_end, import_globals[i].module_name);

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)