faults.hh revision 2201
14486Sbinkertn@umich.edu/* 24486Sbinkertn@umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan 34486Sbinkertn@umich.edu * All rights reserved. 44486Sbinkertn@umich.edu * 54486Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 64486Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are 74486Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright 84486Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer; 94486Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright 104486Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 114486Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution; 124486Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 134486Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 144486Sbinkertn@umich.edu * this software without specific prior written permission. 154486Sbinkertn@umich.edu * 164486Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 174486Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 184486Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 194486Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 204486Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 214486Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 224486Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 234486Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 244486Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 254486Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 264486Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 274486Sbinkertn@umich.edu */ 284486Sbinkertn@umich.edu 293102SN/A#ifndef __FAULTS_HH__ 302568SN/A#define __FAULTS_HH__ 312568SN/A 322568SN/A#include "base/refcnt.hh" 332568SN/A#include "sim/stats.hh" 348839Sandreas.hansson@arm.com#include "config/full_system.hh" 358839Sandreas.hansson@arm.com 368713Sandreas.hansson@arm.comclass ExecContext; 378713Sandreas.hansson@arm.comclass FaultBase; 382568SN/Atypedef RefCountingPtr<FaultBase> Fault; 394439SN/A 402568SN/Atypedef const char * FaultName; 418713Sandreas.hansson@arm.comtypedef Stats::Scalar<> FaultStat; 428713Sandreas.hansson@arm.com 43// Each class has it's name statically define in _name, 44// and has a virtual function to access it's name. 45// The function is necessary because otherwise, all objects 46// which are being accessed cast as a FaultBase * (namely 47// all faults returned using the Fault type) will use the 48// generic FaultBase name. 49 50class FaultBase : public RefCounted 51{ 52 public: 53 virtual FaultName name() = 0; 54 virtual FaultStat & stat() = 0; 55#if FULL_SYSTEM 56 virtual void invoke(ExecContext * xc) = 0; 57#else 58 virtual void invoke(ExecContext * xc); 59#endif 60// template<typename T> 61// bool isA() {return dynamic_cast<T *>(this);} 62 virtual bool isMachineCheckFault() {return false;} 63 virtual bool isAlignmentFault() {return false;} 64}; 65 66FaultBase * const NoFault = 0; 67 68//The ISAs are each responsible for providing a genMachineCheckFault and a 69//genAlignmentFault functions, which return faults to use in the case of a 70//machine check fault or an alignment fault, respectively. Base classes which 71//provide the name() function, and the isMachineCheckFault and isAlignmentFault 72//functions are provided below. 73 74class MachineCheckFault : public virtual FaultBase 75{ 76 private: 77 static FaultName _name; 78 public: 79 FaultName name() {return _name;} 80 bool isMachineCheckFault() {return true;} 81}; 82 83class AlignmentFault : public virtual FaultBase 84{ 85 private: 86 static FaultName _name; 87 public: 88 FaultName name() {return _name;} 89 bool isAlignmentFault() {return true;} 90}; 91 92 93#endif // __FAULTS_HH__ 94