gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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  * Authors: Giacomo Gabrielli
38  */
39 
48 #ifndef __ARCH_ARM_TRACERS_TARMAC_PARSER_HH__
49 #define __ARCH_ARM_TRACERS_TARMAC_PARSER_HH__
50 
51 #include <fstream>
52 #include <unordered_map>
53 
54 #include "arch/arm/registers.hh"
55 #include "base/trace.hh"
56 #include "base/types.hh"
57 #include "cpu/static_inst.hh"
58 #include "cpu/thread_context.hh"
59 #include "mem/request.hh"
60 #include "params/TarmacParser.hh"
61 #include "sim/insttracer.hh"
62 #include "tarmac_base.hh"
63 
64 namespace Trace {
65 
67 {
68  public:
76  {
88  bool mismatch;
94 
96  ThreadContext *_thread,
97  const StaticInstPtr _inst,
98  ArmISA::PCState _pc,
99  bool _mismatch,
100  bool _mismatch_on_pc_or_opcode) :
101  parent(_parent), thread(_thread), inst(_inst), pc(_pc),
102  mismatch(_mismatch),
103  mismatchOnPcOrOpcode(_mismatch_on_pc_or_opcode)
104  {
105  }
106 
107  void process();
108  const char *description() const;
109  };
110 
111  struct ParserInstEntry : public InstEntry
112  {
113  public:
114  uint64_t seq_num;
115  };
116 
117  struct ParserRegEntry : public RegEntry
118  {
119  public:
120  char repr[16];
121  };
122 
123  struct ParserMemEntry : public MemEntry
124  { };
125 
126  static const int MaxLineLength = 256;
127 
132  static void printMismatchHeader(const StaticInstPtr inst,
134 
136  const StaticInstPtr _staticInst, ArmISA::PCState _pc,
137  TarmacParser& _parent,
138  const StaticInstPtr _macroStaticInst = NULL);
139 
140  void dump() override;
141 
147  bool readMemNoEffect(Addr addr, uint8_t *data, unsigned size,
148  unsigned flags);
149 
150  private:
157  bool advanceTrace();
158 
160  const char *iSetStateToStr(ISetState isetstate) const;
161 
164 
167 
170 
173 
175  static char buf[MaxLineLength];
176 
179 
181  using MiscRegMap = std::unordered_map<std::string, RegIndex>;
183 
189 
191  bool mismatch;
192 
198 
201 
203  static int8_t maxVectorLength;
204 
205  protected:
207 };
208 
214 class TarmacParser : public InstTracer
215 {
216  friend class TarmacParserRecord;
217 
218  public:
219  typedef TarmacParserParams Params;
220 
221  TarmacParser(const Params *p) : InstTracer(p), startPc(p->start_pc),
222  exitOnDiff(p->exit_on_diff),
223  exitOnInsnDiff(p->exit_on_insn_diff),
224  memWrCheck(p->mem_wr_check),
225  ignoredAddrRange(p->ignore_mem_addr),
226  cpuId(p->cpu_id),
227  macroopInProgress(false)
228  {
229  assert(!(exitOnDiff && exitOnInsnDiff));
230 
231  trace.open(p->path_to_trace.c_str());
232  if (startPc == 0x0) {
233  started = true;
234  } else {
235  advanceTraceToStartPc();
236  started = false;
237  }
238  }
239 
240  virtual ~TarmacParser()
241  {
242  trace.close();
243  }
244 
245  InstRecord *
248  const StaticInstPtr macroStaticInst = NULL)
249  {
250  if (!started && pc.pc() == startPc)
251  started = true;
252 
253  if (started)
254  return new TarmacParserRecord(when, tc, staticInst, pc, *this,
256  else
257  return NULL;
258  }
259 
260  private:
262  void advanceTraceToStartPc();
263 
265  std::ifstream trace;
266 
272 
277 
283 
286 
289 
291  bool cpuId;
292 
294  bool started;
295 
298 };
299 
300 } // namespace Trace
301 
302 #endif // __ARCH_ARM_TRACERS_TARMAC_PARSER_HH__
TarmacParser(const Params *p)
std::ifstream trace
TARMAC trace file.
bool started
True if tracing has started.
void dump() const
Dump the current event data.
Definition: eventq.cc:400
ISetState
ARM instruction set state.
Definition: tarmac_base.hh:77
Event triggered to check the value of the destination registers.
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:401
static TarmacRecordType currRecordType
Type of last parsed record.
static ParserRegEntry regRecord
Buffer for register trace records.
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Tick _when
timestamp when event should be processed
Definition: eventq.hh:209
bool exitOnInsnDiff
If true, the simulation is stopped as the first mismatch is detected on PC or opcode.
std::shared_ptr< Request > RequestPtr
Definition: request.hh:83
const char * iSetStateToStr(ISetState isetstate) const
Returns the string representation of an instruction set state.
bool parsingStarted
True if a TARMAC instruction record has already been parsed for this instruction. ...
Addr size
The size of the memory request.
Definition: insttracer.hh:84
RequestPtr memReq
Request for memory write checks.
bool mismatch
True if a mismatch has been detected for this instruction.
TarmacParserParams Params
ThreadContext is the external interface to all thread state for anything outside of the CPU...
bool cpuId
If true, the trace format includes the CPU id.
ArmISA::PCState pc
PC of the current instruction.
static std::list< ParserRegEntry > destRegRecords
List of records of destination registers.
bool mismatch
True if a mismatch has been detected for this instruction.
TarmacParser & parent
Reference to the TARMAC trace object to which this record belongs.
Tarmac Parser: this tracer parses an existing Tarmac trace and it diffs it with gem5 simulation statu...
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:72
const char * description() const
Return a C string describing the event.
bool mismatchOnPcOrOpcode
True if a mismatch has been detected for this instruction on PC or opcode.
bool readMemNoEffect(Addr addr, uint8_t *data, unsigned size, unsigned flags)
Performs a memory access to read the value written by a previous write.
Flags flags
Definition: eventq.hh:211
static MiscRegMap miscRegMap
static ParserInstEntry instRecord
Buffer for instruction trace records.
InstRecord * getInstRecord(Tick when, ThreadContext *tc, const StaticInstPtr staticInst, ArmISA::PCState pc, const StaticInstPtr macroStaticInst=NULL)
uint64_t Tick
Tick count type.
Definition: types.hh:63
static int8_t maxVectorLength
Max.
Addr startPc
Tracing starts when the PC gets this value for the first time (ignored if 0x0).
TarmacRecordType
TARMAC trace record type.
Definition: tarmac_base.hh:69
static ParserMemEntry memRecord
Buffer for memory access trace records (stores only).
std::unordered_map< std::string, RegIndex > MiscRegMap
Map from misc.
StaticInstPtr macroStaticInst
Definition: insttracer.hh:70
STL list class.
Definition: stl.hh:54
union Trace::InstRecord::@120 data
ThreadContext * thread
Current thread context.
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
static void printMismatchHeader(const StaticInstPtr inst, ArmISA::PCState pc)
Print a mismatch header containing the instruction fields as reported by gem5.
bool mismatchOnPcOrOpcode
True if a mismatch has been detected for this instruction on PC or opcode.
Definition: eventq.hh:189
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
TarmacParserRecord(Tick _when, ThreadContext *_thread, const StaticInstPtr _staticInst, ArmISA::PCState _pc, TarmacParser &_parent, const StaticInstPtr _macroStaticInst=NULL)
virtual void trace(const char *action)
trace event activity
Definition: eventq.cc:384
AddrRange ignoredAddrRange
Ignored addresses (ignored if empty).
bool macroopInProgress
True if a macroop is currently in progress.
StaticInstPtr staticInst
Definition: insttracer.hh:68
bool advanceTrace()
Advances the TARMAC trace up to the next instruction, register, or memory access record.
static char buf[MaxLineLength]
Buffer used for trace file parsing.
bool memWrCheck
If true, memory write accesses are checked.
TarmacParserRecordEvent(TarmacParser &_parent, ThreadContext *_thread, const StaticInstPtr _inst, ArmISA::PCState _pc, bool _mismatch, bool _mismatch_on_pc_or_opcode)
bool exitOnDiff
If true, the simulation is stopped as the first mismatch is detected.
Bitfield< 0 > p
static const int MaxLineLength
Addr addr
The address that was accessed.
Definition: insttracer.hh:83
const StaticInstPtr inst
Current instruction.

Generated on Fri Feb 28 2020 16:26:57 for gem5 by doxygen 1.8.13