This commit is contained in:
Mikhail Yenuchenko
2026-01-20 16:23:00 +03:00
commit c8ab0ca4f7
107 changed files with 285173 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
include rv32_tests.inc
ARCH_tmp := imf
ifneq (,$(findstring c,$(ARCH_lowercase)))
ARCH_tmp := $(ARCH_tmp)c
endif
override ARCH := $(ARCH_tmp)
src_dir := $(CURDIR)
obj_dir := $(bld_dir)/riscv_objs
test_list := $(patsubst %.S, %, $(notdir $(rv32_isa_tests)))
objs := $(addprefix $(obj_dir)/,$(test_list:%=%.o))
test_elf := $(addprefix $(bld_dir)/,$(test_list:%=%.elf))
test_hex := $(addprefix $(bld_dir)/,$(test_list:%=%.hex))
test_dump := $(addprefix $(bld_dir)/,$(test_list:%=%.dump))
CFLAGS := -I$(inc_dir) -I$(src_dir) -DASM -Wa,-march=rv32$(ARCH)_zicsr_zifencei -march=rv32$(ARCH)_zicsr_zifencei -mabi=ilp32f -D__riscv_xlen=32
LDFLAGS := -static -fvisibility=hidden -nostdlib -nostartfiles -T$(inc_dir)/link.ld -march=rv32$(ARCH)_zicsr_zifencei -mabi=ilp32f
RISCV_TESTS := $(src_dir)/../../../dependencies/riscv-tests/
VPATH += $(src_dir) $(bld_dir) $(obj_dir) $(RISCV_TESTS)
default: log_requested_tgt check_riscv_tests $(test_elf) $(test_hex) $(test_dump)
define compile_template
$(obj_dir)/$$(basename $(notdir $(SRC))).o: $$(SRC) | $(obj_dir)
$(RISCV_GCC) -c $$< $(CFLAGS) -o $$@
endef
$(foreach SRC,$(rv32_isa_tests), $(eval $(compile_template)))
log_requested_tgt:
$(foreach test_name, $(test_list), $(eval $(shell echo $(test_name).hex >> $(bld_dir)/test_info)))
$(obj_dir) :
mkdir -p $(obj_dir)
$(bld_dir)/%.elf: $(obj_dir)/%.o | $(obj_dir)
$(RISCV_GCC) $^ $(LDFLAGS) -o $@
$(bld_dir)/%.hex: $(bld_dir)/%.elf
$(RISCV_OBJCOPY) $^ $@
$(bld_dir)/%.dump: $(bld_dir)/%.elf
$(RISCV_OBJDUMP) -D -w -x -S $^ > $@
clean:
$(RM) $(test_elf) $(test_hex) $(test_dump) $(objs)
$(RM) -R $(obj_dir)
.PHONY: check_riscv_tests
riscv_tests_dir := $(if $(RISCV_TESTS), $(RISCV_TESTS), ./undefined)
riscv_tests_commit := 5f8a4918c6482e65c67a2b7decd5c2af3e3fe0e5
## commit hash readed from local copy of https://github.com/riscv/riscv-tests
tmp_commit = $(shell cd $(riscv_tests_dir) 2>/dev/null && git log -1 | grep "commit" | cut -f2 -d ' ')
is_commit_good = $(if $(subst $(riscv_tests_commit),,$(tmp_commit)),false,true)
# Color
RED=\033[0;31m
NC=\033[0m
check_riscv_tests : $(riscv_tests_dir)
@if [ ! -d $(riscv_tests_dir) ]; then \
echo -e "$(RED)==========================================================================" &&\
echo " Error! Environment variable RISCV_TESTS='$(riscv_tests_dir)' " &&\
echo " directory not exist!" && \
echo "==========================================================================$(NC)" ; \
fi
ifneq ($(is_commit_good),true)
@echo -e "$(RED)=========================================================================="
@echo " Warning! Execution of test code is not guaranteed "
@echo " while using the current commit of repositorylocated at : $(riscv_tests_dir) ."
@echo " "
@echo " Riscv-tests repository must point to commit $(riscv_tests_commit)!"
@echo -e "==========================================================================$(NC)"
endif
$(riscv_tests_dir) :.
ifndef RISCV_TESTS
@echo -e "$(RED)=========================================================================="
@echo " Error! Environment variable RISCV_TESTS not set!"
@echo " You must set the environment variable RISCV_TESTS"
@echo " The variable should point to the local copy of the"
@echo " repository https://github.com/riscv/riscv-tests"
@echo " with the commit $(riscv_tests_commit)"
@echo -e "==========================================================================$(NC)"
exit 1
endif

View File

@@ -0,0 +1,6 @@
#ifndef __RISCV__TEST__H
#define __RISCV__TEST__H
#include "riscv_macros.h"
#endif // #ifndef __RISCV__TEST__H

View File

@@ -0,0 +1,66 @@
ARCH_lowercase = $(shell echo $(ARCH) | tr A-Z a-z)
rv32_isa_tests += isa/rv32ui/add.S \
isa/rv32ui/addi.S \
isa/rv32ui/and.S \
isa/rv32ui/andi.S \
isa/rv32ui/auipc.S \
isa/rv32ui/beq.S \
isa/rv32ui/bge.S \
isa/rv32ui/bgeu.S \
isa/rv32ui/blt.S \
isa/rv32ui/bltu.S \
isa/rv32ui/bne.S \
isa/rv32mi/csr.S \
isa/rv32ui/fence_i.S \
isa/rv32mi/illegal.S \
isa/rv32ui/jal.S \
isa/rv32ui/jalr.S \
isa/rv32ui/lb.S \
isa/rv32ui/lbu.S \
isa/rv32ui/lh.S \
isa/rv32ui/lhu.S \
isa/rv32ui/lui.S \
isa/rv32ui/lw.S \
isa/rv32mi/ma_addr.S \
isa/rv32mi/ma_fetch.S \
isa/rv32mi/mcsr.S \
isa/rv32ui/or.S \
isa/rv32ui/ori.S \
isa/rv32ui/sb.S \
isa/rv32mi/sbreak.S \
isa/rv32mi/scall.S \
isa/rv32ui/sh.S \
isa/rv32mi/shamt.S \
isa/rv32ui/simple.S \
isa/rv32ui/sll.S \
isa/rv32ui/slli.S \
isa/rv32ui/slt.S \
isa/rv32ui/slti.S \
isa/rv32ui/sltiu.S \
isa/rv32ui/sltu.S \
isa/rv32ui/sra.S \
isa/rv32ui/srai.S \
isa/rv32ui/srl.S \
isa/rv32ui/srli.S \
isa/rv32ui/sub.S \
isa/rv32ui/sw.S \
isa/rv32ui/xor.S \
isa/rv32ui/xori.S
ifneq (,$(findstring m,$(ARCH_lowercase)))
rv32_isa_tests += isa/rv32um/div.S \
isa/rv32um/divu.S \
isa/rv32um/mul.S \
isa/rv32um/mulh.S \
isa/rv32um/mulhsu.S \
isa/rv32um/mulhu.S \
isa/rv32um/rem.S \
isa/rv32um/remu.S
endif ## ifeq (m,$(findstring m,$(ARCH_lowercase)))
ifneq (,$(findstring c,$(ARCH_lowercase)))
rv32_isa_tests += isa/rv32uc/rvc.S
endif ## ifeq (m,$(findstring c,$(ARCH_lowercase)))

View File

@@ -0,0 +1,7 @@
#ifndef __TEST__MACROS__H
#define __TEST__MACROS__H
#define sptbr satp
#define mbadaddr mtval
#endif