faults.hh revision 5681
18092Snilay@cs.wisc.edu/* 28092Snilay@cs.wisc.edu * Copyright (c) 2007 The Hewlett-Packard Development Company 38092Snilay@cs.wisc.edu * All rights reserved. 48092Snilay@cs.wisc.edu * 58092Snilay@cs.wisc.edu * Redistribution and use of this software in source and binary forms, 68092Snilay@cs.wisc.edu * with or without modification, are permitted provided that the 78092Snilay@cs.wisc.edu * following conditions are met: 88092Snilay@cs.wisc.edu * 98092Snilay@cs.wisc.edu * The software must be used only for Non-Commercial Use which means any 108092Snilay@cs.wisc.edu * use which is NOT directed to receiving any direct monetary 118092Snilay@cs.wisc.edu * compensation for, or commercial advantage from such use. Illustrative 128092Snilay@cs.wisc.edu * examples of non-commercial use are academic research, personal study, 138092Snilay@cs.wisc.edu * teaching, education and corporate research & development. 148092Snilay@cs.wisc.edu * Illustrative examples of commercial use are distributing products for 158092Snilay@cs.wisc.edu * commercial advantage and providing services using the software for 168092Snilay@cs.wisc.edu * commercial advantage. 178092Snilay@cs.wisc.edu * 188092Snilay@cs.wisc.edu * If you wish to use this software or functionality therein that may be 198092Snilay@cs.wisc.edu * covered by patents for commercial use, please contact: 208092Snilay@cs.wisc.edu * Director of Intellectual Property Licensing 218092Snilay@cs.wisc.edu * Office of Strategy and Technology 228092Snilay@cs.wisc.edu * Hewlett-Packard Company 238092Snilay@cs.wisc.edu * 1501 Page Mill Road 248092Snilay@cs.wisc.edu * Palo Alto, California 94304 258092Snilay@cs.wisc.edu * 268092Snilay@cs.wisc.edu * Redistributions of source code must retain the above copyright notice, 278092Snilay@cs.wisc.edu * this list of conditions and the following disclaimer. Redistributions 288092Snilay@cs.wisc.edu * in binary form must reproduce the above copyright notice, this list of 2912492Sodanrc@yahoo.com.br * conditions and the following disclaimer in the documentation and/or 3012492Sodanrc@yahoo.com.br * other materials provided with the distribution. Neither the name of 318092Snilay@cs.wisc.edu * the COPYRIGHT HOLDER(s), HEWLETT-PACKARD COMPANY, nor the names of its 328092Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 3311305Sblake.hechtman@amd.com * this software without specific prior written permission. No right of 348092Snilay@cs.wisc.edu * sublicense is granted herewith. Derivatives of the software and 358092Snilay@cs.wisc.edu * output created using the software may be prepared, but only for 3611305Sblake.hechtman@amd.com * Non-Commercial Uses. Derivatives of the software may be shared with 3711307Santhony.gutierrez@amd.com * others provided: (i) the others agree to abide by the list of 3814184Sgabeblack@google.com * conditions herein which includes the Non-Commercial Use restrictions; 3914184Sgabeblack@google.com * and (ii) such Derivatives of the software include the above copyright 4014184Sgabeblack@google.com * notice to acknowledge the contribution from this software where 4114184Sgabeblack@google.com * applicable, this list of conditions and the disclaimer below. 4214184Sgabeblack@google.com * 4314184Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 448092Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 458174Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 468092Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 478092Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4811025Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 4911025Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 508174Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 5111025Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 528174Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 538174Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 548174Snilay@cs.wisc.edu * 558092Snilay@cs.wisc.edu * Authors: Gabe Black 5611459Smatthew.poremba@amd.com */ 5711005Sandreas.sandberg@arm.com 5811307Santhony.gutierrez@amd.com#ifndef __ARCH_X86_FAULTS_HH__ 5911307Santhony.gutierrez@amd.com#define __ARCH_X86_FAULTS_HH__ 6011305Sblake.hechtman@amd.com 6111305Sblake.hechtman@amd.com#include "base/misc.hh" 6211305Sblake.hechtman@amd.com#include "sim/faults.hh" 6311305Sblake.hechtman@amd.com 648092Snilay@cs.wisc.edunamespace X86ISA 659508Snilay@cs.wisc.edu{ 669466Snilay@cs.wisc.edu // Base class for all x86 "faults" where faults is in the m5 sense 679466Snilay@cs.wisc.edu class X86FaultBase : public FaultBase 6811305Sblake.hechtman@amd.com { 6911305Sblake.hechtman@amd.com protected: 7011305Sblake.hechtman@amd.com const char * faultName; 719466Snilay@cs.wisc.edu const char * mnem; 729466Snilay@cs.wisc.edu uint64_t errorCode; 738174Snilay@cs.wisc.edu 748174Snilay@cs.wisc.edu X86FaultBase(const char * _faultName, const char * _mnem, 758174Snilay@cs.wisc.edu uint64_t _errorCode = 0) : 768174Snilay@cs.wisc.edu faultName(_faultName), mnem(_mnem), errorCode(_errorCode) 778174Snilay@cs.wisc.edu { 788092Snilay@cs.wisc.edu } 7911459Smatthew.poremba@amd.com 8011305Sblake.hechtman@amd.com const char * name() const 8111305Sblake.hechtman@amd.com { 8211305Sblake.hechtman@amd.com return faultName; 838174Snilay@cs.wisc.edu } 8411305Sblake.hechtman@amd.com 858174Snilay@cs.wisc.edu virtual bool isBenign() 868174Snilay@cs.wisc.edu { 8711305Sblake.hechtman@amd.com return true; 8811305Sblake.hechtman@amd.com } 8911305Sblake.hechtman@amd.com 9011305Sblake.hechtman@amd.com virtual const char * mnemonic() const 9111305Sblake.hechtman@amd.com { 9211305Sblake.hechtman@amd.com return mnem; 9311305Sblake.hechtman@amd.com } 9411305Sblake.hechtman@amd.com }; 9511305Sblake.hechtman@amd.com 9611305Sblake.hechtman@amd.com // Base class for x86 faults which behave as if the underlying instruction 9711305Sblake.hechtman@amd.com // didn't happen. 9811305Sblake.hechtman@amd.com class X86Fault : public X86FaultBase 9911305Sblake.hechtman@amd.com { 10011305Sblake.hechtman@amd.com protected: 10111305Sblake.hechtman@amd.com X86Fault(const char * name, const char * mnem, 10211305Sblake.hechtman@amd.com uint64_t _errorCode = 0) : 10311459Smatthew.poremba@amd.com X86FaultBase(name, mnem, _errorCode) 10411305Sblake.hechtman@amd.com {} 10511307Santhony.gutierrez@amd.com }; 10611307Santhony.gutierrez@amd.com 10711305Sblake.hechtman@amd.com // Base class for x86 traps which behave as if the underlying instruction 10811305Sblake.hechtman@amd.com // completed. 10911305Sblake.hechtman@amd.com class X86Trap : public X86FaultBase 11011305Sblake.hechtman@amd.com { 11111305Sblake.hechtman@amd.com protected: 11211305Sblake.hechtman@amd.com X86Trap(const char * name, const char * mnem, 11311305Sblake.hechtman@amd.com uint64_t _errorCode = 0) : 11411305Sblake.hechtman@amd.com X86FaultBase(name, mnem, _errorCode) 11511305Sblake.hechtman@amd.com {} 11611305Sblake.hechtman@amd.com 11711305Sblake.hechtman@amd.com#if FULL_SYSTEM 11811305Sblake.hechtman@amd.com void invoke(ThreadContext * tc); 11911305Sblake.hechtman@amd.com#endif 12011305Sblake.hechtman@amd.com }; 12111305Sblake.hechtman@amd.com 12211305Sblake.hechtman@amd.com // Base class for x86 aborts which seem to be catastrophic failures. 12311305Sblake.hechtman@amd.com class X86Abort : public X86FaultBase 12411305Sblake.hechtman@amd.com { 12511305Sblake.hechtman@amd.com protected: 12611305Sblake.hechtman@amd.com X86Abort(const char * name, const char * mnem, 12711305Sblake.hechtman@amd.com uint64_t _errorCode = 0) : 12811305Sblake.hechtman@amd.com X86FaultBase(name, mnem, _errorCode) 12911305Sblake.hechtman@amd.com {} 13011305Sblake.hechtman@amd.com 13111459Smatthew.poremba@amd.com#if FULL_SYSTEM 13211305Sblake.hechtman@amd.com void invoke(ThreadContext * tc); 13311307Santhony.gutierrez@amd.com#endif 13411307Santhony.gutierrez@amd.com }; 13511305Sblake.hechtman@amd.com 13611305Sblake.hechtman@amd.com // Base class for x86 interrupts. 13711305Sblake.hechtman@amd.com class X86Interrupt : public X86FaultBase 13811305Sblake.hechtman@amd.com { 13911305Sblake.hechtman@amd.com protected: 14011305Sblake.hechtman@amd.com uint8_t vector; 14111305Sblake.hechtman@amd.com X86Interrupt(const char * name, const char * mnem, uint8_t _vector, 14211305Sblake.hechtman@amd.com uint64_t _errorCode = 0) : 1439508Snilay@cs.wisc.edu X86FaultBase(name, mnem, _errorCode), vector(_vector) 14410472Sandreas.hansson@arm.com {} 14510472Sandreas.hansson@arm.com 1468174Snilay@cs.wisc.edu#if FULL_SYSTEM 14711025Snilay@cs.wisc.edu void invoke(ThreadContext * tc); 14811025Snilay@cs.wisc.edu#endif 1499508Snilay@cs.wisc.edu }; 15011025Snilay@cs.wisc.edu 1519508Snilay@cs.wisc.edu class UnimpInstFault : public FaultBase 1529508Snilay@cs.wisc.edu { 1539508Snilay@cs.wisc.edu public: 1548092Snilay@cs.wisc.edu const char * name() const 1558092Snilay@cs.wisc.edu { 1569302Snilay@cs.wisc.edu return "unimplemented_micro"; 1579302Snilay@cs.wisc.edu } 1588092Snilay@cs.wisc.edu 1598092Snilay@cs.wisc.edu void invoke(ThreadContext * tc) 1608174Snilay@cs.wisc.edu { 1618174Snilay@cs.wisc.edu panic("Unimplemented instruction!"); 1628174Snilay@cs.wisc.edu } 1638174Snilay@cs.wisc.edu }; 1648174Snilay@cs.wisc.edu 1658174Snilay@cs.wisc.edu static inline Fault genMachineCheckFault() 1668174Snilay@cs.wisc.edu { 1678092Snilay@cs.wisc.edu panic("Machine check fault not implemented in x86!\n"); 16812492Sodanrc@yahoo.com.br } 169 170 // Below is a summary of the interrupt/exception information in the 171 // architecture manuals. 172 173 // Class | Type | vector | Cause | mnem 174 //------------------------------------------------------------------------ 175 //Contrib Fault 0 Divide-by-Zero-Error #DE 176 //Benign Either 1 Debug #DB 177 //Benign Interrupt 2 Non-Maskable-Interrupt #NMI 178 //Benign Trap 3 Breakpoint #BP 179 //Benign Trap 4 Overflow #OF 180 //Benign Fault 5 Bound-Range #BR 181 //Benign Fault 6 Invalid-Opcode #UD 182 //Benign Fault 7 Device-Not-Available #NM 183 //Benign Abort 8 Double-Fault #DF 184 // 9 Coprocessor-Segment-Overrun 185 //Contrib Fault 10 Invalid-TSS #TS 186 //Contrib Fault 11 Segment-Not-Present #NP 187 //Contrib Fault 12 Stack #SS 188 //Contrib Fault 13 General-Protection #GP 189 //Either Fault 14 Page-Fault #PF 190 // 15 Reserved 191 //Benign Fault 16 x87 Floating-Point Exception Pending #MF 192 //Benign Fault 17 Alignment-Check #AC 193 //Benign Abort 18 Machine-Check #MC 194 //Benign Fault 19 SIMD Floating-Point #XF 195 // 20-29 Reserved 196 //Contrib ? 30 Security Exception #SX 197 // 31 Reserved 198 //Benign Interrupt 0-255 External Interrupts #INTR 199 //Benign Interrupt 0-255 Software Interrupts INTn 200 201 class DivideByZero : public X86Fault 202 { 203 public: 204 DivideByZero() : 205 X86Fault("Divide-by-Zero-Error", "#DE") 206 {} 207 }; 208 209 class DebugException : public X86FaultBase 210 { 211 public: 212 DebugException() : 213 X86FaultBase("Debug", "#DB") 214 {} 215 }; 216 217 class NonMaskableInterrupt : public X86Interrupt 218 { 219 public: 220 NonMaskableInterrupt(uint8_t _vector) : 221 X86Interrupt("Non Maskable Interrupt", "#NMI", _vector) 222 {} 223 }; 224 225 class Breakpoint : public X86Trap 226 { 227 public: 228 Breakpoint() : 229 X86Trap("Breakpoint", "#BP") 230 {} 231 }; 232 233 class OverflowTrap : public X86Trap 234 { 235 public: 236 OverflowTrap() : 237 X86Trap("Overflow", "#OF") 238 {} 239 }; 240 241 class BoundRange : public X86Fault 242 { 243 public: 244 BoundRange() : 245 X86Fault("Bound-Range", "#BR") 246 {} 247 }; 248 249 class InvalidOpcode : public X86Fault 250 { 251 public: 252 InvalidOpcode() : 253 X86Fault("Invalid-Opcode", "#UD") 254 {} 255 }; 256 257 class DeviceNotAvailable : public X86Fault 258 { 259 public: 260 DeviceNotAvailable() : 261 X86Fault("Device-Not-Available", "#NM") 262 {} 263 }; 264 265 class DoubleFault : public X86Abort 266 { 267 public: 268 DoubleFault() : 269 X86Abort("Double-Fault", "#DF") 270 {} 271 }; 272 273 class InvalidTSS : public X86Fault 274 { 275 public: 276 InvalidTSS() : 277 X86Fault("Invalid-TSS", "#TS") 278 {} 279 }; 280 281 class SegmentNotPresent : public X86Fault 282 { 283 public: 284 SegmentNotPresent() : 285 X86Fault("Segment-Not-Present", "#NP") 286 {} 287 }; 288 289 class StackFault : public X86Fault 290 { 291 public: 292 StackFault() : 293 X86Fault("Stack", "#SS") 294 {} 295 }; 296 297 class GeneralProtection : public X86Fault 298 { 299 public: 300 GeneralProtection(uint64_t _errorCode) : 301 X86Fault("General-Protection", "#GP", _errorCode) 302 {} 303 }; 304 305 class PageFault : public X86Fault 306 { 307 public: 308 PageFault() : 309 X86Fault("Page-Fault", "#PF") 310 {} 311 }; 312 313 class X87FpExceptionPending : public X86Fault 314 { 315 public: 316 X87FpExceptionPending() : 317 X86Fault("x87 Floating-Point Exception Pending", "#MF") 318 {} 319 }; 320 321 class AlignmentCheck : public X86Fault 322 { 323 public: 324 AlignmentCheck() : 325 X86Fault("Alignment-Check", "#AC") 326 {} 327 }; 328 329 class MachineCheck : public X86Abort 330 { 331 public: 332 MachineCheck() : 333 X86Abort("Machine-Check", "#MC") 334 {} 335 }; 336 337 class SIMDFloatingPointFault : public X86Fault 338 { 339 public: 340 SIMDFloatingPointFault() : 341 X86Fault("SIMD Floating-Point", "#XF") 342 {} 343 }; 344 345 class SecurityException : public X86FaultBase 346 { 347 public: 348 SecurityException() : 349 X86FaultBase("Security Exception", "#SX") 350 {} 351 }; 352 353 class ExternalInterrupt : public X86Interrupt 354 { 355 public: 356 ExternalInterrupt(uint8_t _vector) : 357 X86Interrupt("External Interrupt", "#INTR", _vector) 358 {} 359 }; 360 361 class SystemManagementInterrupt : public X86Interrupt 362 { 363 public: 364 SystemManagementInterrupt() : 365 X86Interrupt("System Management Interrupt", "#SMI", 0) 366 {} 367 }; 368 369 class InitInterrupt : public X86Interrupt 370 { 371 uint8_t vector; 372 public: 373 InitInterrupt(uint8_t _vector) : 374 X86Interrupt("INIT Interrupt", "#INIT", _vector) 375 {} 376 }; 377 378 class SoftwareInterrupt : public X86Interrupt 379 { 380 public: 381 SoftwareInterrupt(uint8_t _vector) : 382 X86Interrupt("Software Interrupt", "INTn", _vector) 383 {} 384 }; 385 386 // These faults aren't part of the ISA definition. They trigger filling 387 // the tlb on a miss and are to take the place of a hardware table walker. 388 class FakeITLBFault : public X86Fault 389 { 390 protected: 391 Addr vaddr; 392 public: 393 FakeITLBFault(Addr _vaddr) : 394 X86Fault("fake instruction tlb fault", "itlb"), 395 vaddr(_vaddr) 396 {} 397 398 void invoke(ThreadContext * tc); 399 }; 400 401 class FakeDTLBFault : public X86Fault 402 { 403 protected: 404 Addr vaddr; 405 public: 406 FakeDTLBFault(Addr _vaddr) : 407 X86Fault("fake data tlb fault", "dtlb"), 408 vaddr(_vaddr) 409 {} 410 411 void invoke(ThreadContext * tc); 412 }; 413}; 414 415#endif // __ARCH_X86_FAULTS_HH__ 416