gem5 v23.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, 2020 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 <array>
46#include <bitset>
47#include <cstdint>
48#include <memory>
49#include <string>
50
52#include "base/logging.hh"
53#include "base/refcnt.hh"
54#include "cpu/op_class.hh"
55#include "cpu/reg_class.hh"
57#include "enums/StaticInstFlags.hh"
58#include "sim/byteswap.hh"
59
60namespace gem5
61{
62
63// forward declarations
64class Packet;
65
66class ExecContext;
67class ThreadContext;
68
69namespace loader
70{
71class SymbolTable;
72} // namespace loader
73
74namespace trace
75{
76class InstRecord;
77} // namespace trace
78
87class StaticInst : public RefCounted, public StaticInstFlags
88{
89 public:
91
92 private:
95
98
99 protected:
100
102 std::bitset<Num_Flags> flags;
103
105 OpClass _opClass;
106
108 uint8_t _numSrcRegs = 0;
109
111 uint8_t _numDestRegs = 0;
112
113 std::array<uint8_t, MiscRegClass + 1> _numTypedDestRegs = {};
114
115 public:
116
120
121
122 uint8_t numSrcRegs() const { return _numSrcRegs; }
124 uint8_t numDestRegs() const { return _numDestRegs; }
126 uint8_t
128 {
129 return _numTypedDestRegs[type];
130 }
132
137
138
139 bool isNop() const { return flags[IsNop]; }
140
141 bool
142 isMemRef() const
143 {
144 return flags[IsLoad] || flags[IsStore] || flags[IsAtomic];
145 }
146 bool isLoad() const { return flags[IsLoad]; }
147 bool isStore() const { return flags[IsStore]; }
148 bool isAtomic() const { return flags[IsAtomic]; }
149 bool isStoreConditional() const { return flags[IsStoreConditional]; }
150 bool isInstPrefetch() const { return flags[IsInstPrefetch]; }
151 bool isDataPrefetch() const { return flags[IsDataPrefetch]; }
152 bool isPrefetch() const { return isInstPrefetch() ||
153 isDataPrefetch(); }
154
155 bool isInteger() const { return flags[IsInteger]; }
156 bool isFloating() const { return flags[IsFloating]; }
157 bool isVector() const { return flags[IsVector]; }
158 bool isMatrix() const { return flags[IsMatrix]; }
159
160 bool isControl() const { return flags[IsControl]; }
161 bool isCall() const { return flags[IsCall]; }
162 bool isReturn() const { return flags[IsReturn]; }
163 bool isDirectCtrl() const { return flags[IsDirectControl]; }
164 bool isIndirectCtrl() const { return flags[IsIndirectControl]; }
165 bool isCondCtrl() const { return flags[IsCondControl]; }
166 bool isUncondCtrl() const { return flags[IsUncondControl]; }
167
168 bool isSerializing() const { return flags[IsSerializing] ||
169 flags[IsSerializeBefore] ||
170 flags[IsSerializeAfter]; }
171 bool isSerializeBefore() const { return flags[IsSerializeBefore]; }
172 bool isSerializeAfter() const { return flags[IsSerializeAfter]; }
173 bool isSquashAfter() const { return flags[IsSquashAfter]; }
174 bool
176 {
177 return flags[IsReadBarrier] && flags[IsWriteBarrier];
178 }
179 bool isReadBarrier() const { return flags[IsReadBarrier]; }
180 bool isWriteBarrier() const { return flags[IsWriteBarrier]; }
181 bool isNonSpeculative() const { return flags[IsNonSpeculative]; }
182 bool isQuiesce() const { return flags[IsQuiesce]; }
183 bool isUnverifiable() const { return flags[IsUnverifiable]; }
184 bool isSyscall() const { return flags[IsSyscall]; }
185 bool isMacroop() const { return flags[IsMacroop]; }
186 bool isMicroop() const { return flags[IsMicroop]; }
187 bool isDelayedCommit() const { return flags[IsDelayedCommit]; }
188 bool isLastMicroop() const { return flags[IsLastMicroop]; }
189 bool isFirstMicroop() const { return flags[IsFirstMicroop]; }
190 // hardware transactional memory
191 // HtmCmds must be identified as such in order
192 // to provide them with necessary memory ordering semantics.
193 bool isHtmStart() const { return flags[IsHtmStart]; }
194 bool isHtmStop() const { return flags[IsHtmStop]; }
195 bool isHtmCancel() const { return flags[IsHtmCancel]; }
196
197 bool
198 isHtmCmd() const
199 {
200 return isHtmStart() || isHtmStop() || isHtmCancel();
201 }
203
204 void setFirstMicroop() { flags[IsFirstMicroop] = true; }
205 void setLastMicroop() { flags[IsLastMicroop] = true; }
206 void setDelayedCommit() { flags[IsDelayedCommit] = true; }
207 void setFlag(Flags f) { flags[f] = true; }
208
210 OpClass opClass() const { return _opClass; }
211
212
215 const RegId &destRegIdx(int i) const { return (this->*_destRegIdxPtr)[i]; }
216
217 void
219 {
220 (this->*_destRegIdxPtr)[i] = val;
221 }
222
225 const RegId &srcRegIdx(int i) const { return (this->*_srcRegIdxPtr)[i]; }
226
227 void
228 setSrcRegIdx(int i, const RegId &val)
229 {
230 (this->*_srcRegIdxPtr)[i] = val;
231 }
232
235
236 virtual uint64_t getEMI() const { return 0; }
237
238 protected:
239
246 void
248 {
249 _srcRegIdxPtr = src;
250 _destRegIdxPtr = dest;
251 }
252
259 const char *mnemonic;
260
265 mutable std::unique_ptr<std::string> cachedDisassembly;
266
270 virtual std::string generateDisassembly(
271 Addr pc, const loader::SymbolTable *symtab) const = 0;
272
278 StaticInst(const char *_mnemonic, OpClass op_class)
279 : _opClass(op_class), mnemonic(_mnemonic)
280 {}
281
282 public:
283 virtual ~StaticInst() {};
284
286 trace::InstRecord *traceData) const = 0;
287
288 virtual Fault
290 {
291 panic("initiateAcc not defined!");
292 }
293
294 virtual Fault
296 trace::InstRecord *trace_data) const
297 {
298 panic("completeAcc not defined!");
299 }
300
301 virtual void advancePC(PCStateBase &pc_state) const = 0;
302 virtual void advancePC(ThreadContext *tc) const;
303
304 virtual std::unique_ptr<PCStateBase>
305 buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const
306 {
307 panic("buildRetPC not defined!");
308 }
309
314 virtual StaticInstPtr fetchMicroop(MicroPC upc) const;
315
321 virtual std::unique_ptr<PCStateBase> branchTarget(
322 const PCStateBase &pc) const;
323
331 virtual std::unique_ptr<PCStateBase> branchTarget(
332 ThreadContext *tc) const;
333
341 virtual const std::string &disassemble(Addr pc,
342 const loader::SymbolTable *symtab=nullptr) const;
343
348 void printFlags(std::ostream &outs, const std::string &separator) const;
349
351 std::string getName() { return mnemonic; }
352
353 protected:
354 template<typename T>
355 size_t
356 simpleAsBytes(void *buf, size_t max_size, const T &t)
357 {
358 size_t size = sizeof(T);
359 if (size <= max_size)
360 *reinterpret_cast<T *>(buf) = htole<T>(t);
361 return size;
362 }
363
364 public:
376 virtual size_t asBytes(void *buf, size_t max_size) { return 0; }
377};
378
379} // namespace gem5
380
381#endif // __CPU_STATIC_INST_HH__
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Wrapper that groups a few flag bits under the same undelying container.
Definition flags.hh:45
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Derive from RefCounted if you want to enable reference counting of this class.
Definition refcnt.hh:61
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:93
Base, ISA-independent static instruction class.
static StaticInstPtr nullStaticInstPtr
Pointer to a statically allocated "null" instruction object.
StaticInst(const char *_mnemonic, OpClass op_class)
Constructor.
bool isInteger() const
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.
bool isQuiesce() const
bool isHtmStop() const
virtual const std::string & disassemble(Addr pc, const loader::SymbolTable *symtab=nullptr) const
Return string representation of disassembled instruction.
bool isUnverifiable() const
virtual ~StaticInst()
RegIdArrayPtr _srcRegIdxPtr
See srcRegIdx().
virtual uint64_t getEMI() const
uint8_t numSrcRegs() const
Number of source registers.
virtual StaticInstPtr fetchMicroop(MicroPC upc) const
Return the microop that goes with a particular micropc.
virtual std::string generateDisassembly(Addr pc, const loader::SymbolTable *symtab) const =0
Internal function to generate disassembly string.
void setDestRegIdx(int i, const RegId &val)
OpClass opClass() const
Operation class. Used to select appropriate function unit in issue.
void setRegIdxArrays(RegIdArrayPtr src, RegIdArrayPtr dest)
Set the pointers which point to the arrays of source and destination register indices.
virtual std::unique_ptr< PCStateBase > buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const
bool isSyscall() const
bool isPrefetch() const
std::array< uint8_t, MiscRegClass+1 > _numTypedDestRegs
std::unique_ptr< std::string > cachedDisassembly
String representation of disassembly (lazily evaluated via disassemble()).
bool isStoreConditional() const
bool isFirstMicroop() const
bool isDirectCtrl() const
bool isHtmCmd() const
bool isUncondCtrl() const
bool isSerializeBefore() const
bool isLoad() const
virtual std::unique_ptr< PCStateBase > branchTarget(const PCStateBase &pc) const
Return the target address for a PC-relative branch.
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
bool isSquashAfter() const
uint8_t numDestRegs() const
Number of destination registers.
bool isMatrix() const
virtual void advancePC(PCStateBase &pc_state) const =0
RegId(StaticInst::*)[] RegIdArrayPtr
bool isHtmCancel() const
bool isFloating() const
bool isWriteBarrier() const
bool isNop() const
uint8_t _numSrcRegs
See numSrcRegs().
bool isMacroop() const
bool isReturn() const
bool isMemRef() const
virtual Fault execute(ExecContext *xc, trace::InstRecord *traceData) const =0
bool isReadBarrier() const
uint8_t _numDestRegs
See numDestRegs().
std::string getName()
Return name of machine instruction.
bool isNonSpeculative() const
RegIdArrayPtr _destRegIdxPtr
See destRegIdx().
const RegId & destRegIdx(int i) const
Return logical index (architectural reg num) of i'th destination reg.
bool isDataPrefetch() const
uint8_t numDestRegs(RegClassType type) const
Number of destination registers of a particular type.
bool isIndirectCtrl() const
bool isVector() const
bool isHtmStart() const
bool isLastMicroop() const
void setSrcRegIdx(int i, const RegId &val)
bool isFullMemBarrier() const
bool isStore() const
bool isInstPrefetch() const
void setFlag(Flags f)
bool isSerializing() const
const char * mnemonic
Base mnemonic (e.g., "add").
virtual Fault completeAcc(Packet *pkt, ExecContext *xc, trace::InstRecord *trace_data) const
std::bitset< Num_Flags > flags
Flag values for this instruction.
bool isAtomic() const
bool isMicroop() const
bool isCall() const
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...
const RegId & srcRegIdx(int i) const
Return logical index (architectural reg num) of i'th source reg.
virtual Fault initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const
bool isCondCtrl() const
bool isDelayedCommit() const
bool isControl() const
bool isSerializeAfter() const
OpClass _opClass
See opClass().
ThreadContext is the external interface to all thread state for anything outside of the CPU.
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 4 > pc
Bitfield< 63 > val
Definition misc.hh:776
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition mem.hh:108
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint16_t MicroPC
Definition types.hh:149
RegClassType
Enumerate the classes of registers.
Definition reg_class.hh:59
Classes for managing reference counted objects.

Generated on Mon Jul 10 2023 14:24:30 for gem5 by doxygen 1.9.7