npc,fix: bugs of new arch in cpu-tests
All checks were successful
Build npc tests / npc-build (flow) (push) Successful in 3m7s
Build npc tests / npc-build (flow-simlib) (push) Successful in 3m13s
Build abstract machine with nix / build-packages (nemu) (pull_request) Successful in 25s
Build abstract machine with nix / build-packages (nemu-lib) (pull_request) Successful in 19s
Build abstract machine with nix / build-packages (rv32Cross.abstract-machine) (pull_request) Successful in 7s
Build abstract machine with nix / build-packages (abstract-machine) (pull_request) Successful in 1m23s

This commit is contained in:
xinyangli 2024-09-06 14:56:10 +08:00
parent fd1aae7c33
commit 24aeabee4f
Signed by: xin
SSH key fingerprint: SHA256:UU5pRTl7NiLFJbWJZa+snLylZSXIz5rgHmwjzv8v4oE
29 changed files with 1317 additions and 544 deletions

View file

@ -88,14 +88,18 @@ public:
ram->transfer(waddr, (uint8_t *)&wdata, len, true);
} else if (devices->handle(waddr, (uint8_t *)&wdata, len, true)) {
}
logger->trace("[W] 0x{:x}: 0x{:x}", waddr, wdata);
}
word_t read(paddr_t raddr) const {
word_t read(paddr_t raddr, int rmask) const {
word_t res = 0;
size_t len = (rmask & 1) + ((rmask & 2) >> 1) + ((rmask & 4) >> 2) +
((rmask & 8) >> 3);
if (ram->in_pmem(raddr)) {
ram->transfer(raddr, (uint8_t *)&res, 4, false);
ram->transfer(raddr, (uint8_t *)&res, len, false);
} else if (devices->handle(raddr, (uint8_t *)&res, 4, false)) {
}
logger->trace("[R] 0x{:x}: 0x{:x}", raddr, res);
return res;
}
@ -120,7 +124,7 @@ public:
void *get_pmem() { return ram->mem.data(); }
void trace(paddr_t addr, bool is_read, word_t pc = 0, word_t value = 0) {
logger->trace("[{}] 0x{:x}", is_read ? 'R' : 'W', this->read(addr));
logger->trace("[{}] 0x{:x}", is_read ? 'R' : 'W', this->read(addr, value));
}
private:

View file

@ -1,6 +1,7 @@
#ifndef _NPC_TYPES_H__
#define _NPC_TYPES_H__
#ifdef __cplusplus
#include <string>
extern "C" {
#endif
#include <gdbstub.h>
@ -32,6 +33,7 @@ struct Breakpoint {
struct DbgState {
std::vector<Breakpoint> *bp;
std::string *cmd_return_buf;
};
#endif

View file

@ -34,6 +34,7 @@ template <typename T, typename R> class VlModuleInterfaceCommon : public T {
uint64_t sim_time = 0;
uint64_t posedge_cnt = 0;
std::unique_ptr<Tracer<T>> tracer;
std::filesystem::path wavefile;
public:
const R *registers;
@ -43,8 +44,7 @@ public:
}
void setup(std::filesystem::path wavefile, const R *r) {
if (!wavefile.empty())
tracer = std::make_unique<Tracer<T>>(this, wavefile);
wavefile = "wave.vcd";
registers = r;
}
@ -89,10 +89,30 @@ public:
this->reset = 0;
g_skip_memcheck = false;
}
bool is_posedge() {
// Will be posedge when eval is called
return T::clock == 0;
}
bool start_trace() { return init_tracer(wavefile); }
bool end_trace() {
tracer.reset();
return true;
}
private:
bool init_tracer(std::filesystem::path wavefile) {
fmt::print("wavefile: {}", wavefile.string());
std::filesystem::path wav = "wave.vcd";
if (!wav.empty()) {
// Creating of tracer must happen after this class fully initialized
tracer = std::make_unique<Tracer<T>>(this, wav);
return true;
}
return false;
}
};
#endif

View file

@ -27,18 +27,23 @@ public:
}
private:
static vpiHandle get_handle(const std::string name) {
vpiHandle hdl = vpi_handle_by_name((PLI_BYTE8 *)name.c_str(), nullptr);
if (hdl == nullptr) {
SPDLOG_ERROR("VPI Handle {} not found", name);
exit(EXIT_FAILURE);
} else {
SPDLOG_INFO("Found VPI handle {} at {}", name, (void *)hdl);
}
return hdl;
}
void init_handlers(const std::string regs_prefix, const std::string pcname) {
pc_handle = get_handle(pcname);
for (int i = 0; i < nr; i++) {
std::string regname = regs_prefix + std::to_string(i);
vpiHandle vh = vpi_handle_by_name((PLI_BYTE8 *)regname.c_str(), nullptr);
if (vh == nullptr) {
std::cerr << "vpiHandle " << regname.c_str() << " not found"
<< std::endl;
exit(EXIT_FAILURE);
}
reg_handles[i] = vh;
reg_handles[i] = get_handle(regname);
}
pc_handle = vpi_handle_by_name((PLI_BYTE8 *)pcname.c_str(), nullptr);
}
};