Compare commits
	
		
			4 Commits
		
	
	
		
			9dfca612b7
			...
			feature/re
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 58311b37db | |||
| ad8dc09bee | |||
| 2bba5645c3 | |||
| bf0a5a80de | 
| @@ -6,7 +6,7 @@ project(dbt-rise-tgc VERSION 1.0.0) | ||||
|  | ||||
| include(GNUInstallDirs) | ||||
|  | ||||
| find_package(elfio QUIET) | ||||
| find_package(elfio) | ||||
| find_package(Boost COMPONENTS coroutine) | ||||
|  | ||||
| if(WITH_LLVM) | ||||
| @@ -35,12 +35,13 @@ FILE(GLOB TGC_VM_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/vm/interp/vm_*.cpp) | ||||
| set(LIB_SOURCES  | ||||
|     src/vm/fp_functions.cpp | ||||
|     src/plugin/instruction_count.cpp | ||||
|     src/plugin/pctrace.cpp | ||||
|      | ||||
|     ${TGC_SOURCES} | ||||
|     ${TGC_VM_SOURCES} | ||||
| ) | ||||
| if(TARGET RapidJSON) | ||||
|     list(APPEND LIB_SOURCES src/plugin/cycle_estimate.cpp src/plugin/pctrace.cpp) | ||||
|     list(APPEND LIB_SOURCES src/plugin/cycle_estimate.cpp) | ||||
| endif() | ||||
|  | ||||
| if(WITH_LLVM) | ||||
|   | ||||
							
								
								
									
										1
									
								
								gen_input/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								gen_input/.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -1,2 +1 @@ | ||||
| /src-gen/ | ||||
| /CoreDSL-Instruction-Set-Description | ||||
|   | ||||
| @@ -94,7 +94,7 @@ protected: | ||||
|  | ||||
|     inline const char *name(size_t index){return traits::reg_aliases.at(index);} | ||||
|  | ||||
|     typename arch::traits<ARCH>::opcode_e decode_inst_id(code_word_t instr); | ||||
|     compile_func decode_inst(code_word_t instr) ; | ||||
|     virt_addr_t execute_inst(finish_cond_e cond, virt_addr_t start, uint64_t icount_limit) override; | ||||
|  | ||||
|     // some compile time constants | ||||
| @@ -114,7 +114,7 @@ protected: | ||||
|     struct instruction_pattern { | ||||
|         uint32_t value; | ||||
|         uint32_t mask; | ||||
|         typename arch::traits<ARCH>::opcode_e id; | ||||
|         compile_func opc; | ||||
|     }; | ||||
|  | ||||
|     std::array<std::vector<instruction_pattern>, 4> qlut; | ||||
| @@ -201,13 +201,73 @@ private: | ||||
|         size_t length; | ||||
|         uint32_t value; | ||||
|         uint32_t mask; | ||||
|         typename arch::traits<ARCH>::opcode_e op; | ||||
|         compile_func op; | ||||
|     }; | ||||
|  | ||||
|     const std::array<InstructionDesriptor, ${instructions.size}> instr_descr = {{ | ||||
|          /* entries are: size, valid value, valid mask, function ptr */<%instructions.each{instr -> %> | ||||
|         {${instr.length}, ${instr.encoding}, ${instr.mask}, arch::traits<ARCH>::opcode_e::${instr.instruction.name}},<%}%> | ||||
|         /* instruction ${instr.instruction.name} */ | ||||
|         {${instr.length}, ${instr.encoding}, ${instr.mask}, &this_class::__${generator.functionName(instr.name)}},<%}%> | ||||
|     }}; | ||||
|   | ||||
|     /* instruction definitions */<%instructions.eachWithIndex{instr, idx -> %> | ||||
|     /* instruction ${idx}: ${instr.name} */ | ||||
|     compile_ret_t __${generator.functionName(instr.name)}(virt_addr_t& pc, code_word_t instr){ | ||||
|         // pre execution stuff | ||||
|         if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, ${idx}); | ||||
|         <%instr.fields.eachLine{%>${it} | ||||
|         <%}%>if(this->disass_enabled){ | ||||
|             /* generate console output when executing the command */ | ||||
|             <%instr.disass.eachLine{%>${it} | ||||
|             <%}%> | ||||
|         } | ||||
|         auto* PC = reinterpret_cast<uint${addrDataWidth}_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]); | ||||
|         auto* NEXT_PC = reinterpret_cast<uint${addrDataWidth}_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]); | ||||
|         auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]); | ||||
|         // used registers<%instr.usedVariables.each{ k,v-> | ||||
|             if(v.isArray) {%> | ||||
|         auto* ${k} = reinterpret_cast<uint${nativeTypeSize(v.type.size)}_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::${k}0]);<% }else{ %>  | ||||
|         auto* ${k} = reinterpret_cast<uint${nativeTypeSize(v.type.size)}_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::${k}]); | ||||
|         <%}}%>// calculate next pc value | ||||
|         *NEXT_PC = *PC + ${instr.length/8}; | ||||
|         // execute instruction | ||||
|         try { | ||||
|         <%instr.behavior.eachLine{%>${it} | ||||
|         <%}%>} catch(...){} | ||||
|         // post execution stuff | ||||
|         process_spawn_blocks(); | ||||
|         if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, ${idx}); | ||||
|         // trap check | ||||
|         if(*trap_state!=0){ | ||||
|             super::core.enter_trap(*trap_state, pc.val, instr); | ||||
|         } else { | ||||
|             (*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]))++; | ||||
|             (*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]))++; | ||||
|         } | ||||
|         (*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++; | ||||
|         pc.val=*NEXT_PC; | ||||
|         return pc; | ||||
|     } | ||||
|     <%}%> | ||||
|     /**************************************************************************** | ||||
|      * end opcode definitions | ||||
|      ****************************************************************************/ | ||||
|     compile_ret_t illegal_intruction(virt_addr_t &pc, code_word_t instr) { | ||||
|         this->do_sync(PRE_SYNC, static_cast<unsigned>(arch::traits<ARCH>::opcode_e::MAX_OPCODE)); | ||||
|         uint32_t* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]); | ||||
|         uint32_t* NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]); | ||||
|         *NEXT_PC = *PC + ((instr & 3) == 3 ? 4 : 2); | ||||
|         raise(0,  2); | ||||
|         // post execution stuff | ||||
|         if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, static_cast<unsigned>(arch::traits<ARCH>::opcode_e::MAX_OPCODE)); | ||||
|         auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]); | ||||
|         // trap check | ||||
|         if(*trap_state!=0){ | ||||
|             super::core.enter_trap(*trap_state, pc.val, instr); | ||||
|         } | ||||
|         pc.val=*NEXT_PC; | ||||
|         return pc; | ||||
|     } | ||||
|  | ||||
|     //static constexpr typename traits::addr_t upper_bits = ~traits::PGMASK; | ||||
|     iss::status fetch_ins(virt_addr_t pc, uint8_t * data){ | ||||
| @@ -247,7 +307,6 @@ constexpr size_t bit_count(uint32_t u) { | ||||
| template <typename ARCH> | ||||
| vm_impl<ARCH>::vm_impl(ARCH &core, unsigned core_id, unsigned cluster_id) | ||||
| : vm_base<ARCH>(core, core_id, cluster_id) { | ||||
|     unsigned id=0; | ||||
|     for (auto instr : instr_descr) { | ||||
|         auto quadrant = instr.value & 0x3; | ||||
|         qlut[quadrant].push_back(instruction_pattern{instr.value, instr.mask, instr.op}); | ||||
| @@ -268,74 +327,31 @@ inline bool is_jump_to_self_enabled(finish_cond_e cond){ | ||||
| } | ||||
|  | ||||
| template <typename ARCH> | ||||
| typename arch::traits<ARCH>::opcode_e vm_impl<ARCH>::decode_inst_id(code_word_t instr){ | ||||
| typename vm_impl<ARCH>::compile_func vm_impl<ARCH>::decode_inst(code_word_t instr){ | ||||
|     for(auto& e: qlut[instr&0x3]){ | ||||
|         if(!((instr&e.mask) ^ e.value )) return e.id; | ||||
|         if(!((instr&e.mask) ^ e.value )) return e.opc; | ||||
|     } | ||||
|     return arch::traits<ARCH>::opcode_e::MAX_OPCODE; | ||||
|     return &this_class::illegal_intruction; | ||||
| } | ||||
|  | ||||
| template <typename ARCH> | ||||
| typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e cond, virt_addr_t start, uint64_t icount_limit){ | ||||
|     // we fetch at max 4 byte, alignment is 2 | ||||
|     code_word_t instr = 0; | ||||
|     auto *const data = (uint8_t *)&instr; | ||||
|     code_word_t insn = 0; | ||||
|     auto *const data = (uint8_t *)&insn; | ||||
|     auto pc=start; | ||||
|  | ||||
|     auto* PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]); | ||||
|     auto* NEXT_PC = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::NEXT_PC]); | ||||
|     auto* trap_state = reinterpret_cast<uint32_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::TRAP_STATE]); | ||||
|     auto* icount = reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::ICOUNT]); | ||||
|     auto* instret = reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::INSTRET]); | ||||
|  | ||||
|     while(!this->core.should_stop() && | ||||
|             !(is_count_limit_enabled(cond) && this->core.get_icount() >= icount_limit)){ | ||||
|         if(fetch_ins(pc, data)!=iss::Ok){ | ||||
|         auto res = fetch_ins(pc, data); | ||||
|         if(res!=iss::Ok){ | ||||
|             this->do_sync(POST_SYNC, std::numeric_limits<unsigned>::max()); | ||||
|             pc.val = super::core.enter_trap(std::numeric_limits<uint64_t>::max(), pc.val, 0); | ||||
|         } else { | ||||
|             if (is_jump_to_self_enabled(cond) && | ||||
|                     (instr == 0x0000006f || (instr&0xffff)==0xa001)) throw simulation_stopped(0); // 'J 0' or 'C.J 0' | ||||
|             auto inst_id = decode_inst_id(instr); | ||||
|             // pre execution stuff | ||||
|             if(this->sync_exec && PRE_SYNC) this->do_sync(PRE_SYNC, static_cast<unsigned>(inst_id)); | ||||
|             switch(inst_id){<%instructions.eachWithIndex{instr, idx -> %> | ||||
|             case arch::traits<ARCH>::opcode_e::${instr.name}: { | ||||
| 		        <%instr.fields.eachLine{%>${it} | ||||
| 		        <%}%>if(this->disass_enabled){ | ||||
| 		            /* generate console output when executing the command */ | ||||
| 		            <%instr.disass.eachLine{%>${it} | ||||
| 		            <%}%> | ||||
| 		        } | ||||
| 		        // used registers<%instr.usedVariables.each{ k,v-> | ||||
| 		        if(v.isArray) {%> | ||||
| 		        auto* ${k} = reinterpret_cast<uint${nativeTypeSize(v.type.size)}_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::${k}0]);<% }else{ %>  | ||||
| 		        auto* ${k} = reinterpret_cast<uint${nativeTypeSize(v.type.size)}_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::${k}]); | ||||
| 		        <%}}%>// calculate next pc value | ||||
| 		        *NEXT_PC = *PC + ${instr.length/8}; | ||||
| 		        // execute instruction | ||||
| 		        try { | ||||
| 		        <%instr.behavior.eachLine{%>${it} | ||||
| 		        <%}%>} catch(...){} | ||||
| 	    	} | ||||
| 	    	break;<%}%> | ||||
|             default: { | ||||
|                 *NEXT_PC = *PC + ((instr & 3) == 3 ? 4 : 2); | ||||
|                 raise(0,  2); | ||||
|             } | ||||
|             } | ||||
|             // post execution stuff | ||||
|             process_spawn_blocks(); | ||||
|             if(this->sync_exec && POST_SYNC) this->do_sync(POST_SYNC, static_cast<unsigned>(inst_id)); | ||||
|             // trap check | ||||
|             if(*trap_state!=0){ | ||||
|                 super::core.enter_trap(*trap_state, pc.val, instr); | ||||
|             } else { | ||||
|                 (*icount)++; | ||||
|                 (*instret)++; | ||||
|             } | ||||
|             (*reinterpret_cast<uint64_t*>(this->regs_base_ptr+arch::traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::CYCLE]))++; | ||||
|             pc.val=*NEXT_PC; | ||||
|                     (insn == 0x0000006f || (insn&0xffff)==0xa001)) throw simulation_stopped(0); // 'J 0' or 'C.J 0' | ||||
|             auto f = decode_inst(insn); | ||||
|             auto old_pc = pc.val; | ||||
|             pc = (this->*f)(pc, insn); | ||||
|             this->core.reg.PC = this->core.reg.NEXT_PC; | ||||
|             this->core.reg.trap_state = this->core.reg.pending_trap; | ||||
|         } | ||||
| @@ -343,7 +359,7 @@ typename vm_base<ARCH>::virt_addr_t vm_impl<ARCH>::execute_inst(finish_cond_e co | ||||
|     return pc; | ||||
| } | ||||
|  | ||||
| } | ||||
| } // namespace mnrv32 | ||||
|  | ||||
| template <> | ||||
| std::unique_ptr<vm_if> create<arch::${coreDef.name.toLowerCase()}>(arch::${coreDef.name.toLowerCase()} *core, unsigned short port, bool dump) { | ||||
|   | ||||
| @@ -1,100 +0,0 @@ | ||||
| /******************************************************************************* | ||||
|  * Copyright (C) 2022 MINRES Technologies GmbH | ||||
|  * All rights reserved. | ||||
|  * | ||||
|  * Redistribution and use in source and binary forms, with or without | ||||
|  * modification, are permitted provided that the following conditions are met: | ||||
|  * | ||||
|  * 1. Redistributions of source code must retain the above copyright notice, | ||||
|  *    this list of conditions and the following disclaimer. | ||||
|  * | ||||
|  * 2. Redistributions in binary form must reproduce the above copyright notice, | ||||
|  *    this list of conditions and the following disclaimer in the documentation | ||||
|  *    and/or other materials provided with the distribution. | ||||
|  * | ||||
|  * 3. Neither the name of the copyright holder nor the names of its contributors | ||||
|  *    may be used to endorse or promote products derived from this software | ||||
|  *    without specific prior written permission. | ||||
|  * | ||||
|  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||||
|  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
|  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
|  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||||
|  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||||
|  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||
|  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||||
|  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||||
|  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||||
|  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||
|  * POSSIBILITY OF SUCH DAMAGE. | ||||
|  * | ||||
|  * Contributors: | ||||
|  *       eyck@minres.com - initial implementation | ||||
|  ******************************************************************************/ | ||||
|  | ||||
| #ifndef _RISCV_HART_M_P_HWL_H | ||||
| #define _RISCV_HART_M_P_HWL_H | ||||
|  | ||||
| #include <iss/vm_types.h> | ||||
|  | ||||
| namespace iss { | ||||
| namespace arch { | ||||
|  | ||||
| template <typename BASE> class hwl : public BASE { | ||||
| public: | ||||
|     using base_class = BASE; | ||||
|     using this_class = hwl<BASE>; | ||||
|     using reg_t = typename BASE::reg_t; | ||||
|  | ||||
|     hwl(); | ||||
|     virtual ~hwl() = default; | ||||
|  | ||||
| protected: | ||||
|     iss::status read_custom_csr_reg(unsigned addr, reg_t &val) override; | ||||
|     iss::status write_custom_csr_reg(unsigned addr, reg_t val) override; | ||||
| }; | ||||
|  | ||||
|  | ||||
| template<typename BASE> | ||||
| inline hwl<BASE>::hwl() { | ||||
|     for (unsigned addr = 0x800; addr < 0x803; ++addr){ | ||||
|         this->register_custom_csr_rd(addr); | ||||
|         this->register_custom_csr_wr(addr); | ||||
|     } | ||||
|     for (unsigned addr = 0x804; addr < 0x807; ++addr){ | ||||
|         this->register_custom_csr_rd(addr); | ||||
|         this->register_custom_csr_wr(addr); | ||||
|     } | ||||
| } | ||||
|  | ||||
| template<typename BASE> | ||||
| inline iss::status iss::arch::hwl<BASE>::read_custom_csr_reg(unsigned addr, reg_t &val) { | ||||
|     switch(addr){ | ||||
|     case 0x800: val = this->reg.lpstart0; break; | ||||
|     case 0x801: val = this->reg.lpend0;   break; | ||||
|     case 0x802: val = this->reg.lpcount0; break; | ||||
|     case 0x804: val = this->reg.lpstart1; break; | ||||
|     case 0x805: val = this->reg.lpend1;   break; | ||||
|     case 0x806: val = this->reg.lpcount1; break; | ||||
|     } | ||||
|     return iss::Ok; | ||||
| } | ||||
|  | ||||
| template<typename BASE> | ||||
| inline iss::status iss::arch::hwl<BASE>::write_custom_csr_reg(unsigned addr, reg_t val) { | ||||
|     switch(addr){ | ||||
|     case 0x800: this->reg.lpstart0 = val; break; | ||||
|     case 0x801: this->reg.lpend0   = val; break; | ||||
|     case 0x802: this->reg.lpcount0 = val; break; | ||||
|     case 0x804: this->reg.lpstart1 = val; break; | ||||
|     case 0x805: this->reg.lpend1   = val; break; | ||||
|     case 0x806: this->reg.lpcount1 = val; break; | ||||
|     } | ||||
|     return iss::Ok; | ||||
| } | ||||
|  | ||||
| } // namespace arch | ||||
| } // namespace iss | ||||
|  | ||||
|  | ||||
| #endif /* _RISCV_HART_M_P_H */ | ||||
| @@ -321,16 +321,6 @@ protected: | ||||
|     iss::status read_dpc_reg(unsigned addr, reg_t &val); | ||||
|     iss::status write_dpc_reg(unsigned addr, reg_t val); | ||||
|  | ||||
|     virtual iss::status read_custom_csr_reg(unsigned addr, reg_t &val) {return iss::status::Err;}; | ||||
|     virtual iss::status write_custom_csr_reg(unsigned addr, reg_t val) {return iss::status::Err;}; | ||||
|  | ||||
|     void register_custom_csr_rd(unsigned addr){ | ||||
|         csr_rd_cb[addr] = &this_class::read_custom_csr_reg; | ||||
|     } | ||||
|     void register_custom_csr_wr(unsigned addr){ | ||||
|         csr_wr_cb[addr] = &this_class::write_custom_csr_reg; | ||||
|     } | ||||
|  | ||||
|     reg_t mhartid_reg{0x0}; | ||||
|     std::function<iss::status(phys_addr_t, unsigned, uint8_t *const)>mem_read_cb; | ||||
|     std::function<iss::status(phys_addr_t, unsigned, const uint8_t *const)> mem_write_cb; | ||||
|   | ||||
| @@ -408,16 +408,6 @@ private: | ||||
|     iss::status read_fcsr(unsigned addr, reg_t &val); | ||||
|     iss::status write_fcsr(unsigned addr, reg_t val); | ||||
|  | ||||
|     virtual iss::status read_custom_csr_reg(unsigned addr, reg_t &val) {return iss::status::Err;}; | ||||
|     virtual iss::status write_custom_csr_reg(unsigned addr, reg_t val) {return iss::status::Err;}; | ||||
|  | ||||
|     void register_custom_csr_rd(unsigned addr){ | ||||
|         csr_rd_cb[addr] = &this_class::read_custom_csr_reg; | ||||
|     } | ||||
|     void register_custom_csr_wr(unsigned addr){ | ||||
|         csr_wr_cb[addr] = &this_class::write_custom_csr_reg; | ||||
|     } | ||||
|  | ||||
|     reg_t mhartid_reg{0x0}; | ||||
|     std::function<iss::status(phys_addr_t, unsigned, uint8_t *const)>mem_read_cb; | ||||
|     std::function<iss::status(phys_addr_t, unsigned, const uint8_t *const)> mem_write_cb; | ||||
|   | ||||
| @@ -339,16 +339,6 @@ protected: | ||||
|     iss::status write_dpc_reg(unsigned addr, reg_t val); | ||||
|     iss::status write_pmpcfg_reg(unsigned addr, reg_t val); | ||||
|  | ||||
|     virtual iss::status read_custom_csr_reg(unsigned addr, reg_t &val) {return iss::status::Err;}; | ||||
|     virtual iss::status write_custom_csr_reg(unsigned addr, reg_t val) {return iss::status::Err;}; | ||||
|  | ||||
|     void register_custom_csr_rd(unsigned addr){ | ||||
|         csr_rd_cb[addr] = &this_class::read_custom_csr_reg; | ||||
|     } | ||||
|     void register_custom_csr_wr(unsigned addr){ | ||||
|         csr_wr_cb[addr] = &this_class::write_custom_csr_reg; | ||||
|     } | ||||
|  | ||||
|     reg_t mhartid_reg{0x0}; | ||||
|     std::function<iss::status(phys_addr_t, unsigned, uint8_t *const)>mem_read_cb; | ||||
|     std::function<iss::status(phys_addr_t, unsigned, const uint8_t *const)> mem_write_cb; | ||||
|   | ||||
| @@ -53,7 +53,7 @@ template <> struct traits<tgc_c> { | ||||
|     static constexpr std::array<const char*, 36> reg_aliases{ | ||||
|         {"ZERO", "RA", "SP", "GP", "TP", "T0", "T1", "T2", "S0", "S1", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "S2", "S3", "S4", "S5", "S6", "S7", "S8", "S9", "S10", "S11", "T3", "T4", "T5", "T6", "PC", "NEXT_PC", "PRIV", "DPC"}}; | ||||
|  | ||||
|     enum constants {MISA_VAL=0b01000000000000000001000100000100, MARCHID_VAL=0x80000003, RFS=32, XLEN=32, CSR_SIZE=4096, INSTR_ALIGNMENT=2, fence=0, fencei=1, fencevmal=2, fencevmau=3, MUL_LEN=64}; | ||||
|     enum constants {MISA_VAL=0b01000000000000000001000100000100, MARCHID_VAL=0x80000003, XLEN=32, CSR_SIZE=4096, INSTR_ALIGNMENT=2, fence=0, fencei=1, fencevmal=2, fencevmau=3, MUL_LEN=64}; | ||||
|  | ||||
|     constexpr static unsigned FP_REGS_SIZE = 0; | ||||
|  | ||||
|   | ||||
| @@ -214,26 +214,12 @@ template <typename ARCH> status riscv_target_adapter<ARCH>::write_registers(cons | ||||
|     auto start_reg=arch::traits<ARCH>::X0; | ||||
|     auto *reg_base = core->get_regs_base_ptr(); | ||||
|     auto iter = data.data(); | ||||
|     bool e_ext = arch::traits<ARCH>::PC<32; | ||||
|     for (size_t reg_no = 0; reg_no < start_reg+33/*arch::traits<ARCH>::NUM_REGS*/; ++reg_no) { | ||||
|         if(e_ext && reg_no>15){ | ||||
|             if(reg_no==32){ | ||||
|                 auto reg_width = arch::traits<ARCH>::reg_bit_widths[arch::traits<ARCH>::PC] / 8; | ||||
|                 auto offset = traits<ARCH>::reg_byte_offsets[arch::traits<ARCH>::PC]; | ||||
|                 std::copy(iter, iter + reg_width, reg_base); | ||||
|             } else { | ||||
|                 const uint64_t zero_val=0; | ||||
|                 auto reg_width = arch::traits<ARCH>::reg_bit_widths[15] / 8; | ||||
|                 auto iter = (uint8_t*)&zero_val; | ||||
|                 std::copy(iter, iter + reg_width, reg_base); | ||||
|             } | ||||
|         } else { | ||||
|             auto reg_width = arch::traits<ARCH>::reg_bit_widths[reg_no] / 8; | ||||
|             auto offset = traits<ARCH>::reg_byte_offsets[reg_no]; | ||||
|             std::copy(iter, iter + reg_width, reg_base); | ||||
|             iter += 4; | ||||
|             reg_base += offset; | ||||
|         } | ||||
|         auto reg_width = arch::traits<ARCH>::reg_bit_widths[reg_no] / 8; | ||||
|         auto offset = traits<ARCH>::reg_byte_offsets[reg_no]; | ||||
|         std::copy(iter, iter + reg_width, reg_base); | ||||
|         iter += 4; | ||||
|         reg_base += offset; | ||||
|     } | ||||
|     return Ok; | ||||
| } | ||||
|   | ||||
| @@ -90,6 +90,7 @@ private: | ||||
|     std::ofstream output; | ||||
|     std::string filename; | ||||
|     std::vector<instr_desc> delays; | ||||
|     bool jumped, first; | ||||
|  | ||||
| }; | ||||
| } | ||||
|   | ||||
| @@ -75,7 +75,6 @@ using tgc_e_plat_type = iss::arch::riscv_hart_mu_p<iss::arch::tgc_e, (iss::arch: | ||||
| #include <iss/log_categories.h> | ||||
| #include <iss/plugin/cycle_estimate.h> | ||||
| #include <iss/plugin/instruction_count.h> | ||||
| #include <iss/plugin/pctrace.h> | ||||
| #include <iss/plugin/loader.h> | ||||
| #if defined(HAS_LUA) | ||||
| #include <iss/plugin/lua.h> | ||||
| @@ -209,11 +208,7 @@ int main(int argc, char *argv[]) { | ||||
|                     auto *ce_plugin = new iss::plugin::cycle_estimate(filename); | ||||
|                     vm->register_plugin(*ce_plugin); | ||||
|                     plugin_list.push_back(ce_plugin); | ||||
|                 } else if (plugin_name == "pctrace") { | ||||
|                     auto *plugin = new iss::plugin::cov(filename); | ||||
|                     vm->register_plugin(*plugin); | ||||
|                     plugin_list.push_back(plugin); | ||||
|                } else { | ||||
|                 } else { | ||||
|                     std::array<char const*, 1> a{{filename.c_str()}}; | ||||
|                     iss::plugin::loader l(plugin_name, {{"initPlugin"}}); | ||||
|                     auto* plugin = l.call_function<iss::vm_plugin*>("initPlugin", a.size(), a.data()); | ||||
|   | ||||
| @@ -20,6 +20,8 @@ iss::plugin::cov::cov(std::string const &filename) | ||||
|     , filename(filename) | ||||
| { | ||||
|     output.open("output.trc"); | ||||
|     jumped = false; | ||||
|     first = true; | ||||
| } | ||||
|  | ||||
| iss::plugin::cov::~cov() { | ||||
| @@ -79,13 +81,47 @@ bool iss::plugin::cov::registration(const char *const version, vm_if& vm) { | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
| inline string formatPC(uint64_t pc) { | ||||
|     stringstream stream; | ||||
|     stream << "0x" << std::hex << pc; | ||||
|     return stream.str(); | ||||
| } | ||||
|  | ||||
| void iss::plugin::cov::callback(instr_info_t iinfo, const exec_info& einfo) { | ||||
| //    if((instr_if->get_next_pc() - instr_if->get_pc() != 4) ||( instr_if->get_next_pc() - instr_if->get_pc() != 2)){ | ||||
| //        std::cout << "jump from " << std::hex << instr_if->get_pc() << " to " << instr_if->get_next_pc()<< " after " << std::dec << counter <<" linear instructions" <<std::endl; | ||||
| //        counter = 0; | ||||
| //    }else { | ||||
| //        counter++; | ||||
| //    auto delay = 0; | ||||
| //    auto entry = delays[iinfo.instr_id]; | ||||
| //    bool taken = einfo.branch_taken; | ||||
| //    if (einfo.branch_taken) | ||||
| //        delay = entry.taken; | ||||
| //    else | ||||
| //        delay = entry.not_taken; | ||||
| // | ||||
| //    if (first){ | ||||
| //        output << formatPC(instr_if->get_pc()) << "," << delay; | ||||
| //        first = false; | ||||
| //    } | ||||
| //    if(instr_if->get_next_pc()-instr_if->get_pc() != delays[iinfo.instr_id].size/8){ | ||||
| //        //The goal is to keep the output in start-target pairs, so after a jump the target address needs to get written | ||||
| //        //to the output. If the target happens to also be a start, we keep the pairing by adding a 0-delay entry. | ||||
| //        if (jumped) | ||||
| //            output <<"\n" <<formatPC(instr_if->get_pc()) << "," << 0; | ||||
| //        output <<"\n" << formatPC(instr_if->get_pc()) << "," << delay; | ||||
| //        jumped = true; | ||||
| //    } | ||||
| //    else{ | ||||
| //        if (jumped){ | ||||
| //            output <<"\n" << formatPC(instr_if->get_pc()) << "," << delay; | ||||
| //            jumped = false; | ||||
| //        } | ||||
| //        else if(delay!=1){ | ||||
| //            output <<"\n" << formatPC(instr_if->get_pc()) << "," << delay; | ||||
| //            output <<"\n" << formatPC(instr_if->get_pc()) << "," << 0; | ||||
| //        } | ||||
| // | ||||
| //    } | ||||
|  | ||||
| //source code for the full output | ||||
|     auto delay = 0; | ||||
|     auto entry = delays[iinfo.instr_id]; | ||||
|     bool taken = einfo.branch_taken; | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user