gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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;
76  const FaultVect offset;
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:
270  TlbRefillFault(Addr asid, Addr vaddr, Addr vpn, bool store) :
271  TlbFault<TlbRefillFault>(asid, vaddr, vpn, store)
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:
285  TlbInvalidFault(Addr asid, Addr vaddr, Addr vpn, bool store) :
286  TlbFault<TlbInvalidFault>(asid, vaddr, vpn, store)
287  {}
288 };
289 
290 class TlbModifiedFault : public TlbFault<TlbModifiedFault>
291 {
292  public:
294  TlbFault<TlbModifiedFault>(asid, vaddr, vpn, false)
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__
#define DPRINTF(x,...)
Definition: trace.hh:225
FaultName name() const
Definition: faults.hh:109
TlbRefillFault(Addr asid, Addr vaddr, Addr vpn, bool store)
Definition: faults.hh:270
CoprocessorUnusableFault(int _procid)
Definition: faults.hh:155
ExcCode code() const
Definition: faults.hh:111
FaultVect offset(ThreadContext *tc) const
Definition: faults.hh:175
ExcCode code() const
Definition: faults.hh:261
virtual TheISA::PCState pcState() const =0
AddressErrorFault(Addr _vaddr, bool _store)
Definition: faults.hh:206
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
Bitfield< 6, 2 > excCode
ExcCode
Definition: faults.hh:44
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
FaultVect offset(ThreadContext *tc) const
Definition: faults.hh:275
FaultVect offset(ThreadContext *tc) const
Definition: faults.hh:110
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.hh:194
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.hh:159
Bitfield< 5, 0 > status
FaultVect vect(ThreadContext *tc) const
Definition: faults.hh:94
Addr FaultVect
Definition: faults.hh:42
const char * FaultName
Definition: faults.hh:36
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.hh:247
virtual FaultVect base(ThreadContext *tc) const
Definition: faults.hh:84
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.cc:129
ExcCode code() const
Definition: faults.hh:297
void setTlbExceptionState(ThreadContext *tc, uint8_t excCode)
Definition: faults.hh:230
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
TlbFault(Addr _asid, Addr _vaddr, Addr _vpn, bool _store)
Definition: faults.hh:225
TlbModifiedFault(Addr asid, Addr vaddr, Addr vpn)
Definition: faults.hh:293
Bitfield< 12, 5 > asid
Definition: dt_constants.hh:82
static FaultVals vals
Definition: faults.hh:107
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:225
void setExceptionState(ThreadContext *, uint8_t)
Definition: faults.cc:97
AddressFault(Addr _vaddr, bool _store)
Definition: faults.hh:190
virtual RegVal readMiscReg(RegIndex misc_reg)=0
ExcCode code() const
Definition: faults.hh:211
TlbInvalidFault(Addr asid, Addr vaddr, Addr vpn, bool store)
Definition: faults.hh:285

Generated on Thu May 28 2020 16:11:01 for gem5 by doxygen 1.8.13