diff --git a/difftest/online_vcs/build.rs b/difftest/online_vcs/build.rs index 8613e22876..6d6e4292aa 100644 --- a/difftest/online_vcs/build.rs +++ b/difftest/online_vcs/build.rs @@ -1,3 +1,13 @@ +use std::path::Path; +use std::env; + fn main() { + let vcs_lib_dir = env::var("VCS_LIB_DIR").unwrap(); + println!("cargo:rustc-link-search=native={}", Path::new(&vcs_lib_dir).display()); + let vcs_compiled_lib_dir = env::var("VCS_COMPILED_LIB_DIR").unwrap(); + println!("cargo:rustc-link-search=native={}", Path::new(&vcs_compiled_lib_dir).display()); println!("cargo::rustc-link-lib=TestBench"); + println!("cargo::rustc-link-lib=vcsnew64"); + println!("cargo::rustc-link-lib=vcs_tls"); + println!("cargo::rustc-link-lib=vfs"); } diff --git a/difftest/online_vcs/src/main.rs b/difftest/online_vcs/src/main.rs index 71c35e105a..8f1ba1c9e3 100644 --- a/difftest/online_vcs/src/main.rs +++ b/difftest/online_vcs/src/main.rs @@ -2,7 +2,7 @@ extern crate online_dpi; use std::{ - ffi::{c_char, c_int, CString}, + ffi::{c_char, c_int, c_void, CString}, ptr, }; @@ -15,5 +15,16 @@ fn main() { let argc = c_args.len() as c_int; let argv = c_args_ptr.as_ptr() as *mut *mut c_char; - // TODO + unsafe { + vcs_main(argc, argv); + VcsInit(); + VcsSimUntilInterrupt(); + } } + +extern "C" { + fn vcs_main(argc: c_int, argv: *mut *mut c_char) -> c_int; + fn VcsInit() -> c_void; + fn VcsSimUntilInterrupt() -> c_void; +} + diff --git a/difftest/vcs-emu.nix b/difftest/vcs-emu.nix new file mode 100644 index 0000000000..5a8dda4064 --- /dev/null +++ b/difftest/vcs-emu.nix @@ -0,0 +1,68 @@ +{ lib +, callPackage +, elaborateConfig + +, rustPlatform + +, rust-analyzer +, rust-bindgen + +, vcStaticInstallPath +, vcs-lib + +, cmake +, clang-tools +}: + +let + spike_interfaces = callPackage ./spike_interfaces { }; + + self = rustPlatform.buildRustPackage { + name = "t1-vcs-emu"; + src = with lib.fileset; toSource { + root = ./.; + fileset = unions [ + ./spike_rs + ./offline + ./online_dpi + ./online_drive + ./online_vcs + ./test_common + ./Cargo.lock + ./Cargo.toml + ]; + }; + + buildInputs = [ + spike_interfaces + vcs-lib + ]; + + buildFeatures = lib.optionals vcs-lib.enable-trace [ "trace" ]; + + env = { + VCS_LIB_DIR = "${vcStaticInstallPath}/vcs-mx/linux64/lib"; + VCS_COMPILED_LIB_DIR = "${vcs-lib}/lib"; + DESIGN_VLEN = elaborateConfig.parameter.vLen; + DESIGN_DLEN = elaborateConfig.parameter.dLen; + }; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + dontUseCmakeConfigure = true; + + passthru = { + devShell = self.overrideAttrs (old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ + rust-analyzer + rust-bindgen + clang-tools + ]; + }); + inherit spike_interfaces; + }; + }; +in +self diff --git a/ipemu/src/TestBench.scala b/ipemu/src/TestBench.scala index bd019a81e8..9297ada4f4 100644 --- a/ipemu/src/TestBench.scala +++ b/ipemu/src/TestBench.scala @@ -37,11 +37,6 @@ class TestBench(generator: SerializableModuleGenerator[T1, T1Parameter]) extends | export "DPI-C" function dump_wave; | function dump_wave(input string file); |`ifdef VCS - | $$fsdbDumpfile(file); - | $$fsdbDumpvars("+all"); - | $$fsdbDumpSVA(); - | $$fsdbDumpvars(0); - | $$fsdbDumpon; |`endif |`ifdef VERILATOR | $$dumpfile(file); diff --git a/nix/t1/default.nix b/nix/t1/default.nix index 309c37ab5b..e67333b59c 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -117,8 +117,8 @@ lib.makeScope newScope }; vcs-emu-compiled = innerSelf.callPackage ./vcs.nix { rtl = vcs-emu-rtl; }; vcs-emu-compiled-trace = innerSelf.callPackage ./vcs.nix { rtl = vcs-emu-rtl; enable-trace = true; }; - vcs-emu = innerSelf.callPackage ../../difftest/default.nix { verilated = vcs-emu-compiled; }; - vcs-emu-trace = innerSelf.callPackage ../../difftest/default.nix { verilated = vcs-emu-compiled-trace; }; + vcs-emu = innerSelf.callPackage ../../difftest/vcs-emu.nix { vcs-lib = vcs-emu-compiled; vcStaticInstallPath = builtins.getEnv "VC_STATIC_HOME"; }; + vcs-emu-trace = innerSelf.callPackage ../../difftest/vcs-emu.nix { vcs-lib = vcs-emu-compiled-trace; vcStaticInstallPath = builtins.getEnv "VC_STATIC_HOME"; }; }; subsystem = rec {