2 * Copyright (c) 2009-2014, 2016-2019 ARM Limited
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.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "arch/arm/utility.hh"
44 #include "arch/arm/faults.hh"
45 #include "arch/arm/isa_traits.hh"
46 #include "arch/arm/system.hh"
47 #include "arch/arm/tlb.hh"
48 #include "arch/arm/vtophys.hh"
49 #include "cpu/base.hh"
50 #include "cpu/checker/cpu.hh"
51 #include "cpu/thread_context.hh"
52 #include "mem/fs_translating_port_proxy.hh"
53 #include "sim/full_system.hh"
58 initCPU(ThreadContext
*tc
, int cpuId
)
60 // Reset CP15?? What does that mean -- ali
64 static Fault reset
= std::make_shared
<Reset
>();
69 getArgument(ThreadContext
*tc
, int &number
, uint16_t size
, bool fp
)
72 panic("getArgument() only implemented for full system mode.\n");
77 panic("getArgument(): Floating point arguments not implemented\n");
80 if (size
== (uint16_t)(-1))
81 size
= sizeof(uint64_t);
83 if (number
< 8 /*NumArgumentRegs64*/) {
84 return tc
->readIntReg(number
);
86 panic("getArgument(): No support reading stack args for AArch64\n");
89 if (size
== (uint16_t)(-1))
90 // todo: should this not be sizeof(uint32_t) rather?
91 size
= ArmISA::MachineBytes
;
93 if (number
< NumArgumentRegs
) {
94 // If the argument is 64 bits, it must be in an even regiser
95 // number. Increment the number here if it isn't even.
96 if (size
== sizeof(uint64_t)) {
97 if ((number
% 2) != 0)
99 // Read the two halves of the data. Number is inc here to
100 // get the second half of the 64 bit reg.
102 tmp
= tc
->readIntReg(number
++);
103 tmp
|= tc
->readIntReg(number
) << 32;
106 return tc
->readIntReg(number
);
109 Addr sp
= tc
->readIntReg(StackPointerReg
);
110 PortProxy
&vp
= tc
->getVirtProxy();
112 if (size
== sizeof(uint64_t)) {
113 // If the argument is even it must be aligned
114 if ((number
% 2) != 0)
116 arg
= vp
.read
<uint64_t>(sp
+
117 (number
-NumArgumentRegs
) * sizeof(uint32_t));
118 // since two 32 bit args == 1 64 bit arg, increment number
121 arg
= vp
.read
<uint32_t>(sp
+
122 (number
-NumArgumentRegs
) * sizeof(uint32_t));
127 panic("getArgument() should always return\n");
131 skipFunction(ThreadContext
*tc
)
133 PCState newPC
= tc
->pcState();
135 newPC
.set(tc
->readIntReg(INTREG_X30
));
137 newPC
.set(tc
->readIntReg(ReturnAddressReg
) & ~ULL(1));
140 CheckerCPU
*checker
= tc
->getCheckerCpuPtr();
142 tc
->pcStateNoRecord(newPC
);
149 copyVecRegs(ThreadContext
*src
, ThreadContext
*dest
)
151 auto src_mode
= RenameMode
<ArmISA::ISA
>::mode(src
->pcState());
153 // The way vector registers are copied (VecReg vs VecElem) is relevant
154 // in the O3 model only.
155 if (src_mode
== Enums::Full
) {
156 for (auto idx
= 0; idx
< NumVecRegs
; idx
++)
157 dest
->setVecRegFlat(idx
, src
->readVecRegFlat(idx
));
159 for (auto idx
= 0; idx
< NumVecRegs
; idx
++)
160 for (auto elem_idx
= 0; elem_idx
< NumVecElemPerVecReg
; elem_idx
++)
161 dest
->setVecElemFlat(
162 idx
, elem_idx
, src
->readVecElemFlat(idx
, elem_idx
));
167 copyRegs(ThreadContext
*src
, ThreadContext
*dest
)
169 for (int i
= 0; i
< NumIntRegs
; i
++)
170 dest
->setIntRegFlat(i
, src
->readIntRegFlat(i
));
172 for (int i
= 0; i
< NumFloatRegs
; i
++)
173 dest
->setFloatRegFlat(i
, src
->readFloatRegFlat(i
));
175 for (int i
= 0; i
< NumCCRegs
; i
++)
176 dest
->setCCReg(i
, src
->readCCReg(i
));
178 for (int i
= 0; i
< NumMiscRegs
; i
++)
179 dest
->setMiscRegNoEffect(i
, src
->readMiscRegNoEffect(i
));
181 copyVecRegs(src
, dest
);
183 // setMiscReg "with effect" will set the misc register mapping correctly.
184 // e.g. updateRegMap(val)
185 dest
->setMiscReg(MISCREG_CPSR
, src
->readMiscRegNoEffect(MISCREG_CPSR
));
187 // Copy over the PC State
188 dest
->pcState(src
->pcState());
190 // Invalidate the tlb misc register cache
191 dynamic_cast<TLB
*>(dest
->getITBPtr())->invalidateMiscReg();
192 dynamic_cast<TLB
*>(dest
->getDTBPtr())->invalidateMiscReg();
196 sendEvent(ThreadContext
*tc
)
198 if (tc
->readMiscReg(MISCREG_SEV_MAILBOX
) == 0) {
199 // Post Interrupt and wake cpu if needed
200 tc
->getCpuPtr()->postInterrupt(tc
->threadId(), INT_SEV
, 0);
205 inSecureState(ThreadContext
*tc
)
207 SCR scr
= inAArch64(tc
) ? tc
->readMiscReg(MISCREG_SCR_EL3
) :
208 tc
->readMiscReg(MISCREG_SCR
);
209 return ArmSystem::haveSecurity(tc
) && inSecureState(
210 scr
, tc
->readMiscReg(MISCREG_CPSR
));
214 isSecureBelowEL3(ThreadContext
*tc
)
216 SCR scr
= tc
->readMiscReg(MISCREG_SCR_EL3
);
217 return ArmSystem::haveEL(tc
, EL3
) && scr
.ns
== 0;
221 inAArch64(ThreadContext
*tc
)
223 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
224 return opModeIs64((OperatingMode
) (uint8_t) cpsr
.mode
);
228 longDescFormatInUse(ThreadContext
*tc
)
230 TTBCR ttbcr
= tc
->readMiscReg(MISCREG_TTBCR
);
231 return ArmSystem::haveLPAE(tc
) && ttbcr
.eae
;
235 readMPIDR(ArmSystem
*arm_sys
, ThreadContext
*tc
)
237 const ExceptionLevel current_el
= currEL(tc
);
239 const bool is_secure
= isSecureBelowEL3(tc
);
241 switch (current_el
) {
243 // Note: in MsrMrs instruction we read the register value before
244 // checking access permissions. This means that EL0 entry must
245 // be part of the table even if MPIDR is not accessible in user
247 warn_once("Trying to read MPIDR at EL0\n");
250 if (ArmSystem::haveEL(tc
, EL2
) && !is_secure
)
251 return tc
->readMiscReg(MISCREG_VMPIDR_EL2
);
253 return getMPIDR(arm_sys
, tc
);
256 return getMPIDR(arm_sys
, tc
);
258 panic("Invalid EL for reading MPIDR register\n");
263 getMPIDR(ArmSystem
*arm_sys
, ThreadContext
*tc
)
265 // Multiprocessor Affinity Register MPIDR from Cortex(tm)-A15 Technical
268 // bit 31 - Multi-processor extensions available
269 // bit 30 - Uni-processor system
270 // bit 24 - Multi-threaded cores
271 // bit 11-8 - Cluster ID
274 // We deliberately extend both the Cluster ID and CPU ID fields to allow
275 // for simulation of larger systems
276 assert((0 <= tc
->cpuId()) && (tc
->cpuId() < 256));
277 assert(tc
->socketId() < 65536);
278 if (arm_sys
->multiThread
) {
279 return 0x80000000 | // multiprocessor extensions available
280 0x01000000 | // multi-threaded cores
282 } else if (arm_sys
->multiProc
) {
283 return 0x80000000 | // multiprocessor extensions available
284 tc
->cpuId() | tc
->socketId() << 8;
286 return 0x80000000 | // multiprocessor extensions available
287 0x40000000 | // in up system
288 tc
->cpuId() | tc
->socketId() << 8;
293 HaveVirtHostExt(ThreadContext
*tc
)
295 AA64MMFR1 id_aa64mmfr1
= tc
->readMiscReg(MISCREG_ID_AA64MMFR1_EL1
);
296 return id_aa64mmfr1
.vh
;
300 HaveSecureEL2Ext(ThreadContext
*tc
)
302 AA64PFR0 id_aa64pfr0
= tc
->readMiscReg(MISCREG_ID_AA64PFR0_EL1
);
303 return id_aa64pfr0
.sel2
;
307 IsSecureEL2Enabled(ThreadContext
*tc
)
309 SCR scr
= tc
->readMiscReg(MISCREG_SCR_EL3
);
310 if (ArmSystem::haveEL(tc
, EL2
) && HaveSecureEL2Ext(tc
)) {
311 if (ArmSystem::haveEL(tc
, EL3
))
312 return !ELIs32(tc
, EL3
) && scr
.eel2
;
314 return inSecureState(tc
);
320 EL2Enabled(ThreadContext
*tc
)
322 SCR scr
= tc
->readMiscReg(MISCREG_SCR_EL3
);
323 return ArmSystem::haveEL(tc
, EL2
) &&
324 (!ArmSystem::haveEL(tc
, EL3
) || scr
.ns
|| IsSecureEL2Enabled(tc
));
328 ELIs64(ThreadContext
*tc
, ExceptionLevel el
)
330 return !ELIs32(tc
, el
);
334 ELIs32(ThreadContext
*tc
, ExceptionLevel el
)
337 std::tie(known
, aarch32
) = ELUsingAArch32K(tc
, el
);
338 panic_if(!known
, "EL state is UNKNOWN");
343 ELIsInHost(ThreadContext
*tc
, ExceptionLevel el
)
345 const HCR hcr
= tc
->readMiscReg(MISCREG_HCR_EL2
);
346 return ((IsSecureEL2Enabled(tc
) || !isSecureBelowEL3(tc
)) &&
347 HaveVirtHostExt(tc
) && !ELIs32(tc
, EL2
) && hcr
.e2h
== 1 &&
348 (el
== EL2
|| (el
== EL0
&& hcr
.tge
== 1)));
351 std::pair
<bool, bool>
352 ELUsingAArch32K(ThreadContext
*tc
, ExceptionLevel el
)
354 // Return true if the specified EL is in aarch32 state.
355 const bool have_el3
= ArmSystem::haveSecurity(tc
);
356 const bool have_el2
= ArmSystem::haveVirtualization(tc
);
358 panic_if(el
== EL2
&& !have_el2
, "Asking for EL2 when it doesn't exist");
359 panic_if(el
== EL3
&& !have_el3
, "Asking for EL3 when it doesn't exist");
362 known
= aarch32
= false;
363 if (ArmSystem::highestELIs64(tc
) && ArmSystem::highestEL(tc
) == el
) {
364 // Target EL is the highest one in a system where
365 // the highest is using AArch64.
366 known
= true; aarch32
= false;
367 } else if (!ArmSystem::highestELIs64(tc
)) {
368 // All ELs are using AArch32:
369 known
= true; aarch32
= true;
371 SCR scr
= tc
->readMiscReg(MISCREG_SCR_EL3
);
372 bool aarch32_below_el3
= (have_el3
&& scr
.rw
== 0);
374 HCR hcr
= tc
->readMiscReg(MISCREG_HCR_EL2
);
375 bool aarch32_at_el1
= (aarch32_below_el3
377 && !isSecureBelowEL3(tc
) && hcr
.rw
== 0));
379 // Only know if EL0 using AArch32 from PSTATE
380 if (el
== EL0
&& !aarch32_at_el1
) {
381 // EL0 controlled by PSTATE
382 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
384 known
= (currEL(tc
) == EL0
);
385 aarch32
= (cpsr
.width
== 1);
388 aarch32
= (aarch32_below_el3
&& el
!= EL3
)
389 || (aarch32_at_el1
&& (el
== EL0
|| el
== EL1
) );
393 return std::make_pair(known
, aarch32
);
397 isBigEndian64(ThreadContext
*tc
)
399 switch (currEL(tc
)) {
401 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL3
)).ee
;
403 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL2
)).ee
;
405 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL1
)).ee
;
407 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL1
)).e0e
;
409 panic("Invalid exception level");
415 badMode32(ThreadContext
*tc
, OperatingMode mode
)
417 return unknownMode32(mode
) || !ArmSystem::haveEL(tc
, opModeToEL(mode
));
421 badMode(ThreadContext
*tc
, OperatingMode mode
)
423 return unknownMode(mode
) || !ArmSystem::haveEL(tc
, opModeToEL(mode
));
427 purifyTaggedAddr(Addr addr
, ThreadContext
*tc
, ExceptionLevel el
,
433 if (bits(addr
, 55, 48) == 0xFF && tcr
.tbi1
)
434 return addr
| mask(63, 55);
435 else if (!bits(addr
, 55, 48) && tcr
.tbi0
)
436 return bits(addr
,55, 0);
439 assert(ArmSystem::haveVirtualization(tc
));
440 tcr
= tc
->readMiscReg(MISCREG_TCR_EL2
);
442 return addr
& mask(56);
445 assert(ArmSystem::haveSecurity(tc
));
447 return addr
& mask(56);
450 panic("Invalid exception level");
454 return addr
; // Nothing to do if this is not a tagged address
458 purifyTaggedAddr(Addr addr
, ThreadContext
*tc
, ExceptionLevel el
)
465 tcr
= tc
->readMiscReg(MISCREG_TCR_EL1
);
466 if (bits(addr
, 55, 48) == 0xFF && tcr
.tbi1
)
467 return addr
| mask(63, 55);
468 else if (!bits(addr
, 55, 48) && tcr
.tbi0
)
469 return bits(addr
,55, 0);
472 assert(ArmSystem::haveVirtualization(tc
));
473 tcr
= tc
->readMiscReg(MISCREG_TCR_EL2
);
475 return addr
& mask(56);
478 assert(ArmSystem::haveSecurity(tc
));
479 tcr
= tc
->readMiscReg(MISCREG_TCR_EL3
);
481 return addr
& mask(56);
484 panic("Invalid exception level");
488 return addr
; // Nothing to do if this is not a tagged address
494 return addr
& ~(PageBytes
- 1);
500 return (addr
+ PageBytes
- 1) & ~(PageBytes
- 1);
504 mcrMrc15TrapToHyp(const MiscRegIndex miscReg
, ThreadContext
*tc
, uint32_t iss
)
512 bool trapToHype
= false;
514 const CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
515 const HCR hcr
= tc
->readMiscReg(MISCREG_HCR
);
516 const SCR scr
= tc
->readMiscReg(MISCREG_SCR
);
517 const HDCR hdcr
= tc
->readMiscReg(MISCREG_HDCR
);
518 const HSTR hstr
= tc
->readMiscReg(MISCREG_HSTR
);
519 const HCPTR hcptr
= tc
->readMiscReg(MISCREG_HCPTR
);
521 if (!inSecureState(scr
, cpsr
) && (cpsr
.mode
!= MODE_HYP
)) {
522 mcrMrcIssExtract(iss
, isRead
, crm
, rt
, crn
, opc1
, opc2
);
523 trapToHype
= ((uint32_t) hstr
) & (1 << crn
);
524 trapToHype
|= hdcr
.tpm
&& (crn
== 9) && (crm
>= 12);
525 trapToHype
|= hcr
.tidcp
&& (
526 ((crn
== 9) && ((crm
<= 2) || ((crm
>= 5) && (crm
<= 8)))) ||
527 ((crn
== 10) && ((crm
<= 1) || (crm
== 4) || (crm
== 8))) ||
528 ((crn
== 11) && ((crm
<= 8) || (crm
== 15))) );
531 switch (unflattenMiscReg(miscReg
)) {
533 trapToHype
= hcptr
.tcpac
;
539 trapToHype
= hcr
.tid1
;
545 trapToHype
= hcr
.tid2
;
547 case MISCREG_ID_PFR0
:
548 case MISCREG_ID_PFR1
:
549 case MISCREG_ID_DFR0
:
550 case MISCREG_ID_AFR0
:
551 case MISCREG_ID_MMFR0
:
552 case MISCREG_ID_MMFR1
:
553 case MISCREG_ID_MMFR2
:
554 case MISCREG_ID_MMFR3
:
555 case MISCREG_ID_ISAR0
:
556 case MISCREG_ID_ISAR1
:
557 case MISCREG_ID_ISAR2
:
558 case MISCREG_ID_ISAR3
:
559 case MISCREG_ID_ISAR4
:
560 case MISCREG_ID_ISAR5
:
561 trapToHype
= hcr
.tid3
;
566 trapToHype
= hcr
.tsw
;
568 case MISCREG_DCIMVAC
:
569 case MISCREG_DCCIMVAC
:
570 case MISCREG_DCCMVAC
:
571 trapToHype
= hcr
.tpc
;
573 case MISCREG_ICIMVAU
:
574 case MISCREG_ICIALLU
:
575 case MISCREG_ICIALLUIS
:
576 case MISCREG_DCCMVAU
:
577 trapToHype
= hcr
.tpu
;
579 case MISCREG_TLBIALLIS
:
580 case MISCREG_TLBIMVAIS
:
581 case MISCREG_TLBIASIDIS
:
582 case MISCREG_TLBIMVAAIS
:
583 case MISCREG_TLBIMVALIS
:
584 case MISCREG_TLBIMVAALIS
:
585 case MISCREG_DTLBIALL
:
586 case MISCREG_ITLBIALL
:
587 case MISCREG_DTLBIMVA
:
588 case MISCREG_ITLBIMVA
:
589 case MISCREG_DTLBIASID
:
590 case MISCREG_ITLBIASID
:
591 case MISCREG_TLBIMVAA
:
592 case MISCREG_TLBIALL
:
593 case MISCREG_TLBIMVA
:
594 case MISCREG_TLBIMVAL
:
595 case MISCREG_TLBIMVAAL
:
596 case MISCREG_TLBIASID
:
597 trapToHype
= hcr
.ttlb
;
600 trapToHype
= hcr
.tac
;
617 case MISCREG_CONTEXTIDR
:
618 trapToHype
= hcr
.tvm
& !isRead
;
621 trapToHype
= hdcr
.tpmcr
;
624 case MISCREG_ICC_SGI0R
:
625 if (tc
->getIsaPtr()->haveGICv3CpuIfc())
626 trapToHype
= hcr
.fmo
;
628 case MISCREG_ICC_SGI1R
:
629 case MISCREG_ICC_ASGI1R
:
630 if (tc
->getIsaPtr()->haveGICv3CpuIfc())
631 trapToHype
= hcr
.imo
;
633 // No default action needed
644 mcrMrc14TrapToHyp(const MiscRegIndex miscReg
, HCR hcr
, CPSR cpsr
, SCR scr
,
645 HDCR hdcr
, HSTR hstr
, HCPTR hcptr
, uint32_t iss
)
653 bool trapToHype
= false;
655 if (!inSecureState(scr
, cpsr
) && (cpsr
.mode
!= MODE_HYP
)) {
656 mcrMrcIssExtract(iss
, isRead
, crm
, rt
, crn
, opc1
, opc2
);
657 inform("trap check M:%x N:%x 1:%x 2:%x hdcr %x, hcptr %x, hstr %x\n",
658 crm
, crn
, opc1
, opc2
, hdcr
, hcptr
, hstr
);
659 trapToHype
= hdcr
.tda
&& (opc1
== 0);
660 trapToHype
|= hcptr
.tta
&& (opc1
== 1);
662 switch (unflattenMiscReg(miscReg
)) {
663 case MISCREG_DBGOSLSR
:
664 case MISCREG_DBGOSLAR
:
665 case MISCREG_DBGOSDLR
:
666 case MISCREG_DBGPRCR
:
667 trapToHype
= hdcr
.tdosa
;
669 case MISCREG_DBGDRAR
:
670 case MISCREG_DBGDSAR
:
671 trapToHype
= hdcr
.tdra
;
674 trapToHype
= hcr
.tid0
;
678 trapToHype
= hstr
.tjdbx
;
682 trapToHype
= hstr
.ttee
;
684 // No default action needed
694 mcrrMrrc15TrapToHyp(const MiscRegIndex miscReg
, CPSR cpsr
, SCR scr
, HSTR hstr
,
695 HCR hcr
, uint32_t iss
)
703 bool trapToHype
= false;
705 if (!inSecureState(scr
, cpsr
) && (cpsr
.mode
!= MODE_HYP
)) {
706 // This is technically the wrong function, but we can re-use it for
707 // the moment because we only need one field, which overlaps with the
709 mcrMrcIssExtract(iss
, isRead
, crm
, rt
, crn
, opc1
, opc2
);
710 trapToHype
= ((uint32_t) hstr
) & (1 << crm
);
713 switch (unflattenMiscReg(miscReg
)) {
729 case MISCREG_CONTEXTIDR
:
730 trapToHype
= hcr
.tvm
& !isRead
;
732 // No default action needed
742 decodeMrsMsrBankedReg(uint8_t sysM
, bool r
, bool &isIntReg
, int ®Idx
,
743 CPSR cpsr
, SCR scr
, NSACR nsacr
, bool checkSecurity
)
745 OperatingMode mode
= MODE_UNDEFINED
;
748 // R mostly indicates if its a int register or a misc reg, we override
749 // below if the few corner cases
751 // Loosely based on ARM ARM issue C section B9.3.10
756 regIdx
= MISCREG_SPSR_FIQ
;
760 regIdx
= MISCREG_SPSR_IRQ
;
764 regIdx
= MISCREG_SPSR_SVC
;
768 regIdx
= MISCREG_SPSR_ABT
;
772 regIdx
= MISCREG_SPSR_UND
;
773 mode
= MODE_UNDEFINED
;
776 regIdx
= MISCREG_SPSR_MON
;
780 regIdx
= MISCREG_SPSR_HYP
;
788 int sysM4To3
= bits(sysM
, 4, 3);
792 regIdx
= intRegInMode(mode
, bits(sysM
, 2, 0) + 8);
793 } else if (sysM4To3
== 1) {
795 regIdx
= intRegInMode(mode
, bits(sysM
, 2, 0) + 8);
796 } else if (sysM4To3
== 3) {
797 if (bits(sysM
, 1) == 0) {
799 regIdx
= intRegInMode(mode
, 14 - bits(sysM
, 0));
802 if (bits(sysM
, 0) == 1) {
803 regIdx
= intRegInMode(mode
, 13); // R13 in HYP
806 regIdx
= MISCREG_ELR_HYP
;
809 } else { // Other Banked registers
810 int sysM2
= bits(sysM
, 2);
811 int sysM1
= bits(sysM
, 1);
813 mode
= (OperatingMode
) ( ((sysM2
|| sysM1
) << 0) |
815 ((sysM2
&& !sysM1
) << 2) |
816 ((sysM2
&& sysM1
) << 3) |
818 regIdx
= intRegInMode(mode
, 14 - bits(sysM
, 0));
819 // Don't flatten the register here. This is going to go through
820 // setIntReg() which will do the flattening
821 ok
&= mode
!= cpsr
.mode
;
825 // Check that the requested register is accessable from the current mode
826 if (ok
&& checkSecurity
&& mode
!= cpsr
.mode
) {
833 ok
&= mode
!= MODE_HYP
;
834 ok
&= (mode
!= MODE_MON
) || !scr
.ns
;
837 ok
&= mode
!= MODE_MON
;
838 ok
&= (mode
!= MODE_FIQ
) || !nsacr
.rfr
;
845 ok
&= mode
!= MODE_HYP
;
846 ok
&= (mode
!= MODE_MON
) || !scr
.ns
;
847 ok
&= (mode
!= MODE_FIQ
) || !nsacr
.rfr
;
849 // can access everything, no further checks required
853 panic("unknown Mode 0x%x\n", cpsr
.mode
);
861 SPAlignmentCheckEnabled(ThreadContext
* tc
)
863 switch (currEL(tc
)) {
865 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL3
)).sa
;
867 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL2
)).sa
;
869 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL1
)).sa
;
871 return ((SCTLR
) tc
->readMiscReg(MISCREG_SCTLR_EL1
)).sa0
;
873 panic("Invalid exception level");
879 decodePhysAddrRange64(uint8_t pa_enc
)
897 panic("Invalid phys. address range encoding");
902 encodePhysAddrRange64(int pa_size
)
918 panic("Invalid phys. address range");
922 } // namespace ArmISA