isa.cc revision 13599
17405SAli.Saidi@ARM.com/*
212667Schuan.zhu@arm.com * Copyright (c) 2010-2018 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"
5113531Sjairo.balart@metempsy.com#include "dev/arm/gic_v3.hh"
5213531Sjairo.balart@metempsy.com#include "dev/arm/gic_v3_cpu_interface.hh"
539384SAndreas.Sandberg@arm.com#include "params/ArmISA.hh"
547678Sgblack@eecs.umich.edu#include "sim/faults.hh"
558059SAli.Saidi@ARM.com#include "sim/stat_control.hh"
568284SAli.Saidi@ARM.com#include "sim/system.hh"
577405SAli.Saidi@ARM.com
587405SAli.Saidi@ARM.comnamespace ArmISA
597405SAli.Saidi@ARM.com{
607405SAli.Saidi@ARM.com
619384SAndreas.Sandberg@arm.comISA::ISA(Params *p)
6210461SAndreas.Sandberg@ARM.com    : SimObject(p),
6310461SAndreas.Sandberg@ARM.com      system(NULL),
6411165SRekai.GonzalezAlberquilla@arm.com      _decoderFlavour(p->decoderFlavour),
6513599Sgiacomo.travaglini@arm.com      _vecRegRenameMode(Enums::Full),
6612714Sgiacomo.travaglini@arm.com      pmu(p->pmu),
6712714Sgiacomo.travaglini@arm.com      impdefAsNop(p->impdef_nop)
689384SAndreas.Sandberg@arm.com{
6911770SCurtis.Dunham@arm.com    miscRegs[MISCREG_SCTLR_RST] = 0;
7010037SARM gem5 Developers
7110461SAndreas.Sandberg@ARM.com    // Hook up a dummy device if we haven't been configured with a
7210461SAndreas.Sandberg@ARM.com    // real PMU. By using a dummy device, we don't need to check that
7310461SAndreas.Sandberg@ARM.com    // the PMU exist every time we try to access a PMU register.
7410461SAndreas.Sandberg@ARM.com    if (!pmu)
7510461SAndreas.Sandberg@ARM.com        pmu = &dummyDevice;
7610461SAndreas.Sandberg@ARM.com
7710609Sandreas.sandberg@arm.com    // Give all ISA devices a pointer to this ISA
7810609Sandreas.sandberg@arm.com    pmu->setISA(this);
7910609Sandreas.sandberg@arm.com
8010037SARM gem5 Developers    system = dynamic_cast<ArmSystem *>(p->system);
8110037SARM gem5 Developers
8210037SARM gem5 Developers    // Cache system-level properties
8310037SARM gem5 Developers    if (FullSystem && system) {
8411771SCurtis.Dunham@arm.com        highestELIs64 = system->highestELIs64();
8510037SARM gem5 Developers        haveSecurity = system->haveSecurity();
8610037SARM gem5 Developers        haveLPAE = system->haveLPAE();
8713173Sgiacomo.travaglini@arm.com        haveCrypto = system->haveCrypto();
8810037SARM gem5 Developers        haveVirtualization = system->haveVirtualization();
8910037SARM gem5 Developers        haveLargeAsid64 = system->haveLargeAsid64();
9013114Sgiacomo.travaglini@arm.com        physAddrRange = system->physAddrRange();
9110037SARM gem5 Developers    } else {
9211771SCurtis.Dunham@arm.com        highestELIs64 = true; // ArmSystem::highestELIs64 does the same
9310037SARM gem5 Developers        haveSecurity = haveLPAE = haveVirtualization = false;
9413499Sgiacomo.travaglini@arm.com        haveCrypto = true;
9510037SARM gem5 Developers        haveLargeAsid64 = false;
9613114Sgiacomo.travaglini@arm.com        physAddrRange = 32;  // dummy value
9710037SARM gem5 Developers    }
9810037SARM gem5 Developers
9913531Sjairo.balart@metempsy.com    // GICv3 CPU interface system registers are supported
10013531Sjairo.balart@metempsy.com    haveGICv3CPUInterface = false;
10113531Sjairo.balart@metempsy.com
10213531Sjairo.balart@metempsy.com    if (system && dynamic_cast<Gicv3 *>(system->getGIC())) {
10313531Sjairo.balart@metempsy.com        haveGICv3CPUInterface = true;
10413531Sjairo.balart@metempsy.com    }
10513531Sjairo.balart@metempsy.com
10613599Sgiacomo.travaglini@arm.com    // Initial rename mode depends on highestEL
10713599Sgiacomo.travaglini@arm.com    const_cast<Enums::VecRegRenameMode&>(_vecRegRenameMode) =
10813599Sgiacomo.travaglini@arm.com        highestELIs64 ? Enums::Full : Enums::Elem;
10913599Sgiacomo.travaglini@arm.com
11012477SCurtis.Dunham@arm.com    initializeMiscRegMetadata();
11110037SARM gem5 Developers    preUnflattenMiscReg();
11210037SARM gem5 Developers
1139384SAndreas.Sandberg@arm.com    clear();
1149384SAndreas.Sandberg@arm.com}
1159384SAndreas.Sandberg@arm.com
11612479SCurtis.Dunham@arm.comstd::vector<struct ISA::MiscRegLUTEntry> ISA::lookUpMiscReg(NUM_MISCREGS);
11712479SCurtis.Dunham@arm.com
1189384SAndreas.Sandberg@arm.comconst ArmISAParams *
1199384SAndreas.Sandberg@arm.comISA::params() const
1209384SAndreas.Sandberg@arm.com{
1219384SAndreas.Sandberg@arm.com    return dynamic_cast<const Params *>(_params);
1229384SAndreas.Sandberg@arm.com}
1239384SAndreas.Sandberg@arm.com
1247427Sgblack@eecs.umich.eduvoid
1257427Sgblack@eecs.umich.eduISA::clear()
1267427Sgblack@eecs.umich.edu{
1279385SAndreas.Sandberg@arm.com    const Params *p(params());
1289385SAndreas.Sandberg@arm.com
1297427Sgblack@eecs.umich.edu    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
1307427Sgblack@eecs.umich.edu    memset(miscRegs, 0, sizeof(miscRegs));
13110037SARM gem5 Developers
13213114Sgiacomo.travaglini@arm.com    initID32(p);
13310037SARM gem5 Developers
13413114Sgiacomo.travaglini@arm.com    // We always initialize AArch64 ID registers even
13513114Sgiacomo.travaglini@arm.com    // if we are in AArch32. This is done since if we
13613114Sgiacomo.travaglini@arm.com    // are in SE mode we don't know if our ArmProcess is
13713114Sgiacomo.travaglini@arm.com    // AArch32 or AArch64
13813114Sgiacomo.travaglini@arm.com    initID64(p);
13912690Sgiacomo.travaglini@arm.com
14010037SARM gem5 Developers    // Start with an event in the mailbox
1417427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SEV_MAILBOX] = 1;
1427427Sgblack@eecs.umich.edu
14310037SARM gem5 Developers    // Separate Instruction and Data TLBs
1447427Sgblack@eecs.umich.edu    miscRegs[MISCREG_TLBTR] = 1;
1457427Sgblack@eecs.umich.edu
1467427Sgblack@eecs.umich.edu    MVFR0 mvfr0 = 0;
1477427Sgblack@eecs.umich.edu    mvfr0.advSimdRegisters = 2;
1487427Sgblack@eecs.umich.edu    mvfr0.singlePrecision = 2;
1497427Sgblack@eecs.umich.edu    mvfr0.doublePrecision = 2;
1507427Sgblack@eecs.umich.edu    mvfr0.vfpExceptionTrapping = 0;
1517427Sgblack@eecs.umich.edu    mvfr0.divide = 1;
1527427Sgblack@eecs.umich.edu    mvfr0.squareRoot = 1;
1537427Sgblack@eecs.umich.edu    mvfr0.shortVectors = 1;
1547427Sgblack@eecs.umich.edu    mvfr0.roundingModes = 1;
1557427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR0] = mvfr0;
1567427Sgblack@eecs.umich.edu
1577427Sgblack@eecs.umich.edu    MVFR1 mvfr1 = 0;
1587427Sgblack@eecs.umich.edu    mvfr1.flushToZero = 1;
1597427Sgblack@eecs.umich.edu    mvfr1.defaultNaN = 1;
1607427Sgblack@eecs.umich.edu    mvfr1.advSimdLoadStore = 1;
1617427Sgblack@eecs.umich.edu    mvfr1.advSimdInteger = 1;
1627427Sgblack@eecs.umich.edu    mvfr1.advSimdSinglePrecision = 1;
1637427Sgblack@eecs.umich.edu    mvfr1.advSimdHalfPrecision = 1;
1647427Sgblack@eecs.umich.edu    mvfr1.vfpHalfPrecision = 1;
1657427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR1] = mvfr1;
1667427Sgblack@eecs.umich.edu
1677436Sdam.sunwoo@arm.com    // Reset values of PRRR and NMRR are implementation dependent
1687436Sdam.sunwoo@arm.com
16910037SARM gem5 Developers    // @todo: PRRR and NMRR in secure state?
17010037SARM gem5 Developers    miscRegs[MISCREG_PRRR_NS] =
1717436Sdam.sunwoo@arm.com        (1 << 19) | // 19
1727436Sdam.sunwoo@arm.com        (0 << 18) | // 18
1737436Sdam.sunwoo@arm.com        (0 << 17) | // 17
1747436Sdam.sunwoo@arm.com        (1 << 16) | // 16
1757436Sdam.sunwoo@arm.com        (2 << 14) | // 15:14
1767436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
1777436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
1787436Sdam.sunwoo@arm.com        (2 << 8)  | // 9:8
1797436Sdam.sunwoo@arm.com        (2 << 6)  | // 7:6
1807436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
1817436Sdam.sunwoo@arm.com        (1 << 2)  | // 3:2
1827436Sdam.sunwoo@arm.com        0;          // 1:0
18313393Sgiacomo.travaglini@arm.com
18410037SARM gem5 Developers    miscRegs[MISCREG_NMRR_NS] =
1857436Sdam.sunwoo@arm.com        (1 << 30) | // 31:30
1867436Sdam.sunwoo@arm.com        (0 << 26) | // 27:26
1877436Sdam.sunwoo@arm.com        (0 << 24) | // 25:24
1887436Sdam.sunwoo@arm.com        (3 << 22) | // 23:22
1897436Sdam.sunwoo@arm.com        (2 << 20) | // 21:20
1907436Sdam.sunwoo@arm.com        (0 << 18) | // 19:18
1917436Sdam.sunwoo@arm.com        (0 << 16) | // 17:16
1927436Sdam.sunwoo@arm.com        (1 << 14) | // 15:14
1937436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
1947436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
1957436Sdam.sunwoo@arm.com        (0 << 8)  | // 9:8
1967436Sdam.sunwoo@arm.com        (3 << 6)  | // 7:6
1977436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
1987436Sdam.sunwoo@arm.com        (0 << 2)  | // 3:2
1997436Sdam.sunwoo@arm.com        0;          // 1:0
2007436Sdam.sunwoo@arm.com
20113393Sgiacomo.travaglini@arm.com    if (FullSystem && system->highestELIs64()) {
20213393Sgiacomo.travaglini@arm.com        // Initialize AArch64 state
20313393Sgiacomo.travaglini@arm.com        clear64(p);
20413393Sgiacomo.travaglini@arm.com        return;
20513393Sgiacomo.travaglini@arm.com    }
20613393Sgiacomo.travaglini@arm.com
20713393Sgiacomo.travaglini@arm.com    // Initialize AArch32 state...
20813393Sgiacomo.travaglini@arm.com    clear32(p, sctlr_rst);
20913393Sgiacomo.travaglini@arm.com}
21013393Sgiacomo.travaglini@arm.com
21113393Sgiacomo.travaglini@arm.comvoid
21213393Sgiacomo.travaglini@arm.comISA::clear32(const ArmISAParams *p, const SCTLR &sctlr_rst)
21313393Sgiacomo.travaglini@arm.com{
21413393Sgiacomo.travaglini@arm.com    CPSR cpsr = 0;
21513393Sgiacomo.travaglini@arm.com    cpsr.mode = MODE_USER;
21613393Sgiacomo.travaglini@arm.com
21713396Sgiacomo.travaglini@arm.com    if (FullSystem) {
21813396Sgiacomo.travaglini@arm.com        miscRegs[MISCREG_MVBAR] = system->resetAddr();
21913396Sgiacomo.travaglini@arm.com    }
22013396Sgiacomo.travaglini@arm.com
22113393Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_CPSR] = cpsr;
22213393Sgiacomo.travaglini@arm.com    updateRegMap(cpsr);
22313393Sgiacomo.travaglini@arm.com
22413393Sgiacomo.travaglini@arm.com    SCTLR sctlr = 0;
22513393Sgiacomo.travaglini@arm.com    sctlr.te = (bool) sctlr_rst.te;
22613393Sgiacomo.travaglini@arm.com    sctlr.nmfi = (bool) sctlr_rst.nmfi;
22713393Sgiacomo.travaglini@arm.com    sctlr.v = (bool) sctlr_rst.v;
22813393Sgiacomo.travaglini@arm.com    sctlr.u = 1;
22913393Sgiacomo.travaglini@arm.com    sctlr.xp = 1;
23013393Sgiacomo.travaglini@arm.com    sctlr.rao2 = 1;
23113393Sgiacomo.travaglini@arm.com    sctlr.rao3 = 1;
23213393Sgiacomo.travaglini@arm.com    sctlr.rao4 = 0xf;  // SCTLR[6:3]
23313393Sgiacomo.travaglini@arm.com    sctlr.uci = 1;
23413393Sgiacomo.travaglini@arm.com    sctlr.dze = 1;
23513393Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_SCTLR_NS] = sctlr;
23613393Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
23713393Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_HCPTR] = 0;
23813393Sgiacomo.travaglini@arm.com
2397644Sali.saidi@arm.com    miscRegs[MISCREG_CPACR] = 0;
2408147SAli.Saidi@ARM.com
2419385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_FPSID] = p->fpsid;
2429385SAndreas.Sandberg@arm.com
24310037SARM gem5 Developers    if (haveLPAE) {
24410037SARM gem5 Developers        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
24510037SARM gem5 Developers        ttbcr.eae = 0;
24610037SARM gem5 Developers        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
24710037SARM gem5 Developers        // Enforce consistency with system-level settings
24810037SARM gem5 Developers        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
24910037SARM gem5 Developers    }
25010037SARM gem5 Developers
25110037SARM gem5 Developers    if (haveSecurity) {
25210037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_S] = sctlr;
25310037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 0;
25410037SARM gem5 Developers        miscRegs[MISCREG_VBAR_S] = 0;
25510037SARM gem5 Developers    } else {
25610037SARM gem5 Developers        // we're always non-secure
25710037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 1;
25810037SARM gem5 Developers    }
2598147SAli.Saidi@ARM.com
2607427Sgblack@eecs.umich.edu    //XXX We need to initialize the rest of the state.
2617427Sgblack@eecs.umich.edu}
2627427Sgblack@eecs.umich.edu
26310037SARM gem5 Developersvoid
26410037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p)
26510037SARM gem5 Developers{
26610037SARM gem5 Developers    CPSR cpsr = 0;
26713396Sgiacomo.travaglini@arm.com    Addr rvbar = system->resetAddr();
26810037SARM gem5 Developers    switch (system->highestEL()) {
26910037SARM gem5 Developers        // Set initial EL to highest implemented EL using associated stack
27010037SARM gem5 Developers        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
27110037SARM gem5 Developers        // value
27210037SARM gem5 Developers      case EL3:
27310037SARM gem5 Developers        cpsr.mode = MODE_EL3H;
27410037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
27510037SARM gem5 Developers        break;
27610037SARM gem5 Developers      case EL2:
27710037SARM gem5 Developers        cpsr.mode = MODE_EL2H;
27810037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
27910037SARM gem5 Developers        break;
28010037SARM gem5 Developers      case EL1:
28110037SARM gem5 Developers        cpsr.mode = MODE_EL1H;
28210037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
28310037SARM gem5 Developers        break;
28410037SARM gem5 Developers      default:
28510037SARM gem5 Developers        panic("Invalid highest implemented exception level");
28610037SARM gem5 Developers        break;
28710037SARM gem5 Developers    }
28810037SARM gem5 Developers
28910037SARM gem5 Developers    // Initialize rest of CPSR
29010037SARM gem5 Developers    cpsr.daif = 0xf;  // Mask all interrupts
29110037SARM gem5 Developers    cpsr.ss = 0;
29210037SARM gem5 Developers    cpsr.il = 0;
29310037SARM gem5 Developers    miscRegs[MISCREG_CPSR] = cpsr;
29410037SARM gem5 Developers    updateRegMap(cpsr);
29510037SARM gem5 Developers
29610037SARM gem5 Developers    // Initialize other control registers
29710037SARM gem5 Developers    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
29810037SARM gem5 Developers    if (haveSecurity) {
29911770SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830;
30010037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
30111574SCurtis.Dunham@arm.com    } else if (haveVirtualization) {
30211770SCurtis.Dunham@arm.com        // also  MISCREG_SCTLR_EL2 (by mapping)
30311770SCurtis.Dunham@arm.com        miscRegs[MISCREG_HSCTLR] = 0x30c50830;
30410037SARM gem5 Developers    } else {
30511770SCurtis.Dunham@arm.com        // also  MISCREG_SCTLR_EL1 (by mapping)
30611770SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init
30710037SARM gem5 Developers        // Always non-secure
30810037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3] = 1;
30910037SARM gem5 Developers    }
31013114Sgiacomo.travaglini@arm.com}
31110037SARM gem5 Developers
31213114Sgiacomo.travaglini@arm.comvoid
31313114Sgiacomo.travaglini@arm.comISA::initID32(const ArmISAParams *p)
31413114Sgiacomo.travaglini@arm.com{
31513114Sgiacomo.travaglini@arm.com    // Initialize configurable default values
31613114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_MIDR] = p->midr;
31713114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_MIDR_EL1] = p->midr;
31813114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_VPIDR] = p->midr;
31913114Sgiacomo.travaglini@arm.com
32013114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
32113114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
32213114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
32313114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
32413114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
32513114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
32613114Sgiacomo.travaglini@arm.com
32713114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
32813114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
32913114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
33013114Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
33113499Sgiacomo.travaglini@arm.com
33213499Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_ISAR5] = insertBits(
33313499Sgiacomo.travaglini@arm.com        miscRegs[MISCREG_ID_ISAR5], 19, 4,
33413499Sgiacomo.travaglini@arm.com        haveCrypto ? 0x1112 : 0x0);
33513114Sgiacomo.travaglini@arm.com}
33613114Sgiacomo.travaglini@arm.com
33713114Sgiacomo.travaglini@arm.comvoid
33813114Sgiacomo.travaglini@arm.comISA::initID64(const ArmISAParams *p)
33913114Sgiacomo.travaglini@arm.com{
34010037SARM gem5 Developers    // Initialize configurable id registers
34110037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
34210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
34310461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
34410461SAndreas.Sandberg@ARM.com        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
34510461SAndreas.Sandberg@ARM.com        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
34610461SAndreas.Sandberg@ARM.com
34710037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
34810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
34910037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
35010037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
35110037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
35213116Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_AA64MMFR2_EL1] = p->id_aa64mmfr2_el1;
35310037SARM gem5 Developers
35410461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0_EL1] =
35510461SAndreas.Sandberg@ARM.com        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
35610461SAndreas.Sandberg@ARM.com
35710461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
35810461SAndreas.Sandberg@ARM.com
35910037SARM gem5 Developers    // Enforce consistency with system-level settings...
36010037SARM gem5 Developers
36110037SARM gem5 Developers    // EL3
36210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
36310037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
36411574SCurtis.Dunham@arm.com        haveSecurity ? 0x2 : 0x0);
36510037SARM gem5 Developers    // EL2
36610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
36710037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
36811574SCurtis.Dunham@arm.com        haveVirtualization ? 0x2 : 0x0);
36910037SARM gem5 Developers    // Large ASID support
37010037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
37110037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
37210037SARM gem5 Developers        haveLargeAsid64 ? 0x2 : 0x0);
37310037SARM gem5 Developers    // Physical address size
37410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
37510037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
37613114Sgiacomo.travaglini@arm.com        encodePhysAddrRange64(physAddrRange));
37713173Sgiacomo.travaglini@arm.com    // Crypto
37813173Sgiacomo.travaglini@arm.com    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = insertBits(
37913173Sgiacomo.travaglini@arm.com        miscRegs[MISCREG_ID_AA64ISAR0_EL1], 19, 4,
38013173Sgiacomo.travaglini@arm.com        haveCrypto ? 0x1112 : 0x0);
38110037SARM gem5 Developers}
38210037SARM gem5 Developers
38312972Sandreas.sandberg@arm.comvoid
38412972Sandreas.sandberg@arm.comISA::startup(ThreadContext *tc)
38512972Sandreas.sandberg@arm.com{
38612972Sandreas.sandberg@arm.com    pmu->setThreadContext(tc);
38712972Sandreas.sandberg@arm.com
38813531Sjairo.balart@metempsy.com    if (system) {
38913531Sjairo.balart@metempsy.com        Gicv3 *gicv3 = dynamic_cast<Gicv3 *>(system->getGIC());
39013531Sjairo.balart@metempsy.com        if (gicv3) {
39113531Sjairo.balart@metempsy.com            gicv3CpuInterface.reset(gicv3->getCPUInterface(tc->contextId()));
39213531Sjairo.balart@metempsy.com            gicv3CpuInterface->setISA(this);
39313531Sjairo.balart@metempsy.com        }
39413531Sjairo.balart@metempsy.com    }
39512972Sandreas.sandberg@arm.com}
39612972Sandreas.sandberg@arm.com
39712972Sandreas.sandberg@arm.com
39813581Sgabeblack@google.comRegVal
39910035Sandreas.hansson@arm.comISA::readMiscRegNoEffect(int misc_reg) const
4007405SAli.Saidi@ARM.com{
4017405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
4027614Sminkyu.jeong@arm.com
40312478SCurtis.Dunham@arm.com    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
40412478SCurtis.Dunham@arm.com    const auto &map = getMiscIndices(misc_reg);
40512478SCurtis.Dunham@arm.com    int lower = map.first, upper = map.second;
40612478SCurtis.Dunham@arm.com    // NB!: apply architectural masks according to desired register,
40712478SCurtis.Dunham@arm.com    // despite possibly getting value from different (mapped) register.
40812478SCurtis.Dunham@arm.com    auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32))
40912478SCurtis.Dunham@arm.com                                          |(miscRegs[upper] << 32));
41012478SCurtis.Dunham@arm.com    if (val & reg.res0()) {
41112478SCurtis.Dunham@arm.com        DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n",
41212478SCurtis.Dunham@arm.com                miscRegName[misc_reg], val & reg.res0());
41312478SCurtis.Dunham@arm.com    }
41412478SCurtis.Dunham@arm.com    if ((val & reg.res1()) != reg.res1()) {
41512478SCurtis.Dunham@arm.com        DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n",
41612478SCurtis.Dunham@arm.com                miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1());
41712478SCurtis.Dunham@arm.com    }
41812478SCurtis.Dunham@arm.com    return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao
4197405SAli.Saidi@ARM.com}
4207405SAli.Saidi@ARM.com
4217405SAli.Saidi@ARM.com
42213581Sgabeblack@google.comRegVal
4237405SAli.Saidi@ARM.comISA::readMiscReg(int misc_reg, ThreadContext *tc)
4247405SAli.Saidi@ARM.com{
42510037SARM gem5 Developers    CPSR cpsr = 0;
42610037SARM gem5 Developers    PCState pc = 0;
42710037SARM gem5 Developers    SCR scr = 0;
4289050Schander.sudanthi@arm.com
4297405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
43010037SARM gem5 Developers        cpsr = miscRegs[misc_reg];
43110037SARM gem5 Developers        pc = tc->pcState();
4327720Sgblack@eecs.umich.edu        cpsr.j = pc.jazelle() ? 1 : 0;
4337720Sgblack@eecs.umich.edu        cpsr.t = pc.thumb() ? 1 : 0;
4347405SAli.Saidi@ARM.com        return cpsr;
4357405SAli.Saidi@ARM.com    }
4367757SAli.Saidi@ARM.com
43710037SARM gem5 Developers#ifndef NDEBUG
43810037SARM gem5 Developers    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
43910037SARM gem5 Developers        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
44010037SARM gem5 Developers            warn("Unimplemented system register %s read.\n",
44110037SARM gem5 Developers                 miscRegName[misc_reg]);
44210037SARM gem5 Developers        else
44310037SARM gem5 Developers            panic("Unimplemented system register %s read.\n",
44410037SARM gem5 Developers                  miscRegName[misc_reg]);
44510037SARM gem5 Developers    }
44610037SARM gem5 Developers#endif
44710037SARM gem5 Developers
44810037SARM gem5 Developers    switch (unflattenMiscReg(misc_reg)) {
44910037SARM gem5 Developers      case MISCREG_HCR:
45010037SARM gem5 Developers        {
45110037SARM gem5 Developers            if (!haveVirtualization)
45210037SARM gem5 Developers                return 0;
45310037SARM gem5 Developers            else
45410037SARM gem5 Developers                return readMiscRegNoEffect(MISCREG_HCR);
45510037SARM gem5 Developers        }
45610037SARM gem5 Developers      case MISCREG_CPACR:
45710037SARM gem5 Developers        {
45810037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
45910037SARM gem5 Developers            CPACR cpacrMask = 0;
46010037SARM gem5 Developers            // Only cp10, cp11, and ase are implemented, nothing else should
46110037SARM gem5 Developers            // be readable? (straight copy from the write code)
46210037SARM gem5 Developers            cpacrMask.cp10 = ones;
46310037SARM gem5 Developers            cpacrMask.cp11 = ones;
46410037SARM gem5 Developers            cpacrMask.asedis = ones;
46510037SARM gem5 Developers
46610037SARM gem5 Developers            // Security Extensions may limit the readability of CPACR
46710037SARM gem5 Developers            if (haveSecurity) {
46810037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
46910037SARM gem5 Developers                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
47012667Schuan.zhu@arm.com                if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) {
47110037SARM gem5 Developers                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
47210037SARM gem5 Developers                    // NB: Skipping the full loop, here
47310037SARM gem5 Developers                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
47410037SARM gem5 Developers                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
47510037SARM gem5 Developers                }
47610037SARM gem5 Developers            }
47713581Sgabeblack@google.com            RegVal val = readMiscRegNoEffect(MISCREG_CPACR);
47810037SARM gem5 Developers            val &= cpacrMask;
47910037SARM gem5 Developers            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
48010037SARM gem5 Developers                    miscRegName[misc_reg], val);
48110037SARM gem5 Developers            return val;
48210037SARM gem5 Developers        }
4838284SAli.Saidi@ARM.com      case MISCREG_MPIDR:
48410037SARM gem5 Developers      case MISCREG_MPIDR_EL1:
48513550Sgiacomo.travaglini@arm.com        return readMPIDR(system, tc);
48610037SARM gem5 Developers      case MISCREG_VMPIDR:
48713550Sgiacomo.travaglini@arm.com      case MISCREG_VMPIDR_EL2:
48810037SARM gem5 Developers        // top bit defined as RES1
48910037SARM gem5 Developers        return readMiscRegNoEffect(misc_reg) | 0x80000000;
49010037SARM gem5 Developers      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
49110037SARM gem5 Developers      case MISCREG_REVIDR:  // not implemented, so alias MIDR
49210037SARM gem5 Developers      case MISCREG_MIDR:
49310037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
49410037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
49510037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
49610037SARM gem5 Developers            return readMiscRegNoEffect(misc_reg);
49710037SARM gem5 Developers        } else {
49810037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_VPIDR);
4999050Schander.sudanthi@arm.com        }
5008284SAli.Saidi@ARM.com        break;
50110037SARM gem5 Developers      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
50210037SARM gem5 Developers      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
50310037SARM gem5 Developers      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
50410037SARM gem5 Developers      case MISCREG_AIDR:  // AUX ID set to 0
50510037SARM gem5 Developers      case MISCREG_TCMTR: // No TCM's
50610037SARM gem5 Developers        return 0;
50710037SARM gem5 Developers
5087405SAli.Saidi@ARM.com      case MISCREG_CLIDR:
5097731SAli.Saidi@ARM.com        warn_once("The clidr register always reports 0 caches.\n");
5108468Swade.walker@arm.com        warn_once("clidr LoUIS field of 0b001 to match current "
5118468Swade.walker@arm.com                  "ARM implementations.\n");
5128468Swade.walker@arm.com        return 0x00200000;
5137405SAli.Saidi@ARM.com      case MISCREG_CCSIDR:
5147731SAli.Saidi@ARM.com        warn_once("The ccsidr register isn't implemented and "
5157405SAli.Saidi@ARM.com                "always reads as 0.\n");
5167405SAli.Saidi@ARM.com        break;
51711809Sbaz21@cam.ac.uk      case MISCREG_CTR:                 // AArch32, ARMv7, top bit set
51811809Sbaz21@cam.ac.uk      case MISCREG_CTR_EL0:             // AArch64
5199130Satgutier@umich.edu        {
5209130Satgutier@umich.edu            //all caches have the same line size in gem5
5219130Satgutier@umich.edu            //4 byte words in ARM
5229130Satgutier@umich.edu            unsigned lineSizeWords =
5239814Sandreas.hansson@arm.com                tc->getSystemPtr()->cacheLineSize() / 4;
5249130Satgutier@umich.edu            unsigned log2LineSizeWords = 0;
5259130Satgutier@umich.edu
5269130Satgutier@umich.edu            while (lineSizeWords >>= 1) {
5279130Satgutier@umich.edu                ++log2LineSizeWords;
5289130Satgutier@umich.edu            }
5299130Satgutier@umich.edu
5309130Satgutier@umich.edu            CTR ctr = 0;
5319130Satgutier@umich.edu            //log2 of minimun i-cache line size (words)
5329130Satgutier@umich.edu            ctr.iCacheLineSize = log2LineSizeWords;
5339130Satgutier@umich.edu            //b11 - gem5 uses pipt
5349130Satgutier@umich.edu            ctr.l1IndexPolicy = 0x3;
5359130Satgutier@umich.edu            //log2 of minimum d-cache line size (words)
5369130Satgutier@umich.edu            ctr.dCacheLineSize = log2LineSizeWords;
5379130Satgutier@umich.edu            //log2 of max reservation size (words)
5389130Satgutier@umich.edu            ctr.erg = log2LineSizeWords;
5399130Satgutier@umich.edu            //log2 of max writeback size (words)
5409130Satgutier@umich.edu            ctr.cwg = log2LineSizeWords;
5419130Satgutier@umich.edu            //b100 - gem5 format is ARMv7
5429130Satgutier@umich.edu            ctr.format = 0x4;
5439130Satgutier@umich.edu
5449130Satgutier@umich.edu            return ctr;
5459130Satgutier@umich.edu        }
5467583SAli.Saidi@arm.com      case MISCREG_ACTLR:
5477583SAli.Saidi@arm.com        warn("Not doing anything for miscreg ACTLR\n");
5487583SAli.Saidi@arm.com        break;
54910461SAndreas.Sandberg@ARM.com
55010461SAndreas.Sandberg@ARM.com      case MISCREG_PMXEVTYPER_PMCCFILTR:
55110461SAndreas.Sandberg@ARM.com      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
55210461SAndreas.Sandberg@ARM.com      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
55310461SAndreas.Sandberg@ARM.com      case MISCREG_PMCR ... MISCREG_PMOVSSET:
55410461SAndreas.Sandberg@ARM.com        return pmu->readMiscReg(misc_reg);
55510461SAndreas.Sandberg@ARM.com
5568302SAli.Saidi@ARM.com      case MISCREG_CPSR_Q:
5578302SAli.Saidi@ARM.com        panic("shouldn't be reading this register seperately\n");
5587783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_QC:
5597783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
5607783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_EXC:
5617783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
56210037SARM gem5 Developers      case MISCREG_FPSR:
56310037SARM gem5 Developers        {
56410037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
56510037SARM gem5 Developers            FPSCR fpscrMask = 0;
56610037SARM gem5 Developers            fpscrMask.ioc = ones;
56710037SARM gem5 Developers            fpscrMask.dzc = ones;
56810037SARM gem5 Developers            fpscrMask.ofc = ones;
56910037SARM gem5 Developers            fpscrMask.ufc = ones;
57010037SARM gem5 Developers            fpscrMask.ixc = ones;
57110037SARM gem5 Developers            fpscrMask.idc = ones;
57210037SARM gem5 Developers            fpscrMask.qc = ones;
57310037SARM gem5 Developers            fpscrMask.v = ones;
57410037SARM gem5 Developers            fpscrMask.c = ones;
57510037SARM gem5 Developers            fpscrMask.z = ones;
57610037SARM gem5 Developers            fpscrMask.n = ones;
57710037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
57810037SARM gem5 Developers        }
57910037SARM gem5 Developers      case MISCREG_FPCR:
58010037SARM gem5 Developers        {
58110037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
58210037SARM gem5 Developers            FPSCR fpscrMask  = 0;
58310037SARM gem5 Developers            fpscrMask.len    = ones;
58410037SARM gem5 Developers            fpscrMask.stride = ones;
58510037SARM gem5 Developers            fpscrMask.rMode  = ones;
58610037SARM gem5 Developers            fpscrMask.fz     = ones;
58710037SARM gem5 Developers            fpscrMask.dn     = ones;
58810037SARM gem5 Developers            fpscrMask.ahp    = ones;
58910037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
59010037SARM gem5 Developers        }
59110037SARM gem5 Developers      case MISCREG_NZCV:
59210037SARM gem5 Developers        {
59310037SARM gem5 Developers            CPSR cpsr = 0;
59410338SCurtis.Dunham@arm.com            cpsr.nz   = tc->readCCReg(CCREG_NZ);
59510338SCurtis.Dunham@arm.com            cpsr.c    = tc->readCCReg(CCREG_C);
59610338SCurtis.Dunham@arm.com            cpsr.v    = tc->readCCReg(CCREG_V);
59710037SARM gem5 Developers            return cpsr;
59810037SARM gem5 Developers        }
59910037SARM gem5 Developers      case MISCREG_DAIF:
60010037SARM gem5 Developers        {
60110037SARM gem5 Developers            CPSR cpsr = 0;
60210037SARM gem5 Developers            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
60310037SARM gem5 Developers            return cpsr;
60410037SARM gem5 Developers        }
60510037SARM gem5 Developers      case MISCREG_SP_EL0:
60610037SARM gem5 Developers        {
60710037SARM gem5 Developers            return tc->readIntReg(INTREG_SP0);
60810037SARM gem5 Developers        }
60910037SARM gem5 Developers      case MISCREG_SP_EL1:
61010037SARM gem5 Developers        {
61110037SARM gem5 Developers            return tc->readIntReg(INTREG_SP1);
61210037SARM gem5 Developers        }
61310037SARM gem5 Developers      case MISCREG_SP_EL2:
61410037SARM gem5 Developers        {
61510037SARM gem5 Developers            return tc->readIntReg(INTREG_SP2);
61610037SARM gem5 Developers        }
61710037SARM gem5 Developers      case MISCREG_SPSEL:
61810037SARM gem5 Developers        {
61910037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0x1;
62010037SARM gem5 Developers        }
62110037SARM gem5 Developers      case MISCREG_CURRENTEL:
62210037SARM gem5 Developers        {
62310037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0xc;
62410037SARM gem5 Developers        }
6258549Sdaniel.johnson@arm.com      case MISCREG_L2CTLR:
6268868SMatt.Horsnell@arm.com        {
6278868SMatt.Horsnell@arm.com            // mostly unimplemented, just set NumCPUs field from sim and return
6288868SMatt.Horsnell@arm.com            L2CTLR l2ctlr = 0;
6298868SMatt.Horsnell@arm.com            // b00:1CPU to b11:4CPUs
6308868SMatt.Horsnell@arm.com            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
6318868SMatt.Horsnell@arm.com            return l2ctlr;
6328868SMatt.Horsnell@arm.com        }
6338868SMatt.Horsnell@arm.com      case MISCREG_DBGDIDR:
6348868SMatt.Horsnell@arm.com        /* For now just implement the version number.
63510461SAndreas.Sandberg@ARM.com         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
6368868SMatt.Horsnell@arm.com         */
63710461SAndreas.Sandberg@ARM.com        return 0x5 << 16;
63810037SARM gem5 Developers      case MISCREG_DBGDSCRint:
6398868SMatt.Horsnell@arm.com        return 0;
64010037SARM gem5 Developers      case MISCREG_ISR:
64111150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
64210037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR),
64310037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
64410037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR));
64510037SARM gem5 Developers      case MISCREG_ISR_EL1:
64611150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
64710037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR_EL2),
64810037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
64910037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR_EL3));
65010037SARM gem5 Developers      case MISCREG_DCZID_EL0:
65110037SARM gem5 Developers        return 0x04;  // DC ZVA clear 64-byte chunks
65210037SARM gem5 Developers      case MISCREG_HCPTR:
65310037SARM gem5 Developers        {
65413581Sgabeblack@google.com            RegVal val = readMiscRegNoEffect(misc_reg);
65510037SARM gem5 Developers            // The trap bit associated with CP14 is defined as RAZ
65610037SARM gem5 Developers            val &= ~(1 << 14);
65710037SARM gem5 Developers            // If a CP bit in NSACR is 0 then the corresponding bit in
65810037SARM gem5 Developers            // HCPTR is RAO/WI
65910037SARM gem5 Developers            bool secure_lookup = haveSecurity &&
66010037SARM gem5 Developers                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
66110037SARM gem5 Developers                              readMiscRegNoEffect(MISCREG_CPSR));
66210037SARM gem5 Developers            if (!secure_lookup) {
66313581Sgabeblack@google.com                RegVal mask = readMiscRegNoEffect(MISCREG_NSACR);
66410037SARM gem5 Developers                val |= (mask ^ 0x7FFF) & 0xBFFF;
66510037SARM gem5 Developers            }
66610037SARM gem5 Developers            // Set the bits for unimplemented coprocessors to RAO/WI
66710037SARM gem5 Developers            val |= 0x33FF;
66810037SARM gem5 Developers            return (val);
66910037SARM gem5 Developers        }
67010037SARM gem5 Developers      case MISCREG_HDFAR: // alias for secure DFAR
67110037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_DFAR_S);
67210037SARM gem5 Developers      case MISCREG_HIFAR: // alias for secure IFAR
67310037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_IFAR_S);
67410844Sandreas.sandberg@arm.com
67511772SCurtis.Dunham@arm.com      case MISCREG_ID_PFR0:
67611772SCurtis.Dunham@arm.com        // !ThumbEE | !Jazelle | Thumb | ARM
67711772SCurtis.Dunham@arm.com        return 0x00000031;
67811772SCurtis.Dunham@arm.com      case MISCREG_ID_PFR1:
67911774SCurtis.Dunham@arm.com        {   // Timer | Virti | !M Profile | TrustZone | ARMv4
68011774SCurtis.Dunham@arm.com            bool haveTimer = (system->getGenericTimer() != NULL);
68111774SCurtis.Dunham@arm.com            return 0x00000001
68211774SCurtis.Dunham@arm.com                 | (haveSecurity       ? 0x00000010 : 0x0)
68311774SCurtis.Dunham@arm.com                 | (haveVirtualization ? 0x00001000 : 0x0)
68411774SCurtis.Dunham@arm.com                 | (haveTimer          ? 0x00010000 : 0x0);
68511774SCurtis.Dunham@arm.com        }
68611773SCurtis.Dunham@arm.com      case MISCREG_ID_AA64PFR0_EL1:
68713531Sjairo.balart@metempsy.com        return 0x0000000000000002 | // AArch{64,32} supported at EL0
68813531Sjairo.balart@metempsy.com               0x0000000000000020                               | // EL1
68913531Sjairo.balart@metempsy.com               (haveVirtualization    ? 0x0000000000000200 : 0) | // EL2
69013531Sjairo.balart@metempsy.com               (haveSecurity          ? 0x0000000000002000 : 0) | // EL3
69113531Sjairo.balart@metempsy.com               (haveGICv3CPUInterface ? 0x0000000001000000 : 0);
69211773SCurtis.Dunham@arm.com      case MISCREG_ID_AA64PFR1_EL1:
69311773SCurtis.Dunham@arm.com        return 0; // bits [63:0] RES0 (reserved for future use)
69411772SCurtis.Dunham@arm.com
69510037SARM gem5 Developers      // Generic Timer registers
69612816Sgiacomo.travaglini@arm.com      case MISCREG_CNTHV_CTL_EL2:
69712816Sgiacomo.travaglini@arm.com      case MISCREG_CNTHV_CVAL_EL2:
69812816Sgiacomo.travaglini@arm.com      case MISCREG_CNTHV_TVAL_EL2:
69910844Sandreas.sandberg@arm.com      case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
70010844Sandreas.sandberg@arm.com      case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
70110844Sandreas.sandberg@arm.com      case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
70210844Sandreas.sandberg@arm.com      case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
70310844Sandreas.sandberg@arm.com        return getGenericTimer(tc).readMiscReg(misc_reg);
70410844Sandreas.sandberg@arm.com
70513531Sjairo.balart@metempsy.com      case MISCREG_ICC_PMR_EL1 ... MISCREG_ICC_IGRPEN1_EL3:
70613531Sjairo.balart@metempsy.com      case MISCREG_ICH_AP0R0_EL2 ... MISCREG_ICH_LR15_EL2:
70713531Sjairo.balart@metempsy.com        return getGICv3CPUInterface(tc).readMiscReg(misc_reg);
70813531Sjairo.balart@metempsy.com
70910188Sgeoffrey.blake@arm.com      default:
71010037SARM gem5 Developers        break;
71110037SARM gem5 Developers
7127405SAli.Saidi@ARM.com    }
7137405SAli.Saidi@ARM.com    return readMiscRegNoEffect(misc_reg);
7147405SAli.Saidi@ARM.com}
7157405SAli.Saidi@ARM.com
7167405SAli.Saidi@ARM.comvoid
71713582Sgabeblack@google.comISA::setMiscRegNoEffect(int misc_reg, RegVal val)
7187405SAli.Saidi@ARM.com{
7197405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
7207614Sminkyu.jeong@arm.com
72112478SCurtis.Dunham@arm.com    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
72212478SCurtis.Dunham@arm.com    const auto &map = getMiscIndices(misc_reg);
72312478SCurtis.Dunham@arm.com    int lower = map.first, upper = map.second;
72412478SCurtis.Dunham@arm.com
72512478SCurtis.Dunham@arm.com    auto v = (val & ~reg.wi()) | reg.rao();
72611771SCurtis.Dunham@arm.com    if (upper > 0) {
72712478SCurtis.Dunham@arm.com        miscRegs[lower] = bits(v, 31, 0);
72812478SCurtis.Dunham@arm.com        miscRegs[upper] = bits(v, 63, 32);
72910037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
73012478SCurtis.Dunham@arm.com                misc_reg, lower, upper, v);
73110037SARM gem5 Developers    } else {
73212478SCurtis.Dunham@arm.com        miscRegs[lower] = v;
73310037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
73412478SCurtis.Dunham@arm.com                misc_reg, lower, v);
73510037SARM gem5 Developers    }
7367405SAli.Saidi@ARM.com}
7377405SAli.Saidi@ARM.com
7387405SAli.Saidi@ARM.comvoid
73913582Sgabeblack@google.comISA::setMiscReg(int misc_reg, RegVal val, ThreadContext *tc)
7407405SAli.Saidi@ARM.com{
7417749SAli.Saidi@ARM.com
74213581Sgabeblack@google.com    RegVal newVal = val;
74310037SARM gem5 Developers    bool secure_lookup;
74410037SARM gem5 Developers    SCR scr;
7458284SAli.Saidi@ARM.com
7467405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
7477405SAli.Saidi@ARM.com        updateRegMap(val);
7487749SAli.Saidi@ARM.com
7497749SAli.Saidi@ARM.com
7507749SAli.Saidi@ARM.com        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
7517749SAli.Saidi@ARM.com        int old_mode = old_cpsr.mode;
7527405SAli.Saidi@ARM.com        CPSR cpsr = val;
75312510Sgiacomo.travaglini@arm.com        if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) {
75412406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
75512406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
7567749SAli.Saidi@ARM.com        }
7577749SAli.Saidi@ARM.com
7587614Sminkyu.jeong@arm.com        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
7597614Sminkyu.jeong@arm.com                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
7607720Sgblack@eecs.umich.edu        PCState pc = tc->pcState();
7617720Sgblack@eecs.umich.edu        pc.nextThumb(cpsr.t);
7627720Sgblack@eecs.umich.edu        pc.nextJazelle(cpsr.j);
76312763Sgiacomo.travaglini@arm.com        pc.illegalExec(cpsr.il == 1);
7648887Sgeoffrey.blake@arm.com
7658887Sgeoffrey.blake@arm.com        // Follow slightly different semantics if a CheckerCPU object
7668887Sgeoffrey.blake@arm.com        // is connected
7678887Sgeoffrey.blake@arm.com        CheckerCPU *checker = tc->getCheckerCpuPtr();
7688887Sgeoffrey.blake@arm.com        if (checker) {
7698887Sgeoffrey.blake@arm.com            tc->pcStateNoRecord(pc);
7708887Sgeoffrey.blake@arm.com        } else {
7718887Sgeoffrey.blake@arm.com            tc->pcState(pc);
7728887Sgeoffrey.blake@arm.com        }
7737408Sgblack@eecs.umich.edu    } else {
77410037SARM gem5 Developers#ifndef NDEBUG
77510037SARM gem5 Developers        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
77610037SARM gem5 Developers            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
77710037SARM gem5 Developers                warn("Unimplemented system register %s write with %#x.\n",
77810037SARM gem5 Developers                    miscRegName[misc_reg], val);
77910037SARM gem5 Developers            else
78010037SARM gem5 Developers                panic("Unimplemented system register %s write with %#x.\n",
78110037SARM gem5 Developers                    miscRegName[misc_reg], val);
78210037SARM gem5 Developers        }
78310037SARM gem5 Developers#endif
78410037SARM gem5 Developers        switch (unflattenMiscReg(misc_reg)) {
7857408Sgblack@eecs.umich.edu          case MISCREG_CPACR:
7867408Sgblack@eecs.umich.edu            {
7878206SWilliam.Wang@arm.com
7888206SWilliam.Wang@arm.com                const uint32_t ones = (uint32_t)(-1);
7898206SWilliam.Wang@arm.com                CPACR cpacrMask = 0;
7908206SWilliam.Wang@arm.com                // Only cp10, cp11, and ase are implemented, nothing else should
7918206SWilliam.Wang@arm.com                // be writable
7928206SWilliam.Wang@arm.com                cpacrMask.cp10 = ones;
7938206SWilliam.Wang@arm.com                cpacrMask.cp11 = ones;
7948206SWilliam.Wang@arm.com                cpacrMask.asedis = ones;
79510037SARM gem5 Developers
79610037SARM gem5 Developers                // Security Extensions may limit the writability of CPACR
79710037SARM gem5 Developers                if (haveSecurity) {
79810037SARM gem5 Developers                    scr = readMiscRegNoEffect(MISCREG_SCR);
79910037SARM gem5 Developers                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
80012667Schuan.zhu@arm.com                    if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) {
80110037SARM gem5 Developers                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
80210037SARM gem5 Developers                        // NB: Skipping the full loop, here
80310037SARM gem5 Developers                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
80410037SARM gem5 Developers                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
80510037SARM gem5 Developers                    }
80610037SARM gem5 Developers                }
80710037SARM gem5 Developers
80813581Sgabeblack@google.com                RegVal old_val = readMiscRegNoEffect(MISCREG_CPACR);
8098206SWilliam.Wang@arm.com                newVal &= cpacrMask;
81010037SARM gem5 Developers                newVal |= old_val & ~cpacrMask;
81110037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
81210037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
81310037SARM gem5 Developers            }
81410037SARM gem5 Developers            break;
81510037SARM gem5 Developers          case MISCREG_CPTR_EL2:
81610037SARM gem5 Developers            {
81710037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
81810037SARM gem5 Developers                CPTR cptrMask = 0;
81910037SARM gem5 Developers                cptrMask.tcpac = ones;
82010037SARM gem5 Developers                cptrMask.tta = ones;
82110037SARM gem5 Developers                cptrMask.tfp = ones;
82210037SARM gem5 Developers                newVal &= cptrMask;
82310037SARM gem5 Developers                cptrMask = 0;
82410037SARM gem5 Developers                cptrMask.res1_13_12_el2 = ones;
82510037SARM gem5 Developers                cptrMask.res1_9_0_el2 = ones;
82610037SARM gem5 Developers                newVal |= cptrMask;
82710037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
82810037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
82910037SARM gem5 Developers            }
83010037SARM gem5 Developers            break;
83110037SARM gem5 Developers          case MISCREG_CPTR_EL3:
83210037SARM gem5 Developers            {
83310037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
83410037SARM gem5 Developers                CPTR cptrMask = 0;
83510037SARM gem5 Developers                cptrMask.tcpac = ones;
83610037SARM gem5 Developers                cptrMask.tta = ones;
83710037SARM gem5 Developers                cptrMask.tfp = ones;
83810037SARM gem5 Developers                newVal &= cptrMask;
8398206SWilliam.Wang@arm.com                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
8408206SWilliam.Wang@arm.com                        miscRegName[misc_reg], newVal);
8417408Sgblack@eecs.umich.edu            }
8427408Sgblack@eecs.umich.edu            break;
8437408Sgblack@eecs.umich.edu          case MISCREG_CSSELR:
8447731SAli.Saidi@ARM.com            warn_once("The csselr register isn't implemented.\n");
8458206SWilliam.Wang@arm.com            return;
84610037SARM gem5 Developers
84710037SARM gem5 Developers          case MISCREG_DC_ZVA_Xt:
84810037SARM gem5 Developers            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
84910037SARM gem5 Developers            return;
85010037SARM gem5 Developers
8517408Sgblack@eecs.umich.edu          case MISCREG_FPSCR:
8527408Sgblack@eecs.umich.edu            {
8537408Sgblack@eecs.umich.edu                const uint32_t ones = (uint32_t)(-1);
8547408Sgblack@eecs.umich.edu                FPSCR fpscrMask = 0;
8557408Sgblack@eecs.umich.edu                fpscrMask.ioc = ones;
8567408Sgblack@eecs.umich.edu                fpscrMask.dzc = ones;
8577408Sgblack@eecs.umich.edu                fpscrMask.ofc = ones;
8587408Sgblack@eecs.umich.edu                fpscrMask.ufc = ones;
8597408Sgblack@eecs.umich.edu                fpscrMask.ixc = ones;
8607408Sgblack@eecs.umich.edu                fpscrMask.idc = ones;
86110037SARM gem5 Developers                fpscrMask.ioe = ones;
86210037SARM gem5 Developers                fpscrMask.dze = ones;
86310037SARM gem5 Developers                fpscrMask.ofe = ones;
86410037SARM gem5 Developers                fpscrMask.ufe = ones;
86510037SARM gem5 Developers                fpscrMask.ixe = ones;
86610037SARM gem5 Developers                fpscrMask.ide = ones;
8677408Sgblack@eecs.umich.edu                fpscrMask.len = ones;
8687408Sgblack@eecs.umich.edu                fpscrMask.stride = ones;
8697408Sgblack@eecs.umich.edu                fpscrMask.rMode = ones;
8707408Sgblack@eecs.umich.edu                fpscrMask.fz = ones;
8717408Sgblack@eecs.umich.edu                fpscrMask.dn = ones;
8727408Sgblack@eecs.umich.edu                fpscrMask.ahp = ones;
8737408Sgblack@eecs.umich.edu                fpscrMask.qc = ones;
8747408Sgblack@eecs.umich.edu                fpscrMask.v = ones;
8757408Sgblack@eecs.umich.edu                fpscrMask.c = ones;
8767408Sgblack@eecs.umich.edu                fpscrMask.z = ones;
8777408Sgblack@eecs.umich.edu                fpscrMask.n = ones;
8787408Sgblack@eecs.umich.edu                newVal = (newVal & (uint32_t)fpscrMask) |
87910037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
88010037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
8819377Sgblack@eecs.umich.edu                tc->getDecoderPtr()->setContext(newVal);
8827408Sgblack@eecs.umich.edu            }
8837408Sgblack@eecs.umich.edu            break;
88410037SARM gem5 Developers          case MISCREG_FPSR:
88510037SARM gem5 Developers            {
88610037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
88710037SARM gem5 Developers                FPSCR fpscrMask = 0;
88810037SARM gem5 Developers                fpscrMask.ioc = ones;
88910037SARM gem5 Developers                fpscrMask.dzc = ones;
89010037SARM gem5 Developers                fpscrMask.ofc = ones;
89110037SARM gem5 Developers                fpscrMask.ufc = ones;
89210037SARM gem5 Developers                fpscrMask.ixc = ones;
89310037SARM gem5 Developers                fpscrMask.idc = ones;
89410037SARM gem5 Developers                fpscrMask.qc = ones;
89510037SARM gem5 Developers                fpscrMask.v = ones;
89610037SARM gem5 Developers                fpscrMask.c = ones;
89710037SARM gem5 Developers                fpscrMask.z = ones;
89810037SARM gem5 Developers                fpscrMask.n = ones;
89910037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
90010037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
90110037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
90210037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
90310037SARM gem5 Developers            }
90410037SARM gem5 Developers            break;
90510037SARM gem5 Developers          case MISCREG_FPCR:
90610037SARM gem5 Developers            {
90710037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
90810037SARM gem5 Developers                FPSCR fpscrMask  = 0;
90910037SARM gem5 Developers                fpscrMask.len    = ones;
91010037SARM gem5 Developers                fpscrMask.stride = ones;
91110037SARM gem5 Developers                fpscrMask.rMode  = ones;
91210037SARM gem5 Developers                fpscrMask.fz     = ones;
91310037SARM gem5 Developers                fpscrMask.dn     = ones;
91410037SARM gem5 Developers                fpscrMask.ahp    = ones;
91510037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
91610037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
91710037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
91810037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
91910037SARM gem5 Developers            }
92010037SARM gem5 Developers            break;
9218302SAli.Saidi@ARM.com          case MISCREG_CPSR_Q:
9228302SAli.Saidi@ARM.com            {
9238302SAli.Saidi@ARM.com                assert(!(newVal & ~CpsrMaskQ));
92410037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
9258302SAli.Saidi@ARM.com                misc_reg = MISCREG_CPSR;
9268302SAli.Saidi@ARM.com            }
9278302SAli.Saidi@ARM.com            break;
9287783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_QC:
9297783SGiacomo.Gabrielli@arm.com            {
93010037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
93110037SARM gem5 Developers                         (newVal & FpscrQcMask);
9327783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
9337783SGiacomo.Gabrielli@arm.com            }
9347783SGiacomo.Gabrielli@arm.com            break;
9357783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_EXC:
9367783SGiacomo.Gabrielli@arm.com            {
93710037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
93810037SARM gem5 Developers                         (newVal & FpscrExcMask);
9397783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
9407783SGiacomo.Gabrielli@arm.com            }
9417783SGiacomo.Gabrielli@arm.com            break;
9427408Sgblack@eecs.umich.edu          case MISCREG_FPEXC:
9437408Sgblack@eecs.umich.edu            {
9448206SWilliam.Wang@arm.com                // vfpv3 architecture, section B.6.1 of DDI04068
9458206SWilliam.Wang@arm.com                // bit 29 - valid only if fpexc[31] is 0
9467408Sgblack@eecs.umich.edu                const uint32_t fpexcMask = 0x60000000;
9477408Sgblack@eecs.umich.edu                newVal = (newVal & fpexcMask) |
94810037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
9497408Sgblack@eecs.umich.edu            }
9507408Sgblack@eecs.umich.edu            break;
95110037SARM gem5 Developers          case MISCREG_HCR:
95210037SARM gem5 Developers            {
95310037SARM gem5 Developers                if (!haveVirtualization)
95410037SARM gem5 Developers                    return;
95510037SARM gem5 Developers            }
95610037SARM gem5 Developers            break;
95710037SARM gem5 Developers          case MISCREG_IFSR:
95810037SARM gem5 Developers            {
95910037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.96
96010037SARM gem5 Developers                const uint32_t ifsrMask =
96110037SARM gem5 Developers                    mask(31, 13) | mask(11, 11) | mask(8, 6);
96210037SARM gem5 Developers                newVal = newVal & ~ifsrMask;
96310037SARM gem5 Developers            }
96410037SARM gem5 Developers            break;
96510037SARM gem5 Developers          case MISCREG_DFSR:
96610037SARM gem5 Developers            {
96710037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.52
96810037SARM gem5 Developers                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
96910037SARM gem5 Developers                newVal = newVal & ~dfsrMask;
97010037SARM gem5 Developers            }
97110037SARM gem5 Developers            break;
97210037SARM gem5 Developers          case MISCREG_AMAIR0:
97310037SARM gem5 Developers          case MISCREG_AMAIR1:
97410037SARM gem5 Developers            {
97510037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.5
97610037SARM gem5 Developers                // Valid only with LPAE
97710037SARM gem5 Developers                if (!haveLPAE)
97810037SARM gem5 Developers                    return;
97910037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
98010037SARM gem5 Developers            }
98110037SARM gem5 Developers            break;
98210037SARM gem5 Developers          case MISCREG_SCR:
98312406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
98412406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
98510037SARM gem5 Developers            break;
9867408Sgblack@eecs.umich.edu          case MISCREG_SCTLR:
9877408Sgblack@eecs.umich.edu            {
9887408Sgblack@eecs.umich.edu                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
98910037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
99012639Sgiacomo.travaglini@arm.com
99112639Sgiacomo.travaglini@arm.com                MiscRegIndex sctlr_idx;
99212639Sgiacomo.travaglini@arm.com                if (haveSecurity && !highestELIs64 && !scr.ns) {
99312639Sgiacomo.travaglini@arm.com                    sctlr_idx = MISCREG_SCTLR_S;
99412639Sgiacomo.travaglini@arm.com                } else {
99512639Sgiacomo.travaglini@arm.com                    sctlr_idx =  MISCREG_SCTLR_NS;
99612639Sgiacomo.travaglini@arm.com                }
99712639Sgiacomo.travaglini@arm.com
99810037SARM gem5 Developers                SCTLR sctlr = miscRegs[sctlr_idx];
9997408Sgblack@eecs.umich.edu                SCTLR new_sctlr = newVal;
100010037SARM gem5 Developers                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
100113581Sgabeblack@google.com                miscRegs[sctlr_idx] = (RegVal)new_sctlr;
100212406Sgabeblack@google.com                getITBPtr(tc)->invalidateMiscReg();
100312406Sgabeblack@google.com                getDTBPtr(tc)->invalidateMiscReg();
10047408Sgblack@eecs.umich.edu            }
10059385SAndreas.Sandberg@arm.com          case MISCREG_MIDR:
10069385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR0:
10079385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR1:
100810461SAndreas.Sandberg@ARM.com          case MISCREG_ID_DFR0:
10099385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR0:
10109385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR1:
10119385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR2:
10129385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR3:
10139385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR0:
10149385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR1:
10159385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR2:
10169385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR3:
10179385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR4:
10189385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR5:
10199385SAndreas.Sandberg@arm.com
10209385SAndreas.Sandberg@arm.com          case MISCREG_MPIDR:
10219385SAndreas.Sandberg@arm.com          case MISCREG_FPSID:
10227408Sgblack@eecs.umich.edu          case MISCREG_TLBTR:
10237408Sgblack@eecs.umich.edu          case MISCREG_MVFR0:
10247408Sgblack@eecs.umich.edu          case MISCREG_MVFR1:
102510037SARM gem5 Developers
102610037SARM gem5 Developers          case MISCREG_ID_AA64AFR0_EL1:
102710037SARM gem5 Developers          case MISCREG_ID_AA64AFR1_EL1:
102810037SARM gem5 Developers          case MISCREG_ID_AA64DFR0_EL1:
102910037SARM gem5 Developers          case MISCREG_ID_AA64DFR1_EL1:
103010037SARM gem5 Developers          case MISCREG_ID_AA64ISAR0_EL1:
103110037SARM gem5 Developers          case MISCREG_ID_AA64ISAR1_EL1:
103210037SARM gem5 Developers          case MISCREG_ID_AA64MMFR0_EL1:
103310037SARM gem5 Developers          case MISCREG_ID_AA64MMFR1_EL1:
103413116Sgiacomo.travaglini@arm.com          case MISCREG_ID_AA64MMFR2_EL1:
103510037SARM gem5 Developers          case MISCREG_ID_AA64PFR0_EL1:
103610037SARM gem5 Developers          case MISCREG_ID_AA64PFR1_EL1:
10379385SAndreas.Sandberg@arm.com            // ID registers are constants.
10387408Sgblack@eecs.umich.edu            return;
10399385SAndreas.Sandberg@arm.com
104012605Sgiacomo.travaglini@arm.com          // TLB Invalidate All
104112605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
104212605Sgiacomo.travaglini@arm.com            {
104312605Sgiacomo.travaglini@arm.com                assert32(tc);
104412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
104512605Sgiacomo.travaglini@arm.com
104612605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
104712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
104812605Sgiacomo.travaglini@arm.com                return;
104912605Sgiacomo.travaglini@arm.com            }
105012605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Inner Shareable
10517408Sgblack@eecs.umich.edu          case MISCREG_TLBIALLIS:
105212605Sgiacomo.travaglini@arm.com            {
105312605Sgiacomo.travaglini@arm.com                assert32(tc);
105412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
105512605Sgiacomo.travaglini@arm.com
105612605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
105712605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
105812605Sgiacomo.travaglini@arm.com                return;
105912605Sgiacomo.travaglini@arm.com            }
106012605Sgiacomo.travaglini@arm.com          // Instruction TLB Invalidate All
10617408Sgblack@eecs.umich.edu          case MISCREG_ITLBIALL:
106212605Sgiacomo.travaglini@arm.com            {
106312605Sgiacomo.travaglini@arm.com                assert32(tc);
106412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
106512605Sgiacomo.travaglini@arm.com
106612605Sgiacomo.travaglini@arm.com                ITLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
106712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
106812605Sgiacomo.travaglini@arm.com                return;
106912605Sgiacomo.travaglini@arm.com            }
107012605Sgiacomo.travaglini@arm.com          // Data TLB Invalidate All
10717408Sgblack@eecs.umich.edu          case MISCREG_DTLBIALL:
107212605Sgiacomo.travaglini@arm.com            {
107312605Sgiacomo.travaglini@arm.com                assert32(tc);
107412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
107512605Sgiacomo.travaglini@arm.com
107612605Sgiacomo.travaglini@arm.com                DTLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
107712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
107812605Sgiacomo.travaglini@arm.com                return;
107912605Sgiacomo.travaglini@arm.com            }
108012605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA
108112605Sgiacomo.travaglini@arm.com          // mcr tlbimval(is) is invalidating all matching entries
108212605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
108312605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
108412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVA:
108512576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAL:
108612605Sgiacomo.travaglini@arm.com            {
108712605Sgiacomo.travaglini@arm.com                assert32(tc);
108812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
108912605Sgiacomo.travaglini@arm.com
109012605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1,
109112605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
109212605Sgiacomo.travaglini@arm.com                               mbits(newVal, 31, 12),
109312605Sgiacomo.travaglini@arm.com                               bits(newVal, 7,0));
109412605Sgiacomo.travaglini@arm.com
109512605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
109612605Sgiacomo.travaglini@arm.com                return;
109712605Sgiacomo.travaglini@arm.com            }
109812605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, Inner Shareable
109912605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAIS:
110012576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVALIS:
110112605Sgiacomo.travaglini@arm.com            {
110212605Sgiacomo.travaglini@arm.com                assert32(tc);
110312605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
110412605Sgiacomo.travaglini@arm.com
110512605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1,
110612605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
110712605Sgiacomo.travaglini@arm.com                               mbits(newVal, 31, 12),
110812605Sgiacomo.travaglini@arm.com                               bits(newVal, 7,0));
110912605Sgiacomo.travaglini@arm.com
111012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
111112605Sgiacomo.travaglini@arm.com                return;
111212605Sgiacomo.travaglini@arm.com            }
111312605Sgiacomo.travaglini@arm.com          // TLB Invalidate by ASID match
111412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIASID:
111512605Sgiacomo.travaglini@arm.com            {
111612605Sgiacomo.travaglini@arm.com                assert32(tc);
111712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
111812605Sgiacomo.travaglini@arm.com
111912605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1,
112012605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
112112605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
112212605Sgiacomo.travaglini@arm.com
112312605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
112412605Sgiacomo.travaglini@arm.com                return;
112512605Sgiacomo.travaglini@arm.com            }
112612605Sgiacomo.travaglini@arm.com          // TLB Invalidate by ASID match, Inner Shareable
11277408Sgblack@eecs.umich.edu          case MISCREG_TLBIASIDIS:
112812605Sgiacomo.travaglini@arm.com            {
112912605Sgiacomo.travaglini@arm.com                assert32(tc);
113012605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
113112605Sgiacomo.travaglini@arm.com
113212605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1,
113312605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
113412605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
113512605Sgiacomo.travaglini@arm.com
113612605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
113712605Sgiacomo.travaglini@arm.com                return;
113812605Sgiacomo.travaglini@arm.com            }
113912605Sgiacomo.travaglini@arm.com          // mcr tlbimvaal(is) is invalidating all matching entries
114012605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
114112605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
114212605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, All ASID
114312605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAA:
114412576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAAL:
114512605Sgiacomo.travaglini@arm.com            {
114612605Sgiacomo.travaglini@arm.com                assert32(tc);
114712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
114812605Sgiacomo.travaglini@arm.com
114912605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
115012605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), false);
115112605Sgiacomo.travaglini@arm.com
115212605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
115312605Sgiacomo.travaglini@arm.com                return;
115412605Sgiacomo.travaglini@arm.com            }
115512605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, All ASID, Inner Shareable
115612605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAAIS:
115712576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAALIS:
115812605Sgiacomo.travaglini@arm.com            {
115912605Sgiacomo.travaglini@arm.com                assert32(tc);
116012605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
116112605Sgiacomo.travaglini@arm.com
116212605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
116312605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), false);
116412605Sgiacomo.travaglini@arm.com
116512605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
116612605Sgiacomo.travaglini@arm.com                return;
116712605Sgiacomo.travaglini@arm.com            }
116812605Sgiacomo.travaglini@arm.com          // mcr tlbimvalh(is) is invalidating all matching entries
116912605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
117012605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
117112605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, Hyp mode
117212605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAH:
117312576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVALH:
117412605Sgiacomo.travaglini@arm.com            {
117512605Sgiacomo.travaglini@arm.com                assert32(tc);
117612605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
117712605Sgiacomo.travaglini@arm.com
117812605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
117912605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), true);
118012605Sgiacomo.travaglini@arm.com
118112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
118212605Sgiacomo.travaglini@arm.com                return;
118312605Sgiacomo.travaglini@arm.com            }
118412605Sgiacomo.travaglini@arm.com          // TLB Invalidate by VA, Hyp mode, Inner Shareable
118512605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVAHIS:
118612576Sgiacomo.travaglini@arm.com          case MISCREG_TLBIMVALHIS:
118712605Sgiacomo.travaglini@arm.com            {
118812605Sgiacomo.travaglini@arm.com                assert32(tc);
118912605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
119012605Sgiacomo.travaglini@arm.com
119112605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
119212605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31,12), true);
119312605Sgiacomo.travaglini@arm.com
119412605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
119512605Sgiacomo.travaglini@arm.com                return;
119612605Sgiacomo.travaglini@arm.com            }
119712605Sgiacomo.travaglini@arm.com          // mcr tlbiipas2l(is) is invalidating all matching entries
119812605Sgiacomo.travaglini@arm.com          // regardless of the level of lookup, since in gem5 we cache
119912605Sgiacomo.travaglini@arm.com          // in the tlb the last level of lookup only.
120012605Sgiacomo.travaglini@arm.com          // TLB Invalidate by Intermediate Physical Address, Stage 2
120112605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2:
120212577Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2L:
120312605Sgiacomo.travaglini@arm.com            {
120412605Sgiacomo.travaglini@arm.com                assert32(tc);
120512605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
120612605Sgiacomo.travaglini@arm.com
120712605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1,
120812605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
120912605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
121012605Sgiacomo.travaglini@arm.com
121112605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
121212605Sgiacomo.travaglini@arm.com                return;
121312605Sgiacomo.travaglini@arm.com            }
121412605Sgiacomo.travaglini@arm.com          // TLB Invalidate by Intermediate Physical Address, Stage 2,
121512605Sgiacomo.travaglini@arm.com          // Inner Shareable
121612605Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2IS:
121712577Sgiacomo.travaglini@arm.com          case MISCREG_TLBIIPAS2LIS:
121812605Sgiacomo.travaglini@arm.com            {
121912605Sgiacomo.travaglini@arm.com                assert32(tc);
122012605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
122112605Sgiacomo.travaglini@arm.com
122212605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1,
122312605Sgiacomo.travaglini@arm.com                               haveSecurity && !scr.ns,
122412605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
122512605Sgiacomo.travaglini@arm.com
122612605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
122712605Sgiacomo.travaglini@arm.com                return;
122812605Sgiacomo.travaglini@arm.com            }
122912605Sgiacomo.travaglini@arm.com          // Instruction TLB Invalidate by VA
123010037SARM gem5 Developers          case MISCREG_ITLBIMVA:
123112605Sgiacomo.travaglini@arm.com            {
123212605Sgiacomo.travaglini@arm.com                assert32(tc);
123312605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
123412605Sgiacomo.travaglini@arm.com
123512605Sgiacomo.travaglini@arm.com                ITLBIMVA tlbiOp(EL1,
123612605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
123712605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31, 12),
123812605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
123912605Sgiacomo.travaglini@arm.com
124012605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
124112605Sgiacomo.travaglini@arm.com                return;
124212605Sgiacomo.travaglini@arm.com            }
124312605Sgiacomo.travaglini@arm.com          // Data TLB Invalidate by VA
124410037SARM gem5 Developers          case MISCREG_DTLBIMVA:
124512605Sgiacomo.travaglini@arm.com            {
124612605Sgiacomo.travaglini@arm.com                assert32(tc);
124712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
124812605Sgiacomo.travaglini@arm.com
124912605Sgiacomo.travaglini@arm.com                DTLBIMVA tlbiOp(EL1,
125012605Sgiacomo.travaglini@arm.com                                haveSecurity && !scr.ns,
125112605Sgiacomo.travaglini@arm.com                                mbits(newVal, 31, 12),
125212605Sgiacomo.travaglini@arm.com                                bits(newVal, 7,0));
125312605Sgiacomo.travaglini@arm.com
125412605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
125512605Sgiacomo.travaglini@arm.com                return;
125612605Sgiacomo.travaglini@arm.com            }
125712605Sgiacomo.travaglini@arm.com          // Instruction TLB Invalidate by ASID match
125810037SARM gem5 Developers          case MISCREG_ITLBIASID:
125912605Sgiacomo.travaglini@arm.com            {
126012605Sgiacomo.travaglini@arm.com                assert32(tc);
126112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
126212605Sgiacomo.travaglini@arm.com
126312605Sgiacomo.travaglini@arm.com                ITLBIASID tlbiOp(EL1,
126412605Sgiacomo.travaglini@arm.com                                 haveSecurity && !scr.ns,
126512605Sgiacomo.travaglini@arm.com                                 bits(newVal, 7,0));
126612605Sgiacomo.travaglini@arm.com
126712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
126812605Sgiacomo.travaglini@arm.com                return;
126912605Sgiacomo.travaglini@arm.com            }
127012605Sgiacomo.travaglini@arm.com          // Data TLB Invalidate by ASID match
127110037SARM gem5 Developers          case MISCREG_DTLBIASID:
127212605Sgiacomo.travaglini@arm.com            {
127312605Sgiacomo.travaglini@arm.com                assert32(tc);
127412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
127512605Sgiacomo.travaglini@arm.com
127612605Sgiacomo.travaglini@arm.com                DTLBIASID tlbiOp(EL1,
127712605Sgiacomo.travaglini@arm.com                                 haveSecurity && !scr.ns,
127812605Sgiacomo.travaglini@arm.com                                 bits(newVal, 7,0));
127912605Sgiacomo.travaglini@arm.com
128012605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
128112605Sgiacomo.travaglini@arm.com                return;
128212605Sgiacomo.travaglini@arm.com            }
128312605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Non-Secure Non-Hyp
128410037SARM gem5 Developers          case MISCREG_TLBIALLNSNH:
128512605Sgiacomo.travaglini@arm.com            {
128612605Sgiacomo.travaglini@arm.com                assert32(tc);
128712605Sgiacomo.travaglini@arm.com
128812605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, false);
128912605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
129012605Sgiacomo.travaglini@arm.com                return;
129112605Sgiacomo.travaglini@arm.com            }
129212605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Non-Secure Non-Hyp, Inner Shareable
129310037SARM gem5 Developers          case MISCREG_TLBIALLNSNHIS:
129412605Sgiacomo.travaglini@arm.com            {
129512605Sgiacomo.travaglini@arm.com                assert32(tc);
129612605Sgiacomo.travaglini@arm.com
129712605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, false);
129812605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
129912605Sgiacomo.travaglini@arm.com                return;
130012605Sgiacomo.travaglini@arm.com            }
130112605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Hyp mode
130210037SARM gem5 Developers          case MISCREG_TLBIALLH:
130312605Sgiacomo.travaglini@arm.com            {
130412605Sgiacomo.travaglini@arm.com                assert32(tc);
130512605Sgiacomo.travaglini@arm.com
130612605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, true);
130712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
130812605Sgiacomo.travaglini@arm.com                return;
130912605Sgiacomo.travaglini@arm.com            }
131012605Sgiacomo.travaglini@arm.com          // TLB Invalidate All, Hyp mode, Inner Shareable
131110037SARM gem5 Developers          case MISCREG_TLBIALLHIS:
131212605Sgiacomo.travaglini@arm.com            {
131312605Sgiacomo.travaglini@arm.com                assert32(tc);
131412605Sgiacomo.travaglini@arm.com
131512605Sgiacomo.travaglini@arm.com                TLBIALLN tlbiOp(EL1, true);
131612605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
131712605Sgiacomo.travaglini@arm.com                return;
131812605Sgiacomo.travaglini@arm.com            }
131912605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL3
132012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_ALLE3:
132112605Sgiacomo.travaglini@arm.com            {
132212605Sgiacomo.travaglini@arm.com                assert64(tc);
132312605Sgiacomo.travaglini@arm.com
132412605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL3, true);
132512605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
132612605Sgiacomo.travaglini@arm.com                return;
132712605Sgiacomo.travaglini@arm.com            }
132812605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL3, Inner Shareable
132910037SARM gem5 Developers          case MISCREG_TLBI_ALLE3IS:
133012605Sgiacomo.travaglini@arm.com            {
133112605Sgiacomo.travaglini@arm.com                assert64(tc);
133212605Sgiacomo.travaglini@arm.com
133312605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL3, true);
133412605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
133512605Sgiacomo.travaglini@arm.com                return;
133612605Sgiacomo.travaglini@arm.com            }
133713549Sanouk.vanlaer@arm.com          // AArch64 TLB Invalidate All, EL2, Inner Shareable
133813549Sanouk.vanlaer@arm.com          case MISCREG_TLBI_ALLE2:
133913549Sanouk.vanlaer@arm.com          case MISCREG_TLBI_ALLE2IS:
134013549Sanouk.vanlaer@arm.com            {
134113549Sanouk.vanlaer@arm.com                assert64(tc);
134213549Sanouk.vanlaer@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
134313549Sanouk.vanlaer@arm.com
134413549Sanouk.vanlaer@arm.com                TLBIALL tlbiOp(EL2, haveSecurity && !scr.ns);
134513549Sanouk.vanlaer@arm.com                tlbiOp(tc);
134613549Sanouk.vanlaer@arm.com                return;
134713549Sanouk.vanlaer@arm.com            }
134812605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL1
134910037SARM gem5 Developers          case MISCREG_TLBI_ALLE1:
135010037SARM gem5 Developers          case MISCREG_TLBI_VMALLE1:
135110037SARM gem5 Developers          case MISCREG_TLBI_VMALLS12E1:
135210037SARM gem5 Developers            // @todo: handle VMID and stage 2 to enable Virtualization
135312605Sgiacomo.travaglini@arm.com            {
135412605Sgiacomo.travaglini@arm.com                assert64(tc);
135512605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
135612605Sgiacomo.travaglini@arm.com
135712605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
135812605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
135912605Sgiacomo.travaglini@arm.com                return;
136012605Sgiacomo.travaglini@arm.com            }
136112605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate All, EL1, Inner Shareable
136212605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_ALLE1IS:
136312605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VMALLE1IS:
136412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VMALLS12E1IS:
136512605Sgiacomo.travaglini@arm.com            // @todo: handle VMID and stage 2 to enable Virtualization
136612605Sgiacomo.travaglini@arm.com            {
136712605Sgiacomo.travaglini@arm.com                assert64(tc);
136812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
136912605Sgiacomo.travaglini@arm.com
137012605Sgiacomo.travaglini@arm.com                TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns);
137112605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
137212605Sgiacomo.travaglini@arm.com                return;
137312605Sgiacomo.travaglini@arm.com            }
137412605Sgiacomo.travaglini@arm.com          // VAEx(IS) and VALEx(IS) are the same because TLBs
137512605Sgiacomo.travaglini@arm.com          // only store entries
137610037SARM gem5 Developers          // from the last level of translation table walks
137710037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
137812605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL3
137912605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAE3_Xt:
138012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VALE3_Xt:
138112605Sgiacomo.travaglini@arm.com            {
138212605Sgiacomo.travaglini@arm.com                assert64(tc);
138312605Sgiacomo.travaglini@arm.com
138412605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL3, true,
138512605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
138612605Sgiacomo.travaglini@arm.com                               0xbeef);
138712605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
138812605Sgiacomo.travaglini@arm.com                return;
138912605Sgiacomo.travaglini@arm.com            }
139012605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL3, Inner Shareable
139110037SARM gem5 Developers          case MISCREG_TLBI_VAE3IS_Xt:
139210037SARM gem5 Developers          case MISCREG_TLBI_VALE3IS_Xt:
139312605Sgiacomo.travaglini@arm.com            {
139412605Sgiacomo.travaglini@arm.com                assert64(tc);
139512605Sgiacomo.travaglini@arm.com
139612605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL3, true,
139712605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
139812605Sgiacomo.travaglini@arm.com                               0xbeef);
139912605Sgiacomo.travaglini@arm.com
140012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
140112605Sgiacomo.travaglini@arm.com                return;
140212605Sgiacomo.travaglini@arm.com            }
140312605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL2
140412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAE2_Xt:
140512605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VALE2_Xt:
140612605Sgiacomo.travaglini@arm.com            {
140712605Sgiacomo.travaglini@arm.com                assert64(tc);
140812605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
140912605Sgiacomo.travaglini@arm.com
141012605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
141112605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
141212605Sgiacomo.travaglini@arm.com                               0xbeef);
141312605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
141412605Sgiacomo.travaglini@arm.com                return;
141512605Sgiacomo.travaglini@arm.com            }
141612605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL2, Inner Shareable
141710037SARM gem5 Developers          case MISCREG_TLBI_VAE2IS_Xt:
141810037SARM gem5 Developers          case MISCREG_TLBI_VALE2IS_Xt:
141912605Sgiacomo.travaglini@arm.com            {
142012605Sgiacomo.travaglini@arm.com                assert64(tc);
142112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
142212605Sgiacomo.travaglini@arm.com
142312605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns,
142412605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
142512605Sgiacomo.travaglini@arm.com                               0xbeef);
142612605Sgiacomo.travaglini@arm.com
142712605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
142812605Sgiacomo.travaglini@arm.com                return;
142912605Sgiacomo.travaglini@arm.com            }
143012605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL1
143112605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAE1_Xt:
143212605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VALE1_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                TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
144012605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
144112605Sgiacomo.travaglini@arm.com                               asid);
144212605Sgiacomo.travaglini@arm.com
144312605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
144412605Sgiacomo.travaglini@arm.com                return;
144512605Sgiacomo.travaglini@arm.com            }
144612605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, EL1, Inner Shareable
144710037SARM gem5 Developers          case MISCREG_TLBI_VAE1IS_Xt:
144810037SARM gem5 Developers          case MISCREG_TLBI_VALE1IS_Xt:
144912605Sgiacomo.travaglini@arm.com            {
145012605Sgiacomo.travaglini@arm.com                assert64(tc);
145112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
145212605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
145312605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
145412605Sgiacomo.travaglini@arm.com
145512605Sgiacomo.travaglini@arm.com                TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns,
145612605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 43, 0)) << 12,
145712605Sgiacomo.travaglini@arm.com                               asid);
145812605Sgiacomo.travaglini@arm.com
145912605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
146012605Sgiacomo.travaglini@arm.com                return;
146112605Sgiacomo.travaglini@arm.com            }
146212605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by ASID, EL1
146310037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
146412605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_ASIDE1_Xt:
146512605Sgiacomo.travaglini@arm.com            {
146612605Sgiacomo.travaglini@arm.com                assert64(tc);
146712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
146812605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
146912605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
147012605Sgiacomo.travaglini@arm.com
147112605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
147212605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
147312605Sgiacomo.travaglini@arm.com                return;
147412605Sgiacomo.travaglini@arm.com            }
147512605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by ASID, EL1, Inner Shareable
147610037SARM gem5 Developers          case MISCREG_TLBI_ASIDE1IS_Xt:
147712605Sgiacomo.travaglini@arm.com            {
147812605Sgiacomo.travaglini@arm.com                assert64(tc);
147912605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
148012605Sgiacomo.travaglini@arm.com                auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) :
148112605Sgiacomo.travaglini@arm.com                                              bits(newVal, 55, 48);
148212605Sgiacomo.travaglini@arm.com
148312605Sgiacomo.travaglini@arm.com                TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid);
148412605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
148512605Sgiacomo.travaglini@arm.com                return;
148612605Sgiacomo.travaglini@arm.com            }
148710037SARM gem5 Developers          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
148810037SARM gem5 Developers          // entries from the last level of translation table walks
148912605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, All ASID, EL1
149012605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAAE1_Xt:
149112605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_VAALE1_Xt:
149212605Sgiacomo.travaglini@arm.com            {
149312605Sgiacomo.travaglini@arm.com                assert64(tc);
149412605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
149512605Sgiacomo.travaglini@arm.com
149612605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
149712605Sgiacomo.travaglini@arm.com                    static_cast<Addr>(bits(newVal, 43, 0)) << 12, false);
149812605Sgiacomo.travaglini@arm.com
149912605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
150012605Sgiacomo.travaglini@arm.com                return;
150112605Sgiacomo.travaglini@arm.com            }
150212605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by VA, All ASID, EL1, Inner Shareable
150310037SARM gem5 Developers          case MISCREG_TLBI_VAAE1IS_Xt:
150410037SARM gem5 Developers          case MISCREG_TLBI_VAALE1IS_Xt:
150512605Sgiacomo.travaglini@arm.com            {
150612605Sgiacomo.travaglini@arm.com                assert64(tc);
150712605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
150812605Sgiacomo.travaglini@arm.com
150912605Sgiacomo.travaglini@arm.com                TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns,
151012605Sgiacomo.travaglini@arm.com                    static_cast<Addr>(bits(newVal, 43, 0)) << 12, false);
151112605Sgiacomo.travaglini@arm.com
151212605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
151312605Sgiacomo.travaglini@arm.com                return;
151412605Sgiacomo.travaglini@arm.com            }
151512605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by Intermediate Physical Address,
151612605Sgiacomo.travaglini@arm.com          // Stage 2, EL1
151712605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_IPAS2E1_Xt:
151812605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_IPAS2LE1_Xt:
151912605Sgiacomo.travaglini@arm.com            {
152012605Sgiacomo.travaglini@arm.com                assert64(tc);
152112605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
152212605Sgiacomo.travaglini@arm.com
152312605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
152412605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
152512605Sgiacomo.travaglini@arm.com
152612605Sgiacomo.travaglini@arm.com                tlbiOp(tc);
152712605Sgiacomo.travaglini@arm.com                return;
152812605Sgiacomo.travaglini@arm.com            }
152912605Sgiacomo.travaglini@arm.com          // AArch64 TLB Invalidate by Intermediate Physical Address,
153012605Sgiacomo.travaglini@arm.com          // Stage 2, EL1, Inner Shareable
153112605Sgiacomo.travaglini@arm.com          case MISCREG_TLBI_IPAS2E1IS_Xt:
153210037SARM gem5 Developers          case MISCREG_TLBI_IPAS2LE1IS_Xt:
153312605Sgiacomo.travaglini@arm.com            {
153412605Sgiacomo.travaglini@arm.com                assert64(tc);
153512605Sgiacomo.travaglini@arm.com                scr = readMiscReg(MISCREG_SCR, tc);
153612605Sgiacomo.travaglini@arm.com
153712605Sgiacomo.travaglini@arm.com                TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns,
153812605Sgiacomo.travaglini@arm.com                               static_cast<Addr>(bits(newVal, 35, 0)) << 12);
153912605Sgiacomo.travaglini@arm.com
154012605Sgiacomo.travaglini@arm.com                tlbiOp.broadcast(tc);
154112605Sgiacomo.travaglini@arm.com                return;
154212605Sgiacomo.travaglini@arm.com            }
15437583SAli.Saidi@arm.com          case MISCREG_ACTLR:
15447583SAli.Saidi@arm.com            warn("Not doing anything for write of miscreg ACTLR\n");
15457583SAli.Saidi@arm.com            break;
154610461SAndreas.Sandberg@ARM.com
154710461SAndreas.Sandberg@ARM.com          case MISCREG_PMXEVTYPER_PMCCFILTR:
154810461SAndreas.Sandberg@ARM.com          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
154910461SAndreas.Sandberg@ARM.com          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
155010461SAndreas.Sandberg@ARM.com          case MISCREG_PMCR ... MISCREG_PMOVSSET:
155110461SAndreas.Sandberg@ARM.com            pmu->setMiscReg(misc_reg, newVal);
15527583SAli.Saidi@arm.com            break;
155310461SAndreas.Sandberg@ARM.com
155410461SAndreas.Sandberg@ARM.com
155510037SARM gem5 Developers          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
155610037SARM gem5 Developers            {
155710037SARM gem5 Developers                HSTR hstrMask = 0;
155810037SARM gem5 Developers                hstrMask.tjdbx = 1;
155910037SARM gem5 Developers                newVal &= ~((uint32_t) hstrMask);
156010037SARM gem5 Developers                break;
156110037SARM gem5 Developers            }
156210037SARM gem5 Developers          case MISCREG_HCPTR:
156310037SARM gem5 Developers            {
156410037SARM gem5 Developers                // If a CP bit in NSACR is 0 then the corresponding bit in
156510037SARM gem5 Developers                // HCPTR is RAO/WI. Same applies to NSASEDIS
156610037SARM gem5 Developers                secure_lookup = haveSecurity &&
156710037SARM gem5 Developers                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
156810037SARM gem5 Developers                                  readMiscRegNoEffect(MISCREG_CPSR));
156910037SARM gem5 Developers                if (!secure_lookup) {
157013581Sgabeblack@google.com                    RegVal oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
157113581Sgabeblack@google.com                    RegVal mask =
157213581Sgabeblack@google.com                        (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
157310037SARM gem5 Developers                    newVal = (newVal & ~mask) | (oldValue & mask);
157410037SARM gem5 Developers                }
157510037SARM gem5 Developers                break;
157610037SARM gem5 Developers            }
157710037SARM gem5 Developers          case MISCREG_HDFAR: // alias for secure DFAR
157810037SARM gem5 Developers            misc_reg = MISCREG_DFAR_S;
157910037SARM gem5 Developers            break;
158010037SARM gem5 Developers          case MISCREG_HIFAR: // alias for secure IFAR
158110037SARM gem5 Developers            misc_reg = MISCREG_IFAR_S;
158210037SARM gem5 Developers            break;
158310037SARM gem5 Developers          case MISCREG_ATS1CPR:
158410037SARM gem5 Developers          case MISCREG_ATS1CPW:
158510037SARM gem5 Developers          case MISCREG_ATS1CUR:
158610037SARM gem5 Developers          case MISCREG_ATS1CUW:
158710037SARM gem5 Developers          case MISCREG_ATS12NSOPR:
158810037SARM gem5 Developers          case MISCREG_ATS12NSOPW:
158910037SARM gem5 Developers          case MISCREG_ATS12NSOUR:
159010037SARM gem5 Developers          case MISCREG_ATS12NSOUW:
159110037SARM gem5 Developers          case MISCREG_ATS1HR:
159210037SARM gem5 Developers          case MISCREG_ATS1HW:
15937436Sdam.sunwoo@arm.com            {
159411608Snikos.nikoleris@arm.com              Request::Flags flags = 0;
159510037SARM gem5 Developers              BaseTLB::Mode mode = BaseTLB::Read;
159610037SARM gem5 Developers              TLB::ArmTranslationType tranType = TLB::NormalTran;
15977436Sdam.sunwoo@arm.com              Fault fault;
15987436Sdam.sunwoo@arm.com              switch(misc_reg) {
159910037SARM gem5 Developers                case MISCREG_ATS1CPR:
160010037SARM gem5 Developers                  flags    = TLB::MustBeOne;
160110037SARM gem5 Developers                  tranType = TLB::S1CTran;
160210037SARM gem5 Developers                  mode     = BaseTLB::Read;
160310037SARM gem5 Developers                  break;
160410037SARM gem5 Developers                case MISCREG_ATS1CPW:
160510037SARM gem5 Developers                  flags    = TLB::MustBeOne;
160610037SARM gem5 Developers                  tranType = TLB::S1CTran;
160710037SARM gem5 Developers                  mode     = BaseTLB::Write;
160810037SARM gem5 Developers                  break;
160910037SARM gem5 Developers                case MISCREG_ATS1CUR:
161010037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
161110037SARM gem5 Developers                  tranType = TLB::S1CTran;
161210037SARM gem5 Developers                  mode     = BaseTLB::Read;
161310037SARM gem5 Developers                  break;
161410037SARM gem5 Developers                case MISCREG_ATS1CUW:
161510037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
161610037SARM gem5 Developers                  tranType = TLB::S1CTran;
161710037SARM gem5 Developers                  mode     = BaseTLB::Write;
161810037SARM gem5 Developers                  break;
161910037SARM gem5 Developers                case MISCREG_ATS12NSOPR:
162010037SARM gem5 Developers                  if (!haveSecurity)
162110037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPR");
162210037SARM gem5 Developers                  flags    = TLB::MustBeOne;
162310037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
162410037SARM gem5 Developers                  mode     = BaseTLB::Read;
162510037SARM gem5 Developers                  break;
162610037SARM gem5 Developers                case MISCREG_ATS12NSOPW:
162710037SARM gem5 Developers                  if (!haveSecurity)
162810037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPW");
162910037SARM gem5 Developers                  flags    = TLB::MustBeOne;
163010037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
163110037SARM gem5 Developers                  mode     = BaseTLB::Write;
163210037SARM gem5 Developers                  break;
163310037SARM gem5 Developers                case MISCREG_ATS12NSOUR:
163410037SARM gem5 Developers                  if (!haveSecurity)
163510037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUR");
163610037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
163710037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
163810037SARM gem5 Developers                  mode     = BaseTLB::Read;
163910037SARM gem5 Developers                  break;
164010037SARM gem5 Developers                case MISCREG_ATS12NSOUW:
164110037SARM gem5 Developers                  if (!haveSecurity)
164210037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUW");
164310037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
164410037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
164510037SARM gem5 Developers                  mode     = BaseTLB::Write;
164610037SARM gem5 Developers                  break;
164710037SARM gem5 Developers                case MISCREG_ATS1HR: // only really useful from secure mode.
164810037SARM gem5 Developers                  flags    = TLB::MustBeOne;
164910037SARM gem5 Developers                  tranType = TLB::HypMode;
165010037SARM gem5 Developers                  mode     = BaseTLB::Read;
165110037SARM gem5 Developers                  break;
165210037SARM gem5 Developers                case MISCREG_ATS1HW:
165310037SARM gem5 Developers                  flags    = TLB::MustBeOne;
165410037SARM gem5 Developers                  tranType = TLB::HypMode;
165510037SARM gem5 Developers                  mode     = BaseTLB::Write;
165610037SARM gem5 Developers                  break;
16577436Sdam.sunwoo@arm.com              }
165810037SARM gem5 Developers              // If we're in timing mode then doing the translation in
165910037SARM gem5 Developers              // functional mode then we're slightly distorting performance
166010037SARM gem5 Developers              // results obtained from simulations. The translation should be
166110037SARM gem5 Developers              // done in the same mode the core is running in. NOTE: This
166210037SARM gem5 Developers              // can't be an atomic translation because that causes problems
166310037SARM gem5 Developers              // with unexpected atomic snoop requests.
166413417Sgiacomo.travaglini@arm.com              warn("Translating via %s in functional mode! Fix Me!\n",
166513417Sgiacomo.travaglini@arm.com                   miscRegName[misc_reg]);
166612749Sgiacomo.travaglini@arm.com
166712749Sgiacomo.travaglini@arm.com              auto req = std::make_shared<Request>(
166812749Sgiacomo.travaglini@arm.com                  0, val, 0, flags,  Request::funcMasterId,
166912749Sgiacomo.travaglini@arm.com                  tc->pcState().pc(), tc->contextId());
167012749Sgiacomo.travaglini@arm.com
167112406Sgabeblack@google.com              fault = getDTBPtr(tc)->translateFunctional(
167212749Sgiacomo.travaglini@arm.com                      req, tc, mode, tranType);
167312749Sgiacomo.travaglini@arm.com
167410037SARM gem5 Developers              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
167510037SARM gem5 Developers              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
167610037SARM gem5 Developers
167713581Sgabeblack@google.com              RegVal newVal;
16787436Sdam.sunwoo@arm.com              if (fault == NoFault) {
167912749Sgiacomo.travaglini@arm.com                  Addr paddr = req->getPaddr();
168010037SARM gem5 Developers                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
168110037SARM gem5 Developers                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
168210037SARM gem5 Developers                      newVal = (paddr & mask(39, 12)) |
168312406Sgabeblack@google.com                               (getDTBPtr(tc)->getAttr());
168410037SARM gem5 Developers                  } else {
168510037SARM gem5 Developers                      newVal = (paddr & 0xfffff000) |
168612406Sgabeblack@google.com                               (getDTBPtr(tc)->getAttr());
168710037SARM gem5 Developers                  }
16887436Sdam.sunwoo@arm.com                  DPRINTF(MiscRegs,
16897436Sdam.sunwoo@arm.com                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
169010037SARM gem5 Developers                          val, newVal);
169110037SARM gem5 Developers              } else {
169212524Sgiacomo.travaglini@arm.com                  ArmFault *armFault = static_cast<ArmFault *>(fault.get());
169312570Sgiacomo.travaglini@arm.com                  armFault->update(tc);
169410037SARM gem5 Developers                  // Set fault bit and FSR
169510037SARM gem5 Developers                  FSR fsr = armFault->getFsr(tc);
169610037SARM gem5 Developers
169710037SARM gem5 Developers                  newVal = ((fsr >> 9) & 1) << 11;
169810037SARM gem5 Developers                  if (newVal) {
169910037SARM gem5 Developers                    // LPAE - rearange fault status
170010037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0x3f) << 1;
170110037SARM gem5 Developers                  } else {
170210037SARM gem5 Developers                    // VMSA - rearange fault status
170310037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0xf) << 1;
170410037SARM gem5 Developers                    newVal |= ((fsr >> 10) & 0x1) << 5;
170510037SARM gem5 Developers                    newVal |= ((fsr >> 12) & 0x1) << 6;
170610037SARM gem5 Developers                  }
170710037SARM gem5 Developers                  newVal |= 0x1; // F bit
170810037SARM gem5 Developers                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
170910037SARM gem5 Developers                  newVal |= armFault->isStage2() ? 0x200 : 0;
171010037SARM gem5 Developers                  DPRINTF(MiscRegs,
171110037SARM gem5 Developers                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
171210037SARM gem5 Developers                          val, fsr, newVal);
17137436Sdam.sunwoo@arm.com              }
171410037SARM gem5 Developers              setMiscRegNoEffect(MISCREG_PAR, newVal);
17157436Sdam.sunwoo@arm.com              return;
17167436Sdam.sunwoo@arm.com            }
171710037SARM gem5 Developers          case MISCREG_TTBCR:
171810037SARM gem5 Developers            {
171910037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
172010037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
172110037SARM gem5 Developers                TTBCR ttbcrMask = 0;
172210037SARM gem5 Developers                TTBCR ttbcrNew = newVal;
172310037SARM gem5 Developers
172410037SARM gem5 Developers                // ARM DDI 0406C.b, ARMv7-32
172510037SARM gem5 Developers                ttbcrMask.n = ones; // T0SZ
172610037SARM gem5 Developers                if (haveSecurity) {
172710037SARM gem5 Developers                    ttbcrMask.pd0 = ones;
172810037SARM gem5 Developers                    ttbcrMask.pd1 = ones;
172910037SARM gem5 Developers                }
173010037SARM gem5 Developers                ttbcrMask.epd0 = ones;
173110037SARM gem5 Developers                ttbcrMask.irgn0 = ones;
173210037SARM gem5 Developers                ttbcrMask.orgn0 = ones;
173310037SARM gem5 Developers                ttbcrMask.sh0 = ones;
173410037SARM gem5 Developers                ttbcrMask.ps = ones; // T1SZ
173510037SARM gem5 Developers                ttbcrMask.a1 = ones;
173610037SARM gem5 Developers                ttbcrMask.epd1 = ones;
173710037SARM gem5 Developers                ttbcrMask.irgn1 = ones;
173810037SARM gem5 Developers                ttbcrMask.orgn1 = ones;
173910037SARM gem5 Developers                ttbcrMask.sh1 = ones;
174010037SARM gem5 Developers                if (haveLPAE)
174110037SARM gem5 Developers                    ttbcrMask.eae = ones;
174210037SARM gem5 Developers
174310037SARM gem5 Developers                if (haveLPAE && ttbcrNew.eae) {
174410037SARM gem5 Developers                    newVal = newVal & ttbcrMask;
174510037SARM gem5 Developers                } else {
174610037SARM gem5 Developers                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
174710037SARM gem5 Developers                }
174812666Sgiacomo.travaglini@arm.com                // Invalidate TLB MiscReg
174912666Sgiacomo.travaglini@arm.com                getITBPtr(tc)->invalidateMiscReg();
175012666Sgiacomo.travaglini@arm.com                getDTBPtr(tc)->invalidateMiscReg();
175112666Sgiacomo.travaglini@arm.com                break;
175210037SARM gem5 Developers            }
175310037SARM gem5 Developers          case MISCREG_TTBR0:
175410037SARM gem5 Developers          case MISCREG_TTBR1:
175510037SARM gem5 Developers            {
175610037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
175710037SARM gem5 Developers                if (haveLPAE) {
175810037SARM gem5 Developers                    if (ttbcr.eae) {
175910037SARM gem5 Developers                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
176010037SARM gem5 Developers                        // ARMv8 AArch32 bit 63-56 only
176110037SARM gem5 Developers                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
176210037SARM gem5 Developers                        newVal = (newVal & (~ttbrMask));
176310037SARM gem5 Developers                    }
176410037SARM gem5 Developers                }
176512666Sgiacomo.travaglini@arm.com                // Invalidate TLB MiscReg
176612406Sgabeblack@google.com                getITBPtr(tc)->invalidateMiscReg();
176712406Sgabeblack@google.com                getDTBPtr(tc)->invalidateMiscReg();
176812666Sgiacomo.travaglini@arm.com                break;
176910508SAli.Saidi@ARM.com            }
177012666Sgiacomo.travaglini@arm.com          case MISCREG_SCTLR_EL1:
17717749SAli.Saidi@ARM.com          case MISCREG_CONTEXTIDR:
17727749SAli.Saidi@ARM.com          case MISCREG_PRRR:
17737749SAli.Saidi@ARM.com          case MISCREG_NMRR:
177410037SARM gem5 Developers          case MISCREG_MAIR0:
177510037SARM gem5 Developers          case MISCREG_MAIR1:
17767749SAli.Saidi@ARM.com          case MISCREG_DACR:
177710037SARM gem5 Developers          case MISCREG_VTTBR:
177810037SARM gem5 Developers          case MISCREG_SCR_EL3:
177911575SDylan.Johnson@ARM.com          case MISCREG_HCR_EL2:
178010037SARM gem5 Developers          case MISCREG_TCR_EL1:
178110037SARM gem5 Developers          case MISCREG_TCR_EL2:
178210037SARM gem5 Developers          case MISCREG_TCR_EL3:
178310508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL2:
178410508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL3:
178511573SDylan.Johnson@ARM.com          case MISCREG_HSCTLR:
178610037SARM gem5 Developers          case MISCREG_TTBR0_EL1:
178710037SARM gem5 Developers          case MISCREG_TTBR1_EL1:
178810037SARM gem5 Developers          case MISCREG_TTBR0_EL2:
178912675Sgiacomo.travaglini@arm.com          case MISCREG_TTBR1_EL2:
179010037SARM gem5 Developers          case MISCREG_TTBR0_EL3:
179112406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
179212406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
17937749SAli.Saidi@ARM.com            break;
179410037SARM gem5 Developers          case MISCREG_NZCV:
179510037SARM gem5 Developers            {
179610037SARM gem5 Developers                CPSR cpsr = val;
179710037SARM gem5 Developers
179810338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_NZ, cpsr.nz);
179910338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_C,  cpsr.c);
180010338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_V,  cpsr.v);
180110037SARM gem5 Developers            }
180210037SARM gem5 Developers            break;
180310037SARM gem5 Developers          case MISCREG_DAIF:
180410037SARM gem5 Developers            {
180510037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
180610037SARM gem5 Developers                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
180710037SARM gem5 Developers                newVal = cpsr;
180810037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
180910037SARM gem5 Developers            }
181010037SARM gem5 Developers            break;
181110037SARM gem5 Developers          case MISCREG_SP_EL0:
181210037SARM gem5 Developers            tc->setIntReg(INTREG_SP0, newVal);
181310037SARM gem5 Developers            break;
181410037SARM gem5 Developers          case MISCREG_SP_EL1:
181510037SARM gem5 Developers            tc->setIntReg(INTREG_SP1, newVal);
181610037SARM gem5 Developers            break;
181710037SARM gem5 Developers          case MISCREG_SP_EL2:
181810037SARM gem5 Developers            tc->setIntReg(INTREG_SP2, newVal);
181910037SARM gem5 Developers            break;
182010037SARM gem5 Developers          case MISCREG_SPSEL:
182110037SARM gem5 Developers            {
182210037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
182310037SARM gem5 Developers                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
182410037SARM gem5 Developers                newVal = cpsr;
182510037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
182610037SARM gem5 Developers            }
182710037SARM gem5 Developers            break;
182810037SARM gem5 Developers          case MISCREG_CURRENTEL:
182910037SARM gem5 Developers            {
183010037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
183110037SARM gem5 Developers                cpsr.el = (uint8_t) ((CPSR) newVal).el;
183210037SARM gem5 Developers                newVal = cpsr;
183310037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
183410037SARM gem5 Developers            }
183510037SARM gem5 Developers            break;
183610037SARM gem5 Developers          case MISCREG_AT_S1E1R_Xt:
183710037SARM gem5 Developers          case MISCREG_AT_S1E1W_Xt:
183810037SARM gem5 Developers          case MISCREG_AT_S1E0R_Xt:
183910037SARM gem5 Developers          case MISCREG_AT_S1E0W_Xt:
184010037SARM gem5 Developers          case MISCREG_AT_S1E2R_Xt:
184110037SARM gem5 Developers          case MISCREG_AT_S1E2W_Xt:
184210037SARM gem5 Developers          case MISCREG_AT_S12E1R_Xt:
184310037SARM gem5 Developers          case MISCREG_AT_S12E1W_Xt:
184410037SARM gem5 Developers          case MISCREG_AT_S12E0R_Xt:
184510037SARM gem5 Developers          case MISCREG_AT_S12E0W_Xt:
184610037SARM gem5 Developers          case MISCREG_AT_S1E3R_Xt:
184710037SARM gem5 Developers          case MISCREG_AT_S1E3W_Xt:
184810037SARM gem5 Developers            {
184912749Sgiacomo.travaglini@arm.com                RequestPtr req = std::make_shared<Request>();
185011608Snikos.nikoleris@arm.com                Request::Flags flags = 0;
185110037SARM gem5 Developers                BaseTLB::Mode mode = BaseTLB::Read;
185210037SARM gem5 Developers                TLB::ArmTranslationType tranType = TLB::NormalTran;
185310037SARM gem5 Developers                Fault fault;
185410037SARM gem5 Developers                switch(misc_reg) {
185510037SARM gem5 Developers                  case MISCREG_AT_S1E1R_Xt:
185610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
185711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
185810037SARM gem5 Developers                    mode     = BaseTLB::Read;
185910037SARM gem5 Developers                    break;
186010037SARM gem5 Developers                  case MISCREG_AT_S1E1W_Xt:
186110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
186211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
186310037SARM gem5 Developers                    mode     = BaseTLB::Write;
186410037SARM gem5 Developers                    break;
186510037SARM gem5 Developers                  case MISCREG_AT_S1E0R_Xt:
186610037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
186711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
186810037SARM gem5 Developers                    mode     = BaseTLB::Read;
186910037SARM gem5 Developers                    break;
187010037SARM gem5 Developers                  case MISCREG_AT_S1E0W_Xt:
187110037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
187211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
187310037SARM gem5 Developers                    mode     = BaseTLB::Write;
187410037SARM gem5 Developers                    break;
187510037SARM gem5 Developers                  case MISCREG_AT_S1E2R_Xt:
187610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
187711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
187810037SARM gem5 Developers                    mode     = BaseTLB::Read;
187910037SARM gem5 Developers                    break;
188010037SARM gem5 Developers                  case MISCREG_AT_S1E2W_Xt:
188110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
188211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
188310037SARM gem5 Developers                    mode     = BaseTLB::Write;
188410037SARM gem5 Developers                    break;
188510037SARM gem5 Developers                  case MISCREG_AT_S12E0R_Xt:
188610037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
188711577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
188810037SARM gem5 Developers                    mode     = BaseTLB::Read;
188910037SARM gem5 Developers                    break;
189010037SARM gem5 Developers                  case MISCREG_AT_S12E0W_Xt:
189110037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
189211577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
189310037SARM gem5 Developers                    mode     = BaseTLB::Write;
189410037SARM gem5 Developers                    break;
189510037SARM gem5 Developers                  case MISCREG_AT_S12E1R_Xt:
189610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
189711577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
189810037SARM gem5 Developers                    mode     = BaseTLB::Read;
189910037SARM gem5 Developers                    break;
190010037SARM gem5 Developers                  case MISCREG_AT_S12E1W_Xt:
190110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
190211577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
190310037SARM gem5 Developers                    mode     = BaseTLB::Write;
190410037SARM gem5 Developers                    break;
190510037SARM gem5 Developers                  case MISCREG_AT_S1E3R_Xt:
190610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
190711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
190810037SARM gem5 Developers                    mode     = BaseTLB::Read;
190910037SARM gem5 Developers                    break;
191010037SARM gem5 Developers                  case MISCREG_AT_S1E3W_Xt:
191110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
191211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
191310037SARM gem5 Developers                    mode     = BaseTLB::Write;
191410037SARM gem5 Developers                    break;
191510037SARM gem5 Developers                }
191610037SARM gem5 Developers                // If we're in timing mode then doing the translation in
191710037SARM gem5 Developers                // functional mode then we're slightly distorting performance
191810037SARM gem5 Developers                // results obtained from simulations. The translation should be
191910037SARM gem5 Developers                // done in the same mode the core is running in. NOTE: This
192010037SARM gem5 Developers                // can't be an atomic translation because that causes problems
192110037SARM gem5 Developers                // with unexpected atomic snoop requests.
192213417Sgiacomo.travaglini@arm.com                warn("Translating via %s in functional mode! Fix Me!\n",
192313417Sgiacomo.travaglini@arm.com                     miscRegName[misc_reg]);
192413417Sgiacomo.travaglini@arm.com
192511560Sandreas.sandberg@arm.com                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
192610037SARM gem5 Developers                               tc->pcState().pc());
192711435Smitch.hayenga@arm.com                req->setContext(tc->contextId());
192812406Sgabeblack@google.com                fault = getDTBPtr(tc)->translateFunctional(req, tc, mode,
192912406Sgabeblack@google.com                                                           tranType);
193010037SARM gem5 Developers
193113581Sgabeblack@google.com                RegVal newVal;
193210037SARM gem5 Developers                if (fault == NoFault) {
193310037SARM gem5 Developers                    Addr paddr = req->getPaddr();
193412406Sgabeblack@google.com                    uint64_t attr = getDTBPtr(tc)->getAttr();
193510037SARM gem5 Developers                    uint64_t attr1 = attr >> 56;
193610037SARM gem5 Developers                    if (!attr1 || attr1 ==0x44) {
193710037SARM gem5 Developers                        attr |= 0x100;
193810037SARM gem5 Developers                        attr &= ~ uint64_t(0x80);
193910037SARM gem5 Developers                    }
194010037SARM gem5 Developers                    newVal = (paddr & mask(47, 12)) | attr;
194110037SARM gem5 Developers                    DPRINTF(MiscRegs,
194210037SARM gem5 Developers                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
194310037SARM gem5 Developers                          val, newVal);
194410037SARM gem5 Developers                } else {
194512524Sgiacomo.travaglini@arm.com                    ArmFault *armFault = static_cast<ArmFault *>(fault.get());
194612570Sgiacomo.travaglini@arm.com                    armFault->update(tc);
194710037SARM gem5 Developers                    // Set fault bit and FSR
194810037SARM gem5 Developers                    FSR fsr = armFault->getFsr(tc);
194910037SARM gem5 Developers
195011577SDylan.Johnson@ARM.com                    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
195111577SDylan.Johnson@ARM.com                    if (cpsr.width) { // AArch32
195211577SDylan.Johnson@ARM.com                        newVal = ((fsr >> 9) & 1) << 11;
195311577SDylan.Johnson@ARM.com                        // rearrange fault status
195411577SDylan.Johnson@ARM.com                        newVal |= ((fsr >>  0) & 0x3f) << 1;
195511577SDylan.Johnson@ARM.com                        newVal |= 0x1; // F bit
195611577SDylan.Johnson@ARM.com                        newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
195711577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 0x200 : 0;
195811577SDylan.Johnson@ARM.com                    } else { // AArch64
195911577SDylan.Johnson@ARM.com                        newVal = 1; // F bit
196011577SDylan.Johnson@ARM.com                        newVal |= fsr << 1; // FST
196111577SDylan.Johnson@ARM.com                        // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
196211577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
196311577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
196411577SDylan.Johnson@ARM.com                        newVal |= 1 << 11; // RES1
196511577SDylan.Johnson@ARM.com                    }
196610037SARM gem5 Developers                    DPRINTF(MiscRegs,
196710037SARM gem5 Developers                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
196810037SARM gem5 Developers                            val, fsr, newVal);
196910037SARM gem5 Developers                }
197010037SARM gem5 Developers                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
197110037SARM gem5 Developers                return;
197210037SARM gem5 Developers            }
197310037SARM gem5 Developers          case MISCREG_SPSR_EL3:
197410037SARM gem5 Developers          case MISCREG_SPSR_EL2:
197510037SARM gem5 Developers          case MISCREG_SPSR_EL1:
197610037SARM gem5 Developers            // Force bits 23:21 to 0
197710037SARM gem5 Developers            newVal = val & ~(0x7 << 21);
197810037SARM gem5 Developers            break;
19798549Sdaniel.johnson@arm.com          case MISCREG_L2CTLR:
19808549Sdaniel.johnson@arm.com            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
19818549Sdaniel.johnson@arm.com                 miscRegName[misc_reg], uint32_t(val));
198210037SARM gem5 Developers            break;
198310037SARM gem5 Developers
198410037SARM gem5 Developers          // Generic Timer registers
198512816Sgiacomo.travaglini@arm.com          case MISCREG_CNTHV_CTL_EL2:
198612816Sgiacomo.travaglini@arm.com          case MISCREG_CNTHV_CVAL_EL2:
198712816Sgiacomo.travaglini@arm.com          case MISCREG_CNTHV_TVAL_EL2:
198810844Sandreas.sandberg@arm.com          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
198910844Sandreas.sandberg@arm.com          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
199010844Sandreas.sandberg@arm.com          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
199110844Sandreas.sandberg@arm.com          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
199210844Sandreas.sandberg@arm.com            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
199310037SARM gem5 Developers            break;
199413531Sjairo.balart@metempsy.com
199513531Sjairo.balart@metempsy.com          case MISCREG_ICC_PMR_EL1 ... MISCREG_ICC_IGRPEN1_EL3:
199613531Sjairo.balart@metempsy.com          case MISCREG_ICH_AP0R0_EL2 ... MISCREG_ICH_LR15_EL2:
199713531Sjairo.balart@metempsy.com            getGICv3CPUInterface(tc).setMiscReg(misc_reg, newVal);
199813531Sjairo.balart@metempsy.com            return;
19997405SAli.Saidi@ARM.com        }
20007405SAli.Saidi@ARM.com    }
20017405SAli.Saidi@ARM.com    setMiscRegNoEffect(misc_reg, newVal);
20027405SAli.Saidi@ARM.com}
20037405SAli.Saidi@ARM.com
200410844Sandreas.sandberg@arm.comBaseISADevice &
200510844Sandreas.sandberg@arm.comISA::getGenericTimer(ThreadContext *tc)
200610037SARM gem5 Developers{
200710844Sandreas.sandberg@arm.com    // We only need to create an ISA interface the first time we try
200810844Sandreas.sandberg@arm.com    // to access the timer.
200910844Sandreas.sandberg@arm.com    if (timer)
201010844Sandreas.sandberg@arm.com        return *timer.get();
201110844Sandreas.sandberg@arm.com
201210844Sandreas.sandberg@arm.com    assert(system);
201310844Sandreas.sandberg@arm.com    GenericTimer *generic_timer(system->getGenericTimer());
201410844Sandreas.sandberg@arm.com    if (!generic_timer) {
201510844Sandreas.sandberg@arm.com        panic("Trying to get a generic timer from a system that hasn't "
201610844Sandreas.sandberg@arm.com              "been configured to use a generic timer.\n");
201710037SARM gem5 Developers    }
201810037SARM gem5 Developers
201911150Smitch.hayenga@arm.com    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
202012972Sandreas.sandberg@arm.com    timer->setThreadContext(tc);
202112972Sandreas.sandberg@arm.com
202210844Sandreas.sandberg@arm.com    return *timer.get();
202310037SARM gem5 Developers}
202410037SARM gem5 Developers
202513531Sjairo.balart@metempsy.comBaseISADevice &
202613531Sjairo.balart@metempsy.comISA::getGICv3CPUInterface(ThreadContext *tc)
202713531Sjairo.balart@metempsy.com{
202813531Sjairo.balart@metempsy.com    panic_if(!gicv3CpuInterface, "GICV3 cpu interface is not registered!");
202913531Sjairo.balart@metempsy.com    return *gicv3CpuInterface.get();
203013531Sjairo.balart@metempsy.com}
203113531Sjairo.balart@metempsy.com
20327405SAli.Saidi@ARM.com}
20339384SAndreas.Sandberg@arm.com
20349384SAndreas.Sandberg@arm.comArmISA::ISA *
20359384SAndreas.Sandberg@arm.comArmISAParams::create()
20369384SAndreas.Sandberg@arm.com{
20379384SAndreas.Sandberg@arm.com    return new ArmISA::ISA(this);
20389384SAndreas.Sandberg@arm.com}
2039