isa.cc revision 12576:e55d2103ccac
16242Sgblack@eecs.umich.edu/*
28868SMatt.Horsnell@arm.com * Copyright (c) 2010-2016 ARM Limited
37093Sgblack@eecs.umich.edu * All rights reserved
47093Sgblack@eecs.umich.edu *
57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97093Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137093Sgblack@eecs.umich.edu *
146242Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
156242Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
166242Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
176242Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
186242Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
196242Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
206242Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
216242Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
226242Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
236242Sgblack@eecs.umich.edu * this software without specific prior written permission.
246242Sgblack@eecs.umich.edu *
256242Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
266242Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
276242Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
286242Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
296242Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
306242Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
316242Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
326242Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
336242Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
346242Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
356242Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
366242Sgblack@eecs.umich.edu *
376242Sgblack@eecs.umich.edu * Authors: Gabe Black
386242Sgblack@eecs.umich.edu *          Ali Saidi
396242Sgblack@eecs.umich.edu */
406242Sgblack@eecs.umich.edu
416242Sgblack@eecs.umich.edu#include "arch/arm/isa.hh"
426242Sgblack@eecs.umich.edu#include "arch/arm/pmu.hh"
436242Sgblack@eecs.umich.edu#include "arch/arm/system.hh"
446242Sgblack@eecs.umich.edu#include "arch/arm/tlb.hh"
456242Sgblack@eecs.umich.edu#include "cpu/base.hh"
466242Sgblack@eecs.umich.edu#include "cpu/checker/cpu.hh"
476242Sgblack@eecs.umich.edu#include "debug/Arm.hh"
486242Sgblack@eecs.umich.edu#include "debug/MiscRegs.hh"
496242Sgblack@eecs.umich.edu#include "dev/arm/generic_timer.hh"
506242Sgblack@eecs.umich.edu#include "params/ArmISA.hh"
516242Sgblack@eecs.umich.edu#include "sim/faults.hh"
526242Sgblack@eecs.umich.edu#include "sim/stat_control.hh"
536242Sgblack@eecs.umich.edu#include "sim/system.hh"
546242Sgblack@eecs.umich.edu
556242Sgblack@eecs.umich.edunamespace ArmISA
566242Sgblack@eecs.umich.edu{
576242Sgblack@eecs.umich.edu
586242Sgblack@eecs.umich.eduISA::ISA(Params *p)
596242Sgblack@eecs.umich.edu    : SimObject(p),
606242Sgblack@eecs.umich.edu      system(NULL),
616242Sgblack@eecs.umich.edu      _decoderFlavour(p->decoderFlavour),
626242Sgblack@eecs.umich.edu      _vecRegRenameMode(p->vecRegRenameMode),
636242Sgblack@eecs.umich.edu      pmu(p->pmu)
646242Sgblack@eecs.umich.edu{
657111Sgblack@eecs.umich.edu    miscRegs[MISCREG_SCTLR_RST] = 0;
666242Sgblack@eecs.umich.edu
676242Sgblack@eecs.umich.edu    // Hook up a dummy device if we haven't been configured with a
686242Sgblack@eecs.umich.edu    // real PMU. By using a dummy device, we don't need to check that
696242Sgblack@eecs.umich.edu    // the PMU exist every time we try to access a PMU register.
708302SAli.Saidi@ARM.com    if (!pmu)
716735Sgblack@eecs.umich.edu        pmu = &dummyDevice;
726242Sgblack@eecs.umich.edu
736242Sgblack@eecs.umich.edu    // Give all ISA devices a pointer to this ISA
746242Sgblack@eecs.umich.edu    pmu->setISA(this);
756723Sgblack@eecs.umich.edu
766242Sgblack@eecs.umich.edu    system = dynamic_cast<ArmSystem *>(p->system);
776242Sgblack@eecs.umich.edu
786261Sgblack@eecs.umich.edu    // Cache system-level properties
796403Sgblack@eecs.umich.edu    if (FullSystem && system) {
806403Sgblack@eecs.umich.edu        highestELIs64 = system->highestELIs64();
817783SGiacomo.Gabrielli@arm.com        haveSecurity = system->haveSecurity();
827783SGiacomo.Gabrielli@arm.com        haveLPAE = system->haveLPAE();
836403Sgblack@eecs.umich.edu        haveVirtualization = system->haveVirtualization();
847325Sgblack@eecs.umich.edu        haveLargeAsid64 = system->haveLargeAsid64();
857325Sgblack@eecs.umich.edu        physAddrRange64 = system->physAddrRange64();
867400SAli.Saidi@ARM.com    } else {
877350SAli.Saidi@ARM.com        highestELIs64 = true; // ArmSystem::highestELIs64 does the same
887259Sgblack@eecs.umich.edu        haveSecurity = haveLPAE = haveVirtualization = false;
898868SMatt.Horsnell@arm.com        haveLargeAsid64 = false;
908868SMatt.Horsnell@arm.com        physAddrRange64 = 32;  // dummy value
918868SMatt.Horsnell@arm.com    }
928868SMatt.Horsnell@arm.com
938868SMatt.Horsnell@arm.com    initializeMiscRegMetadata();
948868SMatt.Horsnell@arm.com    preUnflattenMiscReg();
958868SMatt.Horsnell@arm.com
968868SMatt.Horsnell@arm.com    clear();
978868SMatt.Horsnell@arm.com}
988868SMatt.Horsnell@arm.com
998868SMatt.Horsnell@arm.comstd::vector<struct ISA::MiscRegLUTEntry> ISA::lookUpMiscReg(NUM_MISCREGS);
1008868SMatt.Horsnell@arm.com
1018868SMatt.Horsnell@arm.comconst ArmISAParams *
1028868SMatt.Horsnell@arm.comISA::params() const
1038868SMatt.Horsnell@arm.com{
1048868SMatt.Horsnell@arm.com    return dynamic_cast<const Params *>(_params);
1058868SMatt.Horsnell@arm.com}
1068868SMatt.Horsnell@arm.com
1078868SMatt.Horsnell@arm.comvoid
1088868SMatt.Horsnell@arm.comISA::clear()
1098868SMatt.Horsnell@arm.com{
1108868SMatt.Horsnell@arm.com    const Params *p(params());
1118868SMatt.Horsnell@arm.com
1128868SMatt.Horsnell@arm.com    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
1138868SMatt.Horsnell@arm.com    memset(miscRegs, 0, sizeof(miscRegs));
1148868SMatt.Horsnell@arm.com
1158868SMatt.Horsnell@arm.com    // Initialize configurable default values
1168868SMatt.Horsnell@arm.com    miscRegs[MISCREG_MIDR] = p->midr;
1178868SMatt.Horsnell@arm.com    miscRegs[MISCREG_MIDR_EL1] = p->midr;
1188868SMatt.Horsnell@arm.com    miscRegs[MISCREG_VPIDR] = p->midr;
1198868SMatt.Horsnell@arm.com
1208868SMatt.Horsnell@arm.com    if (FullSystem && system->highestELIs64()) {
1218868SMatt.Horsnell@arm.com        // Initialize AArch64 state
1228868SMatt.Horsnell@arm.com        clear64(p);
1238868SMatt.Horsnell@arm.com        return;
1247259Sgblack@eecs.umich.edu    }
1257259Sgblack@eecs.umich.edu
1267259Sgblack@eecs.umich.edu    // Initialize AArch32 state...
1277264Sgblack@eecs.umich.edu
1287267Sgblack@eecs.umich.edu    CPSR cpsr = 0;
1297285Sgblack@eecs.umich.edu    cpsr.mode = MODE_USER;
1307265Sgblack@eecs.umich.edu    miscRegs[MISCREG_CPSR] = cpsr;
1317266Sgblack@eecs.umich.edu    updateRegMap(cpsr);
1327266Sgblack@eecs.umich.edu
1337266Sgblack@eecs.umich.edu    SCTLR sctlr = 0;
1347268Sgblack@eecs.umich.edu    sctlr.te = (bool) sctlr_rst.te;
1357272Sgblack@eecs.umich.edu    sctlr.nmfi = (bool) sctlr_rst.nmfi;
1367272Sgblack@eecs.umich.edu    sctlr.v = (bool) sctlr_rst.v;
1377271Sgblack@eecs.umich.edu    sctlr.u = 1;
1387273Sgblack@eecs.umich.edu    sctlr.xp = 1;
1397287Sgblack@eecs.umich.edu    sctlr.rao2 = 1;
1407287Sgblack@eecs.umich.edu    sctlr.rao3 = 1;
1417274Sgblack@eecs.umich.edu    sctlr.rao4 = 0xf;  // SCTLR[6:3]
1427275Sgblack@eecs.umich.edu    sctlr.uci = 1;
1437276Sgblack@eecs.umich.edu    sctlr.dze = 1;
1447286Sgblack@eecs.umich.edu    miscRegs[MISCREG_SCTLR_NS] = sctlr;
1457297Sgblack@eecs.umich.edu    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
1467297Sgblack@eecs.umich.edu    miscRegs[MISCREG_HCPTR] = 0;
1477298Sgblack@eecs.umich.edu
1487352Sgblack@eecs.umich.edu    // Start with an event in the mailbox
1497352Sgblack@eecs.umich.edu    miscRegs[MISCREG_SEV_MAILBOX] = 1;
1507354Sgblack@eecs.umich.edu
1517353Sgblack@eecs.umich.edu    // Separate Instruction and Data TLBs
1527355Sgblack@eecs.umich.edu    miscRegs[MISCREG_TLBTR] = 1;
1537355Sgblack@eecs.umich.edu
1547355Sgblack@eecs.umich.edu    MVFR0 mvfr0 = 0;
1557355Sgblack@eecs.umich.edu    mvfr0.advSimdRegisters = 2;
1567355Sgblack@eecs.umich.edu    mvfr0.singlePrecision = 2;
1577355Sgblack@eecs.umich.edu    mvfr0.doublePrecision = 2;
1587355Sgblack@eecs.umich.edu    mvfr0.vfpExceptionTrapping = 0;
1597355Sgblack@eecs.umich.edu    mvfr0.divide = 1;
1607355Sgblack@eecs.umich.edu    mvfr0.squareRoot = 1;
1617355Sgblack@eecs.umich.edu    mvfr0.shortVectors = 1;
1627355Sgblack@eecs.umich.edu    mvfr0.roundingModes = 1;
1637355Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR0] = mvfr0;
1647355Sgblack@eecs.umich.edu
1657355Sgblack@eecs.umich.edu    MVFR1 mvfr1 = 0;
1667362Sgblack@eecs.umich.edu    mvfr1.flushToZero = 1;
1677362Sgblack@eecs.umich.edu    mvfr1.defaultNaN = 1;
1687362Sgblack@eecs.umich.edu    mvfr1.advSimdLoadStore = 1;
1697362Sgblack@eecs.umich.edu    mvfr1.advSimdInteger = 1;
1707390Sgblack@eecs.umich.edu    mvfr1.advSimdSinglePrecision = 1;
1717404SAli.Saidi@ARM.com    mvfr1.advSimdHalfPrecision = 1;
1727404SAli.Saidi@ARM.com    mvfr1.vfpHalfPrecision = 1;
1737404SAli.Saidi@ARM.com    miscRegs[MISCREG_MVFR1] = mvfr1;
1747404SAli.Saidi@ARM.com
1757406SAli.Saidi@ARM.com    // Reset values of PRRR and NMRR are implementation dependent
1767406SAli.Saidi@ARM.com
1777406SAli.Saidi@ARM.com    // @todo: PRRR and NMRR in secure state?
1787436Sdam.sunwoo@arm.com    miscRegs[MISCREG_PRRR_NS] =
1797436Sdam.sunwoo@arm.com        (1 << 19) | // 19
1807436Sdam.sunwoo@arm.com        (0 << 18) | // 18
1817436Sdam.sunwoo@arm.com        (0 << 17) | // 17
1827436Sdam.sunwoo@arm.com        (1 << 16) | // 16
1837436Sdam.sunwoo@arm.com        (2 << 14) | // 15:14
1847436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
1857436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
1867436Sdam.sunwoo@arm.com        (2 << 8)  | // 9:8
1877583SAli.Saidi@arm.com        (2 << 6)  | // 7:6
1888468Swade.walker@arm.com        (2 << 4)  | // 5:4
1898284SAli.Saidi@ARM.com        (1 << 2)  | // 3:2
1907583SAli.Saidi@arm.com        0;          // 1:0
1917583SAli.Saidi@arm.com    miscRegs[MISCREG_NMRR_NS] =
1927583SAli.Saidi@arm.com        (1 << 30) | // 31:30
1937583SAli.Saidi@arm.com        (0 << 26) | // 27:26
1947583SAli.Saidi@arm.com        (0 << 24) | // 25:24
1957583SAli.Saidi@arm.com        (3 << 22) | // 23:22
1967583SAli.Saidi@arm.com        (2 << 20) | // 21:20
1977583SAli.Saidi@arm.com        (0 << 18) | // 19:18
1987583SAli.Saidi@arm.com        (0 << 16) | // 17:16
1997583SAli.Saidi@arm.com        (1 << 14) | // 15:14
2007583SAli.Saidi@arm.com        (0 << 12) | // 13:12
2017583SAli.Saidi@arm.com        (2 << 10) | // 11:10
2027583SAli.Saidi@arm.com        (0 << 8)  | // 9:8
2037583SAli.Saidi@arm.com        (3 << 6)  | // 7:6
2047583SAli.Saidi@arm.com        (2 << 4)  | // 5:4
2058147SAli.Saidi@ARM.com        (0 << 2)  | // 3:2
2068147SAli.Saidi@ARM.com        0;          // 1:0
2078147SAli.Saidi@ARM.com
2088147SAli.Saidi@ARM.com    miscRegs[MISCREG_CPACR] = 0;
2098147SAli.Saidi@ARM.com
2108147SAli.Saidi@ARM.com    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
2118208SAli.Saidi@ARM.com    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
2128209SAli.Saidi@ARM.com    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
2138209SAli.Saidi@ARM.com    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
2148299Schander.sudanthi@arm.com
2158549Sdaniel.johnson@arm.com    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
2167259Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
2177406SAli.Saidi@ARM.com    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
2187259Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
2197259Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
2207259Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
2217259Sgblack@eecs.umich.edu
2227259Sgblack@eecs.umich.edu    miscRegs[MISCREG_FPSID] = p->fpsid;
2237259Sgblack@eecs.umich.edu
2247259Sgblack@eecs.umich.edu    if (haveLPAE) {
2257259Sgblack@eecs.umich.edu        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
2267259Sgblack@eecs.umich.edu        ttbcr.eae = 0;
2277259Sgblack@eecs.umich.edu        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
2287351Sgblack@eecs.umich.edu        // Enforce consistency with system-level settings
2297351Sgblack@eecs.umich.edu        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
2307351Sgblack@eecs.umich.edu    }
2317351Sgblack@eecs.umich.edu
2327351Sgblack@eecs.umich.edu    if (haveSecurity) {
2338058SAli.Saidi@ARM.com        miscRegs[MISCREG_SCTLR_S] = sctlr;
2348550SChander.Sudanthi@ARM.com        miscRegs[MISCREG_SCR] = 0;
2357351Sgblack@eecs.umich.edu        miscRegs[MISCREG_VBAR_S] = 0;
2367259Sgblack@eecs.umich.edu    } else {
2377259Sgblack@eecs.umich.edu        // we're always non-secure
2387259Sgblack@eecs.umich.edu        miscRegs[MISCREG_SCR] = 1;
2397259Sgblack@eecs.umich.edu    }
2407259Sgblack@eecs.umich.edu
2417259Sgblack@eecs.umich.edu    //XXX We need to initialize the rest of the state.
2427259Sgblack@eecs.umich.edu}
2436735Sgblack@eecs.umich.edu
2446261Sgblack@eecs.umich.eduvoid
2456261Sgblack@eecs.umich.eduISA::clear64(const ArmISAParams *p)
2468868SMatt.Horsnell@arm.com{
2478868SMatt.Horsnell@arm.com    CPSR cpsr = 0;
2488868SMatt.Horsnell@arm.com    Addr rvbar = system->resetAddr64();
2497259Sgblack@eecs.umich.edu    switch (system->highestEL()) {
2507259Sgblack@eecs.umich.edu        // Set initial EL to highest implemented EL using associated stack
2517259Sgblack@eecs.umich.edu        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
2528868SMatt.Horsnell@arm.com        // value
2536261Sgblack@eecs.umich.edu      case EL3:
2548302SAli.Saidi@ARM.com        cpsr.mode = MODE_EL3H;
2557259Sgblack@eecs.umich.edu        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
2567783SGiacomo.Gabrielli@arm.com        break;
2577783SGiacomo.Gabrielli@arm.com      case EL2:
2587400SAli.Saidi@ARM.com        cpsr.mode = MODE_EL2H;
2598868SMatt.Horsnell@arm.com        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
2608868SMatt.Horsnell@arm.com        break;
2618868SMatt.Horsnell@arm.com      case EL1:
2628868SMatt.Horsnell@arm.com        cpsr.mode = MODE_EL1H;
2638868SMatt.Horsnell@arm.com        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
2648868SMatt.Horsnell@arm.com        break;
2658868SMatt.Horsnell@arm.com      default:
2668868SMatt.Horsnell@arm.com        panic("Invalid highest implemented exception level");
2678868SMatt.Horsnell@arm.com        break;
2688868SMatt.Horsnell@arm.com    }
2698868SMatt.Horsnell@arm.com
2708868SMatt.Horsnell@arm.com    // Initialize rest of CPSR
2718868SMatt.Horsnell@arm.com    cpsr.daif = 0xf;  // Mask all interrupts
2728868SMatt.Horsnell@arm.com    cpsr.ss = 0;
2738868SMatt.Horsnell@arm.com    cpsr.il = 0;
2748868SMatt.Horsnell@arm.com    miscRegs[MISCREG_CPSR] = cpsr;
2758868SMatt.Horsnell@arm.com    updateRegMap(cpsr);
2768868SMatt.Horsnell@arm.com
2778868SMatt.Horsnell@arm.com    // Initialize other control registers
2788868SMatt.Horsnell@arm.com    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
2798868SMatt.Horsnell@arm.com    if (haveSecurity) {
2808868SMatt.Horsnell@arm.com        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830;
2818868SMatt.Horsnell@arm.com        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
2828868SMatt.Horsnell@arm.com    } else if (haveVirtualization) {
2838868SMatt.Horsnell@arm.com        // also  MISCREG_SCTLR_EL2 (by mapping)
2848868SMatt.Horsnell@arm.com        miscRegs[MISCREG_HSCTLR] = 0x30c50830;
2858868SMatt.Horsnell@arm.com    } else {
2868868SMatt.Horsnell@arm.com        // also  MISCREG_SCTLR_EL1 (by mapping)
2878868SMatt.Horsnell@arm.com        miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init
2888868SMatt.Horsnell@arm.com        // Always non-secure
2898868SMatt.Horsnell@arm.com        miscRegs[MISCREG_SCR_EL3] = 1;
2908868SMatt.Horsnell@arm.com    }
2917285Sgblack@eecs.umich.edu
2927267Sgblack@eecs.umich.edu    // Initialize configurable id registers
2937287Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
2947287Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
2957297Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
2967297Sgblack@eecs.umich.edu        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
2977355Sgblack@eecs.umich.edu        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
2987355Sgblack@eecs.umich.edu
2997355Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
3007355Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
3017355Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
3027390Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
3037436Sdam.sunwoo@arm.com    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
3047436Sdam.sunwoo@arm.com
3057436Sdam.sunwoo@arm.com    miscRegs[MISCREG_ID_DFR0_EL1] =
3067436Sdam.sunwoo@arm.com        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
3078468Swade.walker@arm.com
3087583SAli.Saidi@arm.com    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
3097583SAli.Saidi@arm.com
3107583SAli.Saidi@arm.com    // Enforce consistency with system-level settings...
3117583SAli.Saidi@arm.com
3128147SAli.Saidi@ARM.com    // EL3
3138299Schander.sudanthi@arm.com    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
3148549Sdaniel.johnson@arm.com        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
3157583SAli.Saidi@arm.com        haveSecurity ? 0x2 : 0x0);
3167406SAli.Saidi@ARM.com    // EL2
3178299Schander.sudanthi@arm.com    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
3188468Swade.walker@arm.com        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
3198147SAli.Saidi@ARM.com        haveVirtualization ? 0x2 : 0x0);
3207297Sgblack@eecs.umich.edu    // Large ASID support
3217272Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
3227406SAli.Saidi@ARM.com        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
3238179Sgblack@eecs.umich.edu        haveLargeAsid64 ? 0x2 : 0x0);
3248550SChander.Sudanthi@ARM.com    // Physical address size
3257259Sgblack@eecs.umich.edu    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
3266242Sgblack@eecs.umich.edu        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
3276242Sgblack@eecs.umich.edu        encodePhysAddrRange64(physAddrRange64));
3286242Sgblack@eecs.umich.edu}
3298303SAli.Saidi@ARM.com
3306242Sgblack@eecs.umich.eduMiscReg
3316242Sgblack@eecs.umich.eduISA::readMiscRegNoEffect(int misc_reg) const
3326242Sgblack@eecs.umich.edu{
3336735Sgblack@eecs.umich.edu    assert(misc_reg < NumMiscRegs);
3346242Sgblack@eecs.umich.edu
3356242Sgblack@eecs.umich.edu    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
3366735Sgblack@eecs.umich.edu    const auto &map = getMiscIndices(misc_reg);
3376242Sgblack@eecs.umich.edu    int lower = map.first, upper = map.second;
3386242Sgblack@eecs.umich.edu    // NB!: apply architectural masks according to desired register,
3396242Sgblack@eecs.umich.edu    // despite possibly getting value from different (mapped) register.
3406242Sgblack@eecs.umich.edu    auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32))
3416242Sgblack@eecs.umich.edu                                          |(miscRegs[upper] << 32));
3426242Sgblack@eecs.umich.edu    if (val & reg.res0()) {
3436242Sgblack@eecs.umich.edu        DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n",
3446735Sgblack@eecs.umich.edu                miscRegName[misc_reg], val & reg.res0());
3456750Sgblack@eecs.umich.edu    }
3466750Sgblack@eecs.umich.edu    if ((val & reg.res1()) != reg.res1()) {
3478302SAli.Saidi@ARM.com        DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n",
3488302SAli.Saidi@ARM.com                miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1());
3496750Sgblack@eecs.umich.edu    }
3506735Sgblack@eecs.umich.edu    return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao
3517360Sgblack@eecs.umich.edu}
3526735Sgblack@eecs.umich.edu
3536735Sgblack@eecs.umich.edu
3546735Sgblack@eecs.umich.eduMiscReg
3556735Sgblack@eecs.umich.eduISA::readMiscReg(int misc_reg, ThreadContext *tc)
3566735Sgblack@eecs.umich.edu{
3576735Sgblack@eecs.umich.edu    CPSR cpsr = 0;
3587406SAli.Saidi@ARM.com    PCState pc = 0;
3596735Sgblack@eecs.umich.edu    SCR scr = 0;
3606735Sgblack@eecs.umich.edu
3617360Sgblack@eecs.umich.edu    if (misc_reg == MISCREG_CPSR) {
3626735Sgblack@eecs.umich.edu        cpsr = miscRegs[misc_reg];
3637360Sgblack@eecs.umich.edu        pc = tc->pcState();
3646735Sgblack@eecs.umich.edu        cpsr.j = pc.jazelle() ? 1 : 0;
3656735Sgblack@eecs.umich.edu        cpsr.t = pc.thumb() ? 1 : 0;
3666735Sgblack@eecs.umich.edu        return cpsr;
3676735Sgblack@eecs.umich.edu    }
3686735Sgblack@eecs.umich.edu
3696735Sgblack@eecs.umich.edu#ifndef NDEBUG
3707406SAli.Saidi@ARM.com    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
3716735Sgblack@eecs.umich.edu        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
3726735Sgblack@eecs.umich.edu            warn("Unimplemented system register %s read.\n",
3736735Sgblack@eecs.umich.edu                 miscRegName[misc_reg]);
3746735Sgblack@eecs.umich.edu        else
3756735Sgblack@eecs.umich.edu            panic("Unimplemented system register %s read.\n",
3766735Sgblack@eecs.umich.edu                  miscRegName[misc_reg]);
3777320Sgblack@eecs.umich.edu    }
3787320Sgblack@eecs.umich.edu#endif
3797320Sgblack@eecs.umich.edu
3807320Sgblack@eecs.umich.edu    switch (unflattenMiscReg(misc_reg)) {
3817320Sgblack@eecs.umich.edu      case MISCREG_HCR:
3827320Sgblack@eecs.umich.edu        {
3837320Sgblack@eecs.umich.edu            if (!haveVirtualization)
3847320Sgblack@eecs.umich.edu                return 0;
3857320Sgblack@eecs.umich.edu            else
3867320Sgblack@eecs.umich.edu                return readMiscRegNoEffect(MISCREG_HCR);
3877320Sgblack@eecs.umich.edu        }
3887320Sgblack@eecs.umich.edu      case MISCREG_CPACR:
3897320Sgblack@eecs.umich.edu        {
3907320Sgblack@eecs.umich.edu            const uint32_t ones = (uint32_t)(-1);
3917320Sgblack@eecs.umich.edu            CPACR cpacrMask = 0;
3927320Sgblack@eecs.umich.edu            // Only cp10, cp11, and ase are implemented, nothing else should
3938206SWilliam.Wang@arm.com            // be readable? (straight copy from the write code)
3947320Sgblack@eecs.umich.edu            cpacrMask.cp10 = ones;
3957320Sgblack@eecs.umich.edu            cpacrMask.cp11 = ones;
3967320Sgblack@eecs.umich.edu            cpacrMask.asedis = ones;
3977362Sgblack@eecs.umich.edu
3987362Sgblack@eecs.umich.edu            // Security Extensions may limit the readability of CPACR
3997362Sgblack@eecs.umich.edu            if (haveSecurity) {
4007362Sgblack@eecs.umich.edu                scr = readMiscRegNoEffect(MISCREG_SCR);
4017362Sgblack@eecs.umich.edu                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
4027362Sgblack@eecs.umich.edu                if (scr.ns && (cpsr.mode != MODE_MON)) {
4037362Sgblack@eecs.umich.edu                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
4047362Sgblack@eecs.umich.edu                    // NB: Skipping the full loop, here
4057376Sgblack@eecs.umich.edu                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
4067376Sgblack@eecs.umich.edu                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
4077376Sgblack@eecs.umich.edu                }
4087376Sgblack@eecs.umich.edu            }
4097376Sgblack@eecs.umich.edu            MiscReg val = readMiscRegNoEffect(MISCREG_CPACR);
4107376Sgblack@eecs.umich.edu            val &= cpacrMask;
4117376Sgblack@eecs.umich.edu            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
4127376Sgblack@eecs.umich.edu                    miscRegName[misc_reg], val);
4137376Sgblack@eecs.umich.edu            return val;
4147376Sgblack@eecs.umich.edu        }
4157376Sgblack@eecs.umich.edu      case MISCREG_MPIDR:
4167376Sgblack@eecs.umich.edu        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
4177376Sgblack@eecs.umich.edu        scr  = readMiscRegNoEffect(MISCREG_SCR);
4187376Sgblack@eecs.umich.edu        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
4197376Sgblack@eecs.umich.edu            return getMPIDR(system, tc);
4207376Sgblack@eecs.umich.edu        } else {
4217376Sgblack@eecs.umich.edu            return readMiscReg(MISCREG_VMPIDR, tc);
4227376Sgblack@eecs.umich.edu        }
4237376Sgblack@eecs.umich.edu            break;
4247376Sgblack@eecs.umich.edu      case MISCREG_MPIDR_EL1:
4257376Sgblack@eecs.umich.edu        // @todo in the absence of v8 virtualization support just return MPIDR_EL1
4267376Sgblack@eecs.umich.edu        return getMPIDR(system, tc) & 0xffffffff;
4277376Sgblack@eecs.umich.edu      case MISCREG_VMPIDR:
4287376Sgblack@eecs.umich.edu        // top bit defined as RES1
4297376Sgblack@eecs.umich.edu        return readMiscRegNoEffect(misc_reg) | 0x80000000;
4307376Sgblack@eecs.umich.edu      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
4317383Sgblack@eecs.umich.edu      case MISCREG_REVIDR:  // not implemented, so alias MIDR
4327643Sgblack@eecs.umich.edu      case MISCREG_MIDR:
4337643Sgblack@eecs.umich.edu        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
4347783SGiacomo.Gabrielli@arm.com        scr  = readMiscRegNoEffect(MISCREG_SCR);
4357783SGiacomo.Gabrielli@arm.com        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
4367783SGiacomo.Gabrielli@arm.com            return readMiscRegNoEffect(misc_reg);
4377783SGiacomo.Gabrielli@arm.com        } else {
4387783SGiacomo.Gabrielli@arm.com            return readMiscRegNoEffect(MISCREG_VPIDR);
4397643Sgblack@eecs.umich.edu        }
4407640Sgblack@eecs.umich.edu        break;
4417640Sgblack@eecs.umich.edu      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
4427640Sgblack@eecs.umich.edu      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
4437640Sgblack@eecs.umich.edu      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
4447640Sgblack@eecs.umich.edu      case MISCREG_AIDR:  // AUX ID set to 0
4457640Sgblack@eecs.umich.edu      case MISCREG_TCMTR: // No TCM's
4467383Sgblack@eecs.umich.edu        return 0;
4477383Sgblack@eecs.umich.edu
4487383Sgblack@eecs.umich.edu      case MISCREG_CLIDR:
4497383Sgblack@eecs.umich.edu        warn_once("The clidr register always reports 0 caches.\n");
4507383Sgblack@eecs.umich.edu        warn_once("clidr LoUIS field of 0b001 to match current "
4517383Sgblack@eecs.umich.edu                  "ARM implementations.\n");
4527383Sgblack@eecs.umich.edu        return 0x00200000;
4537383Sgblack@eecs.umich.edu      case MISCREG_CCSIDR:
4547383Sgblack@eecs.umich.edu        warn_once("The ccsidr register isn't implemented and "
4557383Sgblack@eecs.umich.edu                "always reads as 0.\n");
4567383Sgblack@eecs.umich.edu        break;
4577383Sgblack@eecs.umich.edu      case MISCREG_CTR:                 // AArch32, ARMv7, top bit set
4587383Sgblack@eecs.umich.edu      case MISCREG_CTR_EL0:             // AArch64
4597383Sgblack@eecs.umich.edu        {
4607383Sgblack@eecs.umich.edu            //all caches have the same line size in gem5
4617383Sgblack@eecs.umich.edu            //4 byte words in ARM
4627383Sgblack@eecs.umich.edu            unsigned lineSizeWords =
4637383Sgblack@eecs.umich.edu                tc->getSystemPtr()->cacheLineSize() / 4;
4647383Sgblack@eecs.umich.edu            unsigned log2LineSizeWords = 0;
4657383Sgblack@eecs.umich.edu
4667383Sgblack@eecs.umich.edu            while (lineSizeWords >>= 1) {
4677404SAli.Saidi@ARM.com                ++log2LineSizeWords;
4687404SAli.Saidi@ARM.com            }
4697404SAli.Saidi@ARM.com
4707404SAli.Saidi@ARM.com            CTR ctr = 0;
4717404SAli.Saidi@ARM.com            //log2 of minimun i-cache line size (words)
4727404SAli.Saidi@ARM.com            ctr.iCacheLineSize = log2LineSizeWords;
4737404SAli.Saidi@ARM.com            //b11 - gem5 uses pipt
4747404SAli.Saidi@ARM.com            ctr.l1IndexPolicy = 0x3;
4757404SAli.Saidi@ARM.com            //log2 of minimum d-cache line size (words)
4767404SAli.Saidi@ARM.com            ctr.dCacheLineSize = log2LineSizeWords;
4777404SAli.Saidi@ARM.com            //log2 of max reservation size (words)
4787404SAli.Saidi@ARM.com            ctr.erg = log2LineSizeWords;
4797404SAli.Saidi@ARM.com            //log2 of max writeback size (words)
4807404SAli.Saidi@ARM.com            ctr.cwg = log2LineSizeWords;
4817404SAli.Saidi@ARM.com            //b100 - gem5 format is ARMv7
4827404SAli.Saidi@ARM.com            ctr.format = 0x4;
4837404SAli.Saidi@ARM.com
4847404SAli.Saidi@ARM.com            return ctr;
4857404SAli.Saidi@ARM.com        }
4867404SAli.Saidi@ARM.com      case MISCREG_ACTLR:
4877404SAli.Saidi@ARM.com        warn("Not doing anything for miscreg ACTLR\n");
4887404SAli.Saidi@ARM.com        break;
4897404SAli.Saidi@ARM.com
4907404SAli.Saidi@ARM.com      case MISCREG_PMXEVTYPER_PMCCFILTR:
4917404SAli.Saidi@ARM.com      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
4927404SAli.Saidi@ARM.com      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
4937404SAli.Saidi@ARM.com      case MISCREG_PMCR ... MISCREG_PMOVSSET:
4947404SAli.Saidi@ARM.com        return pmu->readMiscReg(misc_reg);
4957404SAli.Saidi@ARM.com
4967404SAli.Saidi@ARM.com      case MISCREG_CPSR_Q:
4977404SAli.Saidi@ARM.com        panic("shouldn't be reading this register seperately\n");
4987404SAli.Saidi@ARM.com      case MISCREG_FPSCR_QC:
4997404SAli.Saidi@ARM.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
5007404SAli.Saidi@ARM.com      case MISCREG_FPSCR_EXC:
5017404SAli.Saidi@ARM.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
5027404SAli.Saidi@ARM.com      case MISCREG_FPSR:
5037404SAli.Saidi@ARM.com        {
5047404SAli.Saidi@ARM.com            const uint32_t ones = (uint32_t)(-1);
5057404SAli.Saidi@ARM.com            FPSCR fpscrMask = 0;
5067404SAli.Saidi@ARM.com            fpscrMask.ioc = ones;
5077404SAli.Saidi@ARM.com            fpscrMask.dzc = ones;
5087404SAli.Saidi@ARM.com            fpscrMask.ofc = ones;
5097404SAli.Saidi@ARM.com            fpscrMask.ufc = ones;
5108552Sdaniel.johnson@arm.com            fpscrMask.ixc = ones;
5118552Sdaniel.johnson@arm.com            fpscrMask.idc = ones;
5128552Sdaniel.johnson@arm.com            fpscrMask.qc = ones;
5138552Sdaniel.johnson@arm.com            fpscrMask.v = ones;
5148552Sdaniel.johnson@arm.com            fpscrMask.c = ones;
5158549Sdaniel.johnson@arm.com            fpscrMask.z = ones;
5168549Sdaniel.johnson@arm.com            fpscrMask.n = ones;
5178549Sdaniel.johnson@arm.com            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
5188549Sdaniel.johnson@arm.com        }
5198549Sdaniel.johnson@arm.com      case MISCREG_FPCR:
5208549Sdaniel.johnson@arm.com        {
5218549Sdaniel.johnson@arm.com            const uint32_t ones = (uint32_t)(-1);
5228549Sdaniel.johnson@arm.com            FPSCR fpscrMask  = 0;
5238549Sdaniel.johnson@arm.com            fpscrMask.ioe = ones;
5248549Sdaniel.johnson@arm.com            fpscrMask.dze = ones;
5258549Sdaniel.johnson@arm.com            fpscrMask.ofe = ones;
5268549Sdaniel.johnson@arm.com            fpscrMask.ufe = ones;
5278549Sdaniel.johnson@arm.com            fpscrMask.ixe = ones;
5288549Sdaniel.johnson@arm.com            fpscrMask.ide = ones;
5298549Sdaniel.johnson@arm.com            fpscrMask.len    = ones;
5308549Sdaniel.johnson@arm.com            fpscrMask.stride = ones;
5318549Sdaniel.johnson@arm.com            fpscrMask.rMode  = ones;
5328902Sandreas.hansson@arm.com            fpscrMask.fz     = ones;
5336242Sgblack@eecs.umich.edu            fpscrMask.dn     = ones;
5346242Sgblack@eecs.umich.edu            fpscrMask.ahp    = ones;
535            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
536        }
537      case MISCREG_NZCV:
538        {
539            CPSR cpsr = 0;
540            cpsr.nz   = tc->readCCReg(CCREG_NZ);
541            cpsr.c    = tc->readCCReg(CCREG_C);
542            cpsr.v    = tc->readCCReg(CCREG_V);
543            return cpsr;
544        }
545      case MISCREG_DAIF:
546        {
547            CPSR cpsr = 0;
548            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
549            return cpsr;
550        }
551      case MISCREG_SP_EL0:
552        {
553            return tc->readIntReg(INTREG_SP0);
554        }
555      case MISCREG_SP_EL1:
556        {
557            return tc->readIntReg(INTREG_SP1);
558        }
559      case MISCREG_SP_EL2:
560        {
561            return tc->readIntReg(INTREG_SP2);
562        }
563      case MISCREG_SPSEL:
564        {
565            return miscRegs[MISCREG_CPSR] & 0x1;
566        }
567      case MISCREG_CURRENTEL:
568        {
569            return miscRegs[MISCREG_CPSR] & 0xc;
570        }
571      case MISCREG_L2CTLR:
572        {
573            // mostly unimplemented, just set NumCPUs field from sim and return
574            L2CTLR l2ctlr = 0;
575            // b00:1CPU to b11:4CPUs
576            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
577            return l2ctlr;
578        }
579      case MISCREG_DBGDIDR:
580        /* For now just implement the version number.
581         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
582         */
583        return 0x5 << 16;
584      case MISCREG_DBGDSCRint:
585        return 0;
586      case MISCREG_ISR:
587        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
588            readMiscRegNoEffect(MISCREG_HCR),
589            readMiscRegNoEffect(MISCREG_CPSR),
590            readMiscRegNoEffect(MISCREG_SCR));
591      case MISCREG_ISR_EL1:
592        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
593            readMiscRegNoEffect(MISCREG_HCR_EL2),
594            readMiscRegNoEffect(MISCREG_CPSR),
595            readMiscRegNoEffect(MISCREG_SCR_EL3));
596      case MISCREG_DCZID_EL0:
597        return 0x04;  // DC ZVA clear 64-byte chunks
598      case MISCREG_HCPTR:
599        {
600            MiscReg val = readMiscRegNoEffect(misc_reg);
601            // The trap bit associated with CP14 is defined as RAZ
602            val &= ~(1 << 14);
603            // If a CP bit in NSACR is 0 then the corresponding bit in
604            // HCPTR is RAO/WI
605            bool secure_lookup = haveSecurity &&
606                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
607                              readMiscRegNoEffect(MISCREG_CPSR));
608            if (!secure_lookup) {
609                MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR);
610                val |= (mask ^ 0x7FFF) & 0xBFFF;
611            }
612            // Set the bits for unimplemented coprocessors to RAO/WI
613            val |= 0x33FF;
614            return (val);
615        }
616      case MISCREG_HDFAR: // alias for secure DFAR
617        return readMiscRegNoEffect(MISCREG_DFAR_S);
618      case MISCREG_HIFAR: // alias for secure IFAR
619        return readMiscRegNoEffect(MISCREG_IFAR_S);
620      case MISCREG_HVBAR: // bottom bits reserved
621        return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0;
622      case MISCREG_SCTLR:
623        return (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818;
624      case MISCREG_SCTLR_EL1:
625        return (readMiscRegNoEffect(misc_reg) & 0x37DDDBBF) | 0x30D00800;
626      case MISCREG_SCTLR_EL2:
627      case MISCREG_SCTLR_EL3:
628      case MISCREG_HSCTLR:
629        return (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830;
630
631      case MISCREG_ID_PFR0:
632        // !ThumbEE | !Jazelle | Thumb | ARM
633        return 0x00000031;
634      case MISCREG_ID_PFR1:
635        {   // Timer | Virti | !M Profile | TrustZone | ARMv4
636            bool haveTimer = (system->getGenericTimer() != NULL);
637            return 0x00000001
638                 | (haveSecurity       ? 0x00000010 : 0x0)
639                 | (haveVirtualization ? 0x00001000 : 0x0)
640                 | (haveTimer          ? 0x00010000 : 0x0);
641        }
642      case MISCREG_ID_AA64PFR0_EL1:
643        return 0x0000000000000002   // AArch{64,32} supported at EL0
644             | 0x0000000000000020                             // EL1
645             | (haveVirtualization ? 0x0000000000000200 : 0)  // EL2
646             | (haveSecurity       ? 0x0000000000002000 : 0); // EL3
647      case MISCREG_ID_AA64PFR1_EL1:
648        return 0; // bits [63:0] RES0 (reserved for future use)
649
650      // Generic Timer registers
651      case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
652      case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
653      case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
654      case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
655        return getGenericTimer(tc).readMiscReg(misc_reg);
656
657      default:
658        break;
659
660    }
661    return readMiscRegNoEffect(misc_reg);
662}
663
664void
665ISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
666{
667    assert(misc_reg < NumMiscRegs);
668
669    const auto &reg = lookUpMiscReg[misc_reg]; // bit masks
670    const auto &map = getMiscIndices(misc_reg);
671    int lower = map.first, upper = map.second;
672
673    auto v = (val & ~reg.wi()) | reg.rao();
674    if (upper > 0) {
675        miscRegs[lower] = bits(v, 31, 0);
676        miscRegs[upper] = bits(v, 63, 32);
677        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
678                misc_reg, lower, upper, v);
679    } else {
680        miscRegs[lower] = v;
681        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
682                misc_reg, lower, v);
683    }
684}
685
686namespace {
687
688template<typename T>
689TLB *
690getITBPtr(T *tc)
691{
692    auto tlb = dynamic_cast<TLB *>(tc->getITBPtr());
693    assert(tlb);
694    return tlb;
695}
696
697template<typename T>
698TLB *
699getDTBPtr(T *tc)
700{
701    auto tlb = dynamic_cast<TLB *>(tc->getDTBPtr());
702    assert(tlb);
703    return tlb;
704}
705
706} // anonymous namespace
707
708void
709ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
710{
711
712    MiscReg newVal = val;
713    int x;
714    bool secure_lookup;
715    bool hyp;
716    System *sys;
717    ThreadContext *oc;
718    uint8_t target_el;
719    uint16_t asid;
720    SCR scr;
721
722    if (misc_reg == MISCREG_CPSR) {
723        updateRegMap(val);
724
725
726        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
727        int old_mode = old_cpsr.mode;
728        CPSR cpsr = val;
729        if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) {
730            getITBPtr(tc)->invalidateMiscReg();
731            getDTBPtr(tc)->invalidateMiscReg();
732        }
733
734        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
735                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
736        PCState pc = tc->pcState();
737        pc.nextThumb(cpsr.t);
738        pc.nextJazelle(cpsr.j);
739
740        // Follow slightly different semantics if a CheckerCPU object
741        // is connected
742        CheckerCPU *checker = tc->getCheckerCpuPtr();
743        if (checker) {
744            tc->pcStateNoRecord(pc);
745        } else {
746            tc->pcState(pc);
747        }
748    } else {
749#ifndef NDEBUG
750        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
751            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
752                warn("Unimplemented system register %s write with %#x.\n",
753                    miscRegName[misc_reg], val);
754            else
755                panic("Unimplemented system register %s write with %#x.\n",
756                    miscRegName[misc_reg], val);
757        }
758#endif
759        switch (unflattenMiscReg(misc_reg)) {
760          case MISCREG_CPACR:
761            {
762
763                const uint32_t ones = (uint32_t)(-1);
764                CPACR cpacrMask = 0;
765                // Only cp10, cp11, and ase are implemented, nothing else should
766                // be writable
767                cpacrMask.cp10 = ones;
768                cpacrMask.cp11 = ones;
769                cpacrMask.asedis = ones;
770
771                // Security Extensions may limit the writability of CPACR
772                if (haveSecurity) {
773                    scr = readMiscRegNoEffect(MISCREG_SCR);
774                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
775                    if (scr.ns && (cpsr.mode != MODE_MON)) {
776                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
777                        // NB: Skipping the full loop, here
778                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
779                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
780                    }
781                }
782
783                MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR);
784                newVal &= cpacrMask;
785                newVal |= old_val & ~cpacrMask;
786                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
787                        miscRegName[misc_reg], newVal);
788            }
789            break;
790          case MISCREG_CPACR_EL1:
791            {
792                const uint32_t ones = (uint32_t)(-1);
793                CPACR cpacrMask = 0;
794                cpacrMask.tta = ones;
795                cpacrMask.fpen = ones;
796                newVal &= cpacrMask;
797                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
798                        miscRegName[misc_reg], newVal);
799            }
800            break;
801          case MISCREG_CPTR_EL2:
802            {
803                const uint32_t ones = (uint32_t)(-1);
804                CPTR cptrMask = 0;
805                cptrMask.tcpac = ones;
806                cptrMask.tta = ones;
807                cptrMask.tfp = ones;
808                newVal &= cptrMask;
809                cptrMask = 0;
810                cptrMask.res1_13_12_el2 = ones;
811                cptrMask.res1_9_0_el2 = ones;
812                newVal |= cptrMask;
813                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
814                        miscRegName[misc_reg], newVal);
815            }
816            break;
817          case MISCREG_CPTR_EL3:
818            {
819                const uint32_t ones = (uint32_t)(-1);
820                CPTR cptrMask = 0;
821                cptrMask.tcpac = ones;
822                cptrMask.tta = ones;
823                cptrMask.tfp = ones;
824                newVal &= cptrMask;
825                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
826                        miscRegName[misc_reg], newVal);
827            }
828            break;
829          case MISCREG_CSSELR:
830            warn_once("The csselr register isn't implemented.\n");
831            return;
832
833          case MISCREG_DC_ZVA_Xt:
834            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
835            return;
836
837          case MISCREG_FPSCR:
838            {
839                const uint32_t ones = (uint32_t)(-1);
840                FPSCR fpscrMask = 0;
841                fpscrMask.ioc = ones;
842                fpscrMask.dzc = ones;
843                fpscrMask.ofc = ones;
844                fpscrMask.ufc = ones;
845                fpscrMask.ixc = ones;
846                fpscrMask.idc = ones;
847                fpscrMask.ioe = ones;
848                fpscrMask.dze = ones;
849                fpscrMask.ofe = ones;
850                fpscrMask.ufe = ones;
851                fpscrMask.ixe = ones;
852                fpscrMask.ide = ones;
853                fpscrMask.len = ones;
854                fpscrMask.stride = ones;
855                fpscrMask.rMode = ones;
856                fpscrMask.fz = ones;
857                fpscrMask.dn = ones;
858                fpscrMask.ahp = ones;
859                fpscrMask.qc = ones;
860                fpscrMask.v = ones;
861                fpscrMask.c = ones;
862                fpscrMask.z = ones;
863                fpscrMask.n = ones;
864                newVal = (newVal & (uint32_t)fpscrMask) |
865                         (readMiscRegNoEffect(MISCREG_FPSCR) &
866                          ~(uint32_t)fpscrMask);
867                tc->getDecoderPtr()->setContext(newVal);
868            }
869            break;
870          case MISCREG_FPSR:
871            {
872                const uint32_t ones = (uint32_t)(-1);
873                FPSCR fpscrMask = 0;
874                fpscrMask.ioc = ones;
875                fpscrMask.dzc = ones;
876                fpscrMask.ofc = ones;
877                fpscrMask.ufc = ones;
878                fpscrMask.ixc = ones;
879                fpscrMask.idc = ones;
880                fpscrMask.qc = ones;
881                fpscrMask.v = ones;
882                fpscrMask.c = ones;
883                fpscrMask.z = ones;
884                fpscrMask.n = ones;
885                newVal = (newVal & (uint32_t)fpscrMask) |
886                         (readMiscRegNoEffect(MISCREG_FPSCR) &
887                          ~(uint32_t)fpscrMask);
888                misc_reg = MISCREG_FPSCR;
889            }
890            break;
891          case MISCREG_FPCR:
892            {
893                const uint32_t ones = (uint32_t)(-1);
894                FPSCR fpscrMask  = 0;
895                fpscrMask.ioe = ones;
896                fpscrMask.dze = ones;
897                fpscrMask.ofe = ones;
898                fpscrMask.ufe = ones;
899                fpscrMask.ixe = ones;
900                fpscrMask.ide = ones;
901                fpscrMask.len    = ones;
902                fpscrMask.stride = ones;
903                fpscrMask.rMode  = ones;
904                fpscrMask.fz     = ones;
905                fpscrMask.dn     = ones;
906                fpscrMask.ahp    = ones;
907                newVal = (newVal & (uint32_t)fpscrMask) |
908                         (readMiscRegNoEffect(MISCREG_FPSCR) &
909                          ~(uint32_t)fpscrMask);
910                misc_reg = MISCREG_FPSCR;
911            }
912            break;
913          case MISCREG_CPSR_Q:
914            {
915                assert(!(newVal & ~CpsrMaskQ));
916                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
917                misc_reg = MISCREG_CPSR;
918            }
919            break;
920          case MISCREG_FPSCR_QC:
921            {
922                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
923                         (newVal & FpscrQcMask);
924                misc_reg = MISCREG_FPSCR;
925            }
926            break;
927          case MISCREG_FPSCR_EXC:
928            {
929                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
930                         (newVal & FpscrExcMask);
931                misc_reg = MISCREG_FPSCR;
932            }
933            break;
934          case MISCREG_FPEXC:
935            {
936                // vfpv3 architecture, section B.6.1 of DDI04068
937                // bit 29 - valid only if fpexc[31] is 0
938                const uint32_t fpexcMask = 0x60000000;
939                newVal = (newVal & fpexcMask) |
940                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
941            }
942            break;
943          case MISCREG_HCR:
944            {
945                if (!haveVirtualization)
946                    return;
947            }
948            break;
949          case MISCREG_IFSR:
950            {
951                // ARM ARM (ARM DDI 0406C.b) B4.1.96
952                const uint32_t ifsrMask =
953                    mask(31, 13) | mask(11, 11) | mask(8, 6);
954                newVal = newVal & ~ifsrMask;
955            }
956            break;
957          case MISCREG_DFSR:
958            {
959                // ARM ARM (ARM DDI 0406C.b) B4.1.52
960                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
961                newVal = newVal & ~dfsrMask;
962            }
963            break;
964          case MISCREG_AMAIR0:
965          case MISCREG_AMAIR1:
966            {
967                // ARM ARM (ARM DDI 0406C.b) B4.1.5
968                // Valid only with LPAE
969                if (!haveLPAE)
970                    return;
971                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
972            }
973            break;
974          case MISCREG_SCR:
975            getITBPtr(tc)->invalidateMiscReg();
976            getDTBPtr(tc)->invalidateMiscReg();
977            break;
978          case MISCREG_SCTLR:
979            {
980                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
981                scr = readMiscRegNoEffect(MISCREG_SCR);
982                MiscRegIndex sctlr_idx = (haveSecurity && !scr.ns)
983                                         ? MISCREG_SCTLR_S : MISCREG_SCTLR_NS;
984                SCTLR sctlr = miscRegs[sctlr_idx];
985                SCTLR new_sctlr = newVal;
986                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
987                miscRegs[sctlr_idx] = (MiscReg)new_sctlr;
988                getITBPtr(tc)->invalidateMiscReg();
989                getDTBPtr(tc)->invalidateMiscReg();
990            }
991          case MISCREG_MIDR:
992          case MISCREG_ID_PFR0:
993          case MISCREG_ID_PFR1:
994          case MISCREG_ID_DFR0:
995          case MISCREG_ID_MMFR0:
996          case MISCREG_ID_MMFR1:
997          case MISCREG_ID_MMFR2:
998          case MISCREG_ID_MMFR3:
999          case MISCREG_ID_ISAR0:
1000          case MISCREG_ID_ISAR1:
1001          case MISCREG_ID_ISAR2:
1002          case MISCREG_ID_ISAR3:
1003          case MISCREG_ID_ISAR4:
1004          case MISCREG_ID_ISAR5:
1005
1006          case MISCREG_MPIDR:
1007          case MISCREG_FPSID:
1008          case MISCREG_TLBTR:
1009          case MISCREG_MVFR0:
1010          case MISCREG_MVFR1:
1011
1012          case MISCREG_ID_AA64AFR0_EL1:
1013          case MISCREG_ID_AA64AFR1_EL1:
1014          case MISCREG_ID_AA64DFR0_EL1:
1015          case MISCREG_ID_AA64DFR1_EL1:
1016          case MISCREG_ID_AA64ISAR0_EL1:
1017          case MISCREG_ID_AA64ISAR1_EL1:
1018          case MISCREG_ID_AA64MMFR0_EL1:
1019          case MISCREG_ID_AA64MMFR1_EL1:
1020          case MISCREG_ID_AA64PFR0_EL1:
1021          case MISCREG_ID_AA64PFR1_EL1:
1022            // ID registers are constants.
1023            return;
1024
1025          // TLBI all entries, EL0&1 inner sharable (ignored)
1026          case MISCREG_TLBIALLIS:
1027          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
1028            assert32(tc);
1029            target_el = 1; // el 0 and 1 are handled together
1030            scr = readMiscReg(MISCREG_SCR, tc);
1031            secure_lookup = haveSecurity && !scr.ns;
1032            sys = tc->getSystemPtr();
1033            for (x = 0; x < sys->numContexts(); x++) {
1034                oc = sys->getThreadContext(x);
1035                getITBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
1036                getDTBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
1037
1038                // If CheckerCPU is connected, need to notify it of a flush
1039                CheckerCPU *checker = oc->getCheckerCpuPtr();
1040                if (checker) {
1041                    getITBPtr(checker)->flushAllSecurity(secure_lookup,
1042                                                         target_el);
1043                    getDTBPtr(checker)->flushAllSecurity(secure_lookup,
1044                                                         target_el);
1045                }
1046            }
1047            return;
1048          // TLBI all entries, EL0&1, instruction side
1049          case MISCREG_ITLBIALL:
1050            assert32(tc);
1051            target_el = 1; // el 0 and 1 are handled together
1052            scr = readMiscReg(MISCREG_SCR, tc);
1053            secure_lookup = haveSecurity && !scr.ns;
1054            getITBPtr(tc)->flushAllSecurity(secure_lookup, target_el);
1055            return;
1056          // TLBI all entries, EL0&1, data side
1057          case MISCREG_DTLBIALL:
1058            assert32(tc);
1059            target_el = 1; // el 0 and 1 are handled together
1060            scr = readMiscReg(MISCREG_SCR, tc);
1061            secure_lookup = haveSecurity && !scr.ns;
1062            getDTBPtr(tc)->flushAllSecurity(secure_lookup, target_el);
1063            return;
1064          // TLBI based on VA, EL0&1 inner sharable (ignored)
1065          case MISCREG_TLBIMVAL:
1066          case MISCREG_TLBIMVALIS:
1067            // mcr tlbimval(is) is invalidating all matching entries
1068            // regardless of the level of lookup, since in gem5 we cache
1069            // in the tlb the last level of lookup only.
1070          case MISCREG_TLBIMVA:
1071          case MISCREG_TLBIMVAIS:
1072            assert32(tc);
1073            target_el = 1; // el 0 and 1 are handled together
1074            scr = readMiscReg(MISCREG_SCR, tc);
1075            secure_lookup = haveSecurity && !scr.ns;
1076            sys = tc->getSystemPtr();
1077            for (x = 0; x < sys->numContexts(); x++) {
1078                oc = sys->getThreadContext(x);
1079                getITBPtr(oc)->flushMvaAsid(mbits(newVal, 31, 12),
1080                                              bits(newVal, 7,0),
1081                                              secure_lookup, target_el);
1082                getDTBPtr(oc)->flushMvaAsid(mbits(newVal, 31, 12),
1083                                              bits(newVal, 7,0),
1084                                              secure_lookup, target_el);
1085
1086                CheckerCPU *checker = oc->getCheckerCpuPtr();
1087                if (checker) {
1088                    getITBPtr(checker)->flushMvaAsid(mbits(newVal, 31, 12),
1089                        bits(newVal, 7,0), secure_lookup, target_el);
1090                    getDTBPtr(checker)->flushMvaAsid(mbits(newVal, 31, 12),
1091                        bits(newVal, 7,0), secure_lookup, target_el);
1092                }
1093            }
1094            return;
1095          // TLBI by ASID, EL0&1, inner sharable
1096          case MISCREG_TLBIASIDIS:
1097          case MISCREG_TLBIASID:
1098            assert32(tc);
1099            target_el = 1; // el 0 and 1 are handled together
1100            scr = readMiscReg(MISCREG_SCR, tc);
1101            secure_lookup = haveSecurity && !scr.ns;
1102            sys = tc->getSystemPtr();
1103            for (x = 0; x < sys->numContexts(); x++) {
1104                oc = sys->getThreadContext(x);
1105                getITBPtr(oc)->flushAsid(bits(newVal, 7,0),
1106                    secure_lookup, target_el);
1107                getDTBPtr(oc)->flushAsid(bits(newVal, 7,0),
1108                    secure_lookup, target_el);
1109                CheckerCPU *checker = oc->getCheckerCpuPtr();
1110                if (checker) {
1111                    getITBPtr(checker)->flushAsid(bits(newVal, 7,0),
1112                        secure_lookup, target_el);
1113                    getDTBPtr(checker)->flushAsid(bits(newVal, 7,0),
1114                        secure_lookup, target_el);
1115                }
1116            }
1117            return;
1118          // TLBI by address, EL0&1, inner sharable (ignored)
1119          case MISCREG_TLBIMVAAL:
1120          case MISCREG_TLBIMVAALIS:
1121            // mcr tlbimvaal(is) is invalidating all matching entries
1122            // regardless of the level of lookup, since in gem5 we cache
1123            // in the tlb the last level of lookup only.
1124          case MISCREG_TLBIMVAA:
1125          case MISCREG_TLBIMVAAIS:
1126            assert32(tc);
1127            target_el = 1; // el 0 and 1 are handled together
1128            scr = readMiscReg(MISCREG_SCR, tc);
1129            secure_lookup = haveSecurity && !scr.ns;
1130            hyp = 0;
1131            tlbiMVA(tc, newVal, secure_lookup, hyp, target_el);
1132            return;
1133          // TLBI by address, EL2, hypervisor mode
1134          case MISCREG_TLBIMVALH:
1135          case MISCREG_TLBIMVALHIS:
1136            // mcr tlbimvalh(is) is invalidating all matching entries
1137            // regardless of the level of lookup, since in gem5 we cache
1138            // in the tlb the last level of lookup only.
1139          case MISCREG_TLBIMVAH:
1140          case MISCREG_TLBIMVAHIS:
1141            assert32(tc);
1142            target_el = 1; // aarch32, use hyp bit
1143            scr = readMiscReg(MISCREG_SCR, tc);
1144            secure_lookup = haveSecurity && !scr.ns;
1145            hyp = 1;
1146            tlbiMVA(tc, newVal, secure_lookup, hyp, target_el);
1147            return;
1148          // TLBI by address and asid, EL0&1, instruction side only
1149          case MISCREG_ITLBIMVA:
1150            assert32(tc);
1151            target_el = 1; // el 0 and 1 are handled together
1152            scr = readMiscReg(MISCREG_SCR, tc);
1153            secure_lookup = haveSecurity && !scr.ns;
1154            getITBPtr(tc)->flushMvaAsid(mbits(newVal, 31, 12),
1155                bits(newVal, 7,0), secure_lookup, target_el);
1156            return;
1157          // TLBI by address and asid, EL0&1, data side only
1158          case MISCREG_DTLBIMVA:
1159            assert32(tc);
1160            target_el = 1; // el 0 and 1 are handled together
1161            scr = readMiscReg(MISCREG_SCR, tc);
1162            secure_lookup = haveSecurity && !scr.ns;
1163            getDTBPtr(tc)->flushMvaAsid(mbits(newVal, 31, 12),
1164                bits(newVal, 7,0), secure_lookup, target_el);
1165            return;
1166          // TLBI by ASID, EL0&1, instrution side only
1167          case MISCREG_ITLBIASID:
1168            assert32(tc);
1169            target_el = 1; // el 0 and 1 are handled together
1170            scr = readMiscReg(MISCREG_SCR, tc);
1171            secure_lookup = haveSecurity && !scr.ns;
1172            getITBPtr(tc)->flushAsid(bits(newVal, 7,0), secure_lookup,
1173                                       target_el);
1174            return;
1175          // TLBI by ASID EL0&1 data size only
1176          case MISCREG_DTLBIASID:
1177            assert32(tc);
1178            target_el = 1; // el 0 and 1 are handled together
1179            scr = readMiscReg(MISCREG_SCR, tc);
1180            secure_lookup = haveSecurity && !scr.ns;
1181            getDTBPtr(tc)->flushAsid(bits(newVal, 7,0), secure_lookup,
1182                                       target_el);
1183            return;
1184          // Invalidate entire Non-secure Hyp/Non-Hyp Unified TLB
1185          case MISCREG_TLBIALLNSNH:
1186          case MISCREG_TLBIALLNSNHIS:
1187            assert32(tc);
1188            target_el = 1; // el 0 and 1 are handled together
1189            hyp = 0;
1190            tlbiALLN(tc, hyp, target_el);
1191            return;
1192          // TLBI all entries, EL2, hyp,
1193          case MISCREG_TLBIALLH:
1194          case MISCREG_TLBIALLHIS:
1195            assert32(tc);
1196            target_el = 1; // aarch32, use hyp bit
1197            hyp = 1;
1198            tlbiALLN(tc, hyp, target_el);
1199            return;
1200          // AArch64 TLBI: invalidate all entries EL3
1201          case MISCREG_TLBI_ALLE3IS:
1202          case MISCREG_TLBI_ALLE3:
1203            assert64(tc);
1204            target_el = 3;
1205            secure_lookup = true;
1206            tlbiALL(tc, secure_lookup, target_el);
1207            return;
1208          // @todo: uncomment this to enable Virtualization
1209          // case MISCREG_TLBI_ALLE2IS:
1210          // case MISCREG_TLBI_ALLE2:
1211          // TLBI all entries, EL0&1
1212          case MISCREG_TLBI_ALLE1IS:
1213          case MISCREG_TLBI_ALLE1:
1214          // AArch64 TLBI: invalidate all entries, stage 1, current VMID
1215          case MISCREG_TLBI_VMALLE1IS:
1216          case MISCREG_TLBI_VMALLE1:
1217          // AArch64 TLBI: invalidate all entries, stages 1 & 2, current VMID
1218          case MISCREG_TLBI_VMALLS12E1IS:
1219          case MISCREG_TLBI_VMALLS12E1:
1220            // @todo: handle VMID and stage 2 to enable Virtualization
1221            assert64(tc);
1222            target_el = 1; // el 0 and 1 are handled together
1223            scr = readMiscReg(MISCREG_SCR, tc);
1224            secure_lookup = haveSecurity && !scr.ns;
1225            tlbiALL(tc, secure_lookup, target_el);
1226            return;
1227          // AArch64 TLBI: invalidate by VA and ASID, stage 1, current VMID
1228          // VAEx(IS) and VALEx(IS) are the same because TLBs only store entries
1229          // from the last level of translation table walks
1230          // @todo: handle VMID to enable Virtualization
1231          // TLBI all entries, EL0&1
1232          case MISCREG_TLBI_VAE3IS_Xt:
1233          case MISCREG_TLBI_VAE3_Xt:
1234          // TLBI by VA, EL3  regime stage 1, last level walk
1235          case MISCREG_TLBI_VALE3IS_Xt:
1236          case MISCREG_TLBI_VALE3_Xt:
1237            assert64(tc);
1238            target_el = 3;
1239            asid = 0xbeef; // does not matter, tlbi is global
1240            secure_lookup = true;
1241            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
1242            return;
1243          // TLBI by VA, EL2
1244          case MISCREG_TLBI_VAE2IS_Xt:
1245          case MISCREG_TLBI_VAE2_Xt:
1246          // TLBI by VA, EL2, stage1 last level walk
1247          case MISCREG_TLBI_VALE2IS_Xt:
1248          case MISCREG_TLBI_VALE2_Xt:
1249            assert64(tc);
1250            target_el = 2;
1251            asid = 0xbeef; // does not matter, tlbi is global
1252            scr = readMiscReg(MISCREG_SCR, tc);
1253            secure_lookup = haveSecurity && !scr.ns;
1254            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
1255            return;
1256          // TLBI by VA EL1 & 0, stage1, ASID, current VMID
1257          case MISCREG_TLBI_VAE1IS_Xt:
1258          case MISCREG_TLBI_VAE1_Xt:
1259          case MISCREG_TLBI_VALE1IS_Xt:
1260          case MISCREG_TLBI_VALE1_Xt:
1261            assert64(tc);
1262            asid = bits(newVal, 63, 48);
1263            target_el = 1; // el 0 and 1 are handled together
1264            scr = readMiscReg(MISCREG_SCR, tc);
1265            secure_lookup = haveSecurity && !scr.ns;
1266            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
1267            return;
1268          // AArch64 TLBI: invalidate by ASID, stage 1, current VMID
1269          // @todo: handle VMID to enable Virtualization
1270          case MISCREG_TLBI_ASIDE1IS_Xt:
1271          case MISCREG_TLBI_ASIDE1_Xt:
1272            assert64(tc);
1273            target_el = 1; // el 0 and 1 are handled together
1274            scr = readMiscReg(MISCREG_SCR, tc);
1275            secure_lookup = haveSecurity && !scr.ns;
1276            sys = tc->getSystemPtr();
1277            for (x = 0; x < sys->numContexts(); x++) {
1278                oc = sys->getThreadContext(x);
1279                asid = bits(newVal, 63, 48);
1280                if (!haveLargeAsid64)
1281                    asid &= mask(8);
1282                getITBPtr(oc)->flushAsid(asid, secure_lookup, target_el);
1283                getDTBPtr(oc)->flushAsid(asid, secure_lookup, target_el);
1284                CheckerCPU *checker = oc->getCheckerCpuPtr();
1285                if (checker) {
1286                    getITBPtr(checker)->flushAsid(asid,
1287                        secure_lookup, target_el);
1288                    getDTBPtr(checker)->flushAsid(asid,
1289                        secure_lookup, target_el);
1290                }
1291            }
1292            return;
1293          // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID
1294          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
1295          // entries from the last level of translation table walks
1296          // @todo: handle VMID to enable Virtualization
1297          case MISCREG_TLBI_VAAE1IS_Xt:
1298          case MISCREG_TLBI_VAAE1_Xt:
1299          case MISCREG_TLBI_VAALE1IS_Xt:
1300          case MISCREG_TLBI_VAALE1_Xt:
1301            assert64(tc);
1302            target_el = 1; // el 0 and 1 are handled together
1303            scr = readMiscReg(MISCREG_SCR, tc);
1304            secure_lookup = haveSecurity && !scr.ns;
1305            sys = tc->getSystemPtr();
1306            for (x = 0; x < sys->numContexts(); x++) {
1307                // @todo: extra controls on TLBI broadcast?
1308                oc = sys->getThreadContext(x);
1309                Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
1310                getITBPtr(oc)->flushMva(va,
1311                    secure_lookup, false, target_el);
1312                getDTBPtr(oc)->flushMva(va,
1313                    secure_lookup, false, target_el);
1314
1315                CheckerCPU *checker = oc->getCheckerCpuPtr();
1316                if (checker) {
1317                    getITBPtr(checker)->flushMva(va,
1318                        secure_lookup, false, target_el);
1319                    getDTBPtr(checker)->flushMva(va,
1320                        secure_lookup, false, target_el);
1321                }
1322            }
1323            return;
1324          // AArch64 TLBI: invalidate by IPA, stage 2, current VMID
1325          case MISCREG_TLBI_IPAS2LE1IS_Xt:
1326          case MISCREG_TLBI_IPAS2LE1_Xt:
1327          case MISCREG_TLBI_IPAS2E1IS_Xt:
1328          case MISCREG_TLBI_IPAS2E1_Xt:
1329            assert64(tc);
1330            target_el = 1; // EL 0 and 1 are handled together
1331            scr = readMiscReg(MISCREG_SCR, tc);
1332            secure_lookup = haveSecurity && !scr.ns;
1333            sys = tc->getSystemPtr();
1334            for (x = 0; x < sys->numContexts(); x++) {
1335                oc = sys->getThreadContext(x);
1336                Addr ipa = ((Addr) bits(newVal, 35, 0)) << 12;
1337                getITBPtr(oc)->flushIpaVmid(ipa,
1338                    secure_lookup, false, target_el);
1339                getDTBPtr(oc)->flushIpaVmid(ipa,
1340                    secure_lookup, false, target_el);
1341
1342                CheckerCPU *checker = oc->getCheckerCpuPtr();
1343                if (checker) {
1344                    getITBPtr(checker)->flushIpaVmid(ipa,
1345                        secure_lookup, false, target_el);
1346                    getDTBPtr(checker)->flushIpaVmid(ipa,
1347                        secure_lookup, false, target_el);
1348                }
1349            }
1350            return;
1351          case MISCREG_ACTLR:
1352            warn("Not doing anything for write of miscreg ACTLR\n");
1353            break;
1354
1355          case MISCREG_PMXEVTYPER_PMCCFILTR:
1356          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
1357          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
1358          case MISCREG_PMCR ... MISCREG_PMOVSSET:
1359            pmu->setMiscReg(misc_reg, newVal);
1360            break;
1361
1362
1363          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
1364            {
1365                HSTR hstrMask = 0;
1366                hstrMask.tjdbx = 1;
1367                newVal &= ~((uint32_t) hstrMask);
1368                break;
1369            }
1370          case MISCREG_HCPTR:
1371            {
1372                // If a CP bit in NSACR is 0 then the corresponding bit in
1373                // HCPTR is RAO/WI. Same applies to NSASEDIS
1374                secure_lookup = haveSecurity &&
1375                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
1376                                  readMiscRegNoEffect(MISCREG_CPSR));
1377                if (!secure_lookup) {
1378                    MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
1379                    MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
1380                    newVal = (newVal & ~mask) | (oldValue & mask);
1381                }
1382                break;
1383            }
1384          case MISCREG_HDFAR: // alias for secure DFAR
1385            misc_reg = MISCREG_DFAR_S;
1386            break;
1387          case MISCREG_HIFAR: // alias for secure IFAR
1388            misc_reg = MISCREG_IFAR_S;
1389            break;
1390          case MISCREG_ATS1CPR:
1391          case MISCREG_ATS1CPW:
1392          case MISCREG_ATS1CUR:
1393          case MISCREG_ATS1CUW:
1394          case MISCREG_ATS12NSOPR:
1395          case MISCREG_ATS12NSOPW:
1396          case MISCREG_ATS12NSOUR:
1397          case MISCREG_ATS12NSOUW:
1398          case MISCREG_ATS1HR:
1399          case MISCREG_ATS1HW:
1400            {
1401              Request::Flags flags = 0;
1402              BaseTLB::Mode mode = BaseTLB::Read;
1403              TLB::ArmTranslationType tranType = TLB::NormalTran;
1404              Fault fault;
1405              switch(misc_reg) {
1406                case MISCREG_ATS1CPR:
1407                  flags    = TLB::MustBeOne;
1408                  tranType = TLB::S1CTran;
1409                  mode     = BaseTLB::Read;
1410                  break;
1411                case MISCREG_ATS1CPW:
1412                  flags    = TLB::MustBeOne;
1413                  tranType = TLB::S1CTran;
1414                  mode     = BaseTLB::Write;
1415                  break;
1416                case MISCREG_ATS1CUR:
1417                  flags    = TLB::MustBeOne | TLB::UserMode;
1418                  tranType = TLB::S1CTran;
1419                  mode     = BaseTLB::Read;
1420                  break;
1421                case MISCREG_ATS1CUW:
1422                  flags    = TLB::MustBeOne | TLB::UserMode;
1423                  tranType = TLB::S1CTran;
1424                  mode     = BaseTLB::Write;
1425                  break;
1426                case MISCREG_ATS12NSOPR:
1427                  if (!haveSecurity)
1428                      panic("Security Extensions required for ATS12NSOPR");
1429                  flags    = TLB::MustBeOne;
1430                  tranType = TLB::S1S2NsTran;
1431                  mode     = BaseTLB::Read;
1432                  break;
1433                case MISCREG_ATS12NSOPW:
1434                  if (!haveSecurity)
1435                      panic("Security Extensions required for ATS12NSOPW");
1436                  flags    = TLB::MustBeOne;
1437                  tranType = TLB::S1S2NsTran;
1438                  mode     = BaseTLB::Write;
1439                  break;
1440                case MISCREG_ATS12NSOUR:
1441                  if (!haveSecurity)
1442                      panic("Security Extensions required for ATS12NSOUR");
1443                  flags    = TLB::MustBeOne | TLB::UserMode;
1444                  tranType = TLB::S1S2NsTran;
1445                  mode     = BaseTLB::Read;
1446                  break;
1447                case MISCREG_ATS12NSOUW:
1448                  if (!haveSecurity)
1449                      panic("Security Extensions required for ATS12NSOUW");
1450                  flags    = TLB::MustBeOne | TLB::UserMode;
1451                  tranType = TLB::S1S2NsTran;
1452                  mode     = BaseTLB::Write;
1453                  break;
1454                case MISCREG_ATS1HR: // only really useful from secure mode.
1455                  flags    = TLB::MustBeOne;
1456                  tranType = TLB::HypMode;
1457                  mode     = BaseTLB::Read;
1458                  break;
1459                case MISCREG_ATS1HW:
1460                  flags    = TLB::MustBeOne;
1461                  tranType = TLB::HypMode;
1462                  mode     = BaseTLB::Write;
1463                  break;
1464              }
1465              // If we're in timing mode then doing the translation in
1466              // functional mode then we're slightly distorting performance
1467              // results obtained from simulations. The translation should be
1468              // done in the same mode the core is running in. NOTE: This
1469              // can't be an atomic translation because that causes problems
1470              // with unexpected atomic snoop requests.
1471              warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
1472              Request req(0, val, 0, flags,  Request::funcMasterId,
1473                          tc->pcState().pc(), tc->contextId());
1474              fault = getDTBPtr(tc)->translateFunctional(
1475                      &req, tc, mode, tranType);
1476              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1477              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
1478
1479              MiscReg newVal;
1480              if (fault == NoFault) {
1481                  Addr paddr = req.getPaddr();
1482                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
1483                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
1484                      newVal = (paddr & mask(39, 12)) |
1485                               (getDTBPtr(tc)->getAttr());
1486                  } else {
1487                      newVal = (paddr & 0xfffff000) |
1488                               (getDTBPtr(tc)->getAttr());
1489                  }
1490                  DPRINTF(MiscRegs,
1491                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
1492                          val, newVal);
1493              } else {
1494                  ArmFault *armFault = static_cast<ArmFault *>(fault.get());
1495                  armFault->update(tc);
1496                  // Set fault bit and FSR
1497                  FSR fsr = armFault->getFsr(tc);
1498
1499                  newVal = ((fsr >> 9) & 1) << 11;
1500                  if (newVal) {
1501                    // LPAE - rearange fault status
1502                    newVal |= ((fsr >>  0) & 0x3f) << 1;
1503                  } else {
1504                    // VMSA - rearange fault status
1505                    newVal |= ((fsr >>  0) & 0xf) << 1;
1506                    newVal |= ((fsr >> 10) & 0x1) << 5;
1507                    newVal |= ((fsr >> 12) & 0x1) << 6;
1508                  }
1509                  newVal |= 0x1; // F bit
1510                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1511                  newVal |= armFault->isStage2() ? 0x200 : 0;
1512                  DPRINTF(MiscRegs,
1513                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
1514                          val, fsr, newVal);
1515              }
1516              setMiscRegNoEffect(MISCREG_PAR, newVal);
1517              return;
1518            }
1519          case MISCREG_TTBCR:
1520            {
1521                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1522                const uint32_t ones = (uint32_t)(-1);
1523                TTBCR ttbcrMask = 0;
1524                TTBCR ttbcrNew = newVal;
1525
1526                // ARM DDI 0406C.b, ARMv7-32
1527                ttbcrMask.n = ones; // T0SZ
1528                if (haveSecurity) {
1529                    ttbcrMask.pd0 = ones;
1530                    ttbcrMask.pd1 = ones;
1531                }
1532                ttbcrMask.epd0 = ones;
1533                ttbcrMask.irgn0 = ones;
1534                ttbcrMask.orgn0 = ones;
1535                ttbcrMask.sh0 = ones;
1536                ttbcrMask.ps = ones; // T1SZ
1537                ttbcrMask.a1 = ones;
1538                ttbcrMask.epd1 = ones;
1539                ttbcrMask.irgn1 = ones;
1540                ttbcrMask.orgn1 = ones;
1541                ttbcrMask.sh1 = ones;
1542                if (haveLPAE)
1543                    ttbcrMask.eae = ones;
1544
1545                if (haveLPAE && ttbcrNew.eae) {
1546                    newVal = newVal & ttbcrMask;
1547                } else {
1548                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
1549                }
1550            }
1551            M5_FALLTHROUGH;
1552          case MISCREG_TTBR0:
1553          case MISCREG_TTBR1:
1554            {
1555                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1556                if (haveLPAE) {
1557                    if (ttbcr.eae) {
1558                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
1559                        // ARMv8 AArch32 bit 63-56 only
1560                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
1561                        newVal = (newVal & (~ttbrMask));
1562                    }
1563                }
1564            }
1565            M5_FALLTHROUGH;
1566          case MISCREG_SCTLR_EL1:
1567            {
1568                getITBPtr(tc)->invalidateMiscReg();
1569                getDTBPtr(tc)->invalidateMiscReg();
1570                setMiscRegNoEffect(misc_reg, newVal);
1571            }
1572            M5_FALLTHROUGH;
1573          case MISCREG_CONTEXTIDR:
1574          case MISCREG_PRRR:
1575          case MISCREG_NMRR:
1576          case MISCREG_MAIR0:
1577          case MISCREG_MAIR1:
1578          case MISCREG_DACR:
1579          case MISCREG_VTTBR:
1580          case MISCREG_SCR_EL3:
1581          case MISCREG_HCR_EL2:
1582          case MISCREG_TCR_EL1:
1583          case MISCREG_TCR_EL2:
1584          case MISCREG_TCR_EL3:
1585          case MISCREG_SCTLR_EL2:
1586          case MISCREG_SCTLR_EL3:
1587          case MISCREG_HSCTLR:
1588          case MISCREG_TTBR0_EL1:
1589          case MISCREG_TTBR1_EL1:
1590          case MISCREG_TTBR0_EL2:
1591          case MISCREG_TTBR0_EL3:
1592            getITBPtr(tc)->invalidateMiscReg();
1593            getDTBPtr(tc)->invalidateMiscReg();
1594            break;
1595          case MISCREG_NZCV:
1596            {
1597                CPSR cpsr = val;
1598
1599                tc->setCCReg(CCREG_NZ, cpsr.nz);
1600                tc->setCCReg(CCREG_C,  cpsr.c);
1601                tc->setCCReg(CCREG_V,  cpsr.v);
1602            }
1603            break;
1604          case MISCREG_DAIF:
1605            {
1606                CPSR cpsr = miscRegs[MISCREG_CPSR];
1607                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
1608                newVal = cpsr;
1609                misc_reg = MISCREG_CPSR;
1610            }
1611            break;
1612          case MISCREG_SP_EL0:
1613            tc->setIntReg(INTREG_SP0, newVal);
1614            break;
1615          case MISCREG_SP_EL1:
1616            tc->setIntReg(INTREG_SP1, newVal);
1617            break;
1618          case MISCREG_SP_EL2:
1619            tc->setIntReg(INTREG_SP2, newVal);
1620            break;
1621          case MISCREG_SPSEL:
1622            {
1623                CPSR cpsr = miscRegs[MISCREG_CPSR];
1624                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
1625                newVal = cpsr;
1626                misc_reg = MISCREG_CPSR;
1627            }
1628            break;
1629          case MISCREG_CURRENTEL:
1630            {
1631                CPSR cpsr = miscRegs[MISCREG_CPSR];
1632                cpsr.el = (uint8_t) ((CPSR) newVal).el;
1633                newVal = cpsr;
1634                misc_reg = MISCREG_CPSR;
1635            }
1636            break;
1637          case MISCREG_AT_S1E1R_Xt:
1638          case MISCREG_AT_S1E1W_Xt:
1639          case MISCREG_AT_S1E0R_Xt:
1640          case MISCREG_AT_S1E0W_Xt:
1641          case MISCREG_AT_S1E2R_Xt:
1642          case MISCREG_AT_S1E2W_Xt:
1643          case MISCREG_AT_S12E1R_Xt:
1644          case MISCREG_AT_S12E1W_Xt:
1645          case MISCREG_AT_S12E0R_Xt:
1646          case MISCREG_AT_S12E0W_Xt:
1647          case MISCREG_AT_S1E3R_Xt:
1648          case MISCREG_AT_S1E3W_Xt:
1649            {
1650                RequestPtr req = new Request;
1651                Request::Flags flags = 0;
1652                BaseTLB::Mode mode = BaseTLB::Read;
1653                TLB::ArmTranslationType tranType = TLB::NormalTran;
1654                Fault fault;
1655                switch(misc_reg) {
1656                  case MISCREG_AT_S1E1R_Xt:
1657                    flags    = TLB::MustBeOne;
1658                    tranType = TLB::S1E1Tran;
1659                    mode     = BaseTLB::Read;
1660                    break;
1661                  case MISCREG_AT_S1E1W_Xt:
1662                    flags    = TLB::MustBeOne;
1663                    tranType = TLB::S1E1Tran;
1664                    mode     = BaseTLB::Write;
1665                    break;
1666                  case MISCREG_AT_S1E0R_Xt:
1667                    flags    = TLB::MustBeOne | TLB::UserMode;
1668                    tranType = TLB::S1E0Tran;
1669                    mode     = BaseTLB::Read;
1670                    break;
1671                  case MISCREG_AT_S1E0W_Xt:
1672                    flags    = TLB::MustBeOne | TLB::UserMode;
1673                    tranType = TLB::S1E0Tran;
1674                    mode     = BaseTLB::Write;
1675                    break;
1676                  case MISCREG_AT_S1E2R_Xt:
1677                    flags    = TLB::MustBeOne;
1678                    tranType = TLB::S1E2Tran;
1679                    mode     = BaseTLB::Read;
1680                    break;
1681                  case MISCREG_AT_S1E2W_Xt:
1682                    flags    = TLB::MustBeOne;
1683                    tranType = TLB::S1E2Tran;
1684                    mode     = BaseTLB::Write;
1685                    break;
1686                  case MISCREG_AT_S12E0R_Xt:
1687                    flags    = TLB::MustBeOne | TLB::UserMode;
1688                    tranType = TLB::S12E0Tran;
1689                    mode     = BaseTLB::Read;
1690                    break;
1691                  case MISCREG_AT_S12E0W_Xt:
1692                    flags    = TLB::MustBeOne | TLB::UserMode;
1693                    tranType = TLB::S12E0Tran;
1694                    mode     = BaseTLB::Write;
1695                    break;
1696                  case MISCREG_AT_S12E1R_Xt:
1697                    flags    = TLB::MustBeOne;
1698                    tranType = TLB::S12E1Tran;
1699                    mode     = BaseTLB::Read;
1700                    break;
1701                  case MISCREG_AT_S12E1W_Xt:
1702                    flags    = TLB::MustBeOne;
1703                    tranType = TLB::S12E1Tran;
1704                    mode     = BaseTLB::Write;
1705                    break;
1706                  case MISCREG_AT_S1E3R_Xt:
1707                    flags    = TLB::MustBeOne;
1708                    tranType = TLB::S1E3Tran;
1709                    mode     = BaseTLB::Read;
1710                    break;
1711                  case MISCREG_AT_S1E3W_Xt:
1712                    flags    = TLB::MustBeOne;
1713                    tranType = TLB::S1E3Tran;
1714                    mode     = BaseTLB::Write;
1715                    break;
1716                }
1717                // If we're in timing mode then doing the translation in
1718                // functional mode then we're slightly distorting performance
1719                // results obtained from simulations. The translation should be
1720                // done in the same mode the core is running in. NOTE: This
1721                // can't be an atomic translation because that causes problems
1722                // with unexpected atomic snoop requests.
1723                warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
1724                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
1725                               tc->pcState().pc());
1726                req->setContext(tc->contextId());
1727                fault = getDTBPtr(tc)->translateFunctional(req, tc, mode,
1728                                                           tranType);
1729
1730                MiscReg newVal;
1731                if (fault == NoFault) {
1732                    Addr paddr = req->getPaddr();
1733                    uint64_t attr = getDTBPtr(tc)->getAttr();
1734                    uint64_t attr1 = attr >> 56;
1735                    if (!attr1 || attr1 ==0x44) {
1736                        attr |= 0x100;
1737                        attr &= ~ uint64_t(0x80);
1738                    }
1739                    newVal = (paddr & mask(47, 12)) | attr;
1740                    DPRINTF(MiscRegs,
1741                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
1742                          val, newVal);
1743                } else {
1744                    ArmFault *armFault = static_cast<ArmFault *>(fault.get());
1745                    armFault->update(tc);
1746                    // Set fault bit and FSR
1747                    FSR fsr = armFault->getFsr(tc);
1748
1749                    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
1750                    if (cpsr.width) { // AArch32
1751                        newVal = ((fsr >> 9) & 1) << 11;
1752                        // rearrange fault status
1753                        newVal |= ((fsr >>  0) & 0x3f) << 1;
1754                        newVal |= 0x1; // F bit
1755                        newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1756                        newVal |= armFault->isStage2() ? 0x200 : 0;
1757                    } else { // AArch64
1758                        newVal = 1; // F bit
1759                        newVal |= fsr << 1; // FST
1760                        // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
1761                        newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
1762                        newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
1763                        newVal |= 1 << 11; // RES1
1764                    }
1765                    DPRINTF(MiscRegs,
1766                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
1767                            val, fsr, newVal);
1768                }
1769                delete req;
1770                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
1771                return;
1772            }
1773          case MISCREG_SPSR_EL3:
1774          case MISCREG_SPSR_EL2:
1775          case MISCREG_SPSR_EL1:
1776            // Force bits 23:21 to 0
1777            newVal = val & ~(0x7 << 21);
1778            break;
1779          case MISCREG_L2CTLR:
1780            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
1781                 miscRegName[misc_reg], uint32_t(val));
1782            break;
1783
1784          // Generic Timer registers
1785          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
1786          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
1787          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
1788          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
1789            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
1790            break;
1791        }
1792    }
1793    setMiscRegNoEffect(misc_reg, newVal);
1794}
1795
1796void
1797ISA::tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid,
1798            bool secure_lookup, uint8_t target_el)
1799{
1800    if (!haveLargeAsid64)
1801        asid &= mask(8);
1802    Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
1803    System *sys = tc->getSystemPtr();
1804    for (int x = 0; x < sys->numContexts(); x++) {
1805        ThreadContext *oc = sys->getThreadContext(x);
1806        getITBPtr(oc)->flushMvaAsid(va, asid,
1807                                      secure_lookup, target_el);
1808        getDTBPtr(oc)->flushMvaAsid(va, asid,
1809                                      secure_lookup, target_el);
1810
1811        CheckerCPU *checker = oc->getCheckerCpuPtr();
1812        if (checker) {
1813            getITBPtr(checker)->flushMvaAsid(
1814                va, asid, secure_lookup, target_el);
1815            getDTBPtr(checker)->flushMvaAsid(
1816                va, asid, secure_lookup, target_el);
1817        }
1818    }
1819}
1820
1821void
1822ISA::tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el)
1823{
1824    System *sys = tc->getSystemPtr();
1825    for (int x = 0; x < sys->numContexts(); x++) {
1826        ThreadContext *oc = sys->getThreadContext(x);
1827        getITBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
1828        getDTBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
1829
1830        // If CheckerCPU is connected, need to notify it of a flush
1831        CheckerCPU *checker = oc->getCheckerCpuPtr();
1832        if (checker) {
1833            getITBPtr(checker)->flushAllSecurity(secure_lookup,
1834                                                   target_el);
1835            getDTBPtr(checker)->flushAllSecurity(secure_lookup,
1836                                                   target_el);
1837        }
1838    }
1839}
1840
1841void
1842ISA::tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el)
1843{
1844    System *sys = tc->getSystemPtr();
1845    for (int x = 0; x < sys->numContexts(); x++) {
1846      ThreadContext *oc = sys->getThreadContext(x);
1847      getITBPtr(oc)->flushAllNs(hyp, target_el);
1848      getDTBPtr(oc)->flushAllNs(hyp, target_el);
1849
1850      CheckerCPU *checker = oc->getCheckerCpuPtr();
1851      if (checker) {
1852          getITBPtr(checker)->flushAllNs(hyp, target_el);
1853          getDTBPtr(checker)->flushAllNs(hyp, target_el);
1854      }
1855    }
1856}
1857
1858void
1859ISA::tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, bool hyp,
1860             uint8_t target_el)
1861{
1862    System *sys = tc->getSystemPtr();
1863    for (int x = 0; x < sys->numContexts(); x++) {
1864        ThreadContext *oc = sys->getThreadContext(x);
1865        getITBPtr(oc)->flushMva(mbits(newVal, 31,12),
1866            secure_lookup, hyp, target_el);
1867        getDTBPtr(oc)->flushMva(mbits(newVal, 31,12),
1868            secure_lookup, hyp, target_el);
1869
1870        CheckerCPU *checker = oc->getCheckerCpuPtr();
1871        if (checker) {
1872            getITBPtr(checker)->flushMva(mbits(newVal, 31,12),
1873                secure_lookup, hyp, target_el);
1874            getDTBPtr(checker)->flushMva(mbits(newVal, 31,12),
1875                secure_lookup, hyp, target_el);
1876        }
1877    }
1878}
1879
1880BaseISADevice &
1881ISA::getGenericTimer(ThreadContext *tc)
1882{
1883    // We only need to create an ISA interface the first time we try
1884    // to access the timer.
1885    if (timer)
1886        return *timer.get();
1887
1888    assert(system);
1889    GenericTimer *generic_timer(system->getGenericTimer());
1890    if (!generic_timer) {
1891        panic("Trying to get a generic timer from a system that hasn't "
1892              "been configured to use a generic timer.\n");
1893    }
1894
1895    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
1896    return *timer.get();
1897}
1898
1899}
1900
1901ArmISA::ISA *
1902ArmISAParams::create()
1903{
1904    return new ArmISA::ISA(this);
1905}
1906