isa.cc revision 11574
12810SN/A/*
210764Sandreas.hansson@arm.com * Copyright (c) 2010-2016 ARM Limited
39663Suri.wiener@arm.com * All rights reserved
49663Suri.wiener@arm.com *
59663Suri.wiener@arm.com * The license below extends only to copyright in the software and shall
69663Suri.wiener@arm.com * not be construed as granting a license to any other intellectual
79663Suri.wiener@arm.com * property including but not limited to intellectual property relating
89663Suri.wiener@arm.com * to a hardware implementation of the functionality of the software
99663Suri.wiener@arm.com * licensed hereunder.  You may use the software subject to the license
109663Suri.wiener@arm.com * terms below provided that you ensure that this notice is replicated
119663Suri.wiener@arm.com * unmodified and in its entirety in all distributions of the software,
129663Suri.wiener@arm.com * modified or unmodified, in source code or in binary form.
139663Suri.wiener@arm.com *
142810SN/A * Redistribution and use in source and binary forms, with or without
157636Ssteve.reinhardt@amd.com * modification, are permitted provided that the following conditions are
162810SN/A * met: redistributions of source code must retain the above copyright
172810SN/A * notice, this list of conditions and the following disclaimer;
182810SN/A * redistributions in binary form must reproduce the above copyright
192810SN/A * notice, this list of conditions and the following disclaimer in the
202810SN/A * documentation and/or other materials provided with the distribution;
212810SN/A * neither the name of the copyright holders nor the names of its
222810SN/A * contributors may be used to endorse or promote products derived from
232810SN/A * this software without specific prior written permission.
242810SN/A *
252810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
262810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
272810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
282810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
292810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
302810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
312810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
322810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
332810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
342810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
352810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
362810SN/A *
372810SN/A * Authors: Gabe Black
382810SN/A *          Ali Saidi
392810SN/A */
402810SN/A
412810SN/A#include "arch/arm/isa.hh"
422810SN/A#include "arch/arm/pmu.hh"
432810SN/A#include "arch/arm/system.hh"
442810SN/A#include "cpu/checker/cpu.hh"
452810SN/A#include "cpu/base.hh"
462810SN/A#include "debug/Arm.hh"
472810SN/A#include "debug/MiscRegs.hh"
482810SN/A#include "dev/arm/generic_timer.hh"
492810SN/A#include "params/ArmISA.hh"
506216Snate@binkert.org#include "sim/faults.hh"
516216Snate@binkert.org#include "sim/stat_control.hh"
522810SN/A#include "sim/system.hh"
532810SN/A
542810SN/Anamespace ArmISA
556216Snate@binkert.org{
566216Snate@binkert.org
578232Snate@binkert.org
586216Snate@binkert.org/**
595338Sstever@gmail.com * Some registers aliase with others, and therefore need to be translated.
606216Snate@binkert.org * For each entry:
612810SN/A * The first value is the misc register that is to be looked up
622810SN/A * the second value is the lower part of the translation
632810SN/A * the third the upper part
649725Sandreas.hansson@arm.com */
6510582SCurtis.Dunham@arm.comconst struct ISA::MiscRegInitializerEntry
6610503SCurtis.Dunham@arm.com    ISA::MiscRegSwitch[miscRegTranslateMax] = {
6710764Sandreas.hansson@arm.com    {MISCREG_CSSELR_EL1, {MISCREG_CSSELR, 0}},
6810764Sandreas.hansson@arm.com    {MISCREG_SCTLR_EL1, {MISCREG_SCTLR, 0}},
6910503SCurtis.Dunham@arm.com    {MISCREG_SCTLR_EL2, {MISCREG_HSCTLR, 0}},
702810SN/A    {MISCREG_ACTLR_EL1, {MISCREG_ACTLR, 0}},
712810SN/A    {MISCREG_ACTLR_EL2, {MISCREG_HACTLR, 0}},
722810SN/A    {MISCREG_CPACR_EL1, {MISCREG_CPACR, 0}},
734903SN/A    {MISCREG_CPTR_EL2, {MISCREG_HCPTR, 0}},
744903SN/A    {MISCREG_HCR_EL2, {MISCREG_HCR, 0}},
754903SN/A    {MISCREG_MDCR_EL2, {MISCREG_HDCR, 0}},
764903SN/A    {MISCREG_HSTR_EL2, {MISCREG_HSTR, 0}},
774903SN/A    {MISCREG_HACR_EL2, {MISCREG_HACR, 0}},
784903SN/A    {MISCREG_TTBR0_EL1, {MISCREG_TTBR0, 0}},
794903SN/A    {MISCREG_TTBR1_EL1, {MISCREG_TTBR1, 0}},
804908SN/A    {MISCREG_TTBR0_EL2, {MISCREG_HTTBR, 0}},
815875Ssteve.reinhardt@amd.com    {MISCREG_VTTBR_EL2, {MISCREG_VTTBR, 0}},
824903SN/A    {MISCREG_TCR_EL1, {MISCREG_TTBCR, 0}},
835875Ssteve.reinhardt@amd.com    {MISCREG_TCR_EL2, {MISCREG_HTCR, 0}},
844903SN/A    {MISCREG_VTCR_EL2, {MISCREG_VTCR, 0}},
854903SN/A    {MISCREG_AFSR0_EL1, {MISCREG_ADFSR, 0}},
864903SN/A    {MISCREG_AFSR1_EL1, {MISCREG_AIFSR, 0}},
874903SN/A    {MISCREG_AFSR0_EL2, {MISCREG_HADFSR, 0}},
887669Ssteve.reinhardt@amd.com    {MISCREG_AFSR1_EL2, {MISCREG_HAIFSR, 0}},
897669Ssteve.reinhardt@amd.com    {MISCREG_ESR_EL2, {MISCREG_HSR, 0}},
907669Ssteve.reinhardt@amd.com    {MISCREG_FAR_EL1, {MISCREG_DFAR, MISCREG_IFAR}},
917669Ssteve.reinhardt@amd.com    {MISCREG_FAR_EL2, {MISCREG_HDFAR, MISCREG_HIFAR}},
924903SN/A    {MISCREG_HPFAR_EL2, {MISCREG_HPFAR, 0}},
934903SN/A    {MISCREG_PAR_EL1, {MISCREG_PAR, 0}},
945318SN/A    {MISCREG_MAIR_EL1, {MISCREG_PRRR, MISCREG_NMRR}},
954908SN/A    {MISCREG_MAIR_EL2, {MISCREG_HMAIR0, MISCREG_HMAIR1}},
965318SN/A    {MISCREG_AMAIR_EL1, {MISCREG_AMAIR0, MISCREG_AMAIR1}},
979543Ssascha.bischoff@arm.com    {MISCREG_VBAR_EL1, {MISCREG_VBAR, 0}},
989543Ssascha.bischoff@arm.com    {MISCREG_VBAR_EL2, {MISCREG_HVBAR, 0}},
999543Ssascha.bischoff@arm.com    {MISCREG_CONTEXTIDR_EL1, {MISCREG_CONTEXTIDR, 0}},
1009543Ssascha.bischoff@arm.com    {MISCREG_TPIDR_EL0, {MISCREG_TPIDRURW, 0}},
1014908SN/A    {MISCREG_TPIDRRO_EL0, {MISCREG_TPIDRURO, 0}},
1024908SN/A    {MISCREG_TPIDR_EL1, {MISCREG_TPIDRPRW, 0}},
1034908SN/A    {MISCREG_TPIDR_EL2, {MISCREG_HTPIDR, 0}},
1044908SN/A    {MISCREG_TEECR32_EL1, {MISCREG_TEECR, 0}},
1054903SN/A    {MISCREG_CNTFRQ_EL0, {MISCREG_CNTFRQ, 0}},
1064903SN/A    {MISCREG_CNTPCT_EL0, {MISCREG_CNTPCT, 0}},
1075875Ssteve.reinhardt@amd.com    {MISCREG_CNTVCT_EL0, {MISCREG_CNTVCT, 0}},
1084903SN/A    {MISCREG_CNTVOFF_EL2, {MISCREG_CNTVOFF, 0}},
1094903SN/A    {MISCREG_CNTKCTL_EL1, {MISCREG_CNTKCTL, 0}},
1104903SN/A    {MISCREG_CNTHCTL_EL2, {MISCREG_CNTHCTL, 0}},
1117667Ssteve.reinhardt@amd.com    {MISCREG_CNTP_TVAL_EL0, {MISCREG_CNTP_TVAL, 0}},
1127667Ssteve.reinhardt@amd.com    {MISCREG_CNTP_CTL_EL0, {MISCREG_CNTP_CTL, 0}},
1137667Ssteve.reinhardt@amd.com    {MISCREG_CNTP_CVAL_EL0, {MISCREG_CNTP_CVAL, 0}},
1147667Ssteve.reinhardt@amd.com    {MISCREG_CNTV_TVAL_EL0, {MISCREG_CNTV_TVAL, 0}},
1157667Ssteve.reinhardt@amd.com    {MISCREG_CNTV_CTL_EL0, {MISCREG_CNTV_CTL, 0}},
1167667Ssteve.reinhardt@amd.com    {MISCREG_CNTV_CVAL_EL0, {MISCREG_CNTV_CVAL, 0}},
1177667Ssteve.reinhardt@amd.com    {MISCREG_CNTHP_TVAL_EL2, {MISCREG_CNTHP_TVAL, 0}},
1187667Ssteve.reinhardt@amd.com    {MISCREG_CNTHP_CTL_EL2, {MISCREG_CNTHP_CTL, 0}},
1197667Ssteve.reinhardt@amd.com    {MISCREG_CNTHP_CVAL_EL2, {MISCREG_CNTHP_CVAL, 0}},
1207669Ssteve.reinhardt@amd.com    {MISCREG_DACR32_EL2, {MISCREG_DACR, 0}},
1217669Ssteve.reinhardt@amd.com    {MISCREG_IFSR32_EL2, {MISCREG_IFSR, 0}},
1227669Ssteve.reinhardt@amd.com    {MISCREG_TEEHBR32_EL1, {MISCREG_TEEHBR, 0}},
1237667Ssteve.reinhardt@amd.com    {MISCREG_SDER32_EL3, {MISCREG_SDER, 0}}
1247667Ssteve.reinhardt@amd.com};
1257667Ssteve.reinhardt@amd.com
1267667Ssteve.reinhardt@amd.com
1274903SN/AISA::ISA(Params *p)
1284903SN/A    : SimObject(p),
1294903SN/A      system(NULL),
1304903SN/A      _decoderFlavour(p->decoderFlavour),
1314903SN/A      pmu(p->pmu),
1324903SN/A      lookUpMiscReg(NUM_MISCREGS, {0,0})
1334903SN/A{
1344903SN/A    SCTLR sctlr;
1357667Ssteve.reinhardt@amd.com    sctlr = 0;
1364903SN/A    miscRegs[MISCREG_SCTLR_RST] = sctlr;
1374903SN/A
1384903SN/A    // Hook up a dummy device if we haven't been configured with a
1394903SN/A    // real PMU. By using a dummy device, we don't need to check that
1404903SN/A    // the PMU exist every time we try to access a PMU register.
1414903SN/A    if (!pmu)
1422810SN/A        pmu = &dummyDevice;
1434908SN/A
1444908SN/A    // Give all ISA devices a pointer to this ISA
1454908SN/A    pmu->setISA(this);
1464908SN/A
1475318SN/A    system = dynamic_cast<ArmSystem *>(p->system);
1489543Ssascha.bischoff@arm.com
1499543Ssascha.bischoff@arm.com    // Cache system-level properties
1509543Ssascha.bischoff@arm.com    if (FullSystem && system) {
1519543Ssascha.bischoff@arm.com        haveSecurity = system->haveSecurity();
1529543Ssascha.bischoff@arm.com        haveLPAE = system->haveLPAE();
1539543Ssascha.bischoff@arm.com        haveVirtualization = system->haveVirtualization();
1549543Ssascha.bischoff@arm.com        haveLargeAsid64 = system->haveLargeAsid64();
1555318SN/A        physAddrRange64 = system->physAddrRange64();
1565318SN/A    } else {
1575318SN/A        haveSecurity = haveLPAE = haveVirtualization = false;
1584908SN/A        haveLargeAsid64 = false;
1594908SN/A        physAddrRange64 = 32;  // dummy value
1604908SN/A    }
1614908SN/A
1624908SN/A    /** Fill in the miscReg translation table */
1634920SN/A    for (uint32_t i = 0; i < miscRegTranslateMax; i++) {
1644920SN/A        struct MiscRegLUTEntry new_entry;
1654920SN/A
1664920SN/A        uint32_t select = MiscRegSwitch[i].index;
1674920SN/A        new_entry = MiscRegSwitch[i].entry;
1684920SN/A
1694920SN/A        lookUpMiscReg[select] = new_entry;
1704920SN/A    }
1714920SN/A
1724920SN/A    preUnflattenMiscReg();
1734920SN/A
1744920SN/A    clear();
1754920SN/A}
1764920SN/A
1774908SN/Aconst ArmISAParams *
1785314SN/AISA::params() const
1795314SN/A{
1805314SN/A    return dynamic_cast<const Params *>(_params);
1815314SN/A}
1825314SN/A
1835875Ssteve.reinhardt@amd.comvoid
1845875Ssteve.reinhardt@amd.comISA::clear()
1858988SAli.Saidi@ARM.com{
1868988SAli.Saidi@ARM.com    const Params *p(params());
1878988SAli.Saidi@ARM.com
1888988SAli.Saidi@ARM.com    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
1898988SAli.Saidi@ARM.com    memset(miscRegs, 0, sizeof(miscRegs));
1908988SAli.Saidi@ARM.com
1918988SAli.Saidi@ARM.com    // Initialize configurable default values
1928988SAli.Saidi@ARM.com    miscRegs[MISCREG_MIDR] = p->midr;
1938988SAli.Saidi@ARM.com    miscRegs[MISCREG_MIDR_EL1] = p->midr;
1948988SAli.Saidi@ARM.com    miscRegs[MISCREG_VPIDR] = p->midr;
1958988SAli.Saidi@ARM.com
1968988SAli.Saidi@ARM.com    if (FullSystem && system->highestELIs64()) {
1975875Ssteve.reinhardt@amd.com        // Initialize AArch64 state
1985875Ssteve.reinhardt@amd.com        clear64(p);
1995314SN/A        return;
2005314SN/A    }
2015314SN/A
2025314SN/A    // Initialize AArch32 state...
2035314SN/A
2045314SN/A    CPSR cpsr = 0;
20510764Sandreas.hansson@arm.com    cpsr.mode = MODE_USER;
20610764Sandreas.hansson@arm.com    miscRegs[MISCREG_CPSR] = cpsr;
2072810SN/A    updateRegMap(cpsr);
20810764Sandreas.hansson@arm.com
20910764Sandreas.hansson@arm.com    SCTLR sctlr = 0;
21010028SGiacomo.Gabrielli@arm.com    sctlr.te = (bool) sctlr_rst.te;
21110764Sandreas.hansson@arm.com    sctlr.nmfi = (bool) sctlr_rst.nmfi;
2124666SN/A    sctlr.v = (bool) sctlr_rst.v;
2134626SN/A    sctlr.u = 1;
2145730SSteve.Reinhardt@amd.com    sctlr.xp = 1;
2154626SN/A    sctlr.rao2 = 1;
2164626SN/A    sctlr.rao3 = 1;
2174908SN/A    sctlr.rao4 = 0xf;  // SCTLR[6:3]
2184626SN/A    sctlr.uci = 1;
2199725Sandreas.hansson@arm.com    sctlr.dze = 1;
2204626SN/A    miscRegs[MISCREG_SCTLR_NS] = sctlr;
2215875Ssteve.reinhardt@amd.com    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
2225875Ssteve.reinhardt@amd.com    miscRegs[MISCREG_HCPTR] = 0;
2235875Ssteve.reinhardt@amd.com
22410764Sandreas.hansson@arm.com    // Start with an event in the mailbox
2259725Sandreas.hansson@arm.com    miscRegs[MISCREG_SEV_MAILBOX] = 1;
2264668SN/A
2272810SN/A    // Separate Instruction and Data TLBs
2282810SN/A    miscRegs[MISCREG_TLBTR] = 1;
2294908SN/A
2305318SN/A    MVFR0 mvfr0 = 0;
2315318SN/A    mvfr0.advSimdRegisters = 2;
2325318SN/A    mvfr0.singlePrecision = 2;
2335318SN/A    mvfr0.doublePrecision = 2;
2345318SN/A    mvfr0.vfpExceptionTrapping = 0;
2355318SN/A    mvfr0.divide = 1;
2365318SN/A    mvfr0.squareRoot = 1;
2379725Sandreas.hansson@arm.com    mvfr0.shortVectors = 1;
2385318SN/A    mvfr0.roundingModes = 1;
2395318SN/A    miscRegs[MISCREG_MVFR0] = mvfr0;
2404908SN/A
24110679Sandreas.hansson@arm.com    MVFR1 mvfr1 = 0;
2424908SN/A    mvfr1.flushToZero = 1;
2434908SN/A    mvfr1.defaultNaN = 1;
2445730SSteve.Reinhardt@amd.com    mvfr1.advSimdLoadStore = 1;
2454908SN/A    mvfr1.advSimdInteger = 1;
2464908SN/A    mvfr1.advSimdSinglePrecision = 1;
2474908SN/A    mvfr1.advSimdHalfPrecision = 1;
2484908SN/A    mvfr1.vfpHalfPrecision = 1;
2494908SN/A    miscRegs[MISCREG_MVFR1] = mvfr1;
2504908SN/A
25110424Sandreas.hansson@arm.com    // Reset values of PRRR and NMRR are implementation dependent
2524908SN/A
25310679Sandreas.hansson@arm.com    // @todo: PRRR and NMRR in secure state?
2547667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_PRRR_NS] =
2557667Ssteve.reinhardt@amd.com        (1 << 19) | // 19
2564908SN/A        (0 << 18) | // 18
2574908SN/A        (0 << 17) | // 17
2584908SN/A        (1 << 16) | // 16
2599725Sandreas.hansson@arm.com        (2 << 14) | // 15:14
2604908SN/A        (0 << 12) | // 13:12
2614908SN/A        (2 << 10) | // 11:10
2624908SN/A        (2 << 8)  | // 9:8
2634908SN/A        (2 << 6)  | // 7:6
2644908SN/A        (2 << 4)  | // 5:4
2652810SN/A        (1 << 2)  | // 3:2
2662810SN/A        0;          // 1:0
2672810SN/A    miscRegs[MISCREG_NMRR_NS] =
2689725Sandreas.hansson@arm.com        (1 << 30) | // 31:30
2699725Sandreas.hansson@arm.com        (0 << 26) | // 27:26
2709725Sandreas.hansson@arm.com        (0 << 24) | // 25:24
2712810SN/A        (3 << 22) | // 23:22
2722810SN/A        (2 << 20) | // 21:20
2732810SN/A        (0 << 18) | // 19:18
2742810SN/A        (0 << 16) | // 17:16
2752810SN/A        (1 << 14) | // 15:14
2762810SN/A        (0 << 12) | // 13:12
2772810SN/A        (2 << 10) | // 11:10
2784903SN/A        (0 << 8)  | // 9:8
2792810SN/A        (3 << 6)  | // 7:6
2804903SN/A        (2 << 4)  | // 5:4
2814903SN/A        (0 << 2)  | // 3:2
2824903SN/A        0;          // 1:0
2834903SN/A
2844903SN/A    miscRegs[MISCREG_CPACR] = 0;
2854903SN/A
2867667Ssteve.reinhardt@amd.com
2877667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_PFR0] = p->id_pfr0;
2887667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_PFR1] = p->id_pfr1;
2897667Ssteve.reinhardt@amd.com
2905875Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
2915875Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
2925875Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
2935875Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
2945875Ssteve.reinhardt@amd.com
2954903SN/A    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
2969725Sandreas.hansson@arm.com    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
2977667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
2987667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
2994903SN/A    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
3007667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
3017667Ssteve.reinhardt@amd.com
3029725Sandreas.hansson@arm.com    miscRegs[MISCREG_FPSID] = p->fpsid;
3034665SN/A
3045318SN/A    if (haveLPAE) {
3055318SN/A        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
3065318SN/A        ttbcr.eae = 0;
3075318SN/A        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
3089725Sandreas.hansson@arm.com        // Enforce consistency with system-level settings
3092810SN/A        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
3104665SN/A    }
3114665SN/A
3124902SN/A    if (haveSecurity) {
3134902SN/A        miscRegs[MISCREG_SCTLR_S] = sctlr;
3144665SN/A        miscRegs[MISCREG_SCR] = 0;
31510725Sandreas.hansson@arm.com        miscRegs[MISCREG_VBAR_S] = 0;
3169663Suri.wiener@arm.com    } else {
3174910SN/A        // we're always non-secure
3184903SN/A        miscRegs[MISCREG_SCR] = 1;
3194903SN/A    }
3204903SN/A
3214903SN/A    //XXX We need to initialize the rest of the state.
3224903SN/A}
3234903SN/A
3244903SN/Avoid
3254903SN/AISA::clear64(const ArmISAParams *p)
3264903SN/A{
3274903SN/A    CPSR cpsr = 0;
3284903SN/A    Addr rvbar = system->resetAddr64();
3294903SN/A    switch (system->highestEL()) {
3304903SN/A        // Set initial EL to highest implemented EL using associated stack
3314903SN/A        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
3329725Sandreas.hansson@arm.com        // value
3339725Sandreas.hansson@arm.com      case EL3:
3344903SN/A        cpsr.mode = MODE_EL3H;
3354903SN/A        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
3364902SN/A        break;
3374902SN/A      case EL2:
3384665SN/A        cpsr.mode = MODE_EL2H;
3394903SN/A        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
3404903SN/A        break;
3414903SN/A      case EL1:
3424903SN/A        cpsr.mode = MODE_EL1H;
3434903SN/A        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
3449725Sandreas.hansson@arm.com        break;
3454903SN/A      default:
3464903SN/A        panic("Invalid highest implemented exception level");
3477667Ssteve.reinhardt@amd.com        break;
3484665SN/A    }
3494903SN/A
3504903SN/A    // Initialize rest of CPSR
3514902SN/A    cpsr.daif = 0xf;  // Mask all interrupts
3524665SN/A    cpsr.ss = 0;
3534665SN/A    cpsr.il = 0;
3547667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_CPSR] = cpsr;
3557667Ssteve.reinhardt@amd.com    updateRegMap(cpsr);
3567667Ssteve.reinhardt@amd.com
3577667Ssteve.reinhardt@amd.com    // Initialize other control registers
3587667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
3597667Ssteve.reinhardt@amd.com    if (haveSecurity) {
3607667Ssteve.reinhardt@amd.com        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50870;
3617667Ssteve.reinhardt@amd.com        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
3628931Sandreas.hansson@arm.com    } else if (haveVirtualization) {
3637667Ssteve.reinhardt@amd.com        miscRegs[MISCREG_SCTLR_EL2] = 0x30c50870;
36410571Sandreas.hansson@arm.com    } else {
36510571Sandreas.hansson@arm.com        miscRegs[MISCREG_SCTLR_EL1] = 0x30c50870;
36610571Sandreas.hansson@arm.com        // Always non-secure
36710571Sandreas.hansson@arm.com        miscRegs[MISCREG_SCR_EL3] = 1;
36810571Sandreas.hansson@arm.com    }
3699725Sandreas.hansson@arm.com
3709725Sandreas.hansson@arm.com    // Initialize configurable id registers
3714670SN/A    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
37210582SCurtis.Dunham@arm.com    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
3734670SN/A    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
3744916SN/A        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
3754670SN/A        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
3764670SN/A
3774670SN/A    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
3784670SN/A    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
3797667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
3804670SN/A    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
3817667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
3827667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_AA64PFR0_EL1] = p->id_aa64pfr0_el1;
3837667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_AA64PFR1_EL1] = p->id_aa64pfr1_el1;
3847667Ssteve.reinhardt@amd.com
3857667Ssteve.reinhardt@amd.com    miscRegs[MISCREG_ID_DFR0_EL1] =
3867667Ssteve.reinhardt@amd.com        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
3874670SN/A
3884667SN/A    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
3894902SN/A
3904902SN/A    // Enforce consistency with system-level settings...
3914665SN/A
3924665SN/A    // EL3
3934665SN/A    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
3944665SN/A        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
3954665SN/A        haveSecurity ? 0x2 : 0x0);
3964665SN/A    // EL2
3979725Sandreas.hansson@arm.com    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
3989725Sandreas.hansson@arm.com        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
3994665SN/A        haveVirtualization ? 0x2 : 0x0);
4004665SN/A    // Large ASID support
4014665SN/A    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
4024903SN/A        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
4039725Sandreas.hansson@arm.com        haveLargeAsid64 ? 0x2 : 0x0);
4044903SN/A    // Physical address size
4054903SN/A    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
4069725Sandreas.hansson@arm.com        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
4074903SN/A        encodePhysAddrRange64(physAddrRange64));
4089725Sandreas.hansson@arm.com}
4099725Sandreas.hansson@arm.com
4104665SN/AMiscReg
4114665SN/AISA::readMiscRegNoEffect(int misc_reg) const
4122810SN/A{
4132810SN/A    assert(misc_reg < NumMiscRegs);
4142810SN/A
4152810SN/A    int flat_idx = flattenMiscIndex(misc_reg);  // Note: indexes of AArch64
4164670SN/A                                                // registers are left unchanged
4174668SN/A    MiscReg val;
4187667Ssteve.reinhardt@amd.com
4197667Ssteve.reinhardt@amd.com    if (lookUpMiscReg[flat_idx].lower == 0 || flat_idx == MISCREG_SPSR
4209725Sandreas.hansson@arm.com            || flat_idx == MISCREG_SCTLR_EL1) {
4215270SN/A        if (flat_idx == MISCREG_SPSR)
4225270SN/A            flat_idx = flattenMiscIndex(MISCREG_SPSR);
4235270SN/A        if (flat_idx == MISCREG_SCTLR_EL1)
4245270SN/A            flat_idx = flattenMiscIndex(MISCREG_SCTLR);
4255270SN/A        val = miscRegs[flat_idx];
4265270SN/A    } else
4275270SN/A        if (lookUpMiscReg[flat_idx].upper > 0)
4285270SN/A            val = ((miscRegs[lookUpMiscReg[flat_idx].lower] & mask(32))
4299725Sandreas.hansson@arm.com                    | (miscRegs[lookUpMiscReg[flat_idx].upper] << 32));
4309725Sandreas.hansson@arm.com        else
4315318SN/A            val = miscRegs[lookUpMiscReg[flat_idx].lower];
4325318SN/A
4335318SN/A    return val;
4349725Sandreas.hansson@arm.com}
4355270SN/A
4369725Sandreas.hansson@arm.com
4379725Sandreas.hansson@arm.comMiscReg
4385270SN/AISA::readMiscReg(int misc_reg, ThreadContext *tc)
4394668SN/A{
4404668SN/A    CPSR cpsr = 0;
4414668SN/A    PCState pc = 0;
4425314SN/A    SCR scr = 0;
4435314SN/A
4445314SN/A    if (misc_reg == MISCREG_CPSR) {
4455314SN/A        cpsr = miscRegs[misc_reg];
4465314SN/A        pc = tc->pcState();
4475314SN/A        cpsr.j = pc.jazelle() ? 1 : 0;
4485314SN/A        cpsr.t = pc.thumb() ? 1 : 0;
44910764Sandreas.hansson@arm.com        return cpsr;
4505314SN/A    }
4515314SN/A
4529725Sandreas.hansson@arm.com#ifndef NDEBUG
4539725Sandreas.hansson@arm.com    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
4545314SN/A        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
4555314SN/A            warn("Unimplemented system register %s read.\n",
4565314SN/A                 miscRegName[misc_reg]);
4575314SN/A        else
4584668SN/A            panic("Unimplemented system register %s read.\n",
4595314SN/A                  miscRegName[misc_reg]);
4602810SN/A    }
46110725Sandreas.hansson@arm.com#endif
46210764Sandreas.hansson@arm.com
46310028SGiacomo.Gabrielli@arm.com    switch (unflattenMiscReg(misc_reg)) {
4645730SSteve.Reinhardt@amd.com      case MISCREG_HCR:
4655730SSteve.Reinhardt@amd.com        {
4665314SN/A            if (!haveVirtualization)
4675314SN/A                return 0;
4685314SN/A            else
4695314SN/A                return readMiscRegNoEffect(MISCREG_HCR);
4707667Ssteve.reinhardt@amd.com        }
4717667Ssteve.reinhardt@amd.com      case MISCREG_CPACR:
4722810SN/A        {
4735314SN/A            const uint32_t ones = (uint32_t)(-1);
4749725Sandreas.hansson@arm.com            CPACR cpacrMask = 0;
4759725Sandreas.hansson@arm.com            // Only cp10, cp11, and ase are implemented, nothing else should
4765314SN/A            // be readable? (straight copy from the write code)
4779725Sandreas.hansson@arm.com            cpacrMask.cp10 = ones;
4782810SN/A            cpacrMask.cp11 = ones;
4792810SN/A            cpacrMask.asedis = ones;
4802810SN/A
4819663Suri.wiener@arm.com            // Security Extensions may limit the readability of CPACR
4829663Suri.wiener@arm.com            if (haveSecurity) {
4839663Suri.wiener@arm.com                scr = readMiscRegNoEffect(MISCREG_SCR);
4849663Suri.wiener@arm.com                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
4859663Suri.wiener@arm.com                if (scr.ns && (cpsr.mode != MODE_MON)) {
4869663Suri.wiener@arm.com                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
4879663Suri.wiener@arm.com                    // NB: Skipping the full loop, here
488                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
489                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
490                }
491            }
492            MiscReg val = readMiscRegNoEffect(MISCREG_CPACR);
493            val &= cpacrMask;
494            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
495                    miscRegName[misc_reg], val);
496            return val;
497        }
498      case MISCREG_MPIDR:
499        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
500        scr  = readMiscRegNoEffect(MISCREG_SCR);
501        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
502            return getMPIDR(system, tc);
503        } else {
504            return readMiscReg(MISCREG_VMPIDR, tc);
505        }
506            break;
507      case MISCREG_MPIDR_EL1:
508        // @todo in the absence of v8 virtualization support just return MPIDR_EL1
509        return getMPIDR(system, tc) & 0xffffffff;
510      case MISCREG_VMPIDR:
511        // top bit defined as RES1
512        return readMiscRegNoEffect(misc_reg) | 0x80000000;
513      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
514      case MISCREG_REVIDR:  // not implemented, so alias MIDR
515      case MISCREG_MIDR:
516        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
517        scr  = readMiscRegNoEffect(MISCREG_SCR);
518        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
519            return readMiscRegNoEffect(misc_reg);
520        } else {
521            return readMiscRegNoEffect(MISCREG_VPIDR);
522        }
523        break;
524      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
525      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
526      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
527      case MISCREG_AIDR:  // AUX ID set to 0
528      case MISCREG_TCMTR: // No TCM's
529        return 0;
530
531      case MISCREG_CLIDR:
532        warn_once("The clidr register always reports 0 caches.\n");
533        warn_once("clidr LoUIS field of 0b001 to match current "
534                  "ARM implementations.\n");
535        return 0x00200000;
536      case MISCREG_CCSIDR:
537        warn_once("The ccsidr register isn't implemented and "
538                "always reads as 0.\n");
539        break;
540      case MISCREG_CTR:
541        {
542            //all caches have the same line size in gem5
543            //4 byte words in ARM
544            unsigned lineSizeWords =
545                tc->getSystemPtr()->cacheLineSize() / 4;
546            unsigned log2LineSizeWords = 0;
547
548            while (lineSizeWords >>= 1) {
549                ++log2LineSizeWords;
550            }
551
552            CTR ctr = 0;
553            //log2 of minimun i-cache line size (words)
554            ctr.iCacheLineSize = log2LineSizeWords;
555            //b11 - gem5 uses pipt
556            ctr.l1IndexPolicy = 0x3;
557            //log2 of minimum d-cache line size (words)
558            ctr.dCacheLineSize = log2LineSizeWords;
559            //log2 of max reservation size (words)
560            ctr.erg = log2LineSizeWords;
561            //log2 of max writeback size (words)
562            ctr.cwg = log2LineSizeWords;
563            //b100 - gem5 format is ARMv7
564            ctr.format = 0x4;
565
566            return ctr;
567        }
568      case MISCREG_ACTLR:
569        warn("Not doing anything for miscreg ACTLR\n");
570        break;
571
572      case MISCREG_PMXEVTYPER_PMCCFILTR:
573      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
574      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
575      case MISCREG_PMCR ... MISCREG_PMOVSSET:
576        return pmu->readMiscReg(misc_reg);
577
578      case MISCREG_CPSR_Q:
579        panic("shouldn't be reading this register seperately\n");
580      case MISCREG_FPSCR_QC:
581        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
582      case MISCREG_FPSCR_EXC:
583        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
584      case MISCREG_FPSR:
585        {
586            const uint32_t ones = (uint32_t)(-1);
587            FPSCR fpscrMask = 0;
588            fpscrMask.ioc = ones;
589            fpscrMask.dzc = ones;
590            fpscrMask.ofc = ones;
591            fpscrMask.ufc = ones;
592            fpscrMask.ixc = ones;
593            fpscrMask.idc = ones;
594            fpscrMask.qc = ones;
595            fpscrMask.v = ones;
596            fpscrMask.c = ones;
597            fpscrMask.z = ones;
598            fpscrMask.n = ones;
599            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
600        }
601      case MISCREG_FPCR:
602        {
603            const uint32_t ones = (uint32_t)(-1);
604            FPSCR fpscrMask  = 0;
605            fpscrMask.ioe = ones;
606            fpscrMask.dze = ones;
607            fpscrMask.ofe = ones;
608            fpscrMask.ufe = ones;
609            fpscrMask.ixe = ones;
610            fpscrMask.ide = ones;
611            fpscrMask.len    = ones;
612            fpscrMask.stride = ones;
613            fpscrMask.rMode  = ones;
614            fpscrMask.fz     = ones;
615            fpscrMask.dn     = ones;
616            fpscrMask.ahp    = ones;
617            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
618        }
619      case MISCREG_NZCV:
620        {
621            CPSR cpsr = 0;
622            cpsr.nz   = tc->readCCReg(CCREG_NZ);
623            cpsr.c    = tc->readCCReg(CCREG_C);
624            cpsr.v    = tc->readCCReg(CCREG_V);
625            return cpsr;
626        }
627      case MISCREG_DAIF:
628        {
629            CPSR cpsr = 0;
630            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
631            return cpsr;
632        }
633      case MISCREG_SP_EL0:
634        {
635            return tc->readIntReg(INTREG_SP0);
636        }
637      case MISCREG_SP_EL1:
638        {
639            return tc->readIntReg(INTREG_SP1);
640        }
641      case MISCREG_SP_EL2:
642        {
643            return tc->readIntReg(INTREG_SP2);
644        }
645      case MISCREG_SPSEL:
646        {
647            return miscRegs[MISCREG_CPSR] & 0x1;
648        }
649      case MISCREG_CURRENTEL:
650        {
651            return miscRegs[MISCREG_CPSR] & 0xc;
652        }
653      case MISCREG_L2CTLR:
654        {
655            // mostly unimplemented, just set NumCPUs field from sim and return
656            L2CTLR l2ctlr = 0;
657            // b00:1CPU to b11:4CPUs
658            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
659            return l2ctlr;
660        }
661      case MISCREG_DBGDIDR:
662        /* For now just implement the version number.
663         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
664         */
665        return 0x5 << 16;
666      case MISCREG_DBGDSCRint:
667        return 0;
668      case MISCREG_ISR:
669        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
670            readMiscRegNoEffect(MISCREG_HCR),
671            readMiscRegNoEffect(MISCREG_CPSR),
672            readMiscRegNoEffect(MISCREG_SCR));
673      case MISCREG_ISR_EL1:
674        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
675            readMiscRegNoEffect(MISCREG_HCR_EL2),
676            readMiscRegNoEffect(MISCREG_CPSR),
677            readMiscRegNoEffect(MISCREG_SCR_EL3));
678      case MISCREG_DCZID_EL0:
679        return 0x04;  // DC ZVA clear 64-byte chunks
680      case MISCREG_HCPTR:
681        {
682            MiscReg val = readMiscRegNoEffect(misc_reg);
683            // The trap bit associated with CP14 is defined as RAZ
684            val &= ~(1 << 14);
685            // If a CP bit in NSACR is 0 then the corresponding bit in
686            // HCPTR is RAO/WI
687            bool secure_lookup = haveSecurity &&
688                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
689                              readMiscRegNoEffect(MISCREG_CPSR));
690            if (!secure_lookup) {
691                MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR);
692                val |= (mask ^ 0x7FFF) & 0xBFFF;
693            }
694            // Set the bits for unimplemented coprocessors to RAO/WI
695            val |= 0x33FF;
696            return (val);
697        }
698      case MISCREG_HDFAR: // alias for secure DFAR
699        return readMiscRegNoEffect(MISCREG_DFAR_S);
700      case MISCREG_HIFAR: // alias for secure IFAR
701        return readMiscRegNoEffect(MISCREG_IFAR_S);
702      case MISCREG_HVBAR: // bottom bits reserved
703        return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0;
704      case MISCREG_SCTLR: // Some bits hardwired
705        // The FI field (bit 21) is common between S/NS versions of the register
706        return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21))  |
707               (readMiscRegNoEffect(misc_reg)        & 0x72DD39FF) | 0x00C00818; // V8 SCTLR
708      case MISCREG_SCTLR_EL1:
709        // The FI field (bit 21) is common between S/NS versions of the register
710        return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21))  |
711               (readMiscRegNoEffect(misc_reg)        & 0x37DDDBFF) | 0x30D00800; // V8 SCTLR_EL1
712      case MISCREG_SCTLR_EL3:
713        // The FI field (bit 21) is common between S/NS versions of the register
714        return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21))  |
715               (readMiscRegNoEffect(misc_reg)        & 0x32CD183F) | 0x30C50830; // V8 SCTLR_EL3
716      case MISCREG_HSCTLR: // FI comes from SCTLR
717        {
718            uint32_t mask = 1 << 27;
719            return (readMiscRegNoEffect(MISCREG_HSCTLR) & ~mask) |
720                (readMiscRegNoEffect(MISCREG_SCTLR)  &  mask);
721        }
722      case MISCREG_SCR:
723        {
724            CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
725            if (cpsr.width) {
726                return readMiscRegNoEffect(MISCREG_SCR);
727            } else {
728                return readMiscRegNoEffect(MISCREG_SCR_EL3);
729            }
730        }
731
732      // Generic Timer registers
733      case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
734      case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
735      case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
736      case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
737        return getGenericTimer(tc).readMiscReg(misc_reg);
738
739      default:
740        break;
741
742    }
743    return readMiscRegNoEffect(misc_reg);
744}
745
746void
747ISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
748{
749    assert(misc_reg < NumMiscRegs);
750
751    int flat_idx = flattenMiscIndex(misc_reg);  // Note: indexes of AArch64
752                                                // registers are left unchanged
753
754    int flat_idx2 = lookUpMiscReg[flat_idx].upper;
755
756    if (flat_idx2 > 0) {
757        miscRegs[lookUpMiscReg[flat_idx].lower] = bits(val, 31, 0);
758        miscRegs[flat_idx2] = bits(val, 63, 32);
759        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
760                misc_reg, flat_idx, flat_idx2, val);
761    } else {
762        if (flat_idx == MISCREG_SPSR)
763            flat_idx = flattenMiscIndex(MISCREG_SPSR);
764        else if (flat_idx == MISCREG_SCTLR_EL1)
765            flat_idx = flattenMiscIndex(MISCREG_SCTLR);
766        else
767            flat_idx = (lookUpMiscReg[flat_idx].lower > 0) ?
768                       lookUpMiscReg[flat_idx].lower : flat_idx;
769        miscRegs[flat_idx] = val;
770        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
771                misc_reg, flat_idx, val);
772    }
773}
774
775void
776ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
777{
778
779    MiscReg newVal = val;
780    int x;
781    bool secure_lookup;
782    bool hyp;
783    System *sys;
784    ThreadContext *oc;
785    uint8_t target_el;
786    uint16_t asid;
787    SCR scr;
788
789    if (misc_reg == MISCREG_CPSR) {
790        updateRegMap(val);
791
792
793        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
794        int old_mode = old_cpsr.mode;
795        CPSR cpsr = val;
796        if (old_mode != cpsr.mode) {
797            tc->getITBPtr()->invalidateMiscReg();
798            tc->getDTBPtr()->invalidateMiscReg();
799        }
800
801        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
802                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
803        PCState pc = tc->pcState();
804        pc.nextThumb(cpsr.t);
805        pc.nextJazelle(cpsr.j);
806
807        // Follow slightly different semantics if a CheckerCPU object
808        // is connected
809        CheckerCPU *checker = tc->getCheckerCpuPtr();
810        if (checker) {
811            tc->pcStateNoRecord(pc);
812        } else {
813            tc->pcState(pc);
814        }
815    } else {
816#ifndef NDEBUG
817        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
818            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
819                warn("Unimplemented system register %s write with %#x.\n",
820                    miscRegName[misc_reg], val);
821            else
822                panic("Unimplemented system register %s write with %#x.\n",
823                    miscRegName[misc_reg], val);
824        }
825#endif
826        switch (unflattenMiscReg(misc_reg)) {
827          case MISCREG_CPACR:
828            {
829
830                const uint32_t ones = (uint32_t)(-1);
831                CPACR cpacrMask = 0;
832                // Only cp10, cp11, and ase are implemented, nothing else should
833                // be writable
834                cpacrMask.cp10 = ones;
835                cpacrMask.cp11 = ones;
836                cpacrMask.asedis = ones;
837
838                // Security Extensions may limit the writability of CPACR
839                if (haveSecurity) {
840                    scr = readMiscRegNoEffect(MISCREG_SCR);
841                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
842                    if (scr.ns && (cpsr.mode != MODE_MON)) {
843                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
844                        // NB: Skipping the full loop, here
845                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
846                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
847                    }
848                }
849
850                MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR);
851                newVal &= cpacrMask;
852                newVal |= old_val & ~cpacrMask;
853                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
854                        miscRegName[misc_reg], newVal);
855            }
856            break;
857          case MISCREG_CPACR_EL1:
858            {
859                const uint32_t ones = (uint32_t)(-1);
860                CPACR cpacrMask = 0;
861                cpacrMask.tta = ones;
862                cpacrMask.fpen = ones;
863                newVal &= cpacrMask;
864                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
865                        miscRegName[misc_reg], newVal);
866            }
867            break;
868          case MISCREG_CPTR_EL2:
869            {
870                const uint32_t ones = (uint32_t)(-1);
871                CPTR cptrMask = 0;
872                cptrMask.tcpac = ones;
873                cptrMask.tta = ones;
874                cptrMask.tfp = ones;
875                newVal &= cptrMask;
876                cptrMask = 0;
877                cptrMask.res1_13_12_el2 = ones;
878                cptrMask.res1_9_0_el2 = ones;
879                newVal |= cptrMask;
880                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
881                        miscRegName[misc_reg], newVal);
882            }
883            break;
884          case MISCREG_CPTR_EL3:
885            {
886                const uint32_t ones = (uint32_t)(-1);
887                CPTR cptrMask = 0;
888                cptrMask.tcpac = ones;
889                cptrMask.tta = ones;
890                cptrMask.tfp = ones;
891                newVal &= cptrMask;
892                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
893                        miscRegName[misc_reg], newVal);
894            }
895            break;
896          case MISCREG_CSSELR:
897            warn_once("The csselr register isn't implemented.\n");
898            return;
899
900          case MISCREG_DC_ZVA_Xt:
901            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
902            return;
903
904          case MISCREG_FPSCR:
905            {
906                const uint32_t ones = (uint32_t)(-1);
907                FPSCR fpscrMask = 0;
908                fpscrMask.ioc = ones;
909                fpscrMask.dzc = ones;
910                fpscrMask.ofc = ones;
911                fpscrMask.ufc = ones;
912                fpscrMask.ixc = ones;
913                fpscrMask.idc = ones;
914                fpscrMask.ioe = ones;
915                fpscrMask.dze = ones;
916                fpscrMask.ofe = ones;
917                fpscrMask.ufe = ones;
918                fpscrMask.ixe = ones;
919                fpscrMask.ide = ones;
920                fpscrMask.len = ones;
921                fpscrMask.stride = ones;
922                fpscrMask.rMode = ones;
923                fpscrMask.fz = ones;
924                fpscrMask.dn = ones;
925                fpscrMask.ahp = ones;
926                fpscrMask.qc = ones;
927                fpscrMask.v = ones;
928                fpscrMask.c = ones;
929                fpscrMask.z = ones;
930                fpscrMask.n = ones;
931                newVal = (newVal & (uint32_t)fpscrMask) |
932                         (readMiscRegNoEffect(MISCREG_FPSCR) &
933                          ~(uint32_t)fpscrMask);
934                tc->getDecoderPtr()->setContext(newVal);
935            }
936            break;
937          case MISCREG_FPSR:
938            {
939                const uint32_t ones = (uint32_t)(-1);
940                FPSCR fpscrMask = 0;
941                fpscrMask.ioc = ones;
942                fpscrMask.dzc = ones;
943                fpscrMask.ofc = ones;
944                fpscrMask.ufc = ones;
945                fpscrMask.ixc = ones;
946                fpscrMask.idc = ones;
947                fpscrMask.qc = ones;
948                fpscrMask.v = ones;
949                fpscrMask.c = ones;
950                fpscrMask.z = ones;
951                fpscrMask.n = ones;
952                newVal = (newVal & (uint32_t)fpscrMask) |
953                         (readMiscRegNoEffect(MISCREG_FPSCR) &
954                          ~(uint32_t)fpscrMask);
955                misc_reg = MISCREG_FPSCR;
956            }
957            break;
958          case MISCREG_FPCR:
959            {
960                const uint32_t ones = (uint32_t)(-1);
961                FPSCR fpscrMask  = 0;
962                fpscrMask.ioe = ones;
963                fpscrMask.dze = ones;
964                fpscrMask.ofe = ones;
965                fpscrMask.ufe = ones;
966                fpscrMask.ixe = ones;
967                fpscrMask.ide = ones;
968                fpscrMask.len    = ones;
969                fpscrMask.stride = ones;
970                fpscrMask.rMode  = ones;
971                fpscrMask.fz     = ones;
972                fpscrMask.dn     = ones;
973                fpscrMask.ahp    = ones;
974                newVal = (newVal & (uint32_t)fpscrMask) |
975                         (readMiscRegNoEffect(MISCREG_FPSCR) &
976                          ~(uint32_t)fpscrMask);
977                misc_reg = MISCREG_FPSCR;
978            }
979            break;
980          case MISCREG_CPSR_Q:
981            {
982                assert(!(newVal & ~CpsrMaskQ));
983                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
984                misc_reg = MISCREG_CPSR;
985            }
986            break;
987          case MISCREG_FPSCR_QC:
988            {
989                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
990                         (newVal & FpscrQcMask);
991                misc_reg = MISCREG_FPSCR;
992            }
993            break;
994          case MISCREG_FPSCR_EXC:
995            {
996                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
997                         (newVal & FpscrExcMask);
998                misc_reg = MISCREG_FPSCR;
999            }
1000            break;
1001          case MISCREG_FPEXC:
1002            {
1003                // vfpv3 architecture, section B.6.1 of DDI04068
1004                // bit 29 - valid only if fpexc[31] is 0
1005                const uint32_t fpexcMask = 0x60000000;
1006                newVal = (newVal & fpexcMask) |
1007                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
1008            }
1009            break;
1010          case MISCREG_HCR:
1011            {
1012                if (!haveVirtualization)
1013                    return;
1014            }
1015            break;
1016          case MISCREG_IFSR:
1017            {
1018                // ARM ARM (ARM DDI 0406C.b) B4.1.96
1019                const uint32_t ifsrMask =
1020                    mask(31, 13) | mask(11, 11) | mask(8, 6);
1021                newVal = newVal & ~ifsrMask;
1022            }
1023            break;
1024          case MISCREG_DFSR:
1025            {
1026                // ARM ARM (ARM DDI 0406C.b) B4.1.52
1027                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
1028                newVal = newVal & ~dfsrMask;
1029            }
1030            break;
1031          case MISCREG_AMAIR0:
1032          case MISCREG_AMAIR1:
1033            {
1034                // ARM ARM (ARM DDI 0406C.b) B4.1.5
1035                // Valid only with LPAE
1036                if (!haveLPAE)
1037                    return;
1038                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
1039            }
1040            break;
1041          case MISCREG_SCR:
1042            tc->getITBPtr()->invalidateMiscReg();
1043            tc->getDTBPtr()->invalidateMiscReg();
1044            break;
1045          case MISCREG_SCTLR:
1046            {
1047                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
1048                MiscRegIndex sctlr_idx;
1049                scr = readMiscRegNoEffect(MISCREG_SCR);
1050                if (haveSecurity && !scr.ns) {
1051                    sctlr_idx = MISCREG_SCTLR_S;
1052                } else {
1053                    sctlr_idx = MISCREG_SCTLR_NS;
1054                    // The FI field (bit 21) is common between S/NS versions
1055                    // of the register, we store this in the secure copy of
1056                    // the reg
1057                    miscRegs[MISCREG_SCTLR_S] &=         ~(1 << 21);
1058                    miscRegs[MISCREG_SCTLR_S] |= newVal & (1 << 21);
1059                }
1060                SCTLR sctlr = miscRegs[sctlr_idx];
1061                SCTLR new_sctlr = newVal;
1062                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
1063                miscRegs[sctlr_idx] = (MiscReg)new_sctlr;
1064                tc->getITBPtr()->invalidateMiscReg();
1065                tc->getDTBPtr()->invalidateMiscReg();
1066            }
1067          case MISCREG_MIDR:
1068          case MISCREG_ID_PFR0:
1069          case MISCREG_ID_PFR1:
1070          case MISCREG_ID_DFR0:
1071          case MISCREG_ID_MMFR0:
1072          case MISCREG_ID_MMFR1:
1073          case MISCREG_ID_MMFR2:
1074          case MISCREG_ID_MMFR3:
1075          case MISCREG_ID_ISAR0:
1076          case MISCREG_ID_ISAR1:
1077          case MISCREG_ID_ISAR2:
1078          case MISCREG_ID_ISAR3:
1079          case MISCREG_ID_ISAR4:
1080          case MISCREG_ID_ISAR5:
1081
1082          case MISCREG_MPIDR:
1083          case MISCREG_FPSID:
1084          case MISCREG_TLBTR:
1085          case MISCREG_MVFR0:
1086          case MISCREG_MVFR1:
1087
1088          case MISCREG_ID_AA64AFR0_EL1:
1089          case MISCREG_ID_AA64AFR1_EL1:
1090          case MISCREG_ID_AA64DFR0_EL1:
1091          case MISCREG_ID_AA64DFR1_EL1:
1092          case MISCREG_ID_AA64ISAR0_EL1:
1093          case MISCREG_ID_AA64ISAR1_EL1:
1094          case MISCREG_ID_AA64MMFR0_EL1:
1095          case MISCREG_ID_AA64MMFR1_EL1:
1096          case MISCREG_ID_AA64PFR0_EL1:
1097          case MISCREG_ID_AA64PFR1_EL1:
1098            // ID registers are constants.
1099            return;
1100
1101          // TLBI all entries, EL0&1 inner sharable (ignored)
1102          case MISCREG_TLBIALLIS:
1103          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
1104            assert32(tc);
1105            target_el = 1; // el 0 and 1 are handled together
1106            scr = readMiscReg(MISCREG_SCR, tc);
1107            secure_lookup = haveSecurity && !scr.ns;
1108            sys = tc->getSystemPtr();
1109            for (x = 0; x < sys->numContexts(); x++) {
1110                oc = sys->getThreadContext(x);
1111                assert(oc->getITBPtr() && oc->getDTBPtr());
1112                oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el);
1113                oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el);
1114
1115                // If CheckerCPU is connected, need to notify it of a flush
1116                CheckerCPU *checker = oc->getCheckerCpuPtr();
1117                if (checker) {
1118                    checker->getITBPtr()->flushAllSecurity(secure_lookup,
1119                                                           target_el);
1120                    checker->getDTBPtr()->flushAllSecurity(secure_lookup,
1121                                                           target_el);
1122                }
1123            }
1124            return;
1125          // TLBI all entries, EL0&1, instruction side
1126          case MISCREG_ITLBIALL:
1127            assert32(tc);
1128            target_el = 1; // el 0 and 1 are handled together
1129            scr = readMiscReg(MISCREG_SCR, tc);
1130            secure_lookup = haveSecurity && !scr.ns;
1131            tc->getITBPtr()->flushAllSecurity(secure_lookup, target_el);
1132            return;
1133          // TLBI all entries, EL0&1, data side
1134          case MISCREG_DTLBIALL:
1135            assert32(tc);
1136            target_el = 1; // el 0 and 1 are handled together
1137            scr = readMiscReg(MISCREG_SCR, tc);
1138            secure_lookup = haveSecurity && !scr.ns;
1139            tc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el);
1140            return;
1141          // TLBI based on VA, EL0&1 inner sharable (ignored)
1142          case MISCREG_TLBIMVAIS:
1143          case MISCREG_TLBIMVA:
1144            assert32(tc);
1145            target_el = 1; // el 0 and 1 are handled together
1146            scr = readMiscReg(MISCREG_SCR, tc);
1147            secure_lookup = haveSecurity && !scr.ns;
1148            sys = tc->getSystemPtr();
1149            for (x = 0; x < sys->numContexts(); x++) {
1150                oc = sys->getThreadContext(x);
1151                assert(oc->getITBPtr() && oc->getDTBPtr());
1152                oc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
1153                                              bits(newVal, 7,0),
1154                                              secure_lookup, target_el);
1155                oc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
1156                                              bits(newVal, 7,0),
1157                                              secure_lookup, target_el);
1158
1159                CheckerCPU *checker = oc->getCheckerCpuPtr();
1160                if (checker) {
1161                    checker->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
1162                        bits(newVal, 7,0), secure_lookup, target_el);
1163                    checker->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
1164                        bits(newVal, 7,0), secure_lookup, target_el);
1165                }
1166            }
1167            return;
1168          // TLBI by ASID, EL0&1, inner sharable
1169          case MISCREG_TLBIASIDIS:
1170          case MISCREG_TLBIASID:
1171            assert32(tc);
1172            target_el = 1; // el 0 and 1 are handled together
1173            scr = readMiscReg(MISCREG_SCR, tc);
1174            secure_lookup = haveSecurity && !scr.ns;
1175            sys = tc->getSystemPtr();
1176            for (x = 0; x < sys->numContexts(); x++) {
1177                oc = sys->getThreadContext(x);
1178                assert(oc->getITBPtr() && oc->getDTBPtr());
1179                oc->getITBPtr()->flushAsid(bits(newVal, 7,0),
1180                    secure_lookup, target_el);
1181                oc->getDTBPtr()->flushAsid(bits(newVal, 7,0),
1182                    secure_lookup, target_el);
1183                CheckerCPU *checker = oc->getCheckerCpuPtr();
1184                if (checker) {
1185                    checker->getITBPtr()->flushAsid(bits(newVal, 7,0),
1186                        secure_lookup, target_el);
1187                    checker->getDTBPtr()->flushAsid(bits(newVal, 7,0),
1188                        secure_lookup, target_el);
1189                }
1190            }
1191            return;
1192          // TLBI by address, EL0&1, inner sharable (ignored)
1193          case MISCREG_TLBIMVAAIS:
1194          case MISCREG_TLBIMVAA:
1195            assert32(tc);
1196            target_el = 1; // el 0 and 1 are handled together
1197            scr = readMiscReg(MISCREG_SCR, tc);
1198            secure_lookup = haveSecurity && !scr.ns;
1199            hyp = 0;
1200            tlbiMVA(tc, newVal, secure_lookup, hyp, target_el);
1201            return;
1202          // TLBI by address, EL2, hypervisor mode
1203          case MISCREG_TLBIMVAH:
1204          case MISCREG_TLBIMVAHIS:
1205            assert32(tc);
1206            target_el = 1; // aarch32, use hyp bit
1207            scr = readMiscReg(MISCREG_SCR, tc);
1208            secure_lookup = haveSecurity && !scr.ns;
1209            hyp = 1;
1210            tlbiMVA(tc, newVal, secure_lookup, hyp, target_el);
1211            return;
1212          // TLBI by address and asid, EL0&1, instruction side only
1213          case MISCREG_ITLBIMVA:
1214            assert32(tc);
1215            target_el = 1; // el 0 and 1 are handled together
1216            scr = readMiscReg(MISCREG_SCR, tc);
1217            secure_lookup = haveSecurity && !scr.ns;
1218            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
1219                bits(newVal, 7,0), secure_lookup, target_el);
1220            return;
1221          // TLBI by address and asid, EL0&1, data side only
1222          case MISCREG_DTLBIMVA:
1223            assert32(tc);
1224            target_el = 1; // el 0 and 1 are handled together
1225            scr = readMiscReg(MISCREG_SCR, tc);
1226            secure_lookup = haveSecurity && !scr.ns;
1227            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
1228                bits(newVal, 7,0), secure_lookup, target_el);
1229            return;
1230          // TLBI by ASID, EL0&1, instrution side only
1231          case MISCREG_ITLBIASID:
1232            assert32(tc);
1233            target_el = 1; // el 0 and 1 are handled together
1234            scr = readMiscReg(MISCREG_SCR, tc);
1235            secure_lookup = haveSecurity && !scr.ns;
1236            tc->getITBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup,
1237                                       target_el);
1238            return;
1239          // TLBI by ASID EL0&1 data size only
1240          case MISCREG_DTLBIASID:
1241            assert32(tc);
1242            target_el = 1; // el 0 and 1 are handled together
1243            scr = readMiscReg(MISCREG_SCR, tc);
1244            secure_lookup = haveSecurity && !scr.ns;
1245            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup,
1246                                       target_el);
1247            return;
1248          // Invalidate entire Non-secure Hyp/Non-Hyp Unified TLB
1249          case MISCREG_TLBIALLNSNH:
1250          case MISCREG_TLBIALLNSNHIS:
1251            assert32(tc);
1252            target_el = 1; // el 0 and 1 are handled together
1253            hyp = 0;
1254            tlbiALLN(tc, hyp, target_el);
1255            return;
1256          // TLBI all entries, EL2, hyp,
1257          case MISCREG_TLBIALLH:
1258          case MISCREG_TLBIALLHIS:
1259            assert32(tc);
1260            target_el = 1; // aarch32, use hyp bit
1261            hyp = 1;
1262            tlbiALLN(tc, hyp, target_el);
1263            return;
1264          // AArch64 TLBI: invalidate all entries EL3
1265          case MISCREG_TLBI_ALLE3IS:
1266          case MISCREG_TLBI_ALLE3:
1267            assert64(tc);
1268            target_el = 3;
1269            secure_lookup = true;
1270            tlbiALL(tc, secure_lookup, target_el);
1271            return;
1272          // @todo: uncomment this to enable Virtualization
1273          // case MISCREG_TLBI_ALLE2IS:
1274          // case MISCREG_TLBI_ALLE2:
1275          // TLBI all entries, EL0&1
1276          case MISCREG_TLBI_ALLE1IS:
1277          case MISCREG_TLBI_ALLE1:
1278          // AArch64 TLBI: invalidate all entries, stage 1, current VMID
1279          case MISCREG_TLBI_VMALLE1IS:
1280          case MISCREG_TLBI_VMALLE1:
1281          // AArch64 TLBI: invalidate all entries, stages 1 & 2, current VMID
1282          case MISCREG_TLBI_VMALLS12E1IS:
1283          case MISCREG_TLBI_VMALLS12E1:
1284            // @todo: handle VMID and stage 2 to enable Virtualization
1285            assert64(tc);
1286            target_el = 1; // el 0 and 1 are handled together
1287            scr = readMiscReg(MISCREG_SCR, tc);
1288            secure_lookup = haveSecurity && !scr.ns;
1289            tlbiALL(tc, secure_lookup, target_el);
1290            return;
1291          // AArch64 TLBI: invalidate by VA and ASID, stage 1, current VMID
1292          // VAEx(IS) and VALEx(IS) are the same because TLBs only store entries
1293          // from the last level of translation table walks
1294          // @todo: handle VMID to enable Virtualization
1295          // TLBI all entries, EL0&1
1296          case MISCREG_TLBI_VAE3IS_Xt:
1297          case MISCREG_TLBI_VAE3_Xt:
1298          // TLBI by VA, EL3  regime stage 1, last level walk
1299          case MISCREG_TLBI_VALE3IS_Xt:
1300          case MISCREG_TLBI_VALE3_Xt:
1301            assert64(tc);
1302            target_el = 3;
1303            asid = 0xbeef; // does not matter, tlbi is global
1304            secure_lookup = true;
1305            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
1306            return;
1307          // TLBI by VA, EL2
1308          case MISCREG_TLBI_VAE2IS_Xt:
1309          case MISCREG_TLBI_VAE2_Xt:
1310          // TLBI by VA, EL2, stage1 last level walk
1311          case MISCREG_TLBI_VALE2IS_Xt:
1312          case MISCREG_TLBI_VALE2_Xt:
1313            assert64(tc);
1314            target_el = 2;
1315            asid = 0xbeef; // does not matter, tlbi is global
1316            scr = readMiscReg(MISCREG_SCR, tc);
1317            secure_lookup = haveSecurity && !scr.ns;
1318            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
1319            return;
1320          // TLBI by VA EL1 & 0, stage1, ASID, current VMID
1321          case MISCREG_TLBI_VAE1IS_Xt:
1322          case MISCREG_TLBI_VAE1_Xt:
1323          case MISCREG_TLBI_VALE1IS_Xt:
1324          case MISCREG_TLBI_VALE1_Xt:
1325            assert64(tc);
1326            asid = bits(newVal, 63, 48);
1327            target_el = 1; // el 0 and 1 are handled together
1328            scr = readMiscReg(MISCREG_SCR, tc);
1329            secure_lookup = haveSecurity && !scr.ns;
1330            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
1331            return;
1332          // AArch64 TLBI: invalidate by ASID, stage 1, current VMID
1333          // @todo: handle VMID to enable Virtualization
1334          case MISCREG_TLBI_ASIDE1IS_Xt:
1335          case MISCREG_TLBI_ASIDE1_Xt:
1336            assert64(tc);
1337            target_el = 1; // el 0 and 1 are handled together
1338            scr = readMiscReg(MISCREG_SCR, tc);
1339            secure_lookup = haveSecurity && !scr.ns;
1340            sys = tc->getSystemPtr();
1341            for (x = 0; x < sys->numContexts(); x++) {
1342                oc = sys->getThreadContext(x);
1343                assert(oc->getITBPtr() && oc->getDTBPtr());
1344                asid = bits(newVal, 63, 48);
1345                if (!haveLargeAsid64)
1346                    asid &= mask(8);
1347                oc->getITBPtr()->flushAsid(asid, secure_lookup, target_el);
1348                oc->getDTBPtr()->flushAsid(asid, secure_lookup, target_el);
1349                CheckerCPU *checker = oc->getCheckerCpuPtr();
1350                if (checker) {
1351                    checker->getITBPtr()->flushAsid(asid,
1352                        secure_lookup, target_el);
1353                    checker->getDTBPtr()->flushAsid(asid,
1354                        secure_lookup, target_el);
1355                }
1356            }
1357            return;
1358          // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID
1359          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
1360          // entries from the last level of translation table walks
1361          // @todo: handle VMID to enable Virtualization
1362          case MISCREG_TLBI_VAAE1IS_Xt:
1363          case MISCREG_TLBI_VAAE1_Xt:
1364          case MISCREG_TLBI_VAALE1IS_Xt:
1365          case MISCREG_TLBI_VAALE1_Xt:
1366            assert64(tc);
1367            target_el = 1; // el 0 and 1 are handled together
1368            scr = readMiscReg(MISCREG_SCR, tc);
1369            secure_lookup = haveSecurity && !scr.ns;
1370            sys = tc->getSystemPtr();
1371            for (x = 0; x < sys->numContexts(); x++) {
1372                // @todo: extra controls on TLBI broadcast?
1373                oc = sys->getThreadContext(x);
1374                assert(oc->getITBPtr() && oc->getDTBPtr());
1375                Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
1376                oc->getITBPtr()->flushMva(va,
1377                    secure_lookup, false, target_el);
1378                oc->getDTBPtr()->flushMva(va,
1379                    secure_lookup, false, target_el);
1380
1381                CheckerCPU *checker = oc->getCheckerCpuPtr();
1382                if (checker) {
1383                    checker->getITBPtr()->flushMva(va,
1384                        secure_lookup, false, target_el);
1385                    checker->getDTBPtr()->flushMva(va,
1386                        secure_lookup, false, target_el);
1387                }
1388            }
1389            return;
1390          // AArch64 TLBI: invalidate by IPA, stage 2, current VMID
1391          case MISCREG_TLBI_IPAS2LE1IS_Xt:
1392          case MISCREG_TLBI_IPAS2LE1_Xt:
1393          case MISCREG_TLBI_IPAS2E1IS_Xt:
1394          case MISCREG_TLBI_IPAS2E1_Xt:
1395            assert64(tc);
1396            // @todo: implement these as part of Virtualization
1397            warn("Not doing anything for write of miscreg ITLB_IPAS2\n");
1398            return;
1399          case MISCREG_ACTLR:
1400            warn("Not doing anything for write of miscreg ACTLR\n");
1401            break;
1402
1403          case MISCREG_PMXEVTYPER_PMCCFILTR:
1404          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
1405          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
1406          case MISCREG_PMCR ... MISCREG_PMOVSSET:
1407            pmu->setMiscReg(misc_reg, newVal);
1408            break;
1409
1410
1411          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
1412            {
1413                HSTR hstrMask = 0;
1414                hstrMask.tjdbx = 1;
1415                newVal &= ~((uint32_t) hstrMask);
1416                break;
1417            }
1418          case MISCREG_HCPTR:
1419            {
1420                // If a CP bit in NSACR is 0 then the corresponding bit in
1421                // HCPTR is RAO/WI. Same applies to NSASEDIS
1422                secure_lookup = haveSecurity &&
1423                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
1424                                  readMiscRegNoEffect(MISCREG_CPSR));
1425                if (!secure_lookup) {
1426                    MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
1427                    MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
1428                    newVal = (newVal & ~mask) | (oldValue & mask);
1429                }
1430                break;
1431            }
1432          case MISCREG_HDFAR: // alias for secure DFAR
1433            misc_reg = MISCREG_DFAR_S;
1434            break;
1435          case MISCREG_HIFAR: // alias for secure IFAR
1436            misc_reg = MISCREG_IFAR_S;
1437            break;
1438          case MISCREG_ATS1CPR:
1439          case MISCREG_ATS1CPW:
1440          case MISCREG_ATS1CUR:
1441          case MISCREG_ATS1CUW:
1442          case MISCREG_ATS12NSOPR:
1443          case MISCREG_ATS12NSOPW:
1444          case MISCREG_ATS12NSOUR:
1445          case MISCREG_ATS12NSOUW:
1446          case MISCREG_ATS1HR:
1447          case MISCREG_ATS1HW:
1448            {
1449              unsigned flags = 0;
1450              BaseTLB::Mode mode = BaseTLB::Read;
1451              TLB::ArmTranslationType tranType = TLB::NormalTran;
1452              Fault fault;
1453              switch(misc_reg) {
1454                case MISCREG_ATS1CPR:
1455                  flags    = TLB::MustBeOne;
1456                  tranType = TLB::S1CTran;
1457                  mode     = BaseTLB::Read;
1458                  break;
1459                case MISCREG_ATS1CPW:
1460                  flags    = TLB::MustBeOne;
1461                  tranType = TLB::S1CTran;
1462                  mode     = BaseTLB::Write;
1463                  break;
1464                case MISCREG_ATS1CUR:
1465                  flags    = TLB::MustBeOne | TLB::UserMode;
1466                  tranType = TLB::S1CTran;
1467                  mode     = BaseTLB::Read;
1468                  break;
1469                case MISCREG_ATS1CUW:
1470                  flags    = TLB::MustBeOne | TLB::UserMode;
1471                  tranType = TLB::S1CTran;
1472                  mode     = BaseTLB::Write;
1473                  break;
1474                case MISCREG_ATS12NSOPR:
1475                  if (!haveSecurity)
1476                      panic("Security Extensions required for ATS12NSOPR");
1477                  flags    = TLB::MustBeOne;
1478                  tranType = TLB::S1S2NsTran;
1479                  mode     = BaseTLB::Read;
1480                  break;
1481                case MISCREG_ATS12NSOPW:
1482                  if (!haveSecurity)
1483                      panic("Security Extensions required for ATS12NSOPW");
1484                  flags    = TLB::MustBeOne;
1485                  tranType = TLB::S1S2NsTran;
1486                  mode     = BaseTLB::Write;
1487                  break;
1488                case MISCREG_ATS12NSOUR:
1489                  if (!haveSecurity)
1490                      panic("Security Extensions required for ATS12NSOUR");
1491                  flags    = TLB::MustBeOne | TLB::UserMode;
1492                  tranType = TLB::S1S2NsTran;
1493                  mode     = BaseTLB::Read;
1494                  break;
1495                case MISCREG_ATS12NSOUW:
1496                  if (!haveSecurity)
1497                      panic("Security Extensions required for ATS12NSOUW");
1498                  flags    = TLB::MustBeOne | TLB::UserMode;
1499                  tranType = TLB::S1S2NsTran;
1500                  mode     = BaseTLB::Write;
1501                  break;
1502                case MISCREG_ATS1HR: // only really useful from secure mode.
1503                  flags    = TLB::MustBeOne;
1504                  tranType = TLB::HypMode;
1505                  mode     = BaseTLB::Read;
1506                  break;
1507                case MISCREG_ATS1HW:
1508                  flags    = TLB::MustBeOne;
1509                  tranType = TLB::HypMode;
1510                  mode     = BaseTLB::Write;
1511                  break;
1512              }
1513              // If we're in timing mode then doing the translation in
1514              // functional mode then we're slightly distorting performance
1515              // results obtained from simulations. The translation should be
1516              // done in the same mode the core is running in. NOTE: This
1517              // can't be an atomic translation because that causes problems
1518              // with unexpected atomic snoop requests.
1519              warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
1520              Request req(0, val, 0, flags,  Request::funcMasterId,
1521                          tc->pcState().pc(), tc->contextId());
1522              fault = tc->getDTBPtr()->translateFunctional(&req, tc, mode, tranType);
1523              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1524              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
1525
1526              MiscReg newVal;
1527              if (fault == NoFault) {
1528                  Addr paddr = req.getPaddr();
1529                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
1530                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
1531                      newVal = (paddr & mask(39, 12)) |
1532                               (tc->getDTBPtr()->getAttr());
1533                  } else {
1534                      newVal = (paddr & 0xfffff000) |
1535                               (tc->getDTBPtr()->getAttr());
1536                  }
1537                  DPRINTF(MiscRegs,
1538                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
1539                          val, newVal);
1540              } else {
1541                  ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get());
1542                  // Set fault bit and FSR
1543                  FSR fsr = armFault->getFsr(tc);
1544
1545                  newVal = ((fsr >> 9) & 1) << 11;
1546                  if (newVal) {
1547                    // LPAE - rearange fault status
1548                    newVal |= ((fsr >>  0) & 0x3f) << 1;
1549                  } else {
1550                    // VMSA - rearange fault status
1551                    newVal |= ((fsr >>  0) & 0xf) << 1;
1552                    newVal |= ((fsr >> 10) & 0x1) << 5;
1553                    newVal |= ((fsr >> 12) & 0x1) << 6;
1554                  }
1555                  newVal |= 0x1; // F bit
1556                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1557                  newVal |= armFault->isStage2() ? 0x200 : 0;
1558                  DPRINTF(MiscRegs,
1559                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
1560                          val, fsr, newVal);
1561              }
1562              setMiscRegNoEffect(MISCREG_PAR, newVal);
1563              return;
1564            }
1565          case MISCREG_TTBCR:
1566            {
1567                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1568                const uint32_t ones = (uint32_t)(-1);
1569                TTBCR ttbcrMask = 0;
1570                TTBCR ttbcrNew = newVal;
1571
1572                // ARM DDI 0406C.b, ARMv7-32
1573                ttbcrMask.n = ones; // T0SZ
1574                if (haveSecurity) {
1575                    ttbcrMask.pd0 = ones;
1576                    ttbcrMask.pd1 = ones;
1577                }
1578                ttbcrMask.epd0 = ones;
1579                ttbcrMask.irgn0 = ones;
1580                ttbcrMask.orgn0 = ones;
1581                ttbcrMask.sh0 = ones;
1582                ttbcrMask.ps = ones; // T1SZ
1583                ttbcrMask.a1 = ones;
1584                ttbcrMask.epd1 = ones;
1585                ttbcrMask.irgn1 = ones;
1586                ttbcrMask.orgn1 = ones;
1587                ttbcrMask.sh1 = ones;
1588                if (haveLPAE)
1589                    ttbcrMask.eae = ones;
1590
1591                if (haveLPAE && ttbcrNew.eae) {
1592                    newVal = newVal & ttbcrMask;
1593                } else {
1594                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
1595                }
1596            }
1597          case MISCREG_TTBR0:
1598          case MISCREG_TTBR1:
1599            {
1600                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
1601                if (haveLPAE) {
1602                    if (ttbcr.eae) {
1603                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
1604                        // ARMv8 AArch32 bit 63-56 only
1605                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
1606                        newVal = (newVal & (~ttbrMask));
1607                    }
1608                }
1609            }
1610          case MISCREG_SCTLR_EL1:
1611            {
1612                tc->getITBPtr()->invalidateMiscReg();
1613                tc->getDTBPtr()->invalidateMiscReg();
1614                setMiscRegNoEffect(misc_reg, newVal);
1615            }
1616          case MISCREG_CONTEXTIDR:
1617          case MISCREG_PRRR:
1618          case MISCREG_NMRR:
1619          case MISCREG_MAIR0:
1620          case MISCREG_MAIR1:
1621          case MISCREG_DACR:
1622          case MISCREG_VTTBR:
1623          case MISCREG_SCR_EL3:
1624          case MISCREG_TCR_EL1:
1625          case MISCREG_TCR_EL2:
1626          case MISCREG_TCR_EL3:
1627          case MISCREG_SCTLR_EL2:
1628          case MISCREG_SCTLR_EL3:
1629          case MISCREG_HSCTLR:
1630          case MISCREG_TTBR0_EL1:
1631          case MISCREG_TTBR1_EL1:
1632          case MISCREG_TTBR0_EL2:
1633          case MISCREG_TTBR0_EL3:
1634            tc->getITBPtr()->invalidateMiscReg();
1635            tc->getDTBPtr()->invalidateMiscReg();
1636            break;
1637          case MISCREG_NZCV:
1638            {
1639                CPSR cpsr = val;
1640
1641                tc->setCCReg(CCREG_NZ, cpsr.nz);
1642                tc->setCCReg(CCREG_C,  cpsr.c);
1643                tc->setCCReg(CCREG_V,  cpsr.v);
1644            }
1645            break;
1646          case MISCREG_DAIF:
1647            {
1648                CPSR cpsr = miscRegs[MISCREG_CPSR];
1649                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
1650                newVal = cpsr;
1651                misc_reg = MISCREG_CPSR;
1652            }
1653            break;
1654          case MISCREG_SP_EL0:
1655            tc->setIntReg(INTREG_SP0, newVal);
1656            break;
1657          case MISCREG_SP_EL1:
1658            tc->setIntReg(INTREG_SP1, newVal);
1659            break;
1660          case MISCREG_SP_EL2:
1661            tc->setIntReg(INTREG_SP2, newVal);
1662            break;
1663          case MISCREG_SPSEL:
1664            {
1665                CPSR cpsr = miscRegs[MISCREG_CPSR];
1666                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
1667                newVal = cpsr;
1668                misc_reg = MISCREG_CPSR;
1669            }
1670            break;
1671          case MISCREG_CURRENTEL:
1672            {
1673                CPSR cpsr = miscRegs[MISCREG_CPSR];
1674                cpsr.el = (uint8_t) ((CPSR) newVal).el;
1675                newVal = cpsr;
1676                misc_reg = MISCREG_CPSR;
1677            }
1678            break;
1679          case MISCREG_AT_S1E1R_Xt:
1680          case MISCREG_AT_S1E1W_Xt:
1681          case MISCREG_AT_S1E0R_Xt:
1682          case MISCREG_AT_S1E0W_Xt:
1683          case MISCREG_AT_S1E2R_Xt:
1684          case MISCREG_AT_S1E2W_Xt:
1685          case MISCREG_AT_S12E1R_Xt:
1686          case MISCREG_AT_S12E1W_Xt:
1687          case MISCREG_AT_S12E0R_Xt:
1688          case MISCREG_AT_S12E0W_Xt:
1689          case MISCREG_AT_S1E3R_Xt:
1690          case MISCREG_AT_S1E3W_Xt:
1691            {
1692                RequestPtr req = new Request;
1693                unsigned flags = 0;
1694                BaseTLB::Mode mode = BaseTLB::Read;
1695                TLB::ArmTranslationType tranType = TLB::NormalTran;
1696                Fault fault;
1697                switch(misc_reg) {
1698                  case MISCREG_AT_S1E1R_Xt:
1699                    flags    = TLB::MustBeOne;
1700                    tranType = TLB::S1CTran;
1701                    mode     = BaseTLB::Read;
1702                    break;
1703                  case MISCREG_AT_S1E1W_Xt:
1704                    flags    = TLB::MustBeOne;
1705                    tranType = TLB::S1CTran;
1706                    mode     = BaseTLB::Write;
1707                    break;
1708                  case MISCREG_AT_S1E0R_Xt:
1709                    flags    = TLB::MustBeOne | TLB::UserMode;
1710                    tranType = TLB::S1CTran;
1711                    mode     = BaseTLB::Read;
1712                    break;
1713                  case MISCREG_AT_S1E0W_Xt:
1714                    flags    = TLB::MustBeOne | TLB::UserMode;
1715                    tranType = TLB::S1CTran;
1716                    mode     = BaseTLB::Write;
1717                    break;
1718                  case MISCREG_AT_S1E2R_Xt:
1719                    flags    = TLB::MustBeOne;
1720                    tranType = TLB::HypMode;
1721                    mode     = BaseTLB::Read;
1722                    break;
1723                  case MISCREG_AT_S1E2W_Xt:
1724                    flags    = TLB::MustBeOne;
1725                    tranType = TLB::HypMode;
1726                    mode     = BaseTLB::Write;
1727                    break;
1728                  case MISCREG_AT_S12E0R_Xt:
1729                    flags    = TLB::MustBeOne | TLB::UserMode;
1730                    tranType = TLB::S1S2NsTran;
1731                    mode     = BaseTLB::Read;
1732                    break;
1733                  case MISCREG_AT_S12E0W_Xt:
1734                    flags    = TLB::MustBeOne | TLB::UserMode;
1735                    tranType = TLB::S1S2NsTran;
1736                    mode     = BaseTLB::Write;
1737                    break;
1738                  case MISCREG_AT_S12E1R_Xt:
1739                    flags    = TLB::MustBeOne;
1740                    tranType = TLB::S1S2NsTran;
1741                    mode     = BaseTLB::Read;
1742                    break;
1743                  case MISCREG_AT_S12E1W_Xt:
1744                    flags    = TLB::MustBeOne;
1745                    tranType = TLB::S1S2NsTran;
1746                    mode     = BaseTLB::Write;
1747                    break;
1748                  case MISCREG_AT_S1E3R_Xt:
1749                    flags    = TLB::MustBeOne;
1750                    tranType = TLB::HypMode; // There is no TZ mode defined.
1751                    mode     = BaseTLB::Read;
1752                    break;
1753                  case MISCREG_AT_S1E3W_Xt:
1754                    flags    = TLB::MustBeOne;
1755                    tranType = TLB::HypMode; // There is no TZ mode defined.
1756                    mode     = BaseTLB::Write;
1757                    break;
1758                }
1759                // If we're in timing mode then doing the translation in
1760                // functional mode then we're slightly distorting performance
1761                // results obtained from simulations. The translation should be
1762                // done in the same mode the core is running in. NOTE: This
1763                // can't be an atomic translation because that causes problems
1764                // with unexpected atomic snoop requests.
1765                warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
1766                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
1767                               tc->pcState().pc());
1768                req->setContext(tc->contextId());
1769                fault = tc->getDTBPtr()->translateFunctional(req, tc, mode,
1770                                                             tranType);
1771
1772                MiscReg newVal;
1773                if (fault == NoFault) {
1774                    Addr paddr = req->getPaddr();
1775                    uint64_t attr = tc->getDTBPtr()->getAttr();
1776                    uint64_t attr1 = attr >> 56;
1777                    if (!attr1 || attr1 ==0x44) {
1778                        attr |= 0x100;
1779                        attr &= ~ uint64_t(0x80);
1780                    }
1781                    newVal = (paddr & mask(47, 12)) | attr;
1782                    DPRINTF(MiscRegs,
1783                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
1784                          val, newVal);
1785                } else {
1786                    ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get());
1787                    // Set fault bit and FSR
1788                    FSR fsr = armFault->getFsr(tc);
1789
1790                    newVal = ((fsr >> 9) & 1) << 11;
1791                    // rearange fault status
1792                    newVal |= ((fsr >>  0) & 0x3f) << 1;
1793                    newVal |= 0x1; // F bit
1794                    newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
1795                    newVal |= armFault->isStage2() ? 0x200 : 0;
1796                    DPRINTF(MiscRegs,
1797                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
1798                            val, fsr, newVal);
1799                }
1800                delete req;
1801                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
1802                return;
1803            }
1804          case MISCREG_SPSR_EL3:
1805          case MISCREG_SPSR_EL2:
1806          case MISCREG_SPSR_EL1:
1807            // Force bits 23:21 to 0
1808            newVal = val & ~(0x7 << 21);
1809            break;
1810          case MISCREG_L2CTLR:
1811            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
1812                 miscRegName[misc_reg], uint32_t(val));
1813            break;
1814
1815          // Generic Timer registers
1816          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
1817          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
1818          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
1819          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
1820            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
1821            break;
1822        }
1823    }
1824    setMiscRegNoEffect(misc_reg, newVal);
1825}
1826
1827void
1828ISA::tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid,
1829            bool secure_lookup, uint8_t target_el)
1830{
1831    if (!haveLargeAsid64)
1832        asid &= mask(8);
1833    Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
1834    System *sys = tc->getSystemPtr();
1835    for (int x = 0; x < sys->numContexts(); x++) {
1836        ThreadContext *oc = sys->getThreadContext(x);
1837        assert(oc->getITBPtr() && oc->getDTBPtr());
1838        oc->getITBPtr()->flushMvaAsid(va, asid,
1839                                      secure_lookup, target_el);
1840        oc->getDTBPtr()->flushMvaAsid(va, asid,
1841                                      secure_lookup, target_el);
1842
1843        CheckerCPU *checker = oc->getCheckerCpuPtr();
1844        if (checker) {
1845            checker->getITBPtr()->flushMvaAsid(
1846                va, asid, secure_lookup, target_el);
1847            checker->getDTBPtr()->flushMvaAsid(
1848                va, asid, secure_lookup, target_el);
1849        }
1850    }
1851}
1852
1853void
1854ISA::tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el)
1855{
1856    System *sys = tc->getSystemPtr();
1857    for (int x = 0; x < sys->numContexts(); x++) {
1858        ThreadContext *oc = sys->getThreadContext(x);
1859        assert(oc->getITBPtr() && oc->getDTBPtr());
1860        oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el);
1861        oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el);
1862
1863        // If CheckerCPU is connected, need to notify it of a flush
1864        CheckerCPU *checker = oc->getCheckerCpuPtr();
1865        if (checker) {
1866            checker->getITBPtr()->flushAllSecurity(secure_lookup,
1867                                                   target_el);
1868            checker->getDTBPtr()->flushAllSecurity(secure_lookup,
1869                                                   target_el);
1870        }
1871    }
1872}
1873
1874void
1875ISA::tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el)
1876{
1877    System *sys = tc->getSystemPtr();
1878    for (int x = 0; x < sys->numContexts(); x++) {
1879      ThreadContext *oc = sys->getThreadContext(x);
1880      assert(oc->getITBPtr() && oc->getDTBPtr());
1881      oc->getITBPtr()->flushAllNs(hyp, target_el);
1882      oc->getDTBPtr()->flushAllNs(hyp, target_el);
1883
1884      CheckerCPU *checker = oc->getCheckerCpuPtr();
1885      if (checker) {
1886          checker->getITBPtr()->flushAllNs(hyp, target_el);
1887          checker->getDTBPtr()->flushAllNs(hyp, target_el);
1888      }
1889    }
1890}
1891
1892void
1893ISA::tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, bool hyp,
1894             uint8_t target_el)
1895{
1896    System *sys = tc->getSystemPtr();
1897    for (int x = 0; x < sys->numContexts(); x++) {
1898        ThreadContext *oc = sys->getThreadContext(x);
1899        assert(oc->getITBPtr() && oc->getDTBPtr());
1900        oc->getITBPtr()->flushMva(mbits(newVal, 31,12),
1901            secure_lookup, hyp, target_el);
1902        oc->getDTBPtr()->flushMva(mbits(newVal, 31,12),
1903            secure_lookup, hyp, target_el);
1904
1905        CheckerCPU *checker = oc->getCheckerCpuPtr();
1906        if (checker) {
1907            checker->getITBPtr()->flushMva(mbits(newVal, 31,12),
1908                secure_lookup, hyp, target_el);
1909            checker->getDTBPtr()->flushMva(mbits(newVal, 31,12),
1910                secure_lookup, hyp, target_el);
1911        }
1912    }
1913}
1914
1915BaseISADevice &
1916ISA::getGenericTimer(ThreadContext *tc)
1917{
1918    // We only need to create an ISA interface the first time we try
1919    // to access the timer.
1920    if (timer)
1921        return *timer.get();
1922
1923    assert(system);
1924    GenericTimer *generic_timer(system->getGenericTimer());
1925    if (!generic_timer) {
1926        panic("Trying to get a generic timer from a system that hasn't "
1927              "been configured to use a generic timer.\n");
1928    }
1929
1930    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
1931    return *timer.get();
1932}
1933
1934}
1935
1936ArmISA::ISA *
1937ArmISAParams::create()
1938{
1939    return new ArmISA::ISA(this);
1940}
1941