debugfaults.hh revision 10417
17405SAli.Saidi@ARM.com/*
212666Sgiacomo.travaglini@arm.com * Copyright (c) 2010 Advanced Micro Devices, Inc.
37405SAli.Saidi@ARM.com * All rights reserved.
47405SAli.Saidi@ARM.com *
57405SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67405SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77405SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87405SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97405SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
107405SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117405SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127405SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137405SAli.Saidi@ARM.com *
147405SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
157405SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
167405SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
177405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
187405SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
197405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
207405SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
217405SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
227405SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
237405SAli.Saidi@ARM.com * this software without specific prior written permission.
247405SAli.Saidi@ARM.com *
257405SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
267405SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
277405SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
287405SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
297405SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
307405SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
317405SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
327405SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
337405SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
347405SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
357405SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367405SAli.Saidi@ARM.com *
377405SAli.Saidi@ARM.com * Authors: Gabe Black
387405SAli.Saidi@ARM.com */
397405SAli.Saidi@ARM.com
407405SAli.Saidi@ARM.com#ifndef __ARCH_GENERIC_DEBUGFAULTS_HH__
417405SAli.Saidi@ARM.com#define __ARCH_GENERIC_DEBUGFAULTS_HH__
4210461SAndreas.Sandberg@ARM.com
439050Schander.sudanthi@arm.com#include <string>
4412406Sgabeblack@google.com
4512605Sgiacomo.travaglini@arm.com#include "base/misc.hh"
4611793Sbrandon.potter@amd.com#include "sim/faults.hh"
478887Sgeoffrey.blake@arm.com
488232Snate@binkert.orgnamespace GenericISA
498232Snate@binkert.org{
5010844Sandreas.sandberg@arm.com
519384SAndreas.Sandberg@arm.comclass M5DebugFault : public FaultBase
527678Sgblack@eecs.umich.edu{
538059SAli.Saidi@ARM.com  public:
548284SAli.Saidi@ARM.com    enum DebugFunc
557405SAli.Saidi@ARM.com    {
567405SAli.Saidi@ARM.com        PanicFunc,
577405SAli.Saidi@ARM.com        FatalFunc,
587405SAli.Saidi@ARM.com        WarnFunc,
599384SAndreas.Sandberg@arm.com        WarnOnceFunc
6010461SAndreas.Sandberg@ARM.com    };
6110461SAndreas.Sandberg@ARM.com
6211165SRekai.GonzalezAlberquilla@arm.com  protected:
6312109SRekai.GonzalezAlberquilla@arm.com    std::string message;
6412479SCurtis.Dunham@arm.com    DebugFunc func;
659384SAndreas.Sandberg@arm.com
6611770SCurtis.Dunham@arm.com  public:
6710037SARM gem5 Developers    M5DebugFault(DebugFunc _func, std::string _message) :
6810461SAndreas.Sandberg@ARM.com        message(_message), func(_func)
6910461SAndreas.Sandberg@ARM.com    {}
7010461SAndreas.Sandberg@ARM.com
7110461SAndreas.Sandberg@ARM.com    FaultName
7210461SAndreas.Sandberg@ARM.com    name() const
7310461SAndreas.Sandberg@ARM.com    {
7410609Sandreas.sandberg@arm.com        switch (func) {
7510609Sandreas.sandberg@arm.com          case PanicFunc:
7610609Sandreas.sandberg@arm.com            return "panic fault";
7710037SARM gem5 Developers          case FatalFunc:
7810037SARM gem5 Developers            return "fatal fault";
7910037SARM gem5 Developers          case WarnFunc:
8010037SARM gem5 Developers            return "warn fault";
8111771SCurtis.Dunham@arm.com          case WarnOnceFunc:
8210037SARM gem5 Developers            return "warn_once fault";
8310037SARM gem5 Developers          default:
8410037SARM gem5 Developers            panic("unrecognized debug function number\n");
8510037SARM gem5 Developers        }
8610037SARM gem5 Developers    }
8710037SARM gem5 Developers
8811771SCurtis.Dunham@arm.com    void
8910037SARM gem5 Developers    invoke(ThreadContext *tc, const StaticInstPtr &inst =
9010037SARM gem5 Developers           StaticInst::nullStaticInstPtr)
9110037SARM gem5 Developers    {
9210037SARM gem5 Developers        switch (func) {
9310037SARM gem5 Developers          case PanicFunc:
9412477SCurtis.Dunham@arm.com            panic(message);
9510037SARM gem5 Developers            break;
9610037SARM gem5 Developers          case FatalFunc:
979384SAndreas.Sandberg@arm.com            fatal(message);
989384SAndreas.Sandberg@arm.com            break;
999384SAndreas.Sandberg@arm.com          case WarnFunc:
10012479SCurtis.Dunham@arm.com            warn(message);
10112479SCurtis.Dunham@arm.com            break;
1029384SAndreas.Sandberg@arm.com          case WarnOnceFunc:
1039384SAndreas.Sandberg@arm.com            warn_once(message);
1049384SAndreas.Sandberg@arm.com            break;
1059384SAndreas.Sandberg@arm.com          default:
1069384SAndreas.Sandberg@arm.com            panic("unrecognized debug function number\n");
1079384SAndreas.Sandberg@arm.com        }
1087427Sgblack@eecs.umich.edu    }
1097427Sgblack@eecs.umich.edu};
1107427Sgblack@eecs.umich.edu
1119385SAndreas.Sandberg@arm.comtemplate <int Func>
1129385SAndreas.Sandberg@arm.comclass M5VarArgsFault : public M5DebugFault
1137427Sgblack@eecs.umich.edu{
1147427Sgblack@eecs.umich.edu  public:
11510037SARM gem5 Developers    template<typename ...Args>
11610037SARM gem5 Developers    M5VarArgsFault(const std::string &format, const Args &...args) :
11710037SARM gem5 Developers        M5DebugFault((DebugFunc)Func, csprintf(format, args...))
11810037SARM gem5 Developers    {}
11910037SARM gem5 Developers};
12010037SARM gem5 Developers
12110037SARM gem5 Developerstypedef M5VarArgsFault<M5DebugFault::PanicFunc> M5PanicFault;
12210037SARM gem5 Developerstypedef M5VarArgsFault<M5DebugFault::FatalFunc> M5FatalFault;
12310037SARM gem5 Developerstypedef M5VarArgsFault<M5DebugFault::WarnFunc> M5WarnFault;
12410037SARM gem5 Developerstypedef M5VarArgsFault<M5DebugFault::WarnOnceFunc> M5WarnOnceFault;
12510037SARM gem5 Developers
12610037SARM gem5 Developers} // namespace GenericISA
12710037SARM gem5 Developers
12810037SARM gem5 Developers#endif // __ARCH_GENERIC_DEBUGFAULTS_HH__
1297427Sgblack@eecs.umich.edu