feat(npc): ebreak support through external inst matching

This commit is contained in:
xinyangli 2024-04-11 11:44:54 +08:00
parent 55230247b2
commit e99236f711
Signed by: xin
SSH key fingerprint: SHA256:qZ/tzd8lYRtUFSrfBDBMcUqV4GHKxqeqRA3huItgvbk
8 changed files with 97 additions and 25 deletions

View file

@ -79,5 +79,8 @@ public:
// printf("waddr: 0x%x\n", waddr);
mem[addr_to_index((uint32_t)waddr)] = expand_bits(wmask) & wdata;
}
void *guest_to_host(std::size_t addr) {
return mem.data() + addr_to_index(addr);
}
};
#endif

View file

@ -34,19 +34,29 @@ struct DifftestTrmInterface : public TrmInterface {
fetch_state();
};
exec = [this](uint64_t n) {
while (n--) {
bool enable_disasm = true;
if (n > 30) {
enable_disasm = false;
}
while (n--) {
word_t pc = this->ref.at("pc");
word_t inst = this->ref.at(pc);
std::cout << d.disassemble(pc, (uint8_t *)&inst, WORD_BYTES)
<< std::endl;
if (enable_disasm)
std::cout << d.disassemble(pc, (uint8_t *)&inst, WORD_BYTES)
<< std::endl;
if (inst == 1048691) {
// ebreak
throw TrmRuntimeException(TrmRuntimeException::EBREAK, "ebreak");
}
this->ref.exec(1);
this->dut.exec(1);
this->ref.fetch_state();
this->dut.fetch_state();
if (*(CPUState *)this->ref.cpu_state !=
*(CPUState *)this->dut.cpu_state) {
throw std::runtime_error("Difftest failed");
throw TrmRuntimeException(TrmRuntimeException::DIFFTEST_FAILED,
"Difftest failed");
}
}
};

View file

@ -96,6 +96,21 @@ public:
virtual void print(std::ostream &os) const = 0;
};
class TrmRuntimeException : public std::exception {
private:
const char *msg_;
int code_;
public:
enum { EBREAK, DIFFTEST_FAILED };
TrmRuntimeException(int code, const char *message)
: code_(code), msg_(message) {}
virtual const char *what() const throw() { return msg_; }
int error_code() const { return code_; }
};
struct RefTrmInterface : TrmInterface {
RefTrmInterface(std::filesystem::path lib_file) {
void *handle = dlopen(lib_file.c_str(), RTLD_LAZY);