faults.hh revision 2175
12735Sktlim@umich.edu/* 210319SAndreas.Sandberg@ARM.com * Copyright (c) 2003-2005 The Regents of The University of Michigan 310319SAndreas.Sandberg@ARM.com * All rights reserved. 410319SAndreas.Sandberg@ARM.com * 510319SAndreas.Sandberg@ARM.com * Redistribution and use in source and binary forms, with or without 610319SAndreas.Sandberg@ARM.com * modification, are permitted provided that the following conditions are 710319SAndreas.Sandberg@ARM.com * met: redistributions of source code must retain the above copyright 810319SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer; 910319SAndreas.Sandberg@ARM.com * redistributions in binary form must reproduce the above copyright 1010319SAndreas.Sandberg@ARM.com * notice, this list of conditions and the following disclaimer in the 1110319SAndreas.Sandberg@ARM.com * documentation and/or other materials provided with the distribution; 1210319SAndreas.Sandberg@ARM.com * neither the name of the copyright holders nor the names of its 1310319SAndreas.Sandberg@ARM.com * contributors may be used to endorse or promote products derived from 142735Sktlim@umich.edu * this software without specific prior written permission. 1511303Ssteve.reinhardt@amd.com * 162735Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172735Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182735Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192735Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202735Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212735Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222735Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232735Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242735Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252735Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262735Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272735Sktlim@umich.edu */ 282735Sktlim@umich.edu 292735Sktlim@umich.edu#ifndef __FAULTS_HH__ 302735Sktlim@umich.edu#define __FAULTS_HH__ 312735Sktlim@umich.edu 322735Sktlim@umich.edu#include "base/refcnt.hh" 332735Sktlim@umich.edu#include "sim/stats.hh" 342735Sktlim@umich.edu#include "config/full_system.hh" 352735Sktlim@umich.edu 362735Sktlim@umich.educlass ExecContext; 372735Sktlim@umich.educlass FaultBase; 382735Sktlim@umich.edutypedef RefCountingPtr<FaultBase> Fault; 392735Sktlim@umich.edu 402735Sktlim@umich.edutypedef const char * FaultName; 412735Sktlim@umich.edutypedef Stats::Scalar<> FaultStat; 4210319SAndreas.Sandberg@ARM.com 432735Sktlim@umich.edu// Each class has it's name statically define in _name, 442735Sktlim@umich.edu// and has a virtual function to access it's name. 4510319SAndreas.Sandberg@ARM.com// The function is necessary because otherwise, all objects 4610319SAndreas.Sandberg@ARM.com// which are being accessed cast as a FaultBase * (namely 4710319SAndreas.Sandberg@ARM.com// all faults returned using the Fault type) will use the 4810319SAndreas.Sandberg@ARM.com// generic FaultBase name. 4910319SAndreas.Sandberg@ARM.com 5010319SAndreas.Sandberg@ARM.comclass FaultBase : public RefCounted 5110529Smorr@cs.wisc.edu{ 5210319SAndreas.Sandberg@ARM.com public: 5310319SAndreas.Sandberg@ARM.com virtual FaultName name() = 0; 5411608Snikos.nikoleris@arm.com virtual FaultStat & stat() = 0; 552735Sktlim@umich.edu#if FULL_SYSTEM 562735Sktlim@umich.edu virtual void ev5_trap(ExecContext * xc) = 0; 5710319SAndreas.Sandberg@ARM.com#endif 5810319SAndreas.Sandberg@ARM.com template<typename T> 5910319SAndreas.Sandberg@ARM.com bool isA() {return dynamic_cast<T *>(this);} 6010319SAndreas.Sandberg@ARM.com virtual bool isMachineCheckFault() {return false;} 6110319SAndreas.Sandberg@ARM.com virtual bool isAlignmentFault() {return false;} 6210319SAndreas.Sandberg@ARM.com}; 6310319SAndreas.Sandberg@ARM.com 6410319SAndreas.Sandberg@ARM.comFaultBase * const NoFault = 0; 6510319SAndreas.Sandberg@ARM.com 6610319SAndreas.Sandberg@ARM.com//The ISAs are each responsible for providing a genMachineCheckFault and a 6710319SAndreas.Sandberg@ARM.com//genAlignmentFault functions, which return faults to use in the case of a 6810319SAndreas.Sandberg@ARM.com//machine check fault or an alignment fault, respectively. Base classes which 6910319SAndreas.Sandberg@ARM.com//provide the name() function, and the isMachineCheckFault and isAlignmentFault 7010319SAndreas.Sandberg@ARM.com//functions are provided below. 712735Sktlim@umich.edu 722735Sktlim@umich.educlass MachineCheckFault : public virtual FaultBase 7310319SAndreas.Sandberg@ARM.com{ 7410319SAndreas.Sandberg@ARM.com private: 7510319SAndreas.Sandberg@ARM.com static FaultName _name; 7610319SAndreas.Sandberg@ARM.com public: 7710319SAndreas.Sandberg@ARM.com FaultName name() {return _name;} 7810319SAndreas.Sandberg@ARM.com bool isMachineCheckFault() {return true;} 7910319SAndreas.Sandberg@ARM.com}; 8010319SAndreas.Sandberg@ARM.com 8110319SAndreas.Sandberg@ARM.comclass AlignmentFault : public virtual FaultBase 8210319SAndreas.Sandberg@ARM.com{ 8310319SAndreas.Sandberg@ARM.com private: 8410319SAndreas.Sandberg@ARM.com static FaultName _name; 8510319SAndreas.Sandberg@ARM.com public: 8610319SAndreas.Sandberg@ARM.com FaultName name() {return _name;} 8710319SAndreas.Sandberg@ARM.com bool isAlignmentFault() {return true;} 882735Sktlim@umich.edu}; 892735Sktlim@umich.edu 9010319SAndreas.Sandberg@ARM.com 9110319SAndreas.Sandberg@ARM.com#endif // __FAULTS_HH__ 9210319SAndreas.Sandberg@ARM.com