gem5 v25.0.0.1
Loading...
Searching...
No Matches
isa.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 The Regents of The University of Michigan
3 * Copyright (c) 2009 The University of Edinburgh
4 * Copyright (c) 2014 Sven Karlsson
5 * Copyright (c) 2016 RISC-V Foundation
6 * Copyright (c) 2016 The University of Virginia
7 * Copyright (c) 2020 Barkhausen Institut
8 * Coypright (c) 2024 University of Rostock
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are
13 * met: redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer;
15 * redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution;
18 * neither the name of the copyright holders nor the names of its
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef __ARCH_RISCV_ISA_HH__
36#define __ARCH_RISCV_ISA_HH__
37
38#include <string>
39#include <unordered_map>
40#include <vector>
41
42#include "arch/generic/isa.hh"
43#include "arch/riscv/pcstate.hh"
45#include "arch/riscv/types.hh"
46#include "base/types.hh"
47
48namespace gem5
49{
50
51struct RiscvISAParams;
52class Checkpoint;
53
54namespace RiscvISA
55{
56
58{
59 PRV_U = 0,
60 PRV_S = 1,
61 // NEVER SET prv = PRV_HS!
62 PRV_HS = 2, // H-extension
64};
65
67{
68 OFF = 0,
70 CLEAN = 2,
71 DIRTY = 3,
72};
73
75
76class ISA : public BaseISA
77{
78 protected:
82
83 bool hpmCounterEnabled(int counter) const;
84
85 // Load reserve - store conditional monitor
86 const int WARN_FAILURE = 10000;
88 std::unordered_map<int, Addr> load_reservation_addrs;
89
93 unsigned vlen;
94
98 unsigned elen;
99
104
113
121
127
128 public:
129 using Params = RiscvISAParams;
130
131 void clear() override;
132
134 newPCState(Addr new_inst_addr=0) const override
135 {
136 return new PCState(rvSext(new_inst_addr), _rvType);
137 }
138
139 public:
140 RegVal readMiscRegNoEffect(RegIndex idx) const override;
141 RegVal readMiscReg(RegIndex idx) override;
142 void setMiscRegNoEffect(RegIndex idx, RegVal val) override;
143 void setMiscReg(RegIndex idx, RegVal val) override;
144
145 // Derived class could provide knowledge of non-standard CSRs to other
146 // components by overriding the two getCSRxxxMap here and properly
147 // implementing the corresponding read/set function. However, customized
148 // maps should always be compatible with the standard maps.
149 virtual const std::unordered_map<int, CSRMetadata>&
151 {
152 return CSRData;
153 }
154 virtual const std::unordered_map<int, RegVal>&
156 {
158 }
159
160 virtual const std::unordered_map<int, RegVal>&
165
166 bool inUserMode() const override;
167 void copyRegsFrom(ThreadContext *src) override;
168
169 void serialize(CheckpointOut &cp) const override;
170 void unserialize(CheckpointIn &cp) override;
171
172 ISA(const Params &p);
173
174 void handleLockedRead(const RequestPtr &req) override;
175
176 bool handleLockedWrite(const RequestPtr &req,
177 Addr cacheBlockMask) override;
178
179 void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override;
180
181 void globalClearExclusive() override;
182
183 void resetThread() override;
184
185 RiscvType rvType() const { return _rvType; }
186
187 bool getEnableRvv() const { return enableRvv; }
188
189 bool virtualizationEnabled() const;
190
191 void
193 {
194 Addr& load_reservation_addr = load_reservation_addrs[cid];
195 load_reservation_addr = INVALID_RESERVATION_ADDR;
196 }
197
199 unsigned getVecLenInBits() { return vlen; }
200 unsigned getVecLenInBytes() { return vlen >> 3; }
201 unsigned getVecElemLenInBits() { return elen; }
202
203 int64_t getVectorLengthInBytes() const override { return vlen >> 3; }
204
206
208
209 bool enableZcd() { return _enableZcd; }
210
211 bool enableSmrnmi() { return _enableSmrnmi; }
212
214 RegIndex idx, uint64_t cause, bool intr) const;
215
217 {
218 return (_rvType == RV32) ? sext<32>(addr) : addr;
219 }
220
221 void swapToVirtCSR(uint64_t& csr, RegIndex& midx, std::string& csrName);
222
223 Fault hpmCounterCheck(int counter, ExtMachInst machInst) const;
224 Fault tvmChecks(uint64_t csr, PrivilegeMode pm, ExtMachInst machInst);
225
226 RegVal backdoorReadCSRAllBits(ExecContext *xc, uint64_t csr);
227 RegVal readCSR(ExecContext *xc, uint64_t csr);
228 void writeCSR(ExecContext *xc, uint64_t csr, RegVal writeData);
229};
230
231// V-bit utilities (H-extension)
232
235
236void setV(ExecContext *xc);
237void setV(ThreadContext *tc);
238
239void resetV(ExecContext *xc);
240void resetV(ThreadContext *tc);
241
243 ExecContext *xc, ExtMachInst machInst, bool set_dirty);
244
246 ExecContext *xc, ExtMachInst machInst, bool set_dirty, bool check_vill);
247
248} // namespace RiscvISA
249} // namespace gem5
250
251std::ostream &operator<<(std::ostream &os, gem5::RiscvISA::PrivilegeMode pm);
252
253#endif // __ARCH_RISCV_ISA_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
BaseISA(const SimObjectParams &p, const std::string &name)
Definition isa.hh:64
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
const bool _wfiResumeOnPending
The WFI instruction can halt the execution of a hart.
Definition isa.hh:112
virtual const std::unordered_map< int, CSRMetadata > & getCSRDataMap() const
Definition isa.hh:150
void setMiscReg(RegIndex idx, RegVal val) override
Definition isa.cc:687
void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override
Definition isa.cc:993
virtual const std::unordered_map< int, RegVal > & getCSRMaskMap() const
Definition isa.hh:155
RegVal readMiscReg(RegIndex idx) override
Definition isa.cc:492
void globalClearExclusive() override
Definition isa.cc:1065
const int WARN_FAILURE
Definition isa.hh:86
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition isa.cc:977
void resetThread() override
Definition isa.cc:1073
PrivilegeModeSet _privilegeModeSet
The combination of privilege modes in Privilege Levels section of RISC-V privileged spec.
Definition isa.hh:103
Fault hpmCounterCheck(int counter, ExtMachInst machInst) const
Definition isa.cc:434
bool enableSmrnmi()
Definition isa.hh:211
Addr rvSext(Addr addr) const
Definition isa.hh:216
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
Definition isa.cc:677
PCStateBase * newPCState(Addr new_inst_addr=0) const override
Definition isa.hh:134
RegVal readMiscRegNoEffect(RegIndex idx) const override
Definition isa.cc:482
bool enableZcd()
Definition isa.hh:209
bool hpmCounterEnabled(int counter) const
unsigned elen
Length of each vector element in bits.
Definition isa.hh:98
Fault tvmChecks(uint64_t csr, PrivilegeMode pm, ExtMachInst machInst)
Definition isa.cc:1112
void copyRegsFrom(ThreadContext *src) override
Definition isa.cc:332
RiscvType rvType() const
Definition isa.hh:185
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
Definition isa.cc:1017
unsigned vlen
Length of each vector register in bits.
Definition isa.hh:93
void swapToVirtCSR(uint64_t &csr, RegIndex &midx, std::string &csrName)
Definition isa.cc:1086
void clear() override
Definition isa.cc:357
bool getEnableRvv() const
Definition isa.hh:187
unsigned getVecElemLenInBits()
Definition isa.hh:201
void writeCSR(ExecContext *xc, uint64_t csr, RegVal writeData)
Definition isa.cc:1213
bool _enableSmrnmi
Resumable non-maskable interrupt Set true to make NMI recoverable.
Definition isa.hh:126
RegVal readCSR(ExecContext *xc, uint64_t csr)
Definition isa.cc:1165
std::vector< RegVal > miscRegFile
Definition isa.hh:80
unsigned getVecLenInBits()
Methods for getting VLEN, VLENB and ELEN values.
Definition isa.hh:199
bool inUserMode() const override
Definition isa.cc:326
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition isa.cc:986
const Addr INVALID_RESERVATION_ADDR
Definition isa.hh:87
bool resumeOnPending()
Definition isa.hh:207
bool _enableZcd
Enable Zcd extensions.
Definition isa.hh:120
virtual Addr getFaultHandlerAddr(RegIndex idx, uint64_t cause, bool intr) const
Definition isa.cc:1321
int64_t getVectorLengthInBytes() const override
This function returns the vector length of the Vector Length Agnostic extension of the ISA.
Definition isa.hh:203
bool virtualizationEnabled() const
Definition isa.cc:1079
void clearLoadReservation(ContextID cid)
Definition isa.hh:192
unsigned getVecLenInBytes()
Definition isa.hh:200
std::unordered_map< int, Addr > load_reservation_addrs
Definition isa.hh:88
RiscvType _rvType
Definition isa.hh:79
PrivilegeModeSet getPrivilegeModeSet()
Definition isa.hh:205
RiscvISAParams Params
Definition isa.hh:129
virtual const std::unordered_map< int, RegVal > & getCSRWriteMaskMap() const
Definition isa.hh:161
ISA(const Params &p)
Definition isa.cc:300
void handleLockedRead(const RequestPtr &req) override
Definition isa.cc:1007
RegVal backdoorReadCSRAllBits(ExecContext *xc, uint64_t csr)
Definition isa.cc:1143
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL vector class.
Definition stl.hh:37
constexpr uint64_t sext(uint64_t val)
Sign-extend an N-bit value to 64 bits.
Definition bitfield.hh:129
GenericISA::DelaySlotPCState< 4 > PCState
Definition pcstate.hh:40
Bitfield< 0 > p
constexpr enums::RiscvType RV32
Definition pcstate.hh:56
Fault updateVPUStatus(ExecContext *xc, ExtMachInst machInst, bool set_dirty, bool check_vill)
Definition isa.cc:1385
enums::PrivilegeModeSet PrivilegeModeSet
Definition pcstate.hh:59
FPUStatus VPUStatus
Definition isa.hh:74
Fault updateFPUStatus(ExecContext *xc, ExtMachInst machInst, bool set_dirty)
Definition isa.cc:1358
void resetV(ExecContext *xc)
Definition isa.cc:1347
enums::RiscvType RiscvType
Definition pcstate.hh:55
const std::unordered_map< int, CSRMetadata > CSRData
Definition misc.hh:604
const std::unordered_map< int, RegVal > CSRMasks[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
Definition misc.hh:1694
const std::unordered_map< int, RegVal > CSRWriteMasks[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
Definition misc.hh:1816
bool virtualizationEnabled(ExecContext *xc)
Definition isa.cc:1331
void setV(ExecContext *xc)
Definition isa.cc:1338
Bitfield< 63 > val
Definition misc.hh:804
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint16_t RegIndex
Definition types.hh:176
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
std::shared_ptr< Request > RequestPtr
Definition request.hh:94
uint64_t RegVal
Definition types.hh:173
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
Packet * PacketPtr
int ContextID
Globally unique thread context ID.
Definition types.hh:239
std::ostream & operator<<(std::ostream &os, gem5::RiscvISA::PrivilegeMode pm)
Definition isa.cc:1422

Generated on Sat Oct 18 2025 08:06:40 for gem5 by doxygen 1.14.0