gem5 v24.0.0.0
Loading...
Searching...
No Matches
utility.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010, 2012-2013, 2016-2020, 2022-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) 2003-2005 The Regents of The University of Michigan
15 * Copyright (c) 2007-2008 The Florida State University
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#ifndef __ARCH_ARM_UTILITY_HH__
43#define __ARCH_ARM_UTILITY_HH__
44
45#include "arch/arm/regs/cc.hh"
46#include "arch/arm/regs/int.hh"
47#include "arch/arm/regs/misc.hh"
48#include "arch/arm/types.hh"
49#include "base/logging.hh"
50#include "base/trace.hh"
51#include "base/types.hh"
52#include "cpu/static_inst.hh"
53#include "cpu/thread_context.hh"
54#include "enums/ArmExtension.hh"
55
56namespace gem5
57{
58
59class ArmSystem;
60
61namespace ArmISA
62{
63
64inline bool
65testPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
66{
67 bool n = (nz & 0x2);
68 bool z = (nz & 0x1);
69
70 switch (code) {
71 case COND_EQ: return z;
72 case COND_NE: return !z;
73 case COND_CS: return c;
74 case COND_CC: return !c;
75 case COND_MI: return n;
76 case COND_PL: return !n;
77 case COND_VS: return v;
78 case COND_VC: return !v;
79 case COND_HI: return (c && !z);
80 case COND_LS: return !(c && !z);
81 case COND_GE: return !(n ^ v);
82 case COND_LT: return (n ^ v);
83 case COND_GT: return !(n ^ v || z);
84 case COND_LE: return (n ^ v || z);
85 case COND_AL: return true;
86 case COND_UC: return true;
87 default:
88 panic("Unhandled predicate condition: %d\n", code);
89 }
90}
91
94void sendEvent(ThreadContext *tc);
95
96static inline bool
97inUserMode(CPSR cpsr)
98{
99 return cpsr.mode == MODE_USER || cpsr.mode == MODE_EL0T;
100}
101
102static inline bool
104{
105 return !inUserMode(cpsr);
106}
107
108bool isSecure(ThreadContext *tc);
109
110bool inAArch64(ThreadContext *tc);
111
117
118inline ExceptionLevel
119currEL(CPSR cpsr)
120{
121 return opModeToEL((OperatingMode) (uint8_t)cpsr.mode);
122}
123
128bool HaveExt(ThreadContext *tc, ArmExtension ext);
129
131bool EL2Enabled(ThreadContext *tc);
132
149
151 ExceptionLevel el, bool secure);
152
153bool ELStateUsingAArch32(ThreadContext *tc, ExceptionLevel el, bool secure);
154
156
158
164
166
167bool isBigEndian64(const ThreadContext *tc);
168
169
179
189
190static inline uint8_t
191itState(CPSR psr)
192{
193 ITSTATE it = 0;
194 it.top6 = psr.it2;
195 it.bottom2 = psr.it1;
196
197 return (uint8_t)it;
198}
199
201
210 TCR tcr, bool isInstr);
212 bool isInstr);
214 int topbit);
215int computeAddrTop(ThreadContext *tc, bool selbit, bool isInstr,
216 TCR tcr, ExceptionLevel el);
217
219
221
223
228
231
233Affinity getAffinity(ArmSystem *arm_sys, ThreadContext *tc);
234
235static inline uint32_t
236mcrMrcIssBuild(bool isRead, uint32_t crm, RegIndex rt, uint32_t crn,
237 uint32_t opc1, uint32_t opc2)
238{
239 return (isRead << 0) |
240 (crm << 1) |
241 (rt << 5) |
242 (crn << 10) |
243 (opc1 << 14) |
244 (opc2 << 17);
245}
246
247static inline void
248mcrMrcIssExtract(uint32_t iss, bool &isRead, uint32_t &crm, RegIndex &rt,
249 uint32_t &crn, uint32_t &opc1, uint32_t &opc2)
250{
251 isRead = (iss >> 0) & 0x1;
252 crm = (iss >> 1) & 0xF;
253 rt = (RegIndex)((iss >> 5) & 0xF);
254 crn = (iss >> 10) & 0xF;
255 opc1 = (iss >> 14) & 0x7;
256 opc2 = (iss >> 17) & 0x7;
257}
258
259static inline uint32_t
260mcrrMrrcIssBuild(bool isRead, uint32_t crm, RegIndex rt, RegIndex rt2,
261 uint32_t opc1)
262{
263 return (isRead << 0) |
264 (crm << 1) |
265 (rt << 5) |
266 (rt2 << 10) |
267 (opc1 << 16);
268}
269
270Fault mcrMrc15Trap(const MiscRegIndex miscReg, ExtMachInst machInst,
271 ThreadContext *tc, uint32_t imm);
272bool mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc,
273 uint32_t iss, ExceptionClass *ec=nullptr);
274
275bool mcrMrc14TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc,
276 uint32_t iss);
277
278Fault mcrrMrrc15Trap(const MiscRegIndex miscReg, ExtMachInst machInst,
279 ThreadContext *tc, uint32_t imm);
280bool mcrrMrrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc,
281 uint32_t iss, ExceptionClass *ec=nullptr);
282
284 ExtMachInst machInst, ThreadContext *tc,
285 uint32_t imm, ExceptionClass ec);
287 ThreadContext *tc);
289 ThreadContext *tc);
290bool isGenericTimerHypTrap(const MiscRegIndex miscReg, ThreadContext *tc,
293 ThreadContext *tc);
299 ThreadContext *tc);
301 ThreadContext *tc);
303 ThreadContext *tc);
305 ThreadContext *tc);
307 ThreadContext *tc);
309 ThreadContext *tc);
311 ThreadContext *tc);
313 ThreadContext *tc);
315 ThreadContext *tc);
317 ThreadContext *tc);
319 ThreadContext *tc);
321 ThreadContext *tc);
322
324
327
328// Decodes the register index to access based on the fields used in a MSR
329// or MRS instruction
330bool decodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx,
331 CPSR cpsr, SCR scr, NSACR nsacr,
332 bool checkSecurity=true);
333
334// This wrapper function is used to turn the register index into a source
335// parameter for the instruction. See Operands.isa
336static inline int
338{
339 int regIdx;
340 bool isIntReg;
341 bool validReg;
342
343 validReg = decodeMrsMsrBankedReg(
344 sysM, r, isIntReg, regIdx, 0, 0, 0, false);
345 return (validReg && isIntReg) ? regIdx : int_reg::Zero;
346}
347
351int decodePhysAddrRange64(uint8_t pa_enc);
352
356uint8_t encodePhysAddrRange64(int pa_size);
357
358inline ByteOrder
360{
361 return isBigEndian64(tc) ? ByteOrder::big : ByteOrder::little;
362};
363
365
368
369bool fgtEnabled(ThreadContext *tc);
371
374
375static inline bool
377{
378 return regime == TranslationRegime::EL10;
379}
380
381} // namespace ArmISA
382} // namespace gem5
383
384#endif
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
ThreadContext is the external interface to all thread state for anything outside of the CPU.
STL pair class.
Definition stl.hh:58
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
constexpr RegId Zero
Definition int.hh:228
bool badMode(ThreadContext *tc, OperatingMode mode)
badMode is checking if the execution mode provided as an argument is valid and implemented.
Definition utility.cc:406
bool ELIs32(ThreadContext *tc, ExceptionLevel el)
Definition utility.cc:282
ByteOrder byteOrder(const ThreadContext *tc)
Definition utility.hh:359
static void mcrMrcIssExtract(uint32_t iss, bool &isRead, uint32_t &crm, RegIndex &rt, uint32_t &crn, uint32_t &opc1, uint32_t &opc2)
Definition utility.hh:248
Bitfield< 28 > v
Definition misc_types.hh:54
static bool useVMID(TranslationRegime regime)
Definition utility.hh:376
bool isAArch64AArch32SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:924
bool isGenericTimerVirtSystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:1034
uint8_t encodePhysAddrRange64(int pa_size)
Returns the encoding corresponding to the specified n.
Definition utility.cc:1311
Bitfield< 31 > n
Fault mcrrMrrc15Trap(const MiscRegIndex misc_reg, ExtMachInst mach_inst, ThreadContext *tc, uint32_t imm)
Definition utility.cc:716
void syncVecRegsToElems(ThreadContext *tc)
Definition utility.cc:1334
Bitfield< 15, 12 > rt
Definition types.hh:115
Fault AArch64AArch32SystemAccessTrap(const MiscRegIndex misc_reg, ExtMachInst mach_inst, ThreadContext *tc, uint32_t imm, ExceptionClass ec)
Definition utility.cc:786
bool ELIsInHost(ThreadContext *tc, ExceptionLevel el)
Returns true if the current exception level el is executing a Host OS or an application of a Host OS ...
Definition utility.cc:290
bool isGenericTimerSystemAccessTrapEL3(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:1113
ExceptionLevel debugTargetFrom(ThreadContext *tc, bool secure)
Definition utility.cc:102
Bitfield< 4, 0 > mode
Definition misc_types.hh:74
ExceptionLevel currEL(const ThreadContext *tc)
Returns the current Exception Level (EL) of the provided ThreadContext.
Definition utility.cc:133
bool SPAlignmentCheckEnabled(ThreadContext *tc)
Definition utility.cc:1264
bool isSecure(ThreadContext *tc)
Definition utility.cc:74
static uint32_t mcrrMrrcIssBuild(bool isRead, uint32_t crm, RegIndex rt, RegIndex rt2, uint32_t opc1)
Definition utility.hh:260
Affinity getAffinity(ArmSystem *arm_sys, ThreadContext *tc)
Retrieves MPIDR_EL1.
Definition utility.cc:221
Fault mcrMrc15Trap(const MiscRegIndex misc_reg, ExtMachInst mach_inst, ThreadContext *tc, uint32_t imm)
Definition utility.cc:504
Bitfield< 7, 0 > imm
Definition types.hh:132
ExceptionLevel s1TranslationRegime(ThreadContext *tc, ExceptionLevel el)
Definition utility.cc:238
Addr maskTaggedAddr(Addr addr, ThreadContext *tc, ExceptionLevel el, int topbit)
Definition utility.cc:458
bool longDescFormatInUse(ThreadContext *tc)
Definition utility.cc:140
Addr roundPage(Addr addr)
Definition utility.cc:498
bool isGenericTimerPhysEL1SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:1010
bool isAArch64AArch32SystemAccessTrapEL1(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:800
bool isBigEndian64(const ThreadContext *tc)
Definition utility.cc:382
bool isGenericTimerSystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:938
bool ELStateUsingAArch32(ThreadContext *tc, ExceptionLevel el, bool secure)
Definition utility.cc:374
void sendEvent(ThreadContext *tc)
Send an event (SEV) to a specific PE if there isn't already a pending event.
Definition utility.cc:65
bool isGenericTimerCommonEL0HypTrap(const MiscRegIndex misc_reg, ThreadContext *tc, ExceptionClass *ec)
Definition utility.cc:840
Bitfield< 11 > z
bool isGenericTimerPhysHypTrap(const MiscRegIndex misc_reg, ThreadContext *tc, ExceptionClass *ec)
Definition utility.cc:856
Bitfield< 7, 5 > opc2
Definition types.hh:106
bool isGenericTimerCommonEL0SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:972
bool ELIs64(ThreadContext *tc, ExceptionLevel el)
Definition utility.cc:276
bool isGenericTimerSystemAccessTrapEL1(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:878
bool condGenericTimerCommonEL0SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:1044
bool isGenericTimerHypTrap(const MiscRegIndex misc_reg, ThreadContext *tc, ExceptionClass *ec)
Definition utility.cc:814
static bool inPrivilegedMode(CPSR cpsr)
Definition utility.hh:103
bool mcrMrc15TrapToHyp(const MiscRegIndex misc_reg, ThreadContext *tc, uint32_t iss, ExceptionClass *ec)
Definition utility.cc:514
bool isSecureBelowEL3(ThreadContext *tc)
Definition utility.cc:86
TranslationRegime translationRegime(ThreadContext *tc, ExceptionLevel el)
Definition utility.cc:1379
bool fgtEnabled(ThreadContext *tc)
Definition utility.cc:1360
bool isUnpriviledgeAccess(ThreadContext *tc)
Definition utility.cc:1246
ConditionCode
Definition cc.hh:104
@ COND_EQ
Definition cc.hh:105
@ COND_PL
Definition cc.hh:110
@ COND_MI
Definition cc.hh:109
@ COND_GE
Definition cc.hh:115
@ COND_LS
Definition cc.hh:114
@ COND_LE
Definition cc.hh:118
@ COND_VC
Definition cc.hh:112
@ COND_HI
Definition cc.hh:113
@ COND_CC
Definition cc.hh:108
@ COND_GT
Definition cc.hh:117
@ COND_UC
Definition cc.hh:120
@ COND_NE
Definition cc.hh:106
@ COND_VS
Definition cc.hh:111
@ COND_LT
Definition cc.hh:116
@ COND_AL
Definition cc.hh:119
@ COND_CS
Definition cc.hh:107
bool EL2Enabled(ThreadContext *tc)
Definition utility.cc:267
ExceptionLevel translationEl(TranslationRegime regime)
Definition utility.cc:1398
std::pair< bool, bool > ELUsingAArch32K(ThreadContext *tc, ExceptionLevel el)
This function checks whether selected EL provided as an argument is using the AArch32 ISA.
Definition utility.cc:301
bool IsSecureEL2Enabled(ThreadContext *tc)
Definition utility.cc:253
int computeAddrTop(ThreadContext *tc, bool selbit, bool is_instr, TCR tcr, ExceptionLevel el)
Definition utility.cc:412
static uint32_t mcrMrcIssBuild(bool isRead, uint32_t crm, RegIndex rt, uint32_t crn, uint32_t opc1, uint32_t opc2)
Definition utility.hh:236
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 24, 0 > iss
bool mcrMrc14TrapToHyp(const MiscRegIndex misc_reg, ThreadContext *tc, uint32_t iss)
Definition utility.cc:661
bool isHcrxEL2Enabled(ThreadContext *tc)
Definition utility.cc:1368
bool badMode32(ThreadContext *tc, OperatingMode mode)
badMode is checking if the execution mode provided as an argument is valid and implemented for AArch3...
Definition utility.cc:400
bool decodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx, CPSR cpsr, SCR scr, NSACR nsacr, bool checkSecurity)
Definition utility.cc:1129
RegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
This helper function is returning the value of MPIDR_EL1.
Definition utility.cc:173
void syncVecElemsToRegs(ThreadContext *tc)
Definition utility.cc:1346
static bool inUserMode(CPSR cpsr)
Definition utility.hh:97
bool isGenericTimerPhysEL0SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:985
Bitfield< 3, 2 > el
Definition misc_types.hh:73
bool testPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
Definition utility.hh:65
bool isSecureAtEL(ThreadContext *tc, ExceptionLevel el)
Definition utility.cc:93
std::pair< bool, bool > ELStateUsingAArch32K(ThreadContext *tc, ExceptionLevel el, bool secure)
Definition utility.cc:322
bool condGenericTimerPhysEL1SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:1105
static int decodeMrsMsrBankedIntRegIndex(uint8_t sysM, bool r)
Definition utility.hh:337
bool condGenericTimerSystemAccessTrapEL1(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:897
int decodePhysAddrRange64(uint8_t pa_enc)
Returns the n.
Definition utility.cc:1288
static ExceptionLevel opModeToEL(OperatingMode mode)
Definition types.hh:400
RegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
This helper function is either returing the value of MPIDR_EL1 (by calling getMPIDR),...
Definition utility.cc:147
bool inAArch64(ThreadContext *tc)
Definition utility.cc:126
static uint8_t itState(CPSR psr)
Definition utility.hh:191
bool HaveExt(ThreadContext *tc, ArmExtension ext)
Returns true if the provided ThreadContext supports the ArmExtension passed as a second argument.
Definition utility.cc:231
Addr purifyTaggedAddr(Addr addr, ThreadContext *tc, ExceptionLevel el, TCR tcr, bool is_instr)
Removes the tag from tagged addresses if that mode is enabled.
Definition utility.cc:473
bool condGenericTimerPhysHypTrap(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:863
Addr truncPage(Addr addr)
Definition utility.cc:492
bool condGenericTimerCommonEL1SystemAccessTrapEL2(const MiscRegIndex misc_reg, ThreadContext *tc)
Definition utility.cc:1071
Bitfield< 12 > ext
bool mcrrMrrc15TrapToHyp(const MiscRegIndex misc_reg, ThreadContext *tc, uint32_t iss, ExceptionClass *ec)
Definition utility.cc:726
Bitfield< 3 > addr
Definition types.hh:84
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< FaultBase > Fault
Definition types.hh:249
uint64_t RegVal
Definition types.hh:173
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