mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-09 13:16:26 +00:00
Implement invokeNative asm code for MinGW (#1753)
And update the document of building iwasm for MinGW.
This commit is contained in:
parent
ec5ab8274d
commit
12bcc20710
57
core/iwasm/common/arch/invokeNative_mingw_x64.s
Normal file
57
core/iwasm/common/arch/invokeNative_mingw_x64.s
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
|
.text
|
||||||
|
.align 2
|
||||||
|
.globl invokeNative
|
||||||
|
invokeNative:
|
||||||
|
|
||||||
|
# %rcx func_ptr
|
||||||
|
# %rdx argv
|
||||||
|
# %r8 n_stacks
|
||||||
|
|
||||||
|
push %rbp
|
||||||
|
mov %rsp, %rbp
|
||||||
|
|
||||||
|
mov %rcx, %r10 # func_ptr
|
||||||
|
mov %rdx, %rax # argv
|
||||||
|
mov %r8, %rcx # n_stacks
|
||||||
|
|
||||||
|
# fill all fp args
|
||||||
|
movsd 0(%rax), %xmm0
|
||||||
|
movsd 8(%rax), %xmm1
|
||||||
|
movsd 16(%rax), %xmm2
|
||||||
|
movsd 24(%rax), %xmm3
|
||||||
|
|
||||||
|
# check for stack args
|
||||||
|
cmp $0, %rcx
|
||||||
|
jz cycle_end
|
||||||
|
|
||||||
|
mov %rsp, %rdx
|
||||||
|
and $15, %rdx
|
||||||
|
jz no_abort
|
||||||
|
int $3
|
||||||
|
no_abort:
|
||||||
|
mov %rcx, %rdx
|
||||||
|
and $1, %rdx
|
||||||
|
shl $3, %rdx
|
||||||
|
sub %rdx, %rsp
|
||||||
|
|
||||||
|
# store stack args
|
||||||
|
lea 56(%rax, %rcx, 8), %r9
|
||||||
|
sub %rsp, %r9 # offset
|
||||||
|
cycle:
|
||||||
|
push (%rsp, %r9)
|
||||||
|
loop cycle
|
||||||
|
|
||||||
|
cycle_end:
|
||||||
|
mov 32(%rax), %rcx
|
||||||
|
mov 40(%rax), %rdx
|
||||||
|
mov 48(%rax), %r8
|
||||||
|
mov 56(%rax), %r9
|
||||||
|
|
||||||
|
sub $32, %rsp # shadow space
|
||||||
|
|
||||||
|
call *%r10
|
||||||
|
leave
|
||||||
|
ret
|
57
core/iwasm/common/arch/invokeNative_mingw_x64_simd.s
Normal file
57
core/iwasm/common/arch/invokeNative_mingw_x64_simd.s
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||||
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
|
.text
|
||||||
|
.align 2
|
||||||
|
.globl invokeNative
|
||||||
|
invokeNative:
|
||||||
|
|
||||||
|
# %rcx func_ptr
|
||||||
|
# %rdx argv
|
||||||
|
# %r8 n_stacks
|
||||||
|
|
||||||
|
push %rbp
|
||||||
|
mov %rsp, %rbp
|
||||||
|
|
||||||
|
mov %rcx, %r10 # func_ptr
|
||||||
|
mov %rdx, %rax # argv
|
||||||
|
mov %r8, %rcx # n_stacks
|
||||||
|
|
||||||
|
# fill all fp args
|
||||||
|
movdqu 0(%rax), %xmm0
|
||||||
|
movdqu 16(%rax), %xmm1
|
||||||
|
movdqu 32(%rax), %xmm2
|
||||||
|
movdqu 48(%rax), %xmm3
|
||||||
|
|
||||||
|
# check for stack args
|
||||||
|
cmp $0, %rcx
|
||||||
|
jz cycle_end
|
||||||
|
|
||||||
|
mov %rsp, %rdx
|
||||||
|
and $15, %rdx
|
||||||
|
jz no_abort
|
||||||
|
int $3
|
||||||
|
no_abort:
|
||||||
|
mov %rcx, %rdx
|
||||||
|
and $1, %rdx
|
||||||
|
shl $3, %rdx
|
||||||
|
sub %rdx, %rsp
|
||||||
|
|
||||||
|
# store stack args
|
||||||
|
lea 88(%rax, %rcx, 8), %r9
|
||||||
|
sub %rsp, %r9 # offset
|
||||||
|
cycle:
|
||||||
|
push (%rsp, %r9)
|
||||||
|
loop cycle
|
||||||
|
|
||||||
|
cycle_end:
|
||||||
|
mov 64(%rax), %rcx
|
||||||
|
mov 72(%rax), %rdx
|
||||||
|
mov 80(%rax), %r8
|
||||||
|
mov 88(%rax), %r9
|
||||||
|
|
||||||
|
sub $32, %rsp # shadow space
|
||||||
|
|
||||||
|
call *%r10
|
||||||
|
leave
|
||||||
|
ret
|
|
@ -27,13 +27,21 @@ if (WAMR_BUILD_INVOKE_NATIVE_GENERAL EQUAL 1)
|
||||||
elseif (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
elseif (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
||||||
if (NOT WAMR_BUILD_SIMD EQUAL 1)
|
if (NOT WAMR_BUILD_SIMD EQUAL 1)
|
||||||
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
|
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
|
||||||
|
if (NOT MINGW)
|
||||||
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64.asm)
|
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64.asm)
|
||||||
|
else ()
|
||||||
|
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_mingw_x64.s)
|
||||||
|
endif ()
|
||||||
else ()
|
else ()
|
||||||
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64.s)
|
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64.s)
|
||||||
endif ()
|
endif ()
|
||||||
else ()
|
else ()
|
||||||
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
|
if (WAMR_BUILD_PLATFORM STREQUAL "windows")
|
||||||
|
if (NOT MINGW)
|
||||||
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64_simd.asm)
|
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64_simd.asm)
|
||||||
|
else ()
|
||||||
|
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_mingw_x64_simd.s)
|
||||||
|
endif ()
|
||||||
else()
|
else()
|
||||||
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64_simd.s)
|
set (source_all ${c_source_all} ${IWASM_COMMON_DIR}/arch/invokeNative_em64_simd.s)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -382,6 +382,8 @@ are valid for the MSYS2 build environment:
|
||||||
```Bash
|
```Bash
|
||||||
pacman -R cmake
|
pacman -R cmake
|
||||||
pacman -S mingw-w64-x86_64-cmake
|
pacman -S mingw-w64-x86_64-cmake
|
||||||
|
pacman -S mingw-w64-x86_64-gcc
|
||||||
|
pacman -S make git
|
||||||
```
|
```
|
||||||
|
|
||||||
Then follow the build instructions for Windows above, and add the following
|
Then follow the build instructions for Windows above, and add the following
|
||||||
|
@ -389,16 +391,15 @@ arguments for cmake:
|
||||||
|
|
||||||
```Bash
|
```Bash
|
||||||
cmake .. -G"Unix Makefiles" \
|
cmake .. -G"Unix Makefiles" \
|
||||||
-DWAMR_BUILD_LIBC_UVWASI=0 \
|
|
||||||
-DWAMR_BUILD_INVOKE_NATIVE_GENERAL=1 \
|
|
||||||
-DWAMR_DISABLE_HW_BOUND_CHECK=1
|
-DWAMR_DISABLE_HW_BOUND_CHECK=1
|
||||||
````
|
````
|
||||||
|
|
||||||
Note that WASI will be disabled until further work is done towards full MinGW support.
|
Note that WASI will be disabled until further work is done towards full MinGW support.
|
||||||
|
|
||||||
- uvwasi not building out of the box, though it reportedly supports MinGW.
|
- Since memory access boundary check with hardware trap feature is disabled, when generating the AOT file with `wamrc`, the `--bounds-checks=1` flag should be added to generate the memory access boundary check instructions to ensure the sandbox security:
|
||||||
- Failing compilation of assembler files, the C version of `invokeNative()` will
|
```bash
|
||||||
be used instead.
|
wamrc --bounds-checks=1 -o <aot_file> <wasm_file>
|
||||||
|
```
|
||||||
- Compiler complaining about missing `UnwindInfoAddress` field in `RUNTIME_FUNCTION`
|
- Compiler complaining about missing `UnwindInfoAddress` field in `RUNTIME_FUNCTION`
|
||||||
struct (winnt.h).
|
struct (winnt.h).
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ print_help()
|
||||||
}
|
}
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
||||||
static void *
|
static const void *
|
||||||
app_instance_main(wasm_module_inst_t module_inst)
|
app_instance_main(wasm_module_inst_t module_inst)
|
||||||
{
|
{
|
||||||
const char *exception;
|
const char *exception;
|
||||||
|
@ -66,7 +66,7 @@ app_instance_main(wasm_module_inst_t module_inst)
|
||||||
return exception;
|
return exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static const void *
|
||||||
app_instance_func(wasm_module_inst_t module_inst, const char *func_name)
|
app_instance_func(wasm_module_inst_t module_inst, const char *func_name)
|
||||||
{
|
{
|
||||||
wasm_application_execute_func(module_inst, func_name, app_argc - 1,
|
wasm_application_execute_func(module_inst, func_name, app_argc - 1,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user