Skip to content

Commit

Permalink
[nix] vcs-emu: support load DPI at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
FanShupei committed Dec 6, 2024
1 parent ed6238e commit 1fe975d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
3 changes: 3 additions & 0 deletions difftest/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ rustPlatform.buildRustPackage {
'';

passthru = {
# include "lib" prefix, without ".so" suffix, for "-sv_lib" option
svLibName = "lib${moduleType}";

dpiLibPath = "/lib/libdpi_${moduleType}.a";
};
}
2 changes: 1 addition & 1 deletion difftest/dpi_t1emu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["staticlib"]
crate-type = ["staticlib", "cdylib"]

[dependencies]
dpi_common = { path = "../dpi_common" }
Expand Down
2 changes: 1 addition & 1 deletion difftest/dpi_t1rocketemu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["staticlib"]
crate-type = ["staticlib", "cdylib"]

[dependencies]
dpi_common = { path = "../dpi_common" }
Expand Down
4 changes: 3 additions & 1 deletion nix/t1/conversion/sv-to-vcs-simulator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

assert lib.assertMsg (builtins.typeOf vsrc == "list") "vsrc should be a list of file path";
assert lib.assertMsg (builtins.typeOf vcsLinkLibs == "list") "vcsLinkLibs should be list of strings";
assert lib.assertMsg (builtins.length vcsLinkLibs > 0) "vcsLinkLibs should contain at least one static library path to link";

stdenv.mkDerivation rec {
name = mainProgram;
Expand Down Expand Up @@ -74,6 +73,9 @@ stdenv.mkDerivation rec {

passthru = {
inherit snps-fhs-env enableTrace enableCover;

# DPI library should be loaded at runtime through "-sv_lib"
isRuntimeLoad = (builtins.length vcsLinkLibs == 0);
};

shellHook = ''
Expand Down
11 changes: 9 additions & 2 deletions nix/t1/run/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
, verilator-emu
, verilator-emu-trace
, vcs-emu
, vcs-emu-rtlink
, vcs-emu-cover
, vcs-emu-trace
, vcs-dpi-lib
, cases
, configName
, topName
}:
let
runVerilatorEmu = callPackage ./run-verilator-emu.nix { };
runVCSEmu = callPackage ./run-vcs-emu.nix { };
runVCSEmu_ = callPackage ./run-vcs-emu.nix { };
runFsdb2vcd = callPackage ./run-fsdb2vcd.nix { };
runVCSEmu = emulator: runVCSEmu_ { inherit emulator; };
runVCSEmuRT = emulator: runVCSEmu_ {
inherit emulator;
dpilib = vcs-dpi-lib;
};

# cases is now { mlir = { hello = ...; ... }; ... }
emuAttrs = lib.pipe cases [
Expand All @@ -32,7 +39,7 @@ let
innerMapper = caseName: case: {
verilator-emu = runVerilatorEmu verilator-emu case;
verilator-emu-trace = runVerilatorEmu verilator-emu-trace case;
vcs-emu = runVCSEmu vcs-emu case;
vcs-emu = runVCSEmuRT vcs-emu-rtlink case;
vcs-emu-cover = runVCSEmu vcs-emu-cover case;
vcs-emu-trace = runVCSEmu vcs-emu-trace case;
vcs-prof-vcd = runFsdb2vcd (runVCSEmu vcs-emu-trace case);
Expand Down
9 changes: 8 additions & 1 deletion nix/t1/run/run-vcs-emu.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{ lib, stdenvNoCC, zstd, jq, offline-checker }:
emulator:

{ emulator
, dpilib ? null
}:

testCase:

assert lib.assertMsg (!emulator.isRuntimeLoad || (dpilib != null)) "dpilib must be set for rtlink emu";

stdenvNoCC.mkDerivation (finalAttr: {
name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enableTrace "-trace");
nativeBuildInputs = [ zstd jq ];
Expand All @@ -13,6 +19,7 @@ stdenvNoCC.mkDerivation (finalAttr: {
mkdir -p "$out"
emuDriverArgsArray=(
${lib.optionalString emulator.isRuntimeLoad "-sv_root ${dpilib}/lib -sv_lib ${dpilib.svLibName}"}
"-exitstatus"
"+t1_elf_file=${testCase}/bin/${testCase.pname}.elf"
${lib.optionalString emulator.enableTrace "+t1_wave_path=${testCase.pname}.fsdb"}
Expand Down
4 changes: 4 additions & 0 deletions nix/t1/t1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ forEachTop (topName: generator: self: {
vsrc = lib.filesystem.listFilesRecursive self.clean-vsrc.outPath;
vcsLinkLibs = [ "${self.vcs-dpi-lib}/lib/libdpi_${topName}.a" ];
};
vcs-emu-rtlink = self.vcs-emu.override {
vcsLinkLibs = [ ];
mainProgram = "${topName}-vcs-simulator-rtlink";
};
vcs-emu-cover = self.vcs-emu.override {
enableCover = true;
mainProgram = "${topName}-vcs-cover-simulator";
Expand Down

0 comments on commit 1fe975d

Please sign in to comment.