gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/static_inst.hh"
46 #include "cpu/thread_context.hh"
47 #include "sim/faults.hh"
48 
49 namespace gem5
50 {
51 
52 namespace GenericISA
53 {
54 
55 class M5DebugFault : public FaultBase
56 {
57  protected:
58  std::string _message;
59  virtual void debugFunc() = 0;
60  void
62  {
63  if (inst) {
64  std::unique_ptr<PCStateBase> pc(tc->pcState().clone());
65  inst->advancePC(*pc);
66  tc->pcState(*pc);
67  }
68  }
69 
70  public:
71  M5DebugFault(std::string _m) : _message(_m) {}
72 
73  template <class ...Args>
74  M5DebugFault(const std::string &format, const Args &...args) :
75  _message(csprintf(format, args...))
76  {}
77 
78  std::string message() { return _message; }
79 
80  void
81  invoke(ThreadContext *tc, const StaticInstPtr &inst =
82  nullStaticInstPtr) override
83  {
84  debugFunc();
85  advancePC(tc, inst);
86  }
87 };
88 
89 // The "Flavor" template parameter is to keep warn, hack or inform messages
90 // with the same token from blocking each other.
91 template <class Flavor>
93 {
94  protected:
95  bool &once;
96 
97  template <class F, class OnceToken>
98  static bool &
99  lookUpToken(const OnceToken &token)
100  {
101  static std::map<OnceToken, bool> tokenMap;
102  return tokenMap[token];
103  }
104 
105  public:
106  template <class OnceToken, class ...Args>
107  M5DebugOnceFault(const OnceToken &token, const std::string &format,
108  const Args &...args) :
109  M5DebugFault(format, args...), once(lookUpToken<Flavor>(token))
110  {}
111 
112  void
113  invoke(ThreadContext *tc, const StaticInstPtr &inst =
114  nullStaticInstPtr) override
115  {
116  if (!once) {
117  once = true;
118  debugFunc();
119  }
120  advancePC(tc, inst);
121  }
122 };
123 
125 {
126  public:
128  void debugFunc() override { panic(message()); }
129  FaultName name() const override { return "panic fault"; }
130 };
131 
133 {
134  public:
136  void debugFunc() override { fatal(message()); }
137  FaultName name() const override { return "fatal fault"; }
138 };
139 
140 template <class Base>
141 class M5WarnFaultBase : public Base
142 {
143  public:
144  using Base::Base;
145  void debugFunc() override { warn(this->message()); }
146  FaultName name() const override { return "warn fault"; }
147 };
148 
151 
152 template <class Base>
153 class M5HackFaultBase : public Base
154 {
155  public:
156  using Base::Base;
157  void debugFunc() override { hack(this->message()); }
158  FaultName name() const override { return "hack fault"; }
159 };
160 
163 
164 template <class Base>
165 class M5InformFaultBase : public Base
166 {
167  public:
168  using Base::Base;
169  void debugFunc() override { inform(this->message()); }
170  FaultName name() const override { return "inform fault"; }
171 };
172 
174 using M5InformOnceFault =
176 
177 } // namespace GenericISA
178 } // namespace gem5
179 
180 #endif // __ARCH_GENERIC_DEBUGFAULTS_HH__
fatal
#define fatal(...)
This implements a cprintf based fatal() function.
Definition: logging.hh:200
gem5::GenericISA::M5HackFaultBase
Definition: debugfaults.hh:153
gem5::GenericISA::M5DebugFault::M5DebugFault
M5DebugFault(const std::string &format, const Args &...args)
Definition: debugfaults.hh:74
warn
#define warn(...)
Definition: logging.hh:256
gem5::ArmISA::format
Bitfield< 31, 29 > format
Definition: misc_types.hh:704
gem5::GenericISA::M5DebugOnceFault::once
bool & once
Definition: debugfaults.hh:95
gem5::GenericISA::M5PanicFault::name
FaultName name() const override
Definition: debugfaults.hh:129
gem5::GenericISA::M5DebugOnceFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition: debugfaults.hh:113
gem5::GenericISA::M5DebugFault
Definition: debugfaults.hh:55
gem5::ThreadContext::pcState
virtual const PCStateBase & pcState() const =0
gem5::GenericISA::M5PanicFault
Definition: debugfaults.hh:124
gem5::GenericISA::M5FatalFault::name
FaultName name() const override
Definition: debugfaults.hh:137
gem5::GenericISA::M5DebugFault::invoke
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
Definition: debugfaults.hh:81
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:169
gem5::scmi::token
token
Definition: scmi_platform.hh:80
gem5::GenericISA::M5InformFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:170
gem5::StaticInst::advancePC
virtual void advancePC(PCStateBase &pc_state) const =0
hack
#define hack(...)
Definition: logging.hh:258
gem5::GenericISA::M5DebugOnceFault::lookUpToken
static bool & lookUpToken(const OnceToken &token)
Definition: debugfaults.hh:99
gem5::GenericISA::M5WarnFaultBase
Definition: debugfaults.hh:141
gem5::RefCountingPtr< StaticInst >
gem5::GenericISA::M5FatalFault
Definition: debugfaults.hh:132
gem5::auxv::Base
@ Base
Definition: aux_vector.hh:74
gem5::GenericISA::M5DebugFault::_message
std::string _message
Definition: debugfaults.hh:58
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:71
gem5::GenericISA::M5FatalFault::debugFunc
void debugFunc() override
Definition: debugfaults.hh:136
gem5::GenericISA::M5DebugFault::message
std::string message()
Definition: debugfaults.hh:78
gem5::ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
gem5::GenericISA::M5PanicFault::debugFunc
void debugFunc() override
Definition: debugfaults.hh:128
gem5::GenericISA::M5WarnFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:145
static_inst.hh
null_static_inst.hh
gem5::GenericISA::M5DebugOnceFault::M5DebugOnceFault
M5DebugOnceFault(const OnceToken &token, const std::string &format, const Args &...args)
Definition: debugfaults.hh:107
gem5::FaultName
const typedef char * FaultName
Definition: faults.hh:53
gem5::GenericISA::M5HackFaultBase::debugFunc
void debugFunc() override
Definition: debugfaults.hh:157
inform
#define inform(...)
Definition: logging.hh:257
gem5::GenericISA::M5DebugFault::debugFunc
virtual void debugFunc()=0
gem5::GenericISA::M5DebugFault::advancePC
void advancePC(ThreadContext *tc, const StaticInstPtr &inst)
Definition: debugfaults.hh:61
gem5::FaultBase
Definition: translation_gen.test.cc:49
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: gpu_translation_state.hh:37
thread_context.hh
gem5::GenericISA::M5InformFaultBase
Definition: debugfaults.hh:165
gem5::GenericISA::M5HackFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:158
gem5::PCStateBase::clone
virtual PCStateBase * clone() const =0
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::GenericISA::M5WarnFaultBase::name
FaultName name() const override
Definition: debugfaults.hh:146
gem5::GenericISA::M5DebugOnceFault
Definition: debugfaults.hh:92

Generated on Sun Jul 30 2023 01:56:50 for gem5 by doxygen 1.8.17