Skip to content

Commit

Permalink
[nix] fix t1 vcs build
Browse files Browse the repository at this point in the history
  • Loading branch information
FanShupei authored and sequencer committed Aug 29, 2024
1 parent 0f83a3a commit b281345
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 10 deletions.
40 changes: 40 additions & 0 deletions difftest/offline.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
47 changes: 47 additions & 0 deletions difftest/vcs.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
2 changes: 2 additions & 0 deletions ipemu/src/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 4 additions & 7 deletions nix/t1/run-vcs-emulation.nix
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nix/t1/vcs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b281345

Please sign in to comment.