gem5  v21.1.0.2
debugfaults.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 Advanced Micro Devices, Inc.
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __ARCH_GENERIC_DEBUGFAULTS_HH__
39 #define __ARCH_GENERIC_DEBUGFAULTS_HH__
40 
41 #include <string>
42 
43 #include "base/logging.hh"
44 #include "cpu/null_static_inst.hh"
45 #include "cpu/thread_context.hh"
46 #include "sim/faults.hh"
47 
48 namespace gem5
49 {
50 
51 namespace GenericISA
52 {
53 
54 class M5DebugFault : public FaultBase
55 {
56  protected:
57  std::string _message;
58  virtual void debugFunc() = 0;
59  void
61  {
62  if (inst) {
63  auto pc = tc->pcState();
64  inst->advancePC(pc);
65  tc->pcState(pc);
66  }
67  }
68 
69  public:
70  M5DebugFault(std::string _m) : _message(_m) {}
71 
72  template <class ...Args>
73  M5DebugFault(const std::string &format, const Args &...args) :
74  _message(csprintf(format, args...))
75  {}
76 
77  std::string message() { return _message; }
78 
79  void
80  invoke(ThreadContext *tc, const StaticInstPtr &inst =
81  nullStaticInstPtr) override
82  {
83  debugFunc();
84  advancePC(tc, inst);
85  }
86 };
87 
88 // The "Flavor" template parameter is to keep warn, hack or inform messages
89 // with the same token from blocking each other.
90 template <class Flavor>
92 {
93  protected:
94  bool &once;
95 
96  template <class F, class OnceToken>
97  static bool &
98  lookUpToken(const OnceToken &token)
99  {
100  static std::map<OnceToken, bool> tokenMap;
101  return tokenMap[token];
102  }
103 
104  public:
105  template <class OnceToken, class ...Args>
106  M5DebugOnceFault(const OnceToken &token, const std::string &format,
107  const Args &...args) :
108  M5DebugFault(format, args...), once(lookUpToken<Flavor>(token))
109  {}
110 
111  void
112  invoke(ThreadContext *tc, const StaticInstPtr &inst =
113  nullStaticInstPtr) override
114  {
115  if (!once) {
116  once = true;
117  debugFunc();
118  }
119  advancePC(tc, inst);
120  }
121 };
122 
124 {
125  public:
127  void debugFunc() override { panic(message()); }
128  FaultName name() const override { return "panic fault"; }
129 };
130 
132 {
133  public:
135  void debugFunc() override { fatal(message()); }
136  FaultName name() const override { return "fatal fault"; }
137 };
138 
139 template <class Base>
140 class M5WarnFaultBase : public Base
141 {
142  public:
143  using Base::Base;
144  void debugFunc() override { warn(this->message()); }
145  FaultName name() const override { return "warn fault"; }
146 };
147 
150 
151 template <class Base>
152 class M5HackFaultBase : public Base
153 {
154  public:
155  using Base::Base;
156  void debugFunc() override { hack(this->message()); }
157  FaultName name() const override { return "hack fault"; }
158 };
159 
162 
163 template <class Base>
164 class M5InformFaultBase : public Base
165 {
166  public:
167  using Base::Base;
168  void debugFunc() override { inform(this->message()); }
169  FaultName name() const override { return "inform fault"; }
170 };
171 
173 using M5InformOnceFault =
175 
176 } // namespace GenericISA
177 } // namespace gem5
178 
179 #endif // __ARCH_GENERIC_DEBUGFAULTS_HH__
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:189
gem5::GenericISA::M5HackFaultBase
Definition: debugfaults.hh:152
gem5::GenericISA::M5DebugFault::M5DebugFault
M5DebugFault(const std::string &format, const Args &...args)
Definition: debugfaults.hh:73
warn
#define warn(...)
Definition: logging.hh:245
gem5::ArmISA::format
Bitfield< 31, 29 > format
Definition: misc_types.hh:646
gem5::GenericISA::M5DebugOnceFault::once
bool & once
Definition: debugfaults.hh:94
gem5::GenericISA::M5PanicFault::name
FaultName name() const override
Definition: debugfaults.hh:128
gem5::GenericISA::M5DebugOnceFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition: debugfaults.hh:112
gem5::GenericISA::M5DebugFault
Definition: debugfaults.hh:54
gem5::GenericISA::M5PanicFault
Definition: debugfaults.hh:123
gem5::GenericISA::M5FatalFault::name
FaultName name() const override
Definition: debugfaults.hh:136
gem5::GenericISA::M5DebugFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition: debugfaults.hh:80
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
faults.hh
gem5::GenericISA::M5InformFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:168
gem5::scmi::token
token
Definition: scmi_platform.hh:80
gem5::GenericISA::M5InformFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:169
hack
#define hack(...)
Definition: logging.hh:247
gem5::GenericISA::M5DebugOnceFault::lookUpToken
static bool & lookUpToken(const OnceToken &token)
Definition: debugfaults.hh:98
gem5::GenericISA::M5WarnFaultBase
Definition: debugfaults.hh:140
gem5::RefCountingPtr< StaticInst >
gem5::GenericISA::M5FatalFault
Definition: debugfaults.hh:131
gem5::auxv::Base
@ Base
Definition: aux_vector.hh:76
gem5::GenericISA::M5DebugFault::_message
std::string _message
Definition: debugfaults.hh:57
gem5::nullStaticInstPtr
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.
Definition: null_static_inst.cc:36
gem5::GenericISA::M5DebugFault::M5DebugFault
M5DebugFault(std::string _m)
Definition: debugfaults.hh:70
gem5::GenericISA::M5FatalFault::debugFunc
void debugFunc() override
Definition: debugfaults.hh:135
gem5::GenericISA::M5DebugFault::message
std::string message()
Definition: debugfaults.hh:77
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:93
gem5::GenericISA::M5PanicFault::debugFunc
void debugFunc() override
Definition: debugfaults.hh:127
gem5::GenericISA::M5WarnFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:144
gem5::ThreadContext::pcState
virtual TheISA::PCState pcState() const =0
null_static_inst.hh
gem5::GenericISA::M5DebugOnceFault::M5DebugOnceFault
M5DebugOnceFault(const OnceToken &token, const std::string &format, const Args &...args)
Definition: debugfaults.hh:106
gem5::FaultName
const typedef char * FaultName
Definition: faults.hh:53
gem5::GenericISA::M5HackFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:156
inform
#define inform(...)
Definition: logging.hh:246
gem5::GenericISA::M5DebugFault::debugFunc
virtual void debugFunc()=0
gem5::GenericISA::M5DebugFault::advancePC
void advancePC(ThreadContext *tc, const StaticInstPtr &inst)
Definition: debugfaults.hh:60
gem5::FaultBase
Definition: faults.hh:58
gem5::MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:243
logging.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
thread_context.hh
gem5::GenericISA::M5InformFaultBase
Definition: debugfaults.hh:164
gem5::GenericISA::M5HackFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:157
gem5::StaticInst::advancePC
virtual void advancePC(TheISA::PCState &pc_state) const =0
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::GenericISA::M5WarnFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:145
gem5::GenericISA::M5DebugOnceFault
Definition: debugfaults.hh:91

Generated on Tue Sep 21 2021 12:24:47 for gem5 by doxygen 1.8.17