gem5 v24.0.0.0
Loading...
Searching...
No Matches
insttracer.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014, 2017, 2020, 2023 Arm Limited
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 * Copyright (c) 2001-2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __INSTRECORD_HH__
42#define __INSTRECORD_HH__
43
44#include <memory>
45
47#include "base/types.hh"
48#include "cpu/inst_res.hh"
49#include "cpu/inst_seq.hh"
50#include "cpu/static_inst.hh"
51#include "params/InstTracer.hh"
52#include "sim/sim_object.hh"
53
54namespace gem5
55{
56
57class ThreadContext;
58
59namespace trace {
60
62{
63 protected:
65
66 // The following fields are initialized by the constructor and
67 // thus guaranteed to be valid.
69 // need to make this ref-counted so it doesn't go away before we
70 // dump the record
72 std::unique_ptr<PCStateBase> pc;
74
75 // The remaining fields are only valid for particular instruction
76 // types (e.g, addresses for memory ops) or when particular
77 // options are enabled (e.g., tracing full register contents).
78 // Each data field has an associated valid flag to indicate
79 // whether the data field is valid.
80
81 /*** @defgroup mem
82 * @{
83 * Memory request information in the instruction accessed memory.
84 * @see mem_valid
85 */
86 Addr addr = 0;
87 Addr size = 0;
88 unsigned flags = 0;
89
100 union Data
101 {
102 ~Data() {}
103 Data() {}
104 uint64_t asInt = 0;
105 double asDouble;
108
114
120
125 {
127 DataInt8 = 1, // set to equal number of bytes
132 DataReg = 5
134
138 bool mem_valid = false;
139
143 bool fetch_seq_valid = false;
147 bool cp_seq_valid = false;
148
151 bool predicate = true;
152
157 bool faulting = false;
158
159 public:
161 const StaticInstPtr _staticInst, const PCStateBase &_pc,
162 const StaticInstPtr _macroStaticInst=nullptr)
163 : when(_when), thread(_thread), staticInst(_staticInst),
164 pc(_pc.clone()), macroStaticInst(_macroStaticInst)
165 {}
166
167 virtual ~InstRecord()
168 {
169 if (dataStatus == DataReg)
170 data.asReg.~InstResult();
171 }
172
173 void setWhen(Tick new_when) { when = new_when; }
174 void
175 setMem(Addr a, Addr s, unsigned f)
176 {
177 addr = a;
178 size = s;
179 flags = f;
180 mem_valid = true;
181 }
182
183 template <typename T, size_t N>
184 void
185 setData(std::array<T, N> d)
186 {
187 data.asInt = d[0];
188 dataStatus = (DataStatus)sizeof(T);
189 static_assert(sizeof(T) == DataInt8 || sizeof(T) == DataInt16 ||
190 sizeof(T) == DataInt32 || sizeof(T) == DataInt64,
191 "Type T has an unrecognized size.");
192 }
193
194 void
195 setData(uint64_t d)
196 {
197 data.asInt = d;
199 }
200 void
201 setData(uint32_t d)
202 {
203 data.asInt = d;
205 }
206 void
207 setData(uint16_t d)
208 {
209 data.asInt = d;
211 }
212 void
213 setData(uint8_t d)
214 {
215 data.asInt = d;
217 }
218
219 void setData(int64_t d) { setData((uint64_t)d); }
220 void setData(int32_t d) { setData((uint32_t)d); }
221 void setData(int16_t d) { setData((uint16_t)d); }
222 void setData(int8_t d) { setData((uint8_t)d); }
223
224 void
225 setData(double d)
226 {
227 data.asDouble = d;
229 }
230
231 void
232 setData(const RegClass &reg_class, RegVal val)
233 {
234 new(&data.asReg) InstResult(reg_class, val);
235 switch (reg_class.type()) {
236 case IntRegClass:
237 case MiscRegClass:
238 case CCRegClass:
240 break;
241 case FloatRegClass:
243 break;
244 default:
246 break;
247 }
248 }
249
250 void
251 setData(const RegClass &reg_class, const void *val)
252 {
253 new(&data.asReg) InstResult(reg_class, val);
254 switch (reg_class.type()) {
255 case IntRegClass:
256 case MiscRegClass:
257 case CCRegClass:
259 break;
260 case FloatRegClass:
262 break;
263 default:
265 break;
266 }
267 }
268
269 void
271 {
272 fetch_seq = seq;
273 fetch_seq_valid = true;
274 }
275
276 void
278 {
279 cp_seq = seq;
280 cp_seq_valid = true;
281 }
282
283 void setPredicate(bool val) { predicate = val; }
284
285 void setFaulting(bool val) { faulting = val; }
286
287 virtual void dump() = 0;
288
289 public:
290 Tick getWhen() const { return when; }
291 ThreadContext *getThread() const { return thread; }
293 const PCStateBase &getPCState() const { return *pc; }
295
296 Addr getAddr() const { return addr; }
297 Addr getSize() const { return size; }
298 unsigned getFlags() const { return flags; }
299 bool getMemValid() const { return mem_valid; }
300
301 uint64_t getIntData() const { return data.asInt; }
302 double getFloatData() const { return data.asDouble; }
303 int getDataStatus() const { return dataStatus; }
304
305 InstSeqNum getFetchSeq() const { return fetch_seq; }
306 bool getFetchSeqValid() const { return fetch_seq_valid; }
307
308 InstSeqNum getCpSeq() const { return cp_seq; }
309 bool getCpSeqValid() const { return cp_seq_valid; }
310
311 bool getFaulting() const { return faulting; }
312};
313
323{
324 public:
325 InstDisassembler(const SimObjectParams &params)
327 {}
328
329 virtual std::string
331 const PCStateBase &pc,
332 const loader::SymbolTable *symtab) const
333 {
334 return inst->disassemble(pc.instAddr(), symtab);
335 }
336};
337
338class InstTracer : public SimObject
339{
340 public:
345
346 virtual ~InstTracer() {}
347
348 virtual InstRecord *
350 const StaticInstPtr staticInst, const PCStateBase &pc,
351 const StaticInstPtr macroStaticInst=nullptr) = 0;
352
353 std::string
355 const PCStateBase &pc,
356 const loader::SymbolTable *symtab=nullptr) const
357 {
358 return disassembler->disassemble(inst, pc, symtab);
359 }
360
361 private:
363};
364
365} // namespace trace
366} // namespace gem5
367
368#endif // __INSTRECORD_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
constexpr RegClassType type() const
Definition reg_class.hh:236
Abstract superclass for simulation objects.
SimObjectParams Params
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
The base InstDisassembler class provides a one-API interface to disassemble the instruction passed as...
InstDisassembler(const SimObjectParams &params)
virtual std::string disassemble(StaticInstPtr inst, const PCStateBase &pc, const loader::SymbolTable *symtab) const
void setData(const RegClass &reg_class, RegVal val)
unsigned getFlags() const
void setData(int64_t d)
void setFaulting(bool val)
void setData(double d)
bool getCpSeqValid() const
Addr addr
The address that was accessed.
Definition insttracer.hh:86
void setData(uint32_t d)
InstSeqNum getFetchSeq() const
bool faulting
Did the execution of this instruction fault? (requires ExecFaulting to be enabled)
StaticInstPtr staticInst
Definition insttracer.hh:71
InstSeqNum getCpSeq() const
void setData(uint64_t d)
void setCPSeq(InstSeqNum seq)
InstRecord(Tick _when, ThreadContext *_thread, const StaticInstPtr _staticInst, const PCStateBase &_pc, const StaticInstPtr _macroStaticInst=nullptr)
void setMem(Addr a, Addr s, unsigned f)
StaticInstPtr getMacroStaticInst() const
StaticInstPtr macroStaticInst
Definition insttracer.hh:73
void setData(int32_t d)
void setFetchSeq(InstSeqNum seq)
void setData(int16_t d)
ThreadContext * thread
Definition insttracer.hh:68
unsigned flags
The flags that were assigned to the request.
Definition insttracer.hh:88
std::unique_ptr< PCStateBase > pc
Definition insttracer.hh:72
ThreadContext * getThread() const
bool getFetchSeqValid() const
uint64_t getIntData() const
const PCStateBase & getPCState() const
virtual void dump()=0
bool predicate
is the predicate for execution this inst true or false (not execed)?
void setPredicate(bool val)
union gem5::trace::InstRecord::Data data
void setData(uint8_t d)
double getFloatData() const
void setData(std::array< T, N > d)
void setData(uint16_t d)
StaticInstPtr getStaticInst() const
void setData(int8_t d)
Addr size
The size of the memory request.
Definition insttracer.hh:87
void setData(const RegClass &reg_class, const void *val)
void setWhen(Tick new_when)
InstTracer(const Params &p)
virtual InstRecord * getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst, const PCStateBase &pc, const StaticInstPtr macroStaticInst=nullptr)=0
std::string disassemble(StaticInstPtr inst, const PCStateBase &pc, const loader::SymbolTable *symtab=nullptr) const
InstDisassembler * disassembler
const Params & params() const
bool cp_seq_valid
Are the commit sequence number fields valid?
DataStatus
What size of data was written?
enum gem5::trace::InstRecord::DataStatus dataStatus
bool fetch_seq_valid
Are the fetch sequence number fields valid?
bool mem_valid
Are the memory fields in the record valid?
Bitfield< 4 > s
Bitfield< 8 > a
Definition misc_types.hh:66
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 9 > d
Definition misc_types.hh:64
Bitfield< 4 > pc
Bitfield< 0 > p
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t RegVal
Definition types.hh:173
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint64_t Tick
Tick count type.
Definition types.hh:58
uint64_t InstSeqNum
Definition inst_seq.hh:40
@ FloatRegClass
Floating-point register.
Definition reg_class.hh:62
@ CCRegClass
Condition-code register.
Definition reg_class.hh:69
@ IntRegClass
Integer register.
Definition reg_class.hh:61
@ MiscRegClass
Control (misc) register.
Definition reg_class.hh:70

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0