Compare commits

..

5 Commits

6 changed files with 60 additions and 43 deletions

View File

@ -6,3 +6,6 @@ run:
run-external:
docker run --rm -it -v "./examples:/home/ubuntu/examples" wasm-base:latest /usr/bin/fish
bochs:
nix shell nixpkgs#bochs --command sh -c "bochs -f ./examples/arch/bochs/bochsrc-host.txt -q"

View File

@ -4,7 +4,7 @@ WASI_CC := ${WASI_ROOT}/bin/clang
WASI_CFLAGS := --target=wasm32 \
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
-z stack-size=4096 \
-O2 -nostdlib \
-O0 -nostdlib \
-Wl,--no-entry \
-Wl,--initial-memory=65536 \
-Wl,--export-all \
@ -15,17 +15,15 @@ WASI_CFLAGS := --target=wasm32 \
WAMR := /opt/wamr
IWASM_LIB := /opt/wamr-libiwasm
CC := gcc
# 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
# NOTE: When compiling I get "error: bp cannot be used in asm here"
# I could remove "ebp" from the clobber list (ARCH_ASM_CLOBBER_ALL) or
# use the -fomit-frame-pointer flag to tell gcc it shouldn't rely on ebp for enter/leave...
CFLAGS := -I. -O0 -m32 -ffunction-sections -std=c11 -fomit-frame-pointer
LDFLAGS = -Wl,-T linker.ld $^ -Wl,--build-id=none -static -nostdlib -m32 \
-Wl,-rpath,${IWASM_LIB} -L${IWASM_LIB} -liwasm -lgcc
INCL := -I${WAMR}/core/iwasm/include \
-I${WAMR}/core/iwasm/common \
-I${WAMR}/core/shared/platform/include \
-I${WAMR}/core/shared/platform/linux \
-I${WAMR}/core/shared/mem-alloc \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/utils/uncommon
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/platform/baremetal
WAMRC := /opt/wamr-wamrc/wamrc
WAMRCFLAGS := --target=i386 --format=object
XXD := busybox xxd
@ -87,11 +85,12 @@ BOCHS_RUNNER_ARGS = \
-V arch/bochs/vgabios.bin \
-b arch/bochs/BIOS-bochs-latest \
${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
# ${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
${BUILD_DIR}/%/trace.pb:
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
-f ${FAIL_TRACE} \
-e $(shell dirname $<)/system.elf \
-i $(shell dirname $<)/system.iso \
-e $(shell dirname $<)/$*/system.elf \
-i $(shell dirname $<)/$*/system.iso \
-- \
-Wf,--state-file=$(shell dirname $<)/state \
-Wf,--trace-file=$(shell dirname $<)/trace.pb \

View File

@ -0,0 +1,9 @@
megs: 32
display_library: nogui
romimage: file=/home/ubuntu/examples/arch/bochs/BIOS-bochs-latest
vgaromimage: file=/home/ubuntu/examples/arch/bochs/vgabios.bin
ata0-master: type=cdrom, path=/home/ubuntu/examples/build-bochs/sum/system.iso, status=inserted
boot: cdrom
log: bochslog.txt
clock: sync=realtime, time0=local
cpu: count=1, ips=1000000

View File

@ -0,0 +1,10 @@
megs: 32
display_library: nogui
romimage: file="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/arch/bochs/BIOS-bochs-latest"
vgaromimage: file="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/arch/bochs/vgabios.bin"
ata0-master: type=cdrom, path="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/build-bochs/sum/system.iso", status=inserted
boot: cdrom
log: bochslog.txt
clock: sync=realtime, time0=local
cpu: count=1, ips=1000000
sound: driver=dummy

View File

@ -1,18 +1,14 @@
// 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 "__WASM_ARRAY_FILE__"
#define STACK_SIZE (8 * 1024)
#define HEAP_SIZE (8 * 1024)
#define STACK_SIZE (4 * 1024)
#define HEAP_SIZE (4 * 1024)
// TODO: Set this up so the lsp actually finds the includes...
@ -22,8 +18,6 @@ MAIN() {
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;
@ -39,14 +33,14 @@ MAIN() {
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,
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);
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
/* arguments are always transferred in 32-bit element */
uint32 args[1];

View File

@ -31,21 +31,21 @@ RUN git clone https://gitea.vps.chriphost.de/christoph/wamr \
WORKDIR /wamr
# Build WAMR iwasm (vmcore standalone interpreter)
# RUN cd product-mini/platforms/linux \
# && mkdir build_iwasm && cd build_iwasm \
# && cmake \
# -DWAMR_BUILD_PLATFORM=linux \
# -DWAMR_BUILD_TARGET=X86_64 \
# -DWAMR_BUILD_AOT=0 \
# -DWAMR_BUILD_WAMR_COMPILER=0 \
# -DWAMR_BUILD_INTERP=1 \
# -DWAMR_BUILD_FAST_INTERP=0 \
# -DWAMR_BUILD_JIT=0 \
# -DWAMR_BUILD_FAST_JIT=0 \
# -DWAMR_BUILD_LIBC_BUILTIN=1 \
# -DWAMR_BUILD_LIBC_WASI=1 \
# .. \
# && make -j$(nproc)
RUN cd product-mini/platforms/linux \
&& mkdir build_iwasm && cd build_iwasm \
&& cmake \
-DWAMR_BUILD_PLATFORM=linux \
-DWAMR_BUILD_TARGET=X86_64 \
-DWAMR_BUILD_AOT=0 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=1 \
.. \
&& make -j$(nproc)
# Build WAMR wamrc (standalone compiler)
RUN cd wamr-compiler \
@ -110,6 +110,7 @@ RUN mkdir build_libiwasm && cd build_libiwasm \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_SIMD=0 \
-DCMAKE_COLOR_DIAGNOSTICS=ON \
.. \
&& make -j$(nproc)
@ -134,12 +135,13 @@ RUN apt-get update \
grub-pc-bin \
&& apt-get clean
COPY --from=wamr-builder /wamr /opt/wamr
COPY --from=wamr-builder /wamrlib /opt/wamrlib
COPY --from=wamr-builder /wamrlib /opt/wamr
COPY --from=wamr-builder /wamr/wamr-compiler/build_wamrc /opt/wamr/wamr-compiler/build_wamrc
COPY --from=wamr-builder /wamr/product-mini/platforms/linux/build_iwasm /opt/wamr/product-mini/platforms/linux/build_iwasm
RUN ln -sf /opt/wamr/product-mini/platforms/linux/build_iwasm /opt/wamr-iwasm \
&& ln -sf /opt/wamr/wamr-compiler/build_wamrc /opt/wamr-wamrc \
&& ln -sf /opt/wamrlib/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \
&& ln -sf /opt/wamrlib/build_libiwasm /opt/wamr-libiwasm
&& ln -sf /opt/wamr/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \
&& ln -sf /opt/wamr/build_libiwasm /opt/wamr-libiwasm
COPY ./examples /home/ubuntu/examples
WORKDIR /home/ubuntu/examples