Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ if(WITH_SYSTEM_LLVM)
endif()
endif()

if(NOT TARGET scc-util)
option(WITH_SCP4SCC "Build SCC with SCP compatibility support" ON)
endif()

include(FetchContent)
if(NOT TARGET dbt-rise-core)
FetchContent_Declare(
dbt_rise_core_git
GIT_REPOSITORY "https://github.com/Minres/DBT-RISE-Core.git"
GIT_TAG 6d53b71b9d0062ad3dc0305efd53b58de638f305
GIT_TAG dbd196e96d48d978698df521e5220134500c6854
GIT_SHALLOW OFF
UPDATE_DISCONNECTED NOT ${UPDATE_EXTERNAL_PROJECT} # When enabled, this option causes the update step to be skipped.
)
Expand Down Expand Up @@ -288,6 +292,13 @@ target_link_libraries(decoder_test PUBLIC dbt-rise-riscv)
#
###############################################################################
if(TARGET scc-sysc)
if(NOT WITH_SCP4SCC)
message(FATAL_ERROR
"The dbt-rise-riscv SystemC wrapper requires SCC's SCP compatibility support. "
"Set WITH_SCP4SCC=ON before configuring SCC (before add_subdirectory(scc) "
"or FetchContent_MakeAvailable(scc_git) in the parent project).")
endif()

project(dbt-rise-riscv_sc VERSION 1.0.0)
set(USE_SC_SIGNAL4IRQ OFF CACHE BOOL "Enable the use of sc_signals for interrupt delivery")

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Along with the different ISA implementations there is a wrapper implementing the
For an example take a look at [ https://github.com/Minres/RISCV-VP]( https://github.com/Minres/RISCV-VP).

Last but not least a SystemC wrapper is provided to allow easy integration into SystemC based virtual platforms (e.g. https://github.com/Minres/RISCV-VP).
The SystemC wrapper requires SCP logging support. This is supported by the SCC and only requires setting the option `WITH_SCP4SCC` before adding SCC:


Since DBT-RISE uses a generative approach other needed combinations or custom extension can be generated. For further information please do not hesitate to contact [info@minres.com](mailto:info@minres.com).

Expand Down
6 changes: 4 additions & 2 deletions contrib/generate_custom_cores.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ esac
[[ -d $ROOT_DIR/build/TGC-GEN ]] || (cd build; git clone --recursive -b develop https://git.minres.com/TGFS/TGC-GEN.git )

# Generate standard cores
for core in RV32I RV32IMAC RV32GC RV64I RV64GC; do
for core in RV32I RV32IMAC RV32GC RV64I RV64IMAC RV64GC; do
for backend in ${BACKENDS}; do
${SCRIPTDIR}/generate_iss.sh -o ${OUTPUT_ROOT} -t ${TMPL_DIR} -m src -c $core -b ${backend} ${TMPL_DIR}/../../gen_input/cores.core_desc
done
#python3 ${SCRIPTDIR}/update_cycle_yaml.py -i ${OUTPUT_ROOT}/contrib/instr/${core}_instr.yaml -o ${OUTPUT_ROOT}/contrib/instr/${core}_fast.yaml -s fast
#python3 ${SCRIPTDIR}/update_cycle_yaml.py -i ${OUTPUT_ROOT}/contrib/instr/${core}_instr.yaml -o ${OUTPUT_ROOT}/contrib/instr/${core}_slow.yaml -s slow
done
for core in RV32GCV RV64GCV; do
${SCRIPTDIR}/generate_iss.sh -o ${OUTPUT_ROOT} -t ${TMPL_DIR} -m src -c $core -b interp ${TMPL_DIR}/../../gen_input/cores.core_desc
for backend in ${BACKENDS}; do
${SCRIPTDIR}/generate_iss.sh -o ${OUTPUT_ROOT} -t ${TMPL_DIR} -m src -c $core -b ${backend} ${TMPL_DIR}/../../gen_input/cores.core_desc
done
#python3 ${SCRIPTDIR}/update_cycle_yaml.py -i ${OUTPUT_ROOT}/contrib/instr/${core}_instr.yaml -o ${OUTPUT_ROOT}/contrib/instr/${core}_fast.yaml -s fast
#python3 ${SCRIPTDIR}/update_cycle_yaml.py -i ${OUTPUT_ROOT}/contrib/instr/${core}_instr.yaml -o ${OUTPUT_ROOT}/contrib/instr/${core}_slow.yaml -s slow
done
Expand Down
19 changes: 9 additions & 10 deletions gen_input/templates/asmjit/CORENAME.cpp.gtl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public:
using code_word_t = typename super::code_word_t;
using mem_type_e = typename super::mem_type_e;
using addr_t = typename super::addr_t;
using reg_t = typename traits::reg_t;


<%if(vector) {%>
static constexpr auto& vlseg = softvec_if::vlseg<traits::VLEN>;
Expand Down Expand Up @@ -272,14 +274,14 @@ private:
compile_func op;
};

const std::array<instruction_descriptor, ${instructions.size()}> instr_descr = {{
static constexpr std::array<instruction_descriptor, ${instructions.size()}> instr_descr = {{
/* entries are: size, valid value, valid mask, function ptr */<%instructions.each{instr -> %>
/* instruction ${instr.instruction.name}, encoding '${instr.encoding}' */
{${instr.length}, ${instr.encoding}, ${instr.mask}, &this_class::__${generator.functionName(instr.name)}},<%}%>
}};

//needs to be declared after instr_descr
decoder instr_decoder;
decoder<reg_t, traits::INSTR_ALIGNMENT> instr_decoder;

/* instruction definitions */<%instructions.eachWithIndex{instr, idx -> %>
/* instruction ${idx}: ${instr.name} */
Expand Down Expand Up @@ -353,13 +355,10 @@ template <typename ARCH>
vm_impl<ARCH>::vm_impl(ARCH &core, unsigned core_id, unsigned cluster_id)
: vm_base<ARCH>(core, core_id, cluster_id)
, instr_decoder([this]() {
std::vector<generic_instruction_descriptor> g_instr_descr;
g_instr_descr.reserve(instr_descr.size());
for (uint32_t i = 0; i < instr_descr.size(); ++i) {
generic_instruction_descriptor new_instr_descr {instr_descr[i].value, instr_descr[i].mask, i};
g_instr_descr.push_back(new_instr_descr);
}
return std::move(g_instr_descr);
std::array<generic_instruction_descriptor, instr_descr.size()> g_instr_descr;
for (uint32_t i = 0; i < instr_descr.size(); ++i)
g_instr_descr[i] = {instr_descr[i].value, instr_descr[i].mask, i};
return g_instr_descr;
}()) {}

template <typename ARCH>
Expand All @@ -372,7 +371,7 @@ continuation_e vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, jit_hold
return ILLEGAL_FETCH;
if (instr == 0x0000006f || (instr&0xffff)==0xa001)
return JUMP_TO_SELF;
uint32_t inst_index = instr_decoder.decode_instr(instr);
uint32_t inst_index = instr_decoder.decode_instr_cached(pc.val, instr);
compile_func f = nullptr;
if(inst_index < instr_descr.size())
f = instr_descr[inst_index].op;
Expand Down
17 changes: 7 additions & 10 deletions gen_input/templates/interp/CORENAME.cpp.gtl
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ private:
typename arch::traits<ARCH>::opcode_e op;
};

const std::array<instruction_descriptor, ${instructions.size()}> instr_descr = {{
static constexpr std::array<instruction_descriptor, ${instructions.size()}> instr_descr = {{
/* entries are: size, valid value, valid mask, function ptr */<%instructions.each{instr -> %>
{${instr.length}, ${instr.encoding}, ${instr.mask}, arch::traits<ARCH>::opcode_e::${instr.instruction.name}},<%}%>
}};

//needs to be declared after instr_descr
decoder instr_decoder;
decoder<reg_t, traits::INSTR_ALIGNMENT> instr_decoder;

iss::status fetch_ins(virt_addr_t pc, uint8_t * data){
if (this->core.read({iss::address_type::LOGICAL, pc.access, arch::traits<ARCH>::IMEM, pc.val}, 4, data) != iss::Ok)
Expand Down Expand Up @@ -323,13 +323,10 @@ template <typename ARCH>
vm_impl<ARCH>::vm_impl(ARCH &core, unsigned core_id, unsigned cluster_id)
: vm_base<ARCH>(core, core_id, cluster_id)
, instr_decoder([this]() {
std::vector<generic_instruction_descriptor> g_instr_descr;
g_instr_descr.reserve(instr_descr.size());
for (uint32_t i = 0; i < instr_descr.size(); ++i) {
generic_instruction_descriptor new_instr_descr {instr_descr[i].value, instr_descr[i].mask, i};
g_instr_descr.push_back(new_instr_descr);
}
return std::move(g_instr_descr);
std::array<generic_instruction_descriptor, instr_descr.size()> g_instr_descr;
for (uint32_t i = 0; i < instr_descr.size(); ++i)
g_instr_descr[i] = {instr_descr[i].value, instr_descr[i].mask, i};
return g_instr_descr;
}()) {
// std::ofstream json_out{"idecode_tree.json"};
// json_out<<instr_decoder.print_tree_as_pretty_json();
Expand Down Expand Up @@ -375,7 +372,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
} else {
if (is_jump_to_self_enabled(cond) &&
(instr == 0x0000006f || (instr&0xffff)==0xa001)) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
uint32_t inst_index = instr_decoder.decode_instr(instr);
uint32_t inst_index = instr_decoder.decode_instr_cached(pc.val, instr);
opcode_e inst_id = arch::traits<ARCH>::opcode_e::MAX_OPCODE;;
if(inst_index <instr_descr.size())
inst_id = instr_descr[inst_index].op;
Expand Down
19 changes: 9 additions & 10 deletions gen_input/templates/llvm/CORENAME.cpp.gtl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public:
using phys_addr_t = typename super::phys_addr_t;
using code_word_t = typename super::code_word_t;
using addr_t = typename super::addr_t;
using reg_t = typename traits::reg_t;


vm_impl();

Expand Down Expand Up @@ -172,14 +174,14 @@ private:
compile_func op;
};

const std::array<instruction_descriptor, ${instructions.size()}> instr_descr = {{
static constexpr std::array<instruction_descriptor, ${instructions.size()}> instr_descr = {{
/* entries are: size, valid value, valid mask, function ptr */<%instructions.each{instr -> %>
/* instruction ${instr.instruction.name}, encoding '${instr.encoding}' */
{${instr.length}, ${instr.encoding}, ${instr.mask}, &this_class::__${generator.functionName(instr.name)}},<%}%>
}};

//needs to be declared after instr_descr
decoder instr_decoder;
decoder<reg_t, traits::INSTR_ALIGNMENT> instr_decoder;

/* instruction definitions */<%instructions.eachWithIndex{instr, idx -> %>
/* instruction ${idx}: ${instr.name} */
Expand Down Expand Up @@ -257,13 +259,10 @@ template <typename ARCH>
vm_impl<ARCH>::vm_impl(ARCH &core, unsigned core_id, unsigned cluster_id)
: vm_base<ARCH>(core, core_id, cluster_id)
, instr_decoder([this]() {
std::vector<generic_instruction_descriptor> g_instr_descr;
g_instr_descr.reserve(instr_descr.size());
for (uint32_t i = 0; i < instr_descr.size(); ++i) {
generic_instruction_descriptor new_instr_descr {instr_descr[i].value, instr_descr[i].mask, i};
g_instr_descr.push_back(new_instr_descr);
}
return std::move(g_instr_descr);
std::array<generic_instruction_descriptor, instr_descr.size()> g_instr_descr;
for (uint32_t i = 0; i < instr_descr.size(); ++i)
g_instr_descr[i] = {instr_descr[i].value, instr_descr[i].mask, i};
return g_instr_descr;
}()) {}

template <typename ARCH>
Expand All @@ -280,7 +279,7 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, BasicBlock *this_block)
this->builder.CreateBr(this->leave_blk);
return std::make_tuple(JUMP_TO_SELF, nullptr);
}
uint32_t inst_index = instr_decoder.decode_instr(instr);
uint32_t inst_index = instr_decoder.decode_instr_cached(pc.val, instr);
compile_func f = nullptr;
if(inst_index < instr_descr.size())
f = instr_descr[inst_index].op;
Expand Down
24 changes: 12 additions & 12 deletions src/decoder_test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <array>
#include <cstdint>
#include <fstream>
#include <iss/instruction_decoder.h>
#include <limits>
#include <vector>

enum class opcode_e {
Expand All @@ -18,26 +20,24 @@ struct instruction_descriptor {
opcode_e op;
};

const std::array<instruction_descriptor, 2> instr_descr = {{//{16, 0b1000000000000000, 0b1111110000000011, opcode_e::C__LBU},
{16, 0b1000010000000000, 0b1111110001000011, opcode_e::C__LHU},
{16, 0b1000010001000000, 0b1111110001000011, opcode_e::C__LH}}};
static constexpr std::array<instruction_descriptor, 2> instr_descr = {{//{16, 0b1000000000000000, 0b1111110000000011, opcode_e::C__LBU},
{16, 0b1000010000000000, 0b1111110001000011, opcode_e::C__LHU},
{16, 0b1000010001000000, 0b1111110001000011, opcode_e::C__LH}}};

int main(int argc, char* argv[]) {
iss::decoder instr_decoder([]() {
iss::decoder<uint64_t, 2> instr_decoder(nonstd::span{[]() {
std::vector<iss::generic_instruction_descriptor> g_instr_descr;
g_instr_descr.reserve(instr_descr.size());
for(uint32_t i = 0; i < instr_descr.size(); ++i) {
iss::generic_instruction_descriptor new_instr_descr{instr_descr[i].value, instr_descr[i].mask, i};
g_instr_descr.push_back(new_instr_descr);
}
return std::move(g_instr_descr);
}());
for(uint32_t i = 0; i < instr_descr.size(); ++i)
g_instr_descr.emplace_back(iss::generic_instruction_descriptor{instr_descr[i].value, instr_descr[i].mask, i});
return g_instr_descr;
}()});

std::ofstream json_out{"idecode_tree.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);
auto inst_index1 = instr_decoder.decode_instr_cached(0, 0x8440);
auto inst_index2 = instr_decoder.decode_instr_cached(0, 0x86b0);

return inst_index1 == inst_index2 ? 0 : 1;
}
29 changes: 15 additions & 14 deletions src/sysc/core2sc_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <iss/mem/memory_if.h>
#include <iss/vm_types.h>
#include <scc/async_event.h>
#include <scc/report.h>
#include <scp/report.h>
#include <shared_mutex>
#include <sysc/kernel/sc_simcontext.h>
#include <sysc/kernel/sc_time.h>
Expand Down Expand Up @@ -180,10 +180,10 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
static CONSTEXPR char const* fmt_str = sizeof(reg_t) == 4 ? "[disass] 0x{:08x} {:40} [p:{};s:0x{:02x};i:{};c:{}]"
: "[disass] 0x{:012x} {:40} [p:{};s:0x{:04x};i:{};c:{}]";
if(printpc) {
SCCINFO(owner->hier_name()) << fmt::format(fmt_str, pc, str, this->lvl[this->reg.PRIV], (reg_t)this->state.mstatus,
this->reg.icount, this->reg.cycle + this->cycle_offset);
SCP_INFO(()) << fmt::format(fmt_str, pc, str, this->lvl[this->reg.PRIV], (reg_t)this->state.mstatus, this->reg.icount,
this->reg.cycle + this->cycle_offset);
} else {
SCCINFO(owner->hier_name()) << "[disass] " << str;
SCP_INFO(()) << "[disass] " << str;
}
};
void no_disass(uint64_t pc, std::string const& str, bool printpc) { return; };
Expand Down Expand Up @@ -216,8 +216,8 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
SCCERR(owner->hier_name()) << "tohost value is 0x" << std::hex << payload_addr << std::dec << " (" << payload_addr
<< "), stopping simulation";
} else {
SCCINFO(owner->hier_name())
<< "tohost value is 0x" << std::hex << payload_addr << std::dec << " (" << payload_addr << "), stopping simulation";
SCP_INFO(()) << "tohost value is 0x" << std::hex << payload_addr << std::dec << " (" << payload_addr
<< "), stopping simulation";
}
this->reg.trap_state = std::numeric_limits<uint32_t>::max();
this->interrupt_sim = payload_addr;
Expand Down Expand Up @@ -269,7 +269,7 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
if(this->reg.trap_state)
return;
// now wait until something is happening
SCCDEBUG(owner->hier_name()) << "Sleeping until interrupt";
SCP_DEBUG(()) << "Sleeping until interrupt";
wfi_inst.store(true, std::memory_order_relaxed);
std::function<void(void)> f = [this]() {
auto start = sc_core::sc_time_stamp();
Expand All @@ -279,12 +279,12 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
if(is_debugger_stop_evt)
break;
}
SCCDEBUG(this->owner->hier_name()) << "Got WFI event";
SCP_DEBUG(()) << "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;
SCCDEBUG(owner->hier_name()) << "Increasing cycles by " << cycles << " after WFI";
SCP_DEBUG(()) << "Increasing cycles by " << cycles << " after WFI";
}
owner->qk_reset(this->instr_if.get_total_cycles());
};
Expand All @@ -294,7 +294,7 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if

void cancel_wait() {
if(wfi_inst.load(std::memory_order_relaxed) == true) {
SCCDEBUG(owner->hier_name()) << "Trigger debugger stop event";
SCP_DEBUG(()) << "Trigger debugger stop event";
this->debugger_stop_evt.notify(sc_core::SC_ZERO_TIME);
}
}
Expand Down Expand Up @@ -345,11 +345,11 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
this->mip_csr &= ~mask;
this->check_interrupt();
if(value)
SCCTRACE(owner->hier_name()) << "Triggering interrupt " << id
SCP_TRACE(()) << "Triggering interrupt " << id
#ifndef NDEBUG
<< " (Pending trap: " << std::hex << "0x"
<< ((this->reg.pending_trap >> 16) & 0xff) // 0x80 << 24 | (cause << 16) | trap_id
<< ")"
<< " (Pending trap: " << std::hex << "0x"
<< ((this->reg.pending_trap >> 16) & 0xff) // 0x80 << 24 | (cause << 16) | trap_id
<< ")"
#endif
;
} else if(clic_ptr) { // CLIC mode
Expand Down Expand Up @@ -390,6 +390,7 @@ template <typename PLAT> class core2sc_adapter : public PLAT, public sc2core_if
}

sysc::riscv::core_complex_if* const owner{nullptr};
SCP_LOGGER(owner->hier_name());
util::LoggerDelegate log_delegate;
sc_core::sc_event wfi_evt;
sc_core::sc_event debugger_stop_evt;
Expand Down
Loading
Loading