Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nix] bump spike to 2024-07-25 HEAD #689

Merged
merged 5 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions difftest/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{ lib
, enableDebugging
, libspike
, libspike_interfaces
, callPackage
, elaborateConfig

Expand All @@ -15,8 +17,6 @@
}:

let
spike_interfaces = callPackage ./spike_interfaces { };

self = rustPlatform.buildRustPackage {
name = "difftest";
src = with lib.fileset; toSource {
Expand All @@ -32,7 +32,7 @@ let
};

buildInputs = [
spike_interfaces
libspike_interfaces
verilated
];

Expand All @@ -47,7 +47,11 @@ let
VERILATED_INC_DIR = "${verilated}/include";
VERILATED_LIB_DIR = "${verilated}/lib";
SPIKE_LIB_DIR = "${libspike}/lib";
SPIKE_INTERFACES_LIB_DIR = "${spike_interfaces}/lib";
SPIKE_INTERFACES_LIB_DIR = "${libspike_interfaces}/lib";
SPIKE_ISA_STRING =
"rv32gc" +
(builtins.concatStringsSep "_" elaborateConfig.parameter.extensions)
+ "_Zvl${toString elaborateConfig.parameter.vLen}b";
DESIGN_VLEN = elaborateConfig.parameter.vLen;
DESIGN_DLEN = elaborateConfig.parameter.dLen;
};
Expand All @@ -66,7 +70,17 @@ let
clang-tools
];
});
inherit spike_interfaces;
inherit libspike_interfaces;

# enable debug info for difftest itself and libspike
withDebug = self.overrideAttrs (old: {
cargoBuildType = "debug";
doCheck = false;
env = old.env // {
SPIKE_LIB_DIR = "${enableDebugging libspike}/lib";
};
dontStrip = true;
});
};
};
in
Expand Down
11 changes: 5 additions & 6 deletions difftest/spike_interfaces/spike_interfaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ constexpr uint32_t CSR_MSIMEND = 0x7cc;

void *ffi_target;

cfg_t make_spike_cfg(const std::string &varch) {
cfg_t make_spike_cfg() {
cfg_t cfg;
cfg.initrd_bounds = std::make_pair((reg_t)0, (reg_t)0),
cfg.bootargs = nullptr;
cfg.isa = DEFAULT_ISA;
cfg.priv = DEFAULT_PRIV;
cfg.varch = varch.data();
cfg.misaligned = false;
cfg.endianness = endianness_little;
cfg.pmpregions = 16;
Expand All @@ -25,9 +24,9 @@ cfg_t make_spike_cfg(const std::string &varch) {
return cfg;
}

Spike::Spike(const char *arch, const char *set, const char *lvl,
Spike::Spike(const char *set, const char *lvl,
size_t lane_number)
: sim(), varch(arch), isa(set, lvl), cfg(make_spike_cfg(varch)),
: sim(), isa(set, lvl), cfg(make_spike_cfg()),
proc(
/*isa*/ &isa,
/*cfg*/ &cfg,
Expand All @@ -44,9 +43,9 @@ Spike::Spike(const char *arch, const char *set, const char *lvl,
proc.enable_log_commits();
}

spike_t *spike_new(const char *arch, const char *set, const char *lvl,
spike_t *spike_new(const char *set, const char *lvl,
size_t lane_number) {
return new spike_t{new Spike(arch, set, lvl, lane_number)};
return new spike_t{new Spike(set, lvl, lane_number)};
}

const char *proc_disassemble(spike_processor_t *proc) {
Expand Down
3 changes: 1 addition & 2 deletions difftest/spike_interfaces/spike_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ class sim_t : public simif_t {

class Spike {
public:
Spike(const char *arch, const char *set, const char *lvl, size_t lane_number);
Spike(const char *set, const char *lvl, size_t lane_number);
processor_t *get_proc() { return &proc; }

private:
std::string varch;
cfg_t cfg;
sim_t sim;
isa_parser_t isa;
Expand Down
2 changes: 1 addition & 1 deletion difftest/spike_interfaces/spike_interfaces_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef struct spike_processor_t spike_processor_t;
typedef struct spike_state_t spike_state_t;

void spike_register_callback(void *ffi_target, ffi_callback callback);
spike_t *spike_new(const char *arch, const char *set, const char *lvl,
spike_t *spike_new(const char *set, const char *lvl,
size_t lane_number);
const char *proc_disassemble(spike_processor_t *proc);
void proc_reset(spike_processor_t *proc);
Expand Down
6 changes: 2 additions & 4 deletions difftest/spike_rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ type FfiCallback = extern "C" fn(*mut (), u64) -> *mut u8;

impl Spike {
// we need to have a boxed SpikeCObject, since its pointer will be passed to C to perform FFI call
pub fn new(arch: &str, set: &str, lvl: &str, lane_number: usize, mem_size: usize) -> Box<Self> {
let arch = CString::new(arch).unwrap();
pub fn new(set: &str, lvl: &str, lane_number: usize, mem_size: usize) -> Box<Self> {
let set = CString::new(set).unwrap();
let lvl = CString::new(lvl).unwrap();
let spike = unsafe { spike_new(arch.as_ptr(), set.as_ptr(), lvl.as_ptr(), lane_number) };
let spike = unsafe { spike_new(set.as_ptr(), lvl.as_ptr(), lane_number) };
let mut self_: Box<Spike> = Box::new(Spike { spike, mem: vec![0; mem_size], size: mem_size });

// TODO: support customized ffi
Expand Down Expand Up @@ -243,7 +242,6 @@ impl Drop for State {
extern "C" {
pub fn spike_register_callback(target: *mut (), callback: FfiCallback);
fn spike_new(
arch: *const c_char,
set: *const c_char,
lvl: *const c_char,
lane_number: usize,
Expand Down
5 changes: 2 additions & 3 deletions difftest/test_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ pub struct CommonArgs {
pub dlen: u32,

/// ISA config
#[arg(long, default_value = "rv32gcv")]
#[arg(long, default_value = env!("SPIKE_ISA_STRING"))]
pub set: String,
}

pub static MEM_SIZE: usize = 1usize << 32;

impl CommonArgs {
pub fn to_spike_c_handler(&self) -> Box<Spike> {
let arch = &format!("vlen:{},elen:32", self.vlen);
let lvl = "M";

Spike::new(arch, &self.set, lvl, (self.dlen / 32) as usize, MEM_SIZE)
Spike::new(&self.set, lvl, (self.dlen / 32) as usize, MEM_SIZE)
}

pub fn setup_logger(&self) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rec {
espresso = final.callPackage ./pkgs/espresso.nix { };
dramsim3 = final.callPackage ./pkgs/dramsim3.nix { };
libspike = final.callPackage ./pkgs/libspike.nix { };
libspike_interfaces = final.callPackage ../difftest/spike_interfaces { };
buddy-mlir = final.callPackage ./pkgs/buddy-mlir.nix { };
fetchMillDeps = final.callPackage ./pkgs/mill-builder.nix { };
circt-full = final.callPackage ./pkgs/circt-full.nix { };
Expand Down
7 changes: 4 additions & 3 deletions nix/pkgs/libspike.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ stdenv, dtc, fetchFromGitHub }:

stdenv.mkDerivation {
version = "unstable-2024-02-20";
version = "unstable-2024-07-03";
pname = "libspike";

env.cmakeConfig = ''
Expand All @@ -17,11 +17,12 @@ stdenv.mkDerivation {
'';
nativeBuildInputs = [ dtc ];
enableParallelBuilding = true;
separateDebugInfo = true;
src = fetchFromGitHub {
owner = "riscv";
repo = "riscv-isa-sim";
rev = "a22119e562c4185275a10eb11ca4ba568d09a570";
sha256 = "sha256-FR+so/kFbdSdlAQ6/P4WlD+wr18R4LXCwaNSTlki8mk=";
rev = "4a2da916671d49d9ab82f702f50995c19110c2a3";
hash = "sha256-c+yYuz2Z2/MwGmHYcv/gPIJQluzBjw8uUlOXsf9Bz28=";
};
configureFlags = [
"--enable-commitlog"
Expand Down