gem5  v19.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-2019 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  * Authors: Korey Sewell
42  * Stephen Hines
43  */
44 
45 #ifndef __ARCH_ARM_UTILITY_HH__
46 #define __ARCH_ARM_UTILITY_HH__
47 
48 #include "arch/arm/isa_traits.hh"
49 #include "arch/arm/miscregs.hh"
50 #include "arch/arm/types.hh"
51 #include "base/logging.hh"
52 #include "base/trace.hh"
53 #include "base/types.hh"
54 #include "cpu/static_inst.hh"
55 #include "cpu/thread_context.hh"
56 
57 class ArmSystem;
58 
59 namespace ArmISA {
60 
61 inline PCState
62 buildRetPC(const PCState &curPC, const PCState &callPC)
63 {
64  PCState retPC = callPC;
65  retPC.uEnd();
66  return retPC;
67 }
68 
69 inline bool
70 testPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
71 {
72  bool n = (nz & 0x2);
73  bool z = (nz & 0x1);
74 
75  switch (code)
76  {
77  case COND_EQ: return z;
78  case COND_NE: return !z;
79  case COND_CS: return c;
80  case COND_CC: return !c;
81  case COND_MI: return n;
82  case COND_PL: return !n;
83  case COND_VS: return v;
84  case COND_VC: return !v;
85  case COND_HI: return (c && !z);
86  case COND_LS: return !(c && !z);
87  case COND_GE: return !(n ^ v);
88  case COND_LT: return (n ^ v);
89  case COND_GT: return !(n ^ v || z);
90  case COND_LE: return (n ^ v || z);
91  case COND_AL: return true;
92  case COND_UC: return true;
93  default:
94  panic("Unhandled predicate condition: %d\n", code);
95  }
96 }
97 
98 void copyRegs(ThreadContext *src, ThreadContext *dest);
99 
100 static inline void
102 {
103  panic("Copy Misc. Regs Not Implemented Yet\n");
104 }
105 
108 void sendEvent(ThreadContext *tc);
109 
110 static inline bool
111 inUserMode(CPSR cpsr)
112 {
113  return cpsr.mode == MODE_USER || cpsr.mode == MODE_EL0T;
114 }
115 
116 static inline bool
118 {
120 }
121 
122 static inline bool
124 {
125  return !inUserMode(cpsr);
126 }
127 
128 static inline bool
130 {
131  return !inUserMode(tc);
132 }
133 
134 bool inAArch64(ThreadContext *tc);
135 
136 static inline OperatingMode
138 {
139  CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
140  return (OperatingMode) (uint8_t) cpsr.mode;
141 }
142 
143 static inline ExceptionLevel
145 {
146  return opModeToEL(currOpMode(tc));
147 }
148 
149 inline ExceptionLevel
150 currEL(CPSR cpsr)
151 {
152  return opModeToEL((OperatingMode) (uint8_t)cpsr.mode);
153 }
154 
158 bool EL2Enabled(ThreadContext *tc);
159 
177 
178 bool ELIs32(ThreadContext *tc, ExceptionLevel el);
179 
180 bool ELIs64(ThreadContext *tc, ExceptionLevel el);
181 
187 
188 bool isBigEndian64(ThreadContext *tc);
189 
199 
208 bool badMode(ThreadContext *tc, OperatingMode mode);
209 
210 static inline uint8_t
211 itState(CPSR psr)
212 {
213  ITSTATE it = 0;
214  it.top6 = psr.it2;
215  it.bottom2 = psr.it1;
216 
217  return (uint8_t)it;
218 }
219 
221 
230  TCR tcr, bool isInstr);
232  bool isInstr);
233 int computeAddrTop(ThreadContext *tc, bool selbit, bool isInstr,
234  TTBCR tcr, ExceptionLevel el);
235 
236 static inline bool
237 inSecureState(SCR scr, CPSR cpsr)
238 {
239  switch ((OperatingMode) (uint8_t) cpsr.mode) {
240  case MODE_MON:
241  case MODE_EL3T:
242  case MODE_EL3H:
243  return true;
244  case MODE_HYP:
245  case MODE_EL2T:
246  case MODE_EL2H:
247  return false;
248  default:
249  return !scr.ns;
250  }
251 }
252 
253 bool inSecureState(ThreadContext *tc);
254 
256 
260 RegVal readMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
261 
263 RegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc);
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 bool
314 mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss);
315 
316 bool
317 mcrMrc14TrapToHyp(const MiscRegIndex miscReg, HCR hcr, CPSR cpsr, SCR scr,
318  HDCR hdcr, HSTR hstr, HCPTR hcptr, uint32_t iss);
319 bool
320 mcrrMrrc15TrapToHyp(const MiscRegIndex miscReg, CPSR cpsr, SCR scr, HSTR hstr,
321  HCR hcr, uint32_t iss);
322 
324 
325 uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp);
326 
327 void skipFunction(ThreadContext *tc);
328 
329 inline void
331 {
332  inst->advancePC(pc);
333 }
334 
335 Addr truncPage(Addr addr);
336 Addr roundPage(Addr addr);
337 
338 inline uint64_t
340 {
341  return tc->readMiscReg(MISCREG_CONTEXTIDR);
342 }
343 
344 // Decodes the register index to access based on the fields used in a MSR
345 // or MRS instruction
346 bool
347 decodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx,
348  CPSR cpsr, SCR scr, NSACR nsacr,
349  bool checkSecurity = true);
350 
351 // This wrapper function is used to turn the register index into a source
352 // parameter for the instruction. See Operands.isa
353 static inline int
354 decodeMrsMsrBankedIntRegIndex(uint8_t sysM, bool r)
355 {
356  int regIdx;
357  bool isIntReg;
358  bool validReg;
359 
360  validReg = decodeMrsMsrBankedReg(sysM, r, isIntReg, regIdx, 0, 0, 0, false);
361  return (validReg && isIntReg) ? regIdx : INTREG_DUMMY;
362 }
363 
367 int decodePhysAddrRange64(uint8_t pa_enc);
368 
372 uint8_t encodePhysAddrRange64(int pa_size);
373 
375 {
377 };
378 
379 }
380 
381 #endif
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
MiscRegIndex
Definition: miscregs.hh:57
Bitfield< 15, 12 > rt
Definition: types.hh:125
Bitfield< 28 > v
static ExceptionLevel currEL(ThreadContext *tc)
Definition: utility.hh:144
IntRegIndex
Definition: intregs.hh:53
bool IsSecureEL2Enabled(ThreadContext *tc)
Definition: utility.cc:312
bool HaveVirtHostExt(ThreadContext *tc)
Definition: utility.cc:283
STL pair class.
Definition: stl.hh:61
PCState buildRetPC(const PCState &curPC, const PCState &callPC)
Definition: utility.hh:62
Bitfield< 11 > z
ip6_addr_t addr
Definition: inet.hh:335
static uint8_t itState(CPSR psr)
Definition: utility.hh:211
OperatingMode
Definition: types.hh:592
uint64_t RegVal
Definition: types.hh:168
static uint32_t mcrrMrrcIssBuild(bool isRead, uint32_t crm, IntRegIndex rt, IntRegIndex rt2, uint32_t opc1)
Definition: utility.hh:290
Definition: ccregs.hh:42
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:663
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:477
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:225
ThreadContext is the external interface to all thread state for anything outside of the CPU...
bool testPredicate(uint32_t nz, uint32_t c, uint32_t v, ConditionCode code)
Definition: utility.hh:70
RegVal getMPIDR(ArmSystem *arm_sys, ThreadContext *tc)
This helper function is returing the value of MPIDR_EL1.
Definition: utility.cc:253
static bool inPrivilegedMode(CPSR cpsr)
Definition: utility.hh:123
ExceptionLevel
Definition: types.hh:585
Bitfield< 31 > n
ConditionCode
Definition: ccregs.hh:64
int decodePhysAddrRange64(uint8_t pa_enc)
Returns the n.
Definition: utility.cc:898
bool HaveSecureEL2Ext(ThreadContext *tc)
Definition: utility.cc:305
bool ELIs64(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:333
bool isBigEndian64(ThreadContext *tc)
Definition: utility.cc:402
uint8_t encodePhysAddrRange64(int pa_size)
Returns the encoding corresponding to the specified n.
Definition: utility.cc:921
static OperatingMode currOpMode(ThreadContext *tc)
Definition: utility.hh:137
Bitfield< 3, 2 > el
Bitfield< 4 > pc
int computeAddrTop(ThreadContext *tc, bool selbit, bool isInstr, TCR tcr, ExceptionLevel el)
Definition: utility.cc:432
ByteOrder byteOrder(ThreadContext *tc)
Definition: utility.hh:374
ExceptionLevel s1TranslationRegime(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:290
bool mcrMrc15TrapToHyp(const MiscRegIndex miscReg, ThreadContext *tc, uint32_t iss)
Definition: utility.cc:517
uint64_t getArgument(ThreadContext *tc, int &number, uint16_t size, bool fp)
Definition: utility.cc:59
bool mcrrMrrc15TrapToHyp(const MiscRegIndex miscReg, CPSR cpsr, SCR scr, HSTR hstr, HCR hcr, uint32_t iss)
Definition: utility.cc:713
ByteOrder
Definition: types.hh:247
static int decodeMrsMsrBankedIntRegIndex(uint8_t sysM, bool r)
Definition: utility.hh:354
bool SPAlignmentCheckEnabled(ThreadContext *tc)
Definition: utility.cc:880
static ExceptionLevel opModeToEL(OperatingMode mode)
Definition: types.hh:690
bool ELIs32(ThreadContext *tc, ExceptionLevel el)
Definition: utility.cc:339
void advancePC(PCState &pc, const StaticInstPtr &inst)
Definition: utility.hh:330
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:357
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:142
Addr roundPage(Addr addr)
Definition: utility.cc:511
static void copyMiscRegs(ThreadContext *src, ThreadContext *dest)
Definition: utility.hh:101
Addr truncPage(Addr addr)
Definition: utility.cc:505
static bool inUserMode(CPSR cpsr)
Definition: utility.hh:111
void sendEvent(ThreadContext *tc)
Send an event (SEV) to a specific PE if there isn&#39;t already a pending event.
Definition: utility.cc:186
void skipFunction(ThreadContext *tc)
Definition: utility.cc:121
bool decodeMrsMsrBankedReg(uint8_t sysM, bool r, bool &isIntReg, int &regIdx, CPSR cpsr, SCR scr, NSACR nsacr, bool checkSecurity)
Definition: utility.cc:761
virtual RegVal readMiscRegNoEffect(RegIndex misc_reg) const =0
Bitfield< 29 > c
bool longDescFormatInUse(ThreadContext *tc)
Definition: utility.cc:218
uint64_t getExecutingAsid(ThreadContext *tc)
Definition: utility.hh:339
virtual void advancePC(TheISA::PCState &pcState) const =0
GenericISA::SimplePCState< MachInst > PCState
Definition: types.hh:43
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
Bitfield< 7, 5 > opc2
Definition: types.hh:116
bool inAArch64(ThreadContext *tc)
Definition: utility.cc:211
bool inSecureState(ThreadContext *tc)
Definition: utility.cc:195
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:348
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:325
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:157
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:420
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:426

Generated on Fri Feb 28 2020 16:26:56 for gem5 by doxygen 1.8.13