gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utility.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, 2012-2013, 2016-2020 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/isa_traits.hh"
46 #include "arch/arm/miscregs.hh"
47 #include "arch/arm/types.hh"
48 #include "base/logging.hh"
49 #include "base/trace.hh"
50 #include "base/types.hh"
51 #include "cpu/static_inst.hh"
52 #include "cpu/thread_context.hh"
53 
54 class ArmSystem;
55 
56 namespace ArmISA {
57 
58 inline PCState
59 buildRetPC(const PCState &curPC, const PCState &callPC)
60 {
61  PCState retPC = callPC;
62  retPC.uEnd();
63  return retPC;
64 }
65 
66 inline bool
67 testPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
68 {
69  bool n = (nz & 0x2);
70  bool z = (nz & 0x1);
71 
72  switch (code)
73  {
74  case COND_EQ: return z;
75  case COND_NE: return !z;
76  case COND_CS: return c;
77  case COND_CC: return !c;
78  case COND_MI: return n;
79  case COND_PL: return !n;
80  case COND_VS: return v;
81  case COND_VC: return !v;
82  case COND_HI: return (c && !z);
83  case COND_LS: return !(c && !z);
84  case COND_GE: return !(n ^ v);
85  case COND_LT: return (n ^ v);
86  case COND_GT: return !(n ^ v || z);
87  case COND_LE: return (n ^ v || z);
88  case COND_AL: return true;
89  case COND_UC: return true;
90  default:
91  panic("Unhandled predicate condition: %d\n", code);
92  }
93 }
94 
95 void copyRegs(ThreadContext *src, ThreadContext *dest);
96 
97 static inline void
99 {
100  panic("Copy Misc. Regs Not Implemented Yet\n");
101 }
102 
105 void sendEvent(ThreadContext *tc);
106 
107 static inline bool
108 inUserMode(CPSR cpsr)
109 {
110  return cpsr.mode == MODE_USER || cpsr.mode == MODE_EL0T;
111 }
112 
113 static inline bool
115 {
117 }
118 
119 static inline bool
121 {
122  return !inUserMode(cpsr);
123 }
124 
125 static inline bool
127 {
128  return !inUserMode(tc);
129 }
130 
131 bool inAArch64(ThreadContext *tc);
132 
133 static inline OperatingMode
135 {
136  CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
137  return (OperatingMode) (uint8_t) cpsr.mode;
138 }
139 
140 static inline ExceptionLevel
142 {
143  return opModeToEL(currOpMode(tc));
144 }
145 
146 inline ExceptionLevel
147 currEL(CPSR cpsr)
148 {
149  return opModeToEL((OperatingMode) (uint8_t)cpsr.mode);
150 }
151 
155 bool EL2Enabled(ThreadContext *tc);
156 
174 
175 bool ELIs32(ThreadContext *tc, ExceptionLevel el);
176 
177 bool ELIs64(ThreadContext *tc, ExceptionLevel el);
178 
184 
185 bool isBigEndian64(const ThreadContext *tc);
186 
196 
205 bool badMode(ThreadContext *tc, OperatingMode mode);
206 
207 static inline uint8_t
208 itState(CPSR psr)
209 {
210  ITSTATE it = 0;
211  it.top6 = psr.it2;
212  it.bottom2 = psr.it1;
213 
214  return (uint8_t)it;
215 }
216 
218 
227  TCR tcr, bool isInstr);
229  bool isInstr);
230 int computeAddrTop(ThreadContext *tc, bool selbit, bool isInstr,
231  TTBCR tcr, ExceptionLevel el);
232 
233 static inline bool
234 inSecureState(SCR scr, CPSR cpsr)
235 {
236  switch ((OperatingMode) (uint8_t) cpsr.mode) {
237  case MODE_MON:
238  case MODE_EL3T:
239  case MODE_EL3H:
240  return true;
241  case MODE_HYP:
242  case MODE_EL2T:
243  case MODE_EL2H:
244  return false;
245  default:
246  return !scr.ns;
247  }
248 }
249 
250 bool inSecureState(ThreadContext *tc);
251 
253 
257 RegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
258 
260 RegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
261 
264 
265 static inline uint32_t
266 mcrMrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, uint32_t crn,
267  uint32_t opc1, uint32_t opc2)
268 {
269  return (isRead << 0) |
270  (crm << 1) |
271  (rt << 5) |
272  (crn << 10) |
273  (opc1 << 14) |
274  (opc2 << 17);
275 }
276 
277 static inline void
278 mcrMrcIssExtract(uint32_t iss, bool &isRead, uint32_t &crm, IntRegIndex &rt,
279  uint32_t &crn, uint32_t &opc1, uint32_t &opc2)
280 {
281  isRead = (iss >> 0) & 0x1;
282  crm = (iss >> 1) & 0xF;
283  rt = (IntRegIndex) ((iss >> 5) & 0xF);
284  crn = (iss >> 10) & 0xF;
285  opc1 = (iss >> 14) & 0x7;
286  opc2 = (iss >> 17) & 0x7;
287 }
288 
289 static inline uint32_t
290 mcrrMrrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, IntRegIndex rt2,
291  uint32_t opc1)
292 {
293  return (isRead << 0) |
294  (crm << 1) |
295  (rt << 5) |
296  (rt2 << 10) |
297  (opc1 << 16);
298 }
299 
300 static inline uint32_t
301 msrMrs64IssBuild(bool isRead, uint32_t op0, uint32_t op1, uint32_t crn,
302  uint32_t crm, uint32_t op2, IntRegIndex rt)
303 {
304  return isRead |
305  (crm << 1) |
306  (rt << 5) |
307  (crn << 10) |
308  (op1 << 14) |
309  (op2 << 17) |
310  (op0 << 20);
311 }
312 
313 Fault
314 mcrMrc15Trap(const MiscRegIndex miscReg, ExtMachInst machInst,
315  ThreadContext *tc, uint32_t imm);
316 bool
317 mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss,
318  ExceptionClass *ec = nullptr);
319 
320 bool
321 mcrMrc14TrapToHyp(const MiscRegIndex miscReg, HCR hcr, CPSR cpsr, SCR scr,
322  HDCR hdcr, HSTR hstr, HCPTR hcptr, uint32_t iss);
323 
324 Fault
325 mcrrMrrc15Trap(const MiscRegIndex miscReg, ExtMachInst machInst,
326  ThreadContext *tc, uint32_t imm);
327 bool
329  uint32_t iss, ExceptionClass *ec = nullptr);
330 
331 Fault
333  ExtMachInst machInst, ThreadContext *tc,
334  uint32_t imm, ExceptionClass ec);
335 bool
337  ThreadContext *tc);
338 bool
340  ThreadContext *tc);
341 bool
343  ExceptionClass *ec);
344 bool condGenericTimerPhysHypTrap(const MiscRegIndex miscReg,
345  ThreadContext *tc);
346 bool
348  ExceptionClass *ec);
349 bool
351  ExceptionClass *ec);
352 bool
354 bool
356  ThreadContext *tc);
357 bool
359  ThreadContext *tc);
360 bool
362  ThreadContext *tc);
363 bool
365  ThreadContext *tc);
366 bool
368  ThreadContext *tc);
369 bool
371  ThreadContext *tc);
372 bool
374  ThreadContext *tc);
375 bool
377  ThreadContext *tc);
378 bool
380  ThreadContext *tc);
381 bool
383  ThreadContext *tc);
384 bool
386  ThreadContext *tc);
387 
389 
390 uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
391 
392 inline void
394 {
395  inst->advancePC(pc);
396 }
397 
398 Addr truncPage(Addr addr);
399 Addr roundPage(Addr addr);
400 
401 inline uint64_t
403 {
404  return tc->readMiscReg(MISCREG_CONTEXTIDR);
405 }
406 
407 // Decodes the register index to access based on the fields used in a MSR
408 // or MRS instruction
409 bool
410 decodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx,
411  CPSR cpsr, SCR scr, NSACR nsacr,
412  bool checkSecurity = true);
413 
414 // This wrapper function is used to turn the register index into a source
415 // parameter for the instruction. See Operands.isa
416 static inline int
417 decodeMrsMsrBankedIntRegIndex(uint8_t sysM, bool r)
418 {
419  int regIdx;
420  bool isIntReg;
421  bool validReg;
422 
423  validReg = decodeMrsMsrBankedReg(sysM, r, isIntReg, regIdx, 0, 0, 0, false);
424  return (validReg && isIntReg) ? regIdx : INTREG_DUMMY;
425 }
426 
430 int decodePhysAddrRange64(uint8_t pa_enc);
431 
435 uint8_t encodePhysAddrRange64(int pa_size);
436 
438 {
440 };
441 
442 }
443 
444 #endif
bool mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss, ExceptionClass *ec)
Definition: utility.cc:530
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:163
bool condGenericTimerPhysEL1SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1120
MiscRegIndex
Definition: miscregs.hh:56
Bitfield< 15, 12 > rt
Definition: types.hh:123
Bitfield< 28 > v
IntRegIndex
Definition: intregs.hh:51
RegVal getAffinity(ArmSystem *arm_sys, ThreadContext *tc)
Retrieves MPIDR_EL1.
Definition: utility.cc:280
bool isGenericTimerVirtSystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1050
bool IsSecureEL2Enabled(ThreadContext *tc)
Definition: utility.cc:315
bool HaveVirtHostExt(ThreadContext *tc)
Definition: utility.cc:286
bool isAArch64AArch32SystemAccessTrapEL1(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:820
STL pair class.
Definition: stl.hh:58
PCState buildRetPC(const PCState &curPC, const PCState &callPC)
Definition: utility.hh:59
uint64_t ExtMachInst
Definition: types.hh:39
Bitfield< 11 > z
ip6_addr_t addr
Definition: inet.hh:330
static uint8_t itState(CPSR psr)
Definition: utility.hh:208
bool isGenericTimerHypTrap(const MiscRegIndex miscReg, ThreadContext *tc, ExceptionClass *ec)
Definition: utility.cc:834
OperatingMode
Definition: types.hh:590
uint64_t RegVal
Definition: types.hh:166
static uint32_t mcrrMrrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, IntRegIndex rt2, uint32_t opc1)
Definition: utility.hh:290
bool mcrrMrrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss, ExceptionClass *ec)
Definition: utility.cc:745
Definition: ccregs.hh:41
Bitfield< 4, 0 > mode
bool mcrMrc14TrapToHyp(const MiscRegIndex miscReg, HCR hcr, CPSR cpsr, SCR scr, HDCR hdcr, HSTR hstr, HCPTR hcptr, uint32_t iss)
Definition: utility.cc:685
Addr purifyTaggedAddr(Addr addr, ThreadContext *tc, ExceptionLevel el, TCR tcr, bool isInstr)
Removes the tag from tagged addresses if that mode is enabled.
Definition: utility.cc:480
RegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
This helper function is either returing the value of MPIDR_EL1 (by calling getMPIDR), or it is issuing a read to VMPIDR_EL2 (as it happens in virtualized systems)
Definition: utility.cc:204
ThreadContext is the external interface to all thread state for anything outside of the CPU...
static ExceptionLevel currEL(const ThreadContext *tc)
Definition: utility.hh:141
bool testPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
Definition: utility.hh:67
Fault AArch64AArch32SystemAccessTrap(const MiscRegIndex miscReg, ExtMachInst machInst, ThreadContext *tc, uint32_t imm, ExceptionClass ec)
Definition: utility.cc:806
RegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
This helper function is returning the value of MPIDR_EL1.
Definition: utility.cc:232
bool isGenericTimerSystemAccessTrapEL1(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:898
static bool inPrivilegedMode(CPSR cpsr)
Definition: utility.hh:120
ExceptionLevel
Definition: types.hh:583
Bitfield< 31 > n
ConditionCode
Definition: ccregs.hh:63
int decodePhysAddrRange64(uint8_t pa_enc)
Returns the n.
Definition: utility.cc:1281
bool HaveSecureEL2Ext(ThreadContext *tc)
Definition: utility.cc:308
bool ELIs64(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:336
uint8_t encodePhysAddrRange64(int pa_size)
Returns the encoding corresponding to the specified n.
Definition: utility.cc:1304
bool isGenericTimerCommonEL0SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:992
Bitfield< 3, 2 > el
Bitfield< 4 > pc
int computeAddrTop(ThreadContext *tc, bool selbit, bool isInstr, TCR tcr, ExceptionLevel el)
Definition: utility.cc:435
bool isAArch64AArch32SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:944
bool isGenericTimerCommonEL0HypTrap(const MiscRegIndex miscReg, ThreadContext *tc, ExceptionClass *ec)
Definition: utility.cc:860
ExceptionLevel s1TranslationRegime(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:293
uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
Definition: utility.cc:56
ByteOrder
Definition: types.hh:245
static int decodeMrsMsrBankedIntRegIndex(uint8_t sysM, bool r)
Definition: utility.hh:417
bool SPAlignmentCheckEnabled(ThreadContext *tc)
Definition: utility.cc:1263
static ExceptionLevel opModeToEL(OperatingMode mode)
Definition: types.hh:688
bool ELIs32(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:342
bool condGenericTimerCommonEL0SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1059
void advancePC(PCState &pc, const StaticInstPtr &inst)
Definition: utility.hh:393
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:360
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
Addr roundPage(Addr addr)
Definition: utility.cc:514
static void copyMiscRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.hh:98
Bitfield< 7, 0 > imm
Definition: types.hh:140
bool isGenericTimerPhysEL0SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1005
Fault mcrMrc15Trap(const MiscRegIndex miscReg, ExtMachInst machInst, ThreadContext *tc, uint32_t imm)
Definition: utility.cc:520
Addr truncPage(Addr addr)
Definition: utility.cc:508
static bool inUserMode(CPSR cpsr)
Definition: utility.hh:108
void sendEvent(ThreadContext *tc)
Send an event (SEV) to a specific PE if there isn&#39;t already a pending event.
Definition: utility.cc:165
bool decodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx, CPSR cpsr, SCR scr, NSACR nsacr, bool checkSecurity)
Definition: utility.cc:1144
bool isGenericTimerPhysHypTrap(const MiscRegIndex miscReg, ThreadContext *tc, ExceptionClass *ec)
Definition: utility.cc:876
ExceptionClass
Definition: types.hh:610
Fault mcrrMrrc15Trap(const MiscRegIndex miscReg, ExtMachInst machInst, ThreadContext *tc, uint32_t imm)
Definition: utility.cc:735
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
Bitfield< 29 > c
bool longDescFormatInUse(ThreadContext *tc)
Definition: utility.cc:197
uint64_t getExecutingAsid(ThreadContext *tc)
Definition: utility.hh:402
virtual void advancePC(TheISA::PCState &pcState) const =0
static void mcrMrcIssExtract(uint32_t iss, bool &isRead, uint32_t &crm, IntRegIndex &rt, uint32_t &crn, uint32_t &opc1, uint32_t &opc2)
Definition: utility.hh:278
bool isBigEndian64(const ThreadContext *tc)
Definition: utility.cc:405
Bitfield< 7, 5 > opc2
Definition: types.hh:114
bool inAArch64(ThreadContext *tc)
Definition: utility.cc:190
bool inSecureState(ThreadContext *tc)
Definition: utility.cc:174
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:351
static uint32_t msrMrs64IssBuild(bool isRead, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, IntRegIndex rt)
Definition: utility.hh:301
bool EL2Enabled(ThreadContext *tc)
Definition: utility.cc:328
static uint32_t mcrMrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, uint32_t crn, uint32_t opc1, uint32_t opc2)
Definition: utility.hh:266
Bitfield< 19, 16 > fp
void copyRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.cc:136
GenericISA::DelaySlotPCState< MachInst > PCState
Definition: types.hh:41
bool condGenericTimerPhysHypTrap(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:883
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:423
virtual RegVal readMiscReg(RegIndex misc_reg)=0
bool badMode(ThreadContext *tc, OperatingMode mode)
badMode is checking if the execution mode provided as an argument is valid and implemented.
Definition: utility.cc:429
bool condGenericTimerCommonEL1SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1086
std::shared_ptr< FaultBase > Fault
Definition: types.hh:238
bool condGenericTimerSystemAccessTrapEL1(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:917
static OperatingMode currOpMode(const ThreadContext *tc)
Definition: utility.hh:134
bool isGenericTimerSystemAccessTrapEL3(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1128
bool isGenericTimerSystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:958
ByteOrder byteOrder(const ThreadContext *tc)
Definition: utility.hh:437
bool isGenericTimerPhysEL1SystemAccessTrapEL2(const MiscRegIndex miscReg, ThreadContext *tc)
Definition: utility.cc:1028

Generated on Thu May 28 2020 16:11:03 for gem5 by doxygen 1.8.13