Compare commits

..

No commits in common. "a45fcd28db032099aaa24b3a6472f957cbe3c4b9" and "c28e8fd00c9c58472cf9495737c20034e3390723" have entirely different histories.

9 changed files with 877 additions and 937 deletions

View File

@ -38,9 +38,7 @@
#include <asmjit/asmjit.h> #include <asmjit/asmjit.h>
#include <util/logging.h> #include <util/logging.h>
#include <iss/instruction_decoder.h> #include <iss/instruction_decoder.h>
<%def fcsr = registers.find {it.name=='FCSR'}
if(fcsr != null) {%>
#include <vm/fp_functions.h><%}%>
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
@ -90,6 +88,7 @@ protected:
using super::write_reg_to_mem; using super::write_reg_to_mem;
using super::gen_read_mem; using super::gen_read_mem;
using super::gen_write_mem; using super::gen_write_mem;
using super::gen_wait;
using super::gen_leave; using super::gen_leave;
using super::gen_sync; using super::gen_sync;
@ -101,9 +100,7 @@ protected:
void gen_block_prologue(jit_holder& jh) override; void gen_block_prologue(jit_holder& jh) override;
void gen_block_epilogue(jit_holder& jh) override; void gen_block_epilogue(jit_holder& jh) override;
inline const char *name(size_t index){return traits::reg_aliases.at(index);} inline const char *name(size_t index){return traits::reg_aliases.at(index);}
<%if(fcsr != null) {%>
inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";}
<%}%>
void gen_instr_prologue(jit_holder& jh); void gen_instr_prologue(jit_holder& jh);
void gen_instr_epilogue(jit_holder& jh); void gen_instr_epilogue(jit_holder& jh);
inline void gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t cause); inline void gen_raise(jit_holder& jh, uint16_t trap_id, uint16_t cause);
@ -116,9 +113,6 @@ protected:
auto sign_mask = 1ULL<<(W-1); auto sign_mask = 1ULL<<(W-1);
return (from & mask) | ((from & sign_mask) ? ~mask : 0); return (from & mask) | ((from & sign_mask) ? ~mask : 0);
} }
<%functions.each{ it.eachLine { %>
${it}<%}%>
<%}%>
private: private:
/**************************************************************************** /****************************************************************************
* start opcode definitions * start opcode definitions
@ -201,7 +195,7 @@ private:
gen_raise(jh, 0, 2); gen_raise(jh, 0, 2);
gen_sync(jh, POST_SYNC, instr_descr.size()); gen_sync(jh, POST_SYNC, instr_descr.size());
gen_instr_epilogue(jh); gen_instr_epilogue(jh);
return ILLEGAL_INSTR; return BRANCH;
} }
}; };
@ -230,9 +224,9 @@ continuation_e vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned
paddr = this->core.virt2phys(pc); paddr = this->core.virt2phys(pc);
auto res = this->core.read(paddr, 4, data); auto res = this->core.read(paddr, 4, data);
if (res != iss::Ok) if (res != iss::Ok)
return ILLEGAL_FETCH; throw trap_access(TRAP_ID, pc.val);
if (instr == 0x0000006f || (instr&0xffff)==0xa001) if (instr == 0x0000006f || (instr&0xffff)==0xa001)
return JUMP_TO_SELF; throw simulation_stopped(0); // 'J 0' or 'C.J 0'
++inst_cnt; ++inst_cnt;
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
compile_func f = nullptr; compile_func f = nullptr;

View File

@ -267,7 +267,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
opcode_e inst_id = arch::traits<ARCH>::opcode_e::MAX_OPCODE;; opcode_e inst_id = arch::traits<ARCH>::opcode_e::MAX_OPCODE;;
if(inst_index <instr_descr.size()) if(inst_index <instr_descr.size())
inst_id = instr_descr[inst_index].op; inst_id = instr_descr.at(instr_decoder.decode_instr(instr)).op;
// pre execution stuff // pre execution stuff
this->core.reg.last_branch = 0; this->core.reg.last_branch = 0;
@ -279,7 +279,6 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
<%}%>if(this->disass_enabled){ <%}%>if(this->disass_enabled){
/* generate console output when executing the command */<%instr.disass.eachLine{%> /* generate console output when executing the command */<%instr.disass.eachLine{%>
${it}<%}%> ${it}<%}%>
this->core.disass_output(pc.val, mnemonic);
} }
// used registers<%instr.usedVariables.each{ k,v-> // used registers<%instr.usedVariables.each{ k,v->
if(v.isArray) {%> if(v.isArray) {%>

View File

@ -37,9 +37,7 @@
#include <iss/llvm/vm_base.h> #include <iss/llvm/vm_base.h>
#include <util/logging.h> #include <util/logging.h>
#include <iss/instruction_decoder.h> #include <iss/instruction_decoder.h>
<%def fcsr = registers.find {it.name=='FCSR'}
if(fcsr != null) {%>
#include <vm/fp_functions.h><%}%>
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
@ -85,9 +83,7 @@ protected:
using vm_base<ARCH>::get_reg_ptr; using vm_base<ARCH>::get_reg_ptr;
inline const char *name(size_t index){return traits::reg_aliases.at(index);} inline const char *name(size_t index){return traits::reg_aliases.at(index);}
<%if(fcsr != null) {%>
inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";}
<%}%>
template <typename T> inline ConstantInt *size(T type) { template <typename T> inline ConstantInt *size(T type) {
return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits())); return ConstantInt::get(getContext(), APInt(32, type->getType()->getScalarSizeInBits()));
} }
@ -135,9 +131,7 @@ protected:
auto sign_mask = 1ULL<<(W-1); auto sign_mask = 1ULL<<(W-1);
return (from & mask) | ((from & sign_mask) ? ~mask : 0); return (from & mask) | ((from & sign_mask) ? ~mask : 0);
} }
<%functions.each{ it.eachLine { %>
${it}<%}%>
<%}%>
private: private:
/**************************************************************************** /****************************************************************************
* start opcode definitions * start opcode definitions
@ -218,7 +212,7 @@ private:
bb = this->leave_blk; bb = this->leave_blk;
this->gen_instr_epilogue(bb); this->gen_instr_epilogue(bb);
this->builder.CreateBr(bb); this->builder.CreateBr(bb);
return std::make_tuple(ILLEGAL_INSTR, nullptr); return std::make_tuple(BRANCH, nullptr);
} }
}; };
@ -253,11 +247,19 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
auto *const data = (uint8_t *)&instr; auto *const data = (uint8_t *)&instr;
if(this->core.has_mmu()) if(this->core.has_mmu())
paddr = this->core.virt2phys(pc); paddr = this->core.virt2phys(pc);
//TODO: re-add page handling
// if ((pc.val & upper_bits) != ((pc.val + 2) & upper_bits)) { // we may cross a page boundary
// auto res = this->core.read(paddr, 2, data);
// if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
// if ((instr & 0x3) == 0x3) { // this is a 32bit instruction
// res = this->core.read(this->core.v2p(pc + 2), 2, data + 2);
// }
// } else {
auto res = this->core.read(paddr, 4, data); auto res = this->core.read(paddr, 4, data);
if (res != iss::Ok) if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
return std::make_tuple(ILLEGAL_FETCH, nullptr); // }
if (instr == 0x0000006f || (instr&0xffff)==0xa001) if (instr == 0x0000006f || (instr&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
return std::make_tuple(JUMP_TO_SELF, nullptr); // curr pc on stack
++inst_cnt; ++inst_cnt;
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
compile_func f = nullptr; compile_func f = nullptr;

View File

@ -38,9 +38,7 @@
#include <util/logging.h> #include <util/logging.h>
#include <sstream> #include <sstream>
#include <iss/instruction_decoder.h> #include <iss/instruction_decoder.h>
<%def fcsr = registers.find {it.name=='FCSR'}
if(fcsr != null) {%>
#include <vm/fp_functions.h><%}%>
#ifndef FMT_HEADER_ONLY #ifndef FMT_HEADER_ONLY
#define FMT_HEADER_ONLY #define FMT_HEADER_ONLY
#endif #endif
@ -87,12 +85,7 @@ protected:
using compile_func = compile_ret_t (this_class::*)(virt_addr_t &pc, code_word_t instr, tu_builder&); using compile_func = compile_ret_t (this_class::*)(virt_addr_t &pc, code_word_t instr, tu_builder&);
inline const char *name(size_t index){return traits::reg_aliases.at(index);} inline const char *name(size_t index){return traits::reg_aliases.at(index);}
<%
if(fcsr != null) {%>
inline const char *fname(size_t index){return index < 32?name(index+traits::F0):"illegal";}
void add_prologue(tu_builder& tu) override;
<%}%>
void setup_module(std::string m) override { void setup_module(std::string m) override {
super::setup_module(m); super::setup_module(m);
} }
@ -105,6 +98,8 @@ if(fcsr != null) {%>
void gen_leave_trap(tu_builder& tu, unsigned lvl); void gen_leave_trap(tu_builder& tu, unsigned lvl);
void gen_wait(tu_builder& tu, unsigned type);
inline void gen_set_tval(tu_builder& tu, uint64_t new_tval); inline void gen_set_tval(tu_builder& tu, uint64_t new_tval);
inline void gen_set_tval(tu_builder& tu, value new_tval); inline void gen_set_tval(tu_builder& tu, value new_tval);
@ -138,9 +133,6 @@ if(fcsr != null) {%>
return (from & mask) | ((from & sign_mask) ? ~mask : 0); return (from & mask) | ((from & sign_mask) ? ~mask : 0);
} }
<%functions.each{ it.eachLine { %>
${it}<%}%>
<%}%>
private: private:
/**************************************************************************** /****************************************************************************
* start opcode definitions * start opcode definitions
@ -171,7 +163,6 @@ private:
<%}%>if(this->disass_enabled){ <%}%>if(this->disass_enabled){
/* generate console output when executing the command */<%instr.disass.eachLine{%> /* generate console output when executing the command */<%instr.disass.eachLine{%>
${it}<%}%> ${it}<%}%>
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ ${instr.length/8}; pc=pc+ ${instr.length/8};
@ -196,11 +187,11 @@ private:
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction")); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction"));
} }
pc = pc + ((instr & 3) == 3 ? 4 : 2); pc = pc + ((instr & 3) == 3 ? 4 : 2);
gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise_trap(tu, 0, 2); // illegal instruction trap
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size()); vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size());
vm_impl::gen_trap_check(tu); vm_impl::gen_trap_check(tu);
return ILLEGAL_INSTR; return BRANCH;
} }
}; };
@ -233,11 +224,19 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
phys_addr_t paddr(pc); phys_addr_t paddr(pc);
if(this->core.has_mmu()) if(this->core.has_mmu())
paddr = this->core.virt2phys(pc); paddr = this->core.virt2phys(pc);
//TODO: re-add page handling
// if ((pc.val & upper_bits) != ((pc.val + 2) & upper_bits)) { // we may cross a page boundary
// auto res = this->core.read(paddr, 2, data);
// if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
// if ((insn & 0x3) == 0x3) { // this is a 32bit instruction
// res = this->core.read(this->core.v2p(pc + 2), 2, data + 2);
// }
// } else {
auto res = this->core.read(paddr, 4, reinterpret_cast<uint8_t*>(&instr)); auto res = this->core.read(paddr, 4, reinterpret_cast<uint8_t*>(&instr));
if (res != iss::Ok) if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
return ILLEGAL_FETCH; // }
if (instr == 0x0000006f || (instr&0xffff)==0xa001) if (instr == 0x0000006f || (instr&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
return JUMP_TO_SELF; // curr pc on stack
++inst_cnt; ++inst_cnt;
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
compile_func f = nullptr; compile_func f = nullptr;
@ -259,6 +258,9 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(tu_builder& tu, unsi
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP), 32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP), 32));
} }
template <typename ARCH> void vm_impl<ARCH>::gen_wait(tu_builder& tu, unsigned type) {
}
template <typename ARCH> void vm_impl<ARCH>::gen_set_tval(tu_builder& tu, uint64_t new_tval) { template <typename ARCH> void vm_impl<ARCH>::gen_set_tval(tu_builder& tu, uint64_t new_tval) {
tu(fmt::format("tval = {};", new_tval)); tu(fmt::format("tval = {};", new_tval));
} }
@ -273,39 +275,6 @@ template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(tu_builder& tu) {
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP),32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP),32));
tu("return *next_pc;"); tu("return *next_pc;");
} }
<%
if(fcsr != null) {%>
template <typename ARCH> void vm_impl<ARCH>::add_prologue(tu_builder& tu){
std::ostringstream os;
os << "uint32_t (*fget_flags)()=" << (uintptr_t)&fget_flags << ";\\n";
os << "uint32_t (*fadd_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fadd_s << ";\\n";
os << "uint32_t (*fsub_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fsub_s << ";\\n";
os << "uint32_t (*fmul_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fmul_s << ";\\n";
os << "uint32_t (*fdiv_s)(uint32_t v1, uint32_t v2, uint8_t mode)=" << (uintptr_t)&fdiv_s << ";\\n";
os << "uint32_t (*fsqrt_s)(uint32_t v1, uint8_t mode)=" << (uintptr_t)&fsqrt_s << ";\\n";
os << "uint32_t (*fcmp_s)(uint32_t v1, uint32_t v2, uint32_t op)=" << (uintptr_t)&fcmp_s << ";\\n";
os << "uint32_t (*fcvt_s)(uint32_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_s << ";\\n";
os << "uint32_t (*fmadd_s)(uint32_t v1, uint32_t v2, uint32_t v3, uint32_t op, uint8_t mode)=" << (uintptr_t)&fmadd_s << ";\\n";
os << "uint32_t (*fsel_s)(uint32_t v1, uint32_t v2, uint32_t op)=" << (uintptr_t)&fsel_s << ";\\n";
os << "uint32_t (*fclass_s)( uint32_t v1 )=" << (uintptr_t)&fclass_s << ";\\n";
os << "uint32_t (*fconv_d2f)(uint64_t v1, uint8_t mode)=" << (uintptr_t)&fconv_d2f << ";\\n";
os << "uint64_t (*fconv_f2d)(uint32_t v1, uint8_t mode)=" << (uintptr_t)&fconv_f2d << ";\\n";
os << "uint64_t (*fadd_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fadd_d << ";\\n";
os << "uint64_t (*fsub_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fsub_d << ";\\n";
os << "uint64_t (*fmul_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fmul_d << ";\\n";
os << "uint64_t (*fdiv_d)(uint64_t v1, uint64_t v2, uint8_t mode)=" << (uintptr_t)&fdiv_d << ";\\n";
os << "uint64_t (*fsqrt_d)(uint64_t v1, uint8_t mode)=" << (uintptr_t)&fsqrt_d << ";\\n";
os << "uint64_t (*fcmp_d)(uint64_t v1, uint64_t v2, uint32_t op)=" << (uintptr_t)&fcmp_d << ";\\n";
os << "uint64_t (*fcvt_d)(uint64_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_d << ";\\n";
os << "uint64_t (*fmadd_d)(uint64_t v1, uint64_t v2, uint64_t v3, uint32_t op, uint8_t mode)=" << (uintptr_t)&fmadd_d << ";\\n";
os << "uint64_t (*fsel_d)(uint64_t v1, uint64_t v2, uint32_t op)=" << (uintptr_t)&fsel_d << ";\\n";
os << "uint64_t (*fclass_d)(uint64_t v1 )=" << (uintptr_t)&fclass_d << ";\\n";
os << "uint64_t (*fcvt_32_64)(uint32_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_32_64 << ";\\n";
os << "uint32_t (*fcvt_64_32)(uint64_t v1, uint32_t op, uint8_t mode)=" << (uintptr_t)&fcvt_64_32 << ";\\n";
os << "uint32_t (*unbox_s)(uint64_t v)=" << (uintptr_t)&unbox_s << ";\\n";
tu.add_prologue(os.str());
}
<%}%>
} // namespace ${coreDef.name.toLowerCase()} } // namespace ${coreDef.name.toLowerCase()}

View File

@ -69,8 +69,7 @@ int main(int argc, char* argv[]) {
("logfile,l", po::value<std::string>(), "Sets default log file.") ("logfile,l", po::value<std::string>(), "Sets default log file.")
("disass,d", po::value<std::string>()->implicit_value(""), "Enables disassembly") ("disass,d", po::value<std::string>()->implicit_value(""), "Enables disassembly")
("gdb-port,g", po::value<unsigned>()->default_value(0), "enable gdb server and specify port to use") ("gdb-port,g", po::value<unsigned>()->default_value(0), "enable gdb server and specify port to use")
("ilimit,i", po::value<uint64_t>()->default_value(std::numeric_limits<uint64_t>::max()), "max. number of instructions to simulate") ("instructions,i", po::value<uint64_t>()->default_value(std::numeric_limits<uint64_t>::max()), "max. number of instructions to simulate")
("flimit", po::value<uint64_t>()->default_value(std::numeric_limits<uint64_t>::max()), "max. number of fetches to simulate")
("reset,r", po::value<std::string>(), "reset address") ("reset,r", po::value<std::string>(), "reset address")
("dump-ir", "dump the intermediate representation") ("dump-ir", "dump the intermediate representation")
("elf,f", po::value<std::vector<std::string>>(), "ELF file(s) to load") ("elf,f", po::value<std::vector<std::string>>(), "ELF file(s) to load")
@ -216,15 +215,8 @@ int main(int argc, char* argv[]) {
start_address = str.find("0x") == 0 ? std::stoull(str.substr(2), nullptr, 16) : std::stoull(str, nullptr, 10); start_address = str.find("0x") == 0 ? std::stoull(str.substr(2), nullptr, 16) : std::stoull(str, nullptr, 10);
} }
vm->reset(start_address); vm->reset(start_address);
auto limit = clim["ilimit"].as<uint64_t>(); auto cycles = clim["instructions"].as<uint64_t>();
auto cond = iss::finish_cond_e::JUMP_TO_SELF; res = vm->start(cycles, dump);
if(clim.count("flimit")) {
cond = cond | iss::finish_cond_e::FCOUNT_LIMIT;
limit = clim["flimit"].as<uint64_t>();
} else {
cond = cond | iss::finish_cond_e::ICOUNT_LIMIT;
}
res = vm->start(limit, dump, cond);
auto instr_if = vm->get_arch()->get_instrumentation_if(); auto instr_if = vm->get_arch()->get_instrumentation_if();
// this assumes a single input file // this assumes a single input file

View File

@ -88,6 +88,7 @@ protected:
using super::write_reg_to_mem; using super::write_reg_to_mem;
using super::gen_read_mem; using super::gen_read_mem;
using super::gen_write_mem; using super::gen_write_mem;
using super::gen_wait;
using super::gen_leave; using super::gen_leave;
using super::gen_sync; using super::gen_sync;
@ -112,7 +113,6 @@ protected:
auto sign_mask = 1ULL<<(W-1); auto sign_mask = 1ULL<<(W-1);
return (from & mask) | ((from & sign_mask) ? ~mask : 0); return (from & mask) | ((from & sign_mask) ? ~mask : 0);
} }
private: private:
/**************************************************************************** /****************************************************************************
* start opcode definitions * start opcode definitions
@ -500,7 +500,6 @@ private:
(gen_operation(cc, band, (gen_operation(cc, add, load_reg_from_mem(jh, traits::X0 + rs1), (int16_t)sext<12>(imm)) (gen_operation(cc, band, (gen_operation(cc, add, load_reg_from_mem(jh, traits::X0 + rs1), (int16_t)sext<12>(imm))
), addr_mask) ), addr_mask)
), 32, true); ), 32, true);
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, urem, new_pc, static_cast<uint32_t>(traits::INSTR_ALIGNMENT)) cmp(cc, gen_operation(cc, urem, new_pc, static_cast<uint32_t>(traits::INSTR_ALIGNMENT))
,0); ,0);
@ -523,7 +522,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 3); gen_sync(jh, POST_SYNC, 3);
@ -568,7 +566,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) cmp(cc, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2))
,0); ,0);
@ -587,7 +584,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 4); gen_sync(jh, POST_SYNC, 4);
@ -632,7 +628,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2))
,0); ,0);
@ -651,7 +646,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 5); gen_sync(jh, POST_SYNC, 5);
@ -696,7 +690,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, lt, gen_ext(cc, cmp(cc, gen_operation(cc, lt, gen_ext(cc,
load_reg_from_mem(jh, traits::X0 + rs1), 32, false), gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs1), 32, false), gen_ext(cc,
@ -717,7 +710,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 6); gen_sync(jh, POST_SYNC, 6);
@ -762,7 +754,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, gte, gen_ext(cc, cmp(cc, gen_operation(cc, gte, gen_ext(cc,
load_reg_from_mem(jh, traits::X0 + rs1), 32, false), gen_ext(cc, load_reg_from_mem(jh, traits::X0 + rs1), 32, false), gen_ext(cc,
@ -783,7 +774,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 7); gen_sync(jh, POST_SYNC, 7);
@ -828,7 +818,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ltu, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) cmp(cc, gen_operation(cc, ltu, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2))
,0); ,0);
@ -847,7 +836,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 8); gen_sync(jh, POST_SYNC, 8);
@ -892,7 +880,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, gteu, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2)) cmp(cc, gen_operation(cc, gteu, load_reg_from_mem(jh, traits::X0 + rs1), load_reg_from_mem(jh, traits::X0 + rs2))
,0); ,0);
@ -911,7 +898,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 9); gen_sync(jh, POST_SYNC, 9);
@ -2378,7 +2364,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "ecall"; std::string mnemonic = "ecall";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -2415,7 +2401,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "ebreak"; std::string mnemonic = "ebreak";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -2452,7 +2438,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "mret"; std::string mnemonic = "mret";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -2489,7 +2475,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "wfi"; std::string mnemonic = "wfi";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -2511,10 +2497,7 @@ private:
gen_instr_prologue(jh); gen_instr_prologue(jh);
cc.comment("//behavior:"); cc.comment("//behavior:");
/*generate behavior*/ /*generate behavior*/
InvokeNode* call_wait; gen_wait(jh, 1);
jh.cc.comment("//call_wait");
jh.cc.invoke(&call_wait, &wait, FuncSignature::build<void, int32_t>());
setArg(call_wait, 0, 1);
auto returnValue = CONT; auto returnValue = CONT;
gen_sync(jh, POST_SYNC, 41); gen_sync(jh, POST_SYNC, 41);
@ -3133,7 +3116,6 @@ private:
auto divisor = gen_ext(cc, auto divisor = gen_ext(cc,
load_reg_from_mem(jh, traits::X0 + rs2), 32, true); load_reg_from_mem(jh, traits::X0 + rs2), 32, true);
if(rd!=0){ if(rd!=0){
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ne, divisor, 0) cmp(cc, gen_operation(cc, ne, divisor, 0)
,0); ,0);
@ -3141,7 +3123,6 @@ private:
cc.je(label_else); cc.je(label_else);
{ {
auto MMIN = ((uint32_t)1)<<(static_cast<uint32_t>(traits::XLEN)-1); auto MMIN = ((uint32_t)1)<<(static_cast<uint32_t>(traits::XLEN)-1);
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, land, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), MMIN) cmp(cc, gen_operation(cc, land, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), MMIN)
, gen_operation(cc, eq, divisor, - 1) , gen_operation(cc, eq, divisor, - 1)
@ -3163,7 +3144,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
cc.jmp(label_merge); cc.jmp(label_merge);
cc.bind(label_else); cc.bind(label_else);
{ {
@ -3173,7 +3153,6 @@ private:
cc.bind(label_merge); cc.bind(label_merge);
} }
} }
}
auto returnValue = CONT; auto returnValue = CONT;
gen_sync(jh, POST_SYNC, 53); gen_sync(jh, POST_SYNC, 53);
@ -3217,7 +3196,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0) cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0)
,0); ,0);
@ -3240,7 +3218,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = CONT; auto returnValue = CONT;
gen_sync(jh, POST_SYNC, 54); gen_sync(jh, POST_SYNC, 54);
@ -3284,7 +3261,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0) cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0)
,0); ,0);
@ -3292,7 +3268,6 @@ private:
cc.je(label_else); cc.je(label_else);
{ {
auto MMIN = (uint32_t)1<<(static_cast<uint32_t>(traits::XLEN)-1); auto MMIN = (uint32_t)1<<(static_cast<uint32_t>(traits::XLEN)-1);
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, land, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), MMIN) cmp(cc, gen_operation(cc, land, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1), MMIN)
, gen_operation(cc, eq, gen_ext(cc, , gen_operation(cc, eq, gen_ext(cc,
@ -3322,7 +3297,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
cc.jmp(label_merge); cc.jmp(label_merge);
cc.bind(label_else); cc.bind(label_else);
{ {
@ -3333,7 +3307,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = CONT; auto returnValue = CONT;
gen_sync(jh, POST_SYNC, 55); gen_sync(jh, POST_SYNC, 55);
@ -3377,7 +3350,6 @@ private:
gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise(jh, 0, static_cast<int32_t>(traits::RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
else{ else{
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0) cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs2), 0)
,0); ,0);
@ -3400,7 +3372,6 @@ private:
} }
cc.bind(label_merge); cc.bind(label_merge);
} }
}
auto returnValue = CONT; auto returnValue = CONT;
gen_sync(jh, POST_SYNC, 56); gen_sync(jh, POST_SYNC, 56);
@ -3417,7 +3388,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.addi4spn"), "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c__addi4spn"),
fmt::arg("rd", name(8+rd)), fmt::arg("imm", imm)); fmt::arg("rd", name(8+rd)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3465,7 +3436,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c.lw"), "{mnemonic:10} {rd}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c__lw"),
fmt::arg("rd", name(8+rd)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1))); fmt::arg("rd", name(8+rd)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3511,7 +3482,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs2}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c.sw"), "{mnemonic:10} {rs2}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c__sw"),
fmt::arg("rs2", name(8+rs2)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1))); fmt::arg("rs2", name(8+rs2)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3554,7 +3525,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.addi"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__addi"),
fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3601,8 +3572,8 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "c.nop"; std::string mnemonic = "c__nop";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
jh.disass_collection.push_back(mnemonic_ptr); jh.disass_collection.push_back(mnemonic_ptr);
@ -3638,7 +3609,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.jal"), "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c__jal"),
fmt::arg("imm", imm)); fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3682,7 +3653,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.li"), "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c__li"),
fmt::arg("rd", name(rd)), fmt::arg("imm", imm)); fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3729,7 +3700,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.lui"), "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c__lui"),
fmt::arg("rd", name(rd)), fmt::arg("imm", imm)); fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3773,7 +3744,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {nzimm:#05x}", fmt::arg("mnemonic", "c.addi16sp"), "{mnemonic:10} {nzimm:#05x}", fmt::arg("mnemonic", "c__addi16sp"),
fmt::arg("nzimm", nzimm)); fmt::arg("nzimm", nzimm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3818,8 +3789,8 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = ".reserved_clui"; std::string mnemonic = "__reserved_clui";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
jh.disass_collection.push_back(mnemonic_ptr); jh.disass_collection.push_back(mnemonic_ptr);
@ -3857,7 +3828,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.srli"), "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c__srli"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt)); fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3898,7 +3869,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.srai"), "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c__srai"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt)); fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3952,7 +3923,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.andi"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__andi"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -3994,7 +3965,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.sub"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__sub"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4036,7 +4007,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.xor"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__xor"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4077,7 +4048,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.or"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__or"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4118,7 +4089,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.and"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__and"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4158,7 +4129,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.j"), "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c__j"),
fmt::arg("imm", imm)); fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4200,7 +4171,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.beqz"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__beqz"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4223,7 +4194,6 @@ private:
cc.comment("//behavior:"); cc.comment("//behavior:");
/*generate behavior*/ /*generate behavior*/
mov(jh.cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(NO_JUMP)); mov(jh.cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(NO_JUMP));
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1+8), 0) cmp(cc, gen_operation(cc, eq, load_reg_from_mem(jh, traits::X0 + rs1+8), 0)
,0); ,0);
@ -4234,7 +4204,6 @@ private:
mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(KNOWN_JUMP)); mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(KNOWN_JUMP));
} }
cc.bind(label_merge); cc.bind(label_merge);
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 75); gen_sync(jh, POST_SYNC, 75);
@ -4251,7 +4220,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.bnez"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__bnez"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4274,7 +4243,6 @@ private:
cc.comment("//behavior:"); cc.comment("//behavior:");
/*generate behavior*/ /*generate behavior*/
mov(jh.cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(NO_JUMP)); mov(jh.cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(NO_JUMP));
{
auto label_merge = cc.newLabel(); auto label_merge = cc.newLabel();
cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs1+8), 0) cmp(cc, gen_operation(cc, ne, load_reg_from_mem(jh, traits::X0 + rs1+8), 0)
,0); ,0);
@ -4285,7 +4253,6 @@ private:
mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(KNOWN_JUMP)); mov(cc, get_ptr_for(jh, traits::LAST_BRANCH), static_cast<int>(KNOWN_JUMP));
} }
cc.bind(label_merge); cc.bind(label_merge);
}
auto returnValue = BRANCH; auto returnValue = BRANCH;
gen_sync(jh, POST_SYNC, 76); gen_sync(jh, POST_SYNC, 76);
@ -4302,7 +4269,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {nzuimm}", fmt::arg("mnemonic", "c.slli"), "{mnemonic:10} {rs1}, {nzuimm}", fmt::arg("mnemonic", "c__slli"),
fmt::arg("rs1", name(rs1)), fmt::arg("nzuimm", nzuimm)); fmt::arg("rs1", name(rs1)), fmt::arg("nzuimm", nzuimm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4350,7 +4317,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, sp, {uimm:#05x}", fmt::arg("mnemonic", "c.lwsp"), "{mnemonic:10} {rd}, sp, {uimm:#05x}", fmt::arg("mnemonic", "c__lwsp"),
fmt::arg("rd", name(rd)), fmt::arg("uimm", uimm)); fmt::arg("rd", name(rd)), fmt::arg("uimm", uimm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4400,7 +4367,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.mv"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__mv"),
fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2))); fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4446,7 +4413,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c.jr"), "{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c__jr"),
fmt::arg("rs1", name(rs1))); fmt::arg("rs1", name(rs1)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4492,8 +4459,8 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = ".reserved_cmv"; std::string mnemonic = "__reserved_cmv";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
jh.disass_collection.push_back(mnemonic_ptr); jh.disass_collection.push_back(mnemonic_ptr);
@ -4531,7 +4498,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.add"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__add"),
fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2))); fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4579,7 +4546,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c.jalr"), "{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c__jalr"),
fmt::arg("rs1", name(rs1))); fmt::arg("rs1", name(rs1)));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4628,8 +4595,8 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "c.ebreak"; std::string mnemonic = "c__ebreak";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
jh.disass_collection.push_back(mnemonic_ptr); jh.disass_collection.push_back(mnemonic_ptr);
@ -4667,7 +4634,7 @@ private:
/* generate disass */ /* generate disass */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs2}, {uimm:#05x}(sp)", fmt::arg("mnemonic", "c.swsp"), "{mnemonic:10} {rs2}, {uimm:#05x}(sp)", fmt::arg("mnemonic", "c__swsp"),
fmt::arg("rs2", name(rs2)), fmt::arg("uimm", uimm)); fmt::arg("rs2", name(rs2)), fmt::arg("uimm", uimm));
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4712,7 +4679,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate disass */ /* generate disass */
//No disass specified, using instruction name //This disass is not yet implemented
std::string mnemonic = "dii"; std::string mnemonic = "dii";
InvokeNode* call_print_disass; InvokeNode* call_print_disass;
char* mnemonic_ptr = strdup(mnemonic.c_str()); char* mnemonic_ptr = strdup(mnemonic.c_str());
@ -4768,7 +4735,7 @@ private:
gen_raise(jh, 0, 2); gen_raise(jh, 0, 2);
gen_sync(jh, POST_SYNC, instr_descr.size()); gen_sync(jh, POST_SYNC, instr_descr.size());
gen_instr_epilogue(jh); gen_instr_epilogue(jh);
return ILLEGAL_INSTR; return BRANCH;
} }
}; };
@ -4797,9 +4764,9 @@ continuation_e vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned
paddr = this->core.virt2phys(pc); paddr = this->core.virt2phys(pc);
auto res = this->core.read(paddr, 4, data); auto res = this->core.read(paddr, 4, data);
if (res != iss::Ok) if (res != iss::Ok)
return ILLEGAL_FETCH; throw trap_access(TRAP_ID, pc.val);
if (instr == 0x0000006f || (instr&0xffff)==0xa001) if (instr == 0x0000006f || (instr&0xffff)==0xa001)
return JUMP_TO_SELF; throw simulation_stopped(0); // 'J 0' or 'C.J 0'
++inst_cnt; ++inst_cnt;
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
compile_func f = nullptr; compile_func f = nullptr;

View File

@ -343,7 +343,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
opcode_e inst_id = arch::traits<ARCH>::opcode_e::MAX_OPCODE;; opcode_e inst_id = arch::traits<ARCH>::opcode_e::MAX_OPCODE;;
if(inst_index <instr_descr.size()) if(inst_index <instr_descr.size())
inst_id = instr_descr[inst_index].op; inst_id = instr_descr.at(instr_decoder.decode_instr(instr)).op;
// pre execution stuff // pre execution stuff
this->core.reg.last_branch = 0; this->core.reg.last_branch = 0;
@ -1458,9 +1458,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::ECALL: { case arch::traits<ARCH>::opcode_e::ECALL: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "ecall");
std::string mnemonic = "ecall";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 4; *NEXT_PC = *PC + 4;
@ -1473,9 +1471,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::EBREAK: { case arch::traits<ARCH>::opcode_e::EBREAK: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "ebreak");
std::string mnemonic = "ebreak";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 4; *NEXT_PC = *PC + 4;
@ -1488,9 +1484,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::MRET: { case arch::traits<ARCH>::opcode_e::MRET: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "mret");
std::string mnemonic = "mret";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 4; *NEXT_PC = *PC + 4;
@ -1503,9 +1497,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::WFI: { case arch::traits<ARCH>::opcode_e::WFI: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "wfi");
std::string mnemonic = "wfi";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 4; *NEXT_PC = *PC + 4;
@ -1729,7 +1721,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {rd}, {imm}", fmt::arg("mnemonic", "fence_i"), "{mnemonic:10} {rs1}, {rd}, {imm}", fmt::arg("mnemonic", "fence.i"),
fmt::arg("rs1", name(rs1)), fmt::arg("rd", name(rd)), fmt::arg("imm", imm)); fmt::arg("rs1", name(rs1)), fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
this->core.disass_output(pc.val, mnemonic); this->core.disass_output(pc.val, mnemonic);
} }
@ -2103,9 +2095,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
uint8_t nzimm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5)); uint8_t nzimm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "c.nop");
std::string mnemonic = "c.nop";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 2; *NEXT_PC = *PC + 2;
@ -2211,9 +2201,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rd = ((bit_sub<7,5>(instr)));
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, ".reserved_clui");
std::string mnemonic = ".reserved_clui";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 2; *NEXT_PC = *PC + 2;
@ -2532,9 +2520,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::__reserved_cmv: { case arch::traits<ARCH>::opcode_e::__reserved_cmv: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, ".reserved_cmv");
std::string mnemonic = ".reserved_cmv";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 2; *NEXT_PC = *PC + 2;
@ -2600,9 +2586,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::C__EBREAK: { case arch::traits<ARCH>::opcode_e::C__EBREAK: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "c.ebreak");
std::string mnemonic = "c.ebreak";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 2; *NEXT_PC = *PC + 2;
@ -2641,9 +2625,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co
case arch::traits<ARCH>::opcode_e::DII: { case arch::traits<ARCH>::opcode_e::DII: {
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name this->core.disass_output(pc.val, "dii");
std::string mnemonic = "dii";
this->core.disass_output(pc.val, mnemonic);
} }
// used registers// calculate next pc value // used registers// calculate next pc value
*NEXT_PC = *PC + 2; *NEXT_PC = *PC + 2;

File diff suppressed because it is too large Load Diff

View File

@ -98,6 +98,8 @@ protected:
void gen_leave_trap(tu_builder& tu, unsigned lvl); void gen_leave_trap(tu_builder& tu, unsigned lvl);
void gen_wait(tu_builder& tu, unsigned type);
inline void gen_set_tval(tu_builder& tu, uint64_t new_tval); inline void gen_set_tval(tu_builder& tu, uint64_t new_tval);
inline void gen_set_tval(tu_builder& tu, value new_tval); inline void gen_set_tval(tu_builder& tu, value new_tval);
@ -131,7 +133,6 @@ protected:
return (from & mask) | ((from & sign_mask) ? ~mask : 0); return (from & mask) | ((from & sign_mask) ? ~mask : 0);
} }
private: private:
/**************************************************************************** /****************************************************************************
* start opcode definitions * start opcode definitions
@ -349,7 +350,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)((int32_t)imm),32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)((int32_t)imm),32));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -384,7 +386,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+(int32_t)imm),32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)(PC+(int32_t)imm),32));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -425,7 +428,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+4),32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)(PC+4),32));
} }
auto PC_val_v = tu.assignment("PC_val", new_pc,32); auto PC_val_v = tu.assignment("PC_val", new_pc,32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
@ -478,7 +482,8 @@ private:
this->gen_raise_trap(tu, 0, 0); this->gen_raise_trap(tu, 0, 0);
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)(PC+4),32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)(PC+4),32));
} }
auto PC_val_v = tu.assignment("PC_val", new_pc,32); auto PC_val_v = tu.assignment("PC_val", new_pc,32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
@ -804,7 +809,8 @@ private:
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 8),8,true),8); auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 8),8,true),8);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext(res,32,false)); tu.store(rd + traits::X0,
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -844,7 +850,8 @@ private:
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 16),16,true),16); auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 16),16,true),16);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext(res,32,false)); tu.store(rd + traits::X0,
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -884,7 +891,8 @@ private:
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 32),32,true),32); auto res = tu.assignment(tu.ext(tu.read_mem(traits::MEM, load_address, 32),32,true),32);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext(res,32,false)); tu.store(rd + traits::X0,
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -924,7 +932,8 @@ private:
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 8),8); auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 8),8);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext(res,32,false)); tu.store(rd + traits::X0,
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -964,7 +973,8 @@ private:
tu.constant((int16_t)sext<12>(imm),16))),32,false),32); tu.constant((int16_t)sext<12>(imm),16))),32,false),32);
auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 16),16); auto res = tu.assignment(tu.read_mem(traits::MEM, load_address, 16),16);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext(res,32,false)); tu.store(rd + traits::X0,
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -1111,7 +1121,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.add( tu.store(rd + traits::X0,
tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant((int16_t)sext<12>(imm),16))),32,false)); tu.constant((int16_t)sext<12>(imm),16))),32,false));
} }
@ -1149,7 +1160,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_SLT, tu.store(rd + traits::X0,
tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_SLT,
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.constant((int16_t)sext<12>(imm),16))), tu.constant(1,8),tu.constant(0,8))); tu.constant((int16_t)sext<12>(imm),16))), tu.constant(1,8),tu.constant(0,8)));
} }
@ -1187,7 +1199,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_ULT, tu.store(rd + traits::X0,
tu.conditionalAssignment((tu.icmp(ICmpInst::ICMP_ULT,
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))), tu.constant(1,8),tu.constant(0,8))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))), tu.constant(1,8),tu.constant(0,8)));
} }
@ -1225,7 +1238,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.bitwise_xor( tu.store(rd + traits::X0,
tu.bitwise_xor(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
@ -1263,7 +1277,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.bitwise_or( tu.store(rd + traits::X0,
tu.bitwise_or(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
@ -1301,7 +1316,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.bitwise_and( tu.store(rd + traits::X0,
tu.bitwise_and(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant((uint32_t)((int16_t)sext<12>(imm)),32))); tu.constant((uint32_t)((int16_t)sext<12>(imm)),32)));
} }
@ -1339,7 +1355,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.shl( tu.store(rd + traits::X0,
tu.shl(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant(shamt,8))); tu.constant(shamt,8)));
} }
@ -1377,7 +1394,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.lshr( tu.store(rd + traits::X0,
tu.lshr(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant(shamt,8))); tu.constant(shamt,8)));
} }
@ -1415,7 +1433,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.ashr( tu.store(rd + traits::X0,
tu.ext((tu.ashr(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.constant(shamt,8))),32,false)); tu.constant(shamt,8))),32,false));
} }
@ -1453,7 +1472,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.add( tu.store(rd + traits::X0,
tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false)); tu.load(rs2+ traits::X0, 0))),32,false));
} }
@ -1491,7 +1511,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.sub( tu.store(rd + traits::X0,
tu.ext((tu.sub(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false)); tu.load(rs2+ traits::X0, 0))),32,false));
} }
@ -1529,7 +1550,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.shl( tu.store(rd + traits::X0,
tu.shl(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
(tu.bitwise_and( (tu.bitwise_and(
tu.load(rs2+ traits::X0, 0), tu.load(rs2+ traits::X0, 0),
@ -1569,7 +1591,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_SLT, tu.store(rd + traits::X0,
tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_SLT,
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ traits::X0, 0),32,true)), tu.constant(1,8),tu.constant(0,8))); tu.ext(tu.load(rs2+ traits::X0, 0),32,true)), tu.constant(1,8),tu.constant(0,8)));
} }
@ -1607,7 +1630,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_ULT, tu.store(rd + traits::X0,
tu.conditionalAssignment(tu.icmp(ICmpInst::ICMP_ULT,
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)), tu.constant(1,8),tu.constant(0,8))); tu.load(rs2+ traits::X0, 0)), tu.constant(1,8),tu.constant(0,8)));
} }
@ -1645,7 +1669,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.bitwise_xor( tu.store(rd + traits::X0,
tu.bitwise_xor(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2+ traits::X0, 0)));
} }
@ -1683,7 +1708,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.lshr( tu.store(rd + traits::X0,
tu.lshr(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
(tu.bitwise_and( (tu.bitwise_and(
tu.load(rs2+ traits::X0, 0), tu.load(rs2+ traits::X0, 0),
@ -1723,7 +1749,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.ashr( tu.store(rd + traits::X0,
tu.ext((tu.ashr(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
(tu.bitwise_and( (tu.bitwise_and(
tu.load(rs2+ traits::X0, 0), tu.load(rs2+ traits::X0, 0),
@ -1763,7 +1790,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.bitwise_or( tu.store(rd + traits::X0,
tu.bitwise_or(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2+ traits::X0, 0)));
} }
@ -1801,7 +1829,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.bitwise_and( tu.store(rd + traits::X0,
tu.bitwise_and(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2+ traits::X0, 0)));
} }
@ -1852,9 +1881,7 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "ecall");
std::string mnemonic = "ecall";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 4; pc=pc+ 4;
@ -1878,9 +1905,7 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "ebreak");
std::string mnemonic = "ebreak";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 4; pc=pc+ 4;
@ -1904,9 +1929,7 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "mret");
std::string mnemonic = "mret";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 4; pc=pc+ 4;
@ -1930,16 +1953,14 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "wfi");
std::string mnemonic = "wfi";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 4; pc=pc+ 4;
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.callf("wait", tu.constant(1,8)); this->gen_wait(tu, 1);
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -1975,7 +1996,8 @@ private:
auto xrs1 = tu.assignment(tu.load(rs1+ traits::X0, 0),32); auto xrs1 = tu.assignment(tu.load(rs1+ traits::X0, 0),32);
if(rd!=0){ auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32); if(rd!=0){ auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32);
tu.write_mem(traits::CSR, csr, xrs1); tu.write_mem(traits::CSR, csr, xrs1);
tu.store(rd + traits::X0, xrd); tu.store(rd + traits::X0,
xrd);
} }
else{ else{
tu.write_mem(traits::CSR, csr, xrs1); tu.write_mem(traits::CSR, csr, xrs1);
@ -2021,7 +2043,8 @@ private:
xrs1)); xrs1));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, xrd); tu.store(rd + traits::X0,
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2064,7 +2087,8 @@ private:
tu.logical_neg(xrs1))); tu.logical_neg(xrs1)));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, xrd); tu.store(rd + traits::X0,
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2102,7 +2126,8 @@ private:
auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32); auto xrd = tu.assignment(tu.read_mem(traits::CSR, csr, 32),32);
tu.write_mem(traits::CSR, csr, tu.constant((uint32_t)zimm,32)); tu.write_mem(traits::CSR, csr, tu.constant((uint32_t)zimm,32));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, xrd); tu.store(rd + traits::X0,
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2144,7 +2169,8 @@ private:
tu.constant((uint32_t)zimm,32))); tu.constant((uint32_t)zimm,32)));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, xrd); tu.store(rd + traits::X0,
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2186,7 +2212,8 @@ private:
tu.constant(~ ((uint32_t)zimm),32))); tu.constant(~ ((uint32_t)zimm),32)));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, xrd); tu.store(rd + traits::X0,
xrd);
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2254,7 +2281,8 @@ private:
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ traits::X0, 0),32,true)),64); tu.ext(tu.load(rs2+ traits::X0, 0),32,true)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext(res,32,false)); tu.store(rd + traits::X0,
tu.ext(res,32,false));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2293,7 +2321,8 @@ private:
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ traits::X0, 0),32,true)),64); tu.ext(tu.load(rs2+ traits::X0, 0),32,true)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.ashr( tu.store(rd + traits::X0,
tu.ext((tu.ashr(
res, res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false)); tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
@ -2334,7 +2363,8 @@ private:
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.load(rs2+ traits::X0, 0)),64); tu.load(rs2+ traits::X0, 0)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.ashr( tu.store(rd + traits::X0,
tu.ext((tu.ashr(
res, res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false)); tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
@ -2375,7 +2405,8 @@ private:
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0)),64); tu.load(rs2+ traits::X0, 0)),64);
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.lshr( tu.store(rd + traits::X0,
tu.ext((tu.lshr(
res, res,
tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false)); tu.constant(static_cast<uint32_t>(traits:: XLEN),32))),32,false));
} }
@ -2425,14 +2456,17 @@ private:
tu.icmp(ICmpInst::ICMP_EQ, tu.icmp(ICmpInst::ICMP_EQ,
divisor, divisor,
tu.constant(- 1,8)))); tu.constant(- 1,8))));
tu.store(rd + traits::X0, tu.constant(MMIN,32)); tu.store(rd + traits::X0,
tu.constant(MMIN,32));
tu.open_else(); tu.open_else();
tu.store(rd + traits::X0, tu.ext((tu.sdiv( tu.store(rd + traits::X0,
tu.ext((tu.sdiv(
dividend, dividend,
divisor)),32,false)); divisor)),32,false));
tu.close_scope(); tu.close_scope();
tu.open_else(); tu.open_else();
tu.store(rd + traits::X0, tu.constant((uint32_t)- 1,32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)- 1,32));
tu.close_scope(); tu.close_scope();
} }
} }
@ -2472,13 +2506,15 @@ private:
tu.load(rs2+ traits::X0, 0), tu.load(rs2+ traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.udiv( tu.store(rd + traits::X0,
tu.udiv(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2+ traits::X0, 0)));
} }
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)- 1,32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)- 1,32));
} }
tu.close_scope(); tu.close_scope();
} }
@ -2526,18 +2562,21 @@ private:
tu.ext(tu.load(rs2+ traits::X0, 0),32,true), tu.ext(tu.load(rs2+ traits::X0, 0),32,true),
tu.constant(- 1,8)))); tu.constant(- 1,8))));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant(0,8)); tu.store(rd + traits::X0,
tu.constant(0,8));
} }
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.srem( tu.store(rd + traits::X0,
tu.ext((tu.srem(
tu.ext(tu.load(rs1+ traits::X0, 0),32,true), tu.ext(tu.load(rs1+ traits::X0, 0),32,true),
tu.ext(tu.load(rs2+ traits::X0, 0),32,true))),32,false)); tu.ext(tu.load(rs2+ traits::X0, 0),32,true))),32,false));
} }
tu.close_scope(); tu.close_scope();
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.load(rs1 + traits::X0, 0)); tu.store(rd + traits::X0,
tu.load(rs1+ traits::X0, 0));
} }
tu.close_scope(); tu.close_scope();
} }
@ -2577,13 +2616,15 @@ private:
tu.load(rs2+ traits::X0, 0), tu.load(rs2+ traits::X0, 0),
tu.constant(0,8))); tu.constant(0,8)));
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.urem( tu.store(rd + traits::X0,
tu.urem(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))); tu.load(rs2+ traits::X0, 0)));
} }
tu.open_else(); tu.open_else();
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.load(rs1 + traits::X0, 0)); tu.store(rd + traits::X0,
tu.load(rs1+ traits::X0, 0));
} }
tu.close_scope(); tu.close_scope();
} }
@ -2605,7 +2646,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.addi4spn"), "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c__addi4spn"),
fmt::arg("rd", name(8+rd)), fmt::arg("imm", imm)); fmt::arg("rd", name(8+rd)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2615,7 +2656,8 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
if(imm) { if(imm) {
tu.store(rd+8 + traits::X0, tu.ext((tu.add( tu.store(rd+8 + traits::X0,
tu.ext((tu.add(
tu.load(2+ traits::X0, 0), tu.load(2+ traits::X0, 0),
tu.constant(imm,16))),32,false)); tu.constant(imm,16))),32,false));
} }
@ -2641,7 +2683,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c.lw"), "{mnemonic:10} {rd}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c__lw"),
fmt::arg("rd", name(8+rd)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1))); fmt::arg("rd", name(8+rd)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2653,7 +2695,8 @@ private:
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8+ traits::X0, 0),
tu.constant(uimm,8))),32,false),32); tu.constant(uimm,8))),32,false),32);
tu.store(rd+8 + traits::X0, tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false)); tu.store(rd+8 + traits::X0,
tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
tu.close_scope(); tu.close_scope();
@ -2673,7 +2716,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs2}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c.sw"), "{mnemonic:10} {rs2}, {uimm:#05x}({rs1})", fmt::arg("mnemonic", "c__sw"),
fmt::arg("rs2", name(8+rs2)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1))); fmt::arg("rs2", name(8+rs2)), fmt::arg("uimm", uimm), fmt::arg("rs1", name(8+rs1)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2704,7 +2747,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.addi"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__addi"),
fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(rs1)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2718,7 +2761,8 @@ private:
} }
else{ else{
if(rs1!=0) { if(rs1!=0) {
tu.store(rs1 + traits::X0, tu.ext((tu.add( tu.store(rs1 + traits::X0,
tu.ext((tu.add(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant((int8_t)sext<6>(imm),8))),32,false)); tu.constant((int8_t)sext<6>(imm),8))),32,false));
} }
@ -2739,9 +2783,7 @@ private:
uint8_t nzimm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5)); uint8_t nzimm = ((bit_sub<2,5>(instr)) | (bit_sub<12,1>(instr) << 5));
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "c__nop");
std::string mnemonic = "c.nop";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 2; pc=pc+ 2;
@ -2765,7 +2807,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.jal"), "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c__jal"),
fmt::arg("imm", imm)); fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2775,7 +2817,8 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(NO_JUMP),32));
tu.store(1 + traits::X0, tu.constant((uint32_t)(PC+2),32)); tu.store(1 + traits::X0,
tu.constant((uint32_t)(PC+2),32));
auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<12>(imm)),32); auto PC_val_v = tu.assignment("PC_val", (uint32_t)(PC+(int16_t)sext<12>(imm)),32);
tu.store(traits::NEXT_PC, PC_val_v); tu.store(traits::NEXT_PC, PC_val_v);
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(KNOWN_JUMP), 2)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(KNOWN_JUMP), 2));
@ -2797,7 +2840,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.li"), "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c__li"),
fmt::arg("rd", name(rd)), fmt::arg("imm", imm)); fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2811,7 +2854,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)((int8_t)sext<6>(imm)),32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)((int8_t)sext<6>(imm)),32));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2832,7 +2876,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c.lui"), "{mnemonic:10} {rd}, {imm:#05x}", fmt::arg("mnemonic", "c__lui"),
fmt::arg("rd", name(rd)), fmt::arg("imm", imm)); fmt::arg("rd", name(rd)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2845,7 +2889,8 @@ private:
this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION)); this->gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION));
} }
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.constant((uint32_t)((int32_t)sext<18>(imm)),32)); tu.store(rd + traits::X0,
tu.constant((uint32_t)((int32_t)sext<18>(imm)),32));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2864,7 +2909,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {nzimm:#05x}", fmt::arg("mnemonic", "c.addi16sp"), "{mnemonic:10} {nzimm:#05x}", fmt::arg("mnemonic", "c__addi16sp"),
fmt::arg("nzimm", nzimm)); fmt::arg("nzimm", nzimm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2874,7 +2919,8 @@ private:
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
if(nzimm) { if(nzimm) {
tu.store(2 + traits::X0, tu.ext((tu.add( tu.store(2 + traits::X0,
tu.ext((tu.add(
tu.load(2+ traits::X0, 0), tu.load(2+ traits::X0, 0),
tu.constant((int16_t)sext<10>(nzimm),16))),32,false)); tu.constant((int16_t)sext<10>(nzimm),16))),32,false));
} }
@ -2897,9 +2943,7 @@ private:
uint8_t rd = ((bit_sub<7,5>(instr))); uint8_t rd = ((bit_sub<7,5>(instr)));
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "__reserved_clui");
std::string mnemonic = ".reserved_clui";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 2; pc=pc+ 2;
@ -2925,7 +2969,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.srli"), "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c__srli"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt)); fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2934,7 +2978,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rs1+8 + traits::X0, tu.lshr( tu.store(rs1+8 + traits::X0,
tu.lshr(
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8+ traits::X0, 0),
tu.constant(shamt,8))); tu.constant(shamt,8)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -2955,7 +3000,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c.srai"), "{mnemonic:10} {rs1}, {shamt}", fmt::arg("mnemonic", "c__srai"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt)); fmt::arg("rs1", name(8+rs1)), fmt::arg("shamt", shamt));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -2964,12 +3009,14 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
if(shamt){ tu.store(rs1+8 + traits::X0, tu.ext((tu.ashr( if(shamt){ tu.store(rs1+8 + traits::X0,
tu.ext((tu.ashr(
(tu.ext(tu.load(rs1+8+ traits::X0, 0),32,true)), (tu.ext(tu.load(rs1+8+ traits::X0, 0),32,true)),
tu.constant(shamt,8))),32,false)); tu.constant(shamt,8))),32,false));
} }
else{ else{
if(static_cast<uint32_t>(traits:: XLEN)==128){ tu.store(rs1+8 + traits::X0, tu.ext((tu.ashr( if(static_cast<uint32_t>(traits:: XLEN)==128){ tu.store(rs1+8 + traits::X0,
tu.ext((tu.ashr(
(tu.ext(tu.load(rs1+8+ traits::X0, 0),32,true)), (tu.ext(tu.load(rs1+8+ traits::X0, 0),32,true)),
tu.constant(64,8))),32,false)); tu.constant(64,8))),32,false));
} }
@ -2992,7 +3039,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.andi"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__andi"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3001,7 +3048,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rs1+8 + traits::X0, tu.ext((tu.bitwise_and( tu.store(rs1+8 + traits::X0,
tu.ext((tu.bitwise_and(
tu.load(rs1+8+ traits::X0, 0), tu.load(rs1+8+ traits::X0, 0),
tu.constant((int8_t)sext<6>(imm),8))),32,false)); tu.constant((int8_t)sext<6>(imm),8))),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3022,7 +3070,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.sub"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__sub"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3031,7 +3079,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.ext((tu.sub( tu.store(rd+8 + traits::X0,
tu.ext((tu.sub(
tu.load(rd+8+ traits::X0, 0), tu.load(rd+8+ traits::X0, 0),
tu.load(rs2+8+ traits::X0, 0))),32,false)); tu.load(rs2+8+ traits::X0, 0))),32,false));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3052,7 +3101,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.xor"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__xor"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3061,7 +3110,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.bitwise_xor( tu.store(rd+8 + traits::X0,
tu.bitwise_xor(
tu.load(rd+8+ traits::X0, 0), tu.load(rd+8+ traits::X0, 0),
tu.load(rs2+8+ traits::X0, 0))); tu.load(rs2+8+ traits::X0, 0)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3082,7 +3132,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.or"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__or"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3091,7 +3141,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.bitwise_or( tu.store(rd+8 + traits::X0,
tu.bitwise_or(
tu.load(rd+8+ traits::X0, 0), tu.load(rd+8+ traits::X0, 0),
tu.load(rs2+8+ traits::X0, 0))); tu.load(rs2+8+ traits::X0, 0)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3112,7 +3163,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.and"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__and"),
fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2))); fmt::arg("rd", name(8+rd)), fmt::arg("rs2", name(8+rs2)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3121,7 +3172,8 @@ private:
gen_set_pc(tu, pc, traits::NEXT_PC); gen_set_pc(tu, pc, traits::NEXT_PC);
tu.open_scope(); tu.open_scope();
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
tu.store(rd+8 + traits::X0, tu.bitwise_and( tu.store(rd+8 + traits::X0,
tu.bitwise_and(
tu.load(rd+8+ traits::X0, 0), tu.load(rd+8+ traits::X0, 0),
tu.load(rs2+8+ traits::X0, 0))); tu.load(rs2+8+ traits::X0, 0)));
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3141,7 +3193,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c.j"), "{mnemonic:10} {imm:#05x}", fmt::arg("mnemonic", "c__j"),
fmt::arg("imm", imm)); fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3172,7 +3224,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.beqz"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__beqz"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3207,7 +3259,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c.bnez"), "{mnemonic:10} {rs1}, {imm:#05x}", fmt::arg("mnemonic", "c__bnez"),
fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm)); fmt::arg("rs1", name(8+rs1)), fmt::arg("imm", imm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3242,7 +3294,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}, {nzuimm}", fmt::arg("mnemonic", "c.slli"), "{mnemonic:10} {rs1}, {nzuimm}", fmt::arg("mnemonic", "c__slli"),
fmt::arg("rs1", name(rs1)), fmt::arg("nzuimm", nzuimm)); fmt::arg("rs1", name(rs1)), fmt::arg("nzuimm", nzuimm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3256,7 +3308,8 @@ private:
} }
else{ else{
if(rs1!=0) { if(rs1!=0) {
tu.store(rs1 + traits::X0, tu.shl( tu.store(rs1 + traits::X0,
tu.shl(
tu.load(rs1+ traits::X0, 0), tu.load(rs1+ traits::X0, 0),
tu.constant(nzuimm,8))); tu.constant(nzuimm,8)));
} }
@ -3279,7 +3332,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, sp, {uimm:#05x}", fmt::arg("mnemonic", "c.lwsp"), "{mnemonic:10} {rd}, sp, {uimm:#05x}", fmt::arg("mnemonic", "c__lwsp"),
fmt::arg("rd", name(rd)), fmt::arg("uimm", uimm)); fmt::arg("rd", name(rd)), fmt::arg("uimm", uimm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3295,7 +3348,8 @@ private:
auto offs = tu.assignment(tu.ext((tu.add( auto offs = tu.assignment(tu.ext((tu.add(
tu.load(2+ traits::X0, 0), tu.load(2+ traits::X0, 0),
tu.constant(uimm,8))),32,false),32); tu.constant(uimm,8))),32,false),32);
tu.store(rd + traits::X0, tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false)); tu.store(rd + traits::X0,
tu.ext(tu.ext(tu.read_mem(traits::MEM, offs, 32),32,true),32,false));
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3315,7 +3369,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.mv"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__mv"),
fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2))); fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3329,7 +3383,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.load(rs2 + traits::X0, 0)); tu.store(rd + traits::X0,
tu.load(rs2+ traits::X0, 0));
} }
} }
auto returnValue = std::make_tuple(CONT); auto returnValue = std::make_tuple(CONT);
@ -3349,7 +3404,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c.jr"), "{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c__jr"),
fmt::arg("rs1", name(rs1))); fmt::arg("rs1", name(rs1)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3384,9 +3439,7 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "__reserved_cmv");
std::string mnemonic = ".reserved_cmv";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 2; pc=pc+ 2;
@ -3412,7 +3465,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c.add"), "{mnemonic:10} {rd}, {rs2}", fmt::arg("mnemonic", "c__add"),
fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2))); fmt::arg("rd", name(rd)), fmt::arg("rs2", name(rs2)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3426,7 +3479,8 @@ private:
} }
else{ else{
if(rd!=0) { if(rd!=0) {
tu.store(rd + traits::X0, tu.ext((tu.add( tu.store(rd + traits::X0,
tu.ext((tu.add(
tu.load(rd+ traits::X0, 0), tu.load(rd+ traits::X0, 0),
tu.load(rs2+ traits::X0, 0))),32,false)); tu.load(rs2+ traits::X0, 0))),32,false));
} }
@ -3448,7 +3502,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c.jalr"), "{mnemonic:10} {rs1}", fmt::arg("mnemonic", "c__jalr"),
fmt::arg("rs1", name(rs1))); fmt::arg("rs1", name(rs1)));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3464,7 +3518,8 @@ private:
else{ else{
auto addr_mask = (uint32_t)- 2; auto addr_mask = (uint32_t)- 2;
auto new_pc = tu.assignment(tu.load(rs1+ traits::X0, 0),32); auto new_pc = tu.assignment(tu.load(rs1+ traits::X0, 0),32);
tu.store(1 + traits::X0, tu.constant((uint32_t)(PC+2),32)); tu.store(1 + traits::X0,
tu.constant((uint32_t)(PC+2),32));
auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and( auto PC_val_v = tu.assignment("PC_val", tu.bitwise_and(
new_pc, new_pc,
tu.constant(addr_mask,32)),32); tu.constant(addr_mask,32)),32);
@ -3486,9 +3541,7 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "c__ebreak");
std::string mnemonic = "c.ebreak";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 2; pc=pc+ 2;
@ -3514,7 +3567,7 @@ private:
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
auto mnemonic = fmt::format( auto mnemonic = fmt::format(
"{mnemonic:10} {rs2}, {uimm:#05x}(sp)", fmt::arg("mnemonic", "c.swsp"), "{mnemonic:10} {rs2}, {uimm:#05x}(sp)", fmt::arg("mnemonic", "c__swsp"),
fmt::arg("rs2", name(rs2)), fmt::arg("uimm", uimm)); fmt::arg("rs2", name(rs2)), fmt::arg("uimm", uimm));
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
@ -3547,9 +3600,7 @@ private:
uint64_t PC = pc.val; uint64_t PC = pc.val;
if(this->disass_enabled){ if(this->disass_enabled){
/* generate console output when executing the command */ /* generate console output when executing the command */
//No disass specified, using instruction name tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, "dii");
std::string mnemonic = "dii";
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, mnemonic);
} }
auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]); auto cur_pc_val = tu.constant(pc.val, traits::reg_bit_widths[traits::PC]);
pc=pc+ 2; pc=pc+ 2;
@ -3575,11 +3626,11 @@ private:
tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction")); tu("print_disass(core_ptr, {:#x}, \"{}\");", pc.val, std::string("illegal_instruction"));
} }
pc = pc + ((instr & 3) == 3 ? 4 : 2); pc = pc + ((instr & 3) == 3 ? 4 : 2);
gen_raise_trap(tu, 0, static_cast<int32_t>(traits:: RV_CAUSE_ILLEGAL_INSTRUCTION)); gen_raise_trap(tu, 0, 2); // illegal instruction trap
this->gen_set_tval(tu, instr); this->gen_set_tval(tu, instr);
vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size()); vm_impl::gen_sync(tu, iss::POST_SYNC, instr_descr.size());
vm_impl::gen_trap_check(tu); vm_impl::gen_trap_check(tu);
return ILLEGAL_INSTR; return BRANCH;
} }
}; };
@ -3612,11 +3663,19 @@ vm_impl<ARCH>::gen_single_inst_behavior(virt_addr_t &pc, unsigned int &inst_cnt,
phys_addr_t paddr(pc); phys_addr_t paddr(pc);
if(this->core.has_mmu()) if(this->core.has_mmu())
paddr = this->core.virt2phys(pc); paddr = this->core.virt2phys(pc);
//TODO: re-add page handling
// if ((pc.val & upper_bits) != ((pc.val + 2) & upper_bits)) { // we may cross a page boundary
// auto res = this->core.read(paddr, 2, data);
// if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
// if ((insn & 0x3) == 0x3) { // this is a 32bit instruction
// res = this->core.read(this->core.v2p(pc + 2), 2, data + 2);
// }
// } else {
auto res = this->core.read(paddr, 4, reinterpret_cast<uint8_t*>(&instr)); auto res = this->core.read(paddr, 4, reinterpret_cast<uint8_t*>(&instr));
if (res != iss::Ok) if (res != iss::Ok) throw trap_access(TRAP_ID, pc.val);
return ILLEGAL_FETCH; // }
if (instr == 0x0000006f || (instr&0xffff)==0xa001) if (instr == 0x0000006f || (instr&0xffff)==0xa001) throw simulation_stopped(0); // 'J 0' or 'C.J 0'
return JUMP_TO_SELF; // curr pc on stack
++inst_cnt; ++inst_cnt;
uint32_t inst_index = instr_decoder.decode_instr(instr); uint32_t inst_index = instr_decoder.decode_instr(instr);
compile_func f = nullptr; compile_func f = nullptr;
@ -3638,6 +3697,9 @@ template <typename ARCH> void vm_impl<ARCH>::gen_leave_trap(tu_builder& tu, unsi
tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP), 32)); tu.store(traits::LAST_BRANCH, tu.constant(static_cast<int>(UNKNOWN_JUMP), 32));
} }
template <typename ARCH> void vm_impl<ARCH>::gen_wait(tu_builder& tu, unsigned type) {
}
template <typename ARCH> void vm_impl<ARCH>::gen_set_tval(tu_builder& tu, uint64_t new_tval) { template <typename ARCH> void vm_impl<ARCH>::gen_set_tval(tu_builder& tu, uint64_t new_tval) {
tu(fmt::format("tval = {};", new_tval)); tu(fmt::format("tval = {};", new_tval));
} }
@ -3653,7 +3715,6 @@ template <typename ARCH> void vm_impl<ARCH>::gen_trap_behavior(tu_builder& tu) {
tu("return *next_pc;"); tu("return *next_pc;");
} }
} // namespace tgc5c } // namespace tgc5c
template <> template <>