
Index: ChangeLog from Benoît Perrot <benoit@lrde.epita.fr> * src/vm/memory.hh, src/vm/mmu.hh, src/vm/cpu.cc, * src/vm/virtual_machine.cc: Implement reset() method. * src/vm/virtual_machine.hh, src/vm/virtual_machine.hh: Keep and reload the main offset of loaded program. 2004-07-14 Benoît Perrot <benoit@lrde.epita.fr> Index: src/vm/memory.hh --- src/vm/memory.hh (revision 109) +++ src/vm/memory.hh (working copy) @@ -53,6 +53,12 @@ } /** \} */ + /// Reset the memory + void reset() + { + // DO NOT zero-ify the memory + } + protected: int translate(int offset) const { Index: src/vm/virtual_machine.hh --- src/vm/virtual_machine.hh (revision 112) +++ src/vm/virtual_machine.hh (working copy) @@ -86,6 +86,8 @@ public: /// Load a program into memory. void load_program(const inst::Program& program); + protected: + int main_offset_; // FIXME: Must disappear! public: /// Execute a program. Index: src/vm/cpu.cc --- src/vm/cpu.cc (revision 109) +++ src/vm/cpu.cc (working copy) @@ -69,6 +69,7 @@ // Initialize special registers to 0. lo_ = 0; hi_ = 0; + pc_ = 0; // Initialize pipeline with nops for (unsigned i = 0; i < 6; ++i) Index: src/vm/mmu.hh --- src/vm/mmu.hh (revision 109) +++ src/vm/mmu.hh (working copy) @@ -40,6 +40,12 @@ {} /** \} */ + /// Reset the mmu + void reset() + { + // Nothing to do? + } + /** \name Proxy for memory data access. \{ */ public: Index: src/vm/virtual_machine.cc --- src/vm/virtual_machine.cc (revision 112) +++ src/vm/virtual_machine.cc (working copy) @@ -24,27 +24,37 @@ void VirtualMachine::reset() { + memory_.reset(); + mmu_.reset(); + cp0_.reset(); + cpu_.reset(); } void VirtualMachine::load_program(const inst::Program &program) { + reset(); + if (! program.text_section ().has_label(inst::Label("main"))) { std::cerr << "No `main' label in assembly file." << std::endl; exit_set(exit_runtime); return; } + main_offset_ = program.text_section().get_offset(inst::Label("main")); mmu_.data_store(program.data_section()); mmu_.inst_store(program.text_section()); - cpu_.set_pc(program.text_section ().get_offset(inst::Label("main"))); } void VirtualMachine::execute() { - // FIXME: precondition on loaded program + // FIXME: VirtualMachine::reset()? + cp0_.reset(); + cpu_.reset(); + // FIXME: precondition on loaded program + cpu_.set_pc(main_offset_); while (!cpu_.get_halt()) { cpu_.step(); @@ -55,9 +65,14 @@ void VirtualMachine::execute(bool trace_p) { + // FIXME: VirtualMachine::reset()? + cp0_.reset(); + cpu_.reset(); + if (status_ == stop) return; + cpu_.set_pc(main_offset_); cpu_.set_trace(trace_p); while (status_ == run) {