From 6e2844c1b5d1b2c8bbc6b36a29726c19fd0c0593 Mon Sep 17 00:00:00 2001 From: Andrew Waterman Date: Sat, 16 Apr 2011 19:44:16 -0700 Subject: [PATCH] [sim] added "str" debug command it prints the c string starting at the specified memory address. --- riscv/sim.cc | 17 +++++++++++++++++ riscv/sim.h | 1 + 2 files changed, 18 insertions(+) diff --git a/riscv/sim.cc b/riscv/sim.cc index 50264ed..7ac60c1 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -75,6 +75,7 @@ void sim_t::run(bool debug) funcs["fregs"] = &sim_t::interactive_fregs; funcs["fregd"] = &sim_t::interactive_fregd; funcs["mem"] = &sim_t::interactive_mem; + funcs["str"] = &sim_t::interactive_str; funcs["until"] = &sim_t::interactive_until; funcs["while"] = &sim_t::interactive_until; funcs["q"] = &sim_t::interactive_quit; @@ -254,6 +255,22 @@ void sim_t::interactive_mem(const std::string& cmd, const std::vector& args) +{ + if(args.size() != 1) + throw trap_illegal_instruction; + + reg_t addr = strtol(args[0].c_str(),NULL,16); + + mmu_t mmu(mem,memsz); + char ch; + + while((ch = mmu.load_uint8(addr++))) + putchar(ch); + + putchar('\n'); +} + void sim_t::interactive_until(const std::string& cmd, const std::vector& args) { if(args.size() < 3) diff --git a/riscv/sim.h b/riscv/sim.h index 722fe64..a471500 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -46,6 +46,7 @@ private: void interactive_fregs(const std::string& cmd, const std::vector& args); void interactive_fregd(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); void interactive_until(const std::string& cmd, const std::vector& args); reg_t get_reg(const std::vector& args); -- 2.30.2