From 90bafe660b323250338fd564bb9ab4316576d59b Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Fri, 16 Mar 2018 14:52:09 -0700 Subject: [PATCH] Implement debug havereset bits --- riscv/debug_module.cc | 14 ++++++++++++++ riscv/debug_module.h | 8 +++++++- riscv/processor.cc | 2 ++ riscv/sim.cc | 5 +++++ riscv/sim.h | 5 +++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/riscv/debug_module.cc b/riscv/debug_module.cc index 74c3023..6f9359b 100644 --- a/riscv/debug_module.cc +++ b/riscv/debug_module.cc @@ -35,6 +35,7 @@ debug_module_t::debug_module_t(sim_t *sim, unsigned progbufsize, unsigned max_bu memset(halted, 0, sizeof(halted)); memset(debug_rom_flags, 0, sizeof(debug_rom_flags)); memset(resumeack, 0, sizeof(resumeack)); + memset(havereset, 0, sizeof(havereset)); memset(program_buffer, 0, program_buffer_bytes); program_buffer[4*progbufsize] = ebreak(); program_buffer[4*progbufsize+1] = ebreak() >> 8; @@ -387,6 +388,10 @@ bool debug_module_t::dmi_read(unsigned address, uint32_t *value) result = set_field(result, DMI_DMSTATUS_IMPEBREAK, dmstatus.impebreak); + result = set_field(result, DMI_DMSTATUS_ALLHAVERESET, + havereset[dmcontrol.hartsel]); + result = set_field(result, DMI_DMSTATUS_ANYHAVERESET, + havereset[dmcontrol.hartsel]); result = set_field(result, DMI_DMSTATUS_ALLNONEXISTENT, dmstatus.allnonexistant); result = set_field(result, DMI_DMSTATUS_ALLUNAVAIL, dmstatus.allunavail); result = set_field(result, DMI_DMSTATUS_ALLRUNNING, dmstatus.allrunning); @@ -664,6 +669,9 @@ bool debug_module_t::dmi_write(unsigned address, uint32_t value) dmcontrol.ndmreset = get_field(value, DMI_DMCONTROL_NDMRESET); dmcontrol.hartsel = get_field(value, ((1L<reset(); // reset the extension + + sim->proc_reset(id); } // Count number of contiguous 0 bits starting from the LSB. diff --git a/riscv/sim.cc b/riscv/sim.cc index 81c5f6f..04fbe3c 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -364,3 +364,8 @@ void sim_t::write_chunk(addr_t taddr, size_t len, const void* src) memcpy(&data, src, sizeof data); debug_mmu->store_uint64(taddr, data); } + +void sim_t::proc_reset(unsigned id) +{ + debug_module.proc_reset(id); +} diff --git a/riscv/sim.h b/riscv/sim.h index 9a0a10b..257de5b 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -24,6 +24,8 @@ public: // used for MMIO addresses virtual bool mmio_load(reg_t addr, size_t len, uint8_t* bytes) = 0; virtual bool mmio_store(reg_t addr, size_t len, const uint8_t* bytes) = 0; + // Callback for processors to let the simulation know they were reset. + virtual void proc_reset(unsigned id) = 0; }; // this class encapsulates the processors and memory in a RISC-V machine. @@ -49,6 +51,9 @@ public: processor_t* get_core(size_t i) { return procs.at(i); } unsigned nprocs() const { return procs.size(); } + // Callback for processors to let the simulation know they were reset. + void proc_reset(unsigned id); + private: std::vector> mems; mmu_t* debug_mmu; // debug port into main memory -- 2.30.2