isa.cc revision 13582
16019Shines@cs.fsu.edu/*
211496Sandreas.sandberg@arm.com * Copyright (c) 2010-2018 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 * Redistribution and use in source and binary forms, with or without
156019Shines@cs.fsu.edu * modification, are permitted provided that the following conditions are
166019Shines@cs.fsu.edu * met: redistributions of source code must retain the above copyright
176019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer;
186019Shines@cs.fsu.edu * redistributions in binary form must reproduce the above copyright
196019Shines@cs.fsu.edu * notice, this list of conditions and the following disclaimer in the
206019Shines@cs.fsu.edu * documentation and/or other materials provided with the distribution;
216019Shines@cs.fsu.edu * neither the name of the copyright holders nor the names of its
226019Shines@cs.fsu.edu * contributors may be used to endorse or promote products derived from
236019Shines@cs.fsu.edu * this software without specific prior written permission.
246019Shines@cs.fsu.edu *
256019Shines@cs.fsu.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
266019Shines@cs.fsu.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
276019Shines@cs.fsu.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
286019Shines@cs.fsu.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
296019Shines@cs.fsu.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
306019Shines@cs.fsu.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
316019Shines@cs.fsu.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326019Shines@cs.fsu.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
336019Shines@cs.fsu.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
346019Shines@cs.fsu.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
356019Shines@cs.fsu.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
366019Shines@cs.fsu.edu *
376019Shines@cs.fsu.edu * Authors: Gabe Black
386019Shines@cs.fsu.edu *          Ali Saidi
396019Shines@cs.fsu.edu */
406019Shines@cs.fsu.edu
416735Sgblack@eecs.umich.edu#include "arch/arm/isa.hh"
426735Sgblack@eecs.umich.edu#include "arch/arm/pmu.hh"
4310037SARM gem5 Developers#include "arch/arm/system.hh"
4410037SARM gem5 Developers#include "arch/arm/tlb.hh"
456019Shines@cs.fsu.edu#include "arch/arm/tlbi_op.hh"
466019Shines@cs.fsu.edu#include "cpu/base.hh"
476019Shines@cs.fsu.edu#include "cpu/checker/cpu.hh"
4811793Sbrandon.potter@amd.com#include "debug/Arm.hh"
4911793Sbrandon.potter@amd.com#include "debug/MiscRegs.hh"
5010037SARM gem5 Developers#include "dev/arm/generic_timer.hh"
5110037SARM gem5 Developers#include "dev/arm/gic_v3.hh"
5210037SARM gem5 Developers#include "dev/arm/gic_v3_cpu_interface.hh"
538229Snate@binkert.org#include "params/ArmISA.hh"
548229Snate@binkert.org#include "sim/faults.hh"
556019Shines@cs.fsu.edu#include "sim/stat_control.hh"
568232Snate@binkert.org#include "sim/system.hh"
578782Sgblack@eecs.umich.edu
586019Shines@cs.fsu.edunamespace ArmISA
596019Shines@cs.fsu.edu{
606019Shines@cs.fsu.edu
616019Shines@cs.fsu.eduISA::ISA(Params *p)
6210037SARM gem5 Developers    : SimObject(p),
6310037SARM gem5 Developers      system(NULL),
6410037SARM gem5 Developers      _decoderFlavour(p->decoderFlavour),
6510037SARM gem5 Developers      _vecRegRenameMode(p->vecRegRenameMode),
6610037SARM gem5 Developers      pmu(p->pmu),
6710037SARM gem5 Developers      impdefAsNop(p->impdef_nop)
6810037SARM gem5 Developers{
6910037SARM gem5 Developers    miscRegs[MISCREG_SCTLR_RST] = 0;
7010037SARM gem5 Developers
7110037SARM gem5 Developers    // Hook up a dummy device if we haven't been configured with a
7210037SARM gem5 Developers    // real PMU. By using a dummy device, we don't need to check that
7310037SARM gem5 Developers    // the PMU exist every time we try to access a PMU register.
7410037SARM gem5 Developers    if (!pmu)
7510037SARM gem5 Developers        pmu = &dummyDevice;
7610037SARM gem5 Developers
7710037SARM gem5 Developers    // Give all ISA devices a pointer to this ISA
7810037SARM gem5 Developers    pmu->setISA(this);
7910037SARM gem5 Developers
8010037SARM gem5 Developers    system = dynamic_cast<ArmSystem *>(p->system);
8110037SARM gem5 Developers
8210037SARM gem5 Developers    // Cache system-level properties
8310037SARM gem5 Developers    if (FullSystem && system) {
8410037SARM gem5 Developers        highestELIs64 = system->highestELIs64();
8510037SARM gem5 Developers        haveSecurity = system->haveSecurity();
8610037SARM gem5 Developers        haveLPAE = system->haveLPAE();
8710037SARM gem5 Developers        haveCrypto = system->haveCrypto();
8810037SARM gem5 Developers        haveVirtualization = system->haveVirtualization();
8910037SARM gem5 Developers        haveLargeAsid64 = system->haveLargeAsid64();
9010037SARM gem5 Developers        physAddrRange = system->physAddrRange();
9110037SARM gem5 Developers    } else {
9210037SARM gem5 Developers        highestELIs64 = true; // ArmSystem::highestELIs64 does the same
9310037SARM gem5 Developers        haveSecurity = haveLPAE = haveVirtualization = false;
9410037SARM gem5 Developers        haveCrypto = true;
9510037SARM gem5 Developers        haveLargeAsid64 = false;
9610037SARM gem5 Developers        physAddrRange = 32;  // dummy value
9710037SARM gem5 Developers    }
9810037SARM gem5 Developers
9910037SARM gem5 Developers    // GICv3 CPU interface system registers are supported
10010037SARM gem5 Developers    haveGICv3CPUInterface = false;
10110037SARM gem5 Developers
1026019Shines@cs.fsu.edu    if (system && dynamic_cast<Gicv3 *>(system->getGIC())) {
10310037SARM gem5 Developers        haveGICv3CPUInterface = true;
10410037SARM gem5 Developers    }
10510037SARM gem5 Developers
1066019Shines@cs.fsu.edu    initializeMiscRegMetadata();
10710037SARM gem5 Developers    preUnflattenMiscReg();
10810037SARM gem5 Developers
10910037SARM gem5 Developers    clear();
11010037SARM gem5 Developers}
11110037SARM gem5 Developers
11210037SARM gem5 Developersstd::vector<struct ISA::MiscRegLUTEntry> ISA::lookUpMiscReg(NUM_MISCREGS);
11310037SARM gem5 Developers
11410037SARM gem5 Developersconst ArmISAParams *
11510037SARM gem5 DevelopersISA::params() const
11610037SARM gem5 Developers{
11710037SARM gem5 Developers    return dynamic_cast<const Params *>(_params);
11810037SARM gem5 Developers}
11910037SARM gem5 Developers
12010037SARM gem5 Developersvoid
12110037SARM gem5 DevelopersISA::clear()
12210037SARM gem5 Developers{
12310037SARM gem5 Developers    const Params *p(params());
12410037SARM gem5 Developers
12510037SARM gem5 Developers    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
12610037SARM gem5 Developers    memset(miscRegs, 0, sizeof(miscRegs));
12710037SARM gem5 Developers
12810037SARM gem5 Developers    initID32(p);
12910037SARM gem5 Developers
13010037SARM gem5 Developers    // We always initialize AArch64 ID registers even
13110037SARM gem5 Developers    // if we are in AArch32. This is done since if we
13210037SARM gem5 Developers    // are in SE mode we don't know if our ArmProcess is
13310037SARM gem5 Developers    // AArch32 or AArch64
13410037SARM gem5 Developers    initID64(p);
13510037SARM gem5 Developers
13610037SARM gem5 Developers    // Start with an event in the mailbox
13710037SARM gem5 Developers    miscRegs[MISCREG_SEV_MAILBOX] = 1;
13810037SARM gem5 Developers
13910037SARM gem5 Developers    // Separate Instruction and Data TLBs
14010037SARM gem5 Developers    miscRegs[MISCREG_TLBTR] = 1;
14110037SARM gem5 Developers
14210037SARM gem5 Developers    MVFR0 mvfr0 = 0;
14310037SARM gem5 Developers    mvfr0.advSimdRegisters = 2;
14410037SARM gem5 Developers    mvfr0.singlePrecision = 2;
14510037SARM gem5 Developers    mvfr0.doublePrecision = 2;
14610037SARM gem5 Developers    mvfr0.vfpExceptionTrapping = 0;
1476019Shines@cs.fsu.edu    mvfr0.divide = 1;
14810037SARM gem5 Developers    mvfr0.squareRoot = 1;
14910037SARM gem5 Developers    mvfr0.shortVectors = 1;
15010037SARM gem5 Developers    mvfr0.roundingModes = 1;
1516019Shines@cs.fsu.edu    miscRegs[MISCREG_MVFR0] = mvfr0;
15210037SARM gem5 Developers
15310037SARM gem5 Developers    MVFR1 mvfr1 = 0;
15410037SARM gem5 Developers    mvfr1.flushToZero = 1;
15510037SARM gem5 Developers    mvfr1.defaultNaN = 1;
15610037SARM gem5 Developers    mvfr1.advSimdLoadStore = 1;
15710037SARM gem5 Developers    mvfr1.advSimdInteger = 1;
15810037SARM gem5 Developers    mvfr1.advSimdSinglePrecision = 1;
15910037SARM gem5 Developers    mvfr1.advSimdHalfPrecision = 1;
16010037SARM gem5 Developers    mvfr1.vfpHalfPrecision = 1;
16110037SARM gem5 Developers    miscRegs[MISCREG_MVFR1] = mvfr1;
16210037SARM gem5 Developers
16310037SARM gem5 Developers    // Reset values of PRRR and NMRR are implementation dependent
16410037SARM gem5 Developers
16510037SARM gem5 Developers    // @todo: PRRR and NMRR in secure state?
16610037SARM gem5 Developers    miscRegs[MISCREG_PRRR_NS] =
16710037SARM gem5 Developers        (1 << 19) | // 19
16810037SARM gem5 Developers        (0 << 18) | // 18
16910037SARM gem5 Developers        (0 << 17) | // 17
17010037SARM gem5 Developers        (1 << 16) | // 16
17110037SARM gem5 Developers        (2 << 14) | // 15:14
17210037SARM gem5 Developers        (0 << 12) | // 13:12
17310037SARM gem5 Developers        (2 << 10) | // 11:10
17410037SARM gem5 Developers        (2 << 8)  | // 9:8
17510037SARM gem5 Developers        (2 << 6)  | // 7:6
17610037SARM gem5 Developers        (2 << 4)  | // 5:4
17710037SARM gem5 Developers        (1 << 2)  | // 3:2
17810037SARM gem5 Developers        0;          // 1:0
17910037SARM gem5 Developers
18010037SARM gem5 Developers    miscRegs[MISCREG_NMRR_NS] =
18110037SARM gem5 Developers        (1 << 30) | // 31:30
18210037SARM gem5 Developers        (0 << 26) | // 27:26
18310037SARM gem5 Developers        (0 << 24) | // 25:24
18410037SARM gem5 Developers        (3 << 22) | // 23:22
18510037SARM gem5 Developers        (2 << 20) | // 21:20
18610037SARM gem5 Developers        (0 << 18) | // 19:18
18710037SARM gem5 Developers        (0 << 16) | // 17:16
18810037SARM gem5 Developers        (1 << 14) | // 15:14
18910037SARM gem5 Developers        (0 << 12) | // 13:12
19010037SARM gem5 Developers        (2 << 10) | // 11:10
19110037SARM gem5 Developers        (0 << 8)  | // 9:8
19210037SARM gem5 Developers        (3 << 6)  | // 7:6
1936019Shines@cs.fsu.edu        (2 << 4)  | // 5:4
19410037SARM gem5 Developers        (0 << 2)  | // 3:2
19510037SARM gem5 Developers        0;          // 1:0
19610037SARM gem5 Developers
1976019Shines@cs.fsu.edu    if (FullSystem && system->highestELIs64()) {
19810037SARM gem5 Developers        // Initialize AArch64 state
19910037SARM gem5 Developers        clear64(p);
20010037SARM gem5 Developers        return;
20110037SARM gem5 Developers    }
20210037SARM gem5 Developers
20310037SARM gem5 Developers    // Initialize AArch32 state...
20410037SARM gem5 Developers    clear32(p, sctlr_rst);
20510037SARM gem5 Developers}
20610037SARM gem5 Developers
20710037SARM gem5 Developersvoid
20810037SARM gem5 DevelopersISA::clear32(const ArmISAParams *p, const SCTLR &sctlr_rst)
20910037SARM gem5 Developers{
21010037SARM gem5 Developers    CPSR cpsr = 0;
21110037SARM gem5 Developers    cpsr.mode = MODE_USER;
21210037SARM gem5 Developers
21310037SARM gem5 Developers    if (FullSystem) {
21410037SARM gem5 Developers        miscRegs[MISCREG_MVBAR] = system->resetAddr();
21510037SARM gem5 Developers    }
21610037SARM gem5 Developers
21710037SARM gem5 Developers    miscRegs[MISCREG_CPSR] = cpsr;
21810037SARM gem5 Developers    updateRegMap(cpsr);
21910037SARM gem5 Developers
22010037SARM gem5 Developers    SCTLR sctlr = 0;
22110037SARM gem5 Developers    sctlr.te = (bool) sctlr_rst.te;
22210037SARM gem5 Developers    sctlr.nmfi = (bool) sctlr_rst.nmfi;
22310037SARM gem5 Developers    sctlr.v = (bool) sctlr_rst.v;
22410037SARM gem5 Developers    sctlr.u = 1;
22510037SARM gem5 Developers    sctlr.xp = 1;
22610037SARM gem5 Developers    sctlr.rao2 = 1;
22710037SARM gem5 Developers    sctlr.rao3 = 1;
22810037SARM gem5 Developers    sctlr.rao4 = 0xf;  // SCTLR[6:3]
22910037SARM gem5 Developers    sctlr.uci = 1;
23010037SARM gem5 Developers    sctlr.dze = 1;
23110037SARM gem5 Developers    miscRegs[MISCREG_SCTLR_NS] = sctlr;
23210037SARM gem5 Developers    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
23310037SARM gem5 Developers    miscRegs[MISCREG_HCPTR] = 0;
23410037SARM gem5 Developers
23510037SARM gem5 Developers    miscRegs[MISCREG_CPACR] = 0;
23610037SARM gem5 Developers
23710037SARM gem5 Developers    miscRegs[MISCREG_FPSID] = p->fpsid;
23810037SARM gem5 Developers
23910037SARM gem5 Developers    if (haveLPAE) {
24010037SARM gem5 Developers        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
24110037SARM gem5 Developers        ttbcr.eae = 0;
24210037SARM gem5 Developers        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
24310037SARM gem5 Developers        // Enforce consistency with system-level settings
24410037SARM gem5 Developers        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
24510037SARM gem5 Developers    }
24610037SARM gem5 Developers
24710037SARM gem5 Developers    if (haveSecurity) {
24810037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_S] = sctlr;
24910037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 0;
25010037SARM gem5 Developers        miscRegs[MISCREG_VBAR_S] = 0;
25110037SARM gem5 Developers    } else {
25210037SARM gem5 Developers        // we're always non-secure
25310037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 1;
25410037SARM gem5 Developers    }
25510037SARM gem5 Developers
25610037SARM gem5 Developers    //XXX We need to initialize the rest of the state.
25710037SARM gem5 Developers}
25810037SARM gem5 Developers
25910037SARM gem5 Developersvoid
26010037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p)
26110037SARM gem5 Developers{
26210037SARM gem5 Developers    CPSR cpsr = 0;
26310037SARM gem5 Developers    Addr rvbar = system->resetAddr();
26410037SARM gem5 Developers    switch (system->highestEL()) {
26510037SARM gem5 Developers        // Set initial EL to highest implemented EL using associated stack
26610037SARM gem5 Developers        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
26710037SARM gem5 Developers        // value
26810037SARM gem5 Developers      case EL3:
26910037SARM gem5 Developers        cpsr.mode = MODE_EL3H;
27010037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
27110037SARM gem5 Developers        break;
27210037SARM gem5 Developers      case EL2:
27310037SARM gem5 Developers        cpsr.mode = MODE_EL2H;
27410037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
27510037SARM gem5 Developers        break;
27610037SARM gem5 Developers      case EL1:
27710037SARM gem5 Developers        cpsr.mode = MODE_EL1H;
27810037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
27910037SARM gem5 Developers        break;
28010037SARM gem5 Developers      default:
28110037SARM gem5 Developers        panic("Invalid highest implemented exception level");
28210037SARM gem5 Developers        break;
28310037SARM gem5 Developers    }
28410037SARM gem5 Developers
28510037SARM gem5 Developers    // Initialize rest of CPSR
28610037SARM gem5 Developers    cpsr.daif = 0xf;  // Mask all interrupts
28710037SARM gem5 Developers    cpsr.ss = 0;
28810037SARM gem5 Developers    cpsr.il = 0;
28910037SARM gem5 Developers    miscRegs[MISCREG_CPSR] = cpsr;
29010037SARM gem5 Developers    updateRegMap(cpsr);
29110037SARM gem5 Developers
29210037SARM gem5 Developers    // Initialize other control registers
29310037SARM gem5 Developers    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
29410037SARM gem5 Developers    if (haveSecurity) {
29510037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830;
2966019Shines@cs.fsu.edu        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
29710037SARM gem5 Developers    } else if (haveVirtualization) {
2987362Sgblack@eecs.umich.edu        // also  MISCREG_SCTLR_EL2 (by mapping)
2996735Sgblack@eecs.umich.edu        miscRegs[MISCREG_HSCTLR] = 0x30c50830;
30010037SARM gem5 Developers    } else {
3016019Shines@cs.fsu.edu        // also  MISCREG_SCTLR_EL1 (by mapping)
30210037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init
30310037SARM gem5 Developers        // Always non-secure
3047400SAli.Saidi@ARM.com        miscRegs[MISCREG_SCR_EL3] = 1;
3056735Sgblack@eecs.umich.edu    }
3066735Sgblack@eecs.umich.edu}
30710037SARM gem5 Developers
3086735Sgblack@eecs.umich.eduvoid
30910037SARM gem5 DevelopersISA::initID32(const ArmISAParams *p)
31010037SARM gem5 Developers{
31110037SARM gem5 Developers    // Initialize configurable default values
31210037SARM gem5 Developers    miscRegs[MISCREG_MIDR] = p->midr;
3137400SAli.Saidi@ARM.com    miscRegs[MISCREG_MIDR_EL1] = p->midr;
31410037SARM gem5 Developers    miscRegs[MISCREG_VPIDR] = p->midr;
31510037SARM gem5 Developers
31610037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
31710037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
31810037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
31910037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
32010037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
32110037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
32210037SARM gem5 Developers
32310037SARM gem5 Developers    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
32410037SARM gem5 Developers    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
32510037SARM gem5 Developers    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
32610037SARM gem5 Developers    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
32710037SARM gem5 Developers
32810037SARM gem5 Developers    miscRegs[MISCREG_ID_ISAR5] = insertBits(
32910037SARM gem5 Developers        miscRegs[MISCREG_ID_ISAR5], 19, 4,
33010037SARM gem5 Developers        haveCrypto ? 0x1112 : 0x0);
3316019Shines@cs.fsu.edu}
3326019Shines@cs.fsu.edu
33310037SARM gem5 Developersvoid
33410037SARM gem5 DevelopersISA::initID64(const ArmISAParams *p)
33510037SARM gem5 Developers{
33610037SARM gem5 Developers    // Initialize configurable id registers
33710037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
33810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
33910037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
34010037SARM gem5 Developers        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
34110037SARM gem5 Developers        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
34211574SCurtis.Dunham@arm.com
34311574SCurtis.Dunham@arm.com    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
34411574SCurtis.Dunham@arm.com    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
34511574SCurtis.Dunham@arm.com    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
34610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
34710037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
34810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR2_EL1] = p->id_aa64mmfr2_el1;
34910037SARM gem5 Developers
35010037SARM gem5 Developers    miscRegs[MISCREG_ID_DFR0_EL1] =
35110037SARM gem5 Developers        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
35210037SARM gem5 Developers
35310037SARM gem5 Developers    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
35410037SARM gem5 Developers
35510037SARM gem5 Developers    // Enforce consistency with system-level settings...
35610037SARM gem5 Developers
35710037SARM gem5 Developers    // EL3
35810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
35910037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
36010037SARM gem5 Developers        haveSecurity ? 0x2 : 0x0);
36110037SARM gem5 Developers    // EL2
36210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
36310037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
36410037SARM gem5 Developers        haveVirtualization ? 0x2 : 0x0);
36510037SARM gem5 Developers    // Large ASID support
36610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
36710037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
36810037SARM gem5 Developers        haveLargeAsid64 ? 0x2 : 0x0);
36910037SARM gem5 Developers    // Physical address size
37010037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
37110037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
37210037SARM gem5 Developers        encodePhysAddrRange64(physAddrRange));
37310037SARM gem5 Developers    // Crypto
37410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = insertBits(
37510037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64ISAR0_EL1], 19, 4,
37610037SARM gem5 Developers        haveCrypto ? 0x1112 : 0x0);
37710037SARM gem5 Developers}
37810037SARM gem5 Developers
37910037SARM gem5 Developersvoid
38010037SARM gem5 DevelopersISA::startup(ThreadContext *tc)
38110037SARM gem5 Developers{
38210037SARM gem5 Developers    pmu->setThreadContext(tc);
38310037SARM gem5 Developers
38410037SARM gem5 Developers    if (system) {
38510037SARM gem5 Developers        Gicv3 *gicv3 = dynamic_cast<Gicv3 *>(system->getGIC());
38610037SARM gem5 Developers        if (gicv3) {
38710037SARM gem5 Developers            gicv3CpuInterface.reset(gicv3->getCPUInterface(tc->contextId()));
38810037SARM gem5 Developers            gicv3CpuInterface->setISA(this);
38910037SARM gem5 Developers        }
39010037SARM gem5 Developers    }
39110037SARM gem5 Developers}
39210037SARM gem5 Developers
39310037SARM gem5 Developers
39410037SARM gem5 DevelopersRegVal
39510037SARM gem5 DevelopersISA::readMiscRegNoEffect(int misc_reg) const
39610037SARM gem5 Developers{
39710037SARM gem5 Developers    assert(misc_reg < NumMiscRegs);
39810037SARM gem5 Developers
39910037SARM gem5 Developers    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
40010037SARM gem5 Developers    const auto &map = getMiscIndices(misc_reg);
40110037SARM gem5 Developers    int lower = map.first, upper = map.second;
40210037SARM gem5 Developers    // NB!: apply architectural masks according to desired register,
40310037SARM gem5 Developers    // despite possibly getting value from different (mapped) register.
40410037SARM gem5 Developers    auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32))
40510037SARM gem5 Developers                                          |(miscRegs[upper] << 32));
40610037SARM gem5 Developers    if (val & reg.res0()) {
40710037SARM gem5 Developers        DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n",
40810037SARM gem5 Developers                miscRegName[misc_reg], val & reg.res0());
40910037SARM gem5 Developers    }
41010037SARM gem5 Developers    if ((val & reg.res1()) != reg.res1()) {
41110037SARM gem5 Developers        DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n",
41210037SARM gem5 Developers                miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1());
41310037SARM gem5 Developers    }
41410037SARM gem5 Developers    return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao
41510037SARM gem5 Developers}
41610037SARM gem5 Developers
41710037SARM gem5 Developers
41810037SARM gem5 DevelopersRegVal
41910037SARM gem5 DevelopersISA::readMiscReg(int misc_reg, ThreadContext *tc)
42010037SARM gem5 Developers{
42110037SARM gem5 Developers    CPSR cpsr = 0;
42210037SARM gem5 Developers    PCState pc = 0;
42310037SARM gem5 Developers    SCR scr = 0;
42410037SARM gem5 Developers
42510037SARM gem5 Developers    if (misc_reg == MISCREG_CPSR) {
42610037SARM gem5 Developers        cpsr = miscRegs[misc_reg];
42710037SARM gem5 Developers        pc = tc->pcState();
42810037SARM gem5 Developers        cpsr.j = pc.jazelle() ? 1 : 0;
42910417Sandreas.hansson@arm.com        cpsr.t = pc.thumb() ? 1 : 0;
4306019Shines@cs.fsu.edu        return cpsr;
43110037SARM gem5 Developers    }
43210037SARM gem5 Developers
43310037SARM gem5 Developers#ifndef NDEBUG
43410037SARM gem5 Developers    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
43510037SARM gem5 Developers        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
43610037SARM gem5 Developers            warn("Unimplemented system register %s read.\n",
43710037SARM gem5 Developers                 miscRegName[misc_reg]);
43810037SARM gem5 Developers        else
43910037SARM gem5 Developers            panic("Unimplemented system register %s read.\n",
44010037SARM gem5 Developers                  miscRegName[misc_reg]);
44110037SARM gem5 Developers    }
44210037SARM gem5 Developers#endif
44311578SDylan.Johnson@ARM.com
44411578SDylan.Johnson@ARM.com    switch (unflattenMiscReg(misc_reg)) {
44510037SARM gem5 Developers      case MISCREG_HCR:
44610037SARM gem5 Developers        {
44710037SARM gem5 Developers            if (!haveVirtualization)
44810037SARM gem5 Developers                return 0;
44910037SARM gem5 Developers            else
45010037SARM gem5 Developers                return readMiscRegNoEffect(MISCREG_HCR);
45110037SARM gem5 Developers        }
45210037SARM gem5 Developers      case MISCREG_CPACR:
45310037SARM gem5 Developers        {
45410037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
45510037SARM gem5 Developers            CPACR cpacrMask = 0;
45610037SARM gem5 Developers            // Only cp10, cp11, and ase are implemented, nothing else should
45710037SARM gem5 Developers            // be readable? (straight copy from the write code)
45810037SARM gem5 Developers            cpacrMask.cp10 = ones;
45910037SARM gem5 Developers            cpacrMask.cp11 = ones;
46010037SARM gem5 Developers            cpacrMask.asedis = ones;
46110037SARM gem5 Developers
46210037SARM gem5 Developers            // Security Extensions may limit the readability of CPACR
4636735Sgblack@eecs.umich.edu            if (haveSecurity) {
4648782Sgblack@eecs.umich.edu                scr = readMiscRegNoEffect(MISCREG_SCR);
4658782Sgblack@eecs.umich.edu                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
4666735Sgblack@eecs.umich.edu                if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) {
4676019Shines@cs.fsu.edu                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
4686735Sgblack@eecs.umich.edu                    // NB: Skipping the full loop, here
46910037SARM gem5 Developers                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
4708303SAli.Saidi@ARM.com                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
47110338SCurtis.Dunham@arm.com                }
47210338SCurtis.Dunham@arm.com            }
47310338SCurtis.Dunham@arm.com            RegVal val = readMiscRegNoEffect(MISCREG_CPACR);
47410338SCurtis.Dunham@arm.com            val &= cpacrMask;
4758303SAli.Saidi@ARM.com            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
4767720Sgblack@eecs.umich.edu                    miscRegName[misc_reg], val);
4778205SAli.Saidi@ARM.com            return val;
4788205SAli.Saidi@ARM.com        }
4798205SAli.Saidi@ARM.com      case MISCREG_MPIDR:
4806735Sgblack@eecs.umich.edu      case MISCREG_MPIDR_EL1:
48110037SARM gem5 Developers        return readMPIDR(system, tc);
48210037SARM gem5 Developers      case MISCREG_VMPIDR:
48310037SARM gem5 Developers      case MISCREG_VMPIDR_EL2:
48410037SARM gem5 Developers        // top bit defined as RES1
48510037SARM gem5 Developers        return readMiscRegNoEffect(misc_reg) | 0x80000000;
48610037SARM gem5 Developers      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
48710037SARM gem5 Developers      case MISCREG_REVIDR:  // not implemented, so alias MIDR
48810037SARM gem5 Developers      case MISCREG_MIDR:
48910037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
49010037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
49110037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
49210037SARM gem5 Developers            return readMiscRegNoEffect(misc_reg);
49310037SARM gem5 Developers        } else {
49410037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_VPIDR);
49510037SARM gem5 Developers        }
49610037SARM gem5 Developers        break;
49710037SARM gem5 Developers      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
49810037SARM gem5 Developers      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
49910037SARM gem5 Developers      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
50010037SARM gem5 Developers      case MISCREG_AIDR:  // AUX ID set to 0
50110037SARM gem5 Developers      case MISCREG_TCMTR: // No TCM's
50210037SARM gem5 Developers        return 0;
50310037SARM gem5 Developers
50410037SARM gem5 Developers      case MISCREG_CLIDR:
50510037SARM gem5 Developers        warn_once("The clidr register always reports 0 caches.\n");
50610037SARM gem5 Developers        warn_once("clidr LoUIS field of 0b001 to match current "
50710037SARM gem5 Developers                  "ARM implementations.\n");
50810037SARM gem5 Developers        return 0x00200000;
50910037SARM gem5 Developers      case MISCREG_CCSIDR:
51010037SARM gem5 Developers        warn_once("The ccsidr register isn't implemented and "
51110037SARM gem5 Developers                "always reads as 0.\n");
51210037SARM gem5 Developers        break;
51310037SARM gem5 Developers      case MISCREG_CTR:                 // AArch32, ARMv7, top bit set
51410037SARM gem5 Developers      case MISCREG_CTR_EL0:             // AArch64
51510037SARM gem5 Developers        {
51610037SARM gem5 Developers            //all caches have the same line size in gem5
51710037SARM gem5 Developers            //4 byte words in ARM
51810037SARM gem5 Developers            unsigned lineSizeWords =
51910037SARM gem5 Developers                tc->getSystemPtr()->cacheLineSize() / 4;
52010037SARM gem5 Developers            unsigned log2LineSizeWords = 0;
52110037SARM gem5 Developers
52210037SARM gem5 Developers            while (lineSizeWords >>= 1) {
52310037SARM gem5 Developers                ++log2LineSizeWords;
52410037SARM gem5 Developers            }
52510037SARM gem5 Developers
52610037SARM gem5 Developers            CTR ctr = 0;
52710037SARM gem5 Developers            //log2 of minimun i-cache line size (words)
52810037SARM gem5 Developers            ctr.iCacheLineSize = log2LineSizeWords;
5296735Sgblack@eecs.umich.edu            //b11 - gem5 uses pipt
5306735Sgblack@eecs.umich.edu            ctr.l1IndexPolicy = 0x3;
5316735Sgblack@eecs.umich.edu            //log2 of minimum d-cache line size (words)
53210037SARM gem5 Developers            ctr.dCacheLineSize = log2LineSizeWords;
5338518Sgeoffrey.blake@arm.com            //log2 of max reservation size (words)
5348518Sgeoffrey.blake@arm.com            ctr.erg = log2LineSizeWords;
5356735Sgblack@eecs.umich.edu            //log2 of max writeback size (words)
53610037SARM gem5 Developers            ctr.cwg = log2LineSizeWords;
53710037SARM gem5 Developers            //b100 - gem5 format is ARMv7
53810037SARM gem5 Developers            ctr.format = 0x4;
53910037SARM gem5 Developers
54010037SARM gem5 Developers            return ctr;
54110037SARM gem5 Developers        }
54210037SARM gem5 Developers      case MISCREG_ACTLR:
54310037SARM gem5 Developers        warn("Not doing anything for miscreg ACTLR\n");
54410037SARM gem5 Developers        break;
54510037SARM gem5 Developers
54610037SARM gem5 Developers      case MISCREG_PMXEVTYPER_PMCCFILTR:
54710037SARM gem5 Developers      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
5486735Sgblack@eecs.umich.edu      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
5496735Sgblack@eecs.umich.edu      case MISCREG_PMCR ... MISCREG_PMOVSSET:
5506735Sgblack@eecs.umich.edu        return pmu->readMiscReg(misc_reg);
5516735Sgblack@eecs.umich.edu
5526735Sgblack@eecs.umich.edu      case MISCREG_CPSR_Q:
5536735Sgblack@eecs.umich.edu        panic("shouldn't be reading this register seperately\n");
5546735Sgblack@eecs.umich.edu      case MISCREG_FPSCR_QC:
5556735Sgblack@eecs.umich.edu        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
5566735Sgblack@eecs.umich.edu      case MISCREG_FPSCR_EXC:
55710037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
55810037SARM gem5 Developers      case MISCREG_FPSR:
55910037SARM gem5 Developers        {
5606735Sgblack@eecs.umich.edu            const uint32_t ones = (uint32_t)(-1);
5616735Sgblack@eecs.umich.edu            FPSCR fpscrMask = 0;
5626735Sgblack@eecs.umich.edu            fpscrMask.ioc = ones;
5636735Sgblack@eecs.umich.edu            fpscrMask.dzc = ones;
56410037SARM gem5 Developers            fpscrMask.ofc = ones;
56510037SARM gem5 Developers            fpscrMask.ufc = ones;
56610037SARM gem5 Developers            fpscrMask.ixc = ones;
56710037SARM gem5 Developers            fpscrMask.idc = ones;
56810037SARM gem5 Developers            fpscrMask.qc = ones;
56910037SARM gem5 Developers            fpscrMask.v = ones;
57010037SARM gem5 Developers            fpscrMask.c = ones;
57110037SARM gem5 Developers            fpscrMask.z = ones;
57210037SARM gem5 Developers            fpscrMask.n = ones;
57310037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
5746735Sgblack@eecs.umich.edu        }
5756735Sgblack@eecs.umich.edu      case MISCREG_FPCR:
5767093Sgblack@eecs.umich.edu        {
5777093Sgblack@eecs.umich.edu            const uint32_t ones = (uint32_t)(-1);
5787720Sgblack@eecs.umich.edu            FPSCR fpscrMask  = 0;
5797585SAli.Saidi@arm.com            fpscrMask.len    = ones;
5807720Sgblack@eecs.umich.edu            fpscrMask.stride = ones;
5817720Sgblack@eecs.umich.edu            fpscrMask.rMode  = ones;
5827720Sgblack@eecs.umich.edu            fpscrMask.fz     = ones;
5837720Sgblack@eecs.umich.edu            fpscrMask.dn     = ones;
5847720Sgblack@eecs.umich.edu            fpscrMask.ahp    = ones;
5857720Sgblack@eecs.umich.edu            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
58610037SARM gem5 Developers        }
58710037SARM gem5 Developers      case MISCREG_NZCV:
5887720Sgblack@eecs.umich.edu        {
5896019Shines@cs.fsu.edu            CPSR cpsr = 0;
5907189Sgblack@eecs.umich.edu            cpsr.nz   = tc->readCCReg(CCREG_NZ);
5917400SAli.Saidi@ARM.com            cpsr.c    = tc->readCCReg(CCREG_C);
59210417Sandreas.hansson@arm.com            cpsr.v    = tc->readCCReg(CCREG_V);
59310037SARM gem5 Developers            return cpsr;
59410037SARM gem5 Developers        }
59510037SARM gem5 Developers      case MISCREG_DAIF:
59610037SARM gem5 Developers        {
59710037SARM gem5 Developers            CPSR cpsr = 0;
59810037SARM gem5 Developers            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
59910037SARM gem5 Developers            return cpsr;
60010037SARM gem5 Developers        }
60111574SCurtis.Dunham@arm.com      case MISCREG_SP_EL0:
60211574SCurtis.Dunham@arm.com        {
60311574SCurtis.Dunham@arm.com            return tc->readIntReg(INTREG_SP0);
60411574SCurtis.Dunham@arm.com        }
60511574SCurtis.Dunham@arm.com      case MISCREG_SP_EL1:
60610037SARM gem5 Developers        {
60710037SARM gem5 Developers            return tc->readIntReg(INTREG_SP1);
60810037SARM gem5 Developers        }
60910037SARM gem5 Developers      case MISCREG_SP_EL2:
61010037SARM gem5 Developers        {
61110037SARM gem5 Developers            return tc->readIntReg(INTREG_SP2);
61210037SARM gem5 Developers        }
61310037SARM gem5 Developers      case MISCREG_SPSEL:
61410037SARM gem5 Developers        {
61510037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0x1;
61610037SARM gem5 Developers        }
61710037SARM gem5 Developers      case MISCREG_CURRENTEL:
61810037SARM gem5 Developers        {
61910338SCurtis.Dunham@arm.com            return miscRegs[MISCREG_CPSR] & 0xc;
62010338SCurtis.Dunham@arm.com        }
62110338SCurtis.Dunham@arm.com      case MISCREG_L2CTLR:
62210037SARM gem5 Developers        {
62310037SARM gem5 Developers            // mostly unimplemented, just set NumCPUs field from sim and return
62410037SARM gem5 Developers            L2CTLR l2ctlr = 0;
62510037SARM gem5 Developers            // b00:1CPU to b11:4CPUs
62610037SARM gem5 Developers            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
62710037SARM gem5 Developers            return l2ctlr;
62810037SARM gem5 Developers        }
62910037SARM gem5 Developers      case MISCREG_DBGDIDR:
63010037SARM gem5 Developers        /* For now just implement the version number.
63110037SARM gem5 Developers         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
63210338SCurtis.Dunham@arm.com         */
63310037SARM gem5 Developers        return 0x5 << 16;
63410037SARM gem5 Developers      case MISCREG_DBGDSCRint:
63510037SARM gem5 Developers        return 0;
63610037SARM gem5 Developers      case MISCREG_ISR:
63710037SARM gem5 Developers        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
63810037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR),
63910037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
64010037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR));
64110037SARM gem5 Developers      case MISCREG_ISR_EL1:
64210037SARM gem5 Developers        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
64310037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR_EL2),
64410037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
64510037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR_EL3));
64610037SARM gem5 Developers      case MISCREG_DCZID_EL0:
64710037SARM gem5 Developers        return 0x04;  // DC ZVA clear 64-byte chunks
64810037SARM gem5 Developers      case MISCREG_HCPTR:
64910037SARM gem5 Developers        {
65010037SARM gem5 Developers            RegVal val = readMiscRegNoEffect(misc_reg);
65110037SARM gem5 Developers            // The trap bit associated with CP14 is defined as RAZ
65210037SARM gem5 Developers            val &= ~(1 << 14);
65310037SARM gem5 Developers            // If a CP bit in NSACR is 0 then the corresponding bit in
65410037SARM gem5 Developers            // HCPTR is RAO/WI
65510037SARM gem5 Developers            bool secure_lookup = haveSecurity &&
65610037SARM gem5 Developers                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
65710037SARM gem5 Developers                              readMiscRegNoEffect(MISCREG_CPSR));
65810037SARM gem5 Developers            if (!secure_lookup) {
65910037SARM gem5 Developers                RegVal mask = readMiscRegNoEffect(MISCREG_NSACR);
66010037SARM gem5 Developers                val |= (mask ^ 0x7FFF) & 0xBFFF;
66110037SARM gem5 Developers            }
66210037SARM gem5 Developers            // Set the bits for unimplemented coprocessors to RAO/WI
66310037SARM gem5 Developers            val |= 0x33FF;
66410037SARM gem5 Developers            return (val);
66510037SARM gem5 Developers        }
66610037SARM gem5 Developers      case MISCREG_HDFAR: // alias for secure DFAR
66710037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_DFAR_S);
66810037SARM gem5 Developers      case MISCREG_HIFAR: // alias for secure IFAR
66910037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_IFAR_S);
67010037SARM gem5 Developers
67110037SARM gem5 Developers      case MISCREG_ID_PFR0:
67210037SARM gem5 Developers        // !ThumbEE | !Jazelle | Thumb | ARM
67310037SARM gem5 Developers        return 0x00000031;
67410037SARM gem5 Developers      case MISCREG_ID_PFR1:
67510037SARM gem5 Developers        {   // Timer | Virti | !M Profile | TrustZone | ARMv4
67610037SARM gem5 Developers            bool haveTimer = (system->getGenericTimer() != NULL);
67710037SARM gem5 Developers            return 0x00000001
67810037SARM gem5 Developers                 | (haveSecurity       ? 0x00000010 : 0x0)
67910037SARM gem5 Developers                 | (haveVirtualization ? 0x00001000 : 0x0)
68010037SARM gem5 Developers                 | (haveTimer          ? 0x00010000 : 0x0);
68110037SARM gem5 Developers        }
68210417Sandreas.hansson@arm.com      case MISCREG_ID_AA64PFR0_EL1:
6837400SAli.Saidi@ARM.com        return 0x0000000000000002 | // AArch{64,32} supported at EL0
6848782Sgblack@eecs.umich.edu               0x0000000000000020                               | // EL1
68511150Smitch.hayenga@arm.com               (haveVirtualization    ? 0x0000000000000200 : 0) | // EL2
6868782Sgblack@eecs.umich.edu               (haveSecurity          ? 0x0000000000002000 : 0) | // EL3
6878782Sgblack@eecs.umich.edu               (haveGICv3CPUInterface ? 0x0000000001000000 : 0);
68810037SARM gem5 Developers      case MISCREG_ID_AA64PFR1_EL1:
68910037SARM gem5 Developers        return 0; // bits [63:0] RES0 (reserved for future use)
69010037SARM gem5 Developers
69110037SARM gem5 Developers      // Generic Timer registers
69210037SARM gem5 Developers      case MISCREG_CNTHV_CTL_EL2:
69310037SARM gem5 Developers      case MISCREG_CNTHV_CVAL_EL2:
69410037SARM gem5 Developers      case MISCREG_CNTHV_TVAL_EL2:
69510037SARM gem5 Developers      case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
69610037SARM gem5 Developers      case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
69710037SARM gem5 Developers      case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
69810037SARM gem5 Developers      case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
69910037SARM gem5 Developers        return getGenericTimer(tc).readMiscReg(misc_reg);
70010037SARM gem5 Developers
70110037SARM gem5 Developers      case MISCREG_ICC_PMR_EL1 ... MISCREG_ICC_IGRPEN1_EL3:
70210037SARM gem5 Developers      case MISCREG_ICH_AP0R0_EL2 ... MISCREG_ICH_LR15_EL2:
70310037SARM gem5 Developers        return getGICv3CPUInterface(tc).readMiscReg(misc_reg);
70410037SARM gem5 Developers
70510037SARM gem5 Developers      default:
70610037SARM gem5 Developers        break;
7077400SAli.Saidi@ARM.com
7087400SAli.Saidi@ARM.com    }
7097189Sgblack@eecs.umich.edu    return readMiscRegNoEffect(misc_reg);
71010417Sandreas.hansson@arm.com}
7117189Sgblack@eecs.umich.edu
7128782Sgblack@eecs.umich.eduvoid
7138782Sgblack@eecs.umich.eduISA::setMiscRegNoEffect(int misc_reg, RegVal val)
7148806Sgblack@eecs.umich.edu{
7158806Sgblack@eecs.umich.edu    assert(misc_reg < NumMiscRegs);
7168806Sgblack@eecs.umich.edu
7178806Sgblack@eecs.umich.edu    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
7188806Sgblack@eecs.umich.edu    const auto &map = getMiscIndices(misc_reg);
7198806Sgblack@eecs.umich.edu    int lower = map.first, upper = map.second;
7208806Sgblack@eecs.umich.edu
7218806Sgblack@eecs.umich.edu    auto v = (val & ~reg.wi()) | reg.rao();
7228806Sgblack@eecs.umich.edu    if (upper > 0) {
7238806Sgblack@eecs.umich.edu        miscRegs[lower] = bits(v, 31, 0);
7248806Sgblack@eecs.umich.edu        miscRegs[upper] = bits(v, 63, 32);
7257189Sgblack@eecs.umich.edu        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
7268806Sgblack@eecs.umich.edu                misc_reg, lower, upper, v);
7278806Sgblack@eecs.umich.edu    } else {
7287189Sgblack@eecs.umich.edu        miscRegs[lower] = v;
7297189Sgblack@eecs.umich.edu        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
7307189Sgblack@eecs.umich.edu                misc_reg, lower, v);
73110037SARM gem5 Developers    }
73210037SARM gem5 Developers}
73310037SARM gem5 Developers
73410037SARM gem5 Developersvoid
73510037SARM gem5 DevelopersISA::setMiscReg(int misc_reg, RegVal val, ThreadContext *tc)
73610037SARM gem5 Developers{
73710037SARM gem5 Developers
73810037SARM gem5 Developers    RegVal newVal = val;
73910037SARM gem5 Developers    bool secure_lookup;
74010037SARM gem5 Developers    SCR scr;
74110037SARM gem5 Developers
74210037SARM gem5 Developers    if (misc_reg == MISCREG_CPSR) {
74310037SARM gem5 Developers        updateRegMap(val);
74410037SARM gem5 Developers
74510037SARM gem5 Developers
74610037SARM gem5 Developers        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
74710037SARM gem5 Developers        int old_mode = old_cpsr.mode;
74810037SARM gem5 Developers        CPSR cpsr = val;
74910037SARM gem5 Developers        if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) {
75010037SARM gem5 Developers            getITBPtr(tc)->invalidateMiscReg();
75110037SARM gem5 Developers            getDTBPtr(tc)->invalidateMiscReg();
75210037SARM gem5 Developers        }
75310037SARM gem5 Developers
75410037SARM gem5 Developers        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
75510037SARM gem5 Developers                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
75610037SARM gem5 Developers        PCState pc = tc->pcState();
75710037SARM gem5 Developers        pc.nextThumb(cpsr.t);
75810037SARM gem5 Developers        pc.nextJazelle(cpsr.j);
75910037SARM gem5 Developers        pc.illegalExec(cpsr.il == 1);
76010037SARM gem5 Developers
76110037SARM gem5 Developers        // Follow slightly different semantics if a CheckerCPU object
76210037SARM gem5 Developers        // is connected
76310037SARM gem5 Developers        CheckerCPU *checker = tc->getCheckerCpuPtr();
76410037SARM gem5 Developers        if (checker) {
76510037SARM gem5 Developers            tc->pcStateNoRecord(pc);
76610037SARM gem5 Developers        } else {
76710037SARM gem5 Developers            tc->pcState(pc);
76810037SARM gem5 Developers        }
76910037SARM gem5 Developers    } else {
7707197Sgblack@eecs.umich.edu#ifndef NDEBUG
77110417Sandreas.hansson@arm.com        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
7727197Sgblack@eecs.umich.edu            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
7738782Sgblack@eecs.umich.edu                warn("Unimplemented system register %s write with %#x.\n",
7748782Sgblack@eecs.umich.edu                    miscRegName[misc_reg], val);
7758806Sgblack@eecs.umich.edu            else
7768806Sgblack@eecs.umich.edu                panic("Unimplemented system register %s write with %#x.\n",
7777197Sgblack@eecs.umich.edu                    miscRegName[misc_reg], val);
7788806Sgblack@eecs.umich.edu        }
7798806Sgblack@eecs.umich.edu#endif
7808806Sgblack@eecs.umich.edu        switch (unflattenMiscReg(misc_reg)) {
78110037SARM gem5 Developers          case MISCREG_CPACR:
78210037SARM gem5 Developers            {
78310037SARM gem5 Developers
78410037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
78510037SARM gem5 Developers                CPACR cpacrMask = 0;
78610037SARM gem5 Developers                // Only cp10, cp11, and ase are implemented, nothing else should
78711877Sbrandon.potter@amd.com                // be writable
78811877Sbrandon.potter@amd.com                cpacrMask.cp10 = ones;
7898806Sgblack@eecs.umich.edu                cpacrMask.cp11 = ones;
7908806Sgblack@eecs.umich.edu                cpacrMask.asedis = ones;
7918806Sgblack@eecs.umich.edu
7928806Sgblack@eecs.umich.edu                // Security Extensions may limit the writability of CPACR
7938806Sgblack@eecs.umich.edu                if (haveSecurity) {
7948806Sgblack@eecs.umich.edu                    scr = readMiscRegNoEffect(MISCREG_SCR);
7957197Sgblack@eecs.umich.edu                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
7967197Sgblack@eecs.umich.edu                    if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) {
79710037SARM gem5 Developers                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
79810037SARM gem5 Developers                        // NB: Skipping the full loop, here
79910037SARM gem5 Developers                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
80010037SARM gem5 Developers                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
80110037SARM gem5 Developers                    }
80210037SARM gem5 Developers                }
80310037SARM gem5 Developers
80410037SARM gem5 Developers                RegVal old_val = readMiscRegNoEffect(MISCREG_CPACR);
80510037SARM gem5 Developers                newVal &= cpacrMask;
80610037SARM gem5 Developers                newVal |= old_val & ~cpacrMask;
80710037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
80810037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
80910037SARM gem5 Developers            }
81010037SARM gem5 Developers            break;
81110037SARM gem5 Developers          case MISCREG_CPTR_EL2:
81210037SARM gem5 Developers            {
81310037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
81410037SARM gem5 Developers                CPTR cptrMask = 0;
81510037SARM gem5 Developers                cptrMask.tcpac = ones;
81610037SARM gem5 Developers                cptrMask.tta = ones;
81710037SARM gem5 Developers                cptrMask.tfp = ones;
81810037SARM gem5 Developers                newVal &= cptrMask;
81910037SARM gem5 Developers                cptrMask = 0;
82010037SARM gem5 Developers                cptrMask.res1_13_12_el2 = ones;
82110037SARM gem5 Developers                cptrMask.res1_9_0_el2 = ones;
82210037SARM gem5 Developers                newVal |= cptrMask;
82310037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
82410037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
82510037SARM gem5 Developers            }
82610037SARM gem5 Developers            break;
82710037SARM gem5 Developers          case MISCREG_CPTR_EL3:
82810037SARM gem5 Developers            {
82910037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
83010037SARM gem5 Developers                CPTR cptrMask = 0;
83110037SARM gem5 Developers                cptrMask.tcpac = ones;
83210037SARM gem5 Developers                cptrMask.tta = ones;
83310037SARM gem5 Developers                cptrMask.tfp = ones;
83410037SARM gem5 Developers                newVal &= cptrMask;
83510037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
83610037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
83710037SARM gem5 Developers            }
83810037SARM gem5 Developers            break;
83910037SARM gem5 Developers          case MISCREG_CSSELR:
84010037SARM gem5 Developers            warn_once("The csselr register isn't implemented.\n");
84110037SARM gem5 Developers            return;
84210037SARM gem5 Developers
84310037SARM gem5 Developers          case MISCREG_DC_ZVA_Xt:
84410037SARM gem5 Developers            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
84510037SARM gem5 Developers            return;
84610037SARM gem5 Developers
84710037SARM gem5 Developers          case MISCREG_FPSCR:
84811576SDylan.Johnson@ARM.com            {
84911576SDylan.Johnson@ARM.com                const uint32_t ones = (uint32_t)(-1);
85011576SDylan.Johnson@ARM.com                FPSCR fpscrMask = 0;
85111576SDylan.Johnson@ARM.com                fpscrMask.ioc = ones;
85211576SDylan.Johnson@ARM.com                fpscrMask.dzc = ones;
85311576SDylan.Johnson@ARM.com                fpscrMask.ofc = ones;
85410037SARM gem5 Developers                fpscrMask.ufc = ones;
85510037SARM gem5 Developers                fpscrMask.ixc = ones;
85610037SARM gem5 Developers                fpscrMask.idc = ones;
85710037SARM gem5 Developers                fpscrMask.ioe = ones;
85810037SARM gem5 Developers                fpscrMask.dze = ones;
85910037SARM gem5 Developers                fpscrMask.ofe = ones;
86010037SARM gem5 Developers                fpscrMask.ufe = ones;
86110037SARM gem5 Developers                fpscrMask.ixe = ones;
86210037SARM gem5 Developers                fpscrMask.ide = ones;
86310037SARM gem5 Developers                fpscrMask.len = ones;
86410037SARM gem5 Developers                fpscrMask.stride = ones;
86510037SARM gem5 Developers                fpscrMask.rMode = ones;
86610037SARM gem5 Developers                fpscrMask.fz = ones;
86710037SARM gem5 Developers                fpscrMask.dn = ones;
86810037SARM gem5 Developers                fpscrMask.ahp = ones;
86910037SARM gem5 Developers                fpscrMask.qc = ones;
87010037SARM gem5 Developers                fpscrMask.v = ones;
87110037SARM gem5 Developers                fpscrMask.c = ones;
87210037SARM gem5 Developers                fpscrMask.z = ones;
87310037SARM gem5 Developers                fpscrMask.n = ones;
87410037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
87510037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
87610037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
87710037SARM gem5 Developers                tc->getDecoderPtr()->setContext(newVal);
87810037SARM gem5 Developers            }
87910037SARM gem5 Developers            break;
88010037SARM gem5 Developers          case MISCREG_FPSR:
88110037SARM gem5 Developers            {
88210037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
88310037SARM gem5 Developers                FPSCR fpscrMask = 0;
88410037SARM gem5 Developers                fpscrMask.ioc = ones;
88510037SARM gem5 Developers                fpscrMask.dzc = ones;
88610037SARM gem5 Developers                fpscrMask.ofc = ones;
88710037SARM gem5 Developers                fpscrMask.ufc = ones;
88810037SARM gem5 Developers                fpscrMask.ixc = ones;
88910037SARM gem5 Developers                fpscrMask.idc = ones;
89010037SARM gem5 Developers                fpscrMask.qc = ones;
89110037SARM gem5 Developers                fpscrMask.v = ones;
89210037SARM gem5 Developers                fpscrMask.c = ones;
89310037SARM gem5 Developers                fpscrMask.z = ones;
89410037SARM gem5 Developers                fpscrMask.n = ones;
89510417Sandreas.hansson@arm.com                newVal = (newVal & (uint32_t)fpscrMask) |
89610037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
89710037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
89810037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
89910037SARM gem5 Developers            }
90010037SARM gem5 Developers            break;
90110037SARM gem5 Developers          case MISCREG_FPCR:
90210037SARM gem5 Developers            {
90310037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
90410037SARM gem5 Developers                FPSCR fpscrMask  = 0;
90510037SARM gem5 Developers                fpscrMask.len    = ones;
90610037SARM gem5 Developers                fpscrMask.stride = ones;
90710037SARM gem5 Developers                fpscrMask.rMode  = ones;
90810037SARM gem5 Developers                fpscrMask.fz     = ones;
90910037SARM gem5 Developers                fpscrMask.dn     = ones;
91010037SARM gem5 Developers                fpscrMask.ahp    = ones;
91110037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
91210037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
91310037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
91410037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
91510037SARM gem5 Developers            }
91610037SARM gem5 Developers            break;
91710037SARM gem5 Developers          case MISCREG_CPSR_Q:
91810037SARM gem5 Developers            {
91910037SARM gem5 Developers                assert(!(newVal & ~CpsrMaskQ));
92010037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
92110037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
9227362Sgblack@eecs.umich.edu            }
9237362Sgblack@eecs.umich.edu            break;
92410417Sandreas.hansson@arm.com          case MISCREG_FPSCR_QC:
9257362Sgblack@eecs.umich.edu            {
92610037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
92710037SARM gem5 Developers                         (newVal & FpscrQcMask);
92810037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
92910037SARM gem5 Developers            }
93010037SARM gem5 Developers            break;
93110037SARM gem5 Developers          case MISCREG_FPSCR_EXC:
93210037SARM gem5 Developers            {
93310037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
93410037SARM gem5 Developers                         (newVal & FpscrExcMask);
93510037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
93610037SARM gem5 Developers            }
93710037SARM gem5 Developers            break;
93810037SARM gem5 Developers          case MISCREG_FPEXC:
93910037SARM gem5 Developers            {
94010037SARM gem5 Developers                // vfpv3 architecture, section B.6.1 of DDI04068
94110037SARM gem5 Developers                // bit 29 - valid only if fpexc[31] is 0
94210037SARM gem5 Developers                const uint32_t fpexcMask = 0x60000000;
94310037SARM gem5 Developers                newVal = (newVal & fpexcMask) |
94410037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
94510037SARM gem5 Developers            }
94610037SARM gem5 Developers            break;
94710037SARM gem5 Developers          case MISCREG_HCR:
94810037SARM gem5 Developers            {
94911150Smitch.hayenga@arm.com                if (!haveVirtualization)
95010037SARM gem5 Developers                    return;
95110037SARM gem5 Developers            }
95210037SARM gem5 Developers            break;
95310037SARM gem5 Developers          case MISCREG_IFSR:
95410037SARM gem5 Developers            {
95510037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.96
95610037SARM gem5 Developers                const uint32_t ifsrMask =
9578205SAli.Saidi@ARM.com                    mask(31, 13) | mask(11, 11) | mask(8, 6);
95810037SARM gem5 Developers                newVal = newVal & ~ifsrMask;
95911496Sandreas.sandberg@arm.com            }
96010037SARM gem5 Developers            break;
96110037SARM gem5 Developers          case MISCREG_DFSR:
96210037SARM gem5 Developers            {
96310037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.52
96410037SARM gem5 Developers                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
96510037SARM gem5 Developers                newVal = newVal & ~dfsrMask;
96610037SARM gem5 Developers            }
96710037SARM gem5 Developers            break;
96810037SARM gem5 Developers          case MISCREG_AMAIR0:
96910037SARM gem5 Developers          case MISCREG_AMAIR1:
97010037SARM gem5 Developers            {
97110037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.5
97210037SARM gem5 Developers                // Valid only with LPAE
97310037SARM gem5 Developers                if (!haveLPAE)
97411585SDylan.Johnson@ARM.com                    return;
97511585SDylan.Johnson@ARM.com                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
97611585SDylan.Johnson@ARM.com            }
97711585SDylan.Johnson@ARM.com            break;
97811585SDylan.Johnson@ARM.com          case MISCREG_SCR:
97911585SDylan.Johnson@ARM.com            getITBPtr(tc)->invalidateMiscReg();
98011585SDylan.Johnson@ARM.com            getDTBPtr(tc)->invalidateMiscReg();
98111585SDylan.Johnson@ARM.com            break;
98211585SDylan.Johnson@ARM.com          case MISCREG_SCTLR:
98311585SDylan.Johnson@ARM.com            {
98411585SDylan.Johnson@ARM.com                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
98510037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
98610037SARM gem5 Developers
98710037SARM gem5 Developers                MiscRegIndex sctlr_idx;
98810037SARM gem5 Developers                if (haveSecurity && !highestELIs64 && !scr.ns) {
98910037SARM gem5 Developers                    sctlr_idx = MISCREG_SCTLR_S;
99010037SARM gem5 Developers                } else {
99110037SARM gem5 Developers                    sctlr_idx =  MISCREG_SCTLR_NS;
9927362Sgblack@eecs.umich.edu                }
9938314Sgeoffrey.blake@arm.com
99410037SARM gem5 Developers                SCTLR sctlr = miscRegs[sctlr_idx];
99510037SARM gem5 Developers                SCTLR new_sctlr = newVal;
99610037SARM gem5 Developers                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
99710037SARM gem5 Developers                miscRegs[sctlr_idx] = (RegVal)new_sctlr;
99810037SARM gem5 Developers                getITBPtr(tc)->invalidateMiscReg();
99910037SARM gem5 Developers                getDTBPtr(tc)->invalidateMiscReg();
100010037SARM gem5 Developers            }
100110037SARM gem5 Developers          case MISCREG_MIDR:
100210037SARM gem5 Developers          case MISCREG_ID_PFR0:
100310037SARM gem5 Developers          case MISCREG_ID_PFR1:
100410037SARM gem5 Developers          case MISCREG_ID_DFR0:
100510037SARM gem5 Developers          case MISCREG_ID_MMFR0:
100610037SARM gem5 Developers          case MISCREG_ID_MMFR1:
100710037SARM gem5 Developers          case MISCREG_ID_MMFR2:
100810037SARM gem5 Developers          case MISCREG_ID_MMFR3:
100910037SARM gem5 Developers          case MISCREG_ID_ISAR0:
101010037SARM gem5 Developers          case MISCREG_ID_ISAR1:
101110037SARM gem5 Developers          case MISCREG_ID_ISAR2:
101210037SARM gem5 Developers          case MISCREG_ID_ISAR3:
101310037SARM gem5 Developers          case MISCREG_ID_ISAR4:
101410037SARM gem5 Developers          case MISCREG_ID_ISAR5:
101510037SARM gem5 Developers
101610037SARM gem5 Developers          case MISCREG_MPIDR:
101710037SARM gem5 Developers          case MISCREG_FPSID:
101810037SARM gem5 Developers          case MISCREG_TLBTR:
101910037SARM gem5 Developers          case MISCREG_MVFR0:
102010037SARM gem5 Developers          case MISCREG_MVFR1:
102110037SARM gem5 Developers
102210037SARM gem5 Developers          case MISCREG_ID_AA64AFR0_EL1:
102310037SARM gem5 Developers          case MISCREG_ID_AA64AFR1_EL1:
102410037SARM gem5 Developers          case MISCREG_ID_AA64DFR0_EL1:
102510037SARM gem5 Developers          case MISCREG_ID_AA64DFR1_EL1:
102610037SARM gem5 Developers          case MISCREG_ID_AA64ISAR0_EL1:
102710037SARM gem5 Developers          case MISCREG_ID_AA64ISAR1_EL1:
102810037SARM gem5 Developers          case MISCREG_ID_AA64MMFR0_EL1:
102910037SARM gem5 Developers          case MISCREG_ID_AA64MMFR1_EL1:
103010037SARM gem5 Developers          case MISCREG_ID_AA64MMFR2_EL1:
103110037SARM gem5 Developers          case MISCREG_ID_AA64PFR0_EL1:
103210037SARM gem5 Developers          case MISCREG_ID_AA64PFR1_EL1:
103310037SARM gem5 Developers            // ID registers are constants.
103410037SARM gem5 Developers            return;
103510037SARM gem5 Developers
103610037SARM gem5 Developers          // TLB Invalidate All
103710037SARM gem5 Developers          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
103810037SARM gem5 Developers            {
103910037SARM gem5 Developers                assert32(tc);
104010037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
104110037SARM gem5 Developers
104210037SARM gem5 Developers                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
104310037SARM gem5 Developers                tlbiOp(tc);
104410037SARM gem5 Developers                return;
104510037SARM gem5 Developers            }
104610037SARM gem5 Developers          // TLB Invalidate All, Inner Shareable
104710037SARM gem5 Developers          case MISCREG_TLBIALLIS:
104810037SARM gem5 Developers            {
104910037SARM gem5 Developers                assert32(tc);
105010037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
105110037SARM gem5 Developers
105210037SARM gem5 Developers                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
105310037SARM gem5 Developers                tlbiOp.broadcast(tc);
105410037SARM gem5 Developers                return;
105510037SARM gem5 Developers            }
105610037SARM gem5 Developers          // Instruction TLB Invalidate All
105710037SARM gem5 Developers          case MISCREG_ITLBIALL:
105810037SARM gem5 Developers            {
105910037SARM gem5 Developers                assert32(tc);
106010037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
106110037SARM gem5 Developers
106210037SARM gem5 Developers                ITLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
106310037SARM gem5 Developers                tlbiOp(tc);
106410037SARM gem5 Developers                return;
106510037SARM gem5 Developers            }
106610037SARM gem5 Developers          // Data TLB Invalidate All
106710037SARM gem5 Developers          case MISCREG_DTLBIALL:
106810037SARM gem5 Developers            {
106910037SARM gem5 Developers                assert32(tc);
107010037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
107110037SARM gem5 Developers
107210037SARM gem5 Developers                DTLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
107310037SARM gem5 Developers                tlbiOp(tc);
107410037SARM gem5 Developers                return;
107510037SARM gem5 Developers            }
107610037SARM gem5 Developers          // TLB Invalidate by VA
107710037SARM gem5 Developers          // mcr tlbimval(is) is invalidating all matching entries
107810037SARM gem5 Developers          // regardless of the level of lookup, since in gem5 we cache
107910037SARM gem5 Developers          // in the tlb the last level of lookup only.
108010037SARM gem5 Developers          case MISCREG_TLBIMVA:
108110037SARM gem5 Developers          case MISCREG_TLBIMVAL:
108210037SARM gem5 Developers            {
108310037SARM gem5 Developers                assert32(tc);
108410037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
108510037SARM gem5 Developers
108610037SARM gem5 Developers                TLBIMVA tlbiOp(EL1,
108710037SARM gem5 Developers                               haveSecurity && !scr.ns,
108810037SARM gem5 Developers                               mbits(newVal, 31, 12),
108910037SARM gem5 Developers                               bits(newVal, 7,0));
109010037SARM gem5 Developers
109110037SARM gem5 Developers                tlbiOp(tc);
109210037SARM gem5 Developers                return;
109310037SARM gem5 Developers            }
109410037SARM gem5 Developers          // TLB Invalidate by VA, Inner Shareable
109510037SARM gem5 Developers          case MISCREG_TLBIMVAIS:
109610037SARM gem5 Developers          case MISCREG_TLBIMVALIS:
109710037SARM gem5 Developers            {
109810037SARM gem5 Developers                assert32(tc);
109910037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
110010037SARM gem5 Developers
110110037SARM gem5 Developers                TLBIMVA tlbiOp(EL1,
110210037SARM gem5 Developers                               haveSecurity && !scr.ns,
110310037SARM gem5 Developers                               mbits(newVal, 31, 12),
110410037SARM gem5 Developers                               bits(newVal, 7,0));
110510037SARM gem5 Developers
110610037SARM gem5 Developers                tlbiOp.broadcast(tc);
110710037SARM gem5 Developers                return;
110810037SARM gem5 Developers            }
110910037SARM gem5 Developers          // TLB Invalidate by ASID match
111010037SARM gem5 Developers          case MISCREG_TLBIASID:
111110037SARM gem5 Developers            {
111210037SARM gem5 Developers                assert32(tc);
111310037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
111410037SARM gem5 Developers
111510037SARM gem5 Developers                TLBIASID tlbiOp(EL1,
111610037SARM gem5 Developers                                haveSecurity && !scr.ns,
111710037SARM gem5 Developers                                bits(newVal, 7,0));
111810037SARM gem5 Developers
111910037SARM gem5 Developers                tlbiOp(tc);
112010037SARM gem5 Developers                return;
112110037SARM gem5 Developers            }
112210037SARM gem5 Developers          // TLB Invalidate by ASID match, Inner Shareable
112310037SARM gem5 Developers          case MISCREG_TLBIASIDIS:
112410037SARM gem5 Developers            {
112510037SARM gem5 Developers                assert32(tc);
112610037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
112710037SARM gem5 Developers
112810037SARM gem5 Developers                TLBIASID tlbiOp(EL1,
112910037SARM gem5 Developers                                haveSecurity && !scr.ns,
113010037SARM gem5 Developers                                bits(newVal, 7,0));
113111581SDylan.Johnson@ARM.com
113210037SARM gem5 Developers                tlbiOp.broadcast(tc);
113310037SARM gem5 Developers                return;
113410037SARM gem5 Developers            }
113510037SARM gem5 Developers          // mcr tlbimvaal(is) is invalidating all matching entries
113610037SARM gem5 Developers          // regardless of the level of lookup, since in gem5 we cache
113710037SARM gem5 Developers          // in the tlb the last level of lookup only.
113810037SARM gem5 Developers          // TLB Invalidate by VA, All ASID
113910037SARM gem5 Developers          case MISCREG_TLBIMVAA:
114010037SARM gem5 Developers          case MISCREG_TLBIMVAAL:
114110367SAndrew.Bardsley@arm.com            {
114210367SAndrew.Bardsley@arm.com                assert32(tc);
114310037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
114410037SARM gem5 Developers
114510037SARM gem5 Developers                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
114610037SARM gem5 Developers                                mbits(newVal, 31,12), false);
114710037SARM gem5 Developers
114810037SARM gem5 Developers                tlbiOp(tc);
114910037SARM gem5 Developers                return;
115010037SARM gem5 Developers            }
115110037SARM gem5 Developers          // TLB Invalidate by VA, All ASID, Inner Shareable
115210037SARM gem5 Developers          case MISCREG_TLBIMVAAIS:
115310037SARM gem5 Developers          case MISCREG_TLBIMVAALIS:
115410037SARM gem5 Developers            {
115510037SARM gem5 Developers                assert32(tc);
115610037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
115710037SARM gem5 Developers
115810037SARM gem5 Developers                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
115910037SARM gem5 Developers                                mbits(newVal, 31,12), false);
116010037SARM gem5 Developers
116110037SARM gem5 Developers                tlbiOp.broadcast(tc);
116210037SARM gem5 Developers                return;
116310037SARM gem5 Developers            }
116410037SARM gem5 Developers          // mcr tlbimvalh(is) is invalidating all matching entries
116510037SARM gem5 Developers          // regardless of the level of lookup, since in gem5 we cache
116610037SARM gem5 Developers          // in the tlb the last level of lookup only.
116710037SARM gem5 Developers          // TLB Invalidate by VA, Hyp mode
116810037SARM gem5 Developers          case MISCREG_TLBIMVAH:
116910037SARM gem5 Developers          case MISCREG_TLBIMVALH:
117010037SARM gem5 Developers            {
117110037SARM gem5 Developers                assert32(tc);
117210037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
117310037SARM gem5 Developers
117410037SARM gem5 Developers                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
117510037SARM gem5 Developers                                mbits(newVal, 31,12), true);
117610037SARM gem5 Developers
117710037SARM gem5 Developers                tlbiOp(tc);
117810037SARM gem5 Developers                return;
117910037SARM gem5 Developers            }
118010037SARM gem5 Developers          // TLB Invalidate by VA, Hyp mode, Inner Shareable
118110037SARM gem5 Developers          case MISCREG_TLBIMVAHIS:
118210037SARM gem5 Developers          case MISCREG_TLBIMVALHIS:
118310037SARM gem5 Developers            {
118410037SARM gem5 Developers                assert32(tc);
118510037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
118610037SARM gem5 Developers
118710037SARM gem5 Developers                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
118810037SARM gem5 Developers                                mbits(newVal, 31,12), true);
118910037SARM gem5 Developers
119010037SARM gem5 Developers                tlbiOp.broadcast(tc);
119110037SARM gem5 Developers                return;
119210037SARM gem5 Developers            }
119310037SARM gem5 Developers          // mcr tlbiipas2l(is) is invalidating all matching entries
119410037SARM gem5 Developers          // regardless of the level of lookup, since in gem5 we cache
119510037SARM gem5 Developers          // in the tlb the last level of lookup only.
119610037SARM gem5 Developers          // TLB Invalidate by Intermediate Physical Address, Stage 2
119711581SDylan.Johnson@ARM.com          case MISCREG_TLBIIPAS2:
119810037SARM gem5 Developers          case MISCREG_TLBIIPAS2L:
119910037SARM gem5 Developers            {
120010037SARM gem5 Developers                assert32(tc);
120110037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
120210037SARM gem5 Developers
120310037SARM gem5 Developers                TLBIIPA tlbiOp(EL1,
120410037SARM gem5 Developers                               haveSecurity && !scr.ns,
120510037SARM gem5 Developers                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
120610037SARM gem5 Developers
120710037SARM gem5 Developers                tlbiOp(tc);
120810037SARM gem5 Developers                return;
120910037SARM gem5 Developers            }
121010037SARM gem5 Developers          // TLB Invalidate by Intermediate Physical Address, Stage 2,
121110037SARM gem5 Developers          // Inner Shareable
121210037SARM gem5 Developers          case MISCREG_TLBIIPAS2IS:
121310037SARM gem5 Developers          case MISCREG_TLBIIPAS2LIS:
121410037SARM gem5 Developers            {
121510037SARM gem5 Developers                assert32(tc);
121610037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
121710037SARM gem5 Developers
121810037SARM gem5 Developers                TLBIIPA tlbiOp(EL1,
121910037SARM gem5 Developers                               haveSecurity && !scr.ns,
122010037SARM gem5 Developers                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
122110037SARM gem5 Developers
122210037SARM gem5 Developers                tlbiOp.broadcast(tc);
122310037SARM gem5 Developers                return;
122410037SARM gem5 Developers            }
122510037SARM gem5 Developers          // Instruction TLB Invalidate by VA
122610037SARM gem5 Developers          case MISCREG_ITLBIMVA:
122710037SARM gem5 Developers            {
122810037SARM gem5 Developers                assert32(tc);
122910037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
123010037SARM gem5 Developers
123110037SARM gem5 Developers                ITLBIMVA tlbiOp(EL1,
123210037SARM gem5 Developers                                haveSecurity && !scr.ns,
123310037SARM gem5 Developers                                mbits(newVal, 31, 12),
123410037SARM gem5 Developers                                bits(newVal, 7,0));
123510037SARM gem5 Developers
123610037SARM gem5 Developers                tlbiOp(tc);
123710037SARM gem5 Developers                return;
123810037SARM gem5 Developers            }
123910037SARM gem5 Developers          // Data TLB Invalidate by VA
124010037SARM gem5 Developers          case MISCREG_DTLBIMVA:
124110037SARM gem5 Developers            {
124210037SARM gem5 Developers                assert32(tc);
124310037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
124410037SARM gem5 Developers
124510037SARM gem5 Developers                DTLBIMVA tlbiOp(EL1,
124610037SARM gem5 Developers                                haveSecurity && !scr.ns,
124710037SARM gem5 Developers                                mbits(newVal, 31, 12),
124810037SARM gem5 Developers                                bits(newVal, 7,0));
124910037SARM gem5 Developers
125010037SARM gem5 Developers                tlbiOp(tc);
125110037SARM gem5 Developers                return;
125210037SARM gem5 Developers            }
125310037SARM gem5 Developers          // Instruction TLB Invalidate by ASID match
125410037SARM gem5 Developers          case MISCREG_ITLBIASID:
125510037SARM gem5 Developers            {
125610037SARM gem5 Developers                assert32(tc);
125710037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
125810417Sandreas.hansson@arm.com
125910037SARM gem5 Developers                ITLBIASID tlbiOp(EL1,
126010037SARM gem5 Developers                                 haveSecurity && !scr.ns,
126110037SARM gem5 Developers                                 bits(newVal, 7,0));
126210037SARM gem5 Developers
126310037SARM gem5 Developers                tlbiOp(tc);
126410037SARM gem5 Developers                return;
126510037SARM gem5 Developers            }
126610037SARM gem5 Developers          // Data TLB Invalidate by ASID match
126710037SARM gem5 Developers          case MISCREG_DTLBIASID:
126810037SARM gem5 Developers            {
126910037SARM gem5 Developers                assert32(tc);
127010037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
127110037SARM gem5 Developers
127210037SARM gem5 Developers                DTLBIASID tlbiOp(EL1,
127310037SARM gem5 Developers                                 haveSecurity && !scr.ns,
127410037SARM gem5 Developers                                 bits(newVal, 7,0));
127510037SARM gem5 Developers
127610037SARM gem5 Developers                tlbiOp(tc);
127710037SARM gem5 Developers                return;
127810037SARM gem5 Developers            }
127910037SARM gem5 Developers          // TLB Invalidate All, Non-Secure Non-Hyp
128010037SARM gem5 Developers          case MISCREG_TLBIALLNSNH:
128110037SARM gem5 Developers            {
128210037SARM gem5 Developers                assert32(tc);
128310037SARM gem5 Developers
128410037SARM gem5 Developers                TLBIALLN tlbiOp(EL1, false);
128510037SARM gem5 Developers                tlbiOp(tc);
128610037SARM gem5 Developers                return;
128711581SDylan.Johnson@ARM.com            }
128810037SARM gem5 Developers          // TLB Invalidate All, Non-Secure Non-Hyp, Inner Shareable
128910037SARM gem5 Developers          case MISCREG_TLBIALLNSNHIS:
129010037SARM gem5 Developers            {
129110037SARM gem5 Developers                assert32(tc);
129210037SARM gem5 Developers
129310037SARM gem5 Developers                TLBIALLN tlbiOp(EL1, false);
129410037SARM gem5 Developers                tlbiOp.broadcast(tc);
129510037SARM gem5 Developers                return;
129610037SARM gem5 Developers            }
129710037SARM gem5 Developers          // TLB Invalidate All, Hyp mode
129810037SARM gem5 Developers          case MISCREG_TLBIALLH:
129910037SARM gem5 Developers            {
130010037SARM gem5 Developers                assert32(tc);
130110037SARM gem5 Developers
130210037SARM gem5 Developers                TLBIALLN tlbiOp(EL1, true);
130310037SARM gem5 Developers                tlbiOp(tc);
130410037SARM gem5 Developers                return;
130510037SARM gem5 Developers            }
130610037SARM gem5 Developers          // TLB Invalidate All, Hyp mode, Inner Shareable
130710037SARM gem5 Developers          case MISCREG_TLBIALLHIS:
130810037SARM gem5 Developers            {
130910037SARM gem5 Developers                assert32(tc);
131010037SARM gem5 Developers
131110037SARM gem5 Developers                TLBIALLN tlbiOp(EL1, true);
131210037SARM gem5 Developers                tlbiOp.broadcast(tc);
131310037SARM gem5 Developers                return;
131410037SARM gem5 Developers            }
131510037SARM gem5 Developers          // AArch64 TLB Invalidate All, EL3
131610037SARM gem5 Developers          case MISCREG_TLBI_ALLE3:
131710037SARM gem5 Developers            {
131810037SARM gem5 Developers                assert64(tc);
131910037SARM gem5 Developers
132010037SARM gem5 Developers                TLBIALL tlbiOp(EL3, true);
132110037SARM gem5 Developers                tlbiOp(tc);
132210037SARM gem5 Developers                return;
132310037SARM gem5 Developers            }
132410037SARM gem5 Developers          // AArch64 TLB Invalidate All, EL3, Inner Shareable
132510037SARM gem5 Developers          case MISCREG_TLBI_ALLE3IS:
132611581SDylan.Johnson@ARM.com            {
132710037SARM gem5 Developers                assert64(tc);
132810037SARM gem5 Developers
132910037SARM gem5 Developers                TLBIALL tlbiOp(EL3, true);
133010037SARM gem5 Developers                tlbiOp.broadcast(tc);
133110037SARM gem5 Developers                return;
133210037SARM gem5 Developers            }
133310037SARM gem5 Developers          // AArch64 TLB Invalidate All, EL2, Inner Shareable
133410037SARM gem5 Developers          case MISCREG_TLBI_ALLE2:
133510037SARM gem5 Developers          case MISCREG_TLBI_ALLE2IS:
133610037SARM gem5 Developers            {
133710037SARM gem5 Developers                assert64(tc);
133810037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
133910037SARM gem5 Developers
134010037SARM gem5 Developers                TLBIALL tlbiOp(EL2, haveSecurity && !scr.ns);
134110037SARM gem5 Developers                tlbiOp(tc);
134210037SARM gem5 Developers                return;
134310037SARM gem5 Developers            }
134410037SARM gem5 Developers          // AArch64 TLB Invalidate All, EL1
134510037SARM gem5 Developers          case MISCREG_TLBI_ALLE1:
134610037SARM gem5 Developers          case MISCREG_TLBI_VMALLE1:
134710037SARM gem5 Developers          case MISCREG_TLBI_VMALLS12E1:
134810037SARM gem5 Developers            // @todo: handle VMID and stage 2 to enable Virtualization
134910037SARM gem5 Developers            {
135010037SARM gem5 Developers                assert64(tc);
135110037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
135210037SARM gem5 Developers
135310037SARM gem5 Developers                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
135410037SARM gem5 Developers                tlbiOp(tc);
135510037SARM gem5 Developers                return;
135610037SARM gem5 Developers            }
135710417Sandreas.hansson@arm.com          // AArch64 TLB Invalidate All, EL1, Inner Shareable
135810037SARM gem5 Developers          case MISCREG_TLBI_ALLE1IS:
135910037SARM gem5 Developers          case MISCREG_TLBI_VMALLE1IS:
136010037SARM gem5 Developers          case MISCREG_TLBI_VMALLS12E1IS:
136110037SARM gem5 Developers            // @todo: handle VMID and stage 2 to enable Virtualization
136210037SARM gem5 Developers            {
136310037SARM gem5 Developers                assert64(tc);
136410037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
136510037SARM gem5 Developers
136610037SARM gem5 Developers                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
136710037SARM gem5 Developers                tlbiOp.broadcast(tc);
136810037SARM gem5 Developers                return;
136910037SARM gem5 Developers            }
137010037SARM gem5 Developers          // VAEx(IS) and VALEx(IS) are the same because TLBs
137110037SARM gem5 Developers          // only store entries
137210417Sandreas.hansson@arm.com          // from the last level of translation table walks
137310037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
137411150Smitch.hayenga@arm.com          // AArch64 TLB Invalidate by VA, EL3
137510037SARM gem5 Developers          case MISCREG_TLBI_VAE3_Xt:
137610037SARM gem5 Developers          case MISCREG_TLBI_VALE3_Xt:
137710037SARM gem5 Developers            {
137810037SARM gem5 Developers                assert64(tc);
137910037SARM gem5 Developers
138010037SARM gem5 Developers                TLBIMVA tlbiOp(EL3, true,
138110037SARM gem5 Developers                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
138210037SARM gem5 Developers                               0xbeef);
138310037SARM gem5 Developers                tlbiOp(tc);
138410037SARM gem5 Developers                return;
138510037SARM gem5 Developers            }
138610037SARM gem5 Developers          // AArch64 TLB Invalidate by VA, EL3, Inner Shareable
138710037SARM gem5 Developers          case MISCREG_TLBI_VAE3IS_Xt:
138810037SARM gem5 Developers          case MISCREG_TLBI_VALE3IS_Xt:
138910037SARM gem5 Developers            {
139010037SARM gem5 Developers                assert64(tc);
139110037SARM gem5 Developers
139210037SARM gem5 Developers                TLBIMVA tlbiOp(EL3, true,
139310037SARM gem5 Developers                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
139410037SARM gem5 Developers                               0xbeef);
139510037SARM gem5 Developers
139611581SDylan.Johnson@ARM.com                tlbiOp.broadcast(tc);
139711581SDylan.Johnson@ARM.com                return;
139810037SARM gem5 Developers            }
13997362Sgblack@eecs.umich.edu          // AArch64 TLB Invalidate by VA, EL2
14007362Sgblack@eecs.umich.edu          case MISCREG_TLBI_VAE2_Xt:
14017652Sminkyu.jeong@arm.com          case MISCREG_TLBI_VALE2_Xt:
140210417Sandreas.hansson@arm.com            {
14037652Sminkyu.jeong@arm.com                assert64(tc);
14047652Sminkyu.jeong@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
14057652Sminkyu.jeong@arm.com
14067652Sminkyu.jeong@arm.com                TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
14077652Sminkyu.jeong@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
14087720Sgblack@eecs.umich.edu                               0xbeef);
14097720Sgblack@eecs.umich.edu                tlbiOp(tc);
14107720Sgblack@eecs.umich.edu                return;
14117720Sgblack@eecs.umich.edu            }
14127652Sminkyu.jeong@arm.com          // AArch64 TLB Invalidate by VA, EL2, Inner Shareable
14137652Sminkyu.jeong@arm.com          case MISCREG_TLBI_VAE2IS_Xt:
14148518Sgeoffrey.blake@arm.com          case MISCREG_TLBI_VALE2IS_Xt:
141510417Sandreas.hansson@arm.com            {
14168518Sgeoffrey.blake@arm.com                assert64(tc);
14178806Sgblack@eecs.umich.edu                scr = readMiscReg(MISCREG_SCR, tc);
14188806Sgblack@eecs.umich.edu
14198806Sgblack@eecs.umich.edu                TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
14208806Sgblack@eecs.umich.edu                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
14218806Sgblack@eecs.umich.edu                               0xbeef);
14228806Sgblack@eecs.umich.edu
14238806Sgblack@eecs.umich.edu                tlbiOp.broadcast(tc);
142411150Smitch.hayenga@arm.com                return;
14258518Sgeoffrey.blake@arm.com            }
14268518Sgeoffrey.blake@arm.com          // AArch64 TLB Invalidate by VA, EL1
142710037SARM gem5 Developers          case MISCREG_TLBI_VAE1_Xt:
142810037SARM gem5 Developers          case MISCREG_TLBI_VALE1_Xt:
142910037SARM gem5 Developers            {
143010037SARM gem5 Developers                assert64(tc);
143110037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
143210037SARM gem5 Developers                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
143310037SARM gem5 Developers                                              bits(newVal, 55, 48);
143410037SARM gem5 Developers
143510037SARM gem5 Developers                TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
143610037SARM gem5 Developers                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
143710037SARM gem5 Developers                               asid);
143810037SARM gem5 Developers
143910037SARM gem5 Developers                tlbiOp(tc);
144010037SARM gem5 Developers                return;
144110037SARM gem5 Developers            }
144210037SARM gem5 Developers          // AArch64 TLB Invalidate by VA, EL1, Inner Shareable
144310037SARM gem5 Developers          case MISCREG_TLBI_VAE1IS_Xt:
144410037SARM gem5 Developers          case MISCREG_TLBI_VALE1IS_Xt:
144510037SARM gem5 Developers            {
144610037SARM gem5 Developers                assert64(tc);
144710037SARM gem5 Developers                scr = readMiscReg(MISCREG_SCR, tc);
144810037SARM gem5 Developers                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
144910037SARM gem5 Developers                                              bits(newVal, 55, 48);
145010037SARM gem5 Developers
145110037SARM gem5 Developers                TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
145210037SARM gem5 Developers                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
145310037SARM gem5 Developers                               asid);
145410037SARM gem5 Developers
145510037SARM gem5 Developers                tlbiOp.broadcast(tc);
14566019Shines@cs.fsu.edu                return;
14576019Shines@cs.fsu.edu            }
1458          // AArch64 TLB Invalidate by ASID, EL1
1459          // @todo: handle VMID to enable Virtualization
1460          case MISCREG_TLBI_ASIDE1_Xt:
1461            {
1462                assert64(tc);
1463                scr = readMiscReg(MISCREG_SCR, tc);
1464                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
1465                                              bits(newVal, 55, 48);
1466
1467                TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
1468                tlbiOp(tc);
1469                return;
1470            }
1471          // AArch64 TLB Invalidate by ASID, EL1, Inner Shareable
1472          case MISCREG_TLBI_ASIDE1IS_Xt:
1473            {
1474                assert64(tc);
1475                scr = readMiscReg(MISCREG_SCR, tc);
1476                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
1477                                              bits(newVal, 55, 48);
1478
1479                TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
1480                tlbiOp.broadcast(tc);
1481                return;
1482            }
1483          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
1484          // entries from the last level of translation table walks
1485          // AArch64 TLB Invalidate by VA, All ASID, EL1
1486          case MISCREG_TLBI_VAAE1_Xt:
1487          case MISCREG_TLBI_VAALE1_Xt:
1488            {
1489                assert64(tc);
1490                scr = readMiscReg(MISCREG_SCR, tc);
1491
1492                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
1493                    static_cast<Addr>(bits(newVal, 43, 0)) << 12, false);
1494
1495                tlbiOp(tc);
1496                return;
1497            }
1498          // AArch64 TLB Invalidate by VA, All ASID, EL1, Inner Shareable
1499          case MISCREG_TLBI_VAAE1IS_Xt:
1500          case MISCREG_TLBI_VAALE1IS_Xt:
1501            {
1502                assert64(tc);
1503                scr = readMiscReg(MISCREG_SCR, tc);
1504
1505                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
1506                    static_cast<Addr>(bits(newVal, 43, 0)) << 12, false);
1507
1508                tlbiOp.broadcast(tc);
1509                return;
1510            }
1511          // AArch64 TLB Invalidate by Intermediate Physical Address,
1512          // Stage 2, EL1
1513          case MISCREG_TLBI_IPAS2E1_Xt:
1514          case MISCREG_TLBI_IPAS2LE1_Xt:
1515            {
1516                assert64(tc);
1517                scr = readMiscReg(MISCREG_SCR, tc);
1518
1519                TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
1520                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
1521
1522                tlbiOp(tc);
1523                return;
1524            }
1525          // AArch64 TLB Invalidate by Intermediate Physical Address,
1526          // Stage 2, EL1, Inner Shareable
1527          case MISCREG_TLBI_IPAS2E1IS_Xt:
1528          case MISCREG_TLBI_IPAS2LE1IS_Xt:
1529            {
1530                assert64(tc);
1531                scr = readMiscReg(MISCREG_SCR, tc);
1532
1533                TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
1534                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
1535
1536                tlbiOp.broadcast(tc);
1537                return;
1538            }
1539          case MISCREG_ACTLR:
1540            warn("Not doing anything for write of miscreg ACTLR\n");
1541            break;
1542
1543          case MISCREG_PMXEVTYPER_PMCCFILTR:
1544          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
1545          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
1546          case MISCREG_PMCR ... MISCREG_PMOVSSET:
1547            pmu->setMiscReg(misc_reg, newVal);
1548            break;
1549
1550
1551          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
1552            {
1553                HSTR hstrMask = 0;
1554                hstrMask.tjdbx = 1;
1555                newVal &= ~((uint32_t) hstrMask);
1556                break;
1557            }
1558          case MISCREG_HCPTR:
1559            {
1560                // If a CP bit in NSACR is 0 then the corresponding bit in
1561                // HCPTR is RAO/WI. Same applies to NSASEDIS
1562                secure_lookup = haveSecurity &&
1563                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
1564                                  readMiscRegNoEffect(MISCREG_CPSR));
1565                if (!secure_lookup) {
1566                    RegVal oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
1567                    RegVal mask =
1568                        (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
1569                    newVal = (newVal & ~mask) | (oldValue & mask);
1570                }
1571                break;
1572            }
1573          case MISCREG_HDFAR: // alias for secure DFAR
1574            misc_reg = MISCREG_DFAR_S;
1575            break;
1576          case MISCREG_HIFAR: // alias for secure IFAR
1577            misc_reg = MISCREG_IFAR_S;
1578            break;
1579          case MISCREG_ATS1CPR:
1580          case MISCREG_ATS1CPW:
1581          case MISCREG_ATS1CUR:
1582          case MISCREG_ATS1CUW:
1583          case MISCREG_ATS12NSOPR:
1584          case MISCREG_ATS12NSOPW:
1585          case MISCREG_ATS12NSOUR:
1586          case MISCREG_ATS12NSOUW:
1587          case MISCREG_ATS1HR:
1588          case MISCREG_ATS1HW:
1589            {
1590              Request::Flags flags = 0;
1591              BaseTLB::Mode mode = BaseTLB::Read;
1592              TLB::ArmTranslationType tranType = TLB::NormalTran;
1593              Fault fault;
1594              switch(misc_reg) {
1595                case MISCREG_ATS1CPR:
1596                  flags    = TLB::MustBeOne;
1597                  tranType = TLB::S1CTran;
1598                  mode     = BaseTLB::Read;
1599                  break;
1600                case MISCREG_ATS1CPW:
1601                  flags    = TLB::MustBeOne;
1602                  tranType = TLB::S1CTran;
1603                  mode     = BaseTLB::Write;
1604                  break;
1605                case MISCREG_ATS1CUR:
1606                  flags    = TLB::MustBeOne | TLB::UserMode;
1607                  tranType = TLB::S1CTran;
1608                  mode     = BaseTLB::Read;
1609                  break;
1610                case MISCREG_ATS1CUW:
1611                  flags    = TLB::MustBeOne | TLB::UserMode;
1612                  tranType = TLB::S1CTran;
1613                  mode     = BaseTLB::Write;
1614                  break;
1615                case MISCREG_ATS12NSOPR:
1616                  if (!haveSecurity)
1617                      panic("Security Extensions required for ATS12NSOPR");
1618                  flags    = TLB::MustBeOne;
1619                  tranType = TLB::S1S2NsTran;
1620                  mode     = BaseTLB::Read;
1621                  break;
1622                case MISCREG_ATS12NSOPW:
1623                  if (!haveSecurity)
1624                      panic("Security Extensions required for ATS12NSOPW");
1625                  flags    = TLB::MustBeOne;
1626                  tranType = TLB::S1S2NsTran;
1627                  mode     = BaseTLB::Write;
1628                  break;
1629                case MISCREG_ATS12NSOUR:
1630                  if (!haveSecurity)
1631                      panic("Security Extensions required for ATS12NSOUR");
1632                  flags    = TLB::MustBeOne | TLB::UserMode;
1633                  tranType = TLB::S1S2NsTran;
1634                  mode     = BaseTLB::Read;
1635                  break;
1636                case MISCREG_ATS12NSOUW:
1637                  if (!haveSecurity)
1638                      panic("Security Extensions required for ATS12NSOUW");
1639                  flags    = TLB::MustBeOne | TLB::UserMode;
1640                  tranType = TLB::S1S2NsTran;
1641                  mode     = BaseTLB::Write;
1642                  break;
1643                case MISCREG_ATS1HR: // only really useful from secure mode.
1644                  flags    = TLB::MustBeOne;
1645                  tranType = TLB::HypMode;
1646                  mode     = BaseTLB::Read;
1647                  break;
1648                case MISCREG_ATS1HW:
1649                  flags    = TLB::MustBeOne;
1650                  tranType = TLB::HypMode;
1651                  mode     = BaseTLB::Write;
1652                  break;
1653              }
1654              // If we're in timing mode then doing the translation in
1655              // functional mode then we're slightly distorting performance
1656              // results obtained from simulations. The translation should be
1657              // done in the same mode the core is running in. NOTE: This
1658              // can't be an atomic translation because that causes problems
1659              // with unexpected atomic snoop requests.
1660              warn("Translating via %s in functional mode! Fix Me!\n",
1661                   miscRegName[misc_reg]);
1662
1663              auto req = std::make_shared<Request>(
1664                  0, val, 0, flags,  Request::funcMasterId,
1665                  tc->pcState().pc(), tc->contextId());
1666
1667              fault = getDTBPtr(tc)->translateFunctional(
1668                      req, tc, mode, tranType);
1669
1670              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1671              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
1672
1673              RegVal newVal;
1674              if (fault == NoFault) {
1675                  Addr paddr = req->getPaddr();
1676                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
1677                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
1678                      newVal = (paddr & mask(39, 12)) |
1679                               (getDTBPtr(tc)->getAttr());
1680                  } else {
1681                      newVal = (paddr & 0xfffff000) |
1682                               (getDTBPtr(tc)->getAttr());
1683                  }
1684                  DPRINTF(MiscRegs,
1685                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
1686                          val, newVal);
1687              } else {
1688                  ArmFault *armFault = static_cast<ArmFault *>(fault.get());
1689                  armFault->update(tc);
1690                  // Set fault bit and FSR
1691                  FSR fsr = armFault->getFsr(tc);
1692
1693                  newVal = ((fsr >> 9) & 1) << 11;
1694                  if (newVal) {
1695                    // LPAE - rearange fault status
1696                    newVal |= ((fsr >>  0) & 0x3f) << 1;
1697                  } else {
1698                    // VMSA - rearange fault status
1699                    newVal |= ((fsr >>  0) & 0xf) << 1;
1700                    newVal |= ((fsr >> 10) & 0x1) << 5;
1701                    newVal |= ((fsr >> 12) & 0x1) << 6;
1702                  }
1703                  newVal |= 0x1; // F bit
1704                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1705                  newVal |= armFault->isStage2() ? 0x200 : 0;
1706                  DPRINTF(MiscRegs,
1707                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
1708                          val, fsr, newVal);
1709              }
1710              setMiscRegNoEffect(MISCREG_PAR, newVal);
1711              return;
1712            }
1713          case MISCREG_TTBCR:
1714            {
1715                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1716                const uint32_t ones = (uint32_t)(-1);
1717                TTBCR ttbcrMask = 0;
1718                TTBCR ttbcrNew = newVal;
1719
1720                // ARM DDI 0406C.b, ARMv7-32
1721                ttbcrMask.n = ones; // T0SZ
1722                if (haveSecurity) {
1723                    ttbcrMask.pd0 = ones;
1724                    ttbcrMask.pd1 = ones;
1725                }
1726                ttbcrMask.epd0 = ones;
1727                ttbcrMask.irgn0 = ones;
1728                ttbcrMask.orgn0 = ones;
1729                ttbcrMask.sh0 = ones;
1730                ttbcrMask.ps = ones; // T1SZ
1731                ttbcrMask.a1 = ones;
1732                ttbcrMask.epd1 = ones;
1733                ttbcrMask.irgn1 = ones;
1734                ttbcrMask.orgn1 = ones;
1735                ttbcrMask.sh1 = ones;
1736                if (haveLPAE)
1737                    ttbcrMask.eae = ones;
1738
1739                if (haveLPAE && ttbcrNew.eae) {
1740                    newVal = newVal & ttbcrMask;
1741                } else {
1742                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
1743                }
1744                // Invalidate TLB MiscReg
1745                getITBPtr(tc)->invalidateMiscReg();
1746                getDTBPtr(tc)->invalidateMiscReg();
1747                break;
1748            }
1749          case MISCREG_TTBR0:
1750          case MISCREG_TTBR1:
1751            {
1752                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1753                if (haveLPAE) {
1754                    if (ttbcr.eae) {
1755                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
1756                        // ARMv8 AArch32 bit 63-56 only
1757                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
1758                        newVal = (newVal & (~ttbrMask));
1759                    }
1760                }
1761                // Invalidate TLB MiscReg
1762                getITBPtr(tc)->invalidateMiscReg();
1763                getDTBPtr(tc)->invalidateMiscReg();
1764                break;
1765            }
1766          case MISCREG_SCTLR_EL1:
1767          case MISCREG_CONTEXTIDR:
1768          case MISCREG_PRRR:
1769          case MISCREG_NMRR:
1770          case MISCREG_MAIR0:
1771          case MISCREG_MAIR1:
1772          case MISCREG_DACR:
1773          case MISCREG_VTTBR:
1774          case MISCREG_SCR_EL3:
1775          case MISCREG_HCR_EL2:
1776          case MISCREG_TCR_EL1:
1777          case MISCREG_TCR_EL2:
1778          case MISCREG_TCR_EL3:
1779          case MISCREG_SCTLR_EL2:
1780          case MISCREG_SCTLR_EL3:
1781          case MISCREG_HSCTLR:
1782          case MISCREG_TTBR0_EL1:
1783          case MISCREG_TTBR1_EL1:
1784          case MISCREG_TTBR0_EL2:
1785          case MISCREG_TTBR1_EL2:
1786          case MISCREG_TTBR0_EL3:
1787            getITBPtr(tc)->invalidateMiscReg();
1788            getDTBPtr(tc)->invalidateMiscReg();
1789            break;
1790          case MISCREG_NZCV:
1791            {
1792                CPSR cpsr = val;
1793
1794                tc->setCCReg(CCREG_NZ, cpsr.nz);
1795                tc->setCCReg(CCREG_C,  cpsr.c);
1796                tc->setCCReg(CCREG_V,  cpsr.v);
1797            }
1798            break;
1799          case MISCREG_DAIF:
1800            {
1801                CPSR cpsr = miscRegs[MISCREG_CPSR];
1802                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
1803                newVal = cpsr;
1804                misc_reg = MISCREG_CPSR;
1805            }
1806            break;
1807          case MISCREG_SP_EL0:
1808            tc->setIntReg(INTREG_SP0, newVal);
1809            break;
1810          case MISCREG_SP_EL1:
1811            tc->setIntReg(INTREG_SP1, newVal);
1812            break;
1813          case MISCREG_SP_EL2:
1814            tc->setIntReg(INTREG_SP2, newVal);
1815            break;
1816          case MISCREG_SPSEL:
1817            {
1818                CPSR cpsr = miscRegs[MISCREG_CPSR];
1819                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
1820                newVal = cpsr;
1821                misc_reg = MISCREG_CPSR;
1822            }
1823            break;
1824          case MISCREG_CURRENTEL:
1825            {
1826                CPSR cpsr = miscRegs[MISCREG_CPSR];
1827                cpsr.el = (uint8_t) ((CPSR) newVal).el;
1828                newVal = cpsr;
1829                misc_reg = MISCREG_CPSR;
1830            }
1831            break;
1832          case MISCREG_AT_S1E1R_Xt:
1833          case MISCREG_AT_S1E1W_Xt:
1834          case MISCREG_AT_S1E0R_Xt:
1835          case MISCREG_AT_S1E0W_Xt:
1836          case MISCREG_AT_S1E2R_Xt:
1837          case MISCREG_AT_S1E2W_Xt:
1838          case MISCREG_AT_S12E1R_Xt:
1839          case MISCREG_AT_S12E1W_Xt:
1840          case MISCREG_AT_S12E0R_Xt:
1841          case MISCREG_AT_S12E0W_Xt:
1842          case MISCREG_AT_S1E3R_Xt:
1843          case MISCREG_AT_S1E3W_Xt:
1844            {
1845                RequestPtr req = std::make_shared<Request>();
1846                Request::Flags flags = 0;
1847                BaseTLB::Mode mode = BaseTLB::Read;
1848                TLB::ArmTranslationType tranType = TLB::NormalTran;
1849                Fault fault;
1850                switch(misc_reg) {
1851                  case MISCREG_AT_S1E1R_Xt:
1852                    flags    = TLB::MustBeOne;
1853                    tranType = TLB::S1E1Tran;
1854                    mode     = BaseTLB::Read;
1855                    break;
1856                  case MISCREG_AT_S1E1W_Xt:
1857                    flags    = TLB::MustBeOne;
1858                    tranType = TLB::S1E1Tran;
1859                    mode     = BaseTLB::Write;
1860                    break;
1861                  case MISCREG_AT_S1E0R_Xt:
1862                    flags    = TLB::MustBeOne | TLB::UserMode;
1863                    tranType = TLB::S1E0Tran;
1864                    mode     = BaseTLB::Read;
1865                    break;
1866                  case MISCREG_AT_S1E0W_Xt:
1867                    flags    = TLB::MustBeOne | TLB::UserMode;
1868                    tranType = TLB::S1E0Tran;
1869                    mode     = BaseTLB::Write;
1870                    break;
1871                  case MISCREG_AT_S1E2R_Xt:
1872                    flags    = TLB::MustBeOne;
1873                    tranType = TLB::S1E2Tran;
1874                    mode     = BaseTLB::Read;
1875                    break;
1876                  case MISCREG_AT_S1E2W_Xt:
1877                    flags    = TLB::MustBeOne;
1878                    tranType = TLB::S1E2Tran;
1879                    mode     = BaseTLB::Write;
1880                    break;
1881                  case MISCREG_AT_S12E0R_Xt:
1882                    flags    = TLB::MustBeOne | TLB::UserMode;
1883                    tranType = TLB::S12E0Tran;
1884                    mode     = BaseTLB::Read;
1885                    break;
1886                  case MISCREG_AT_S12E0W_Xt:
1887                    flags    = TLB::MustBeOne | TLB::UserMode;
1888                    tranType = TLB::S12E0Tran;
1889                    mode     = BaseTLB::Write;
1890                    break;
1891                  case MISCREG_AT_S12E1R_Xt:
1892                    flags    = TLB::MustBeOne;
1893                    tranType = TLB::S12E1Tran;
1894                    mode     = BaseTLB::Read;
1895                    break;
1896                  case MISCREG_AT_S12E1W_Xt:
1897                    flags    = TLB::MustBeOne;
1898                    tranType = TLB::S12E1Tran;
1899                    mode     = BaseTLB::Write;
1900                    break;
1901                  case MISCREG_AT_S1E3R_Xt:
1902                    flags    = TLB::MustBeOne;
1903                    tranType = TLB::S1E3Tran;
1904                    mode     = BaseTLB::Read;
1905                    break;
1906                  case MISCREG_AT_S1E3W_Xt:
1907                    flags    = TLB::MustBeOne;
1908                    tranType = TLB::S1E3Tran;
1909                    mode     = BaseTLB::Write;
1910                    break;
1911                }
1912                // If we're in timing mode then doing the translation in
1913                // functional mode then we're slightly distorting performance
1914                // results obtained from simulations. The translation should be
1915                // done in the same mode the core is running in. NOTE: This
1916                // can't be an atomic translation because that causes problems
1917                // with unexpected atomic snoop requests.
1918                warn("Translating via %s in functional mode! Fix Me!\n",
1919                     miscRegName[misc_reg]);
1920
1921                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
1922                               tc->pcState().pc());
1923                req->setContext(tc->contextId());
1924                fault = getDTBPtr(tc)->translateFunctional(req, tc, mode,
1925                                                           tranType);
1926
1927                RegVal newVal;
1928                if (fault == NoFault) {
1929                    Addr paddr = req->getPaddr();
1930                    uint64_t attr = getDTBPtr(tc)->getAttr();
1931                    uint64_t attr1 = attr >> 56;
1932                    if (!attr1 || attr1 ==0x44) {
1933                        attr |= 0x100;
1934                        attr &= ~ uint64_t(0x80);
1935                    }
1936                    newVal = (paddr & mask(47, 12)) | attr;
1937                    DPRINTF(MiscRegs,
1938                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
1939                          val, newVal);
1940                } else {
1941                    ArmFault *armFault = static_cast<ArmFault *>(fault.get());
1942                    armFault->update(tc);
1943                    // Set fault bit and FSR
1944                    FSR fsr = armFault->getFsr(tc);
1945
1946                    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
1947                    if (cpsr.width) { // AArch32
1948                        newVal = ((fsr >> 9) & 1) << 11;
1949                        // rearrange fault status
1950                        newVal |= ((fsr >>  0) & 0x3f) << 1;
1951                        newVal |= 0x1; // F bit
1952                        newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1953                        newVal |= armFault->isStage2() ? 0x200 : 0;
1954                    } else { // AArch64
1955                        newVal = 1; // F bit
1956                        newVal |= fsr << 1; // FST
1957                        // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
1958                        newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
1959                        newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
1960                        newVal |= 1 << 11; // RES1
1961                    }
1962                    DPRINTF(MiscRegs,
1963                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
1964                            val, fsr, newVal);
1965                }
1966                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
1967                return;
1968            }
1969          case MISCREG_SPSR_EL3:
1970          case MISCREG_SPSR_EL2:
1971          case MISCREG_SPSR_EL1:
1972            // Force bits 23:21 to 0
1973            newVal = val & ~(0x7 << 21);
1974            break;
1975          case MISCREG_L2CTLR:
1976            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
1977                 miscRegName[misc_reg], uint32_t(val));
1978            break;
1979
1980          // Generic Timer registers
1981          case MISCREG_CNTHV_CTL_EL2:
1982          case MISCREG_CNTHV_CVAL_EL2:
1983          case MISCREG_CNTHV_TVAL_EL2:
1984          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
1985          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
1986          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
1987          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
1988            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
1989            break;
1990
1991          case MISCREG_ICC_PMR_EL1 ... MISCREG_ICC_IGRPEN1_EL3:
1992          case MISCREG_ICH_AP0R0_EL2 ... MISCREG_ICH_LR15_EL2:
1993            getGICv3CPUInterface(tc).setMiscReg(misc_reg, newVal);
1994            return;
1995        }
1996    }
1997    setMiscRegNoEffect(misc_reg, newVal);
1998}
1999
2000BaseISADevice &
2001ISA::getGenericTimer(ThreadContext *tc)
2002{
2003    // We only need to create an ISA interface the first time we try
2004    // to access the timer.
2005    if (timer)
2006        return *timer.get();
2007
2008    assert(system);
2009    GenericTimer *generic_timer(system->getGenericTimer());
2010    if (!generic_timer) {
2011        panic("Trying to get a generic timer from a system that hasn't "
2012              "been configured to use a generic timer.\n");
2013    }
2014
2015    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
2016    timer->setThreadContext(tc);
2017
2018    return *timer.get();
2019}
2020
2021BaseISADevice &
2022ISA::getGICv3CPUInterface(ThreadContext *tc)
2023{
2024    panic_if(!gicv3CpuInterface, "GICV3 cpu interface is not registered!");
2025    return *gicv3CpuInterface.get();
2026}
2027
2028}
2029
2030ArmISA::ISA *
2031ArmISAParams::create()
2032{
2033    return new ArmISA::ISA(this);
2034}
2035