virtual_machine.hh 2.96 KB
Newer Older
Benoit Perrot's avatar
Benoit Perrot committed
1
//
Benoit Perrot's avatar
Benoit Perrot committed
2
// This file is part of Nolimips, a MIPS simulator with unlimited registers
3
// Copyright (C) 2003, 2004, 2006 Benoit Perrot <benoit@lrde.epita.fr>
Benoit Perrot's avatar
Benoit Perrot committed
4
//
Benoit Perrot's avatar
Benoit Perrot committed
5
// Nolimips is free software; you can redistribute it and/or modify
Benoit Perrot's avatar
Benoit Perrot committed
6
7
8
// 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.
9
//
Benoit Perrot's avatar
Benoit Perrot committed
10
// Nolimips is distributed in the hope that it will be useful,
Benoit Perrot's avatar
Benoit Perrot committed
11
12
13
// 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.
14
//
Benoit Perrot's avatar
Benoit Perrot committed
15
16
17
18
// 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
//
Benoit Perrot's avatar
Benoit Perrot committed
19
20
/** \file vm/virtual_machine.hh
    \brief Declare Virtual Machine class. */
21
22
23
#ifndef VM_VIRTUAL_MACHINE_HH
# define VM_VIRTUAL_MACHINE_HH

24
# include <ostream>
25

26
# include "vm/fwd.hh"
27
# include "vm/memory.hh"
Benoit Perrot's avatar
Benoit Perrot committed
28
# include "vm/mmu.hh"
Benoit Perrot's avatar
Benoit Perrot committed
29
# include "vm/cp0.hh"
Benoit Perrot's avatar
Benoit Perrot committed
30
# include "vm/cpu.hh"
31

32
33
namespace inst { class Program; }

34
35
namespace vm
{
Benoit Perrot's avatar
Benoit Perrot committed
36
37

  /// Virtual Machine abstraction
38
  class VirtualMachine
39
  {
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  public:
    enum mode_type
      {
	normal,
	step
      };

    enum status_type
      {
	run,
	pause,
	stop,
	halt
      };

Benoit Perrot's avatar
Benoit Perrot committed
55
56
    /** \name Constructor and destructor.
	\{ */
57
  public:
58
    VirtualMachine(mode_type mode = normal);
Benoit Perrot's avatar
Benoit Perrot committed
59
    /** \} */
60

61
62
  public:
    /// Reset the vm
63
    void reset();
Benoit Perrot's avatar
Benoit Perrot committed
64

65
    /// Print the vm
66
    void write(std::ostream& ostr) const;
67

68
  public:
Benoit Perrot's avatar
Benoit Perrot committed
69
    /// Load a program into memory.
70
    void load_program(const inst::Program &program);
71

72
  public:
Benoit Perrot's avatar
Benoit Perrot committed
73
    /// Execute a program.
74
    void execute();
75

76
77
78
79
    /** \name Shell entry point
	\{ */
  public:
    /// Execute a program
80
    void execute(bool trace_p);
81
82

    /// Add a breakpoint
83
    void add_breakpoint(int offset);
84

Benoit Perrot's avatar
Benoit Perrot committed
85
    /// Return CPU's call stack
86
    const std::vector<register_type> &get_call_stack() const;
87
88
89

  public:
    /// Make the vm runnable
90
    void set_runnable();
91
92

    /// Run only the next instruction
93
    void set_run_next();
94
95

    /// Return the status of the vm
96
    status_type get_status() const;
97

98
    const Cp0 &get_cp0() const;
99
    Cp0 &get_cp0();
100

101
102
    const Cpu &get_cpu() const;
    Cpu	&get_cpu();
103

104
105
106
107
108
109
110
  protected:
    /// The virtual machine mode.
    mode_type	mode_;
    /// The virtual machine status.
    status_type	status_;
    /** \} */

111
112
113
114
115
116
117
  protected:
    int main_offset_; // FIXME: Must disappear!

  protected:
    /// The list of breakpoints
    std::list<int> breakpoints_; // FIXME: Should be in dedicated hardware!

118
  protected:
Benoit Perrot's avatar
Benoit Perrot committed
119
    /// Memory block.
120
    Memory memory_;
Benoit Perrot's avatar
Benoit Perrot committed
121

Benoit Perrot's avatar
Benoit Perrot committed
122
    /// Memory management unit.
123
    Mmu mmu_;
Benoit Perrot's avatar
Benoit Perrot committed
124
    /// Control coprocessor.
125
    Cp0 cp0_;
Benoit Perrot's avatar
Benoit Perrot committed
126
    /// Central processor unit.
127
    Cpu cpu_;
128
129
  };

130
  inline std::ostream&
131
  operator<<(std::ostream &os, const VirtualMachine &vm);
132

133
134
} // namespace vm

135
136
# include "vm/virtual_machine.hxx"

137
#endif // !VM_VIRTUAL_MACHINE_HH