diff --git a/CMakeLists.txt b/CMakeLists.txt index 9846759..405c4b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ if(NOT TARGET dbt-rise-core) FetchContent_Declare( dbt_rise_core_git GIT_REPOSITORY "https://github.com/Minres/DBT-RISE-Core.git" - GIT_TAG 7cd010c + GIT_TAG 29e97c02 GIT_SHALLOW OFF UPDATE_DISCONNECTED NOT ${UPDATE_EXTERNAL_PROJECT} # When enabled, this option causes the update step to be skipped. ) diff --git a/src/decoder_test.cpp b/src/decoder_test.cpp index 00f5259..61a784b 100644 --- a/src/decoder_test.cpp +++ b/src/decoder_test.cpp @@ -34,7 +34,7 @@ int main(int argc, char* argv[]) { }()); std::ofstream json_out{"idecode_tree.json"}; - json_out << instr_decoder.print_tree_as_pretty_json(); + json_out << instr_decoder.print_tree_as_json(); auto inst_index1 = instr_decoder.decode_instr(0x8440); auto inst_index2 = instr_decoder.decode_instr(0x86b0); diff --git a/src/sysc/core2sc_adapter.h b/src/sysc/core2sc_adapter.h index b3cd825..e3c9a4e 100644 --- a/src/sysc/core2sc_adapter.h +++ b/src/sysc/core2sc_adapter.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -262,6 +263,7 @@ template class core2sc_adapter : public PLAT, public sc2core_if SCCDEBUG(owner->hier_name()) << "Sleeping until interrupt"; wfi_inst.store(true, std::memory_order_relaxed); std::function f = [this]() { + auto start = sc_core::sc_time_stamp(); while((this->mip_csr & this->mie_csr) == 0) { sc_core::wait(this->wfi_evt | this->debugger_stop_evt); bool is_debugger_stop_evt = this->debugger_stop_evt.triggered(); @@ -269,6 +271,11 @@ template class core2sc_adapter : public PLAT, public sc2core_if break; } SCCINFO(this->owner->hier_name()) << "Got WFI event"; + auto duration = sc_core::sc_time_stamp() - start; + if(clk_if && duration > sc_core::SC_ZERO_TIME) { + auto cycles = duration.value() / clk_if->read().value(); + this->reg.cycle += cycles; + } }; owner->exec_on_sysc(f); wfi_inst.store(false, std::memory_order_relaxed); diff --git a/src/sysc/core_complex.cpp b/src/sysc/core_complex.cpp index 00e7414..ec52b59 100644 --- a/src/sysc/core_complex.cpp +++ b/src/sysc/core_complex.cpp @@ -170,6 +170,7 @@ void core_complex::create_cpu(std::string const& type, std::string SCCFATAL() << "Could not create vm for isa " << type << " and backend " << backend; } else { core->set_hartid(hart_id); + core->set_clk_if(clk_i.get_interface(0)); core->set_clint_irq_count(clint_irq_i.size()); auto* srv = debugger::server::get(); if(srv) diff --git a/src/sysc/sc2core_if.h b/src/sysc/sc2core_if.h index b85ab0a..03e07f8 100644 --- a/src/sysc/sc2core_if.h +++ b/src/sysc/sc2core_if.h @@ -66,6 +66,10 @@ struct sc2core_if { util::delegate register_csr_wr; virtual void register_unknown_instr_handler(util::delegate) = 0; virtual void set_clint_irq_count(size_t) = 0; + void set_clk_if(sc_core::sc_signal_in_if* clk_if) { this->clk_if = clk_if; }; + +protected: + sc_core::sc_signal_in_if* clk_if{nullptr}; }; } // namespace sysc #endif /* _SYSC_SC2CORE_IF_H_ */