Commit 0112e711 authored by Benoit Perrot's avatar Benoit Perrot
Browse files

Index: ChangeLog

--- ChangeLog Mon, 12 Jan 2004 15:28:03 +0100 noe (mipsy/2_ChangeLog 1.58 604)
+++ ChangeLog Mon, 12 Jan 2004 17:26:41 +0100 noe (mipsy/2_ChangeLog 1.58 604)
@@ -1,5 +1,13 @@
 2004-01-12  Benoît Perrot  <benoit@lrde.epita.fr>
 
+	* src/vm/cpu.hh,
+	* src/vm/memory.hh,
+	* src/vm/mmu.hh,
+	* src/vm/virtual_machine.hh:
+	Add some comments.
+
+2004-01-12  Benoît Perrot  <benoit@lrde.epita.fr>
+
 	* src/vm/mmu.hh:
 	* src/vm/Makefile.am: Distribute mmu.hh.
 	* src/vm/cpu.hh, src/vm/cpu.cc,
parent 53104451
2004-01-12 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/cpu.hh,
* src/vm/memory.hh,
* src/vm/mmu.hh,
* src/vm/virtual_machine.hh:
Add some comments.
2004-01-12 Benot Perrot <benoit@lrde.epita.fr>
* src/vm/mmu.hh:
......
......@@ -2,30 +2,32 @@
(Created-By-Prcs-Version 1 3 2)
(Project-Description "")
(Project-Version mipsy 0 64)
(Parent-Version mipsy 0 63)
(Project-Version mipsy 0 65)
(Parent-Version mipsy 0 64)
(Version-Log
"Index: ChangeLog
--- ChangeLog Sat, 10 Jan 2004 23:58:50 +0100 noe (mipsy/2_ChangeLog 1.57 604)
+++ ChangeLog Mon, 12 Jan 2004 15:27:22 +0100 noe (mipsy/2_ChangeLog 1.57 604)
@@ -1,3 +1,11 @@
+2004-01-12 Benot Perrot <benoit@lrde.epita.fr>
+
+ * src/vm/mmu.hh:
+ * src/vm/Makefile.am: Distribute mmu.hh.
+ * src/vm/cpu.hh, src/vm/cpu.cc,
--- ChangeLog Mon, 12 Jan 2004 15:28:03 +0100 noe (mipsy/2_ChangeLog 1.58 604)
+++ ChangeLog Mon, 12 Jan 2004 17:26:41 +0100 noe (mipsy/2_ChangeLog 1.58 604)
@@ -1,5 +1,13 @@
2004-01-12 Benot Perrot <benoit@lrde.epita.fr>
+ * src/vm/cpu.hh,
+ * src/vm/memory.hh,
+ * src/vm/mmu.hh,
+ * src/vm/virtual_machine.hh:
+ Use a Memory Management Unit to access memory.
+ Add some comments.
+
2004-01-10 Benot Perrot <benoit@lrde.epita.fr>
* dev/inst-nodes-gen.py: Generate interface of classes in
+2004-01-12 Benot Perrot <benoit@lrde.epita.fr>
+
* src/vm/mmu.hh:
* src/vm/Makefile.am: Distribute mmu.hh.
* src/vm/cpu.hh, src/vm/cpu.cc,
")
(New-Version-Log
"")
(Checkin-Time "Mon, 12 Jan 2004 15:28:03 +0100")
(Checkin-Time "Mon, 12 Jan 2004 17:38:59 +0100")
(Checkin-Login noe)
(Files
......@@ -33,7 +35,7 @@
;; ./
(AUTHORS (mipsy/0_AUTHORS 1.1 604))
(COPYING (mipsy/1_COPYING 1.1 604))
(ChangeLog (mipsy/2_ChangeLog 1.58 604))
(ChangeLog (mipsy/2_ChangeLog 1.59 604))
(Makefile.am (mipsy/3_Makefile.a 1.7 604))
(NEWS (mipsy/b/25_NEWS 1.5 604))
(README (mipsy/4_README 1.2 604))
......@@ -110,13 +112,13 @@
;; ./src/vm/
(src/vm/Makefile.am (mipsy/b/0_Makefile.a 1.4 604))
(src/vm/cpu.hh (mipsy/b/1_cpu.hh 1.10 604))
(src/vm/cpu.hh (mipsy/b/1_cpu.hh 1.11 604))
(src/vm/cpu.cc (mipsy/b/5_virtual_ma 1.18 604))
(src/vm/memory.hh (mipsy/b/2_memory.hh 1.7 604))
(src/vm/mmu.hh (mipsy/c/15_mmu.hh 1.1 604))
(src/vm/memory.hh (mipsy/b/2_memory.hh 1.8 604))
(src/vm/mmu.hh (mipsy/c/15_mmu.hh 1.2 604))
(src/vm/segment.hh (mipsy/b/3_segment.hh 1.2 604))
(src/vm/table.hh (mipsy/b/4_table.hh 1.2 604))
(src/vm/virtual_machine.hh (mipsy/b/6_virtual_ma 1.13 604))
(src/vm/virtual_machine.hh (mipsy/b/6_virtual_ma 1.14 604))
(src/vm/vm-tasks.cc (mipsy/b/7_vm-tasks.c 1.5 604))
(src/vm/vm-tasks.hh (mipsy/b/8_vm-tasks.h 1.3 604))
......
......@@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
/** \file vm/cpu.hh
\brief Declare Central Processor Unit class. */
#ifndef VM_CPU_HH
# define VM_CPU_HH
......@@ -37,10 +39,12 @@ namespace vm
typedef int32_t register_t;
typedef uint32_t uregister_t;
/// Central Processor Unit abstraction
class Cpu:
protected inst::ConstVisitor
{
public:
/// General purpose registers indices
enum kind_t
{
zero = 0,
......@@ -57,7 +61,10 @@ namespace vm
ra = 31
};
/** \name Constructor and destructor
\{ */
public:
/// Construct a CPU.
Cpu(Mmu& mmu,
std::istream& istr,
std::ostream& ostr,
......@@ -70,9 +77,11 @@ namespace vm
{
reset();
}
/** \} */
public:
void reset()
/// Reset the CPU (set general purpose registers to zero, etc.)
void reset()
{
halt = false;
......@@ -87,32 +96,48 @@ namespace vm
hi = 0;
}
/** \name General purpose registers accessors.
\{ */
public:
register_t get_register(kind_t k) const
/// Return the general purpose register \a k.
register_t get_register(kind_t k) const
{
return GPR[k];
}
void set_register(kind_t k, register_t r)
/// Set the general purpose register \a k to \a r.
void set_register(kind_t k, register_t r)
{
if (k != Cpu::zero)
GPR[k] = r;
}
/** \} */
bool has_unlimited(int i) const
/** \name Unlimited registers accessors.
\{ */
public:
/// Return true if the unlimited register \a i exists.
bool has_unlimited(int i) const
{
return unlimited.has(i);
}
register_t get_unlimited(int i) const
/// Return the unlimited register indexed by \a i.
register_t get_unlimited(int i) const
{
precondition(has_unlimited(i));
return unlimited.get(i);
}
void set_unlimited(int i, register_t r)
/// Set the unlimited register indexed by \a i to \a r.
void set_unlimited(int i, register_t r)
{
unlimited.put(i, r);
}
/** \} */
register_t get_register(const inst::Register& reg) const
/** \name Registers unified accessors.
\{ */
public:
/// Return the register identified by \a reg.
register_t get_register(const inst::Register& reg) const
{
if (reg.get_kind() == inst::Register::unlimited)
{
......@@ -123,26 +148,38 @@ namespace vm
Cpu::zero <= reg.get_index() && reg.get_index() <= Cpu::ra);
return get_register((kind_t) reg.get_index());
}
void set_register(const inst::Register& reg, register_t r)
/// Set the register identified by \a reg to \a r.
void set_register(const inst::Register& reg, register_t r)
{
if (reg.get_kind() == inst::Register::unlimited)
{
unlimited.put(reg.get_index (), r);
unlimited.put(reg.get_index(), r);
return;
}
precondition(reg.get_kind() == inst::Register::general &&
Cpu::zero <= reg.get_index() && reg.get_index() <= Cpu::ra);
set_register((kind_t) reg.get_index(), r);
}
/** \} */
register_t get_hi() const { return hi; }
void set_hi(register_t r) { hi = r; }
register_t get_lo() const { return lo; }
void set_lo(register_t r) { lo = r; }
register_t get_pc() const { return pc; }
void set_pc(register_t r) { pc = r; }
/** \name Special registers accessors.
\{ */
public:
/// Return the HI register.
register_t get_hi() const { return hi; }
/// Set the HI register to \a r.
void set_hi(register_t r) { hi = r; }
/// Return the LO register.
register_t get_lo() const { return lo; }
/// Set the LO register to \a r.
void set_lo(register_t r) { lo = r; }
/// Return the PC register.
register_t get_pc() const { return pc; }
/// Set the PC register to \a r.
void set_pc(register_t r) { pc = r; }
/** \} */
protected:
virtual void visit(const inst::Add& add);
......@@ -207,26 +244,33 @@ namespace vm
virtual void visit(const inst::Syscall& sycall);
protected:
Mmu& mmu;
register_t GPR[32];
register_t hi, lo;
register_t pc;
/// Memory management unit link.
Mmu& mmu;
/// General purpose registers.
register_t GPR[32];
/// Special HIgh register.
register_t hi;
/// Special LOw register.
register_t lo;
/// Special Program Counter.
register_t pc;
/// Unilimited registers.
Table<int, register_t> unlimited;
public:
bool get_halt() const { return halt; }
bool get_halt() const { return halt; }
protected:
bool halt;
bool halt;
std::istream& istr;
std::ostream& ostr;
protected:
void call()
void call()
{
if (check_callee_save_p)
for (int i = Cpu::s0; i <= Cpu::s7; ++i)
......@@ -235,7 +279,7 @@ namespace vm
unlimited.begin_scope();
}
void ret()
void ret()
{
unlimited.end_scope();
......@@ -246,7 +290,7 @@ namespace vm
std::cerr
<< "Warning: callee save register `$s" << i - Cpu::s0
<< "' was not preserved across last call to 0x"
<< std::hex << call_stack.top() << std::dec << std::endl;
<< std::hex << call_stack.top() << std::dec << std::endl;
set_register((Cpu::kind_t) i, get_unlimited(-i));
exit_set(exit_runtime);
}
......@@ -254,10 +298,12 @@ namespace vm
}
protected:
std::stack<register_t> call_stack;
bool check_callee_save_p;
bool check_callee_save_p;
public:
void step()
/// Make one execution step.
void step()
{
const inst::Inst& ri = mmu.inst()[pc / 4];
pc = pc + 4;
......@@ -267,7 +313,7 @@ namespace vm
ri.accept(*this);
}
protected:
bool trace_p;
bool trace_p;
};
} // namespace vm
......
......@@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
/** \file vm/memory.hh
\brief Declare Memory class. */
#ifndef VM_MEMORY_HH
# define VM_MEMORY_HH
......@@ -33,18 +35,23 @@
namespace vm
{
/// Memory abstraction
class Memory
{
public:
static const int stack_bottom = INT32_MAX - 3;
static const int default_stack_size = 512 * 1024;
/** \name Constructor and destructor
\{ */
public:
/// Construct a Memory.
Memory(int stack_size = default_stack_size):
heap(0), stack(stack_size), stack_top(stack_bottom - stack_size + 4)
{
assertion(stack_size > 0);
}
/** \} */
protected:
int translate(int offset) const
......@@ -75,6 +82,8 @@ namespace vm
return stack.size ();
}
/** \name Store instructions.
\{ */
public:
void store(const inst::DataSection& data_section)
{
......@@ -83,6 +92,7 @@ namespace vm
heap.store_byte(i, data_section.load_byte(i));
}
/// Store a byte in memory.
void store_byte(int offset, int b)
{
precondition(offset >= 0);
......@@ -91,7 +101,7 @@ namespace vm
else
stack.store_byte(translate(offset), b);
}
/// Store a word in memory.
void store_word(int offset, int w)
{
precondition(offset >= 0);
......@@ -100,9 +110,12 @@ namespace vm
else
stack.store_word(translate(offset), w);
}
/** \} */
/** \name Load instructions.
\{ */
public:
/// Load a byte from memory.
int load_byte(int offset) const
{
precondition(offset >= 0);
......@@ -110,7 +123,7 @@ namespace vm
return heap.load_byte(offset);
return stack.load_byte(translate(offset));
}
/// Load a word from memory.
int load_word(int offset) const
{
precondition(offset >= 0);
......@@ -118,7 +131,7 @@ namespace vm
return heap.load_word(offset);
return stack.load_word(translate(offset));
}
/** \} */
protected:
Segment heap;
......
......@@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
/** \file vm/memory.hh
\brief Declare Memory Management Unit class. */
#ifndef VM_MMU_HH
# define VM_MMU_HH
......@@ -26,32 +28,43 @@
namespace vm
{
/// Memory Management Unit abstraction
class Mmu
{
/** \name Constructor and destructor
\{ */
public:
Mmu(Memory& memory):
memory_(memory),
text_section_(0)
{}
/** \} */
/** \name Proxy for memory data access.
\{ */
public:
void data_store(const inst::DataSection& data_section)
{
memory_.store(data_section);
}
/// Store a byte in memory.
void data_store_byte(int offset, int b)
{
memory_.store_byte(offset, b);
}
/// Store a word in memory.
void data_store_word(int offset, int w)
{
memory_.store_word(offset, w);
}
/// Load a byte from memory.
int data_load_byte(int offset) const
{
return memory_.load_byte(offset);
}
/// Load a word from memory.
int data_load_word(int offset) const
{
return memory_.load_word(offset);
......@@ -61,7 +74,10 @@ namespace vm
{
return memory_.sbrk(size);
}
/** \} */
/** \name Proxy for memory instruction access.
\{ */
public:
const inst::TextSection& inst() const
{
......@@ -71,9 +87,12 @@ namespace vm
{
text_section_ = &text_section;
}
/** \} */
protected:
/// Memory link.
Memory& memory_;
const inst::TextSection* text_section_;
};
......
......@@ -16,6 +16,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
/** \file vm/virtual_machine.hh
\brief Declare Virtual Machine class. */
#ifndef VM_VIRTUAL_MACHINE_HH
# define VM_VIRTUAL_MACHINE_HH
......@@ -32,9 +34,12 @@
namespace vm
{
/// Virtual Machine abstraction
class VirtualMachine
{
/** \name Constructor and destructor.
\{ */
public:
VirtualMachine(bool check_callee_save_p,
bool trace_exec_p,
......@@ -44,9 +49,10 @@ namespace vm
cpu(mmu, istr, ostr, check_callee_save_p, trace_exec_p)
{
}
/** \} */
public:
/// Load a program into memory.
void load_program(const inst::Program& program)
{
if (! program.text_section ().has_label(inst::Label("main")))
......@@ -61,6 +67,7 @@ namespace vm
}
public:
/// Execute a program.
void execute()
{
// FIXME: precondition on loaded program
......@@ -70,8 +77,11 @@ namespace vm
}
protected:
/// Memory block.
Memory memory;
/// Memory management unit.
Mmu mmu;
/// Central processor unit.
Cpu cpu;
};
......
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