faults.hh revision 5684
17151Sgblack@eecs.umich.edu/* 27151Sgblack@eecs.umich.edu * Copyright (c) 2007 The Hewlett-Packard Development Company 37151Sgblack@eecs.umich.edu * All rights reserved. 47151Sgblack@eecs.umich.edu * 57151Sgblack@eecs.umich.edu * Redistribution and use of this software in source and binary forms, 67151Sgblack@eecs.umich.edu * with or without modification, are permitted provided that the 77151Sgblack@eecs.umich.edu * following conditions are met: 87151Sgblack@eecs.umich.edu * 97151Sgblack@eecs.umich.edu * The software must be used only for Non-Commercial Use which means any 107151Sgblack@eecs.umich.edu * use which is NOT directed to receiving any direct monetary 117151Sgblack@eecs.umich.edu * compensation for, or commercial advantage from such use. Illustrative 127151Sgblack@eecs.umich.edu * examples of non-commercial use are academic research, personal study, 137151Sgblack@eecs.umich.edu * teaching, education and corporate research & development. 147151Sgblack@eecs.umich.edu * Illustrative examples of commercial use are distributing products for 157151Sgblack@eecs.umich.edu * commercial advantage and providing services using the software for 167151Sgblack@eecs.umich.edu * commercial advantage. 177151Sgblack@eecs.umich.edu * 187151Sgblack@eecs.umich.edu * If you wish to use this software or functionality therein that may be 197151Sgblack@eecs.umich.edu * covered by patents for commercial use, please contact: 207151Sgblack@eecs.umich.edu * Director of Intellectual Property Licensing 217151Sgblack@eecs.umich.edu * Office of Strategy and Technology 227151Sgblack@eecs.umich.edu * Hewlett-Packard Company 237151Sgblack@eecs.umich.edu * 1501 Page Mill Road 247151Sgblack@eecs.umich.edu * Palo Alto, California 94304 257151Sgblack@eecs.umich.edu * 267151Sgblack@eecs.umich.edu * Redistributions of source code must retain the above copyright notice, 277151Sgblack@eecs.umich.edu * this list of conditions and the following disclaimer. Redistributions 287151Sgblack@eecs.umich.edu * in binary form must reproduce the above copyright notice, this list of 297151Sgblack@eecs.umich.edu * conditions and the following disclaimer in the documentation and/or 307151Sgblack@eecs.umich.edu * other materials provided with the distribution. Neither the name of 317151Sgblack@eecs.umich.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 327151Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 337151Sgblack@eecs.umich.edu * this software without specific prior written permission. No right of 347151Sgblack@eecs.umich.edu * sublicense is granted herewith. Derivatives of the software and 357151Sgblack@eecs.umich.edu * output created using the software may be prepared, but only for 367151Sgblack@eecs.umich.edu * Non-Commercial Uses. Derivatives of the software may be shared with 377151Sgblack@eecs.umich.edu * others provided: (i) the others agree to abide by the list of 387151Sgblack@eecs.umich.edu * conditions herein which includes the Non-Commercial Use restrictions; 397151Sgblack@eecs.umich.edu * and (ii) such Derivatives of the software include the above copyright 407151Sgblack@eecs.umich.edu * notice to acknowledge the contribution from this software where 417151Sgblack@eecs.umich.edu * applicable, this list of conditions and the disclaimer below. 427151Sgblack@eecs.umich.edu * 437151Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 447151Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 457151Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 467151Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 477151Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 487151Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 497720Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 507720Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 517720Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 527720Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 537151Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 547151Sgblack@eecs.umich.edu * 557151Sgblack@eecs.umich.edu * Authors: Gabe Black 567720Sgblack@eecs.umich.edu */ 577720Sgblack@eecs.umich.edu 587720Sgblack@eecs.umich.edu#ifndef __ARCH_X86_FAULTS_HH__ 597594SGene.Wu@arm.com#define __ARCH_X86_FAULTS_HH__ 607151Sgblack@eecs.umich.edu 617151Sgblack@eecs.umich.edu#include "base/misc.hh" 627151Sgblack@eecs.umich.edu#include "sim/faults.hh" 637151Sgblack@eecs.umich.edu 647151Sgblack@eecs.umich.edunamespace X86ISA 657151Sgblack@eecs.umich.edu{ 667151Sgblack@eecs.umich.edu // Base class for all x86 "faults" where faults is in the m5 sense 677151Sgblack@eecs.umich.edu class X86FaultBase : public FaultBase 687151Sgblack@eecs.umich.edu { 697151Sgblack@eecs.umich.edu protected: 707151Sgblack@eecs.umich.edu const char * faultName; 717720Sgblack@eecs.umich.edu const char * mnem; 727720Sgblack@eecs.umich.edu uint64_t errorCode; 737151Sgblack@eecs.umich.edu 747151Sgblack@eecs.umich.edu X86FaultBase(const char * _faultName, const char * _mnem, 757151Sgblack@eecs.umich.edu uint64_t _errorCode = 0) : 767720Sgblack@eecs.umich.edu faultName(_faultName), mnem(_mnem), errorCode(_errorCode) 777151Sgblack@eecs.umich.edu { 787151Sgblack@eecs.umich.edu } 797151Sgblack@eecs.umich.edu 807151Sgblack@eecs.umich.edu const char * name() const 817151Sgblack@eecs.umich.edu { 827151Sgblack@eecs.umich.edu return faultName; 837151Sgblack@eecs.umich.edu } 847151Sgblack@eecs.umich.edu 857151Sgblack@eecs.umich.edu virtual bool isBenign() 867151Sgblack@eecs.umich.edu { 877151Sgblack@eecs.umich.edu return true; 887720Sgblack@eecs.umich.edu } 897720Sgblack@eecs.umich.edu 907602SGene.Wu@arm.com virtual const char * mnemonic() const 917602SGene.Wu@arm.com { 927602SGene.Wu@arm.com return mnem; 937151Sgblack@eecs.umich.edu } 947151Sgblack@eecs.umich.edu 957282Sgblack@eecs.umich.edu void 967151Sgblack@eecs.umich.edu invoke(ThreadContext * tc) 977151Sgblack@eecs.umich.edu { 987151Sgblack@eecs.umich.edu panic("Unimplemented fault %s.\n", name()); 997151Sgblack@eecs.umich.edu } 1007151Sgblack@eecs.umich.edu }; 1017151Sgblack@eecs.umich.edu 1027151Sgblack@eecs.umich.edu // Base class for x86 faults which behave as if the underlying instruction 1037151Sgblack@eecs.umich.edu // didn't happen. 1047720Sgblack@eecs.umich.edu class X86Fault : public X86FaultBase 1057720Sgblack@eecs.umich.edu { 1067720Sgblack@eecs.umich.edu protected: 1077594SGene.Wu@arm.com X86Fault(const char * name, const char * mnem, 1087151Sgblack@eecs.umich.edu uint64_t _errorCode = 0) : 1097151Sgblack@eecs.umich.edu X86FaultBase(name, mnem, _errorCode) 1107151Sgblack@eecs.umich.edu {} 1117720Sgblack@eecs.umich.edu }; 1127720Sgblack@eecs.umich.edu 1137720Sgblack@eecs.umich.edu // Base class for x86 traps which behave as if the underlying instruction 1147594SGene.Wu@arm.com // completed. 1157151Sgblack@eecs.umich.edu class X86Trap : public X86FaultBase 1167151Sgblack@eecs.umich.edu { 1177151Sgblack@eecs.umich.edu protected: 1187282Sgblack@eecs.umich.edu X86Trap(const char * name, const char * mnem, 1197282Sgblack@eecs.umich.edu uint64_t _errorCode = 0) : 1207282Sgblack@eecs.umich.edu X86FaultBase(name, mnem, _errorCode) 1217720Sgblack@eecs.umich.edu {} 1227720Sgblack@eecs.umich.edu 1237282Sgblack@eecs.umich.edu#if FULL_SYSTEM 1247282Sgblack@eecs.umich.edu void invoke(ThreadContext * tc); 1257720Sgblack@eecs.umich.edu#endif 1267282Sgblack@eecs.umich.edu }; 1277282Sgblack@eecs.umich.edu 1287151Sgblack@eecs.umich.edu // Base class for x86 aborts which seem to be catastrophic failures. 1297151Sgblack@eecs.umich.edu class X86Abort : public X86FaultBase 1307151Sgblack@eecs.umich.edu { 1317151Sgblack@eecs.umich.edu protected: 1327151Sgblack@eecs.umich.edu X86Abort(const char * name, const char * mnem, 1337151Sgblack@eecs.umich.edu uint64_t _errorCode = 0) : 1347151Sgblack@eecs.umich.edu X86FaultBase(name, mnem, _errorCode) 1357151Sgblack@eecs.umich.edu {} 1367151Sgblack@eecs.umich.edu 1377151Sgblack@eecs.umich.edu#if FULL_SYSTEM 1387151Sgblack@eecs.umich.edu void invoke(ThreadContext * tc); 1397151Sgblack@eecs.umich.edu#endif 1407151Sgblack@eecs.umich.edu }; 1417151Sgblack@eecs.umich.edu 1427151Sgblack@eecs.umich.edu // Base class for x86 interrupts. 1437720Sgblack@eecs.umich.edu class X86Interrupt : public X86FaultBase 1447720Sgblack@eecs.umich.edu { 1457720Sgblack@eecs.umich.edu protected: 1467720Sgblack@eecs.umich.edu uint8_t vector; 1477151Sgblack@eecs.umich.edu X86Interrupt(const char * name, const char * mnem, uint8_t _vector, 1487151Sgblack@eecs.umich.edu uint64_t _errorCode = 0) : 1497151Sgblack@eecs.umich.edu X86FaultBase(name, mnem, _errorCode), vector(_vector) 1507151Sgblack@eecs.umich.edu {} 1517151Sgblack@eecs.umich.edu 1527151Sgblack@eecs.umich.edu#if FULL_SYSTEM 1537151Sgblack@eecs.umich.edu void invoke(ThreadContext * tc); 1547151Sgblack@eecs.umich.edu#endif 1557151Sgblack@eecs.umich.edu }; 1567151Sgblack@eecs.umich.edu 1577151Sgblack@eecs.umich.edu class UnimpInstFault : public FaultBase 1587294Sgblack@eecs.umich.edu { 1597294Sgblack@eecs.umich.edu public: 1607294Sgblack@eecs.umich.edu const char * name() const 1617294Sgblack@eecs.umich.edu { 1627294Sgblack@eecs.umich.edu return "unimplemented_micro"; 1637294Sgblack@eecs.umich.edu } 1647720Sgblack@eecs.umich.edu 1657720Sgblack@eecs.umich.edu void invoke(ThreadContext * tc) 1667720Sgblack@eecs.umich.edu { 1677720Sgblack@eecs.umich.edu panic("Unimplemented instruction!"); 1687720Sgblack@eecs.umich.edu } 1697151Sgblack@eecs.umich.edu }; 1707151Sgblack@eecs.umich.edu 1717294Sgblack@eecs.umich.edu static inline Fault genMachineCheckFault() 1727294Sgblack@eecs.umich.edu { 1737294Sgblack@eecs.umich.edu panic("Machine check fault not implemented in x86!\n"); 1747294Sgblack@eecs.umich.edu } 1757294Sgblack@eecs.umich.edu 1767294Sgblack@eecs.umich.edu // Below is a summary of the interrupt/exception information in the 1777720Sgblack@eecs.umich.edu // architecture manuals. 1787720Sgblack@eecs.umich.edu 1797720Sgblack@eecs.umich.edu // Class | Type | vector | Cause | mnem 1807720Sgblack@eecs.umich.edu //------------------------------------------------------------------------ 1817720Sgblack@eecs.umich.edu //Contrib Fault 0 Divide-by-Zero-Error #DE 1827151Sgblack@eecs.umich.edu //Benign Either 1 Debug #DB 1837151Sgblack@eecs.umich.edu //Benign Interrupt 2 Non-Maskable-Interrupt #NMI 1847151Sgblack@eecs.umich.edu //Benign Trap 3 Breakpoint #BP 1857151Sgblack@eecs.umich.edu //Benign Trap 4 Overflow #OF 1867151Sgblack@eecs.umich.edu //Benign Fault 5 Bound-Range #BR 1877151Sgblack@eecs.umich.edu //Benign Fault 6 Invalid-Opcode #UD 1887151Sgblack@eecs.umich.edu //Benign Fault 7 Device-Not-Available #NM 1897151Sgblack@eecs.umich.edu //Benign Abort 8 Double-Fault #DF 1907151Sgblack@eecs.umich.edu // 9 Coprocessor-Segment-Overrun 1917151Sgblack@eecs.umich.edu //Contrib Fault 10 Invalid-TSS #TS 1927151Sgblack@eecs.umich.edu //Contrib Fault 11 Segment-Not-Present #NP 193 //Contrib Fault 12 Stack #SS 194 //Contrib Fault 13 General-Protection #GP 195 //Either Fault 14 Page-Fault #PF 196 // 15 Reserved 197 //Benign Fault 16 x87 Floating-Point Exception Pending #MF 198 //Benign Fault 17 Alignment-Check #AC 199 //Benign Abort 18 Machine-Check #MC 200 //Benign Fault 19 SIMD Floating-Point #XF 201 // 20-29 Reserved 202 //Contrib ? 30 Security Exception #SX 203 // 31 Reserved 204 //Benign Interrupt 0-255 External Interrupts #INTR 205 //Benign Interrupt 0-255 Software Interrupts INTn 206 207 class DivideByZero : public X86Fault 208 { 209 public: 210 DivideByZero() : 211 X86Fault("Divide-by-Zero-Error", "#DE") 212 {} 213 }; 214 215 class DebugException : public X86FaultBase 216 { 217 public: 218 DebugException() : 219 X86FaultBase("Debug", "#DB") 220 {} 221 }; 222 223 class NonMaskableInterrupt : public X86Interrupt 224 { 225 public: 226 NonMaskableInterrupt(uint8_t _vector) : 227 X86Interrupt("Non Maskable Interrupt", "#NMI", _vector) 228 {} 229 }; 230 231 class Breakpoint : public X86Trap 232 { 233 public: 234 Breakpoint() : 235 X86Trap("Breakpoint", "#BP") 236 {} 237 }; 238 239 class OverflowTrap : public X86Trap 240 { 241 public: 242 OverflowTrap() : 243 X86Trap("Overflow", "#OF") 244 {} 245 }; 246 247 class BoundRange : public X86Fault 248 { 249 public: 250 BoundRange() : 251 X86Fault("Bound-Range", "#BR") 252 {} 253 }; 254 255 class InvalidOpcode : public X86Fault 256 { 257 public: 258 InvalidOpcode() : 259 X86Fault("Invalid-Opcode", "#UD") 260 {} 261 }; 262 263 class DeviceNotAvailable : public X86Fault 264 { 265 public: 266 DeviceNotAvailable() : 267 X86Fault("Device-Not-Available", "#NM") 268 {} 269 }; 270 271 class DoubleFault : public X86Abort 272 { 273 public: 274 DoubleFault() : 275 X86Abort("Double-Fault", "#DF") 276 {} 277 }; 278 279 class InvalidTSS : public X86Fault 280 { 281 public: 282 InvalidTSS() : 283 X86Fault("Invalid-TSS", "#TS") 284 {} 285 }; 286 287 class SegmentNotPresent : public X86Fault 288 { 289 public: 290 SegmentNotPresent() : 291 X86Fault("Segment-Not-Present", "#NP") 292 {} 293 }; 294 295 class StackFault : public X86Fault 296 { 297 public: 298 StackFault() : 299 X86Fault("Stack", "#SS") 300 {} 301 }; 302 303 class GeneralProtection : public X86Fault 304 { 305 public: 306 GeneralProtection(uint64_t _errorCode) : 307 X86Fault("General-Protection", "#GP", _errorCode) 308 {} 309 }; 310 311 class PageFault : public X86Fault 312 { 313 public: 314 PageFault() : 315 X86Fault("Page-Fault", "#PF") 316 {} 317 }; 318 319 class X87FpExceptionPending : public X86Fault 320 { 321 public: 322 X87FpExceptionPending() : 323 X86Fault("x87 Floating-Point Exception Pending", "#MF") 324 {} 325 }; 326 327 class AlignmentCheck : public X86Fault 328 { 329 public: 330 AlignmentCheck() : 331 X86Fault("Alignment-Check", "#AC") 332 {} 333 }; 334 335 class MachineCheck : public X86Abort 336 { 337 public: 338 MachineCheck() : 339 X86Abort("Machine-Check", "#MC") 340 {} 341 }; 342 343 class SIMDFloatingPointFault : public X86Fault 344 { 345 public: 346 SIMDFloatingPointFault() : 347 X86Fault("SIMD Floating-Point", "#XF") 348 {} 349 }; 350 351 class SecurityException : public X86FaultBase 352 { 353 public: 354 SecurityException() : 355 X86FaultBase("Security Exception", "#SX") 356 {} 357 }; 358 359 class ExternalInterrupt : public X86Interrupt 360 { 361 public: 362 ExternalInterrupt(uint8_t _vector) : 363 X86Interrupt("External Interrupt", "#INTR", _vector) 364 {} 365 }; 366 367 class SystemManagementInterrupt : public X86Interrupt 368 { 369 public: 370 SystemManagementInterrupt() : 371 X86Interrupt("System Management Interrupt", "#SMI", 0) 372 {} 373 }; 374 375 class InitInterrupt : public X86Interrupt 376 { 377 uint8_t vector; 378 public: 379 InitInterrupt(uint8_t _vector) : 380 X86Interrupt("INIT Interrupt", "#INIT", _vector) 381 {} 382 }; 383 384 class SoftwareInterrupt : public X86Interrupt 385 { 386 public: 387 SoftwareInterrupt(uint8_t _vector) : 388 X86Interrupt("Software Interrupt", "INTn", _vector) 389 {} 390 }; 391 392 // These faults aren't part of the ISA definition. They trigger filling 393 // the tlb on a miss and are to take the place of a hardware table walker. 394 class FakeITLBFault : public X86Fault 395 { 396 protected: 397 Addr vaddr; 398 public: 399 FakeITLBFault(Addr _vaddr) : 400 X86Fault("fake instruction tlb fault", "itlb"), 401 vaddr(_vaddr) 402 {} 403 404 void invoke(ThreadContext * tc); 405 }; 406 407 class FakeDTLBFault : public X86Fault 408 { 409 protected: 410 Addr vaddr; 411 public: 412 FakeDTLBFault(Addr _vaddr) : 413 X86Fault("fake data tlb fault", "dtlb"), 414 vaddr(_vaddr) 415 {} 416 417 void invoke(ThreadContext * tc); 418 }; 419}; 420 421#endif // __ARCH_X86_FAULTS_HH__ 422