Implement riscv support for interpreter (#505)
This commit is contained in:
@ -9,11 +9,28 @@
|
||||
#include "bh_assert.h"
|
||||
#include "bh_log.h"
|
||||
#include "wasm_export.h"
|
||||
#if defined(BUILD_TARGET_RISCV64_LP64) || defined(BUILD_TARGET_RISCV32_ILP32)
|
||||
#include "test_wasm_riscv64.h"
|
||||
#else
|
||||
#include "test_wasm.h"
|
||||
#endif /* end of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <sys/printk.h>
|
||||
|
||||
#if defined(BUILD_TARGET_RISCV64_LP64) || defined(BUILD_TARGET_RISCV32_ILP32)
|
||||
#if defined(BUILD_TARGET_RISCV64_LP64)
|
||||
#define CONFIG_GLOBAL_HEAP_BUF_SIZE 4360
|
||||
#define CONFIG_APP_STACK_SIZE 288
|
||||
#define CONFIG_MAIN_THREAD_STACK_SIZE 2400
|
||||
#else
|
||||
#define CONFIG_GLOBAL_HEAP_BUF_SIZE 5120
|
||||
#define CONFIG_APP_STACK_SIZE 512
|
||||
#define CONFIG_MAIN_THREAD_STACK_SIZE 4096
|
||||
#endif
|
||||
#define CONFIG_APP_HEAP_SIZE 256
|
||||
#else /* else of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */
|
||||
|
||||
#define CONFIG_GLOBAL_HEAP_BUF_SIZE 131072
|
||||
#define CONFIG_APP_STACK_SIZE 8192
|
||||
#define CONFIG_APP_HEAP_SIZE 8192
|
||||
@ -24,6 +41,8 @@
|
||||
#define CONFIG_MAIN_THREAD_STACK_SIZE 4096
|
||||
#endif
|
||||
|
||||
#endif /* end of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */
|
||||
|
||||
static int app_argc;
|
||||
static char **app_argv;
|
||||
|
||||
@ -120,7 +139,6 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
(void) arg2;
|
||||
(void) arg3;
|
||||
|
||||
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
|
||||
41
product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h
Normal file
41
product-mini/platforms/zephyr/simple/src/test_wasm_riscv64.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
unsigned char __aligned(4) wasm_test_file[] = {
|
||||
0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, 0x01, 0x10, 0x03, 0x60,
|
||||
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x01,
|
||||
0x7F, 0x00, 0x02, 0x31, 0x04, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x70, 0x75,
|
||||
0x74, 0x73, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x61, 0x6C,
|
||||
0x6C, 0x6F, 0x63, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x70, 0x72,
|
||||
0x69, 0x6E, 0x74, 0x66, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x04, 0x66,
|
||||
0x72, 0x65, 0x65, 0x00, 0x02, 0x03, 0x02, 0x01, 0x01, 0x04, 0x05, 0x01,
|
||||
0x70, 0x01, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x01, 0x06, 0x12, 0x03,
|
||||
0x7F, 0x01, 0x41, 0xC0, 0x01, 0x0B, 0x7F, 0x00, 0x41, 0x3A, 0x0B, 0x7F,
|
||||
0x00, 0x41, 0xC0, 0x01, 0x0B, 0x07, 0x2C, 0x04, 0x06, 0x6D, 0x65, 0x6D,
|
||||
0x6F, 0x72, 0x79, 0x02, 0x00, 0x04, 0x6D, 0x61, 0x69, 0x6E, 0x00, 0x04,
|
||||
0x0A, 0x5F, 0x5F, 0x64, 0x61, 0x74, 0x61, 0x5F, 0x65, 0x6E, 0x64, 0x03,
|
||||
0x01, 0x0B, 0x5F, 0x5F, 0x68, 0x65, 0x61, 0x70, 0x5F, 0x62, 0x61, 0x73,
|
||||
0x65, 0x03, 0x02, 0x0A, 0xB1, 0x01, 0x01, 0xAE, 0x01, 0x01, 0x03, 0x7F,
|
||||
0x23, 0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x20, 0x6B, 0x22, 0x02, 0x24,
|
||||
0x80, 0x80, 0x80, 0x80, 0x00, 0x41, 0x9B, 0x80, 0x80, 0x80, 0x00, 0x10,
|
||||
0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x02, 0x40, 0x02, 0x40, 0x41, 0x10,
|
||||
0x10, 0x81, 0x80, 0x80, 0x80, 0x00, 0x22, 0x03, 0x0D, 0x00, 0x41, 0xA8,
|
||||
0x80, 0x80, 0x80, 0x00, 0x10, 0x80, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41,
|
||||
0x7F, 0x21, 0x04, 0x0C, 0x01, 0x0B, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
|
||||
0x10, 0x41, 0x80, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x41, 0x10, 0x6A,
|
||||
0x10, 0x82, 0x80, 0x80, 0x80, 0x00, 0x1A, 0x41, 0x00, 0x21, 0x04, 0x20,
|
||||
0x03, 0x41, 0x04, 0x6A, 0x41, 0x00, 0x2F, 0x00, 0x91, 0x80, 0x80, 0x80,
|
||||
0x00, 0x3B, 0x00, 0x00, 0x20, 0x03, 0x41, 0x00, 0x28, 0x00, 0x8D, 0x80,
|
||||
0x80, 0x80, 0x00, 0x36, 0x00, 0x00, 0x20, 0x02, 0x20, 0x03, 0x36, 0x02,
|
||||
0x00, 0x41, 0x93, 0x80, 0x80, 0x80, 0x00, 0x20, 0x02, 0x10, 0x82, 0x80,
|
||||
0x80, 0x80, 0x00, 0x1A, 0x20, 0x03, 0x10, 0x83, 0x80, 0x80, 0x80, 0x00,
|
||||
0x0B, 0x20, 0x02, 0x41, 0x20, 0x6A, 0x24, 0x80, 0x80, 0x80, 0x80, 0x00,
|
||||
0x20, 0x04, 0x0B, 0x0B, 0x40, 0x01, 0x00, 0x41, 0x00, 0x0B, 0x3A, 0x62,
|
||||
0x75, 0x66, 0x20, 0x70, 0x74, 0x72, 0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00,
|
||||
0x31, 0x32, 0x33, 0x34, 0x0A, 0x00, 0x62, 0x75, 0x66, 0x3A, 0x20, 0x25,
|
||||
0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C,
|
||||
0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C, 0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75,
|
||||
0x66, 0x20, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64, 0x00
|
||||
};
|
||||
27
product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh
Executable file
27
product-mini/platforms/zephyr/simple/src/wasm-app-riscv64/build.sh
Executable file
@ -0,0 +1,27 @@
|
||||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
WAMR_DIR=${PWD}/../../..
|
||||
|
||||
echo "Build wasm app .."
|
||||
/opt/wasi-sdk/bin/clang -O3 \
|
||||
-z stack-size=128 -Wl,--initial-memory=65536 \
|
||||
-Wl,--global-base=0 \
|
||||
-o test.wasm main.c \
|
||||
-Wl,--export=main -Wl,--export=__main_argc_argv \
|
||||
-Wl,--export=__data_end -Wl,--export=__heap_base \
|
||||
-Wl,--strip-all,--no-entry \
|
||||
-Wl,--allow-undefined \
|
||||
-nostdlib \
|
||||
|
||||
echo "Build binarydump tool .."
|
||||
rm -fr build && mkdir build && cd build
|
||||
cmake ../../../../../../../test-tools/binarydump-tool
|
||||
make
|
||||
cd ..
|
||||
|
||||
echo "Generate test_wasm.h .."
|
||||
./build/binarydump -o test_wasm.h -n wasm_test_file test.wasm
|
||||
cp -a test_wasm.h ../test_wasm_riscv64.h
|
||||
|
||||
echo "Done"
|
||||
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *buf;
|
||||
|
||||
printf("Hello world!\n");
|
||||
|
||||
buf = malloc(16);
|
||||
if (!buf) {
|
||||
printf("malloc buf failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("buf ptr: %p\n", buf);
|
||||
|
||||
snprintf(buf, 1024, "%s", "1234\n");
|
||||
printf("buf: %s", buf);
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user