gem5  v20.1.0.0
faults.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * Copyright (c) 2007 MIPS Technologies, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __MIPS_FAULTS_HH__
31 #define __MIPS_FAULTS_HH__
32 
34 #include "cpu/thread_context.hh"
35 #include "debug/MipsPRA.hh"
36 #include "sim/faults.hh"
37 #include "sim/full_system.hh"
38 
39 namespace MipsISA
40 {
41 
42 typedef Addr FaultVect;
43 
44 enum ExcCode {
45  // A dummy value to use when the code isn't defined or doesn't matter.
47 
57  ExcCodeBp = 9,
58  ExcCodeRI = 10,
59  ExcCodeCpU = 11,
60  ExcCodeOv = 12,
61  ExcCodeTr = 13,
62  ExcCodeC2E = 18,
68 };
69 
70 class MipsFaultBase : public FaultBase
71 {
72  public:
73  struct FaultVals
74  {
75  const FaultName name;
77  const ExcCode code;
78  };
79 
80  void setExceptionState(ThreadContext *, uint8_t);
81 
82  virtual FaultVect offset(ThreadContext *tc) const = 0;
83  virtual ExcCode code() const = 0;
84  virtual FaultVect base(ThreadContext *tc) const
85  {
86  StatusReg status = tc->readMiscReg(MISCREG_STATUS);
87  if (!status.bev)
88  return tc->readMiscReg(MISCREG_EBASE);
89  else
90  return 0xbfc00200;
91  }
92 
93  FaultVect
94  vect(ThreadContext *tc) const
95  {
96  return base(tc) + offset(tc);
97  }
98 
99  void invoke(ThreadContext * tc, const StaticInstPtr &inst =
101 };
102 
103 template <typename T>
104 class MipsFault : public MipsFaultBase
105 {
106  protected:
107  static FaultVals vals;
108  public:
109  FaultName name() const { return vals.name; }
110  FaultVect offset(ThreadContext *tc) const { return vals.offset; }
111  ExcCode code() const { return vals.code; }
112 };
113 
114 class SystemCallFault : public MipsFault<SystemCallFault> {};
115 class ReservedInstructionFault : public MipsFault<ReservedInstructionFault> {};
116 class ThreadFault : public MipsFault<ThreadFault> {};
117 class IntegerOverflowFault : public MipsFault<IntegerOverflowFault> {};
118 class TrapFault : public MipsFault<TrapFault> {};
119 class BreakpointFault : public MipsFault<BreakpointFault> {};
120 class DspStateDisabledFault : public MipsFault<DspStateDisabledFault> {};
121 
122 class MachineCheckFault : public MipsFault<MachineCheckFault>
123 {
124  public:
125  bool isMachineCheckFault() { return true; }
126 };
127 
128 class ResetFault : public MipsFault<ResetFault>
129 {
130  public:
131  void invoke(ThreadContext * tc, const StaticInstPtr &inst =
133 
134 };
135 
136 class SoftResetFault : public MipsFault<SoftResetFault>
137 {
138  public:
139  void invoke(ThreadContext * tc, const StaticInstPtr &inst =
141 };
142 
143 class NonMaskableInterrupt : public MipsFault<NonMaskableInterrupt>
144 {
145  public:
146  void invoke(ThreadContext * tc, const StaticInstPtr &inst =
148 };
149 
150 class CoprocessorUnusableFault : public MipsFault<CoprocessorUnusableFault>
151 {
152  protected:
153  int coProcID;
154  public:
155  CoprocessorUnusableFault(int _procid) : coProcID(_procid)
156  {}
157 
158  void
159  invoke(ThreadContext * tc, const StaticInstPtr &inst =
161  {
163  if (FullSystem) {
164  CauseReg cause = tc->readMiscReg(MISCREG_CAUSE);
165  cause.ce = coProcID;
166  tc->setMiscRegNoEffect(MISCREG_CAUSE, cause);
167  }
168  }
169 };
170 
171 class InterruptFault : public MipsFault<InterruptFault>
172 {
173  public:
174  FaultVect
176  {
177  CauseReg cause = tc->readMiscRegNoEffect(MISCREG_CAUSE);
178  // offset 0x200 for release 2, 0x180 for release 1.
179  return cause.iv ? 0x200 : 0x180;
180  }
181 };
182 
183 template <typename T>
184 class AddressFault : public MipsFault<T>
185 {
186  protected:
188  bool store;
189 
190  AddressFault(Addr _vaddr, bool _store) : vaddr(_vaddr), store(_store)
191  {}
192 
193  void
194  invoke(ThreadContext * tc, const StaticInstPtr &inst =
196  {
197  MipsFault<T>::invoke(tc, inst);
198  if (FullSystem)
200  }
201 };
202 
203 class AddressErrorFault : public AddressFault<AddressErrorFault>
204 {
205  public:
206  AddressErrorFault(Addr _vaddr, bool _store) :
207  AddressFault<AddressErrorFault>(_vaddr, _store)
208  {}
209 
210  ExcCode
211  code() const
212  {
213  return store ? ExcCodeAdES : ExcCodeAdEL;
214  }
215 
216 };
217 
218 template <typename T>
219 class TlbFault : public AddressFault<T>
220 {
221  protected:
224 
225  TlbFault(Addr _asid, Addr _vaddr, Addr _vpn, bool _store) :
226  AddressFault<T>(_vaddr, _store), asid(_asid), vpn(_vpn)
227  {}
228 
229  void
231  {
232  this->setExceptionState(tc, excCode);
233 
235  EntryHiReg entryHi = tc->readMiscReg(MISCREG_ENTRYHI);
236  entryHi.asid = this->asid;
237  entryHi.vpn2 = this->vpn >> 2;
238  entryHi.vpn2x = this->vpn & 0x3;
239  tc->setMiscRegNoEffect(MISCREG_ENTRYHI, entryHi);
240 
241  ContextReg context = tc->readMiscReg(MISCREG_CONTEXT);
242  context.badVPN2 = this->vpn >> 2;
243  tc->setMiscRegNoEffect(MISCREG_CONTEXT, context);
244  }
245 
246  void
247  invoke(ThreadContext * tc, const StaticInstPtr &inst =
249  {
250  if (FullSystem) {
251  DPRINTF(MipsPRA, "Fault %s encountered.\n", this->name());
252  Addr vect = this->vect(tc);
253  setTlbExceptionState(tc, this->code());
254  tc->pcState(vect);
255  } else {
256  AddressFault<T>::invoke(tc, inst);
257  }
258  }
259 
260  ExcCode
261  code() const
262  {
263  return this->store ? ExcCodeTlbS : ExcCodeTlbL;
264  }
265 };
266 
267 class TlbRefillFault : public TlbFault<TlbRefillFault>
268 {
269  public:
272  {}
273 
274  FaultVect
276  {
277  StatusReg status = tc->readMiscReg(MISCREG_STATUS);
278  return status.exl ? 0x180 : 0x000;
279  }
280 };
281 
282 class TlbInvalidFault : public TlbFault<TlbInvalidFault>
283 {
284  public:
287  {}
288 };
289 
290 class TlbModifiedFault : public TlbFault<TlbModifiedFault>
291 {
292  public:
295  {}
296 
298 };
299 
300 /*
301  * Explicitly declare template static member variables to avoid warnings
302  * in some clang versions
303  */
321 
322 
323 
324 } // namespace MipsISA
325 
326 #endif // __MIPS_FAULTS_HH__
ThreadContext::readMiscRegNoEffect
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
ArmISA::status
Bitfield< 5, 0 > status
Definition: miscregs_types.hh:417
MipsISA::IntegerOverflowFault
Definition: faults.hh:117
MipsISA::TlbFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.hh:247
MipsISA::ExcCodeMod
@ ExcCodeMod
Definition: faults.hh:49
MipsISA::excCode
Bitfield< 6, 2 > excCode
Definition: pra_constants.hh:196
MipsISA::ExcCode
ExcCode
Definition: faults.hh:44
MipsISA::ExcCodeIBE
@ ExcCodeIBE
Definition: faults.hh:54
MipsISA::TlbFault::asid
Addr asid
Definition: faults.hh:222
MipsISA::AddressErrorFault::code
ExcCode code() const
Definition: faults.hh:211
MipsISA::CoprocessorUnusableFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.hh:159
MipsISA::SoftResetFault
Definition: faults.hh:136
MipsISA::ExcCodeSys
@ ExcCodeSys
Definition: faults.hh:56
MipsISA::TlbFault::TlbFault
TlbFault(Addr _asid, Addr _vaddr, Addr _vpn, bool _store)
Definition: faults.hh:225
MipsISA::MISCREG_CONTEXT
@ MISCREG_CONTEXT
Definition: registers.hh:156
MipsISA::ThreadFault
Definition: faults.hh:116
MipsISA::ExcCodeAdEL
@ ExcCodeAdEL
Definition: faults.hh:52
pra_constants.hh
MipsISA::TlbFault::setTlbExceptionState
void setTlbExceptionState(ThreadContext *tc, uint8_t excCode)
Definition: faults.hh:230
MipsISA::CoprocessorUnusableFault
Definition: faults.hh:150
MipsISA::CoprocessorUnusableFault::CoprocessorUnusableFault
CoprocessorUnusableFault(int _procid)
Definition: faults.hh:155
MipsISA::MipsFaultBase::setExceptionState
void setExceptionState(ThreadContext *, uint8_t)
Definition: faults.cc:97
MipsISA::DspStateDisabledFault
Definition: faults.hh:120
MipsISA::ExcCodeInt
@ ExcCodeInt
Definition: faults.hh:48
MipsISA::MISCREG_CAUSE
@ MISCREG_CAUSE
Definition: registers.hh:184
MipsISA::ExcCodeDBE
@ ExcCodeDBE
Definition: faults.hh:55
MipsISA::ExcCodeTlbL
@ ExcCodeTlbL
Definition: faults.hh:50
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
MipsISA::TlbFault::code
ExcCode code() const
Definition: faults.hh:261
faults.hh
MipsISA::MachineCheckFault::isMachineCheckFault
bool isMachineCheckFault()
Definition: faults.hh:125
MipsISA::MipsFaultBase::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.cc:129
MipsISA::TlbInvalidFault
Definition: faults.hh:282
MipsISA
Definition: decoder.cc:31
MipsISA::MipsFaultBase::code
virtual ExcCode code() const =0
MipsISA::ExcCodeThread
@ ExcCodeThread
Definition: faults.hh:66
MipsISA::MipsFaultBase
Definition: faults.hh:70
MipsISA::MipsFault::code
ExcCode code() const
Definition: faults.hh:111
MipsISA::MipsFaultBase::FaultVals
Definition: faults.hh:73
MipsISA::MISCREG_STATUS
@ MISCREG_STATUS
Definition: registers.hh:179
MipsISA::ExcCodeCacheErr
@ ExcCodeCacheErr
Definition: faults.hh:67
MipsISA::FaultVect
Addr FaultVect
Definition: faults.hh:42
MipsISA::AddressFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.hh:194
MipsISA::MipsFault
Definition: faults.hh:104
MipsISA::ExcCodeTlbS
@ ExcCodeTlbS
Definition: faults.hh:51
MipsISA::ExcCodeMCheck
@ ExcCodeMCheck
Definition: faults.hh:65
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
MipsISA::MISCREG_EBASE
@ MISCREG_EBASE
Definition: registers.hh:189
MipsISA::TlbModifiedFault
Definition: faults.hh:290
MipsISA::ExcCodeDummy
@ ExcCodeDummy
Definition: faults.hh:46
FaultName
const typedef char * FaultName
Definition: faults.hh:49
MipsISA::MipsFaultBase::FaultVals::offset
const FaultVect offset
Definition: faults.hh:76
MipsISA::ResetFault
Definition: faults.hh:128
MipsISA::NonMaskableInterrupt::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.cc:164
MipsISA::ReservedInstructionFault
Definition: faults.hh:115
MipsISA::BreakpointFault
Definition: faults.hh:119
MipsISA::TlbFault
Definition: faults.hh:219
MipsISA::ExcCodeBp
@ ExcCodeBp
Definition: faults.hh:57
MipsISA::MISCREG_ENTRYHI
@ MISCREG_ENTRYHI
Definition: registers.hh:175
MipsISA::InterruptFault::offset
FaultVect offset(ThreadContext *tc) const
Definition: faults.hh:175
MipsISA::MipsFaultBase::FaultVals::code
const ExcCode code
Definition: faults.hh:77
MipsISA::MipsFault::vals
static FaultVals vals
Definition: faults.hh:107
MipsISA::TrapFault
Definition: faults.hh:118
MipsISA::ResetFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.cc:141
MipsISA::SystemCallFault
Definition: faults.hh:114
MipsISA::MipsFaultBase::offset
virtual FaultVect offset(ThreadContext *tc) const =0
MipsISA::CoprocessorUnusableFault::coProcID
int coProcID
Definition: faults.hh:153
MipsISA::TlbModifiedFault::TlbModifiedFault
TlbModifiedFault(Addr asid, Addr vaddr, Addr vpn)
Definition: faults.hh:293
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
StaticInst::nullStaticInstPtr
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:237
MipsISA::MipsFaultBase::base
virtual FaultVect base(ThreadContext *tc) const
Definition: faults.hh:84
MipsISA::ExcCodeCpU
@ ExcCodeCpU
Definition: faults.hh:59
MipsISA::MipsFault::name
FaultName name() const
Definition: faults.hh:109
MipsISA::TlbRefillFault
Definition: faults.hh:267
MipsISA::MipsFaultBase::FaultVals::name
const FaultName name
Definition: faults.hh:75
MipsISA::AddressFault::store
bool store
Definition: faults.hh:188
full_system.hh
ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
MipsISA::InterruptFault
Definition: faults.hh:171
MipsISA::ExcCodeRI
@ ExcCodeRI
Definition: faults.hh:58
MipsISA::ExcCodeMDMX
@ ExcCodeMDMX
Definition: faults.hh:63
MipsISA::MipsFaultBase::vect
FaultVect vect(ThreadContext *tc) const
Definition: faults.hh:94
MipsISA::AddressFault::vaddr
Addr vaddr
Definition: faults.hh:187
MipsISA::MipsFault::offset
FaultVect offset(ThreadContext *tc) const
Definition: faults.hh:110
MipsISA::AddressFault::AddressFault
AddressFault(Addr _vaddr, bool _store)
Definition: faults.hh:190
MipsISA::TlbInvalidFault::TlbInvalidFault
TlbInvalidFault(Addr asid, Addr vaddr, Addr vpn, bool store)
Definition: faults.hh:285
MipsISA::TlbRefillFault::offset
FaultVect offset(ThreadContext *tc) const
Definition: faults.hh:275
ThreadContext::readMiscReg
virtual RegVal readMiscReg(RegIndex misc_reg)=0
MipsISA::TlbModifiedFault::code
ExcCode code() const
Definition: faults.hh:297
MipsISA::ExcCodeWatch
@ ExcCodeWatch
Definition: faults.hh:64
MipsISA::NonMaskableInterrupt
Definition: faults.hh:143
MipsISA::TlbFault::vpn
Addr vpn
Definition: faults.hh:223
MipsISA::AddressFault
Definition: faults.hh:184
MipsISA::SoftResetFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.cc:158
MipsISA::ExcCodeTr
@ ExcCodeTr
Definition: faults.hh:61
RefCountingPtr< StaticInst >
MipsISA::ExcCodeAdES
@ ExcCodeAdES
Definition: faults.hh:53
ThreadContext::setMiscRegNoEffect
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
MipsISA::TlbRefillFault::TlbRefillFault
TlbRefillFault(Addr asid, Addr vaddr, Addr vpn, bool store)
Definition: faults.hh:270
MipsISA::ExcCodeC2E
@ ExcCodeC2E
Definition: faults.hh:62
FaultBase
Definition: faults.hh:54
MipsISA::AddressErrorFault
Definition: faults.hh:203
MipsISA::MISCREG_BADVADDR
@ MISCREG_BADVADDR
Definition: registers.hh:171
thread_context.hh
MipsISA::ExcCodeOv
@ ExcCodeOv
Definition: faults.hh:60
MipsISA::MachineCheckFault
Definition: faults.hh:122
MipsISA::AddressErrorFault::AddressErrorFault
AddressErrorFault(Addr _vaddr, bool _store)
Definition: faults.hh:206

Generated on Wed Sep 30 2020 14:01:59 for gem5 by doxygen 1.8.17