Compare commits
7 Commits
e6237cc06e
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
593f0e34f7
|
|||
|
64a7098112
|
|||
|
7a4bf17670
|
|||
|
ad8a908506
|
|||
|
eb5b895b00
|
|||
|
25b5ecfb3b
|
|||
|
60fa13573d
|
11
Makefile
11
Makefile
@ -1,5 +1,5 @@
|
||||
docker:
|
||||
docker build -t gitea.vps.chriphost.de/christoph/wasm-base:latest -f wasm-base.dockerfile . --build-arg CACHE_DATE="$(shell date)"
|
||||
docker build --progress=plain -t gitea.vps.chriphost.de/christoph/wasm-base:latest -f wasm-base.dockerfile . --build-arg CACHE_DATE="$(shell date)"
|
||||
|
||||
run:
|
||||
docker run --rm -it gitea.vps.chriphost.de/christoph/wasm-base:latest /usr/bin/fish
|
||||
@ -9,3 +9,12 @@ run-external:
|
||||
|
||||
bochs-host:
|
||||
nix shell nixpkgs#bochs --command sh -c "bochs -q -f ./examples/arch/bochs/bochsrc-host.txt -q"
|
||||
|
||||
qemu-host:
|
||||
qemu-system-i386 -drive file=./examples/build-bochs/sum/system.iso,media=cdrom -boot d -m 32 -S -s
|
||||
|
||||
gdb-host:
|
||||
nix shell nixpkgs#gdb --command gdb ./examples/build-bochs/sum/system.elf -ex "set substitute-path build-bochs ./examples/build-bochs" -ex "target remote localhost:1234" -ex "break os_main"
|
||||
|
||||
radare:
|
||||
radare2 -AA -c "s dbg.os_main; pdf" ./examples/build-bochs/sum/system.elf
|
||||
|
||||
@ -1,16 +1,5 @@
|
||||
ARCH ?= bochs
|
||||
|
||||
BUILD_DIR := build-${ARCH}
|
||||
FAIL_BIN ?= /home/fail/bin
|
||||
FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
|
||||
FAIL_TRACE ?= ${FAIL_BIN}/generic-tracing-client
|
||||
FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
|
||||
FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
|
||||
FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
|
||||
FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
|
||||
BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
|
||||
RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser.py
|
||||
|
||||
EXPERIMENTS := $(patsubst %.c,%,$(shell echo *.c))
|
||||
|
||||
include arch/${ARCH}.mk
|
||||
@ -25,42 +14,39 @@ help:
|
||||
@echo "Current Configuartion"
|
||||
@echo " ARCH=${ARCH}"
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.wasm
|
||||
rm -f *.aot
|
||||
rm -f *_wasm.c
|
||||
rm -f *.d
|
||||
rm -f *.o
|
||||
rm -f embed/*_host.c
|
||||
rm -f *_host.elf
|
||||
rm -rf ${BUILD_DIR}
|
||||
# rm -f *.wasm
|
||||
# rm -f *.aot
|
||||
# rm -f *_wasm.c
|
||||
# rm -f *.d
|
||||
# rm -f *.o
|
||||
# rm -f embed/*_host.c
|
||||
# rm -f *_host.elf
|
||||
rm -rf ${BUILD_DIR}/*
|
||||
|
||||
clean-%:
|
||||
rm -rf ${BUILD_DIR}/$(patsubst clean-%,%,$@)
|
||||
contrib/clean-db '${ARCH}/$(patsubst clean-%,%,$@)'
|
||||
|
||||
|
||||
build-%:
|
||||
@echo "****************************************************************\n\
|
||||
* The next step is to trace a golden run. The golden run executes the\n\
|
||||
* system-under-test (SUT) within the emulator. A trace file is \n\
|
||||
* produced and saved as: ${BUILD_DIR}/main/trace.pb\n\
|
||||
*\n\
|
||||
* $ make trace-$(patsubst build-%,%,$@)\n\
|
||||
****************************************************************"
|
||||
|
||||
* The next step is to trace a golden run. The golden run executes the\n \
|
||||
* system-under-test (SUT) within the emulator. A trace file is \n \
|
||||
* produced and saved as: ${BUILD_DIR}/main/trace.pb\n \
|
||||
*\n \
|
||||
* $ make trace-$(patsubst build-%,%,$@)\n \
|
||||
****************************************************************"
|
||||
|
||||
trace-%:
|
||||
@echo "****************************************************************\n\
|
||||
* The trace is now generated. It can be viewed with\n\
|
||||
*\n\
|
||||
* $ make dump-$(patsubst trace-%,%,$@)\n\
|
||||
*\n\
|
||||
* Next, we have to import the trace into the database\n\
|
||||
*\n\
|
||||
* $ make import-$(patsubst trace-%,%,$@)\n\
|
||||
****************************************************************"
|
||||
* The trace is now generated. It can be viewed with\n \
|
||||
*\n \
|
||||
* $ make dump-$(patsubst trace-%,%,$@)\n \
|
||||
*\n \
|
||||
* Next, we have to import the trace into the database\n \
|
||||
*\n \
|
||||
* $ make import-$(patsubst trace-%,%,$@)\n \
|
||||
****************************************************************"
|
||||
|
||||
dump-%: ${BUILD_DIR}/%/trace.pb
|
||||
${FAIL_DUMP} $(shell dirname $<)/trace.pb
|
||||
@ -75,35 +61,31 @@ ${HOME}/.my.cnf:
|
||||
|
||||
import-%: import-arch-%
|
||||
@echo "****************************************************************\n\
|
||||
* The golden run sits now within the MySQL database. If you are interested,\n\
|
||||
* use the 'mysql' command to inspect the curent state of the DB. The tables\n\
|
||||
* trace, fsppilot, and fspgroup are of special interest.\n\
|
||||
*\n\
|
||||
* Next, we have to run the campaign sever and the injection client\n\
|
||||
*\n\
|
||||
* $ make server-$(patsubst import-%,%,$@) &\n\
|
||||
* $ make client-$(patsubst import-%,%,$@) \n\n\
|
||||
* Afterwards, the results can be viewd with\n\
|
||||
* $ make result-$(subst import-,,$@)\n\
|
||||
****************************************************************"
|
||||
|
||||
server-%:
|
||||
${FAIL_SERVER} -v ${ARCH}/$(subst server-,,$@) -b %
|
||||
* The golden run sits now within the MySQL database. If you are interested,\n \
|
||||
* use the 'mysql' command to inspect the curent state of the DB. The tables\n \
|
||||
* trace, fsppilot, and fspgroup are of special interest.\n \
|
||||
*\n \
|
||||
* Next, we have to run the campaign sever and the injection client\n \
|
||||
*\n \
|
||||
* $ make server-$(patsubst import-%,%,$@) &\n \
|
||||
* $ make client-$(patsubst import-%,%,$@) \n\n \
|
||||
* Afterwards, the results can be viewd with\n \
|
||||
* $ make result-$(subst import-,,$@)\n \
|
||||
****************************************************************"
|
||||
|
||||
result-%:
|
||||
@echo "select variant, benchmark, resulttype, sum(t.time2 - t.time1 + 1) as faults\
|
||||
FROM variant v \
|
||||
JOIN trace t ON v.id = t.variant_id \
|
||||
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address\
|
||||
JOIN fspgroup g ON g.variant_id = t.variant_id AND g.instr2 = t.instr2 AND g.data_address = t.data_address \
|
||||
JOIN result_GenericExperimentMessage r ON r.pilot_id = g.pilot_id \
|
||||
JOIN fsppilot p ON r.pilot_id = p.id \
|
||||
WHERE v.variant = \"${ARCH}/$(patsubst result-%,%,$@)\"\
|
||||
WHERE v.variant = \"${ARCH}/$(patsubst result-%,%,$@)\" \
|
||||
GROUP BY v.id, resulttype \
|
||||
ORDER BY variant, benchmark, resulttype;" |mysql -t
|
||||
|
||||
resultbrowser:
|
||||
${RESULT_BROWSER} --host=0.0.0.0 --port=5000
|
||||
|
||||
|
||||
# Do never remove implicitly generated stuff
|
||||
.SECONDARY:
|
||||
|
||||
@ -1,5 +1,12 @@
|
||||
# C -> WASM
|
||||
WASI_ROOT := /opt/wasi-sdk
|
||||
WAMR := /opt/wamr
|
||||
|
||||
# -O3 generates more code than -O2 (unrolling/inlining etc.)
|
||||
OPT := -O2
|
||||
|
||||
################################################################
|
||||
# C -> WASM
|
||||
|
||||
WASI_CC := ${WASI_ROOT}/bin/clang
|
||||
WASI_CFLAGS := \
|
||||
--target=wasm32 \
|
||||
@ -14,67 +21,6 @@ WASI_CFLAGS := \
|
||||
-Wl,--export=__heap_base \
|
||||
-Wl,--export=__data_end
|
||||
|
||||
# WASM -> Baremetal
|
||||
WAMR := /opt/wamr
|
||||
|
||||
WAMRC := /opt/wamr-wamrc/wamrc
|
||||
WAMRCFLAGS := \
|
||||
--target=i386 \
|
||||
--cpu=generic
|
||||
XXD := busybox xxd
|
||||
|
||||
# NOTE: make build-sum: "error: bp cannot be used in ‘asm’ here"
|
||||
# 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...
|
||||
CC := /opt/crosscompiler/bin/i686-elf-gcc
|
||||
CFLAGS := \
|
||||
-I. \
|
||||
-O0 \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-fomit-frame-pointer \
|
||||
-ggdb
|
||||
IWASM_LIB := /opt/wamr-libiwasm # Baremetal
|
||||
LDFLAGS = \
|
||||
-Wl,-T linker.ld \
|
||||
$^ \
|
||||
-Wl,--build-id=none \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m32 \
|
||||
-Wl,-rpath,${IWASM_LIB} \
|
||||
-L${IWASM_LIB} \
|
||||
-liwasm \
|
||||
-lc \
|
||||
-lgcc
|
||||
INCL := \
|
||||
-I${WAMR}/core/iwasm/include \
|
||||
-I${WAMR}/core/shared/utils \
|
||||
-I${WAMR}/core/shared/platform/baremetal \
|
||||
-I/opt/crosscompiler/i686-elf/include
|
||||
|
||||
CC_LINUX := gcc
|
||||
CFLAGS_LINUX := \
|
||||
-I. \
|
||||
-O0 \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-ggdb
|
||||
IWASM_LIB_LINUX := /opt/wamr-libiwasm-linux
|
||||
LDFLAGS_LINUX = \
|
||||
$^ \
|
||||
-m32 \
|
||||
-Wl,-rpath,${IWASM_LIB_LINUX} \
|
||||
-L${IWASM_LIB_LINUX} \
|
||||
-liwasm \
|
||||
-lm
|
||||
INCL_LINUX := \
|
||||
-I${WAMR}/core/iwasm/include \
|
||||
-I${WAMR}/core/shared/utils \
|
||||
-I${WAMR}/core/shared/platform/linux
|
||||
|
||||
################################################################
|
||||
# C -> WASM
|
||||
${BUILD_DIR}/%/module.wasm: %.c
|
||||
mkdir -p $(shell dirname $@)
|
||||
${WASI_CC} ${WASI_CFLAGS} $< -o $@
|
||||
@ -91,21 +37,64 @@ ${BUILD_DIR}/%/module.wasm: %.c
|
||||
# ${CC} ${LDFLAGS} -o $@
|
||||
|
||||
################################################################
|
||||
# WASM -> AOT -> Loaded by Runtime (FAIL)
|
||||
# WASM -> AOT
|
||||
|
||||
WAMRC := /opt/wamr-wamrc/wamrc
|
||||
WAMRCFLAGS := \
|
||||
--target=i386 \
|
||||
--cpu=generic \
|
||||
--opt-level=0
|
||||
|
||||
${BUILD_DIR}/%/module.aot: ${BUILD_DIR}/%/module.wasm
|
||||
${WAMRC} ${WAMRCFLAGS} -o $@ $<
|
||||
|
||||
XXD := busybox xxd
|
||||
|
||||
${BUILD_DIR}/%/module_wasm.c: ${BUILD_DIR}/%/module.aot
|
||||
${XXD} -i $< > $@
|
||||
|
||||
################################################################
|
||||
# AOT loaded by Runtime (FAIL+Baremetal platform)
|
||||
|
||||
# NOTE: make build-sum: "error: bp cannot be used in ‘asm’ here"
|
||||
# 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...
|
||||
CC := /opt/crosscompiler/bin/i386-elf-gcc
|
||||
CFLAGS := \
|
||||
-I. \
|
||||
${OPT} \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-ffreestanding \
|
||||
-fomit-frame-pointer \
|
||||
-ggdb
|
||||
IWASM_LIB_DEBUG := /opt/wamr-libiwasm-baremetal-debug
|
||||
IWASM_LIB_RELEASE := /opt/wamr-libiwasm-baremetal-release
|
||||
LDFLAGS = \
|
||||
-Wl,-T linker.ld \
|
||||
$^ \
|
||||
-Wl,--build-id=none \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m32 \
|
||||
-L${IWASM_LIB_RELEASE} \
|
||||
-liwasm \
|
||||
-lc \
|
||||
-lgcc \
|
||||
-lm
|
||||
INCL := \
|
||||
-I${WAMR}/core/iwasm/include \
|
||||
-I${WAMR}/core/shared/utils \
|
||||
-I${WAMR}/core/shared/platform/baremetal
|
||||
|
||||
${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module_wasm.c
|
||||
cp embed/host.c ${BUILD_DIR}/$*/module_host.c
|
||||
cp embed/host-fail.c ${BUILD_DIR}/$*/module_host-fail.c
|
||||
sed -i \
|
||||
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
|
||||
-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 ${BUILD_DIR}/$*/module_host.c -o $@
|
||||
${BUILD_DIR}/$*/module_host-fail.c
|
||||
${CC} ${CFLAGS} ${INCL} -c ${BUILD_DIR}/$*/module_host-fail.c -o $@
|
||||
|
||||
${BUILD_DIR}/startup.o: arch/bochs/startup.s
|
||||
${CC} $< ${CFLAGS} -c -o $@
|
||||
@ -117,7 +106,31 @@ ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/syscalls.o ${BUI
|
||||
${CC} ${LDFLAGS} -o $@
|
||||
|
||||
################################################################
|
||||
# WASM -> AOT -> Loaded by Runtime (Host/Linux)
|
||||
# AOT loaded by Runtime (Host+Linux platform)
|
||||
|
||||
CC_LINUX := gcc
|
||||
CFLAGS_LINUX := \
|
||||
-I. \
|
||||
${OPT} \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-ggdb
|
||||
IWASM_LIB_LINUX_DEBUG := /opt/wamr-libiwasm-linux-debug
|
||||
IWASM_LIB_LINUX_RELEASE := /opt/wamr-libiwasm-linux-release
|
||||
LDFLAGS_LINUX = \
|
||||
$^ \
|
||||
-Wl,--build-id=none \
|
||||
-static \
|
||||
-m32 \
|
||||
-Wl,-rpath,${IWASM_LIB_LINUX_RELEASE} \
|
||||
-L${IWASM_LIB_LINUX_RELEASE} \
|
||||
-liwasm \
|
||||
-lm
|
||||
INCL_LINUX := \
|
||||
-I${WAMR}/core/iwasm/include \
|
||||
-I${WAMR}/core/shared/utils \
|
||||
-I${WAMR}/core/shared/platform/linux
|
||||
|
||||
${BUILD_DIR}/%/system-linux.o: ${BUILD_DIR}/%/module_wasm.c
|
||||
cp embed/host-linux.c ${BUILD_DIR}/$*/module_host-linux.c
|
||||
sed -i \
|
||||
@ -131,7 +144,71 @@ ${BUILD_DIR}/%/system-linux.elf: ${BUILD_DIR}/%/system-linux.o
|
||||
${CC_LINUX} ${LDFLAGS_LINUX} -o $@
|
||||
|
||||
################################################################
|
||||
# Bochs
|
||||
# AOT loaded by Runtime (Host+Baremetal platform)
|
||||
|
||||
CC_BAREMETAL := /opt/crosscompiler/bin/i386-elf-gcc
|
||||
CFLAGS_BAREMETAL := \
|
||||
-I. \
|
||||
${OPT} \
|
||||
-m32 \
|
||||
-ffunction-sections \
|
||||
-ffreestanding \
|
||||
-ggdb
|
||||
IWASM_LIB_BAREMETAL := /opt/wamr-libiwasm
|
||||
LDFLAGS_BAREMETAL = \
|
||||
$^ \
|
||||
-Wl,--build-id=none \
|
||||
-static \
|
||||
-nostdlib \
|
||||
-m32 \
|
||||
-L${IWASM_LIB_BAREMETAL} \
|
||||
-liwasm \
|
||||
-lc \
|
||||
-lgcc \
|
||||
-lm \
|
||||
--entry main
|
||||
# Trace where the memset symbol is actually coming from
|
||||
# LDFLAGS_BAREMETAL += -Wl,-Map,$@.map -Wl,--trace-symbol=memset
|
||||
INCL_BAREMETAL := \
|
||||
-I${WAMR}/core/iwasm/include \
|
||||
-I${WAMR}/core/shared/utils \
|
||||
-I${WAMR}/core/shared/platform/baremetal
|
||||
|
||||
${BUILD_DIR}/%/system-baremetal.o: ${BUILD_DIR}/%/module_wasm.c
|
||||
cp embed/host-baremetal.c ${BUILD_DIR}/$*/module_host-baremetal.c
|
||||
sed -i \
|
||||
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
|
||||
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
|
||||
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
|
||||
${BUILD_DIR}/$*/module_host-baremetal.c
|
||||
${CC_BAREMETAL} ${CFLAGS_BAREMETAL} ${INCL_BAREMETAL} -c ${BUILD_DIR}/$*/module_host-baremetal.c -o $@
|
||||
|
||||
${BUILD_DIR}/%/system-baremetal.elf: ${BUILD_DIR}/%/system-baremetal.o ${BUILD_DIR}/syscalls.o
|
||||
${CC_BAREMETAL} ${LDFLAGS_BAREMETAL} -o $@
|
||||
|
||||
################################################################
|
||||
# Fail/Bochs
|
||||
|
||||
# FAIL_BIN ?= /home/fail/bin
|
||||
# FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
|
||||
# FAIL_TRACE ?= ${FAIL_BIN}/generic-tracing-client
|
||||
# FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
|
||||
# FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
|
||||
# FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
|
||||
# FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
|
||||
# BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
|
||||
# RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser.py
|
||||
|
||||
FAIL_BIN ?= /home/fail/mars
|
||||
FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
|
||||
FAIL_TRACE ?= ${FAIL_BIN}/fail-x86-tracing
|
||||
FAIL_INJECT ?= ${FAIL_BIN}/generic-experiment-client
|
||||
FAIL_DUMP ?= ${FAIL_BIN}/dump-trace
|
||||
FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
|
||||
FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
|
||||
BOCHS_RUNNER ?= ${FAIL_BIN}/bochs-experiment-runner.py
|
||||
RESULT_BROWSER ?= ${FAIL_BIN}/resultbrowser
|
||||
|
||||
${BUILD_DIR}/%/system.iso: ${BUILD_DIR}/%/system.elf
|
||||
rm -rf $(shell dirname $<)/grub
|
||||
mkdir -p $(shell dirname $<)/grub/boot/grub
|
||||
@ -151,11 +228,16 @@ ${BUILD_DIR}/%/trace.pb:
|
||||
-e ${BUILD_DIR}/$*/system.elf \
|
||||
-i ${BUILD_DIR}/$*/system.iso \
|
||||
-- \
|
||||
-Wf,--state-file=${BUILD_DIR}/state \
|
||||
-Wf,--trace-file=${BUILD_DIR}/trace.pb \
|
||||
-Wf,--start-symbol=start_trace \
|
||||
-Wf,--save-symbol=start_trace \
|
||||
-Wf,--end-symbol=stop_trace \
|
||||
-Wf,--check-bounds
|
||||
-Wf,--state-file=${BUILD_DIR}/$*/state \
|
||||
-Wf,--trace-file=${BUILD_DIR}/$*/trace.pb \
|
||||
-Wf,--elf-file=${BUILD_DIR}/$*/system.elf
|
||||
# -Wf,--check-bounds
|
||||
|
||||
server-%:
|
||||
${FAIL_SERVER} -v ${ARCH}/$(subst server-,,$@) -b % --inject-single-bit --inject-registers
|
||||
|
||||
client-%:
|
||||
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} \
|
||||
@ -166,13 +248,14 @@ client-%:
|
||||
-- \
|
||||
-Wf,--state-dir=${BUILD_DIR}/$(subst client-,,$@)/state \
|
||||
-Wf,--trap \
|
||||
-Wf,--timeout=10 \
|
||||
-Wf,--timeout=500000 \
|
||||
-Wf,--ok-marker=ok_marker \
|
||||
-Wf,--fail-marker=fail_marker \
|
||||
-Wf,--catch-write-textsegment \
|
||||
-Wf,--catch-outerspace \
|
||||
2>/dev/null | grep -B 2 -A 8 'INJECT'
|
||||
|
||||
# -Wf,--catch-write-textsegment \
|
||||
# -Wf,--catch-outerspace \
|
||||
|
||||
inject-%:
|
||||
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
|
||||
-f ${FAIL_INJECT} \
|
||||
@ -187,17 +270,28 @@ inject-%:
|
||||
-Wf,--catch-write-textsegment \
|
||||
-Wf,--catch-outerspace
|
||||
|
||||
# TODO: Command line interface changed
|
||||
# NOTE: Command line interface changed?
|
||||
import-arch-%: ${BUILD_DIR}/%/trace.pb ${HOME}/.my.cnf
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type ram
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type register
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i regs
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i regs --no-gp --ip
|
||||
# ${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter
|
||||
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter --no-gp --ip
|
||||
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i MemoryImporter
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter
|
||||
# ${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter --no-gp --ip
|
||||
|
||||
${FAIL_IMPORT} -t $< -i MemoryImporter -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem
|
||||
${FAIL_IMPORT} -t $< -i RegisterImporter -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs --flags
|
||||
${FAIL_IMPORT} -t $< -i RegisterImporter -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip --no-gp --ip
|
||||
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip
|
||||
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem
|
||||
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs
|
||||
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip --sources
|
||||
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b mem --sources
|
||||
${FAIL_IMPORT} -t $< -i ElfImporter --objdump /usr/bin/objdump -e $(shell dirname $<)/system.elf -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b regs --sources
|
||||
|
||||
${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
|
||||
|
||||
define arch-make-targets
|
||||
@ -217,6 +311,20 @@ linux-run-$1: ${BUILD_DIR}/$1/system-linux.elf
|
||||
linux-gdb-$1: ${BUILD_DIR}/$1/system-linux.elf
|
||||
gdb --tui ${BUILD_DIR}/$1/system-linux.elf
|
||||
|
||||
linux-objdump-$1:
|
||||
objdump --disassemble --disassembler-options intel --disassembler-color=off --source ${BUILD_DIR}/$1/system-linux.elf | less
|
||||
|
||||
baremetal-build-$1: ${BUILD_DIR}/$1/system-baremetal.elf
|
||||
|
||||
baremetal-run-$1: ${BUILD_DIR}/$1/system-baremetal.elf
|
||||
${BUILD_DIR}/$1/system-baremetal.elf
|
||||
|
||||
baremetal-gdb-$1: ${BUILD_DIR}/$1/system-baremetal.elf
|
||||
gdb --tui -ex "set substitute-path /wamrlib ${WAMR}" ${BUILD_DIR}/$1/system-baremetal.elf
|
||||
|
||||
baremetal-objdump-$1:
|
||||
objdump --disassemble --disassembler-options intel --disassembler-color=off --source ${BUILD_DIR}/$1/system-baremetal.elf | less
|
||||
|
||||
bochs-run-$1: ${BUILD_DIR}/$1/system.iso
|
||||
bochs -q -f arch/bochs/bochsrc-docker.txt
|
||||
|
||||
|
||||
85
examples/embed/host-baremetal.c
Normal file
85
examples/embed/host-baremetal.c
Normal file
@ -0,0 +1,85 @@
|
||||
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
|
||||
|
||||
#include "lib.c"
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "wasm_export.h"
|
||||
|
||||
#include "__WASM_ARRAY_FILE__"
|
||||
|
||||
#define STACK_SIZE (4 * 1024)
|
||||
#define HEAP_SIZE STACK_SIZE
|
||||
#define RUNTIME_POOL_SIZE (4 * STACK_SIZE)
|
||||
|
||||
// TODO: Set this up so the lsp actually finds the includes...
|
||||
|
||||
// MAIN() {
|
||||
int main(int argc, char *argv[]) {
|
||||
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;
|
||||
|
||||
/* initialize the wasm runtime */
|
||||
static char global_heap_buf[RUNTIME_POOL_SIZE];
|
||||
static RuntimeInitArgs init_args;
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
// init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
init_args.max_thread_num = 1;
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* parse the WASM file from buffer and create a WASM module */
|
||||
module = wasm_runtime_load(__WASM_ARRAY__, __WASM_ARRAY_LEN__, error_buf,
|
||||
sizeof(error_buf));
|
||||
|
||||
if (!module) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 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));
|
||||
|
||||
if (!module_inst) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* 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_t 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 */
|
||||
}
|
||||
// MARKER(stop_trace);
|
||||
//
|
||||
uint32_t result = args[0];
|
||||
|
||||
wasm_runtime_destroy_exec_env(exec_env);
|
||||
wasm_runtime_deinstantiate(module_inst);
|
||||
wasm_runtime_unload(module);
|
||||
wasm_runtime_destroy();
|
||||
|
||||
/* the return value is stored in args[0] */
|
||||
if (result == 100) {
|
||||
// MARKER(ok_marker);
|
||||
return 0;
|
||||
} else {
|
||||
// MARKER(fail_marker);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ MAIN() {
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
|
||||
|
||||
/* arguments are always transferred in 32-bit element */
|
||||
uint32 args[1];
|
||||
uint32_t args[1];
|
||||
|
||||
/* call an arbitrary WASM function */
|
||||
MARKER(start_trace);
|
||||
@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
|
||||
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
|
||||
|
||||
/* arguments are always transferred in 32-bit element */
|
||||
uint32 args[1];
|
||||
uint32_t args[1];
|
||||
|
||||
/* call an arbitrary WASM function */
|
||||
// MARKER(start_trace);
|
||||
|
||||
@ -21,7 +21,7 @@ RUN apt-get update \
|
||||
ARG GCCVERSION=5.4.0
|
||||
ARG BINUTILSVERSION=2.26.1
|
||||
ARG CROSSPREFIX=/opt/crosscompiler
|
||||
ARG CROSSTARGET=i686-elf
|
||||
ARG CROSSTARGET=i386-elf
|
||||
|
||||
# Build Binutils for cross-compilation
|
||||
WORKDIR /
|
||||
@ -162,12 +162,52 @@ RUN git clone https://gitea.vps.chriphost.de/christoph/wamr wamrlib \
|
||||
# && make -j$(nproc)
|
||||
|
||||
# Build WAMR libiwasm (vmcore interpreter runtime - to run wasm modules embedded in a native application)
|
||||
# TODO: Should probably put the cross-compilation definitions in a toolchain file
|
||||
COPY --from=compiler-builder /opt/crosscompiler /opt/crosscompiler
|
||||
WORKDIR /wamrlib
|
||||
RUN mkdir build_libiwasm && cd build_libiwasm \
|
||||
RUN mkdir build_libiwasm_baremetal_release && cd build_libiwasm_baremetal_release \
|
||||
&& cmake \
|
||||
-DCMAKE_SYSTEM_NAME=Generic \
|
||||
-DCMAKE_SYSTEM_PROCESSOR=i386 \
|
||||
-DCMAKE_C_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
|
||||
-DCMAKE_CXX_COMPILER=/opt/crosscompiler/bin/i386-elf-g++ \
|
||||
-DCMAKE_ASM_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
|
||||
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG" \
|
||||
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG" \
|
||||
-DCMAKE_VERBOSE_MAKEFILE=ON \
|
||||
-DWAMR_BUILD_PLATFORM=baremetal \
|
||||
-DWAMR_BUILD_TARGET=X86_32 \
|
||||
-DWAMR_BUILD_AOT=0 \
|
||||
-DWAMR_BUILD_AOT=1 \
|
||||
-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=0 \
|
||||
-DWAMR_BUILD_SIMD=0 \
|
||||
-DCMAKE_COLOR_DIAGNOSTICS=ON \
|
||||
.. \
|
||||
&& make -j$(nproc)
|
||||
|
||||
WORKDIR /wamrlib
|
||||
RUN mkdir build_libiwasm_baremetal_debug && cd build_libiwasm_baremetal_debug \
|
||||
&& cmake \
|
||||
-DCMAKE_SYSTEM_NAME=Generic \
|
||||
-DCMAKE_SYSTEM_PROCESSOR=i386 \
|
||||
-DCMAKE_C_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
|
||||
-DCMAKE_CXX_COMPILER=/opt/crosscompiler/bin/i386-elf-g++ \
|
||||
-DCMAKE_ASM_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \
|
||||
-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_C_FLAGS_DEBUG="-O0 -ggdb" \
|
||||
-DCMAKE_CXX_FLAGS_DEBUG="-O0 -ggdb" \
|
||||
-DCMAKE_VERBOSE_MAKEFILE=ON \
|
||||
-DWAMR_BUILD_PLATFORM=baremetal \
|
||||
-DWAMR_BUILD_TARGET=X86_32 \
|
||||
-DWAMR_BUILD_AOT=1 \
|
||||
-DWAMR_BUILD_WAMR_COMPILER=0 \
|
||||
-DWAMR_BUILD_INTERP=1 \
|
||||
-DWAMR_BUILD_FAST_INTERP=0 \
|
||||
@ -182,8 +222,32 @@ RUN mkdir build_libiwasm && cd build_libiwasm \
|
||||
|
||||
# Build WAMR libiwasm for the host system
|
||||
WORKDIR /wamrlib
|
||||
RUN mkdir build_libiwasm_linux && cd build_libiwasm_linux \
|
||||
RUN mkdir build_libiwasm_linux_release && cd build_libiwasm_linux_release \
|
||||
&& cmake \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_C_FLAGS_RELEASE="-O2 -DNDEBUG" \
|
||||
-DCMAKE_CXX_FLAGS_RELEASE="-O2 -DNDEBUG" \
|
||||
-DWAMR_BUILD_PLATFORM=linux \
|
||||
-DWAMR_BUILD_TARGET=X86_32 \
|
||||
-DWAMR_BUILD_AOT=1 \
|
||||
-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=0 \
|
||||
-DWAMR_BUILD_SIMD=0 \
|
||||
-DCMAKE_COLOR_DIAGNOSTICS=ON \
|
||||
.. \
|
||||
&& make -j$(nproc)
|
||||
|
||||
WORKDIR /wamrlib
|
||||
RUN mkdir build_libiwasm_linux_debug && cd build_libiwasm_linux_debug \
|
||||
&& cmake \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_C_FLAGS_DEBUG="-O0 -ggdb" \
|
||||
-DCMAKE_CXX_FLAGS_DEBUG="-O0 -ggdb" \
|
||||
-DWAMR_BUILD_PLATFORM=linux \
|
||||
-DWAMR_BUILD_TARGET=X86_32 \
|
||||
-DWAMR_BUILD_AOT=1 \
|
||||
@ -231,8 +295,10 @@ COPY --from=wamr-builder /wamr/product-mini/platforms/linux/build_iwasm /opt/wam
|
||||
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/wamr/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \
|
||||
&& ln -sf /opt/wamr/build_libiwasm /opt/wamr-libiwasm \
|
||||
&& ln -sf /opt/wamr/build_libiwasm_linux /opt/wamr-libiwasm-linux
|
||||
&& ln -sf /opt/wamr/build_libiwasm_baremetal_release /opt/wamr-libiwasm-baremetal-release \
|
||||
&& ln -sf /opt/wamr/build_libiwasm_baremetal_debug /opt/wamr-libiwasm-baremetal-debug \
|
||||
&& ln -sf /opt/wamr/build_libiwasm_linux_release /opt/wamr-libiwasm-linux-release \
|
||||
&& ln -sf /opt/wamr/build_libiwasm_linux_debug /opt/wamr-libiwasm-linux-debug
|
||||
|
||||
COPY ./examples /home/ubuntu/examples
|
||||
WORKDIR /home/ubuntu/examples
|
||||
|
||||
Reference in New Issue
Block a user