debugfaults.hh revision 14277
17965Sgblack@eecs.umich.edu/* 28332Snate@binkert.org * Copyright (c) 2010 Advanced Micro Devices, Inc. 37965Sgblack@eecs.umich.edu * All rights reserved. 47965Sgblack@eecs.umich.edu * 57965Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 67965Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 77965Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 87965Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 97965Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 107965Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 117965Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 127965Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 137965Sgblack@eecs.umich.edu * 147965Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 157965Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 167965Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 177965Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 187965Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 197965Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 207965Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 217965Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 227965Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 237965Sgblack@eecs.umich.edu * this software without specific prior written permission. 247965Sgblack@eecs.umich.edu * 257965Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 267965Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 277965Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 287965Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 297965Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 307965Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 317965Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 327965Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 337965Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 347965Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 357965Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 367965Sgblack@eecs.umich.edu * 377965Sgblack@eecs.umich.edu * Authors: Gabe Black 387965Sgblack@eecs.umich.edu */ 397965Sgblack@eecs.umich.edu 407965Sgblack@eecs.umich.edu#ifndef __ARCH_GENERIC_DEBUGFAULTS_HH__ 417965Sgblack@eecs.umich.edu#define __ARCH_GENERIC_DEBUGFAULTS_HH__ 427965Sgblack@eecs.umich.edu 438229Snate@binkert.org#include <string> 448229Snate@binkert.org 4512334Sgabeblack@google.com#include "base/logging.hh" 467965Sgblack@eecs.umich.edu#include "sim/faults.hh" 477965Sgblack@eecs.umich.edu 487965Sgblack@eecs.umich.edunamespace GenericISA 497965Sgblack@eecs.umich.edu{ 508590Sgblack@eecs.umich.edu 517965Sgblack@eecs.umich.educlass M5DebugFault : public FaultBase 527965Sgblack@eecs.umich.edu{ 5314277Sgabeblack@google.com protected: 5414277Sgabeblack@google.com std::string _message; 5514277Sgabeblack@google.com virtual void debugFunc() = 0; 5614277Sgabeblack@google.com void 5714277Sgabeblack@google.com advancePC(ThreadContext *tc, const StaticInstPtr &inst) 587965Sgblack@eecs.umich.edu { 5914277Sgabeblack@google.com if (inst) { 6014277Sgabeblack@google.com auto pc = tc->pcState(); 6114277Sgabeblack@google.com inst->advancePC(pc); 6214277Sgabeblack@google.com tc->pcState(pc); 637965Sgblack@eecs.umich.edu } 647965Sgblack@eecs.umich.edu } 657965Sgblack@eecs.umich.edu 6614277Sgabeblack@google.com public: 6714277Sgabeblack@google.com M5DebugFault(std::string _m) : _message(_m) {} 6814277Sgabeblack@google.com 6914277Sgabeblack@google.com template <class ...Args> 7014277Sgabeblack@google.com M5DebugFault(const std::string &format, const Args &...args) : 7114277Sgabeblack@google.com _message(csprintf(format, args...)) 7214277Sgabeblack@google.com {} 7314277Sgabeblack@google.com 7414277Sgabeblack@google.com std::string message() { return _message; } 7514277Sgabeblack@google.com 767965Sgblack@eecs.umich.edu void 7710417Sandreas.hansson@arm.com invoke(ThreadContext *tc, const StaticInstPtr &inst = 7814277Sgabeblack@google.com StaticInst::nullStaticInstPtr) override 797965Sgblack@eecs.umich.edu { 8014277Sgabeblack@google.com debugFunc(); 8114277Sgabeblack@google.com advancePC(tc, inst); 827965Sgblack@eecs.umich.edu } 837965Sgblack@eecs.umich.edu}; 848590Sgblack@eecs.umich.edu 8514277Sgabeblack@google.com// The "Flavor" template parameter is to keep warn, hack or inform messages 8614277Sgabeblack@google.com// with the same token from blocking each other. 8714277Sgabeblack@google.comtemplate <class Flavor> 8814277Sgabeblack@google.comclass M5DebugOnceFault : public M5DebugFault 8914277Sgabeblack@google.com{ 9014277Sgabeblack@google.com protected: 9114277Sgabeblack@google.com bool &once; 9214277Sgabeblack@google.com 9314277Sgabeblack@google.com template <class F, class OnceToken> 9414277Sgabeblack@google.com static bool & 9514277Sgabeblack@google.com lookUpToken(const OnceToken &token) 9614277Sgabeblack@google.com { 9714277Sgabeblack@google.com static std::map<OnceToken, bool> tokenMap; 9814277Sgabeblack@google.com return tokenMap[token]; 9914277Sgabeblack@google.com } 10014277Sgabeblack@google.com 10114277Sgabeblack@google.com public: 10214277Sgabeblack@google.com template <class OnceToken, class ...Args> 10314277Sgabeblack@google.com M5DebugOnceFault(const OnceToken &token, const std::string &format, 10414277Sgabeblack@google.com const Args &...args) : 10514277Sgabeblack@google.com M5DebugFault(format, args...), once(lookUpToken<Flavor>(token)) 10614277Sgabeblack@google.com {} 10714277Sgabeblack@google.com 10814277Sgabeblack@google.com void 10914277Sgabeblack@google.com invoke(ThreadContext *tc, const StaticInstPtr &inst = 11014277Sgabeblack@google.com StaticInst::nullStaticInstPtr) override 11114277Sgabeblack@google.com { 11214277Sgabeblack@google.com if (!once) { 11314277Sgabeblack@google.com once = true; 11414277Sgabeblack@google.com debugFunc(); 11514277Sgabeblack@google.com } 11614277Sgabeblack@google.com advancePC(tc, inst); 11714277Sgabeblack@google.com } 11814277Sgabeblack@google.com}; 11914277Sgabeblack@google.com 12014277Sgabeblack@google.comclass M5PanicFault : public M5DebugFault 1218590Sgblack@eecs.umich.edu{ 1228590Sgblack@eecs.umich.edu public: 12314277Sgabeblack@google.com using M5DebugFault::M5DebugFault; 12414277Sgabeblack@google.com void debugFunc() override { panic(message()); } 12514277Sgabeblack@google.com FaultName name() const override { return "panic fault"; } 1268590Sgblack@eecs.umich.edu}; 1278590Sgblack@eecs.umich.edu 12814277Sgabeblack@google.comclass M5FatalFault : public M5DebugFault 12914277Sgabeblack@google.com{ 13014277Sgabeblack@google.com public: 13114277Sgabeblack@google.com using M5DebugFault::M5DebugFault; 13214277Sgabeblack@google.com void debugFunc() override { fatal(message()); } 13314277Sgabeblack@google.com FaultName name() const override { return "fatal fault"; } 13414277Sgabeblack@google.com}; 13514277Sgabeblack@google.com 13614277Sgabeblack@google.comtemplate <class Base> 13714277Sgabeblack@google.comclass M5WarnFaultBase : public Base 13814277Sgabeblack@google.com{ 13914277Sgabeblack@google.com public: 14014277Sgabeblack@google.com using Base::Base; 14114277Sgabeblack@google.com void debugFunc() override { warn(this->message()); } 14214277Sgabeblack@google.com FaultName name() const override { return "warn fault"; } 14314277Sgabeblack@google.com}; 14414277Sgabeblack@google.com 14514277Sgabeblack@google.comusing M5WarnFault = M5WarnFaultBase<M5DebugFault>; 14614277Sgabeblack@google.comusing M5WarnOnceFault = M5WarnFaultBase<M5DebugOnceFault<M5WarnFault>>; 14714277Sgabeblack@google.com 14814277Sgabeblack@google.comtemplate <class Base> 14914277Sgabeblack@google.comclass M5HackFaultBase : public Base 15014277Sgabeblack@google.com{ 15114277Sgabeblack@google.com public: 15214277Sgabeblack@google.com using Base::Base; 15314277Sgabeblack@google.com void debugFunc() override { hack(this->message()); } 15414277Sgabeblack@google.com FaultName name() const override { return "hack fault"; } 15514277Sgabeblack@google.com}; 15614277Sgabeblack@google.com 15714277Sgabeblack@google.comusing M5HackFault = M5HackFaultBase<M5DebugFault>; 15814277Sgabeblack@google.comusing M5HackOnceFault = M5HackFaultBase<M5DebugOnceFault<M5HackFault>>; 15914277Sgabeblack@google.com 16014277Sgabeblack@google.comtemplate <class Base> 16114277Sgabeblack@google.comclass M5InformFaultBase : public Base 16214277Sgabeblack@google.com{ 16314277Sgabeblack@google.com public: 16414277Sgabeblack@google.com using Base::Base; 16514277Sgabeblack@google.com void debugFunc() override { inform(this->message()); } 16614277Sgabeblack@google.com FaultName name() const override { return "inform fault"; } 16714277Sgabeblack@google.com}; 16814277Sgabeblack@google.com 16914277Sgabeblack@google.comusing M5InformFault = M5InformFaultBase<M5DebugFault>; 17014277Sgabeblack@google.comusing M5InformOnceFault = 17114277Sgabeblack@google.com M5InformFaultBase<M5DebugOnceFault<M5InformFault>>; 1728590Sgblack@eecs.umich.edu 1737965Sgblack@eecs.umich.edu} // namespace GenericISA 1747965Sgblack@eecs.umich.edu 1757965Sgblack@eecs.umich.edu#endif // __ARCH_GENERIC_DEBUGFAULTS_HH__ 176