gem5  v20.0.0.2
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 
42 #ifndef __CPU_STATIC_INST_HH__
43 #define __CPU_STATIC_INST_HH__
44 
45 #include <bitset>
46 #include <memory>
47 #include <string>
48 
49 #include "arch/registers.hh"
50 #include "arch/types.hh"
51 #include "base/logging.hh"
52 #include "base/refcnt.hh"
53 #include "base/types.hh"
54 #include "config/the_isa.hh"
55 #include "cpu/op_class.hh"
56 #include "cpu/reg_class.hh"
57 #include "cpu/static_inst_fwd.hh"
58 #include "cpu/thread_context.hh"
59 #include "enums/StaticInstFlags.hh"
60 #include "sim/byteswap.hh"
61 
62 // forward declarations
63 class Packet;
64 
65 class ExecContext;
66 
67 namespace Loader
68 {
69 class SymbolTable;
70 } // namespace Loader
71 
72 namespace Trace
73 {
74 class InstRecord;
75 } // namespace Trace
76 
85 class StaticInst : public RefCounted, public StaticInstFlags
86 {
87  public:
90 
91  enum {
92  MaxInstSrcRegs = TheISA::MaxInstSrcRegs, //< Max source regs
93  MaxInstDestRegs = TheISA::MaxInstDestRegs //< Max dest regs
94  };
95 
96  protected:
97 
99  std::bitset<Num_Flags> flags;
100 
102  OpClass _opClass;
103 
105  int8_t _numSrcRegs;
106 
108  int8_t _numDestRegs;
109 
112 
117 
125  public:
126 
133 
134  int8_t numSrcRegs() const { return _numSrcRegs; }
137  int8_t numDestRegs() const { return _numDestRegs; }
139  int8_t numFPDestRegs() const { return _numFPDestRegs; }
141  int8_t numIntDestRegs() const { return _numIntDestRegs; }
143  int8_t numVecDestRegs() const { return _numVecDestRegs; }
145  int8_t numVecElemDestRegs() const { return _numVecElemDestRegs; }
147  int8_t numVecPredDestRegs() const { return _numVecPredDestRegs; }
149  int8_t numCCDestRegs() const { return _numCCDestRegs; }
151 
156 
157 
158  bool isNop() const { return flags[IsNop]; }
159 
160  bool isMemRef() const { return flags[IsMemRef]; }
161  bool isLoad() const { return flags[IsLoad]; }
162  bool isStore() const { return flags[IsStore]; }
163  bool isAtomic() const { return flags[IsAtomic]; }
164  bool isStoreConditional() const { return flags[IsStoreConditional]; }
165  bool isInstPrefetch() const { return flags[IsInstPrefetch]; }
166  bool isDataPrefetch() const { return flags[IsDataPrefetch]; }
167  bool isPrefetch() const { return isInstPrefetch() ||
168  isDataPrefetch(); }
169 
170  bool isInteger() const { return flags[IsInteger]; }
171  bool isFloating() const { return flags[IsFloating]; }
172  bool isVector() const { return flags[IsVector]; }
173  bool isCC() const { return flags[IsCC]; }
174 
175  bool isControl() const { return flags[IsControl]; }
176  bool isCall() const { return flags[IsCall]; }
177  bool isReturn() const { return flags[IsReturn]; }
178  bool isDirectCtrl() const { return flags[IsDirectControl]; }
179  bool isIndirectCtrl() const { return flags[IsIndirectControl]; }
180  bool isCondCtrl() const { return flags[IsCondControl]; }
181  bool isUncondCtrl() const { return flags[IsUncondControl]; }
182  bool isCondDelaySlot() const { return flags[IsCondDelaySlot]; }
183 
184  bool isThreadSync() const { return flags[IsThreadSync]; }
185  bool isSerializing() const { return flags[IsSerializing] ||
186  flags[IsSerializeBefore] ||
187  flags[IsSerializeAfter]; }
188  bool isSerializeBefore() const { return flags[IsSerializeBefore]; }
189  bool isSerializeAfter() const { return flags[IsSerializeAfter]; }
190  bool isSquashAfter() const { return flags[IsSquashAfter]; }
191  bool isMemBarrier() const { return flags[IsMemBarrier]; }
192  bool isWriteBarrier() const { return flags[IsWriteBarrier]; }
193  bool isNonSpeculative() const { return flags[IsNonSpeculative]; }
194  bool isQuiesce() const { return flags[IsQuiesce]; }
195  bool isIprAccess() const { return flags[IsIprAccess]; }
196  bool isUnverifiable() const { return flags[IsUnverifiable]; }
197  bool isSyscall() const { return flags[IsSyscall]; }
198  bool isMacroop() const { return flags[IsMacroop]; }
199  bool isMicroop() const { return flags[IsMicroop]; }
200  bool isDelayedCommit() const { return flags[IsDelayedCommit]; }
201  bool isLastMicroop() const { return flags[IsLastMicroop]; }
202  bool isFirstMicroop() const { return flags[IsFirstMicroop]; }
203  //This flag doesn't do anything yet
204  bool isMicroBranch() const { return flags[IsMicroBranch]; }
206 
207  void setFirstMicroop() { flags[IsFirstMicroop] = true; }
208  void setLastMicroop() { flags[IsLastMicroop] = true; }
209  void setDelayedCommit() { flags[IsDelayedCommit] = true; }
210  void setFlag(Flags f) { flags[f] = true; }
211 
213  OpClass opClass() const { return _opClass; }
214 
215 
218  const RegId& destRegIdx(int i) const { return _destRegIdx[i]; }
219 
222  const RegId& srcRegIdx(int i) const { return _srcRegIdx[i]; }
223 
226 
229 
231  const ExtMachInst machInst;
232 
233  protected:
234 
236  RegId _destRegIdx[MaxInstDestRegs];
238  RegId _srcRegIdx[MaxInstSrcRegs];
239 
246  const char *mnemonic;
247 
252  mutable std::string *cachedDisassembly;
253 
257  virtual std::string
258  generateDisassembly(Addr pc, const Loader::SymbolTable *symtab) const = 0;
259 
265  StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
266  : _opClass(__opClass), _numSrcRegs(0), _numDestRegs(0),
267  _numFPDestRegs(0), _numIntDestRegs(0), _numCCDestRegs(0),
268  _numVecDestRegs(0), _numVecElemDestRegs(0), _numVecPredDestRegs(0),
269  machInst(_machInst), mnemonic(_mnemonic), cachedDisassembly(0)
270  { }
271 
272  public:
273  virtual ~StaticInst();
274 
275  virtual Fault execute(ExecContext *xc,
276  Trace::InstRecord *traceData) const = 0;
277 
279  Trace::InstRecord *traceData) const
280  {
281  panic("initiateAcc not defined!");
282  }
283 
284  virtual Fault completeAcc(Packet *pkt, ExecContext *xc,
285  Trace::InstRecord *traceData) const
286  {
287  panic("completeAcc not defined!");
288  }
289 
290  virtual void advancePC(TheISA::PCState &pcState) const = 0;
291 
296  virtual StaticInstPtr fetchMicroop(MicroPC upc) const;
297 
303  virtual TheISA::PCState branchTarget(const TheISA::PCState &pc) const;
304 
312  virtual TheISA::PCState branchTarget(ThreadContext *tc) const;
313 
318  bool hasBranchTarget(const TheISA::PCState &pc, ThreadContext *tc,
319  TheISA::PCState &tgt) const;
320 
328  virtual const std::string &disassemble(Addr pc,
329  const Loader::SymbolTable *symtab=nullptr) const;
330 
335  void printFlags(std::ostream &outs, const std::string &separator) const;
336 
338  std::string getName() { return mnemonic; }
339 
340  protected:
341  template<typename T>
342  size_t
343  simpleAsBytes(void *buf, size_t max_size, const T &t)
344  {
345  size_t size = sizeof(T);
346  if (size <= max_size)
347  *reinterpret_cast<T *>(buf) = htole<T>(t);
348  return size;
349  }
350 
351  public:
363  virtual size_t asBytes(void *buf, size_t max_size) { return 0; }
364 };
365 
366 #endif // __CPU_STATIC_INST_HH__
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
int8_t _numVecElemDestRegs
Definition: static_inst.hh:121
bool isPrefetch() const
Definition: static_inst.hh:167
bool isCondDelaySlot() const
Definition: static_inst.hh:182
void setDelayedCommit()
Definition: static_inst.hh:209
bool isStore() const
Definition: static_inst.hh:162
std::string * cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
Definition: static_inst.hh:252
int8_t _numSrcRegs
See numSrcRegs().
Definition: static_inst.hh:105
bool isDelayedCommit() const
Definition: static_inst.hh:200
Bitfield< 7 > i
uint64_t ExtMachInst
Definition: types.hh:39
int8_t _numFPDestRegs
The following are used to track physical register usage for machines with separate int & FP reg files...
Definition: static_inst.hh:113
int8_t _numCCDestRegs
Definition: static_inst.hh:115
virtual Fault completeAcc(Packet *pkt, ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:284
bool isMacroop() const
Definition: static_inst.hh:198
bool isLoad() const
Definition: static_inst.hh:161
int8_t numVecElemDestRegs() const
Number of vector element destination regs.
Definition: static_inst.hh:145
int8_t numVecPredDestRegs() const
Number of predicate destination regs.
Definition: static_inst.hh:147
int8_t numDestRegs() const
Number of destination registers.
Definition: static_inst.hh:137
bool isFloating() const
Definition: static_inst.hh:171
bool isUnverifiable() const
Definition: static_inst.hh:196
const char * mnemonic
Base mnemonic (e.g., "add").
Definition: static_inst.hh:246
bool isAtomic() const
Definition: static_inst.hh:163
bool isDataPrefetch() const
Definition: static_inst.hh:166
bool isIndirectCtrl() const
Definition: static_inst.hh:179
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th source reg.
Definition: static_inst.hh:222
std::string getName()
Return name of machine instruction.
Definition: static_inst.hh:338
bool isSerializeBefore() const
Definition: static_inst.hh:188
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:363
bool isSyscall() const
Definition: static_inst.hh:197
int8_t numFPDestRegs() const
Number of floating-point destination regs.
Definition: static_inst.hh:139
bool isReturn() const
Definition: static_inst.hh:177
const int MaxInstSrcRegs
Definition: registers.hh:57
int8_t _numVecPredDestRegs
Definition: static_inst.hh:122
int8_t _numIntDestRegs
Definition: static_inst.hh:114
OpClass _opClass
See opClass().
Definition: static_inst.hh:102
If you want a reference counting pointer to a mutable object, create it like this: ...
Definition: refcnt.hh:118
ThreadContext is the external interface to all thread state for anything outside of the CPU...
bool isMicroBranch() const
Definition: static_inst.hh:204
virtual Fault initiateAcc(ExecContext *xc, Trace::InstRecord *traceData) const
Definition: static_inst.hh:278
bool isDirectCtrl() const
Definition: static_inst.hh:178
bool isUncondCtrl() const
Definition: static_inst.hh:181
bool isMemBarrier() const
Definition: static_inst.hh:191
Bitfield< 6 > f
bool isMemRef() const
Definition: static_inst.hh:160
bool isNop() const
Definition: static_inst.hh:158
int8_t numVecDestRegs() const
Number of vector destination regs.
Definition: static_inst.hh:143
bool isSerializing() const
Definition: static_inst.hh:185
const ExtMachInst machInst
The binary machine instruction.
Definition: static_inst.hh:231
std::bitset< Num_Flags > flags
Flag values for this instruction.
Definition: static_inst.hh:99
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:70
Bitfield< 4 > pc
bool isWriteBarrier() const
Definition: static_inst.hh:192
Definition: flags.hh:33
bool isCondCtrl() const
Definition: static_inst.hh:180
bool isIprAccess() const
Definition: static_inst.hh:195
bool isQuiesce() const
Definition: static_inst.hh:194
uint16_t MicroPC
Definition: types.hh:142
bool isCall() const
Definition: static_inst.hh:176
Derive from RefCounted if you want to enable reference counting of this class.
Definition: refcnt.hh:57
void advancePC(PCState &pc, const StaticInstPtr &inst)
Definition: utility.hh:393
void setFirstMicroop()
Definition: static_inst.hh:207
void setLastMicroop()
Definition: static_inst.hh:208
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:140
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
bool isInteger() const
Definition: static_inst.hh:170
static StaticInstPtr nopStaticInstPtr
Pointer to a statically allocated generic "nop" instruction object.
Definition: static_inst.hh:228
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
Definition: static_inst.hh:213
bool isStoreConditional() const
Definition: static_inst.hh:164
bool isFirstMicroop() const
Definition: static_inst.hh:202
bool isVector() const
Definition: static_inst.hh:172
int8_t _numDestRegs
See numDestRegs().
Definition: static_inst.hh:108
bool isControl() const
Definition: static_inst.hh:175
int8_t _numVecDestRegs
To use in architectures with vector register file.
Definition: static_inst.hh:120
void setFlag(Flags f)
Definition: static_inst.hh:210
int8_t numCCDestRegs() const
Number of coprocesor destination regs.
Definition: static_inst.hh:149
bool isNonSpeculative() const
Definition: static_inst.hh:193
Base, ISA-independent static instruction class.
Definition: static_inst.hh:85
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i&#39;th destination reg.
Definition: static_inst.hh:218
StaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
Constructor.
Definition: static_inst.hh:265
TheISA::ExtMachInst ExtMachInst
Binary extended machine instruction type.
Definition: static_inst.hh:89
bool isSquashAfter() const
Definition: static_inst.hh:190
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:75
bool isCC() const
Definition: static_inst.hh:173
Bitfield< 5 > t
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
Definition: static_inst.hh:225
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
bool isSerializeAfter() const
Definition: static_inst.hh:189
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
int8_t numIntDestRegs() const
Number of integer destination regs.
Definition: static_inst.hh:141
bool isMicroop() const
Definition: static_inst.hh:199
bool isThreadSync() const
Definition: static_inst.hh:184
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
Definition: static_inst.hh:343
bool isInstPrefetch() const
Definition: static_inst.hh:165
bool isLastMicroop() const
Definition: static_inst.hh:201

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