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

View File

@ -7,7 +7,7 @@ all: help
BUILD_DIR := build-${ARCH} BUILD_DIR := build-${ARCH}
FAIL_BIN ?= ${BUILD_DIR}/bin FAIL_BIN ?= ${BUILD_DIR}/bin
FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server FAIL_SERVER ?= ${FAIL_BIN}/generic-experiment-server
FAIL_TRACE ?= ${FAIL_BIN}/fail-generic-tracing -Wf,--full-trace FAIL_TRACE ?= ${FAIL_BIN}/fail-generic-tracing
FAIL_INJECT ?= ${FAIL_BIN}/fail-generic-experiment FAIL_INJECT ?= ${FAIL_BIN}/fail-generic-experiment
FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks FAIL_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks
FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace
@ -54,6 +54,8 @@ clean:
clean-%: clean-%:
rm -rf ${BUILD_DIR}/$(patsubst clean-%,%,$@) rm -rf ${BUILD_DIR}/$(patsubst clean-%,%,$@)
contrib/clean-db '${ARCH}/$(patsubst clean-%,%,$@)'
build-%: build-%:
@echo "****************************************************************\n\ @echo "****************************************************************\n\
@ -87,12 +89,7 @@ ${HOME}/.my.cnf:
@echo "host=db" >> $@ @echo "host=db" >> $@
@echo "port=3306" >> $@ @echo "port=3306" >> $@
import-%: ${BUILD_DIR}/%/trace.pb ${HOME}/.my.cnf import-%: import-arch-%
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-%,%,$@) -b mem -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type ram
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-%,%,$@) -b regs-trace -t $< -e $(shell dirname $<)/system.elf -i mem --memory-type register
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-%,%,$@) -b regs -t $< -e $(shell dirname $<)/system.elf -i regs
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i regs --no-gp --ip
${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-%,%,$@) -b %% --overwrite
@echo "****************************************************************\n\ @echo "****************************************************************\n\
* The golden run sits now within the MySQL database. If you are interested,\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\ * use the 'mysql' command to inspect the curent state of the DB. The tables\n\

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

16
contrib/clean-db Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
variant=$1;
variant_ids=`echo "select id from variant where variant like '"${variant}"';" | mysql -N `
variant_ids=`echo ${variant_ids} | tr " " ","`
echo Delete variants $variant_ids
echo "delete from result_GenericExperimentMessage where pilot_id in (select id from fsppilot where variant_id in (${variant_ids}));" | mysql
echo "delete from fspgroup where variant_id in (${variant_ids});" | mysql
echo "delete from fsppilot where variant_id in (${variant_ids});" | mysql
echo "delete from trace where variant_id in (${variant_ids});" | mysql

View File

@ -0,0 +1,19 @@
set @variant = 'riscv32/main';
SELECT count(*) from trace where variant_id in (SELECT id FROM variant where variant = @variant and benchmark in ("regs-trace"));
SELECT count(*) from trace where variant_id in (SELECT id FROM variant where variant = @variant and benchmark in ("regs", "ip"));
SELECT count(*),
sum(t1.instr1 != t2.instr1) as instr1,
sum(t1.time1 != t2.time1) as time1,
sum(t1.time2 != t2.time2) as time2,
sum(t1.instr1_absolute != t2.instr1_absolute) as instr1_absolute,
sum(t1.instr2_absolute != t2.instr2_absolute) as instr2_absolute,
sum(t1.data_address != t2.data_address) as data_address
FROM trace t1
JOIN trace t2 ON t1.instr2 = t2.instr2 AND t1.data_address = t2.data_address
WHERE
t1.variant_id in (SELECT id FROM variant where variant = @variant and benchmark in ("regs", "ip"))
and
t2.variant_id in (SELECT id FROM variant where variant = @variant and benchmark in ("regs-trace"));
;

17
simple.c Normal file
View File

@ -0,0 +1,17 @@
#include "lib.c"
int array[] = {1, 1, 2, 3, 5, 8, 13, 21};
int sum;
MAIN() {
MARKER(start_trace);
sum = array[0] + array[1];
MARKER(stop_trace);
if ((sum & 0x0f) != 2)
MARKER(fail_marker);
else
MARKER(ok_marker);
}