gem5 v24.0.0.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 std::unique_ptr<PCStateBase>
90 buildRetPC(const PCStateBase &cur_pc,
91 const PCStateBase &call_pc) const override
92 {
93 PCStateBase *ret_pc_ptr = call_pc.clone();
94 auto &ret_pc = ret_pc_ptr->as<PCState>();
95 ret_pc.advance();
96 return std::unique_ptr<PCStateBase>{ret_pc_ptr};
97 }
98
99 size_t
100 asBytes(void *buf, size_t size) override
101 {
102 return simpleAsBytes(buf, size, machInst);
103 }
104};
105
110{
111 protected:
113
114 RiscvMacroInst(const char *mnem, ExtMachInst _machInst,
115 OpClass __opClass) :
116 RiscvStaticInst(mnem, _machInst, __opClass)
117 {
118 flags[IsMacroop] = true;
119 }
120
122
124 fetchMicroop(MicroPC upc) const override
125 {
126 return microops[upc];
127 }
128
129 Fault
130 initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const override
131 {
132 panic("Tried to execute a macroop directly!\n");
133 }
134
135 Fault
137 trace::InstRecord *traceData) const override
138 {
139 panic("Tried to execute a macroop directly!\n");
140 }
141
142 Fault
143 execute(ExecContext *xc, trace::InstRecord *traceData) const override
144 {
145 panic("Tried to execute a macroop directly!\n");
146 }
147
148 void size(size_t newSize) override
149 {
150 for (int i = 0; i < microops.size(); i++) {
151 microops[i]->size(newSize);
152 }
153 _size = newSize;
154 }
155
156};
157
162{
163 protected:
164 RiscvMicroInst(const char *mnem, ExtMachInst _machInst,
165 OpClass __opClass) :
166 RiscvStaticInst(mnem, _machInst, __opClass)
167 {
168 flags[IsMicroop] = true;
169 }
170
171 void advancePC(PCStateBase &pcState) const override;
172 void advancePC(ThreadContext *tc) const override;
173};
174
175} // namespace RiscvISA
176} // namespace gem5
177
178#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
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Base class for all RISC-V Macroops.
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
Base class for all RISC-V Microops.
RiscvMicroInst(const char *mnem, ExtMachInst _machInst, OpClass __opClass)
void advancePC(PCStateBase &pcState) const override
Base class for all RISC-V static instructions.
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)
Base, ISA-independent static instruction class.
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:188
constexpr enums::RiscvType RV32
Definition pcstate.hh:56
Bitfield< 2 > i
Bitfield< 3 > x
Definition pagetable.hh:73
Bitfield< 4 > pc
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
uint16_t MicroPC
Definition types.hh:149
Declaration of the Packet class.

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0