aboutsummaryrefslogtreecommitdiff
path: root/riscv
diff options
context:
space:
mode:
authorJerry Zhao <jerryz123@berkeley.edu>2024-06-28 14:02:58 -0700
committerGitHub <noreply@github.com>2024-06-28 14:02:58 -0700
commit1b1a333763eae2e74dbf38b39d9adab39c4bed7c (patch)
tree9634f6ec1a17584ea82e1f9d994bbe1a179b4bda /riscv
parentf2a20b185e3c339a9dec60d75853847734e44e85 (diff)
parentabb2d55541d38a78773e185c760a911e58997e41 (diff)
downloadriscv-isa-sim-1b1a333763eae2e74dbf38b39d9adab39c4bed7c.zip
riscv-isa-sim-1b1a333763eae2e74dbf38b39d9adab39c4bed7c.tar.gz
riscv-isa-sim-1b1a333763eae2e74dbf38b39d9adab39c4bed7c.tar.bz2
Merge pull request #1714 from abejgonzalez/fix-interactive-insn
Fix insn interactive command (catch/print trap, use proper access func)
Diffstat (limited to 'riscv')
-rw-r--r--riscv/interactive.cc59
1 files changed, 30 insertions, 29 deletions
diff --git a/riscv/interactive.cc b/riscv/interactive.cc
index b0855fa..9a4b697 100644
--- a/riscv/interactive.cc
+++ b/riscv/interactive.cc
@@ -452,37 +452,16 @@ void sim_t::interactive_pc(const std::string& cmd, const std::vector<std::string
<< zext(get_pc(args), max_xlen) << std::endl;
}
-static reg_t load(mmu_t* mmu, reg_t addr) {
- reg_t val;
-
- switch (addr % 8)
- {
- case 0:
- val = mmu->load<uint64_t>(addr);
- break;
- case 4:
- val = mmu->load<uint32_t>(addr);
- break;
- case 2:
- case 6:
- val = mmu->load<uint16_t>(addr);
- break;
- default:
- val = mmu->load<uint8_t>(addr);
- break;
- }
- return val;
-}
-
reg_t sim_t::get_insn(const std::vector<std::string>& args)
{
if (args.size() != 1)
throw trap_interactive();
processor_t *p = get_core(args[0]);
- reg_t addr = p->get_state()->pc;
+ reg_t pc = p->get_state()->pc;
mmu_t* mmu = p->get_mmu();
- return load(mmu, addr);
+ icache_entry_t* ic_entry = mmu->access_icache(pc);
+ return ic_entry->data.insn.bits();
}
void sim_t::interactive_insn(const std::string& cmd, const std::vector<std::string>& args)
@@ -493,11 +472,16 @@ void sim_t::interactive_insn(const std::string& cmd, const std::vector<std::stri
processor_t *p = get_core(args[0]);
int max_xlen = p->get_isa().get_max_xlen();
- insn_t insn(get_insn(args));
-
std::ostream out(sout_.rdbuf());
- out << std::hex << std::setfill('0') << "0x" << std::setw(max_xlen/4)
- << zext(insn.bits(), max_xlen) << " " << p->get_disassembler()->disassemble(insn) << std::endl;
+ try
+ {
+ insn_t insn(get_insn(args));
+ out << std::hex << std::setfill('0') << "0x" << std::setw(max_xlen/4)
+ << zext(insn.bits(), max_xlen) << " " << p->get_disassembler()->disassemble(insn) << std::endl;
+ }
+ catch (trap_t& t) {
+ out << "Unable to obtain insn due to " << t.name() << std::endl;
+ }
}
void sim_t::interactive_priv(const std::string& cmd, const std::vector<std::string>& args)
@@ -708,7 +692,24 @@ reg_t sim_t::get_mem(const std::vector<std::string>& args)
if (addr == LONG_MAX)
addr = strtoul(addr_str.c_str(),NULL,16);
- return load(mmu, addr);
+ reg_t val;
+ switch (addr % 8)
+ {
+ case 0:
+ val = mmu->load<uint64_t>(addr);
+ break;
+ case 4:
+ val = mmu->load<uint32_t>(addr);
+ break;
+ case 2:
+ case 6:
+ val = mmu->load<uint16_t>(addr);
+ break;
+ default:
+ val = mmu->load<uint8_t>(addr);
+ break;
+ }
+ return val;
}
void sim_t::interactive_mem(const std::string& cmd, const std::vector<std::string>& args)