Commit 7691c8d0 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

from  Benoît Perrot  <benoit@lrde.epita.fr>

        * src/vm/virtual_machine.hh: Move the implementation of
        rarely used methods to...
        * src/vm/virtual_machine.cc: This file.

parent 99fde49b
2004-07-14 Benot Perrot <benoit@lrde.epita.fr> 2004-07-14 Benot Perrot <benoit@lrde.epita.fr>
* src/shell.cc (readline): When the true readline is lacking, use * src/vm/virtual_machine.hh: Move the implementation of
STL's getline instead of istream::operator>> to get a line instead rarely used methods to...
of a word. * src/vm/virtual_machine.cc: This file.
2004-07-14 Benot Perrot <benoit@lrde.epita.fr>
* src/shell/shell.cc (readline): When the true readline is
lacking, use STL's getline instead of istream::operator>> to get a
line instead of a word.
Reported by Julien Vanegue. Reported by Julien Vanegue.
2004-07-14 Benot Perrot <benoit@lrde.epita.fr> 2004-07-14 Benot Perrot <benoit@lrde.epita.fr>
......
...@@ -9,5 +9,5 @@ libvm_a_SOURCES = \ ...@@ -9,5 +9,5 @@ libvm_a_SOURCES = \
cpu.hh cpu.cc \ cpu.hh cpu.cc \
segment.hh \ segment.hh \
memory.hh \ memory.hh \
virtual_machine.hh \ virtual_machine.hh virtual_machine.cc \
vm-tasks.hh vm-tasks.cc vm-tasks.hh vm-tasks.cc
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2003, 2004 Benoit Perrot <benoit@lrde.epita.fr>
//
// Nolimips is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Nolimips is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
#include "vm/virtual_machine.hh"
namespace vm
{
void
VirtualMachine::reset()
{
}
void
VirtualMachine::load_program(const inst::Program &program)
{
if (! program.text_section ().has_label(inst::Label("main")))
{
std::cerr << "No `main' label in assembly file." << std::endl;
exit_set(exit_runtime);
return;
}
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
while (!cpu_.get_halt())
{
cpu_.step();
cp0_.set_count(cp0_.get_count() + 1);
}
}
void
VirtualMachine::execute(bool trace_p)
{
if (status_ == stop)
return;
cpu_.set_trace(trace_p);
while (status_ == run)
{
cpu_.step();
cp0_.set_count(cp0_.get_count() + 1);
if (cpu_.get_halt())
{
status_ = halt;
std::cerr << "Program exited." << std::endl;
break;
}
if (has(breakpoints_, cpu_.get_pc()))
{
std::cout << "Breakpoint at pc = " << cpu_.get_pc() << std::endl;
status_ = pause;
}
if (mode_ == step)
status_ = pause;
}
}
void
VirtualMachine::add_breakpoint(const std::string& label)
{
int offset;
if (!has_label(label))
{
std::cerr << "Label " << label << " not found" << std::endl;
return;
}
offset = get_offset(label);
std::cout << "Breakpoint " << label
<< " at " << offset << " (+4)" << std::endl;
breakpoints_.push_back(offset + 4);
}
} // namespace vm
...@@ -73,11 +73,10 @@ namespace vm ...@@ -73,11 +73,10 @@ namespace vm
public: public:
/// Reset the vm /// Reset the vm
void reset() void reset();
{
}
/// Print the vm /// Print the vm
void print(std::ostream& ostr) const void print(std::ostream& ostr) const
{ {
// FIXME: print the whole cpu, and cp0. // FIXME: print the whole cpu, and cp0.
ostr << cpu_; ostr << cpu_;
...@@ -86,31 +85,11 @@ namespace vm ...@@ -86,31 +85,11 @@ namespace vm
public: public:
/// Load a program into memory. /// Load a program into memory.
void load_program(const inst::Program& program) void load_program(const inst::Program& program);
{
if (! program.text_section ().has_label(inst::Label("main")))
{
std::cerr << "No `main' label in assembly file." << std::endl;
exit_set(exit_runtime);
return;
}
mmu_.data_store(program.data_section());
mmu_.inst_store(program.text_section());
cpu_.set_pc(program.text_section ().get_offset(inst::Label("main")));
}
public: public:
/// Execute a program. /// Execute a program.
void execute() void execute();
{
// FIXME: precondition on loaded program
while (!cpu_.get_halt())
{
cpu_.step();
cp0_.set_count(cp0_.get_count() + 1);
}
}
/** \name Shell entry point /** \name Shell entry point
\{ */ \{ */
...@@ -129,48 +108,10 @@ namespace vm ...@@ -129,48 +108,10 @@ namespace vm
public: public:
/// Execute a program /// Execute a program
void execute(bool trace_p) void execute(bool trace_p);
{
if (status_ == stop)
return;
cpu_.set_trace(trace_p);
while (status_ == run)
{
cpu_.step();
cp0_.set_count(cp0_.get_count() + 1);
if (cpu_.get_halt())
{
status_ = halt;
std::cerr << "Program exited." << std::endl;
break;
}
if (has(breakpoints_, cpu_.get_pc()))
{
std::cout << "Breakpoint at pc = " << cpu_.get_pc() << std::endl;
status_ = pause;
}
if (mode_ == step)
status_ = pause;
}
}
/// Add a breakpoint /// Add a breakpoint
void add_breakpoint(const std::string& label) void add_breakpoint(const std::string& label);
{
int offset;
if (!has_label(label))
{
std::cerr << "Label " << label << " not found" << std::endl;
return;
}
offset = get_offset(label);
std::cout << "Breakpoint " << label
<< " at " << offset << " (+4)" << std::endl;
breakpoints_.push_back(offset + 4);
}
protected: protected:
/// The list of breakpoints /// The list of breakpoints
...@@ -179,21 +120,21 @@ namespace vm ...@@ -179,21 +120,21 @@ namespace vm
public: public:
/// Make the vm runnable /// Make the vm runnable
void set_runnable() void set_runnable()
{ {
status_ = run; status_ = run;
mode_ = normal; mode_ = normal;
} }
/// Run only the next instruction /// Run only the next instruction
void set_run_next() void set_run_next()
{ {
status_ = run; status_ = run;
mode_ = step; mode_ = step;
} }
/// Return the status of the vm /// Return the status of the vm
status_type get_status() const status_type get_status() const
{ {
return status_; return status_;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment