Skip to content

Commit

Permalink
draft to switch wave to fst
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Jul 29, 2024
1 parent 4b33216 commit 5b62e86
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 58 deletions.
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ trait Emulator extends Cross.Module2[String, String] {
| ${mfccompiler.rtls().map(_.path.toString).mkString("\n")}
| TOP_MODULE TestHarness
| PREFIX VTestHarness
| TRACE_FST
| VERILATOR_ARGS ${verilatorArgs().mkString(" ")}
|)
|""".stripMargin
Expand Down
40 changes: 23 additions & 17 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,30 @@
in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
deps = with pkgs; [
git
gnumake autoconf automake
mill
dtc
verilator cmake ninja
python3
python3Packages.pip
pkgsCross.riscv64-embedded.buildPackages.gcc
pkgsCross.riscv64-embedded.buildPackages.gdb
openocd
circt
let
pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
deps = with pkgs; [
git
gnumake
autoconf
automake
mill
dtc
verilator
cmake
ninja
python3
python3Packages.pip
pkgsCross.riscv64-embedded.buildPackages.gcc
pkgsCross.riscv64-embedded.buildPackages.gdb
openocd
circt
libz

spike riscvTests
];
in
spike
riscvTests
];
in
{
legacyPackages = pkgs;
devShell = pkgs.mkShell.override { stdenv = pkgs.clangStdenv; } {
Expand Down
32 changes: 11 additions & 21 deletions src/main/resources/csrc/emulator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "verilated.h"
#if VM_TRACE
#include <memory>
#include "verilated_vcd_c.h"
#include "verilated_fst_c.h"
#endif
#include <fesvr/dtm.h>
#include "remote_bitbang.h"
Expand Down Expand Up @@ -82,8 +82,8 @@ EMULATOR DEBUG OPTIONS (only supported in debug build -- try `make debug`)\n",
stdout);
#endif
fputs("\
-v, --vcd=FILE, Write vcd trace to FILE (or '-' for stdout)\n\
-x, --dump-start=CYCLE Start VCD tracing at CYCLE\n\
-v, --fst=FILE, Write fst trace to FILE (or '-' for stdout)\n\
-x, --dump-start=CYCLE Start FST tracing at CYCLE\n\
+dump-start\n\
", stdout);
fputs("\n" PLUSARG_USAGE_OPTIONS, stdout);
Expand All @@ -95,8 +95,8 @@ EMULATOR DEBUG OPTIONS (only supported in debug build -- try `make debug`)\n",
" - run a bare metal test showing cycle-by-cycle information:\n"
" %s +verbose $RISCV/riscv64-unknown-elf/share/riscv-tests/isa/rv64ui-p-add 2>&1 | spike-dasm\n"
#if VM_TRACE
" - run a bare metal test to generate a VCD waveform:\n"
" %s -v rv64ui-p-add.vcd $RISCV/riscv64-unknown-elf/share/riscv-tests/isa/rv64ui-p-add\n"
" - run a bare metal test to generate a FST waveform:\n"
" %s -v rv64ui-p-add.fst $RISCV/riscv64-unknown-elf/share/riscv-tests/isa/rv64ui-p-add\n"
#endif
" - run an ELF (you wrote, called 'hello') using the proxy kernel:\n"
" %s pk hello\n",
Expand All @@ -116,7 +116,7 @@ int main(int argc, char** argv)
// Port numbers are 16 bit unsigned integers.
uint16_t rbb_port = 0;
#if VM_TRACE
FILE * vcdfile = NULL;
char* fstfile = NULL;
uint64_t start = 0;
#endif
char ** htif_argv = NULL;
Expand All @@ -131,7 +131,7 @@ int main(int argc, char** argv)
{"rbb-port", required_argument, 0, 'r' },
{"verbose", no_argument, 0, 'V' },
#if VM_TRACE
{"vcd", required_argument, 0, 'v' },
{"fst", required_argument, 0, 'v' },
{"dump-start", required_argument, 0, 'x' },
#endif
HTIF_LONG_OPTIONS
Expand All @@ -154,14 +154,7 @@ int main(int argc, char** argv)
case 'r': rbb_port = atoi(optarg); break;
case 'V': verbose = true; break;
#if VM_TRACE
case 'v': {
vcdfile = strcmp(optarg, "-") == 0 ? stdout : fopen(optarg, "w");
if (!vcdfile) {
std::cerr << "Unable to open " << optarg << " for VCD write\n";
return 1;
}
break;
}
case 'v': fstfile = optarg; break;
case 'x': start = atoll(optarg); break;
#endif
// Process legacy '+' EMULATOR arguments by replacing them with
Expand Down Expand Up @@ -258,11 +251,10 @@ int main(int argc, char** argv)

#if VM_TRACE
Verilated::traceEverOn(true); // Verilator must compute traced signals
std::unique_ptr<VerilatedVcdFILE> vcdfd(new VerilatedVcdFILE(vcdfile));
std::unique_ptr<VerilatedVcdC> tfp(new VerilatedVcdC(vcdfd.get()));
if (vcdfile) {
std::unique_ptr<VerilatedFstC> tfp(new VerilatedFstC());
if (fstfile) {
tile->trace(tfp.get(), 99); // Trace 99 levels of hierarchy
tfp->open("");
tfp->open(fstfile);
}
#endif

Expand Down Expand Up @@ -307,8 +299,6 @@ int main(int argc, char** argv)
#if VM_TRACE
if (tfp)
tfp->close();
if (vcdfile)
fclose(vcdfile);
#endif

if (dtm->exit_code())
Expand Down
22 changes: 2 additions & 20 deletions src/main/resources/csrc/verilator.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
#ifndef _ROCKET_VERILATOR_H
#define _ROCKET_VERILATOR_H

#include "verilated_vcd_c.h"
#include "verilated_fst_c.h"
#include <stdlib.h>
#include <stdio.h>

extern bool verbose;
extern bool done_reset;

class VerilatedVcdFILE : public VerilatedVcdFile {
public:
VerilatedVcdFILE(FILE* file) : file(file) {}
~VerilatedVcdFILE() {}
bool open(const std::string& name) override {
// file should already be open
return file != NULL;
}
void close() override {
// file should be closed elsewhere
}
ssize_t write(const char* bufp, ssize_t len) override {
return fwrite(bufp, 1, len, file);
}
private:
FILE* file;
};

#endif
#endif

0 comments on commit 5b62e86

Please sign in to comment.