cp0.hxx 2.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// This file is part of Nolimips, a MIPS simulator with unlimited registers
// Copyright (C) 2006 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
//
#ifndef VM_CP0_HXX
# define VM_CP0_HXX

# include "vm/cp0.hh"
23
# include "vm/system_library.hh"
24
25
26
27
28
29
30
31
32
33

# include "inst/register.hh"

# include "common.hh"

namespace vm
{

  //
  inline
34
35
36
  Cp0::Cp0(Cpu &cpu):
    cpu_(cpu),
    system_library_(0)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  {
    reset();
  }

  inline void
  Cp0::reset()
  {
    // Initialize registers to 0.
    for (unsigned i = 0; i < 32; ++i)
      registers[i] = 0;

    fatal_exception_ = false;
  }

51
52
53
54
55
56
  inline void
  Cp0::set_system_library(SystemLibrary *l)
  {
    system_library_ = l;
  }

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  //
  inline void
  Cp0::set_count(Cp0::register_type r)
  {
    registers[count] = r;
  }
  inline Cp0::register_type
  Cp0::get_count() const
  {
    return registers[count];
  }

  inline void
  Cp0::set_register(const inst::Register &reg, Cp0::register_type r)
  {
    precondition(reg.get_kind() == inst::Register::generic);
    registers[reg.get_index()] = r;
  }
  inline Cp0::register_type
  Cp0::get_register(const inst::Register &reg) const
  {
    precondition(reg.get_kind() == inst::Register::generic);
    return registers[reg.get_index()];
  }
81
82
83
84
85
  inline Cp0::register_type
  Cp0::get_register(kind_type k) const
  {
    return registers[k];
  }
86
87
88
89
90
91
92

  //
  inline void
  Cp0::raise_overflow()
  {
    registers[cause] = overflow;
    std::cerr << "Runtime Exception: Overflow" << std::endl;
93
    fatal_exception_ = true;
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  }

  inline void
  Cp0::raise_addr_load()
  {
    registers[cause] = addr_load;
    std::cerr << "Runtime Exception: Address error on load" << std::endl;
    fatal_exception_ = true;
  }
  inline void
  Cp0::raise_addr_store()
  {
    registers[cause] = addr_store;
    std::cerr << "Runtime Exception: Address error on store" << std::endl;
    fatal_exception_ = true;
  }

111
112
113
114
115
116
117
  inline void
  Cp0::raise_syscall()
  {
    precondition(system_library_);
    system_library_->invoke(cpu_);
  }

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
  //
  inline void
  Cp0::set_fatal_exception()
  {
    fatal_exception_ = true;
  }

  inline bool
  Cp0::fatal_exception() const
  {
    return fatal_exception_;
  }

} // namespace vm

#endif // !VM_CP0_HXX