riscv

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 6e5c9723f4a3225c377ed446e55dce0540348a64
parent 47ee1d1bc6ecc2249dc63ee42cac30231fc1b4b7
Author: Brian Swetland <swetland@frotz.net>
Date:   Thu, 21 Apr 2022 18:53:23 -0700

adjust to changes in the riscv compliance test suite

- abandon their build system entirely
- add a Makefile.test to build and run tests
- move updated header and linkscript to target/
- remove old compliance/ directory
- update readme

Diffstat:
M.gitignore | 2+-
AMakefile.test | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 7+++----
Dcompliance/compliance_io.h | 36------------------------------------
Dcompliance/compliance_test.h | 46----------------------------------------------
Dcompliance/makefile.inc | 30------------------------------
Dcompliance/run.sh | 6------
Dcompliance/setup.sh | 12------------
Atarget/link.ld | 18++++++++++++++++++
Atarget/model_test.h | 34++++++++++++++++++++++++++++++++++
10 files changed, 119 insertions(+), 135 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,5 +1,5 @@ out/ bin/ gen/ -rvc/ +tests/ .* diff --git a/Makefile.test b/Makefile.test @@ -0,0 +1,63 @@ + +RVSIM := bin/rvsim +TESTROOT := ../riscv-arch-test +BUILDDIR := tests + +V ?= @ + +RISCV_PREFIX := /work/riscv/toolchains/riscv32-elf-7.3.0-Linux-x86_64/bin/riscv32-elf- +#RISCV_PREFIX := riscv32-unknown-elf- + +RISCV_GCC := $(RISCV_PREFIX)gcc +RISCV_OBJDUMP := $(RISCV_PREFIX)objdump +RISCV_OBJCOPY := $(RISCV_PREFIX)objcopy +RISCV_NM := $(RISCV_PREFIX)nm +RISCV_CFLAGS := -g -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles +RISCV_CFLAGS += -march=rv32i -mabi=ilp32 -DXLEN=32 -Ttarget/link.ld +RISCV_CFLAGS += -I$(TESTROOT)/riscv-test-env -I$(TESTROOT)/riscv-test-env/p -Itarget +all: run-tests + +TESTSUITE := $(TESTROOT)/riscv-test-suite + +TESTGROUP := rv32i_m/I + +TESTSRC := $(sort $(wildcard $(TESTSUITE)/$(TESTGROUP)/src/*.S)) + + +TESTELF := $(patsubst $(TESTSUITE)/$(TESTGROUP)/src/%.S,$(BUILDDIR)/$(TESTGROUP)/%.elf,$(TESTSRC)) + +TESTBIN := $(patsubst %.elf,%.bin,$(TESTELF)) +TESTLST := $(patsubst %.elf,%.lst,$(TESTELF)) +TESTMAP := $(patsubst %.elf,%.map,$(TESTELF)) +TESTLOG := $(patsubst %.elf,%.log,$(TESTELF)) +TESTSIG := $(patsubst %.elf,%.sig,$(TESTELF)) +TESTDIFF := $(patsubst %.elf,%.diff,$(TESTELF)) +TESTPASS := $(patsubst %.elf,%.pass,$(TESTELF)) + +.SECONDARY: $(TESTELF) $(TESTLST) $(TESTMAP) $(TESTBIN) + +.PRECIOUS: $(TESTLOG) $(TESTSIG) $(TESTDIFF) + +$(BUILDDIR)/$(TESTGROUP)/%.elf: $(TESTSUITE)/$(TESTGROUP)/src/%.S + @mkdir -p $(dir $@) + @echo building $@ + $(V)$(RISCV_GCC) $(RISCV_CFLAGS) -o $@ $< + +$(BUILDDIR)/%.map: $(BUILDDIR)/%.elf + $(V)$(RISCV_NM) $< > $@ + +$(BUILDDIR)/%.bin: $(BUILDDIR)/%.elf + $(V)$(RISCV_OBJCOPY) -O binary $< $@ + +$(BUILDDIR)/%.lst: $(BUILDDIR)/%.elf + $(V)$(RISCV_OBJDUMP) -D $< > $@ + +$(BUILDDIR)/%.pass: $(BUILDDIR)/%.bin $(BUILDDIR)/%.map $(BUILDDIR)/%.lst + @echo running $< + $(V)$(RVSIM) $< -dump=$(patsubst %.pass,%.sig,$@) \ + -from=$$(grep begin_signature $(patsubst %.pass,%.map,$@) | awk '{print $$1}') \ + -to=$$(grep end_signature $(patsubst %.pass,%.map,$@) | awk '{print $$1}') \ + 2> $(patsubst %.pass,%.log,$@) 1>&2 + $(V)if diff $(patsubst %.pass,%.sig,$@) $(patsubst $(BUILDDIR)/$(TESTGROUP)/%.pass,$(TESTSUITE)/$(TESTGROUP)/references/%.reference_output,$@) > $(patsubst %.pass,%.diff,$@) ; then echo PASS ; touch $@; else echo FAIL ; exit 1 ; fi + +run-tests: $(TESTPASS) diff --git a/README.md b/README.md @@ -23,10 +23,9 @@ $ ./bin/rvsim out/hello.bin ### running the riscv compliance tests -The scripts in `compliance/` check out, build, and run riscv compliance suite from github. +Check out https://github.com/riscv-non-isa/riscv-arch-test adjacent to this directory. ``` -$ cd compliance -$ ./setup.sh -$ ./run.sh +make -f Makefile.test ``` + diff --git a/compliance/compliance_io.h b/compliance/compliance_io.h @@ -1,36 +0,0 @@ -// RISC-V Compliance IO Test Header File - -/* - * Copyright (c) 2005-2018 Imperas Software Ltd., www.imperas.com - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, - * either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _COMPLIANCE_IO_H -#define _COMPLIANCE_IO_H - -//----------------------------------------------------------------------- -// RV IO Macros (Non functional) -//----------------------------------------------------------------------- - -#define RVTEST_IO_INIT -#define RVTEST_IO_WRITE_STR(_SP, _STR) -#define RVTEST_IO_CHECK() -#define RVTEST_IO_ASSERT_GPR_EQ(_SP, _R, _I) -#define RVTEST_IO_ASSERT_SFPR_EQ(_F, _R, _I) -#define RVTEST_IO_ASSERT_DFPR_EQ(_D, _R, _I) - -#endif // _COMPLIANCE_IO_H diff --git a/compliance/compliance_test.h b/compliance/compliance_test.h @@ -1,46 +0,0 @@ -// RISC-V Compliance Test Header File -// Copyright (c) 2017, Codasip Ltd. All Rights Reserved. -// See LICENSE for license details. -// -// Description: Common header file for RV32I tests - -#ifndef _COMPLIANCE_TEST_H -#define _COMPLIANCE_TEST_H - -#include "riscv_test.h" - -//----------------------------------------------------------------------- -// RV Compliance Macros -//----------------------------------------------------------------------- - -#define RV_COMPLIANCE_RV32M \ - RVTEST_RV32M \ - -#if 0 -#define RV_COMPLIANCE_HALT \ - RVTEST_PASS \ - -#define RV_COMPLIANCE_CODE_BEGIN \ - RVTEST_CODE_BEGIN \ - -#else -#define RV_COMPLIANCE_HALT .long 0x0000000b; -#define RV_COMPLIANCE_CODE_BEGIN \ -.section .text.init; \ -.align 6; \ -.globl _start; \ -_start: \ -begin_testcode: \ - -#endif - -#define RV_COMPLIANCE_CODE_END \ - RVTEST_CODE_END \ - -#define RV_COMPLIANCE_DATA_BEGIN \ - RVTEST_DATA_BEGIN \ - -#define RV_COMPLIANCE_DATA_END \ - RVTEST_DATA_END \ - -#endif diff --git a/compliance/makefile.inc b/compliance/makefile.inc @@ -1,30 +0,0 @@ -TARGET_SIM ?= /work/riscv/riscv/bin/rvsim -ifeq ($(shell command -v $(TARGET_SIM) 2> /dev/null),) - $(error Target simulator executable '$(TARGET_SIM)` not found) -endif - -RUN_TARGET=\ - $(TARGET_SIM) \ - $(work_dir_isa)/$<.bin \ - -dump=$(work_dir_isa)/$(*).signature.output \ - -from=$$(grep begin_signature $(work_dir_isa)/$<.map | awk '{print $$1}') \ - -to=$$(grep end_signature $(work_dir_isa)/$<.map | awk '{print $$1}') \ - 2> $(work_dir_isa)/$@ 1>&2 - -RISCV_PREFIX ?= riscv32-unknown-elf- -RISCV_GCC ?= $(RISCV_PREFIX)gcc -RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump -RISCV_OBJCOPY ?= $(RISCV_PREFIX)objcopy -RISCV_NM ?= $(RISCV_PREFIX)nm -RISCV_GCC_OPTS ?= -static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles - -COMPILE_TARGET=\ - $$(RISCV_GCC) $(2) $$(RISCV_GCC_OPTS) \ - -I$(ROOTDIR)/riscv-test-env/ \ - -I$(ROOTDIR)/riscv-test-env/p/ \ - -I$(TARGETDIR)/$(RISCV_TARGET)/ \ - -T$(ROOTDIR)/riscv-test-env/p/link.ld $$< \ - -o $(work_dir_isa)/$$@; \ - $$(RISCV_OBJDUMP) -D $(work_dir_isa)/$$@ > $(work_dir_isa)/$$@.objdump; \ - $$(RISCV_OBJCOPY) -O binary $(work_dir_isa)/$$@ $(work_dir_isa)/$$@.bin; \ - $$(RISCV_NM) $(work_dir_isa)/$$@ > $(work_dir_isa)/$$@.map diff --git a/compliance/run.sh b/compliance/run.sh @@ -1,6 +0,0 @@ -#!/bin/sh - -export RVSIM=`pwd`/../bin/rvsim -export TOOLCHAIN=`pwd`/../../toolchains/riscv32-elf-7.3.0-Linux-x86_64/bin/riscv32-elf- - -make -C rvc RISCV_TARGET=rvsim RISCV_PREFIX=${TOOLCHAIN} TARGET_SIM=${RVSIM} diff --git a/compliance/setup.sh b/compliance/setup.sh @@ -1,12 +0,0 @@ -#!/bin/sh -e - -git clone git@github.com:riscv/riscv-compliance.git rvc - -mkdir -p rvc/riscv-target/rvsim/device/rv32i -mkdir -p rvc/riscv-target/rvsim/device/rv32im - -ln -s ../../../compliance_io.h rvc/riscv-target/rvsim/compliance_io.h -ln -s ../../../compliance_test.h rvc/riscv-target/rvsim/compliance_test.h -ln -s ../../../../../makefile.inc rvc/riscv-target/rvsim/device/rv32i/Makefile.include -ln -s ../../../../../makefile.inc rvc/riscv-target/rvsim/device/rv32im/Makefile.include - diff --git a/target/link.ld b/target/link.ld @@ -0,0 +1,18 @@ +OUTPUT_ARCH( "riscv" ) +ENTRY(rvtest_entry_point) + +SECTIONS +{ + . = 0x80000000; + .text.init : { *(.text.init) } + . = ALIGN(0x1000); + .tohost : { *(.tohost) } + . = ALIGN(0x1000); + .text : { *(.text) } + . = ALIGN(0x1000); + .data : { *(.data) } + .data.string : { *(.data.string)} + .bss : { *(.bss) } + _end = .; +} + diff --git a/target/model_test.h b/target/model_test.h @@ -0,0 +1,34 @@ +#ifndef _MODEL_TEST_H +#define _MODEL_TEST_H + +// #include "riscv_test.h" + +#define RVMODEL_RV32M + +#define RVMODEL_BOOT .globl _start; _start: + +#define RVMODEL_DATA_BEGIN \ + .align 4; .globl begin_signature; begin_signature: +#define RVMODEL_DATA_END \ + .align 4; .globl end_signature; end_signature: + +#define RVMODEL_HALT .long 0x0000000b; +#define RVMODEL_CODE_BEGIN +#define RVMODEL_CODE_END +// .globl _start; \ +//_start: \ +//begin_testcode: \ + +#define RVMODEL_IO_INIT +#define RVMODEL_IO_WRITE_STR(_SP, _STR) +#define RVMODEL_IO_CHECK() +#define RVMODEL_IO_ASSERT_GPR_EQ(_SP, _R, _I) +#define RVMODEL_IO_ASSERT_SFPR_EQ(_F, _R, _I) +#define RVMODEL_IO_ASSERT_DFPR_EQ(_D, _R, _I) + +#define RVMODEL_SET_MSW_INT +#define RVMODEL_CLEAR_MSW_INT +#define RVMODEL_CLEAR_MTIMER_INT +#define RVMODEL_CLEAR_MEXT_INT + +#endif