From b60865d8c333224257d60b06df31802b09abba8c Mon Sep 17 00:00:00 2001 From: Christian Dietrich Date: Wed, 18 Aug 2021 15:50:54 +0200 Subject: [PATCH] AVR: Add support for FAIL/SAIL AVR --- Makefile | 11 ++--- arch/avr.mk | 78 +++++++++++++++++++++++++++++++ arch/avr/lib.c | 11 +++++ arch/bochs.mk | 8 ++++ arch/riscv-common.mk | 11 ++++- contrib/clean-db | 16 +++++++ contrib/sail-regs-sanitycheck.sql | 19 ++++++++ simple.c | 17 +++++++ 8 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 arch/avr.mk create mode 100644 arch/avr/lib.c create mode 100755 contrib/clean-db create mode 100644 contrib/sail-regs-sanitycheck.sql create mode 100644 simple.c diff --git a/Makefile b/Makefile index da9b45a..4821c34 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ all: help BUILD_DIR := build-${ARCH} FAIL_BIN ?= ${BUILD_DIR}/bin 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_IMPORT ?= ${FAIL_BIN}/import-trace --enable-sanitychecks FAIL_PRUNE ?= ${FAIL_BIN}/prune-trace @@ -54,6 +54,8 @@ clean: clean-%: rm -rf ${BUILD_DIR}/$(patsubst clean-%,%,$@) + contrib/clean-db '${ARCH}/$(patsubst clean-%,%,$@)' + build-%: @echo "****************************************************************\n\ @@ -87,12 +89,7 @@ ${HOME}/.my.cnf: @echo "host=db" >> $@ @echo "port=3306" >> $@ -import-%: ${BUILD_DIR}/%/trace.pb ${HOME}/.my.cnf - ${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 +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\ diff --git a/arch/avr.mk b/arch/avr.mk new file mode 100644 index 0000000..f145d5b --- /dev/null +++ b/arch/avr.mk @@ -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 + + + diff --git a/arch/avr/lib.c b/arch/avr/lib.c new file mode 100644 index 0000000..78a77de --- /dev/null +++ b/arch/avr/lib.c @@ -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"); +} + diff --git a/arch/bochs.mk b/arch/bochs.mk index fa361a5..ec1711d 100644 --- a/arch/bochs.mk +++ b/arch/bochs.mk @@ -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 diff --git a/arch/riscv-common.mk b/arch/riscv-common.mk index 830f3ae..dd99cc6 100644 --- a/arch/riscv-common.mk +++ b/arch/riscv-common.mk @@ -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 diff --git a/contrib/clean-db b/contrib/clean-db new file mode 100755 index 0000000..46efdcb --- /dev/null +++ b/contrib/clean-db @@ -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 + + + diff --git a/contrib/sail-regs-sanitycheck.sql b/contrib/sail-regs-sanitycheck.sql new file mode 100644 index 0000000..9d29446 --- /dev/null +++ b/contrib/sail-regs-sanitycheck.sql @@ -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")); + ; + diff --git a/simple.c b/simple.c new file mode 100644 index 0000000..4c0bc73 --- /dev/null +++ b/simple.c @@ -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); +} +