faults.cc revision 12259
16019Shines@cs.fsu.edu/*
212259Sgiacomo.travaglini@arm.com * Copyright (c) 2010, 2012-2014, 2016-2017 ARM Limited
37093Sgblack@eecs.umich.edu * All rights reserved
47093Sgblack@eecs.umich.edu *
57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97093Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137093Sgblack@eecs.umich.edu *
146019Shines@cs.fsu.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
156019Shines@cs.fsu.edu * Copyright (c) 2007-2008 The Florida State University
166019Shines@cs.fsu.edu * All rights reserved.
176019Shines@cs.fsu.edu *
186019Shines@cs.fsu.edu * Redistribution and use in source and binary forms, with or without
196019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
206019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
216019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
226019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
236019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
246019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
256019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
266019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
276019Shines@cs.fsu.edu * this software without specific prior written permission.
286019Shines@cs.fsu.edu *
296019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
306019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
326019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
346019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
366019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
386019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406019Shines@cs.fsu.edu *
416735Sgblack@eecs.umich.edu * Authors: Ali Saidi
426735Sgblack@eecs.umich.edu *          Gabe Black
4310037SARM gem5 Developers *          Giacomo Gabrielli
4410037SARM gem5 Developers *          Thomas Grocutt
456019Shines@cs.fsu.edu */
466019Shines@cs.fsu.edu
476019Shines@cs.fsu.edu#include "arch/arm/faults.hh"
4811793Sbrandon.potter@amd.com
4911793Sbrandon.potter@amd.com#include "arch/arm/insts/static_inst.hh"
5010037SARM gem5 Developers#include "arch/arm/system.hh"
5110037SARM gem5 Developers#include "arch/arm/utility.hh"
5210037SARM gem5 Developers#include "base/compiler.hh"
538229Snate@binkert.org#include "base/trace.hh"
548229Snate@binkert.org#include "cpu/base.hh"
556019Shines@cs.fsu.edu#include "cpu/thread_context.hh"
568232Snate@binkert.org#include "debug/Faults.hh"
578782Sgblack@eecs.umich.edu#include "sim/full_system.hh"
586019Shines@cs.fsu.edu
596019Shines@cs.fsu.edunamespace ArmISA
606019Shines@cs.fsu.edu{
616019Shines@cs.fsu.edu
6210037SARM gem5 Developersuint8_t ArmFault::shortDescFaultSources[] = {
6310037SARM gem5 Developers    0x01,  // AlignmentFault
6410037SARM gem5 Developers    0x04,  // InstructionCacheMaintenance
6510037SARM gem5 Developers    0xff,  // SynchExtAbtOnTranslTableWalkL0 (INVALID)
6610037SARM gem5 Developers    0x0c,  // SynchExtAbtOnTranslTableWalkL1
6710037SARM gem5 Developers    0x0e,  // SynchExtAbtOnTranslTableWalkL2
6810037SARM gem5 Developers    0xff,  // SynchExtAbtOnTranslTableWalkL3 (INVALID)
6910037SARM gem5 Developers    0xff,  // SynchPtyErrOnTranslTableWalkL0 (INVALID)
7010037SARM gem5 Developers    0x1c,  // SynchPtyErrOnTranslTableWalkL1
7110037SARM gem5 Developers    0x1e,  // SynchPtyErrOnTranslTableWalkL2
7210037SARM gem5 Developers    0xff,  // SynchPtyErrOnTranslTableWalkL3 (INVALID)
7310037SARM gem5 Developers    0xff,  // TranslationL0 (INVALID)
7410037SARM gem5 Developers    0x05,  // TranslationL1
7510037SARM gem5 Developers    0x07,  // TranslationL2
7610037SARM gem5 Developers    0xff,  // TranslationL3 (INVALID)
7710037SARM gem5 Developers    0xff,  // AccessFlagL0 (INVALID)
7810037SARM gem5 Developers    0x03,  // AccessFlagL1
7910037SARM gem5 Developers    0x06,  // AccessFlagL2
8010037SARM gem5 Developers    0xff,  // AccessFlagL3 (INVALID)
8110037SARM gem5 Developers    0xff,  // DomainL0 (INVALID)
8210037SARM gem5 Developers    0x09,  // DomainL1
8310037SARM gem5 Developers    0x0b,  // DomainL2
8410037SARM gem5 Developers    0xff,  // DomainL3 (INVALID)
8510037SARM gem5 Developers    0xff,  // PermissionL0 (INVALID)
8610037SARM gem5 Developers    0x0d,  // PermissionL1
8710037SARM gem5 Developers    0x0f,  // PermissionL2
8810037SARM gem5 Developers    0xff,  // PermissionL3 (INVALID)
8910037SARM gem5 Developers    0x02,  // DebugEvent
9010037SARM gem5 Developers    0x08,  // SynchronousExternalAbort
9110037SARM gem5 Developers    0x10,  // TLBConflictAbort
9210037SARM gem5 Developers    0x19,  // SynchPtyErrOnMemoryAccess
9310037SARM gem5 Developers    0x16,  // AsynchronousExternalAbort
9410037SARM gem5 Developers    0x18,  // AsynchPtyErrOnMemoryAccess
9510037SARM gem5 Developers    0xff,  // AddressSizeL0 (INVALID)
9610037SARM gem5 Developers    0xff,  // AddressSizeL1 (INVALID)
9710037SARM gem5 Developers    0xff,  // AddressSizeL2 (INVALID)
9810037SARM gem5 Developers    0xff,  // AddressSizeL3 (INVALID)
9910037SARM gem5 Developers    0x40,  // PrefetchTLBMiss
10010037SARM gem5 Developers    0x80   // PrefetchUncacheable
10110037SARM gem5 Developers};
1026019Shines@cs.fsu.edu
10310037SARM gem5 Developersstatic_assert(sizeof(ArmFault::shortDescFaultSources) ==
10410037SARM gem5 Developers              ArmFault::NumFaultSources,
10510037SARM gem5 Developers              "Invalid size of ArmFault::shortDescFaultSources[]");
1066019Shines@cs.fsu.edu
10710037SARM gem5 Developersuint8_t ArmFault::longDescFaultSources[] = {
10810037SARM gem5 Developers    0x21,  // AlignmentFault
10910037SARM gem5 Developers    0xff,  // InstructionCacheMaintenance (INVALID)
11010037SARM gem5 Developers    0xff,  // SynchExtAbtOnTranslTableWalkL0 (INVALID)
11110037SARM gem5 Developers    0x15,  // SynchExtAbtOnTranslTableWalkL1
11210037SARM gem5 Developers    0x16,  // SynchExtAbtOnTranslTableWalkL2
11310037SARM gem5 Developers    0x17,  // SynchExtAbtOnTranslTableWalkL3
11410037SARM gem5 Developers    0xff,  // SynchPtyErrOnTranslTableWalkL0 (INVALID)
11510037SARM gem5 Developers    0x1d,  // SynchPtyErrOnTranslTableWalkL1
11610037SARM gem5 Developers    0x1e,  // SynchPtyErrOnTranslTableWalkL2
11710037SARM gem5 Developers    0x1f,  // SynchPtyErrOnTranslTableWalkL3
11810037SARM gem5 Developers    0xff,  // TranslationL0 (INVALID)
11910037SARM gem5 Developers    0x05,  // TranslationL1
12010037SARM gem5 Developers    0x06,  // TranslationL2
12110037SARM gem5 Developers    0x07,  // TranslationL3
12210037SARM gem5 Developers    0xff,  // AccessFlagL0 (INVALID)
12310037SARM gem5 Developers    0x09,  // AccessFlagL1
12410037SARM gem5 Developers    0x0a,  // AccessFlagL2
12510037SARM gem5 Developers    0x0b,  // AccessFlagL3
12610037SARM gem5 Developers    0xff,  // DomainL0 (INVALID)
12710037SARM gem5 Developers    0x3d,  // DomainL1
12810037SARM gem5 Developers    0x3e,  // DomainL2
12910037SARM gem5 Developers    0xff,  // DomainL3 (RESERVED)
13010037SARM gem5 Developers    0xff,  // PermissionL0 (INVALID)
13110037SARM gem5 Developers    0x0d,  // PermissionL1
13210037SARM gem5 Developers    0x0e,  // PermissionL2
13310037SARM gem5 Developers    0x0f,  // PermissionL3
13410037SARM gem5 Developers    0x22,  // DebugEvent
13510037SARM gem5 Developers    0x10,  // SynchronousExternalAbort
13610037SARM gem5 Developers    0x30,  // TLBConflictAbort
13710037SARM gem5 Developers    0x18,  // SynchPtyErrOnMemoryAccess
13810037SARM gem5 Developers    0x11,  // AsynchronousExternalAbort
13910037SARM gem5 Developers    0x19,  // AsynchPtyErrOnMemoryAccess
14010037SARM gem5 Developers    0xff,  // AddressSizeL0 (INVALID)
14110037SARM gem5 Developers    0xff,  // AddressSizeL1 (INVALID)
14210037SARM gem5 Developers    0xff,  // AddressSizeL2 (INVALID)
14310037SARM gem5 Developers    0xff,  // AddressSizeL3 (INVALID)
14410037SARM gem5 Developers    0x40,  // PrefetchTLBMiss
14510037SARM gem5 Developers    0x80   // PrefetchUncacheable
14610037SARM gem5 Developers};
1476019Shines@cs.fsu.edu
14810037SARM gem5 Developersstatic_assert(sizeof(ArmFault::longDescFaultSources) ==
14910037SARM gem5 Developers              ArmFault::NumFaultSources,
15010037SARM gem5 Developers              "Invalid size of ArmFault::longDescFaultSources[]");
1516019Shines@cs.fsu.edu
15210037SARM gem5 Developersuint8_t ArmFault::aarch64FaultSources[] = {
15310037SARM gem5 Developers    0x21,  // AlignmentFault
15410037SARM gem5 Developers    0xff,  // InstructionCacheMaintenance (INVALID)
15510037SARM gem5 Developers    0x14,  // SynchExtAbtOnTranslTableWalkL0
15610037SARM gem5 Developers    0x15,  // SynchExtAbtOnTranslTableWalkL1
15710037SARM gem5 Developers    0x16,  // SynchExtAbtOnTranslTableWalkL2
15810037SARM gem5 Developers    0x17,  // SynchExtAbtOnTranslTableWalkL3
15910037SARM gem5 Developers    0x1c,  // SynchPtyErrOnTranslTableWalkL0
16010037SARM gem5 Developers    0x1d,  // SynchPtyErrOnTranslTableWalkL1
16110037SARM gem5 Developers    0x1e,  // SynchPtyErrOnTranslTableWalkL2
16210037SARM gem5 Developers    0x1f,  // SynchPtyErrOnTranslTableWalkL3
16310037SARM gem5 Developers    0x04,  // TranslationL0
16410037SARM gem5 Developers    0x05,  // TranslationL1
16510037SARM gem5 Developers    0x06,  // TranslationL2
16610037SARM gem5 Developers    0x07,  // TranslationL3
16710037SARM gem5 Developers    0x08,  // AccessFlagL0
16810037SARM gem5 Developers    0x09,  // AccessFlagL1
16910037SARM gem5 Developers    0x0a,  // AccessFlagL2
17010037SARM gem5 Developers    0x0b,  // AccessFlagL3
17110037SARM gem5 Developers    // @todo: Section & Page Domain Fault in AArch64?
17210037SARM gem5 Developers    0xff,  // DomainL0 (INVALID)
17310037SARM gem5 Developers    0xff,  // DomainL1 (INVALID)
17410037SARM gem5 Developers    0xff,  // DomainL2 (INVALID)
17510037SARM gem5 Developers    0xff,  // DomainL3 (INVALID)
17610037SARM gem5 Developers    0x0c,  // PermissionL0
17710037SARM gem5 Developers    0x0d,  // PermissionL1
17810037SARM gem5 Developers    0x0e,  // PermissionL2
17910037SARM gem5 Developers    0x0f,  // PermissionL3
18010037SARM gem5 Developers    0xff,  // DebugEvent (INVALID)
18110037SARM gem5 Developers    0x10,  // SynchronousExternalAbort
18210037SARM gem5 Developers    0x30,  // TLBConflictAbort
18310037SARM gem5 Developers    0x18,  // SynchPtyErrOnMemoryAccess
18410037SARM gem5 Developers    0xff,  // AsynchronousExternalAbort (INVALID)
18510037SARM gem5 Developers    0xff,  // AsynchPtyErrOnMemoryAccess (INVALID)
18610037SARM gem5 Developers    0x00,  // AddressSizeL0
18710037SARM gem5 Developers    0x01,  // AddressSizeL1
18810037SARM gem5 Developers    0x02,  // AddressSizeL2
18910037SARM gem5 Developers    0x03,  // AddressSizeL3
19010037SARM gem5 Developers    0x40,  // PrefetchTLBMiss
19110037SARM gem5 Developers    0x80   // PrefetchUncacheable
19210037SARM gem5 Developers};
1936019Shines@cs.fsu.edu
19410037SARM gem5 Developersstatic_assert(sizeof(ArmFault::aarch64FaultSources) ==
19510037SARM gem5 Developers              ArmFault::NumFaultSources,
19610037SARM gem5 Developers              "Invalid size of ArmFault::aarch64FaultSources[]");
1976019Shines@cs.fsu.edu
19810037SARM gem5 Developers// Fields: name, offset, cur{ELT,ELH}Offset, lowerEL{64,32}Offset, next mode,
19910037SARM gem5 Developers//         {ARM, Thumb, ARM_ELR, Thumb_ELR} PC offset, hyp trap,
20010037SARM gem5 Developers//         {A, F} disable, class, stat
20110037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<Reset>::vals = {
20210037SARM gem5 Developers    // Some dummy values (the reset vector has an IMPLEMENTATION DEFINED
20310037SARM gem5 Developers    // location in AArch64)
20410037SARM gem5 Developers    "Reset",                 0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC,
20510037SARM gem5 Developers    0, 0, 0, 0, false, true,  true,  EC_UNKNOWN, FaultStat()
20610037SARM gem5 Developers};
20710037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<UndefinedInstruction>::vals = {
20810037SARM gem5 Developers    "Undefined Instruction", 0x004, 0x000, 0x200, 0x400, 0x600, MODE_UNDEFINED,
20910037SARM gem5 Developers    4, 2, 0, 0, true,  false, false, EC_UNKNOWN, FaultStat()
21010037SARM gem5 Developers};
21110037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<SupervisorCall>::vals = {
21210037SARM gem5 Developers    "Supervisor Call",       0x008, 0x000, 0x200, 0x400, 0x600, MODE_SVC,
21310037SARM gem5 Developers    4, 2, 4, 2, true,  false, false, EC_SVC_TO_HYP, FaultStat()
21410037SARM gem5 Developers};
21510037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<SecureMonitorCall>::vals = {
21610037SARM gem5 Developers    "Secure Monitor Call",   0x008, 0x000, 0x200, 0x400, 0x600, MODE_MON,
21710037SARM gem5 Developers    4, 4, 4, 4, false, true,  true,  EC_SMC_TO_HYP, FaultStat()
21810037SARM gem5 Developers};
21910037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<HypervisorCall>::vals = {
22010037SARM gem5 Developers    "Hypervisor Call",       0x008, 0x000, 0x200, 0x400, 0x600, MODE_HYP,
22110037SARM gem5 Developers    4, 4, 4, 4, true,  false, false, EC_HVC, FaultStat()
22210037SARM gem5 Developers};
22310037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<PrefetchAbort>::vals = {
22410037SARM gem5 Developers    "Prefetch Abort",        0x00C, 0x000, 0x200, 0x400, 0x600, MODE_ABORT,
22510037SARM gem5 Developers    4, 4, 0, 0, true,  true,  false, EC_PREFETCH_ABORT_TO_HYP, FaultStat()
22610037SARM gem5 Developers};
22710037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<DataAbort>::vals = {
22810037SARM gem5 Developers    "Data Abort",            0x010, 0x000, 0x200, 0x400, 0x600, MODE_ABORT,
22910037SARM gem5 Developers    8, 8, 0, 0, true,  true,  false, EC_DATA_ABORT_TO_HYP, FaultStat()
23010037SARM gem5 Developers};
23110037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<VirtualDataAbort>::vals = {
23210037SARM gem5 Developers    "Virtual Data Abort",    0x010, 0x000, 0x200, 0x400, 0x600, MODE_ABORT,
23310037SARM gem5 Developers    8, 8, 0, 0, true,  true,  false, EC_INVALID, FaultStat()
23410037SARM gem5 Developers};
23510037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<HypervisorTrap>::vals = {
23610037SARM gem5 Developers    // @todo: double check these values
23710037SARM gem5 Developers    "Hypervisor Trap",       0x014, 0x000, 0x200, 0x400, 0x600, MODE_HYP,
23810037SARM gem5 Developers    0, 0, 0, 0, false, false, false, EC_UNKNOWN, FaultStat()
23910037SARM gem5 Developers};
24010037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<Interrupt>::vals = {
24110037SARM gem5 Developers    "IRQ",                   0x018, 0x080, 0x280, 0x480, 0x680, MODE_IRQ,
24210037SARM gem5 Developers    4, 4, 0, 0, false, true,  false, EC_UNKNOWN, FaultStat()
24310037SARM gem5 Developers};
24410037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<VirtualInterrupt>::vals = {
24510037SARM gem5 Developers    "Virtual IRQ",           0x018, 0x080, 0x280, 0x480, 0x680, MODE_IRQ,
24610037SARM gem5 Developers    4, 4, 0, 0, false, true,  false, EC_INVALID, FaultStat()
24710037SARM gem5 Developers};
24810037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<FastInterrupt>::vals = {
24910037SARM gem5 Developers    "FIQ",                   0x01C, 0x100, 0x300, 0x500, 0x700, MODE_FIQ,
25010037SARM gem5 Developers    4, 4, 0, 0, false, true,  true,  EC_UNKNOWN, FaultStat()
25110037SARM gem5 Developers};
25210037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<VirtualFastInterrupt>::vals = {
25310037SARM gem5 Developers    "Virtual FIQ",           0x01C, 0x100, 0x300, 0x500, 0x700, MODE_FIQ,
25410037SARM gem5 Developers    4, 4, 0, 0, false, true,  true,  EC_INVALID, FaultStat()
25510037SARM gem5 Developers};
25610037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<SupervisorTrap>::vals = {
25710037SARM gem5 Developers    // Some dummy values (SupervisorTrap is AArch64-only)
25810037SARM gem5 Developers    "Supervisor Trap",   0x014, 0x000, 0x200, 0x400, 0x600, MODE_SVC,
25910037SARM gem5 Developers    0, 0, 0, 0, false, false, false, EC_UNKNOWN, FaultStat()
26010037SARM gem5 Developers};
26110037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<SecureMonitorTrap>::vals = {
26210037SARM gem5 Developers    // Some dummy values (SecureMonitorTrap is AArch64-only)
26310037SARM gem5 Developers    "Secure Monitor Trap",   0x014, 0x000, 0x200, 0x400, 0x600, MODE_MON,
26410037SARM gem5 Developers    0, 0, 0, 0, false, false, false, EC_UNKNOWN, FaultStat()
26510037SARM gem5 Developers};
26610037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<PCAlignmentFault>::vals = {
26710037SARM gem5 Developers    // Some dummy values (PCAlignmentFault is AArch64-only)
26810037SARM gem5 Developers    "PC Alignment Fault",   0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC,
26910037SARM gem5 Developers    0, 0, 0, 0, true, false, false, EC_PC_ALIGNMENT, FaultStat()
27010037SARM gem5 Developers};
27110037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<SPAlignmentFault>::vals = {
27210037SARM gem5 Developers    // Some dummy values (SPAlignmentFault is AArch64-only)
27310037SARM gem5 Developers    "SP Alignment Fault",   0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC,
27410037SARM gem5 Developers    0, 0, 0, 0, true, false, false, EC_STACK_PTR_ALIGNMENT, FaultStat()
27510037SARM gem5 Developers};
27610037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<SystemError>::vals = {
27710037SARM gem5 Developers    // Some dummy values (SError is AArch64-only)
27810037SARM gem5 Developers    "SError",                0x000, 0x180, 0x380, 0x580, 0x780, MODE_SVC,
27910037SARM gem5 Developers    0, 0, 0, 0, false, true,  true,  EC_SERROR, FaultStat()
28010037SARM gem5 Developers};
28110037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<ArmSev>::vals = {
28210037SARM gem5 Developers    // Some dummy values
28310037SARM gem5 Developers    "ArmSev Flush",          0x000, 0x000, 0x000, 0x000, 0x000, MODE_SVC,
28410037SARM gem5 Developers    0, 0, 0, 0, false, true,  true,  EC_UNKNOWN, FaultStat()
28510037SARM gem5 Developers};
28610037SARM gem5 Developerstemplate<> ArmFault::FaultVals ArmFaultVals<IllegalInstSetStateFault>::vals = {
28710037SARM gem5 Developers    // Some dummy values (SPAlignmentFault is AArch64-only)
28810037SARM gem5 Developers    "Illegal Inst Set State Fault",   0x000, 0x000, 0x200, 0x400, 0x600, MODE_SVC,
28910037SARM gem5 Developers    0, 0, 0, 0, true, false, false, EC_ILLEGAL_INST, FaultStat()
29010037SARM gem5 Developers};
2916019Shines@cs.fsu.edu
29210037SARM gem5 DevelopersAddr
2937362Sgblack@eecs.umich.eduArmFault::getVector(ThreadContext *tc)
2946735Sgblack@eecs.umich.edu{
29510037SARM gem5 Developers    Addr base;
2966019Shines@cs.fsu.edu
29710037SARM gem5 Developers    // ARM ARM issue C B1.8.1
29810037SARM gem5 Developers    bool haveSecurity = ArmSystem::haveSecurity(tc);
2997400SAli.Saidi@ARM.com
3006735Sgblack@eecs.umich.edu    // panic if SCTLR.VE because I have no idea what to do with vectored
3016735Sgblack@eecs.umich.edu    // interrupts
30210037SARM gem5 Developers    SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR);
3036735Sgblack@eecs.umich.edu    assert(!sctlr.ve);
30410037SARM gem5 Developers    // Check for invalid modes
30510037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
30610037SARM gem5 Developers    assert(haveSecurity                      || cpsr.mode != MODE_MON);
30710037SARM gem5 Developers    assert(ArmSystem::haveVirtualization(tc) || cpsr.mode != MODE_HYP);
3087400SAli.Saidi@ARM.com
30910037SARM gem5 Developers    switch (cpsr.mode)
31010037SARM gem5 Developers    {
31110037SARM gem5 Developers      case MODE_MON:
31210037SARM gem5 Developers        base = tc->readMiscReg(MISCREG_MVBAR);
31310037SARM gem5 Developers        break;
31410037SARM gem5 Developers      case MODE_HYP:
31510037SARM gem5 Developers        base = tc->readMiscReg(MISCREG_HVBAR);
31610037SARM gem5 Developers        break;
31710037SARM gem5 Developers      default:
31810037SARM gem5 Developers        if (sctlr.v) {
31910037SARM gem5 Developers            base = HighVecs;
32010037SARM gem5 Developers        } else {
32110037SARM gem5 Developers            base = haveSecurity ? tc->readMiscReg(MISCREG_VBAR) : 0;
32210037SARM gem5 Developers        }
32310037SARM gem5 Developers        break;
32410037SARM gem5 Developers    }
32510037SARM gem5 Developers    return base + offset(tc);
3266019Shines@cs.fsu.edu}
3276019Shines@cs.fsu.edu
32810037SARM gem5 DevelopersAddr
32910037SARM gem5 DevelopersArmFault::getVector64(ThreadContext *tc)
33010037SARM gem5 Developers{
33110037SARM gem5 Developers    Addr vbar;
33210037SARM gem5 Developers    switch (toEL) {
33310037SARM gem5 Developers      case EL3:
33410037SARM gem5 Developers        assert(ArmSystem::haveSecurity(tc));
33510037SARM gem5 Developers        vbar = tc->readMiscReg(MISCREG_VBAR_EL3);
33610037SARM gem5 Developers        break;
33711574SCurtis.Dunham@arm.com      case EL2:
33811574SCurtis.Dunham@arm.com        assert(ArmSystem::haveVirtualization(tc));
33911574SCurtis.Dunham@arm.com        vbar = tc->readMiscReg(MISCREG_VBAR_EL2);
34011574SCurtis.Dunham@arm.com        break;
34110037SARM gem5 Developers      case EL1:
34210037SARM gem5 Developers        vbar = tc->readMiscReg(MISCREG_VBAR_EL1);
34310037SARM gem5 Developers        break;
34410037SARM gem5 Developers      default:
34510037SARM gem5 Developers        panic("Invalid target exception level");
34610037SARM gem5 Developers        break;
34710037SARM gem5 Developers    }
34810037SARM gem5 Developers    return vbar + offset64();
34910037SARM gem5 Developers}
35010037SARM gem5 Developers
35110037SARM gem5 DevelopersMiscRegIndex
35210037SARM gem5 DevelopersArmFault::getSyndromeReg64() const
35310037SARM gem5 Developers{
35410037SARM gem5 Developers    switch (toEL) {
35510037SARM gem5 Developers      case EL1:
35610037SARM gem5 Developers        return MISCREG_ESR_EL1;
35710037SARM gem5 Developers      case EL2:
35810037SARM gem5 Developers        return MISCREG_ESR_EL2;
35910037SARM gem5 Developers      case EL3:
36010037SARM gem5 Developers        return MISCREG_ESR_EL3;
36110037SARM gem5 Developers      default:
36210037SARM gem5 Developers        panic("Invalid exception level");
36310037SARM gem5 Developers        break;
36410037SARM gem5 Developers    }
36510037SARM gem5 Developers}
36610037SARM gem5 Developers
36710037SARM gem5 DevelopersMiscRegIndex
36810037SARM gem5 DevelopersArmFault::getFaultAddrReg64() const
36910037SARM gem5 Developers{
37010037SARM gem5 Developers    switch (toEL) {
37110037SARM gem5 Developers      case EL1:
37210037SARM gem5 Developers        return MISCREG_FAR_EL1;
37310037SARM gem5 Developers      case EL2:
37410037SARM gem5 Developers        return MISCREG_FAR_EL2;
37510037SARM gem5 Developers      case EL3:
37610037SARM gem5 Developers        return MISCREG_FAR_EL3;
37710037SARM gem5 Developers      default:
37810037SARM gem5 Developers        panic("Invalid exception level");
37910037SARM gem5 Developers        break;
38010037SARM gem5 Developers    }
38110037SARM gem5 Developers}
38210037SARM gem5 Developers
38310037SARM gem5 Developersvoid
38410037SARM gem5 DevelopersArmFault::setSyndrome(ThreadContext *tc, MiscRegIndex syndrome_reg)
38510037SARM gem5 Developers{
38610037SARM gem5 Developers    uint32_t value;
38710037SARM gem5 Developers    uint32_t exc_class = (uint32_t) ec(tc);
38810037SARM gem5 Developers    uint32_t issVal = iss();
38910037SARM gem5 Developers    assert(!from64 || ArmSystem::highestELIs64(tc));
39010037SARM gem5 Developers
39110037SARM gem5 Developers    value = exc_class << 26;
39210037SARM gem5 Developers
39310037SARM gem5 Developers    // HSR.IL not valid for Prefetch Aborts (0x20, 0x21) and Data Aborts (0x24,
39410037SARM gem5 Developers    // 0x25) for which the ISS information is not valid (ARMv7).
39510037SARM gem5 Developers    // @todo: ARMv8 revises AArch32 functionality: when HSR.IL is not
39610037SARM gem5 Developers    // valid it is treated as RES1.
39710037SARM gem5 Developers    if (to64) {
39810037SARM gem5 Developers        value |= 1 << 25;
39910037SARM gem5 Developers    } else if ((bits(exc_class, 5, 3) != 4) ||
40010037SARM gem5 Developers               (bits(exc_class, 2) && bits(issVal, 24))) {
40110037SARM gem5 Developers        if (!machInst.thumb || machInst.bigThumb)
40210037SARM gem5 Developers            value |= 1 << 25;
40310037SARM gem5 Developers    }
40410037SARM gem5 Developers    // Condition code valid for EC[5:4] nonzero
40510037SARM gem5 Developers    if (!from64 && ((bits(exc_class, 5, 4) == 0) &&
40610037SARM gem5 Developers                    (bits(exc_class, 3, 0) != 0))) {
40710037SARM gem5 Developers        if (!machInst.thumb) {
40810037SARM gem5 Developers            uint32_t      cond;
40910037SARM gem5 Developers            ConditionCode condCode = (ConditionCode) (uint32_t) machInst.condCode;
41010037SARM gem5 Developers            // If its on unconditional instruction report with a cond code of
41110037SARM gem5 Developers            // 0xE, ie the unconditional code
41210037SARM gem5 Developers            cond  = (condCode == COND_UC) ? COND_AL : condCode;
41310037SARM gem5 Developers            value |= cond << 20;
41410037SARM gem5 Developers            value |= 1    << 24;
41510037SARM gem5 Developers        }
41610037SARM gem5 Developers        value |= bits(issVal, 19, 0);
41710037SARM gem5 Developers    } else {
41810037SARM gem5 Developers        value |= issVal;
41910037SARM gem5 Developers    }
42010037SARM gem5 Developers    tc->setMiscReg(syndrome_reg, value);
42110037SARM gem5 Developers}
42210037SARM gem5 Developers
42310037SARM gem5 Developersvoid
42410417Sandreas.hansson@arm.comArmFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
4256019Shines@cs.fsu.edu{
42610037SARM gem5 Developers    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
42710037SARM gem5 Developers
42810037SARM gem5 Developers    if (ArmSystem::highestELIs64(tc)) {  // ARMv8
42910037SARM gem5 Developers        // Determine source exception level and mode
43010037SARM gem5 Developers        fromMode = (OperatingMode) (uint8_t) cpsr.mode;
43110037SARM gem5 Developers        fromEL = opModeToEL(fromMode);
43210037SARM gem5 Developers        if (opModeIs64(fromMode))
43310037SARM gem5 Developers            from64 = true;
43410037SARM gem5 Developers
43510037SARM gem5 Developers        // Determine target exception level
43610037SARM gem5 Developers        if (ArmSystem::haveSecurity(tc) && routeToMonitor(tc))
43710037SARM gem5 Developers            toEL = EL3;
43811578SDylan.Johnson@ARM.com        else if (ArmSystem::haveVirtualization(tc) && routeToHyp(tc))
43911578SDylan.Johnson@ARM.com            toEL = EL2;
44010037SARM gem5 Developers        else
44110037SARM gem5 Developers            toEL = opModeToEL(nextMode());
44210037SARM gem5 Developers        if (fromEL > toEL)
44310037SARM gem5 Developers            toEL = fromEL;
44410037SARM gem5 Developers
44510037SARM gem5 Developers        if (toEL == ArmSystem::highestEL(tc) || ELIs64(tc, toEL)) {
44610037SARM gem5 Developers            // Invoke exception handler in AArch64 state
44710037SARM gem5 Developers            to64 = true;
44810037SARM gem5 Developers            invoke64(tc, inst);
44910037SARM gem5 Developers            return;
45010037SARM gem5 Developers        }
45110037SARM gem5 Developers    }
45210037SARM gem5 Developers
45310037SARM gem5 Developers    // ARMv7 (ARM ARM issue C B1.9)
45410037SARM gem5 Developers
45510037SARM gem5 Developers    bool have_security       = ArmSystem::haveSecurity(tc);
45610037SARM gem5 Developers    bool have_virtualization = ArmSystem::haveVirtualization(tc);
45710037SARM gem5 Developers
4586735Sgblack@eecs.umich.edu    FaultBase::invoke(tc);
4598782Sgblack@eecs.umich.edu    if (!FullSystem)
4608782Sgblack@eecs.umich.edu        return;
4616735Sgblack@eecs.umich.edu    countStat()++;
4626019Shines@cs.fsu.edu
4636735Sgblack@eecs.umich.edu    SCTLR sctlr = tc->readMiscReg(MISCREG_SCTLR);
46410037SARM gem5 Developers    SCR scr = tc->readMiscReg(MISCREG_SCR);
4658303SAli.Saidi@ARM.com    CPSR saved_cpsr = tc->readMiscReg(MISCREG_CPSR);
46610338SCurtis.Dunham@arm.com    saved_cpsr.nz = tc->readCCReg(CCREG_NZ);
46710338SCurtis.Dunham@arm.com    saved_cpsr.c = tc->readCCReg(CCREG_C);
46810338SCurtis.Dunham@arm.com    saved_cpsr.v = tc->readCCReg(CCREG_V);
46910338SCurtis.Dunham@arm.com    saved_cpsr.ge = tc->readCCReg(CCREG_GE);
4708303SAli.Saidi@ARM.com
4717720Sgblack@eecs.umich.edu    Addr curPc M5_VAR_USED = tc->pcState().pc();
4728205SAli.Saidi@ARM.com    ITSTATE it = tc->pcState().itstate();
4738205SAli.Saidi@ARM.com    saved_cpsr.it2 = it.top6;
4748205SAli.Saidi@ARM.com    saved_cpsr.it1 = it.bottom2;
4756735Sgblack@eecs.umich.edu
47610037SARM gem5 Developers    // if we have a valid instruction then use it to annotate this fault with
47710037SARM gem5 Developers    // extra information. This is used to generate the correct fault syndrome
47810037SARM gem5 Developers    // information
47910037SARM gem5 Developers    if (inst) {
48010037SARM gem5 Developers        ArmStaticInst *armInst = reinterpret_cast<ArmStaticInst *>(inst.get());
48110037SARM gem5 Developers        armInst->annotateFault(this);
48210037SARM gem5 Developers    }
48310037SARM gem5 Developers
48410037SARM gem5 Developers    if (have_security && routeToMonitor(tc))
48510037SARM gem5 Developers        cpsr.mode = MODE_MON;
48610037SARM gem5 Developers    else if (have_virtualization && routeToHyp(tc))
48710037SARM gem5 Developers        cpsr.mode = MODE_HYP;
48810037SARM gem5 Developers    else
48910037SARM gem5 Developers        cpsr.mode = nextMode();
49010037SARM gem5 Developers
49110037SARM gem5 Developers    // Ensure Secure state if initially in Monitor mode
49210037SARM gem5 Developers    if (have_security && saved_cpsr.mode == MODE_MON) {
49310037SARM gem5 Developers        SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR);
49410037SARM gem5 Developers        if (scr.ns) {
49510037SARM gem5 Developers            scr.ns = 0;
49610037SARM gem5 Developers            tc->setMiscRegNoEffect(MISCREG_SCR, scr);
49710037SARM gem5 Developers        }
49810037SARM gem5 Developers    }
49910037SARM gem5 Developers
50010037SARM gem5 Developers    // some bits are set differently if we have been routed to hyp mode
50110037SARM gem5 Developers    if (cpsr.mode == MODE_HYP) {
50210037SARM gem5 Developers        SCTLR hsctlr = tc->readMiscReg(MISCREG_HSCTLR);
50310037SARM gem5 Developers        cpsr.t = hsctlr.te;
50410037SARM gem5 Developers        cpsr.e = hsctlr.ee;
50510037SARM gem5 Developers        if (!scr.ea)  {cpsr.a = 1;}
50610037SARM gem5 Developers        if (!scr.fiq) {cpsr.f = 1;}
50710037SARM gem5 Developers        if (!scr.irq) {cpsr.i = 1;}
50810037SARM gem5 Developers    } else if (cpsr.mode == MODE_MON) {
50910037SARM gem5 Developers        // Special case handling when entering monitor mode
51010037SARM gem5 Developers        cpsr.t = sctlr.te;
51110037SARM gem5 Developers        cpsr.e = sctlr.ee;
51210037SARM gem5 Developers        cpsr.a = 1;
51310037SARM gem5 Developers        cpsr.f = 1;
51410037SARM gem5 Developers        cpsr.i = 1;
51510037SARM gem5 Developers    } else {
51610037SARM gem5 Developers        cpsr.t = sctlr.te;
51710037SARM gem5 Developers        cpsr.e = sctlr.ee;
51810037SARM gem5 Developers
51910037SARM gem5 Developers        // The *Disable functions are virtual and different per fault
52010037SARM gem5 Developers        cpsr.a = cpsr.a | abortDisable(tc);
52110037SARM gem5 Developers        cpsr.f = cpsr.f | fiqDisable(tc);
52210037SARM gem5 Developers        cpsr.i = 1;
52310037SARM gem5 Developers    }
5246735Sgblack@eecs.umich.edu    cpsr.it1 = cpsr.it2 = 0;
5256735Sgblack@eecs.umich.edu    cpsr.j = 0;
5266735Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_CPSR, cpsr);
52710037SARM gem5 Developers
5288518Sgeoffrey.blake@arm.com    // Make sure mailbox sets to one always
5298518Sgeoffrey.blake@arm.com    tc->setMiscReg(MISCREG_SEV_MAILBOX, 1);
5306735Sgblack@eecs.umich.edu
53110037SARM gem5 Developers    // Clear the exclusive monitor
53210037SARM gem5 Developers    tc->setMiscReg(MISCREG_LOCKFLAG, 0);
53310037SARM gem5 Developers
53410037SARM gem5 Developers    if (cpsr.mode == MODE_HYP) {
53510037SARM gem5 Developers        tc->setMiscReg(MISCREG_ELR_HYP, curPc +
53610037SARM gem5 Developers                (saved_cpsr.t ? thumbPcOffset(true)  : armPcOffset(true)));
53710037SARM gem5 Developers    } else {
53810037SARM gem5 Developers        tc->setIntReg(INTREG_LR, curPc +
53910037SARM gem5 Developers                (saved_cpsr.t ? thumbPcOffset(false) : armPcOffset(false)));
54010037SARM gem5 Developers    }
54110037SARM gem5 Developers
54210037SARM gem5 Developers    switch (cpsr.mode) {
5436735Sgblack@eecs.umich.edu      case MODE_FIQ:
5446735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_FIQ, saved_cpsr);
5456735Sgblack@eecs.umich.edu        break;
5466735Sgblack@eecs.umich.edu      case MODE_IRQ:
5476735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_IRQ, saved_cpsr);
5486735Sgblack@eecs.umich.edu        break;
5496735Sgblack@eecs.umich.edu      case MODE_SVC:
5506735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_SVC, saved_cpsr);
5516735Sgblack@eecs.umich.edu        break;
55210037SARM gem5 Developers      case MODE_MON:
55310037SARM gem5 Developers        assert(have_security);
55410037SARM gem5 Developers        tc->setMiscReg(MISCREG_SPSR_MON, saved_cpsr);
5556735Sgblack@eecs.umich.edu        break;
5566735Sgblack@eecs.umich.edu      case MODE_ABORT:
5576735Sgblack@eecs.umich.edu        tc->setMiscReg(MISCREG_SPSR_ABT, saved_cpsr);
5586735Sgblack@eecs.umich.edu        break;
55910037SARM gem5 Developers      case MODE_UNDEFINED:
56010037SARM gem5 Developers        tc->setMiscReg(MISCREG_SPSR_UND, saved_cpsr);
56110037SARM gem5 Developers        if (ec(tc) != EC_UNKNOWN)
56210037SARM gem5 Developers            setSyndrome(tc, MISCREG_HSR);
56310037SARM gem5 Developers        break;
56410037SARM gem5 Developers      case MODE_HYP:
56510037SARM gem5 Developers        assert(have_virtualization);
56610037SARM gem5 Developers        tc->setMiscReg(MISCREG_SPSR_HYP, saved_cpsr);
56710037SARM gem5 Developers        setSyndrome(tc, MISCREG_HSR);
56810037SARM gem5 Developers        break;
5696735Sgblack@eecs.umich.edu      default:
5706735Sgblack@eecs.umich.edu        panic("unknown Mode\n");
5717093Sgblack@eecs.umich.edu    }
5727093Sgblack@eecs.umich.edu
5737720Sgblack@eecs.umich.edu    Addr newPc = getVector(tc);
5747585SAli.Saidi@arm.com    DPRINTF(Faults, "Invoking Fault:%s cpsr:%#x PC:%#x lr:%#x newVec: %#x\n",
5757720Sgblack@eecs.umich.edu            name(), cpsr, curPc, tc->readIntReg(INTREG_LR), newPc);
5767720Sgblack@eecs.umich.edu    PCState pc(newPc);
5777720Sgblack@eecs.umich.edu    pc.thumb(cpsr.t);
5787720Sgblack@eecs.umich.edu    pc.nextThumb(pc.thumb());
5797720Sgblack@eecs.umich.edu    pc.jazelle(cpsr.j);
5807720Sgblack@eecs.umich.edu    pc.nextJazelle(pc.jazelle());
58110037SARM gem5 Developers    pc.aarch64(!cpsr.width);
58210037SARM gem5 Developers    pc.nextAArch64(!cpsr.width);
5837720Sgblack@eecs.umich.edu    tc->pcState(pc);
5846019Shines@cs.fsu.edu}
5857189Sgblack@eecs.umich.edu
5867400SAli.Saidi@ARM.comvoid
58710417Sandreas.hansson@arm.comArmFault::invoke64(ThreadContext *tc, const StaticInstPtr &inst)
58810037SARM gem5 Developers{
58910037SARM gem5 Developers    // Determine actual misc. register indices for ELR_ELx and SPSR_ELx
59010037SARM gem5 Developers    MiscRegIndex elr_idx, spsr_idx;
59110037SARM gem5 Developers    switch (toEL) {
59210037SARM gem5 Developers      case EL1:
59310037SARM gem5 Developers        elr_idx = MISCREG_ELR_EL1;
59410037SARM gem5 Developers        spsr_idx = MISCREG_SPSR_EL1;
59510037SARM gem5 Developers        break;
59611574SCurtis.Dunham@arm.com      case EL2:
59711574SCurtis.Dunham@arm.com        assert(ArmSystem::haveVirtualization(tc));
59811574SCurtis.Dunham@arm.com        elr_idx = MISCREG_ELR_EL2;
59911574SCurtis.Dunham@arm.com        spsr_idx = MISCREG_SPSR_EL2;
60011574SCurtis.Dunham@arm.com        break;
60110037SARM gem5 Developers      case EL3:
60210037SARM gem5 Developers        assert(ArmSystem::haveSecurity(tc));
60310037SARM gem5 Developers        elr_idx = MISCREG_ELR_EL3;
60410037SARM gem5 Developers        spsr_idx = MISCREG_SPSR_EL3;
60510037SARM gem5 Developers        break;
60610037SARM gem5 Developers      default:
60710037SARM gem5 Developers        panic("Invalid target exception level");
60810037SARM gem5 Developers        break;
60910037SARM gem5 Developers    }
61010037SARM gem5 Developers
61110037SARM gem5 Developers    // Save process state into SPSR_ELx
61210037SARM gem5 Developers    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
61310037SARM gem5 Developers    CPSR spsr = cpsr;
61410338SCurtis.Dunham@arm.com    spsr.nz = tc->readCCReg(CCREG_NZ);
61510338SCurtis.Dunham@arm.com    spsr.c = tc->readCCReg(CCREG_C);
61610338SCurtis.Dunham@arm.com    spsr.v = tc->readCCReg(CCREG_V);
61710037SARM gem5 Developers    if (from64) {
61810037SARM gem5 Developers        // Force some bitfields to 0
61910037SARM gem5 Developers        spsr.q = 0;
62010037SARM gem5 Developers        spsr.it1 = 0;
62110037SARM gem5 Developers        spsr.j = 0;
62210037SARM gem5 Developers        spsr.res0_23_22 = 0;
62310037SARM gem5 Developers        spsr.ge = 0;
62410037SARM gem5 Developers        spsr.it2 = 0;
62510037SARM gem5 Developers        spsr.t = 0;
62610037SARM gem5 Developers    } else {
62710338SCurtis.Dunham@arm.com        spsr.ge = tc->readCCReg(CCREG_GE);
62810037SARM gem5 Developers        ITSTATE it = tc->pcState().itstate();
62910037SARM gem5 Developers        spsr.it2 = it.top6;
63010037SARM gem5 Developers        spsr.it1 = it.bottom2;
63110037SARM gem5 Developers        // Force some bitfields to 0
63210037SARM gem5 Developers        spsr.res0_23_22 = 0;
63310037SARM gem5 Developers        spsr.ss = 0;
63410037SARM gem5 Developers    }
63510037SARM gem5 Developers    tc->setMiscReg(spsr_idx, spsr);
63610037SARM gem5 Developers
63710037SARM gem5 Developers    // Save preferred return address into ELR_ELx
63810037SARM gem5 Developers    Addr curr_pc = tc->pcState().pc();
63910037SARM gem5 Developers    Addr ret_addr = curr_pc;
64010037SARM gem5 Developers    if (from64)
64110037SARM gem5 Developers        ret_addr += armPcElrOffset();
64210037SARM gem5 Developers    else
64310037SARM gem5 Developers        ret_addr += spsr.t ? thumbPcElrOffset() : armPcElrOffset();
64410037SARM gem5 Developers    tc->setMiscReg(elr_idx, ret_addr);
64510037SARM gem5 Developers
64610037SARM gem5 Developers    // Update process state
64710037SARM gem5 Developers    OperatingMode64 mode = 0;
64810037SARM gem5 Developers    mode.spX = 1;
64910037SARM gem5 Developers    mode.el = toEL;
65010037SARM gem5 Developers    mode.width = 0;
65110037SARM gem5 Developers    cpsr.mode = mode;
65210037SARM gem5 Developers    cpsr.daif = 0xf;
65310037SARM gem5 Developers    cpsr.il = 0;
65410037SARM gem5 Developers    cpsr.ss = 0;
65510037SARM gem5 Developers    tc->setMiscReg(MISCREG_CPSR, cpsr);
65610037SARM gem5 Developers
65710037SARM gem5 Developers    // Set PC to start of exception handler
65810037SARM gem5 Developers    Addr new_pc = purifyTaggedAddr(getVector64(tc), tc, toEL);
65910037SARM gem5 Developers    DPRINTF(Faults, "Invoking Fault (AArch64 target EL):%s cpsr:%#x PC:%#x "
66010037SARM gem5 Developers            "elr:%#x newVec: %#x\n", name(), cpsr, curr_pc, ret_addr, new_pc);
66110037SARM gem5 Developers    PCState pc(new_pc);
66210037SARM gem5 Developers    pc.aarch64(!cpsr.width);
66310037SARM gem5 Developers    pc.nextAArch64(!cpsr.width);
66410037SARM gem5 Developers    tc->pcState(pc);
66510037SARM gem5 Developers
66610037SARM gem5 Developers    // If we have a valid instruction then use it to annotate this fault with
66710037SARM gem5 Developers    // extra information. This is used to generate the correct fault syndrome
66810037SARM gem5 Developers    // information
66910037SARM gem5 Developers    if (inst)
67010037SARM gem5 Developers        reinterpret_cast<ArmStaticInst *>(inst.get())->annotateFault(this);
67110037SARM gem5 Developers    // Save exception syndrome
67210037SARM gem5 Developers    if ((nextMode() != MODE_IRQ) && (nextMode() != MODE_FIQ))
67310037SARM gem5 Developers        setSyndrome(tc, getSyndromeReg64());
67410037SARM gem5 Developers}
67510037SARM gem5 Developers
67610037SARM gem5 Developersvoid
67710417Sandreas.hansson@arm.comReset::invoke(ThreadContext *tc, const StaticInstPtr &inst)
6787400SAli.Saidi@ARM.com{
6798782Sgblack@eecs.umich.edu    if (FullSystem) {
68011150Smitch.hayenga@arm.com        tc->getCpuPtr()->clearInterrupts(tc->threadId());
6818782Sgblack@eecs.umich.edu        tc->clearArchRegs();
6828782Sgblack@eecs.umich.edu    }
68310037SARM gem5 Developers    if (!ArmSystem::highestELIs64(tc)) {
68410037SARM gem5 Developers        ArmFault::invoke(tc, inst);
68510037SARM gem5 Developers        tc->setMiscReg(MISCREG_VMPIDR,
68610037SARM gem5 Developers                       getMPIDR(dynamic_cast<ArmSystem*>(tc->getSystemPtr()), tc));
68710037SARM gem5 Developers
68810037SARM gem5 Developers        // Unless we have SMC code to get us there, boot in HYP!
68910037SARM gem5 Developers        if (ArmSystem::haveVirtualization(tc) &&
69010037SARM gem5 Developers            !ArmSystem::haveSecurity(tc)) {
69110037SARM gem5 Developers            CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
69210037SARM gem5 Developers            cpsr.mode = MODE_HYP;
69310037SARM gem5 Developers            tc->setMiscReg(MISCREG_CPSR, cpsr);
69410037SARM gem5 Developers        }
69510037SARM gem5 Developers    } else {
69610037SARM gem5 Developers        // Advance the PC to the IMPLEMENTATION DEFINED reset value
69710037SARM gem5 Developers        PCState pc = ArmSystem::resetAddr64(tc);
69810037SARM gem5 Developers        pc.aarch64(true);
69910037SARM gem5 Developers        pc.nextAArch64(true);
70010037SARM gem5 Developers        tc->pcState(pc);
70110037SARM gem5 Developers    }
7027400SAli.Saidi@ARM.com}
7037400SAli.Saidi@ARM.com
7047189Sgblack@eecs.umich.eduvoid
70510417Sandreas.hansson@arm.comUndefinedInstruction::invoke(ThreadContext *tc, const StaticInstPtr &inst)
7067189Sgblack@eecs.umich.edu{
7078782Sgblack@eecs.umich.edu    if (FullSystem) {
7088782Sgblack@eecs.umich.edu        ArmFault::invoke(tc, inst);
7098806Sgblack@eecs.umich.edu        return;
7108806Sgblack@eecs.umich.edu    }
7118806Sgblack@eecs.umich.edu
7128806Sgblack@eecs.umich.edu    // If the mnemonic isn't defined this has to be an unknown instruction.
7138806Sgblack@eecs.umich.edu    assert(unknown || mnemonic != NULL);
7148806Sgblack@eecs.umich.edu    if (disabled) {
7158806Sgblack@eecs.umich.edu        panic("Attempted to execute disabled instruction "
7168806Sgblack@eecs.umich.edu                "'%s' (inst 0x%08x)", mnemonic, machInst);
7178806Sgblack@eecs.umich.edu    } else if (unknown) {
7188806Sgblack@eecs.umich.edu        panic("Attempted to execute unknown instruction (inst 0x%08x)",
7198806Sgblack@eecs.umich.edu              machInst);
7207189Sgblack@eecs.umich.edu    } else {
7218806Sgblack@eecs.umich.edu        panic("Attempted to execute unimplemented instruction "
7228806Sgblack@eecs.umich.edu                "'%s' (inst 0x%08x)", mnemonic, machInst);
7237189Sgblack@eecs.umich.edu    }
7247189Sgblack@eecs.umich.edu}
7257189Sgblack@eecs.umich.edu
72610037SARM gem5 Developersbool
72710037SARM gem5 DevelopersUndefinedInstruction::routeToHyp(ThreadContext *tc) const
72810037SARM gem5 Developers{
72910037SARM gem5 Developers    bool toHyp;
73010037SARM gem5 Developers
73110037SARM gem5 Developers    SCR  scr  = tc->readMiscRegNoEffect(MISCREG_SCR);
73210037SARM gem5 Developers    HCR  hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
73310037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
73410037SARM gem5 Developers
73510037SARM gem5 Developers    // if in Hyp mode then stay in Hyp mode
73610037SARM gem5 Developers    toHyp  = scr.ns && (cpsr.mode == MODE_HYP);
73710037SARM gem5 Developers    // if HCR.TGE is set to 1, take to Hyp mode through Hyp Trap vector
73810037SARM gem5 Developers    toHyp |= !inSecureState(scr, cpsr) && hcr.tge && (cpsr.mode == MODE_USER);
73910037SARM gem5 Developers    return toHyp;
74010037SARM gem5 Developers}
74110037SARM gem5 Developers
74210037SARM gem5 Developersuint32_t
74310037SARM gem5 DevelopersUndefinedInstruction::iss() const
74410037SARM gem5 Developers{
74510037SARM gem5 Developers    if (overrideEc == EC_INVALID)
74610037SARM gem5 Developers        return issRaw;
74710037SARM gem5 Developers
74810037SARM gem5 Developers    uint32_t new_iss = 0;
74910037SARM gem5 Developers    uint32_t op0, op1, op2, CRn, CRm, Rt, dir;
75010037SARM gem5 Developers
75110037SARM gem5 Developers    dir = bits(machInst, 21, 21);
75210037SARM gem5 Developers    op0 = bits(machInst, 20, 19);
75310037SARM gem5 Developers    op1 = bits(machInst, 18, 16);
75410037SARM gem5 Developers    CRn = bits(machInst, 15, 12);
75510037SARM gem5 Developers    CRm = bits(machInst, 11, 8);
75610037SARM gem5 Developers    op2 = bits(machInst, 7, 5);
75710037SARM gem5 Developers    Rt = bits(machInst, 4, 0);
75810037SARM gem5 Developers
75910037SARM gem5 Developers    new_iss = op0 << 20 | op2 << 17 | op1 << 14 | CRn << 10 |
76010037SARM gem5 Developers            Rt << 5 | CRm << 1 | dir;
76110037SARM gem5 Developers
76210037SARM gem5 Developers    return new_iss;
76310037SARM gem5 Developers}
76410037SARM gem5 Developers
7657197Sgblack@eecs.umich.eduvoid
76610417Sandreas.hansson@arm.comSupervisorCall::invoke(ThreadContext *tc, const StaticInstPtr &inst)
7677197Sgblack@eecs.umich.edu{
7688782Sgblack@eecs.umich.edu    if (FullSystem) {
7698782Sgblack@eecs.umich.edu        ArmFault::invoke(tc, inst);
7708806Sgblack@eecs.umich.edu        return;
7718806Sgblack@eecs.umich.edu    }
7727197Sgblack@eecs.umich.edu
7738806Sgblack@eecs.umich.edu    // As of now, there isn't a 32 bit thumb version of this instruction.
7748806Sgblack@eecs.umich.edu    assert(!machInst.bigThumb);
7758806Sgblack@eecs.umich.edu    uint32_t callNum;
77610037SARM gem5 Developers    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
77710037SARM gem5 Developers    OperatingMode mode = (OperatingMode)(uint8_t)cpsr.mode;
77810037SARM gem5 Developers    if (opModeIs64(mode))
77910037SARM gem5 Developers        callNum = tc->readIntReg(INTREG_X8);
78010037SARM gem5 Developers    else
78110037SARM gem5 Developers        callNum = tc->readIntReg(INTREG_R7);
78211877Sbrandon.potter@amd.com    Fault fault;
78311877Sbrandon.potter@amd.com    tc->syscall(callNum, &fault);
7848806Sgblack@eecs.umich.edu
7858806Sgblack@eecs.umich.edu    // Advance the PC since that won't happen automatically.
7868806Sgblack@eecs.umich.edu    PCState pc = tc->pcState();
7878806Sgblack@eecs.umich.edu    assert(inst);
7888806Sgblack@eecs.umich.edu    inst->advancePC(pc);
7898806Sgblack@eecs.umich.edu    tc->pcState(pc);
7907197Sgblack@eecs.umich.edu}
7917197Sgblack@eecs.umich.edu
79210037SARM gem5 Developersbool
79310037SARM gem5 DevelopersSupervisorCall::routeToHyp(ThreadContext *tc) const
79410037SARM gem5 Developers{
79510037SARM gem5 Developers    bool toHyp;
79610037SARM gem5 Developers
79710037SARM gem5 Developers    SCR  scr  = tc->readMiscRegNoEffect(MISCREG_SCR);
79810037SARM gem5 Developers    HCR  hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
79910037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
80010037SARM gem5 Developers
80110037SARM gem5 Developers    // if in Hyp mode then stay in Hyp mode
80210037SARM gem5 Developers    toHyp  = scr.ns && (cpsr.mode == MODE_HYP);
80310037SARM gem5 Developers    // if HCR.TGE is set to 1, take to Hyp mode through Hyp Trap vector
80410037SARM gem5 Developers    toHyp |= !inSecureState(scr, cpsr) && hcr.tge && (cpsr.mode == MODE_USER);
80510037SARM gem5 Developers    return toHyp;
80610037SARM gem5 Developers}
80710037SARM gem5 Developers
80810037SARM gem5 DevelopersExceptionClass
80910037SARM gem5 DevelopersSupervisorCall::ec(ThreadContext *tc) const
81010037SARM gem5 Developers{
81110037SARM gem5 Developers    return (overrideEc != EC_INVALID) ? overrideEc :
81210037SARM gem5 Developers        (from64 ? EC_SVC_64 : vals.ec);
81310037SARM gem5 Developers}
81410037SARM gem5 Developers
81510037SARM gem5 Developersuint32_t
81610037SARM gem5 DevelopersSupervisorCall::iss() const
81710037SARM gem5 Developers{
81810037SARM gem5 Developers    // Even if we have a 24 bit imm from an arm32 instruction then we only use
81910037SARM gem5 Developers    // the bottom 16 bits for the ISS value (it doesn't hurt for AArch64 SVC).
82010037SARM gem5 Developers    return issRaw & 0xFFFF;
82110037SARM gem5 Developers}
82210037SARM gem5 Developers
82310037SARM gem5 Developersuint32_t
82410037SARM gem5 DevelopersSecureMonitorCall::iss() const
82510037SARM gem5 Developers{
82610037SARM gem5 Developers    if (from64)
82710037SARM gem5 Developers        return bits(machInst, 20, 5);
82810037SARM gem5 Developers    return 0;
82910037SARM gem5 Developers}
83010037SARM gem5 Developers
83110037SARM gem5 DevelopersExceptionClass
83210037SARM gem5 DevelopersUndefinedInstruction::ec(ThreadContext *tc) const
83310037SARM gem5 Developers{
83410037SARM gem5 Developers    return (overrideEc != EC_INVALID) ? overrideEc : vals.ec;
83510037SARM gem5 Developers}
83610037SARM gem5 Developers
83710037SARM gem5 Developers
83810037SARM gem5 DevelopersHypervisorCall::HypervisorCall(ExtMachInst _machInst, uint32_t _imm) :
83910037SARM gem5 Developers        ArmFaultVals<HypervisorCall>(_machInst, _imm)
84010037SARM gem5 Developers{}
84110037SARM gem5 Developers
84210037SARM gem5 DevelopersExceptionClass
84311576SDylan.Johnson@ARM.comHypervisorCall::ec(ThreadContext *tc) const
84411576SDylan.Johnson@ARM.com{
84511576SDylan.Johnson@ARM.com    return from64 ? EC_HVC_64 : vals.ec;
84611576SDylan.Johnson@ARM.com}
84711576SDylan.Johnson@ARM.com
84811576SDylan.Johnson@ARM.comExceptionClass
84910037SARM gem5 DevelopersHypervisorTrap::ec(ThreadContext *tc) const
85010037SARM gem5 Developers{
85110037SARM gem5 Developers    return (overrideEc != EC_INVALID) ? overrideEc : vals.ec;
85210037SARM gem5 Developers}
85310037SARM gem5 Developers
85410037SARM gem5 Developerstemplate<class T>
85510037SARM gem5 DevelopersFaultOffset
85610037SARM gem5 DevelopersArmFaultVals<T>::offset(ThreadContext *tc)
85710037SARM gem5 Developers{
85810037SARM gem5 Developers    bool isHypTrap = false;
85910037SARM gem5 Developers
86010037SARM gem5 Developers    // Normally we just use the exception vector from the table at the top if
86110037SARM gem5 Developers    // this file, however if this exception has caused a transition to hype
86210037SARM gem5 Developers    // mode, and its an exception type that would only do this if it has been
86310037SARM gem5 Developers    // trapped then we use the hyp trap vector instead of the normal vector
86410037SARM gem5 Developers    if (vals.hypTrappable) {
86510037SARM gem5 Developers        CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
86610037SARM gem5 Developers        if (cpsr.mode == MODE_HYP) {
86710037SARM gem5 Developers            CPSR spsr = tc->readMiscReg(MISCREG_SPSR_HYP);
86810037SARM gem5 Developers            isHypTrap = spsr.mode != MODE_HYP;
86910037SARM gem5 Developers        }
87010037SARM gem5 Developers    }
87110037SARM gem5 Developers    return isHypTrap ? 0x14 : vals.offset;
87210037SARM gem5 Developers}
87310037SARM gem5 Developers
87410037SARM gem5 Developers// void
87510037SARM gem5 Developers// SupervisorCall::setSyndrome64(ThreadContext *tc, MiscRegIndex esr_idx)
87610037SARM gem5 Developers// {
87710037SARM gem5 Developers//     ESR esr = 0;
87810037SARM gem5 Developers//     esr.ec = machInst.aarch64 ? SvcAArch64 : SvcAArch32;
87910037SARM gem5 Developers//     esr.il = !machInst.thumb;
88010037SARM gem5 Developers//     if (machInst.aarch64)
88110037SARM gem5 Developers//         esr.imm16 = bits(machInst.instBits, 20, 5);
88210037SARM gem5 Developers//     else if (machInst.thumb)
88310037SARM gem5 Developers//         esr.imm16 = bits(machInst.instBits, 7, 0);
88410037SARM gem5 Developers//     else
88510037SARM gem5 Developers//         esr.imm16 = bits(machInst.instBits, 15, 0);
88610037SARM gem5 Developers//     tc->setMiscReg(esr_idx, esr);
88710037SARM gem5 Developers// }
88810037SARM gem5 Developers
88910037SARM gem5 Developersvoid
89010417Sandreas.hansson@arm.comSecureMonitorCall::invoke(ThreadContext *tc, const StaticInstPtr &inst)
89110037SARM gem5 Developers{
89210037SARM gem5 Developers    if (FullSystem) {
89310037SARM gem5 Developers        ArmFault::invoke(tc, inst);
89410037SARM gem5 Developers        return;
89510037SARM gem5 Developers    }
89610037SARM gem5 Developers}
89710037SARM gem5 Developers
89810037SARM gem5 DevelopersExceptionClass
89910037SARM gem5 DevelopersSecureMonitorCall::ec(ThreadContext *tc) const
90010037SARM gem5 Developers{
90110037SARM gem5 Developers    return (from64 ? EC_SMC_64 : vals.ec);
90210037SARM gem5 Developers}
90310037SARM gem5 Developers
90410037SARM gem5 DevelopersExceptionClass
90510037SARM gem5 DevelopersSupervisorTrap::ec(ThreadContext *tc) const
90610037SARM gem5 Developers{
90710037SARM gem5 Developers    return (overrideEc != EC_INVALID) ? overrideEc : vals.ec;
90810037SARM gem5 Developers}
90910037SARM gem5 Developers
91010037SARM gem5 DevelopersExceptionClass
91110037SARM gem5 DevelopersSecureMonitorTrap::ec(ThreadContext *tc) const
91210037SARM gem5 Developers{
91310037SARM gem5 Developers    return (overrideEc != EC_INVALID) ? overrideEc :
91410037SARM gem5 Developers        (from64 ? EC_SMC_64 : vals.ec);
91510037SARM gem5 Developers}
91610037SARM gem5 Developers
9177362Sgblack@eecs.umich.edutemplate<class T>
9187362Sgblack@eecs.umich.eduvoid
91910417Sandreas.hansson@arm.comAbortFault<T>::invoke(ThreadContext *tc, const StaticInstPtr &inst)
9207362Sgblack@eecs.umich.edu{
92110037SARM gem5 Developers    if (tranMethod == ArmFault::UnknownTran) {
92210037SARM gem5 Developers        tranMethod = longDescFormatInUse(tc) ? ArmFault::LpaeTran
92310037SARM gem5 Developers                                             : ArmFault::VmsaTran;
92410037SARM gem5 Developers
92510037SARM gem5 Developers        if ((tranMethod == ArmFault::VmsaTran) && this->routeToMonitor(tc)) {
92610037SARM gem5 Developers            // See ARM ARM B3-1416
92710037SARM gem5 Developers            bool override_LPAE = false;
92810037SARM gem5 Developers            TTBCR ttbcr_s = tc->readMiscReg(MISCREG_TTBCR_S);
92910037SARM gem5 Developers            TTBCR M5_VAR_USED ttbcr_ns = tc->readMiscReg(MISCREG_TTBCR_NS);
93010037SARM gem5 Developers            if (ttbcr_s.eae) {
93110037SARM gem5 Developers                override_LPAE = true;
93210037SARM gem5 Developers            } else {
93310037SARM gem5 Developers                // Unimplemented code option, not seen in testing.  May need
93410037SARM gem5 Developers                // extension according to the manual exceprt above.
93510037SARM gem5 Developers                DPRINTF(Faults, "Warning: Incomplete translation method "
93610037SARM gem5 Developers                        "override detected.\n");
93710037SARM gem5 Developers            }
93810037SARM gem5 Developers            if (override_LPAE)
93910037SARM gem5 Developers                tranMethod = ArmFault::LpaeTran;
94010037SARM gem5 Developers        }
94110037SARM gem5 Developers    }
94210037SARM gem5 Developers
94310037SARM gem5 Developers    if (source == ArmFault::AsynchronousExternalAbort) {
94411150Smitch.hayenga@arm.com        tc->getCpuPtr()->clearInterrupt(tc->threadId(), INT_ABT, 0);
94510037SARM gem5 Developers    }
94610037SARM gem5 Developers    // Get effective fault source encoding
94710037SARM gem5 Developers    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
94810037SARM gem5 Developers    FSR  fsr  = getFsr(tc);
94910037SARM gem5 Developers
95010037SARM gem5 Developers    // source must be determined BEFORE invoking generic routines which will
95110037SARM gem5 Developers    // try to set hsr etc. and are based upon source!
9528205SAli.Saidi@ARM.com    ArmFaultVals<T>::invoke(tc, inst);
95310037SARM gem5 Developers
95411496Sandreas.sandberg@arm.com    if (!this->to64) {  // AArch32
95510037SARM gem5 Developers        if (cpsr.mode == MODE_HYP) {
95610037SARM gem5 Developers            tc->setMiscReg(T::HFarIndex, faultAddr);
95710037SARM gem5 Developers        } else if (stage2) {
95810037SARM gem5 Developers            tc->setMiscReg(MISCREG_HPFAR, (faultAddr >> 8) & ~0xf);
95910037SARM gem5 Developers            tc->setMiscReg(T::HFarIndex,  OVAddr);
96010037SARM gem5 Developers        } else {
96110037SARM gem5 Developers            tc->setMiscReg(T::FsrIndex, fsr);
96210037SARM gem5 Developers            tc->setMiscReg(T::FarIndex, faultAddr);
96310037SARM gem5 Developers        }
96410037SARM gem5 Developers        DPRINTF(Faults, "Abort Fault source=%#x fsr=%#x faultAddr=%#x "\
96510037SARM gem5 Developers                "tranMethod=%#x\n", source, fsr, faultAddr, tranMethod);
96610037SARM gem5 Developers    } else {  // AArch64
96710037SARM gem5 Developers        // Set the FAR register.  Nothing else to do if we are in AArch64 state
96810037SARM gem5 Developers        // because the syndrome register has already been set inside invoke64()
96911585SDylan.Johnson@ARM.com        if (stage2) {
97011585SDylan.Johnson@ARM.com            // stage 2 fault, set HPFAR_EL2 to the faulting IPA
97111585SDylan.Johnson@ARM.com            // and FAR_EL2 to the Original VA
97211585SDylan.Johnson@ARM.com            tc->setMiscReg(AbortFault<T>::getFaultAddrReg64(), OVAddr);
97311585SDylan.Johnson@ARM.com            tc->setMiscReg(MISCREG_HPFAR_EL2, bits(faultAddr, 47, 12) << 4);
97411585SDylan.Johnson@ARM.com
97511585SDylan.Johnson@ARM.com            DPRINTF(Faults, "Abort Fault (Stage 2) VA: 0x%x IPA: 0x%x\n",
97611585SDylan.Johnson@ARM.com                    OVAddr, faultAddr);
97711585SDylan.Johnson@ARM.com        } else {
97811585SDylan.Johnson@ARM.com            tc->setMiscReg(AbortFault<T>::getFaultAddrReg64(), faultAddr);
97911585SDylan.Johnson@ARM.com        }
98010037SARM gem5 Developers    }
98110037SARM gem5 Developers}
98210037SARM gem5 Developers
98310037SARM gem5 Developerstemplate<class T>
98410037SARM gem5 DevelopersFSR
98510037SARM gem5 DevelopersAbortFault<T>::getFsr(ThreadContext *tc)
98610037SARM gem5 Developers{
9877362Sgblack@eecs.umich.edu    FSR fsr = 0;
9888314Sgeoffrey.blake@arm.com
98910037SARM gem5 Developers    if (((CPSR) tc->readMiscRegNoEffect(MISCREG_CPSR)).width) {
99010037SARM gem5 Developers        // AArch32
99110037SARM gem5 Developers        assert(tranMethod != ArmFault::UnknownTran);
99210037SARM gem5 Developers        if (tranMethod == ArmFault::LpaeTran) {
99310037SARM gem5 Developers            srcEncoded = ArmFault::longDescFaultSources[source];
99410037SARM gem5 Developers            fsr.status = srcEncoded;
99510037SARM gem5 Developers            fsr.lpae   = 1;
99610037SARM gem5 Developers        } else {
99710037SARM gem5 Developers            srcEncoded = ArmFault::shortDescFaultSources[source];
99810037SARM gem5 Developers            fsr.fsLow  = bits(srcEncoded, 3, 0);
99910037SARM gem5 Developers            fsr.fsHigh = bits(srcEncoded, 4);
100010037SARM gem5 Developers            fsr.domain = static_cast<uint8_t>(domain);
100110037SARM gem5 Developers        }
100210037SARM gem5 Developers        fsr.wnr = (write ? 1 : 0);
100310037SARM gem5 Developers        fsr.ext = 0;
100410037SARM gem5 Developers    } else {
100510037SARM gem5 Developers        // AArch64
100610037SARM gem5 Developers        srcEncoded = ArmFault::aarch64FaultSources[source];
100710037SARM gem5 Developers    }
100810037SARM gem5 Developers    if (srcEncoded == ArmFault::FaultSourceInvalid) {
100910037SARM gem5 Developers        panic("Invalid fault source\n");
101010037SARM gem5 Developers    }
101110037SARM gem5 Developers    return fsr;
101210037SARM gem5 Developers}
101310037SARM gem5 Developers
101410037SARM gem5 Developerstemplate<class T>
101510037SARM gem5 Developersbool
101610037SARM gem5 DevelopersAbortFault<T>::abortDisable(ThreadContext *tc)
101710037SARM gem5 Developers{
101810037SARM gem5 Developers    if (ArmSystem::haveSecurity(tc)) {
101910037SARM gem5 Developers        SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR);
102010037SARM gem5 Developers        return (!scr.ns || scr.aw);
102110037SARM gem5 Developers    }
102210037SARM gem5 Developers    return true;
102310037SARM gem5 Developers}
102410037SARM gem5 Developers
102510037SARM gem5 Developerstemplate<class T>
102610037SARM gem5 Developersvoid
102710037SARM gem5 DevelopersAbortFault<T>::annotate(ArmFault::AnnotationIDs id, uint64_t val)
102810037SARM gem5 Developers{
102910037SARM gem5 Developers    switch (id)
103010037SARM gem5 Developers    {
103110037SARM gem5 Developers      case ArmFault::S1PTW:
103210037SARM gem5 Developers        s1ptw = val;
103310037SARM gem5 Developers        break;
103410037SARM gem5 Developers      case ArmFault::OVA:
103510037SARM gem5 Developers        OVAddr = val;
103610037SARM gem5 Developers        break;
103710037SARM gem5 Developers
103810037SARM gem5 Developers      // Just ignore unknown ID's
103910037SARM gem5 Developers      default:
104010037SARM gem5 Developers        break;
104110037SARM gem5 Developers    }
104210037SARM gem5 Developers}
104310037SARM gem5 Developers
104410037SARM gem5 Developerstemplate<class T>
104510037SARM gem5 Developersuint32_t
104610037SARM gem5 DevelopersAbortFault<T>::iss() const
104710037SARM gem5 Developers{
104810037SARM gem5 Developers    uint32_t val;
104910037SARM gem5 Developers
105010037SARM gem5 Developers    val  = srcEncoded & 0x3F;
105110037SARM gem5 Developers    val |= write << 6;
105210037SARM gem5 Developers    val |= s1ptw << 7;
105310037SARM gem5 Developers    return (val);
105410037SARM gem5 Developers}
105510037SARM gem5 Developers
105610037SARM gem5 Developerstemplate<class T>
105710037SARM gem5 Developersbool
105810037SARM gem5 DevelopersAbortFault<T>::isMMUFault() const
105910037SARM gem5 Developers{
106010037SARM gem5 Developers    // NOTE: Not relying on LL information being aligned to lowest bits here
106110037SARM gem5 Developers    return
106210037SARM gem5 Developers         (source == ArmFault::AlignmentFault)     ||
106310037SARM gem5 Developers        ((source >= ArmFault::TranslationLL) &&
106410037SARM gem5 Developers         (source <  ArmFault::TranslationLL + 4)) ||
106510037SARM gem5 Developers        ((source >= ArmFault::AccessFlagLL) &&
106610037SARM gem5 Developers         (source <  ArmFault::AccessFlagLL + 4))  ||
106710037SARM gem5 Developers        ((source >= ArmFault::DomainLL) &&
106810037SARM gem5 Developers         (source <  ArmFault::DomainLL + 4))      ||
106910037SARM gem5 Developers        ((source >= ArmFault::PermissionLL) &&
107010037SARM gem5 Developers         (source <  ArmFault::PermissionLL + 4));
107110037SARM gem5 Developers}
107210037SARM gem5 Developers
107310037SARM gem5 DevelopersExceptionClass
107410037SARM gem5 DevelopersPrefetchAbort::ec(ThreadContext *tc) const
107510037SARM gem5 Developers{
107610037SARM gem5 Developers    if (to64) {
107710037SARM gem5 Developers        // AArch64
107810037SARM gem5 Developers        if (toEL == fromEL)
107910037SARM gem5 Developers            return EC_PREFETCH_ABORT_CURR_EL;
108010037SARM gem5 Developers        else
108110037SARM gem5 Developers            return EC_PREFETCH_ABORT_LOWER_EL;
108210037SARM gem5 Developers    } else {
108310037SARM gem5 Developers        // AArch32
108410037SARM gem5 Developers        // Abort faults have different EC codes depending on whether
108510037SARM gem5 Developers        // the fault originated within HYP mode, or not. So override
108610037SARM gem5 Developers        // the method and add the extra adjustment of the EC value.
108710037SARM gem5 Developers
108810037SARM gem5 Developers        ExceptionClass ec = ArmFaultVals<PrefetchAbort>::vals.ec;
108910037SARM gem5 Developers
109010037SARM gem5 Developers        CPSR spsr = tc->readMiscReg(MISCREG_SPSR_HYP);
109110037SARM gem5 Developers        if (spsr.mode == MODE_HYP) {
109210037SARM gem5 Developers            ec = ((ExceptionClass) (((uint32_t) ec) + 1));
109310037SARM gem5 Developers        }
109410037SARM gem5 Developers        return ec;
109510037SARM gem5 Developers    }
109610037SARM gem5 Developers}
109710037SARM gem5 Developers
109810037SARM gem5 Developersbool
109910037SARM gem5 DevelopersPrefetchAbort::routeToMonitor(ThreadContext *tc) const
110010037SARM gem5 Developers{
110110037SARM gem5 Developers    SCR scr = 0;
110210037SARM gem5 Developers    if (from64)
110310037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR_EL3);
110410037SARM gem5 Developers    else
110510037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR);
110610037SARM gem5 Developers
110710037SARM gem5 Developers    return scr.ea && !isMMUFault();
110810037SARM gem5 Developers}
110910037SARM gem5 Developers
111010037SARM gem5 Developersbool
111110037SARM gem5 DevelopersPrefetchAbort::routeToHyp(ThreadContext *tc) const
111210037SARM gem5 Developers{
111310037SARM gem5 Developers    bool toHyp;
111410037SARM gem5 Developers
111510037SARM gem5 Developers    SCR  scr  = tc->readMiscRegNoEffect(MISCREG_SCR);
111610037SARM gem5 Developers    HCR  hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
111710037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
111810037SARM gem5 Developers    HDCR hdcr = tc->readMiscRegNoEffect(MISCREG_HDCR);
111910037SARM gem5 Developers
112010037SARM gem5 Developers    // if in Hyp mode then stay in Hyp mode
112110037SARM gem5 Developers    toHyp  = scr.ns && (cpsr.mode == MODE_HYP);
112210037SARM gem5 Developers    // otherwise, check whether to take to Hyp mode through Hyp Trap vector
112310037SARM gem5 Developers    toHyp |= (stage2 ||
112410037SARM gem5 Developers                ( (source ==               DebugEvent) && hdcr.tde && (cpsr.mode !=  MODE_HYP)) ||
112510037SARM gem5 Developers                ( (source == SynchronousExternalAbort) && hcr.tge  && (cpsr.mode == MODE_USER))
112611581SDylan.Johnson@ARM.com             ) && !inSecureState(tc);
112710037SARM gem5 Developers    return toHyp;
112810037SARM gem5 Developers}
112910037SARM gem5 Developers
113010037SARM gem5 DevelopersExceptionClass
113110037SARM gem5 DevelopersDataAbort::ec(ThreadContext *tc) const
113210037SARM gem5 Developers{
113310037SARM gem5 Developers    if (to64) {
113410037SARM gem5 Developers        // AArch64
113510037SARM gem5 Developers        if (source == ArmFault::AsynchronousExternalAbort) {
113610367SAndrew.Bardsley@arm.com            panic("Asynchronous External Abort should be handled with "
113710367SAndrew.Bardsley@arm.com                    "SystemErrors (SErrors)!");
113810037SARM gem5 Developers        }
113910037SARM gem5 Developers        if (toEL == fromEL)
114010037SARM gem5 Developers            return EC_DATA_ABORT_CURR_EL;
114110037SARM gem5 Developers        else
114210037SARM gem5 Developers            return EC_DATA_ABORT_LOWER_EL;
114310037SARM gem5 Developers    } else {
114410037SARM gem5 Developers        // AArch32
114510037SARM gem5 Developers        // Abort faults have different EC codes depending on whether
114610037SARM gem5 Developers        // the fault originated within HYP mode, or not. So override
114710037SARM gem5 Developers        // the method and add the extra adjustment of the EC value.
114810037SARM gem5 Developers
114910037SARM gem5 Developers        ExceptionClass ec = ArmFaultVals<DataAbort>::vals.ec;
115010037SARM gem5 Developers
115110037SARM gem5 Developers        CPSR spsr = tc->readMiscReg(MISCREG_SPSR_HYP);
115210037SARM gem5 Developers        if (spsr.mode == MODE_HYP) {
115310037SARM gem5 Developers            ec = ((ExceptionClass) (((uint32_t) ec) + 1));
115410037SARM gem5 Developers        }
115510037SARM gem5 Developers        return ec;
115610037SARM gem5 Developers    }
115710037SARM gem5 Developers}
115810037SARM gem5 Developers
115910037SARM gem5 Developersbool
116010037SARM gem5 DevelopersDataAbort::routeToMonitor(ThreadContext *tc) const
116110037SARM gem5 Developers{
116210037SARM gem5 Developers    SCR scr = 0;
116310037SARM gem5 Developers    if (from64)
116410037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR_EL3);
116510037SARM gem5 Developers    else
116610037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR);
116710037SARM gem5 Developers
116810037SARM gem5 Developers    return scr.ea && !isMMUFault();
116910037SARM gem5 Developers}
117010037SARM gem5 Developers
117110037SARM gem5 Developersbool
117210037SARM gem5 DevelopersDataAbort::routeToHyp(ThreadContext *tc) const
117310037SARM gem5 Developers{
117410037SARM gem5 Developers    bool toHyp;
117510037SARM gem5 Developers
117610037SARM gem5 Developers    SCR  scr  = tc->readMiscRegNoEffect(MISCREG_SCR);
117710037SARM gem5 Developers    HCR  hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
117810037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
117910037SARM gem5 Developers    HDCR hdcr = tc->readMiscRegNoEffect(MISCREG_HDCR);
118010037SARM gem5 Developers
118110037SARM gem5 Developers    // if in Hyp mode then stay in Hyp mode
118210037SARM gem5 Developers    toHyp  = scr.ns && (cpsr.mode == MODE_HYP);
118310037SARM gem5 Developers    // otherwise, check whether to take to Hyp mode through Hyp Trap vector
118410037SARM gem5 Developers    toHyp |= (stage2 ||
118510037SARM gem5 Developers                ( (cpsr.mode != MODE_HYP) && ( ((source == AsynchronousExternalAbort) && hcr.amo) ||
118610037SARM gem5 Developers                                               ((source == DebugEvent) && hdcr.tde) )
118710037SARM gem5 Developers                ) ||
118810037SARM gem5 Developers                ( (cpsr.mode == MODE_USER) && hcr.tge &&
118910037SARM gem5 Developers                  ((source == AlignmentFault)            ||
119010037SARM gem5 Developers                   (source == SynchronousExternalAbort))
119110037SARM gem5 Developers                )
119211581SDylan.Johnson@ARM.com             ) && !inSecureState(tc);
119310037SARM gem5 Developers    return toHyp;
119410037SARM gem5 Developers}
119510037SARM gem5 Developers
119610037SARM gem5 Developersuint32_t
119710037SARM gem5 DevelopersDataAbort::iss() const
119810037SARM gem5 Developers{
119910037SARM gem5 Developers    uint32_t val;
120010037SARM gem5 Developers
120110037SARM gem5 Developers    // Add on the data abort specific fields to the generic abort ISS value
120210037SARM gem5 Developers    val  = AbortFault<DataAbort>::iss();
120310037SARM gem5 Developers    // ISS is valid if not caused by a stage 1 page table walk, and when taken
120410037SARM gem5 Developers    // to AArch64 only when directed to EL2
120510037SARM gem5 Developers    if (!s1ptw && (!to64 || toEL == EL2)) {
120610037SARM gem5 Developers        val |= isv << 24;
120710037SARM gem5 Developers        if (isv) {
120810037SARM gem5 Developers            val |= sas << 22;
120910037SARM gem5 Developers            val |= sse << 21;
121010037SARM gem5 Developers            val |= srt << 16;
121110037SARM gem5 Developers            // AArch64 only. These assignments are safe on AArch32 as well
121210037SARM gem5 Developers            // because these vars are initialized to false
121310037SARM gem5 Developers            val |= sf << 15;
121410037SARM gem5 Developers            val |= ar << 14;
121510037SARM gem5 Developers        }
121610037SARM gem5 Developers    }
121710037SARM gem5 Developers    return (val);
121810037SARM gem5 Developers}
121910037SARM gem5 Developers
122010037SARM gem5 Developersvoid
122110037SARM gem5 DevelopersDataAbort::annotate(AnnotationIDs id, uint64_t val)
122210037SARM gem5 Developers{
122310037SARM gem5 Developers    AbortFault<DataAbort>::annotate(id, val);
122410037SARM gem5 Developers    switch (id)
122510037SARM gem5 Developers    {
122610037SARM gem5 Developers      case SAS:
122710037SARM gem5 Developers        isv = true;
122810037SARM gem5 Developers        sas = val;
122910037SARM gem5 Developers        break;
123010037SARM gem5 Developers      case SSE:
123110037SARM gem5 Developers        isv = true;
123210037SARM gem5 Developers        sse = val;
123310037SARM gem5 Developers        break;
123410037SARM gem5 Developers      case SRT:
123510037SARM gem5 Developers        isv = true;
123610037SARM gem5 Developers        srt = val;
123710037SARM gem5 Developers        break;
123810037SARM gem5 Developers      case SF:
123910037SARM gem5 Developers        isv = true;
124010037SARM gem5 Developers        sf  = val;
124110037SARM gem5 Developers        break;
124210037SARM gem5 Developers      case AR:
124310037SARM gem5 Developers        isv = true;
124410037SARM gem5 Developers        ar  = val;
124510037SARM gem5 Developers        break;
124610037SARM gem5 Developers      // Just ignore unknown ID's
124710037SARM gem5 Developers      default:
124810037SARM gem5 Developers        break;
124910037SARM gem5 Developers    }
125010037SARM gem5 Developers}
125110037SARM gem5 Developers
125210037SARM gem5 Developersvoid
125310417Sandreas.hansson@arm.comVirtualDataAbort::invoke(ThreadContext *tc, const StaticInstPtr &inst)
125410037SARM gem5 Developers{
125510037SARM gem5 Developers    AbortFault<VirtualDataAbort>::invoke(tc, inst);
125610037SARM gem5 Developers    HCR hcr = tc->readMiscRegNoEffect(MISCREG_HCR);
125710037SARM gem5 Developers    hcr.va = 0;
125810037SARM gem5 Developers    tc->setMiscRegNoEffect(MISCREG_HCR, hcr);
125910037SARM gem5 Developers}
126010037SARM gem5 Developers
126110037SARM gem5 Developersbool
126210037SARM gem5 DevelopersInterrupt::routeToMonitor(ThreadContext *tc) const
126310037SARM gem5 Developers{
126410037SARM gem5 Developers    assert(ArmSystem::haveSecurity(tc));
126510037SARM gem5 Developers    SCR scr = 0;
126610037SARM gem5 Developers    if (from64)
126710037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR_EL3);
126810037SARM gem5 Developers    else
126910037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR);
127010037SARM gem5 Developers    return scr.irq;
127110037SARM gem5 Developers}
127210037SARM gem5 Developers
127310037SARM gem5 Developersbool
127410037SARM gem5 DevelopersInterrupt::routeToHyp(ThreadContext *tc) const
127510037SARM gem5 Developers{
127610037SARM gem5 Developers    bool toHyp;
127710037SARM gem5 Developers
127810037SARM gem5 Developers    SCR  scr  = tc->readMiscRegNoEffect(MISCREG_SCR);
127910037SARM gem5 Developers    HCR  hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
128010037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
128110037SARM gem5 Developers    // Determine whether IRQs are routed to Hyp mode.
128211581SDylan.Johnson@ARM.com    toHyp = (!scr.irq && hcr.imo && !inSecureState(tc)) ||
128310037SARM gem5 Developers            (cpsr.mode == MODE_HYP);
128410037SARM gem5 Developers    return toHyp;
128510037SARM gem5 Developers}
128610037SARM gem5 Developers
128710037SARM gem5 Developersbool
128810037SARM gem5 DevelopersInterrupt::abortDisable(ThreadContext *tc)
128910037SARM gem5 Developers{
129010037SARM gem5 Developers    if (ArmSystem::haveSecurity(tc)) {
129110037SARM gem5 Developers        SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR);
129210037SARM gem5 Developers        return (!scr.ns || scr.aw);
129310037SARM gem5 Developers    }
129410037SARM gem5 Developers    return true;
129510037SARM gem5 Developers}
129610037SARM gem5 Developers
129710037SARM gem5 DevelopersVirtualInterrupt::VirtualInterrupt()
129810037SARM gem5 Developers{}
129910037SARM gem5 Developers
130010037SARM gem5 Developersbool
130110037SARM gem5 DevelopersFastInterrupt::routeToMonitor(ThreadContext *tc) const
130210037SARM gem5 Developers{
130310037SARM gem5 Developers    assert(ArmSystem::haveSecurity(tc));
130410037SARM gem5 Developers    SCR scr = 0;
130510037SARM gem5 Developers    if (from64)
130610037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR_EL3);
130710037SARM gem5 Developers    else
130810037SARM gem5 Developers        scr = tc->readMiscRegNoEffect(MISCREG_SCR);
130910037SARM gem5 Developers    return scr.fiq;
131010037SARM gem5 Developers}
131110037SARM gem5 Developers
131210037SARM gem5 Developersbool
131310037SARM gem5 DevelopersFastInterrupt::routeToHyp(ThreadContext *tc) const
131410037SARM gem5 Developers{
131510037SARM gem5 Developers    bool toHyp;
131610037SARM gem5 Developers
131710037SARM gem5 Developers    SCR  scr  = tc->readMiscRegNoEffect(MISCREG_SCR);
131810037SARM gem5 Developers    HCR  hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
131910037SARM gem5 Developers    CPSR cpsr = tc->readMiscRegNoEffect(MISCREG_CPSR);
132010037SARM gem5 Developers    // Determine whether IRQs are routed to Hyp mode.
132111581SDylan.Johnson@ARM.com    toHyp = (!scr.fiq && hcr.fmo && !inSecureState(tc)) ||
132210037SARM gem5 Developers            (cpsr.mode == MODE_HYP);
132310037SARM gem5 Developers    return toHyp;
132410037SARM gem5 Developers}
132510037SARM gem5 Developers
132610037SARM gem5 Developersbool
132710037SARM gem5 DevelopersFastInterrupt::abortDisable(ThreadContext *tc)
132810037SARM gem5 Developers{
132910037SARM gem5 Developers    if (ArmSystem::haveSecurity(tc)) {
133010037SARM gem5 Developers        SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR);
133110037SARM gem5 Developers        return (!scr.ns || scr.aw);
133210037SARM gem5 Developers    }
133310037SARM gem5 Developers    return true;
133410037SARM gem5 Developers}
133510037SARM gem5 Developers
133610037SARM gem5 Developersbool
133710037SARM gem5 DevelopersFastInterrupt::fiqDisable(ThreadContext *tc)
133810037SARM gem5 Developers{
133910037SARM gem5 Developers    if (ArmSystem::haveVirtualization(tc)) {
134010037SARM gem5 Developers        return true;
134110037SARM gem5 Developers    } else if (ArmSystem::haveSecurity(tc)) {
134210037SARM gem5 Developers        SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR);
134310037SARM gem5 Developers        return (!scr.ns || scr.fw);
134410037SARM gem5 Developers    }
134510037SARM gem5 Developers    return true;
134610037SARM gem5 Developers}
134710037SARM gem5 Developers
134810037SARM gem5 DevelopersVirtualFastInterrupt::VirtualFastInterrupt()
134910037SARM gem5 Developers{}
135010037SARM gem5 Developers
135110037SARM gem5 Developersvoid
135210417Sandreas.hansson@arm.comPCAlignmentFault::invoke(ThreadContext *tc, const StaticInstPtr &inst)
135310037SARM gem5 Developers{
135410037SARM gem5 Developers    ArmFaultVals<PCAlignmentFault>::invoke(tc, inst);
135510037SARM gem5 Developers    assert(from64);
135610037SARM gem5 Developers    // Set the FAR
135710037SARM gem5 Developers    tc->setMiscReg(getFaultAddrReg64(), faultPC);
135810037SARM gem5 Developers}
135910037SARM gem5 Developers
136010037SARM gem5 DevelopersSPAlignmentFault::SPAlignmentFault()
136110037SARM gem5 Developers{}
136210037SARM gem5 Developers
136310037SARM gem5 DevelopersSystemError::SystemError()
136410037SARM gem5 Developers{}
136510037SARM gem5 Developers
136610037SARM gem5 Developersvoid
136710417Sandreas.hansson@arm.comSystemError::invoke(ThreadContext *tc, const StaticInstPtr &inst)
136810037SARM gem5 Developers{
136911150Smitch.hayenga@arm.com    tc->getCpuPtr()->clearInterrupt(tc->threadId(), INT_ABT, 0);
137010037SARM gem5 Developers    ArmFault::invoke(tc, inst);
137110037SARM gem5 Developers}
137210037SARM gem5 Developers
137310037SARM gem5 Developersbool
137410037SARM gem5 DevelopersSystemError::routeToMonitor(ThreadContext *tc) const
137510037SARM gem5 Developers{
137610037SARM gem5 Developers    assert(ArmSystem::haveSecurity(tc));
137710037SARM gem5 Developers    assert(from64);
137810037SARM gem5 Developers    SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR_EL3);
137910037SARM gem5 Developers    return scr.ea;
138010037SARM gem5 Developers}
138110037SARM gem5 Developers
138210037SARM gem5 Developersbool
138310037SARM gem5 DevelopersSystemError::routeToHyp(ThreadContext *tc) const
138410037SARM gem5 Developers{
138510037SARM gem5 Developers    bool toHyp;
138610037SARM gem5 Developers    assert(from64);
138710037SARM gem5 Developers
138810037SARM gem5 Developers    SCR scr = tc->readMiscRegNoEffect(MISCREG_SCR_EL3);
138910037SARM gem5 Developers    HCR hcr  = tc->readMiscRegNoEffect(MISCREG_HCR);
139010037SARM gem5 Developers
139111581SDylan.Johnson@ARM.com    toHyp = (!scr.ea && hcr.amo && !inSecureState(tc)) ||
139211581SDylan.Johnson@ARM.com            (!scr.ea && !scr.rw && !hcr.amo && !inSecureState(tc));
139310037SARM gem5 Developers    return toHyp;
13947362Sgblack@eecs.umich.edu}
13957362Sgblack@eecs.umich.edu
13967652Sminkyu.jeong@arm.comvoid
139710417Sandreas.hansson@arm.comArmSev::invoke(ThreadContext *tc, const StaticInstPtr &inst) {
13988518Sgeoffrey.blake@arm.com    DPRINTF(Faults, "Invoking ArmSev Fault\n");
13998806Sgblack@eecs.umich.edu    if (!FullSystem)
14008806Sgblack@eecs.umich.edu        return;
14018806Sgblack@eecs.umich.edu
14028806Sgblack@eecs.umich.edu    // Set sev_mailbox to 1, clear the pending interrupt from remote
14038806Sgblack@eecs.umich.edu    // SEV execution and let pipeline continue as pcState is still
14048806Sgblack@eecs.umich.edu    // valid.
14058806Sgblack@eecs.umich.edu    tc->setMiscReg(MISCREG_SEV_MAILBOX, 1);
140611150Smitch.hayenga@arm.com    tc->getCpuPtr()->clearInterrupt(tc->threadId(), INT_SEV, 0);
14078518Sgeoffrey.blake@arm.com}
14088518Sgeoffrey.blake@arm.com
140910037SARM gem5 Developers// Instantiate all the templates to make the linker happy
141010037SARM gem5 Developerstemplate class ArmFaultVals<Reset>;
141110037SARM gem5 Developerstemplate class ArmFaultVals<UndefinedInstruction>;
141210037SARM gem5 Developerstemplate class ArmFaultVals<SupervisorCall>;
141310037SARM gem5 Developerstemplate class ArmFaultVals<SecureMonitorCall>;
141410037SARM gem5 Developerstemplate class ArmFaultVals<HypervisorCall>;
141510037SARM gem5 Developerstemplate class ArmFaultVals<PrefetchAbort>;
141610037SARM gem5 Developerstemplate class ArmFaultVals<DataAbort>;
141710037SARM gem5 Developerstemplate class ArmFaultVals<VirtualDataAbort>;
141810037SARM gem5 Developerstemplate class ArmFaultVals<HypervisorTrap>;
141910037SARM gem5 Developerstemplate class ArmFaultVals<Interrupt>;
142010037SARM gem5 Developerstemplate class ArmFaultVals<VirtualInterrupt>;
142110037SARM gem5 Developerstemplate class ArmFaultVals<FastInterrupt>;
142210037SARM gem5 Developerstemplate class ArmFaultVals<VirtualFastInterrupt>;
142310037SARM gem5 Developerstemplate class ArmFaultVals<SupervisorTrap>;
142410037SARM gem5 Developerstemplate class ArmFaultVals<SecureMonitorTrap>;
142510037SARM gem5 Developerstemplate class ArmFaultVals<PCAlignmentFault>;
142610037SARM gem5 Developerstemplate class ArmFaultVals<SPAlignmentFault>;
142710037SARM gem5 Developerstemplate class ArmFaultVals<SystemError>;
142810037SARM gem5 Developerstemplate class ArmFaultVals<ArmSev>;
142910037SARM gem5 Developerstemplate class AbortFault<PrefetchAbort>;
143010037SARM gem5 Developerstemplate class AbortFault<DataAbort>;
143110037SARM gem5 Developerstemplate class AbortFault<VirtualDataAbort>;
143210037SARM gem5 Developers
143310037SARM gem5 Developers
143410037SARM gem5 DevelopersIllegalInstSetStateFault::IllegalInstSetStateFault()
143510037SARM gem5 Developers{}
143610037SARM gem5 Developers
14376019Shines@cs.fsu.edu
14386019Shines@cs.fsu.edu} // namespace ArmISA
1439