2018-11-08 13:31:28 +01:00
|
|
|
/*******************************************************************************
|
|
|
|
* Copyright (C) 2017, 2018 MINRES Technologies GmbH
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2017-09-21 13:13:01 +02:00
|
|
|
|
2022-07-18 11:02:17 +02:00
|
|
|
// clang-format off
|
|
|
|
#include <iss/debugger/gdb_session.h>
|
|
|
|
#include <iss/debugger/encoderdecoder.h>
|
|
|
|
#include <iss/debugger/server.h>
|
|
|
|
#include <iss/debugger/target_adapter_if.h>
|
|
|
|
#include <iss/iss.h>
|
2022-03-26 10:48:21 +01:00
|
|
|
#include <iss/vm_types.h>
|
2023-07-14 11:11:03 +02:00
|
|
|
#include "iss_factory.h"
|
2022-07-18 11:02:17 +02:00
|
|
|
#ifndef WIN32
|
|
|
|
#include <iss/plugin/loader.h>
|
|
|
|
#endif
|
2023-07-09 22:20:50 +02:00
|
|
|
#include "sc_core_adapter_if.h"
|
2022-03-26 10:48:21 +01:00
|
|
|
#include <iss/arch/tgc_mapper.h>
|
2021-10-12 14:24:55 +02:00
|
|
|
#include <scc/report.h>
|
|
|
|
#include <util/ities.h>
|
2018-11-08 13:31:28 +01:00
|
|
|
#include <iostream>
|
2020-09-04 15:37:21 +02:00
|
|
|
#include <sstream>
|
2021-07-27 09:38:05 +02:00
|
|
|
#include <array>
|
2023-10-22 23:19:09 +02:00
|
|
|
#include <numeric>
|
2021-10-12 14:24:55 +02:00
|
|
|
#include <iss/plugin/cycle_estimate.h>
|
|
|
|
#include <iss/plugin/instruction_count.h>
|
2022-01-31 21:38:18 +01:00
|
|
|
|
2022-07-18 11:02:17 +02:00
|
|
|
// clang-format on
|
2017-10-09 22:52:19 +02:00
|
|
|
|
2021-05-16 15:06:42 +02:00
|
|
|
#define STR(X) #X
|
2023-10-29 17:06:56 +01:00
|
|
|
#define CREATE_CORE(CN) \
|
|
|
|
if(type == STR(CN)) { \
|
|
|
|
std::tie(cpu, vm) = create_core<CN##_plat_type>(backend, gdb_port, hart_id); \
|
|
|
|
} else
|
2021-05-16 15:06:42 +02:00
|
|
|
|
2021-11-11 08:33:35 +01:00
|
|
|
#ifdef HAS_SCV
|
2018-11-08 13:31:28 +01:00
|
|
|
#include <scv.h>
|
2021-07-27 09:38:05 +02:00
|
|
|
#else
|
|
|
|
#include <scv-tr.h>
|
|
|
|
using namespace scv_tr;
|
2017-10-22 19:29:37 +02:00
|
|
|
#endif
|
2017-09-21 13:13:01 +02:00
|
|
|
|
2021-08-16 16:59:23 +02:00
|
|
|
#ifndef CWR_SYSTEMC
|
|
|
|
#define GET_PROP_VALUE(P) P.get_value()
|
|
|
|
#else
|
|
|
|
#define GET_PROP_VALUE(P) P.getValue()
|
|
|
|
#endif
|
|
|
|
|
2022-07-18 11:02:17 +02:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
|
|
|
|
#define strncasecmp _strnicmp
|
|
|
|
#define strcasecmp _stricmp
|
|
|
|
#endif
|
|
|
|
|
2017-09-21 13:13:01 +02:00
|
|
|
namespace sysc {
|
2021-03-22 12:57:40 +01:00
|
|
|
namespace tgfs {
|
2018-02-06 12:34:34 +01:00
|
|
|
using namespace std;
|
|
|
|
using namespace iss;
|
2018-11-08 13:31:28 +01:00
|
|
|
using namespace logging;
|
|
|
|
using namespace sc_core;
|
2018-02-06 12:34:34 +01:00
|
|
|
|
2017-10-09 22:52:19 +02:00
|
|
|
namespace {
|
|
|
|
iss::debugger::encoder_decoder encdec;
|
2018-11-08 13:31:28 +01:00
|
|
|
std::array<const char, 4> lvl = {{'U', 'S', 'H', 'M'}};
|
2023-10-29 17:06:56 +01:00
|
|
|
} // namespace
|
2017-10-22 19:29:37 +02:00
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
int cmd_sysc(int argc, char* argv[], debugger::out_func of, debugger::data_func df, debugger::target_adapter_if* tgt_adapter) {
|
|
|
|
if(argc > 1) {
|
|
|
|
if(strcasecmp(argv[1], "print_time") == 0) {
|
2018-11-08 13:31:28 +01:00
|
|
|
std::string t = sc_time_stamp().to_string();
|
2017-10-09 22:52:19 +02:00
|
|
|
of(t.c_str());
|
2018-11-08 13:31:28 +01:00
|
|
|
std::array<char, 64> buf;
|
|
|
|
encdec.enc_string(t.c_str(), buf.data(), 63);
|
|
|
|
df(buf.data());
|
2018-02-06 12:34:34 +01:00
|
|
|
return Ok;
|
2023-10-29 17:06:56 +01:00
|
|
|
} else if(strcasecmp(argv[1], "break") == 0) {
|
2018-11-08 13:31:28 +01:00
|
|
|
sc_time t;
|
2023-10-29 17:06:56 +01:00
|
|
|
if(argc == 4) {
|
2018-11-08 13:31:28 +01:00
|
|
|
t = scc::parse_from_string(argv[2], argv[3]);
|
2023-10-29 17:06:56 +01:00
|
|
|
} else if(argc == 3) {
|
2018-11-08 13:31:28 +01:00
|
|
|
t = scc::parse_from_string(argv[2]);
|
2017-10-09 22:52:19 +02:00
|
|
|
} else
|
2018-02-06 12:34:34 +01:00
|
|
|
return Err;
|
2017-10-09 22:52:19 +02:00
|
|
|
// no check needed as it is only called if debug server is active
|
2018-11-08 13:31:28 +01:00
|
|
|
tgt_adapter->add_break_condition([t]() -> unsigned {
|
2020-06-18 07:38:56 +02:00
|
|
|
SCCTRACE() << "Checking condition at " << sc_time_stamp();
|
2018-11-08 13:31:28 +01:00
|
|
|
return sc_time_stamp() >= t ? std::numeric_limits<unsigned>::max() : 0;
|
2017-10-09 22:52:19 +02:00
|
|
|
});
|
2018-02-06 12:34:34 +01:00
|
|
|
return Ok;
|
2017-10-09 22:52:19 +02:00
|
|
|
}
|
2018-02-06 12:34:34 +01:00
|
|
|
return Err;
|
2017-10-09 22:52:19 +02:00
|
|
|
}
|
2018-02-06 12:34:34 +01:00
|
|
|
return Err;
|
2017-10-09 22:52:19 +02:00
|
|
|
}
|
|
|
|
|
2021-05-16 15:06:42 +02:00
|
|
|
using cpu_ptr = std::unique_ptr<iss::arch_if>;
|
2023-10-29 17:06:56 +01:00
|
|
|
using vm_ptr = std::unique_ptr<iss::vm_if>;
|
2021-05-16 15:06:42 +02:00
|
|
|
|
|
|
|
class core_wrapper {
|
|
|
|
public:
|
2023-10-29 17:06:56 +01:00
|
|
|
core_wrapper(core_complex* owner)
|
|
|
|
: owner(owner) {}
|
2021-05-16 15:06:42 +02:00
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
void reset(uint64_t addr) { vm->reset(addr); }
|
|
|
|
inline void start(bool dump = false) { vm->start(std::numeric_limits<uint64_t>::max(), dump); }
|
|
|
|
inline std::pair<uint64_t, bool> load_file(std::string const& name) {
|
2023-07-14 11:11:03 +02:00
|
|
|
iss::arch_if* cc = cpu->get_arch_if();
|
2023-10-29 17:06:56 +01:00
|
|
|
return cc->load_file(name);
|
|
|
|
};
|
2021-05-16 15:06:42 +02:00
|
|
|
|
|
|
|
std::function<unsigned(void)> get_mode;
|
|
|
|
std::function<uint64_t(void)> get_state;
|
|
|
|
std::function<bool(void)> get_interrupt_execution;
|
|
|
|
std::function<void(bool)> set_interrupt_execution;
|
|
|
|
std::function<void(short, bool)> local_irq;
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
void create_cpu(std::string const& type, std::string const& backend, unsigned gdb_port, uint32_t hart_id) {
|
|
|
|
auto& f = sysc::iss_factory::instance();
|
|
|
|
if(type.size() == 0 || type == "?") {
|
|
|
|
std::cout << "Available cores: " << util::join(f.get_names(), ", ") << std::endl;
|
2023-07-09 22:20:50 +02:00
|
|
|
sc_core::sc_stop();
|
2023-10-29 17:06:56 +01:00
|
|
|
} else if(type.find('|') != std::string::npos) {
|
|
|
|
std::tie(cpu, vm) = f.create(type + "|" + backend);
|
2023-07-09 22:20:50 +02:00
|
|
|
} else {
|
|
|
|
auto base_isa = type.substr(0, 5);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(base_isa == "tgc5d" || base_isa == "tgc5e") {
|
2023-10-27 22:14:11 +02:00
|
|
|
std::tie(cpu, vm) = f.create(type + "|mu_p_clic_pmp|" + backend, gdb_port, owner);
|
2023-07-09 22:20:50 +02:00
|
|
|
} else {
|
2023-07-14 11:11:03 +02:00
|
|
|
std::tie(cpu, vm) = f.create(type + "|m_p|" + backend, gdb_port, owner);
|
2023-10-29 17:06:56 +01:00
|
|
|
}
|
2023-07-09 22:20:50 +02:00
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
if(!cpu) {
|
|
|
|
SCCFATAL() << "Could not create cpu for isa " << type << " and backend " << backend;
|
2021-05-16 15:06:42 +02:00
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
if(!vm) {
|
|
|
|
SCCFATAL() << "Could not create vm for isa " << type << " and backend " << backend;
|
2023-07-09 22:20:50 +02:00
|
|
|
}
|
2023-07-14 11:11:03 +02:00
|
|
|
auto* sc_cpu_if = reinterpret_cast<sc_core_adapter_if*>(cpu.get());
|
|
|
|
sc_cpu_if->set_mhartid(hart_id);
|
|
|
|
get_mode = [sc_cpu_if]() { return sc_cpu_if->get_mode(); };
|
|
|
|
get_state = [sc_cpu_if]() { return sc_cpu_if->get_state(); };
|
|
|
|
get_interrupt_execution = [sc_cpu_if]() { return sc_cpu_if->get_interrupt_execution(); };
|
|
|
|
set_interrupt_execution = [sc_cpu_if](bool b) { return sc_cpu_if->set_interrupt_execution(b); };
|
|
|
|
local_irq = [sc_cpu_if](short s, bool b) { return sc_cpu_if->local_irq(s, b); };
|
2023-07-09 22:20:50 +02:00
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
auto* srv = debugger::server<debugger::gdb_session>::get();
|
|
|
|
if(srv)
|
|
|
|
tgt_adapter = srv->get_target();
|
|
|
|
if(tgt_adapter)
|
|
|
|
tgt_adapter->add_custom_command({"sysc",
|
|
|
|
[this](int argc, char* argv[], debugger::out_func of, debugger::data_func df) -> int {
|
|
|
|
return cmd_sysc(argc, argv, of, df, tgt_adapter);
|
|
|
|
},
|
|
|
|
"SystemC sub-commands: break <time>, print_time"});
|
2021-05-16 15:06:42 +02:00
|
|
|
}
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
core_complex* const owner;
|
2021-05-16 15:06:42 +02:00
|
|
|
vm_ptr vm{nullptr};
|
2023-07-14 11:11:03 +02:00
|
|
|
sc_cpu_ptr cpu{nullptr};
|
2023-10-29 17:06:56 +01:00
|
|
|
iss::debugger::target_adapter_if* tgt_adapter{nullptr};
|
2021-05-16 15:06:42 +02:00
|
|
|
};
|
|
|
|
|
2021-07-27 09:38:05 +02:00
|
|
|
struct core_trace {
|
|
|
|
//! transaction recording database
|
2023-10-29 17:06:56 +01:00
|
|
|
scv_tr_db* m_db{nullptr};
|
2021-07-27 09:38:05 +02:00
|
|
|
//! blocking transaction recording stream handle
|
2023-10-29 17:06:56 +01:00
|
|
|
scv_tr_stream* stream_handle{nullptr};
|
2021-07-27 09:38:05 +02:00
|
|
|
//! transaction generator handle for blocking transactions
|
2023-10-29 17:06:56 +01:00
|
|
|
scv_tr_generator<_scv_tr_generator_default_data, _scv_tr_generator_default_data>* instr_tr_handle{nullptr};
|
2021-07-27 09:38:05 +02:00
|
|
|
scv_tr_handle tr_handle;
|
|
|
|
};
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
SC_HAS_PROCESS(core_complex); // NOLINT
|
2021-08-16 16:59:23 +02:00
|
|
|
#ifndef CWR_SYSTEMC
|
2021-08-16 17:55:14 +02:00
|
|
|
core_complex::core_complex(sc_module_name const& name)
|
2018-11-08 13:31:28 +01:00
|
|
|
: sc_module(name)
|
2023-05-04 21:59:31 +02:00
|
|
|
, fetch_lut(tlm_dmi_ext())
|
2017-10-04 10:31:11 +02:00
|
|
|
, read_lut(tlm_dmi_ext())
|
2023-10-29 17:06:56 +01:00
|
|
|
, write_lut(tlm_dmi_ext()) {
|
|
|
|
init();
|
2021-08-16 16:59:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
void core_complex::init() {
|
|
|
|
trc = new core_trace();
|
2023-05-04 21:59:31 +02:00
|
|
|
ibus.register_invalidate_direct_mem_ptr([=](uint64_t start, uint64_t end) -> void {
|
|
|
|
auto lut_entry = fetch_lut.getEntry(start);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && end <= lut_entry.get_end_address() + 1) {
|
2023-05-04 21:59:31 +02:00
|
|
|
fetch_lut.removeEntry(lut_entry);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dbus.register_invalidate_direct_mem_ptr([=](uint64_t start, uint64_t end) -> void {
|
2017-10-04 10:31:11 +02:00
|
|
|
auto lut_entry = read_lut.getEntry(start);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && end <= lut_entry.get_end_address() + 1) {
|
2017-10-04 10:31:11 +02:00
|
|
|
read_lut.removeEntry(lut_entry);
|
|
|
|
}
|
|
|
|
lut_entry = write_lut.getEntry(start);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && end <= lut_entry.get_end_address() + 1) {
|
2017-10-04 10:31:11 +02:00
|
|
|
write_lut.removeEntry(lut_entry);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
SC_THREAD(run);
|
2018-07-13 20:04:07 +02:00
|
|
|
SC_METHOD(rst_cb);
|
|
|
|
sensitive << rst_i;
|
2017-11-10 22:40:24 +01:00
|
|
|
SC_METHOD(sw_irq_cb);
|
2018-11-08 13:31:28 +01:00
|
|
|
sensitive << sw_irq_i;
|
2017-11-10 22:40:24 +01:00
|
|
|
SC_METHOD(timer_irq_cb);
|
2018-11-08 13:31:28 +01:00
|
|
|
sensitive << timer_irq_i;
|
2022-10-26 17:21:44 +02:00
|
|
|
SC_METHOD(ext_irq_cb);
|
|
|
|
sensitive << ext_irq_i;
|
|
|
|
SC_METHOD(local_irq_cb);
|
2023-10-29 17:06:56 +01:00
|
|
|
for(auto pin : local_irq_i)
|
2022-10-26 17:21:44 +02:00
|
|
|
sensitive << pin;
|
2023-10-29 17:06:56 +01:00
|
|
|
trc->m_db = scv_tr_db::get_default_db();
|
2021-08-16 16:59:23 +02:00
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
SC_METHOD(forward);
|
2021-08-16 16:59:23 +02:00
|
|
|
#ifndef CWR_SYSTEMC
|
2023-10-29 17:06:56 +01:00
|
|
|
sensitive << clk_i;
|
2021-08-16 16:59:23 +02:00
|
|
|
#else
|
2023-10-29 17:06:56 +01:00
|
|
|
sensitive << curr_clk;
|
|
|
|
t2t.reset(new scc::tick2time{"t2t"});
|
|
|
|
t2t->clk_i(clk_i);
|
|
|
|
t2t->clk_o(curr_clk);
|
2021-08-16 16:59:23 +02:00
|
|
|
#endif
|
2017-10-04 10:31:11 +02:00
|
|
|
}
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
core_complex::~core_complex() {
|
2021-08-16 16:59:23 +02:00
|
|
|
delete cpu;
|
|
|
|
delete trc;
|
2023-10-29 17:06:56 +01:00
|
|
|
for(auto* p : plugin_list)
|
2021-10-12 14:24:55 +02:00
|
|
|
delete p;
|
2021-08-16 16:59:23 +02:00
|
|
|
}
|
2017-10-04 10:31:11 +02:00
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
void core_complex::trace(sc_trace_file* trf) const {}
|
2017-10-04 10:31:11 +02:00
|
|
|
|
|
|
|
void core_complex::before_end_of_elaboration() {
|
2023-10-29 17:06:56 +01:00
|
|
|
SCCDEBUG(SCMOD) << "instantiating iss::arch::tgf with " << GET_PROP_VALUE(backend) << " backend";
|
2021-08-16 16:59:23 +02:00
|
|
|
// cpu = scc::make_unique<core_wrapper>(this);
|
|
|
|
cpu = new core_wrapper(this);
|
|
|
|
cpu->create_cpu(GET_PROP_VALUE(core_type), GET_PROP_VALUE(backend), GET_PROP_VALUE(gdb_server_port), GET_PROP_VALUE(mhartid));
|
2023-10-29 17:06:56 +01:00
|
|
|
sc_assert(cpu->vm != nullptr);
|
2021-08-16 16:59:23 +02:00
|
|
|
cpu->vm->setDisassEnabled(GET_PROP_VALUE(enable_disass) || trc->m_db != nullptr);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(GET_PROP_VALUE(plugins).length()) {
|
2021-10-12 14:24:55 +02:00
|
|
|
auto p = util::split(GET_PROP_VALUE(plugins), ';');
|
2023-10-29 17:06:56 +01:00
|
|
|
for(std::string const& opt_val : p) {
|
|
|
|
std::string plugin_name = opt_val;
|
2021-10-12 14:24:55 +02:00
|
|
|
std::string filename{"cycles.txt"};
|
|
|
|
std::size_t found = opt_val.find('=');
|
2023-10-29 17:06:56 +01:00
|
|
|
if(found != std::string::npos) {
|
2021-10-12 14:24:55 +02:00
|
|
|
plugin_name = opt_val.substr(0, found);
|
|
|
|
filename = opt_val.substr(found + 1, opt_val.size());
|
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
if(plugin_name == "ic") {
|
|
|
|
auto* plugin = new iss::plugin::instruction_count(filename);
|
2021-10-12 14:24:55 +02:00
|
|
|
cpu->vm->register_plugin(*plugin);
|
|
|
|
plugin_list.push_back(plugin);
|
2023-10-29 17:06:56 +01:00
|
|
|
} else if(plugin_name == "ce") {
|
|
|
|
auto* plugin = new iss::plugin::cycle_estimate(filename);
|
2021-10-12 14:24:55 +02:00
|
|
|
cpu->vm->register_plugin(*plugin);
|
2022-01-31 21:38:18 +01:00
|
|
|
plugin_list.push_back(plugin);
|
2021-10-12 14:24:55 +02:00
|
|
|
} else {
|
2022-07-18 11:02:17 +02:00
|
|
|
#ifndef WIN32
|
2021-10-12 14:24:55 +02:00
|
|
|
std::array<char const*, 1> a{{filename.c_str()}};
|
|
|
|
iss::plugin::loader l(plugin_name, {{"initPlugin"}});
|
|
|
|
auto* plugin = l.call_function<iss::vm_plugin*>("initPlugin", a.size(), a.data());
|
2023-10-29 17:06:56 +01:00
|
|
|
if(plugin) {
|
2021-10-12 14:24:55 +02:00
|
|
|
cpu->vm->register_plugin(*plugin);
|
|
|
|
plugin_list.push_back(plugin);
|
|
|
|
} else
|
2022-07-18 11:02:17 +02:00
|
|
|
#endif
|
2021-10-12 14:24:55 +02:00
|
|
|
SCCERR(SCMOD) << "Unknown plugin '" << plugin_name << "' or plugin not found";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 10:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void core_complex::start_of_simulation() {
|
2023-05-02 11:13:25 +02:00
|
|
|
// quantum_keeper.reset();
|
2023-10-29 17:06:56 +01:00
|
|
|
if(GET_PROP_VALUE(elf_file).size() > 0) {
|
2021-08-16 16:59:23 +02:00
|
|
|
istringstream is(GET_PROP_VALUE(elf_file));
|
2018-11-08 13:31:28 +01:00
|
|
|
string s;
|
2023-10-29 17:06:56 +01:00
|
|
|
while(getline(is, s, ',')) {
|
2018-11-08 13:31:28 +01:00
|
|
|
std::pair<uint64_t, bool> start_addr = cpu->load_file(s);
|
2021-08-16 16:59:23 +02:00
|
|
|
#ifndef CWR_SYSTEMC
|
2023-10-29 17:06:56 +01:00
|
|
|
if(reset_address.is_default_value() && start_addr.second == true)
|
2018-11-08 13:31:28 +01:00
|
|
|
reset_address.set_value(start_addr.first);
|
2021-08-16 16:59:23 +02:00
|
|
|
#else
|
2023-10-29 17:06:56 +01:00
|
|
|
if(start_addr.second == true)
|
|
|
|
reset_address = start_addr.first;
|
2021-08-16 16:59:23 +02:00
|
|
|
#endif
|
2018-11-08 13:31:28 +01:00
|
|
|
}
|
2018-03-27 19:49:11 +02:00
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
if(trc->m_db != nullptr && trc->stream_handle == nullptr) {
|
2018-11-08 13:31:28 +01:00
|
|
|
string basename(this->name());
|
2021-07-27 09:38:05 +02:00
|
|
|
trc->stream_handle = new scv_tr_stream((basename + ".instr").c_str(), "TRANSACTOR", trc->m_db);
|
|
|
|
trc->instr_tr_handle = new scv_tr_generator<>("execute", *trc->stream_handle);
|
2018-11-08 13:31:28 +01:00
|
|
|
}
|
2017-10-22 19:29:37 +02:00
|
|
|
}
|
|
|
|
|
2021-07-27 09:38:05 +02:00
|
|
|
bool core_complex::disass_output(uint64_t pc, const std::string instr_str) {
|
2023-10-29 17:06:56 +01:00
|
|
|
if(trc->m_db == nullptr)
|
|
|
|
return false;
|
|
|
|
if(trc->tr_handle.is_active())
|
|
|
|
trc->tr_handle.end_transaction();
|
2021-07-27 09:38:05 +02:00
|
|
|
trc->tr_handle = trc->instr_tr_handle->begin_transaction();
|
|
|
|
trc->tr_handle.record_attribute("PC", pc);
|
|
|
|
trc->tr_handle.record_attribute("INSTR", instr_str);
|
|
|
|
trc->tr_handle.record_attribute("MODE", lvl[cpu->get_mode()]);
|
|
|
|
trc->tr_handle.record_attribute("MSTATUS", cpu->get_state());
|
|
|
|
trc->tr_handle.record_attribute("LTIME_START", quantum_keeper.get_current_time().value() / 1000);
|
|
|
|
return true;
|
2017-10-04 10:31:11 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 16:59:23 +02:00
|
|
|
void core_complex::forward() {
|
|
|
|
#ifndef CWR_SYSTEMC
|
2023-10-29 17:06:56 +01:00
|
|
|
set_clock_period(clk_i.read());
|
2021-08-16 16:59:23 +02:00
|
|
|
#else
|
2023-10-29 17:06:56 +01:00
|
|
|
set_clock_period(curr_clk.read());
|
2021-08-16 16:59:23 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void core_complex::set_clock_period(sc_core::sc_time period) {
|
2023-10-29 17:06:56 +01:00
|
|
|
curr_clk = period;
|
|
|
|
if(period == SC_ZERO_TIME)
|
|
|
|
cpu->set_interrupt_execution(true);
|
2018-07-13 20:04:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void core_complex::rst_cb() {
|
2023-10-29 17:06:56 +01:00
|
|
|
if(rst_i.read())
|
|
|
|
cpu->set_interrupt_execution(true);
|
2017-11-10 22:40:24 +01:00
|
|
|
}
|
|
|
|
|
2022-10-26 17:21:44 +02:00
|
|
|
void core_complex::sw_irq_cb() { cpu->local_irq(3, sw_irq_i.read()); }
|
2017-11-10 22:40:24 +01:00
|
|
|
|
2022-10-26 17:21:44 +02:00
|
|
|
void core_complex::timer_irq_cb() { cpu->local_irq(7, timer_irq_i.read()); }
|
2017-11-10 22:40:24 +01:00
|
|
|
|
2022-10-26 17:21:44 +02:00
|
|
|
void core_complex::ext_irq_cb() { cpu->local_irq(11, ext_irq_i.read()); }
|
|
|
|
|
|
|
|
void core_complex::local_irq_cb() {
|
2023-10-29 17:06:56 +01:00
|
|
|
for(auto i = 0U; i < local_irq_i.size(); ++i) {
|
2022-10-26 17:21:44 +02:00
|
|
|
if(local_irq_i[i].event()) {
|
2023-10-29 17:06:56 +01:00
|
|
|
cpu->local_irq(16 + i, local_irq_i[i].read());
|
2022-10-26 17:21:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 10:31:11 +02:00
|
|
|
|
|
|
|
void core_complex::run() {
|
2018-07-13 20:04:07 +02:00
|
|
|
wait(SC_ZERO_TIME); // separate from elaboration phase
|
2018-11-08 13:31:28 +01:00
|
|
|
do {
|
2023-05-02 11:21:42 +02:00
|
|
|
wait(SC_ZERO_TIME);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(rst_i.read()) {
|
2021-08-16 16:59:23 +02:00
|
|
|
cpu->reset(GET_PROP_VALUE(reset_address));
|
2018-07-13 20:04:07 +02:00
|
|
|
wait(rst_i.negedge_event());
|
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
while(curr_clk.read() == SC_ZERO_TIME) {
|
2021-08-16 16:59:23 +02:00
|
|
|
wait(curr_clk.value_changed_event());
|
2018-07-13 20:04:07 +02:00
|
|
|
}
|
2023-05-02 11:13:25 +02:00
|
|
|
quantum_keeper.reset();
|
2018-07-13 20:04:07 +02:00
|
|
|
cpu->set_interrupt_execution(false);
|
2023-10-22 23:19:09 +02:00
|
|
|
cpu->start(dump_ir);
|
2023-10-29 17:06:56 +01:00
|
|
|
} while(cpu->get_interrupt_execution());
|
2018-07-13 20:04:07 +02:00
|
|
|
sc_stop();
|
2017-10-04 10:31:11 +02:00
|
|
|
}
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
bool core_complex::read_mem(uint64_t addr, unsigned length, uint8_t* const data, bool is_fetch) {
|
|
|
|
auto& dmi_lut = is_fetch ? fetch_lut : read_lut;
|
2023-05-04 21:59:31 +02:00
|
|
|
auto lut_entry = dmi_lut.getEntry(addr);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && addr + length <= lut_entry.get_end_address() + 1) {
|
2017-10-04 10:31:11 +02:00
|
|
|
auto offset = addr - lut_entry.get_start_address();
|
|
|
|
std::copy(lut_entry.get_dmi_ptr() + offset, lut_entry.get_dmi_ptr() + offset + length, data);
|
2023-10-27 21:12:49 +02:00
|
|
|
if(is_fetch)
|
2023-10-29 17:06:56 +01:00
|
|
|
ibus_inc += lut_entry.get_read_latency() / curr_clk;
|
2023-10-27 21:12:49 +02:00
|
|
|
else
|
2023-10-29 17:06:56 +01:00
|
|
|
dbus_inc += lut_entry.get_read_latency() / curr_clk;
|
2017-10-04 10:31:11 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
2023-10-29 17:06:56 +01:00
|
|
|
auto& sckt = is_fetch ? ibus : dbus;
|
2017-10-04 10:31:11 +02:00
|
|
|
tlm::tlm_generic_payload gp;
|
|
|
|
gp.set_command(tlm::TLM_READ_COMMAND);
|
|
|
|
gp.set_address(addr);
|
|
|
|
gp.set_data_ptr(data);
|
|
|
|
gp.set_data_length(length);
|
2017-11-10 22:40:24 +01:00
|
|
|
gp.set_streaming_width(length);
|
2023-10-29 17:06:56 +01:00
|
|
|
sc_time delay = quantum_keeper.get_local_time();
|
|
|
|
if(trc->m_db != nullptr && trc->tr_handle.is_valid()) {
|
|
|
|
if(is_fetch && trc->tr_handle.is_active()) {
|
2021-07-27 09:38:05 +02:00
|
|
|
trc->tr_handle.end_transaction();
|
2017-11-27 00:15:20 +01:00
|
|
|
}
|
2021-07-27 09:38:05 +02:00
|
|
|
auto preExt = new tlm::scc::scv::tlm_recording_extension(trc->tr_handle, this);
|
2017-10-22 19:29:37 +02:00
|
|
|
gp.set_extension(preExt);
|
|
|
|
}
|
2023-10-27 21:12:49 +02:00
|
|
|
auto pre_delay = delay;
|
|
|
|
dbus->b_transport(gp, delay);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(pre_delay > delay) {
|
2023-10-27 21:12:49 +02:00
|
|
|
quantum_keeper.reset();
|
|
|
|
} else {
|
2023-10-29 17:06:56 +01:00
|
|
|
auto incr = (delay - quantum_keeper.get_local_time()) / curr_clk;
|
2023-10-27 21:12:49 +02:00
|
|
|
if(is_fetch)
|
2023-10-29 17:06:56 +01:00
|
|
|
ibus_inc += incr;
|
2023-10-27 21:12:49 +02:00
|
|
|
else
|
2023-10-29 17:06:56 +01:00
|
|
|
dbus_inc += incr;
|
2023-10-27 21:12:49 +02:00
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
SCCTRACE(this->name()) << "[local time: " << delay << "]: finish read_mem(0x" << std::hex << addr << ") : 0x"
|
|
|
|
<< (length == 4 ? *(uint32_t*)data : length == 2 ? *(uint16_t*)data : (unsigned)*data);
|
|
|
|
if(gp.get_response_status() != tlm::TLM_OK_RESPONSE) {
|
2017-10-04 10:31:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
if(gp.is_dmi_allowed() && !GET_PROP_VALUE(disable_dmi)) {
|
2017-10-04 10:31:11 +02:00
|
|
|
gp.set_command(tlm::TLM_READ_COMMAND);
|
|
|
|
gp.set_address(addr);
|
|
|
|
tlm_dmi_ext dmi_data;
|
2023-10-29 17:06:56 +01:00
|
|
|
if(sckt->get_direct_mem_ptr(gp, dmi_data)) {
|
|
|
|
if(dmi_data.is_read_allowed())
|
|
|
|
dmi_lut.addEntry(dmi_data, dmi_data.get_start_address(), dmi_data.get_end_address() - dmi_data.get_start_address() + 1);
|
2017-10-04 10:31:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
bool core_complex::write_mem(uint64_t addr, unsigned length, const uint8_t* const data) {
|
2017-10-04 10:31:11 +02:00
|
|
|
auto lut_entry = write_lut.getEntry(addr);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(lut_entry.get_granted_access() != tlm::tlm_dmi::DMI_ACCESS_NONE && addr + length <= lut_entry.get_end_address() + 1) {
|
2017-10-04 10:31:11 +02:00
|
|
|
auto offset = addr - lut_entry.get_start_address();
|
|
|
|
std::copy(data, data + length, lut_entry.get_dmi_ptr() + offset);
|
2023-10-29 17:06:56 +01:00
|
|
|
dbus_inc += lut_entry.get_write_latency() / curr_clk;
|
2017-10-04 10:31:11 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
write_buf.resize(length);
|
|
|
|
std::copy(data, data + length, write_buf.begin()); // need to copy as TLM does not guarantee data integrity
|
|
|
|
tlm::tlm_generic_payload gp;
|
|
|
|
gp.set_command(tlm::TLM_WRITE_COMMAND);
|
|
|
|
gp.set_address(addr);
|
|
|
|
gp.set_data_ptr(write_buf.data());
|
|
|
|
gp.set_data_length(length);
|
2017-11-10 22:40:24 +01:00
|
|
|
gp.set_streaming_width(length);
|
2023-10-29 17:06:56 +01:00
|
|
|
sc_time delay = quantum_keeper.get_local_time();
|
|
|
|
if(trc->m_db != nullptr && trc->tr_handle.is_valid()) {
|
2021-07-27 09:38:05 +02:00
|
|
|
auto preExt = new tlm::scc::scv::tlm_recording_extension(trc->tr_handle, this);
|
2017-11-27 00:15:20 +01:00
|
|
|
gp.set_extension(preExt);
|
|
|
|
}
|
2023-10-27 21:12:49 +02:00
|
|
|
auto pre_delay = delay;
|
2023-05-04 21:59:31 +02:00
|
|
|
dbus->b_transport(gp, delay);
|
2023-10-29 17:06:56 +01:00
|
|
|
if(pre_delay > delay)
|
2023-10-27 21:12:49 +02:00
|
|
|
quantum_keeper.reset();
|
|
|
|
else
|
2023-10-29 17:06:56 +01:00
|
|
|
dbus_inc += (delay - quantum_keeper.get_local_time()) / curr_clk;
|
|
|
|
SCCTRACE() << "[local time: " << delay << "]: finish write_mem(0x" << std::hex << addr << ") : 0x"
|
|
|
|
<< (length == 4 ? *(uint32_t*)data : length == 2 ? *(uint16_t*)data : (unsigned)*data);
|
|
|
|
if(gp.get_response_status() != tlm::TLM_OK_RESPONSE) {
|
2017-10-04 10:31:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-10-29 17:06:56 +01:00
|
|
|
if(gp.is_dmi_allowed() && !GET_PROP_VALUE(disable_dmi)) {
|
2017-10-04 10:31:11 +02:00
|
|
|
gp.set_command(tlm::TLM_READ_COMMAND);
|
|
|
|
gp.set_address(addr);
|
|
|
|
tlm_dmi_ext dmi_data;
|
2023-10-29 17:06:56 +01:00
|
|
|
if(dbus->get_direct_mem_ptr(gp, dmi_data)) {
|
|
|
|
if(dmi_data.is_write_allowed())
|
2017-10-04 10:31:11 +02:00
|
|
|
write_lut.addEntry(dmi_data, dmi_data.get_start_address(),
|
|
|
|
dmi_data.get_end_address() - dmi_data.get_start_address() + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
bool core_complex::read_mem_dbg(uint64_t addr, unsigned length, uint8_t* const data) {
|
2023-05-02 11:13:25 +02:00
|
|
|
tlm::tlm_generic_payload gp;
|
|
|
|
gp.set_command(tlm::TLM_READ_COMMAND);
|
|
|
|
gp.set_address(addr);
|
|
|
|
gp.set_data_ptr(data);
|
|
|
|
gp.set_data_length(length);
|
|
|
|
gp.set_streaming_width(length);
|
2023-05-04 21:59:31 +02:00
|
|
|
return dbus->transport_dbg(gp) == length;
|
2017-10-04 10:31:11 +02:00
|
|
|
}
|
|
|
|
|
2023-10-29 17:06:56 +01:00
|
|
|
bool core_complex::write_mem_dbg(uint64_t addr, unsigned length, const uint8_t* const data) {
|
2023-05-02 11:13:25 +02:00
|
|
|
write_buf.resize(length);
|
|
|
|
std::copy(data, data + length, write_buf.begin()); // need to copy as TLM does not guarantee data integrity
|
|
|
|
tlm::tlm_generic_payload gp;
|
|
|
|
gp.set_command(tlm::TLM_WRITE_COMMAND);
|
|
|
|
gp.set_address(addr);
|
|
|
|
gp.set_data_ptr(write_buf.data());
|
|
|
|
gp.set_data_length(length);
|
|
|
|
gp.set_streaming_width(length);
|
2023-05-04 21:59:31 +02:00
|
|
|
return dbus->transport_dbg(gp) == length;
|
2017-09-21 13:13:01 +02:00
|
|
|
}
|
2023-07-09 22:20:50 +02:00
|
|
|
} /* namespace tgfs */
|
2017-09-21 13:13:01 +02:00
|
|
|
} /* namespace sysc */
|