gem5  v20.1.0.0
tarmac_parser.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011,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 
46 #ifndef __ARCH_ARM_TRACERS_TARMAC_PARSER_HH__
47 #define __ARCH_ARM_TRACERS_TARMAC_PARSER_HH__
48 
49 #include <fstream>
50 #include <unordered_map>
51 
52 #include "arch/arm/registers.hh"
53 #include "base/trace.hh"
54 #include "base/types.hh"
55 #include "cpu/static_inst.hh"
56 #include "cpu/thread_context.hh"
57 #include "mem/request.hh"
58 #include "params/TarmacParser.hh"
59 #include "sim/insttracer.hh"
60 #include "tarmac_base.hh"
61 
62 namespace Trace {
63 
65 {
66  public:
74  {
86  bool mismatch;
92 
94  ThreadContext *_thread,
95  const StaticInstPtr _inst,
96  ArmISA::PCState _pc,
97  bool _mismatch,
98  bool _mismatch_on_pc_or_opcode) :
99  parent(_parent), thread(_thread), inst(_inst), pc(_pc),
100  mismatch(_mismatch),
101  mismatchOnPcOrOpcode(_mismatch_on_pc_or_opcode)
102  {
103  }
104 
105  void process();
106  const char *description() const;
107  };
108 
109  struct ParserInstEntry : public InstEntry
110  {
111  public:
112  uint64_t seq_num;
113  };
114 
115  struct ParserRegEntry : public RegEntry
116  {
117  public:
118  char repr[16];
119  };
120 
121  struct ParserMemEntry : public MemEntry
122  { };
123 
124  static const int MaxLineLength = 256;
125 
130  static void printMismatchHeader(const StaticInstPtr inst,
132 
133  TarmacParserRecord(Tick _when, ThreadContext *_thread,
134  const StaticInstPtr _staticInst, ArmISA::PCState _pc,
135  TarmacParser& _parent,
136  const StaticInstPtr _macroStaticInst = NULL);
137 
138  void dump() override;
139 
145  bool readMemNoEffect(Addr addr, uint8_t *data, unsigned size,
146  unsigned flags);
147 
148  private:
155  bool advanceTrace();
156 
158  const char *iSetStateToStr(ISetState isetstate) const;
159 
162 
165 
168 
171 
173  static char buf[MaxLineLength];
174 
177 
179  using MiscRegMap = std::unordered_map<std::string, RegIndex>;
181 
187 
189  bool mismatch;
190 
196 
199 
201  static int8_t maxVectorLength;
202 
203  protected:
205 };
206 
212 class TarmacParser : public InstTracer
213 {
214  friend class TarmacParserRecord;
215 
216  public:
217  typedef TarmacParserParams Params;
218 
219  TarmacParser(const Params *p) : InstTracer(p), startPc(p->start_pc),
220  exitOnDiff(p->exit_on_diff),
221  exitOnInsnDiff(p->exit_on_insn_diff),
222  memWrCheck(p->mem_wr_check),
223  ignoredAddrRange(p->ignore_mem_addr),
224  cpuId(p->cpu_id),
225  macroopInProgress(false)
226  {
227  assert(!(exitOnDiff && exitOnInsnDiff));
228 
229  trace.open(p->path_to_trace.c_str());
230  if (startPc == 0x0) {
231  started = true;
232  } else {
234  started = false;
235  }
236  }
237 
238  virtual ~TarmacParser()
239  {
240  trace.close();
241  }
242 
243  InstRecord *
244  getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst,
246  const StaticInstPtr macroStaticInst = NULL)
247  {
248  if (!started && pc.pc() == startPc)
249  started = true;
250 
251  if (started)
252  return new TarmacParserRecord(when, tc, staticInst, pc, *this,
253  macroStaticInst);
254  else
255  return NULL;
256  }
257 
258  private:
260  void advanceTraceToStartPc();
261 
263  std::ifstream trace;
264 
270 
275 
281 
284 
287 
289  bool cpuId;
290 
292  bool started;
293 
296 };
297 
298 } // namespace Trace
299 
300 #endif // __ARCH_ARM_TRACERS_TARMAC_PARSER_HH__
Trace::TarmacParser::startPc
Addr startPc
Tracing starts when the PC gets this value for the first time (ignored if 0x0).
Definition: tarmac_parser.hh:269
Trace::TarmacParserRecord::regRecord
static ParserRegEntry regRecord
Buffer for register trace records.
Definition: tarmac_parser.hh:164
Trace::InstRecord::addr
Addr addr
The address that was accessed.
Definition: insttracer.hh:80
Trace::TarmacParser::cpuId
bool cpuId
If true, the trace format includes the CPU id.
Definition: tarmac_parser.hh:289
Trace::TarmacParserRecord::TarmacParserRecord
TarmacParserRecord(Tick _when, ThreadContext *_thread, const StaticInstPtr _staticInst, ArmISA::PCState _pc, TarmacParser &_parent, const StaticInstPtr _macroStaticInst=NULL)
Definition: tarmac_parser.cc:956
Trace::InstRecord::data
union Trace::InstRecord::@115 data
Trace::TarmacParser::getInstRecord
InstRecord * getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst, ArmISA::PCState pc, const StaticInstPtr macroStaticInst=NULL)
Definition: tarmac_parser.hh:244
Trace::TarmacParserRecord::mismatch
bool mismatch
True if a mismatch has been detected for this instruction.
Definition: tarmac_parser.hh:189
Trace::TarmacParser::started
bool started
True if tracing has started.
Definition: tarmac_parser.hh:292
Trace::TarmacParser::memWrCheck
bool memWrCheck
If true, memory write accesses are checked.
Definition: tarmac_parser.hh:283
Trace::TarmacParserRecord::instRecord
static ParserInstEntry instRecord
Buffer for instruction trace records.
Definition: tarmac_parser.hh:161
Trace::TarmacParserRecord::ParserRegEntry
Definition: tarmac_parser.hh:115
insttracer.hh
Trace::TarmacParserRecord::ParserMemEntry
Definition: tarmac_parser.hh:121
Trace::TarmacBaseRecord
Definition: tarmac_base.hh:62
Trace
Definition: nativetrace.cc:52
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Trace::TarmacParserRecord::TarmacParserRecordEvent::inst
const StaticInstPtr inst
Current instruction.
Definition: tarmac_parser.hh:82
Trace::TarmacParserRecord::parent
TarmacParser & parent
Definition: tarmac_parser.hh:204
Trace::InstRecord
Definition: insttracer.hh:55
Trace::TarmacParser::TarmacParser
TarmacParser(const Params *p)
Definition: tarmac_parser.hh:219
RequestPtr
std::shared_ptr< Request > RequestPtr
Definition: request.hh:82
Trace::TarmacParserRecord::destRegRecords
static std::list< ParserRegEntry > destRegRecords
List of records of destination registers.
Definition: tarmac_parser.hh:176
Trace::TarmacParserRecord::dump
void dump() override
Definition: tarmac_parser.cc:973
Trace::TarmacParserRecord::mismatchOnPcOrOpcode
bool mismatchOnPcOrOpcode
True if a mismatch has been detected for this instruction on PC or opcode.
Definition: tarmac_parser.hh:195
Trace::TarmacParserRecord::TarmacParserRecordEvent::TarmacParserRecordEvent
TarmacParserRecordEvent(TarmacParser &_parent, ThreadContext *_thread, const StaticInstPtr _inst, ArmISA::PCState _pc, bool _mismatch, bool _mismatch_on_pc_or_opcode)
Definition: tarmac_parser.hh:93
tarmac_base.hh
Trace::TarmacParserRecord::readMemNoEffect
bool readMemNoEffect(Addr addr, uint8_t *data, unsigned size, unsigned flags)
Performs a memory access to read the value written by a previous write.
Definition: tarmac_parser.cc:1283
Trace::TarmacParserRecord::TarmacParserRecordEvent::mismatchOnPcOrOpcode
bool mismatchOnPcOrOpcode
True if a mismatch has been detected for this instruction on PC or opcode.
Definition: tarmac_parser.hh:91
request.hh
Trace::TarmacParserRecord::TarmacParserRecordEvent::pc
ArmISA::PCState pc
PC of the current instruction.
Definition: tarmac_parser.hh:84
Trace::InstRecord::pc
TheISA::PCState pc
Definition: insttracer.hh:66
Trace::TarmacParser::macroopInProgress
bool macroopInProgress
True if a macroop is currently in progress.
Definition: tarmac_parser.hh:295
Trace::TarmacParser::exitOnInsnDiff
bool exitOnInsnDiff
If true, the simulation is stopped as the first mismatch is detected on PC or opcode.
Definition: tarmac_parser.hh:280
Trace::TarmacParserRecord::memRecord
static ParserMemEntry memRecord
Buffer for memory access trace records (stores only).
Definition: tarmac_parser.hh:167
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
Event
Definition: eventq.hh:246
AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:68
MipsISA::pc
Bitfield< 4 > pc
Definition: pra_constants.hh:240
Trace::TarmacParserRecord::iSetStateToStr
const char * iSetStateToStr(ISetState isetstate) const
Returns the string representation of an instruction set state.
Definition: tarmac_parser.cc:1351
Trace::TarmacParserRecord::memReq
RequestPtr memReq
Request for memory write checks.
Definition: tarmac_parser.hh:198
Trace::TarmacParser
Tarmac Parser: this tracer parses an existing Tarmac trace and it diffs it with gem5 simulation statu...
Definition: tarmac_parser.hh:212
Trace::TarmacParserRecord::miscRegMap
static MiscRegMap miscRegMap
Definition: tarmac_parser.hh:180
Trace::TarmacBaseRecord::RegEntry
TARMAC register trace record.
Definition: tarmac_base.hh:98
Trace::TarmacParser::TarmacParserRecord
friend class TarmacParserRecord
Definition: tarmac_parser.hh:214
Trace::InstRecord::flags
unsigned flags
The flags that were assigned to the request.
Definition: insttracer.hh:82
static_inst.hh
Trace::TarmacParser::trace
std::ifstream trace
TARMAC trace file.
Definition: tarmac_parser.hh:263
Trace::TarmacBaseRecord::ISetState
ISetState
ARM instruction set state.
Definition: tarmac_base.hh:74
Trace::TarmacParserRecord::maxVectorLength
static int8_t maxVectorLength
Max.
Definition: tarmac_parser.hh:201
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Trace::TarmacParserRecord::TarmacParserRecordEvent::thread
ThreadContext * thread
Current thread context.
Definition: tarmac_parser.hh:80
Trace::TarmacParser::Params
TarmacParserParams Params
Definition: tarmac_parser.hh:217
Trace::TarmacParserRecord::MiscRegMap
std::unordered_map< std::string, RegIndex > MiscRegMap
Map from misc.
Definition: tarmac_parser.hh:179
Trace::TarmacParser::~TarmacParser
virtual ~TarmacParser()
Definition: tarmac_parser.hh:238
Trace::InstRecord::size
Addr size
The size of the memory request.
Definition: insttracer.hh:81
Trace::TarmacParserRecord
Definition: tarmac_parser.hh:64
MipsISA::PCState
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
types.hh
registers.hh
Trace::TarmacParserRecord::TarmacParserRecordEvent::mismatch
bool mismatch
True if a mismatch has been detected for this instruction.
Definition: tarmac_parser.hh:86
Trace::TarmacParserRecord::ParserRegEntry::repr
char repr[16]
Definition: tarmac_parser.hh:118
Trace::TarmacParserRecord::MaxLineLength
static const int MaxLineLength
Definition: tarmac_parser.hh:124
Trace::TarmacParser::advanceTraceToStartPc
void advanceTraceToStartPc()
Helper function to advance the trace up to startPc.
Definition: tarmac_parser.cc:1320
Trace::TarmacParserRecord::currRecordType
static TarmacRecordType currRecordType
Type of last parsed record.
Definition: tarmac_parser.hh:170
Trace::TarmacParserRecord::printMismatchHeader
static void printMismatchHeader(const StaticInstPtr inst, ArmISA::PCState pc)
Print a mismatch header containing the instruction fields as reported by gem5.
Definition: tarmac_parser.cc:943
Trace::InstTracer
Definition: insttracer.hh:257
Trace::TarmacParserRecord::TarmacParserRecordEvent::process
void process()
Definition: tarmac_parser.cc:734
RefCountingPtr< StaticInst >
trace.hh
Trace::TarmacParser::ignoredAddrRange
AddrRange ignoredAddrRange
Ignored addresses (ignored if empty).
Definition: tarmac_parser.hh:286
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Trace::TarmacParserRecord::ParserInstEntry
Definition: tarmac_parser.hh:109
std::list
STL list class.
Definition: stl.hh:51
Trace::TarmacParserRecord::parsingStarted
bool parsingStarted
True if a TARMAC instruction record has already been parsed for this instruction.
Definition: tarmac_parser.hh:186
Trace::TarmacParserRecord::TarmacParserRecordEvent
Event triggered to check the value of the destination registers.
Definition: tarmac_parser.hh:73
Trace::TarmacParser::exitOnDiff
bool exitOnDiff
If true, the simulation is stopped as the first mismatch is detected.
Definition: tarmac_parser.hh:274
Trace::TarmacParserRecord::ParserInstEntry::seq_num
uint64_t seq_num
Definition: tarmac_parser.hh:112
thread_context.hh
Trace::TarmacParserRecord::TarmacParserRecordEvent::parent
TarmacParser & parent
Reference to the TARMAC trace object to which this record belongs.
Definition: tarmac_parser.hh:78
Trace::TarmacParserRecord::advanceTrace
bool advanceTrace()
Advances the TARMAC trace up to the next instruction, register, or memory access record.
Definition: tarmac_parser.cc:1080
Trace::TarmacParserRecord::buf
static char buf[MaxLineLength]
Buffer used for trace file parsing.
Definition: tarmac_parser.hh:173
Trace::TarmacParserRecord::TarmacParserRecordEvent::description
const char * description() const
Return a C string describing the event.
Definition: tarmac_parser.cc:936
Trace::TarmacBaseRecord::TarmacRecordType
TarmacRecordType
TARMAC trace record type.
Definition: tarmac_base.hh:66

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