faults.hh revision 5652
12889Sbinkertn@umich.edu/* 22889Sbinkertn@umich.edu * Copyright (c) 2007 The Hewlett-Packard Development Company 32889Sbinkertn@umich.edu * All rights reserved. 42889Sbinkertn@umich.edu * 52889Sbinkertn@umich.edu * Redistribution and use of this software in source and binary forms, 62889Sbinkertn@umich.edu * with or without modification, are permitted provided that the 72889Sbinkertn@umich.edu * following conditions are met: 82889Sbinkertn@umich.edu * 92889Sbinkertn@umich.edu * The software must be used only for Non-Commercial Use which means any 102889Sbinkertn@umich.edu * use which is NOT directed to receiving any direct monetary 112889Sbinkertn@umich.edu * compensation for, or commercial advantage from such use. Illustrative 122889Sbinkertn@umich.edu * examples of non-commercial use are academic research, personal study, 132889Sbinkertn@umich.edu * teaching, education and corporate research & development. 142889Sbinkertn@umich.edu * Illustrative examples of commercial use are distributing products for 152889Sbinkertn@umich.edu * commercial advantage and providing services using the software for 162889Sbinkertn@umich.edu * commercial advantage. 172889Sbinkertn@umich.edu * 182889Sbinkertn@umich.edu * If you wish to use this software or functionality therein that may be 192889Sbinkertn@umich.edu * covered by patents for commercial use, please contact: 202889Sbinkertn@umich.edu * Director of Intellectual Property Licensing 212889Sbinkertn@umich.edu * Office of Strategy and Technology 222889Sbinkertn@umich.edu * Hewlett-Packard Company 232889Sbinkertn@umich.edu * 1501 Page Mill Road 242889Sbinkertn@umich.edu * Palo Alto, California 94304 252889Sbinkertn@umich.edu * 262889Sbinkertn@umich.edu * Redistributions of source code must retain the above copyright notice, 272889Sbinkertn@umich.edu * this list of conditions and the following disclaimer. Redistributions 282889Sbinkertn@umich.edu * in binary form must reproduce the above copyright notice, this list of 292889Sbinkertn@umich.edu * conditions and the following disclaimer in the documentation and/or 302889Sbinkertn@umich.edu * other materials provided with the distribution. Neither the name of 312889Sbinkertn@umich.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 324053Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 332889Sbinkertn@umich.edu * this software without specific prior written permission. No right of 342889Sbinkertn@umich.edu * sublicense is granted herewith. Derivatives of the software and 352889Sbinkertn@umich.edu * output created using the software may be prepared, but only for 362889Sbinkertn@umich.edu * Non-Commercial Uses. Derivatives of the software may be shared with 372889Sbinkertn@umich.edu * others provided: (i) the others agree to abide by the list of 382889Sbinkertn@umich.edu * conditions herein which includes the Non-Commercial Use restrictions; 392889Sbinkertn@umich.edu * and (ii) such Derivatives of the software include the above copyright 402889Sbinkertn@umich.edu * notice to acknowledge the contribution from this software where 412889Sbinkertn@umich.edu * applicable, this list of conditions and the disclaimer below. 422889Sbinkertn@umich.edu * 432889Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 444053Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 454053Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 464053Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 474053Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 484053Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 494053Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 504053Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 514053Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 524053Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 534053Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 544053Sbinkertn@umich.edu * 554053Sbinkertn@umich.edu * Authors: Gabe Black 564053Sbinkertn@umich.edu */ 572889Sbinkertn@umich.edu 582889Sbinkertn@umich.edu#ifndef __ARCH_X86_FAULTS_HH__ 592889Sbinkertn@umich.edu#define __ARCH_X86_FAULTS_HH__ 602889Sbinkertn@umich.edu 612889Sbinkertn@umich.edu#include "base/misc.hh" 622890Sbinkertn@umich.edu#include "sim/faults.hh" 632889Sbinkertn@umich.edu 642889Sbinkertn@umich.edunamespace X86ISA 652889Sbinkertn@umich.edu{ 662889Sbinkertn@umich.edu // Base class for all x86 "faults" where faults is in the m5 sense 672889Sbinkertn@umich.edu class X86FaultBase : public FaultBase 682889Sbinkertn@umich.edu { 692889Sbinkertn@umich.edu protected: 702889Sbinkertn@umich.edu const char * faultName; 712889Sbinkertn@umich.edu const char * mnem; 722889Sbinkertn@umich.edu uint64_t errorCode; 732889Sbinkertn@umich.edu 742889Sbinkertn@umich.edu X86FaultBase(const char * _faultName, const char * _mnem, 752889Sbinkertn@umich.edu uint64_t _errorCode = 0) : 762889Sbinkertn@umich.edu faultName(_faultName), mnem(_mnem), errorCode(_errorCode) 772889Sbinkertn@umich.edu { 782889Sbinkertn@umich.edu } 792889Sbinkertn@umich.edu 802889Sbinkertn@umich.edu const char * name() const 812889Sbinkertn@umich.edu { 822889Sbinkertn@umich.edu return faultName; 832889Sbinkertn@umich.edu } 842889Sbinkertn@umich.edu 852889Sbinkertn@umich.edu virtual bool isBenign() 862889Sbinkertn@umich.edu { 872889Sbinkertn@umich.edu return true; 882889Sbinkertn@umich.edu } 892889Sbinkertn@umich.edu 902889Sbinkertn@umich.edu virtual const char * mnemonic() const 912889Sbinkertn@umich.edu { 922889Sbinkertn@umich.edu return mnem; 932889Sbinkertn@umich.edu } 942889Sbinkertn@umich.edu }; 952889Sbinkertn@umich.edu 962889Sbinkertn@umich.edu // Base class for x86 faults which behave as if the underlying instruction 972889Sbinkertn@umich.edu // didn't happen. 982889Sbinkertn@umich.edu class X86Fault : public X86FaultBase 992889Sbinkertn@umich.edu { 1002889Sbinkertn@umich.edu protected: 1012889Sbinkertn@umich.edu X86Fault(const char * name, const char * mnem, 1022889Sbinkertn@umich.edu uint64_t _errorCode = 0) : 1032889Sbinkertn@umich.edu X86FaultBase(name, mnem, _errorCode) 1042889Sbinkertn@umich.edu {} 1052889Sbinkertn@umich.edu }; 1062889Sbinkertn@umich.edu 1072889Sbinkertn@umich.edu // Base class for x86 traps which behave as if the underlying instruction 1082889Sbinkertn@umich.edu // completed. 1092889Sbinkertn@umich.edu class X86Trap : public X86FaultBase 1102889Sbinkertn@umich.edu { 1112889Sbinkertn@umich.edu protected: 1122889Sbinkertn@umich.edu X86Trap(const char * name, const char * mnem, 1132889Sbinkertn@umich.edu uint64_t _errorCode = 0) : 1142889Sbinkertn@umich.edu X86FaultBase(name, mnem, _errorCode) 1152889Sbinkertn@umich.edu {} 1162889Sbinkertn@umich.edu 1172889Sbinkertn@umich.edu#if FULL_SYSTEM 1182889Sbinkertn@umich.edu void invoke(ThreadContext * tc); 1192889Sbinkertn@umich.edu#endif 1202889Sbinkertn@umich.edu }; 1212889Sbinkertn@umich.edu 1222889Sbinkertn@umich.edu // Base class for x86 aborts which seem to be catastrophic failures. 1232889Sbinkertn@umich.edu class X86Abort : public X86FaultBase 1242889Sbinkertn@umich.edu { 1252889Sbinkertn@umich.edu protected: 1262889Sbinkertn@umich.edu X86Abort(const char * name, const char * mnem, 1272889Sbinkertn@umich.edu uint64_t _errorCode = 0) : 1282889Sbinkertn@umich.edu X86FaultBase(name, mnem, _errorCode) 1292889Sbinkertn@umich.edu {} 1302889Sbinkertn@umich.edu 1312899Sbinkertn@umich.edu#if FULL_SYSTEM 1322899Sbinkertn@umich.edu void invoke(ThreadContext * tc); 1332889Sbinkertn@umich.edu#endif 1342889Sbinkertn@umich.edu }; 1352889Sbinkertn@umich.edu 1362889Sbinkertn@umich.edu // Base class for x86 interrupts. 1372889Sbinkertn@umich.edu class X86Interrupt : public X86FaultBase 1382889Sbinkertn@umich.edu { 1392889Sbinkertn@umich.edu protected: 1402889Sbinkertn@umich.edu X86Interrupt(const char * name, const char * mnem, 1412889Sbinkertn@umich.edu uint64_t _errorCode = 0) : 1422889Sbinkertn@umich.edu X86FaultBase(name, mnem, _errorCode) 1432889Sbinkertn@umich.edu {} 1442889Sbinkertn@umich.edu 1452889Sbinkertn@umich.edu#if FULL_SYSTEM 1462889Sbinkertn@umich.edu void invoke(ThreadContext * tc); 1472889Sbinkertn@umich.edu#endif 1482889Sbinkertn@umich.edu }; 1492889Sbinkertn@umich.edu 1502889Sbinkertn@umich.edu class UnimpInstFault : public FaultBase 1512889Sbinkertn@umich.edu { 1524053Sbinkertn@umich.edu public: 1534053Sbinkertn@umich.edu const char * name() const 1542889Sbinkertn@umich.edu { 1554053Sbinkertn@umich.edu return "unimplemented_micro"; 1564044Sbinkertn@umich.edu } 1574044Sbinkertn@umich.edu 1582889Sbinkertn@umich.edu void invoke(ThreadContext * tc) 1592889Sbinkertn@umich.edu { 1602889Sbinkertn@umich.edu panic("Unimplemented instruction!"); 1612889Sbinkertn@umich.edu } 1622889Sbinkertn@umich.edu }; 1632889Sbinkertn@umich.edu 1642889Sbinkertn@umich.edu static inline Fault genMachineCheckFault() 1652889Sbinkertn@umich.edu { 1662889Sbinkertn@umich.edu panic("Machine check fault not implemented in x86!\n"); 1672903Ssaidi@eecs.umich.edu } 1682889Sbinkertn@umich.edu 1692889Sbinkertn@umich.edu // Below is a summary of the interrupt/exception information in the 1702889Sbinkertn@umich.edu // architecture manuals. 1712889Sbinkertn@umich.edu 1722889Sbinkertn@umich.edu // Class | Type | vector | Cause | mnem 1732889Sbinkertn@umich.edu //------------------------------------------------------------------------ 1742889Sbinkertn@umich.edu //Contrib Fault 0 Divide-by-Zero-Error #DE 1752889Sbinkertn@umich.edu //Benign Either 1 Debug #DB 1762889Sbinkertn@umich.edu //Benign Interrupt 2 Non-Maskable-Interrupt #NMI 1772889Sbinkertn@umich.edu //Benign Trap 3 Breakpoint #BP 1782889Sbinkertn@umich.edu //Benign Trap 4 Overflow #OF 1792889Sbinkertn@umich.edu //Benign Fault 5 Bound-Range #BR 1802889Sbinkertn@umich.edu //Benign Fault 6 Invalid-Opcode #UD 1812889Sbinkertn@umich.edu //Benign Fault 7 Device-Not-Available #NM 1822889Sbinkertn@umich.edu //Benign Abort 8 Double-Fault #DF 1832889Sbinkertn@umich.edu // 9 Coprocessor-Segment-Overrun 1842889Sbinkertn@umich.edu //Contrib Fault 10 Invalid-TSS #TS 1852889Sbinkertn@umich.edu //Contrib Fault 11 Segment-Not-Present #NP 1862889Sbinkertn@umich.edu //Contrib Fault 12 Stack #SS 1872889Sbinkertn@umich.edu //Contrib Fault 13 General-Protection #GP 1882889Sbinkertn@umich.edu //Either Fault 14 Page-Fault #PF 1892889Sbinkertn@umich.edu // 15 Reserved 1904042Sbinkertn@umich.edu //Benign Fault 16 x87 Floating-Point Exception Pending #MF 1914042Sbinkertn@umich.edu //Benign Fault 17 Alignment-Check #AC 1923624Sbinkertn@umich.edu //Benign Abort 18 Machine-Check #MC 1932889Sbinkertn@umich.edu //Benign Fault 19 SIMD Floating-Point #XF 1942889Sbinkertn@umich.edu // 20-29 Reserved 1952889Sbinkertn@umich.edu //Contrib ? 30 Security Exception #SX 1962889Sbinkertn@umich.edu // 31 Reserved 1972889Sbinkertn@umich.edu //Benign Interrupt 0-255 External Interrupts #INTR 1982889Sbinkertn@umich.edu //Benign Interrupt 0-255 Software Interrupts INTn 1992889Sbinkertn@umich.edu 2002889Sbinkertn@umich.edu class DivideByZero : public X86Fault 2012889Sbinkertn@umich.edu { 2022889Sbinkertn@umich.edu public: 2032889Sbinkertn@umich.edu DivideByZero() : 2042889Sbinkertn@umich.edu X86Fault("Divide-by-Zero-Error", "#DE") 2052889Sbinkertn@umich.edu {} 2062889Sbinkertn@umich.edu }; 2072889Sbinkertn@umich.edu 2082889Sbinkertn@umich.edu class DebugException : public X86FaultBase 2092889Sbinkertn@umich.edu { 2102889Sbinkertn@umich.edu public: 2112889Sbinkertn@umich.edu DebugException() : 2122889Sbinkertn@umich.edu X86FaultBase("Debug", "#DB") 2132889Sbinkertn@umich.edu {} 2142889Sbinkertn@umich.edu }; 2152889Sbinkertn@umich.edu 2162889Sbinkertn@umich.edu class NonMaskableInterrupt : public X86Interrupt 2172889Sbinkertn@umich.edu { 2182889Sbinkertn@umich.edu public: 2192889Sbinkertn@umich.edu NonMaskableInterrupt() : 2202889Sbinkertn@umich.edu X86Interrupt("Non-Maskable-Interrupt", "#NMI") 2212889Sbinkertn@umich.edu {} 2222889Sbinkertn@umich.edu }; 2234053Sbinkertn@umich.edu 2244053Sbinkertn@umich.edu class Breakpoint : public X86Trap 2254053Sbinkertn@umich.edu { 2264053Sbinkertn@umich.edu public: 2274053Sbinkertn@umich.edu Breakpoint() : 2284053Sbinkertn@umich.edu X86Trap("Breakpoint", "#BP") 2294053Sbinkertn@umich.edu {} 2304053Sbinkertn@umich.edu }; 2314053Sbinkertn@umich.edu 2324053Sbinkertn@umich.edu class OverflowTrap : public X86Trap 2334053Sbinkertn@umich.edu { 2344053Sbinkertn@umich.edu public: 2354053Sbinkertn@umich.edu OverflowTrap() : 2362889Sbinkertn@umich.edu X86Trap("Overflow", "#OF") 2372889Sbinkertn@umich.edu {} 2382889Sbinkertn@umich.edu }; 2392889Sbinkertn@umich.edu 2402889Sbinkertn@umich.edu class BoundRange : public X86Fault 2412889Sbinkertn@umich.edu { 2422889Sbinkertn@umich.edu public: 2433624Sbinkertn@umich.edu BoundRange() : 2442889Sbinkertn@umich.edu X86Fault("Bound-Range", "#BR") 2452889Sbinkertn@umich.edu {} 2462967Sktlim@umich.edu }; 2472967Sktlim@umich.edu 2482967Sktlim@umich.edu class InvalidOpcode : public X86Fault 2492967Sktlim@umich.edu { 2502889Sbinkertn@umich.edu public: 2512889Sbinkertn@umich.edu InvalidOpcode() : 2522889Sbinkertn@umich.edu X86Fault("Invalid-Opcode", "#UD") 2532922Sktlim@umich.edu {} 2542922Sktlim@umich.edu }; 2554053Sbinkertn@umich.edu 2562889Sbinkertn@umich.edu class DeviceNotAvailable : public X86Fault 2572889Sbinkertn@umich.edu { 2582889Sbinkertn@umich.edu public: 2593624Sbinkertn@umich.edu DeviceNotAvailable() : 2602889Sbinkertn@umich.edu X86Fault("Device-Not-Available", "#NM") 2612889Sbinkertn@umich.edu {} 2622889Sbinkertn@umich.edu }; 2632889Sbinkertn@umich.edu 2642889Sbinkertn@umich.edu class DoubleFault : public X86Abort 2652889Sbinkertn@umich.edu { 2662889Sbinkertn@umich.edu public: 2674078Sbinkertn@umich.edu DoubleFault() : 2682889Sbinkertn@umich.edu X86Abort("Double-Fault", "#DF") 2692889Sbinkertn@umich.edu {} 2703645Sbinkertn@umich.edu }; 2713645Sbinkertn@umich.edu 2722889Sbinkertn@umich.edu class InvalidTSS : public X86Fault 2734053Sbinkertn@umich.edu { 2744053Sbinkertn@umich.edu public: 2754042Sbinkertn@umich.edu InvalidTSS() : 2764053Sbinkertn@umich.edu X86Fault("Invalid-TSS", "#TS") 2774053Sbinkertn@umich.edu {} 2784053Sbinkertn@umich.edu }; 2794053Sbinkertn@umich.edu 2804053Sbinkertn@umich.edu class SegmentNotPresent : public X86Fault 2814053Sbinkertn@umich.edu { 2824053Sbinkertn@umich.edu public: 2834053Sbinkertn@umich.edu SegmentNotPresent() : 2844053Sbinkertn@umich.edu X86Fault("Segment-Not-Present", "#NP") 2854053Sbinkertn@umich.edu {} 2864053Sbinkertn@umich.edu }; 2874053Sbinkertn@umich.edu 2884053Sbinkertn@umich.edu class StackFault : public X86Fault 2894053Sbinkertn@umich.edu { 2904046Sbinkertn@umich.edu public: 2914042Sbinkertn@umich.edu StackFault() : 2924053Sbinkertn@umich.edu X86Fault("Stack", "#SS") 2934053Sbinkertn@umich.edu {} 2944053Sbinkertn@umich.edu }; 2954074Sbinkertn@umich.edu 2964042Sbinkertn@umich.edu class GeneralProtection : public X86Fault 2974074Sbinkertn@umich.edu { 2984074Sbinkertn@umich.edu public: 2994074Sbinkertn@umich.edu GeneralProtection(uint64_t _errorCode) : 3004074Sbinkertn@umich.edu X86Fault("General-Protection", "#GP", _errorCode) 3014042Sbinkertn@umich.edu {} 3024046Sbinkertn@umich.edu }; 3034042Sbinkertn@umich.edu 3044042Sbinkertn@umich.edu class PageFault : public X86Fault 3054042Sbinkertn@umich.edu { 3062889Sbinkertn@umich.edu public: 3072889Sbinkertn@umich.edu PageFault() : 3082889Sbinkertn@umich.edu X86Fault("Page-Fault", "#PF") 3092891Sbinkertn@umich.edu {} 3103887Sbinkertn@umich.edu }; 3113887Sbinkertn@umich.edu 3122899Sbinkertn@umich.edu class X87FpExceptionPending : public X86Fault 3132899Sbinkertn@umich.edu { 3142899Sbinkertn@umich.edu public: 3154042Sbinkertn@umich.edu X87FpExceptionPending() : 3162899Sbinkertn@umich.edu X86Fault("x87 Floating-Point Exception Pending", "#MF") 3172899Sbinkertn@umich.edu {} 3182899Sbinkertn@umich.edu }; 3192899Sbinkertn@umich.edu 3202899Sbinkertn@umich.edu class AlignmentCheck : public X86Fault 3212899Sbinkertn@umich.edu { 3222899Sbinkertn@umich.edu public: 3232899Sbinkertn@umich.edu AlignmentCheck() : 3242899Sbinkertn@umich.edu X86Fault("Alignment-Check", "#AC") 3252889Sbinkertn@umich.edu {} 3262889Sbinkertn@umich.edu }; 3272889Sbinkertn@umich.edu 3282889Sbinkertn@umich.edu class MachineCheck : public X86Abort 3292889Sbinkertn@umich.edu { 3302889Sbinkertn@umich.edu public: 3312889Sbinkertn@umich.edu MachineCheck() : 3322889Sbinkertn@umich.edu X86Abort("Machine-Check", "#MC") 3332889Sbinkertn@umich.edu {} 3342889Sbinkertn@umich.edu }; 3352889Sbinkertn@umich.edu 3362889Sbinkertn@umich.edu class SIMDFloatingPointFault : public X86Fault 3372889Sbinkertn@umich.edu { 3382889Sbinkertn@umich.edu public: 3392889Sbinkertn@umich.edu SIMDFloatingPointFault() : 3402889Sbinkertn@umich.edu X86Fault("SIMD Floating-Point", "#XF") 3412889Sbinkertn@umich.edu {} 342 }; 343 344 class SecurityException : public X86FaultBase 345 { 346 public: 347 SecurityException() : 348 X86FaultBase("Security Exception", "#SX") 349 {} 350 }; 351 352 class ExternalInterrupt : public X86Interrupt 353 { 354 public: 355 ExternalInterrupt() : 356 X86Interrupt("External Interrupt", "#INTR") 357 {} 358 }; 359 360 class SoftwareInterrupt : public X86Interrupt 361 { 362 public: 363 SoftwareInterrupt() : 364 X86Interrupt("Software Interrupt", "INTn") 365 {} 366 }; 367 368 // These faults aren't part of the ISA definition. They trigger filling 369 // the tlb on a miss and are to take the place of a hardware table walker. 370 class FakeITLBFault : public X86Fault 371 { 372 protected: 373 Addr vaddr; 374 public: 375 FakeITLBFault(Addr _vaddr) : 376 X86Fault("fake instruction tlb fault", "itlb"), 377 vaddr(_vaddr) 378 {} 379 380 void invoke(ThreadContext * tc); 381 }; 382 383 class FakeDTLBFault : public X86Fault 384 { 385 protected: 386 Addr vaddr; 387 public: 388 FakeDTLBFault(Addr _vaddr) : 389 X86Fault("fake data tlb fault", "dtlb"), 390 vaddr(_vaddr) 391 {} 392 393 void invoke(ThreadContext * tc); 394 }; 395}; 396 397#endif // __ARCH_X86_FAULTS_HH__ 398