gem5  v20.1.0.0
insttracer.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, 2017, 2020 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 
45 #include "arch/generic/vec_reg.hh"
46 #include "base/types.hh"
47 #include "cpu/inst_seq.hh"
48 #include "cpu/static_inst.hh"
49 #include "sim/sim_object.hh"
50 
51 class ThreadContext;
52 
53 namespace Trace {
54 
56 {
57  protected:
59 
60  // The following fields are initialized by the constructor and
61  // thus guaranteed to be valid.
63  // need to make this ref-counted so it doesn't go away before we
64  // dump the record
68 
69  // The remaining fields are only valid for particular instruction
70  // types (e.g, addresses for memory ops) or when particular
71  // options are enabled (e.g., tracing full register contents).
72  // Each data field has an associated valid flag to indicate
73  // whether the data field is valid.
74 
75  /*** @defgroup mem
76  * @{
77  * Memory request information in the instruction accessed memory.
78  * @see mem_valid
79  */
82  unsigned flags;
83 
94  union {
95  uint64_t as_int;
96  double as_double;
100  } data;
101 
107 
113 
117  enum DataStatus {
119  DataInt8 = 1, // set to equal number of bytes
124  DataVec = 5,
126  } data_status;
127 
131  bool mem_valid;
132 
141 
144  bool predicate;
145 
150  bool faulting;
151 
152  public:
153  InstRecord(Tick _when, ThreadContext *_thread,
154  const StaticInstPtr _staticInst,
155  TheISA::PCState _pc,
156  const StaticInstPtr _macroStaticInst = NULL)
157  : when(_when), thread(_thread), staticInst(_staticInst), pc(_pc),
158  macroStaticInst(_macroStaticInst), addr(0), size(0), flags(0),
160  fetch_seq_valid(false), cp_seq_valid(false), predicate(true),
161  faulting(false)
162  { }
163 
164  virtual ~InstRecord()
165  {
166  if (data_status == DataVec) {
167  assert(data.as_vec);
168  delete data.as_vec;
169  } else if (data_status == DataVecPred) {
170  assert(data.as_pred);
171  delete data.as_pred;
172  }
173  }
174 
175  void setWhen(Tick new_when) { when = new_when; }
176  void setMem(Addr a, Addr s, unsigned f)
177  {
178  addr = a; size = s; flags = f; mem_valid = true;
179  }
180 
181  template <typename T, size_t N>
182  void
183  setData(std::array<T, N> d)
184  {
185  data.as_int = d[0];
186  data_status = (DataStatus)sizeof(T);
187  static_assert(sizeof(T) == DataInt8 || sizeof(T) == DataInt16 ||
188  sizeof(T) == DataInt32 || sizeof(T) == DataInt64,
189  "Type T has an unrecognized size.");
190  }
191 
192  void setData(uint64_t d) { data.as_int = d; data_status = DataInt64; }
193  void setData(uint32_t d) { data.as_int = d; data_status = DataInt32; }
194  void setData(uint16_t d) { data.as_int = d; data_status = DataInt16; }
195  void setData(uint8_t d) { data.as_int = d; data_status = DataInt8; }
196 
197  void setData(int64_t d) { setData((uint64_t)d); }
198  void setData(int32_t d) { setData((uint32_t)d); }
199  void setData(int16_t d) { setData((uint16_t)d); }
200  void setData(int8_t d) { setData((uint8_t)d); }
201 
202  void setData(double d) { data.as_double = d; data_status = DataDouble; }
203 
204  void
206  {
207  data.as_vec = new ::VecRegContainer<TheISA::VecRegSizeBytes>(d);
209  }
210 
211  void
214  {
218  }
219 
221  { fetch_seq = seq; fetch_seq_valid = true; }
222 
224  { cp_seq = seq; cp_seq_valid = true; }
225 
226  void setPredicate(bool val) { predicate = val; }
227 
228  void setFaulting(bool val) { faulting = val; }
229 
230  virtual void dump() = 0;
231 
232  public:
233  Tick getWhen() const { return when; }
234  ThreadContext *getThread() const { return thread; }
236  TheISA::PCState getPCState() const { return pc; }
238 
239  Addr getAddr() const { return addr; }
240  Addr getSize() const { return size; }
241  unsigned getFlags() const { return flags; }
242  bool getMemValid() const { return mem_valid; }
243 
244  uint64_t getIntData() const { return data.as_int; }
245  double getFloatData() const { return data.as_double; }
246  int getDataStatus() const { return data_status; }
247 
248  InstSeqNum getFetchSeq() const { return fetch_seq; }
249  bool getFetchSeqValid() const { return fetch_seq_valid; }
250 
251  InstSeqNum getCpSeq() const { return cp_seq; }
252  bool getCpSeqValid() const { return cp_seq_valid; }
253 
254  bool getFaulting() const { return faulting; }
255 };
256 
257 class InstTracer : public SimObject
258 {
259  public:
261  {}
262 
263  virtual ~InstTracer()
264  {};
265 
266  virtual InstRecord *
267  getInstRecord(Tick when, ThreadContext *tc,
268  const StaticInstPtr staticInst, TheISA::PCState pc,
269  const StaticInstPtr macroStaticInst = NULL) = 0;
270 };
271 
272 
273 
274 } // namespace Trace
275 
276 #endif // __INSTRECORD_HH__
Trace::InstRecord::mem_valid
bool mem_valid
Definition: insttracer.hh:131
Trace::InstRecord::getCpSeq
InstSeqNum getCpSeq() const
Definition: insttracer.hh:251
Trace::InstRecord::getFloatData
double getFloatData() const
Definition: insttracer.hh:245
Trace::InstRecord::addr
Addr addr
The address that was accessed.
Definition: insttracer.hh:80
Trace::InstRecord::when
Tick when
Definition: insttracer.hh:58
SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:113
Trace::InstRecord::setData
void setData(uint32_t d)
Definition: insttracer.hh:193
VecPredRegContainer
Generic predicate register container.
Definition: vec_pred_reg.hh:47
Trace::InstRecord::data
union Trace::InstRecord::@115 data
Trace::InstRecord::staticInst
StaticInstPtr staticInst
Definition: insttracer.hh:65
Trace::InstRecord::setData
void setData(double d)
Definition: insttracer.hh:202
Trace::InstRecord::setData
void setData(uint8_t d)
Definition: insttracer.hh:195
Trace::InstRecord::setFetchSeq
void setFetchSeq(InstSeqNum seq)
Definition: insttracer.hh:220
Trace
Definition: nativetrace.cc:52
Trace::InstRecord::setData
void setData(::VecRegContainer< TheISA::VecRegSizeBytes > &d)
Definition: insttracer.hh:205
Trace::InstRecord::fetch_seq
InstSeqNum fetch_seq
Definition: insttracer.hh:106
Trace::InstRecord::getIntData
uint64_t getIntData() const
Definition: insttracer.hh:244
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
ArmISA::VecPredRegContainer
VecPredReg::Container VecPredRegContainer
Definition: registers.hh:77
Trace::InstRecord::macroStaticInst
StaticInstPtr macroStaticInst
Definition: insttracer.hh:67
Trace::InstRecord
Definition: insttracer.hh:55
Trace::InstRecord::setMem
void setMem(Addr a, Addr s, unsigned f)
Definition: insttracer.hh:176
Trace::InstRecord::setCPSeq
void setCPSeq(InstSeqNum seq)
Definition: insttracer.hh:223
Trace::InstRecord::setData
void setData(::VecPredRegContainer< TheISA::VecPredRegSizeBits, TheISA::VecPredRegHasPackedRepr > &d)
Definition: insttracer.hh:212
Trace::InstRecord::getMemValid
bool getMemValid() const
Definition: insttracer.hh:242
Trace::InstRecord::DataInt64
@ DataInt64
Definition: insttracer.hh:122
Trace::InstRecord::setData
void setData(int16_t d)
Definition: insttracer.hh:199
Trace::InstRecord::dump
virtual void dump()=0
Trace::InstTracer::getInstRecord
virtual InstRecord * getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst, TheISA::PCState pc, const StaticInstPtr macroStaticInst=NULL)=0
Trace::InstRecord::~InstRecord
virtual ~InstRecord()
Definition: insttracer.hh:164
Trace::InstTracer::~InstTracer
virtual ~InstTracer()
Definition: insttracer.hh:263
Trace::InstRecord::getFlags
unsigned getFlags() const
Definition: insttracer.hh:241
Trace::InstRecord::pc
TheISA::PCState pc
Definition: insttracer.hh:66
Trace::InstRecord::DataVec
@ DataVec
Definition: insttracer.hh:124
Trace::InstRecord::as_double
double as_double
Definition: insttracer.hh:96
Trace::InstRecord::getFaulting
bool getFaulting() const
Definition: insttracer.hh:254
Trace::InstRecord::data_status
enum Trace::InstRecord::DataStatus data_status
Trace::InstRecord::InstRecord
InstRecord(Tick _when, ThreadContext *_thread, const StaticInstPtr _staticInst, TheISA::PCState _pc, const StaticInstPtr _macroStaticInst=NULL)
Definition: insttracer.hh:153
ArmISA::a
Bitfield< 8 > a
Definition: miscregs_types.hh:62
inst_seq.hh
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
Trace::InstRecord::setData
void setData(int8_t d)
Definition: insttracer.hh:200
Trace::InstRecord::getCpSeqValid
bool getCpSeqValid() const
Definition: insttracer.hh:252
sim_object.hh
Trace::InstRecord::faulting
bool faulting
Did the execution of this instruction fault? (requires ExecFaulting to be enabled)
Definition: insttracer.hh:150
ArmISA::d
Bitfield< 9 > d
Definition: miscregs_types.hh:60
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
Trace::InstRecord::cp_seq_valid
bool cp_seq_valid
Definition: insttracer.hh:140
Trace::InstRecord::cp_seq
InstSeqNum cp_seq
Definition: insttracer.hh:112
ArmISA::VecPredRegHasPackedRepr
constexpr unsigned VecPredRegHasPackedRepr
Definition: types.hh:820
Trace::InstRecord::DataInt16
@ DataInt16
Definition: insttracer.hh:120
Trace::InstRecord::getFetchSeq
InstSeqNum getFetchSeq() const
Definition: insttracer.hh:248
Trace::InstRecord::setData
void setData(int64_t d)
Definition: insttracer.hh:197
Trace::InstRecord::DataDouble
@ DataDouble
Definition: insttracer.hh:123
Trace::InstRecord::getWhen
Tick getWhen() const
Definition: insttracer.hh:233
Trace::InstRecord::DataInt32
@ DataInt32
Definition: insttracer.hh:121
Trace::InstRecord::flags
unsigned flags
The flags that were assigned to the request.
Definition: insttracer.hh:82
static_inst.hh
Trace::InstRecord::as_int
uint64_t as_int
Definition: insttracer.hh:95
Trace::InstRecord::fetch_seq_valid
bool fetch_seq_valid
Definition: insttracer.hh:136
Trace::InstRecord::setData
void setData(std::array< T, N > d)
Definition: insttracer.hh:183
vec_pred_reg.hh
Trace::InstRecord::setData
void setData(int32_t d)
Definition: insttracer.hh:198
X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
InstSeqNum
uint64_t InstSeqNum
Definition: inst_seq.hh:37
Trace::InstRecord::DataInt8
@ DataInt8
Definition: insttracer.hh:119
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
ArmISA::VecPredRegSizeBits
constexpr unsigned VecPredRegSizeBits
Definition: types.hh:819
Trace::InstRecord::getPCState
TheISA::PCState getPCState() const
Definition: insttracer.hh:236
Trace::InstRecord::getDataStatus
int getDataStatus() const
Definition: insttracer.hh:246
Trace::InstRecord::getStaticInst
StaticInstPtr getStaticInst() const
Definition: insttracer.hh:235
Trace::InstRecord::getAddr
Addr getAddr() const
Definition: insttracer.hh:239
Trace::InstRecord::thread
ThreadContext * thread
Definition: insttracer.hh:62
vec_reg.hh
Trace::InstRecord::setData
void setData(uint16_t d)
Definition: insttracer.hh:194
Trace::InstRecord::size
Addr size
The size of the memory request.
Definition: insttracer.hh:81
Trace::InstRecord::getFetchSeqValid
bool getFetchSeqValid() const
Definition: insttracer.hh:249
Trace::InstRecord::as_pred
::VecPredRegContainer< TheISA::VecPredRegSizeBits, TheISA::VecPredRegHasPackedRepr > * as_pred
Definition: insttracer.hh:99
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
types.hh
Trace::InstRecord::getMacroStaticInst
StaticInstPtr getMacroStaticInst() const
Definition: insttracer.hh:237
Trace::InstRecord::getSize
Addr getSize() const
Definition: insttracer.hh:240
Trace::InstRecord::setFaulting
void setFaulting(bool val)
Definition: insttracer.hh:228
Trace::InstRecord::DataVecPred
@ DataVecPred
Definition: insttracer.hh:125
Trace::InstRecord::setPredicate
void setPredicate(bool val)
Definition: insttracer.hh:226
Trace::InstTracer
Definition: insttracer.hh:257
RefCountingPtr< StaticInst >
Trace::InstTracer::InstTracer
InstTracer(const Params *p)
Definition: insttracer.hh:260
Trace::InstRecord::DataInvalid
@ DataInvalid
Definition: insttracer.hh:118
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
Trace::InstRecord::as_vec
::VecRegContainer< TheISA::VecRegSizeBytes > * as_vec
Definition: insttracer.hh:97
Trace::InstRecord::setData
void setData(uint64_t d)
Definition: insttracer.hh:192
Trace::InstRecord::getThread
ThreadContext * getThread() const
Definition: insttracer.hh:234
Trace::InstRecord::setWhen
void setWhen(Tick new_when)
Definition: insttracer.hh:175
VecRegContainer< TheISA::VecRegSizeBytes >
Trace::InstRecord::DataStatus
DataStatus
Definition: insttracer.hh:117
ArmISA::f
Bitfield< 6 > f
Definition: miscregs_types.hh:64
Trace::InstRecord::predicate
bool predicate
is the predicate for execution this inst true or false (not execed)?
Definition: insttracer.hh:144
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17