diff --git a/riscv/interactive.cc b/riscv/interactive.cc index 71e26e6221..3f7651312d 100644 --- a/riscv/interactive.cc +++ b/riscv/interactive.cc @@ -277,6 +277,7 @@ void sim_t::interactive() funcs["fregs"] = &sim_t::interactive_fregs; funcs["fregd"] = &sim_t::interactive_fregd; funcs["pc"] = &sim_t::interactive_pc; + funcs["insn"] = &sim_t::interactive_insn; funcs["priv"] = &sim_t::interactive_priv; funcs["mem"] = &sim_t::interactive_mem; funcs["str"] = &sim_t::interactive_str; @@ -367,6 +368,7 @@ void sim_t::interactive_help(const std::string& cmd, const std::vector # Display double precision in \n" "vreg [reg] # Display vector [reg] (all if omitted) in \n" "pc # Show current PC in \n" + "insn # Show current instruction corresponding to PC in \n" "priv # Show current privilege level in \n" "mem [core] # Show contents of virtual memory in [core] (physical memory if omitted)\n" "str [core] # Show NUL-terminated C string at virtual address in [core] (physical address if omitted)\n" @@ -377,6 +379,8 @@ void sim_t::interactive_help(const std::string& cmd, const std::vector # Run noisy and stop when in hits \n" "until pc # Stop when PC in hits \n" "untiln pc # Run noisy and stop when PC in hits \n" + "until insn # Stop when instruction corresponding to PC in hits \n" + "untiln insn # Run noisy and stop when instruction corresponding to PC in hits \n" "until mem [core] # Stop when virtual memory in [core] (physical address if omitted) becomes \n" "untiln mem [core] # Run noisy and stop when virtual memory in [core] (physical address if omitted) becomes \n" "while reg # Run while in is \n" @@ -448,6 +452,54 @@ void sim_t::interactive_pc(const std::string& cmd, const std::vectorload(addr); + break; + case 4: + val = mmu->load(addr); + break; + case 2: + case 6: + val = mmu->load(addr); + break; + default: + val = mmu->load(addr); + break; + } + return val; +} + +reg_t sim_t::get_insn(const std::vector& args) +{ + if (args.size() != 1) + throw trap_interactive(); + + processor_t *p = get_core(args[0]); + reg_t addr = p->get_state()->pc; + mmu_t* mmu = p->get_mmu(); + return load(mmu, addr); +} + +void sim_t::interactive_insn(const std::string& cmd, const std::vector& args) +{ + if (args.size() != 1) + throw trap_interactive(); + + 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; +} + void sim_t::interactive_priv(const std::string& cmd, const std::vector& args) { if (args.size() != 1) @@ -647,27 +699,11 @@ reg_t sim_t::get_mem(const std::vector& args) addr_str = args[1]; } - reg_t addr = strtol(addr_str.c_str(),NULL,16), val; + reg_t addr = strtol(addr_str.c_str(),NULL,16); if (addr == LONG_MAX) addr = strtoul(addr_str.c_str(),NULL,16); - switch (addr % 8) - { - case 0: - val = mmu->load(addr); - break; - case 4: - val = mmu->load(addr); - break; - case 2: - case 6: - val = mmu->load(addr); - break; - default: - val = mmu->load(addr); - break; - } - return val; + return load(mmu, addr); } void sim_t::interactive_mem(const std::string& cmd, const std::vector& args) @@ -743,6 +779,7 @@ void sim_t::interactive_until(const std::string& cmd, const std::vectorget_mtimecmp(p->get_id()) << std::endl; } - diff --git a/riscv/sim.h b/riscv/sim.h index 726de7d794..540d80d857 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -123,6 +123,7 @@ class sim_t : public htif_t, public simif_t void interactive_fregs(const std::string& cmd, const std::vector& args); void interactive_fregd(const std::string& cmd, const std::vector& args); void interactive_pc(const std::string& cmd, const std::vector& args); + void interactive_insn(const std::string& cmd, const std::vector& args); void interactive_priv(const std::string& cmd, const std::vector& args); void interactive_mem(const std::string& cmd, const std::vector& args); void interactive_str(const std::string& cmd, const std::vector& args); @@ -136,6 +137,7 @@ class sim_t : public htif_t, public simif_t freg_t get_freg(const std::vector& args, int size); reg_t get_mem(const std::vector& args); reg_t get_pc(const std::vector& args); + reg_t get_insn(const std::vector& args); friend class processor_t; friend class mmu_t;