gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exec_context.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015 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) 2002-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  * Authors: Kevin Lim
41  * Andreas Sandberg
42  * Mitch Hayenga
43  */
44 
45 #ifndef __CPU_SIMPLE_EXEC_CONTEXT_HH__
46 #define __CPU_SIMPLE_EXEC_CONTEXT_HH__
47 
48 #include "arch/registers.hh"
49 #include "base/types.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/base.hh"
52 #include "cpu/exec_context.hh"
53 #include "cpu/simple/base.hh"
54 #include "cpu/static_inst_fwd.hh"
55 #include "cpu/translation.hh"
56 #include "mem/request.hh"
57 
58 class BaseSimpleCPU;
59 
61  protected:
66 
67  public:
70 
71  // This is the offset from the current pc that fetch should be performed
73  // This flag says to stay at the current pc. This is useful for
74  // instructions which go beyond MachInst boundaries.
75  bool stayAtPC;
76 
77  // Branch prediction
79 
82  // Number of simulated instructions
87 
88  // Number of integer alu accesses
90 
91  // Number of float alu accesses
93 
94  // Number of function calls/returns
96 
97  // Conditional control instructions;
99 
100  // Number of int instructions
102 
103  // Number of float instructions
105 
106  // Number of integer register file accesses
109 
110  // Number of float register file accesses
113 
114  // Number of condition code register file accesses
117 
118  // Number of simulated memory references
122 
123  // Number of idle cycles
125 
126  // Number of busy cycles
128 
129  // Number of simulated loads
131 
132  // Number of idle cycles
135 
136  // Number of cycles stalled for I-cache responses
139 
140  // Number of cycles stalled for D-cache responses
143 
152 
153  // Instruction mix histogram by OpClass
155 
156  public:
159  : cpu(_cpu), thread(_thread), fetchOffset(0), stayAtPC(false),
161  { }
162 
164  IntReg readIntRegOperand(const StaticInst *si, int idx) override
165  {
166  numIntRegReads++;
167  return thread->readIntReg(si->srcRegIdx(idx));
168  }
169 
171  void setIntRegOperand(const StaticInst *si, int idx, IntReg val) override
172  {
173  numIntRegWrites++;
174  thread->setIntReg(si->destRegIdx(idx), val);
175  }
176 
178  FloatReg readFloatRegOperand(const StaticInst *si, int idx) override
179  {
180  numFpRegReads++;
181  int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
182  return thread->readFloatReg(reg_idx);
183  }
184 
188  {
189  numFpRegReads++;
190  int reg_idx = si->srcRegIdx(idx) - TheISA::FP_Reg_Base;
191  return thread->readFloatRegBits(reg_idx);
192  }
193 
195  void setFloatRegOperand(const StaticInst *si, int idx,
196  FloatReg val) override
197  {
198  numFpRegWrites++;
199  int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
200  thread->setFloatReg(reg_idx, val);
201  }
202 
205  void setFloatRegOperandBits(const StaticInst *si, int idx,
206  FloatRegBits val) override
207  {
208  numFpRegWrites++;
209  int reg_idx = si->destRegIdx(idx) - TheISA::FP_Reg_Base;
210  thread->setFloatRegBits(reg_idx, val);
211  }
212 
213  CCReg readCCRegOperand(const StaticInst *si, int idx) override
214  {
215  numCCRegReads++;
216  int reg_idx = si->srcRegIdx(idx) - TheISA::CC_Reg_Base;
217  return thread->readCCReg(reg_idx);
218  }
219 
220  void setCCRegOperand(const StaticInst *si, int idx, CCReg val) override
221  {
222  numCCRegWrites++;
223  int reg_idx = si->destRegIdx(idx) - TheISA::CC_Reg_Base;
224  thread->setCCReg(reg_idx, val);
225  }
226 
227  MiscReg readMiscRegOperand(const StaticInst *si, int idx) override
228  {
229  numIntRegReads++;
230  int reg_idx = si->srcRegIdx(idx) - TheISA::Misc_Reg_Base;
231  return thread->readMiscReg(reg_idx);
232  }
233 
234  void setMiscRegOperand(const StaticInst *si, int idx,
235  const MiscReg &val) override
236  {
237  numIntRegWrites++;
238  int reg_idx = si->destRegIdx(idx) - TheISA::Misc_Reg_Base;
239  thread->setMiscReg(reg_idx, val);
240  }
241 
246  MiscReg readMiscReg(int misc_reg) override
247  {
248  numIntRegReads++;
249  return thread->readMiscReg(misc_reg);
250  }
251 
256  void setMiscReg(int misc_reg, const MiscReg &val) override
257  {
258  numIntRegWrites++;
259  thread->setMiscReg(misc_reg, val);
260  }
261 
262  PCState pcState() const override
263  {
264  return thread->pcState();
265  }
266 
267  void pcState(const PCState &val) override
268  {
269  thread->pcState(val);
270  }
271 
272 
278  void setEA(Addr EA) override
279  { panic("BaseSimpleCPU::setEA() not implemented\n"); }
280 
286  Addr getEA() const override
287  { panic("BaseSimpleCPU::getEA() not implemented\n"); }
288 
289  Fault readMem(Addr addr, uint8_t *data, unsigned int size,
290  Request::Flags flags) override
291  {
292  return cpu->readMem(addr, data, size, flags);
293  }
294 
296  Request::Flags flags) override
297  {
298  return cpu->initiateMemRead(addr, size, flags);
299  }
300 
301  Fault writeMem(uint8_t *data, unsigned int size, Addr addr,
302  Request::Flags flags, uint64_t *res) override
303  {
304  return cpu->writeMem(data, size, addr, flags, res);
305  }
306 
310  void setStCondFailures(unsigned int sc_failures) override
311  {
312  thread->setStCondFailures(sc_failures);
313  }
314 
318  unsigned int readStCondFailures() const override
319  {
320  return thread->readStCondFailures();
321  }
322 
326  void syscall(int64_t callnum, Fault *fault) override
327  {
328  if (FullSystem)
329  panic("Syscall emulation isn't available in FS mode.");
330 
331  thread->syscall(callnum, fault);
332  }
333 
335  ThreadContext *tcBase() override
336  {
337  return thread->getTC();
338  }
339 
344  Fault hwrei() override
345  {
346  return thread->hwrei();
347  }
348 
353  bool simPalCheck(int palFunc) override
354  {
355  return thread->simPalCheck(palFunc);
356  }
357 
358  bool readPredicate() override
359  {
360  return thread->readPredicate();
361  }
362 
363  void setPredicate(bool val) override
364  {
365  thread->setPredicate(val);
366 
367  if (cpu->traceData) {
368  cpu->traceData->setPredicate(val);
369  }
370  }
371 
375  void demapPage(Addr vaddr, uint64_t asn) override
376  {
377  thread->demapPage(vaddr, asn);
378  }
379 
380  void armMonitor(Addr address) override
381  {
382  cpu->armMonitor(thread->threadId(), address);
383  }
384 
385  bool mwait(PacketPtr pkt) override
386  {
387  return cpu->mwait(thread->threadId(), pkt);
388  }
389 
390  void mwaitAtomic(ThreadContext *tc) override
391  {
392  cpu->mwaitAtomic(thread->threadId(), tc, thread->dtb);
393  }
394 
395  AddressMonitor *getAddrMonitor() override
396  {
397  return cpu->getCpuAddrMonitor(thread->threadId());
398  }
399 
400 #if THE_ISA == MIPS_ISA
402  override
403  {
404  panic("Simple CPU models do not support multithreaded "
405  "register access.");
406  }
407 
408  void setRegOtherThread(int regIdx, MiscReg val,
409  ThreadID tid = InvalidThreadID) override
410  {
411  panic("Simple CPU models do not support multithreaded "
412  "register access.");
413  }
414 
415 #endif
416 
417 };
418 
419 #endif // __CPU_EXEC_CONTEXT_HH__
MiscReg readMiscReg(int misc_reg) override
Reads a miscellaneous register, handling any architectural side effects due to reading that register...
uint64_t readIntReg(int reg_idx)
uint8_t CCReg
Definition: registers.hh:57
Stats::Scalar numFpAluAccesses
Definition: exec_context.hh:92
void setMiscReg(int misc_reg, const MiscReg &val, ThreadID tid=0)
Stats::Average notIdleFraction
A stat that calculates the per tick average of a value.
Definition: statistics.hh:2485
Fault writeMem(uint8_t *data, unsigned int size, Addr addr, Request::Flags flags, uint64_t *res) override
For atomic-mode contexts, perform an atomic memory write operation.
FloatReg readFloatRegOperand(const StaticInst *si, int idx) override
Reads a floating point register of single register width.
#define panic(...)
Definition: misc.hh:153
MiscReg readMiscRegOperand(const StaticInst *si, int idx) override
Stats::Scalar numLoadInsts
Stats::Scalar numIntAluAccesses
Definition: exec_context.hh:89
Stats::Vector statExecutedInstType
BaseSimpleCPU * cpu
Definition: exec_context.hh:68
TheISA::FloatRegBits FloatRegBits
Definition: exec_context.hh:64
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
void setCCRegOperand(const StaticInst *si, int idx, CCReg val) override
bool readPredicate() override
ip6_addr_t addr
Definition: inet.hh:335
TheISA::FloatReg FloatReg
Definition: exec_context.hh:63
RegIndex destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:188
TheISA::PCState PCState
Definition: exec_context.hh:75
Stats::Scalar numCCRegReads
bool simPalCheck(int palFunc)
Check for special simulator handling of specific PAL calls.
Definition: ev5.cc:490
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
Stats::Scalar numFpRegWrites
Stats::Scalar numIntRegReads
uint64_t MiscReg
Definition: registers.hh:54
The SimpleThread object provides a combination of the ThreadState object and the ThreadContext interf...
TheISA::IntReg IntReg
Definition: exec_context.hh:74
A vector of scalar stats.
Definition: statistics.hh:2499
Stats::Formula numIdleCycles
unsigned int readStCondFailures() const override
Returns the number of consecutive store conditional failures.
void setStCondFailures(unsigned sc_failures)
void setStCondFailures(unsigned int sc_failures) override
Sets the number of consecutive store conditional failures.
TheISA::MiscReg MiscReg
Definition: exec_context.hh:62
ThreadContext is the external interface to all thread state for anything outside of the CPU...
TheISA::CCReg CCReg
Definition: exec_context.hh:80
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
void setCCReg(int reg_idx, CCReg val)
TheISA::TLB * dtb
PCState pcState() const override
void syscall(int64_t callnum, Fault *fault)
Bitfield< 63 > val
Definition: misc.hh:770
ThreadID threadId() const
Definition: thread_state.hh:80
const char data[]
Definition: circlebuf.cc:43
Bitfield< 15, 0 > si
Definition: types.hh:55
Stats::Scalar numOps
Definition: exec_context.hh:86
unsigned readStCondFailures()
TheISA::FloatReg FloatReg
Definition: exec_context.hh:76
void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val) override
Sets the bits of a floating point register of single width to a binary value.
Stats::Scalar icacheStallCycles
AddressMonitor * getAddrMonitor() override
TheISA::CCReg CCReg
Definition: exec_context.hh:65
void setPredicate(bool val) override
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:72
FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx) override
Reads a floating point register in its binary format, instead of by value.
virtual Fault initiateMemRead(Addr addr, unsigned size, Request::Flags flags)=0
void mwaitAtomic(ThreadContext *tc) override
uint64_t FloatRegBits
Definition: registers.hh:51
TheISA::FloatRegBits FloatRegBits
Definition: exec_context.hh:77
Stats::Scalar numPredictedBranches
Number of branches predicted as taken.
MiscReg readMiscReg(int misc_reg, ThreadID tid=0)
ThreadContext * tcBase() override
Returns a pointer to the ThreadContext.
Stats::Scalar dcacheStallCycles
Stats::Scalar numFpInsts
Stats::Scalar numIntRegWrites
void setPredicate(bool val)
Definition: insttracer.hh:182
Stats::Scalar numMemRefs
void setMiscRegOperand(const StaticInst *si, int idx, const MiscReg &val) override
MiscReg readRegOtherThread(int regIdx, ThreadID tid=InvalidThreadID) override
void demapPage(Addr vaddr, uint64_t asn) override
Invalidate a page in the DTLB and ITLB.
double FloatReg
Definition: registers.hh:50
Stats::Scalar numIntInsts
void demapPage(Addr vaddr, uint64_t asn)
Stats::Scalar numInsts
Definition: exec_context.hh:84
void setFloatRegBits(int reg_idx, FloatRegBits val)
SimpleThread * thread
Definition: exec_context.hh:69
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
ThreadContext * getTC()
Returns the pointer to this SimpleThread's ThreadContext.
Fault hwrei()
Definition: ev5.cc:467
Stats::Formula numBusyCycles
int64_t Counter
Statistics counter type.
Definition: types.hh:58
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
void setFloatReg(int reg_idx, FloatReg val)
RegIndex srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:192
void pcState(const PCState &val) override
Stats::Scalar numBranches
const ThreadID InvalidThreadID
Definition: types.hh:172
void setRegOtherThread(int regIdx, MiscReg val, ThreadID tid=InvalidThreadID) override
Counter numInst
PER-THREAD STATS.
Definition: exec_context.hh:83
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2895
TheISA::PCState pcState()
CCReg readCCReg(int reg_idx)
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
FloatReg readFloatReg(int reg_idx)
bool mwait(PacketPtr pkt) override
Stats::Scalar numCallsReturns
Definition: exec_context.hh:95
void setIntReg(int reg_idx, uint64_t val)
void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val) override
Sets a floating point register of single width to a value.
void setMiscReg(int misc_reg, const MiscReg &val) override
Sets a miscellaneous register, handling any architectural side effects due to writing that register...
int size()
Definition: pagetable.hh:146
Stats::Scalar numFpRegReads
virtual Fault writeMem(uint8_t *data, unsigned size, Addr addr, Request::Flags flags, uint64_t *res)=0
void setIntRegOperand(const StaticInst *si, int idx, IntReg val) override
Sets an integer register to a value.
bool readPredicate()
FloatRegBits readFloatRegBits(int reg_idx)
Trace::InstRecord * traceData
Definition: base.hh:99
void setEA(Addr EA) override
Record the effective address of the instruction.
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
TheISA::PCState predPC
Definition: exec_context.hh:78
Fault hwrei() override
Somewhat Alpha-specific function that handles returning from an error or interrupt.
CCReg readCCRegOperand(const StaticInst *si, int idx) override
Base, ISA-independent static instruction class.
Definition: static_inst.hh:68
Stats::Scalar numStoreInsts
virtual Fault readMem(Addr addr, uint8_t *data, unsigned size, Request::Flags flags)=0
IntReg readIntRegOperand(const StaticInst *si, int idx) override
Reads an integer register.
Stats::Scalar numCCRegWrites
Stats::Formula idleFraction
SimpleExecContext(BaseSimpleCPU *_cpu, SimpleThread *_thread)
Constructor.
Fault readMem(Addr addr, uint8_t *data, unsigned int size, Request::Flags flags) override
Perform an atomic memory read operation.
void syscall(int64_t callnum, Fault *fault) override
Executes a syscall specified by the callnum.
void armMonitor(Addr address) override
bool simPalCheck(int palFunc) override
Check for special simulator handling of specific PAL calls.
Addr getEA() const override
Get the effective address of the instruction.
TheISA::MiscReg MiscReg
Definition: exec_context.hh:78
Fault initiateMemRead(Addr addr, unsigned int size, Request::Flags flags) override
Initiate a timing memory read operation.
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
Stats::Scalar numBranchMispred
Number of misprediced branches.
void setPredicate(bool val)
Stats::Scalar numCondCtrlInsts
Definition: exec_context.hh:98

Generated on Fri Jun 9 2017 13:03:42 for gem5 by doxygen 1.8.6