From: Yunsup Lee Date: Wed, 8 Sep 2010 22:58:39 +0000 (-0700) Subject: [sim] add while to interactive_until X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a9176ab510f8f45990a46da2d5fbe4c4fb4a217c;p=riscv-isa-sim.git [sim] add while to interactive_until --- diff --git a/riscv/insns/mfpcr.h b/riscv/insns/mfpcr.h index d9bfc22..94ce2b2 100644 --- a/riscv/insns/mfpcr.h +++ b/riscv/insns/mfpcr.h @@ -22,7 +22,7 @@ switch(insn.rtype.rb) break; case 17: - val = sim->get_fromhost(); + fromhost = val = sim->get_fromhost(); break; case 24: diff --git a/riscv/insns/mtpcr.h b/riscv/insns/mtpcr.h index cbb580b..5c7289e 100644 --- a/riscv/insns/mtpcr.h +++ b/riscv/insns/mtpcr.h @@ -15,7 +15,8 @@ switch(insn.rtype.rb) break; case 16: - sim->set_tohost(val); + tohost = val; + sim->set_tohost(tohost); break; case 24: diff --git a/riscv/processor.cc b/riscv/processor.cc index fb32f96..e336aa1 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -21,6 +21,8 @@ processor_t::processor_t(sim_t* _sim, char* _mem, size_t _memsz) tid = 0; pcr_k0 = 0; pcr_k1 = 0; + tohost = 0; + fromhost = 0; set_sr(SR_S | (support_64bit ? SR_KX : 0)); set_fsr(0); diff --git a/riscv/processor.h b/riscv/processor.h index 26e49f3..4a1a41d 100644 --- a/riscv/processor.h +++ b/riscv/processor.h @@ -27,6 +27,8 @@ private: reg_t epc; reg_t badvaddr; reg_t ebase; + reg_t tohost; + reg_t fromhost; reg_t pcr_k0; reg_t pcr_k1; uint32_t id; diff --git a/riscv/sim.cc b/riscv/sim.cc index 2bc1775..ca10e09 100644 --- a/riscv/sim.cc +++ b/riscv/sim.cc @@ -53,7 +53,7 @@ void sim_t::run(bool debug) char* p = strtok(s," "); if(!p) { - interactive_run_noisy(std::vector(1,"1")); + interactive_run_noisy(std::string("r"), std::vector(1,"1")); continue; } std::string cmd = p; @@ -63,7 +63,7 @@ void sim_t::run(bool debug) args.push_back(p); - typedef void (sim_t::*interactive_func)(const std::vector&); + typedef void (sim_t::*interactive_func)(const std::string&, const std::vector&); std::map funcs; funcs["r"] = &sim_t::interactive_run_noisy; @@ -75,12 +75,13 @@ void sim_t::run(bool debug) funcs["fregd"] = &sim_t::interactive_fregd; funcs["mem"] = &sim_t::interactive_mem; funcs["until"] = &sim_t::interactive_until; + funcs["while"] = &sim_t::interactive_until; funcs["q"] = &sim_t::interactive_quit; try { if(funcs.count(cmd)) - (this->*funcs[cmd])(args); + (this->*funcs[cmd])(cmd, args); } catch(trap_t t) {} } @@ -94,17 +95,17 @@ void sim_t::step_all(size_t n, size_t interleave, bool noisy) procs[i].step(interleave,noisy); } -void sim_t::interactive_run_noisy(const std::vector& args) +void sim_t::interactive_run_noisy(const std::string& cmd, const std::vector& args) { - interactive_run(args,true); + interactive_run(cmd,args,true); } -void sim_t::interactive_run_silent(const std::vector& args) +void sim_t::interactive_run_silent(const std::string& cmd, const std::vector& args) { - interactive_run(args,false); + interactive_run(cmd,args,false); } -void sim_t::interactive_run(const std::vector& args, bool noisy) +void sim_t::interactive_run(const std::string& cmd, const std::vector& args, bool noisy) { if(args.size()) step_all(atoi(args[0].c_str()),1,noisy); @@ -112,17 +113,17 @@ void sim_t::interactive_run(const std::vector& args, bool noisy) while(1) step_all(1,1,noisy); } -void sim_t::interactive_run_proc_noisy(const std::vector& args) +void sim_t::interactive_run_proc_noisy(const std::string& cmd, const std::vector& args) { - interactive_run_proc(args,true); + interactive_run_proc(cmd,args,true); } -void sim_t::interactive_run_proc_silent(const std::vector& args) +void sim_t::interactive_run_proc_silent(const std::string& cmd, const std::vector& args) { - interactive_run_proc(args,false); + interactive_run_proc(cmd,args,false); } -void sim_t::interactive_run_proc(const std::vector& a, bool noisy) +void sim_t::interactive_run_proc(const std::string& cmd, const std::vector& a, bool noisy) { if(a.size() == 0) return; @@ -137,7 +138,7 @@ void sim_t::interactive_run_proc(const std::vector& a, bool noisy) while(1) procs[p].step(1,noisy); } -void sim_t::interactive_quit(const std::vector& args) +void sim_t::interactive_quit(const std::string& cmd, const std::vector& args) { exit(0); } @@ -180,7 +181,19 @@ reg_t sim_t::get_freg(const std::vector& args) return procs[p].FR[r]; } -void sim_t::interactive_reg(const std::vector& args) +reg_t sim_t::get_tohost(const std::vector& args) +{ + if(args.size() != 1) + throw trap_illegal_instruction; + + int p = atoi(args[0].c_str()); + if(p >= (int)procs.size()) + throw trap_illegal_instruction; + + return procs[p].tohost; +} + +void sim_t::interactive_reg(const std::string& cmd, const std::vector& args) { printf("0x%016llx\n",(unsigned long long)get_reg(args)); } @@ -192,14 +205,14 @@ union fpr double d; }; -void sim_t::interactive_fregs(const std::vector& args) +void sim_t::interactive_fregs(const std::string& cmd, const std::vector& args) { fpr f; f.r = get_freg(args); printf("%g\n",f.s); } -void sim_t::interactive_fregd(const std::vector& args) +void sim_t::interactive_fregd(const std::string& cmd, const std::vector& args) { fpr f; f.r = get_freg(args); @@ -232,17 +245,17 @@ reg_t sim_t::get_mem(const std::vector& args) return val; } -void sim_t::interactive_mem(const std::vector& args) +void sim_t::interactive_mem(const std::string& cmd, const std::vector& args) { printf("0x%016llx\n",(unsigned long long)get_mem(args)); } -void sim_t::interactive_until(const std::vector& args) +void sim_t::interactive_until(const std::string& cmd, const std::vector& args) { if(args.size() < 3) return; - std::string cmd = args[0]; + std::string scmd = args[0]; reg_t val = strtol(args[args.size()-1].c_str(),NULL,16); std::vector args2; @@ -251,16 +264,20 @@ void sim_t::interactive_until(const std::vector& args) while(1) { reg_t current; - if(args[0] == "reg") + if(scmd == "reg") current = get_reg(args2); - else if(args[0] == "pc") + else if(scmd == "pc") current = get_pc(args2); - else if(args[0] == "mem") + else if(scmd == "mem") current = get_mem(args2); + else if(scmd == "tohost") + current = get_tohost(args2); else return; - if(current == val) + if(cmd == "until" && current == val) + break; + if(cmd == "while" && current != val) break; step_all(1,1,false); diff --git a/riscv/sim.h b/riscv/sim.h index 4072fcf..4763713 100644 --- a/riscv/sim.h +++ b/riscv/sim.h @@ -32,26 +32,27 @@ private: void step_all(size_t n, size_t interleave, bool noisy); - void interactive_quit(const std::vector& args); + void interactive_quit(const std::string& cmd, const std::vector& args); - void interactive_run(const std::vector& args, bool noisy); - void interactive_run_noisy(const std::vector& args); - void interactive_run_silent(const std::vector& args); + void interactive_run(const std::string& cmd, const std::vector& args, bool noisy); + void interactive_run_noisy(const std::string& cmd, const std::vector& args); + void interactive_run_silent(const std::string& cmd, const std::vector& args); - void interactive_run_proc(const std::vector& args, bool noisy); - void interactive_run_proc_noisy(const std::vector& args); - void interactive_run_proc_silent(const std::vector& args); + void interactive_run_proc(const std::string& cmd, const std::vector& args, bool noisy); + void interactive_run_proc_noisy(const std::string& cmd, const std::vector& args); + void interactive_run_proc_silent(const std::string& cmd, const std::vector& args); - void interactive_reg(const std::vector& args); - void interactive_fregs(const std::vector& args); - void interactive_fregd(const std::vector& args); - void interactive_mem(const std::vector& args); - void interactive_until(const std::vector& args); + void interactive_reg(const std::string& cmd, const std::vector& args); + 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_until(const std::string& cmd, const std::vector& args); reg_t get_reg(const std::vector& args); reg_t get_freg(const std::vector& args); reg_t get_mem(const std::vector& args); reg_t get_pc(const std::vector& args); + reg_t get_tohost(const std::vector& args); friend class appserver_link_t; };