AVR: Add support for FAIL/SAIL AVR

This commit is contained in:
Christian Dietrich
2021-08-18 15:50:54 +02:00
parent ed94692a08
commit b60865d8c3
8 changed files with 162 additions and 9 deletions

78
arch/avr.mk Normal file
View File

@ -0,0 +1,78 @@
FAIL_DOWNLOAD_URL = ${FAIL_DOWNLOAD_BASE}?job=build-avr-generic-tools
CFLAGS += -mmcu=atmega8
LDFLAGS += -mmcu=atmega8
CC := avr-gcc
################################################################
# Build Targets
${BUILD_DIR}/%/system.o: %.c
mkdir -p $(shell dirname $@)
${CC} ${CFLAGS} -c $< -o $@
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o
${CC} ${LDFLAGS} $< -o $@
${BUILD_DIR}/%/system.bin: ${BUILD_DIR}/%/system.elf
avr-objcopy -Obinary $< $@
${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.bin
${BOCHS_RUNNER} --mode avr -1 \
-f ${FAIL_TRACE} \
-e $(shell dirname $<)/system.elf \
-i $(shell dirname $<)/system.bin \
-- \
-Wf,--full-trace \
-Wf,--state-file=$(shell dirname $<)/state \
-Wf,--trace-file=$(shell dirname $<)/trace.pb \
-Wf,--start-symbol=start_trace \
-Wf,--end-symbol=stop_trace \
-Wf,--check-bounds
client-%:
${BOCHS_RUNNER} --mode avr \
-f ${FAIL_INJECT} \
-e ${BUILD_DIR}/$(subst client-,,$@)/system.elf \
-i ${BUILD_DIR}/$(subst client-,,$@)/system.bin \
-j $(shell getconf _NPROCESSORS_ONLN) \
-- \
-Wf,--state-dir=${BUILD_DIR}/$(subst client-,,$@)/state \
-Wf,--trap \
-Wf,--timeout=1000 \
-Wf,--ok-marker=ok_marker \
-Wf,--fail-marker=fail_marker
2>/dev/null | grep -B 2 -A 8 'INJECT'
inject-%:
${BOCHS_RUNNER} --mode avr -1 \
-f ${FAIL_INJECT} \
-e ${BUILD_DIR}/$(subst inject-,,$@)/system.elf \
-i ${BUILD_DIR}/$(subst inject-,,$@)/system.bin \
-j 1 -- \
-Wf,--state-dir=${BUILD_DIR}/$(subst inject-,,$@)/state \
-Wf,--trap \
-Wf,--timeout=1000 \
-Wf,--ok-marker=ok_marker \
-Wf,--fail-marker=fail_marker
# Unfortunately, the LLVM Disassembler for AVR is crap, Therefore, no regular register injection
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_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
define arch-make-targets
build-$1: ${BUILD_DIR}/$1/system.bin
trace-$1: ${BUILD_DIR}/$1/trace.pb
endef

11
arch/avr/lib.c Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#define ARCH_ASM_CLOBBER_ALL "r0", "r1", "r2"
extern void os_main(void) __attribute__((noinline));
void main() {
os_main();
__asm__ volatile ("sleep");
}

View File

@ -69,6 +69,14 @@ inject-%:
-Wf,--catch-write-textsegment \
-Wf,--catch-outerspace
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
define arch-make-targets
build-$1: ${BUILD_DIR}/$1/system.iso

View File

@ -17,6 +17,7 @@ ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/startup.o ${BUILD_DIR}/%/system.o
${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.elf
${FAIL_TRACE} \
-Wf,--full-trace \
-Wf,--elf-file -Wf,$< \
-Wf,--start-symbol -Wf,start_trace \
-Wf,--end-symbol -Wf,stop_trace \
@ -26,7 +27,7 @@ ${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.elf
-V $<
client-%:
${BOCHS_RUNNER} --mode sail \
${BOCHS_RUNNER} --mode riscv \
-f ${FAIL_INJECT} \
-e ${BUILD_DIR}/$(subst client-,,$@)/system.elf \
-j $(shell getconf _NPROCESSORS_ONLN) \
@ -41,7 +42,7 @@ client-%:
-V 2>/dev/null | grep -B 2 -A 8 'INJECT'
inject-%:
${BOCHS_RUNNER} --mode sail -1 -j 1 \
${BOCHS_RUNNER} --mode riscv -1 -j 1 \
-f ${FAIL_INJECT} \
-e ${BUILD_DIR}/$(subst inject-,,$@)/system.elf \
-- \
@ -54,6 +55,12 @@ inject-%:
-Wf,--catch-outerspace -V
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
define arch-make-targets
build-$1: ${BUILD_DIR}/$1/system.elf