gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
static_inst.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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) 2003-2005 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
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: Steve Reinhardt
42  */
43 
44 #ifndef __CPU_STATIC_INST_HH__
45 #define __CPU_STATIC_INST_HH__
46 
47 #include <bitset>
48 #include <memory>
49 #include <string>
50 
51 #include "arch/registers.hh"
52 #include "arch/types.hh"
53 #include "base/logging.hh"
54 #include "base/refcnt.hh"
55 #include "base/types.hh"
56 #include "config/the_isa.hh"
57 #include "cpu/op_class.hh"
58 #include "cpu/reg_class.hh"
59 #include "cpu/static_inst_fwd.hh"
60 #include "cpu/thread_context.hh"
61 #include "enums/StaticInstFlags.hh"
62 #include "sim/byteswap.hh"
63 
64 // forward declarations
65 class Packet;
66 
67 class ExecContext;
68 
69 class SymbolTable;
70 
71 namespace Trace {
72  class InstRecord;
73 }
74 
83 class StaticInst : public RefCounted, public StaticInstFlags
84 {
85  public:
88 
89  enum {
90  MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
91  MaxInstDestRegs = TheISA::MaxInstDestRegs //< Max dest regs
92  };
93 
94  protected:
95 
97  std::bitset<Num_Flags> flags;
98 
100  OpClass _opClass;
101 
103  int8_t _numSrcRegs;
104 
106  int8_t _numDestRegs;
107 
110 
115 
123  public:
124 
131 
132  int8_t numSrcRegs() const { return _numSrcRegs; }
135  int8_t numDestRegs() const { return _numDestRegs; }
137  int8_t numFPDestRegs() const { return _numFPDestRegs; }
139  int8_t numIntDestRegs() const { return _numIntDestRegs; }
141  int8_t numVecDestRegs() const { return _numVecDestRegs; }
143  int8_t numVecElemDestRegs() const { return _numVecElemDestRegs; }
145  int8_t numVecPredDestRegs() const { return _numVecPredDestRegs; }
147  int8_t numCCDestRegs() const { return _numCCDestRegs; }
149 
154 
155 
156  bool isNop() const { return flags[IsNop]; }
157 
158  bool isMemRef() const { return flags[IsMemRef]; }
159  bool isLoad() const { return flags[IsLoad]; }
160  bool isStore() const { return flags[IsStore]; }
161  bool isAtomic() const { return flags[IsAtomic]; }
162  bool isStoreConditional() const { return flags[IsStoreConditional]; }
163  bool isInstPrefetch() const { return flags[IsInstPrefetch]; }
164  bool isDataPrefetch() const { return flags[IsDataPrefetch]; }
165  bool isPrefetch() const { return isInstPrefetch() ||
166  isDataPrefetch(); }
167 
168  bool isInteger() const { return flags[IsInteger]; }
169  bool isFloating() const { return flags[IsFloating]; }
170  bool isVector() const { return flags[IsVector]; }
171  bool isCC() const { return flags[IsCC]; }
172 
173  bool isControl() const { return flags[IsControl]; }
174  bool isCall() const { return flags[IsCall]; }
175  bool isReturn() const { return flags[IsReturn]; }
176  bool isDirectCtrl() const { return flags[IsDirectControl]; }
177  bool isIndirectCtrl() const { return flags[IsIndirectControl]; }
178  bool isCondCtrl() const { return flags[IsCondControl]; }
179  bool isUncondCtrl() const { return flags[IsUncondControl]; }
180  bool isCondDelaySlot() const { return flags[IsCondDelaySlot]; }
181 
182  bool isThreadSync() const { return flags[IsThreadSync]; }
183  bool isSerializing() const { return flags[IsSerializing] ||
184  flags[IsSerializeBefore] ||
185  flags[IsSerializeAfter]; }
186  bool isSerializeBefore() const { return flags[IsSerializeBefore]; }
187  bool isSerializeAfter() const { return flags[IsSerializeAfter]; }
188  bool isSquashAfter() const { return flags[IsSquashAfter]; }
189  bool isMemBarrier() const { return flags[IsMemBarrier]; }
190  bool isWriteBarrier() const { return flags[IsWriteBarrier]; }
191  bool isNonSpeculative() const { return flags[IsNonSpeculative]; }
192  bool isQuiesce() const { return flags[IsQuiesce]; }
193  bool isIprAccess() const { return flags[IsIprAccess]; }
194  bool isUnverifiable() const { return flags[IsUnverifiable]; }
195  bool isSyscall() const { return flags[IsSyscall]; }
196  bool isMacroop() const { return flags[IsMacroop]; }
197  bool isMicroop() const { return flags[IsMicroop]; }
198  bool isDelayedCommit() const { return flags[IsDelayedCommit]; }
199  bool isLastMicroop() const { return flags[IsLastMicroop]; }
200  bool isFirstMicroop() const { return flags[IsFirstMicroop]; }
201  //This flag doesn't do anything yet
202  bool isMicroBranch() const { return flags[IsMicroBranch]; }
204 
205  void setFirstMicroop() { flags[IsFirstMicroop] = true; }
206  void setLastMicroop() { flags[IsLastMicroop] = true; }
207  void setDelayedCommit() { flags[IsDelayedCommit] = true; }
208  void setFlag(Flags f) { flags[f] = true; }
209 
211  OpClass opClass() const { return _opClass; }
212 
213 
216  const RegId& destRegIdx(int i) const { return _destRegIdx[i]; }
217 
220  const RegId& srcRegIdx(int i) const { return _srcRegIdx[i]; }
221 
224 
227 
229  const ExtMachInst machInst;
230 
231  protected:
232 
234  RegId _destRegIdx[MaxInstDestRegs];
236  RegId _srcRegIdx[MaxInstSrcRegs];
237 
244  const char *mnemonic;
245 
250  mutable std::string *cachedDisassembly;
251 
255  virtual std::string
256  generateDisassembly(Addr pc, const SymbolTable *symtab) const = 0;
257 
263  StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
264  : _opClass(__opClass), _numSrcRegs(0), _numDestRegs(0),
265  _numFPDestRegs(0), _numIntDestRegs(0), _numCCDestRegs(0),
266  _numVecDestRegs(0), _numVecElemDestRegs(0), _numVecPredDestRegs(0),
267  machInst(_machInst), mnemonic(_mnemonic), cachedDisassembly(0)
268  { }
269 
270  public:
271  virtual ~StaticInst();
272 
273  virtual Fault execute(ExecContext *xc,
274  Trace::InstRecord *traceData) const = 0;
275 
277  Trace::InstRecord *traceData) const
278  {
279  panic("initiateAcc not defined!");
280  }
281 
282  virtual Fault completeAcc(Packet *pkt, ExecContext *xc,
283  Trace::InstRecord *traceData) const
284  {
285  panic("completeAcc not defined!");
286  }
287 
288  virtual void advancePC(TheISA::PCState &pcState) const = 0;
289 
294  virtual StaticInstPtr fetchMicroop(MicroPC upc) const;
295 
301  virtual TheISA::PCState branchTarget(const TheISA::PCState &pc) const;
302 
310  virtual TheISA::PCState branchTarget(ThreadContext *tc) const;
311 
316  bool hasBranchTarget(const TheISA::PCState &pc, ThreadContext *tc,
317  TheISA::PCState &tgt) const;
318 
326  virtual const std::string &disassemble(Addr pc,
327  const SymbolTable *symtab = 0) const;
328 
333  void printFlags(std::ostream &outs, const std::string &separator) const;
334 
336  std::string getName() { return mnemonic; }
337 
338  protected:
339  template<typename T>
340  size_t
341  simpleAsBytes(void *buf, size_t max_size, const T &t)
342  {
343  size_t size = sizeof(T);
344  if (size <= max_size)
345  *reinterpret_cast<T *>(buf) = htole<T>(t);
346  return size;
347  }
348 
349  public:
361  virtual size_t asBytes(void *buf, size_t max_size) { return 0; }
362 };
363 
364 #endif // __CPU_STATIC_INST_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
int8_t _numVecElemDestRegs
Definition: static_inst.hh:119
bool isPrefetch() const
Definition: static_inst.hh:165
bool isCondDelaySlot() const
Definition: static_inst.hh:180
void setDelayedCommit()
Definition: static_inst.hh:207
bool isStore() const
Definition: static_inst.hh:160
std::string * cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
Definition: static_inst.hh:250
int8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:103
bool isDelayedCommit() const
Definition: static_inst.hh:198
Bitfield< 7 > i
int8_t _numFPDestRegs
The following are used to track physical register usage for machines with separate int & FP reg files...
Definition: static_inst.hh:111
int8_t _numCCDestRegs
Definition: static_inst.hh:113
virtual Fault completeAcc(Packet *pkt, ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:282
bool isMacroop() const
Definition: static_inst.hh:196
bool isLoad() const
Definition: static_inst.hh:159
int8_t numVecElemDestRegs() const
Number of vector element destination regs.
Definition: static_inst.hh:143
int8_t numVecPredDestRegs() const
Number of predicate destination regs.
Definition: static_inst.hh:145
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:135
bool isFloating() const
Definition: static_inst.hh:169
bool isUnverifiable() const
Definition: static_inst.hh:194
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:244
bool isAtomic() const
Definition: static_inst.hh:161
bool isDataPrefetch() const
Definition: static_inst.hh:164
bool isIndirectCtrl() const
Definition: static_inst.hh:177
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th source reg.
Definition: static_inst.hh:220
std::string getName()
Return name of machine instruction.
Definition: static_inst.hh:336
bool isSerializeBefore() const
Definition: static_inst.hh:186
virtual size_t asBytes(void *buf, size_t max_size)
Instruction classes can override this function to return a a representation of themselves as a blob o...
Definition: static_inst.hh:361
bool isSyscall() const
Definition: static_inst.hh:195
int8_t numFPDestRegs() const
Number of floating-point destination regs.
Definition: static_inst.hh:137
bool isReturn() const
Definition: static_inst.hh:175
const int MaxInstSrcRegs
Definition: registers.hh:59
int8_t _numVecPredDestRegs
Definition: static_inst.hh:120
int8_t _numIntDestRegs
Definition: static_inst.hh:112
OpClass _opClass
See opClass().
Definition: static_inst.hh:100
If you want a reference counting pointer to a mutable object, create it like this: ...
Definition: refcnt.hh:120
ThreadContext is the external interface to all thread state for anything outside of the CPU...
bool isMicroBranch() const
Definition: static_inst.hh:202
virtual Fault initiateAcc(ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:276
bool isDirectCtrl() const
Definition: static_inst.hh:176
bool isUncondCtrl() const
Definition: static_inst.hh:179
bool isMemBarrier() const
Definition: static_inst.hh:189
Bitfield< 6 > f
bool isMemRef() const
Definition: static_inst.hh:158
bool isNop() const
Definition: static_inst.hh:156
int8_t numVecDestRegs() const
Number of vector destination regs.
Definition: static_inst.hh:141
bool isSerializing() const
Definition: static_inst.hh:183
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:229
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:97
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:73
Bitfield< 4 > pc
bool isWriteBarrier() const
Definition: static_inst.hh:190
Definition: flags.hh:35
bool isCondCtrl() const
Definition: static_inst.hh:178
bool isIprAccess() const
Definition: static_inst.hh:193
bool isQuiesce() const
Definition: static_inst.hh:192
uint16_t MicroPC
Definition: types.hh:144
bool isCall() const
Definition: static_inst.hh:174
Derive from RefCounted if you want to enable reference counting of this class.
Definition: refcnt.hh:59
void setFirstMicroop()
Definition: static_inst.hh:205
void setLastMicroop()
Definition: static_inst.hh:206
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
void advancePC(PCState &pc, const StaticInstPtr &inst)
Definition: utility.hh:98
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
bool isInteger() const
Definition: static_inst.hh:168
static StaticInstPtr nopStaticInstPtr
Pointer to a statically allocated generic "nop" instruction object.
Definition: static_inst.hh:226
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:211
bool isStoreConditional() const
Definition: static_inst.hh:162
bool isFirstMicroop() const
Definition: static_inst.hh:200
bool isVector() const
Definition: static_inst.hh:170
int8_t _numDestRegs
See numDestRegs().
Definition: static_inst.hh:106
bool isControl() const
Definition: static_inst.hh:173
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
int8_t _numVecDestRegs
To use in architectures with vector register file.
Definition: static_inst.hh:118
void setFlag(Flags f)
Definition: static_inst.hh:208
int8_t numCCDestRegs() const
Number of coprocesor destination regs.
Definition: static_inst.hh:147
bool isNonSpeculative() const
Definition: static_inst.hh:191
Base, ISA-independent static instruction class.
Definition: static_inst.hh:83
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th destination reg.
Definition: static_inst.hh:216
StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
Constructor.
Definition: static_inst.hh:263
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:87
bool isSquashAfter() const
Definition: static_inst.hh:188
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:79
bool isCC() const
Definition: static_inst.hh:171
Bitfield< 5 > t
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:223
bool isSerializeAfter() const
Definition: static_inst.hh:187
std::shared_ptr< FaultBase > Fault
Definition: types.hh:240
int8_t numIntDestRegs() const
Number of integer destination regs.
Definition: static_inst.hh:139
bool isMicroop() const
Definition: static_inst.hh:197
bool isThreadSync() const
Definition: static_inst.hh:182
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
Definition: static_inst.hh:341
bool isInstPrefetch() const
Definition: static_inst.hh:163
bool isLastMicroop() const
Definition: static_inst.hh:199

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