gem5 v23.0.0.1
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"
36#include "arch/riscv/types.hh"
37#include "cpu/exec_context.hh"
38#include "cpu/static_inst.hh"
39#include "cpu/thread_context.hh"
40#include "mem/packet.hh"
41
42namespace gem5
43{
44
45namespace RiscvISA
46{
47
52{
53 protected:
54 RiscvStaticInst(const char *_mnemonic, ExtMachInst _machInst,
55 OpClass __opClass) :
56 StaticInst(_mnemonic, __opClass), machInst(_machInst)
57 {}
58
59 bool alignmentOk(ExecContext* xc, Addr addr, Addr size) const;
60
61 template <typename T>
62 T
63 rvSelect(T v32, T v64) const
64 {
65 return (machInst.rv_type == RV32) ? v32 : v64;
66 }
67
68 template <typename T32, typename T64>
69 T64 rvExt(T64 x) const { return rvSelect((T64)(T32)x, x); }
70 uint64_t rvZext(uint64_t x) const { return rvExt<uint32_t, uint64_t>(x); }
71 int64_t rvSext(int64_t x) const { return rvExt<int32_t, int64_t>(x); }
72
73 public:
75
76 void
77 advancePC(PCStateBase &pc) const override
78 {
79 pc.as<PCState>().advance();
80 }
81
82 void
83 advancePC(ThreadContext *tc) const override
84 {
85 PCState pc = tc->pcState().as<PCState>();
86 pc.advance();
87 tc->pcState(pc);
88 }
89
90 std::unique_ptr<PCStateBase>
91 buildRetPC(const PCStateBase &cur_pc,
92 const PCStateBase &call_pc) const override
93 {
94 PCStateBase *ret_pc_ptr = call_pc.clone();
95 auto &ret_pc = ret_pc_ptr->as<PCState>();
96 ret_pc.advance();
97 return std::unique_ptr<PCStateBase>{ret_pc_ptr};
98 }
99
100 size_t
101 asBytes(void *buf, size_t size) override
102 {
103 return simpleAsBytes(buf, size, machInst);
104 }
105};
106
111{
112 protected:
114
115 RiscvMacroInst(const char *mnem, ExtMachInst _machInst,
116 OpClass __opClass) :
117 RiscvStaticInst(mnem, _machInst, __opClass)
118 {
119 flags[IsMacroop] = true;
120 }
121
123
125 fetchMicroop(MicroPC upc) const override
126 {
127 return microops[upc];
128 }
129
130 Fault
131 initiateAcc(ExecContext *xc, trace::InstRecord *traceData) const override
132 {
133 panic("Tried to execute a macroop directly!\n");
134 }
135
136 Fault
138 trace::InstRecord *traceData) const override
139 {
140 panic("Tried to execute a macroop directly!\n");
141 }
142
143 Fault
144 execute(ExecContext *xc, trace::InstRecord *traceData) const override
145 {
146 panic("Tried to execute a macroop directly!\n");
147 }
148};
149
154{
155 protected:
156 RiscvMicroInst(const char *mnem, ExtMachInst _machInst,
157 OpClass __opClass) :
158 RiscvStaticInst(mnem, _machInst, __opClass)
159 {
160 flags[IsMicroop] = true;
161 }
162
163 void advancePC(PCStateBase &pcState) const override;
164 void advancePC(ThreadContext *tc) const override;
165};
166
167} // namespace RiscvISA
168} // namespace gem5
169
170#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:72
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.
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...
bool alignmentOk(ExecContext *xc, Addr addr, Addr size) const
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)
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:54
Bitfield< 3 > x
Definition pagetable.hh:73
Bitfield< 4 > pc
Bitfield< 3 > addr
Definition types.hh:84
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
Declaration of the Packet class.

Generated on Mon Jul 10 2023 15:32:02 for gem5 by doxygen 1.9.7