Compare commits
	
		
			4 Commits
		
	
	
		
			4876f18ba9
			...
			e60fa3d5e6
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e60fa3d5e6 | |||
| 8407f6287f | |||
| 0833198d34 | |||
| 57347ae4d9 | 
| @@ -36,11 +36,10 @@ def nativeTypeSize(int size){ | |||||||
|     if(size<=8) return 8; else if(size<=16) return 16; else if(size<=32) return 32; else return 64; |     if(size<=8) return 8; else if(size<=16) return 16; else if(size<=32) return 32; else return 64; | ||||||
| } | } | ||||||
| %> | %> | ||||||
| #include <vm/fp_functions.h> |  | ||||||
| #include <iss/arch/${coreDef.name.toLowerCase()}.h> |  | ||||||
| #include <iss/arch/riscv_hart_m_p.h> |  | ||||||
| #include <iss/debugger/gdb_session.h> | #include <iss/debugger/gdb_session.h> | ||||||
| #include <iss/debugger/server.h> | #include <iss/debugger/server.h> | ||||||
|  | #include <iss/arch/${coreDef.name.toLowerCase()}.h> | ||||||
|  | #include <iss/arch/riscv_hart_m_p.h> | ||||||
| #include <iss/iss.h> | #include <iss/iss.h> | ||||||
| #include <iss/interp/vm_base.h> | #include <iss/interp/vm_base.h> | ||||||
| #include <util/logging.h> | #include <util/logging.h> | ||||||
|   | |||||||
| @@ -477,10 +477,10 @@ template <typename BASE, features_e FEAT> std::pair<uint64_t, bool> riscv_hart_m | |||||||
|     if (fp) { |     if (fp) { | ||||||
|         std::array<char, 5> buf; |         std::array<char, 5> buf; | ||||||
|         auto n = fread(buf.data(), 1, 4, fp); |         auto n = fread(buf.data(), 1, 4, fp); | ||||||
|  |         fclose(fp); | ||||||
|         if (n != 4) throw std::runtime_error("input file has insufficient size"); |         if (n != 4) throw std::runtime_error("input file has insufficient size"); | ||||||
|         buf[4] = 0; |         buf[4] = 0; | ||||||
|         if (strcmp(buf.data() + 1, "ELF") == 0) { |         if (strcmp(buf.data() + 1, "ELF") == 0) { | ||||||
|             fclose(fp); |  | ||||||
|             // Create elfio reader |             // Create elfio reader | ||||||
|             ELFIO::elfio reader; |             ELFIO::elfio reader; | ||||||
|             // Load ELF data |             // Load ELF data | ||||||
| @@ -571,12 +571,12 @@ iss::status riscv_hart_m_p<BASE, FEAT>::read(const address_type type, const acce | |||||||
|             if (unlikely(is_fetch(access) && (addr&(alignment-1)))) { |             if (unlikely(is_fetch(access) && (addr&(alignment-1)))) { | ||||||
|                 fault_data = addr; |                 fault_data = addr; | ||||||
|                 if (is_debug(access)) throw trap_access(0, addr); |                 if (is_debug(access)) throw trap_access(0, addr); | ||||||
|                 this->trap_state = (1 << 31); // issue trap 0 |                 this->trap_state = (1UL << 31); // issue trap 0 | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
|             try { |             try { | ||||||
|                 if(!is_debug(access) && (addr&(alignment-1))){ |                 if(!is_debug(access) && (addr&(alignment-1))){ | ||||||
|                     this->trap_state = 1<<31 | 4<<16; |                     this->trap_state = (1UL << 31) | 4<<16; | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                     return iss::Err; |                     return iss::Err; | ||||||
|                 } |                 } | ||||||
| @@ -595,12 +595,12 @@ iss::status riscv_hart_m_p<BASE, FEAT>::read(const address_type type, const acce | |||||||
|                     res = read_mem( phys_addr, length, data); |                     res = read_mem( phys_addr, length, data); | ||||||
|                 } |                 } | ||||||
|                 if (unlikely(res != iss::Ok)){ |                 if (unlikely(res != iss::Ok)){ | ||||||
|                     this->trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault |                     this->trap_state = (1UL << 31) | (5 << 16); // issue trap 5 (load access fault | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                 } |                 } | ||||||
|                 return res; |                 return res; | ||||||
|             } catch (trap_access &ta) { |             } catch (trap_access &ta) { | ||||||
|                 this->trap_state = (1 << 31) | ta.id; |                 this->trap_state = (1UL << 31) | ta.id; | ||||||
|                 fault_data=ta.addr; |                 fault_data=ta.addr; | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
| @@ -626,7 +626,7 @@ iss::status riscv_hart_m_p<BASE, FEAT>::read(const address_type type, const acce | |||||||
|         } |         } | ||||||
|         return iss::Ok; |         return iss::Ok; | ||||||
|     } catch (trap_access &ta) { |     } catch (trap_access &ta) { | ||||||
|         this->trap_state = (1 << 31) | ta.id; |         this->trap_state = (1UL << 31) | ta.id; | ||||||
|         fault_data=ta.addr; |         fault_data=ta.addr; | ||||||
|         return iss::Err; |         return iss::Err; | ||||||
|     } |     } | ||||||
| @@ -664,12 +664,12 @@ iss::status riscv_hart_m_p<BASE, FEAT>::write(const address_type type, const acc | |||||||
|             if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { |             if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { | ||||||
|                 fault_data = addr; |                 fault_data = addr; | ||||||
|                 if (access && iss::access_type::DEBUG) throw trap_access(0, addr); |                 if (access && iss::access_type::DEBUG) throw trap_access(0, addr); | ||||||
|                 this->trap_state = (1 << 31); // issue trap 0 |                 this->trap_state = (1UL << 31); // issue trap 0 | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
|             try { |             try { | ||||||
|                 if(length>1 && (addr&(length-1)) && (access&access_type::DEBUG) != access_type::DEBUG){ |                 if(length>1 && (addr&(length-1)) && (access&access_type::DEBUG) != access_type::DEBUG){ | ||||||
|                     this->trap_state = 1<<31 | 6<<16; |                     this->trap_state = (1UL << 31) | 6<<16; | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                     return iss::Err; |                     return iss::Err; | ||||||
|                 } |                 } | ||||||
| @@ -688,12 +688,12 @@ iss::status riscv_hart_m_p<BASE, FEAT>::write(const address_type type, const acc | |||||||
|                     res = write_mem( phys_addr, length, data); |                     res = write_mem( phys_addr, length, data); | ||||||
|                 } |                 } | ||||||
|                 if (unlikely(res != iss::Ok)) { |                 if (unlikely(res != iss::Ok)) { | ||||||
|                     this->trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) |                     this->trap_state = (1UL << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                 } |                 } | ||||||
|                 return res; |                 return res; | ||||||
|             } catch (trap_access &ta) { |             } catch (trap_access &ta) { | ||||||
|                 this->trap_state = (1 << 31) | ta.id; |                 this->trap_state = (1UL << 31) | ta.id; | ||||||
|                 fault_data=ta.addr; |                 fault_data=ta.addr; | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
| @@ -753,7 +753,7 @@ iss::status riscv_hart_m_p<BASE, FEAT>::write(const address_type type, const acc | |||||||
|         } |         } | ||||||
|         return iss::Ok; |         return iss::Ok; | ||||||
|     } catch (trap_access &ta) { |     } catch (trap_access &ta) { | ||||||
|         this->trap_state = (1 << 31) | ta.id; |         this->trap_state = (1UL << 31) | ta.id; | ||||||
|         fault_data=ta.addr; |         fault_data=ta.addr; | ||||||
|         return iss::Err; |         return iss::Err; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -526,10 +526,10 @@ template <typename BASE, features_e FEAT> std::pair<uint64_t, bool> riscv_hart_m | |||||||
|     if (fp) { |     if (fp) { | ||||||
|         std::array<char, 5> buf; |         std::array<char, 5> buf; | ||||||
|         auto n = fread(buf.data(), 1, 4, fp); |         auto n = fread(buf.data(), 1, 4, fp); | ||||||
|  |         fclose(fp); | ||||||
|         if (n != 4) throw std::runtime_error("input file has insufficient size"); |         if (n != 4) throw std::runtime_error("input file has insufficient size"); | ||||||
|         buf[4] = 0; |         buf[4] = 0; | ||||||
|         if (strcmp(buf.data() + 1, "ELF") == 0) { |         if (strcmp(buf.data() + 1, "ELF") == 0) { | ||||||
|             fclose(fp); |  | ||||||
|             // Create elfio reader |             // Create elfio reader | ||||||
|             ELFIO::elfio reader; |             ELFIO::elfio reader; | ||||||
|             // Load ELF data |             // Load ELF data | ||||||
| @@ -708,7 +708,7 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::read(const address_type type, const acc | |||||||
|                 if(!pmp_check(access, addr, length) && !is_debug(access)) { |                 if(!pmp_check(access, addr, length) && !is_debug(access)) { | ||||||
|                     fault_data = addr; |                     fault_data = addr; | ||||||
|                     if (is_debug(access)) throw trap_access(0, addr); |                     if (is_debug(access)) throw trap_access(0, addr); | ||||||
|                     this->trap_state = (1 << 31) | ((access==access_type::FETCH?1:5) << 16); // issue trap 1 |                     this->trap_state = (1UL << 31) | ((access==access_type::FETCH?1:5) << 16); // issue trap 1 | ||||||
|                     return iss::Err; |                     return iss::Err; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -716,12 +716,12 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::read(const address_type type, const acc | |||||||
|             if (unlikely(is_fetch(access) && (addr&(alignment-1)))) { |             if (unlikely(is_fetch(access) && (addr&(alignment-1)))) { | ||||||
|                 fault_data = addr; |                 fault_data = addr; | ||||||
|                 if (is_debug(access)) throw trap_access(0, addr); |                 if (is_debug(access)) throw trap_access(0, addr); | ||||||
|                 this->trap_state = (1 << 31); // issue trap 0 |                 this->trap_state = (1UL << 31); // issue trap 0 | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
|             try { |             try { | ||||||
|                 if(!is_debug(access)  && (addr&(alignment-1))){ |                 if(!is_debug(access)  && (addr&(alignment-1))){ | ||||||
|                     this->trap_state = 1<<31 | 4<<16; |                     this->trap_state = (1UL << 31) | 4<<16; | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                     return iss::Err; |                     return iss::Err; | ||||||
|                 } |                 } | ||||||
| @@ -740,12 +740,12 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::read(const address_type type, const acc | |||||||
|                     res = read_mem( phys_addr, length, data); |                     res = read_mem( phys_addr, length, data); | ||||||
|                 } |                 } | ||||||
|                 if (unlikely(res != iss::Ok)){ |                 if (unlikely(res != iss::Ok)){ | ||||||
|                     this->trap_state = (1 << 31) | (5 << 16); // issue trap 5 (load access fault |                     this->trap_state = (1UL << 31) | (5 << 16); // issue trap 5 (load access fault | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                 } |                 } | ||||||
|                 return res; |                 return res; | ||||||
|             } catch (trap_access &ta) { |             } catch (trap_access &ta) { | ||||||
|                 this->trap_state = (1 << 31) | ta.id; |                 this->trap_state = (1UL << 31) | ta.id; | ||||||
|                 fault_data=ta.addr; |                 fault_data=ta.addr; | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
| @@ -771,7 +771,7 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::read(const address_type type, const acc | |||||||
|         } |         } | ||||||
|         return iss::Ok; |         return iss::Ok; | ||||||
|     } catch (trap_access &ta) { |     } catch (trap_access &ta) { | ||||||
|         this->trap_state = (1 << 31) | ta.id; |         this->trap_state = (1UL << 31) | ta.id; | ||||||
|         fault_data=ta.addr; |         fault_data=ta.addr; | ||||||
|         return iss::Err; |         return iss::Err; | ||||||
|     } |     } | ||||||
| @@ -810,19 +810,19 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::write(const address_type type, const ac | |||||||
|                 if(!pmp_check(access, addr, length) && (access&access_type::DEBUG) != access_type::DEBUG) { |                 if(!pmp_check(access, addr, length) && (access&access_type::DEBUG) != access_type::DEBUG) { | ||||||
|                     fault_data = addr; |                     fault_data = addr; | ||||||
|                     if (access && iss::access_type::DEBUG) throw trap_access(0, addr); |                     if (access && iss::access_type::DEBUG) throw trap_access(0, addr); | ||||||
|                     this->trap_state = (1 << 31) | (7 << 16); // issue trap 1 |                     this->trap_state = (1UL << 31) | (7 << 16); // issue trap 1 | ||||||
|                     return iss::Err; |                     return iss::Err; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { |             if (unlikely((access && iss::access_type::FETCH) && (addr & 0x1) == 1)) { | ||||||
|                 fault_data = addr; |                 fault_data = addr; | ||||||
|                 if (access && iss::access_type::DEBUG) throw trap_access(0, addr); |                 if (access && iss::access_type::DEBUG) throw trap_access(0, addr); | ||||||
|                 this->trap_state = (1 << 31); // issue trap 0 |                 this->trap_state = (1UL << 31); // issue trap 0 | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
|             try { |             try { | ||||||
|                 if(length>1 && (addr&(length-1)) && (access&access_type::DEBUG) != access_type::DEBUG){ |                 if(length>1 && (addr&(length-1)) && (access&access_type::DEBUG) != access_type::DEBUG){ | ||||||
|                     this->trap_state = 1<<31 | 6<<16; |                     this->trap_state = (1UL << 31) | 6<<16; | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                     return iss::Err; |                     return iss::Err; | ||||||
|                 } |                 } | ||||||
| @@ -841,12 +841,12 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::write(const address_type type, const ac | |||||||
|                     res = write_mem( phys_addr, length, data); |                     res = write_mem( phys_addr, length, data); | ||||||
|                 } |                 } | ||||||
|                 if (unlikely(res != iss::Ok)) { |                 if (unlikely(res != iss::Ok)) { | ||||||
|                     this->trap_state = (1 << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) |                     this->trap_state = (1UL << 31) | (7 << 16); // issue trap 7 (Store/AMO access fault) | ||||||
|                     fault_data=addr; |                     fault_data=addr; | ||||||
|                 } |                 } | ||||||
|                 return res; |                 return res; | ||||||
|             } catch (trap_access &ta) { |             } catch (trap_access &ta) { | ||||||
|                 this->trap_state = (1 << 31) | ta.id; |                 this->trap_state = (1UL << 31) | ta.id; | ||||||
|                 fault_data=ta.addr; |                 fault_data=ta.addr; | ||||||
|                 return iss::Err; |                 return iss::Err; | ||||||
|             } |             } | ||||||
| @@ -906,7 +906,7 @@ iss::status riscv_hart_mu_p<BASE, FEAT>::write(const address_type type, const ac | |||||||
|         } |         } | ||||||
|         return iss::Ok; |         return iss::Ok; | ||||||
|     } catch (trap_access &ta) { |     } catch (trap_access &ta) { | ||||||
|         this->trap_state = (1 << 31) | ta.id; |         this->trap_state = (1UL << 31) | ta.id; | ||||||
|         fault_data=ta.addr; |         fault_data=ta.addr; | ||||||
|         return iss::Err; |         return iss::Err; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -120,9 +120,9 @@ public: | |||||||
|  |  | ||||||
|     status packetsize_query(std::string &out_buf) override; |     status packetsize_query(std::string &out_buf) override; | ||||||
|  |  | ||||||
|     status add_break(int type, uint64_t addr, unsigned int length) override; |     status add_break(break_type type, uint64_t addr, unsigned int length) override; | ||||||
|  |  | ||||||
|     status remove_break(int type, uint64_t addr, unsigned int length) override; |     status remove_break(break_type type, uint64_t addr, unsigned int length) override; | ||||||
|  |  | ||||||
|     status resume_from_addr(bool step, int sig, uint64_t addr, rp_thread_ref thread, |     status resume_from_addr(bool step, int sig, uint64_t addr, rp_thread_ref thread, | ||||||
|             std::function<void(unsigned)> stop_callback) override; |             std::function<void(unsigned)> stop_callback) override; | ||||||
| @@ -331,7 +331,11 @@ template <typename ARCH> status riscv_target_adapter<ARCH>::packetsize_query(std | |||||||
|     return Ok; |     return Ok; | ||||||
| } | } | ||||||
|  |  | ||||||
| template <typename ARCH> status riscv_target_adapter<ARCH>::add_break(int type, uint64_t addr, unsigned int length) { | template <typename ARCH> status riscv_target_adapter<ARCH>::add_break(break_type type, uint64_t addr, unsigned int length) { | ||||||
|  |     switch(type) { | ||||||
|  |     default: | ||||||
|  |         return Err; | ||||||
|  |     case HW_EXEC: { | ||||||
|         auto saddr = map_addr({iss::access_type::FETCH, iss::address_type::PHYSICAL, 0, addr}); |         auto saddr = map_addr({iss::access_type::FETCH, iss::address_type::PHYSICAL, 0, addr}); | ||||||
|         auto eaddr = map_addr({iss::access_type::FETCH, iss::address_type::PHYSICAL, 0, addr + length}); |         auto eaddr = map_addr({iss::access_type::FETCH, iss::address_type::PHYSICAL, 0, addr + length}); | ||||||
|         target_adapter_base::bp_lut.addEntry(++target_adapter_base::bp_count, saddr.val, eaddr.val - saddr.val); |         target_adapter_base::bp_lut.addEntry(++target_adapter_base::bp_count, saddr.val, eaddr.val - saddr.val); | ||||||
| @@ -340,8 +344,14 @@ template <typename ARCH> status riscv_target_adapter<ARCH>::add_break(int type, | |||||||
|         LOG(TRACE) << "Now having " << target_adapter_base::bp_lut.size() << " breakpoints"; |         LOG(TRACE) << "Now having " << target_adapter_base::bp_lut.size() << " breakpoints"; | ||||||
|         return Ok; |         return Ok; | ||||||
|     } |     } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| template <typename ARCH> status riscv_target_adapter<ARCH>::remove_break(int type, uint64_t addr, unsigned int length) { | template <typename ARCH> status riscv_target_adapter<ARCH>::remove_break(break_type type, uint64_t addr, unsigned int length) { | ||||||
|  |     switch(type) { | ||||||
|  |     default: | ||||||
|  |         return Err; | ||||||
|  |     case HW_EXEC: { | ||||||
|         auto saddr = map_addr({iss::access_type::FETCH, iss::address_type::PHYSICAL, 0, addr}); |         auto saddr = map_addr({iss::access_type::FETCH, iss::address_type::PHYSICAL, 0, addr}); | ||||||
|         unsigned handle = target_adapter_base::bp_lut.getEntry(saddr.val); |         unsigned handle = target_adapter_base::bp_lut.getEntry(saddr.val); | ||||||
|         if (handle) { |         if (handle) { | ||||||
| @@ -355,6 +365,8 @@ template <typename ARCH> status riscv_target_adapter<ARCH>::remove_break(int typ | |||||||
|         LOG(TRACE) << "Now having " << target_adapter_base::bp_lut.size() << " breakpoints"; |         LOG(TRACE) << "Now having " << target_adapter_base::bp_lut.size() << " breakpoints"; | ||||||
|         return Err; |         return Err; | ||||||
|     } |     } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
| template <typename ARCH> | template <typename ARCH> | ||||||
| status riscv_target_adapter<ARCH>::resume_from_addr(bool step, int sig, uint64_t addr, rp_thread_ref thread, | status riscv_target_adapter<ARCH>::resume_from_addr(bool step, int sig, uint64_t addr, rp_thread_ref thread, | ||||||
|   | |||||||
| @@ -69,7 +69,7 @@ struct core_trace; | |||||||
|  |  | ||||||
| class core_complex : public sc_core::sc_module, public scc::traceable { | class core_complex : public sc_core::sc_module, public scc::traceable { | ||||||
| public: | public: | ||||||
|     tlm::scc::initiator_mixin<tlm::scc::scv::tlm_rec_initiator_socket<32>> initiator{"intor"}; |     tlm::scc::initiator_mixin<tlm::tlm_initiator_socket<32>> initiator{"intor"}; | ||||||
|  |  | ||||||
|     sc_core::sc_in<bool> rst_i{"rst_i"}; |     sc_core::sc_in<bool> rst_i{"rst_i"}; | ||||||
|  |  | ||||||
| @@ -84,7 +84,7 @@ public: | |||||||
| #ifndef CWR_SYSTEMC | #ifndef CWR_SYSTEMC | ||||||
| 	sc_core::sc_in<sc_core::sc_time> clk_i{"clk_i"}; | 	sc_core::sc_in<sc_core::sc_time> clk_i{"clk_i"}; | ||||||
|  |  | ||||||
|     sc_core::sc_port<tlm::tlm_peek_if<uint64_t>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> mtime_o; |     sc_core::sc_port<tlm::tlm_peek_if<uint64_t>, 1, sc_core::SC_ZERO_OR_MORE_BOUND> mtime_o{"mtime_o"}; | ||||||
|  |  | ||||||
|     cci::cci_param<std::string> elf_file{"elf_file", ""}; |     cci::cci_param<std::string> elf_file{"elf_file", ""}; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user