gem5 [DEVELOP-FOR-25.0]
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 <unordered_map>
39#include <vector>
40
41#include "arch/generic/isa.hh"
42#include "arch/riscv/pcstate.hh"
44#include "arch/riscv/types.hh"
45#include "base/types.hh"
46
47namespace gem5
48{
49
50struct RiscvISAParams;
51class Checkpoint;
52
53namespace RiscvISA
54{
55
57{
58 PRV_U = 0,
59 PRV_S = 1,
61};
62
64{
65 OFF = 0,
67 CLEAN = 2,
68 DIRTY = 3,
69};
70
72
73class ISA : public BaseISA
74{
75 protected:
79
80 bool hpmCounterEnabled(int counter) const;
81
82 // Load reserve - store conditional monitor
83 const int WARN_FAILURE = 10000;
85 std::unordered_map<int, Addr> load_reservation_addrs;
86
90 unsigned vlen;
91
95 unsigned elen;
96
101
110
118
124
125 public:
126 using Params = RiscvISAParams;
127
128 void clear() override;
129
131 newPCState(Addr new_inst_addr=0) const override
132 {
133 return new PCState(rvSext(new_inst_addr), _rvType);
134 }
135
136 public:
137 RegVal readMiscRegNoEffect(RegIndex idx) const override;
138 RegVal readMiscReg(RegIndex idx) override;
139 void setMiscRegNoEffect(RegIndex idx, RegVal val) override;
140 void setMiscReg(RegIndex idx, RegVal val) override;
141
142 // Derived class could provide knowledge of non-standard CSRs to other
143 // components by overriding the two getCSRxxxMap here and properly
144 // implementing the corresponding read/set function. However, customized
145 // maps should always be compatible with the standard maps.
146 virtual const std::unordered_map<int, CSRMetadata>&
148 {
149 return CSRData;
150 }
151 virtual const std::unordered_map<int, RegVal>&
153 {
155 }
156
157 bool inUserMode() const override;
158 void copyRegsFrom(ThreadContext *src) override;
159
160 void serialize(CheckpointOut &cp) const override;
161 void unserialize(CheckpointIn &cp) override;
162
163 ISA(const Params &p);
164
165 void handleLockedRead(const RequestPtr &req) override;
166
167 bool handleLockedWrite(const RequestPtr &req,
168 Addr cacheBlockMask) override;
169
170 void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override;
171
172 void globalClearExclusive() override;
173
174 void resetThread() override;
175
176 RiscvType rvType() const { return _rvType; }
177
178 bool getEnableRvv() const { return enableRvv; }
179
180 void
182 {
183 Addr& load_reservation_addr = load_reservation_addrs[cid];
184 load_reservation_addr = INVALID_RESERVATION_ADDR;
185 }
186
188 unsigned getVecLenInBits() { return vlen; }
189 unsigned getVecLenInBytes() { return vlen >> 3; }
190 unsigned getVecElemLenInBits() { return elen; }
191
192 int64_t getVectorLengthInBytes() const override { return vlen >> 3; }
193
195
197
198 bool enableZcd() { return _enableZcd; }
199
200 bool enableSmrnmi() { return _enableSmrnmi; }
201
203 RegIndex idx, uint64_t cause, bool intr) const;
204
206 {
207 return (_rvType == RV32) ? sext<32>(addr) : addr;
208 }
209};
210
211} // namespace RiscvISA
212} // namespace gem5
213
214std::ostream &operator<<(std::ostream &os, gem5::RiscvISA::PrivilegeMode pm);
215
216#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
const bool _wfiResumeOnPending
The WFI instruction can halt the execution of a hart.
Definition isa.hh:109
virtual const std::unordered_map< int, CSRMetadata > & getCSRDataMap() const
Definition isa.hh:147
void setMiscReg(RegIndex idx, RegVal val) override
Definition isa.cc:687
void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override
Definition isa.cc:988
virtual const std::unordered_map< int, RegVal > & getCSRMaskMap() const
Definition isa.hh:152
RegVal readMiscReg(RegIndex idx) override
Definition isa.cc:429
void globalClearExclusive() override
Definition isa.cc:1060
const int WARN_FAILURE
Definition isa.hh:83
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition isa.cc:972
void resetThread() override
Definition isa.cc:1068
PrivilegeModeSet _privilegeModeSet
The combination of privilege modes in Privilege Levels section of RISC-V privileged spec.
Definition isa.hh:100
bool enableSmrnmi()
Definition isa.hh:200
Addr rvSext(Addr addr) const
Definition isa.hh:205
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
Definition isa.cc:677
PCStateBase * newPCState(Addr new_inst_addr=0) const override
Definition isa.hh:131
RegVal readMiscRegNoEffect(RegIndex idx) const override
Definition isa.cc:419
bool enableZcd()
Definition isa.hh:198
bool hpmCounterEnabled(int counter) const
Definition isa.cc:390
unsigned elen
Length of each vector element in bits.
Definition isa.hh:95
void copyRegsFrom(ThreadContext *src) override
Definition isa.cc:300
RiscvType rvType() const
Definition isa.hh:176
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
Definition isa.cc:1012
unsigned vlen
Length of each vector register in bits.
Definition isa.hh:90
void clear() override
Definition isa.cc:325
bool getEnableRvv() const
Definition isa.hh:178
unsigned getVecElemLenInBits()
Definition isa.hh:190
bool _enableSmrnmi
Resumable non-maskable interrupt Set true to make NMI recoverable.
Definition isa.hh:123
std::vector< RegVal > miscRegFile
Definition isa.hh:77
unsigned getVecLenInBits()
Methods for getting VLEN, VLENB and ELEN values.
Definition isa.hh:188
bool inUserMode() const override
Definition isa.cc:294
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition isa.cc:981
const Addr INVALID_RESERVATION_ADDR
Definition isa.hh:84
bool resumeOnPending()
Definition isa.hh:196
bool _enableZcd
Enable Zcd extensions.
Definition isa.hh:117
virtual Addr getFaultHandlerAddr(RegIndex idx, uint64_t cause, bool intr) const
Definition isa.cc:1074
int64_t getVectorLengthInBytes() const override
This function returns the vector length of the Vector Length Agnostic extension of the ISA.
Definition isa.hh:192
void clearLoadReservation(ContextID cid)
Definition isa.hh:181
unsigned getVecLenInBytes()
Definition isa.hh:189
std::unordered_map< int, Addr > load_reservation_addrs
Definition isa.hh:85
RiscvType _rvType
Definition isa.hh:76
PrivilegeModeSet getPrivilegeModeSet()
Definition isa.hh:194
RiscvISAParams Params
Definition isa.hh:126
ISA(const Params &p)
Definition isa.cc:267
void handleLockedRead(const RequestPtr &req) override
Definition isa.cc:1002
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
enums::PrivilegeModeSet PrivilegeModeSet
Definition pcstate.hh:59
FPUStatus VPUStatus
Definition isa.hh:71
enums::RiscvType RiscvType
Definition pcstate.hh:55
const std::unordered_map< int, CSRMetadata > CSRData
Definition misc.hh:554
const std::unordered_map< int, RegVal > CSRMasks[enums::Num_RiscvType][enums::Num_PrivilegeModeSet]
Definition misc.hh:1599
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< 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:1087

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