2 * Copyright (c) 2010, 2012-2013, 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 #ifndef __ARM_FAULTS_HH__
48 #define __ARM_FAULTS_HH__
50 #include "arch/arm/miscregs.hh"
51 #include "arch/arm/pagetable.hh"
52 #include "arch/arm/types.hh"
53 #include "base/logging.hh"
54 #include "sim/faults.hh"
55 #include "sim/full_system.hh"
57 // The design of the "name" and "vect" functions is in sim/faults.hh
61 typedef Addr FaultOffset;
63 class ArmFault : public FaultBase
69 // Helper variables for ARMv8 exception handling
70 bool from64; // True if the exception is generated from the AArch64 state
71 bool to64; // True if the exception is taken in AArch64 state
72 ExceptionLevel fromEL; // Source exception level
73 ExceptionLevel toEL; // Target exception level
74 OperatingMode fromMode; // Source operating mode (aarch32)
75 OperatingMode toMode; // Next operating mode (aarch32)
77 // This variable is true if the above fault specific informations
78 // have been updated. This is to prevent that a client is using their
79 // un-updated default constructed value.
82 bool hypRouted; // True if the fault has been routed to Hypervisor
84 virtual Addr getVector(ThreadContext *tc);
85 Addr getVector64(ThreadContext *tc);
88 /// Generic fault source enums used to index into
89 /// {short/long/aarch64}DescFaultSources[] to get the actual encodings based
90 /// on the current register width state and the translation table format in
95 InstructionCacheMaintenance, // Short-desc. format only
96 SynchExtAbtOnTranslTableWalkLL,
97 SynchPtyErrOnTranslTableWalkLL = SynchExtAbtOnTranslTableWalkLL + 4,
98 TranslationLL = SynchPtyErrOnTranslTableWalkLL + 4,
99 AccessFlagLL = TranslationLL + 4,
100 DomainLL = AccessFlagLL + 4,
101 PermissionLL = DomainLL + 4,
102 DebugEvent = PermissionLL + 4,
103 SynchronousExternalAbort,
104 TLBConflictAbort, // Requires LPAE
105 SynchPtyErrOnMemoryAccess,
106 AsynchronousExternalAbort,
107 AsynchPtyErrOnMemoryAccess,
108 AddressSizeLL, // AArch64 only
110 // Not real faults. These are faults to allow the translation function
111 // to inform the memory access function not to proceed for a prefetch
112 // that misses in the TLB or that targets an uncacheable address
113 PrefetchTLBMiss = AddressSizeLL + 4,
117 FaultSourceInvalid = 0xff
120 /// Encodings of the fault sources when the short-desc. translation table
121 /// format is in use (ARM ARM Issue C B3.13.3)
122 static uint8_t shortDescFaultSources[NumFaultSources];
123 /// Encodings of the fault sources when the long-desc. translation table
124 /// format is in use (ARM ARM Issue C B3.13.3)
125 static uint8_t longDescFaultSources[NumFaultSources];
126 /// Encodings of the fault sources in AArch64 state
127 static uint8_t aarch64FaultSources[NumFaultSources];
131 S1PTW, // DataAbort, PrefetchAbort: Stage 1 Page Table Walk,
132 OVA, // DataAbort, PrefetchAbort: stage 1 Virtual Address for stage 2 faults
133 SAS, // DataAbort: Syndrome Access Size
134 SSE, // DataAbort: Syndrome Sign Extend
135 SRT, // DataAbort: Syndrome Register Transfer
138 SF, // DataAbort: width of the accessed register is SixtyFour
139 AR // DataAbort: Acquire/Release semantics
151 const FaultName name;
153 const FaultOffset offset;
155 // Offsets used for exceptions taken in AArch64 state
156 const uint16_t currELTOffset;
157 const uint16_t currELHOffset;
158 const uint16_t lowerEL64Offset;
159 const uint16_t lowerEL32Offset;
161 const OperatingMode nextMode;
163 const uint8_t armPcOffset;
164 const uint8_t thumbPcOffset;
165 // The following two values are used in place of armPcOffset and
166 // thumbPcOffset when the exception return address is saved into ELR
167 // registers (exceptions taken in HYP mode or in AArch64 state)
168 const uint8_t armPcElrOffset;
169 const uint8_t thumbPcElrOffset;
171 const bool hypTrappable;
172 const bool abortDisable;
173 const bool fiqDisable;
175 // Exception class used to appropriately set the syndrome register
176 // (exceptions taken in HYP mode or in AArch64 state)
177 const ExceptionClass ec;
180 FaultVals(const FaultName& name_, const FaultOffset& offset_,
181 const uint16_t& currELTOffset_, const uint16_t& currELHOffset_,
182 const uint16_t& lowerEL64Offset_,
183 const uint16_t& lowerEL32Offset_,
184 const OperatingMode& nextMode_, const uint8_t& armPcOffset_,
185 const uint8_t& thumbPcOffset_, const uint8_t& armPcElrOffset_,
186 const uint8_t& thumbPcElrOffset_, const bool& hypTrappable_,
187 const bool& abortDisable_, const bool& fiqDisable_,
188 const ExceptionClass& ec_)
189 : name(name_), offset(offset_), currELTOffset(currELTOffset_),
190 currELHOffset(currELHOffset_), lowerEL64Offset(lowerEL64Offset_),
191 lowerEL32Offset(lowerEL32Offset_), nextMode(nextMode_),
192 armPcOffset(armPcOffset_), thumbPcOffset(thumbPcOffset_),
193 armPcElrOffset(armPcElrOffset_), thumbPcElrOffset(thumbPcElrOffset_),
194 hypTrappable(hypTrappable_), abortDisable(abortDisable_),
195 fiqDisable(fiqDisable_), ec(ec_) {}
198 ArmFault(ExtMachInst _machInst = 0, uint32_t _iss = 0) :
199 machInst(_machInst), issRaw(_iss), from64(false), to64(false),
200 fromEL(EL0), toEL(EL0), fromMode(MODE_UNDEFINED),
201 faultUpdated(false), hypRouted(false) {}
203 // Returns the actual syndrome register to use based on the target
205 MiscRegIndex getSyndromeReg64() const;
206 // Returns the actual fault address register to use based on the target
208 MiscRegIndex getFaultAddrReg64() const;
210 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
211 StaticInst::nullStaticInstPtr) override;
212 void invoke64(ThreadContext *tc, const StaticInstPtr &inst =
213 StaticInst::nullStaticInstPtr);
214 void update(ThreadContext *tc);
215 virtual void annotate(AnnotationIDs id, uint64_t val) {}
216 virtual FaultStat& countStat() = 0;
217 virtual FaultOffset offset(ThreadContext *tc) = 0;
218 virtual FaultOffset offset64(ThreadContext *tc) = 0;
219 virtual OperatingMode nextMode() = 0;
220 virtual bool routeToMonitor(ThreadContext *tc) const = 0;
221 virtual bool routeToHyp(ThreadContext *tc) const { return false; }
222 virtual uint8_t armPcOffset(bool isHyp) = 0;
223 virtual uint8_t thumbPcOffset(bool isHyp) = 0;
224 virtual uint8_t armPcElrOffset() = 0;
225 virtual uint8_t thumbPcElrOffset() = 0;
226 virtual bool abortDisable(ThreadContext *tc) = 0;
227 virtual bool fiqDisable(ThreadContext *tc) = 0;
228 virtual ExceptionClass ec(ThreadContext *tc) const = 0;
229 virtual uint32_t iss() const = 0;
230 virtual bool isStage2() const { return false; }
231 virtual FSR getFsr(ThreadContext *tc) const { return 0; }
232 virtual void setSyndrome(ThreadContext *tc, MiscRegIndex syndrome_reg);
236 class ArmFaultVals : public ArmFault
239 static FaultVals vals;
242 ArmFaultVals<T>(ExtMachInst _machInst = 0, uint32_t _iss = 0) :
243 ArmFault(_machInst, _iss) {}
244 FaultName name() const override { return vals.name; }
245 FaultStat & countStat() override { return vals.count; }
246 FaultOffset offset(ThreadContext *tc) override;
248 FaultOffset offset64(ThreadContext *tc) override;
250 OperatingMode nextMode() override { return vals.nextMode; }
251 virtual bool routeToMonitor(ThreadContext *tc) const override {
254 uint8_t armPcOffset(bool isHyp) override {
255 return isHyp ? vals.armPcElrOffset
258 uint8_t thumbPcOffset(bool isHyp) override {
259 return isHyp ? vals.thumbPcElrOffset
260 : vals.thumbPcOffset;
262 uint8_t armPcElrOffset() override { return vals.armPcElrOffset; }
263 uint8_t thumbPcElrOffset() override { return vals.thumbPcElrOffset; }
264 bool abortDisable(ThreadContext* tc) override { return vals.abortDisable; }
265 bool fiqDisable(ThreadContext* tc) override { return vals.fiqDisable; }
266 ExceptionClass ec(ThreadContext *tc) const override { return vals.ec; }
267 uint32_t iss() const override { return issRaw; }
270 class Reset : public ArmFaultVals<Reset>
273 Addr getVector(ThreadContext *tc) override;
276 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
277 StaticInst::nullStaticInstPtr) override;
280 class UndefinedInstruction : public ArmFaultVals<UndefinedInstruction>
285 ExceptionClass overrideEc;
286 const char *mnemonic;
289 UndefinedInstruction(ExtMachInst _machInst,
291 const char *_mnemonic = NULL,
292 bool _disabled = false) :
293 ArmFaultVals<UndefinedInstruction>(_machInst),
294 unknown(_unknown), disabled(_disabled),
295 overrideEc(EC_INVALID), mnemonic(_mnemonic)
297 UndefinedInstruction(ExtMachInst _machInst, uint32_t _iss,
298 ExceptionClass _overrideEc, const char *_mnemonic = NULL) :
299 ArmFaultVals<UndefinedInstruction>(_machInst, _iss),
300 unknown(false), disabled(true), overrideEc(_overrideEc),
304 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
305 StaticInst::nullStaticInstPtr) override;
306 bool routeToHyp(ThreadContext *tc) const override;
307 ExceptionClass ec(ThreadContext *tc) const override;
308 uint32_t iss() const override;
311 class SupervisorCall : public ArmFaultVals<SupervisorCall>
314 ExceptionClass overrideEc;
316 SupervisorCall(ExtMachInst _machInst, uint32_t _iss,
317 ExceptionClass _overrideEc = EC_INVALID) :
318 ArmFaultVals<SupervisorCall>(_machInst, _iss),
319 overrideEc(_overrideEc)
322 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
323 StaticInst::nullStaticInstPtr) override;
324 bool routeToHyp(ThreadContext *tc) const override;
325 ExceptionClass ec(ThreadContext *tc) const override;
326 uint32_t iss() const override;
329 class SecureMonitorCall : public ArmFaultVals<SecureMonitorCall>
332 SecureMonitorCall(ExtMachInst _machInst) :
333 ArmFaultVals<SecureMonitorCall>(_machInst)
336 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
337 StaticInst::nullStaticInstPtr) override;
338 ExceptionClass ec(ThreadContext *tc) const override;
339 uint32_t iss() const override;
342 class SupervisorTrap : public ArmFaultVals<SupervisorTrap>
345 ExtMachInst machInst;
346 ExceptionClass overrideEc;
349 SupervisorTrap(ExtMachInst _machInst, uint32_t _iss,
350 ExceptionClass _overrideEc = EC_INVALID) :
351 ArmFaultVals<SupervisorTrap>(_machInst, _iss),
352 overrideEc(_overrideEc)
355 bool routeToHyp(ThreadContext *tc) const override;
356 uint32_t iss() const override;
357 ExceptionClass ec(ThreadContext *tc) const override;
360 class SecureMonitorTrap : public ArmFaultVals<SecureMonitorTrap>
363 ExtMachInst machInst;
364 ExceptionClass overrideEc;
367 SecureMonitorTrap(ExtMachInst _machInst, uint32_t _iss,
368 ExceptionClass _overrideEc = EC_INVALID) :
369 ArmFaultVals<SecureMonitorTrap>(_machInst, _iss),
370 overrideEc(_overrideEc)
373 ExceptionClass ec(ThreadContext *tc) const override;
376 class HypervisorCall : public ArmFaultVals<HypervisorCall>
379 HypervisorCall(ExtMachInst _machInst, uint32_t _imm);
381 ExceptionClass ec(ThreadContext *tc) const override;
384 class HypervisorTrap : public ArmFaultVals<HypervisorTrap>
387 ExtMachInst machInst;
388 ExceptionClass overrideEc;
391 HypervisorTrap(ExtMachInst _machInst, uint32_t _iss,
392 ExceptionClass _overrideEc = EC_INVALID) :
393 ArmFaultVals<HypervisorTrap>(_machInst, _iss),
394 overrideEc(_overrideEc)
397 ExceptionClass ec(ThreadContext *tc) const override;
401 class AbortFault : public ArmFaultVals<T>
405 * The virtual address the fault occured at. If 2 stages of
406 * translation are being used then this is the intermediate
407 * physical address that is the starting point for the second
408 * stage of translation.
412 * Original virtual address. If the fault was generated on the
413 * second stage of translation then this variable stores the
414 * virtual address used in the original stage 1 translation.
418 TlbEntry::DomainType domain;
423 ArmFault::TranMethod tranMethod;
426 AbortFault(Addr _faultAddr, bool _write, TlbEntry::DomainType _domain,
427 uint8_t _source, bool _stage2,
428 ArmFault::TranMethod _tranMethod = ArmFault::UnknownTran) :
429 faultAddr(_faultAddr), OVAddr(0), write(_write),
430 domain(_domain), source(_source), srcEncoded(0),
431 stage2(_stage2), s1ptw(false), tranMethod(_tranMethod)
434 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
435 StaticInst::nullStaticInstPtr) override;
437 FSR getFsr(ThreadContext *tc) const override;
438 uint8_t getFaultStatusCode(ThreadContext *tc) const;
439 bool abortDisable(ThreadContext *tc) override;
440 uint32_t iss() const override;
441 bool isStage2() const override { return stage2; }
442 void annotate(ArmFault::AnnotationIDs id, uint64_t val) override;
443 void setSyndrome(ThreadContext *tc, MiscRegIndex syndrome_reg) override;
444 bool isMMUFault() const;
447 class PrefetchAbort : public AbortFault<PrefetchAbort>
450 static const MiscRegIndex FsrIndex = MISCREG_IFSR;
451 static const MiscRegIndex FarIndex = MISCREG_IFAR;
452 static const MiscRegIndex HFarIndex = MISCREG_HIFAR;
454 PrefetchAbort(Addr _addr, uint8_t _source, bool _stage2 = false,
455 ArmFault::TranMethod _tranMethod = ArmFault::UnknownTran) :
456 AbortFault<PrefetchAbort>(_addr, false, TlbEntry::DomainType::NoAccess,
457 _source, _stage2, _tranMethod)
460 ExceptionClass ec(ThreadContext *tc) const override;
461 // @todo: external aborts should be routed if SCR.EA == 1
462 bool routeToMonitor(ThreadContext *tc) const override;
463 bool routeToHyp(ThreadContext *tc) const override;
466 class DataAbort : public AbortFault<DataAbort>
469 static const MiscRegIndex FsrIndex = MISCREG_DFSR;
470 static const MiscRegIndex FarIndex = MISCREG_DFAR;
471 static const MiscRegIndex HFarIndex = MISCREG_HDFAR;
481 DataAbort(Addr _addr, TlbEntry::DomainType _domain, bool _write, uint8_t _source,
482 bool _stage2 = false, ArmFault::TranMethod _tranMethod = ArmFault::UnknownTran) :
483 AbortFault<DataAbort>(_addr, _write, _domain, _source, _stage2,
485 isv(false), sas (0), sse(0), srt(0), sf(false), ar(false)
488 ExceptionClass ec(ThreadContext *tc) const override;
489 // @todo: external aborts should be routed if SCR.EA == 1
490 bool routeToMonitor(ThreadContext *tc) const override;
491 bool routeToHyp(ThreadContext *tc) const override;
492 uint32_t iss() const override;
493 void annotate(AnnotationIDs id, uint64_t val) override;
496 class VirtualDataAbort : public AbortFault<VirtualDataAbort>
499 static const MiscRegIndex FsrIndex = MISCREG_DFSR;
500 static const MiscRegIndex FarIndex = MISCREG_DFAR;
501 static const MiscRegIndex HFarIndex = MISCREG_HDFAR;
503 VirtualDataAbort(Addr _addr, TlbEntry::DomainType _domain, bool _write,
505 AbortFault<VirtualDataAbort>(_addr, _write, _domain, _source, false)
508 void invoke(ThreadContext *tc, const StaticInstPtr &inst) override;
511 class Interrupt : public ArmFaultVals<Interrupt>
514 bool routeToMonitor(ThreadContext *tc) const override;
515 bool routeToHyp(ThreadContext *tc) const override;
516 bool abortDisable(ThreadContext *tc) override;
519 class VirtualInterrupt : public ArmFaultVals<VirtualInterrupt>
525 class FastInterrupt : public ArmFaultVals<FastInterrupt>
528 bool routeToMonitor(ThreadContext *tc) const override;
529 bool routeToHyp(ThreadContext *tc) const override;
530 bool abortDisable(ThreadContext *tc) override;
531 bool fiqDisable(ThreadContext *tc) override;
534 class VirtualFastInterrupt : public ArmFaultVals<VirtualFastInterrupt>
537 VirtualFastInterrupt();
540 /// PC alignment fault (AArch64 only)
541 class PCAlignmentFault : public ArmFaultVals<PCAlignmentFault>
544 /// The unaligned value of the PC
547 PCAlignmentFault(Addr _faultPC) : faultPC(_faultPC)
549 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
550 StaticInst::nullStaticInstPtr) override;
551 bool routeToHyp(ThreadContext *tc) const override;
554 /// Stack pointer alignment fault (AArch64 only)
555 class SPAlignmentFault : public ArmFaultVals<SPAlignmentFault>
561 /// System error (AArch64 only)
562 class SystemError : public ArmFaultVals<SystemError>
566 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
567 StaticInst::nullStaticInstPtr) override;
568 bool routeToMonitor(ThreadContext *tc) const override;
569 bool routeToHyp(ThreadContext *tc) const override;
572 /// System error (AArch64 only)
573 class SoftwareBreakpoint : public ArmFaultVals<SoftwareBreakpoint>
576 SoftwareBreakpoint(ExtMachInst _mach_inst, uint32_t _iss);
578 bool routeToHyp(ThreadContext *tc) const override;
579 ExceptionClass ec(ThreadContext *tc) const override;
582 // A fault that flushes the pipe, excluding the faulting instructions
583 class ArmSev : public ArmFaultVals<ArmSev>
587 void invoke(ThreadContext *tc, const StaticInstPtr &inst =
588 StaticInst::nullStaticInstPtr) override;
591 /// Illegal Instruction Set State fault (AArch64 only)
592 class IllegalInstSetStateFault : public ArmFaultVals<IllegalInstSetStateFault>
595 IllegalInstSetStateFault();
599 * Explicitly declare template static member variables to avoid warnings
600 * in some clang versions
602 template<> ArmFault::FaultVals ArmFaultVals<Reset>::vals;
603 template<> ArmFault::FaultVals ArmFaultVals<UndefinedInstruction>::vals;
604 template<> ArmFault::FaultVals ArmFaultVals<SupervisorCall>::vals;
605 template<> ArmFault::FaultVals ArmFaultVals<SecureMonitorCall>::vals;
606 template<> ArmFault::FaultVals ArmFaultVals<HypervisorCall>::vals;
607 template<> ArmFault::FaultVals ArmFaultVals<PrefetchAbort>::vals;
608 template<> ArmFault::FaultVals ArmFaultVals<DataAbort>::vals;
609 template<> ArmFault::FaultVals ArmFaultVals<VirtualDataAbort>::vals;
610 template<> ArmFault::FaultVals ArmFaultVals<HypervisorTrap>::vals;
611 template<> ArmFault::FaultVals ArmFaultVals<Interrupt>::vals;
612 template<> ArmFault::FaultVals ArmFaultVals<VirtualInterrupt>::vals;
613 template<> ArmFault::FaultVals ArmFaultVals<FastInterrupt>::vals;
614 template<> ArmFault::FaultVals ArmFaultVals<VirtualFastInterrupt>::vals;
615 template<> ArmFault::FaultVals ArmFaultVals<SupervisorTrap>::vals;
616 template<> ArmFault::FaultVals ArmFaultVals<SecureMonitorTrap>::vals;
617 template<> ArmFault::FaultVals ArmFaultVals<PCAlignmentFault>::vals;
618 template<> ArmFault::FaultVals ArmFaultVals<SPAlignmentFault>::vals;
619 template<> ArmFault::FaultVals ArmFaultVals<SystemError>::vals;
620 template<> ArmFault::FaultVals ArmFaultVals<SoftwareBreakpoint>::vals;
621 template<> ArmFault::FaultVals ArmFaultVals<ArmSev>::vals;
624 } // namespace ArmISA
626 #endif // __ARM_FAULTS_HH__