2 * Copyright (c) 2007 The Hewlett-Packard Development Company
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.
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.
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.
40 #ifndef __ARCH_X86_FAULTS_HH__
41 #define __ARCH_X86_FAULTS_HH__
43 #include "base/bitunion.hh"
44 #include "base/misc.hh"
45 #include "sim/faults.hh"
52 // Base class for all x86 "faults" where faults is in the m5 sense
53 class X86FaultBase : public FaultBase
56 const char * faultName;
61 X86FaultBase(const char * _faultName, const char * _mnem,
62 const uint8_t _vector, uint64_t _errorCode = (uint64_t)-1)
63 : faultName(_faultName), mnem(_mnem),
64 vector(_vector), errorCode(_errorCode)
68 const char * name() const
73 virtual bool isBenign()
78 virtual const char * mnemonic() const
89 void invoke(ThreadContext * tc,
90 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
92 virtual std::string describe() const;
96 // Base class for x86 faults which behave as if the underlying instruction
98 class X86Fault : public X86FaultBase
101 X86Fault(const char * name, const char * mnem,
102 const uint8_t vector, uint64_t _errorCode = (uint64_t)-1)
103 : X86FaultBase(name, mnem, vector, _errorCode)
107 // Base class for x86 traps which behave as if the underlying instruction
109 class X86Trap : public X86FaultBase
112 X86Trap(const char * name, const char * mnem,
113 const uint8_t vector, uint64_t _errorCode = (uint64_t)-1)
114 : X86FaultBase(name, mnem, vector, _errorCode)
118 void invoke(ThreadContext * tc,
119 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
123 // Base class for x86 aborts which seem to be catastrophic failures.
124 class X86Abort : public X86FaultBase
127 X86Abort(const char * name, const char * mnem,
128 const uint8_t vector, uint64_t _errorCode = (uint64_t)-1)
129 : X86FaultBase(name, mnem, vector, _errorCode)
133 void invoke(ThreadContext * tc,
134 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
138 // Base class for x86 interrupts.
139 class X86Interrupt : public X86FaultBase
142 X86Interrupt(const char * name, const char * mnem,
143 const uint8_t _vector, uint64_t _errorCode = (uint64_t)-1)
144 : X86FaultBase(name, mnem, _vector, _errorCode)
148 class UnimpInstFault : public FaultBase
151 const char * name() const
153 return "unimplemented_micro";
156 void invoke(ThreadContext * tc,
157 StaticInstPtr inst = StaticInst::nullStaticInstPtr)
159 panic("Unimplemented instruction!");
163 static inline Fault genMachineCheckFault()
165 panic("Machine check fault not implemented in x86!\n");
168 // Below is a summary of the interrupt/exception information in the
169 // architecture manuals.
171 // Class | Type | vector | Cause | mnem
172 //------------------------------------------------------------------------
173 //Contrib Fault 0 Divide-by-Zero-Error #DE
174 //Benign Either 1 Debug #DB
175 //Benign Interrupt 2 Non-Maskable-Interrupt #NMI
176 //Benign Trap 3 Breakpoint #BP
177 //Benign Trap 4 Overflow #OF
178 //Benign Fault 5 Bound-Range #BR
179 //Benign Fault 6 Invalid-Opcode #UD
180 //Benign Fault 7 Device-Not-Available #NM
181 //Benign Abort 8 Double-Fault #DF
182 // 9 Coprocessor-Segment-Overrun
183 //Contrib Fault 10 Invalid-TSS #TS
184 //Contrib Fault 11 Segment-Not-Present #NP
185 //Contrib Fault 12 Stack #SS
186 //Contrib Fault 13 General-Protection #GP
187 //Either Fault 14 Page-Fault #PF
189 //Benign Fault 16 x87 Floating-Point Exception Pending #MF
190 //Benign Fault 17 Alignment-Check #AC
191 //Benign Abort 18 Machine-Check #MC
192 //Benign Fault 19 SIMD Floating-Point #XF
194 //Contrib ? 30 Security Exception #SX
196 //Benign Interrupt 0-255 External Interrupts #INTR
197 //Benign Interrupt 0-255 Software Interrupts INTn
199 class DivideByZero : public X86Fault
203 X86Fault("Divide-by-Zero-Error", "#DE", 0)
207 class DebugException : public X86FaultBase
211 X86FaultBase("Debug", "#DB", 1)
215 class NonMaskableInterrupt : public X86Interrupt
218 NonMaskableInterrupt(uint8_t _vector) :
219 X86Interrupt("Non Maskable Interrupt", "#NMI", 2, _vector)
223 class Breakpoint : public X86Trap
227 X86Trap("Breakpoint", "#BP", 3)
231 class OverflowTrap : public X86Trap
235 X86Trap("Overflow", "#OF", 4)
239 class BoundRange : public X86Fault
243 X86Fault("Bound-Range", "#BR", 5)
247 class InvalidOpcode : public X86Fault
251 X86Fault("Invalid-Opcode", "#UD", 6)
255 void invoke(ThreadContext * tc,
256 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
260 class DeviceNotAvailable : public X86Fault
263 DeviceNotAvailable() :
264 X86Fault("Device-Not-Available", "#NM", 7)
268 class DoubleFault : public X86Abort
272 X86Abort("Double-Fault", "#DF", 8, 0)
276 class InvalidTSS : public X86Fault
279 InvalidTSS(uint32_t _errorCode) :
280 X86Fault("Invalid-TSS", "#TS", 10, _errorCode)
284 class SegmentNotPresent : public X86Fault
287 SegmentNotPresent(uint32_t _errorCode) :
288 X86Fault("Segment-Not-Present", "#NP", 11, _errorCode)
292 class StackFault : public X86Fault
295 StackFault(uint32_t _errorCode) :
296 X86Fault("Stack", "#SS", 12, _errorCode)
300 class GeneralProtection : public X86Fault
303 GeneralProtection(uint32_t _errorCode) :
304 X86Fault("General-Protection", "#GP", 13, _errorCode)
308 class PageFault : public X86Fault
311 BitUnion32(PageFaultErrorCode)
315 Bitfield<3> reserved;
317 EndBitUnion(PageFaultErrorCode)
322 PageFault(Addr _addr, uint32_t _errorCode) :
323 X86Fault("Page-Fault", "#PF", 14, _errorCode), addr(_addr)
326 PageFault(Addr _addr, bool present, BaseTLB::Mode mode,
327 bool user, bool reserved) :
328 X86Fault("Page-Fault", "#PF", 14, 0), addr(_addr)
330 PageFaultErrorCode code = 0;
331 code.present = present;
332 code.write = (mode == BaseTLB::Write);
334 code.reserved = reserved;
335 code.fetch = (mode == BaseTLB::Execute);
339 void invoke(ThreadContext * tc,
340 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
343 virtual std::string describe() const;
347 class X87FpExceptionPending : public X86Fault
350 X87FpExceptionPending() :
351 X86Fault("x87 Floating-Point Exception Pending", "#MF", 16)
355 class AlignmentCheck : public X86Fault
359 X86Fault("Alignment-Check", "#AC", 17, 0)
363 class MachineCheck : public X86Abort
367 X86Abort("Machine-Check", "#MC", 18)
371 class SIMDFloatingPointFault : public X86Fault
374 SIMDFloatingPointFault() :
375 X86Fault("SIMD Floating-Point", "#XF", 19)
379 class SecurityException : public X86FaultBase
382 SecurityException() :
383 X86FaultBase("Security Exception", "#SX", 30)
387 class ExternalInterrupt : public X86Interrupt
390 ExternalInterrupt(uint8_t _vector) :
391 X86Interrupt("External Interrupt", "#INTR", _vector)
395 class SystemManagementInterrupt : public X86Interrupt
398 SystemManagementInterrupt() :
399 X86Interrupt("System Management Interrupt", "#SMI", 0)
403 class InitInterrupt : public X86Interrupt
406 InitInterrupt(uint8_t _vector) :
407 X86Interrupt("INIT Interrupt", "#INIT", _vector)
410 void invoke(ThreadContext * tc,
411 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
414 class StartupInterrupt : public X86Interrupt
417 StartupInterrupt(uint8_t _vector) :
418 X86Interrupt("Startup Interrupt", "#SIPI", _vector)
421 void invoke(ThreadContext * tc,
422 StaticInstPtr inst = StaticInst::nullStaticInstPtr);
425 class SoftwareInterrupt : public X86Interrupt
428 SoftwareInterrupt(uint8_t _vector) :
429 X86Interrupt("Software Interrupt", "#INTR", _vector)
439 #endif // __ARCH_X86_FAULTS_HH__