gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dyn_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 ARM Limited
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2004-2006 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Authors: Kevin Lim
42  */
43 
44 #ifndef __CPU_O3_DYN_INST_HH__
45 #define __CPU_O3_DYN_INST_HH__
46 
47 #include <array>
48 
49 #include "arch/isa_traits.hh"
50 #include "config/the_isa.hh"
51 #include "cpu/o3/cpu.hh"
52 #include "cpu/o3/isa_specific.hh"
53 #include "cpu/base_dyn_inst.hh"
54 #include "cpu/inst_seq.hh"
55 #include "cpu/reg_class.hh"
56 
57 class Packet;
58 
59 template <class Impl>
60 class BaseO3DynInst : public BaseDynInst<Impl>
61 {
62  public:
64  typedef typename Impl::O3CPU O3CPU;
65 
77 
80 
81  enum {
82  MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
83  MaxInstDestRegs = TheISA::MaxInstDestRegs //< Max dest regs
84  };
85 
86  public:
90  InstSeqNum seq_num, O3CPU *cpu);
91 
93  BaseO3DynInst(const StaticInstPtr &_staticInst,
94  const StaticInstPtr &_macroop);
95 
97 
99  Fault execute();
100 
102  Fault initiateAcc();
103 
106 
107  private:
109  void initVars();
110 
111  protected:
113  std::array<MiscReg, TheISA::MaxMiscDestRegs> _destMiscRegVal;
114 
119  std::array<short, TheISA::MaxMiscDestRegs> _destMiscRegIdx;
120 
123 
124 
125  public:
126 #if TRACING_ON
127 
128  Tick fetchTick; // instruction fetch is completed.
129  int32_t decodeTick; // instruction enters decode phase
130  int32_t renameTick; // instruction enters rename phase
131  int32_t dispatchTick;
132  int32_t issueTick;
133  int32_t completeTick;
134  int32_t commitTick;
135  int32_t storeTick;
136 #endif
137 
141  MiscReg readMiscReg(int misc_reg)
142  {
143  return this->cpu->readMiscReg(misc_reg, this->threadNumber);
144  }
145 
149  void setMiscReg(int misc_reg, const MiscReg &val)
150  {
157  for (int idx = 0; idx < _numDestMiscRegs; idx++) {
158  if (_destMiscRegIdx[idx] == misc_reg) {
159  _destMiscRegVal[idx] = val;
160  return;
161  }
162  }
163 
164  assert(_numDestMiscRegs < TheISA::MaxMiscDestRegs);
165  _destMiscRegIdx[_numDestMiscRegs] = misc_reg;
167  _numDestMiscRegs++;
168  }
169 
174  {
175  return this->cpu->readMiscReg(
176  si->srcRegIdx(idx) - TheISA::Misc_Reg_Base,
177  this->threadNumber);
178  }
179 
183  void setMiscRegOperand(const StaticInst *si, int idx,
184  const MiscReg &val)
185  {
186  int misc_reg = si->destRegIdx(idx) - TheISA::Misc_Reg_Base;
187  setMiscReg(misc_reg, val);
188  }
189 
192  {
193  // @todo: Pretty convoluted way to avoid squashing from happening when
194  // using the TC during an instruction's execution (specifically for
195  // instructions that have side-effects that use the TC). Fix this.
196  // See cpu/o3/dyn_inst_impl.hh.
197  bool no_squash_from_TC = this->thread->noSquashFromTC;
198  this->thread->noSquashFromTC = true;
199 
200  for (int i = 0; i < _numDestMiscRegs; i++)
201  this->cpu->setMiscReg(
202  _destMiscRegIdx[i], _destMiscRegVal[i], this->threadNumber);
203 
204  this->thread->noSquashFromTC = no_squash_from_TC;
205  }
206 
208  {
209 
210  for (int idx = 0; idx < this->numDestRegs(); idx++) {
211  PhysRegIndex prev_phys_reg = this->prevDestRegIdx(idx);
212  TheISA::RegIndex original_dest_reg =
213  this->staticInst->destRegIdx(idx);
214  switch (regIdxToClass(original_dest_reg)) {
215  case IntRegClass:
216  this->setIntRegOperand(this->staticInst.get(), idx,
217  this->cpu->readIntReg(prev_phys_reg));
218  break;
219  case FloatRegClass:
220  this->setFloatRegOperandBits(this->staticInst.get(), idx,
221  this->cpu->readFloatRegBits(prev_phys_reg));
222  break;
223  case CCRegClass:
224  this->setCCRegOperand(this->staticInst.get(), idx,
225  this->cpu->readCCReg(prev_phys_reg));
226  break;
227  case MiscRegClass:
228  // no need to forward misc reg values
229  break;
230  }
231  }
232  }
234  Fault hwrei();
236  void trap(const Fault &fault);
237  bool simPalCheck(int palFunc);
238 
240  void syscall(int64_t callnum, Fault *fault);
241 
242  public:
243 
244  // The register accessor methods provide the index of the
245  // instruction's operand (e.g., 0 or 1), not the architectural
246  // register index, to simplify the implementation of register
247  // renaming. We find the architectural register index by indexing
248  // into the instruction's own operand index table. Note that a
249  // raw pointer to the StaticInst is provided instead of a
250  // ref-counted StaticInstPtr to redice overhead. This is fine as
251  // long as these methods don't copy the pointer into any long-term
252  // storage (which is pretty hard to imagine they would have reason
253  // to do).
254 
256  {
257  return this->cpu->readIntReg(this->_srcRegIdx[idx]);
258  }
259 
261  {
262  return this->cpu->readFloatReg(this->_srcRegIdx[idx]);
263  }
264 
266  {
267  return this->cpu->readFloatRegBits(this->_srcRegIdx[idx]);
268  }
269 
271  {
272  return this->cpu->readCCReg(this->_srcRegIdx[idx]);
273  }
274 
278  void setIntRegOperand(const StaticInst *si, int idx, IntReg val)
279  {
280  this->cpu->setIntReg(this->_destRegIdx[idx], val);
282  }
283 
284  void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
285  {
286  this->cpu->setFloatReg(this->_destRegIdx[idx], val);
288  }
289 
290  void setFloatRegOperandBits(const StaticInst *si, int idx,
292  {
293  this->cpu->setFloatRegBits(this->_destRegIdx[idx], val);
295  }
296 
297  void setCCRegOperand(const StaticInst *si, int idx, CCReg val)
298  {
299  this->cpu->setCCReg(this->_destRegIdx[idx], val);
301  }
302 
303 #if THE_ISA == MIPS_ISA
305  {
306  panic("MIPS MT not defined for O3 CPU.\n");
307  return 0;
308  }
309 
310  void setRegOtherThread(int misc_reg, MiscReg val, ThreadID tid)
311  {
312  panic("MIPS MT not defined for O3 CPU.\n");
313  }
314 #endif
315 
316  public:
322  {
323  return this->staticInst->eaCompInst()->execute(this, this->traceData);
324  }
325 
331  {
332  return this->staticInst->memAccInst()->execute(this, this->traceData);
333  }
334 };
335 
336 #endif // __CPU_O3_ALPHA_DYN_INST_HH__
337 
TheISA::ExtMachInst ExtMachInst
Extended machine instruction type.
Definition: dyn_inst.hh:69
uint8_t CCReg
Definition: registers.hh:57
bool simPalCheck(int palFunc)
Check for special simulator handling of specific PAL calls.
Floating-point register.
Definition: reg_class.hh:43
TheISA::CCReg CCReg
Definition: dyn_inst.hh:76
Bitfield< 7 > i
Definition: miscregs.hh:1378
FloatRegBits readFloatRegOperandBits(const StaticInst *si, int idx)
Reads a floating point register in its binary format, instead of by value.
Definition: dyn_inst.hh:265
IntReg readIntRegOperand(const StaticInst *si, int idx)
Reads an integer register.
Definition: dyn_inst.hh:255
#define panic(...)
Definition: misc.hh:153
void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val)
Records an fp register being set to an integer value.
Definition: dyn_inst.hh:290
Control (misc) register.
Definition: reg_class.hh:45
TheISA::FloatRegBits FloatRegBits
Definition: dyn_inst.hh:75
FloatReg readFloatRegOperand(const StaticInst *si, int idx)
Reads a floating point register of single register width.
Definition: dyn_inst.hh:260
Fault fault
The kind of fault this instruction has generated.
T * get() const
Directly access the pointer itself without taking a reference.
Definition: refcnt.hh:180
RegIndex destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:188
std::array< PhysRegIndex, TheISA::MaxInstDestRegs > _destRegIdx
Physical register index of the destination registers of this instruction.
void setCCRegOperand(const StaticInst *si, int idx, CCReg val)
Records a CC register being set to a value.
TheISA::FloatReg FloatReg
Definition: dyn_inst.hh:74
virtual Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const =0
uint64_t MiscReg
Definition: registers.hh:54
Trace::InstRecord * traceData
InstRecord that tracks this instructions.
TheISA::IntReg IntReg
Definition: exec_context.hh:74
MiscReg readRegOtherThread(int misc_reg, ThreadID tid)
Definition: dyn_inst.hh:304
Fault completeAcc(PacketPtr pkt)
Completes the access.
void trap(const Fault &fault)
Traps to handle specified fault.
Fault hwrei()
Calls hardware return from error interrupt.
const int MaxInstSrcRegs
Definition: registers.hh:56
TheISA::RegIndex RegIndex
Logical register index type.
Definition: dyn_inst.hh:71
void setIntRegOperand(const StaticInst *si, int idx, IntReg val)
Records an integer register being set to a value.
TheISA::CCReg CCReg
Definition: exec_context.hh:80
Bitfield< 63 > val
Definition: misc.hh:770
uint32_t MachInst
Definition: types.hh:40
const int MaxMiscDestRegs
Definition: registers.hh:44
Bitfield< 15, 0 > si
Definition: types.hh:55
TheISA::FloatReg FloatReg
Definition: exec_context.hh:76
CCReg readCCRegOperand(const StaticInst *si, int idx)
Definition: dyn_inst.hh:270
uint8_t _numDestMiscRegs
Number of destination misc.
Definition: dyn_inst.hh:122
void setIntRegOperand(const StaticInst *si, int idx, IntReg val)
Definition: dyn_inst.hh:278
uint8_t RegIndex
Definition: registers.hh:46
uint64_t FloatRegBits
Definition: registers.hh:51
TheISA::FloatRegBits FloatRegBits
Definition: exec_context.hh:77
void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
Records an fp register being set to a value.
Definition: dyn_inst.hh:284
uint64_t Tick
Tick count type.
Definition: types.hh:63
void syscall(int64_t callnum, Fault *fault)
Emulates a syscall.
std::array< MiscReg, TheISA::MaxMiscDestRegs > _destMiscRegVal
Values to be written to the destination misc.
Definition: dyn_inst.hh:113
Condition-code register.
Definition: reg_class.hh:44
Fault memAccess()
Does the memory access part of a memory instruction.
Definition: dyn_inst.hh:330
uint64_t InstSeqNum
Definition: inst_seq.hh:40
std::array< short, TheISA::MaxMiscDestRegs > _destMiscRegIdx
Indexes of the destination misc.
Definition: dyn_inst.hh:119
BaseO3DynInst(const StaticInstPtr &staticInst, const StaticInstPtr &macroop, TheISA::PCState pc, TheISA::PCState predPC, InstSeqNum seq_num, O3CPU *cpu)
BaseDynInst constructor given a binary instruction.
const StaticInstPtr staticInst
The StaticInst used by this BaseDynInst.
double FloatReg
Definition: registers.hh:50
uint64_t ExtMachInst
Definition: types.hh:41
TheISA::PCState pc
PC state for this instruction.
Fault calcEA()
Calculates EA part of a memory instruction.
Definition: dyn_inst.hh:321
Fault execute()
Executes the instruction.
int8_t numDestRegs() const
Returns the number of destination registers.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
RegIndex srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:192
TheISA::MiscReg readMiscRegOperand(const StaticInst *si, int idx)
Reads a misc.
Definition: dyn_inst.hh:173
void updateMiscRegs()
Called at the commit stage to update the misc.
Definition: dyn_inst.hh:191
virtual const StaticInstPtr & eaCompInst() const
Memory references only: returns "fake" instruction representing the effective address part of the mem...
Definition: static_inst.hh:206
void setMiscRegOperand(const StaticInst *si, int idx, const MiscReg &val)
Sets a misc.
Definition: dyn_inst.hh:183
uint64_t IntReg
Definition: registers.hh:47
int16_t ThreadID
Thread index/ID type.
Definition: types.hh:171
PhysRegIndex prevDestRegIdx(int idx) const
Returns the physical register index of the previous physical register that remapped to the same logic...
void setCCRegOperand(const StaticInst *si, int idx, CCReg val)
Records a CC register being set to a value.
Definition: dyn_inst.hh:297
ImplCPU * cpu
Pointer to the Impl's CPU object.
void setRegOtherThread(int misc_reg, MiscReg val, ThreadID tid)
Definition: dyn_inst.hh:310
TheISA::MachInst MachInst
Binary machine instruction type.
Definition: dyn_inst.hh:67
Impl::O3CPU O3CPU
Typedef for the CPU.
Definition: dyn_inst.hh:64
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
MiscReg readMiscReg(int misc_reg)
Reads a misc.
Definition: dyn_inst.hh:141
void setMiscReg(int misc_reg, const MiscReg &val)
Sets a misc.
Definition: dyn_inst.hh:149
void setFloatRegOperandBits(const StaticInst *si, int idx, FloatRegBits val)
Records an fp register being set to an integer value.
std::array< PhysRegIndex, TheISA::MaxInstSrcRegs > _srcRegIdx
Physical register index of the source registers of this instruction.
short int PhysRegIndex
Definition: comm.hh:57
TheISA::MiscReg MiscReg
Misc register index type.
Definition: dyn_inst.hh:79
Base, ISA-independent static instruction class.
Definition: static_inst.hh:68
Defines a dynamic instruction context.
const StaticInstPtr macroop
The Macroop if one exists.
Integer register.
Definition: reg_class.hh:42
TheISA::PCState predPC
Predicted PC state after this instruction.
RegClass regIdxToClass(TheISA::RegIndex reg_idx, TheISA::RegIndex *rel_reg_idx=NULL)
Map a 'unified' architectural register index to its register class.
Definition: reg_class.hh:66
TheISA::IntReg IntReg
Integer register index type.
Definition: dyn_inst.hh:73
virtual const StaticInstPtr & memAccInst() const
Memory references only: returns "fake" instruction representing the memory access part of the memory ...
Definition: static_inst.hh:215
ThreadID threadNumber
The thread this instruction is from.
void setFloatRegOperand(const StaticInst *si, int idx, FloatReg val)
Records an fp register being set to a value.
TheISA::MiscReg MiscReg
Definition: exec_context.hh:78
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
void forwardOldRegs()
Definition: dyn_inst.hh:207
ImplState * thread
Pointer to the thread state.
void initVars()
Initializes variables.
Fault initiateAcc()
Initiates the access.

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