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/isa.hh"
46 #include "arch/arm/self_debug.hh"
47 #include "arch/arm/system.hh"
48 #include "arch/arm/utility.hh"
49 #include "base/compiler.hh"
50 #include "base/trace.hh"
51 #include "cpu/base.hh"
52 #include "cpu/thread_context.hh"
53 #include "debug/Faults.hh"
54 #include "sim/full_system.hh"
59 uint8_t ArmFault::shortDescFaultSources
[] = {
60 0x01, // AlignmentFault
61 0x04, // InstructionCacheMaintenance
62 0xff, // SynchExtAbtOnTranslTableWalkL0 (INVALID)
63 0x0c, // SynchExtAbtOnTranslTableWalkL1
64 0x0e, // SynchExtAbtOnTranslTableWalkL2
65 0xff, // SynchExtAbtOnTranslTableWalkL3 (INVALID)
66 0xff, // SynchPtyErrOnTranslTableWalkL0 (INVALID)
67 0x1c, // SynchPtyErrOnTranslTableWalkL1
68 0x1e, // SynchPtyErrOnTranslTableWalkL2
69 0xff, // SynchPtyErrOnTranslTableWalkL3 (INVALID)
70 0xff, // TranslationL0 (INVALID)
71 0x05, // TranslationL1
72 0x07, // TranslationL2
73 0xff, // TranslationL3 (INVALID)
74 0xff, // AccessFlagL0 (INVALID)
77 0xff, // AccessFlagL3 (INVALID)
78 0xff, // DomainL0 (INVALID)
81 0xff, // DomainL3 (INVALID)
82 0xff, // PermissionL0 (INVALID)
85 0xff, // PermissionL3 (INVALID)
87 0x08, // SynchronousExternalAbort
88 0x10, // TLBConflictAbort
89 0x19, // SynchPtyErrOnMemoryAccess
90 0x16, // AsynchronousExternalAbort
91 0x18, // AsynchPtyErrOnMemoryAccess
92 0xff, // AddressSizeL0 (INVALID)
93 0xff, // AddressSizeL1 (INVALID)
94 0xff, // AddressSizeL2 (INVALID)
95 0xff, // AddressSizeL3 (INVALID)
96 0x40, // PrefetchTLBMiss
97 0x80 // PrefetchUncacheable
100 static_assert(sizeof(ArmFault::shortDescFaultSources
) ==
101 ArmFault::NumFaultSources
,
102 "Invalid size of ArmFault::shortDescFaultSources[]");
104 uint8_t ArmFault::longDescFaultSources
[] = {
105 0x21, // AlignmentFault
106 0xff, // InstructionCacheMaintenance (INVALID)
107 0xff, // SynchExtAbtOnTranslTableWalkL0 (INVALID)
108 0x15, // SynchExtAbtOnTranslTableWalkL1
109 0x16, // SynchExtAbtOnTranslTableWalkL2
110 0x17, // SynchExtAbtOnTranslTableWalkL3
111 0xff, // SynchPtyErrOnTranslTableWalkL0 (INVALID)
112 0x1d, // SynchPtyErrOnTranslTableWalkL1
113 0x1e, // SynchPtyErrOnTranslTableWalkL2
114 0x1f, // SynchPtyErrOnTranslTableWalkL3
115 0xff, // TranslationL0 (INVALID)
116 0x05, // TranslationL1
117 0x06, // TranslationL2
118 0x07, // TranslationL3
119 0xff, // AccessFlagL0 (INVALID)
120 0x09, // AccessFlagL1
121 0x0a, // AccessFlagL2
122 0x0b, // AccessFlagL3
123 0xff, // DomainL0 (INVALID)
126 0xff, // DomainL3 (RESERVED)
127 0xff, // PermissionL0 (INVALID)
128 0x0d, // PermissionL1
129 0x0e, // PermissionL2
130 0x0f, // PermissionL3
132 0x10, // SynchronousExternalAbort
133 0x30, // TLBConflictAbort
134 0x18, // SynchPtyErrOnMemoryAccess
135 0x11, // AsynchronousExternalAbort
136 0x19, // AsynchPtyErrOnMemoryAccess
137 0xff, // AddressSizeL0 (INVALID)
138 0xff, // AddressSizeL1 (INVALID)
139 0xff, // AddressSizeL2 (INVALID)
140 0xff, // AddressSizeL3 (INVALID)
141 0x40, // PrefetchTLBMiss
142 0x80 // PrefetchUncacheable
145 static_assert(sizeof(ArmFault::longDescFaultSources
) ==
146 ArmFault::NumFaultSources
,
147 "Invalid size of ArmFault::longDescFaultSources[]");
149 uint8_t ArmFault::aarch64FaultSources
[] = {
150 0x21, // AlignmentFault
151 0xff, // InstructionCacheMaintenance (INVALID)
152 0x14, // SynchExtAbtOnTranslTableWalkL0
153 0x15, // SynchExtAbtOnTranslTableWalkL1
154 0x16, // SynchExtAbtOnTranslTableWalkL2
155 0x17, // SynchExtAbtOnTranslTableWalkL3
156 0x1c, // SynchPtyErrOnTranslTableWalkL0
157 0x1d, // SynchPtyErrOnTranslTableWalkL1
158 0x1e, // SynchPtyErrOnTranslTableWalkL2
159 0x1f, // SynchPtyErrOnTranslTableWalkL3
160 0x04, // TranslationL0
161 0x05, // TranslationL1
162 0x06, // TranslationL2
163 0x07, // TranslationL3
164 0x08, // AccessFlagL0
165 0x09, // AccessFlagL1
166 0x0a, // AccessFlagL2
167 0x0b, // AccessFlagL3
168 // @todo: Section & Page Domain Fault in AArch64?
169 0xff, // DomainL0 (INVALID)
170 0xff, // DomainL1 (INVALID)
171 0xff, // DomainL2 (INVALID)
172 0xff, // DomainL3 (INVALID)
173 0x0c, // PermissionL0
174 0x0d, // PermissionL1
175 0x0e, // PermissionL2
176 0x0f, // PermissionL3
178 0x10, // SynchronousExternalAbort
179 0x30, // TLBConflictAbort
180 0x18, // SynchPtyErrOnMemoryAccess
181 0xff, // AsynchronousExternalAbort (INVALID)
182 0xff, // AsynchPtyErrOnMemoryAccess (INVALID)
183 0x00, // AddressSizeL0
184 0x01, // AddressSizeL1
185 0x02, // AddressSizeL2
186 0x03, // AddressSizeL3
187 0x40, // PrefetchTLBMiss
188 0x80 // PrefetchUncacheable
191 static_assert(sizeof(ArmFault::aarch64FaultSources
) ==
192 ArmFault::NumFaultSources
,
193 "Invalid size of ArmFault::aarch64FaultSources[]");
195 // Fields: name, offset, cur{ELT,ELH}Offset, lowerEL{64,32}Offset, next mode,
196 // {ARM, Thumb, ARM_ELR, Thumb_ELR} PC offset, hyp trap,
197 // {A, F} disable, class, stat
198 template<> ArmFault::FaultVals ArmFaultVals
<Reset
>::vals(
199 // Some dummy values (the reset vector has an IMPLEMENTATION DEFINED
200 // location in AArch64)
201 "Reset", 0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC
,
202 0, 0, 0, 0, false, true, true, EC_UNKNOWN
204 template<> ArmFault::FaultVals ArmFaultVals
<UndefinedInstruction
>::vals(
205 "Undefined Instruction", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_UNDEFINED
,
206 4, 2, 0, 0, true, false, false, EC_UNKNOWN
208 template<> ArmFault::FaultVals ArmFaultVals
<SupervisorCall
>::vals(
209 "Supervisor Call", 0x008, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
210 4, 2, 4, 2, true, false, false, EC_SVC_TO_HYP
212 template<> ArmFault::FaultVals ArmFaultVals
<SecureMonitorCall
>::vals(
213 "Secure Monitor Call", 0x008, 0x000, 0x200, 0x400, 0x600, MODE_MON
,
214 4, 4, 4, 4, false, true, true, EC_SMC_TO_HYP
216 template<> ArmFault::FaultVals ArmFaultVals
<HypervisorCall
>::vals(
217 "Hypervisor Call", 0x008, 0x000, 0x200, 0x400, 0x600, MODE_HYP
,
218 4, 4, 4, 4, true, false, false, EC_HVC
220 template<> ArmFault::FaultVals ArmFaultVals
<PrefetchAbort
>::vals(
221 "Prefetch Abort", 0x00C, 0x000, 0x200, 0x400, 0x600, MODE_ABORT
,
222 4, 4, 0, 0, true, true, false, EC_PREFETCH_ABORT_TO_HYP
224 template<> ArmFault::FaultVals ArmFaultVals
<DataAbort
>::vals(
225 "Data Abort", 0x010, 0x000, 0x200, 0x400, 0x600, MODE_ABORT
,
226 8, 8, 0, 0, true, true, false, EC_DATA_ABORT_TO_HYP
228 template<> ArmFault::FaultVals ArmFaultVals
<VirtualDataAbort
>::vals(
229 "Virtual Data Abort", 0x010, 0x000, 0x200, 0x400, 0x600, MODE_ABORT
,
230 8, 8, 0, 0, true, true, false, EC_INVALID
232 template<> ArmFault::FaultVals ArmFaultVals
<HypervisorTrap
>::vals(
233 // @todo: double check these values
234 "Hypervisor Trap", 0x014, 0x000, 0x200, 0x400, 0x600, MODE_HYP
,
235 0, 0, 0, 0, false, false, false, EC_UNKNOWN
237 template<> ArmFault::FaultVals ArmFaultVals
<SecureMonitorTrap
>::vals(
238 "Secure Monitor Trap", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_MON
,
239 4, 2, 0, 0, false, false, false, EC_UNKNOWN
241 template<> ArmFault::FaultVals ArmFaultVals
<Interrupt
>::vals(
242 "IRQ", 0x018, 0x080, 0x280, 0x480, 0x680, MODE_IRQ
,
243 4, 4, 0, 0, false, true, false, EC_UNKNOWN
245 template<> ArmFault::FaultVals ArmFaultVals
<VirtualInterrupt
>::vals(
246 "Virtual IRQ", 0x018, 0x080, 0x280, 0x480, 0x680, MODE_IRQ
,
247 4, 4, 0, 0, false, true, false, EC_INVALID
249 template<> ArmFault::FaultVals ArmFaultVals
<FastInterrupt
>::vals(
250 "FIQ", 0x01C, 0x100, 0x300, 0x500, 0x700, MODE_FIQ
,
251 4, 4, 0, 0, false, true, true, EC_UNKNOWN
253 template<> ArmFault::FaultVals ArmFaultVals
<VirtualFastInterrupt
>::vals(
254 "Virtual FIQ", 0x01C, 0x100, 0x300, 0x500, 0x700, MODE_FIQ
,
255 4, 4, 0, 0, false, true, true, EC_INVALID
257 template<> ArmFault::FaultVals ArmFaultVals
<IllegalInstSetStateFault
>::vals(
258 "Illegal Inst Set State Fault", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_UNDEFINED
,
259 4, 2, 0, 0, true, false, false, EC_ILLEGAL_INST
261 template<> ArmFault::FaultVals ArmFaultVals
<SupervisorTrap
>::vals(
262 // Some dummy values (SupervisorTrap is AArch64-only)
263 "Supervisor Trap", 0x014, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
264 0, 0, 0, 0, false, false, false, EC_UNKNOWN
266 template<> ArmFault::FaultVals ArmFaultVals
<PCAlignmentFault
>::vals(
267 // Some dummy values (PCAlignmentFault is AArch64-only)
268 "PC Alignment Fault", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
269 0, 0, 0, 0, true, false, false, EC_PC_ALIGNMENT
271 template<> ArmFault::FaultVals ArmFaultVals
<SPAlignmentFault
>::vals(
272 // Some dummy values (SPAlignmentFault is AArch64-only)
273 "SP Alignment Fault", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
274 0, 0, 0, 0, true, false, false, EC_STACK_PTR_ALIGNMENT
276 template<> ArmFault::FaultVals ArmFaultVals
<SystemError
>::vals(
277 // Some dummy values (SError is AArch64-only)
278 "SError", 0x000, 0x180, 0x380, 0x580, 0x780, MODE_SVC
,
279 0, 0, 0, 0, false, true, true, EC_SERROR
281 template<> ArmFault::FaultVals ArmFaultVals
<SoftwareBreakpoint
>::vals(
282 // Some dummy values (SoftwareBreakpoint is AArch64-only)
283 "Software Breakpoint", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
284 0, 0, 0, 0, true, false, false, EC_SOFTWARE_BREAKPOINT
286 template<> ArmFault::FaultVals ArmFaultVals
<HardwareBreakpoint
>::vals(
287 "Hardware Breakpoint", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
288 0, 0, 0, 0, true, false, false, EC_HW_BREAKPOINT
290 template<> ArmFault::FaultVals ArmFaultVals
<Watchpoint
>::vals(
291 "Watchpoint", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
292 0, 0, 0, 0, true, false, false, EC_WATCHPOINT
294 template<> ArmFault::FaultVals ArmFaultVals
<SoftwareStepFault
>::vals(
295 "SoftwareStep", 0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC
,
296 0, 0, 0, 0, true, false, false, EC_SOFTWARE_STEP
298 template<> ArmFault::FaultVals ArmFaultVals
<ArmSev
>::vals(
300 "ArmSev Flush", 0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC
,
301 0, 0, 0, 0, false, true, true, EC_UNKNOWN
305 ArmFault::getVector(ThreadContext
*tc
)
309 // Check for invalid modes
310 CPSR cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
311 assert(ArmSystem::haveSecurity(tc
) || cpsr
.mode
!= MODE_MON
);
312 assert(ArmSystem::haveVirtualization(tc
) || cpsr
.mode
!= MODE_HYP
);
317 base
= tc
->readMiscReg(MISCREG_MVBAR
);
320 base
= tc
->readMiscReg(MISCREG_HVBAR
);
323 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
327 base
= ArmSystem::haveSecurity(tc
) ?
328 tc
->readMiscReg(MISCREG_VBAR
) : 0;
333 return base
+ offset(tc
);
337 ArmFault::getVector64(ThreadContext
*tc
)
342 assert(ArmSystem::haveSecurity(tc
));
343 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL3
);
346 assert(ArmSystem::haveVirtualization(tc
));
347 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL2
);
350 vbar
= tc
->readMiscReg(MISCREG_VBAR_EL1
);
353 panic("Invalid target exception level");
356 return vbar
+ offset64(tc
);
360 ArmFault::getSyndromeReg64() const
364 return MISCREG_ESR_EL1
;
366 return MISCREG_ESR_EL2
;
368 return MISCREG_ESR_EL3
;
370 panic("Invalid exception level");
376 ArmFault::getFaultAddrReg64() const
380 return MISCREG_FAR_EL1
;
382 return MISCREG_FAR_EL2
;
384 return MISCREG_FAR_EL3
;
386 panic("Invalid exception level");
392 ArmFault::setSyndrome(ThreadContext
*tc
, MiscRegIndex syndrome_reg
)
395 uint32_t exc_class
= (uint32_t) ec(tc
);
396 uint32_t issVal
= iss();
398 assert(!from64
|| ArmSystem::highestELIs64(tc
));
400 value
= exc_class
<< 26;
402 // HSR.IL not valid for Prefetch Aborts (0x20, 0x21) and Data Aborts (0x24,
403 // 0x25) for which the ISS information is not valid (ARMv7).
404 // @todo: ARMv8 revises AArch32 functionality: when HSR.IL is not
405 // valid it is treated as RES1.
408 } else if ((bits(exc_class
, 5, 3) != 4) ||
409 (bits(exc_class
, 2) && bits(issVal
, 24))) {
410 if (!machInst
.thumb
|| machInst
.bigThumb
)
413 // Condition code valid for EC[5:4] nonzero
414 if (!from64
&& ((bits(exc_class
, 5, 4) == 0) &&
415 (bits(exc_class
, 3, 0) != 0))) {
416 if (!machInst
.thumb
) {
418 ConditionCode condCode
= (ConditionCode
) (uint32_t) machInst
.condCode
;
419 // If its on unconditional instruction report with a cond code of
420 // 0xE, ie the unconditional code
421 cond
= (condCode
== COND_UC
) ? COND_AL
: condCode
;
425 value
|= bits(issVal
, 19, 0);
429 tc
->setMiscReg(syndrome_reg
, value
);
433 ArmFault::update(ThreadContext
*tc
)
435 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
437 // Determine source exception level and mode
438 fromMode
= (OperatingMode
) (uint8_t) cpsr
.mode
;
439 fromEL
= opModeToEL(fromMode
);
440 if (opModeIs64(fromMode
))
443 // Determine target exception level (aarch64) or target execution
445 if (ArmSystem::haveSecurity(tc
) && routeToMonitor(tc
)) {
448 } else if (ArmSystem::haveVirtualization(tc
) && routeToHyp(tc
)) {
454 toEL
= opModeToEL(toMode
);
460 // Check for Set Priviledge Access Never, if PAN is supported
461 AA64MMFR1 mmfr1
= tc
->readMiscReg(MISCREG_ID_AA64MMFR1_EL1
);
464 const SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR_EL1
);
468 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
469 if (toEL
== EL2
&& hcr
.e2h
&& hcr
.tge
) {
470 const SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR_EL2
);
475 to64
= ELIs64(tc
, toEL
);
477 // The fault specific informations have been updated; it is
478 // now possible to use them inside the fault.
483 ArmFault::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
485 // Update fault state informations, like the starting mode (aarch32)
486 // or EL (aarch64) and the ending mode or EL.
487 // From the update function we are also evaluating if the fault must
488 // be handled in AArch64 mode (to64).
492 // Invoke exception handler in AArch64 state
497 if (vectorCatch(tc
, inst
))
500 // ARMv7 (ARM ARM issue C B1.9)
502 bool have_security
= ArmSystem::haveSecurity(tc
);
504 FaultBase::invoke(tc
);
509 SCTLR sctlr
= tc
->readMiscReg(MISCREG_SCTLR
);
510 SCR scr
= tc
->readMiscReg(MISCREG_SCR
);
511 CPSR saved_cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
512 saved_cpsr
.nz
= tc
->readCCReg(CCREG_NZ
);
513 saved_cpsr
.c
= tc
->readCCReg(CCREG_C
);
514 saved_cpsr
.v
= tc
->readCCReg(CCREG_V
);
515 saved_cpsr
.ge
= tc
->readCCReg(CCREG_GE
);
517 Addr curPc M5_VAR_USED
= tc
->pcState().pc();
518 ITSTATE it
= tc
->pcState().itstate();
519 saved_cpsr
.it2
= it
.top6
;
520 saved_cpsr
.it1
= it
.bottom2
;
522 // if we have a valid instruction then use it to annotate this fault with
523 // extra information. This is used to generate the correct fault syndrome
525 ArmStaticInst
*arm_inst M5_VAR_USED
= instrAnnotate(inst
);
527 // Ensure Secure state if initially in Monitor mode
528 if (have_security
&& saved_cpsr
.mode
== MODE_MON
) {
529 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
532 tc
->setMiscRegNoEffect(MISCREG_SCR
, scr
);
536 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
539 // some bits are set differently if we have been routed to hyp mode
540 if (cpsr
.mode
== MODE_HYP
) {
541 SCTLR hsctlr
= tc
->readMiscReg(MISCREG_HSCTLR
);
544 if (!scr
.ea
) {cpsr
.a
= 1;}
545 if (!scr
.fiq
) {cpsr
.f
= 1;}
546 if (!scr
.irq
) {cpsr
.i
= 1;}
547 } else if (cpsr
.mode
== MODE_MON
) {
548 // Special case handling when entering monitor mode
558 // The *Disable functions are virtual and different per fault
559 cpsr
.a
= cpsr
.a
| abortDisable(tc
);
560 cpsr
.f
= cpsr
.f
| fiqDisable(tc
);
563 cpsr
.it1
= cpsr
.it2
= 0;
565 cpsr
.pan
= span
? 1 : saved_cpsr
.pan
;
566 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
568 // Make sure mailbox sets to one always
569 tc
->setMiscReg(MISCREG_SEV_MAILBOX
, 1);
571 // Clear the exclusive monitor
572 tc
->setMiscReg(MISCREG_LOCKFLAG
, 0);
574 if (cpsr
.mode
== MODE_HYP
) {
575 tc
->setMiscReg(MISCREG_ELR_HYP
, curPc
+
576 (saved_cpsr
.t
? thumbPcOffset(true) : armPcOffset(true)));
578 tc
->setIntReg(INTREG_LR
, curPc
+
579 (saved_cpsr
.t
? thumbPcOffset(false) : armPcOffset(false)));
584 tc
->setMiscReg(MISCREG_SPSR_FIQ
, saved_cpsr
);
587 tc
->setMiscReg(MISCREG_SPSR_IRQ
, saved_cpsr
);
590 tc
->setMiscReg(MISCREG_SPSR_SVC
, saved_cpsr
);
593 assert(have_security
);
594 tc
->setMiscReg(MISCREG_SPSR_MON
, saved_cpsr
);
597 tc
->setMiscReg(MISCREG_SPSR_ABT
, saved_cpsr
);
600 tc
->setMiscReg(MISCREG_SPSR_UND
, saved_cpsr
);
601 if (ec(tc
) != EC_UNKNOWN
)
602 setSyndrome(tc
, MISCREG_HSR
);
605 assert(ArmSystem::haveVirtualization(tc
));
606 tc
->setMiscReg(MISCREG_SPSR_HYP
, saved_cpsr
);
607 setSyndrome(tc
, MISCREG_HSR
);
610 panic("unknown Mode\n");
613 Addr newPc
= getVector(tc
);
614 DPRINTF(Faults
, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x "
615 "%s\n", name(), cpsr
, curPc
, tc
->readIntReg(INTREG_LR
),
616 newPc
, arm_inst
? csprintf("inst: %#x", arm_inst
->encoding()) :
620 pc
.nextThumb(pc
.thumb());
622 pc
.nextJazelle(pc
.jazelle());
623 pc
.aarch64(!cpsr
.width
);
624 pc
.nextAArch64(!cpsr
.width
);
625 pc
.illegalExec(false);
630 ArmFault::invoke64(ThreadContext
*tc
, const StaticInstPtr
&inst
)
632 // Determine actual misc. register indices for ELR_ELx and SPSR_ELx
633 MiscRegIndex elr_idx
, spsr_idx
;
636 elr_idx
= MISCREG_ELR_EL1
;
637 spsr_idx
= MISCREG_SPSR_EL1
;
640 assert(ArmSystem::haveVirtualization(tc
));
641 elr_idx
= MISCREG_ELR_EL2
;
642 spsr_idx
= MISCREG_SPSR_EL2
;
645 assert(ArmSystem::haveSecurity(tc
));
646 elr_idx
= MISCREG_ELR_EL3
;
647 spsr_idx
= MISCREG_SPSR_EL3
;
650 panic("Invalid target exception level");
654 // Save process state into SPSR_ELx
655 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
657 spsr
.nz
= tc
->readCCReg(CCREG_NZ
);
658 spsr
.c
= tc
->readCCReg(CCREG_C
);
659 spsr
.v
= tc
->readCCReg(CCREG_V
);
660 spsr
.ss
= isResetSPSR() ? 0: cpsr
.ss
;
662 // Force some bitfields to 0
670 spsr
.ge
= tc
->readCCReg(CCREG_GE
);
671 ITSTATE it
= tc
->pcState().itstate();
673 spsr
.it1
= it
.bottom2
;
675 tc
->setMiscReg(spsr_idx
, spsr
);
677 // Save preferred return address into ELR_ELx
678 Addr curr_pc
= tc
->pcState().pc();
679 Addr ret_addr
= curr_pc
;
681 ret_addr
+= armPcElrOffset();
683 ret_addr
+= spsr
.t
? thumbPcElrOffset() : armPcElrOffset();
684 tc
->setMiscReg(elr_idx
, ret_addr
);
686 Addr vec_address
= getVector64(tc
);
688 // Update process state
689 OperatingMode64 mode
= 0;
697 cpsr
.pan
= span
? 1 : spsr
.pan
;
698 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
700 // If we have a valid instruction then use it to annotate this fault with
701 // extra information. This is used to generate the correct fault syndrome
703 ArmStaticInst
*arm_inst M5_VAR_USED
= instrAnnotate(inst
);
705 // Set PC to start of exception handler
706 Addr new_pc
= purifyTaggedAddr(vec_address
, tc
, toEL
, true);
707 DPRINTF(Faults
, "Invoking Fault (AArch64 target EL):%s cpsr:%#x PC:%#x "
708 "elr:%#x newVec: %#x %s\n", name(), cpsr
, curr_pc
, ret_addr
,
709 new_pc
, arm_inst
? csprintf("inst: %#x", arm_inst
->encoding()) :
712 pc
.aarch64(!cpsr
.width
);
713 pc
.nextAArch64(!cpsr
.width
);
714 pc
.illegalExec(false);
718 // Save exception syndrome
719 if ((nextMode() != MODE_IRQ
) && (nextMode() != MODE_FIQ
))
720 setSyndrome(tc
, getSyndromeReg64());
724 ArmFault::vectorCatch(ThreadContext
*tc
, const StaticInstPtr
&inst
)
726 auto *isa
= static_cast<ArmISA::ISA
*>(tc
->getIsaPtr());
727 SelfDebug
* sd
= isa
->getSelfDebug();
728 VectorCatch
* vc
= sd
->getVectorCatch(tc
);
729 if (!vc
->isVCMatch()) {
730 Fault fault
= sd
->testVectorCatch(tc
, 0x0, this);
731 if (fault
!= NoFault
)
732 fault
->invoke(tc
, inst
);
739 ArmFault::instrAnnotate(const StaticInstPtr
&inst
)
742 auto arm_inst
= static_cast<ArmStaticInst
*>(inst
.get());
743 arm_inst
->annotateFault(this);
751 Reset::getVector(ThreadContext
*tc
)
755 // Check for invalid modes
756 CPSR M5_VAR_USED cpsr
= tc
->readMiscRegNoEffect(MISCREG_CPSR
);
757 assert(ArmSystem::haveSecurity(tc
) || cpsr
.mode
!= MODE_MON
);
758 assert(ArmSystem::haveVirtualization(tc
) || cpsr
.mode
!= MODE_HYP
);
760 // RVBAR is aliased (implemented as) MVBAR in gem5, since the two
761 // are mutually exclusive; there is no need to check here for
762 // which register to use since they hold the same value
763 base
= tc
->readMiscReg(MISCREG_MVBAR
);
765 return base
+ offset(tc
);
769 Reset::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
772 tc
->getCpuPtr()->clearInterrupts(tc
->threadId());
775 if (!ArmSystem::highestELIs64(tc
)) {
776 ArmFault::invoke(tc
, inst
);
777 tc
->setMiscReg(MISCREG_VMPIDR
,
778 getMPIDR(dynamic_cast<ArmSystem
*>(tc
->getSystemPtr()), tc
));
780 // Unless we have SMC code to get us there, boot in HYP!
781 if (ArmSystem::haveVirtualization(tc
) &&
782 !ArmSystem::haveSecurity(tc
)) {
783 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
784 cpsr
.mode
= MODE_HYP
;
785 tc
->setMiscReg(MISCREG_CPSR
, cpsr
);
788 // Advance the PC to the IMPLEMENTATION DEFINED reset value
789 PCState pc
= ArmSystem::resetAddr(tc
);
791 pc
.nextAArch64(true);
797 UndefinedInstruction::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
800 ArmFault::invoke(tc
, inst
);
804 // If the mnemonic isn't defined this has to be an unknown instruction.
805 assert(unknown
|| mnemonic
!= NULL
);
806 auto arm_inst
= static_cast<ArmStaticInst
*>(inst
.get());
808 panic("Attempted to execute disabled instruction "
809 "'%s' (inst 0x%08x)", mnemonic
, arm_inst
->encoding());
810 } else if (unknown
) {
811 panic("Attempted to execute unknown instruction (inst 0x%08x)",
812 arm_inst
->encoding());
814 panic("Attempted to execute unimplemented instruction "
815 "'%s' (inst 0x%08x)", mnemonic
, arm_inst
->encoding());
820 UndefinedInstruction::routeToHyp(ThreadContext
*tc
) const
822 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
823 return fromEL
== EL2
||
824 (EL2Enabled(tc
) && (fromEL
== EL0
) && hcr
.tge
);
828 UndefinedInstruction::iss() const
831 // If UndefinedInstruction is routed to hypervisor, iss field is 0.
836 if (overrideEc
== EC_INVALID
)
839 uint32_t new_iss
= 0;
840 uint32_t op0
, op1
, op2
, CRn
, CRm
, Rt
, dir
;
842 dir
= bits(machInst
, 21, 21);
843 op0
= bits(machInst
, 20, 19);
844 op1
= bits(machInst
, 18, 16);
845 CRn
= bits(machInst
, 15, 12);
846 CRm
= bits(machInst
, 11, 8);
847 op2
= bits(machInst
, 7, 5);
848 Rt
= bits(machInst
, 4, 0);
850 new_iss
= op0
<< 20 | op2
<< 17 | op1
<< 14 | CRn
<< 10 |
851 Rt
<< 5 | CRm
<< 1 | dir
;
857 SupervisorCall::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
860 ArmFault::invoke(tc
, inst
);
864 // As of now, there isn't a 32 bit thumb version of this instruction.
865 assert(!machInst
.bigThumb
);
869 // Advance the PC since that won't happen automatically.
870 PCState pc
= tc
->pcState();
877 SupervisorCall::routeToHyp(ThreadContext
*tc
) const
879 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
880 return fromEL
== EL2
||
881 (EL2Enabled(tc
) && fromEL
== EL0
&& hcr
.tge
);
885 SupervisorCall::ec(ThreadContext
*tc
) const
887 return (overrideEc
!= EC_INVALID
) ? overrideEc
:
888 (from64
? EC_SVC_64
: vals
.ec
);
892 SupervisorCall::iss() const
894 // Even if we have a 24 bit imm from an arm32 instruction then we only use
895 // the bottom 16 bits for the ISS value (it doesn't hurt for AArch64 SVC).
896 return issRaw
& 0xFFFF;
900 SecureMonitorCall::iss() const
903 return bits(machInst
, 20, 5);
908 UndefinedInstruction::ec(ThreadContext
*tc
) const
910 // If UndefinedInstruction is routed to hypervisor,
911 // HSR.EC field is 0.
915 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
919 HypervisorCall::HypervisorCall(ExtMachInst _machInst
, uint32_t _imm
) :
920 ArmFaultVals
<HypervisorCall
>(_machInst
, _imm
)
926 HypervisorCall::routeToMonitor(ThreadContext
*tc
) const
928 return from64
&& fromEL
== EL3
;
932 HypervisorCall::routeToHyp(ThreadContext
*tc
) const
934 return !from64
|| fromEL
!= EL3
;
938 HypervisorCall::ec(ThreadContext
*tc
) const
940 return from64
? EC_HVC_64
: vals
.ec
;
944 HypervisorTrap::ec(ThreadContext
*tc
) const
946 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
951 ArmFaultVals
<T
>::offset(ThreadContext
*tc
)
953 bool isHypTrap
= false;
955 // Normally we just use the exception vector from the table at the top if
956 // this file, however if this exception has caused a transition to hype
957 // mode, and its an exception type that would only do this if it has been
958 // trapped then we use the hyp trap vector instead of the normal vector
959 if (vals
.hypTrappable
) {
960 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
961 if (cpsr
.mode
== MODE_HYP
) {
962 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
963 isHypTrap
= spsr
.mode
!= MODE_HYP
;
966 return isHypTrap
? 0x14 : vals
.offset
;
971 ArmFaultVals
<T
>::offset64(ThreadContext
*tc
)
973 if (toEL
== fromEL
) {
974 if (opModeIsT(fromMode
))
975 return vals
.currELTOffset
;
976 return vals
.currELHOffset
;
978 bool lower_32
= false;
980 if (!inSecureState(tc
) && ArmSystem::haveEL(tc
, EL2
))
981 lower_32
= ELIs32(tc
, EL2
);
983 lower_32
= ELIs32(tc
, EL1
);
985 lower_32
= ELIs32(tc
, static_cast<ExceptionLevel
>(toEL
- 1));
989 return vals
.lowerEL32Offset
;
990 return vals
.lowerEL64Offset
;
995 // SupervisorCall::setSyndrome64(ThreadContext *tc, MiscRegIndex esr_idx)
998 // esr.ec = machInst.aarch64 ? SvcAArch64 : SvcAArch32;
999 // esr.il = !machInst.thumb;
1000 // if (machInst.aarch64)
1001 // esr.imm16 = bits(machInst.instBits, 20, 5);
1002 // else if (machInst.thumb)
1003 // esr.imm16 = bits(machInst.instBits, 7, 0);
1005 // esr.imm16 = bits(machInst.instBits, 15, 0);
1006 // tc->setMiscReg(esr_idx, esr);
1010 SecureMonitorCall::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1013 ArmFault::invoke(tc
, inst
);
1019 SecureMonitorCall::ec(ThreadContext
*tc
) const
1021 return (from64
? EC_SMC_64
: vals
.ec
);
1025 SupervisorTrap::routeToHyp(ThreadContext
*tc
) const
1027 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1028 return EL2Enabled(tc
) && currEL(tc
) <= EL1
&& hcr
.tge
;
1032 SupervisorTrap::iss() const
1034 // If SupervisorTrap is routed to hypervisor, iss field is 0.
1042 SupervisorTrap::ec(ThreadContext
*tc
) const
1047 return (overrideEc
!= EC_INVALID
) ? overrideEc
: vals
.ec
;
1051 SecureMonitorTrap::ec(ThreadContext
*tc
) const
1053 return (overrideEc
!= EC_INVALID
) ? overrideEc
:
1054 (from64
? EC_SMC_64
: vals
.ec
);
1059 AbortFault
<T
>::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1061 if (tranMethod
== ArmFault::UnknownTran
) {
1062 tranMethod
= longDescFormatInUse(tc
) ? ArmFault::LpaeTran
1063 : ArmFault::VmsaTran
;
1065 if ((tranMethod
== ArmFault::VmsaTran
) && this->routeToMonitor(tc
)) {
1066 // See ARM ARM B3-1416
1067 bool override_LPAE
= false;
1068 TTBCR ttbcr_s
= tc
->readMiscReg(MISCREG_TTBCR_S
);
1069 TTBCR M5_VAR_USED ttbcr_ns
= tc
->readMiscReg(MISCREG_TTBCR_NS
);
1071 override_LPAE
= true;
1073 // Unimplemented code option, not seen in testing. May need
1074 // extension according to the manual exceprt above.
1075 DPRINTF(Faults
, "Warning: Incomplete translation method "
1076 "override detected.\n");
1079 tranMethod
= ArmFault::LpaeTran
;
1083 if (source
== ArmFault::AsynchronousExternalAbort
) {
1084 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_ABT
, 0);
1086 // Get effective fault source encoding
1087 CPSR cpsr
= tc
->readMiscReg(MISCREG_CPSR
);
1089 // source must be determined BEFORE invoking generic routines which will
1090 // try to set hsr etc. and are based upon source!
1091 ArmFaultVals
<T
>::invoke(tc
, inst
);
1093 if (!this->to64
) { // AArch32
1094 FSR fsr
= getFsr(tc
);
1095 if (cpsr
.mode
== MODE_HYP
) {
1096 tc
->setMiscReg(T::HFarIndex
, faultAddr
);
1097 } else if (stage2
) {
1098 tc
->setMiscReg(MISCREG_HPFAR
, (faultAddr
>> 8) & ~0xf);
1099 tc
->setMiscReg(T::HFarIndex
, OVAddr
);
1100 } else if (debug
> ArmFault::NODEBUG
) {
1101 DBGDS32 Rext
= tc
->readMiscReg(MISCREG_DBGDSCRext
);
1102 tc
->setMiscReg(T::FarIndex
, faultAddr
);
1103 if (debug
== ArmFault::BRKPOINT
){
1105 } else if (debug
== ArmFault::VECTORCATCH
){
1107 } else if (debug
> ArmFault::VECTORCATCH
) {
1109 fsr
.cm
= (debug
== ArmFault::WPOINT_CM
)? 1 : 0;
1112 tc
->setMiscReg(T::FsrIndex
, fsr
);
1113 tc
->setMiscReg(MISCREG_DBGDSCRext
, Rext
);
1116 tc
->setMiscReg(T::FsrIndex
, fsr
);
1117 tc
->setMiscReg(T::FarIndex
, faultAddr
);
1119 DPRINTF(Faults
, "Abort Fault source=%#x fsr=%#x faultAddr=%#x "\
1120 "tranMethod=%#x\n", source
, fsr
, faultAddr
, tranMethod
);
1122 // Set the FAR register. Nothing else to do if we are in AArch64 state
1123 // because the syndrome register has already been set inside invoke64()
1125 // stage 2 fault, set HPFAR_EL2 to the faulting IPA
1126 // and FAR_EL2 to the Original VA
1127 tc
->setMiscReg(AbortFault
<T
>::getFaultAddrReg64(), OVAddr
);
1128 tc
->setMiscReg(MISCREG_HPFAR_EL2
, bits(faultAddr
, 47, 12) << 4);
1130 DPRINTF(Faults
, "Abort Fault (Stage 2) VA: 0x%x IPA: 0x%x\n",
1133 tc
->setMiscReg(AbortFault
<T
>::getFaultAddrReg64(), faultAddr
);
1140 AbortFault
<T
>::setSyndrome(ThreadContext
*tc
, MiscRegIndex syndrome_reg
)
1142 srcEncoded
= getFaultStatusCode(tc
);
1143 if (srcEncoded
== ArmFault::FaultSourceInvalid
) {
1144 panic("Invalid fault source\n");
1146 ArmFault::setSyndrome(tc
, syndrome_reg
);
1151 AbortFault
<T
>::getFaultStatusCode(ThreadContext
*tc
) const
1154 panic_if(!this->faultUpdated
,
1155 "Trying to use un-updated ArmFault internal variables\n");
1161 assert(tranMethod
!= ArmFault::UnknownTran
);
1162 if (tranMethod
== ArmFault::LpaeTran
) {
1163 fsc
= ArmFault::longDescFaultSources
[source
];
1165 fsc
= ArmFault::shortDescFaultSources
[source
];
1169 fsc
= ArmFault::aarch64FaultSources
[source
];
1177 AbortFault
<T
>::getFsr(ThreadContext
*tc
) const
1181 auto fsc
= getFaultStatusCode(tc
);
1184 assert(tranMethod
!= ArmFault::UnknownTran
);
1185 if (tranMethod
== ArmFault::LpaeTran
) {
1189 fsr
.fsLow
= bits(fsc
, 3, 0);
1190 fsr
.fsHigh
= bits(fsc
, 4);
1191 fsr
.domain
= static_cast<uint8_t>(domain
);
1194 fsr
.wnr
= (write
? 1 : 0);
1202 AbortFault
<T
>::abortDisable(ThreadContext
*tc
)
1204 if (ArmSystem::haveSecurity(tc
)) {
1205 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1206 return (!scr
.ns
|| scr
.aw
);
1213 AbortFault
<T
>::annotate(ArmFault::AnnotationIDs id
, uint64_t val
)
1217 case ArmFault::S1PTW
:
1224 // Just ignore unknown ID's
1232 AbortFault
<T
>::iss() const
1236 val
= srcEncoded
& 0x3F;
1244 AbortFault
<T
>::isMMUFault() const
1246 // NOTE: Not relying on LL information being aligned to lowest bits here
1248 (source
== ArmFault::AlignmentFault
) ||
1249 ((source
>= ArmFault::TranslationLL
) &&
1250 (source
< ArmFault::TranslationLL
+ 4)) ||
1251 ((source
>= ArmFault::AccessFlagLL
) &&
1252 (source
< ArmFault::AccessFlagLL
+ 4)) ||
1253 ((source
>= ArmFault::DomainLL
) &&
1254 (source
< ArmFault::DomainLL
+ 4)) ||
1255 ((source
>= ArmFault::PermissionLL
) &&
1256 (source
< ArmFault::PermissionLL
+ 4));
1261 AbortFault
<T
>::getFaultVAddr(Addr
&va
) const
1263 va
= (stage2
? OVAddr
: faultAddr
);
1268 PrefetchAbort::ec(ThreadContext
*tc
) const
1273 return EC_PREFETCH_ABORT_CURR_EL
;
1275 return EC_PREFETCH_ABORT_LOWER_EL
;
1278 // Abort faults have different EC codes depending on whether
1279 // the fault originated within HYP mode, or not. So override
1280 // the method and add the extra adjustment of the EC value.
1282 ExceptionClass ec
= ArmFaultVals
<PrefetchAbort
>::vals
.ec
;
1284 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
1285 if (spsr
.mode
== MODE_HYP
) {
1286 ec
= ((ExceptionClass
) (((uint32_t) ec
) + 1));
1293 PrefetchAbort::routeToMonitor(ThreadContext
*tc
) const
1297 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1299 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1301 return scr
.ea
&& !isMMUFault();
1305 PrefetchAbort::routeToHyp(ThreadContext
*tc
) const
1309 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1310 HDCR hdcr
= tc
->readMiscRegNoEffect(MISCREG_HDCR
);
1312 toHyp
= fromEL
== EL2
;
1313 toHyp
|= ArmSystem::haveEL(tc
, EL2
) && !inSecureState(tc
) &&
1314 currEL(tc
) <= EL1
&& (hcr
.tge
|| stage2
||
1315 (source
== DebugEvent
&& hdcr
.tde
));
1320 DataAbort::ec(ThreadContext
*tc
) const
1324 if (source
== ArmFault::AsynchronousExternalAbort
) {
1325 panic("Asynchronous External Abort should be handled with "
1326 "SystemErrors (SErrors)!");
1329 return EC_DATA_ABORT_CURR_EL
;
1331 return EC_DATA_ABORT_LOWER_EL
;
1334 // Abort faults have different EC codes depending on whether
1335 // the fault originated within HYP mode, or not. So override
1336 // the method and add the extra adjustment of the EC value.
1338 ExceptionClass ec
= ArmFaultVals
<DataAbort
>::vals
.ec
;
1340 CPSR spsr
= tc
->readMiscReg(MISCREG_SPSR_HYP
);
1341 if (spsr
.mode
== MODE_HYP
) {
1342 ec
= ((ExceptionClass
) (((uint32_t) ec
) + 1));
1349 DataAbort::routeToMonitor(ThreadContext
*tc
) const
1353 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1355 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1357 return scr
.ea
&& !isMMUFault();
1361 DataAbort::routeToHyp(ThreadContext
*tc
) const
1365 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1366 HDCR hdcr
= tc
->readMiscRegNoEffect(MISCREG_HDCR
);
1370 amo
= (!HaveVirtHostExt(tc
) || hcr
.e2h
== 0);
1372 // if in Hyp mode then stay in Hyp mode
1373 toHyp
= fromEL
== EL2
||
1374 (EL2Enabled(tc
) && fromEL
<= EL1
1375 && (hcr
.tge
|| stage2
||
1376 ((source
== AsynchronousExternalAbort
) && amo
) ||
1377 ((fromEL
== EL0
) && hcr
.tge
&&
1378 ((source
== AlignmentFault
) ||
1379 (source
== SynchronousExternalAbort
))) ||
1380 ((source
== DebugEvent
) && (hdcr
.tde
|| hcr
.tge
))));
1385 DataAbort::iss() const
1389 // Add on the data abort specific fields to the generic abort ISS value
1390 val
= AbortFault
<DataAbort
>::iss();
1394 // ISS is valid if not caused by a stage 1 page table walk, and when taken
1395 // to AArch64 only when directed to EL2
1396 if (!s1ptw
&& stage2
&& (!to64
|| toEL
== EL2
)) {
1402 // AArch64 only. These assignments are safe on AArch32 as well
1403 // because these vars are initialized to false
1412 DataAbort::annotate(AnnotationIDs id
, uint64_t val
)
1414 AbortFault
<DataAbort
>::annotate(id
, val
);
1443 // Just ignore unknown ID's
1450 VirtualDataAbort::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1452 AbortFault
<VirtualDataAbort
>::invoke(tc
, inst
);
1453 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1455 tc
->setMiscRegNoEffect(MISCREG_HCR
, hcr
);
1459 Interrupt::routeToMonitor(ThreadContext
*tc
) const
1461 assert(ArmSystem::haveSecurity(tc
));
1464 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1466 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1471 Interrupt::routeToHyp(ThreadContext
*tc
) const
1473 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1474 return fromEL
== EL2
||
1475 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| hcr
.imo
));
1479 Interrupt::abortDisable(ThreadContext
*tc
)
1481 if (ArmSystem::haveSecurity(tc
)) {
1482 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1483 return (!scr
.ns
|| scr
.aw
);
1488 VirtualInterrupt::VirtualInterrupt()
1492 FastInterrupt::routeToMonitor(ThreadContext
*tc
) const
1494 assert(ArmSystem::haveSecurity(tc
));
1497 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1499 scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1504 FastInterrupt::routeToHyp(ThreadContext
*tc
) const
1506 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR
);
1507 return fromEL
== EL2
||
1508 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| hcr
.fmo
));
1512 FastInterrupt::abortDisable(ThreadContext
*tc
)
1514 if (ArmSystem::haveSecurity(tc
)) {
1515 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1516 return (!scr
.ns
|| scr
.aw
);
1522 FastInterrupt::fiqDisable(ThreadContext
*tc
)
1524 if (ArmSystem::haveVirtualization(tc
)) {
1526 } else if (ArmSystem::haveSecurity(tc
)) {
1527 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR
);
1528 return (!scr
.ns
|| scr
.fw
);
1533 VirtualFastInterrupt::VirtualFastInterrupt()
1537 PCAlignmentFault::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1539 ArmFaultVals
<PCAlignmentFault
>::invoke(tc
, inst
);
1542 tc
->setMiscReg(getFaultAddrReg64(), faultPC
);
1546 PCAlignmentFault::routeToHyp(ThreadContext
*tc
) const
1548 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1549 return fromEL
== EL2
|| (EL2Enabled(tc
) && fromEL
<= EL1
&& hcr
.tge
);
1552 SPAlignmentFault::SPAlignmentFault()
1556 SPAlignmentFault::routeToHyp(ThreadContext
*tc
) const
1559 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1560 return EL2Enabled(tc
) && currEL(tc
) <= EL1
&& hcr
.tge
== 1;
1563 SystemError::SystemError()
1567 SystemError::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1569 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_ABT
, 0);
1570 ArmFault::invoke(tc
, inst
);
1574 SystemError::routeToMonitor(ThreadContext
*tc
) const
1576 assert(ArmSystem::haveSecurity(tc
));
1578 SCR scr
= tc
->readMiscRegNoEffect(MISCREG_SCR_EL3
);
1579 return scr
.ea
|| fromEL
== EL3
;
1583 SystemError::routeToHyp(ThreadContext
*tc
) const
1587 HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1589 return fromEL
== EL2
||
1590 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| hcr
.amo
));
1594 SoftwareBreakpoint::SoftwareBreakpoint(ExtMachInst _mach_inst
, uint32_t _iss
)
1595 : ArmFaultVals
<SoftwareBreakpoint
>(_mach_inst
, _iss
)
1599 SoftwareBreakpoint::routeToHyp(ThreadContext
*tc
) const
1601 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1602 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1604 return fromEL
== EL2
||
1605 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
));
1609 SoftwareBreakpoint::ec(ThreadContext
*tc
) const
1611 return from64
? EC_SOFTWARE_BREAKPOINT_64
: vals
.ec
;
1614 HardwareBreakpoint::HardwareBreakpoint(Addr _vaddr
, uint32_t _iss
)
1615 : ArmFaultVals
<HardwareBreakpoint
>(0x0, _iss
), vAddr(_vaddr
)
1619 HardwareBreakpoint::routeToHyp(ThreadContext
*tc
) const
1621 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1622 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1624 return EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
);
1628 HardwareBreakpoint::ec(ThreadContext
*tc
) const
1632 return EC_HW_BREAKPOINT_CURR_EL
;
1634 return EC_HW_BREAKPOINT_LOWER_EL
;
1638 HardwareBreakpoint::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1641 ArmFaultVals
<HardwareBreakpoint
>::invoke(tc
, inst
);
1642 MiscRegIndex elr_idx
;
1645 elr_idx
= MISCREG_ELR_EL1
;
1648 assert(ArmSystem::haveVirtualization(tc
));
1649 elr_idx
= MISCREG_ELR_EL2
;
1652 assert(ArmSystem::haveSecurity(tc
));
1653 elr_idx
= MISCREG_ELR_EL3
;
1656 panic("Invalid target exception level");
1660 tc
->setMiscReg(elr_idx
, vAddr
);
1664 Watchpoint::Watchpoint(ExtMachInst _mach_inst
, Addr _vaddr
,
1665 bool _write
, bool _cm
)
1666 : ArmFaultVals
<Watchpoint
>(_mach_inst
), vAddr(_vaddr
),
1667 write(_write
), cm(_cm
)
1671 Watchpoint::iss() const
1673 uint32_t iss
= 0x0022;
1685 Watchpoint::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
)
1687 ArmFaultVals
<Watchpoint
>::invoke(tc
, inst
);
1689 tc
->setMiscReg(getFaultAddrReg64(), vAddr
);
1694 Watchpoint::routeToHyp(ThreadContext
*tc
) const
1696 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1697 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1699 return fromEL
== EL2
||
1700 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
));
1704 Watchpoint::annotate(AnnotationIDs id
, uint64_t val
)
1706 ArmFaultVals
<Watchpoint
>::annotate(id
, val
);
1712 // Just ignore unknown ID's
1719 Watchpoint::ec(ThreadContext
*tc
) const
1723 return EC_WATCHPOINT_CURR_EL
;
1725 return EC_WATCHPOINT_LOWER_EL
;
1728 SoftwareStepFault::SoftwareStepFault(ExtMachInst _mach_inst
, bool is_ldx
,
1730 : ArmFaultVals
<SoftwareStepFault
>(_mach_inst
), isldx(is_ldx
),
1737 SoftwareStepFault::routeToHyp(ThreadContext
*tc
) const
1739 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1740 const HDCR mdcr
= tc
->readMiscRegNoEffect(MISCREG_MDCR_EL2
);
1742 return fromEL
== EL2
||
1743 (EL2Enabled(tc
) && fromEL
<= EL1
&& (hcr
.tge
|| mdcr
.tde
));
1747 SoftwareStepFault::ec(ThreadContext
*tc
) const
1751 return EC_SOFTWARE_STEP_CURR_EL
;
1753 return EC_SOFTWARE_STEP_LOWER_EL
;
1757 SoftwareStepFault::iss() const
1759 uint32_t iss
= 0x0022;
1773 ArmSev::invoke(ThreadContext
*tc
, const StaticInstPtr
&inst
) {
1774 DPRINTF(Faults
, "Invoking ArmSev Fault\n");
1778 // Set sev_mailbox to 1, clear the pending interrupt from remote
1779 // SEV execution and let pipeline continue as pcState is still
1781 tc
->setMiscReg(MISCREG_SEV_MAILBOX
, 1);
1782 tc
->getCpuPtr()->clearInterrupt(tc
->threadId(), INT_SEV
, 0);
1785 // Instantiate all the templates to make the linker happy
1786 template class ArmFaultVals
<Reset
>;
1787 template class ArmFaultVals
<UndefinedInstruction
>;
1788 template class ArmFaultVals
<SupervisorCall
>;
1789 template class ArmFaultVals
<SecureMonitorCall
>;
1790 template class ArmFaultVals
<HypervisorCall
>;
1791 template class ArmFaultVals
<PrefetchAbort
>;
1792 template class ArmFaultVals
<DataAbort
>;
1793 template class ArmFaultVals
<VirtualDataAbort
>;
1794 template class ArmFaultVals
<HypervisorTrap
>;
1795 template class ArmFaultVals
<Interrupt
>;
1796 template class ArmFaultVals
<VirtualInterrupt
>;
1797 template class ArmFaultVals
<FastInterrupt
>;
1798 template class ArmFaultVals
<VirtualFastInterrupt
>;
1799 template class ArmFaultVals
<SupervisorTrap
>;
1800 template class ArmFaultVals
<SecureMonitorTrap
>;
1801 template class ArmFaultVals
<PCAlignmentFault
>;
1802 template class ArmFaultVals
<SPAlignmentFault
>;
1803 template class ArmFaultVals
<SystemError
>;
1804 template class ArmFaultVals
<SoftwareBreakpoint
>;
1805 template class ArmFaultVals
<HardwareBreakpoint
>;
1806 template class ArmFaultVals
<Watchpoint
>;
1807 template class ArmFaultVals
<SoftwareStepFault
>;
1808 template class ArmFaultVals
<ArmSev
>;
1809 template class AbortFault
<PrefetchAbort
>;
1810 template class AbortFault
<DataAbort
>;
1811 template class AbortFault
<VirtualDataAbort
>;
1814 IllegalInstSetStateFault::IllegalInstSetStateFault()
1818 IllegalInstSetStateFault::routeToHyp(ThreadContext
*tc
) const
1820 const HCR hcr
= tc
->readMiscRegNoEffect(MISCREG_HCR_EL2
);
1821 return EL2Enabled(tc
) && fromEL
== EL0
&& hcr
.tge
;
1825 getFaultVAddr(Fault fault
, Addr
&va
)
1827 auto arm_fault
= dynamic_cast<ArmFault
*>(fault
.get());
1830 return arm_fault
->getFaultVAddr(va
);
1832 auto pgt_fault
= dynamic_cast<GenericPageTableFault
*>(fault
.get());
1834 va
= pgt_fault
->getFaultVAddr();
1838 auto align_fault
= dynamic_cast<GenericAlignmentFault
*>(fault
.get());
1840 va
= align_fault
->getFaultVAddr();
1844 // Return false since it's not an address triggered exception
1849 } // namespace ArmISA