330 lines
12 KiB
Makefile
330 lines
12 KiB
Makefile
WASI_ROOT := /opt/wasi-sdk
|
||
WAMR := /opt/wamr
|
||
OPT := -O3
|
||
|
||
################################################################
|
||
# C -> WASM
|
||
|
||
WASI_CC := ${WASI_ROOT}/bin/clang
|
||
WASI_CFLAGS := \
|
||
--target=wasm32 \
|
||
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
|
||
-z stack-size=4096 \
|
||
-O0 \
|
||
-nostdlib \
|
||
-Wl,--no-entry \
|
||
-Wl,--export-all \
|
||
-Wl,--no-gc-sections \
|
||
-Wl,--initial-memory=65536 \
|
||
-Wl,--export=__heap_base \
|
||
-Wl,--export=__data_end
|
||
|
||
${BUILD_DIR}/%/module.wasm: %.c
|
||
mkdir -p $(shell dirname $@)
|
||
${WASI_CC} ${WASI_CFLAGS} $< -o $@
|
||
|
||
################################################################
|
||
# WASM -> Native Object File
|
||
# ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module.wasm
|
||
# ${WAMRC} --target=i386 --format=object -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
|
||
#
|
||
# ${BUILD_DIR}/startup.o: arch/bochs/startup.s
|
||
# ${CC} $< ${CFLAGS} -c -o $@
|
||
#
|
||
# ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
|
||
# ${CC} ${LDFLAGS} -o $@
|
||
|
||
################################################################
|
||
# 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 $< > $@
|
||
|
||
################################################################
|
||
# WASM 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-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-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 $@
|
||
|
||
${BUILD_DIR}/syscalls.o: syscalls.c
|
||
${CC} $< ${CFLAGS} -c -o $@
|
||
|
||
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/syscalls.o ${BUILD_DIR}/startup.o
|
||
${CC} ${LDFLAGS} -o $@
|
||
|
||
################################################################
|
||
# WASM 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 \
|
||
-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-linux.c
|
||
${CC_LINUX} ${CFLAGS_LINUX} ${INCL_LINUX} -c ${BUILD_DIR}/$*/module_host-linux.c -o $@
|
||
|
||
${BUILD_DIR}/%/system-linux.elf: ${BUILD_DIR}/%/system-linux.o
|
||
${CC_LINUX} ${LDFLAGS_LINUX} -o $@
|
||
|
||
################################################################
|
||
# WASM 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
|
||
cp arch/bochs/grub.cfg $(shell dirname $<)/grub/boot/grub
|
||
cp $< $(shell dirname $<)/grub/boot/system.elf
|
||
grub-mkrescue -o $@ $(shell dirname $<)/grub
|
||
|
||
BOCHS_RUNNER_ARGS = \
|
||
-V arch/bochs/vgabios.bin \
|
||
-b arch/bochs/BIOS-bochs-latest \
|
||
|
||
# Don't depend on system.iso so we can run the trace target from the fail docker image that does not have any wamr/wasi stuff
|
||
# ${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
|
||
${BUILD_DIR}/%/trace.pb:
|
||
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
|
||
-f ${FAIL_TRACE} \
|
||
-e ${BUILD_DIR}/$*/system.elf \
|
||
-i ${BUILD_DIR}/$*/system.iso \
|
||
-- \
|
||
-Wf,--start-symbol=start_trace \
|
||
-Wf,--save-symbol=start_trace \
|
||
-Wf,--end-symbol=stop_trace \
|
||
-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} \
|
||
-f ${FAIL_INJECT} \
|
||
-e ${BUILD_DIR}/$(subst client-,,$@)/system.elf \
|
||
-i ${BUILD_DIR}/$(subst client-,,$@)/system.iso \
|
||
-j $(shell getconf _NPROCESSORS_ONLN) \
|
||
-- \
|
||
-Wf,--state-dir=${BUILD_DIR}/$(subst client-,,$@)/state \
|
||
-Wf,--trap \
|
||
-Wf,--timeout=500000 \
|
||
-Wf,--ok-marker=ok_marker \
|
||
-Wf,--fail-marker=fail_marker \
|
||
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} \
|
||
-e ${BUILD_DIR}/$(subst inject-,,$@)/system.elf \
|
||
-i ${BUILD_DIR}/$(subst inject-,,$@)/system.iso \
|
||
-j 1 -- \
|
||
-Wf,--state-dir=${BUILD_DIR}/$(subst inject-,,$@)/state \
|
||
-Wf,--trap \
|
||
-Wf,--timeout=10 \
|
||
-Wf,--ok-marker=ok_marker \
|
||
-Wf,--fail-marker=fail_marker \
|
||
-Wf,--catch-write-textsegment \
|
||
-Wf,--catch-outerspace
|
||
|
||
# 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_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
|
||
|
||
build-$1: ${BUILD_DIR}/$1/system.iso
|
||
|
||
trace-$1: ${BUILD_DIR}/$1/trace.pb
|
||
|
||
objdump-$1:
|
||
objdump --disassemble --disassembler-options intel --disassembler-color=off --source ${BUILD_DIR}/$1/system.elf | less
|
||
|
||
linux-build-$1: ${BUILD_DIR}/$1/system-linux.elf
|
||
|
||
linux-run-$1: ${BUILD_DIR}/$1/system-linux.elf
|
||
${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
|
||
|
||
endef
|