2 * Copyright (c) 2010, 2012-2014, 2016-2018 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 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * Copyright (c) 2007-2008 The Florida State University
16 * All rights reserved.
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.
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.
47 #include "arch/arm/faults.hh"
49 #include "arch/arm/insts/static_inst.hh"
50 #include "arch/arm/system.hh"
51 #include "arch/arm/utility.hh"
52 #include "base/compiler.hh"
53 #include "base/trace.hh"
54 #include "cpu/base.hh"
55 #include "cpu/thread_context.hh"
56 #include "debug/Faults.hh"
57 #include "sim/full_system.hh"
62 uint8_t ArmFault::shortDescFaultSources
[] = {
63 0x01, // AlignmentFault
64 0x04, // InstructionCacheMaintenance
65 0xff, // SynchExtAbtOnTranslTableWalkL0 (INVALID)
66 0x0c, // SynchExtAbtOnTranslTableWalkL1
67 0x0e, // SynchExtAbtOnTranslTableWalkL2
68 0xff, // SynchExtAbtOnTranslTableWalkL3 (INVALID)
69 0xff, // SynchPtyErrOnTranslTableWalkL0 (INVALID)
70 0x1c, // SynchPtyErrOnTranslTableWalkL1
71 0x1e, // SynchPtyErrOnTranslTableWalkL2
72 0xff, // SynchPtyErrOnTranslTableWalkL3 (INVALID)
73 0xff, // TranslationL0 (INVALID)
74 0x05, // TranslationL1
75 0x07, // TranslationL2
76 0xff, // TranslationL3 (INVALID)
77 0xff, // AccessFlagL0 (INVALID)
80 0xff, // AccessFlagL3 (INVALID)
81 0xff, // DomainL0 (INVALID)
84 0xff, // DomainL3 (INVALID)
85 0xff, // PermissionL0 (INVALID)
88 0xff, // PermissionL3 (INVALID)
90 0x08, // SynchronousExternalAbort
91 0x10, // TLBConflictAbort
92 0x19, // SynchPtyErrOnMemoryAccess
93 0x16, // AsynchronousExternalAbort
94 0x18, // AsynchPtyErrOnMemoryAccess
95 0xff, // AddressSizeL0 (INVALID)
96 0xff, // AddressSizeL1 (INVALID)
97 0xff, // AddressSizeL2 (INVALID)
98 0xff, // AddressSizeL3 (INVALID)
99 0x40, // PrefetchTLBMiss
100 0x80 // PrefetchUncacheable
103 static_assert(sizeof(ArmFault::shortDescFaultSources
) ==
104 ArmFault::NumFaultSources
,
105 "Invalid size of ArmFault::shortDescFaultSources[]");
107 uint8_t ArmFault::longDescFaultSources
[] = {
108 0x21, // AlignmentFault
109 0xff, // InstructionCacheMaintenance (INVALID)
110 0xff, // SynchExtAbtOnTranslTableWalkL0 (INVALID)
111 0x15, // SynchExtAbtOnTranslTableWalkL1
112 0x16, // SynchExtAbtOnTranslTableWalkL2
113 0x17, // SynchExtAbtOnTranslTableWalkL3
114 0xff, // SynchPtyErrOnTranslTableWalkL0 (INVALID)
115 0x1d, // SynchPtyErrOnTranslTableWalkL1
116 0x1e, // SynchPtyErrOnTranslTableWalkL2
117 0x1f, // SynchPtyErrOnTranslTableWalkL3
118 0xff, // TranslationL0 (INVALID)
119 0x05, // TranslationL1
120 0x06, // TranslationL2
121 0x07, // TranslationL3
122 0xff, // AccessFlagL0 (INVALID)
123 0x09, // AccessFlagL1
124 0x0a, // AccessFlagL2
125 0x0b, // AccessFlagL3
126 0xff, // DomainL0 (INVALID)
129 0xff, // DomainL3 (RESERVED)
130 0xff, // PermissionL0 (INVALID)
131 0x0d, // PermissionL1
132 0x0e, // PermissionL2
133 0x0f, // PermissionL3
135 0x10, // SynchronousExternalAbort
136 0x30, // TLBConflictAbort
137 0x18, // SynchPtyErrOnMemoryAccess
138 0x11, // AsynchronousExternalAbort
139 0x19, // AsynchPtyErrOnMemoryAccess
140 0xff, // AddressSizeL0 (INVALID)
141 0xff, // AddressSizeL1 (INVALID)
142 0xff, // AddressSizeL2 (INVALID)
143 0xff, // AddressSizeL3 (INVALID)
144 0x40, // PrefetchTLBMiss
145 0x80 // PrefetchUncacheable
148 static_assert(sizeof(ArmFault::longDescFaultSources
) ==
149 ArmFault::NumFaultSources
,
150 "Invalid size of ArmFault::longDescFaultSources[]");
152 uint8_t ArmFault::aarch64FaultSources
[] = {
153 0x21, // AlignmentFault
154 0xff, // InstructionCacheMaintenance (INVALID)
155 0x14, // SynchExtAbtOnTranslTableWalkL0
156 0x15, // SynchExtAbtOnTranslTableWalkL1
157 0x16, // SynchExtAbtOnTranslTableWalkL2
158 0x17, // SynchExtAbtOnTranslTableWalkL3
159 0x1c, // SynchPtyErrOnTranslTableWalkL0
160 0x1d, // SynchPtyErrOnTranslTableWalkL1
161 0x1e, // SynchPtyErrOnTranslTableWalkL2
162 0x1f, // SynchPtyErrOnTranslTableWalkL3
163 0x04, // TranslationL0
164 0x05, // TranslationL1
165 0x06, // TranslationL2
166 0x07, // TranslationL3
167 0x08, // AccessFlagL0
168 0x09, // AccessFlagL1
169 0x0a, // AccessFlagL2
170 0x0b, // AccessFlagL3
171 // @todo: Section & Page Domain Fault in AArch64?
172 0xff, // DomainL0 (INVALID)
173 0xff, // DomainL1 (INVALID)
174 0xff, // DomainL2 (INVALID)
175 0xff, // DomainL3 (INVALID)
176 0x0c, // PermissionL0
177 0x0d, // PermissionL1
178 0x0e, // PermissionL2
179 0x0f, // PermissionL3
181 0x10, // SynchronousExternalAbort
182 0x30, // TLBConflictAbort
183 0x18, // SynchPtyErrOnMemoryAccess
184 0xff, // AsynchronousExternalAbort (INVALID)
185 0xff, // AsynchPtyErrOnMemoryAccess (INVALID)
186 0x00, // AddressSizeL0
187 0x01, // AddressSizeL1
188 0x02, // AddressSizeL2
189 0x03, // AddressSizeL3
190 0x40, // PrefetchTLBMiss
191 0x80 // PrefetchUncacheable
194 static_assert(sizeof(ArmFault::aarch64FaultSources
) ==
195 ArmFault::NumFaultSources
,
196 "Invalid size of ArmFault::aarch64FaultSources[]");
198 // Fields: name, offset, cur{ELT,ELH}Offset, lowerEL{64,32}Offset, next mode,
199 // {ARM, Thumb, ARM_ELR, Thumb_ELR} PC offset, hyp trap,
200 // {A, F} disable, class, stat
201 template<> ArmFault::FaultVals ArmFaultVals
<Reset
>::vals(
202 // Some dummy values (the reset vector has an IMPLEMENTATION DEFINED
203 // location in AArch64)
204 "Reset", 0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC
,
205 0, 0, 0, 0, false, true, true, EC_UNKNOWN
207 template<> ArmFault::FaultVals ArmFaultVals
<UndefinedInstruction
>::vals(
208 "Undefined Instruction", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_UNDEFINED
,
209 4, 2, 0, 0, true, false, false, EC_UNKNOWN
211 template<> ArmFault::FaultVals ArmFaultVals
<SupervisorCall
>::vals(
212 "Supervisor Call", 0x008, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
213 4, 2, 4, 2, true, false, false, EC_SVC_TO_HYP
215 template<> ArmFault::FaultVals ArmFaultVals
<SecureMonitorCall
>::vals(
216 "Secure Monitor Call", 0x008, 0x000, 0x200, 0x400, 0x600, MODE_MON
,
217 4, 4, 4, 4, false, true, true, EC_SMC_TO_HYP
219 template<> ArmFault::FaultVals ArmFaultVals
<HypervisorCall
>::vals(
220 "Hypervisor Call", 0x008, 0x000, 0x200, 0x400, 0x600, MODE_HYP
,
221 4, 4, 4, 4, true, false, false, EC_HVC
223 template<> ArmFault::FaultVals ArmFaultVals
<PrefetchAbort
>::vals(
224 "Prefetch Abort", 0x00C, 0x000, 0x200, 0x400, 0x600, MODE_ABORT
,
225 4, 4, 0, 0, true, true, false, EC_PREFETCH_ABORT_TO_HYP
227 template<> ArmFault::FaultVals ArmFaultVals
<DataAbort
>::vals(
228 "Data Abort", 0x010, 0x000, 0x200, 0x400, 0x600, MODE_ABORT
,
229 8, 8, 0, 0, true, true, false, EC_DATA_ABORT_TO_HYP
231 template<> ArmFault::FaultVals ArmFaultVals
<VirtualDataAbort
>::vals(
232 "Virtual Data Abort", 0x010, 0x000, 0x200, 0x400, 0x600, MODE_ABORT
,
233 8, 8, 0, 0, true, true, false, EC_INVALID
235 template<> ArmFault::FaultVals ArmFaultVals
<HypervisorTrap
>::vals(
236 // @todo: double check these values
237 "Hypervisor Trap", 0x014, 0x000, 0x200, 0x400, 0x600, MODE_HYP
,
238 0, 0, 0, 0, false, false, false, EC_UNKNOWN
240 template<> ArmFault::FaultVals ArmFaultVals
<SecureMonitorTrap
>::vals(
241 "Secure Monitor Trap", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_MON
,
242 4, 2, 0, 0, false, false, false, EC_UNKNOWN
244 template<> ArmFault::FaultVals ArmFaultVals
<Interrupt
>::vals(
245 "IRQ", 0x018, 0x080, 0x280, 0x480, 0x680, MODE_IRQ
,
246 4, 4, 0, 0, false, true, false, EC_UNKNOWN
248 template<> ArmFault::FaultVals ArmFaultVals
<VirtualInterrupt
>::vals(
249 "Virtual IRQ", 0x018, 0x080, 0x280, 0x480, 0x680, MODE_IRQ
,
250 4, 4, 0, 0, false, true, false, EC_INVALID
252 template<> ArmFault::FaultVals ArmFaultVals
<FastInterrupt
>::vals(
253 "FIQ", 0x01C, 0x100, 0x300, 0x500, 0x700, MODE_FIQ
,
254 4, 4, 0, 0, false, true, true, EC_UNKNOWN
256 template<> ArmFault::FaultVals ArmFaultVals
<VirtualFastInterrupt
>::vals(
257 "Virtual FIQ", 0x01C, 0x100, 0x300, 0x500, 0x700, MODE_FIQ
,
258 4, 4, 0, 0, false, true, true, EC_INVALID
260 template<> ArmFault::FaultVals ArmFaultVals
<IllegalInstSetStateFault
>::vals(
261 "Illegal Inst Set State Fault", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_UNDEFINED
,
262 4, 2, 0, 0, true, false, false, EC_ILLEGAL_INST
264 template<> ArmFault::FaultVals ArmFaultVals
<SupervisorTrap
>::vals(
265 // Some dummy values (SupervisorTrap is AArch64-only)
266 "Supervisor Trap", 0x014, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
267 0, 0, 0, 0, false, false, false, EC_UNKNOWN
269 template<> ArmFault::FaultVals ArmFaultVals
<PCAlignmentFault
>::vals(
270 // Some dummy values (PCAlignmentFault is AArch64-only)
271 "PC Alignment Fault", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
272 0, 0, 0, 0, true, false, false, EC_PC_ALIGNMENT
274 template<> ArmFault::FaultVals ArmFaultVals
<SPAlignmentFault
>::vals(
275 // Some dummy values (SPAlignmentFault is AArch64-only)
276 "SP Alignment Fault", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
277 0, 0, 0, 0, true, false, false, EC_STACK_PTR_ALIGNMENT
279 template<> ArmFault::FaultVals ArmFaultVals
<SystemError
>::vals(
280 // Some dummy values (SError is AArch64-only)
281 "SError", 0x000, 0x180, 0x380, 0x580, 0x780, MODE_SVC
,
282 0, 0, 0, 0, false, true, true, EC_SERROR
284 template<> ArmFault::FaultVals ArmFaultVals
<SoftwareBreakpoint
>::vals(
285 // Some dummy values (SoftwareBreakpoint is AArch64-only)
286 "Software Breakpoint", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
287 0, 0, 0, 0, true, false, false, EC_SOFTWARE_BREAKPOINT
289 template<> ArmFault::FaultVals ArmFaultVals
<ArmSev
>::vals(
291 "ArmSev Flush", 0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC
,
292 0, 0, 0, 0, false, true, true, EC_UNKNOWN
296 ArmFault::getVector(ThreadContext
*tc
)
300 // ARM ARM issue C B1.8.1
301 bool haveSecurity
= ArmSystem::haveSecurity(tc
);
303 // Check for invalid modes
304 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
305 assert(haveSecurity
|| cpsr
.mode
!= MODE_MON
);
306 assert(ArmSystem::haveVirtualization(tc
) || cpsr
.mode
!= MODE_HYP
);
311 base
= tc
->readMiscReg(MISCREG_MVBAR
);
314 base
= tc
->readMiscReg(MISCREG_HVBAR
);
317 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
321 base
= haveSecurity
? tc
->readMiscReg(MISCREG_VBAR
) : 0;
325 return base
+ offset(tc
);
329 ArmFault::getVector64(ThreadContext
*tc
)
334 assert(ArmSystem::haveSecurity(tc
));
335 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL3
);
338 assert(ArmSystem::haveVirtualization(tc
));
339 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL2
);
342 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL1
);
345 panic("Invalid target exception level");
348 return vbar
+ offset64(tc
);
352 ArmFault::getSyndromeReg64() const
356 return MISCREG_ESR_EL1
;
358 return MISCREG_ESR_EL2
;
360 return MISCREG_ESR_EL3
;
362 panic("Invalid exception level");
368 ArmFault::getFaultAddrReg64() const
372 return MISCREG_FAR_EL1
;
374 return MISCREG_FAR_EL2
;
376 return MISCREG_FAR_EL3
;
378 panic("Invalid exception level");
384 ArmFault::setSyndrome(ThreadContext
*tc
, MiscRegIndex syndrome_reg
)
387 uint32_t exc_class
= (uint32_t) ec(tc
);
388 uint32_t issVal
= iss();
390 assert(!from64
|| ArmSystem::highestELIs64(tc
));
392 value
= exc_class
<< 26;
394 // HSR.IL not valid for Prefetch Aborts (0x20, 0x21) and Data Aborts (0x24,
395 // 0x25) for which the ISS information is not valid (ARMv7).
396 // @todo: ARMv8 revises AArch32 functionality: when HSR.IL is not
397 // valid it is treated as RES1.
400 } else if ((bits(exc_class
, 5, 3) != 4) ||
401 (bits(exc_class
, 2) && bits(issVal
, 24))) {
402 if (!machInst
.thumb
|| machInst
.bigThumb
)
405 // Condition code valid for EC[5:4] nonzero
406 if (!from64
&& ((bits(exc_class
, 5, 4) == 0) &&
407 (bits(exc_class
, 3, 0) != 0))) {
408 if (!machInst
.thumb
) {
410 ConditionCode condCode
= (ConditionCode
) (uint32_t) machInst
.condCode
;
411 // If its on unconditional instruction report with a cond code of
412 // 0xE, ie the unconditional code
413 cond
= (condCode
== COND_UC
) ? COND_AL
: condCode
;
417 value
|= bits(issVal
, 19, 0);
421 tc
->setMiscReg(syndrome_reg
, value
);
425 ArmFault::update(ThreadContext
*tc
)
427 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
429 // Determine source exception level and mode
430 fromMode
= (OperatingMode
) (uint8_t) cpsr
.mode
;
431 fromEL
= opModeToEL(fromMode
);
432 if (opModeIs64(fromMode
))
435 // Determine target exception level (aarch64) or target execution
437 if (ArmSystem::haveSecurity(tc
) && routeToMonitor(tc
)) {
440 } else if (ArmSystem::haveVirtualization(tc
) && routeToHyp(tc
)) {
446 toEL
= opModeToEL(toMode
);
452 to64
= ELIs64(tc
, toEL
);
454 // The fault specific informations have been updated; it is
455 // now possible to use them inside the fault.
460 ArmFault::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
463 // Update fault state informations, like the starting mode (aarch32)
464 // or EL (aarch64) and the ending mode or EL.
465 // From the update function we are also evaluating if the fault must
466 // be handled in AArch64 mode (to64).
470 // Invoke exception handler in AArch64 state
475 // ARMv7 (ARM ARM issue C B1.9)
477 bool have_security
= ArmSystem::haveSecurity(tc
);
479 FaultBase::invoke(tc
);
484 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
485 SCR scr
= tc
->readMiscReg(MISCREG_SCR
);
486 CPSR saved_cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
487 saved_cpsr
.nz
= tc
->readCCReg(CCREG_NZ
);
488 saved_cpsr
.c
= tc
->readCCReg(CCREG_C
);
489 saved_cpsr
.v
= tc
->readCCReg(CCREG_V
);
490 saved_cpsr
.ge
= tc
->readCCReg(CCREG_GE
);
492 Addr curPc M5_VAR_USED
= tc
->pcState().pc();
493 ITSTATE it
= tc
->pcState().itstate();
494 saved_cpsr
.it2
= it
.top6
;
495 saved_cpsr
.it1
= it
.bottom2
;
497 // if we have a valid instruction then use it to annotate this fault with
498 // extra information. This is used to generate the correct fault syndrome
501 ArmStaticInst
*armInst
= static_cast<ArmStaticInst
*>(inst
.get());
502 armInst
->annotateFault(this);
505 // Ensure Secure state if initially in Monitor mode
506 if (have_security
&& saved_cpsr
.mode
== MODE_MON
) {
507 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
510 tc
->setMiscRegNoEffect(MISCREG_SCR
, scr
);
514 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
517 // some bits are set differently if we have been routed to hyp mode
518 if (cpsr
.mode
== MODE_HYP
) {
519 SCTLR hsctlr
= tc
->readMiscReg(MISCREG_HSCTLR
);
522 if (!scr
.ea
) {cpsr
.a
= 1;}
523 if (!scr
.fiq
) {cpsr
.f
= 1;}
524 if (!scr
.irq
) {cpsr
.i
= 1;}
525 } else if (cpsr
.mode
== MODE_MON
) {
526 // Special case handling when entering monitor mode
536 // The *Disable functions are virtual and different per fault
537 cpsr
.a
= cpsr
.a
| abortDisable(tc
);
538 cpsr
.f
= cpsr
.f
| fiqDisable(tc
);
541 cpsr
.it1
= cpsr
.it2
= 0;
543 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
545 // Make sure mailbox sets to one always
546 tc
->setMiscReg(MISCREG_SEV_MAILBOX
, 1);
548 // Clear the exclusive monitor
549 tc
->setMiscReg(MISCREG_LOCKFLAG
, 0);
551 if (cpsr
.mode
== MODE_HYP
) {
552 tc
->setMiscReg(MISCREG_ELR_HYP
, curPc
+
553 (saved_cpsr
.t
? thumbPcOffset(true) : armPcOffset(true)));
555 tc
->setIntReg(INTREG_LR
, curPc
+
556 (saved_cpsr
.t
? thumbPcOffset(false) : armPcOffset(false)));
561 tc
->setMiscReg(MISCREG_SPSR_FIQ
, saved_cpsr
);
564 tc
->setMiscReg(MISCREG_SPSR_IRQ
, saved_cpsr
);
567 tc
->setMiscReg(MISCREG_SPSR_SVC
, saved_cpsr
);
570 assert(have_security
);
571 tc
->setMiscReg(MISCREG_SPSR_MON
, saved_cpsr
);
574 tc
->setMiscReg(MISCREG_SPSR_ABT
, saved_cpsr
);
577 tc
->setMiscReg(MISCREG_SPSR_UND
, saved_cpsr
);
578 if (ec(tc
) != EC_UNKNOWN
)
579 setSyndrome(tc
, MISCREG_HSR
);
582 assert(ArmSystem::haveVirtualization(tc
));
583 tc
->setMiscReg(MISCREG_SPSR_HYP
, saved_cpsr
);
584 setSyndrome(tc
, MISCREG_HSR
);
587 panic("unknown Mode\n");
590 Addr newPc
= getVector(tc
);
591 DPRINTF(Faults
, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x\n",
592 name(), cpsr
, curPc
, tc
->readIntReg(INTREG_LR
), newPc
);
595 pc
.nextThumb(pc
.thumb());
597 pc
.nextJazelle(pc
.jazelle());
598 pc
.aarch64(!cpsr
.width
);
599 pc
.nextAArch64(!cpsr
.width
);
600 pc
.illegalExec(false);
605 ArmFault::invoke64(ThreadContext
*tc
, const StaticInstPtr
&inst
)
607 // Determine actual misc. register indices for ELR_ELx and SPSR_ELx
608 MiscRegIndex elr_idx
, spsr_idx
;
611 elr_idx
= MISCREG_ELR_EL1
;
612 spsr_idx
= MISCREG_SPSR_EL1
;
615 assert(ArmSystem::haveVirtualization(tc
));
616 elr_idx
= MISCREG_ELR_EL2
;
617 spsr_idx
= MISCREG_SPSR_EL2
;
620 assert(ArmSystem::haveSecurity(tc
));
621 elr_idx
= MISCREG_ELR_EL3
;
622 spsr_idx
= MISCREG_SPSR_EL3
;
625 panic("Invalid target exception level");
629 // Save process state into SPSR_ELx
630 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
632 spsr
.nz
= tc
->readCCReg(CCREG_NZ
);
633 spsr
.c
= tc
->readCCReg(CCREG_C
);
634 spsr
.v
= tc
->readCCReg(CCREG_V
);
636 // Force some bitfields to 0
645 spsr
.ge
= tc
->readCCReg(CCREG_GE
);
646 ITSTATE it
= tc
->pcState().itstate();
648 spsr
.it1
= it
.bottom2
;
649 // Force some bitfields to 0
653 tc
->setMiscReg(spsr_idx
, spsr
);
655 // Save preferred return address into ELR_ELx
656 Addr curr_pc
= tc
->pcState().pc();
657 Addr ret_addr
= curr_pc
;
659 ret_addr
+= armPcElrOffset();
661 ret_addr
+= spsr
.t
? thumbPcElrOffset() : armPcElrOffset();
662 tc
->setMiscReg(elr_idx
, ret_addr
);
664 Addr vec_address
= getVector64(tc
);
666 // Update process state
667 OperatingMode64 mode
= 0;
675 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
677 // Set PC to start of exception handler
678 Addr new_pc
= purifyTaggedAddr(vec_address
, tc
, toEL
);
679 DPRINTF(Faults
, "Invoking Fault (AArch64 target EL):%s cpsr:%#x PC:%#x "
680 "elr:%#x newVec: %#x\n", name(), cpsr
, curr_pc
, ret_addr
, new_pc
);
682 pc
.aarch64(!cpsr
.width
);
683 pc
.nextAArch64(!cpsr
.width
);
684 pc
.illegalExec(false);
687 // If we have a valid instruction then use it to annotate this fault with
688 // extra information. This is used to generate the correct fault syndrome
691 static_cast<ArmStaticInst
*>(inst
.get())->annotateFault(this);
692 // Save exception syndrome
693 if ((nextMode() != MODE_IRQ
) && (nextMode() != MODE_FIQ
))
694 setSyndrome(tc
, getSyndromeReg64());
698 Reset::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
701 tc
->getCpuPtr()->clearInterrupts(tc
->threadId());
704 if (!ArmSystem::highestELIs64(tc
)) {
705 ArmFault::invoke(tc
, inst
);
706 tc
->setMiscReg(MISCREG_VMPIDR
,
707 getMPIDR(dynamic_cast<ArmSystem
*>(tc
->getSystemPtr()), tc
));
709 // Unless we have SMC code to get us there, boot in HYP!
710 if (ArmSystem::haveVirtualization(tc
) &&
711 !ArmSystem::haveSecurity(tc
)) {
712 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
713 cpsr
.mode
= MODE_HYP
;
714 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
717 // Advance the PC to the IMPLEMENTATION DEFINED reset value
718 PCState pc
= ArmSystem::resetAddr64(tc
);
720 pc
.nextAArch64(true);
726 UndefinedInstruction::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
729 ArmFault::invoke(tc
, inst
);
733 // If the mnemonic isn't defined this has to be an unknown instruction.
734 assert(unknown
|| mnemonic
!= NULL
);
736 panic("Attempted to execute disabled instruction "
737 "'%s' (inst 0x%08x)", mnemonic
, machInst
);
738 } else if (unknown
) {
739 panic("Attempted to execute unknown instruction (inst 0x%08x)",
742 panic("Attempted to execute unimplemented instruction "
743 "'%s' (inst 0x%08x)", mnemonic
, machInst
);
748 UndefinedInstruction::routeToHyp(ThreadContext
*tc
) const
752 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
753 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
754 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
756 // if in Hyp mode then stay in Hyp mode
757 toHyp
= scr
.ns
&& (cpsr
.mode
== MODE_HYP
);
758 // if HCR.TGE is set to 1, take to Hyp mode through Hyp Trap vector
759 toHyp
|= !inSecureState(scr
, cpsr
) && hcr
.tge
&& (cpsr
.mode
== MODE_USER
);
764 UndefinedInstruction::iss() const
767 // If UndefinedInstruction is routed to hypervisor, iss field is 0.
772 if (overrideEc
== EC_INVALID
)
775 uint32_t new_iss
= 0;
776 uint32_t op0
, op1
, op2
, CRn
, CRm
, Rt
, dir
;
778 dir
= bits(machInst
, 21, 21);
779 op0
= bits(machInst
, 20, 19);
780 op1
= bits(machInst
, 18, 16);
781 CRn
= bits(machInst
, 15, 12);
782 CRm
= bits(machInst
, 11, 8);
783 op2
= bits(machInst
, 7, 5);
784 Rt
= bits(machInst
, 4, 0);
786 new_iss
= op0
<< 20 | op2
<< 17 | op1
<< 14 | CRn
<< 10 |
787 Rt
<< 5 | CRm
<< 1 | dir
;
793 SupervisorCall::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
796 ArmFault::invoke(tc
, inst
);
800 // As of now, there isn't a 32 bit thumb version of this instruction.
801 assert(!machInst
.bigThumb
);
803 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
804 OperatingMode mode
= (OperatingMode
)(uint8_t)cpsr
.mode
;
805 if (opModeIs64(mode
))
806 callNum
= tc
->readIntReg(INTREG_X8
);
808 callNum
= tc
->readIntReg(INTREG_R7
);
810 tc
->syscall(callNum
, &fault
);
812 // Advance the PC since that won't happen automatically.
813 PCState pc
= tc
->pcState();
820 SupervisorCall::routeToHyp(ThreadContext
*tc
) const
824 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
825 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
826 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
828 // if in Hyp mode then stay in Hyp mode
829 toHyp
= scr
.ns
&& (cpsr
.mode
== MODE_HYP
);
830 // if HCR.TGE is set to 1, take to Hyp mode through Hyp Trap vector
831 toHyp
|= !inSecureState(scr
, cpsr
) && hcr
.tge
&& (cpsr
.mode
== MODE_USER
);
836 SupervisorCall::ec(ThreadContext
*tc
) const
838 return (overrideEc
!= EC_INVALID
) ? overrideEc
:
839 (from64
? EC_SVC_64
: vals
.ec
);
843 SupervisorCall::iss() const
845 // Even if we have a 24 bit imm from an arm32 instruction then we only use
846 // the bottom 16 bits for the ISS value (it doesn't hurt for AArch64 SVC).
847 return issRaw
& 0xFFFF;
851 SecureMonitorCall::iss() const
854 return bits(machInst
, 20, 5);
859 UndefinedInstruction::ec(ThreadContext
*tc
) const
861 // If UndefinedInstruction is routed to hypervisor,
862 // HSR.EC field is 0.
866 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
870 HypervisorCall::HypervisorCall(ExtMachInst _machInst
, uint32_t _imm
) :
871 ArmFaultVals
<HypervisorCall
>(_machInst
, _imm
)
875 HypervisorCall::ec(ThreadContext
*tc
) const
877 return from64
? EC_HVC_64
: vals
.ec
;
881 HypervisorTrap::ec(ThreadContext
*tc
) const
883 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
888 ArmFaultVals
<T
>::offset(ThreadContext
*tc
)
890 bool isHypTrap
= false;
892 // Normally we just use the exception vector from the table at the top if
893 // this file, however if this exception has caused a transition to hype
894 // mode, and its an exception type that would only do this if it has been
895 // trapped then we use the hyp trap vector instead of the normal vector
896 if (vals
.hypTrappable
) {
897 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
898 if (cpsr
.mode
== MODE_HYP
) {
899 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
900 isHypTrap
= spsr
.mode
!= MODE_HYP
;
903 return isHypTrap
? 0x14 : vals
.offset
;
908 ArmFaultVals
<T
>::offset64(ThreadContext
*tc
)
910 if (toEL
== fromEL
) {
911 if (opModeIsT(fromMode
))
912 return vals
.currELTOffset
;
913 return vals
.currELHOffset
;
915 bool lower_32
= false;
917 if (!inSecureState(tc
) && ArmSystem::haveEL(tc
, EL2
))
918 lower_32
= ELIs32(tc
, EL2
);
920 lower_32
= ELIs32(tc
, EL1
);
922 lower_32
= ELIs32(tc
, static_cast<ExceptionLevel
>(toEL
- 1));
926 return vals
.lowerEL32Offset
;
927 return vals
.lowerEL64Offset
;
932 // SupervisorCall::setSyndrome64(ThreadContext *tc, MiscRegIndex esr_idx)
935 // esr.ec = machInst.aarch64 ? SvcAArch64 : SvcAArch32;
936 // esr.il = !machInst.thumb;
937 // if (machInst.aarch64)
938 // esr.imm16 = bits(machInst.instBits, 20, 5);
939 // else if (machInst.thumb)
940 // esr.imm16 = bits(machInst.instBits, 7, 0);
942 // esr.imm16 = bits(machInst.instBits, 15, 0);
943 // tc->setMiscReg(esr_idx, esr);
947 SecureMonitorCall::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
950 ArmFault::invoke(tc
, inst
);
956 SecureMonitorCall::ec(ThreadContext
*tc
) const
958 return (from64
? EC_SMC_64
: vals
.ec
);
962 SupervisorTrap::routeToHyp(ThreadContext
*tc
) const
966 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
967 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
968 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
970 // if HCR.TGE is set to 1, take to Hyp mode through Hyp Trap vector
971 toHyp
|= !inSecureState(scr
, cpsr
) && hcr
.tge
&& (cpsr
.el
== EL0
);
976 SupervisorTrap::iss() const
978 // If SupervisorTrap is routed to hypervisor, iss field is 0.
986 SupervisorTrap::ec(ThreadContext
*tc
) const
991 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
995 SecureMonitorTrap::ec(ThreadContext
*tc
) const
997 return (overrideEc
!= EC_INVALID
) ? overrideEc
:
998 (from64
? EC_SMC_64
: vals
.ec
);
1003 AbortFault
<T
>::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1005 if (tranMethod
== ArmFault::UnknownTran
) {
1006 tranMethod
= longDescFormatInUse(tc
) ? ArmFault::LpaeTran
1007 : ArmFault::VmsaTran
;
1009 if ((tranMethod
== ArmFault::VmsaTran
) && this->routeToMonitor(tc
)) {
1010 // See ARM ARM B3-1416
1011 bool override_LPAE
= false;
1012 TTBCR ttbcr_s
= tc
->readMiscReg(MISCREG_TTBCR_S
);
1013 TTBCR M5_VAR_USED ttbcr_ns
= tc
->readMiscReg(MISCREG_TTBCR_NS
);
1015 override_LPAE
= true;
1017 // Unimplemented code option, not seen in testing. May need
1018 // extension according to the manual exceprt above.
1019 DPRINTF(Faults
, "Warning: Incomplete translation method "
1020 "override detected.\n");
1023 tranMethod
= ArmFault::LpaeTran
;
1027 if (source
== ArmFault::AsynchronousExternalAbort
) {
1028 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_ABT
, 0);
1030 // Get effective fault source encoding
1031 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
1033 // source must be determined BEFORE invoking generic routines which will
1034 // try to set hsr etc. and are based upon source!
1035 ArmFaultVals
<T
>::invoke(tc
, inst
);
1037 if (!this->to64
) { // AArch32
1038 FSR fsr
= getFsr(tc
);
1039 if (cpsr
.mode
== MODE_HYP
) {
1040 tc
->setMiscReg(T::HFarIndex
, faultAddr
);
1041 } else if (stage2
) {
1042 tc
->setMiscReg(MISCREG_HPFAR
, (faultAddr
>> 8) & ~0xf);
1043 tc
->setMiscReg(T::HFarIndex
, OVAddr
);
1045 tc
->setMiscReg(T::FsrIndex
, fsr
);
1046 tc
->setMiscReg(T::FarIndex
, faultAddr
);
1048 DPRINTF(Faults
, "Abort Fault source=%#x fsr=%#x faultAddr=%#x "\
1049 "tranMethod=%#x\n", source
, fsr
, faultAddr
, tranMethod
);
1051 // Set the FAR register. Nothing else to do if we are in AArch64 state
1052 // because the syndrome register has already been set inside invoke64()
1054 // stage 2 fault, set HPFAR_EL2 to the faulting IPA
1055 // and FAR_EL2 to the Original VA
1056 tc
->setMiscReg(AbortFault
<T
>::getFaultAddrReg64(), OVAddr
);
1057 tc
->setMiscReg(MISCREG_HPFAR_EL2
, bits(faultAddr
, 47, 12) << 4);
1059 DPRINTF(Faults
, "Abort Fault (Stage 2) VA: 0x%x IPA: 0x%x\n",
1062 tc
->setMiscReg(AbortFault
<T
>::getFaultAddrReg64(), faultAddr
);
1069 AbortFault
<T
>::setSyndrome(ThreadContext
*tc
, MiscRegIndex syndrome_reg
)
1071 srcEncoded
= getFaultStatusCode(tc
);
1072 if (srcEncoded
== ArmFault::FaultSourceInvalid
) {
1073 panic("Invalid fault source\n");
1075 ArmFault::setSyndrome(tc
, syndrome_reg
);
1080 AbortFault
<T
>::getFaultStatusCode(ThreadContext
*tc
) const
1083 panic_if(!this->faultUpdated
,
1084 "Trying to use un-updated ArmFault internal variables\n");
1090 assert(tranMethod
!= ArmFault::UnknownTran
);
1091 if (tranMethod
== ArmFault::LpaeTran
) {
1092 fsc
= ArmFault::longDescFaultSources
[source
];
1094 fsc
= ArmFault::shortDescFaultSources
[source
];
1098 fsc
= ArmFault::aarch64FaultSources
[source
];
1106 AbortFault
<T
>::getFsr(ThreadContext
*tc
) const
1110 auto fsc
= getFaultStatusCode(tc
);
1113 assert(tranMethod
!= ArmFault::UnknownTran
);
1114 if (tranMethod
== ArmFault::LpaeTran
) {
1118 fsr
.fsLow
= bits(fsc
, 3, 0);
1119 fsr
.fsHigh
= bits(fsc
, 4);
1120 fsr
.domain
= static_cast<uint8_t>(domain
);
1123 fsr
.wnr
= (write
? 1 : 0);
1131 AbortFault
<T
>::abortDisable(ThreadContext
*tc
)
1133 if (ArmSystem::haveSecurity(tc
)) {
1134 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1135 return (!scr
.ns
|| scr
.aw
);
1142 AbortFault
<T
>::annotate(ArmFault::AnnotationIDs id
, uint64_t val
)
1146 case ArmFault::S1PTW
:
1153 // Just ignore unknown ID's
1161 AbortFault
<T
>::iss() const
1165 val
= srcEncoded
& 0x3F;
1173 AbortFault
<T
>::isMMUFault() const
1175 // NOTE: Not relying on LL information being aligned to lowest bits here
1177 (source
== ArmFault::AlignmentFault
) ||
1178 ((source
>= ArmFault::TranslationLL
) &&
1179 (source
< ArmFault::TranslationLL
+ 4)) ||
1180 ((source
>= ArmFault::AccessFlagLL
) &&
1181 (source
< ArmFault::AccessFlagLL
+ 4)) ||
1182 ((source
>= ArmFault::DomainLL
) &&
1183 (source
< ArmFault::DomainLL
+ 4)) ||
1184 ((source
>= ArmFault::PermissionLL
) &&
1185 (source
< ArmFault::PermissionLL
+ 4));
1189 PrefetchAbort::ec(ThreadContext
*tc
) const
1194 return EC_PREFETCH_ABORT_CURR_EL
;
1196 return EC_PREFETCH_ABORT_LOWER_EL
;
1199 // Abort faults have different EC codes depending on whether
1200 // the fault originated within HYP mode, or not. So override
1201 // the method and add the extra adjustment of the EC value.
1203 ExceptionClass ec
= ArmFaultVals
<PrefetchAbort
>::vals
.ec
;
1205 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
1206 if (spsr
.mode
== MODE_HYP
) {
1207 ec
= ((ExceptionClass
) (((uint32_t) ec
) + 1));
1214 PrefetchAbort::routeToMonitor(ThreadContext
*tc
) const
1218 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1220 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1222 return scr
.ea
&& !isMMUFault();
1226 PrefetchAbort::routeToHyp(ThreadContext
*tc
) const
1230 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1231 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1232 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
1233 HDCR hdcr
= tc
->readMiscRegNoEffect(MISCREG_HDCR
);
1235 // if in Hyp mode then stay in Hyp mode
1236 toHyp
= scr
.ns
&& (cpsr
.mode
== MODE_HYP
);
1237 // otherwise, check whether to take to Hyp mode through Hyp Trap vector
1239 ( (source
== DebugEvent
) && hdcr
.tde
&& (cpsr
.mode
!= MODE_HYP
)) ||
1240 ( (source
== SynchronousExternalAbort
) && hcr
.tge
&& (cpsr
.mode
== MODE_USER
))
1241 ) && !inSecureState(tc
);
1246 DataAbort::ec(ThreadContext
*tc
) const
1250 if (source
== ArmFault::AsynchronousExternalAbort
) {
1251 panic("Asynchronous External Abort should be handled with "
1252 "SystemErrors (SErrors)!");
1255 return EC_DATA_ABORT_CURR_EL
;
1257 return EC_DATA_ABORT_LOWER_EL
;
1260 // Abort faults have different EC codes depending on whether
1261 // the fault originated within HYP mode, or not. So override
1262 // the method and add the extra adjustment of the EC value.
1264 ExceptionClass ec
= ArmFaultVals
<DataAbort
>::vals
.ec
;
1266 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
1267 if (spsr
.mode
== MODE_HYP
) {
1268 ec
= ((ExceptionClass
) (((uint32_t) ec
) + 1));
1275 DataAbort::routeToMonitor(ThreadContext
*tc
) const
1279 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1281 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1283 return scr
.ea
&& !isMMUFault();
1287 DataAbort::routeToHyp(ThreadContext
*tc
) const
1291 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1292 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1293 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
1294 HDCR hdcr
= tc
->readMiscRegNoEffect(MISCREG_HDCR
);
1296 // if in Hyp mode then stay in Hyp mode
1297 toHyp
= scr
.ns
&& (cpsr
.mode
== MODE_HYP
);
1298 // otherwise, check whether to take to Hyp mode through Hyp Trap vector
1300 ( (cpsr
.mode
!= MODE_HYP
) && ( ((source
== AsynchronousExternalAbort
) && hcr
.amo
) ||
1301 ((source
== DebugEvent
) && hdcr
.tde
) )
1303 ( (cpsr
.mode
== MODE_USER
) && hcr
.tge
&&
1304 ((source
== AlignmentFault
) ||
1305 (source
== SynchronousExternalAbort
))
1307 ) && !inSecureState(tc
);
1312 DataAbort::iss() const
1316 // Add on the data abort specific fields to the generic abort ISS value
1317 val
= AbortFault
<DataAbort
>::iss();
1318 // ISS is valid if not caused by a stage 1 page table walk, and when taken
1319 // to AArch64 only when directed to EL2
1320 if (!s1ptw
&& (!to64
|| toEL
== EL2
)) {
1326 // AArch64 only. These assignments are safe on AArch32 as well
1327 // because these vars are initialized to false
1336 DataAbort::annotate(AnnotationIDs id
, uint64_t val
)
1338 AbortFault
<DataAbort
>::annotate(id
, val
);
1361 // Just ignore unknown ID's
1368 VirtualDataAbort::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1370 AbortFault
<VirtualDataAbort
>::invoke(tc
, inst
);
1371 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1373 tc
->setMiscRegNoEffect(MISCREG_HCR
, hcr
);
1377 Interrupt::routeToMonitor(ThreadContext
*tc
) const
1379 assert(ArmSystem::haveSecurity(tc
));
1382 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1384 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1389 Interrupt::routeToHyp(ThreadContext
*tc
) const
1393 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1394 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1395 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
1396 // Determine whether IRQs are routed to Hyp mode.
1397 toHyp
= (!scr
.irq
&& hcr
.imo
&& !inSecureState(tc
)) ||
1398 (cpsr
.mode
== MODE_HYP
);
1403 Interrupt::abortDisable(ThreadContext
*tc
)
1405 if (ArmSystem::haveSecurity(tc
)) {
1406 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1407 return (!scr
.ns
|| scr
.aw
);
1412 VirtualInterrupt::VirtualInterrupt()
1416 FastInterrupt::routeToMonitor(ThreadContext
*tc
) const
1418 assert(ArmSystem::haveSecurity(tc
));
1421 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1423 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1428 FastInterrupt::routeToHyp(ThreadContext
*tc
) const
1432 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1433 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1434 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
1435 // Determine whether IRQs are routed to Hyp mode.
1436 toHyp
= (!scr
.fiq
&& hcr
.fmo
&& !inSecureState(tc
)) ||
1437 (cpsr
.mode
== MODE_HYP
);
1442 FastInterrupt::abortDisable(ThreadContext
*tc
)
1444 if (ArmSystem::haveSecurity(tc
)) {
1445 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1446 return (!scr
.ns
|| scr
.aw
);
1452 FastInterrupt::fiqDisable(ThreadContext
*tc
)
1454 if (ArmSystem::haveVirtualization(tc
)) {
1456 } else if (ArmSystem::haveSecurity(tc
)) {
1457 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1458 return (!scr
.ns
|| scr
.fw
);
1463 VirtualFastInterrupt::VirtualFastInterrupt()
1467 PCAlignmentFault::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1469 ArmFaultVals
<PCAlignmentFault
>::invoke(tc
, inst
);
1472 tc
->setMiscReg(getFaultAddrReg64(), faultPC
);
1476 PCAlignmentFault::routeToHyp(ThreadContext
*tc
) const
1480 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1481 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1482 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
1484 // if HCR.TGE is set to 1, take to Hyp mode through Hyp Trap vector
1485 toHyp
|= !inSecureState(scr
, cpsr
) && hcr
.tge
&& (cpsr
.el
== EL0
);
1489 SPAlignmentFault::SPAlignmentFault()
1492 SystemError::SystemError()
1496 SystemError::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1498 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_ABT
, 0);
1499 ArmFault::invoke(tc
, inst
);
1503 SystemError::routeToMonitor(ThreadContext
*tc
) const
1505 assert(ArmSystem::haveSecurity(tc
));
1507 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1512 SystemError::routeToHyp(ThreadContext
*tc
) const
1517 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1518 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1520 toHyp
= (!scr
.ea
&& hcr
.amo
&& !inSecureState(tc
)) ||
1521 (!scr
.ea
&& !scr
.rw
&& !hcr
.amo
&& !inSecureState(tc
));
1526 SoftwareBreakpoint::SoftwareBreakpoint(ExtMachInst _mach_inst
, uint32_t _iss
)
1527 : ArmFaultVals
<SoftwareBreakpoint
>(_mach_inst
, _iss
)
1531 SoftwareBreakpoint::routeToHyp(ThreadContext
*tc
) const
1533 const bool have_el2
= ArmSystem::haveVirtualization(tc
);
1535 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1536 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1538 return have_el2
&& !inSecureState(tc
) && fromEL
<= EL1
&&
1539 (hcr
.tge
|| mdcr
.tde
);
1543 SoftwareBreakpoint::ec(ThreadContext
*tc
) const
1545 return from64
? EC_SOFTWARE_BREAKPOINT_64
: vals
.ec
;
1549 ArmSev::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
) {
1550 DPRINTF(Faults
, "Invoking ArmSev Fault\n");
1554 // Set sev_mailbox to 1, clear the pending interrupt from remote
1555 // SEV execution and let pipeline continue as pcState is still
1557 tc
->setMiscReg(MISCREG_SEV_MAILBOX
, 1);
1558 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_SEV
, 0);
1561 // Instantiate all the templates to make the linker happy
1562 template class ArmFaultVals
<Reset
>;
1563 template class ArmFaultVals
<UndefinedInstruction
>;
1564 template class ArmFaultVals
<SupervisorCall
>;
1565 template class ArmFaultVals
<SecureMonitorCall
>;
1566 template class ArmFaultVals
<HypervisorCall
>;
1567 template class ArmFaultVals
<PrefetchAbort
>;
1568 template class ArmFaultVals
<DataAbort
>;
1569 template class ArmFaultVals
<VirtualDataAbort
>;
1570 template class ArmFaultVals
<HypervisorTrap
>;
1571 template class ArmFaultVals
<Interrupt
>;
1572 template class ArmFaultVals
<VirtualInterrupt
>;
1573 template class ArmFaultVals
<FastInterrupt
>;
1574 template class ArmFaultVals
<VirtualFastInterrupt
>;
1575 template class ArmFaultVals
<SupervisorTrap
>;
1576 template class ArmFaultVals
<SecureMonitorTrap
>;
1577 template class ArmFaultVals
<PCAlignmentFault
>;
1578 template class ArmFaultVals
<SPAlignmentFault
>;
1579 template class ArmFaultVals
<SystemError
>;
1580 template class ArmFaultVals
<SoftwareBreakpoint
>;
1581 template class ArmFaultVals
<ArmSev
>;
1582 template class AbortFault
<PrefetchAbort
>;
1583 template class AbortFault
<DataAbort
>;
1584 template class AbortFault
<VirtualDataAbort
>;
1587 IllegalInstSetStateFault::IllegalInstSetStateFault()
1591 } // namespace ArmISA