gem5 v24.0.0.0
Loading...
Searching...
No Matches
isa.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2012-2024 Arm Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2009 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#ifndef __ARCH_ARM_ISA_HH__
42#define __ARCH_ARM_ISA_HH__
43
45#include "arch/arm/mmu.hh"
46#include "arch/arm/pcstate.hh"
47#include "arch/arm/regs/int.hh"
48#include "arch/arm/regs/mat.hh"
49#include "arch/arm/regs/misc.hh"
50#include "arch/arm/regs/vec.hh"
52#include "arch/arm/system.hh"
53#include "arch/arm/types.hh"
54#include "arch/arm/utility.hh"
55#include "arch/generic/isa.hh"
56#include "debug/Checkpoint.hh"
57#include "enums/DecoderFlavor.hh"
58#include "sim/sim_object.hh"
59
60namespace gem5
61{
62
63struct ArmISAParams;
64struct DummyArmISADeviceParams;
65class Checkpoint;
66class EventManager;
67
68namespace ArmISA
69{
70 class ISA : public BaseISA
71 {
72 protected:
73 // Parent system
75
76 // Micro Architecture
77 const enums::DecoderFlavor _decoderFlavor;
78
81
82 // PMU belonging to this ISA
84
85 // Generic timer interface belonging to this ISA
86 std::unique_ptr<BaseISADevice> timer;
87
88 // GICv3 CPU interface belonging to this ISA
89 std::unique_ptr<BaseISADevice> gicv3CpuInterface;
90
91 // Cached copies of system-level properties
96
98 unsigned sveVL;
99
101 unsigned smeVL;
102
105
111
113
115 InitReg(uint32_t reg)
116 {
118 }
119
121
125
128
129 void
130 updateRegMap(CPSR cpsr)
131 {
132 if (cpsr.width == 0) {
134 } else {
135 switch (cpsr.mode) {
136 case MODE_USER:
137 case MODE_SYSTEM:
139 break;
140 case MODE_FIQ:
142 break;
143 case MODE_IRQ:
145 break;
146 case MODE_SVC:
148 break;
149 case MODE_MON:
151 break;
152 case MODE_ABORT:
154 break;
155 case MODE_HYP:
157 break;
158 case MODE_UNDEFINED:
160 break;
161 default:
162 panic("Unrecognized mode setting in CPSR.\n");
163 }
164 }
165 }
166
167 public:
168 const RegId &mapIntRegId(RegIndex idx) const { return intRegMap[idx]; }
169
170 public:
171 void clear() override;
172
173 protected:
178
179 public:
180 SelfDebug*
182 {
183 return selfDebug;
184 }
185
186 static SelfDebug*
188 {
189 auto *arm_isa = static_cast<ArmISA::ISA *>(tc->getIsaPtr());
190 return arm_isa->getSelfDebug();
191 }
192
193 const ArmRelease* getRelease() const { return release; }
194
195 RegVal readMiscRegNoEffect(RegIndex idx) const override;
196 RegVal readMiscReg(RegIndex idx) override;
197 void setMiscRegNoEffect(RegIndex idx, RegVal val) override;
198 void setMiscReg(RegIndex, RegVal val) override;
199
202
203 int
205 {
206 assert(reg >= 0);
207 int flat_idx = reg;
208
209 if (reg == MISCREG_SPSR) {
210 CPSR cpsr = miscRegs[MISCREG_CPSR];
211 switch (cpsr.mode) {
212 case MODE_EL0T:
213 warn("User mode does not have SPSR\n");
214 flat_idx = MISCREG_SPSR;
215 break;
216 case MODE_EL1T:
217 case MODE_EL1H:
218 flat_idx = MISCREG_SPSR_EL1;
219 break;
220 case MODE_EL2T:
221 case MODE_EL2H:
222 flat_idx = MISCREG_SPSR_EL2;
223 break;
224 case MODE_EL3T:
225 case MODE_EL3H:
226 flat_idx = MISCREG_SPSR_EL3;
227 break;
228 case MODE_USER:
229 warn("User mode does not have SPSR\n");
230 flat_idx = MISCREG_SPSR;
231 break;
232 case MODE_FIQ:
233 flat_idx = MISCREG_SPSR_FIQ;
234 break;
235 case MODE_IRQ:
236 flat_idx = MISCREG_SPSR_IRQ;
237 break;
238 case MODE_SVC:
239 flat_idx = MISCREG_SPSR_SVC;
240 break;
241 case MODE_MON:
242 flat_idx = MISCREG_SPSR_MON;
243 break;
244 case MODE_ABORT:
245 flat_idx = MISCREG_SPSR_ABT;
246 break;
247 case MODE_HYP:
248 flat_idx = MISCREG_SPSR_HYP;
249 break;
250 case MODE_UNDEFINED:
251 flat_idx = MISCREG_SPSR_UND;
252 break;
253 default:
254 warn("Trying to access SPSR in an invalid mode: %d\n",
255 cpsr.mode);
256 flat_idx = MISCREG_SPSR;
257 break;
258 }
259 } else if (lookUpMiscReg[reg].info[MISCREG_MUTEX]) {
260 // Mutually exclusive CP15 register
261 switch (reg) {
265 {
266 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
267 // If the muxed reg has been flattened, work out the
268 // offset and apply it to the unmuxed reg
269 int idxOffset = reg - MISCREG_PRRR_MAIR0;
270 if (ttbcr.eae)
272 idxOffset);
273 else
274 flat_idx = flattenMiscIndex(MISCREG_PRRR +
275 idxOffset);
276 }
277 break;
281 {
282 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
283 // If the muxed reg has been flattened, work out the
284 // offset and apply it to the unmuxed reg
285 int idxOffset = reg - MISCREG_NMRR_MAIR1;
286 if (ttbcr.eae)
288 idxOffset);
289 else
290 flat_idx = flattenMiscIndex(MISCREG_NMRR +
291 idxOffset);
292 }
293 break;
295 {
296 PMSELR pmselr = miscRegs[MISCREG_PMSELR];
297 if (pmselr.sel == 31)
299 else
301 }
302 break;
303 default:
304 panic("Unrecognized misc. register.\n");
305 break;
306 }
307 } else {
308 if (lookUpMiscReg[reg].info[MISCREG_BANKED]) {
309 bool secure_reg = !highestELIs64 && inSecureState();
310 flat_idx += secure_reg ? 2 : 1;
311 } else {
313 !inSecureState());
314 }
315 }
316 return flat_idx;
317 }
318
323 int redirectRegVHE(int misc_reg);
324
325 int
327 {
328 int reg_as_int = static_cast<int>(reg);
330 reg_as_int += (release->has(ArmExtension::SECURITY) && !ns) ?
331 2 : 1;
332 }
333 return reg_as_int;
334 }
335
337 getMiscIndices(int misc_reg) const
338 {
339 // Note: indexes of AArch64 registers are left unchanged
340 int flat_idx = flattenMiscIndex(misc_reg);
341
342 if (lookUpMiscReg[flat_idx].lower == 0) {
343 return std::make_pair(flat_idx, 0);
344 }
345
346 // do additional S/NS flattenings if mapped to NS while in S
347 bool S = !highestELIs64 && inSecureState();
348
349 int lower = lookUpMiscReg[flat_idx].lower;
350 int upper = lookUpMiscReg[flat_idx].upper;
351 // upper == 0, which is CPSR, is not MISCREG_BANKED_CHILD (no-op)
352 lower += S && lookUpMiscReg[lower].info[MISCREG_BANKED_CHILD];
353 upper += S && lookUpMiscReg[upper].info[MISCREG_BANKED_CHILD];
354 return std::make_pair(lower, upper);
355 }
356
358 bool inSecureState() const;
359
363 ExceptionLevel currEL() const;
364
365 unsigned getCurSveVecLenInBits() const;
366
367 unsigned getCurSveVecLenInBitsAtReset() const { return sveVL * 128; }
368
369 unsigned getCurSmeVecLenInBits() const;
370
371 unsigned getCurSmeVecLenInBitsAtReset() const { return smeVL * 128; }
372
373 template <typename Elem>
374 static void
375 zeroSveVecRegUpperPart(Elem *v, unsigned eCount)
376 {
377 static_assert(sizeof(Elem) <= sizeof(uint64_t),
378 "Elem type is too large.");
379 eCount *= (sizeof(uint64_t) / sizeof(Elem));
380 for (int i = 16 / sizeof(Elem); i < eCount; ++i) {
381 v[i] = 0;
382 }
383 }
384
385 void serialize(CheckpointOut &cp) const override;
386 void unserialize(CheckpointIn &cp) override;
387
388 void startup() override;
389
390 void setupThreadContext();
391
393 newPCState(Addr new_inst_addr=0) const override
394 {
395 return new PCState(new_inst_addr);
396 }
397
398 void takeOverFrom(ThreadContext *new_tc,
399 ThreadContext *old_tc) override;
400
401 enums::DecoderFlavor decoderFlavor() const { return _decoderFlavor; }
402
403 PARAMS(ArmISA);
404
405 ISA(const Params &p);
406
407 uint64_t
408 getExecutingAsid() const override
409 {
411 }
412
413 bool
414 inUserMode() const override
415 {
416 CPSR cpsr = miscRegs[MISCREG_CPSR];
417 return ArmISA::inUserMode(cpsr);
418 }
419
420 void copyRegsFrom(ThreadContext *src) override;
421
422 void handleLockedRead(const RequestPtr &req) override;
423 void handleLockedRead(ExecContext *xc, const RequestPtr &req) override;
424
425 bool handleLockedWrite(const RequestPtr &req,
426 Addr cacheBlockMask) override;
427 bool handleLockedWrite(ExecContext *xc, const RequestPtr &req,
428 Addr cacheBlockMask) override;
429
430 void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override;
432 Addr cacheBlockMask) override;
433 void handleLockedSnoopHit() override;
434 void handleLockedSnoopHit(ExecContext *xc) override;
435
436 void globalClearExclusive() override;
437 void globalClearExclusive(ExecContext *xc) override;
438
439 int64_t getVectorLengthInBytes() const override { return sveVL * 16; }
440 };
441
442} // namespace ArmISA
443} // namespace gem5
444
445#endif
Base class for devices that use the MiscReg interfaces.
Definition isa_device.hh:62
Dummy device that prints a warning when it is accessed.
Definition isa_device.hh:98
bool inSecureState() const
Return true if the PE is in Secure state.
Definition isa.cc:1435
const RegId & mapIntRegId(RegIndex idx) const
Definition isa.hh:168
void setMiscRegReset(RegIndex, RegVal val)
Definition isa.cc:1382
unsigned getCurSveVecLenInBits() const
Definition isa.cc:1467
static SelfDebug * getSelfDebug(ThreadContext *tc)
Definition isa.hh:187
ExceptionLevel currEL() const
Returns the current Exception Level (EL) of the ISA object.
Definition isa.cc:1459
void takeOverFrom(ThreadContext *new_tc, ThreadContext *old_tc) override
Definition isa.cc:184
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition isa.cc:1568
void copyRegsFrom(ThreadContext *src) override
Definition isa.cc:191
unsigned getCurSveVecLenInBitsAtReset() const
Definition isa.hh:367
const enums::DecoderFlavor _decoderFlavor
Definition isa.hh:77
DummyISADevice dummyDevice
Dummy device for to handle non-existing ISA devices.
Definition isa.hh:80
RegVal readMiscRegReset(RegIndex) const
Definition isa.cc:1375
void setupThreadContext()
Definition isa.cc:168
void setMiscRegNoEffect(RegIndex idx, RegVal val) override
Definition isa.cc:662
uint8_t physAddrRange
Definition isa.hh:95
void addressTranslation64(MMU::ArmTranslationType tran_type, BaseMMU::Mode mode, Request::Flags flags, RegVal val)
Definition isa.cc:1598
int snsBankedIndex64(MiscRegIndex reg, bool ns) const
Definition isa.hh:326
bool haveLargeAsid64
Definition isa.hh:94
void handleLockedSnoop(PacketPtr pkt, Addr cacheBlockMask) override
Definition isa.cc:1747
void clear() override
Definition isa.cc:138
int flattenMiscIndex(int reg) const
Definition isa.hh:204
std::pair< int, int > getMiscIndices(int misc_reg) const
Definition isa.hh:337
PCStateBase * newPCState(Addr new_inst_addr=0) const override
Definition isa.hh:393
RegVal miscRegs[NUM_MISCREGS]
Definition isa.hh:126
unsigned smeVL
SME vector length in quadwords.
Definition isa.hh:101
BaseISADevice * pmu
Definition isa.hh:83
static void zeroSveVecRegUpperPart(Elem *v, unsigned eCount)
Definition isa.hh:375
std::unique_ptr< BaseISADevice > timer
Definition isa.hh:86
bool handleLockedWrite(const RequestPtr &req, Addr cacheBlockMask) override
Definition isa.cc:1836
SelfDebug * selfDebug
Definition isa.hh:112
uint64_t getExecutingAsid() const override
Definition isa.hh:408
int64_t getVectorLengthInBytes() const override
This function returns the vector length of the Vector Length Agnostic extension of the ISA.
Definition isa.hh:439
void globalClearExclusive() override
Definition isa.cc:1849
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition isa.cc:1577
void updateRegMap(CPSR cpsr)
Definition isa.hh:130
void startup() override
startup() is the final initialization call before simulation.
Definition isa.cc:153
int redirectRegVHE(int misc_reg)
Returns the enconcing equivalent when VHE is implemented and HCR_EL2.E2H is enabled and executing at ...
Definition isa.cc:233
BaseISADevice & getGICv3CPUInterface()
Definition isa.cc:1410
ArmSystem * system
Definition isa.hh:74
BaseISADevice & getGenericTimer()
Definition isa.cc:1389
RegVal readMiscRegNoEffect(RegIndex idx) const override
Definition isa.cc:387
const ArmRelease * getRelease() const
Definition isa.hh:193
bool impdefAsNop
If true, accesses to IMPLEMENTATION DEFINED registers are treated as NOP hence not causing UNDEFINED ...
Definition isa.hh:110
void setMiscReg(RegIndex, RegVal val) override
Definition isa.cc:684
unsigned sveVL
SVE vector length in quadwords.
Definition isa.hh:98
const MiscRegLUTEntryInitializer InitReg(uint32_t reg)
Definition isa.hh:115
void handleLockedRead(const RequestPtr &req) override
Definition isa.cc:1759
const RegId * intRegMap
Definition isa.hh:127
enums::DecoderFlavor decoderFlavor() const
Definition isa.hh:401
void addressTranslation(MMU::ArmTranslationType tran_type, BaseMMU::Mode mode, Request::Flags flags, RegVal val)
Definition isa.cc:1649
void initializeMiscRegMetadata()
Definition misc.cc:2876
const ArmRelease * release
This could be either a FS or a SE release.
Definition isa.hh:104
bool highestELIs64
Definition isa.hh:92
RegVal readMiscReg(RegIndex idx) override
Definition isa.cc:411
void handleLockedSnoopHit() override
Definition isa.cc:1777
SelfDebug * getSelfDebug() const
Definition isa.hh:181
ISA(const Params &p)
Definition isa.cc:86
unsigned getCurSmeVecLenInBitsAtReset() const
Definition isa.hh:371
std::unique_ptr< BaseISADevice > gicv3CpuInterface
Definition isa.hh:89
ExceptionLevel highestEL
Definition isa.hh:93
bool inUserMode() const override
Definition isa.hh:414
unsigned getCurSmeVecLenInBits() const
Definition isa.cc:1518
Metadata table accessible via the value of the register.
Definition misc.hh:1300
bool has(ArmExtension ext) const
Definition system.hh:76
ThreadContext * tc
Definition isa.hh:68
The ExecContext is an abstract base class the provides the interface used by the ISA to manipulate th...
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
SimObjectParams Params
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual BaseISA * getIsaPtr() const =0
STL pair class.
Definition stl.hh:58
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
uint8_t flags
Definition helpers.cc:87
#define warn(...)
Definition logging.hh:256
const RegMap RegIrqMap
Definition int.hh:535
const RegMap RegUsrMap
Definition int.hh:451
const RegMap RegSvcMap
Definition int.hh:479
const RegMap RegFiqMap
Definition int.hh:549
const RegMap RegAbtMap
Definition int.hh:507
const RegMap RegMonMap
Definition int.hh:493
const RegMap Reg64Map
Definition int.hh:437
const RegMap RegUndMap
Definition int.hh:521
const RegMap RegHypMap
Definition int.hh:465
Bitfield< 28 > v
Definition misc_types.hh:54
@ MODE_UNDEFINED
Definition types.hh:303
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > ns
@ MISCREG_PRRR_MAIR0
Definition misc.hh:90
@ MISCREG_NMRR_MAIR1_S
Definition misc.hh:95
@ MISCREG_SPSR_HYP
Definition misc.hh:74
@ MISCREG_SPSR_EL2
Definition misc.hh:639
@ MISCREG_TTBCR
Definition misc.hh:266
@ MISCREG_SPSR_SVC
Definition misc.hh:71
@ MISCREG_PMXEVTYPER
Definition misc.hh:366
@ MISCREG_SPSR_UND
Definition misc.hh:75
@ MISCREG_SPSR_IRQ
Definition misc.hh:70
@ MISCREG_SPSR_ABT
Definition misc.hh:73
@ MISCREG_PRRR
Definition misc.hh:375
@ MISCREG_NMRR_MAIR1
Definition misc.hh:93
@ MISCREG_CPSR
Definition misc.hh:67
@ MISCREG_NMRR
Definition misc.hh:381
@ MISCREG_MAIR1
Definition misc.hh:384
@ MISCREG_PMCCFILTR
Definition misc.hh:367
@ MISCREG_CONTEXTIDR
Definition misc.hh:405
@ MISCREG_SPSR_EL3
Definition misc.hh:646
@ MISCREG_SPSR_EL1
Definition misc.hh:626
@ MISCREG_PMSELR
Definition misc.hh:362
@ MISCREG_SPSR_MON
Definition misc.hh:72
@ MISCREG_PRRR_MAIR0_S
Definition misc.hh:92
@ MISCREG_NMRR_MAIR1_NS
Definition misc.hh:94
@ MISCREG_PRRR_MAIR0_NS
Definition misc.hh:91
@ MISCREG_SPSR
Definition misc.hh:68
@ MISCREG_PMXEVTYPER_PMCCFILTR
Definition misc.hh:96
@ MISCREG_SPSR_FIQ
Definition misc.hh:69
@ MISCREG_MAIR0
Definition misc.hh:378
static bool inUserMode(CPSR cpsr)
Definition utility.hh:97
@ MISCREG_MUTEX
Definition misc.hh:1210
@ MISCREG_BANKED_CHILD
Definition misc.hh:1218
@ MISCREG_BANKED
Definition misc.hh:1212
@ MISCREG_BANKED64
Definition misc.hh:1215
std::vector< struct MiscRegLUTEntry > lookUpMiscReg(NUM_MISCREGS)
Definition misc.hh:1694
GenericISA::DelaySlotPCState< 4 > PCState
Definition pcstate.hh:40
Bitfield< 0 > p
Bitfield< 5, 3 > reg
Definition types.hh:92
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria 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

Generated on Tue Jun 18 2024 16:23:57 for gem5 by doxygen 1.11.0