gem5 v24.0.0.0
Loading...
Searching...
No Matches
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"
45#include "cpu/static_inst.hh"
46#include "cpu/thread_context.hh"
47#include "sim/faults.hh"
48
49namespace gem5
50{
51
52namespace GenericISA
53{
54
55class 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
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.
91template <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
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
140template <class Base>
141class 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
152template <class Base>
153class 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
164template <class Base>
165class 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
176
177} // namespace GenericISA
178} // namespace gem5
179
180#endif // __ARCH_GENERIC_DEBUGFAULTS_HH__
void advancePC(ThreadContext *tc, const StaticInstPtr &inst)
M5DebugFault(const std::string &format, const Args &...args)
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
M5DebugOnceFault(const OnceToken &token, const std::string &format, const Args &...args)
static bool & lookUpToken(const OnceToken &token)
void invoke(ThreadContext *tc, const StaticInstPtr &inst=nullStaticInstPtr) override
FaultName name() const override
FaultName name() const override
FaultName name() const override
FaultName name() const override
FaultName name() const override
virtual PCStateBase * clone() const =0
virtual void advancePC(PCStateBase &pc_state) const =0
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:200
#define hack(...)
Definition logging.hh:258
#define warn(...)
Definition logging.hh:256
#define inform(...)
Definition logging.hh:257
Bitfield< 31, 29 > format
Bitfield< 4 > pc
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
const char * FaultName
Definition faults.hh:55
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0