faults.hh revision 7681:61e31534522d
12SN/A/* 21762SN/A * Copyright (c) 2007 The Hewlett-Packard Development Company 32SN/A * All rights reserved. 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Redistribution and use in source and binary forms, with or without 152SN/A * modification, are permitted provided that the following conditions are 162SN/A * met: redistributions of source code must retain the above copyright 172SN/A * notice, this list of conditions and the following disclaimer; 182SN/A * redistributions in binary form must reproduce the above copyright 192SN/A * notice, this list of conditions and the following disclaimer in the 202SN/A * documentation and/or other materials provided with the distribution; 212SN/A * neither the name of the copyright holders nor the names of its 222SN/A * contributors may be used to endorse or promote products derived from 232SN/A * this software without specific prior written permission. 242SN/A * 252SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272665SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282665SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292665SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302665SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 312665SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 322SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 341722SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 355480Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362SN/A * 372SN/A * Authors: Gabe Black 38146SN/A */ 392SN/A 402SN/A#ifndef __ARCH_X86_FAULTS_HH__ 412158SN/A#define __ARCH_X86_FAULTS_HH__ 42146SN/A 431805SN/A#include "base/bitunion.hh" 44146SN/A#include "base/misc.hh" 451717SN/A#include "sim/faults.hh" 462680SN/A#include "sim/tlb.hh" 475480Snate@binkert.org 482521SN/A#include <string> 4956SN/A 505478SN/Anamespace X86ISA 513348SN/A{ 523348SN/A // Base class for all x86 "faults" where faults is in the m5 sense 532521SN/A class X86FaultBase : public FaultBase 545480Snate@binkert.org { 551805SN/A protected: 562SN/A const char * faultName; 572SN/A const char * mnem; 582107SN/A uint8_t vector; 592SN/A uint64_t errorCode; 605480Snate@binkert.org 615478SN/A X86FaultBase(const char * _faultName, const char * _mnem, 624762SN/A const uint8_t _vector, uint64_t _errorCode = (uint64_t)-1) 632SN/A : faultName(_faultName), mnem(_mnem), 64545SN/A vector(_vector), errorCode(_errorCode) 652521SN/A { 662521SN/A } 672521SN/A 682521SN/A const char * name() const 692SN/A { 702SN/A return faultName; 712SN/A } 72926SN/A 73926SN/A virtual bool isBenign() 74926SN/A { 75926SN/A return true; 76926SN/A } 77926SN/A 78926SN/A virtual const char * mnemonic() const 794395SN/A { 801805SN/A return mnem; 812SN/A } 822SN/A 831634SN/A virtual bool isSoft() 845480Snate@binkert.org { 851634SN/A return false; 862549SN/A } 871806SN/A 881634SN/A#if FULL_SYSTEM 891634SN/A void invoke(ThreadContext * tc, 901634SN/A StaticInstPtr inst = StaticInst::nullStaticInstPtr); 911634SN/A 921634SN/A virtual std::string describe() const; 932521SN/A#endif 941634SN/A }; 951634SN/A 962512SN/A // Base class for x86 faults which behave as if the underlying instruction 975480Snate@binkert.org // didn't happen. 982SN/A class X86Fault : public X86FaultBase 992SN/A { 1002512SN/A protected: 1012512SN/A X86Fault(const char * name, const char * mnem, 1022512SN/A const uint8_t vector, uint64_t _errorCode = (uint64_t)-1) 1032512SN/A : X86FaultBase(name, mnem, vector, _errorCode) 104540SN/A {} 1052641SN/A }; 1062522SN/A 1072641SN/A // Base class for x86 traps which behave as if the underlying instruction 1082512SN/A // completed. 1092630SN/A class X86Trap : public X86FaultBase 1104986SN/A { 1112521SN/A protected: 1122641SN/A X86Trap(const char * name, const char * mnem, 113873SN/A const uint8_t vector, uint64_t _errorCode = (uint64_t)-1) 114873SN/A : X86FaultBase(name, mnem, vector, _errorCode) 115873SN/A {} 116873SN/A 117873SN/A#if FULL_SYSTEM 1182630SN/A void invoke(ThreadContext * tc, 119873SN/A StaticInstPtr inst = StaticInst::nullStaticInstPtr); 120873SN/A#endif 1212630SN/A }; 122873SN/A 123873SN/A // Base class for x86 aborts which seem to be catastrophic failures. 1242630SN/A class X86Abort : public X86FaultBase 125873SN/A { 126873SN/A protected: 1272630SN/A X86Abort(const char * name, const char * mnem, 128873SN/A const uint8_t vector, uint64_t _errorCode = (uint64_t)-1) 129873SN/A : X86FaultBase(name, mnem, vector, _errorCode) 1302512SN/A {} 1312512SN/A 1322512SN/A#if FULL_SYSTEM 1334870SN/A void invoke(ThreadContext * tc, 134873SN/A StaticInstPtr inst = StaticInst::nullStaticInstPtr); 1355480Snate@binkert.org#endif 1362630SN/A }; 137873SN/A 138873SN/A // Base class for x86 interrupts. 139873SN/A class X86Interrupt : public X86FaultBase 140873SN/A { 141873SN/A protected: 1425478SN/A X86Interrupt(const char * name, const char * mnem, 143873SN/A const uint8_t _vector, uint64_t _errorCode = (uint64_t)-1) 144873SN/A : X86FaultBase(name, mnem, _vector, _errorCode) 1452630SN/A {} 146873SN/A }; 147873SN/A 1482630SN/A class UnimpInstFault : public FaultBase 149873SN/A { 150873SN/A public: 1512630SN/A const char * name() const 152873SN/A { 153873SN/A return "unimplemented_micro"; 1542630SN/A } 155873SN/A 156873SN/A void invoke(ThreadContext * tc, 1572630SN/A StaticInstPtr inst = StaticInst::nullStaticInstPtr) 158873SN/A { 159873SN/A panic("Unimplemented instruction!"); 1602630SN/A } 161873SN/A }; 162873SN/A 1632630SN/A static inline Fault genMachineCheckFault() 164873SN/A { 165873SN/A panic("Machine check fault not implemented in x86!\n"); 1662630SN/A } 167873SN/A 168873SN/A // Below is a summary of the interrupt/exception information in the 1692630SN/A // architecture manuals. 170873SN/A 171873SN/A // Class | Type | vector | Cause | mnem 1722630SN/A //------------------------------------------------------------------------ 173873SN/A //Contrib Fault 0 Divide-by-Zero-Error #DE 174873SN/A //Benign Either 1 Debug #DB 1752630SN/A //Benign Interrupt 2 Non-Maskable-Interrupt #NMI 176873SN/A //Benign Trap 3 Breakpoint #BP 177873SN/A //Benign Trap 4 Overflow #OF 1782114SN/A //Benign Fault 5 Bound-Range #BR 1792114SN/A //Benign Fault 6 Invalid-Opcode #UD 1802114SN/A //Benign Fault 7 Device-Not-Available #NM 1812114SN/A //Benign Abort 8 Double-Fault #DF 1822630SN/A // 9 Coprocessor-Segment-Overrun 1832114SN/A //Contrib Fault 10 Invalid-TSS #TS 1842114SN/A //Contrib Fault 11 Segment-Not-Present #NP 185873SN/A //Contrib Fault 12 Stack #SS 1865480Snate@binkert.org //Contrib Fault 13 General-Protection #GP 1872630SN/A //Either Fault 14 Page-Fault #PF 188873SN/A // 15 Reserved 189873SN/A //Benign Fault 16 x87 Floating-Point Exception Pending #MF 1904870SN/A //Benign Fault 17 Alignment-Check #AC 1912SN/A //Benign Abort 18 Machine-Check #MC 1922512SN/A //Benign Fault 19 SIMD Floating-Point #XF 1932SN/A // 20-29 Reserved 1942SN/A //Contrib ? 30 Security Exception #SX 1952512SN/A // 31 Reserved 1965480Snate@binkert.org //Benign Interrupt 0-255 External Interrupts #INTR 1972SN/A //Benign Interrupt 0-255 Software Interrupts INTn 1982641SN/A 1992641SN/A class DivideByZero : public X86Fault 200430SN/A { 2012630SN/A public: 2022641SN/A DivideByZero() : 2032SN/A X86Fault("Divide-by-Zero-Error", "#DE", 0) 204430SN/A {} 205430SN/A }; 2062SN/A 207430SN/A class DebugException : public X86FaultBase 2082SN/A { 209430SN/A public: 2102SN/A DebugException() : 211430SN/A X86FaultBase("Debug", "#DB", 1) 2122SN/A {} 213430SN/A }; 2142SN/A 215430SN/A class NonMaskableInterrupt : public X86Interrupt 2162SN/A { 217430SN/A public: 2182SN/A NonMaskableInterrupt(uint8_t _vector) : 219430SN/A X86Interrupt("Non Maskable Interrupt", "#NMI", 2, _vector) 2202SN/A {} 221430SN/A }; 2222SN/A 2232SN/A class Breakpoint : public X86Trap 2242SN/A { 2252SN/A public: 2262SN/A Breakpoint() : 2272SN/A X86Trap("Breakpoint", "#BP", 3) 228430SN/A {} 2292SN/A }; 230430SN/A 2315478SN/A class OverflowTrap : public X86Trap 232430SN/A { 2332SN/A public: 234430SN/A OverflowTrap() : 2352114SN/A X86Trap("Overflow", "#OF", 4) 2362114SN/A {} 2372114SN/A }; 2382114SN/A 2392114SN/A class BoundRange : public X86Fault 2402114SN/A { 2412114SN/A public: 2422114SN/A BoundRange() : 2432SN/A X86Fault("Bound-Range", "#BR", 5) 2442SN/A {} 2454870SN/A }; 2462SN/A 2472512SN/A class InvalidOpcode : public X86Fault 248545SN/A { 249545SN/A public: 2502SN/A InvalidOpcode() : 2515480Snate@binkert.org X86Fault("Invalid-Opcode", "#UD", 6) 2522SN/A {} 253222SN/A 254222SN/A#if !FULL_SYSTEM 255222SN/A void invoke(ThreadContext * tc, 256222SN/A StaticInstPtr inst = StaticInst::nullStaticInstPtr); 257222SN/A#endif 258222SN/A }; 259222SN/A 260222SN/A class DeviceNotAvailable : public X86Fault 261222SN/A { 262222SN/A public: 263222SN/A DeviceNotAvailable() : 264222SN/A X86Fault("Device-Not-Available", "#NM", 7) 265222SN/A {} 266222SN/A }; 267222SN/A 268430SN/A class DoubleFault : public X86Abort 2692114SN/A { 2702SN/A public: 2712SN/A DoubleFault() : 2722SN/A X86Abort("Double-Fault", "#DF", 8, 0) 2735480Snate@binkert.org {} 2742SN/A }; 275222SN/A 276222SN/A class InvalidTSS : public X86Fault 277222SN/A { 278222SN/A public: 279222SN/A InvalidTSS(uint32_t _errorCode) : 280222SN/A X86Fault("Invalid-TSS", "#TS", 10, _errorCode) 281222SN/A {} 282222SN/A }; 283222SN/A 284222SN/A class SegmentNotPresent : public X86Fault 285222SN/A { 286222SN/A public: 287222SN/A SegmentNotPresent(uint32_t _errorCode) : 288222SN/A X86Fault("Segment-Not-Present", "#NP", 11, _errorCode) 289222SN/A {} 290430SN/A }; 2912114SN/A 292217SN/A class StackFault : public X86Fault 2932SN/A { 294217SN/A public: 2955480Snate@binkert.org StackFault(uint32_t _errorCode) : 296217SN/A X86Fault("Stack", "#SS", 12, _errorCode) 297217SN/A {} 298217SN/A }; 299217SN/A 300217SN/A class GeneralProtection : public X86Fault 3015480Snate@binkert.org { 302217SN/A public: 303237SN/A GeneralProtection(uint32_t _errorCode) : 3042SN/A X86Fault("General-Protection", "#GP", 13, _errorCode) 3052SN/A {} 3065480Snate@binkert.org }; 3075480Snate@binkert.org 3082SN/A class PageFault : public X86Fault 3095480Snate@binkert.org { 3102SN/A protected: 311 BitUnion32(PageFaultErrorCode) 312 Bitfield<0> present; 313 Bitfield<1> write; 314 Bitfield<2> user; 315 Bitfield<3> reserved; 316 Bitfield<4> fetch; 317 EndBitUnion(PageFaultErrorCode) 318 319 Addr addr; 320 321 public: 322 PageFault(Addr _addr, uint32_t _errorCode) : 323 X86Fault("Page-Fault", "#PF", 14, _errorCode), addr(_addr) 324 {} 325 326 PageFault(Addr _addr, bool present, BaseTLB::Mode mode, 327 bool user, bool reserved) : 328 X86Fault("Page-Fault", "#PF", 14, 0), addr(_addr) 329 { 330 PageFaultErrorCode code = 0; 331 code.present = present; 332 code.write = (mode == BaseTLB::Write); 333 code.user = user; 334 code.reserved = reserved; 335 code.fetch = (mode == BaseTLB::Execute); 336 errorCode = code; 337 } 338 339 void invoke(ThreadContext * tc, 340 StaticInstPtr inst = StaticInst::nullStaticInstPtr); 341 342#if FULL_SYSTEM 343 virtual std::string describe() const; 344#endif 345 }; 346 347 class X87FpExceptionPending : public X86Fault 348 { 349 public: 350 X87FpExceptionPending() : 351 X86Fault("x87 Floating-Point Exception Pending", "#MF", 16) 352 {} 353 }; 354 355 class AlignmentCheck : public X86Fault 356 { 357 public: 358 AlignmentCheck() : 359 X86Fault("Alignment-Check", "#AC", 17, 0) 360 {} 361 }; 362 363 class MachineCheck : public X86Abort 364 { 365 public: 366 MachineCheck() : 367 X86Abort("Machine-Check", "#MC", 18) 368 {} 369 }; 370 371 class SIMDFloatingPointFault : public X86Fault 372 { 373 public: 374 SIMDFloatingPointFault() : 375 X86Fault("SIMD Floating-Point", "#XF", 19) 376 {} 377 }; 378 379 class SecurityException : public X86FaultBase 380 { 381 public: 382 SecurityException() : 383 X86FaultBase("Security Exception", "#SX", 30) 384 {} 385 }; 386 387 class ExternalInterrupt : public X86Interrupt 388 { 389 public: 390 ExternalInterrupt(uint8_t _vector) : 391 X86Interrupt("External Interrupt", "#INTR", _vector) 392 {} 393 }; 394 395 class SystemManagementInterrupt : public X86Interrupt 396 { 397 public: 398 SystemManagementInterrupt() : 399 X86Interrupt("System Management Interrupt", "#SMI", 0) 400 {} 401 }; 402 403 class InitInterrupt : public X86Interrupt 404 { 405 public: 406 InitInterrupt(uint8_t _vector) : 407 X86Interrupt("INIT Interrupt", "#INIT", _vector) 408 {} 409 410 void invoke(ThreadContext * tc, 411 StaticInstPtr inst = StaticInst::nullStaticInstPtr); 412 }; 413 414 class StartupInterrupt : public X86Interrupt 415 { 416 public: 417 StartupInterrupt(uint8_t _vector) : 418 X86Interrupt("Startup Interrupt", "#SIPI", _vector) 419 {} 420 421 void invoke(ThreadContext * tc, 422 StaticInstPtr inst = StaticInst::nullStaticInstPtr); 423 }; 424 425 class SoftwareInterrupt : public X86Interrupt 426 { 427 public: 428 SoftwareInterrupt(uint8_t _vector) : 429 X86Interrupt("Software Interrupt", "#INTR", _vector) 430 {} 431 432 bool isSoft() 433 { 434 return true; 435 } 436 }; 437}; 438 439#endif // __ARCH_X86_FAULTS_HH__ 440