Add xtensa AOT support and fix build issue of alios (#223)

* Clean compiling warnings of zephyr samples

* Support xtensa AOT and fix build issue of alios
This commit is contained in:
Weining
2020-04-01 18:38:42 +08:00
committed by GitHub
parent c1a0e6d877
commit c6fc12b7b6
20 changed files with 762 additions and 68 deletions

View File

@ -54,6 +54,54 @@ app_instance_main(wasm_module_inst_t module_inst)
static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 };
#ifdef CONFIG_BOARD_ESP32
#include "mem_alloc.h"
/*
esp32_technical_reference_manual:
"
The capacity of Internal SRAM 1 is 128 KB. Either CPU can read and write this memory at addresses
0x3FFE_0000 ~ 0x3FFF_FFFF of the data bus, and also at addresses 0x400A_0000 ~ 0x400B_FFFF of the
instruction bus.
"
The custom linker script defines dram0_1_seg and map it to 0x400A_0000 ~ 0x400B_FFFF for instruction bus access.
Here we define the buffer that will be placed to dram0_1_seg.
*/
static char esp32_executable_memory_buf[100 * 1024] __attribute__((section (".aot_code_buf"))) = { 0 };
/* the poll allocator for executable memory */
static mem_allocator_t esp32_exec_mem_pool_allocator;
static int
esp32_exec_mem_init()
{
if (!(esp32_exec_mem_pool_allocator =
mem_allocator_create(esp32_executable_memory_buf,
sizeof(esp32_executable_memory_buf))))
return -1;
return 0;
}
static void
esp32_exec_mem_destroy()
{
mem_allocator_destroy(esp32_exec_mem_pool_allocator);
}
static void *
esp32_exec_mem_alloc(unsigned int size)
{
return mem_allocator_malloc(esp32_exec_mem_pool_allocator, size);
}
static void
esp32_exec_mem_free(void *addr)
{
mem_allocator_free(esp32_exec_mem_pool_allocator, addr);
}
#endif /* end of #ifdef CONFIG_BOARD_ESP32 */
void iwasm_main(void *arg1, void *arg2, void *arg3)
{
int start, end;
@ -72,6 +120,7 @@ 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;
@ -84,6 +133,16 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
return;
}
#ifdef CONFIG_BOARD_ESP32
/* Initialize executable memory */
if (esp32_exec_mem_init() != 0) {
printf("Init executable memory failed.\n");
goto fail1;
}
/* Set hook functions for executable memory management */
set_exec_mem_alloc_func(esp32_exec_mem_alloc, esp32_exec_mem_free);
#endif
#if WASM_ENABLE_LOG != 0
bh_log_set_verbose_level(log_verbose_level);
#endif
@ -96,7 +155,11 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
printf("%s\n", error_buf);
#ifdef CONFIG_BOARD_ESP32
goto fail1_1;
#else
goto fail1;
#endif
}
/* instantiate the module */
@ -119,6 +182,12 @@ fail2:
/* unload the module */
wasm_runtime_unload(wasm_module);
#ifdef CONFIG_BOARD_ESP32
fail1_1:
/* destroy executable memory */
esp32_exec_mem_destroy();
#endif
fail1:
/* destroy runtime environment */
wasm_runtime_destroy();