feat: difftest framework
This commit is contained in:
parent
97cf418c86
commit
849f2bb5f3
15 changed files with 318 additions and 84 deletions
|
@ -1,7 +1,10 @@
|
|||
#include "components.hpp"
|
||||
#include "config.hpp"
|
||||
#include "vl_wrapper.hpp"
|
||||
#include "vpi_user.h"
|
||||
#include <VFlow.h>
|
||||
#include <cstdint>
|
||||
#include <difftest.hpp>
|
||||
|
||||
using VlModule = VlModuleInterfaceCommon<VFlow>;
|
||||
using Registers = _RegistersVPI<uint32_t, 32>;
|
||||
|
@ -16,6 +19,8 @@ void *pmem_get() {
|
|||
int pmem_read(int raddr) {
|
||||
void *pmem = pmem_get();
|
||||
auto mem = static_cast<Memory<int, 128 * 1024> *>(pmem);
|
||||
// TODO: Do memory difftest at memory read and write to diagnose at a finer
|
||||
// granularity
|
||||
return mem->read(raddr);
|
||||
}
|
||||
|
||||
|
@ -26,19 +31,55 @@ void pmem_write(int waddr, int wdata, char wmask) {
|
|||
}
|
||||
}
|
||||
|
||||
VlModule *top;
|
||||
Registers *regs;
|
||||
using CPUState = CPUStateBase<uint32_t, 32>;
|
||||
vpiHandle pc = nullptr;
|
||||
void difftest_memcpy(paddr_t, void *, size_t, bool){};
|
||||
|
||||
void difftest_regcpy(void *p, bool direction) {
|
||||
|
||||
if (direction == DIFFTEST_FROM_REF) {
|
||||
((CPUState *)p)->pc = regs->get_pc();
|
||||
for (int i = 0; i < 32; i++) {
|
||||
((CPUState *)p)->reg[i] = (*regs)[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void difftest_exec(uint64_t n) {
|
||||
while (n--) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (top->is_posedge()) {
|
||||
// Posedge
|
||||
regs->update();
|
||||
}
|
||||
top->eval();
|
||||
}
|
||||
}
|
||||
}
|
||||
void difftest_init(int port) {
|
||||
// top = std::make_unique<VlModule>(config.do_trace, config.wavefile);
|
||||
top = new VlModule{config.do_trace, config.wavefile};
|
||||
regs = new Registers("TOP.Flow.reg_0.regFile_", "TOP.Flow.pc.out");
|
||||
top->reset_eval(10);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, char **env) {
|
||||
config.cli_parse(argc, argv);
|
||||
auto top = std::make_shared<VlModule>(config.do_trace, config.wavefile);
|
||||
Registers regs("TOP.Flow.reg_0.regFile_");
|
||||
|
||||
top->reset_eval(10);
|
||||
for (int i = 0; i < config.max_sim_time; i++) {
|
||||
if (top->is_posedge()) {
|
||||
// Posedge
|
||||
regs.update();
|
||||
regs.print_regs();
|
||||
}
|
||||
top->eval();
|
||||
/* -- Difftest -- */
|
||||
std::filesystem::path ref{config.lib_ref};
|
||||
DifftestInterface dut_interface = DifftestInterface{
|
||||
&difftest_memcpy, &difftest_regcpy, &difftest_exec, &difftest_init};
|
||||
DifftestInterface ref_interface = DifftestInterface{ref};
|
||||
|
||||
Difftest<CPUStateBase<uint32_t, 32>> diff{dut_interface, ref_interface,
|
||||
pmem_get(), 128};
|
||||
int t = 8;
|
||||
while (t--) {
|
||||
diff.step(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue