2 * Copyright (c) 2010, 2012-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 * 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.
42 #include "arch/arm/faults.hh"
44 #include "arch/arm/insts/static_inst.hh"
45 #include "arch/arm/interrupts.hh"
46 #include "arch/arm/isa.hh"
47 #include "arch/arm/self_debug.hh"
48 #include "arch/arm/system.hh"
49 #include "arch/arm/utility.hh"
50 #include "base/compiler.hh"
51 #include "base/trace.hh"
52 #include "cpu/base.hh"
53 #include "cpu/thread_context.hh"
54 #include "debug/Faults.hh"
55 #include "sim/full_system.hh"
60 const uint32_t HighVecs
= 0xFFFF0000;
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
<HardwareBreakpoint
>::vals(
290 "Hardware Breakpoint", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
291 0, 0, 0, 0, true, false, false, EC_HW_BREAKPOINT
293 template<> ArmFault::FaultVals ArmFaultVals
<Watchpoint
>::vals(
294 "Watchpoint", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
295 0, 0, 0, 0, true, false, false, EC_WATCHPOINT
297 template<> ArmFault::FaultVals ArmFaultVals
<SoftwareStepFault
>::vals(
298 "SoftwareStep", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
299 0, 0, 0, 0, true, false, false, EC_SOFTWARE_STEP
301 template<> ArmFault::FaultVals ArmFaultVals
<ArmSev
>::vals(
303 "ArmSev Flush", 0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC
,
304 0, 0, 0, 0, false, true, true, EC_UNKNOWN
308 ArmFault::getVector(ThreadContext
*tc
)
312 // Check for invalid modes
313 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
314 assert(ArmSystem::haveSecurity(tc
) || cpsr
.mode
!= MODE_MON
);
315 assert(ArmSystem::haveVirtualization(tc
) || cpsr
.mode
!= MODE_HYP
);
320 base
= tc
->readMiscReg(MISCREG_MVBAR
);
323 base
= tc
->readMiscReg(MISCREG_HVBAR
);
326 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
330 base
= ArmSystem::haveSecurity(tc
) ?
331 tc
->readMiscReg(MISCREG_VBAR
) : 0;
336 return base
+ offset(tc
);
340 ArmFault::getVector64(ThreadContext
*tc
)
345 assert(ArmSystem::haveSecurity(tc
));
346 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL3
);
349 assert(ArmSystem::haveVirtualization(tc
));
350 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL2
);
353 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL1
);
356 panic("Invalid target exception level");
359 return vbar
+ offset64(tc
);
363 ArmFault::getSyndromeReg64() const
367 return MISCREG_ESR_EL1
;
369 return MISCREG_ESR_EL2
;
371 return MISCREG_ESR_EL3
;
373 panic("Invalid exception level");
379 ArmFault::getFaultAddrReg64() const
383 return MISCREG_FAR_EL1
;
385 return MISCREG_FAR_EL2
;
387 return MISCREG_FAR_EL3
;
389 panic("Invalid exception level");
395 ArmFault::setSyndrome(ThreadContext
*tc
, MiscRegIndex syndrome_reg
)
398 uint32_t exc_class
= (uint32_t) ec(tc
);
399 uint32_t issVal
= iss();
401 assert(!from64
|| ArmSystem::highestELIs64(tc
));
403 value
= exc_class
<< 26;
405 // HSR.IL not valid for Prefetch Aborts (0x20, 0x21) and Data Aborts (0x24,
406 // 0x25) for which the ISS information is not valid (ARMv7).
407 // @todo: ARMv8 revises AArch32 functionality: when HSR.IL is not
408 // valid it is treated as RES1.
411 } else if ((bits(exc_class
, 5, 3) != 4) ||
412 (bits(exc_class
, 2) && bits(issVal
, 24))) {
413 if (!machInst
.thumb
|| machInst
.bigThumb
)
416 // Condition code valid for EC[5:4] nonzero
417 if (!from64
&& ((bits(exc_class
, 5, 4) == 0) &&
418 (bits(exc_class
, 3, 0) != 0))) {
419 if (!machInst
.thumb
) {
421 ConditionCode condCode
= (ConditionCode
) (uint32_t) machInst
.condCode
;
422 // If its on unconditional instruction report with a cond code of
423 // 0xE, ie the unconditional code
424 cond
= (condCode
== COND_UC
) ? COND_AL
: condCode
;
428 value
|= bits(issVal
, 19, 0);
432 tc
->setMiscReg(syndrome_reg
, value
);
436 ArmFault::update(ThreadContext
*tc
)
438 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
440 // Determine source exception level and mode
441 fromMode
= (OperatingMode
) (uint8_t) cpsr
.mode
;
442 fromEL
= opModeToEL(fromMode
);
443 if (opModeIs64(fromMode
))
446 // Determine target exception level (aarch64) or target execution
448 if (ArmSystem::haveSecurity(tc
) && routeToMonitor(tc
)) {
451 } else if (ArmSystem::haveVirtualization(tc
) && routeToHyp(tc
)) {
457 toEL
= opModeToEL(toMode
);
463 // Check for Set Priviledge Access Never, if PAN is supported
464 AA64MMFR1 mmfr1
= tc
->readMiscReg(MISCREG_ID_AA64MMFR1_EL1
);
467 const SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR_EL1
);
471 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
472 if (toEL
== EL2
&& hcr
.e2h
&& hcr
.tge
) {
473 const SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR_EL2
);
478 to64
= ELIs64(tc
, toEL
);
480 // The fault specific informations have been updated; it is
481 // now possible to use them inside the fault.
486 ArmFault::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
488 // Update fault state informations, like the starting mode (aarch32)
489 // or EL (aarch64) and the ending mode or EL.
490 // From the update function we are also evaluating if the fault must
491 // be handled in AArch64 mode (to64).
495 // Invoke exception handler in AArch64 state
500 if (vectorCatch(tc
, inst
))
503 // ARMv7 (ARM ARM issue C B1.9)
505 bool have_security
= ArmSystem::haveSecurity(tc
);
507 FaultBase::invoke(tc
);
512 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
513 SCR scr
= tc
->readMiscReg(MISCREG_SCR
);
514 CPSR saved_cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
515 saved_cpsr
.nz
= tc
->readCCReg(CCREG_NZ
);
516 saved_cpsr
.c
= tc
->readCCReg(CCREG_C
);
517 saved_cpsr
.v
= tc
->readCCReg(CCREG_V
);
518 saved_cpsr
.ge
= tc
->readCCReg(CCREG_GE
);
520 Addr curPc M5_VAR_USED
= tc
->pcState().pc();
521 ITSTATE it
= tc
->pcState().itstate();
522 saved_cpsr
.it2
= it
.top6
;
523 saved_cpsr
.it1
= it
.bottom2
;
525 // if we have a valid instruction then use it to annotate this fault with
526 // extra information. This is used to generate the correct fault syndrome
528 ArmStaticInst
*arm_inst M5_VAR_USED
= instrAnnotate(inst
);
530 // Ensure Secure state if initially in Monitor mode
531 if (have_security
&& saved_cpsr
.mode
== MODE_MON
) {
532 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
535 tc
->setMiscRegNoEffect(MISCREG_SCR
, scr
);
539 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
542 // some bits are set differently if we have been routed to hyp mode
543 if (cpsr
.mode
== MODE_HYP
) {
544 SCTLR hsctlr
= tc
->readMiscReg(MISCREG_HSCTLR
);
547 if (!scr
.ea
) {cpsr
.a
= 1;}
548 if (!scr
.fiq
) {cpsr
.f
= 1;}
549 if (!scr
.irq
) {cpsr
.i
= 1;}
550 } else if (cpsr
.mode
== MODE_MON
) {
551 // Special case handling when entering monitor mode
561 // The *Disable functions are virtual and different per fault
562 cpsr
.a
= cpsr
.a
| abortDisable(tc
);
563 cpsr
.f
= cpsr
.f
| fiqDisable(tc
);
566 cpsr
.it1
= cpsr
.it2
= 0;
568 cpsr
.pan
= span
? 1 : saved_cpsr
.pan
;
569 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
571 // Make sure mailbox sets to one always
572 tc
->setMiscReg(MISCREG_SEV_MAILBOX
, 1);
574 // Clear the exclusive monitor
575 tc
->setMiscReg(MISCREG_LOCKFLAG
, 0);
577 if (cpsr
.mode
== MODE_HYP
) {
578 tc
->setMiscReg(MISCREG_ELR_HYP
, curPc
+
579 (saved_cpsr
.t
? thumbPcOffset(true) : armPcOffset(true)));
581 tc
->setIntReg(INTREG_LR
, curPc
+
582 (saved_cpsr
.t
? thumbPcOffset(false) : armPcOffset(false)));
587 tc
->setMiscReg(MISCREG_SPSR_FIQ
, saved_cpsr
);
590 tc
->setMiscReg(MISCREG_SPSR_IRQ
, saved_cpsr
);
593 tc
->setMiscReg(MISCREG_SPSR_SVC
, saved_cpsr
);
596 assert(have_security
);
597 tc
->setMiscReg(MISCREG_SPSR_MON
, saved_cpsr
);
600 tc
->setMiscReg(MISCREG_SPSR_ABT
, saved_cpsr
);
603 tc
->setMiscReg(MISCREG_SPSR_UND
, saved_cpsr
);
604 if (ec(tc
) != EC_UNKNOWN
)
605 setSyndrome(tc
, MISCREG_HSR
);
608 assert(ArmSystem::haveVirtualization(tc
));
609 tc
->setMiscReg(MISCREG_SPSR_HYP
, saved_cpsr
);
610 setSyndrome(tc
, MISCREG_HSR
);
613 panic("unknown Mode\n");
616 Addr newPc
= getVector(tc
);
617 DPRINTF(Faults
, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x "
618 "%s\n", name(), cpsr
, curPc
, tc
->readIntReg(INTREG_LR
),
619 newPc
, arm_inst
? csprintf("inst: %#x", arm_inst
->encoding()) :
623 pc
.nextThumb(pc
.thumb());
625 pc
.nextJazelle(pc
.jazelle());
626 pc
.aarch64(!cpsr
.width
);
627 pc
.nextAArch64(!cpsr
.width
);
628 pc
.illegalExec(false);
633 ArmFault::invoke64(ThreadContext
*tc
, const StaticInstPtr
&inst
)
635 // Determine actual misc. register indices for ELR_ELx and SPSR_ELx
636 MiscRegIndex elr_idx
, spsr_idx
;
639 elr_idx
= MISCREG_ELR_EL1
;
640 spsr_idx
= MISCREG_SPSR_EL1
;
643 assert(ArmSystem::haveVirtualization(tc
));
644 elr_idx
= MISCREG_ELR_EL2
;
645 spsr_idx
= MISCREG_SPSR_EL2
;
648 assert(ArmSystem::haveSecurity(tc
));
649 elr_idx
= MISCREG_ELR_EL3
;
650 spsr_idx
= MISCREG_SPSR_EL3
;
653 panic("Invalid target exception level");
657 // Save process state into SPSR_ELx
658 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
660 spsr
.nz
= tc
->readCCReg(CCREG_NZ
);
661 spsr
.c
= tc
->readCCReg(CCREG_C
);
662 spsr
.v
= tc
->readCCReg(CCREG_V
);
663 spsr
.ss
= isResetSPSR() ? 0: cpsr
.ss
;
665 // Force some bitfields to 0
673 spsr
.ge
= tc
->readCCReg(CCREG_GE
);
674 ITSTATE it
= tc
->pcState().itstate();
676 spsr
.it1
= it
.bottom2
;
678 tc
->setMiscReg(spsr_idx
, spsr
);
680 // Save preferred return address into ELR_ELx
681 Addr curr_pc
= tc
->pcState().pc();
682 Addr ret_addr
= curr_pc
;
684 ret_addr
+= armPcElrOffset();
686 ret_addr
+= spsr
.t
? thumbPcElrOffset() : armPcElrOffset();
687 tc
->setMiscReg(elr_idx
, ret_addr
);
689 Addr vec_address
= getVector64(tc
);
691 // Update process state
692 OperatingMode64 mode
= 0;
700 cpsr
.pan
= span
? 1 : spsr
.pan
;
701 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
703 // If we have a valid instruction then use it to annotate this fault with
704 // extra information. This is used to generate the correct fault syndrome
706 ArmStaticInst
*arm_inst M5_VAR_USED
= instrAnnotate(inst
);
708 // Set PC to start of exception handler
709 Addr new_pc
= purifyTaggedAddr(vec_address
, tc
, toEL
, true);
710 DPRINTF(Faults
, "Invoking Fault (AArch64 target EL):%s cpsr:%#x PC:%#x "
711 "elr:%#x newVec: %#x %s\n", name(), cpsr
, curr_pc
, ret_addr
,
712 new_pc
, arm_inst
? csprintf("inst: %#x", arm_inst
->encoding()) :
715 pc
.aarch64(!cpsr
.width
);
716 pc
.nextAArch64(!cpsr
.width
);
717 pc
.illegalExec(false);
721 // Save exception syndrome
722 if ((nextMode() != MODE_IRQ
) && (nextMode() != MODE_FIQ
))
723 setSyndrome(tc
, getSyndromeReg64());
727 ArmFault::vectorCatch(ThreadContext
*tc
, const StaticInstPtr
&inst
)
729 SelfDebug
*sd
= ArmISA::ISA::getSelfDebug(tc
);
730 VectorCatch
* vc
= sd
->getVectorCatch(tc
);
731 if (!vc
->isVCMatch()) {
732 Fault fault
= sd
->testVectorCatch(tc
, 0x0, this);
733 if (fault
!= NoFault
)
734 fault
->invoke(tc
, inst
);
741 ArmFault::instrAnnotate(const StaticInstPtr
&inst
)
744 auto arm_inst
= static_cast<ArmStaticInst
*>(inst
.get());
745 arm_inst
->annotateFault(this);
753 Reset::getVector(ThreadContext
*tc
)
757 // Check for invalid modes
758 CPSR M5_VAR_USED cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
759 assert(ArmSystem::haveSecurity(tc
) || cpsr
.mode
!= MODE_MON
);
760 assert(ArmSystem::haveVirtualization(tc
) || cpsr
.mode
!= MODE_HYP
);
762 // RVBAR is aliased (implemented as) MVBAR in gem5, since the two
763 // are mutually exclusive; there is no need to check here for
764 // which register to use since they hold the same value
765 base
= tc
->readMiscReg(MISCREG_MVBAR
);
767 return base
+ offset(tc
);
771 Reset::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
774 tc
->getCpuPtr()->clearInterrupts(tc
->threadId());
777 if (!ArmSystem::highestELIs64(tc
)) {
778 ArmFault::invoke(tc
, inst
);
779 tc
->setMiscReg(MISCREG_VMPIDR
,
780 getMPIDR(dynamic_cast<ArmSystem
*>(tc
->getSystemPtr()), tc
));
782 // Unless we have SMC code to get us there, boot in HYP!
783 if (ArmSystem::haveVirtualization(tc
) &&
784 !ArmSystem::haveSecurity(tc
)) {
785 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
786 cpsr
.mode
= MODE_HYP
;
787 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
790 // Advance the PC to the IMPLEMENTATION DEFINED reset value
791 PCState pc
= ArmSystem::resetAddr(tc
);
793 pc
.nextAArch64(true);
799 UndefinedInstruction::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
802 ArmFault::invoke(tc
, inst
);
806 // If the mnemonic isn't defined this has to be an unknown instruction.
807 assert(unknown
|| mnemonic
!= NULL
);
808 auto arm_inst
= static_cast<ArmStaticInst
*>(inst
.get());
810 panic("Attempted to execute disabled instruction "
811 "'%s' (inst 0x%08x)", mnemonic
, arm_inst
->encoding());
812 } else if (unknown
) {
813 panic("Attempted to execute unknown instruction (inst 0x%08x)",
814 arm_inst
->encoding());
816 panic("Attempted to execute unimplemented instruction "
817 "'%s' (inst 0x%08x)", mnemonic
, arm_inst
->encoding());
822 UndefinedInstruction::routeToHyp(ThreadContext
*tc
) const
824 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
825 return fromEL
== EL2
||
826 (EL2Enabled(tc
) && (fromEL
== EL0
) && hcr
.tge
);
830 UndefinedInstruction::iss() const
833 // If UndefinedInstruction is routed to hypervisor, iss field is 0.
838 if (overrideEc
== EC_INVALID
)
841 uint32_t new_iss
= 0;
842 uint32_t op0
, op1
, op2
, CRn
, CRm
, Rt
, dir
;
844 dir
= bits(machInst
, 21, 21);
845 op0
= bits(machInst
, 20, 19);
846 op1
= bits(machInst
, 18, 16);
847 CRn
= bits(machInst
, 15, 12);
848 CRm
= bits(machInst
, 11, 8);
849 op2
= bits(machInst
, 7, 5);
850 Rt
= bits(machInst
, 4, 0);
852 new_iss
= op0
<< 20 | op2
<< 17 | op1
<< 14 | CRn
<< 10 |
853 Rt
<< 5 | CRm
<< 1 | dir
;
859 SupervisorCall::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
862 ArmFault::invoke(tc
, inst
);
866 // As of now, there isn't a 32 bit thumb version of this instruction.
867 assert(!machInst
.bigThumb
);
870 // Advance the PC since that won't happen automatically.
871 PCState pc
= tc
->pcState();
878 SupervisorCall::routeToHyp(ThreadContext
*tc
) const
880 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
881 return fromEL
== EL2
||
882 (EL2Enabled(tc
) && fromEL
== EL0
&& hcr
.tge
);
886 SupervisorCall::ec(ThreadContext
*tc
) const
888 return (overrideEc
!= EC_INVALID
) ? overrideEc
:
889 (from64
? EC_SVC_64
: vals
.ec
);
893 SupervisorCall::iss() const
895 // Even if we have a 24 bit imm from an arm32 instruction then we only use
896 // the bottom 16 bits for the ISS value (it doesn't hurt for AArch64 SVC).
897 return issRaw
& 0xFFFF;
901 SecureMonitorCall::iss() const
904 return bits(machInst
, 20, 5);
909 UndefinedInstruction::ec(ThreadContext
*tc
) const
911 // If UndefinedInstruction is routed to hypervisor,
912 // HSR.EC field is 0.
916 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
920 HypervisorCall::HypervisorCall(ExtMachInst _machInst
, uint32_t _imm
) :
921 ArmFaultVals
<HypervisorCall
>(_machInst
, _imm
)
927 HypervisorCall::routeToMonitor(ThreadContext
*tc
) const
929 return from64
&& fromEL
== EL3
;
933 HypervisorCall::routeToHyp(ThreadContext
*tc
) const
935 return !from64
|| fromEL
!= EL3
;
939 HypervisorCall::ec(ThreadContext
*tc
) const
941 return from64
? EC_HVC_64
: vals
.ec
;
945 HypervisorTrap::ec(ThreadContext
*tc
) const
947 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
952 ArmFaultVals
<T
>::offset(ThreadContext
*tc
)
954 bool isHypTrap
= false;
956 // Normally we just use the exception vector from the table at the top if
957 // this file, however if this exception has caused a transition to hype
958 // mode, and its an exception type that would only do this if it has been
959 // trapped then we use the hyp trap vector instead of the normal vector
960 if (vals
.hypTrappable
) {
961 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
962 if (cpsr
.mode
== MODE_HYP
) {
963 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
964 isHypTrap
= spsr
.mode
!= MODE_HYP
;
967 return isHypTrap
? 0x14 : vals
.offset
;
972 ArmFaultVals
<T
>::offset64(ThreadContext
*tc
)
974 if (toEL
== fromEL
) {
975 if (opModeIsT(fromMode
))
976 return vals
.currELTOffset
;
977 return vals
.currELHOffset
;
979 bool lower_32
= false;
982 lower_32
= ELIs32(tc
, EL2
);
984 lower_32
= ELIs32(tc
, EL1
);
985 } else if (ELIsInHost(tc
, fromEL
) && fromEL
== EL0
&& toEL
== EL2
) {
986 lower_32
= ELIs32(tc
, EL0
);
988 lower_32
= ELIs32(tc
, static_cast<ExceptionLevel
>(toEL
- 1));
992 return vals
.lowerEL32Offset
;
993 return vals
.lowerEL64Offset
;
998 // SupervisorCall::setSyndrome64(ThreadContext *tc, MiscRegIndex esr_idx)
1001 // esr.ec = machInst.aarch64 ? SvcAArch64 : SvcAArch32;
1002 // esr.il = !machInst.thumb;
1003 // if (machInst.aarch64)
1004 // esr.imm16 = bits(machInst.instBits, 20, 5);
1005 // else if (machInst.thumb)
1006 // esr.imm16 = bits(machInst.instBits, 7, 0);
1008 // esr.imm16 = bits(machInst.instBits, 15, 0);
1009 // tc->setMiscReg(esr_idx, esr);
1013 SecureMonitorCall::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1016 ArmFault::invoke(tc
, inst
);
1022 SecureMonitorCall::ec(ThreadContext
*tc
) const
1024 return (from64
? EC_SMC_64
: vals
.ec
);
1028 SupervisorTrap::routeToHyp(ThreadContext
*tc
) const
1030 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1031 return EL2Enabled(tc
) && currEL(tc
) <= EL1
&& hcr
.tge
;
1035 SupervisorTrap::iss() const
1037 // If SupervisorTrap is routed to hypervisor, iss field is 0.
1045 SupervisorTrap::ec(ThreadContext
*tc
) const
1050 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
1054 SecureMonitorTrap::ec(ThreadContext
*tc
) const
1056 return (overrideEc
!= EC_INVALID
) ? overrideEc
:
1057 (from64
? EC_SMC_64
: vals
.ec
);
1062 AbortFault
<T
>::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1064 if (tranMethod
== ArmFault::UnknownTran
) {
1065 tranMethod
= longDescFormatInUse(tc
) ? ArmFault::LpaeTran
1066 : ArmFault::VmsaTran
;
1068 if ((tranMethod
== ArmFault::VmsaTran
) && this->routeToMonitor(tc
)) {
1069 // See ARM ARM B3-1416
1070 bool override_LPAE
= false;
1071 TTBCR ttbcr_s
= tc
->readMiscReg(MISCREG_TTBCR_S
);
1072 TTBCR M5_VAR_USED ttbcr_ns
= tc
->readMiscReg(MISCREG_TTBCR_NS
);
1074 override_LPAE
= true;
1076 // Unimplemented code option, not seen in testing. May need
1077 // extension according to the manual exceprt above.
1078 DPRINTF(Faults
, "Warning: Incomplete translation method "
1079 "override detected.\n");
1082 tranMethod
= ArmFault::LpaeTran
;
1086 if (source
== ArmFault::AsynchronousExternalAbort
) {
1087 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_ABT
, 0);
1089 // Get effective fault source encoding
1090 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
1092 // source must be determined BEFORE invoking generic routines which will
1093 // try to set hsr etc. and are based upon source!
1094 ArmFaultVals
<T
>::invoke(tc
, inst
);
1096 if (!this->to64
) { // AArch32
1097 FSR fsr
= getFsr(tc
);
1098 if (cpsr
.mode
== MODE_HYP
) {
1099 tc
->setMiscReg(T::HFarIndex
, faultAddr
);
1100 } else if (stage2
) {
1101 tc
->setMiscReg(MISCREG_HPFAR
, (faultAddr
>> 8) & ~0xf);
1102 tc
->setMiscReg(T::HFarIndex
, OVAddr
);
1103 } else if (debug
> ArmFault::NODEBUG
) {
1104 DBGDS32 Rext
= tc
->readMiscReg(MISCREG_DBGDSCRext
);
1105 tc
->setMiscReg(T::FarIndex
, faultAddr
);
1106 if (debug
== ArmFault::BRKPOINT
){
1108 } else if (debug
== ArmFault::VECTORCATCH
){
1110 } else if (debug
> ArmFault::VECTORCATCH
) {
1112 fsr
.cm
= (debug
== ArmFault::WPOINT_CM
)? 1 : 0;
1115 tc
->setMiscReg(T::FsrIndex
, fsr
);
1116 tc
->setMiscReg(MISCREG_DBGDSCRext
, Rext
);
1119 tc
->setMiscReg(T::FsrIndex
, fsr
);
1120 tc
->setMiscReg(T::FarIndex
, faultAddr
);
1122 DPRINTF(Faults
, "Abort Fault source=%#x fsr=%#x faultAddr=%#x "\
1123 "tranMethod=%#x\n", source
, fsr
, faultAddr
, tranMethod
);
1125 // Set the FAR register. Nothing else to do if we are in AArch64 state
1126 // because the syndrome register has already been set inside invoke64()
1128 // stage 2 fault, set HPFAR_EL2 to the faulting IPA
1129 // and FAR_EL2 to the Original VA
1130 tc
->setMiscReg(AbortFault
<T
>::getFaultAddrReg64(), OVAddr
);
1131 tc
->setMiscReg(MISCREG_HPFAR_EL2
, bits(faultAddr
, 47, 12) << 4);
1133 DPRINTF(Faults
, "Abort Fault (Stage 2) VA: 0x%x IPA: 0x%x\n",
1136 tc
->setMiscReg(AbortFault
<T
>::getFaultAddrReg64(), faultAddr
);
1143 AbortFault
<T
>::setSyndrome(ThreadContext
*tc
, MiscRegIndex syndrome_reg
)
1145 srcEncoded
= getFaultStatusCode(tc
);
1146 if (srcEncoded
== ArmFault::FaultSourceInvalid
) {
1147 panic("Invalid fault source\n");
1149 ArmFault::setSyndrome(tc
, syndrome_reg
);
1154 AbortFault
<T
>::getFaultStatusCode(ThreadContext
*tc
) const
1157 panic_if(!this->faultUpdated
,
1158 "Trying to use un-updated ArmFault internal variables\n");
1164 assert(tranMethod
!= ArmFault::UnknownTran
);
1165 if (tranMethod
== ArmFault::LpaeTran
) {
1166 fsc
= ArmFault::longDescFaultSources
[source
];
1168 fsc
= ArmFault::shortDescFaultSources
[source
];
1172 fsc
= ArmFault::aarch64FaultSources
[source
];
1180 AbortFault
<T
>::getFsr(ThreadContext
*tc
) const
1184 auto fsc
= getFaultStatusCode(tc
);
1187 assert(tranMethod
!= ArmFault::UnknownTran
);
1188 if (tranMethod
== ArmFault::LpaeTran
) {
1192 fsr
.fsLow
= bits(fsc
, 3, 0);
1193 fsr
.fsHigh
= bits(fsc
, 4);
1194 fsr
.domain
= static_cast<uint8_t>(domain
);
1197 fsr
.wnr
= (write
? 1 : 0);
1205 AbortFault
<T
>::abortDisable(ThreadContext
*tc
)
1207 if (ArmSystem::haveSecurity(tc
)) {
1208 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1209 return (!scr
.ns
|| scr
.aw
);
1216 AbortFault
<T
>::annotate(ArmFault::AnnotationIDs id
, uint64_t val
)
1220 case ArmFault::S1PTW
:
1227 // Just ignore unknown ID's
1235 AbortFault
<T
>::iss() const
1239 val
= srcEncoded
& 0x3F;
1247 AbortFault
<T
>::isMMUFault() const
1249 // NOTE: Not relying on LL information being aligned to lowest bits here
1251 (source
== ArmFault::AlignmentFault
) ||
1252 ((source
>= ArmFault::TranslationLL
) &&
1253 (source
< ArmFault::TranslationLL
+ 4)) ||
1254 ((source
>= ArmFault::AccessFlagLL
) &&
1255 (source
< ArmFault::AccessFlagLL
+ 4)) ||
1256 ((source
>= ArmFault::DomainLL
) &&
1257 (source
< ArmFault::DomainLL
+ 4)) ||
1258 ((source
>= ArmFault::PermissionLL
) &&
1259 (source
< ArmFault::PermissionLL
+ 4));
1264 AbortFault
<T
>::getFaultVAddr(Addr
&va
) const
1266 va
= (stage2
? OVAddr
: faultAddr
);
1271 PrefetchAbort::ec(ThreadContext
*tc
) const
1276 return EC_PREFETCH_ABORT_CURR_EL
;
1278 return EC_PREFETCH_ABORT_LOWER_EL
;
1281 // Abort faults have different EC codes depending on whether
1282 // the fault originated within HYP mode, or not. So override
1283 // the method and add the extra adjustment of the EC value.
1285 ExceptionClass ec
= ArmFaultVals
<PrefetchAbort
>::vals
.ec
;
1287 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
1288 if (spsr
.mode
== MODE_HYP
) {
1289 ec
= ((ExceptionClass
) (((uint32_t) ec
) + 1));
1296 PrefetchAbort::routeToMonitor(ThreadContext
*tc
) const
1300 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1302 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1304 return scr
.ea
&& !isMMUFault();
1308 PrefetchAbort::routeToHyp(ThreadContext
*tc
) const
1312 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1313 HDCR hdcr
= tc
->readMiscRegNoEffect(MISCREG_HDCR
);
1315 toHyp
= fromEL
== EL2
;
1316 toHyp
|= ArmSystem::haveEL(tc
, EL2
) && !isSecure(tc
) &&
1317 currEL(tc
) <= EL1
&& (hcr
.tge
|| stage2
||
1318 (source
== DebugEvent
&& hdcr
.tde
));
1323 DataAbort::ec(ThreadContext
*tc
) const
1327 if (source
== ArmFault::AsynchronousExternalAbort
) {
1328 panic("Asynchronous External Abort should be handled with "
1329 "SystemErrors (SErrors)!");
1332 return EC_DATA_ABORT_CURR_EL
;
1334 return EC_DATA_ABORT_LOWER_EL
;
1337 // Abort faults have different EC codes depending on whether
1338 // the fault originated within HYP mode, or not. So override
1339 // the method and add the extra adjustment of the EC value.
1341 ExceptionClass ec
= ArmFaultVals
<DataAbort
>::vals
.ec
;
1343 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
1344 if (spsr
.mode
== MODE_HYP
) {
1345 ec
= ((ExceptionClass
) (((uint32_t) ec
) + 1));
1352 DataAbort::routeToMonitor(ThreadContext
*tc
) const
1356 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1358 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1360 return scr
.ea
&& !isMMUFault();
1364 DataAbort::routeToHyp(ThreadContext
*tc
) const
1368 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1369 HDCR hdcr
= tc
->readMiscRegNoEffect(MISCREG_HDCR
);
1373 amo
= (!HaveVirtHostExt(tc
) || hcr
.e2h
== 0);
1375 // if in Hyp mode then stay in Hyp mode
1376 toHyp
= fromEL
== EL2
||
1377 (EL2Enabled(tc
) && fromEL
<= EL1
1378 && (hcr
.tge
|| stage2
||
1379 ((source
== AsynchronousExternalAbort
) && amo
) ||
1380 ((fromEL
== EL0
) && hcr
.tge
&&
1381 ((source
== AlignmentFault
) ||
1382 (source
== SynchronousExternalAbort
))) ||
1383 ((source
== DebugEvent
) && (hdcr
.tde
|| hcr
.tge
))));
1388 DataAbort::iss() const
1392 // Add on the data abort specific fields to the generic abort ISS value
1393 val
= AbortFault
<DataAbort
>::iss();
1397 // ISS is valid if not caused by a stage 1 page table walk, and when taken
1398 // to AArch64 only when directed to EL2
1399 if (!s1ptw
&& stage2
&& (!to64
|| toEL
== EL2
)) {
1405 // AArch64 only. These assignments are safe on AArch32 as well
1406 // because these vars are initialized to false
1415 DataAbort::annotate(AnnotationIDs id
, uint64_t val
)
1417 AbortFault
<DataAbort
>::annotate(id
, val
);
1446 // Just ignore unknown ID's
1453 VirtualDataAbort::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1455 AbortFault
<VirtualDataAbort
>::invoke(tc
, inst
);
1456 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1458 tc
->setMiscRegNoEffect(MISCREG_HCR
, hcr
);
1462 Interrupt::routeToMonitor(ThreadContext
*tc
) const
1464 assert(ArmSystem::haveSecurity(tc
));
1467 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1469 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1474 Interrupt::routeToHyp(ThreadContext
*tc
) const
1476 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1477 return fromEL
== EL2
||
1478 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| hcr
.imo
));
1482 Interrupt::abortDisable(ThreadContext
*tc
)
1484 if (ArmSystem::haveSecurity(tc
)) {
1485 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1486 return (!scr
.ns
|| scr
.aw
);
1491 VirtualInterrupt::VirtualInterrupt()
1495 FastInterrupt::routeToMonitor(ThreadContext
*tc
) const
1497 assert(ArmSystem::haveSecurity(tc
));
1500 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1502 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1507 FastInterrupt::routeToHyp(ThreadContext
*tc
) const
1509 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1510 return fromEL
== EL2
||
1511 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| hcr
.fmo
));
1515 FastInterrupt::abortDisable(ThreadContext
*tc
)
1517 if (ArmSystem::haveSecurity(tc
)) {
1518 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1519 return (!scr
.ns
|| scr
.aw
);
1525 FastInterrupt::fiqDisable(ThreadContext
*tc
)
1527 if (ArmSystem::haveVirtualization(tc
)) {
1529 } else if (ArmSystem::haveSecurity(tc
)) {
1530 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1531 return (!scr
.ns
|| scr
.fw
);
1536 VirtualFastInterrupt::VirtualFastInterrupt()
1540 PCAlignmentFault::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1542 ArmFaultVals
<PCAlignmentFault
>::invoke(tc
, inst
);
1545 tc
->setMiscReg(getFaultAddrReg64(), faultPC
);
1549 PCAlignmentFault::routeToHyp(ThreadContext
*tc
) const
1551 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1552 return fromEL
== EL2
|| (EL2Enabled(tc
) && fromEL
<= EL1
&& hcr
.tge
);
1555 SPAlignmentFault::SPAlignmentFault()
1559 SPAlignmentFault::routeToHyp(ThreadContext
*tc
) const
1562 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1563 return EL2Enabled(tc
) && currEL(tc
) <= EL1
&& hcr
.tge
== 1;
1566 SystemError::SystemError()
1570 SystemError::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1572 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_ABT
, 0);
1573 ArmFault::invoke(tc
, inst
);
1577 SystemError::routeToMonitor(ThreadContext
*tc
) const
1579 assert(ArmSystem::haveSecurity(tc
));
1581 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1582 return scr
.ea
|| fromEL
== EL3
;
1586 SystemError::routeToHyp(ThreadContext
*tc
) const
1590 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1592 return fromEL
== EL2
||
1593 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| hcr
.amo
));
1597 SoftwareBreakpoint::SoftwareBreakpoint(ExtMachInst _mach_inst
, uint32_t _iss
)
1598 : ArmFaultVals
<SoftwareBreakpoint
>(_mach_inst
, _iss
)
1602 SoftwareBreakpoint::routeToHyp(ThreadContext
*tc
) const
1604 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1605 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1607 return fromEL
== EL2
||
1608 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
));
1612 SoftwareBreakpoint::ec(ThreadContext
*tc
) const
1614 return from64
? EC_SOFTWARE_BREAKPOINT_64
: vals
.ec
;
1617 HardwareBreakpoint::HardwareBreakpoint(Addr _vaddr
, uint32_t _iss
)
1618 : ArmFaultVals
<HardwareBreakpoint
>(0x0, _iss
), vAddr(_vaddr
)
1622 HardwareBreakpoint::routeToHyp(ThreadContext
*tc
) const
1624 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1625 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1627 return EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
);
1631 HardwareBreakpoint::ec(ThreadContext
*tc
) const
1635 return EC_HW_BREAKPOINT_CURR_EL
;
1637 return EC_HW_BREAKPOINT_LOWER_EL
;
1641 HardwareBreakpoint::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1644 ArmFaultVals
<HardwareBreakpoint
>::invoke(tc
, inst
);
1645 MiscRegIndex elr_idx
;
1648 elr_idx
= MISCREG_ELR_EL1
;
1651 assert(ArmSystem::haveVirtualization(tc
));
1652 elr_idx
= MISCREG_ELR_EL2
;
1655 assert(ArmSystem::haveSecurity(tc
));
1656 elr_idx
= MISCREG_ELR_EL3
;
1659 panic("Invalid target exception level");
1663 tc
->setMiscReg(elr_idx
, vAddr
);
1667 Watchpoint::Watchpoint(ExtMachInst _mach_inst
, Addr _vaddr
,
1668 bool _write
, bool _cm
)
1669 : ArmFaultVals
<Watchpoint
>(_mach_inst
), vAddr(_vaddr
),
1670 write(_write
), cm(_cm
)
1674 Watchpoint::iss() const
1676 uint32_t iss
= 0x0022;
1688 Watchpoint::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1690 ArmFaultVals
<Watchpoint
>::invoke(tc
, inst
);
1692 tc
->setMiscReg(getFaultAddrReg64(), vAddr
);
1697 Watchpoint::routeToHyp(ThreadContext
*tc
) const
1699 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1700 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1702 return fromEL
== EL2
||
1703 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
));
1707 Watchpoint::annotate(AnnotationIDs id
, uint64_t val
)
1709 ArmFaultVals
<Watchpoint
>::annotate(id
, val
);
1715 // Just ignore unknown ID's
1722 Watchpoint::ec(ThreadContext
*tc
) const
1726 return EC_WATCHPOINT_CURR_EL
;
1728 return EC_WATCHPOINT_LOWER_EL
;
1731 SoftwareStepFault::SoftwareStepFault(ExtMachInst _mach_inst
, bool is_ldx
,
1733 : ArmFaultVals
<SoftwareStepFault
>(_mach_inst
), isldx(is_ldx
),
1740 SoftwareStepFault::routeToHyp(ThreadContext
*tc
) const
1742 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1743 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1745 return fromEL
== EL2
||
1746 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
));
1750 SoftwareStepFault::ec(ThreadContext
*tc
) const
1754 return EC_SOFTWARE_STEP_CURR_EL
;
1756 return EC_SOFTWARE_STEP_LOWER_EL
;
1760 SoftwareStepFault::iss() const
1762 uint32_t iss
= 0x0022;
1776 ArmSev::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
) {
1777 DPRINTF(Faults
, "Invoking ArmSev Fault\n");
1781 // Set sev_mailbox to 1, clear the pending interrupt from remote
1782 // SEV execution and let pipeline continue as pcState is still
1784 tc
->setMiscReg(MISCREG_SEV_MAILBOX
, 1);
1785 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_SEV
, 0);
1788 // Instantiate all the templates to make the linker happy
1789 template class ArmFaultVals
<Reset
>;
1790 template class ArmFaultVals
<UndefinedInstruction
>;
1791 template class ArmFaultVals
<SupervisorCall
>;
1792 template class ArmFaultVals
<SecureMonitorCall
>;
1793 template class ArmFaultVals
<HypervisorCall
>;
1794 template class ArmFaultVals
<PrefetchAbort
>;
1795 template class ArmFaultVals
<DataAbort
>;
1796 template class ArmFaultVals
<VirtualDataAbort
>;
1797 template class ArmFaultVals
<HypervisorTrap
>;
1798 template class ArmFaultVals
<Interrupt
>;
1799 template class ArmFaultVals
<VirtualInterrupt
>;
1800 template class ArmFaultVals
<FastInterrupt
>;
1801 template class ArmFaultVals
<VirtualFastInterrupt
>;
1802 template class ArmFaultVals
<SupervisorTrap
>;
1803 template class ArmFaultVals
<SecureMonitorTrap
>;
1804 template class ArmFaultVals
<PCAlignmentFault
>;
1805 template class ArmFaultVals
<SPAlignmentFault
>;
1806 template class ArmFaultVals
<SystemError
>;
1807 template class ArmFaultVals
<SoftwareBreakpoint
>;
1808 template class ArmFaultVals
<HardwareBreakpoint
>;
1809 template class ArmFaultVals
<Watchpoint
>;
1810 template class ArmFaultVals
<SoftwareStepFault
>;
1811 template class ArmFaultVals
<ArmSev
>;
1812 template class AbortFault
<PrefetchAbort
>;
1813 template class AbortFault
<DataAbort
>;
1814 template class AbortFault
<VirtualDataAbort
>;
1817 IllegalInstSetStateFault::IllegalInstSetStateFault()
1821 IllegalInstSetStateFault::routeToHyp(ThreadContext
*tc
) const
1823 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1824 return EL2Enabled(tc
) && fromEL
== EL0
&& hcr
.tge
;
1828 getFaultVAddr(Fault fault
, Addr
&va
)
1830 auto arm_fault
= dynamic_cast<ArmFault
*>(fault
.get());
1833 return arm_fault
->getFaultVAddr(va
);
1835 auto pgt_fault
= dynamic_cast<GenericPageTableFault
*>(fault
.get());
1837 va
= pgt_fault
->getFaultVAddr();
1841 auto align_fault
= dynamic_cast<GenericAlignmentFault
*>(fault
.get());
1843 va
= align_fault
->getFaultVAddr();
1847 // Return false since it's not an address triggered exception
1852 } // namespace ArmISA