gem5  v20.1.0.0
faults.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 The Hewlett-Packard Development Company
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_X86_FAULTS_HH__
39 #define __ARCH_X86_FAULTS_HH__
40 
41 #include <string>
42 
43 #include "arch/x86/tlb.hh"
44 #include "base/bitunion.hh"
45 #include "base/logging.hh"
46 #include "sim/faults.hh"
47 
48 namespace X86ISA
49 {
50 
51 // Base class for all x86 "faults" where faults is in the m5 sense
52 class X86FaultBase : public FaultBase
53 {
54  protected:
55  const char *faultName;
56  const char *mnem;
57  uint8_t vector;
58  uint64_t errorCode;
59 
60  X86FaultBase(const char *_faultName, const char *_mnem,
61  const uint8_t _vector, uint64_t _errorCode=(uint64_t)-1) :
62  faultName(_faultName), mnem(_mnem),
63  vector(_vector), errorCode(_errorCode)
64  {}
65 
66  const char *name() const override { return faultName; }
67  virtual bool isBenign() { return true; }
68  virtual const char *mnemonic() const { return mnem; }
69  virtual bool isSoft() { return false; }
70 
71  void invoke(ThreadContext *tc, const StaticInstPtr &inst=
73 
74  virtual std::string describe() const;
75 
76  public:
82  virtual uint8_t getVector() const { return vector; }
83 };
84 
85 // Base class for x86 faults which behave as if the underlying instruction
86 // didn't happen.
87 class X86Fault : public X86FaultBase
88 {
89  protected:
91 };
92 
93 // Base class for x86 traps which behave as if the underlying instruction
94 // completed.
95 class X86Trap : public X86FaultBase
96 {
97  protected:
99 
100  void invoke(ThreadContext *tc, const StaticInstPtr &inst=
102 };
103 
104 // Base class for x86 aborts which seem to be catastrophic failures.
105 class X86Abort : public X86FaultBase
106 {
107  protected:
109 
110  void invoke(ThreadContext *tc, const StaticInstPtr &inst=
112 };
113 
114 // Base class for x86 interrupts.
116 {
117  protected:
119 };
120 
121 class UnimpInstFault : public FaultBase
122 {
123  public:
124  const char *
125  name() const override
126  {
127  return "unimplemented_micro";
128  }
129 
130  void
133  {
134  panic("Unimplemented instruction!");
135  }
136 };
137 
138 // Below is a summary of the interrupt/exception information in the
139 // architecture manuals.
140 
141 // Class | Type | vector | Cause | mnem
142 //------------------------------------------------------------------------
143 //Contrib Fault 0 Divide Error #DE
144 //Benign Either 1 Debug #DB
145 //Benign Interrupt 2 Non-Maskable-Interrupt #NMI
146 //Benign Trap 3 Breakpoint #BP
147 //Benign Trap 4 Overflow #OF
148 //Benign Fault 5 Bound-Range #BR
149 //Benign Fault 6 Invalid-Opcode #UD
150 //Benign Fault 7 Device-Not-Available #NM
151 //Benign Abort 8 Double-Fault #DF
152 // 9 Coprocessor-Segment-Overrun
153 //Contrib Fault 10 Invalid-TSS #TS
154 //Contrib Fault 11 Segment-Not-Present #NP
155 //Contrib Fault 12 Stack #SS
156 //Contrib Fault 13 General-Protection #GP
157 //Either Fault 14 Page-Fault #PF
158 // 15 Reserved
159 //Benign Fault 16 x87 Floating-Point Exception Pending #MF
160 //Benign Fault 17 Alignment-Check #AC
161 //Benign Abort 18 Machine-Check #MC
162 //Benign Fault 19 SIMD Floating-Point #XF
163 // 20-29 Reserved
164 //Contrib ? 30 Security Exception #SX
165 // 31 Reserved
166 //Benign Interrupt 0-255 External Interrupts #INTR
167 //Benign Interrupt 0-255 Software Interrupts INTn
168 
169 // Note that
170 class DivideError : public X86Fault
171 {
172  public:
173  DivideError() : X86Fault("Divide-Error", "#DE", 0) {}
174 };
175 
177 {
178  public:
179  DebugException() : X86FaultBase("Debug", "#DB", 1) {}
180 };
181 
183 {
184  public:
185  NonMaskableInterrupt(uint8_t _vector) :
186  X86Interrupt("Non Maskable Interrupt", "#NMI", 2, _vector)
187  {}
188 };
189 
190 class Breakpoint : public X86Trap
191 {
192  public:
193  Breakpoint() : X86Trap("Breakpoint", "#BP", 3) {}
194 };
195 
196 class OverflowTrap : public X86Trap
197 {
198  public:
199  OverflowTrap() : X86Trap("Overflow", "#OF", 4) {}
200 };
201 
202 class BoundRange : public X86Fault
203 {
204  public:
205  BoundRange() : X86Fault("Bound-Range", "#BR", 5) {}
206 };
207 
208 class InvalidOpcode : public X86Fault
209 {
210  public:
211  InvalidOpcode() : X86Fault("Invalid-Opcode", "#UD", 6) {}
212 
213  void invoke(ThreadContext *tc, const StaticInstPtr &inst =
215 };
216 
218 {
219  public:
220  DeviceNotAvailable() : X86Fault("Device-Not-Available", "#NM", 7) {}
221 };
222 
223 class DoubleFault : public X86Abort
224 {
225  public:
226  DoubleFault() : X86Abort("Double-Fault", "#DF", 8, 0) {}
227 };
228 
229 class InvalidTSS : public X86Fault
230 {
231  public:
232  InvalidTSS(uint32_t _errorCode) :
233  X86Fault("Invalid-TSS", "#TS", 10, _errorCode)
234  {}
235 };
236 
238 {
239  public:
240  SegmentNotPresent(uint32_t _errorCode) :
241  X86Fault("Segment-Not-Present", "#NP", 11, _errorCode)
242  {}
243 };
244 
245 class StackFault : public X86Fault
246 {
247  public:
248  StackFault(uint32_t _errorCode) : X86Fault("Stack", "#SS", 12, _errorCode)
249  {}
250 };
251 
253 {
254  public:
255  GeneralProtection(uint32_t _errorCode) :
256  X86Fault("General-Protection", "#GP", 13, _errorCode)
257  {}
258 };
259 
260 class PageFault : public X86Fault
261 {
262  protected:
263  BitUnion32(PageFaultErrorCode)
264  Bitfield<0> present;
265  Bitfield<1> write;
266  Bitfield<2> user;
267  Bitfield<3> reserved;
268  Bitfield<4> fetch;
269  EndBitUnion(PageFaultErrorCode)
270 
271  Addr addr;
272 
273  public:
274  PageFault(Addr _addr, uint32_t _errorCode) :
275  X86Fault("Page-Fault", "#PF", 14, _errorCode), addr(_addr)
276  {}
277 
279  bool user, bool reserved) :
280  X86Fault("Page-Fault", "#PF", 14, 0), addr(_addr)
281  {
282  PageFaultErrorCode code = 0;
283  code.present = present;
284  code.write = (mode == BaseTLB::Write);
285  code.user = user;
286  code.reserved = reserved;
287  code.fetch = (mode == BaseTLB::Execute);
288  errorCode = code;
289  }
290 
291  void
292  invoke(ThreadContext *tc, const StaticInstPtr &inst=
294 
295  virtual std::string describe() const;
296 };
297 
299 {
300  public:
302  X86Fault("x87 Floating-Point Exception Pending", "#MF", 16)
303  {}
304 };
305 
306 class AlignmentCheck : public X86Fault
307 {
308  public:
309  AlignmentCheck() : X86Fault("Alignment-Check", "#AC", 17, 0) {}
310 };
311 
312 class MachineCheck : public X86Abort
313 {
314  public:
315  MachineCheck() : X86Abort("Machine-Check", "#MC", 18) {}
316 };
317 
319 {
320  public:
321  SIMDFloatingPointFault() : X86Fault("SIMD Floating-Point", "#XF", 19) {}
322 };
323 
325 {
326  public:
327  SecurityException() : X86FaultBase("Security Exception", "#SX", 30) {}
328 };
329 
331 {
332  public:
333  ExternalInterrupt(uint8_t _vector) :
334  X86Interrupt("External Interrupt", "#INTR", _vector)
335  {}
336 };
337 
339 {
340  public:
342  X86Interrupt("System Management Interrupt", "#SMI", 0)
343  {}
344 };
345 
347 {
348  public:
349  InitInterrupt(uint8_t _vector) :
350  X86Interrupt("INIT Interrupt", "#INIT", _vector)
351  {}
352 
353  void invoke(ThreadContext *tc, const StaticInstPtr &inst=
355 };
356 
358 {
359  public:
360  StartupInterrupt(uint8_t _vector) :
361  X86Interrupt("Startup Interrupt", "#SIPI", _vector)
362  {}
363 
364  void invoke(ThreadContext *tc, const StaticInstPtr &inst=
366 };
367 
369 {
370  public:
371  SoftwareInterrupt(uint8_t _vector) :
372  X86Interrupt("Software Interrupt", "#INTR", _vector)
373  {}
374 
375  bool isSoft() override { return true; }
376 };
377 
378 } // namespace X86ISA
379 
380 #endif // __ARCH_X86_FAULTS_HH__
X86ISA::SystemManagementInterrupt
Definition: faults.hh:338
X86ISA::StartupInterrupt
Definition: faults.hh:357
X86ISA::PageFault::PageFault
PageFault(Addr _addr, bool present, BaseTLB::Mode mode, bool user, bool reserved)
Definition: faults.hh:278
X86ISA::X86FaultBase::vector
uint8_t vector
Definition: faults.hh:57
X86ISA::UnimpInstFault
Definition: faults.hh:121
X86ISA::SecurityException
Definition: faults.hh:324
X86ISA::PageFault::PageFault
PageFault(Addr _addr, uint32_t _errorCode)
Definition: faults.hh:274
X86ISA::StartupInterrupt::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.cc:301
X86ISA::X86FaultBase::name
const char * name() const override
Definition: faults.hh:66
X86ISA::X86FaultBase::mnem
const char * mnem
Definition: faults.hh:56
X86ISA::X87FpExceptionPending::X87FpExceptionPending
X87FpExceptionPending()
Definition: faults.hh:301
X86ISA::InvalidTSS::InvalidTSS
InvalidTSS(uint32_t _errorCode)
Definition: faults.hh:232
X86ISA::StartupInterrupt::StartupInterrupt
StartupInterrupt(uint8_t _vector)
Definition: faults.hh:360
X86ISA::InvalidOpcode
Definition: faults.hh:208
X86ISA::present
Bitfield< 7 > present
Definition: misc.hh:992
X86ISA::X86FaultBase::mnemonic
virtual const char * mnemonic() const
Definition: faults.hh:68
X86ISA::NonMaskableInterrupt::NonMaskableInterrupt
NonMaskableInterrupt(uint8_t _vector)
Definition: faults.hh:185
BaseTLB::Mode
Mode
Definition: tlb.hh:57
X86ISA::GeneralProtection::GeneralProtection
GeneralProtection(uint32_t _errorCode)
Definition: faults.hh:255
X86ISA::X87FpExceptionPending
Definition: faults.hh:298
X86ISA::SegmentNotPresent::SegmentNotPresent
SegmentNotPresent(uint32_t _errorCode)
Definition: faults.hh:240
X86ISA::InitInterrupt::InitInterrupt
InitInterrupt(uint8_t _vector)
Definition: faults.hh:349
X86ISA::OverflowTrap::OverflowTrap
OverflowTrap()
Definition: faults.hh:199
X86ISA::X86FaultBase::describe
virtual std::string describe() const
Definition: faults.cc:95
X86ISA::MachineCheck::MachineCheck
MachineCheck()
Definition: faults.hh:315
X86ISA::SystemManagementInterrupt::SystemManagementInterrupt
SystemManagementInterrupt()
Definition: faults.hh:341
X86ISA::MachineCheck
Definition: faults.hh:312
faults.hh
X86ISA::SegmentNotPresent
Definition: faults.hh:237
X86ISA::SoftwareInterrupt::isSoft
bool isSoft() override
Definition: faults.hh:375
X86ISA::ExternalInterrupt
Definition: faults.hh:330
X86ISA::PageFault::fetch
Bitfield< 4 > fetch
Definition: faults.hh:268
X86ISA::AlignmentCheck::AlignmentCheck
AlignmentCheck()
Definition: faults.hh:309
X86ISA::DoubleFault::DoubleFault
DoubleFault()
Definition: faults.hh:226
X86ISA::SecurityException::SecurityException
SecurityException()
Definition: faults.hh:327
X86ISA::DeviceNotAvailable::DeviceNotAvailable
DeviceNotAvailable()
Definition: faults.hh:220
X86ISA::X86Trap::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.cc:106
X86ISA::NonMaskableInterrupt
Definition: faults.hh:182
X86ISA::PageFault::user
Bitfield< 2 > user
Definition: faults.hh:266
X86ISA::DebugException
Definition: faults.hh:176
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
X86ISA::X86Abort
Definition: faults.hh:105
X86ISA::X86Fault
Definition: faults.hh:87
X86ISA::UnimpInstFault::name
const char * name() const override
Definition: faults.hh:125
X86ISA::InvalidTSS
Definition: faults.hh:229
bitunion.hh
X86ISA::BoundRange::BoundRange
BoundRange()
Definition: faults.hh:205
X86ISA::DeviceNotAvailable
Definition: faults.hh:217
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
X86ISA::InitInterrupt::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.cc:183
X86ISA::OverflowTrap
Definition: faults.hh:196
X86ISA::PageFault::describe
virtual std::string describe() const
Definition: faults.cc:175
X86ISA::StackFault::StackFault
StackFault(uint32_t _errorCode)
Definition: faults.hh:248
X86ISA::PageFault::EndBitUnion
EndBitUnion(PageFaultErrorCode) Addr addr
X86ISA::InitInterrupt
Definition: faults.hh:346
X86ISA::X86FaultBase::getVector
virtual uint8_t getVector() const
Get the vector of an interrupt.
Definition: faults.hh:82
X86ISA::AlignmentCheck
Definition: faults.hh:306
X86ISA::X86Interrupt
Definition: faults.hh:115
X86ISA
This is exposed globally, independent of the ISA.
Definition: acpi.hh:55
X86ISA::InvalidOpcode::InvalidOpcode
InvalidOpcode()
Definition: faults.hh:211
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
X86ISA::GeneralProtection
Definition: faults.hh:252
X86ISA::UnimpInstFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.hh:131
StaticInst::nullStaticInstPtr
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:237
X86ISA::Breakpoint
Definition: faults.hh:190
X86ISA::PageFault::BitUnion32
BitUnion32(PageFaultErrorCode) Bitfield< 0 > present
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:79
BaseTLB::Write
@ Write
Definition: tlb.hh:57
X86ISA::BoundRange
Definition: faults.hh:202
X86ISA::SoftwareInterrupt
Definition: faults.hh:368
X86ISA::PageFault
Definition: faults.hh:260
X86ISA::X86FaultBase::errorCode
uint64_t errorCode
Definition: faults.hh:58
X86ISA::X86Trap
Definition: faults.hh:95
X86ISA::PageFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr)
Definition: faults.cc:136
X86ISA::X86FaultBase
Definition: faults.hh:52
X86ISA::X86FaultBase::faultName
const char * faultName
Definition: faults.hh:55
X86ISA::DoubleFault
Definition: faults.hh:223
X86ISA::DebugException::DebugException
DebugException()
Definition: faults.hh:179
X86ISA::X86Abort::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.cc:119
logging.hh
X86ISA::PageFault::reserved
Bitfield< 3 > reserved
Definition: faults.hh:267
X86ISA::InvalidOpcode::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.cc:125
RefCountingPtr< StaticInst >
X86ISA::DivideError
Definition: faults.hh:170
tlb.hh
X86ISA::X86FaultBase::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=StaticInst::nullStaticInstPtr) override
Definition: faults.cc:56
X86ISA::SoftwareInterrupt::SoftwareInterrupt
SoftwareInterrupt(uint8_t _vector)
Definition: faults.hh:371
X86ISA::X86FaultBase::isSoft
virtual bool isSoft()
Definition: faults.hh:69
X86ISA::ExternalInterrupt::ExternalInterrupt
ExternalInterrupt(uint8_t _vector)
Definition: faults.hh:333
BaseTLB::Execute
@ Execute
Definition: tlb.hh:57
FaultBase
Definition: faults.hh:54
X86ISA::PageFault::write
Bitfield< 1 > write
Definition: faults.hh:265
X86ISA::StackFault
Definition: faults.hh:245
X86ISA::SIMDFloatingPointFault::SIMDFloatingPointFault
SIMDFloatingPointFault()
Definition: faults.hh:321
X86ISA::SIMDFloatingPointFault
Definition: faults.hh:318
X86ISA::Breakpoint::Breakpoint
Breakpoint()
Definition: faults.hh:193
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
X86ISA::X86FaultBase::isBenign
virtual bool isBenign()
Definition: faults.hh:67
X86ISA::DivideError::DivideError
DivideError()
Definition: faults.hh:173
X86ISA::X86FaultBase::X86FaultBase
X86FaultBase(const char *_faultName, const char *_mnem, const uint8_t _vector, uint64_t _errorCode=(uint64_t) -1)
Definition: faults.hh:60

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