From b281345e9dd17146ff36a6df0ea46a005a3b5d50 Mon Sep 17 00:00:00 2001 From: Shupei Fan Date: Thu, 29 Aug 2024 13:28:48 +0000 Subject: [PATCH] [nix] fix t1 vcs build --- difftest/offline.nix | 40 ++++++++++++++++++++++++++++++ difftest/vcs.nix | 47 ++++++++++++++++++++++++++++++++++++ ipemu/src/TestBench.scala | 2 ++ nix/t1/default.nix | 4 ++- nix/t1/run-vcs-emulation.nix | 11 +++------ nix/t1/vcs.nix | 4 +-- 6 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 difftest/offline.nix diff --git a/difftest/offline.nix b/difftest/offline.nix new file mode 100644 index 000000000..6cb220d28 --- /dev/null +++ b/difftest/offline.nix @@ -0,0 +1,40 @@ +{ lib +, elaborateConfig +, rustPlatform +, libspike +, libspike_interfaces +}: + +rustPlatform.buildRustPackage { + name = "offline"; + src = with lib.fileset; toSource { + root = ./.; + fileset = unions [ + ./spike_rs + ./offline + ./dpi_common + ./dpi_t1 + ./test_common + ./Cargo.lock + ./Cargo.toml + ]; + }; + + buildFeatures = []; + buildAndTestSubdir = "./offline"; + + env = { + SPIKE_LIB_DIR = "${libspike}/lib"; + SPIKE_INTERFACES_LIB_DIR = "${libspike_interfaces}/lib"; + DESIGN_VLEN = elaborateConfig.parameter.vLen; + DESIGN_DLEN = elaborateConfig.parameter.dLen; + SPIKE_ISA_STRING = + "rv32gc_" + + (builtins.concatStringsSep "_" elaborateConfig.parameter.extensions) + + "_Zvl${toString elaborateConfig.parameter.vLen}b"; + }; + + cargoLock = { + lockFile = ./Cargo.lock; + }; +} diff --git a/difftest/vcs.nix b/difftest/vcs.nix index e69de29bb..2b2f55910 100644 --- a/difftest/vcs.nix +++ b/difftest/vcs.nix @@ -0,0 +1,47 @@ +{ lib +, elaborateConfig +, rustPlatform +, libspike +, libspike_interfaces +, enable-trace ? false +, vcStaticHome +}: + +rustPlatform.buildRustPackage { + name = "vcs-dpi-lib"; + src = with lib.fileset; toSource { + root = ./.; + fileset = unions [ + ./spike_rs + ./offline + ./dpi_common + ./dpi_t1 + ./test_common + ./Cargo.lock + ./Cargo.toml + ]; + }; + + buildFeatures = ["dpi_common/vcs"] ++ lib.optionals enable-trace [ "dpi_common/trace" ]; + buildAndTestSubdir = "./dpi_t1"; + + env = { + VCS_LIB_DIR = "${vcStaticHome}/vcs-mx/linux64/lib"; + SPIKE_LIB_DIR = "${libspike}/lib"; + SPIKE_INTERFACES_LIB_DIR = "${libspike_interfaces}/lib"; + DESIGN_VLEN = elaborateConfig.parameter.vLen; + DESIGN_DLEN = elaborateConfig.parameter.dLen; + SPIKE_ISA_STRING = + "rv32gc_" + + (builtins.concatStringsSep "_" elaborateConfig.parameter.extensions) + + "_Zvl${toString elaborateConfig.parameter.vLen}b"; + }; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + passthru = { + inherit enable-trace; + }; +} diff --git a/ipemu/src/TestBench.scala b/ipemu/src/TestBench.scala index 897931d49..59d3b9ff9 100644 --- a/ipemu/src/TestBench.scala +++ b/ipemu/src/TestBench.scala @@ -40,6 +40,7 @@ class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter]) setInline( s"$desiredName.sv", s"""module $desiredName(output reg clock, output reg reset); + |`ifdef T1_ENABLE_TRACE | export "DPI-C" function dump_wave; | function dump_wave(input string file); |`ifdef VCS @@ -52,6 +53,7 @@ class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter]) | $$dumpvars(0); |`endif | endfunction; + |`endif | | import "DPI-C" context function void t1_cosim_init(); | initial begin diff --git a/nix/t1/default.nix b/nix/t1/default.nix index b6bdead5c..87158d38c 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -126,11 +126,13 @@ lib.makeScope newScope "--strip-debug-info" ]; }; - vcs-dpi-lib = ipSelf.callPackage ../../difftest/online_vcs { }; + vcs-dpi-lib = ipSelf.callPackage ../../difftest/vcs.nix { }; vcs-dpi-lib-trace = ipSelf.vcs-dpi-lib.override { enable-trace = true; }; # FIXME: vcs-emu should have offline check instead of using verilator one vcs-emu = ipSelf.callPackage ./vcs.nix { }; vcs-emu-trace = ipSelf.callPackage ./vcs.nix { vcs-dpi-lib = ipSelf.vcs-dpi-lib-trace; }; + + offline = ipSelf.callPackage ../../difftest/offline.nix { }; }); subsystem = rec { diff --git a/nix/t1/run-vcs-emulation.nix b/nix/t1/run-vcs-emulation.nix index 1575979e8..8a2a340e6 100644 --- a/nix/t1/run-vcs-emulation.nix +++ b/nix/t1/run-vcs-emulation.nix @@ -1,5 +1,4 @@ -# FIXME: we should have offline check for VCS, importing offline check from verilator-emu is weird -{ lib, stdenvNoCC, zstd, jq, verilator-emu }: +{ lib, stdenvNoCC, zstd, jq, offline }: emulator: testCase: @@ -18,10 +17,8 @@ stdenvNoCC.mkDerivation (finalAttr: { mkdir -p "$out" emuDriverArgsArray=( - "--elf-file" - "${testCase}/bin/${testCase.pname}.elf" - ${lib.optionalString emulator.enable-trace "--wave-path"} - ${lib.optionalString emulator.enable-trace "${testCase.pname}.fsdb"} + "+t1_elf_file=${testCase}/bin/${testCase.pname}.elf" + ${lib.optionalString emulator.enable-trace "+t1_wave_path=${testCase.pname}.fsdb"} ) emuDriverArgs="''${emuDriverArgsArray[@]}" emuDriver="${emulator}/bin/t1-vcs-simulator" @@ -71,7 +68,7 @@ stdenvNoCC.mkDerivation (finalAttr: { ) offlineCheckArgs="''${offlineCheckArgsArray[@]}" echo -e "[nix] running offline check: \033[0;34m${emulator}/bin/offline $offlineCheckArgs\033[0m" - "${verilator-emu}/bin/offline" $offlineCheckArgs &> $out/offline-check-journal + "${offline}/bin/offline" $offlineCheckArgs &> $out/offline-check-journal printf "$?" > $out/offline-check-status if [ "$(cat $out/offline-check-status)" != "0" ]; then diff --git a/nix/t1/vcs.nix b/nix/t1/vcs.nix index 11c18f29d..13a692092 100644 --- a/nix/t1/vcs.nix +++ b/nix/t1/vcs.nix @@ -29,12 +29,12 @@ let -sverilog \ -full64 \ -timescale=1ns/1ps \ - -P $VERDI_HOME/share/PLI/VCS/LINUX64/novas.tab $VERDI_HOME/share/PLI/VCS/LINUX64/pli.a \ ${lib.optionalString vcs-dpi-lib.enable-trace '' + +define+T1_ENABLE_TRACE \ -debug_access+pp+dmptf+thread \ -kdb=common_elab,hgldd_all''} \ -file filelist.f \ - ${vcs-dpi-lib}/lib/libdpi.a \ + ${vcs-dpi-lib}/lib/libdpi_t1.a \ -o t1-vcs-simulator runHook postBuild