gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tarmac_record_v8.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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  * 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 
39 
40 #include <memory>
41 
43 #include "arch/arm/mmu.hh"
45 
46 using namespace ArmISA;
47 
48 namespace Trace {
49 
50 TarmacTracerRecordV8::TraceInstEntryV8::TraceInstEntryV8(
51  const TarmacContext& tarmCtx,
52  bool predicate)
53  : TraceInstEntry(tarmCtx, predicate),
54  TraceEntryV8(tarmCtx.tarmacCpuName()),
55  paddr(0),
56  paddrValid(false)
57 {
58  const auto thread = tarmCtx.thread;
59 
60  // Evaluate physical address
61  auto mmu = static_cast<ArmISA::MMU*>(thread->getMMUPtr());
62  paddrValid = mmu->translateFunctional(
63  thread, addr, paddr);
64 }
65 
67  const TarmacContext& tarmCtx,
68  uint8_t _size, Addr _addr, uint64_t _data)
69  : TraceMemEntry(tarmCtx, _size, _addr, _data),
70  TraceEntryV8(tarmCtx.tarmacCpuName()),
71  paddr(_addr)
72 {
73  const auto thread = tarmCtx.thread;
74 
75  // Evaluate physical address
76  auto mmu = static_cast<ArmISA::MMU*>(thread->getMMUPtr());
78 }
79 
81  const TarmacContext& tarmCtx,
82  const RegId& reg)
83  : TraceRegEntry(tarmCtx, reg),
84  TraceEntryV8(tarmCtx.tarmacCpuName()),
85  regWidth(64)
86 {
87 }
88 
89 void
91  const TarmacContext& tarmCtx,
92  RegIndex regRelIdx
93 )
94 {
95  // Do not trace pseudo register accesses: invalid
96  // register entry.
97  if (regRelIdx > NUM_ARCH_INTREGS) {
98  regValid = false;
99  return;
100  }
101 
102  TraceRegEntry::updateInt(tarmCtx, regRelIdx);
103 
104  if ((regRelIdx != PCReg) || (regRelIdx != StackPointerReg) ||
105  (regRelIdx != FramePointerReg) || (regRelIdx != ReturnAddressReg)) {
106 
107  const auto* arm_inst = static_cast<const ArmStaticInst*>(
108  tarmCtx.staticInst.get()
109  );
110 
111  regWidth = (arm_inst->getIntWidth());
112  if (regWidth == 32) {
113  regName = "W" + std::to_string(regRelIdx);
114  } else {
115  regName = "X" + std::to_string(regRelIdx);
116  }
117  }
118 }
119 
120 void
122  const TarmacContext& tarmCtx,
123  RegIndex regRelIdx
124 )
125 {
126  TraceRegEntry::updateMisc(tarmCtx, regRelIdx);
127  // System registers are 32bit wide
128  regWidth = 32;
129 }
130 
131 void
133  const TarmacContext& tarmCtx,
134  RegIndex regRelIdx
135 )
136 {
137  auto thread = tarmCtx.thread;
138  const auto& vec_container = thread->readVecReg(
139  RegId(regClass, regRelIdx));
140  auto vv = vec_container.as<VecElem>();
141 
142  regWidth = ArmStaticInst::getCurSveVecLenInBits(thread);
143  auto num_elements = regWidth / (sizeof(VecElem) * 8);
144 
145  // Resize vector of values
146  values.resize(num_elements);
147 
148  for (auto i = 0; i < num_elements; i++) {
149  values[i] = vv[i];
150  }
151 
152  regValid = true;
153  regName = "Z" + std::to_string(regRelIdx);
154 }
155 
156 void
158  const TarmacContext& tarmCtx,
159  RegIndex regRelIdx
160 )
161 {
162  auto thread = tarmCtx.thread;
163  const auto& pred_container = thread->readVecPredReg(
164  RegId(regClass, regRelIdx));
165 
166  // Predicate registers are always 1/8 the size of related vector
167  // registers. (getCurSveVecLenInBits(thread) / 8)
168  regWidth = ArmStaticInst::getCurSveVecLenInBits(thread) / 8;
169  auto num_elements = regWidth / 16;
170 
171  // Resize vector of values
172  values.resize(num_elements);
173 
174  // Get a copy of pred_container as a vector of half-words
175  auto vv = pred_container.as<uint16_t>();
176  for (auto i = 0; i < num_elements; i++) {
177  values[i] = vv[i];
178  }
179 
180  regValid = true;
181  regName = "P" + std::to_string(regRelIdx);
182 }
183 
184 void
186  const TarmacContext& tarmCtx)
187 {
188  // Generate an instruction entry in the record and
189  // add it to the Instruction Queue
190  queue.push_back(
191  std::make_unique<TraceInstEntryV8>(tarmCtx, predicate)
192  );
193 }
194 
195 void
197  const TarmacContext& tarmCtx)
198 {
199  // Generate a memory entry in the record if the record
200  // implies a valid memory access, and add it to the
201  // Memory Queue
202  if (getMemValid()) {
203  queue.push_back(
204  std::make_unique<TraceMemEntryV8>(tarmCtx,
205  static_cast<uint8_t>(getSize()),
206  getAddr(), getIntData())
207  );
208  }
209 }
210 
211 void
213  const TarmacContext& tarmCtx)
214 {
215  // Generate an entry for every ARM register being
216  // written by the current instruction
217  for (auto reg = 0; reg < staticInst->numDestRegs(); ++reg) {
218 
219  RegId reg_id = staticInst->destRegIdx(reg);
220 
221  // Creating a single register change entry
222  auto single_reg = genRegister<TraceRegEntryV8>(tarmCtx, reg_id);
223 
224  // Copying the entry and adding it to the "list"
225  // of entries to be dumped to trace.
226  queue.push_back(std::make_unique<TraceRegEntryV8>(single_reg));
227  }
228 
229  // Gem5 is treating CPSR flags as separate registers (CC registers),
230  // in contrast with Tarmac specification: we need to merge the gem5 CC
231  // entries altogether with the CPSR register and produce a single entry.
232  mergeCCEntry<TraceRegEntryV8>(queue, tarmCtx);
233 }
234 
235 void
237  std::ostream& outs,
238  int verbosity,
239  const std::string &prefix) const
240 {
241  // If there is a valid vaddr->paddr translation, print the
242  // physical address, otherwise print the virtual address only.
243  std::string paddr_str = paddrValid? csprintf(":%012x",paddr) :
244  std::string();
245 
246  // Pad the opcode.
247  std::string opcode_str = csprintf("%0*x", instSize >> 2, opcode);
248 
249  // Print the instruction record formatted according
250  // to the Tarmac specification
251  ccprintf(outs, "%s clk %s %s (%u) %08x%s %s %s %s_%s : %s\n",
252  curTick(), /* Tick time */
253  cpuName, /* Cpu name */
254  taken? "IT" : "IS", /* Instruction taken/skipped */
255  instCount, /* Instruction count */
256  addr, /* Instruction virt address */
257  paddr_str, /* Instruction phys address */
258  opcode_str, /* Instruction opcode */
259  iSetStateToStr(isetstate), /* Instruction Set */
260  opModeToStr(mode), /* Exception level */
261  secureMode? "s" : "ns", /* Security */
262  disassemble); /* Instruction disass */
263 }
264 
265 void
267  std::ostream& outs,
268  int verbosity,
269  const std::string &prefix) const
270 {
271  // Print the memory record formatted according
272  // to the Tarmac specification
273  ccprintf(outs, "%s clk %s M%s%d %08x:%012x %0*x\n",
274  curTick(), /* Tick time */
275  cpuName, /* Cpu name */
276  loadAccess? "R" : "W", /* Access type */
277  size, /* Access size */
278  addr, /* Virt Memory address */
279  paddr, /* Phys Memory address */
280  size*2, /* Padding with access size */
281  data); /* Memory data */
282 }
283 
284 void
286  std::ostream& outs,
287  int verbosity,
288  const std::string &prefix) const
289 {
290  // Print the register record formatted according
291  // to the Tarmac specification
292  if (regValid) {
293  ccprintf(outs, "%s clk %s R %s %s\n",
294  curTick(), /* Tick time */
295  cpuName, /* Cpu name */
296  regName, /* Register name */
297  formatReg()); /* Register value */
298  }
299 }
300 
301 std::string
303 {
304  if (regWidth <= 64) {
305  // Register width is < 64 bit (scalar register).
306  return csprintf("%0*x", regWidth / 4, values[Lo]);
307  } else {
308 
309  // Register width is > 64 bit (vector). Iterate over every vector
310  // element. Since the vector values are stored in Little Endian, print
311  // starting from the last element.
312  std::string reg_val;
313  for (auto it = values.rbegin(); it != values.rend(); it++) {
314  reg_val += csprintf("%0*x_",
315  static_cast<int>(sizeof(VecElem) * 2), *it);
316  }
317 
318  // Remove trailing underscore
319  reg_val.pop_back();
320 
321  return reg_val;
322  }
323 }
324 
325 } // namespace Trace
Trace::TarmacTracerRecordV8::TraceRegEntryV8::updatePred
void updatePred(const TarmacContext &tarmCtx, RegIndex regRelIdx) override
Definition: tarmac_record_v8.cc:157
Trace::TarmacTracerRecordV8::TraceInstEntryV8::print
virtual void print(std::ostream &outs, int verbosity=0, const std::string &prefix="") const override
Definition: tarmac_record_v8.cc:236
Trace::iSetStateToStr
std::string iSetStateToStr(TarmacBaseRecord::ISetState isetstate)
Returns the string representation of the instruction set being currently run according to the Tarmac ...
Definition: tarmac_record.cc:53
Trace::InstRecord::data
union Trace::InstRecord::@112 data
Trace::TarmacTracerRecordV8::addMemEntry
void addMemEntry(std::vector< MemPtr > &queue, const TarmacContext &ptr)
Generates an Entry for every memory access triggered.
Definition: tarmac_record_v8.cc:196
Trace::InstRecord::addr
Addr addr
The address that was accessed.
Definition: insttracer.hh:80
Trace::TarmacTracerRecordV8::addRegEntry
void addRegEntry(std::vector< RegPtr > &queue, const TarmacContext &ptr)
Generate a Record for every register being written.
Definition: tarmac_record_v8.cc:212
Trace::TarmacTracerRecord::TraceMemEntry
Memory Entry.
Definition: tarmac_record.hh:170
Trace::TarmacTracerRecordV8::TraceMemEntryV8::print
virtual void print(std::ostream &outs, int verbosity=0, const std::string &prefix="") const override
Definition: tarmac_record_v8.cc:266
StaticInst::destRegIdx
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:234
Trace::InstRecord::staticInst
StaticInstPtr staticInst
Definition: insttracer.hh:65
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Trace
Definition: nativetrace.cc:52
ThreadContext::getMMUPtr
virtual BaseMMU * getMMUPtr()=0
sc_dt::to_string
const std::string to_string(sc_enc enc)
Definition: sc_fxdefs.cc:91
Trace::InstRecord::getIntData
uint64_t getIntData() const
Definition: insttracer.hh:244
std::vector< InstPtr >
Trace::TarmacBaseRecord::InstEntry::addr
Addr addr
Definition: tarmac_base.hh:90
ThreadContext::readVecReg
virtual const TheISA::VecRegContainer & readVecReg(const RegId &reg) const =0
Trace::InstRecord::getMemValid
bool getMemValid() const
Definition: insttracer.hh:242
ArmISA
Definition: ccregs.hh:41
X86ISA::reg
Bitfield< 5, 3 > reg
Definition: types.hh:88
tarmac_record_v8.hh
Trace::TarmacTracerRecord::TraceRegEntry::updateMisc
virtual void updateMisc(const TarmacContext &tarmCtx, RegIndex regRelIdx)
Register update functions.
Definition: tarmac_record.cc:197
Trace::opModeToStr
std::string opModeToStr(OperatingMode opMode)
Returns the string representation of the ARM Operating Mode (CPSR.M[3:0] field) according to the Tarm...
Definition: tarmac_record.cc:68
RegId
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
ArmISA::ArmStaticInst
Definition: static_inst.hh:60
mmu.hh
Trace::TarmacTracerRecordV8::TraceRegEntryV8::TraceRegEntryV8
TraceRegEntryV8(const TarmacContext &tarmCtx, const RegId &reg)
Definition: tarmac_record_v8.cc:80
ArmISA::VecElem
uint32_t VecElem
Definition: registers.hh:60
Trace::TarmacTracerRecordV8::TraceRegEntryV8::updateMisc
void updateMisc(const TarmacContext &tarmCtx, RegIndex regRelIdx) override
Register update functions.
Definition: tarmac_record_v8.cc:121
Trace::TarmacTracerRecordV8::TraceInstEntryV8::paddrValid
bool paddrValid
Definition: tarmac_record_v8.hh:87
Trace::TarmacContext
This object type is encapsulating the informations needed by a Tarmac record to generate it's own ent...
Definition: tarmac_tracer.hh:59
Trace::TarmacTracerRecordV8::TraceRegEntryV8::updateVec
void updateVec(const TarmacContext &tarmCtx, RegIndex regRelIdx) override
Definition: tarmac_record_v8.cc:132
StaticInst::numDestRegs
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:138
Trace::TarmacTracerRecordV8::TraceRegEntryV8::updateInt
void updateInt(const TarmacContext &tarmCtx, RegIndex regRelIdx) override
Definition: tarmac_record_v8.cc:90
Trace::TarmacTracerRecordV8::TraceMemEntryV8::paddr
Addr paddr
Definition: tarmac_record_v8.hh:142
ThreadContext::readVecPredReg
virtual const TheISA::VecPredRegContainer & readVecPredReg(const RegId &reg) const =0
ArmISA::mode
Bitfield< 4, 0 > mode
Definition: miscregs_types.hh:70
ArmISA::FramePointerReg
const int FramePointerReg
Definition: registers.hh:105
Trace::TarmacTracerRecordV8::TraceRegEntryV8::print
virtual void print(std::ostream &outs, int verbosity=0, const std::string &prefix="") const override
Definition: tarmac_record_v8.cc:285
ArmISA::MMU
Definition: mmu.hh:48
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
Trace::TarmacContext::staticInst
const StaticInstPtr staticInst
Definition: tarmac_tracer.hh:72
ArmISA::opcode
Bitfield< 24, 21 > opcode
Definition: types.hh:101
Sinic::regValid
bool regValid(Addr daddr)
Definition: sinicreg.hh:224
Trace::InstRecord::getAddr
Addr getAddr() const
Definition: insttracer.hh:239
Trace::InstRecord::thread
ThreadContext * thread
Definition: insttracer.hh:62
Trace::TarmacTracerRecordV8::TraceEntryV8
General data shared by all v8 entries.
Definition: tarmac_record_v8.hh:62
ArmISA::NUM_ARCH_INTREGS
@ NUM_ARCH_INTREGS
Definition: intregs.hh:124
Trace::InstRecord::size
Addr size
The size of the memory request.
Definition: insttracer.hh:81
tarmac_tracer.hh
ArmISA::StackPointerReg
const int StackPointerReg
Definition: registers.hh:106
RegIndex
uint16_t RegIndex
Definition: types.hh:52
Trace::TarmacTracerRecordV8::TraceRegEntryV8::formatReg
std::string formatReg() const
Returning a string which contains the formatted register value: transformed in hex,...
Definition: tarmac_record_v8.cc:302
Trace::InstRecord::getSize
Addr getSize() const
Definition: insttracer.hh:240
static_inst.hh
Trace::TarmacTracerRecord::TraceInstEntry
Instruction Entry.
Definition: tarmac_record.hh:95
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
Trace::TarmacTracerRecordV8::TraceInstEntryV8::paddr
Addr paddr
Definition: tarmac_record_v8.hh:86
ArmISA::ReturnAddressReg
const int ReturnAddressReg
Definition: registers.hh:107
Trace::TarmacTracerRecord::TraceRegEntry
Register Entry.
Definition: tarmac_record.hh:118
ArmISA::PCReg
const int PCReg
Definition: registers.hh:108
Trace::TarmacTracerRecordV8::addInstEntry
void addInstEntry(std::vector< InstPtr > &queue, const TarmacContext &ptr)
Generates an Entry for the executed instruction.
Definition: tarmac_record_v8.cc:185
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
Trace::TarmacTracerRecordV8::TraceMemEntryV8::TraceMemEntryV8
TraceMemEntryV8(const TarmacContext &tarmCtx, uint8_t _size, Addr _addr, uint64_t _data)
Definition: tarmac_record_v8.cc:66
ArmISA::MMU::translateFunctional
bool translateFunctional(ThreadContext *tc, Addr vaddr, Addr &paddr)
Definition: mmu.cc:44
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
Trace::TarmacTracerRecord::TraceRegEntry::updateInt
virtual void updateInt(const TarmacContext &tarmCtx, RegIndex regRelIdx)
Definition: tarmac_record.cc:250
Trace::TarmacContext::thread
ThreadContext * thread
Definition: tarmac_tracer.hh:71
Trace::InstRecord::predicate
bool predicate
is the predicate for execution this inst true or false (not execed)?
Definition: insttracer.hh:144
RefCountingPtr::get
T * get() const
Directly access the pointer itself without taking a reference.
Definition: refcnt.hh:224

Generated on Tue Jun 22 2021 15:28:21 for gem5 by doxygen 1.8.17