diff --git a/gen_input/templates/CORENAME.cpp.gtl b/gen_input/templates/CORENAME.cpp.gtl index ead228a..eae0aa7 100644 --- a/gen_input/templates/CORENAME.cpp.gtl +++ b/gen_input/templates/CORENAME.cpp.gtl @@ -33,7 +33,7 @@ def getRegisterSizes(){ def regs = registers.collect{it.size} regs[-1]=64 // correct for NEXT_PC - regs+=[32, 32, 64, 64, 64, 32] // append TRAP_STATE, PENDING_TRAP, ICOUNT, CYCLE, INSTRET, INSTRUCTION + //regs+=[32, 32, 64, 64, 64, 32] // append TRAP_STATE, PENDING_TRAP, ICOUNT, CYCLE, INSTRET, INSTRUCTION return regs } %> @@ -51,9 +51,7 @@ constexpr std::array iss::arch::traits iss::arch::traits::reg_bit_widths; constexpr std::array iss::arch::traits::reg_byte_offsets; -${coreDef.name.toLowerCase()}::${coreDef.name.toLowerCase()}() { - reg.icount = 0; -} +${coreDef.name.toLowerCase()}::${coreDef.name.toLowerCase()}() = default; ${coreDef.name.toLowerCase()}::~${coreDef.name.toLowerCase()}() = default; @@ -64,8 +62,8 @@ void ${coreDef.name.toLowerCase()}::reset(uint64_t address) { reg.PC=address; reg.NEXT_PC=reg.PC; reg.PRIV=0x3; - reg.trap_state=0; - reg.icount=0; + trap_state=0; + icount=0; } uint8_t *${coreDef.name.toLowerCase()}::get_regs_base_ptr() { diff --git a/gen_input/templates/CORENAME.h.gtl b/gen_input/templates/CORENAME.h.gtl index c114cec..4497ba3 100644 --- a/gen_input/templates/CORENAME.h.gtl +++ b/gen_input/templates/CORENAME.h.gtl @@ -37,7 +37,7 @@ def nativeTypeSize(int size){ } def getRegisterSizes(){ def regs = registers.collect{nativeTypeSize(it.size)} - regs+=[32,32, 64, 64, 64, 32] // append TRAP_STATE, PENDING_TRAP, ICOUNT, CYCLE, INSTRET, INSTRUCTION + // regs+=[32,32, 64, 64, 64, 32] // append TRAP_STATE, PENDING_TRAP, ICOUNT, CYCLE, INSTRET, INSTRUCTION return regs } def getRegisterOffsets(){ @@ -91,13 +91,7 @@ template <> struct traits<${coreDef.name.toLowerCase()}> { constexpr static unsigned FP_REGS_SIZE = ${constants.find {it.name=='FLEN'}?.value?:0}; enum reg_e { - ${registers.collect{it.name}.join(', ')}, NUM_REGS, - TRAP_STATE=NUM_REGS, - PENDING_TRAP, - ICOUNT, - CYCLE, - INSTRET, - INSTRUCTION + ${registers.collect{it.name}.join(', ')}, NUM_REGS }; using reg_t = uint${addrDataWidth}_t; @@ -142,7 +136,7 @@ struct ${coreDef.name.toLowerCase()}: public arch_if { uint8_t* get_regs_base_ptr() override; - inline uint64_t get_icount() { return reg.icount; } + inline uint64_t get_icount() { return icount; } inline bool should_stop() { return interrupt_sim; } @@ -160,7 +154,7 @@ struct ${coreDef.name.toLowerCase()}: public arch_if { virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; } - inline uint32_t get_last_branch() { return reg.last_branch; } + inline uint32_t get_last_branch() { return last_branch; } #pragma pack(push, 1) @@ -168,12 +162,13 @@ struct ${coreDef.name.toLowerCase()}: public arch_if { registers.each { reg -> if(reg.size>0) {%> uint${byteSize(reg.size)}_t ${reg.name} = 0;<% }}%> - uint32_t trap_state = 0, pending_trap = 0; - uint64_t icount = 0; - uint64_t instret = 0; - uint32_t instruction = 0; - uint32_t last_branch; } reg; + uint32_t trap_state = 0, pending_trap = 0; + uint64_t icount = 0; + uint64_t cycle = 0; + uint64_t instret = 0; + uint32_t instruction = 0; + uint32_t last_branch = 0; #pragma pack(pop) std::array addr_mode; diff --git a/gen_input/templates/interp/CORENAME.cpp.gtl b/gen_input/templates/interp/CORENAME.cpp.gtl index 9883e16..76449f6 100644 --- a/gen_input/templates/interp/CORENAME.cpp.gtl +++ b/gen_input/templates/interp/CORENAME.cpp.gtl @@ -121,7 +121,7 @@ protected: inline void raise(uint16_t trap_id, uint16_t cause){ auto trap_val = 0x80ULL << 24 | (cause << 16) | trap_id; - this->template get_reg(traits::TRAP_STATE) = trap_val; + this->core.trap_state = trap_val; this->template get_reg(traits::NEXT_PC) = std::numeric_limits::max(); } @@ -141,39 +141,39 @@ protected: T& pc_assign(T& val){super::ex_info.branch_taken=true; return val;} inline uint8_t readSpace1(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline uint16_t readSpace2(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline uint32_t readSpace4(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline uint64_t readSpace8(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline void writeSpace1(typename super::mem_type_e space, uint64_t addr, uint8_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } inline void writeSpace2(typename super::mem_type_e space, uint64_t addr, uint16_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } inline void writeSpace4(typename super::mem_type_e space, uint64_t addr, uint32_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } inline void writeSpace8(typename super::mem_type_e space, uint64_t addr, uint64_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } template::type> inline S sext(U from) { @@ -278,16 +278,15 @@ typename arch::traits::opcode_e vm_impl::decode_inst_id(code_word_t template typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e cond, virt_addr_t start, uint64_t icount_limit){ auto pc=start; - auto* PC = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::PC]); auto* NEXT_PC = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::NEXT_PC]); - auto* trap_state = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::TRAP_STATE]); - auto* icount = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::ICOUNT]); - auto* instret = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::INSTRET]); - auto *const instruction = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::INSTRUCTION]); + auto& trap_state = this->core.trap_state; + auto& icount = this->core.icount; + auto& cycle = this->core.cycle; + auto& instret = this->core.instret; + auto& instr = this->core.instruction; // we fetch at max 4 byte, alignment is 2 - auto *const data = reinterpret_cast(instruction); - auto& instr = *instruction; + auto *const data = reinterpret_cast(&instr); while(!this->core.should_stop() && !(is_count_limit_enabled(cond) && this->core.get_icount() >= icount_limit)){ @@ -329,16 +328,16 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co process_spawn_blocks(); if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, static_cast(inst_id)); // trap check - if(*trap_state!=0){ - super::core.enter_trap(*trap_state, pc.val, instr); + if(trap_state!=0){ + super::core.enter_trap(trap_state, pc.val, instr); } else { - (*icount)++; - (*instret)++; + icount++; + instret++; } - (*reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::CYCLE]))++; + cycle++; pc.val=*NEXT_PC; this->core.reg.PC = this->core.reg.NEXT_PC; - this->core.reg.trap_state = this->core.reg.pending_trap; + this->core.trap_state = this->core.pending_trap; } } return pc; diff --git a/incl/iss/arch/riscv_hart_m_p.h b/incl/iss/arch/riscv_hart_m_p.h index 7a798bf..52bf1ad 100644 --- a/incl/iss/arch/riscv_hart_m_p.h +++ b/incl/iss/arch/riscv_hart_m_p.h @@ -203,7 +203,7 @@ public: void disass_output(uint64_t pc, const std::string instr) override { CLOG(INFO, disass) << fmt::format("0x{:016x} {:40} [s:0x{:x};c:{}]", - pc, instr, (reg_t)state.mstatus, this->reg.icount + cycle_offset); + pc, instr, (reg_t)state.mstatus, this->icount + cycle_offset); }; iss::instrumentation_if *get_instrumentation_if() override { return &instr_if; } @@ -239,11 +239,11 @@ protected: uint64_t get_next_pc() override { return arch.reg.NEXT_PC; }; - uint64_t get_instr_word() override { return arch.reg.instruction; } + uint64_t get_instr_word() override { return arch.instruction; } - uint64_t get_instr_count() { return arch.reg.icount; } + uint64_t get_instr_count() { return arch.icount; } - uint64_t get_total_cycles() override { return arch.reg.icount + arch.cycle_offset; } + uint64_t get_total_cycles() override { return arch.icount + arch.cycle_offset; } void set_curr_instr_cycles(unsigned cycles) override { arch.cycle_offset += cycles - 1; }; @@ -568,13 +568,13 @@ iss::status riscv_hart_m_p::read(const address_type type, const acce if (unlikely((access == iss::access_type::FETCH || access == iss::access_type::DEBUG_FETCH) && (addr & 0x1) == 1)) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31); // issue trap 0 + this->trap_state = (1 << 31); // issue trap 0 return iss::Err; } try { auto alignment = access == iss::access_type::FETCH? (traits::MISA_VAL&0x100? 2 : 4) : length; if(alignment>1 && (addr&(alignment-1))){ - this->reg.trap_state = 1<<31 | 4<<16; + this->trap_state = 1<<31 | 4<<16; fault_data=addr; return iss::Err; } @@ -593,12 +593,12 @@ iss::status riscv_hart_m_p::read(const address_type type, const acce res = read_mem( phys_addr, length, data); } if (unlikely(res != iss::Ok)){ - this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault + this->trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault fault_data=addr; } return res; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -624,7 +624,7 @@ iss::status riscv_hart_m_p::read(const address_type type, const acce } return iss::Ok; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -662,12 +662,12 @@ iss::status riscv_hart_m_p::write(const address_type type, const acc if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31); // issue trap 0 + this->trap_state = (1 << 31); // issue trap 0 return iss::Err; } try { if(length>1 && (addr&(length-1)) && (access&access_type::DEBUG) != access_type::DEBUG){ - this->reg.trap_state = 1<<31 | 6<<16; + this->trap_state = 1<<31 | 6<<16; fault_data=addr; return iss::Err; } @@ -686,12 +686,12 @@ iss::status riscv_hart_m_p::write(const address_type type, const acc res = write_mem( phys_addr, length, data); } if (unlikely(res != iss::Ok)) { - this->reg.trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) + this->trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) fault_data=addr; } return res; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -751,7 +751,7 @@ iss::status riscv_hart_m_p::write(const address_type type, const acc } return iss::Ok; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -797,7 +797,7 @@ template iss::status riscv_hart_m_p } template iss::status riscv_hart_m_p::read_cycle(unsigned addr, reg_t &val) { - auto cycle_val = this->reg.icount + cycle_offset; + auto cycle_val = this->icount + cycle_offset; if (addr == mcycle) { val = static_cast(cycle_val); } else if (addr == mcycleh) { @@ -819,16 +819,16 @@ template iss::status riscv_hart_m_p mcycle_csr = (static_cast(val)<<32) + (mcycle_csr & 0xffffffff); } } - cycle_offset = mcycle_csr-this->reg.icount; // TODO: relying on wrap-around + cycle_offset = mcycle_csr-this->icount; // TODO: relying on wrap-around return iss::Ok; } template iss::status riscv_hart_m_p::read_instret(unsigned addr, reg_t &val) { if ((addr&0xff) == (minstret&0xff)) { - val = static_cast(this->reg.instret); + val = static_cast(this->instret); } else if ((addr&0xff) == (minstreth&0xff)) { if (sizeof(typename traits::reg_t) != 4) return iss::Err; - val = static_cast(this->reg.instret >> 32); + val = static_cast(this->instret >> 32); } return iss::Ok; } @@ -837,20 +837,20 @@ template iss::status riscv_hart_m_p if (sizeof(typename traits::reg_t) != 4) { if ((addr&0xff) == (minstreth&0xff)) return iss::Err; - this->reg.instret = static_cast(val); + this->instret = static_cast(val); } else { if ((addr&0xff) == (minstret&0xff)) { - this->reg.instret = (this->reg.instret & 0xffffffff00000000) + val; + this->instret = (this->instret & 0xffffffff00000000) + val; } else { - this->reg.instret = (static_cast(val)<<32) + (this->reg.instret & 0xffffffff); + this->instret = (static_cast(val)<<32) + (this->instret & 0xffffffff); } } - this->reg.instret--; + this->instret--; return iss::Ok; } template iss::status riscv_hart_m_p::read_time(unsigned addr, reg_t &val) { - uint64_t time_val = this->reg.icount / (100000000 / 32768 - 1); //-> ~3052; + uint64_t time_val = this->icount / (100000000 / 32768 - 1); //-> ~3052; if (addr == time) { val = static_cast(time_val); } else if (addr == timeh) { @@ -969,7 +969,7 @@ iss::status riscv_hart_m_p::read_mem(phys_addr_t paddr, unsigned len const mem_type::page_type &p = mem(paddr.val / mem.page_size); uint64_t offs = paddr.val & mem.page_addr_mask; std::copy(p.data() + offs, p.data() + offs + length, data); - if (this->reg.icount > 30000) data[3] |= 0x80; + if (this->icount > 30000) data[3] |= 0x80; } break; default: { for(auto offs=0U; offs::write_mem(phys_addr_t paddr, unsigned le LOG(INFO) << "tohost value is 0x" << std::hex << hostvar << std::dec << " (" << hostvar << "), stopping simulation"; } - this->reg.trap_state=std::numeric_limits::max(); + this->trap_state=std::numeric_limits::max(); this->interrupt_sim=hostvar; break; //throw(iss::simulation_stopped(hostvar)); @@ -1117,7 +1117,7 @@ template void riscv_hart_m_p::check enabled_interrupts >>= 1; res++; } - this->reg.pending_trap = res << 16 | 1; // 0x80 << 24 | (cause << 16) | trap_id + this->pending_trap = res << 16 | 1; // 0x80 << 24 | (cause << 16) | trap_id } } @@ -1165,7 +1165,7 @@ template uint64_t riscv_hart_m_p::e fault_data = 0; } else { csr[mepc] = this->reg.NEXT_PC & get_pc_mask(); // store next address if interrupt - this->reg.pending_trap = 0; + this->pending_trap = 0; } csr[mcause] = (trap_id << (traits::XLEN-1)) + cause; // update mstatus @@ -1187,7 +1187,7 @@ template uint64_t riscv_hart_m_p::e if ((ivec & 0x1) == 1 && trap_id != 0) this->reg.NEXT_PC += 4 * cause; // reset trap state this->reg.PRIV = new_priv; - this->reg.trap_state = 0; + this->trap_state = 0; std::array buffer; #if defined(_MSC_VER) sprintf(buffer.data(), "0x%016llx", addr); diff --git a/incl/iss/arch/riscv_hart_msu_vp.h b/incl/iss/arch/riscv_hart_msu_vp.h index 607c952..e7c86e0 100644 --- a/incl/iss/arch/riscv_hart_msu_vp.h +++ b/incl/iss/arch/riscv_hart_msu_vp.h @@ -307,7 +307,7 @@ public: void disass_output(uint64_t pc, const std::string instr) override { CLOG(INFO, disass) << fmt::format("0x{:016x} {:40} [p:{};s:0x{:x};c:{}]", - pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->reg.ccount + cycle_offset); + pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->icount + cycle_offset); }; iss::instrumentation_if *get_instrumentation_if() override { return &instr_if; } @@ -610,7 +610,7 @@ iss::status riscv_hart_msu_vp::read(const address_type type, const access_ if (unlikely((access == iss::access_type::FETCH || access == iss::access_type::DEBUG_FETCH) && (addr & 0x1) == 1)) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31); // issue trap 0 + this->trap_state = (1 << 31); // issue trap 0 return iss::Err; } try { @@ -629,12 +629,12 @@ iss::status riscv_hart_msu_vp::read(const address_type type, const access_ read_mem( BASE::v2p(phys_addr_t{access, space, addr}), length, data): read_mem( BASE::v2p(iss::addr_t{access, type, space, addr}), length, data); if (unlikely(res != iss::Ok)){ - this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault + this->trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault fault_data=addr; } return res; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -650,7 +650,7 @@ iss::status riscv_hart_msu_vp::read(const address_type type, const access_ case 3: { // SFENCE:VMA upper auto tvm = state.mstatus.TVM; if (this->reg.PRIV == PRIV_S & tvm != 0) { - this->reg.trap_state = (1 << 31) | (2 << 16); + this->trap_state = (1 << 31) | (2 << 16); this->fault_data = this->reg.PC; return iss::Err; } @@ -671,7 +671,7 @@ iss::status riscv_hart_msu_vp::read(const address_type type, const access_ } return iss::Ok; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -709,7 +709,7 @@ iss::status riscv_hart_msu_vp::write(const address_type type, const access if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31); // issue trap 0 + this->trap_state = (1 << 31); // issue trap 0 return iss::Err; } try { @@ -728,12 +728,12 @@ iss::status riscv_hart_msu_vp::write(const address_type type, const access write_mem(phys_addr_t{access, space, addr}, length, data): write_mem(BASE::v2p(iss::addr_t{access, type, space, addr}), length, data); if (unlikely(res != iss::Ok)) { - this->reg.trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) + this->trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) fault_data=addr; } return res; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -782,7 +782,7 @@ iss::status riscv_hart_msu_vp::write(const address_type type, const access ptw.clear(); auto tvm = state.mstatus.TVM; if (this->reg.PRIV == PRIV_S & tvm != 0) { - this->reg.trap_state = (1 << 31) | (2 << 16); + this->trap_state = (1 << 31) | (2 << 16); this->fault_data = this->reg.PC; return iss::Err; } @@ -798,7 +798,7 @@ iss::status riscv_hart_msu_vp::write(const address_type type, const access } return iss::Ok; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -844,7 +844,7 @@ template iss::status riscv_hart_msu_vp::write_reg(unsigned } template iss::status riscv_hart_m_p::read_cycle(unsigned addr, reg_t &val) { - auto cycle_val = this->reg.icount + cycle_offset; + auto cycle_val = this->icount + cycle_offset; if (addr == mcycle) { val = static_cast(cycle_val); } else if (addr == mcycleh) { @@ -866,7 +866,7 @@ template iss::status riscv_hart_m_p::write_cycle(unsigned mcycle_csr = (static_cast(val)<<32) + (mcycle_csr & 0xffffffff); } } - cycle_offset = mcycle_csr-this->reg.icount; // TODO: relying on wrap-around + cycle_offset = mcycle_csr-this->icount; // TODO: relying on wrap-around return iss::Ok; } @@ -897,7 +897,7 @@ template iss::status riscv_hart_m_p::write_instret(unsigne } template iss::status riscv_hart_m_p::read_time(unsigned addr, reg_t &val) { - uint64_t time_val = this->reg.icount / (100000000 / 32768 - 1); //-> ~3052; + uint64_t time_val = this->icount / (100000000 / 32768 - 1); //-> ~3052; if (addr == time) { val = static_cast(time_val); } else if (addr == timeh) { @@ -966,7 +966,7 @@ template iss::status riscv_hart_msu_vp::write_epc(unsigned template iss::status riscv_hart_msu_vp::read_satp(unsigned addr, reg_t &val) { reg_t tvm = state.mstatus.TVM; if (this->reg.PRIV == PRIV_S & tvm != 0) { - this->reg.trap_state = (1 << 31) | (2 << 16); + this->trap_state = (1 << 31) | (2 << 16); this->fault_data = this->reg.PC; return iss::Err; } @@ -977,7 +977,7 @@ template iss::status riscv_hart_msu_vp::read_satp(unsigned template iss::status riscv_hart_msu_vp::write_satp(unsigned addr, reg_t val) { reg_t tvm = state.mstatus.TVM; if (this->reg.PRIV == PRIV_S & tvm != 0) { - this->reg.trap_state = (1 << 31) | (2 << 16); + this->trap_state = (1 << 31) | (2 << 16); this->fault_data = this->reg.PC; return iss::Err; } @@ -1033,7 +1033,7 @@ iss::status riscv_hart_msu_vp::read_mem(phys_addr_t paddr, unsigned length const mem_type::page_type &p = mem(paddr.val / mem.page_size); uint64_t offs = paddr.val & mem.page_addr_mask; std::copy(p.data() + offs, p.data() + offs + length, data); - if (this->reg.icount > 30000) data[3] |= 0x80; + if (this->icount > 30000) data[3] |= 0x80; } break; default: { for(auto offs=0U; offs::write_mem(phys_addr_t paddr, unsigned lengt LOG(INFO) << "tohost value is 0x" << std::hex << hostvar << std::dec << " (" << hostvar << "), stopping simulation"; } - this->reg.trap_state=std::numeric_limits::max(); + this->trap_state=std::numeric_limits::max(); this->interrupt_sim=hostvar; break; //throw(iss::simulation_stopped(hostvar)); @@ -1162,7 +1162,7 @@ template void riscv_hart_msu_vp::check_interrupt() { if (enabled_interrupts != 0) { int res = 0; while ((enabled_interrupts & 1) == 0) enabled_interrupts >>= 1, res++; - this->reg.pending_trap = res << 16 | 1; // 0x80 << 24 | (cause << 16) | trap_id + this->pending_trap = res << 16 | 1; // 0x80 << 24 | (cause << 16) | trap_id } } @@ -1306,7 +1306,7 @@ template uint64_t riscv_hart_msu_vp::enter_trap(uint64_t f if (cur_priv != PRIV_M && ((csr[mideleg] >> cause) & 0x1) != 0) new_priv = (csr[sideleg] >> cause) & 0x1 ? PRIV_U : PRIV_S; csr[uepc | (new_priv << 8)] = this->reg.NEXT_PC; // store next address if interrupt - this->reg.pending_trap = 0; + this->pending_trap = 0; } size_t adr = ucause | (new_priv << 8); csr[adr] = (trap_id << 31) + cause; @@ -1351,7 +1351,7 @@ template uint64_t riscv_hart_msu_vp::enter_trap(uint64_t f << lvl[cur_priv] << " to " << lvl[new_priv]; // reset trap state this->reg.PRIV = new_priv; - this->reg.trap_state = 0; + this->trap_state = 0; update_vm_info(); return this->reg.NEXT_PC; } @@ -1363,7 +1363,7 @@ template uint64_t riscv_hart_msu_vp::leave_trap(uint64_t f auto tsr = state.mstatus.TSR; if (cur_priv == PRIV_S && inst_priv == PRIV_S && tsr != 0) { - this->reg.trap_state = (1 << 31) | (2 << 16); + this->trap_state = (1 << 31) | (2 << 16); this->fault_data = this->reg.PC; return this->reg.PC; } @@ -1402,7 +1402,7 @@ template void riscv_hart_msu_vp::wait_until(uint64_t flags auto status = state.mstatus; auto tw = status.TW; if (this->reg.PRIV == PRIV_S && tw != 0) { - this->reg.trap_state = (1 << 31) | (2 << 16); + this->trap_state = (1 << 31) | (2 << 16); this->fault_data = this->reg.PC; } } diff --git a/incl/iss/arch/riscv_hart_mu_p.h b/incl/iss/arch/riscv_hart_mu_p.h index bd50342..e85f1da 100644 --- a/incl/iss/arch/riscv_hart_mu_p.h +++ b/incl/iss/arch/riscv_hart_mu_p.h @@ -218,7 +218,7 @@ public: void disass_output(uint64_t pc, const std::string instr) override { CLOG(INFO, disass) << fmt::format("0x{:016x} {:40} [p:{};s:0x{:x};c:{}]", - pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->reg.icount + cycle_offset); + pc, instr, lvl[this->reg.PRIV], (reg_t)state.mstatus, this->icount + cycle_offset); }; iss::instrumentation_if *get_instrumentation_if() override { return &instr_if; } @@ -704,20 +704,20 @@ iss::status riscv_hart_mu_p::read(const address_type type, const acc if(!pmp_check(access, addr, length) && (access&access_type::DEBUG) != access_type::DEBUG) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31) | ((access==access_type::FETCH?1:5) << 16); // issue trap 1 + this->trap_state = (1 << 31) | ((access==access_type::FETCH?1:5) << 16); // issue trap 1 return iss::Err; } } if (unlikely((access == iss::access_type::FETCH || access == iss::access_type::DEBUG_FETCH) && (addr & 0x1) == 1)) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31); // issue trap 0 + this->trap_state = (1 << 31); // issue trap 0 return iss::Err; } try { auto alignment = access == iss::access_type::FETCH? (traits::MISA_VAL&0x100? 2 : 4) : length; if(alignment>1 && (addr&(alignment-1))){ - this->reg.trap_state = 1<<31 | 4<<16; + this->trap_state = 1<<31 | 4<<16; fault_data=addr; return iss::Err; } @@ -736,12 +736,12 @@ iss::status riscv_hart_mu_p::read(const address_type type, const acc res = read_mem( phys_addr, length, data); } if (unlikely(res != iss::Ok)){ - this->reg.trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault + this->trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault fault_data=addr; } return res; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -767,7 +767,7 @@ iss::status riscv_hart_mu_p::read(const address_type type, const acc } return iss::Ok; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -806,19 +806,19 @@ iss::status riscv_hart_mu_p::write(const address_type type, const ac if(!pmp_check(access, addr, length) && (access&access_type::DEBUG) != access_type::DEBUG) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31) | (7 << 16); // issue trap 1 + this->trap_state = (1 << 31) | (7 << 16); // issue trap 1 return iss::Err; } } if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { fault_data = addr; if (access && iss::access_type::DEBUG) throw trap_access(0, addr); - this->reg.trap_state = (1 << 31); // issue trap 0 + this->trap_state = (1 << 31); // issue trap 0 return iss::Err; } try { if(length>1 && (addr&(length-1)) && (access&access_type::DEBUG) != access_type::DEBUG){ - this->reg.trap_state = 1<<31 | 6<<16; + this->trap_state = 1<<31 | 6<<16; fault_data=addr; return iss::Err; } @@ -837,12 +837,12 @@ iss::status riscv_hart_mu_p::write(const address_type type, const ac res = write_mem( phys_addr, length, data); } if (unlikely(res != iss::Ok)) { - this->reg.trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) + this->trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) fault_data=addr; } return res; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -902,7 +902,7 @@ iss::status riscv_hart_mu_p::write(const address_type type, const ac } return iss::Ok; } catch (trap_access &ta) { - this->reg.trap_state = (1 << 31) | ta.id; + this->trap_state = (1 << 31) | ta.id; fault_data=ta.addr; return iss::Err; } @@ -948,7 +948,7 @@ template iss::status riscv_hart_mu_p iss::status riscv_hart_mu_p::read_cycle(unsigned addr, reg_t &val) { - auto cycle_val = this->reg.icount + cycle_offset; + auto cycle_val = this->icount + cycle_offset; if (addr == mcycle) { val = static_cast(cycle_val); } else if (addr == mcycleh) { @@ -970,16 +970,16 @@ template iss::status riscv_hart_mu_p(val)<<32) + (mcycle_csr & 0xffffffff); } } - cycle_offset = mcycle_csr-this->reg.icount; // TODO: relying on wrap-around + cycle_offset = mcycle_csr-this->icount; // TODO: relying on wrap-around return iss::Ok; } template iss::status riscv_hart_mu_p::read_instret(unsigned addr, reg_t &val) { if ((addr&0xff) == (minstret&0xff)) { - val = static_cast(this->reg.instret); + val = static_cast(this->instret); } else if ((addr&0xff) == (minstreth&0xff)) { if (sizeof(typename traits::reg_t) != 4) return iss::Err; - val = static_cast(this->reg.instret >> 32); + val = static_cast(this->instret >> 32); } return iss::Ok; } @@ -988,20 +988,20 @@ template iss::status riscv_hart_mu_p::reg_t) != 4) { if ((addr&0xff) == (minstreth&0xff)) return iss::Err; - this->reg.instret = static_cast(val); + this->instret = static_cast(val); } else { if ((addr&0xff) == (minstret&0xff)) { - this->reg.instret = (this->reg.instret & 0xffffffff00000000) + val; + this->instret = (this->instret & 0xffffffff00000000) + val; } else { - this->reg.instret = (static_cast(val)<<32) + (this->reg.instret & 0xffffffff); + this->instret = (static_cast(val)<<32) + (this->instret & 0xffffffff); } } - this->reg.instret--; + this->instret--; return iss::Ok; } template iss::status riscv_hart_mu_p::read_time(unsigned addr, reg_t &val) { - uint64_t time_val = this->reg.icount / (100000000 / 32768 - 1); //-> ~3052; + uint64_t time_val = this->icount / (100000000 / 32768 - 1); //-> ~3052; if (addr == time) { val = static_cast(time_val); } else if (addr == timeh) { @@ -1137,7 +1137,7 @@ iss::status riscv_hart_mu_p::read_mem(phys_addr_t paddr, unsigned le const mem_type::page_type &p = mem(paddr.val / mem.page_size); uint64_t offs = paddr.val & mem.page_addr_mask; std::copy(p.data() + offs, p.data() + offs + length, data); - if (this->reg.icount > 30000) data[3] |= 0x80; + if (this->icount > 30000) data[3] |= 0x80; } break; default: { for(auto offs=0U; offs::write_mem(phys_addr_t paddr, unsigned l LOG(INFO) << "tohost value is 0x" << std::hex << hostvar << std::dec << " (" << hostvar << "), stopping simulation"; } - this->reg.trap_state=std::numeric_limits::max(); + this->trap_state=std::numeric_limits::max(); this->interrupt_sim=hostvar; break; //throw(iss::simulation_stopped(hostvar)); @@ -1284,14 +1284,14 @@ template void riscv_hart_mu_p::chec enabled_interrupts >>= 1; res++; } - this->reg.pending_trap = res << 16 | 1; // 0x80 << 24 | (cause << 16) | trap_id + this->pending_trap = res << 16 | 1; // 0x80 << 24 | (cause << 16) | trap_id } } template uint64_t riscv_hart_mu_p::enter_trap(uint64_t flags, uint64_t addr, uint64_t instr) { // flags are ACTIVE[31:31], CAUSE[30:16], TRAPID[15:0] // calculate and write mcause val - if(flags==std::numeric_limits::max()) flags=this->reg.trap_state; + if(flags==std::numeric_limits::max()) flags=this->trap_state; auto trap_id = bit_sub<0, 16>(flags); auto cause = bit_sub<16, 15>(flags); if (trap_id == 0 && cause == 11) cause = 0x8 + this->reg.PRIV; // adjust environment call cause @@ -1338,7 +1338,7 @@ template uint64_t riscv_hart_mu_p:: if (this->reg.PRIV != PRIV_M && ((csr[mideleg] >> cause) & 0x1) != 0) new_priv = PRIV_U; csr[uepc | (new_priv << 8)] = this->reg.NEXT_PC; // store next address if interrupt - this->reg.pending_trap = 0; + this->pending_trap = 0; } size_t adr = ucause | (new_priv << 8); csr[adr] = (trap_id << (traits::XLEN-1)) + cause; @@ -1378,7 +1378,7 @@ template uint64_t riscv_hart_mu_p:: << lvl[this->reg.PRIV] << " to " << lvl[new_priv]; // reset trap state this->reg.PRIV = new_priv; - this->reg.trap_state = 0; + this->trap_state = 0; return this->reg.NEXT_PC; } @@ -1387,7 +1387,7 @@ template uint64_t riscv_hart_mu_p:: auto inst_priv = (flags & 0x3)? 3:0; if(inst_priv>cur_priv){ auto trap_val = 0x80ULL << 24 | (2 << 16); // illegal instruction - this->reg.trap_state = trap_val; + this->trap_state = trap_val; this->reg.NEXT_PC = std::numeric_limits::max(); } else { auto status = state.mstatus; diff --git a/incl/iss/arch/tgc_c.h b/incl/iss/arch/tgc_c.h index 9640ae9..7a71f8c 100644 --- a/incl/iss/arch/tgc_c.h +++ b/incl/iss/arch/tgc_c.h @@ -58,13 +58,7 @@ template <> struct traits { constexpr static unsigned FP_REGS_SIZE = 0; enum reg_e { - X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, PC, NEXT_PC, PRIV, DPC, NUM_REGS, - TRAP_STATE=NUM_REGS, - PENDING_TRAP, - ICOUNT, - CYCLE, - INSTRET, - INSTRUCTION + X0, X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, PC, NEXT_PC, PRIV, DPC, NUM_REGS }; using reg_t = uint32_t; @@ -77,11 +71,11 @@ template <> struct traits { using phys_addr_t = iss::typed_addr_t; - static constexpr std::array reg_bit_widths{ - {32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,8,32,32,32,64,64,64,32}}; + static constexpr std::array reg_bit_widths{ + {32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,8,32}}; - static constexpr std::array reg_byte_offsets{ - {0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,137,141,145,149,157,165,173}}; + static constexpr std::array reg_byte_offsets{ + {0,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,137}}; static const uint64_t addr_mask = (reg_t(1) << (XLEN - 1)) | ((reg_t(1) << (XLEN - 1)) - 1); @@ -198,7 +192,7 @@ struct tgc_c: public arch_if { uint8_t* get_regs_base_ptr() override; - inline uint64_t get_icount() { return reg.icount; } + inline uint64_t get_icount() { return icount; } inline bool should_stop() { return interrupt_sim; } @@ -216,7 +210,7 @@ struct tgc_c: public arch_if { virtual iss::sync_type needed_sync() const { return iss::NO_SYNC; } - inline uint32_t get_last_branch() { return reg.last_branch; } + inline uint32_t get_last_branch() { return last_branch; } #pragma pack(push, 1) @@ -257,12 +251,13 @@ struct tgc_c: public arch_if { uint32_t NEXT_PC = 0; uint8_t PRIV = 0; uint32_t DPC = 0; - uint32_t trap_state = 0, pending_trap = 0; - uint64_t icount = 0; - uint64_t instret = 0; - uint32_t instruction = 0; - uint32_t last_branch; } reg; + uint32_t trap_state = 0, pending_trap = 0; + uint64_t icount = 0; + uint64_t cycle = 0; + uint64_t instret = 0; + uint32_t instruction = 0; + uint32_t last_branch = 0; #pragma pack(pop) std::array addr_mode; diff --git a/src/iss/tgc_c.cpp b/src/iss/tgc_c.cpp index 3c6fcd0..35a27d0 100644 --- a/src/iss/tgc_c.cpp +++ b/src/iss/tgc_c.cpp @@ -41,12 +41,10 @@ using namespace iss::arch; constexpr std::array iss::arch::traits::reg_names; constexpr std::array iss::arch::traits::reg_aliases; -constexpr std::array iss::arch::traits::reg_bit_widths; -constexpr std::array iss::arch::traits::reg_byte_offsets; +constexpr std::array iss::arch::traits::reg_bit_widths; +constexpr std::array iss::arch::traits::reg_byte_offsets; -tgc_c::tgc_c() { - reg.icount = 0; -} +tgc_c::tgc_c() = default; tgc_c::~tgc_c() = default; @@ -57,8 +55,8 @@ void tgc_c::reset(uint64_t address) { reg.PC=address; reg.NEXT_PC=reg.PC; reg.PRIV=0x3; - reg.trap_state=0; - reg.icount=0; + trap_state=0; + icount=0; } uint8_t *tgc_c::get_regs_base_ptr() { diff --git a/src/plugin/pctrace.cpp b/src/plugin/pctrace.cpp index 4c6ea1a..036b4cc 100644 --- a/src/plugin/pctrace.cpp +++ b/src/plugin/pctrace.cpp @@ -126,7 +126,8 @@ void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info& einfo) { auto delay = 0; size_t id = iinfo.instr_id; auto entry = delays[id]; - auto call = (id==2 || id==3) && bit_sub<7,5>(instr_if->get_instr_word())!=0; + auto instr = instr_if->get_instr_word(); + auto call = (id==2 || id==3) && bit_sub<7,5>(instr)!=0; bool taken = einfo.branch_taken; if (einfo.branch_taken) delay = entry.taken; diff --git a/src/sysc/core_complex.cpp b/src/sysc/core_complex.cpp index f7b95c7..53ff0cb 100644 --- a/src/sysc/core_complex.cpp +++ b/src/sysc/core_complex.cpp @@ -105,7 +105,7 @@ public: heart_state_t &get_state() { return this->state; } void notify_phase(iss::arch_if::exec_phase p) override { - if (p == iss::arch_if::ISTART) owner->sync(this->reg.icount); + if (p == iss::arch_if::ISTART) owner->sync(this->icount); } sync_type needed_sync() const override { return PRE_SYNC; } @@ -115,7 +115,7 @@ public: std::stringstream s; s << "[p:" << lvl[this->reg.PRIV] << ";s:0x" << std::hex << std::setfill('0') << std::setw(sizeof(reg_t) * 2) << (reg_t)this->state.mstatus << std::dec << ";c:" - << this->reg.icount + this->cycle_offset << "]"; + << this->icount + this->cycle_offset << "]"; SCCDEBUG(owner->name())<<"disass: " << "0x" << std::setw(16) << std::right << std::setfill('0') << std::hex << pc << "\t\t" << std::setw(40) << std::setfill(' ') << std::left << instr << s.str(); @@ -175,7 +175,7 @@ public: void wait_until(uint64_t flags) override { SCCDEBUG(owner->name()) << "Sleeping until interrupt"; - while(this->reg.pending_trap == 0 && (this->csr[arch::mip] & this->csr[arch::mie]) == 0) { + while(this->pending_trap == 0 && (this->csr[arch::mip] & this->csr[arch::mie]) == 0) { sc_core::wait(wfi_evt); } PLAT::wait_until(flags); @@ -204,7 +204,7 @@ public: this->csr[arch::mip] &= ~mask; this->check_interrupt(); if(value) - SCCTRACE(owner->name()) << "Triggering interrupt " << id << " Pending trap: " << this->reg.pending_trap; + SCCTRACE(owner->name()) << "Triggering interrupt " << id << " Pending trap: " << this->pending_trap; } private: diff --git a/src/vm/interp/vm_tgc_c.cpp b/src/vm/interp/vm_tgc_c.cpp index 435389d..1da214b 100644 --- a/src/vm/interp/vm_tgc_c.cpp +++ b/src/vm/interp/vm_tgc_c.cpp @@ -115,7 +115,7 @@ protected: inline void raise(uint16_t trap_id, uint16_t cause){ auto trap_val = 0x80ULL << 24 | (cause << 16) | trap_id; - this->template get_reg(traits::TRAP_STATE) = trap_val; + this->core.trap_state = trap_val; this->template get_reg(traits::NEXT_PC) = std::numeric_limits::max(); } @@ -135,39 +135,39 @@ protected: T& pc_assign(T& val){super::ex_info.branch_taken=true; return val;} inline uint8_t readSpace1(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline uint16_t readSpace2(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline uint32_t readSpace4(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline uint64_t readSpace8(typename super::mem_type_e space, uint64_t addr){ auto ret = super::template read_mem(space, addr); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; return ret; } inline void writeSpace1(typename super::mem_type_e space, uint64_t addr, uint8_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } inline void writeSpace2(typename super::mem_type_e space, uint64_t addr, uint16_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } inline void writeSpace4(typename super::mem_type_e space, uint64_t addr, uint32_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } inline void writeSpace8(typename super::mem_type_e space, uint64_t addr, uint64_t data){ super::write_mem(space, addr, data); - if(this->template get_reg(traits::TRAP_STATE)) throw 0; + if(this->core.trap_state) throw 0; } template::type> inline S sext(U from) { @@ -359,16 +359,15 @@ typename arch::traits::opcode_e vm_impl::decode_inst_id(code_word_t template typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e cond, virt_addr_t start, uint64_t icount_limit){ auto pc=start; - auto* PC = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::PC]); auto* NEXT_PC = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::NEXT_PC]); - auto* trap_state = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::TRAP_STATE]); - auto* icount = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::ICOUNT]); - auto* instret = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::INSTRET]); - auto *const instruction = reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::INSTRUCTION]); + auto& trap_state = this->core.trap_state; + auto& icount = this->core.icount; + auto& cycle = this->core.cycle; + auto& instret = this->core.instret; + auto& instr = this->core.instruction; // we fetch at max 4 byte, alignment is 2 - auto *const data = reinterpret_cast(instruction); - auto& instr = *instruction; + auto *const data = reinterpret_cast(&instr); while(!this->core.should_stop() && !(is_count_limit_enabled(cond) && this->core.get_icount() >= icount_limit)){ @@ -2409,16 +2408,16 @@ typename vm_base::virt_addr_t vm_impl::execute_inst(finish_cond_e co process_spawn_blocks(); if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, static_cast(inst_id)); // trap check - if(*trap_state!=0){ - super::core.enter_trap(*trap_state, pc.val, instr); + if(trap_state!=0){ + super::core.enter_trap(trap_state, pc.val, instr); } else { - (*icount)++; - (*instret)++; + icount++; + instret++; } - (*reinterpret_cast(this->regs_base_ptr+arch::traits::reg_byte_offsets[arch::traits::CYCLE]))++; + cycle++; pc.val=*NEXT_PC; this->core.reg.PC = this->core.reg.NEXT_PC; - this->core.reg.trap_state = this->core.reg.pending_trap; + this->core.trap_state = this->core.pending_trap; } } return pc;