isa.cc revision 12666
17405SAli.Saidi@ARM.com/*
212666Sgiacomo.travaglini@arm.com * Copyright (c) 2010-2017 ARM Limited
37405SAli.Saidi@ARM.com * All rights reserved
47405SAli.Saidi@ARM.com *
57405SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67405SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77405SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87405SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97405SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
107405SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117405SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127405SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137405SAli.Saidi@ARM.com *
147405SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
157405SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
167405SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
177405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
187405SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
197405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
207405SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
217405SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
227405SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
237405SAli.Saidi@ARM.com * this software without specific prior written permission.
247405SAli.Saidi@ARM.com *
257405SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
267405SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
277405SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
287405SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
297405SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
307405SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
317405SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
327405SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
337405SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
347405SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
357405SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367405SAli.Saidi@ARM.com *
377405SAli.Saidi@ARM.com * Authors: Gabe Black
387405SAli.Saidi@ARM.com *          Ali Saidi
397405SAli.Saidi@ARM.com */
407405SAli.Saidi@ARM.com
417405SAli.Saidi@ARM.com#include "arch/arm/isa.hh"
4210461SAndreas.Sandberg@ARM.com#include "arch/arm/pmu.hh"
439050Schander.sudanthi@arm.com#include "arch/arm/system.hh"
4412406Sgabeblack@google.com#include "arch/arm/tlb.hh"
4512605Sgiacomo.travaglini@arm.com#include "arch/arm/tlbi_op.hh"
4611793Sbrandon.potter@amd.com#include "cpu/base.hh"
478887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh"
488232Snate@binkert.org#include "debug/Arm.hh"
498232Snate@binkert.org#include "debug/MiscRegs.hh"
5010844Sandreas.sandberg@arm.com#include "dev/arm/generic_timer.hh"
519384SAndreas.Sandberg@arm.com#include "params/ArmISA.hh"
527678Sgblack@eecs.umich.edu#include "sim/faults.hh"
538059SAli.Saidi@ARM.com#include "sim/stat_control.hh"
548284SAli.Saidi@ARM.com#include "sim/system.hh"
557405SAli.Saidi@ARM.com
567405SAli.Saidi@ARM.comnamespace ArmISA
577405SAli.Saidi@ARM.com{
587405SAli.Saidi@ARM.com
599384SAndreas.Sandberg@arm.comISA::ISA(Params *p)
6010461SAndreas.Sandberg@ARM.com    : SimObject(p),
6110461SAndreas.Sandberg@ARM.com      system(NULL),
6211165SRekai.GonzalezAlberquilla@arm.com      _decoderFlavour(p->decoderFlavour),
6312109SRekai.GonzalezAlberquilla@arm.com      _vecRegRenameMode(p->vecRegRenameMode),
6412479SCurtis.Dunham@arm.com      pmu(p->pmu)
659384SAndreas.Sandberg@arm.com{
6611770SCurtis.Dunham@arm.com    miscRegs[MISCREG_SCTLR_RST] = 0;
6710037SARM gem5 Developers
6810461SAndreas.Sandberg@ARM.com    // Hook up a dummy device if we haven't been configured with a
6910461SAndreas.Sandberg@ARM.com    // real PMU. By using a dummy device, we don't need to check that
7010461SAndreas.Sandberg@ARM.com    // the PMU exist every time we try to access a PMU register.
7110461SAndreas.Sandberg@ARM.com    if (!pmu)
7210461SAndreas.Sandberg@ARM.com        pmu = &dummyDevice;
7310461SAndreas.Sandberg@ARM.com
7410609Sandreas.sandberg@arm.com    // Give all ISA devices a pointer to this ISA
7510609Sandreas.sandberg@arm.com    pmu->setISA(this);
7610609Sandreas.sandberg@arm.com
7710037SARM gem5 Developers    system = dynamic_cast<ArmSystem *>(p->system);
7810037SARM gem5 Developers
7910037SARM gem5 Developers    // Cache system-level properties
8010037SARM gem5 Developers    if (FullSystem && system) {
8111771SCurtis.Dunham@arm.com        highestELIs64 = system->highestELIs64();
8210037SARM gem5 Developers        haveSecurity = system->haveSecurity();
8310037SARM gem5 Developers        haveLPAE = system->haveLPAE();
8410037SARM gem5 Developers        haveVirtualization = system->haveVirtualization();
8510037SARM gem5 Developers        haveLargeAsid64 = system->haveLargeAsid64();
8610037SARM gem5 Developers        physAddrRange64 = system->physAddrRange64();
8710037SARM gem5 Developers    } else {
8811771SCurtis.Dunham@arm.com        highestELIs64 = true; // ArmSystem::highestELIs64 does the same
8910037SARM gem5 Developers        haveSecurity = haveLPAE = haveVirtualization = false;
9010037SARM gem5 Developers        haveLargeAsid64 = false;
9110037SARM gem5 Developers        physAddrRange64 = 32;  // dummy value
9210037SARM gem5 Developers    }
9310037SARM gem5 Developers
9412477SCurtis.Dunham@arm.com    initializeMiscRegMetadata();
9510037SARM gem5 Developers    preUnflattenMiscReg();
9610037SARM gem5 Developers
979384SAndreas.Sandberg@arm.com    clear();
989384SAndreas.Sandberg@arm.com}
999384SAndreas.Sandberg@arm.com
10012479SCurtis.Dunham@arm.comstd::vector<struct ISA::MiscRegLUTEntry> ISA::lookUpMiscReg(NUM_MISCREGS);
10112479SCurtis.Dunham@arm.com
1029384SAndreas.Sandberg@arm.comconst ArmISAParams *
1039384SAndreas.Sandberg@arm.comISA::params() const
1049384SAndreas.Sandberg@arm.com{
1059384SAndreas.Sandberg@arm.com    return dynamic_cast<const Params *>(_params);
1069384SAndreas.Sandberg@arm.com}
1079384SAndreas.Sandberg@arm.com
1087427Sgblack@eecs.umich.eduvoid
1097427Sgblack@eecs.umich.eduISA::clear()
1107427Sgblack@eecs.umich.edu{
1119385SAndreas.Sandberg@arm.com    const Params *p(params());
1129385SAndreas.Sandberg@arm.com
1137427Sgblack@eecs.umich.edu    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
1147427Sgblack@eecs.umich.edu    memset(miscRegs, 0, sizeof(miscRegs));
11510037SARM gem5 Developers
11610037SARM gem5 Developers    // Initialize configurable default values
11710037SARM gem5 Developers    miscRegs[MISCREG_MIDR] = p->midr;
11810037SARM gem5 Developers    miscRegs[MISCREG_MIDR_EL1] = p->midr;
11910037SARM gem5 Developers    miscRegs[MISCREG_VPIDR] = p->midr;
12010037SARM gem5 Developers
12110037SARM gem5 Developers    if (FullSystem && system->highestELIs64()) {
12210037SARM gem5 Developers        // Initialize AArch64 state
12310037SARM gem5 Developers        clear64(p);
12410037SARM gem5 Developers        return;
12510037SARM gem5 Developers    }
12610037SARM gem5 Developers
12710037SARM gem5 Developers    // Initialize AArch32 state...
12810037SARM gem5 Developers
1297427Sgblack@eecs.umich.edu    CPSR cpsr = 0;
1307427Sgblack@eecs.umich.edu    cpsr.mode = MODE_USER;
1317427Sgblack@eecs.umich.edu    miscRegs[MISCREG_CPSR] = cpsr;
1327427Sgblack@eecs.umich.edu    updateRegMap(cpsr);
1337427Sgblack@eecs.umich.edu
1347427Sgblack@eecs.umich.edu    SCTLR sctlr = 0;
13510037SARM gem5 Developers    sctlr.te = (bool) sctlr_rst.te;
13610037SARM gem5 Developers    sctlr.nmfi = (bool) sctlr_rst.nmfi;
13710037SARM gem5 Developers    sctlr.v = (bool) sctlr_rst.v;
13810037SARM gem5 Developers    sctlr.u = 1;
1397427Sgblack@eecs.umich.edu    sctlr.xp = 1;
1407427Sgblack@eecs.umich.edu    sctlr.rao2 = 1;
1417427Sgblack@eecs.umich.edu    sctlr.rao3 = 1;
14210037SARM gem5 Developers    sctlr.rao4 = 0xf;  // SCTLR[6:3]
14310204SAli.Saidi@ARM.com    sctlr.uci = 1;
14410204SAli.Saidi@ARM.com    sctlr.dze = 1;
14510037SARM gem5 Developers    miscRegs[MISCREG_SCTLR_NS] = sctlr;
1467427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
14710037SARM gem5 Developers    miscRegs[MISCREG_HCPTR] = 0;
1487427Sgblack@eecs.umich.edu
14910037SARM gem5 Developers    // Start with an event in the mailbox
1507427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SEV_MAILBOX] = 1;
1517427Sgblack@eecs.umich.edu
15210037SARM gem5 Developers    // Separate Instruction and Data TLBs
1537427Sgblack@eecs.umich.edu    miscRegs[MISCREG_TLBTR] = 1;
1547427Sgblack@eecs.umich.edu
1557427Sgblack@eecs.umich.edu    MVFR0 mvfr0 = 0;
1567427Sgblack@eecs.umich.edu    mvfr0.advSimdRegisters = 2;
1577427Sgblack@eecs.umich.edu    mvfr0.singlePrecision = 2;
1587427Sgblack@eecs.umich.edu    mvfr0.doublePrecision = 2;
1597427Sgblack@eecs.umich.edu    mvfr0.vfpExceptionTrapping = 0;
1607427Sgblack@eecs.umich.edu    mvfr0.divide = 1;
1617427Sgblack@eecs.umich.edu    mvfr0.squareRoot = 1;
1627427Sgblack@eecs.umich.edu    mvfr0.shortVectors = 1;
1637427Sgblack@eecs.umich.edu    mvfr0.roundingModes = 1;
1647427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR0] = mvfr0;
1657427Sgblack@eecs.umich.edu
1667427Sgblack@eecs.umich.edu    MVFR1 mvfr1 = 0;
1677427Sgblack@eecs.umich.edu    mvfr1.flushToZero = 1;
1687427Sgblack@eecs.umich.edu    mvfr1.defaultNaN = 1;
1697427Sgblack@eecs.umich.edu    mvfr1.advSimdLoadStore = 1;
1707427Sgblack@eecs.umich.edu    mvfr1.advSimdInteger = 1;
1717427Sgblack@eecs.umich.edu    mvfr1.advSimdSinglePrecision = 1;
1727427Sgblack@eecs.umich.edu    mvfr1.advSimdHalfPrecision = 1;
1737427Sgblack@eecs.umich.edu    mvfr1.vfpHalfPrecision = 1;
1747427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR1] = mvfr1;
1757427Sgblack@eecs.umich.edu
1767436Sdam.sunwoo@arm.com    // Reset values of PRRR and NMRR are implementation dependent
1777436Sdam.sunwoo@arm.com
17810037SARM gem5 Developers    // @todo: PRRR and NMRR in secure state?
17910037SARM gem5 Developers    miscRegs[MISCREG_PRRR_NS] =
1807436Sdam.sunwoo@arm.com        (1 << 19) | // 19
1817436Sdam.sunwoo@arm.com        (0 << 18) | // 18
1827436Sdam.sunwoo@arm.com        (0 << 17) | // 17
1837436Sdam.sunwoo@arm.com        (1 << 16) | // 16
1847436Sdam.sunwoo@arm.com        (2 << 14) | // 15:14
1857436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
1867436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
1877436Sdam.sunwoo@arm.com        (2 << 8)  | // 9:8
1887436Sdam.sunwoo@arm.com        (2 << 6)  | // 7:6
1897436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
1907436Sdam.sunwoo@arm.com        (1 << 2)  | // 3:2
1917436Sdam.sunwoo@arm.com        0;          // 1:0
19210037SARM gem5 Developers    miscRegs[MISCREG_NMRR_NS] =
1937436Sdam.sunwoo@arm.com        (1 << 30) | // 31:30
1947436Sdam.sunwoo@arm.com        (0 << 26) | // 27:26
1957436Sdam.sunwoo@arm.com        (0 << 24) | // 25:24
1967436Sdam.sunwoo@arm.com        (3 << 22) | // 23:22
1977436Sdam.sunwoo@arm.com        (2 << 20) | // 21:20
1987436Sdam.sunwoo@arm.com        (0 << 18) | // 19:18
1997436Sdam.sunwoo@arm.com        (0 << 16) | // 17:16
2007436Sdam.sunwoo@arm.com        (1 << 14) | // 15:14
2017436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
2027436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
2037436Sdam.sunwoo@arm.com        (0 << 8)  | // 9:8
2047436Sdam.sunwoo@arm.com        (3 << 6)  | // 7:6
2057436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
2067436Sdam.sunwoo@arm.com        (0 << 2)  | // 3:2
2077436Sdam.sunwoo@arm.com        0;          // 1:0
2087436Sdam.sunwoo@arm.com
2097644Sali.saidi@arm.com    miscRegs[MISCREG_CPACR] = 0;
2108147SAli.Saidi@ARM.com
2119385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
2129385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
2139385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
2149385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
2159385SAndreas.Sandberg@arm.com
2169385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
2179385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
2189385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
2199385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
2209385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
2219385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
2229385SAndreas.Sandberg@arm.com
2239385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_FPSID] = p->fpsid;
2249385SAndreas.Sandberg@arm.com
22510037SARM gem5 Developers    if (haveLPAE) {
22610037SARM gem5 Developers        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
22710037SARM gem5 Developers        ttbcr.eae = 0;
22810037SARM gem5 Developers        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
22910037SARM gem5 Developers        // Enforce consistency with system-level settings
23010037SARM gem5 Developers        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
23110037SARM gem5 Developers    }
23210037SARM gem5 Developers
23310037SARM gem5 Developers    if (haveSecurity) {
23410037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_S] = sctlr;
23510037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 0;
23610037SARM gem5 Developers        miscRegs[MISCREG_VBAR_S] = 0;
23710037SARM gem5 Developers    } else {
23810037SARM gem5 Developers        // we're always non-secure
23910037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 1;
24010037SARM gem5 Developers    }
2418147SAli.Saidi@ARM.com
2427427Sgblack@eecs.umich.edu    //XXX We need to initialize the rest of the state.
2437427Sgblack@eecs.umich.edu}
2447427Sgblack@eecs.umich.edu
24510037SARM gem5 Developersvoid
24610037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p)
24710037SARM gem5 Developers{
24810037SARM gem5 Developers    CPSR cpsr = 0;
24910037SARM gem5 Developers    Addr rvbar = system->resetAddr64();
25010037SARM gem5 Developers    switch (system->highestEL()) {
25110037SARM gem5 Developers        // Set initial EL to highest implemented EL using associated stack
25210037SARM gem5 Developers        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
25310037SARM gem5 Developers        // value
25410037SARM gem5 Developers      case EL3:
25510037SARM gem5 Developers        cpsr.mode = MODE_EL3H;
25610037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
25710037SARM gem5 Developers        break;
25810037SARM gem5 Developers      case EL2:
25910037SARM gem5 Developers        cpsr.mode = MODE_EL2H;
26010037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
26110037SARM gem5 Developers        break;
26210037SARM gem5 Developers      case EL1:
26310037SARM gem5 Developers        cpsr.mode = MODE_EL1H;
26410037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
26510037SARM gem5 Developers        break;
26610037SARM gem5 Developers      default:
26710037SARM gem5 Developers        panic("Invalid highest implemented exception level");
26810037SARM gem5 Developers        break;
26910037SARM gem5 Developers    }
27010037SARM gem5 Developers
27110037SARM gem5 Developers    // Initialize rest of CPSR
27210037SARM gem5 Developers    cpsr.daif = 0xf;  // Mask all interrupts
27310037SARM gem5 Developers    cpsr.ss = 0;
27410037SARM gem5 Developers    cpsr.il = 0;
27510037SARM gem5 Developers    miscRegs[MISCREG_CPSR] = cpsr;
27610037SARM gem5 Developers    updateRegMap(cpsr);
27710037SARM gem5 Developers
27810037SARM gem5 Developers    // Initialize other control registers
27910037SARM gem5 Developers    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
28010037SARM gem5 Developers    if (haveSecurity) {
28111770SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830;
28210037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
28311574SCurtis.Dunham@arm.com    } else if (haveVirtualization) {
28411770SCurtis.Dunham@arm.com        // also  MISCREG_SCTLR_EL2 (by mapping)
28511770SCurtis.Dunham@arm.com        miscRegs[MISCREG_HSCTLR] = 0x30c50830;
28610037SARM gem5 Developers    } else {
28711770SCurtis.Dunham@arm.com        // also  MISCREG_SCTLR_EL1 (by mapping)
28811770SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init
28910037SARM gem5 Developers        // Always non-secure
29010037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3] = 1;
29110037SARM gem5 Developers    }
29210037SARM gem5 Developers
29310037SARM gem5 Developers    // Initialize configurable id registers
29410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
29510037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
29610461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
29710461SAndreas.Sandberg@ARM.com        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
29810461SAndreas.Sandberg@ARM.com        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
29910461SAndreas.Sandberg@ARM.com
30010037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
30110037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
30210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
30310037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
30410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
30510037SARM gem5 Developers
30610461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0_EL1] =
30710461SAndreas.Sandberg@ARM.com        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
30810461SAndreas.Sandberg@ARM.com
30910461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
31010461SAndreas.Sandberg@ARM.com
31110037SARM gem5 Developers    // Enforce consistency with system-level settings...
31210037SARM gem5 Developers
31310037SARM gem5 Developers    // EL3
31410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
31510037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
31611574SCurtis.Dunham@arm.com        haveSecurity ? 0x2 : 0x0);
31710037SARM gem5 Developers    // EL2
31810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
31910037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
32011574SCurtis.Dunham@arm.com        haveVirtualization ? 0x2 : 0x0);
32110037SARM gem5 Developers    // Large ASID support
32210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
32310037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
32410037SARM gem5 Developers        haveLargeAsid64 ? 0x2 : 0x0);
32510037SARM gem5 Developers    // Physical address size
32610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
32710037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
32810037SARM gem5 Developers        encodePhysAddrRange64(physAddrRange64));
32910037SARM gem5 Developers}
33010037SARM gem5 Developers
3317405SAli.Saidi@ARM.comMiscReg
33210035Sandreas.hansson@arm.comISA::readMiscRegNoEffect(int misc_reg) const
3337405SAli.Saidi@ARM.com{
3347405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
3357614Sminkyu.jeong@arm.com
33612478SCurtis.Dunham@arm.com    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
33712478SCurtis.Dunham@arm.com    const auto &map = getMiscIndices(misc_reg);
33812478SCurtis.Dunham@arm.com    int lower = map.first, upper = map.second;
33912478SCurtis.Dunham@arm.com    // NB!: apply architectural masks according to desired register,
34012478SCurtis.Dunham@arm.com    // despite possibly getting value from different (mapped) register.
34112478SCurtis.Dunham@arm.com    auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32))
34212478SCurtis.Dunham@arm.com                                          |(miscRegs[upper] << 32));
34312478SCurtis.Dunham@arm.com    if (val & reg.res0()) {
34412478SCurtis.Dunham@arm.com        DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n",
34512478SCurtis.Dunham@arm.com                miscRegName[misc_reg], val & reg.res0());
34612478SCurtis.Dunham@arm.com    }
34712478SCurtis.Dunham@arm.com    if ((val & reg.res1()) != reg.res1()) {
34812478SCurtis.Dunham@arm.com        DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n",
34912478SCurtis.Dunham@arm.com                miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1());
35012478SCurtis.Dunham@arm.com    }
35112478SCurtis.Dunham@arm.com    return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao
3527405SAli.Saidi@ARM.com}
3537405SAli.Saidi@ARM.com
3547405SAli.Saidi@ARM.com
3557405SAli.Saidi@ARM.comMiscReg
3567405SAli.Saidi@ARM.comISA::readMiscReg(int misc_reg, ThreadContext *tc)
3577405SAli.Saidi@ARM.com{
35810037SARM gem5 Developers    CPSR cpsr = 0;
35910037SARM gem5 Developers    PCState pc = 0;
36010037SARM gem5 Developers    SCR scr = 0;
3619050Schander.sudanthi@arm.com
3627405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
36310037SARM gem5 Developers        cpsr = miscRegs[misc_reg];
36410037SARM gem5 Developers        pc = tc->pcState();
3657720Sgblack@eecs.umich.edu        cpsr.j = pc.jazelle() ? 1 : 0;
3667720Sgblack@eecs.umich.edu        cpsr.t = pc.thumb() ? 1 : 0;
3677405SAli.Saidi@ARM.com        return cpsr;
3687405SAli.Saidi@ARM.com    }
3697757SAli.Saidi@ARM.com
37010037SARM gem5 Developers#ifndef NDEBUG
37110037SARM gem5 Developers    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
37210037SARM gem5 Developers        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
37310037SARM gem5 Developers            warn("Unimplemented system register %s read.\n",
37410037SARM gem5 Developers                 miscRegName[misc_reg]);
37510037SARM gem5 Developers        else
37610037SARM gem5 Developers            panic("Unimplemented system register %s read.\n",
37710037SARM gem5 Developers                  miscRegName[misc_reg]);
37810037SARM gem5 Developers    }
37910037SARM gem5 Developers#endif
38010037SARM gem5 Developers
38110037SARM gem5 Developers    switch (unflattenMiscReg(misc_reg)) {
38210037SARM gem5 Developers      case MISCREG_HCR:
38310037SARM gem5 Developers        {
38410037SARM gem5 Developers            if (!haveVirtualization)
38510037SARM gem5 Developers                return 0;
38610037SARM gem5 Developers            else
38710037SARM gem5 Developers                return readMiscRegNoEffect(MISCREG_HCR);
38810037SARM gem5 Developers        }
38910037SARM gem5 Developers      case MISCREG_CPACR:
39010037SARM gem5 Developers        {
39110037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
39210037SARM gem5 Developers            CPACR cpacrMask = 0;
39310037SARM gem5 Developers            // Only cp10, cp11, and ase are implemented, nothing else should
39410037SARM gem5 Developers            // be readable? (straight copy from the write code)
39510037SARM gem5 Developers            cpacrMask.cp10 = ones;
39610037SARM gem5 Developers            cpacrMask.cp11 = ones;
39710037SARM gem5 Developers            cpacrMask.asedis = ones;
39810037SARM gem5 Developers
39910037SARM gem5 Developers            // Security Extensions may limit the readability of CPACR
40010037SARM gem5 Developers            if (haveSecurity) {
40110037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
40210037SARM gem5 Developers                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
40310037SARM gem5 Developers                if (scr.ns && (cpsr.mode != MODE_MON)) {
40410037SARM gem5 Developers                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
40510037SARM gem5 Developers                    // NB: Skipping the full loop, here
40610037SARM gem5 Developers                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
40710037SARM gem5 Developers                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
40810037SARM gem5 Developers                }
40910037SARM gem5 Developers            }
41010037SARM gem5 Developers            MiscReg val = readMiscRegNoEffect(MISCREG_CPACR);
41110037SARM gem5 Developers            val &= cpacrMask;
41210037SARM gem5 Developers            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
41310037SARM gem5 Developers                    miscRegName[misc_reg], val);
41410037SARM gem5 Developers            return val;
41510037SARM gem5 Developers        }
4168284SAli.Saidi@ARM.com      case MISCREG_MPIDR:
41710037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
41810037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
41910037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
42010037SARM gem5 Developers            return getMPIDR(system, tc);
4219050Schander.sudanthi@arm.com        } else {
42210037SARM gem5 Developers            return readMiscReg(MISCREG_VMPIDR, tc);
42310037SARM gem5 Developers        }
42410037SARM gem5 Developers            break;
42510037SARM gem5 Developers      case MISCREG_MPIDR_EL1:
42610037SARM gem5 Developers        // @todo in the absence of v8 virtualization support just return MPIDR_EL1
42710037SARM gem5 Developers        return getMPIDR(system, tc) & 0xffffffff;
42810037SARM gem5 Developers      case MISCREG_VMPIDR:
42910037SARM gem5 Developers        // top bit defined as RES1
43010037SARM gem5 Developers        return readMiscRegNoEffect(misc_reg) | 0x80000000;
43110037SARM gem5 Developers      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
43210037SARM gem5 Developers      case MISCREG_REVIDR:  // not implemented, so alias MIDR
43310037SARM gem5 Developers      case MISCREG_MIDR:
43410037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
43510037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
43610037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
43710037SARM gem5 Developers            return readMiscRegNoEffect(misc_reg);
43810037SARM gem5 Developers        } else {
43910037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_VPIDR);
4409050Schander.sudanthi@arm.com        }
4418284SAli.Saidi@ARM.com        break;
44210037SARM gem5 Developers      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
44310037SARM gem5 Developers      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
44410037SARM gem5 Developers      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
44510037SARM gem5 Developers      case MISCREG_AIDR:  // AUX ID set to 0
44610037SARM gem5 Developers      case MISCREG_TCMTR: // No TCM's
44710037SARM gem5 Developers        return 0;
44810037SARM gem5 Developers
4497405SAli.Saidi@ARM.com      case MISCREG_CLIDR:
4507731SAli.Saidi@ARM.com        warn_once("The clidr register always reports 0 caches.\n");
4518468Swade.walker@arm.com        warn_once("clidr LoUIS field of 0b001 to match current "
4528468Swade.walker@arm.com                  "ARM implementations.\n");
4538468Swade.walker@arm.com        return 0x00200000;
4547405SAli.Saidi@ARM.com      case MISCREG_CCSIDR:
4557731SAli.Saidi@ARM.com        warn_once("The ccsidr register isn't implemented and "
4567405SAli.Saidi@ARM.com                "always reads as 0.\n");
4577405SAli.Saidi@ARM.com        break;
45811809Sbaz21@cam.ac.uk      case MISCREG_CTR:                 // AArch32, ARMv7, top bit set
45911809Sbaz21@cam.ac.uk      case MISCREG_CTR_EL0:             // AArch64
4609130Satgutier@umich.edu        {
4619130Satgutier@umich.edu            //all caches have the same line size in gem5
4629130Satgutier@umich.edu            //4 byte words in ARM
4639130Satgutier@umich.edu            unsigned lineSizeWords =
4649814Sandreas.hansson@arm.com                tc->getSystemPtr()->cacheLineSize() / 4;
4659130Satgutier@umich.edu            unsigned log2LineSizeWords = 0;
4669130Satgutier@umich.edu
4679130Satgutier@umich.edu            while (lineSizeWords >>= 1) {
4689130Satgutier@umich.edu                ++log2LineSizeWords;
4699130Satgutier@umich.edu            }
4709130Satgutier@umich.edu
4719130Satgutier@umich.edu            CTR ctr = 0;
4729130Satgutier@umich.edu            //log2 of minimun i-cache line size (words)
4739130Satgutier@umich.edu            ctr.iCacheLineSize = log2LineSizeWords;
4749130Satgutier@umich.edu            //b11 - gem5 uses pipt
4759130Satgutier@umich.edu            ctr.l1IndexPolicy = 0x3;
4769130Satgutier@umich.edu            //log2 of minimum d-cache line size (words)
4779130Satgutier@umich.edu            ctr.dCacheLineSize = log2LineSizeWords;
4789130Satgutier@umich.edu            //log2 of max reservation size (words)
4799130Satgutier@umich.edu            ctr.erg = log2LineSizeWords;
4809130Satgutier@umich.edu            //log2 of max writeback size (words)
4819130Satgutier@umich.edu            ctr.cwg = log2LineSizeWords;
4829130Satgutier@umich.edu            //b100 - gem5 format is ARMv7
4839130Satgutier@umich.edu            ctr.format = 0x4;
4849130Satgutier@umich.edu
4859130Satgutier@umich.edu            return ctr;
4869130Satgutier@umich.edu        }
4877583SAli.Saidi@arm.com      case MISCREG_ACTLR:
4887583SAli.Saidi@arm.com        warn("Not doing anything for miscreg ACTLR\n");
4897583SAli.Saidi@arm.com        break;
49010461SAndreas.Sandberg@ARM.com
49110461SAndreas.Sandberg@ARM.com      case MISCREG_PMXEVTYPER_PMCCFILTR:
49210461SAndreas.Sandberg@ARM.com      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
49310461SAndreas.Sandberg@ARM.com      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
49410461SAndreas.Sandberg@ARM.com      case MISCREG_PMCR ... MISCREG_PMOVSSET:
49510461SAndreas.Sandberg@ARM.com        return pmu->readMiscReg(misc_reg);
49610461SAndreas.Sandberg@ARM.com
4978302SAli.Saidi@ARM.com      case MISCREG_CPSR_Q:
4988302SAli.Saidi@ARM.com        panic("shouldn't be reading this register seperately\n");
4997783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_QC:
5007783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
5017783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_EXC:
5027783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
50310037SARM gem5 Developers      case MISCREG_FPSR:
50410037SARM gem5 Developers        {
50510037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
50610037SARM gem5 Developers            FPSCR fpscrMask = 0;
50710037SARM gem5 Developers            fpscrMask.ioc = ones;
50810037SARM gem5 Developers            fpscrMask.dzc = ones;
50910037SARM gem5 Developers            fpscrMask.ofc = ones;
51010037SARM gem5 Developers            fpscrMask.ufc = ones;
51110037SARM gem5 Developers            fpscrMask.ixc = ones;
51210037SARM gem5 Developers            fpscrMask.idc = ones;
51310037SARM gem5 Developers            fpscrMask.qc = ones;
51410037SARM gem5 Developers            fpscrMask.v = ones;
51510037SARM gem5 Developers            fpscrMask.c = ones;
51610037SARM gem5 Developers            fpscrMask.z = ones;
51710037SARM gem5 Developers            fpscrMask.n = ones;
51810037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
51910037SARM gem5 Developers        }
52010037SARM gem5 Developers      case MISCREG_FPCR:
52110037SARM gem5 Developers        {
52210037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
52310037SARM gem5 Developers            FPSCR fpscrMask  = 0;
52410037SARM gem5 Developers            fpscrMask.ioe = ones;
52510037SARM gem5 Developers            fpscrMask.dze = ones;
52610037SARM gem5 Developers            fpscrMask.ofe = ones;
52710037SARM gem5 Developers            fpscrMask.ufe = ones;
52810037SARM gem5 Developers            fpscrMask.ixe = ones;
52910037SARM gem5 Developers            fpscrMask.ide = ones;
53010037SARM gem5 Developers            fpscrMask.len    = ones;
53110037SARM gem5 Developers            fpscrMask.stride = ones;
53210037SARM gem5 Developers            fpscrMask.rMode  = ones;
53310037SARM gem5 Developers            fpscrMask.fz     = ones;
53410037SARM gem5 Developers            fpscrMask.dn     = ones;
53510037SARM gem5 Developers            fpscrMask.ahp    = ones;
53610037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
53710037SARM gem5 Developers        }
53810037SARM gem5 Developers      case MISCREG_NZCV:
53910037SARM gem5 Developers        {
54010037SARM gem5 Developers            CPSR cpsr = 0;
54110338SCurtis.Dunham@arm.com            cpsr.nz   = tc->readCCReg(CCREG_NZ);
54210338SCurtis.Dunham@arm.com            cpsr.c    = tc->readCCReg(CCREG_C);
54310338SCurtis.Dunham@arm.com            cpsr.v    = tc->readCCReg(CCREG_V);
54410037SARM gem5 Developers            return cpsr;
54510037SARM gem5 Developers        }
54610037SARM gem5 Developers      case MISCREG_DAIF:
54710037SARM gem5 Developers        {
54810037SARM gem5 Developers            CPSR cpsr = 0;
54910037SARM gem5 Developers            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
55010037SARM gem5 Developers            return cpsr;
55110037SARM gem5 Developers        }
55210037SARM gem5 Developers      case MISCREG_SP_EL0:
55310037SARM gem5 Developers        {
55410037SARM gem5 Developers            return tc->readIntReg(INTREG_SP0);
55510037SARM gem5 Developers        }
55610037SARM gem5 Developers      case MISCREG_SP_EL1:
55710037SARM gem5 Developers        {
55810037SARM gem5 Developers            return tc->readIntReg(INTREG_SP1);
55910037SARM gem5 Developers        }
56010037SARM gem5 Developers      case MISCREG_SP_EL2:
56110037SARM gem5 Developers        {
56210037SARM gem5 Developers            return tc->readIntReg(INTREG_SP2);
56310037SARM gem5 Developers        }
56410037SARM gem5 Developers      case MISCREG_SPSEL:
56510037SARM gem5 Developers        {
56610037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0x1;
56710037SARM gem5 Developers        }
56810037SARM gem5 Developers      case MISCREG_CURRENTEL:
56910037SARM gem5 Developers        {
57010037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0xc;
57110037SARM gem5 Developers        }
5728549Sdaniel.johnson@arm.com      case MISCREG_L2CTLR:
5738868SMatt.Horsnell@arm.com        {
5748868SMatt.Horsnell@arm.com            // mostly unimplemented, just set NumCPUs field from sim and return
5758868SMatt.Horsnell@arm.com            L2CTLR l2ctlr = 0;
5768868SMatt.Horsnell@arm.com            // b00:1CPU to b11:4CPUs
5778868SMatt.Horsnell@arm.com            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
5788868SMatt.Horsnell@arm.com            return l2ctlr;
5798868SMatt.Horsnell@arm.com        }
5808868SMatt.Horsnell@arm.com      case MISCREG_DBGDIDR:
5818868SMatt.Horsnell@arm.com        /* For now just implement the version number.
58210461SAndreas.Sandberg@ARM.com         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
5838868SMatt.Horsnell@arm.com         */
58410461SAndreas.Sandberg@ARM.com        return 0x5 << 16;
58510037SARM gem5 Developers      case MISCREG_DBGDSCRint:
5868868SMatt.Horsnell@arm.com        return 0;
58710037SARM gem5 Developers      case MISCREG_ISR:
58811150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
58910037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR),
59010037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
59110037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR));
59210037SARM gem5 Developers      case MISCREG_ISR_EL1:
59311150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
59410037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR_EL2),
59510037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
59610037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR_EL3));
59710037SARM gem5 Developers      case MISCREG_DCZID_EL0:
59810037SARM gem5 Developers        return 0x04;  // DC ZVA clear 64-byte chunks
59910037SARM gem5 Developers      case MISCREG_HCPTR:
60010037SARM gem5 Developers        {
60110037SARM gem5 Developers            MiscReg val = readMiscRegNoEffect(misc_reg);
60210037SARM gem5 Developers            // The trap bit associated with CP14 is defined as RAZ
60310037SARM gem5 Developers            val &= ~(1 << 14);
60410037SARM gem5 Developers            // If a CP bit in NSACR is 0 then the corresponding bit in
60510037SARM gem5 Developers            // HCPTR is RAO/WI
60610037SARM gem5 Developers            bool secure_lookup = haveSecurity &&
60710037SARM gem5 Developers                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
60810037SARM gem5 Developers                              readMiscRegNoEffect(MISCREG_CPSR));
60910037SARM gem5 Developers            if (!secure_lookup) {
61010037SARM gem5 Developers                MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR);
61110037SARM gem5 Developers                val |= (mask ^ 0x7FFF) & 0xBFFF;
61210037SARM gem5 Developers            }
61310037SARM gem5 Developers            // Set the bits for unimplemented coprocessors to RAO/WI
61410037SARM gem5 Developers            val |= 0x33FF;
61510037SARM gem5 Developers            return (val);
61610037SARM gem5 Developers        }
61710037SARM gem5 Developers      case MISCREG_HDFAR: // alias for secure DFAR
61810037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_DFAR_S);
61910037SARM gem5 Developers      case MISCREG_HIFAR: // alias for secure IFAR
62010037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_IFAR_S);
62110037SARM gem5 Developers      case MISCREG_HVBAR: // bottom bits reserved
62210037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0;
62311769SCurtis.Dunham@arm.com      case MISCREG_SCTLR:
62411769SCurtis.Dunham@arm.com        return (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818;
62510037SARM gem5 Developers      case MISCREG_SCTLR_EL1:
62611770SCurtis.Dunham@arm.com        return (readMiscRegNoEffect(misc_reg) & 0x37DDDBBF) | 0x30D00800;
62711770SCurtis.Dunham@arm.com      case MISCREG_SCTLR_EL2:
62810037SARM gem5 Developers      case MISCREG_SCTLR_EL3:
62911770SCurtis.Dunham@arm.com      case MISCREG_HSCTLR:
63011769SCurtis.Dunham@arm.com        return (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830;
63110844Sandreas.sandberg@arm.com
63211772SCurtis.Dunham@arm.com      case MISCREG_ID_PFR0:
63311772SCurtis.Dunham@arm.com        // !ThumbEE | !Jazelle | Thumb | ARM
63411772SCurtis.Dunham@arm.com        return 0x00000031;
63511772SCurtis.Dunham@arm.com      case MISCREG_ID_PFR1:
63611774SCurtis.Dunham@arm.com        {   // Timer | Virti | !M Profile | TrustZone | ARMv4
63711774SCurtis.Dunham@arm.com            bool haveTimer = (system->getGenericTimer() != NULL);
63811774SCurtis.Dunham@arm.com            return 0x00000001
63911774SCurtis.Dunham@arm.com                 | (haveSecurity       ? 0x00000010 : 0x0)
64011774SCurtis.Dunham@arm.com                 | (haveVirtualization ? 0x00001000 : 0x0)
64111774SCurtis.Dunham@arm.com                 | (haveTimer          ? 0x00010000 : 0x0);
64211774SCurtis.Dunham@arm.com        }
64311773SCurtis.Dunham@arm.com      case MISCREG_ID_AA64PFR0_EL1:
64411773SCurtis.Dunham@arm.com        return 0x0000000000000002   // AArch{64,32} supported at EL0
64511773SCurtis.Dunham@arm.com             | 0x0000000000000020                             // EL1
64611773SCurtis.Dunham@arm.com             | (haveVirtualization ? 0x0000000000000200 : 0)  // EL2
64711773SCurtis.Dunham@arm.com             | (haveSecurity       ? 0x0000000000002000 : 0); // EL3
64811773SCurtis.Dunham@arm.com      case MISCREG_ID_AA64PFR1_EL1:
64911773SCurtis.Dunham@arm.com        return 0; // bits [63:0] RES0 (reserved for future use)
65011772SCurtis.Dunham@arm.com
65110037SARM gem5 Developers      // Generic Timer registers
65210844Sandreas.sandberg@arm.com      case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
65310844Sandreas.sandberg@arm.com      case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
65410844Sandreas.sandberg@arm.com      case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
65510844Sandreas.sandberg@arm.com      case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
65610844Sandreas.sandberg@arm.com        return getGenericTimer(tc).readMiscReg(misc_reg);
65710844Sandreas.sandberg@arm.com
65810188Sgeoffrey.blake@arm.com      default:
65910037SARM gem5 Developers        break;
66010037SARM gem5 Developers
6617405SAli.Saidi@ARM.com    }
6627405SAli.Saidi@ARM.com    return readMiscRegNoEffect(misc_reg);
6637405SAli.Saidi@ARM.com}
6647405SAli.Saidi@ARM.com
6657405SAli.Saidi@ARM.comvoid
6667405SAli.Saidi@ARM.comISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
6677405SAli.Saidi@ARM.com{
6687405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
6697614Sminkyu.jeong@arm.com
67012478SCurtis.Dunham@arm.com    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
67112478SCurtis.Dunham@arm.com    const auto &map = getMiscIndices(misc_reg);
67212478SCurtis.Dunham@arm.com    int lower = map.first, upper = map.second;
67312478SCurtis.Dunham@arm.com
67412478SCurtis.Dunham@arm.com    auto v = (val & ~reg.wi()) | reg.rao();
67511771SCurtis.Dunham@arm.com    if (upper > 0) {
67612478SCurtis.Dunham@arm.com        miscRegs[lower] = bits(v, 31, 0);
67712478SCurtis.Dunham@arm.com        miscRegs[upper] = bits(v, 63, 32);
67810037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
67912478SCurtis.Dunham@arm.com                misc_reg, lower, upper, v);
68010037SARM gem5 Developers    } else {
68112478SCurtis.Dunham@arm.com        miscRegs[lower] = v;
68210037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
68312478SCurtis.Dunham@arm.com                misc_reg, lower, v);
68410037SARM gem5 Developers    }
6857405SAli.Saidi@ARM.com}
6867405SAli.Saidi@ARM.com
6877405SAli.Saidi@ARM.comvoid
6887405SAli.Saidi@ARM.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
6897405SAli.Saidi@ARM.com{
6907749SAli.Saidi@ARM.com
6917405SAli.Saidi@ARM.com    MiscReg newVal = val;
69210037SARM gem5 Developers    bool secure_lookup;
69310037SARM gem5 Developers    SCR scr;
6948284SAli.Saidi@ARM.com
6957405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
6967405SAli.Saidi@ARM.com        updateRegMap(val);
6977749SAli.Saidi@ARM.com
6987749SAli.Saidi@ARM.com
6997749SAli.Saidi@ARM.com        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
7007749SAli.Saidi@ARM.com        int old_mode = old_cpsr.mode;
7017405SAli.Saidi@ARM.com        CPSR cpsr = val;
70212510Sgiacomo.travaglini@arm.com        if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) {
70312406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
70412406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
7057749SAli.Saidi@ARM.com        }
7067749SAli.Saidi@ARM.com
7077614Sminkyu.jeong@arm.com        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
7087614Sminkyu.jeong@arm.com                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
7097720Sgblack@eecs.umich.edu        PCState pc = tc->pcState();
7107720Sgblack@eecs.umich.edu        pc.nextThumb(cpsr.t);
7117720Sgblack@eecs.umich.edu        pc.nextJazelle(cpsr.j);
7128887Sgeoffrey.blake@arm.com
7138887Sgeoffrey.blake@arm.com        // Follow slightly different semantics if a CheckerCPU object
7148887Sgeoffrey.blake@arm.com        // is connected
7158887Sgeoffrey.blake@arm.com        CheckerCPU *checker = tc->getCheckerCpuPtr();
7168887Sgeoffrey.blake@arm.com        if (checker) {
7178887Sgeoffrey.blake@arm.com            tc->pcStateNoRecord(pc);
7188887Sgeoffrey.blake@arm.com        } else {
7198887Sgeoffrey.blake@arm.com            tc->pcState(pc);
7208887Sgeoffrey.blake@arm.com        }
7217408Sgblack@eecs.umich.edu    } else {
72210037SARM gem5 Developers#ifndef NDEBUG
72310037SARM gem5 Developers        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
72410037SARM gem5 Developers            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
72510037SARM gem5 Developers                warn("Unimplemented system register %s write with %#x.\n",
72610037SARM gem5 Developers                    miscRegName[misc_reg], val);
72710037SARM gem5 Developers            else
72810037SARM gem5 Developers                panic("Unimplemented system register %s write with %#x.\n",
72910037SARM gem5 Developers                    miscRegName[misc_reg], val);
73010037SARM gem5 Developers        }
73110037SARM gem5 Developers#endif
73210037SARM gem5 Developers        switch (unflattenMiscReg(misc_reg)) {
7337408Sgblack@eecs.umich.edu          case MISCREG_CPACR:
7347408Sgblack@eecs.umich.edu            {
7358206SWilliam.Wang@arm.com
7368206SWilliam.Wang@arm.com                const uint32_t ones = (uint32_t)(-1);
7378206SWilliam.Wang@arm.com                CPACR cpacrMask = 0;
7388206SWilliam.Wang@arm.com                // Only cp10, cp11, and ase are implemented, nothing else should
7398206SWilliam.Wang@arm.com                // be writable
7408206SWilliam.Wang@arm.com                cpacrMask.cp10 = ones;
7418206SWilliam.Wang@arm.com                cpacrMask.cp11 = ones;
7428206SWilliam.Wang@arm.com                cpacrMask.asedis = ones;
74310037SARM gem5 Developers
74410037SARM gem5 Developers                // Security Extensions may limit the writability of CPACR
74510037SARM gem5 Developers                if (haveSecurity) {
74610037SARM gem5 Developers                    scr = readMiscRegNoEffect(MISCREG_SCR);
74710037SARM gem5 Developers                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
74810037SARM gem5 Developers                    if (scr.ns && (cpsr.mode != MODE_MON)) {
74910037SARM gem5 Developers                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
75010037SARM gem5 Developers                        // NB: Skipping the full loop, here
75110037SARM gem5 Developers                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
75210037SARM gem5 Developers                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
75310037SARM gem5 Developers                    }
75410037SARM gem5 Developers                }
75510037SARM gem5 Developers
75610037SARM gem5 Developers                MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR);
7578206SWilliam.Wang@arm.com                newVal &= cpacrMask;
75810037SARM gem5 Developers                newVal |= old_val & ~cpacrMask;
75910037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
76010037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
76110037SARM gem5 Developers            }
76210037SARM gem5 Developers            break;
76310037SARM gem5 Developers          case MISCREG_CPACR_EL1:
76410037SARM gem5 Developers            {
76510037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
76610037SARM gem5 Developers                CPACR cpacrMask = 0;
76710037SARM gem5 Developers                cpacrMask.tta = ones;
76810037SARM gem5 Developers                cpacrMask.fpen = ones;
76910037SARM gem5 Developers                newVal &= cpacrMask;
77010037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
77110037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
77210037SARM gem5 Developers            }
77310037SARM gem5 Developers            break;
77410037SARM gem5 Developers          case MISCREG_CPTR_EL2:
77510037SARM gem5 Developers            {
77610037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
77710037SARM gem5 Developers                CPTR cptrMask = 0;
77810037SARM gem5 Developers                cptrMask.tcpac = ones;
77910037SARM gem5 Developers                cptrMask.tta = ones;
78010037SARM gem5 Developers                cptrMask.tfp = ones;
78110037SARM gem5 Developers                newVal &= cptrMask;
78210037SARM gem5 Developers                cptrMask = 0;
78310037SARM gem5 Developers                cptrMask.res1_13_12_el2 = ones;
78410037SARM gem5 Developers                cptrMask.res1_9_0_el2 = ones;
78510037SARM gem5 Developers                newVal |= cptrMask;
78610037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
78710037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
78810037SARM gem5 Developers            }
78910037SARM gem5 Developers            break;
79010037SARM gem5 Developers          case MISCREG_CPTR_EL3:
79110037SARM gem5 Developers            {
79210037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
79310037SARM gem5 Developers                CPTR cptrMask = 0;
79410037SARM gem5 Developers                cptrMask.tcpac = ones;
79510037SARM gem5 Developers                cptrMask.tta = ones;
79610037SARM gem5 Developers                cptrMask.tfp = ones;
79710037SARM gem5 Developers                newVal &= cptrMask;
7988206SWilliam.Wang@arm.com                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
7998206SWilliam.Wang@arm.com                        miscRegName[misc_reg], newVal);
8007408Sgblack@eecs.umich.edu            }
8017408Sgblack@eecs.umich.edu            break;
8027408Sgblack@eecs.umich.edu          case MISCREG_CSSELR:
8037731SAli.Saidi@ARM.com            warn_once("The csselr register isn't implemented.\n");
8048206SWilliam.Wang@arm.com            return;
80510037SARM gem5 Developers
80610037SARM gem5 Developers          case MISCREG_DC_ZVA_Xt:
80710037SARM gem5 Developers            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
80810037SARM gem5 Developers            return;
80910037SARM gem5 Developers
8107408Sgblack@eecs.umich.edu          case MISCREG_FPSCR:
8117408Sgblack@eecs.umich.edu            {
8127408Sgblack@eecs.umich.edu                const uint32_t ones = (uint32_t)(-1);
8137408Sgblack@eecs.umich.edu                FPSCR fpscrMask = 0;
8147408Sgblack@eecs.umich.edu                fpscrMask.ioc = ones;
8157408Sgblack@eecs.umich.edu                fpscrMask.dzc = ones;
8167408Sgblack@eecs.umich.edu                fpscrMask.ofc = ones;
8177408Sgblack@eecs.umich.edu                fpscrMask.ufc = ones;
8187408Sgblack@eecs.umich.edu                fpscrMask.ixc = ones;
8197408Sgblack@eecs.umich.edu                fpscrMask.idc = ones;
82010037SARM gem5 Developers                fpscrMask.ioe = ones;
82110037SARM gem5 Developers                fpscrMask.dze = ones;
82210037SARM gem5 Developers                fpscrMask.ofe = ones;
82310037SARM gem5 Developers                fpscrMask.ufe = ones;
82410037SARM gem5 Developers                fpscrMask.ixe = ones;
82510037SARM gem5 Developers                fpscrMask.ide = ones;
8267408Sgblack@eecs.umich.edu                fpscrMask.len = ones;
8277408Sgblack@eecs.umich.edu                fpscrMask.stride = ones;
8287408Sgblack@eecs.umich.edu                fpscrMask.rMode = ones;
8297408Sgblack@eecs.umich.edu                fpscrMask.fz = ones;
8307408Sgblack@eecs.umich.edu                fpscrMask.dn = ones;
8317408Sgblack@eecs.umich.edu                fpscrMask.ahp = ones;
8327408Sgblack@eecs.umich.edu                fpscrMask.qc = ones;
8337408Sgblack@eecs.umich.edu                fpscrMask.v = ones;
8347408Sgblack@eecs.umich.edu                fpscrMask.c = ones;
8357408Sgblack@eecs.umich.edu                fpscrMask.z = ones;
8367408Sgblack@eecs.umich.edu                fpscrMask.n = ones;
8377408Sgblack@eecs.umich.edu                newVal = (newVal & (uint32_t)fpscrMask) |
83810037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
83910037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
8409377Sgblack@eecs.umich.edu                tc->getDecoderPtr()->setContext(newVal);
8417408Sgblack@eecs.umich.edu            }
8427408Sgblack@eecs.umich.edu            break;
84310037SARM gem5 Developers          case MISCREG_FPSR:
84410037SARM gem5 Developers            {
84510037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
84610037SARM gem5 Developers                FPSCR fpscrMask = 0;
84710037SARM gem5 Developers                fpscrMask.ioc = ones;
84810037SARM gem5 Developers                fpscrMask.dzc = ones;
84910037SARM gem5 Developers                fpscrMask.ofc = ones;
85010037SARM gem5 Developers                fpscrMask.ufc = ones;
85110037SARM gem5 Developers                fpscrMask.ixc = ones;
85210037SARM gem5 Developers                fpscrMask.idc = ones;
85310037SARM gem5 Developers                fpscrMask.qc = ones;
85410037SARM gem5 Developers                fpscrMask.v = ones;
85510037SARM gem5 Developers                fpscrMask.c = ones;
85610037SARM gem5 Developers                fpscrMask.z = ones;
85710037SARM gem5 Developers                fpscrMask.n = ones;
85810037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
85910037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
86010037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
86110037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
86210037SARM gem5 Developers            }
86310037SARM gem5 Developers            break;
86410037SARM gem5 Developers          case MISCREG_FPCR:
86510037SARM gem5 Developers            {
86610037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
86710037SARM gem5 Developers                FPSCR fpscrMask  = 0;
86810037SARM gem5 Developers                fpscrMask.ioe = ones;
86910037SARM gem5 Developers                fpscrMask.dze = ones;
87010037SARM gem5 Developers                fpscrMask.ofe = ones;
87110037SARM gem5 Developers                fpscrMask.ufe = ones;
87210037SARM gem5 Developers                fpscrMask.ixe = ones;
87310037SARM gem5 Developers                fpscrMask.ide = ones;
87410037SARM gem5 Developers                fpscrMask.len    = ones;
87510037SARM gem5 Developers                fpscrMask.stride = ones;
87610037SARM gem5 Developers                fpscrMask.rMode  = ones;
87710037SARM gem5 Developers                fpscrMask.fz     = ones;
87810037SARM gem5 Developers                fpscrMask.dn     = ones;
87910037SARM gem5 Developers                fpscrMask.ahp    = ones;
88010037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
88110037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
88210037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
88310037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
88410037SARM gem5 Developers            }
88510037SARM gem5 Developers            break;
8868302SAli.Saidi@ARM.com          case MISCREG_CPSR_Q:
8878302SAli.Saidi@ARM.com            {
8888302SAli.Saidi@ARM.com                assert(!(newVal & ~CpsrMaskQ));
88910037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
8908302SAli.Saidi@ARM.com                misc_reg = MISCREG_CPSR;
8918302SAli.Saidi@ARM.com            }
8928302SAli.Saidi@ARM.com            break;
8937783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_QC:
8947783SGiacomo.Gabrielli@arm.com            {
89510037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
89610037SARM gem5 Developers                         (newVal & FpscrQcMask);
8977783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
8987783SGiacomo.Gabrielli@arm.com            }
8997783SGiacomo.Gabrielli@arm.com            break;
9007783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_EXC:
9017783SGiacomo.Gabrielli@arm.com            {
90210037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
90310037SARM gem5 Developers                         (newVal & FpscrExcMask);
9047783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
9057783SGiacomo.Gabrielli@arm.com            }
9067783SGiacomo.Gabrielli@arm.com            break;
9077408Sgblack@eecs.umich.edu          case MISCREG_FPEXC:
9087408Sgblack@eecs.umich.edu            {
9098206SWilliam.Wang@arm.com                // vfpv3 architecture, section B.6.1 of DDI04068
9108206SWilliam.Wang@arm.com                // bit 29 - valid only if fpexc[31] is 0
9117408Sgblack@eecs.umich.edu                const uint32_t fpexcMask = 0x60000000;
9127408Sgblack@eecs.umich.edu                newVal = (newVal & fpexcMask) |
91310037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
9147408Sgblack@eecs.umich.edu            }
9157408Sgblack@eecs.umich.edu            break;
91610037SARM gem5 Developers          case MISCREG_HCR:
91710037SARM gem5 Developers            {
91810037SARM gem5 Developers                if (!haveVirtualization)
91910037SARM gem5 Developers                    return;
92010037SARM gem5 Developers            }
92110037SARM gem5 Developers            break;
92210037SARM gem5 Developers          case MISCREG_IFSR:
92310037SARM gem5 Developers            {
92410037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.96
92510037SARM gem5 Developers                const uint32_t ifsrMask =
92610037SARM gem5 Developers                    mask(31, 13) | mask(11, 11) | mask(8, 6);
92710037SARM gem5 Developers                newVal = newVal & ~ifsrMask;
92810037SARM gem5 Developers            }
92910037SARM gem5 Developers            break;
93010037SARM gem5 Developers          case MISCREG_DFSR:
93110037SARM gem5 Developers            {
93210037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.52
93310037SARM gem5 Developers                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
93410037SARM gem5 Developers                newVal = newVal & ~dfsrMask;
93510037SARM gem5 Developers            }
93610037SARM gem5 Developers            break;
93710037SARM gem5 Developers          case MISCREG_AMAIR0:
93810037SARM gem5 Developers          case MISCREG_AMAIR1:
93910037SARM gem5 Developers            {
94010037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.5
94110037SARM gem5 Developers                // Valid only with LPAE
94210037SARM gem5 Developers                if (!haveLPAE)
94310037SARM gem5 Developers                    return;
94410037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
94510037SARM gem5 Developers            }
94610037SARM gem5 Developers            break;
94710037SARM gem5 Developers          case MISCREG_SCR:
94812406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
94912406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
95010037SARM gem5 Developers            break;
9517408Sgblack@eecs.umich.edu          case MISCREG_SCTLR:
9527408Sgblack@eecs.umich.edu            {
9537408Sgblack@eecs.umich.edu                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
95410037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
95512639Sgiacomo.travaglini@arm.com
95612639Sgiacomo.travaglini@arm.com                MiscRegIndex sctlr_idx;
95712639Sgiacomo.travaglini@arm.com                if (haveSecurity && !highestELIs64 && !scr.ns) {
95812639Sgiacomo.travaglini@arm.com                    sctlr_idx = MISCREG_SCTLR_S;
95912639Sgiacomo.travaglini@arm.com                } else {
96012639Sgiacomo.travaglini@arm.com                    sctlr_idx =  MISCREG_SCTLR_NS;
96112639Sgiacomo.travaglini@arm.com                }
96212639Sgiacomo.travaglini@arm.com
96310037SARM gem5 Developers                SCTLR sctlr = miscRegs[sctlr_idx];
9647408Sgblack@eecs.umich.edu                SCTLR new_sctlr = newVal;
96510037SARM gem5 Developers                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
96610037SARM gem5 Developers                miscRegs[sctlr_idx] = (MiscReg)new_sctlr;
96712406Sgabeblack@google.com                getITBPtr(tc)->invalidateMiscReg();
96812406Sgabeblack@google.com                getDTBPtr(tc)->invalidateMiscReg();
9697408Sgblack@eecs.umich.edu            }
9709385SAndreas.Sandberg@arm.com          case MISCREG_MIDR:
9719385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR0:
9729385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR1:
97310461SAndreas.Sandberg@ARM.com          case MISCREG_ID_DFR0:
9749385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR0:
9759385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR1:
9769385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR2:
9779385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR3:
9789385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR0:
9799385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR1:
9809385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR2:
9819385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR3:
9829385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR4:
9839385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR5:
9849385SAndreas.Sandberg@arm.com
9859385SAndreas.Sandberg@arm.com          case MISCREG_MPIDR:
9869385SAndreas.Sandberg@arm.com          case MISCREG_FPSID:
9877408Sgblack@eecs.umich.edu          case MISCREG_TLBTR:
9887408Sgblack@eecs.umich.edu          case MISCREG_MVFR0:
9897408Sgblack@eecs.umich.edu          case MISCREG_MVFR1:
99010037SARM gem5 Developers
99110037SARM gem5 Developers          case MISCREG_ID_AA64AFR0_EL1:
99210037SARM gem5 Developers          case MISCREG_ID_AA64AFR1_EL1:
99310037SARM gem5 Developers          case MISCREG_ID_AA64DFR0_EL1:
99410037SARM gem5 Developers          case MISCREG_ID_AA64DFR1_EL1:
99510037SARM gem5 Developers          case MISCREG_ID_AA64ISAR0_EL1:
99610037SARM gem5 Developers          case MISCREG_ID_AA64ISAR1_EL1:
99710037SARM gem5 Developers          case MISCREG_ID_AA64MMFR0_EL1:
99810037SARM gem5 Developers          case MISCREG_ID_AA64MMFR1_EL1:
99910037SARM gem5 Developers          case MISCREG_ID_AA64PFR0_EL1:
100010037SARM gem5 Developers          case MISCREG_ID_AA64PFR1_EL1:
10019385SAndreas.Sandberg@arm.com            // ID registers are constants.
10027408Sgblack@eecs.umich.edu            return;
10039385SAndreas.Sandberg@arm.com
100412605Sgiacomo.travaglini@arm.com          // TLB Invalidate All
100512605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
100612605Sgiacomo.travaglini@arm.com            {
100712605Sgiacomo.travaglini@arm.com                assert32(tc);
100812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
100912605Sgiacomo.travaglini@arm.com
101012605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
101112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
101212605Sgiacomo.travaglini@arm.com                return;
101312605Sgiacomo.travaglini@arm.com            }
101412605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Inner Shareable
10157408Sgblack@eecs.umich.edu          case MISCREG_TLBIALLIS:
101612605Sgiacomo.travaglini@arm.com            {
101712605Sgiacomo.travaglini@arm.com                assert32(tc);
101812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
101912605Sgiacomo.travaglini@arm.com
102012605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
102112605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
102212605Sgiacomo.travaglini@arm.com                return;
102312605Sgiacomo.travaglini@arm.com            }
102412605Sgiacomo.travaglini@arm.com          // Instruction TLB Invalidate All
10257408Sgblack@eecs.umich.edu          case MISCREG_ITLBIALL:
102612605Sgiacomo.travaglini@arm.com            {
102712605Sgiacomo.travaglini@arm.com                assert32(tc);
102812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
102912605Sgiacomo.travaglini@arm.com
103012605Sgiacomo.travaglini@arm.com                ITLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
103112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
103212605Sgiacomo.travaglini@arm.com                return;
103312605Sgiacomo.travaglini@arm.com            }
103412605Sgiacomo.travaglini@arm.com          // Data TLB Invalidate All
10357408Sgblack@eecs.umich.edu          case MISCREG_DTLBIALL:
103612605Sgiacomo.travaglini@arm.com            {
103712605Sgiacomo.travaglini@arm.com                assert32(tc);
103812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
103912605Sgiacomo.travaglini@arm.com
104012605Sgiacomo.travaglini@arm.com                DTLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
104112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
104212605Sgiacomo.travaglini@arm.com                return;
104312605Sgiacomo.travaglini@arm.com            }
104412605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA
104512605Sgiacomo.travaglini@arm.com          // mcr tlbimval(is) is invalidating all matching entries
104612605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
104712605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
104812605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVA:
104912576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAL:
105012605Sgiacomo.travaglini@arm.com            {
105112605Sgiacomo.travaglini@arm.com                assert32(tc);
105212605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
105312605Sgiacomo.travaglini@arm.com
105412605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1,
105512605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
105612605Sgiacomo.travaglini@arm.com                               mbits(newVal, 31, 12),
105712605Sgiacomo.travaglini@arm.com                               bits(newVal, 7,0));
105812605Sgiacomo.travaglini@arm.com
105912605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
106012605Sgiacomo.travaglini@arm.com                return;
106112605Sgiacomo.travaglini@arm.com            }
106212605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, Inner Shareable
106312605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAIS:
106412576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVALIS:
106512605Sgiacomo.travaglini@arm.com            {
106612605Sgiacomo.travaglini@arm.com                assert32(tc);
106712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
106812605Sgiacomo.travaglini@arm.com
106912605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1,
107012605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
107112605Sgiacomo.travaglini@arm.com                               mbits(newVal, 31, 12),
107212605Sgiacomo.travaglini@arm.com                               bits(newVal, 7,0));
107312605Sgiacomo.travaglini@arm.com
107412605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
107512605Sgiacomo.travaglini@arm.com                return;
107612605Sgiacomo.travaglini@arm.com            }
107712605Sgiacomo.travaglini@arm.com          // TLB Invalidate by ASID match
107812605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIASID:
107912605Sgiacomo.travaglini@arm.com            {
108012605Sgiacomo.travaglini@arm.com                assert32(tc);
108112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
108212605Sgiacomo.travaglini@arm.com
108312605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1,
108412605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
108512605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
108612605Sgiacomo.travaglini@arm.com
108712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
108812605Sgiacomo.travaglini@arm.com                return;
108912605Sgiacomo.travaglini@arm.com            }
109012605Sgiacomo.travaglini@arm.com          // TLB Invalidate by ASID match, Inner Shareable
10917408Sgblack@eecs.umich.edu          case MISCREG_TLBIASIDIS:
109212605Sgiacomo.travaglini@arm.com            {
109312605Sgiacomo.travaglini@arm.com                assert32(tc);
109412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
109512605Sgiacomo.travaglini@arm.com
109612605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1,
109712605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
109812605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
109912605Sgiacomo.travaglini@arm.com
110012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
110112605Sgiacomo.travaglini@arm.com                return;
110212605Sgiacomo.travaglini@arm.com            }
110312605Sgiacomo.travaglini@arm.com          // mcr tlbimvaal(is) is invalidating all matching entries
110412605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
110512605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
110612605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, All ASID
110712605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAA:
110812576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAAL:
110912605Sgiacomo.travaglini@arm.com            {
111012605Sgiacomo.travaglini@arm.com                assert32(tc);
111112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
111212605Sgiacomo.travaglini@arm.com
111312605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
111412605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), false);
111512605Sgiacomo.travaglini@arm.com
111612605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
111712605Sgiacomo.travaglini@arm.com                return;
111812605Sgiacomo.travaglini@arm.com            }
111912605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, All ASID, Inner Shareable
112012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAAIS:
112112576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAALIS:
112212605Sgiacomo.travaglini@arm.com            {
112312605Sgiacomo.travaglini@arm.com                assert32(tc);
112412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
112512605Sgiacomo.travaglini@arm.com
112612605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
112712605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), false);
112812605Sgiacomo.travaglini@arm.com
112912605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
113012605Sgiacomo.travaglini@arm.com                return;
113112605Sgiacomo.travaglini@arm.com            }
113212605Sgiacomo.travaglini@arm.com          // mcr tlbimvalh(is) is invalidating all matching entries
113312605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
113412605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
113512605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, Hyp mode
113612605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAH:
113712576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVALH:
113812605Sgiacomo.travaglini@arm.com            {
113912605Sgiacomo.travaglini@arm.com                assert32(tc);
114012605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
114112605Sgiacomo.travaglini@arm.com
114212605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
114312605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), true);
114412605Sgiacomo.travaglini@arm.com
114512605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
114612605Sgiacomo.travaglini@arm.com                return;
114712605Sgiacomo.travaglini@arm.com            }
114812605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, Hyp mode, Inner Shareable
114912605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAHIS:
115012576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVALHIS:
115112605Sgiacomo.travaglini@arm.com            {
115212605Sgiacomo.travaglini@arm.com                assert32(tc);
115312605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
115412605Sgiacomo.travaglini@arm.com
115512605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
115612605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), true);
115712605Sgiacomo.travaglini@arm.com
115812605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
115912605Sgiacomo.travaglini@arm.com                return;
116012605Sgiacomo.travaglini@arm.com            }
116112605Sgiacomo.travaglini@arm.com          // mcr tlbiipas2l(is) is invalidating all matching entries
116212605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
116312605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
116412605Sgiacomo.travaglini@arm.com          // TLB Invalidate by Intermediate Physical Address, Stage 2
116512605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2:
116612577Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2L:
116712605Sgiacomo.travaglini@arm.com            {
116812605Sgiacomo.travaglini@arm.com                assert32(tc);
116912605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
117012605Sgiacomo.travaglini@arm.com
117112605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1,
117212605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
117312605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
117412605Sgiacomo.travaglini@arm.com
117512605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
117612605Sgiacomo.travaglini@arm.com                return;
117712605Sgiacomo.travaglini@arm.com            }
117812605Sgiacomo.travaglini@arm.com          // TLB Invalidate by Intermediate Physical Address, Stage 2,
117912605Sgiacomo.travaglini@arm.com          // Inner Shareable
118012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2IS:
118112577Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2LIS:
118212605Sgiacomo.travaglini@arm.com            {
118312605Sgiacomo.travaglini@arm.com                assert32(tc);
118412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
118512605Sgiacomo.travaglini@arm.com
118612605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1,
118712605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
118812605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
118912605Sgiacomo.travaglini@arm.com
119012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
119112605Sgiacomo.travaglini@arm.com                return;
119212605Sgiacomo.travaglini@arm.com            }
119312605Sgiacomo.travaglini@arm.com          // Instruction TLB Invalidate by VA
119410037SARM gem5 Developers          case MISCREG_ITLBIMVA:
119512605Sgiacomo.travaglini@arm.com            {
119612605Sgiacomo.travaglini@arm.com                assert32(tc);
119712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
119812605Sgiacomo.travaglini@arm.com
119912605Sgiacomo.travaglini@arm.com                ITLBIMVA tlbiOp(EL1,
120012605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
120112605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31, 12),
120212605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
120312605Sgiacomo.travaglini@arm.com
120412605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
120512605Sgiacomo.travaglini@arm.com                return;
120612605Sgiacomo.travaglini@arm.com            }
120712605Sgiacomo.travaglini@arm.com          // Data TLB Invalidate by VA
120810037SARM gem5 Developers          case MISCREG_DTLBIMVA:
120912605Sgiacomo.travaglini@arm.com            {
121012605Sgiacomo.travaglini@arm.com                assert32(tc);
121112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
121212605Sgiacomo.travaglini@arm.com
121312605Sgiacomo.travaglini@arm.com                DTLBIMVA tlbiOp(EL1,
121412605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
121512605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31, 12),
121612605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
121712605Sgiacomo.travaglini@arm.com
121812605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
121912605Sgiacomo.travaglini@arm.com                return;
122012605Sgiacomo.travaglini@arm.com            }
122112605Sgiacomo.travaglini@arm.com          // Instruction TLB Invalidate by ASID match
122210037SARM gem5 Developers          case MISCREG_ITLBIASID:
122312605Sgiacomo.travaglini@arm.com            {
122412605Sgiacomo.travaglini@arm.com                assert32(tc);
122512605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
122612605Sgiacomo.travaglini@arm.com
122712605Sgiacomo.travaglini@arm.com                ITLBIASID tlbiOp(EL1,
122812605Sgiacomo.travaglini@arm.com                                 haveSecurity && !scr.ns,
122912605Sgiacomo.travaglini@arm.com                                 bits(newVal, 7,0));
123012605Sgiacomo.travaglini@arm.com
123112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
123212605Sgiacomo.travaglini@arm.com                return;
123312605Sgiacomo.travaglini@arm.com            }
123412605Sgiacomo.travaglini@arm.com          // Data TLB Invalidate by ASID match
123510037SARM gem5 Developers          case MISCREG_DTLBIASID:
123612605Sgiacomo.travaglini@arm.com            {
123712605Sgiacomo.travaglini@arm.com                assert32(tc);
123812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
123912605Sgiacomo.travaglini@arm.com
124012605Sgiacomo.travaglini@arm.com                DTLBIASID tlbiOp(EL1,
124112605Sgiacomo.travaglini@arm.com                                 haveSecurity && !scr.ns,
124212605Sgiacomo.travaglini@arm.com                                 bits(newVal, 7,0));
124312605Sgiacomo.travaglini@arm.com
124412605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
124512605Sgiacomo.travaglini@arm.com                return;
124612605Sgiacomo.travaglini@arm.com            }
124712605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Non-Secure Non-Hyp
124810037SARM gem5 Developers          case MISCREG_TLBIALLNSNH:
124912605Sgiacomo.travaglini@arm.com            {
125012605Sgiacomo.travaglini@arm.com                assert32(tc);
125112605Sgiacomo.travaglini@arm.com
125212605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, false);
125312605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
125412605Sgiacomo.travaglini@arm.com                return;
125512605Sgiacomo.travaglini@arm.com            }
125612605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Non-Secure Non-Hyp, Inner Shareable
125710037SARM gem5 Developers          case MISCREG_TLBIALLNSNHIS:
125812605Sgiacomo.travaglini@arm.com            {
125912605Sgiacomo.travaglini@arm.com                assert32(tc);
126012605Sgiacomo.travaglini@arm.com
126112605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, false);
126212605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
126312605Sgiacomo.travaglini@arm.com                return;
126412605Sgiacomo.travaglini@arm.com            }
126512605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Hyp mode
126610037SARM gem5 Developers          case MISCREG_TLBIALLH:
126712605Sgiacomo.travaglini@arm.com            {
126812605Sgiacomo.travaglini@arm.com                assert32(tc);
126912605Sgiacomo.travaglini@arm.com
127012605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, true);
127112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
127212605Sgiacomo.travaglini@arm.com                return;
127312605Sgiacomo.travaglini@arm.com            }
127412605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Hyp mode, Inner Shareable
127510037SARM gem5 Developers          case MISCREG_TLBIALLHIS:
127612605Sgiacomo.travaglini@arm.com            {
127712605Sgiacomo.travaglini@arm.com                assert32(tc);
127812605Sgiacomo.travaglini@arm.com
127912605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, true);
128012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
128112605Sgiacomo.travaglini@arm.com                return;
128212605Sgiacomo.travaglini@arm.com            }
128312605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL3
128412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_ALLE3:
128512605Sgiacomo.travaglini@arm.com            {
128612605Sgiacomo.travaglini@arm.com                assert64(tc);
128712605Sgiacomo.travaglini@arm.com
128812605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL3, true);
128912605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
129012605Sgiacomo.travaglini@arm.com                return;
129112605Sgiacomo.travaglini@arm.com            }
129212605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL3, Inner Shareable
129310037SARM gem5 Developers          case MISCREG_TLBI_ALLE3IS:
129412605Sgiacomo.travaglini@arm.com            {
129512605Sgiacomo.travaglini@arm.com                assert64(tc);
129612605Sgiacomo.travaglini@arm.com
129712605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL3, true);
129812605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
129912605Sgiacomo.travaglini@arm.com                return;
130012605Sgiacomo.travaglini@arm.com            }
130110037SARM gem5 Developers          // @todo: uncomment this to enable Virtualization
130210037SARM gem5 Developers          // case MISCREG_TLBI_ALLE2IS:
130310037SARM gem5 Developers          // case MISCREG_TLBI_ALLE2:
130412605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL1
130510037SARM gem5 Developers          case MISCREG_TLBI_ALLE1:
130610037SARM gem5 Developers          case MISCREG_TLBI_VMALLE1:
130710037SARM gem5 Developers          case MISCREG_TLBI_VMALLS12E1:
130810037SARM gem5 Developers            // @todo: handle VMID and stage 2 to enable Virtualization
130912605Sgiacomo.travaglini@arm.com            {
131012605Sgiacomo.travaglini@arm.com                assert64(tc);
131112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
131212605Sgiacomo.travaglini@arm.com
131312605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
131412605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
131512605Sgiacomo.travaglini@arm.com                return;
131612605Sgiacomo.travaglini@arm.com            }
131712605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL1, Inner Shareable
131812605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_ALLE1IS:
131912605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VMALLE1IS:
132012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VMALLS12E1IS:
132112605Sgiacomo.travaglini@arm.com            // @todo: handle VMID and stage 2 to enable Virtualization
132212605Sgiacomo.travaglini@arm.com            {
132312605Sgiacomo.travaglini@arm.com                assert64(tc);
132412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
132512605Sgiacomo.travaglini@arm.com
132612605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
132712605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
132812605Sgiacomo.travaglini@arm.com                return;
132912605Sgiacomo.travaglini@arm.com            }
133012605Sgiacomo.travaglini@arm.com          // VAEx(IS) and VALEx(IS) are the same because TLBs
133112605Sgiacomo.travaglini@arm.com          // only store entries
133210037SARM gem5 Developers          // from the last level of translation table walks
133310037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
133412605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL3
133512605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAE3_Xt:
133612605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VALE3_Xt:
133712605Sgiacomo.travaglini@arm.com            {
133812605Sgiacomo.travaglini@arm.com                assert64(tc);
133912605Sgiacomo.travaglini@arm.com
134012605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL3, true,
134112605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
134212605Sgiacomo.travaglini@arm.com                               0xbeef);
134312605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
134412605Sgiacomo.travaglini@arm.com                return;
134512605Sgiacomo.travaglini@arm.com            }
134612605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL3, Inner Shareable
134710037SARM gem5 Developers          case MISCREG_TLBI_VAE3IS_Xt:
134810037SARM gem5 Developers          case MISCREG_TLBI_VALE3IS_Xt:
134912605Sgiacomo.travaglini@arm.com            {
135012605Sgiacomo.travaglini@arm.com                assert64(tc);
135112605Sgiacomo.travaglini@arm.com
135212605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL3, true,
135312605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
135412605Sgiacomo.travaglini@arm.com                               0xbeef);
135512605Sgiacomo.travaglini@arm.com
135612605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
135712605Sgiacomo.travaglini@arm.com                return;
135812605Sgiacomo.travaglini@arm.com            }
135912605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL2
136012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAE2_Xt:
136112605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VALE2_Xt:
136212605Sgiacomo.travaglini@arm.com            {
136312605Sgiacomo.travaglini@arm.com                assert64(tc);
136412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
136512605Sgiacomo.travaglini@arm.com
136612605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
136712605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
136812605Sgiacomo.travaglini@arm.com                               0xbeef);
136912605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
137012605Sgiacomo.travaglini@arm.com                return;
137112605Sgiacomo.travaglini@arm.com            }
137212605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL2, Inner Shareable
137310037SARM gem5 Developers          case MISCREG_TLBI_VAE2IS_Xt:
137410037SARM gem5 Developers          case MISCREG_TLBI_VALE2IS_Xt:
137512605Sgiacomo.travaglini@arm.com            {
137612605Sgiacomo.travaglini@arm.com                assert64(tc);
137712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
137812605Sgiacomo.travaglini@arm.com
137912605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
138012605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
138112605Sgiacomo.travaglini@arm.com                               0xbeef);
138212605Sgiacomo.travaglini@arm.com
138312605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
138412605Sgiacomo.travaglini@arm.com                return;
138512605Sgiacomo.travaglini@arm.com            }
138612605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL1
138712605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAE1_Xt:
138812605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VALE1_Xt:
138912605Sgiacomo.travaglini@arm.com            {
139012605Sgiacomo.travaglini@arm.com                assert64(tc);
139112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
139212605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
139312605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
139412605Sgiacomo.travaglini@arm.com
139512605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
139612605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
139712605Sgiacomo.travaglini@arm.com                               asid);
139812605Sgiacomo.travaglini@arm.com
139912605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
140012605Sgiacomo.travaglini@arm.com                return;
140112605Sgiacomo.travaglini@arm.com            }
140212605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL1, Inner Shareable
140310037SARM gem5 Developers          case MISCREG_TLBI_VAE1IS_Xt:
140410037SARM gem5 Developers          case MISCREG_TLBI_VALE1IS_Xt:
140512605Sgiacomo.travaglini@arm.com            {
140612605Sgiacomo.travaglini@arm.com                assert64(tc);
140712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
140812605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
140912605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
141012605Sgiacomo.travaglini@arm.com
141112605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
141212605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
141312605Sgiacomo.travaglini@arm.com                               asid);
141412605Sgiacomo.travaglini@arm.com
141512605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
141612605Sgiacomo.travaglini@arm.com                return;
141712605Sgiacomo.travaglini@arm.com            }
141812605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by ASID, EL1
141910037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
142012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_ASIDE1_Xt:
142112605Sgiacomo.travaglini@arm.com            {
142212605Sgiacomo.travaglini@arm.com                assert64(tc);
142312605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
142412605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
142512605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
142612605Sgiacomo.travaglini@arm.com
142712605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
142812605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
142912605Sgiacomo.travaglini@arm.com                return;
143012605Sgiacomo.travaglini@arm.com            }
143112605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by ASID, EL1, Inner Shareable
143210037SARM gem5 Developers          case MISCREG_TLBI_ASIDE1IS_Xt:
143312605Sgiacomo.travaglini@arm.com            {
143412605Sgiacomo.travaglini@arm.com                assert64(tc);
143512605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
143612605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
143712605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
143812605Sgiacomo.travaglini@arm.com
143912605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
144012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
144112605Sgiacomo.travaglini@arm.com                return;
144212605Sgiacomo.travaglini@arm.com            }
144310037SARM gem5 Developers          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
144410037SARM gem5 Developers          // entries from the last level of translation table walks
144512605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, All ASID, EL1
144612605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAAE1_Xt:
144712605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAALE1_Xt:
144812605Sgiacomo.travaglini@arm.com            {
144912605Sgiacomo.travaglini@arm.com                assert64(tc);
145012605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
145112605Sgiacomo.travaglini@arm.com
145212605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
145312605Sgiacomo.travaglini@arm.com                    static_cast<Addr>(bits(newVal, 43, 0)) << 12, false);
145412605Sgiacomo.travaglini@arm.com
145512605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
145612605Sgiacomo.travaglini@arm.com                return;
145712605Sgiacomo.travaglini@arm.com            }
145812605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, All ASID, EL1, Inner Shareable
145910037SARM gem5 Developers          case MISCREG_TLBI_VAAE1IS_Xt:
146010037SARM gem5 Developers          case MISCREG_TLBI_VAALE1IS_Xt:
146112605Sgiacomo.travaglini@arm.com            {
146212605Sgiacomo.travaglini@arm.com                assert64(tc);
146312605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
146412605Sgiacomo.travaglini@arm.com
146512605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
146612605Sgiacomo.travaglini@arm.com                    static_cast<Addr>(bits(newVal, 43, 0)) << 12, false);
146712605Sgiacomo.travaglini@arm.com
146812605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
146912605Sgiacomo.travaglini@arm.com                return;
147012605Sgiacomo.travaglini@arm.com            }
147112605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by Intermediate Physical Address,
147212605Sgiacomo.travaglini@arm.com          // Stage 2, EL1
147312605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_IPAS2E1_Xt:
147412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_IPAS2LE1_Xt:
147512605Sgiacomo.travaglini@arm.com            {
147612605Sgiacomo.travaglini@arm.com                assert64(tc);
147712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
147812605Sgiacomo.travaglini@arm.com
147912605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
148012605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
148112605Sgiacomo.travaglini@arm.com
148212605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
148312605Sgiacomo.travaglini@arm.com                return;
148412605Sgiacomo.travaglini@arm.com            }
148512605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by Intermediate Physical Address,
148612605Sgiacomo.travaglini@arm.com          // Stage 2, EL1, Inner Shareable
148712605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_IPAS2E1IS_Xt:
148810037SARM gem5 Developers          case MISCREG_TLBI_IPAS2LE1IS_Xt:
148912605Sgiacomo.travaglini@arm.com            {
149012605Sgiacomo.travaglini@arm.com                assert64(tc);
149112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
149212605Sgiacomo.travaglini@arm.com
149312605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
149412605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
149512605Sgiacomo.travaglini@arm.com
149612605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
149712605Sgiacomo.travaglini@arm.com                return;
149812605Sgiacomo.travaglini@arm.com            }
14997583SAli.Saidi@arm.com          case MISCREG_ACTLR:
15007583SAli.Saidi@arm.com            warn("Not doing anything for write of miscreg ACTLR\n");
15017583SAli.Saidi@arm.com            break;
150210461SAndreas.Sandberg@ARM.com
150310461SAndreas.Sandberg@ARM.com          case MISCREG_PMXEVTYPER_PMCCFILTR:
150410461SAndreas.Sandberg@ARM.com          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
150510461SAndreas.Sandberg@ARM.com          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
150610461SAndreas.Sandberg@ARM.com          case MISCREG_PMCR ... MISCREG_PMOVSSET:
150710461SAndreas.Sandberg@ARM.com            pmu->setMiscReg(misc_reg, newVal);
15087583SAli.Saidi@arm.com            break;
150910461SAndreas.Sandberg@ARM.com
151010461SAndreas.Sandberg@ARM.com
151110037SARM gem5 Developers          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
151210037SARM gem5 Developers            {
151310037SARM gem5 Developers                HSTR hstrMask = 0;
151410037SARM gem5 Developers                hstrMask.tjdbx = 1;
151510037SARM gem5 Developers                newVal &= ~((uint32_t) hstrMask);
151610037SARM gem5 Developers                break;
151710037SARM gem5 Developers            }
151810037SARM gem5 Developers          case MISCREG_HCPTR:
151910037SARM gem5 Developers            {
152010037SARM gem5 Developers                // If a CP bit in NSACR is 0 then the corresponding bit in
152110037SARM gem5 Developers                // HCPTR is RAO/WI. Same applies to NSASEDIS
152210037SARM gem5 Developers                secure_lookup = haveSecurity &&
152310037SARM gem5 Developers                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
152410037SARM gem5 Developers                                  readMiscRegNoEffect(MISCREG_CPSR));
152510037SARM gem5 Developers                if (!secure_lookup) {
152610037SARM gem5 Developers                    MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
152710037SARM gem5 Developers                    MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
152810037SARM gem5 Developers                    newVal = (newVal & ~mask) | (oldValue & mask);
152910037SARM gem5 Developers                }
153010037SARM gem5 Developers                break;
153110037SARM gem5 Developers            }
153210037SARM gem5 Developers          case MISCREG_HDFAR: // alias for secure DFAR
153310037SARM gem5 Developers            misc_reg = MISCREG_DFAR_S;
153410037SARM gem5 Developers            break;
153510037SARM gem5 Developers          case MISCREG_HIFAR: // alias for secure IFAR
153610037SARM gem5 Developers            misc_reg = MISCREG_IFAR_S;
153710037SARM gem5 Developers            break;
153810037SARM gem5 Developers          case MISCREG_ATS1CPR:
153910037SARM gem5 Developers          case MISCREG_ATS1CPW:
154010037SARM gem5 Developers          case MISCREG_ATS1CUR:
154110037SARM gem5 Developers          case MISCREG_ATS1CUW:
154210037SARM gem5 Developers          case MISCREG_ATS12NSOPR:
154310037SARM gem5 Developers          case MISCREG_ATS12NSOPW:
154410037SARM gem5 Developers          case MISCREG_ATS12NSOUR:
154510037SARM gem5 Developers          case MISCREG_ATS12NSOUW:
154610037SARM gem5 Developers          case MISCREG_ATS1HR:
154710037SARM gem5 Developers          case MISCREG_ATS1HW:
15487436Sdam.sunwoo@arm.com            {
154911608Snikos.nikoleris@arm.com              Request::Flags flags = 0;
155010037SARM gem5 Developers              BaseTLB::Mode mode = BaseTLB::Read;
155110037SARM gem5 Developers              TLB::ArmTranslationType tranType = TLB::NormalTran;
15527436Sdam.sunwoo@arm.com              Fault fault;
15537436Sdam.sunwoo@arm.com              switch(misc_reg) {
155410037SARM gem5 Developers                case MISCREG_ATS1CPR:
155510037SARM gem5 Developers                  flags    = TLB::MustBeOne;
155610037SARM gem5 Developers                  tranType = TLB::S1CTran;
155710037SARM gem5 Developers                  mode     = BaseTLB::Read;
155810037SARM gem5 Developers                  break;
155910037SARM gem5 Developers                case MISCREG_ATS1CPW:
156010037SARM gem5 Developers                  flags    = TLB::MustBeOne;
156110037SARM gem5 Developers                  tranType = TLB::S1CTran;
156210037SARM gem5 Developers                  mode     = BaseTLB::Write;
156310037SARM gem5 Developers                  break;
156410037SARM gem5 Developers                case MISCREG_ATS1CUR:
156510037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
156610037SARM gem5 Developers                  tranType = TLB::S1CTran;
156710037SARM gem5 Developers                  mode     = BaseTLB::Read;
156810037SARM gem5 Developers                  break;
156910037SARM gem5 Developers                case MISCREG_ATS1CUW:
157010037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
157110037SARM gem5 Developers                  tranType = TLB::S1CTran;
157210037SARM gem5 Developers                  mode     = BaseTLB::Write;
157310037SARM gem5 Developers                  break;
157410037SARM gem5 Developers                case MISCREG_ATS12NSOPR:
157510037SARM gem5 Developers                  if (!haveSecurity)
157610037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPR");
157710037SARM gem5 Developers                  flags    = TLB::MustBeOne;
157810037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
157910037SARM gem5 Developers                  mode     = BaseTLB::Read;
158010037SARM gem5 Developers                  break;
158110037SARM gem5 Developers                case MISCREG_ATS12NSOPW:
158210037SARM gem5 Developers                  if (!haveSecurity)
158310037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPW");
158410037SARM gem5 Developers                  flags    = TLB::MustBeOne;
158510037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
158610037SARM gem5 Developers                  mode     = BaseTLB::Write;
158710037SARM gem5 Developers                  break;
158810037SARM gem5 Developers                case MISCREG_ATS12NSOUR:
158910037SARM gem5 Developers                  if (!haveSecurity)
159010037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUR");
159110037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
159210037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
159310037SARM gem5 Developers                  mode     = BaseTLB::Read;
159410037SARM gem5 Developers                  break;
159510037SARM gem5 Developers                case MISCREG_ATS12NSOUW:
159610037SARM gem5 Developers                  if (!haveSecurity)
159710037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUW");
159810037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
159910037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
160010037SARM gem5 Developers                  mode     = BaseTLB::Write;
160110037SARM gem5 Developers                  break;
160210037SARM gem5 Developers                case MISCREG_ATS1HR: // only really useful from secure mode.
160310037SARM gem5 Developers                  flags    = TLB::MustBeOne;
160410037SARM gem5 Developers                  tranType = TLB::HypMode;
160510037SARM gem5 Developers                  mode     = BaseTLB::Read;
160610037SARM gem5 Developers                  break;
160710037SARM gem5 Developers                case MISCREG_ATS1HW:
160810037SARM gem5 Developers                  flags    = TLB::MustBeOne;
160910037SARM gem5 Developers                  tranType = TLB::HypMode;
161010037SARM gem5 Developers                  mode     = BaseTLB::Write;
161110037SARM gem5 Developers                  break;
16127436Sdam.sunwoo@arm.com              }
161310037SARM gem5 Developers              // If we're in timing mode then doing the translation in
161410037SARM gem5 Developers              // functional mode then we're slightly distorting performance
161510037SARM gem5 Developers              // results obtained from simulations. The translation should be
161610037SARM gem5 Developers              // done in the same mode the core is running in. NOTE: This
161710037SARM gem5 Developers              // can't be an atomic translation because that causes problems
161810037SARM gem5 Developers              // with unexpected atomic snoop requests.
161910037SARM gem5 Developers              warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
162011560Sandreas.sandberg@arm.com              Request req(0, val, 0, flags,  Request::funcMasterId,
162111435Smitch.hayenga@arm.com                          tc->pcState().pc(), tc->contextId());
162212406Sgabeblack@google.com              fault = getDTBPtr(tc)->translateFunctional(
162312406Sgabeblack@google.com                      &req, tc, mode, tranType);
162410037SARM gem5 Developers              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
162510037SARM gem5 Developers              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
162610037SARM gem5 Developers
162710037SARM gem5 Developers              MiscReg newVal;
16287436Sdam.sunwoo@arm.com              if (fault == NoFault) {
162910653Sandreas.hansson@arm.com                  Addr paddr = req.getPaddr();
163010037SARM gem5 Developers                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
163110037SARM gem5 Developers                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
163210037SARM gem5 Developers                      newVal = (paddr & mask(39, 12)) |
163312406Sgabeblack@google.com                               (getDTBPtr(tc)->getAttr());
163410037SARM gem5 Developers                  } else {
163510037SARM gem5 Developers                      newVal = (paddr & 0xfffff000) |
163612406Sgabeblack@google.com                               (getDTBPtr(tc)->getAttr());
163710037SARM gem5 Developers                  }
16387436Sdam.sunwoo@arm.com                  DPRINTF(MiscRegs,
16397436Sdam.sunwoo@arm.com                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
164010037SARM gem5 Developers                          val, newVal);
164110037SARM gem5 Developers              } else {
164212524Sgiacomo.travaglini@arm.com                  ArmFault *armFault = static_cast<ArmFault *>(fault.get());
164312570Sgiacomo.travaglini@arm.com                  armFault->update(tc);
164410037SARM gem5 Developers                  // Set fault bit and FSR
164510037SARM gem5 Developers                  FSR fsr = armFault->getFsr(tc);
164610037SARM gem5 Developers
164710037SARM gem5 Developers                  newVal = ((fsr >> 9) & 1) << 11;
164810037SARM gem5 Developers                  if (newVal) {
164910037SARM gem5 Developers                    // LPAE - rearange fault status
165010037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0x3f) << 1;
165110037SARM gem5 Developers                  } else {
165210037SARM gem5 Developers                    // VMSA - rearange fault status
165310037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0xf) << 1;
165410037SARM gem5 Developers                    newVal |= ((fsr >> 10) & 0x1) << 5;
165510037SARM gem5 Developers                    newVal |= ((fsr >> 12) & 0x1) << 6;
165610037SARM gem5 Developers                  }
165710037SARM gem5 Developers                  newVal |= 0x1; // F bit
165810037SARM gem5 Developers                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
165910037SARM gem5 Developers                  newVal |= armFault->isStage2() ? 0x200 : 0;
166010037SARM gem5 Developers                  DPRINTF(MiscRegs,
166110037SARM gem5 Developers                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
166210037SARM gem5 Developers                          val, fsr, newVal);
16637436Sdam.sunwoo@arm.com              }
166410037SARM gem5 Developers              setMiscRegNoEffect(MISCREG_PAR, newVal);
16657436Sdam.sunwoo@arm.com              return;
16667436Sdam.sunwoo@arm.com            }
166710037SARM gem5 Developers          case MISCREG_TTBCR:
166810037SARM gem5 Developers            {
166910037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
167010037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
167110037SARM gem5 Developers                TTBCR ttbcrMask = 0;
167210037SARM gem5 Developers                TTBCR ttbcrNew = newVal;
167310037SARM gem5 Developers
167410037SARM gem5 Developers                // ARM DDI 0406C.b, ARMv7-32
167510037SARM gem5 Developers                ttbcrMask.n = ones; // T0SZ
167610037SARM gem5 Developers                if (haveSecurity) {
167710037SARM gem5 Developers                    ttbcrMask.pd0 = ones;
167810037SARM gem5 Developers                    ttbcrMask.pd1 = ones;
167910037SARM gem5 Developers                }
168010037SARM gem5 Developers                ttbcrMask.epd0 = ones;
168110037SARM gem5 Developers                ttbcrMask.irgn0 = ones;
168210037SARM gem5 Developers                ttbcrMask.orgn0 = ones;
168310037SARM gem5 Developers                ttbcrMask.sh0 = ones;
168410037SARM gem5 Developers                ttbcrMask.ps = ones; // T1SZ
168510037SARM gem5 Developers                ttbcrMask.a1 = ones;
168610037SARM gem5 Developers                ttbcrMask.epd1 = ones;
168710037SARM gem5 Developers                ttbcrMask.irgn1 = ones;
168810037SARM gem5 Developers                ttbcrMask.orgn1 = ones;
168910037SARM gem5 Developers                ttbcrMask.sh1 = ones;
169010037SARM gem5 Developers                if (haveLPAE)
169110037SARM gem5 Developers                    ttbcrMask.eae = ones;
169210037SARM gem5 Developers
169310037SARM gem5 Developers                if (haveLPAE && ttbcrNew.eae) {
169410037SARM gem5 Developers                    newVal = newVal & ttbcrMask;
169510037SARM gem5 Developers                } else {
169610037SARM gem5 Developers                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
169710037SARM gem5 Developers                }
169812666Sgiacomo.travaglini@arm.com                // Invalidate TLB MiscReg
169912666Sgiacomo.travaglini@arm.com                getITBPtr(tc)->invalidateMiscReg();
170012666Sgiacomo.travaglini@arm.com                getDTBPtr(tc)->invalidateMiscReg();
170112666Sgiacomo.travaglini@arm.com                break;
170210037SARM gem5 Developers            }
170310037SARM gem5 Developers          case MISCREG_TTBR0:
170410037SARM gem5 Developers          case MISCREG_TTBR1:
170510037SARM gem5 Developers            {
170610037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
170710037SARM gem5 Developers                if (haveLPAE) {
170810037SARM gem5 Developers                    if (ttbcr.eae) {
170910037SARM gem5 Developers                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
171010037SARM gem5 Developers                        // ARMv8 AArch32 bit 63-56 only
171110037SARM gem5 Developers                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
171210037SARM gem5 Developers                        newVal = (newVal & (~ttbrMask));
171310037SARM gem5 Developers                    }
171410037SARM gem5 Developers                }
171512666Sgiacomo.travaglini@arm.com                // Invalidate TLB MiscReg
171612406Sgabeblack@google.com                getITBPtr(tc)->invalidateMiscReg();
171712406Sgabeblack@google.com                getDTBPtr(tc)->invalidateMiscReg();
171812666Sgiacomo.travaglini@arm.com                break;
171910508SAli.Saidi@ARM.com            }
172012666Sgiacomo.travaglini@arm.com          case MISCREG_SCTLR_EL1:
17217749SAli.Saidi@ARM.com          case MISCREG_CONTEXTIDR:
17227749SAli.Saidi@ARM.com          case MISCREG_PRRR:
17237749SAli.Saidi@ARM.com          case MISCREG_NMRR:
172410037SARM gem5 Developers          case MISCREG_MAIR0:
172510037SARM gem5 Developers          case MISCREG_MAIR1:
17267749SAli.Saidi@ARM.com          case MISCREG_DACR:
172710037SARM gem5 Developers          case MISCREG_VTTBR:
172810037SARM gem5 Developers          case MISCREG_SCR_EL3:
172911575SDylan.Johnson@ARM.com          case MISCREG_HCR_EL2:
173010037SARM gem5 Developers          case MISCREG_TCR_EL1:
173110037SARM gem5 Developers          case MISCREG_TCR_EL2:
173210037SARM gem5 Developers          case MISCREG_TCR_EL3:
173310508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL2:
173410508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL3:
173511573SDylan.Johnson@ARM.com          case MISCREG_HSCTLR:
173610037SARM gem5 Developers          case MISCREG_TTBR0_EL1:
173710037SARM gem5 Developers          case MISCREG_TTBR1_EL1:
173810037SARM gem5 Developers          case MISCREG_TTBR0_EL2:
173910037SARM gem5 Developers          case MISCREG_TTBR0_EL3:
174012406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
174112406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
17427749SAli.Saidi@ARM.com            break;
174310037SARM gem5 Developers          case MISCREG_NZCV:
174410037SARM gem5 Developers            {
174510037SARM gem5 Developers                CPSR cpsr = val;
174610037SARM gem5 Developers
174710338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_NZ, cpsr.nz);
174810338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_C,  cpsr.c);
174910338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_V,  cpsr.v);
175010037SARM gem5 Developers            }
175110037SARM gem5 Developers            break;
175210037SARM gem5 Developers          case MISCREG_DAIF:
175310037SARM gem5 Developers            {
175410037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
175510037SARM gem5 Developers                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
175610037SARM gem5 Developers                newVal = cpsr;
175710037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
175810037SARM gem5 Developers            }
175910037SARM gem5 Developers            break;
176010037SARM gem5 Developers          case MISCREG_SP_EL0:
176110037SARM gem5 Developers            tc->setIntReg(INTREG_SP0, newVal);
176210037SARM gem5 Developers            break;
176310037SARM gem5 Developers          case MISCREG_SP_EL1:
176410037SARM gem5 Developers            tc->setIntReg(INTREG_SP1, newVal);
176510037SARM gem5 Developers            break;
176610037SARM gem5 Developers          case MISCREG_SP_EL2:
176710037SARM gem5 Developers            tc->setIntReg(INTREG_SP2, newVal);
176810037SARM gem5 Developers            break;
176910037SARM gem5 Developers          case MISCREG_SPSEL:
177010037SARM gem5 Developers            {
177110037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
177210037SARM gem5 Developers                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
177310037SARM gem5 Developers                newVal = cpsr;
177410037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
177510037SARM gem5 Developers            }
177610037SARM gem5 Developers            break;
177710037SARM gem5 Developers          case MISCREG_CURRENTEL:
177810037SARM gem5 Developers            {
177910037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
178010037SARM gem5 Developers                cpsr.el = (uint8_t) ((CPSR) newVal).el;
178110037SARM gem5 Developers                newVal = cpsr;
178210037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
178310037SARM gem5 Developers            }
178410037SARM gem5 Developers            break;
178510037SARM gem5 Developers          case MISCREG_AT_S1E1R_Xt:
178610037SARM gem5 Developers          case MISCREG_AT_S1E1W_Xt:
178710037SARM gem5 Developers          case MISCREG_AT_S1E0R_Xt:
178810037SARM gem5 Developers          case MISCREG_AT_S1E0W_Xt:
178910037SARM gem5 Developers          case MISCREG_AT_S1E2R_Xt:
179010037SARM gem5 Developers          case MISCREG_AT_S1E2W_Xt:
179110037SARM gem5 Developers          case MISCREG_AT_S12E1R_Xt:
179210037SARM gem5 Developers          case MISCREG_AT_S12E1W_Xt:
179310037SARM gem5 Developers          case MISCREG_AT_S12E0R_Xt:
179410037SARM gem5 Developers          case MISCREG_AT_S12E0W_Xt:
179510037SARM gem5 Developers          case MISCREG_AT_S1E3R_Xt:
179610037SARM gem5 Developers          case MISCREG_AT_S1E3W_Xt:
179710037SARM gem5 Developers            {
179810037SARM gem5 Developers                RequestPtr req = new Request;
179911608Snikos.nikoleris@arm.com                Request::Flags flags = 0;
180010037SARM gem5 Developers                BaseTLB::Mode mode = BaseTLB::Read;
180110037SARM gem5 Developers                TLB::ArmTranslationType tranType = TLB::NormalTran;
180210037SARM gem5 Developers                Fault fault;
180310037SARM gem5 Developers                switch(misc_reg) {
180410037SARM gem5 Developers                  case MISCREG_AT_S1E1R_Xt:
180510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
180611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
180710037SARM gem5 Developers                    mode     = BaseTLB::Read;
180810037SARM gem5 Developers                    break;
180910037SARM gem5 Developers                  case MISCREG_AT_S1E1W_Xt:
181010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
181111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
181210037SARM gem5 Developers                    mode     = BaseTLB::Write;
181310037SARM gem5 Developers                    break;
181410037SARM gem5 Developers                  case MISCREG_AT_S1E0R_Xt:
181510037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
181611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
181710037SARM gem5 Developers                    mode     = BaseTLB::Read;
181810037SARM gem5 Developers                    break;
181910037SARM gem5 Developers                  case MISCREG_AT_S1E0W_Xt:
182010037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
182111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
182210037SARM gem5 Developers                    mode     = BaseTLB::Write;
182310037SARM gem5 Developers                    break;
182410037SARM gem5 Developers                  case MISCREG_AT_S1E2R_Xt:
182510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
182611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
182710037SARM gem5 Developers                    mode     = BaseTLB::Read;
182810037SARM gem5 Developers                    break;
182910037SARM gem5 Developers                  case MISCREG_AT_S1E2W_Xt:
183010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
183111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
183210037SARM gem5 Developers                    mode     = BaseTLB::Write;
183310037SARM gem5 Developers                    break;
183410037SARM gem5 Developers                  case MISCREG_AT_S12E0R_Xt:
183510037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
183611577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
183710037SARM gem5 Developers                    mode     = BaseTLB::Read;
183810037SARM gem5 Developers                    break;
183910037SARM gem5 Developers                  case MISCREG_AT_S12E0W_Xt:
184010037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
184111577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
184210037SARM gem5 Developers                    mode     = BaseTLB::Write;
184310037SARM gem5 Developers                    break;
184410037SARM gem5 Developers                  case MISCREG_AT_S12E1R_Xt:
184510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
184611577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
184710037SARM gem5 Developers                    mode     = BaseTLB::Read;
184810037SARM gem5 Developers                    break;
184910037SARM gem5 Developers                  case MISCREG_AT_S12E1W_Xt:
185010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
185111577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
185210037SARM gem5 Developers                    mode     = BaseTLB::Write;
185310037SARM gem5 Developers                    break;
185410037SARM gem5 Developers                  case MISCREG_AT_S1E3R_Xt:
185510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
185611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
185710037SARM gem5 Developers                    mode     = BaseTLB::Read;
185810037SARM gem5 Developers                    break;
185910037SARM gem5 Developers                  case MISCREG_AT_S1E3W_Xt:
186010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
186111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
186210037SARM gem5 Developers                    mode     = BaseTLB::Write;
186310037SARM gem5 Developers                    break;
186410037SARM gem5 Developers                }
186510037SARM gem5 Developers                // If we're in timing mode then doing the translation in
186610037SARM gem5 Developers                // functional mode then we're slightly distorting performance
186710037SARM gem5 Developers                // results obtained from simulations. The translation should be
186810037SARM gem5 Developers                // done in the same mode the core is running in. NOTE: This
186910037SARM gem5 Developers                // can't be an atomic translation because that causes problems
187010037SARM gem5 Developers                // with unexpected atomic snoop requests.
187110037SARM gem5 Developers                warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
187211560Sandreas.sandberg@arm.com                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
187310037SARM gem5 Developers                               tc->pcState().pc());
187411435Smitch.hayenga@arm.com                req->setContext(tc->contextId());
187512406Sgabeblack@google.com                fault = getDTBPtr(tc)->translateFunctional(req, tc, mode,
187612406Sgabeblack@google.com                                                           tranType);
187710037SARM gem5 Developers
187810037SARM gem5 Developers                MiscReg newVal;
187910037SARM gem5 Developers                if (fault == NoFault) {
188010037SARM gem5 Developers                    Addr paddr = req->getPaddr();
188112406Sgabeblack@google.com                    uint64_t attr = getDTBPtr(tc)->getAttr();
188210037SARM gem5 Developers                    uint64_t attr1 = attr >> 56;
188310037SARM gem5 Developers                    if (!attr1 || attr1 ==0x44) {
188410037SARM gem5 Developers                        attr |= 0x100;
188510037SARM gem5 Developers                        attr &= ~ uint64_t(0x80);
188610037SARM gem5 Developers                    }
188710037SARM gem5 Developers                    newVal = (paddr & mask(47, 12)) | attr;
188810037SARM gem5 Developers                    DPRINTF(MiscRegs,
188910037SARM gem5 Developers                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
189010037SARM gem5 Developers                          val, newVal);
189110037SARM gem5 Developers                } else {
189212524Sgiacomo.travaglini@arm.com                    ArmFault *armFault = static_cast<ArmFault *>(fault.get());
189312570Sgiacomo.travaglini@arm.com                    armFault->update(tc);
189410037SARM gem5 Developers                    // Set fault bit and FSR
189510037SARM gem5 Developers                    FSR fsr = armFault->getFsr(tc);
189610037SARM gem5 Developers
189711577SDylan.Johnson@ARM.com                    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
189811577SDylan.Johnson@ARM.com                    if (cpsr.width) { // AArch32
189911577SDylan.Johnson@ARM.com                        newVal = ((fsr >> 9) & 1) << 11;
190011577SDylan.Johnson@ARM.com                        // rearrange fault status
190111577SDylan.Johnson@ARM.com                        newVal |= ((fsr >>  0) & 0x3f) << 1;
190211577SDylan.Johnson@ARM.com                        newVal |= 0x1; // F bit
190311577SDylan.Johnson@ARM.com                        newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
190411577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 0x200 : 0;
190511577SDylan.Johnson@ARM.com                    } else { // AArch64
190611577SDylan.Johnson@ARM.com                        newVal = 1; // F bit
190711577SDylan.Johnson@ARM.com                        newVal |= fsr << 1; // FST
190811577SDylan.Johnson@ARM.com                        // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
190911577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
191011577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
191111577SDylan.Johnson@ARM.com                        newVal |= 1 << 11; // RES1
191211577SDylan.Johnson@ARM.com                    }
191310037SARM gem5 Developers                    DPRINTF(MiscRegs,
191410037SARM gem5 Developers                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
191510037SARM gem5 Developers                            val, fsr, newVal);
191610037SARM gem5 Developers                }
191710037SARM gem5 Developers                delete req;
191810037SARM gem5 Developers                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
191910037SARM gem5 Developers                return;
192010037SARM gem5 Developers            }
192110037SARM gem5 Developers          case MISCREG_SPSR_EL3:
192210037SARM gem5 Developers          case MISCREG_SPSR_EL2:
192310037SARM gem5 Developers          case MISCREG_SPSR_EL1:
192410037SARM gem5 Developers            // Force bits 23:21 to 0
192510037SARM gem5 Developers            newVal = val & ~(0x7 << 21);
192610037SARM gem5 Developers            break;
19278549Sdaniel.johnson@arm.com          case MISCREG_L2CTLR:
19288549Sdaniel.johnson@arm.com            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
19298549Sdaniel.johnson@arm.com                 miscRegName[misc_reg], uint32_t(val));
193010037SARM gem5 Developers            break;
193110037SARM gem5 Developers
193210037SARM gem5 Developers          // Generic Timer registers
193310844Sandreas.sandberg@arm.com          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
193410844Sandreas.sandberg@arm.com          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
193510844Sandreas.sandberg@arm.com          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
193610844Sandreas.sandberg@arm.com          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
193710844Sandreas.sandberg@arm.com            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
193810037SARM gem5 Developers            break;
19397405SAli.Saidi@ARM.com        }
19407405SAli.Saidi@ARM.com    }
19417405SAli.Saidi@ARM.com    setMiscRegNoEffect(misc_reg, newVal);
19427405SAli.Saidi@ARM.com}
19437405SAli.Saidi@ARM.com
194410844Sandreas.sandberg@arm.comBaseISADevice &
194510844Sandreas.sandberg@arm.comISA::getGenericTimer(ThreadContext *tc)
194610037SARM gem5 Developers{
194710844Sandreas.sandberg@arm.com    // We only need to create an ISA interface the first time we try
194810844Sandreas.sandberg@arm.com    // to access the timer.
194910844Sandreas.sandberg@arm.com    if (timer)
195010844Sandreas.sandberg@arm.com        return *timer.get();
195110844Sandreas.sandberg@arm.com
195210844Sandreas.sandberg@arm.com    assert(system);
195310844Sandreas.sandberg@arm.com    GenericTimer *generic_timer(system->getGenericTimer());
195410844Sandreas.sandberg@arm.com    if (!generic_timer) {
195510844Sandreas.sandberg@arm.com        panic("Trying to get a generic timer from a system that hasn't "
195610844Sandreas.sandberg@arm.com              "been configured to use a generic timer.\n");
195710037SARM gem5 Developers    }
195810037SARM gem5 Developers
195911150Smitch.hayenga@arm.com    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
196010844Sandreas.sandberg@arm.com    return *timer.get();
196110037SARM gem5 Developers}
196210037SARM gem5 Developers
19637405SAli.Saidi@ARM.com}
19649384SAndreas.Sandberg@arm.com
19659384SAndreas.Sandberg@arm.comArmISA::ISA *
19669384SAndreas.Sandberg@arm.comArmISAParams::create()
19679384SAndreas.Sandberg@arm.com{
19689384SAndreas.Sandberg@arm.com    return new ArmISA::ISA(this);
19699384SAndreas.Sandberg@arm.com}
1970