faults.hh revision 8545
16166Ssteve.reinhardt@amd.com/*
26166Ssteve.reinhardt@amd.com * Copyright (c) 2003-2005 The Regents of The University of Michigan
36166Ssteve.reinhardt@amd.com * All rights reserved.
46166Ssteve.reinhardt@amd.com *
56166Ssteve.reinhardt@amd.com * Redistribution and use in source and binary forms, with or without
66166Ssteve.reinhardt@amd.com * modification, are permitted provided that the following conditions are
76166Ssteve.reinhardt@amd.com * met: redistributions of source code must retain the above copyright
86166Ssteve.reinhardt@amd.com * notice, this list of conditions and the following disclaimer;
96166Ssteve.reinhardt@amd.com * redistributions in binary form must reproduce the above copyright
106166Ssteve.reinhardt@amd.com * notice, this list of conditions and the following disclaimer in the
116166Ssteve.reinhardt@amd.com * documentation and/or other materials provided with the distribution;
126166Ssteve.reinhardt@amd.com * neither the name of the copyright holders nor the names of its
136166Ssteve.reinhardt@amd.com * contributors may be used to endorse or promote products derived from
146166Ssteve.reinhardt@amd.com * this software without specific prior written permission.
156166Ssteve.reinhardt@amd.com *
166166Ssteve.reinhardt@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176166Ssteve.reinhardt@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186166Ssteve.reinhardt@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196166Ssteve.reinhardt@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206166Ssteve.reinhardt@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216166Ssteve.reinhardt@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226166Ssteve.reinhardt@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236166Ssteve.reinhardt@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246166Ssteve.reinhardt@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256166Ssteve.reinhardt@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266166Ssteve.reinhardt@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276166Ssteve.reinhardt@amd.com *
286166Ssteve.reinhardt@amd.com * Authors: Nathan Binkert
296166Ssteve.reinhardt@amd.com *          Gabe Black
306166Ssteve.reinhardt@amd.com */
316166Ssteve.reinhardt@amd.com
326166Ssteve.reinhardt@amd.com#ifndef __FAULTS_HH__
336166Ssteve.reinhardt@amd.com#define __FAULTS_HH__
346166Ssteve.reinhardt@amd.com
356166Ssteve.reinhardt@amd.com#include "base/refcnt.hh"
366166Ssteve.reinhardt@amd.com#include "base/types.hh"
376289Snate@binkert.org#include "config/full_system.hh"
386289Snate@binkert.org#include "cpu/static_inst.hh"
396289Snate@binkert.org#include "sim/fault_fwd.hh"
406166Ssteve.reinhardt@amd.com#include "sim/stats.hh"
416166Ssteve.reinhardt@amd.com
426289Snate@binkert.orgclass ThreadContext;
436166Ssteve.reinhardt@amd.com
446166Ssteve.reinhardt@amd.comtypedef const char * FaultName;
456166Ssteve.reinhardt@amd.comtypedef Stats::Scalar FaultStat;
466166Ssteve.reinhardt@amd.com
476166Ssteve.reinhardt@amd.com// Each class has it's name statically define in _name,
486166Ssteve.reinhardt@amd.com// and has a virtual function to access it's name.
496166Ssteve.reinhardt@amd.com// The function is necessary because otherwise, all objects
506166Ssteve.reinhardt@amd.com// which are being accessed cast as a FaultBase * (namely
516166Ssteve.reinhardt@amd.com// all faults returned using the Fault type) will use the
526166Ssteve.reinhardt@amd.com// generic FaultBase name.
536166Ssteve.reinhardt@amd.com
546166Ssteve.reinhardt@amd.comclass FaultBase : public RefCounted
556166Ssteve.reinhardt@amd.com{
566166Ssteve.reinhardt@amd.com  public:
57    virtual FaultName name() const = 0;
58    virtual void invoke(ThreadContext * tc,
59            StaticInstPtr inst = StaticInst::nullStaticInstPtr);
60    virtual bool isMachineCheckFault() const {return false;}
61    virtual bool isAlignmentFault() const {return false;}
62};
63
64class UnimpFault : public FaultBase
65{
66  private:
67    std::string panicStr;
68  public:
69    UnimpFault(std::string _str)
70        : panicStr(_str)
71    { }
72
73    FaultName name() const {return "Unimplemented simulator feature";}
74    void invoke(ThreadContext * tc,
75            StaticInstPtr inst = StaticInst::nullStaticInstPtr);
76};
77
78class ReExec : public FaultBase
79{
80  public:
81    virtual FaultName name() const { return "Re-execution fault";}
82    ReExec() {}
83    void invoke(ThreadContext *tc,
84            StaticInstPtr inst = StaticInst::nullStaticInstPtr);
85};
86
87
88#if !FULL_SYSTEM
89class GenericPageTableFault : public FaultBase
90{
91  private:
92    Addr vaddr;
93  public:
94    FaultName name() const {return "Generic page table fault";}
95    GenericPageTableFault(Addr va) : vaddr(va) {}
96    void invoke(ThreadContext * tc,
97            StaticInstPtr inst = StaticInst::nullStaticInstPtr);
98};
99
100class GenericAlignmentFault : public FaultBase
101{
102  private:
103    Addr vaddr;
104  public:
105    FaultName name() const {return "Generic alignment fault";}
106    GenericAlignmentFault(Addr va) : vaddr(va) {}
107    void invoke(ThreadContext * tc,
108            StaticInstPtr inst = StaticInst::nullStaticInstPtr);
109};
110#endif
111
112#endif // __FAULTS_HH__
113