From f640c1604dd096651fa96e76c5a1d3412c71c4eb Mon Sep 17 00:00:00 2001 From: Jiuyang Liu Date: Sun, 21 Jul 2024 15:39:22 +0800 Subject: [PATCH] [difftest] draft vcs linking Failed to link due to snps doesn't implement the IEEE 1800-2023: = note: /nix/store/2p1sq1nr09xr3xb1a9lrjgdanvk1aakb-binutils-2.42/bin/ld: warning: type of symbol `cosim_init' changed from 1 to 2 in /home/sequencer/t1/difftest/target/debug/deps/libonline_dpi-e08daffbb814a8db.rlib(online_dpi-e08daffbb814a8db.4twjnztmhnh46d6z.rcgu.o) /nix/store/2p1sq1nr09xr3xb1a9lrjgdanvk1aakb-binutils-2.42/bin/ld: /home/sequencer/t1/difftest/target/debug/deps/libonline_dpi-e08daffbb814a8db.rlib(online_dpi-e08daffbb814a8db.3wnd5deuga8hai4e.rcgu.o): in function `online_dpi::svdpi::get_time': /home/sequencer/t1/difftest/online_dpi/src/svdpi.rs:9:(.text._ZN10online_dpi5svdpi8get_time17hc271602d89503b28E+0x56): undefined reference to `svGetTime' collect2: error: ld returned 1 exit status = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified = note: use the `-l` flag to specify native libraries to link = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib) cosim_init is conflict with SNPS symbol, we need to change ours Reproduce via: - nix develop --impure .#t1.blastoise.ip.vcs-emu - cd difftest/ - cargo run --bin online_vcs -- --elf-file $(nix build --no-link --print-out-paths .#t1.blastoise.cases.intrinsic.softmax)/bin/* --timeout 10000 --log-level trace --- difftest/online_vcs/build.rs | 10 +++++ difftest/online_vcs/src/main.rs | 15 +++++++- difftest/vcs-emu.nix | 68 +++++++++++++++++++++++++++++++++ ipemu/src/TestBench.scala | 5 --- nix/t1/default.nix | 4 +- 5 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 difftest/vcs-emu.nix 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 {