Compare commits
3 Commits
ce0c7f4f7f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
b8f4e987b7
|
|||
|
ecfb162062
|
|||
|
20e96abee1
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,5 +1 @@
|
||||
wasm-base/examples/*.wasm
|
||||
wasm-base/examples/*.aot
|
||||
wasm-base/examples/embed/*_host.c
|
||||
wasm-base/examples/*.host
|
||||
wasm-base/examples/*_wasm.c
|
||||
examples/build-*/
|
||||
|
||||
@ -4,8 +4,7 @@ WASI_CC := ${WASI_ROOT}/bin/clang
|
||||
WASI_CFLAGS := --target=wasm32 \
|
||||
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
|
||||
-z stack-size=4096 \
|
||||
-nostdlib \
|
||||
-O0 -g -Wall \
|
||||
-O2 -nostdlib \
|
||||
-Wl,--no-entry \
|
||||
-Wl,--initial-memory=65536 \
|
||||
-Wl,--export-all \
|
||||
@ -16,7 +15,8 @@ WASI_CFLAGS := --target=wasm32 \
|
||||
WAMR := /opt/wamr
|
||||
IWASM_LIB := /opt/wamr-libiwasm
|
||||
CC := gcc
|
||||
CFLAGS := -I. -include arch/${ARCH}/lib.c -O0 -g -m32 -fomit-frame-pointer
|
||||
# NOTE: Without -fomit-frame-pointer I get "error: bp cannot be used in ‘asm’ here"
|
||||
CFLAGS := -I. -O2 -m32 -ffunction-sections -fomit-frame-pointer
|
||||
LDFLAGS := -Wl,-T linker.ld $^ -Wl,--build-id=none -static -nostdlib -m32 \
|
||||
-Wl,-rpath,${IWASM_LIB} -L${IWASM_LIB} -liwasm
|
||||
INCL := -I${WAMR}/core/iwasm/include \
|
||||
@ -29,7 +29,6 @@ INCL := -I${WAMR}/core/iwasm/include \
|
||||
WAMRC := /opt/wamr-wamrc/wamrc
|
||||
WAMRCFLAGS := --target=i386 --format=object
|
||||
XXD := busybox xxd
|
||||
WASM2C := wasm2c
|
||||
|
||||
|
||||
################################################################
|
||||
@ -45,7 +44,7 @@ ${BUILD_DIR}/%/module.wasm: %.c
|
||||
# ${WAMRC} ${WAMRCFLAGS} -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
|
||||
#
|
||||
# ${BUILD_DIR}/startup.o: arch/bochs/startup.s
|
||||
# ${CC} $< ${CFLAGS} -c -ffunction-sections -o $@
|
||||
# ${CC} $< ${CFLAGS} -c -o $@
|
||||
#
|
||||
# ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
|
||||
# ${CC} ${LDFLAGS} -o $@
|
||||
@ -66,10 +65,10 @@ ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module_wasm.c
|
||||
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
|
||||
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
|
||||
${BUILD_DIR}/$*/module_host.c
|
||||
${CC} ${CFLAGS} ${INCL} -c -ffunction-sections ${BUILD_DIR}/$*/module_host.c -o $@
|
||||
${CC} ${CFLAGS} ${INCL} -c ${BUILD_DIR}/$*/module_host.c -o $@
|
||||
|
||||
${BUILD_DIR}/startup.o: arch/bochs/startup.s
|
||||
${CC} $< ${CFLAGS} -c -ffunction-sections -o $@
|
||||
${CC} $< ${CFLAGS} -c -o $@
|
||||
|
||||
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
|
||||
${CC} ${LDFLAGS} -o $@
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
|
||||
|
||||
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
set timeout=0
|
||||
set default=0
|
||||
|
||||
menuentry "CoRedOS" {
|
||||
multiboot /boot/system.elf
|
||||
boot
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,75 +0,0 @@
|
||||
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
|
||||
|
||||
// #include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lib.c"
|
||||
|
||||
// #include "bh_read_file.h"
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#include "module_wasm.c"
|
||||
|
||||
#define STACK_SIZE (8 * 1024)
|
||||
#define HEAP_SIZE (8 * 1024)
|
||||
|
||||
// TODO: Set this up so the lsp actually finds the includes...
|
||||
|
||||
MAIN() {
|
||||
char error_buf[128];
|
||||
wasm_module_t module;
|
||||
wasm_module_inst_t module_inst;
|
||||
wasm_function_inst_t func;
|
||||
wasm_exec_env_t exec_env;
|
||||
uint32 stack_size = 8 * 1024;
|
||||
uint32 heap_size = 8 * 1024;
|
||||
|
||||
/* initialize the wasm runtime */
|
||||
RuntimeInitArgs init_args;
|
||||
memset(&init_args, 0, sizeof(init_args));
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* parse the WASM file from buffer and create a WASM module */
|
||||
module = wasm_runtime_load(build_bochs_sum_module_aot, build_bochs_sum_module_aot_len, error_buf,
|
||||
sizeof(error_buf));
|
||||
|
||||
/* create an instance of the WASM module (WASM linear memory is ready) */
|
||||
module_inst = wasm_runtime_instantiate(module, stack_size, heap_size,
|
||||
error_buf, sizeof(error_buf));
|
||||
|
||||
/* lookup a WASM function by its name, the function signature can NULL here */
|
||||
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
|
||||
|
||||
/* create an execution environment to execute arbitrary WASM functions */
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
|
||||
|
||||
/* arguments are always transferred in 32-bit element */
|
||||
uint32 args[1];
|
||||
|
||||
/* call an arbitrary WASM function */
|
||||
MARKER(start_trace);
|
||||
if (!wasm_runtime_call_wasm(exec_env, func, 0, args)) {
|
||||
/* function wasn't called correctly */
|
||||
POSIX_PRINTF("Failed to call function 'wasm_module'!\n");
|
||||
}
|
||||
MARKER(stop_trace);
|
||||
|
||||
POSIX_PRINTF("Sum: %d\n!", args[0]);
|
||||
|
||||
/* the return value is stored in args[0] */
|
||||
if (args[0] == 100) {
|
||||
MARKER(ok_marker);
|
||||
} else {
|
||||
MARKER(fail_marker);
|
||||
}
|
||||
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy();
|
||||
}
|
||||
@ -1,68 +0,0 @@
|
||||
unsigned char build_bochs_sum_module_aot[] = {
|
||||
0x00, 0x61, 0x6f, 0x74, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3e, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x78, 0x38, 0x36, 0x5f, 0x36, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x7f, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x7f, 0x01, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00,
|
||||
0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x00, 0x00,
|
||||
0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xc3, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x2e,
|
||||
0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8b, 0x47, 0x10,
|
||||
0x48, 0xba, 0x64, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x48, 0x8b,
|
||||
0x88, 0x78, 0x01, 0x00, 0x00, 0x8b, 0x80, 0xd0, 0x01, 0x00, 0x00, 0x83,
|
||||
0xc0, 0xf0, 0x48, 0x89, 0x54, 0x01, 0x08, 0xb8, 0x64, 0x00, 0x00, 0x00,
|
||||
0xc3, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2a, 0x01, 0x00, 0x00,
|
||||
0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x07, 0x00,
|
||||
0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x12, 0x00, 0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x63,
|
||||
0x61, 0x6c, 0x6c, 0x5f, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x77, 0x61, 0x73, 0x6d,
|
||||
0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x0d, 0x00, 0x5f, 0x5f, 0x64, 0x73, 0x6f, 0x5f, 0x68, 0x61,
|
||||
0x6e, 0x64, 0x6c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x0b, 0x00, 0x5f, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x65,
|
||||
0x6e, 0x64, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00,
|
||||
0x5f, 0x5f, 0x73, 0x74, 0x61, 0x63, 0x6b, 0x5f, 0x6c, 0x6f, 0x77, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x5f, 0x5f, 0x73, 0x74,
|
||||
0x61, 0x63, 0x6b, 0x5f, 0x68, 0x69, 0x67, 0x68, 0x00, 0x00, 0x00, 0x00,
|
||||
0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0e, 0x00, 0x5f, 0x5f, 0x67, 0x6c,
|
||||
0x6f, 0x62, 0x61, 0x6c, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x00, 0x00, 0x00,
|
||||
0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0c, 0x00, 0x5f, 0x5f, 0x68, 0x65,
|
||||
0x61, 0x70, 0x5f, 0x62, 0x61, 0x73, 0x65, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x0b, 0x00, 0x5f, 0x5f, 0x68, 0x65, 0x61, 0x70, 0x5f, 0x65,
|
||||
0x6e, 0x64, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0e, 0x00,
|
||||
0x5f, 0x5f, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 0x5f, 0x62, 0x61, 0x73,
|
||||
0x65, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x03, 0x00, 0x0d, 0x00,
|
||||
0x5f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x61, 0x73, 0x65,
|
||||
0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x03, 0x00, 0x16, 0x00,
|
||||
0x5f, 0x5f, 0x77, 0x61, 0x73, 0x6d, 0x5f, 0x66, 0x69, 0x72, 0x73, 0x74,
|
||||
0x5f, 0x70, 0x61, 0x67, 0x65, 0x5f, 0x65, 0x6e, 0x64, 0x00, 0x00, 0x00,
|
||||
0x05, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
unsigned int build_bochs_sum_module_aot_len = 776;
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -6,6 +6,10 @@
|
||||
#define __QUOTE(x) #x
|
||||
#define QUOTE(x) __QUOTE(x)
|
||||
|
||||
#ifndef ARCH_ASM_CLOBBER_ALL
|
||||
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
|
||||
#endif
|
||||
|
||||
#ifndef MARKER
|
||||
#define MARKER(str) \
|
||||
__asm__ volatile(QUOTE(str) ":" \
|
||||
|
||||
Reference in New Issue
Block a user