gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
static_inst.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 RISC-V Foundation
3 * Copyright (c) 2016 The University of Virginia
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
30#ifndef __ARCH_RISCV_STATIC_INST_HH__
31#define __ARCH_RISCV_STATIC_INST_HH__
32
33#include <string>
34
35#include "arch/riscv/pcstate.hh"
37#include "arch/riscv/types.hh"
38#include "cpu/exec_context.hh"
39#include "cpu/static_inst.hh"
40#include "cpu/thread_context.hh"
41#include "mem/packet.hh"
42
43namespace gem5
44{
45
46namespace RiscvISA
47{
48
53{
54 protected:
55 RiscvStaticInst(const char *_mnemonic, ExtMachInst _machInst,
56 OpClass __opClass) :
57 StaticInst(_mnemonic, __opClass), machInst(_machInst)
58 {}
59
60 template <typename T>
61 T
62 rvSelect(T v32, T v64) const
63 {
64 return (machInst.rv_type == RV32) ? v32 : v64;
65 }
66
67 template <typename T32, typename T64>
68 T64 rvExt(T64 x) const { return rvSelect((T64)(T32)x, x); }
69 uint64_t rvZext(uint64_t x) const { return rvExt<uint32_t, uint64_t>(x); }
70 int64_t rvSext(int64_t x) const { return rvExt<int32_t, int64_t>(x); }
71
72 public:
74
75 void
76 advancePC(PCStateBase &pc) const override
77 {
78 pc.as<PCState>().advance();
79 }
80
81 void
82 advancePC(ThreadContext *tc) const override
83 {
84 PCState pc = tc->pcState().as<PCState>();
85 pc.advance();
86 tc->pcState(pc);
87 }
88
89 uint64_t getEMI() const override { return machInst; }
90
91 std::unique_ptr<PCStateBase>
92 buildRetPC(const PCStateBase &cur_pc,
93 const PCStateBase &call_pc) const override
94 {
95 PCStateBase *ret_pc_ptr = call_pc.clone();
96 auto &ret_pc = ret_pc_ptr->as<PCState>();
97 ret_pc.advance();
98 return std::unique_ptr<PCStateBase>{ret_pc_ptr};
99 }
100
101 size_t
102 asBytes(void *buf, size_t size) override
103 {
104 return simpleAsBytes(buf, size, machInst);
105 }
106};
107
112{
113 protected:
115
116 RiscvMacroInst(const char *mnem, ExtMachInst _machInst,
117 OpClass __opClass) :
118 RiscvStaticInst(mnem, _machInst, __opClass)
119 {
120 flags[IsMacroop] = true;
121 }
122
124
126 fetchMicroop(MicroPC upc) const override
127 {
128 return microops[upc];
129 }
130
131 Fault
132 initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const override
133 {
134 panic("Tried to execute a macroop directly!\n");
135 }
136
137 Fault
139 trace::InstRecord *traceData) const override
140 {
141 panic("Tried to execute a macroop directly!\n");
142 }
143
144 Fault
145 execute(ExecContext *xc, trace::InstRecord *traceData) const override
146 {
147 panic("Tried to execute a macroop directly!\n");
148 }
149
150 void size(size_t newSize) override
151 {
152 for (int i = 0; i < microops.size(); i++) {
153 microops[i]->size(newSize);
154 }
155 _size = newSize;
156 }
157
158};
159
164{
165 protected:
166 RiscvMicroInst(const char *mnem, ExtMachInst _machInst,
167 OpClass __opClass) :
168 RiscvStaticInst(mnem, _machInst, __opClass)
169 {
170 flags[IsMicroop] = true;
171 }
172
173 void advancePC(PCStateBase &pcState) const override;
174 void advancePC(ThreadContext *tc) const override;
175};
176
177} // namespace RiscvISA
178} // namespace gem5
179
180#endif // __ARCH_RISCV_STATIC_INST_HH__
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
Target & as()
Definition pcstate.hh:73
virtual PCStateBase * clone() const =0
void size(size_t newSize) override
std::vector< StaticInstPtr > microops
Fault initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const override
Fault completeAcc(PacketPtr pkt, ExecContext *xc, trace::InstRecord *traceData) const override
RiscvMacroInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
StaticInstPtr fetchMicroop(MicroPC upc) const override
Return the microop that goes with a particular micropc.
Fault execute(ExecContext *xc, trace::InstRecord *traceData) const override
RiscvMicroInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
void advancePC(PCStateBase &pcState) const override
size_t asBytes(void *buf, size_t size) override
Instruction classes can override this function to return a a representation of themselves as a blob o...
std::unique_ptr< PCStateBase > buildRetPC(const PCStateBase &cur_pc, const PCStateBase &call_pc) const override
void advancePC(ThreadContext *tc) const override
int64_t rvSext(int64_t x) const
T rvSelect(T v32, T v64) const
void advancePC(PCStateBase &pc) const override
uint64_t rvZext(uint64_t x) const
RiscvStaticInst(const char *_mnemonic, ExtMachInst _machInst, OpClass __opClass)
uint64_t getEMI() const override
StaticInst(const char *_mnemonic, OpClass op_class)
Constructor.
size_t simpleAsBytes(void *buf, size_t max_size, const T &t)
size_t size() const
size_t _size
Instruction size in bytes.
std::bitset< Num_Flags > flags
Flag values for this instruction.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual const PCStateBase & pcState() const =0
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
constexpr enums::RiscvType RV32
Definition pcstate.hh:56
Bitfield< 2 > i
Bitfield< 3 > x
Definition pagetable.hh:76
Bitfield< 4 > pc
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
Packet * PacketPtr
RefCountingPtr< StaticInst > StaticInstPtr
uint16_t MicroPC
Definition types.hh:149
Declaration of the Packet class.

Generated on Mon May 26 2025 09:19:08 for gem5 by doxygen 1.13.2