gem5  v20.0.0.2
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
nativetrace.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2011, 2014, 2016-2017 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) 2006 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 #include "arch/arm/nativetrace.hh"
42 
43 #include "arch/arm/isa_traits.hh"
44 #include "arch/arm/miscregs.hh"
45 #include "cpu/thread_context.hh"
46 #include "debug/ExecRegDelta.hh"
47 #include "params/ArmNativeTrace.hh"
48 #include "sim/byteswap.hh"
49 
50 namespace Trace {
51 
52 #if TRACING_ON
53 static const char *regNames[] = {
54  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
55  "r8", "r9", "r10", "fp", "r12", "sp", "lr", "pc",
56  "cpsr", "f0", "f1", "f2", "f3", "f4", "f5", "f6",
57  "f7", "f8", "f9", "f10", "f11", "f12", "f13", "f14",
58  "f15", "f16", "f17", "f18", "f19", "f20", "f21", "f22",
59  "f23", "f24", "f25", "f26", "f27", "f28", "f29", "f30",
60  "f31", "fpscr"
61 };
62 #endif
63 
64 void
66 {
67  oldState = state[current];
68  current = (current + 1) % 2;
69  newState = state[current];
70 
71  memcpy(newState, oldState, sizeof(state[0]));
72 
73  uint64_t diffVector;
74  parent->read(&diffVector, sizeof(diffVector));
75  diffVector = letoh(diffVector);
76 
77  int changes = 0;
78  for (int i = 0; i < STATE_NUMVALS; i++) {
79  if (diffVector & 0x1) {
80  changed[i] = true;
81  changes++;
82  } else {
83  changed[i] = false;
84  }
85  diffVector >>= 1;
86  }
87 
88  uint64_t values[changes];
89  parent->read(values, sizeof(values));
90  int pos = 0;
91  for (int i = 0; i < STATE_NUMVALS; i++) {
92  if (changed[i]) {
93  newState[i] = letoh(values[pos++]);
94  changed[i] = (newState[i] != oldState[i]);
95  }
96  }
97 }
98 
99 void
101 {
102  oldState = state[current];
103  current = (current + 1) % 2;
104  newState = state[current];
105 
106  // Regular int regs
107  for (int i = 0; i < 15; i++) {
108  newState[i] = tc->readIntReg(i);
109  changed[i] = (oldState[i] != newState[i]);
110  }
111 
112  //R15, aliased with the PC
113  newState[STATE_PC] = tc->pcState().npc();
114  changed[STATE_PC] = (newState[STATE_PC] != oldState[STATE_PC]);
115 
116  //CPSR
117  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
118  cpsr.nz = tc->readCCReg(CCREG_NZ);
119  cpsr.c = tc->readCCReg(CCREG_C);
120  cpsr.v = tc->readCCReg(CCREG_V);
121  cpsr.ge = tc->readCCReg(CCREG_GE);
122 
123  newState[STATE_CPSR] = cpsr;
124  changed[STATE_CPSR] = (newState[STATE_CPSR] != oldState[STATE_CPSR]);
125 
126  for (int i = 0; i < NumVecV7ArchRegs; i++) {
127  auto vec(tc->readVecReg(RegId(VecRegClass,i))
128  .as<uint64_t, MaxSveVecLenInDWords>());
129  newState[STATE_F0 + 2*i] = vec[0];
130  newState[STATE_F0 + 2*i + 1] = vec[1];
131  }
132  newState[STATE_FPSCR] = tc->readMiscRegNoEffect(MISCREG_FPSCR) |
133  tc->readCCReg(CCREG_FP);
134 }
135 
136 void
138 {
139  ThreadContext *tc = record->getThread();
140  // This area is read only on the target. It can't stop there to tell us
141  // what's going on, so we should skip over anything there also.
142  if (tc->nextInstAddr() > 0xffff0000)
143  return;
144  nState.update(this);
145  mState.update(tc);
146 
147  // If a syscall just happened native trace needs another tick
148  if ((mState.oldState[STATE_PC] == nState.oldState[STATE_PC]) &&
149  (mState.newState[STATE_PC] - 4 == nState.newState[STATE_PC])) {
150  DPRINTF(ExecRegDelta, "Advancing to match PCs after syscall\n");
151  nState.update(this);
152 
153  }
154 
155  bool errorFound = false;
156  // Regular int regs
157  for (int i = 0; i < STATE_NUMVALS; i++) {
158  if (nState.changed[i] || mState.changed[i]) {
159  bool oldMatch = (mState.oldState[i] == nState.oldState[i]);
160  bool newMatch = (mState.newState[i] == nState.newState[i]);
161  if (oldMatch && newMatch) {
162  // The more things change, the more they stay the same.
163  continue;
164  }
165 
166  errorFound = true;
167 
168 #ifndef NDEBUG
169  const char *vergence = " ";
170  if (oldMatch && !newMatch) {
171  vergence = "<>";
172  } else if (!oldMatch && newMatch) {
173  vergence = "><";
174  }
175 
176  if (!nState.changed[i]) {
177  DPRINTF(ExecRegDelta, "%s [%5s] "\
178  "Native: %#010x "\
179  "M5: %#010x => %#010x\n",
180  vergence, regNames[i],
181  nState.newState[i],
182  mState.oldState[i], mState.newState[i]);
183  } else if (!mState.changed[i]) {
184  DPRINTF(ExecRegDelta, "%s [%5s] "\
185  "Native: %#010x => %#010x "\
186  "M5: %#010x \n",
187  vergence, regNames[i],
188  nState.oldState[i], nState.newState[i],
189  mState.newState[i]);
190  } else {
191  DPRINTF(ExecRegDelta, "%s [%5s] "\
192  "Native: %#010x => %#010x "\
193  "M5: %#010x => %#010x\n",
194  vergence, regNames[i],
195  nState.oldState[i], nState.newState[i],
196  mState.oldState[i], mState.newState[i]);
197  }
198 #endif
199  }
200  }
201  if (errorFound) {
202  StaticInstPtr inst = record->getStaticInst();
203  assert(inst);
204  bool ran = true;
205  if (inst->isMicroop()) {
206  ran = false;
207  inst = record->getMacroStaticInst();
208  }
209  assert(inst);
210  record->traceInst(inst, ran);
211 
212  bool pcError = (mState.newState[STATE_PC] !=
213  nState.newState[STATE_PC]);
214  if (stopOnPCError && pcError)
215  panic("Native trace detected an error in control flow!");
216  }
217 }
218 
219 } // namespace Trace
220 
222 //
223 // ExeTracer Simulation Object
224 //
226 ArmNativeTraceParams::create()
227 {
228  return new Trace::ArmNativeTrace(this);
229 }
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
#define DPRINTF(x,...)
Definition: trace.hh:222
StaticInstPtr getMacroStaticInst() const
Definition: insttracer.hh:228
Bitfield< 7 > i
virtual TheISA::PCState pcState() const =0
virtual RegVal readIntReg(RegIndex reg_idx) const =0
T letoh(T value)
Definition: byteswap.hh:141
virtual RegVal readCCReg(RegIndex reg_idx) const =0
ThreadContext is the external interface to all thread state for anything outside of the CPU...
virtual const VecRegContainer & readVecReg(const RegId &reg) const =0
ThreadContext * getThread() const
Definition: insttracer.hh:225
constexpr unsigned MaxSveVecLenInDWords
Definition: types.hh:768
VecRegT< VecElem, NumElems, true > as() const
View interposers.
Definition: vec_reg.hh:386
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
const int NumVecV7ArchRegs
Definition: registers.hh:93
void traceInst(const StaticInstPtr &inst, bool ran)
Definition: exetrace.cc:63
virtual Addr nextInstAddr() const =0
void read(void *ptr, size_t size)
Definition: nativetrace.hh:101
void update(NativeTrace *parent)
Definition: nativetrace.cc:65
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
Vector Register.
Definition: reg_class.hh:56
virtual RegVal readMiscReg(RegIndex misc_reg)=0
bool isMicroop() const
Definition: static_inst.hh:199
void check(NativeTraceRecord *record)
Definition: nativetrace.cc:137
StaticInstPtr getStaticInst() const
Definition: insttracer.hh:226

Generated on Mon Jun 8 2020 15:34:40 for gem5 by doxygen 1.8.13