From 512f1e6359a9009a142fb9e97019002ed19ad814 Mon Sep 17 00:00:00 2001 From: Jerry Zhao Date: Wed, 21 Feb 2024 18:57:41 -0800 Subject: [PATCH] Support cosim-mode tests --- Makefile | 11 ++++++++++- macros/general/test_macros.h | 9 ++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f54342a..f615010 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ OUTPUT_STAGE2_PATCH = $(OUTPUT)/patches/stage2/ OUTPUT_STAGE1_BIN = $(OUTPUT)/bin/stage1/ OUTPUT_STAGE2_BIN = $(OUTPUT)/bin/stage2/ CONFIGS = configs/ +TEST_MODE = self SPIKE = spike PATCHER_SPIKE = build/pspike @@ -27,6 +28,14 @@ RISCV_PREFIX = riscv64-unknown-elf- RISCV_GCC = $(RISCV_PREFIX)gcc RISCV_GCC_OPTS = -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -DENTROPY=0xdeadbeef -DLFSR_BITS=9 -fno-tree-loop-distribute-patterns +ifeq ($(TEST_MODE), self) +STAGE2_GCC_OPTS = +else ifeq ($(TEST_MODE), cosim) +STAGE2_GCC_OPTS = -DCOSIM_TEST_CASE +else +$(error "Only self and cosim are supported for TEST_MODE") +endif + PK = ifeq ($(MODE),machine) @@ -94,7 +103,7 @@ compile-stage2: generate-stage2 tests_stage2 = $(addsuffix .stage2, $(tests)) $(tests_stage2): - $(RISCV_GCC) -march=${MARCH} -mabi=${MABI} $(RISCV_GCC_OPTS) -I$(ENV) -Imacros/general -T$(ENV)/link.ld $(ENV_CSRCS) ${OUTPUT_STAGE2}$(shell basename $@ .stage2).S -o ${OUTPUT_STAGE2_BIN}$(shell basename $@ .stage2) + $(RISCV_GCC) -march=${MARCH} -mabi=${MABI} $(RISCV_GCC_OPTS) $(STAGE2_GCC_OPTS) -I$(ENV) -Imacros/general -T$(ENV)/link.ld $(ENV_CSRCS) ${OUTPUT_STAGE2}$(shell basename $@ .stage2).S -o ${OUTPUT_STAGE2_BIN}$(shell basename $@ .stage2) ${SPIKE} --isa=${MARCH} --varch=vlen:${VLEN},elen:${XLEN} $(PK) ${OUTPUT_STAGE2_BIN}$(shell basename $@ .stage2) diff --git a/macros/general/test_macros.h b/macros/general/test_macros.h index 3a5e548..1b34fea 100644 --- a/macros/general/test_macros.h +++ b/macros/general/test_macros.h @@ -17,9 +17,15 @@ #define load lw #endif +#ifdef COSIM_TEST_CASE +// With cosim, only need to load the value to check that it is correct +#define TEST_CASE( testnum, testreg, correctval, code... ) \ + li TESTNUM, testnum; \ + code; +#else // Ugly, this currently inlines the correctval in with the code, // but this avoids many SLLI/ADDI to generate it from an immediate -#define TEST_CASE( testnum, testreg, correctval, code... ) \ +#define TEST_CASE( testnum, testreg, correctval, code... ) \ test_ ## testnum: \ li TESTNUM, testnum; \ code; \ @@ -32,6 +38,7 @@ test_ ## testnum: \ test_ ## testnum ## _data: \ .quad MASK_XLEN(correctval); \ test_ ## testnum ## _success: +#endif # We use a macro hack to simpify code generation for various numbers # of bubble cycles.