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