gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
static_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * Copyright (c) 2013 Advanced Micro Devices, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met: redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer;
10  * redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Authors: Steve Reinhardt
30  */
31 
32 #ifndef __CPU_STATIC_INST_HH__
33 #define __CPU_STATIC_INST_HH__
34 
35 #include <bitset>
36 #include <string>
37 
38 #include "arch/registers.hh"
39 #include "arch/types.hh"
40 #include "base/misc.hh"
41 #include "base/refcnt.hh"
42 #include "base/types.hh"
43 #include "config/the_isa.hh"
44 #include "cpu/op_class.hh"
45 #include "cpu/static_inst_fwd.hh"
46 #include "cpu/thread_context.hh"
47 #include "enums/StaticInstFlags.hh"
48 
49 // forward declarations
50 class Packet;
51 
52 class ExecContext;
53 
54 class SymbolTable;
55 
56 namespace Trace {
57  class InstRecord;
58 }
59 
68 class StaticInst : public RefCounted, public StaticInstFlags
69 {
70  public:
75 
76  enum {
77  MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
78  MaxInstDestRegs = TheISA::MaxInstDestRegs //< Max dest regs
79  };
80 
81  protected:
82 
84  std::bitset<Num_Flags> flags;
85 
87  OpClass _opClass;
88 
90  int8_t _numSrcRegs;
91 
93  int8_t _numDestRegs;
94 
97 
102 
103  public:
104 
110 
111  int8_t numSrcRegs() const { return _numSrcRegs; }
114  int8_t numDestRegs() const { return _numDestRegs; }
116  int8_t numFPDestRegs() const { return _numFPDestRegs; }
118  int8_t numIntDestRegs() const { return _numIntDestRegs; }
120  int8_t numCCDestRegs() const { return _numCCDestRegs; }
123 
128 
129 
130  bool isNop() const { return flags[IsNop]; }
131 
132  bool isMemRef() const { return flags[IsMemRef]; }
133  bool isLoad() const { return flags[IsLoad]; }
134  bool isStore() const { return flags[IsStore]; }
135  bool isStoreConditional() const { return flags[IsStoreConditional]; }
136  bool isInstPrefetch() const { return flags[IsInstPrefetch]; }
137  bool isDataPrefetch() const { return flags[IsDataPrefetch]; }
138  bool isPrefetch() const { return isInstPrefetch() ||
139  isDataPrefetch(); }
140 
141  bool isInteger() const { return flags[IsInteger]; }
142  bool isFloating() const { return flags[IsFloating]; }
143  bool isCC() const { return flags[IsCC]; }
144 
145  bool isControl() const { return flags[IsControl]; }
146  bool isCall() const { return flags[IsCall]; }
147  bool isReturn() const { return flags[IsReturn]; }
148  bool isDirectCtrl() const { return flags[IsDirectControl]; }
149  bool isIndirectCtrl() const { return flags[IsIndirectControl]; }
150  bool isCondCtrl() const { return flags[IsCondControl]; }
151  bool isUncondCtrl() const { return flags[IsUncondControl]; }
152  bool isCondDelaySlot() const { return flags[IsCondDelaySlot]; }
153 
154  bool isThreadSync() const { return flags[IsThreadSync]; }
155  bool isSerializing() const { return flags[IsSerializing] ||
156  flags[IsSerializeBefore] ||
157  flags[IsSerializeAfter]; }
158  bool isSerializeBefore() const { return flags[IsSerializeBefore]; }
159  bool isSerializeAfter() const { return flags[IsSerializeAfter]; }
160  bool isSquashAfter() const { return flags[IsSquashAfter]; }
161  bool isMemBarrier() const { return flags[IsMemBarrier]; }
162  bool isWriteBarrier() const { return flags[IsWriteBarrier]; }
163  bool isNonSpeculative() const { return flags[IsNonSpeculative]; }
164  bool isQuiesce() const { return flags[IsQuiesce]; }
165  bool isIprAccess() const { return flags[IsIprAccess]; }
166  bool isUnverifiable() const { return flags[IsUnverifiable]; }
167  bool isSyscall() const { return flags[IsSyscall]; }
168  bool isMacroop() const { return flags[IsMacroop]; }
169  bool isMicroop() const { return flags[IsMicroop]; }
170  bool isDelayedCommit() const { return flags[IsDelayedCommit]; }
171  bool isLastMicroop() const { return flags[IsLastMicroop]; }
172  bool isFirstMicroop() const { return flags[IsFirstMicroop]; }
173  //This flag doesn't do anything yet
174  bool isMicroBranch() const { return flags[IsMicroBranch]; }
176 
177  void setFirstMicroop() { flags[IsFirstMicroop] = true; }
178  void setLastMicroop() { flags[IsLastMicroop] = true; }
179  void setDelayedCommit() { flags[IsDelayedCommit] = true; }
180  void setFlag(Flags f) { flags[f] = true; }
181 
183  OpClass opClass() const { return _opClass; }
184 
185 
188  RegIndex destRegIdx(int i) const { return _destRegIdx[i]; }
189 
192  RegIndex srcRegIdx(int i) const { return _srcRegIdx[i]; }
193 
198 
205  virtual const
207 
214  virtual const
216 
219 
220  protected:
221 
226 
233  const char *mnemonic;
234 
239  mutable std::string *cachedDisassembly;
240 
244  virtual std::string
245  generateDisassembly(Addr pc, const SymbolTable *symtab) const = 0;
246 
252  StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
253  : _opClass(__opClass), _numSrcRegs(0), _numDestRegs(0),
255  machInst(_machInst), mnemonic(_mnemonic), cachedDisassembly(0)
256  { }
257 
258  public:
259  virtual ~StaticInst();
260 
261  virtual Fault execute(ExecContext *xc,
262  Trace::InstRecord *traceData) const = 0;
263  virtual Fault eaComp(ExecContext *xc,
264  Trace::InstRecord *traceData) const
265  {
266  panic("eaComp not defined!");
267  }
268 
270  Trace::InstRecord *traceData) const
271  {
272  panic("initiateAcc not defined!");
273  }
274 
275  virtual Fault completeAcc(Packet *pkt, ExecContext *xc,
276  Trace::InstRecord *traceData) const
277  {
278  panic("completeAcc not defined!");
279  }
280 
281  virtual void advancePC(TheISA::PCState &pcState) const = 0;
282 
287  virtual StaticInstPtr fetchMicroop(MicroPC upc) const;
288 
294  virtual TheISA::PCState branchTarget(const TheISA::PCState &pc) const;
295 
303  virtual TheISA::PCState branchTarget(ThreadContext *tc) const;
304 
310  TheISA::PCState &tgt) const;
311 
319  virtual const std::string &disassemble(Addr pc,
320  const SymbolTable *symtab = 0) const;
321 
326  void printFlags(std::ostream &outs, const std::string &separator) const;
327 
329  std::string getName() { return mnemonic; }
330 };
331 
332 #endif // __CPU_STATIC_INST_HH__
void setDelayedCommit()
Definition: static_inst.hh:179
bool isFirstMicroop() const
Definition: static_inst.hh:172
std::string * cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
Definition: static_inst.hh:239
bool isMicroBranch() const
Definition: static_inst.hh:174
int8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:90
Bitfield< 7 > i
Definition: miscregs.hh:1378
bool isDataPrefetch() const
Definition: static_inst.hh:137
#define panic(...)
Definition: misc.hh:153
bool isSyscall() const
Definition: static_inst.hh:167
int8_t _numFPDestRegs
The following are used to track physical register usage for machines with separate int & FP reg files...
Definition: static_inst.hh:98
int8_t _numCCDestRegs
Definition: static_inst.hh:100
bool isSquashAfter() const
Definition: static_inst.hh:160
bool isDelayedCommit() const
Definition: static_inst.hh:170
virtual const std::string & disassemble(Addr pc, const SymbolTable *symtab=0) const
Return string representation of disassembled instruction.
Definition: static_inst.cc:89
int8_t numCCDestRegs() const
Number of coprocesor destination regs.
Definition: static_inst.hh:121
bool isMemBarrier() const
Definition: static_inst.hh:161
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:183
bool hasBranchTarget(const TheISA::PCState &pc, ThreadContext *tc, TheISA::PCState &tgt) const
Return true if the instruction is a control transfer, and if so, return the target address as well...
Definition: static_inst.cc:49
bool isMacroop() const
Definition: static_inst.hh:168
bool isIprAccess() const
Definition: static_inst.hh:165
RegIndex destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
Definition: static_inst.hh:188
bool isMicroop() const
Definition: static_inst.hh:169
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:233
bool isCall() const
Definition: static_inst.hh:146
virtual Fault initiateAcc(ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:269
virtual Fault execute(ExecContext *xc, Trace::InstRecord *traceData) const =0
virtual StaticInstPtr fetchMicroop(MicroPC upc) const
Return the microop that goes with a particular micropc.
Definition: static_inst.cc:66
bool isQuiesce() const
Definition: static_inst.hh:164
std::string getName()
Return name of machine instruction.
Definition: static_inst.hh:329
TheISA::RegIndex RegIndex
Logical register index type.
Definition: static_inst.hh:74
bool isNonSpeculative() const
Definition: static_inst.hh:163
bool isUncondCtrl() const
Definition: static_inst.hh:151
virtual ~StaticInst()
Definition: static_inst.cc:42
const int MaxInstSrcRegs
Definition: registers.hh:56
int8_t _numIntDestRegs
Definition: static_inst.hh:99
OpClass _opClass
See opClass().
Definition: static_inst.hh:87
If you want a reference counting pointer to a mutable object, create it like this: ...
Definition: refcnt.hh:106
ThreadContext is the external interface to all thread state for anything outside of the CPU...
bool isSerializing() const
Definition: static_inst.hh:155
bool isMemRef() const
Definition: static_inst.hh:132
Bitfield< 6 > f
Definition: miscregs.hh:1379
bool isStore() const
Definition: static_inst.hh:134
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:218
bool isSerializeAfter() const
Definition: static_inst.hh:159
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:84
Classes for managing reference counted objects.
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Definition: exec_context.hh:72
uint8_t RegIndex
Definition: registers.hh:46
bool isInteger() const
Definition: static_inst.hh:141
RegIndex _srcRegIdx[MaxInstSrcRegs]
See srcRegIdx().
Definition: static_inst.hh:225
Definition: flags.hh:35
void printFlags(std::ostream &outs, const std::string &separator) const
Print a separator separated list of this instruction's set flag names on the given stream...
Definition: static_inst.cc:98
bool isIndirectCtrl() const
Definition: static_inst.hh:149
bool isCondDelaySlot() const
Definition: static_inst.hh:152
uint16_t MicroPC
Definition: types.hh:144
Derive from RefCounted if you want to enable reference counting of this class.
Definition: refcnt.hh:45
bool isControl() const
Definition: static_inst.hh:145
void setFirstMicroop()
Definition: static_inst.hh:177
bool isThreadSync() const
Definition: static_inst.hh:154
void setLastMicroop()
Definition: static_inst.hh:178
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
uint64_t ExtMachInst
Definition: types.hh:41
int8_t numFPDestRegs() const
Number of floating-point destination regs.
Definition: static_inst.hh:116
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
virtual Fault eaComp(ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:263
bool isSerializeBefore() const
Definition: static_inst.hh:158
RegIndex srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
Definition: static_inst.hh:192
bool isCC() const
Definition: static_inst.hh:143
int8_t numSrcRegs() const
Number of source registers.
Definition: static_inst.hh:112
virtual const StaticInstPtr & eaCompInst() const
Memory references only: returns "fake" instruction representing the effective address part of the mem...
Definition: static_inst.hh:206
bool isDirectCtrl() const
Definition: static_inst.hh:148
int8_t _numDestRegs
See numDestRegs().
Definition: static_inst.hh:93
virtual std::string generateDisassembly(Addr pc, const SymbolTable *symtab) const =0
Internal function to generate disassembly string.
bool isUnverifiable() const
Definition: static_inst.hh:166
virtual void advancePC(TheISA::PCState &pcState) const =0
bool isLoad() const
Definition: static_inst.hh:133
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
virtual Fault completeAcc(Packet *pkt, ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:275
void setFlag(Flags f)
Definition: static_inst.hh:180
Base, ISA-independent static instruction class.
Definition: static_inst.hh:68
int8_t numIntDestRegs() const
Number of integer destination regs.
Definition: static_inst.hh:118
StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
Constructor.
Definition: static_inst.hh:252
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:72
IntReg pc
Definition: remote_gdb.hh:91
bool isCondCtrl() const
Definition: static_inst.hh:150
RegIndex _destRegIdx[MaxInstDestRegs]
See destRegIdx().
Definition: static_inst.hh:223
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:197
bool isReturn() const
Definition: static_inst.hh:147
virtual const StaticInstPtr & memAccInst() const
Memory references only: returns "fake" instruction representing the memory access part of the memory ...
Definition: static_inst.hh:215
bool isLastMicroop() const
Definition: static_inst.hh:171
bool isInstPrefetch() const
Definition: static_inst.hh:136
std::shared_ptr< FaultBase > Fault
Definition: types.hh:184
bool isPrefetch() const
Definition: static_inst.hh:138
bool isFloating() const
Definition: static_inst.hh:142
virtual TheISA::PCState branchTarget(const TheISA::PCState &pc) const
Return the target address for a PC-relative branch.
Definition: static_inst.cc:73
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:114
bool isWriteBarrier() const
Definition: static_inst.hh:162
bool isNop() const
Definition: static_inst.hh:130
bool isStoreConditional() const
Definition: static_inst.hh:135

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