isa.cc revision 11768
17405SAli.Saidi@ARM.com/*
211573SDylan.Johnson@ARM.com * Copyright (c) 2010-2016 ARM Limited
37405SAli.Saidi@ARM.com * All rights reserved
47405SAli.Saidi@ARM.com *
57405SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67405SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77405SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87405SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97405SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
107405SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117405SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127405SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137405SAli.Saidi@ARM.com *
147405SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without
157405SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are
167405SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright
177405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer;
187405SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright
197405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the
207405SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution;
217405SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its
227405SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from
237405SAli.Saidi@ARM.com * this software without specific prior written permission.
247405SAli.Saidi@ARM.com *
257405SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
267405SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
277405SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
287405SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
297405SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
307405SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
317405SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
327405SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
337405SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
347405SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
357405SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
367405SAli.Saidi@ARM.com *
377405SAli.Saidi@ARM.com * Authors: Gabe Black
387405SAli.Saidi@ARM.com *          Ali Saidi
397405SAli.Saidi@ARM.com */
407405SAli.Saidi@ARM.com
417405SAli.Saidi@ARM.com#include "arch/arm/isa.hh"
4210461SAndreas.Sandberg@ARM.com#include "arch/arm/pmu.hh"
439050Schander.sudanthi@arm.com#include "arch/arm/system.hh"
448887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh"
4510461SAndreas.Sandberg@ARM.com#include "cpu/base.hh"
468232Snate@binkert.org#include "debug/Arm.hh"
478232Snate@binkert.org#include "debug/MiscRegs.hh"
4810844Sandreas.sandberg@arm.com#include "dev/arm/generic_timer.hh"
499384SAndreas.Sandberg@arm.com#include "params/ArmISA.hh"
507678Sgblack@eecs.umich.edu#include "sim/faults.hh"
518059SAli.Saidi@ARM.com#include "sim/stat_control.hh"
528284SAli.Saidi@ARM.com#include "sim/system.hh"
537405SAli.Saidi@ARM.com
547405SAli.Saidi@ARM.comnamespace ArmISA
557405SAli.Saidi@ARM.com{
567405SAli.Saidi@ARM.com
5710037SARM gem5 Developers
5810037SARM gem5 Developers/**
5911768SCurtis.Dunham@arm.com * Some registers alias with others, and therefore need to be translated.
6010037SARM gem5 Developers * For each entry:
6110037SARM gem5 Developers * The first value is the misc register that is to be looked up
6210037SARM gem5 Developers * the second value is the lower part of the translation
6310037SARM gem5 Developers * the third the upper part
6411768SCurtis.Dunham@arm.com * aligned with reference documentation ARM DDI 0487A.i pp 1540-1543
6510037SARM gem5 Developers */
6610037SARM gem5 Developersconst struct ISA::MiscRegInitializerEntry
6711768SCurtis.Dunham@arm.com    ISA::MiscRegSwitch[] = {
6811768SCurtis.Dunham@arm.com    {MISCREG_ACTLR_EL1, {MISCREG_ACTLR_NS, 0}},
6911768SCurtis.Dunham@arm.com    {MISCREG_AFSR0_EL1, {MISCREG_ADFSR_NS, 0}},
7011768SCurtis.Dunham@arm.com    {MISCREG_AFSR1_EL1, {MISCREG_AIFSR_NS, 0}},
7111768SCurtis.Dunham@arm.com    {MISCREG_AMAIR_EL1, {MISCREG_AMAIR0_NS, MISCREG_AMAIR1_NS}},
7211768SCurtis.Dunham@arm.com    {MISCREG_CONTEXTIDR_EL1, {MISCREG_CONTEXTIDR_NS, 0}},
7311768SCurtis.Dunham@arm.com    {MISCREG_CPACR_EL1, {MISCREG_CPACR, 0}},
7411768SCurtis.Dunham@arm.com    {MISCREG_CSSELR_EL1, {MISCREG_CSSELR_NS, 0}},
7511768SCurtis.Dunham@arm.com    {MISCREG_DACR32_EL2, {MISCREG_DACR_NS, 0}},
7611768SCurtis.Dunham@arm.com    {MISCREG_FAR_EL1, {MISCREG_DFAR_NS, MISCREG_IFAR_NS}},
7711768SCurtis.Dunham@arm.com    // ESR_EL1 -> DFSR
7811768SCurtis.Dunham@arm.com    {MISCREG_HACR_EL2, {MISCREG_HACR, 0}},
7910037SARM gem5 Developers    {MISCREG_ACTLR_EL2, {MISCREG_HACTLR, 0}},
8010037SARM gem5 Developers    {MISCREG_AFSR0_EL2, {MISCREG_HADFSR, 0}},
8110037SARM gem5 Developers    {MISCREG_AFSR1_EL2, {MISCREG_HAIFSR, 0}},
8211768SCurtis.Dunham@arm.com    {MISCREG_AMAIR_EL2, {MISCREG_HAMAIR0, MISCREG_HAMAIR1}},
8311768SCurtis.Dunham@arm.com    {MISCREG_CPTR_EL2, {MISCREG_HCPTR, 0}},
8411768SCurtis.Dunham@arm.com    {MISCREG_HCR_EL2, {MISCREG_HCR, 0 /*MISCREG_HCR2*/}},
8511768SCurtis.Dunham@arm.com    {MISCREG_MDCR_EL2, {MISCREG_HDCR, 0}},
8611768SCurtis.Dunham@arm.com    {MISCREG_FAR_EL2, {MISCREG_HDFAR, MISCREG_HIFAR}},
8711768SCurtis.Dunham@arm.com    {MISCREG_MAIR_EL2, {MISCREG_HMAIR0, MISCREG_HMAIR1}},
8811768SCurtis.Dunham@arm.com    {MISCREG_HPFAR_EL2, {MISCREG_HPFAR, 0}},
8911768SCurtis.Dunham@arm.com    {MISCREG_SCTLR_EL2, {MISCREG_HSCTLR, 0}},
9010037SARM gem5 Developers    {MISCREG_ESR_EL2, {MISCREG_HSR, 0}},
9111768SCurtis.Dunham@arm.com    {MISCREG_HSTR_EL2, {MISCREG_HSTR, 0}},
9211768SCurtis.Dunham@arm.com    {MISCREG_TCR_EL2, {MISCREG_HTCR, 0}},
9311768SCurtis.Dunham@arm.com    {MISCREG_TPIDR_EL2, {MISCREG_HTPIDR, 0}},
9411768SCurtis.Dunham@arm.com    {MISCREG_TTBR0_EL2, {MISCREG_HTTBR, 0}},
9510037SARM gem5 Developers    {MISCREG_VBAR_EL2, {MISCREG_HVBAR, 0}},
9611768SCurtis.Dunham@arm.com    {MISCREG_IFSR32_EL2, {MISCREG_IFSR_NS, 0}},
9711768SCurtis.Dunham@arm.com    {MISCREG_MAIR_EL1, {MISCREG_PRRR_NS, MISCREG_NMRR_NS}},
9811768SCurtis.Dunham@arm.com    {MISCREG_PAR_EL1, {MISCREG_PAR_NS, 0}},
9911768SCurtis.Dunham@arm.com    // RMR_EL1 -> RMR
10011768SCurtis.Dunham@arm.com    // RMR_EL2 -> HRMR
10111768SCurtis.Dunham@arm.com    {MISCREG_SCTLR_EL1, {MISCREG_SCTLR_NS, 0}},
10211768SCurtis.Dunham@arm.com    {MISCREG_SDER32_EL3, {MISCREG_SDER, 0}},
10311768SCurtis.Dunham@arm.com    {MISCREG_TPIDR_EL1, {MISCREG_TPIDRPRW_NS, 0}},
10411768SCurtis.Dunham@arm.com    {MISCREG_TPIDRRO_EL0, {MISCREG_TPIDRURO_NS, 0}},
10511768SCurtis.Dunham@arm.com    {MISCREG_TPIDR_EL0, {MISCREG_TPIDRURW_NS, 0}},
10611768SCurtis.Dunham@arm.com    {MISCREG_TCR_EL1, {MISCREG_TTBCR_NS, 0}},
10711768SCurtis.Dunham@arm.com    {MISCREG_TTBR0_EL1, {MISCREG_TTBR0_NS, 0}},
10811768SCurtis.Dunham@arm.com    {MISCREG_TTBR1_EL1, {MISCREG_TTBR1_NS, 0}},
10911768SCurtis.Dunham@arm.com    {MISCREG_VBAR_EL1, {MISCREG_VBAR_NS, 0}},
11011768SCurtis.Dunham@arm.com    {MISCREG_VMPIDR_EL2, {MISCREG_VMPIDR, 0}},
11111768SCurtis.Dunham@arm.com    {MISCREG_VPIDR_EL2, {MISCREG_VPIDR, 0}},
11211768SCurtis.Dunham@arm.com    {MISCREG_VTCR_EL2, {MISCREG_VTCR, 0}},
11311768SCurtis.Dunham@arm.com    {MISCREG_VTTBR_EL2, {MISCREG_VTTBR, 0}},
11410037SARM gem5 Developers    {MISCREG_CNTFRQ_EL0, {MISCREG_CNTFRQ, 0}},
11511768SCurtis.Dunham@arm.com    {MISCREG_CNTHCTL_EL2, {MISCREG_CNTHCTL, 0}},
11611768SCurtis.Dunham@arm.com    {MISCREG_CNTHP_CTL_EL2, {MISCREG_CNTHP_CTL, 0}},
11711768SCurtis.Dunham@arm.com    {MISCREG_CNTHP_CVAL_EL2, {MISCREG_CNTHP_CVAL, 0}}, /* 64b */
11811768SCurtis.Dunham@arm.com    {MISCREG_CNTHP_TVAL_EL2, {MISCREG_CNTHP_TVAL, 0}},
11910037SARM gem5 Developers    {MISCREG_CNTKCTL_EL1, {MISCREG_CNTKCTL, 0}},
12011768SCurtis.Dunham@arm.com    {MISCREG_CNTP_CTL_EL0, {MISCREG_CNTP_CTL_NS, 0}},
12111768SCurtis.Dunham@arm.com    {MISCREG_CNTP_CVAL_EL0, {MISCREG_CNTP_CVAL_NS, 0}}, /* 64b */
12211768SCurtis.Dunham@arm.com    {MISCREG_CNTP_TVAL_EL0, {MISCREG_CNTP_TVAL_NS, 0}},
12311768SCurtis.Dunham@arm.com    {MISCREG_CNTPCT_EL0, {MISCREG_CNTPCT, 0}}, /* 64b */
12411768SCurtis.Dunham@arm.com    {MISCREG_CNTV_CTL_EL0, {MISCREG_CNTV_CTL, 0}},
12511768SCurtis.Dunham@arm.com    {MISCREG_CNTV_CVAL_EL0, {MISCREG_CNTV_CVAL, 0}}, /* 64b */
12610037SARM gem5 Developers    {MISCREG_CNTV_TVAL_EL0, {MISCREG_CNTV_TVAL, 0}},
12711768SCurtis.Dunham@arm.com    {MISCREG_CNTVCT_EL0, {MISCREG_CNTVCT, 0}}, /* 64b */
12811768SCurtis.Dunham@arm.com    {MISCREG_CNTVOFF_EL2, {MISCREG_CNTVOFF, 0}}, /* 64b */
12911768SCurtis.Dunham@arm.com    {MISCREG_DBGAUTHSTATUS_EL1, {MISCREG_DBGAUTHSTATUS, 0}},
13011768SCurtis.Dunham@arm.com    {MISCREG_DBGBCR0_EL1, {MISCREG_DBGBCR0, 0}},
13111768SCurtis.Dunham@arm.com    {MISCREG_DBGBCR1_EL1, {MISCREG_DBGBCR1, 0}},
13211768SCurtis.Dunham@arm.com    {MISCREG_DBGBCR2_EL1, {MISCREG_DBGBCR2, 0}},
13311768SCurtis.Dunham@arm.com    {MISCREG_DBGBCR3_EL1, {MISCREG_DBGBCR3, 0}},
13411768SCurtis.Dunham@arm.com    {MISCREG_DBGBCR4_EL1, {MISCREG_DBGBCR4, 0}},
13511768SCurtis.Dunham@arm.com    {MISCREG_DBGBCR5_EL1, {MISCREG_DBGBCR5, 0}},
13611768SCurtis.Dunham@arm.com    {MISCREG_DBGBVR0_EL1, {MISCREG_DBGBVR0, 0 /* MISCREG_DBGBXVR0 */}},
13711768SCurtis.Dunham@arm.com    {MISCREG_DBGBVR1_EL1, {MISCREG_DBGBVR1, 0 /* MISCREG_DBGBXVR1 */}},
13811768SCurtis.Dunham@arm.com    {MISCREG_DBGBVR2_EL1, {MISCREG_DBGBVR2, 0 /* MISCREG_DBGBXVR2 */}},
13911768SCurtis.Dunham@arm.com    {MISCREG_DBGBVR3_EL1, {MISCREG_DBGBVR3, 0 /* MISCREG_DBGBXVR3 */}},
14011768SCurtis.Dunham@arm.com    {MISCREG_DBGBVR4_EL1, {MISCREG_DBGBVR4, MISCREG_DBGBXVR4}},
14111768SCurtis.Dunham@arm.com    {MISCREG_DBGBVR5_EL1, {MISCREG_DBGBVR5, MISCREG_DBGBXVR5}},
14211768SCurtis.Dunham@arm.com    {MISCREG_DBGCLAIMSET_EL1, {MISCREG_DBGCLAIMSET, 0}},
14311768SCurtis.Dunham@arm.com    {MISCREG_DBGCLAIMCLR_EL1, {MISCREG_DBGCLAIMCLR, 0}},
14411768SCurtis.Dunham@arm.com    // DBGDTR_EL0 -> DBGDTR{R or T}Xint
14511768SCurtis.Dunham@arm.com    // DBGDTRRX_EL0 -> DBGDTRRXint
14611768SCurtis.Dunham@arm.com    // DBGDTRTX_EL0 -> DBGDTRRXint
14711768SCurtis.Dunham@arm.com    {MISCREG_DBGPRCR_EL1, {MISCREG_DBGPRCR, 0}},
14811768SCurtis.Dunham@arm.com    {MISCREG_DBGVCR32_EL2, {MISCREG_DBGVCR, 0}},
14911768SCurtis.Dunham@arm.com    {MISCREG_DBGWCR0_EL1, {MISCREG_DBGWCR0, 0}},
15011768SCurtis.Dunham@arm.com    {MISCREG_DBGWCR1_EL1, {MISCREG_DBGWCR1, 0}},
15111768SCurtis.Dunham@arm.com    {MISCREG_DBGWCR2_EL1, {MISCREG_DBGWCR2, 0}},
15211768SCurtis.Dunham@arm.com    {MISCREG_DBGWCR3_EL1, {MISCREG_DBGWCR3, 0}},
15311768SCurtis.Dunham@arm.com    {MISCREG_DBGWVR0_EL1, {MISCREG_DBGWVR0, 0}},
15411768SCurtis.Dunham@arm.com    {MISCREG_DBGWVR1_EL1, {MISCREG_DBGWVR1, 0}},
15511768SCurtis.Dunham@arm.com    {MISCREG_DBGWVR2_EL1, {MISCREG_DBGWVR2, 0}},
15611768SCurtis.Dunham@arm.com    {MISCREG_DBGWVR3_EL1, {MISCREG_DBGWVR3, 0}},
15711768SCurtis.Dunham@arm.com    {MISCREG_ID_DFR0_EL1, {MISCREG_ID_DFR0, 0}},
15811768SCurtis.Dunham@arm.com    {MISCREG_MDCCSR_EL0, {MISCREG_DBGDSCRint, 0}},
15911768SCurtis.Dunham@arm.com    {MISCREG_MDRAR_EL1, {MISCREG_DBGDRAR, 0}},
16011768SCurtis.Dunham@arm.com    {MISCREG_MDSCR_EL1, {MISCREG_DBGDSCRext, 0}},
16111768SCurtis.Dunham@arm.com    {MISCREG_OSDLR_EL1, {MISCREG_DBGOSDLR, 0}},
16211768SCurtis.Dunham@arm.com    {MISCREG_OSDTRRX_EL1, {MISCREG_DBGDTRRXext, 0}},
16311768SCurtis.Dunham@arm.com    {MISCREG_OSDTRTX_EL1, {MISCREG_DBGDTRTXext, 0}},
16411768SCurtis.Dunham@arm.com    {MISCREG_OSECCR_EL1, {MISCREG_DBGOSECCR, 0}},
16511768SCurtis.Dunham@arm.com    {MISCREG_OSLAR_EL1, {MISCREG_DBGOSLAR, 0}},
16611768SCurtis.Dunham@arm.com    {MISCREG_OSLSR_EL1, {MISCREG_DBGOSLSR, 0}},
16711768SCurtis.Dunham@arm.com    {MISCREG_PMCCNTR_EL0, {MISCREG_PMCCNTR, 0}},
16811768SCurtis.Dunham@arm.com    {MISCREG_PMCEID0_EL0, {MISCREG_PMCEID0, 0}},
16911768SCurtis.Dunham@arm.com    {MISCREG_PMCEID1_EL0, {MISCREG_PMCEID1, 0}},
17011768SCurtis.Dunham@arm.com    {MISCREG_PMCNTENSET_EL0, {MISCREG_PMCNTENSET, 0}},
17111768SCurtis.Dunham@arm.com    {MISCREG_PMCNTENCLR_EL0, {MISCREG_PMCNTENCLR, 0}},
17211768SCurtis.Dunham@arm.com    {MISCREG_PMCR_EL0, {MISCREG_PMCR, 0}},
17311768SCurtis.Dunham@arm.com/*  {MISCREG_PMEVCNTR0_EL0, {MISCREG_PMEVCNTR0, 0}},
17411768SCurtis.Dunham@arm.com    {MISCREG_PMEVCNTR1_EL0, {MISCREG_PMEVCNTR1, 0}},
17511768SCurtis.Dunham@arm.com    {MISCREG_PMEVCNTR2_EL0, {MISCREG_PMEVCNTR2, 0}},
17611768SCurtis.Dunham@arm.com    {MISCREG_PMEVCNTR3_EL0, {MISCREG_PMEVCNTR3, 0}},
17711768SCurtis.Dunham@arm.com    {MISCREG_PMEVCNTR4_EL0, {MISCREG_PMEVCNTR4, 0}},
17811768SCurtis.Dunham@arm.com    {MISCREG_PMEVCNTR5_EL0, {MISCREG_PMEVCNTR5, 0}},
17911768SCurtis.Dunham@arm.com    {MISCREG_PMEVTYPER0_EL0, {MISCREG_PMEVTYPER0, 0}},
18011768SCurtis.Dunham@arm.com    {MISCREG_PMEVTYPER1_EL0, {MISCREG_PMEVTYPER1, 0}},
18111768SCurtis.Dunham@arm.com    {MISCREG_PMEVTYPER2_EL0, {MISCREG_PMEVTYPER2, 0}},
18211768SCurtis.Dunham@arm.com    {MISCREG_PMEVTYPER3_EL0, {MISCREG_PMEVTYPER3, 0}},
18311768SCurtis.Dunham@arm.com    {MISCREG_PMEVTYPER4_EL0, {MISCREG_PMEVTYPER4, 0}},
18411768SCurtis.Dunham@arm.com    {MISCREG_PMEVTYPER5_EL0, {MISCREG_PMEVTYPER5, 0}}, */
18511768SCurtis.Dunham@arm.com    {MISCREG_PMINTENCLR_EL1, {MISCREG_PMINTENCLR, 0}},
18611768SCurtis.Dunham@arm.com    {MISCREG_PMINTENSET_EL1, {MISCREG_PMINTENSET, 0}},
18711768SCurtis.Dunham@arm.com//  {MISCREG_PMOVSCLR_EL0, {MISCREG_PMOVSCLR, 0}},
18811768SCurtis.Dunham@arm.com    {MISCREG_PMOVSSET_EL0, {MISCREG_PMOVSSET, 0}},
18911768SCurtis.Dunham@arm.com    {MISCREG_PMSELR_EL0, {MISCREG_PMSELR, 0}},
19011768SCurtis.Dunham@arm.com    {MISCREG_PMSWINC_EL0, {MISCREG_PMSWINC, 0}},
19111768SCurtis.Dunham@arm.com    {MISCREG_PMUSERENR_EL0, {MISCREG_PMUSERENR, 0}},
19211768SCurtis.Dunham@arm.com    {MISCREG_PMXEVCNTR_EL0, {MISCREG_PMXEVCNTR, 0}},
19311768SCurtis.Dunham@arm.com    {MISCREG_PMXEVTYPER_EL0, {MISCREG_PMXEVTYPER, 0}},
19411768SCurtis.Dunham@arm.com
19511768SCurtis.Dunham@arm.com    // from ARM DDI 0487A.i, template text
19611768SCurtis.Dunham@arm.com    // "AArch64 System register ___ can be mapped to
19711768SCurtis.Dunham@arm.com    //  AArch32 System register ___, but this is not
19811768SCurtis.Dunham@arm.com    //  architecturally mandated."
19911768SCurtis.Dunham@arm.com    {MISCREG_SCR_EL3, {MISCREG_SCR, 0}}, // D7-2005
20011768SCurtis.Dunham@arm.com    // MDCR_EL3 -> SDCR, D7-2108 (the latter is unimpl. in gem5)
20111768SCurtis.Dunham@arm.com    {MISCREG_SPSR_EL1, {MISCREG_SPSR_SVC, 0}}, // C5.2.17 SPSR_EL1
20211768SCurtis.Dunham@arm.com    {MISCREG_SPSR_EL2, {MISCREG_SPSR_HYP, 0}}, // C5.2.18 SPSR_EL2
20311768SCurtis.Dunham@arm.com    {MISCREG_SPSR_EL3, {MISCREG_SPSR_MON, 0}}, // C5.2.19 SPSR_EL3
20410037SARM gem5 Developers};
20510037SARM gem5 Developers
20610037SARM gem5 Developers
2079384SAndreas.Sandberg@arm.comISA::ISA(Params *p)
20810461SAndreas.Sandberg@ARM.com    : SimObject(p),
20910461SAndreas.Sandberg@ARM.com      system(NULL),
21011165SRekai.GonzalezAlberquilla@arm.com      _decoderFlavour(p->decoderFlavour),
21110461SAndreas.Sandberg@ARM.com      pmu(p->pmu),
21210461SAndreas.Sandberg@ARM.com      lookUpMiscReg(NUM_MISCREGS, {0,0})
2139384SAndreas.Sandberg@arm.com{
2149384SAndreas.Sandberg@arm.com    SCTLR sctlr;
2159384SAndreas.Sandberg@arm.com    sctlr = 0;
2169384SAndreas.Sandberg@arm.com    miscRegs[MISCREG_SCTLR_RST] = sctlr;
21710037SARM gem5 Developers
21810461SAndreas.Sandberg@ARM.com    // Hook up a dummy device if we haven't been configured with a
21910461SAndreas.Sandberg@ARM.com    // real PMU. By using a dummy device, we don't need to check that
22010461SAndreas.Sandberg@ARM.com    // the PMU exist every time we try to access a PMU register.
22110461SAndreas.Sandberg@ARM.com    if (!pmu)
22210461SAndreas.Sandberg@ARM.com        pmu = &dummyDevice;
22310461SAndreas.Sandberg@ARM.com
22410609Sandreas.sandberg@arm.com    // Give all ISA devices a pointer to this ISA
22510609Sandreas.sandberg@arm.com    pmu->setISA(this);
22610609Sandreas.sandberg@arm.com
22710037SARM gem5 Developers    system = dynamic_cast<ArmSystem *>(p->system);
22810037SARM gem5 Developers
22910037SARM gem5 Developers    // Cache system-level properties
23010037SARM gem5 Developers    if (FullSystem && system) {
23110037SARM gem5 Developers        haveSecurity = system->haveSecurity();
23210037SARM gem5 Developers        haveLPAE = system->haveLPAE();
23310037SARM gem5 Developers        haveVirtualization = system->haveVirtualization();
23410037SARM gem5 Developers        haveLargeAsid64 = system->haveLargeAsid64();
23510037SARM gem5 Developers        physAddrRange64 = system->physAddrRange64();
23610037SARM gem5 Developers    } else {
23710037SARM gem5 Developers        haveSecurity = haveLPAE = haveVirtualization = false;
23810037SARM gem5 Developers        haveLargeAsid64 = false;
23910037SARM gem5 Developers        physAddrRange64 = 32;  // dummy value
24010037SARM gem5 Developers    }
24110037SARM gem5 Developers
24210037SARM gem5 Developers    /** Fill in the miscReg translation table */
24311768SCurtis.Dunham@arm.com    for (auto sw : MiscRegSwitch) {
24411768SCurtis.Dunham@arm.com        lookUpMiscReg[sw.index] = sw.entry;
24510037SARM gem5 Developers    }
24610037SARM gem5 Developers
24710037SARM gem5 Developers    preUnflattenMiscReg();
24810037SARM gem5 Developers
2499384SAndreas.Sandberg@arm.com    clear();
2509384SAndreas.Sandberg@arm.com}
2519384SAndreas.Sandberg@arm.com
2529384SAndreas.Sandberg@arm.comconst ArmISAParams *
2539384SAndreas.Sandberg@arm.comISA::params() const
2549384SAndreas.Sandberg@arm.com{
2559384SAndreas.Sandberg@arm.com    return dynamic_cast<const Params *>(_params);
2569384SAndreas.Sandberg@arm.com}
2579384SAndreas.Sandberg@arm.com
2587427Sgblack@eecs.umich.eduvoid
2597427Sgblack@eecs.umich.eduISA::clear()
2607427Sgblack@eecs.umich.edu{
2619385SAndreas.Sandberg@arm.com    const Params *p(params());
2629385SAndreas.Sandberg@arm.com
2637427Sgblack@eecs.umich.edu    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
2647427Sgblack@eecs.umich.edu    memset(miscRegs, 0, sizeof(miscRegs));
26510037SARM gem5 Developers
26610037SARM gem5 Developers    // Initialize configurable default values
26710037SARM gem5 Developers    miscRegs[MISCREG_MIDR] = p->midr;
26810037SARM gem5 Developers    miscRegs[MISCREG_MIDR_EL1] = p->midr;
26910037SARM gem5 Developers    miscRegs[MISCREG_VPIDR] = p->midr;
27010037SARM gem5 Developers
27110037SARM gem5 Developers    if (FullSystem && system->highestELIs64()) {
27210037SARM gem5 Developers        // Initialize AArch64 state
27310037SARM gem5 Developers        clear64(p);
27410037SARM gem5 Developers        return;
27510037SARM gem5 Developers    }
27610037SARM gem5 Developers
27710037SARM gem5 Developers    // Initialize AArch32 state...
27810037SARM gem5 Developers
2797427Sgblack@eecs.umich.edu    CPSR cpsr = 0;
2807427Sgblack@eecs.umich.edu    cpsr.mode = MODE_USER;
2817427Sgblack@eecs.umich.edu    miscRegs[MISCREG_CPSR] = cpsr;
2827427Sgblack@eecs.umich.edu    updateRegMap(cpsr);
2837427Sgblack@eecs.umich.edu
2847427Sgblack@eecs.umich.edu    SCTLR sctlr = 0;
28510037SARM gem5 Developers    sctlr.te = (bool) sctlr_rst.te;
28610037SARM gem5 Developers    sctlr.nmfi = (bool) sctlr_rst.nmfi;
28710037SARM gem5 Developers    sctlr.v = (bool) sctlr_rst.v;
28810037SARM gem5 Developers    sctlr.u = 1;
2897427Sgblack@eecs.umich.edu    sctlr.xp = 1;
2907427Sgblack@eecs.umich.edu    sctlr.rao2 = 1;
2917427Sgblack@eecs.umich.edu    sctlr.rao3 = 1;
29210037SARM gem5 Developers    sctlr.rao4 = 0xf;  // SCTLR[6:3]
29310204SAli.Saidi@ARM.com    sctlr.uci = 1;
29410204SAli.Saidi@ARM.com    sctlr.dze = 1;
29510037SARM gem5 Developers    miscRegs[MISCREG_SCTLR_NS] = sctlr;
2967427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
29710037SARM gem5 Developers    miscRegs[MISCREG_HCPTR] = 0;
2987427Sgblack@eecs.umich.edu
29910037SARM gem5 Developers    // Start with an event in the mailbox
3007427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SEV_MAILBOX] = 1;
3017427Sgblack@eecs.umich.edu
30210037SARM gem5 Developers    // Separate Instruction and Data TLBs
3037427Sgblack@eecs.umich.edu    miscRegs[MISCREG_TLBTR] = 1;
3047427Sgblack@eecs.umich.edu
3057427Sgblack@eecs.umich.edu    MVFR0 mvfr0 = 0;
3067427Sgblack@eecs.umich.edu    mvfr0.advSimdRegisters = 2;
3077427Sgblack@eecs.umich.edu    mvfr0.singlePrecision = 2;
3087427Sgblack@eecs.umich.edu    mvfr0.doublePrecision = 2;
3097427Sgblack@eecs.umich.edu    mvfr0.vfpExceptionTrapping = 0;
3107427Sgblack@eecs.umich.edu    mvfr0.divide = 1;
3117427Sgblack@eecs.umich.edu    mvfr0.squareRoot = 1;
3127427Sgblack@eecs.umich.edu    mvfr0.shortVectors = 1;
3137427Sgblack@eecs.umich.edu    mvfr0.roundingModes = 1;
3147427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR0] = mvfr0;
3157427Sgblack@eecs.umich.edu
3167427Sgblack@eecs.umich.edu    MVFR1 mvfr1 = 0;
3177427Sgblack@eecs.umich.edu    mvfr1.flushToZero = 1;
3187427Sgblack@eecs.umich.edu    mvfr1.defaultNaN = 1;
3197427Sgblack@eecs.umich.edu    mvfr1.advSimdLoadStore = 1;
3207427Sgblack@eecs.umich.edu    mvfr1.advSimdInteger = 1;
3217427Sgblack@eecs.umich.edu    mvfr1.advSimdSinglePrecision = 1;
3227427Sgblack@eecs.umich.edu    mvfr1.advSimdHalfPrecision = 1;
3237427Sgblack@eecs.umich.edu    mvfr1.vfpHalfPrecision = 1;
3247427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR1] = mvfr1;
3257427Sgblack@eecs.umich.edu
3267436Sdam.sunwoo@arm.com    // Reset values of PRRR and NMRR are implementation dependent
3277436Sdam.sunwoo@arm.com
32810037SARM gem5 Developers    // @todo: PRRR and NMRR in secure state?
32910037SARM gem5 Developers    miscRegs[MISCREG_PRRR_NS] =
3307436Sdam.sunwoo@arm.com        (1 << 19) | // 19
3317436Sdam.sunwoo@arm.com        (0 << 18) | // 18
3327436Sdam.sunwoo@arm.com        (0 << 17) | // 17
3337436Sdam.sunwoo@arm.com        (1 << 16) | // 16
3347436Sdam.sunwoo@arm.com        (2 << 14) | // 15:14
3357436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
3367436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
3377436Sdam.sunwoo@arm.com        (2 << 8)  | // 9:8
3387436Sdam.sunwoo@arm.com        (2 << 6)  | // 7:6
3397436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
3407436Sdam.sunwoo@arm.com        (1 << 2)  | // 3:2
3417436Sdam.sunwoo@arm.com        0;          // 1:0
34210037SARM gem5 Developers    miscRegs[MISCREG_NMRR_NS] =
3437436Sdam.sunwoo@arm.com        (1 << 30) | // 31:30
3447436Sdam.sunwoo@arm.com        (0 << 26) | // 27:26
3457436Sdam.sunwoo@arm.com        (0 << 24) | // 25:24
3467436Sdam.sunwoo@arm.com        (3 << 22) | // 23:22
3477436Sdam.sunwoo@arm.com        (2 << 20) | // 21:20
3487436Sdam.sunwoo@arm.com        (0 << 18) | // 19:18
3497436Sdam.sunwoo@arm.com        (0 << 16) | // 17:16
3507436Sdam.sunwoo@arm.com        (1 << 14) | // 15:14
3517436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
3527436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
3537436Sdam.sunwoo@arm.com        (0 << 8)  | // 9:8
3547436Sdam.sunwoo@arm.com        (3 << 6)  | // 7:6
3557436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
3567436Sdam.sunwoo@arm.com        (0 << 2)  | // 3:2
3577436Sdam.sunwoo@arm.com        0;          // 1:0
3587436Sdam.sunwoo@arm.com
3597644Sali.saidi@arm.com    miscRegs[MISCREG_CPACR] = 0;
3608147SAli.Saidi@ARM.com
3619385SAndreas.Sandberg@arm.com
3629385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_PFR0] = p->id_pfr0;
3639385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_PFR1] = p->id_pfr1;
3649385SAndreas.Sandberg@arm.com
3659385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
3669385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
3679385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
3689385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
3699385SAndreas.Sandberg@arm.com
3709385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
3719385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
3729385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
3739385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
3749385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
3759385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
3769385SAndreas.Sandberg@arm.com
3779385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_FPSID] = p->fpsid;
3789385SAndreas.Sandberg@arm.com
37910037SARM gem5 Developers    if (haveLPAE) {
38010037SARM gem5 Developers        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
38110037SARM gem5 Developers        ttbcr.eae = 0;
38210037SARM gem5 Developers        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
38310037SARM gem5 Developers        // Enforce consistency with system-level settings
38410037SARM gem5 Developers        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
38510037SARM gem5 Developers    }
38610037SARM gem5 Developers
38710037SARM gem5 Developers    if (haveSecurity) {
38810037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_S] = sctlr;
38910037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 0;
39010037SARM gem5 Developers        miscRegs[MISCREG_VBAR_S] = 0;
39110037SARM gem5 Developers    } else {
39210037SARM gem5 Developers        // we're always non-secure
39310037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 1;
39410037SARM gem5 Developers    }
3958147SAli.Saidi@ARM.com
3967427Sgblack@eecs.umich.edu    //XXX We need to initialize the rest of the state.
3977427Sgblack@eecs.umich.edu}
3987427Sgblack@eecs.umich.edu
39910037SARM gem5 Developersvoid
40010037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p)
40110037SARM gem5 Developers{
40210037SARM gem5 Developers    CPSR cpsr = 0;
40310037SARM gem5 Developers    Addr rvbar = system->resetAddr64();
40410037SARM gem5 Developers    switch (system->highestEL()) {
40510037SARM gem5 Developers        // Set initial EL to highest implemented EL using associated stack
40610037SARM gem5 Developers        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
40710037SARM gem5 Developers        // value
40810037SARM gem5 Developers      case EL3:
40910037SARM gem5 Developers        cpsr.mode = MODE_EL3H;
41010037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
41110037SARM gem5 Developers        break;
41210037SARM gem5 Developers      case EL2:
41310037SARM gem5 Developers        cpsr.mode = MODE_EL2H;
41410037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
41510037SARM gem5 Developers        break;
41610037SARM gem5 Developers      case EL1:
41710037SARM gem5 Developers        cpsr.mode = MODE_EL1H;
41810037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
41910037SARM gem5 Developers        break;
42010037SARM gem5 Developers      default:
42110037SARM gem5 Developers        panic("Invalid highest implemented exception level");
42210037SARM gem5 Developers        break;
42310037SARM gem5 Developers    }
42410037SARM gem5 Developers
42510037SARM gem5 Developers    // Initialize rest of CPSR
42610037SARM gem5 Developers    cpsr.daif = 0xf;  // Mask all interrupts
42710037SARM gem5 Developers    cpsr.ss = 0;
42810037SARM gem5 Developers    cpsr.il = 0;
42910037SARM gem5 Developers    miscRegs[MISCREG_CPSR] = cpsr;
43010037SARM gem5 Developers    updateRegMap(cpsr);
43110037SARM gem5 Developers
43210037SARM gem5 Developers    // Initialize other control registers
43310037SARM gem5 Developers    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
43410037SARM gem5 Developers    if (haveSecurity) {
43510037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50870;
43610037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
43711574SCurtis.Dunham@arm.com    } else if (haveVirtualization) {
43811574SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_EL2] = 0x30c50870;
43910037SARM gem5 Developers    } else {
44010037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_EL1] = 0x30c50870;
44110037SARM gem5 Developers        // Always non-secure
44210037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3] = 1;
44310037SARM gem5 Developers    }
44410037SARM gem5 Developers
44510037SARM gem5 Developers    // Initialize configurable id registers
44610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
44710037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
44810461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
44910461SAndreas.Sandberg@ARM.com        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
45010461SAndreas.Sandberg@ARM.com        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
45110461SAndreas.Sandberg@ARM.com
45210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
45310037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
45410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
45510037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
45610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
45710037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = p->id_aa64pfr0_el1;
45810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR1_EL1] = p->id_aa64pfr1_el1;
45910037SARM gem5 Developers
46010461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0_EL1] =
46110461SAndreas.Sandberg@ARM.com        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
46210461SAndreas.Sandberg@ARM.com
46310461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
46410461SAndreas.Sandberg@ARM.com
46510037SARM gem5 Developers    // Enforce consistency with system-level settings...
46610037SARM gem5 Developers
46710037SARM gem5 Developers    // EL3
46810037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
46910037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
47011574SCurtis.Dunham@arm.com        haveSecurity ? 0x2 : 0x0);
47110037SARM gem5 Developers    // EL2
47210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
47310037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
47411574SCurtis.Dunham@arm.com        haveVirtualization ? 0x2 : 0x0);
47510037SARM gem5 Developers    // Large ASID support
47610037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
47710037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
47810037SARM gem5 Developers        haveLargeAsid64 ? 0x2 : 0x0);
47910037SARM gem5 Developers    // Physical address size
48010037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
48110037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
48210037SARM gem5 Developers        encodePhysAddrRange64(physAddrRange64));
48310037SARM gem5 Developers}
48410037SARM gem5 Developers
4857405SAli.Saidi@ARM.comMiscReg
48610035Sandreas.hansson@arm.comISA::readMiscRegNoEffect(int misc_reg) const
4877405SAli.Saidi@ARM.com{
4887405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
4897614Sminkyu.jeong@arm.com
49010037SARM gem5 Developers    int flat_idx = flattenMiscIndex(misc_reg);  // Note: indexes of AArch64
49110037SARM gem5 Developers                                                // registers are left unchanged
49210037SARM gem5 Developers    MiscReg val;
4937614Sminkyu.jeong@arm.com
49410037SARM gem5 Developers    if (lookUpMiscReg[flat_idx].lower == 0 || flat_idx == MISCREG_SPSR
49510037SARM gem5 Developers            || flat_idx == MISCREG_SCTLR_EL1) {
49610037SARM gem5 Developers        if (flat_idx == MISCREG_SPSR)
49710037SARM gem5 Developers            flat_idx = flattenMiscIndex(MISCREG_SPSR);
49810037SARM gem5 Developers        if (flat_idx == MISCREG_SCTLR_EL1)
49910037SARM gem5 Developers            flat_idx = flattenMiscIndex(MISCREG_SCTLR);
50010037SARM gem5 Developers        val = miscRegs[flat_idx];
50110037SARM gem5 Developers    } else
50210037SARM gem5 Developers        if (lookUpMiscReg[flat_idx].upper > 0)
50310037SARM gem5 Developers            val = ((miscRegs[lookUpMiscReg[flat_idx].lower] & mask(32))
50410037SARM gem5 Developers                    | (miscRegs[lookUpMiscReg[flat_idx].upper] << 32));
50510037SARM gem5 Developers        else
50610037SARM gem5 Developers            val = miscRegs[lookUpMiscReg[flat_idx].lower];
50710037SARM gem5 Developers
5087614Sminkyu.jeong@arm.com    return val;
5097405SAli.Saidi@ARM.com}
5107405SAli.Saidi@ARM.com
5117405SAli.Saidi@ARM.com
5127405SAli.Saidi@ARM.comMiscReg
5137405SAli.Saidi@ARM.comISA::readMiscReg(int misc_reg, ThreadContext *tc)
5147405SAli.Saidi@ARM.com{
51510037SARM gem5 Developers    CPSR cpsr = 0;
51610037SARM gem5 Developers    PCState pc = 0;
51710037SARM gem5 Developers    SCR scr = 0;
5189050Schander.sudanthi@arm.com
5197405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
52010037SARM gem5 Developers        cpsr = miscRegs[misc_reg];
52110037SARM gem5 Developers        pc = tc->pcState();
5227720Sgblack@eecs.umich.edu        cpsr.j = pc.jazelle() ? 1 : 0;
5237720Sgblack@eecs.umich.edu        cpsr.t = pc.thumb() ? 1 : 0;
5247405SAli.Saidi@ARM.com        return cpsr;
5257405SAli.Saidi@ARM.com    }
5267757SAli.Saidi@ARM.com
52710037SARM gem5 Developers#ifndef NDEBUG
52810037SARM gem5 Developers    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
52910037SARM gem5 Developers        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
53010037SARM gem5 Developers            warn("Unimplemented system register %s read.\n",
53110037SARM gem5 Developers                 miscRegName[misc_reg]);
53210037SARM gem5 Developers        else
53310037SARM gem5 Developers            panic("Unimplemented system register %s read.\n",
53410037SARM gem5 Developers                  miscRegName[misc_reg]);
53510037SARM gem5 Developers    }
53610037SARM gem5 Developers#endif
53710037SARM gem5 Developers
53810037SARM gem5 Developers    switch (unflattenMiscReg(misc_reg)) {
53910037SARM gem5 Developers      case MISCREG_HCR:
54010037SARM gem5 Developers        {
54110037SARM gem5 Developers            if (!haveVirtualization)
54210037SARM gem5 Developers                return 0;
54310037SARM gem5 Developers            else
54410037SARM gem5 Developers                return readMiscRegNoEffect(MISCREG_HCR);
54510037SARM gem5 Developers        }
54610037SARM gem5 Developers      case MISCREG_CPACR:
54710037SARM gem5 Developers        {
54810037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
54910037SARM gem5 Developers            CPACR cpacrMask = 0;
55010037SARM gem5 Developers            // Only cp10, cp11, and ase are implemented, nothing else should
55110037SARM gem5 Developers            // be readable? (straight copy from the write code)
55210037SARM gem5 Developers            cpacrMask.cp10 = ones;
55310037SARM gem5 Developers            cpacrMask.cp11 = ones;
55410037SARM gem5 Developers            cpacrMask.asedis = ones;
55510037SARM gem5 Developers
55610037SARM gem5 Developers            // Security Extensions may limit the readability of CPACR
55710037SARM gem5 Developers            if (haveSecurity) {
55810037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
55910037SARM gem5 Developers                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
56010037SARM gem5 Developers                if (scr.ns && (cpsr.mode != MODE_MON)) {
56110037SARM gem5 Developers                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
56210037SARM gem5 Developers                    // NB: Skipping the full loop, here
56310037SARM gem5 Developers                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
56410037SARM gem5 Developers                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
56510037SARM gem5 Developers                }
56610037SARM gem5 Developers            }
56710037SARM gem5 Developers            MiscReg val = readMiscRegNoEffect(MISCREG_CPACR);
56810037SARM gem5 Developers            val &= cpacrMask;
56910037SARM gem5 Developers            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
57010037SARM gem5 Developers                    miscRegName[misc_reg], val);
57110037SARM gem5 Developers            return val;
57210037SARM gem5 Developers        }
5738284SAli.Saidi@ARM.com      case MISCREG_MPIDR:
57410037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
57510037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
57610037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
57710037SARM gem5 Developers            return getMPIDR(system, tc);
5789050Schander.sudanthi@arm.com        } else {
57910037SARM gem5 Developers            return readMiscReg(MISCREG_VMPIDR, tc);
58010037SARM gem5 Developers        }
58110037SARM gem5 Developers            break;
58210037SARM gem5 Developers      case MISCREG_MPIDR_EL1:
58310037SARM gem5 Developers        // @todo in the absence of v8 virtualization support just return MPIDR_EL1
58410037SARM gem5 Developers        return getMPIDR(system, tc) & 0xffffffff;
58510037SARM gem5 Developers      case MISCREG_VMPIDR:
58610037SARM gem5 Developers        // top bit defined as RES1
58710037SARM gem5 Developers        return readMiscRegNoEffect(misc_reg) | 0x80000000;
58810037SARM gem5 Developers      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
58910037SARM gem5 Developers      case MISCREG_REVIDR:  // not implemented, so alias MIDR
59010037SARM gem5 Developers      case MISCREG_MIDR:
59110037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
59210037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
59310037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
59410037SARM gem5 Developers            return readMiscRegNoEffect(misc_reg);
59510037SARM gem5 Developers        } else {
59610037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_VPIDR);
5979050Schander.sudanthi@arm.com        }
5988284SAli.Saidi@ARM.com        break;
59910037SARM gem5 Developers      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
60010037SARM gem5 Developers      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
60110037SARM gem5 Developers      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
60210037SARM gem5 Developers      case MISCREG_AIDR:  // AUX ID set to 0
60310037SARM gem5 Developers      case MISCREG_TCMTR: // No TCM's
60410037SARM gem5 Developers        return 0;
60510037SARM gem5 Developers
6067405SAli.Saidi@ARM.com      case MISCREG_CLIDR:
6077731SAli.Saidi@ARM.com        warn_once("The clidr register always reports 0 caches.\n");
6088468Swade.walker@arm.com        warn_once("clidr LoUIS field of 0b001 to match current "
6098468Swade.walker@arm.com                  "ARM implementations.\n");
6108468Swade.walker@arm.com        return 0x00200000;
6117405SAli.Saidi@ARM.com      case MISCREG_CCSIDR:
6127731SAli.Saidi@ARM.com        warn_once("The ccsidr register isn't implemented and "
6137405SAli.Saidi@ARM.com                "always reads as 0.\n");
6147405SAli.Saidi@ARM.com        break;
6157583SAli.Saidi@arm.com      case MISCREG_CTR:
6169130Satgutier@umich.edu        {
6179130Satgutier@umich.edu            //all caches have the same line size in gem5
6189130Satgutier@umich.edu            //4 byte words in ARM
6199130Satgutier@umich.edu            unsigned lineSizeWords =
6209814Sandreas.hansson@arm.com                tc->getSystemPtr()->cacheLineSize() / 4;
6219130Satgutier@umich.edu            unsigned log2LineSizeWords = 0;
6229130Satgutier@umich.edu
6239130Satgutier@umich.edu            while (lineSizeWords >>= 1) {
6249130Satgutier@umich.edu                ++log2LineSizeWords;
6259130Satgutier@umich.edu            }
6269130Satgutier@umich.edu
6279130Satgutier@umich.edu            CTR ctr = 0;
6289130Satgutier@umich.edu            //log2 of minimun i-cache line size (words)
6299130Satgutier@umich.edu            ctr.iCacheLineSize = log2LineSizeWords;
6309130Satgutier@umich.edu            //b11 - gem5 uses pipt
6319130Satgutier@umich.edu            ctr.l1IndexPolicy = 0x3;
6329130Satgutier@umich.edu            //log2 of minimum d-cache line size (words)
6339130Satgutier@umich.edu            ctr.dCacheLineSize = log2LineSizeWords;
6349130Satgutier@umich.edu            //log2 of max reservation size (words)
6359130Satgutier@umich.edu            ctr.erg = log2LineSizeWords;
6369130Satgutier@umich.edu            //log2 of max writeback size (words)
6379130Satgutier@umich.edu            ctr.cwg = log2LineSizeWords;
6389130Satgutier@umich.edu            //b100 - gem5 format is ARMv7
6399130Satgutier@umich.edu            ctr.format = 0x4;
6409130Satgutier@umich.edu
6419130Satgutier@umich.edu            return ctr;
6429130Satgutier@umich.edu        }
6437583SAli.Saidi@arm.com      case MISCREG_ACTLR:
6447583SAli.Saidi@arm.com        warn("Not doing anything for miscreg ACTLR\n");
6457583SAli.Saidi@arm.com        break;
64610461SAndreas.Sandberg@ARM.com
64710461SAndreas.Sandberg@ARM.com      case MISCREG_PMXEVTYPER_PMCCFILTR:
64810461SAndreas.Sandberg@ARM.com      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
64910461SAndreas.Sandberg@ARM.com      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
65010461SAndreas.Sandberg@ARM.com      case MISCREG_PMCR ... MISCREG_PMOVSSET:
65110461SAndreas.Sandberg@ARM.com        return pmu->readMiscReg(misc_reg);
65210461SAndreas.Sandberg@ARM.com
6538302SAli.Saidi@ARM.com      case MISCREG_CPSR_Q:
6548302SAli.Saidi@ARM.com        panic("shouldn't be reading this register seperately\n");
6557783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_QC:
6567783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
6577783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_EXC:
6587783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
65910037SARM gem5 Developers      case MISCREG_FPSR:
66010037SARM gem5 Developers        {
66110037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
66210037SARM gem5 Developers            FPSCR fpscrMask = 0;
66310037SARM gem5 Developers            fpscrMask.ioc = ones;
66410037SARM gem5 Developers            fpscrMask.dzc = ones;
66510037SARM gem5 Developers            fpscrMask.ofc = ones;
66610037SARM gem5 Developers            fpscrMask.ufc = ones;
66710037SARM gem5 Developers            fpscrMask.ixc = ones;
66810037SARM gem5 Developers            fpscrMask.idc = ones;
66910037SARM gem5 Developers            fpscrMask.qc = ones;
67010037SARM gem5 Developers            fpscrMask.v = ones;
67110037SARM gem5 Developers            fpscrMask.c = ones;
67210037SARM gem5 Developers            fpscrMask.z = ones;
67310037SARM gem5 Developers            fpscrMask.n = ones;
67410037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
67510037SARM gem5 Developers        }
67610037SARM gem5 Developers      case MISCREG_FPCR:
67710037SARM gem5 Developers        {
67810037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
67910037SARM gem5 Developers            FPSCR fpscrMask  = 0;
68010037SARM gem5 Developers            fpscrMask.ioe = ones;
68110037SARM gem5 Developers            fpscrMask.dze = ones;
68210037SARM gem5 Developers            fpscrMask.ofe = ones;
68310037SARM gem5 Developers            fpscrMask.ufe = ones;
68410037SARM gem5 Developers            fpscrMask.ixe = ones;
68510037SARM gem5 Developers            fpscrMask.ide = ones;
68610037SARM gem5 Developers            fpscrMask.len    = ones;
68710037SARM gem5 Developers            fpscrMask.stride = ones;
68810037SARM gem5 Developers            fpscrMask.rMode  = ones;
68910037SARM gem5 Developers            fpscrMask.fz     = ones;
69010037SARM gem5 Developers            fpscrMask.dn     = ones;
69110037SARM gem5 Developers            fpscrMask.ahp    = ones;
69210037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
69310037SARM gem5 Developers        }
69410037SARM gem5 Developers      case MISCREG_NZCV:
69510037SARM gem5 Developers        {
69610037SARM gem5 Developers            CPSR cpsr = 0;
69710338SCurtis.Dunham@arm.com            cpsr.nz   = tc->readCCReg(CCREG_NZ);
69810338SCurtis.Dunham@arm.com            cpsr.c    = tc->readCCReg(CCREG_C);
69910338SCurtis.Dunham@arm.com            cpsr.v    = tc->readCCReg(CCREG_V);
70010037SARM gem5 Developers            return cpsr;
70110037SARM gem5 Developers        }
70210037SARM gem5 Developers      case MISCREG_DAIF:
70310037SARM gem5 Developers        {
70410037SARM gem5 Developers            CPSR cpsr = 0;
70510037SARM gem5 Developers            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
70610037SARM gem5 Developers            return cpsr;
70710037SARM gem5 Developers        }
70810037SARM gem5 Developers      case MISCREG_SP_EL0:
70910037SARM gem5 Developers        {
71010037SARM gem5 Developers            return tc->readIntReg(INTREG_SP0);
71110037SARM gem5 Developers        }
71210037SARM gem5 Developers      case MISCREG_SP_EL1:
71310037SARM gem5 Developers        {
71410037SARM gem5 Developers            return tc->readIntReg(INTREG_SP1);
71510037SARM gem5 Developers        }
71610037SARM gem5 Developers      case MISCREG_SP_EL2:
71710037SARM gem5 Developers        {
71810037SARM gem5 Developers            return tc->readIntReg(INTREG_SP2);
71910037SARM gem5 Developers        }
72010037SARM gem5 Developers      case MISCREG_SPSEL:
72110037SARM gem5 Developers        {
72210037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0x1;
72310037SARM gem5 Developers        }
72410037SARM gem5 Developers      case MISCREG_CURRENTEL:
72510037SARM gem5 Developers        {
72610037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0xc;
72710037SARM gem5 Developers        }
7288549Sdaniel.johnson@arm.com      case MISCREG_L2CTLR:
7298868SMatt.Horsnell@arm.com        {
7308868SMatt.Horsnell@arm.com            // mostly unimplemented, just set NumCPUs field from sim and return
7318868SMatt.Horsnell@arm.com            L2CTLR l2ctlr = 0;
7328868SMatt.Horsnell@arm.com            // b00:1CPU to b11:4CPUs
7338868SMatt.Horsnell@arm.com            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
7348868SMatt.Horsnell@arm.com            return l2ctlr;
7358868SMatt.Horsnell@arm.com        }
7368868SMatt.Horsnell@arm.com      case MISCREG_DBGDIDR:
7378868SMatt.Horsnell@arm.com        /* For now just implement the version number.
73810461SAndreas.Sandberg@ARM.com         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
7398868SMatt.Horsnell@arm.com         */
74010461SAndreas.Sandberg@ARM.com        return 0x5 << 16;
74110037SARM gem5 Developers      case MISCREG_DBGDSCRint:
7428868SMatt.Horsnell@arm.com        return 0;
74310037SARM gem5 Developers      case MISCREG_ISR:
74411150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
74510037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR),
74610037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
74710037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR));
74810037SARM gem5 Developers      case MISCREG_ISR_EL1:
74911150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
75010037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR_EL2),
75110037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
75210037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR_EL3));
75310037SARM gem5 Developers      case MISCREG_DCZID_EL0:
75410037SARM gem5 Developers        return 0x04;  // DC ZVA clear 64-byte chunks
75510037SARM gem5 Developers      case MISCREG_HCPTR:
75610037SARM gem5 Developers        {
75710037SARM gem5 Developers            MiscReg val = readMiscRegNoEffect(misc_reg);
75810037SARM gem5 Developers            // The trap bit associated with CP14 is defined as RAZ
75910037SARM gem5 Developers            val &= ~(1 << 14);
76010037SARM gem5 Developers            // If a CP bit in NSACR is 0 then the corresponding bit in
76110037SARM gem5 Developers            // HCPTR is RAO/WI
76210037SARM gem5 Developers            bool secure_lookup = haveSecurity &&
76310037SARM gem5 Developers                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
76410037SARM gem5 Developers                              readMiscRegNoEffect(MISCREG_CPSR));
76510037SARM gem5 Developers            if (!secure_lookup) {
76610037SARM gem5 Developers                MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR);
76710037SARM gem5 Developers                val |= (mask ^ 0x7FFF) & 0xBFFF;
76810037SARM gem5 Developers            }
76910037SARM gem5 Developers            // Set the bits for unimplemented coprocessors to RAO/WI
77010037SARM gem5 Developers            val |= 0x33FF;
77110037SARM gem5 Developers            return (val);
77210037SARM gem5 Developers        }
77310037SARM gem5 Developers      case MISCREG_HDFAR: // alias for secure DFAR
77410037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_DFAR_S);
77510037SARM gem5 Developers      case MISCREG_HIFAR: // alias for secure IFAR
77610037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_IFAR_S);
77710037SARM gem5 Developers      case MISCREG_HVBAR: // bottom bits reserved
77810037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0;
77910037SARM gem5 Developers      case MISCREG_SCTLR: // Some bits hardwired
78010037SARM gem5 Developers        // The FI field (bit 21) is common between S/NS versions of the register
78110037SARM gem5 Developers        return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21))  |
78210037SARM gem5 Developers               (readMiscRegNoEffect(misc_reg)        & 0x72DD39FF) | 0x00C00818; // V8 SCTLR
78310037SARM gem5 Developers      case MISCREG_SCTLR_EL1:
78410037SARM gem5 Developers        // The FI field (bit 21) is common between S/NS versions of the register
78510037SARM gem5 Developers        return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21))  |
78610037SARM gem5 Developers               (readMiscRegNoEffect(misc_reg)        & 0x37DDDBFF) | 0x30D00800; // V8 SCTLR_EL1
78710037SARM gem5 Developers      case MISCREG_SCTLR_EL3:
78810037SARM gem5 Developers        // The FI field (bit 21) is common between S/NS versions of the register
78910037SARM gem5 Developers        return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21))  |
79010037SARM gem5 Developers               (readMiscRegNoEffect(misc_reg)        & 0x32CD183F) | 0x30C50830; // V8 SCTLR_EL3
79110037SARM gem5 Developers      case MISCREG_HSCTLR: // FI comes from SCTLR
79210037SARM gem5 Developers        {
79310037SARM gem5 Developers            uint32_t mask = 1 << 27;
79410037SARM gem5 Developers            return (readMiscRegNoEffect(MISCREG_HSCTLR) & ~mask) |
79510037SARM gem5 Developers                (readMiscRegNoEffect(MISCREG_SCTLR)  &  mask);
79610037SARM gem5 Developers        }
79710844Sandreas.sandberg@arm.com
79810037SARM gem5 Developers      // Generic Timer registers
79910844Sandreas.sandberg@arm.com      case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
80010844Sandreas.sandberg@arm.com      case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
80110844Sandreas.sandberg@arm.com      case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
80210844Sandreas.sandberg@arm.com      case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
80310844Sandreas.sandberg@arm.com        return getGenericTimer(tc).readMiscReg(misc_reg);
80410844Sandreas.sandberg@arm.com
80510188Sgeoffrey.blake@arm.com      default:
80610037SARM gem5 Developers        break;
80710037SARM gem5 Developers
8087405SAli.Saidi@ARM.com    }
8097405SAli.Saidi@ARM.com    return readMiscRegNoEffect(misc_reg);
8107405SAli.Saidi@ARM.com}
8117405SAli.Saidi@ARM.com
8127405SAli.Saidi@ARM.comvoid
8137405SAli.Saidi@ARM.comISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val)
8147405SAli.Saidi@ARM.com{
8157405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
8167614Sminkyu.jeong@arm.com
81710037SARM gem5 Developers    int flat_idx = flattenMiscIndex(misc_reg);  // Note: indexes of AArch64
81810037SARM gem5 Developers                                                // registers are left unchanged
8197614Sminkyu.jeong@arm.com
82010037SARM gem5 Developers    int flat_idx2 = lookUpMiscReg[flat_idx].upper;
82110037SARM gem5 Developers
82210037SARM gem5 Developers    if (flat_idx2 > 0) {
82310037SARM gem5 Developers        miscRegs[lookUpMiscReg[flat_idx].lower] = bits(val, 31, 0);
82410037SARM gem5 Developers        miscRegs[flat_idx2] = bits(val, 63, 32);
82510037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
82610037SARM gem5 Developers                misc_reg, flat_idx, flat_idx2, val);
82710037SARM gem5 Developers    } else {
82810037SARM gem5 Developers        if (flat_idx == MISCREG_SPSR)
82910037SARM gem5 Developers            flat_idx = flattenMiscIndex(MISCREG_SPSR);
83010037SARM gem5 Developers        else if (flat_idx == MISCREG_SCTLR_EL1)
83110037SARM gem5 Developers            flat_idx = flattenMiscIndex(MISCREG_SCTLR);
83210037SARM gem5 Developers        else
83310037SARM gem5 Developers            flat_idx = (lookUpMiscReg[flat_idx].lower > 0) ?
83410037SARM gem5 Developers                       lookUpMiscReg[flat_idx].lower : flat_idx;
83510037SARM gem5 Developers        miscRegs[flat_idx] = val;
83610037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
83710037SARM gem5 Developers                misc_reg, flat_idx, val);
83810037SARM gem5 Developers    }
8397405SAli.Saidi@ARM.com}
8407405SAli.Saidi@ARM.com
8417405SAli.Saidi@ARM.comvoid
8427405SAli.Saidi@ARM.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
8437405SAli.Saidi@ARM.com{
8447749SAli.Saidi@ARM.com
8457405SAli.Saidi@ARM.com    MiscReg newVal = val;
8468284SAli.Saidi@ARM.com    int x;
84710037SARM gem5 Developers    bool secure_lookup;
84810037SARM gem5 Developers    bool hyp;
8498284SAli.Saidi@ARM.com    System *sys;
8508284SAli.Saidi@ARM.com    ThreadContext *oc;
85110037SARM gem5 Developers    uint8_t target_el;
85210037SARM gem5 Developers    uint16_t asid;
85310037SARM gem5 Developers    SCR scr;
8548284SAli.Saidi@ARM.com
8557405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
8567405SAli.Saidi@ARM.com        updateRegMap(val);
8577749SAli.Saidi@ARM.com
8587749SAli.Saidi@ARM.com
8597749SAli.Saidi@ARM.com        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
8607749SAli.Saidi@ARM.com        int old_mode = old_cpsr.mode;
8617405SAli.Saidi@ARM.com        CPSR cpsr = val;
8627749SAli.Saidi@ARM.com        if (old_mode != cpsr.mode) {
8637749SAli.Saidi@ARM.com            tc->getITBPtr()->invalidateMiscReg();
8647749SAli.Saidi@ARM.com            tc->getDTBPtr()->invalidateMiscReg();
8657749SAli.Saidi@ARM.com        }
8667749SAli.Saidi@ARM.com
8677614Sminkyu.jeong@arm.com        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
8687614Sminkyu.jeong@arm.com                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
8697720Sgblack@eecs.umich.edu        PCState pc = tc->pcState();
8707720Sgblack@eecs.umich.edu        pc.nextThumb(cpsr.t);
8717720Sgblack@eecs.umich.edu        pc.nextJazelle(cpsr.j);
8728887Sgeoffrey.blake@arm.com
8738887Sgeoffrey.blake@arm.com        // Follow slightly different semantics if a CheckerCPU object
8748887Sgeoffrey.blake@arm.com        // is connected
8758887Sgeoffrey.blake@arm.com        CheckerCPU *checker = tc->getCheckerCpuPtr();
8768887Sgeoffrey.blake@arm.com        if (checker) {
8778887Sgeoffrey.blake@arm.com            tc->pcStateNoRecord(pc);
8788887Sgeoffrey.blake@arm.com        } else {
8798887Sgeoffrey.blake@arm.com            tc->pcState(pc);
8808887Sgeoffrey.blake@arm.com        }
8817408Sgblack@eecs.umich.edu    } else {
88210037SARM gem5 Developers#ifndef NDEBUG
88310037SARM gem5 Developers        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
88410037SARM gem5 Developers            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
88510037SARM gem5 Developers                warn("Unimplemented system register %s write with %#x.\n",
88610037SARM gem5 Developers                    miscRegName[misc_reg], val);
88710037SARM gem5 Developers            else
88810037SARM gem5 Developers                panic("Unimplemented system register %s write with %#x.\n",
88910037SARM gem5 Developers                    miscRegName[misc_reg], val);
89010037SARM gem5 Developers        }
89110037SARM gem5 Developers#endif
89210037SARM gem5 Developers        switch (unflattenMiscReg(misc_reg)) {
8937408Sgblack@eecs.umich.edu          case MISCREG_CPACR:
8947408Sgblack@eecs.umich.edu            {
8958206SWilliam.Wang@arm.com
8968206SWilliam.Wang@arm.com                const uint32_t ones = (uint32_t)(-1);
8978206SWilliam.Wang@arm.com                CPACR cpacrMask = 0;
8988206SWilliam.Wang@arm.com                // Only cp10, cp11, and ase are implemented, nothing else should
8998206SWilliam.Wang@arm.com                // be writable
9008206SWilliam.Wang@arm.com                cpacrMask.cp10 = ones;
9018206SWilliam.Wang@arm.com                cpacrMask.cp11 = ones;
9028206SWilliam.Wang@arm.com                cpacrMask.asedis = ones;
90310037SARM gem5 Developers
90410037SARM gem5 Developers                // Security Extensions may limit the writability of CPACR
90510037SARM gem5 Developers                if (haveSecurity) {
90610037SARM gem5 Developers                    scr = readMiscRegNoEffect(MISCREG_SCR);
90710037SARM gem5 Developers                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
90810037SARM gem5 Developers                    if (scr.ns && (cpsr.mode != MODE_MON)) {
90910037SARM gem5 Developers                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
91010037SARM gem5 Developers                        // NB: Skipping the full loop, here
91110037SARM gem5 Developers                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
91210037SARM gem5 Developers                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
91310037SARM gem5 Developers                    }
91410037SARM gem5 Developers                }
91510037SARM gem5 Developers
91610037SARM gem5 Developers                MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR);
9178206SWilliam.Wang@arm.com                newVal &= cpacrMask;
91810037SARM gem5 Developers                newVal |= old_val & ~cpacrMask;
91910037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
92010037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
92110037SARM gem5 Developers            }
92210037SARM gem5 Developers            break;
92310037SARM gem5 Developers          case MISCREG_CPACR_EL1:
92410037SARM gem5 Developers            {
92510037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
92610037SARM gem5 Developers                CPACR cpacrMask = 0;
92710037SARM gem5 Developers                cpacrMask.tta = ones;
92810037SARM gem5 Developers                cpacrMask.fpen = ones;
92910037SARM gem5 Developers                newVal &= cpacrMask;
93010037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
93110037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
93210037SARM gem5 Developers            }
93310037SARM gem5 Developers            break;
93410037SARM gem5 Developers          case MISCREG_CPTR_EL2:
93510037SARM gem5 Developers            {
93610037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
93710037SARM gem5 Developers                CPTR cptrMask = 0;
93810037SARM gem5 Developers                cptrMask.tcpac = ones;
93910037SARM gem5 Developers                cptrMask.tta = ones;
94010037SARM gem5 Developers                cptrMask.tfp = ones;
94110037SARM gem5 Developers                newVal &= cptrMask;
94210037SARM gem5 Developers                cptrMask = 0;
94310037SARM gem5 Developers                cptrMask.res1_13_12_el2 = ones;
94410037SARM gem5 Developers                cptrMask.res1_9_0_el2 = ones;
94510037SARM gem5 Developers                newVal |= cptrMask;
94610037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
94710037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
94810037SARM gem5 Developers            }
94910037SARM gem5 Developers            break;
95010037SARM gem5 Developers          case MISCREG_CPTR_EL3:
95110037SARM gem5 Developers            {
95210037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
95310037SARM gem5 Developers                CPTR cptrMask = 0;
95410037SARM gem5 Developers                cptrMask.tcpac = ones;
95510037SARM gem5 Developers                cptrMask.tta = ones;
95610037SARM gem5 Developers                cptrMask.tfp = ones;
95710037SARM gem5 Developers                newVal &= cptrMask;
9588206SWilliam.Wang@arm.com                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
9598206SWilliam.Wang@arm.com                        miscRegName[misc_reg], newVal);
9607408Sgblack@eecs.umich.edu            }
9617408Sgblack@eecs.umich.edu            break;
9627408Sgblack@eecs.umich.edu          case MISCREG_CSSELR:
9637731SAli.Saidi@ARM.com            warn_once("The csselr register isn't implemented.\n");
9648206SWilliam.Wang@arm.com            return;
96510037SARM gem5 Developers
96610037SARM gem5 Developers          case MISCREG_DC_ZVA_Xt:
96710037SARM gem5 Developers            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
96810037SARM gem5 Developers            return;
96910037SARM gem5 Developers
9707408Sgblack@eecs.umich.edu          case MISCREG_FPSCR:
9717408Sgblack@eecs.umich.edu            {
9727408Sgblack@eecs.umich.edu                const uint32_t ones = (uint32_t)(-1);
9737408Sgblack@eecs.umich.edu                FPSCR fpscrMask = 0;
9747408Sgblack@eecs.umich.edu                fpscrMask.ioc = ones;
9757408Sgblack@eecs.umich.edu                fpscrMask.dzc = ones;
9767408Sgblack@eecs.umich.edu                fpscrMask.ofc = ones;
9777408Sgblack@eecs.umich.edu                fpscrMask.ufc = ones;
9787408Sgblack@eecs.umich.edu                fpscrMask.ixc = ones;
9797408Sgblack@eecs.umich.edu                fpscrMask.idc = ones;
98010037SARM gem5 Developers                fpscrMask.ioe = ones;
98110037SARM gem5 Developers                fpscrMask.dze = ones;
98210037SARM gem5 Developers                fpscrMask.ofe = ones;
98310037SARM gem5 Developers                fpscrMask.ufe = ones;
98410037SARM gem5 Developers                fpscrMask.ixe = ones;
98510037SARM gem5 Developers                fpscrMask.ide = ones;
9867408Sgblack@eecs.umich.edu                fpscrMask.len = ones;
9877408Sgblack@eecs.umich.edu                fpscrMask.stride = ones;
9887408Sgblack@eecs.umich.edu                fpscrMask.rMode = ones;
9897408Sgblack@eecs.umich.edu                fpscrMask.fz = ones;
9907408Sgblack@eecs.umich.edu                fpscrMask.dn = ones;
9917408Sgblack@eecs.umich.edu                fpscrMask.ahp = ones;
9927408Sgblack@eecs.umich.edu                fpscrMask.qc = ones;
9937408Sgblack@eecs.umich.edu                fpscrMask.v = ones;
9947408Sgblack@eecs.umich.edu                fpscrMask.c = ones;
9957408Sgblack@eecs.umich.edu                fpscrMask.z = ones;
9967408Sgblack@eecs.umich.edu                fpscrMask.n = ones;
9977408Sgblack@eecs.umich.edu                newVal = (newVal & (uint32_t)fpscrMask) |
99810037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
99910037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
10009377Sgblack@eecs.umich.edu                tc->getDecoderPtr()->setContext(newVal);
10017408Sgblack@eecs.umich.edu            }
10027408Sgblack@eecs.umich.edu            break;
100310037SARM gem5 Developers          case MISCREG_FPSR:
100410037SARM gem5 Developers            {
100510037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
100610037SARM gem5 Developers                FPSCR fpscrMask = 0;
100710037SARM gem5 Developers                fpscrMask.ioc = ones;
100810037SARM gem5 Developers                fpscrMask.dzc = ones;
100910037SARM gem5 Developers                fpscrMask.ofc = ones;
101010037SARM gem5 Developers                fpscrMask.ufc = ones;
101110037SARM gem5 Developers                fpscrMask.ixc = ones;
101210037SARM gem5 Developers                fpscrMask.idc = ones;
101310037SARM gem5 Developers                fpscrMask.qc = ones;
101410037SARM gem5 Developers                fpscrMask.v = ones;
101510037SARM gem5 Developers                fpscrMask.c = ones;
101610037SARM gem5 Developers                fpscrMask.z = ones;
101710037SARM gem5 Developers                fpscrMask.n = ones;
101810037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
101910037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
102010037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
102110037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
102210037SARM gem5 Developers            }
102310037SARM gem5 Developers            break;
102410037SARM gem5 Developers          case MISCREG_FPCR:
102510037SARM gem5 Developers            {
102610037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
102710037SARM gem5 Developers                FPSCR fpscrMask  = 0;
102810037SARM gem5 Developers                fpscrMask.ioe = ones;
102910037SARM gem5 Developers                fpscrMask.dze = ones;
103010037SARM gem5 Developers                fpscrMask.ofe = ones;
103110037SARM gem5 Developers                fpscrMask.ufe = ones;
103210037SARM gem5 Developers                fpscrMask.ixe = ones;
103310037SARM gem5 Developers                fpscrMask.ide = ones;
103410037SARM gem5 Developers                fpscrMask.len    = ones;
103510037SARM gem5 Developers                fpscrMask.stride = ones;
103610037SARM gem5 Developers                fpscrMask.rMode  = ones;
103710037SARM gem5 Developers                fpscrMask.fz     = ones;
103810037SARM gem5 Developers                fpscrMask.dn     = ones;
103910037SARM gem5 Developers                fpscrMask.ahp    = ones;
104010037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
104110037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
104210037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
104310037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
104410037SARM gem5 Developers            }
104510037SARM gem5 Developers            break;
10468302SAli.Saidi@ARM.com          case MISCREG_CPSR_Q:
10478302SAli.Saidi@ARM.com            {
10488302SAli.Saidi@ARM.com                assert(!(newVal & ~CpsrMaskQ));
104910037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
10508302SAli.Saidi@ARM.com                misc_reg = MISCREG_CPSR;
10518302SAli.Saidi@ARM.com            }
10528302SAli.Saidi@ARM.com            break;
10537783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_QC:
10547783SGiacomo.Gabrielli@arm.com            {
105510037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
105610037SARM gem5 Developers                         (newVal & FpscrQcMask);
10577783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
10587783SGiacomo.Gabrielli@arm.com            }
10597783SGiacomo.Gabrielli@arm.com            break;
10607783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_EXC:
10617783SGiacomo.Gabrielli@arm.com            {
106210037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
106310037SARM gem5 Developers                         (newVal & FpscrExcMask);
10647783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
10657783SGiacomo.Gabrielli@arm.com            }
10667783SGiacomo.Gabrielli@arm.com            break;
10677408Sgblack@eecs.umich.edu          case MISCREG_FPEXC:
10687408Sgblack@eecs.umich.edu            {
10698206SWilliam.Wang@arm.com                // vfpv3 architecture, section B.6.1 of DDI04068
10708206SWilliam.Wang@arm.com                // bit 29 - valid only if fpexc[31] is 0
10717408Sgblack@eecs.umich.edu                const uint32_t fpexcMask = 0x60000000;
10727408Sgblack@eecs.umich.edu                newVal = (newVal & fpexcMask) |
107310037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
10747408Sgblack@eecs.umich.edu            }
10757408Sgblack@eecs.umich.edu            break;
107610037SARM gem5 Developers          case MISCREG_HCR:
107710037SARM gem5 Developers            {
107810037SARM gem5 Developers                if (!haveVirtualization)
107910037SARM gem5 Developers                    return;
108010037SARM gem5 Developers            }
108110037SARM gem5 Developers            break;
108210037SARM gem5 Developers          case MISCREG_IFSR:
108310037SARM gem5 Developers            {
108410037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.96
108510037SARM gem5 Developers                const uint32_t ifsrMask =
108610037SARM gem5 Developers                    mask(31, 13) | mask(11, 11) | mask(8, 6);
108710037SARM gem5 Developers                newVal = newVal & ~ifsrMask;
108810037SARM gem5 Developers            }
108910037SARM gem5 Developers            break;
109010037SARM gem5 Developers          case MISCREG_DFSR:
109110037SARM gem5 Developers            {
109210037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.52
109310037SARM gem5 Developers                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
109410037SARM gem5 Developers                newVal = newVal & ~dfsrMask;
109510037SARM gem5 Developers            }
109610037SARM gem5 Developers            break;
109710037SARM gem5 Developers          case MISCREG_AMAIR0:
109810037SARM gem5 Developers          case MISCREG_AMAIR1:
109910037SARM gem5 Developers            {
110010037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.5
110110037SARM gem5 Developers                // Valid only with LPAE
110210037SARM gem5 Developers                if (!haveLPAE)
110310037SARM gem5 Developers                    return;
110410037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
110510037SARM gem5 Developers            }
110610037SARM gem5 Developers            break;
110710037SARM gem5 Developers          case MISCREG_SCR:
110810037SARM gem5 Developers            tc->getITBPtr()->invalidateMiscReg();
110910037SARM gem5 Developers            tc->getDTBPtr()->invalidateMiscReg();
111010037SARM gem5 Developers            break;
11117408Sgblack@eecs.umich.edu          case MISCREG_SCTLR:
11127408Sgblack@eecs.umich.edu            {
11137408Sgblack@eecs.umich.edu                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
111410037SARM gem5 Developers                MiscRegIndex sctlr_idx;
111510037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
111610037SARM gem5 Developers                if (haveSecurity && !scr.ns) {
111710037SARM gem5 Developers                    sctlr_idx = MISCREG_SCTLR_S;
111810037SARM gem5 Developers                } else {
111910037SARM gem5 Developers                    sctlr_idx = MISCREG_SCTLR_NS;
112010037SARM gem5 Developers                    // The FI field (bit 21) is common between S/NS versions
112110037SARM gem5 Developers                    // of the register, we store this in the secure copy of
112210037SARM gem5 Developers                    // the reg
112310037SARM gem5 Developers                    miscRegs[MISCREG_SCTLR_S] &=         ~(1 << 21);
112410037SARM gem5 Developers                    miscRegs[MISCREG_SCTLR_S] |= newVal & (1 << 21);
112510037SARM gem5 Developers                }
112610037SARM gem5 Developers                SCTLR sctlr = miscRegs[sctlr_idx];
11277408Sgblack@eecs.umich.edu                SCTLR new_sctlr = newVal;
112810037SARM gem5 Developers                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
112910037SARM gem5 Developers                miscRegs[sctlr_idx] = (MiscReg)new_sctlr;
11307749SAli.Saidi@ARM.com                tc->getITBPtr()->invalidateMiscReg();
11317749SAli.Saidi@ARM.com                tc->getDTBPtr()->invalidateMiscReg();
11327408Sgblack@eecs.umich.edu            }
11339385SAndreas.Sandberg@arm.com          case MISCREG_MIDR:
11349385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR0:
11359385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR1:
113610461SAndreas.Sandberg@ARM.com          case MISCREG_ID_DFR0:
11379385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR0:
11389385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR1:
11399385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR2:
11409385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR3:
11419385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR0:
11429385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR1:
11439385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR2:
11449385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR3:
11459385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR4:
11469385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR5:
11479385SAndreas.Sandberg@arm.com
11489385SAndreas.Sandberg@arm.com          case MISCREG_MPIDR:
11499385SAndreas.Sandberg@arm.com          case MISCREG_FPSID:
11507408Sgblack@eecs.umich.edu          case MISCREG_TLBTR:
11517408Sgblack@eecs.umich.edu          case MISCREG_MVFR0:
11527408Sgblack@eecs.umich.edu          case MISCREG_MVFR1:
115310037SARM gem5 Developers
115410037SARM gem5 Developers          case MISCREG_ID_AA64AFR0_EL1:
115510037SARM gem5 Developers          case MISCREG_ID_AA64AFR1_EL1:
115610037SARM gem5 Developers          case MISCREG_ID_AA64DFR0_EL1:
115710037SARM gem5 Developers          case MISCREG_ID_AA64DFR1_EL1:
115810037SARM gem5 Developers          case MISCREG_ID_AA64ISAR0_EL1:
115910037SARM gem5 Developers          case MISCREG_ID_AA64ISAR1_EL1:
116010037SARM gem5 Developers          case MISCREG_ID_AA64MMFR0_EL1:
116110037SARM gem5 Developers          case MISCREG_ID_AA64MMFR1_EL1:
116210037SARM gem5 Developers          case MISCREG_ID_AA64PFR0_EL1:
116310037SARM gem5 Developers          case MISCREG_ID_AA64PFR1_EL1:
11649385SAndreas.Sandberg@arm.com            // ID registers are constants.
11657408Sgblack@eecs.umich.edu            return;
11669385SAndreas.Sandberg@arm.com
116710037SARM gem5 Developers          // TLBI all entries, EL0&1 inner sharable (ignored)
11687408Sgblack@eecs.umich.edu          case MISCREG_TLBIALLIS:
116910037SARM gem5 Developers          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
117010037SARM gem5 Developers            assert32(tc);
117110037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
117210037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
117310037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
11748284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
11758284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
11768284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
11778284SAli.Saidi@ARM.com                assert(oc->getITBPtr() && oc->getDTBPtr());
117810037SARM gem5 Developers                oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el);
117910037SARM gem5 Developers                oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el);
11808887Sgeoffrey.blake@arm.com
11818887Sgeoffrey.blake@arm.com                // If CheckerCPU is connected, need to notify it of a flush
11828887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
11838733Sgeoffrey.blake@arm.com                if (checker) {
118410037SARM gem5 Developers                    checker->getITBPtr()->flushAllSecurity(secure_lookup,
118510037SARM gem5 Developers                                                           target_el);
118610037SARM gem5 Developers                    checker->getDTBPtr()->flushAllSecurity(secure_lookup,
118710037SARM gem5 Developers                                                           target_el);
11888733Sgeoffrey.blake@arm.com                }
11898284SAli.Saidi@ARM.com            }
11907408Sgblack@eecs.umich.edu            return;
119110037SARM gem5 Developers          // TLBI all entries, EL0&1, instruction side
11927408Sgblack@eecs.umich.edu          case MISCREG_ITLBIALL:
119310037SARM gem5 Developers            assert32(tc);
119410037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
119510037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
119610037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
119710037SARM gem5 Developers            tc->getITBPtr()->flushAllSecurity(secure_lookup, target_el);
11987408Sgblack@eecs.umich.edu            return;
119910037SARM gem5 Developers          // TLBI all entries, EL0&1, data side
12007408Sgblack@eecs.umich.edu          case MISCREG_DTLBIALL:
120110037SARM gem5 Developers            assert32(tc);
120210037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
120310037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
120410037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
120510037SARM gem5 Developers            tc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el);
12067408Sgblack@eecs.umich.edu            return;
120710037SARM gem5 Developers          // TLBI based on VA, EL0&1 inner sharable (ignored)
12087408Sgblack@eecs.umich.edu          case MISCREG_TLBIMVAIS:
12097408Sgblack@eecs.umich.edu          case MISCREG_TLBIMVA:
121010037SARM gem5 Developers            assert32(tc);
121110037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
121210037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
121310037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
12148284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
12158284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
12168284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
12178284SAli.Saidi@ARM.com                assert(oc->getITBPtr() && oc->getDTBPtr());
12188284SAli.Saidi@ARM.com                oc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
121910037SARM gem5 Developers                                              bits(newVal, 7,0),
122010037SARM gem5 Developers                                              secure_lookup, target_el);
12218284SAli.Saidi@ARM.com                oc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
122210037SARM gem5 Developers                                              bits(newVal, 7,0),
122310037SARM gem5 Developers                                              secure_lookup, target_el);
12248887Sgeoffrey.blake@arm.com
12258887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
12268733Sgeoffrey.blake@arm.com                if (checker) {
12278733Sgeoffrey.blake@arm.com                    checker->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
122810037SARM gem5 Developers                        bits(newVal, 7,0), secure_lookup, target_el);
12298733Sgeoffrey.blake@arm.com                    checker->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
123010037SARM gem5 Developers                        bits(newVal, 7,0), secure_lookup, target_el);
12318733Sgeoffrey.blake@arm.com                }
12328284SAli.Saidi@ARM.com            }
12337408Sgblack@eecs.umich.edu            return;
123410037SARM gem5 Developers          // TLBI by ASID, EL0&1, inner sharable
12357408Sgblack@eecs.umich.edu          case MISCREG_TLBIASIDIS:
12367408Sgblack@eecs.umich.edu          case MISCREG_TLBIASID:
123710037SARM gem5 Developers            assert32(tc);
123810037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
123910037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
124010037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
12418284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
12428284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
12438284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
12448284SAli.Saidi@ARM.com                assert(oc->getITBPtr() && oc->getDTBPtr());
124510037SARM gem5 Developers                oc->getITBPtr()->flushAsid(bits(newVal, 7,0),
124610037SARM gem5 Developers                    secure_lookup, target_el);
124710037SARM gem5 Developers                oc->getDTBPtr()->flushAsid(bits(newVal, 7,0),
124810037SARM gem5 Developers                    secure_lookup, target_el);
12498887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
12508733Sgeoffrey.blake@arm.com                if (checker) {
125110037SARM gem5 Developers                    checker->getITBPtr()->flushAsid(bits(newVal, 7,0),
125210037SARM gem5 Developers                        secure_lookup, target_el);
125310037SARM gem5 Developers                    checker->getDTBPtr()->flushAsid(bits(newVal, 7,0),
125410037SARM gem5 Developers                        secure_lookup, target_el);
12558733Sgeoffrey.blake@arm.com                }
12568284SAli.Saidi@ARM.com            }
12577408Sgblack@eecs.umich.edu            return;
125810037SARM gem5 Developers          // TLBI by address, EL0&1, inner sharable (ignored)
12597408Sgblack@eecs.umich.edu          case MISCREG_TLBIMVAAIS:
12607408Sgblack@eecs.umich.edu          case MISCREG_TLBIMVAA:
126110037SARM gem5 Developers            assert32(tc);
126210037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
126310037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
126410037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
126510037SARM gem5 Developers            hyp = 0;
126610037SARM gem5 Developers            tlbiMVA(tc, newVal, secure_lookup, hyp, target_el);
126710037SARM gem5 Developers            return;
126810037SARM gem5 Developers          // TLBI by address, EL2, hypervisor mode
126910037SARM gem5 Developers          case MISCREG_TLBIMVAH:
127010037SARM gem5 Developers          case MISCREG_TLBIMVAHIS:
127110037SARM gem5 Developers            assert32(tc);
127210037SARM gem5 Developers            target_el = 1; // aarch32, use hyp bit
127310037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
127410037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
127510037SARM gem5 Developers            hyp = 1;
127610037SARM gem5 Developers            tlbiMVA(tc, newVal, secure_lookup, hyp, target_el);
127710037SARM gem5 Developers            return;
127810037SARM gem5 Developers          // TLBI by address and asid, EL0&1, instruction side only
127910037SARM gem5 Developers          case MISCREG_ITLBIMVA:
128010037SARM gem5 Developers            assert32(tc);
128110037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
128210037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
128310037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
128410037SARM gem5 Developers            tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
128510037SARM gem5 Developers                bits(newVal, 7,0), secure_lookup, target_el);
128610037SARM gem5 Developers            return;
128710037SARM gem5 Developers          // TLBI by address and asid, EL0&1, data side only
128810037SARM gem5 Developers          case MISCREG_DTLBIMVA:
128910037SARM gem5 Developers            assert32(tc);
129010037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
129110037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
129210037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
129310037SARM gem5 Developers            tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12),
129410037SARM gem5 Developers                bits(newVal, 7,0), secure_lookup, target_el);
129510037SARM gem5 Developers            return;
129610037SARM gem5 Developers          // TLBI by ASID, EL0&1, instrution side only
129710037SARM gem5 Developers          case MISCREG_ITLBIASID:
129810037SARM gem5 Developers            assert32(tc);
129910037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
130010037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
130110037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
130210037SARM gem5 Developers            tc->getITBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup,
130310037SARM gem5 Developers                                       target_el);
130410037SARM gem5 Developers            return;
130510037SARM gem5 Developers          // TLBI by ASID EL0&1 data size only
130610037SARM gem5 Developers          case MISCREG_DTLBIASID:
130710037SARM gem5 Developers            assert32(tc);
130810037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
130910037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
131010037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
131110037SARM gem5 Developers            tc->getDTBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup,
131210037SARM gem5 Developers                                       target_el);
131310037SARM gem5 Developers            return;
131410037SARM gem5 Developers          // Invalidate entire Non-secure Hyp/Non-Hyp Unified TLB
131510037SARM gem5 Developers          case MISCREG_TLBIALLNSNH:
131610037SARM gem5 Developers          case MISCREG_TLBIALLNSNHIS:
131710037SARM gem5 Developers            assert32(tc);
131810037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
131910037SARM gem5 Developers            hyp = 0;
132010037SARM gem5 Developers            tlbiALLN(tc, hyp, target_el);
132110037SARM gem5 Developers            return;
132210037SARM gem5 Developers          // TLBI all entries, EL2, hyp,
132310037SARM gem5 Developers          case MISCREG_TLBIALLH:
132410037SARM gem5 Developers          case MISCREG_TLBIALLHIS:
132510037SARM gem5 Developers            assert32(tc);
132610037SARM gem5 Developers            target_el = 1; // aarch32, use hyp bit
132710037SARM gem5 Developers            hyp = 1;
132810037SARM gem5 Developers            tlbiALLN(tc, hyp, target_el);
132910037SARM gem5 Developers            return;
133010037SARM gem5 Developers          // AArch64 TLBI: invalidate all entries EL3
133110037SARM gem5 Developers          case MISCREG_TLBI_ALLE3IS:
133210037SARM gem5 Developers          case MISCREG_TLBI_ALLE3:
133310037SARM gem5 Developers            assert64(tc);
133410037SARM gem5 Developers            target_el = 3;
133510037SARM gem5 Developers            secure_lookup = true;
133610037SARM gem5 Developers            tlbiALL(tc, secure_lookup, target_el);
133710037SARM gem5 Developers            return;
133810037SARM gem5 Developers          // @todo: uncomment this to enable Virtualization
133910037SARM gem5 Developers          // case MISCREG_TLBI_ALLE2IS:
134010037SARM gem5 Developers          // case MISCREG_TLBI_ALLE2:
134110037SARM gem5 Developers          // TLBI all entries, EL0&1
134210037SARM gem5 Developers          case MISCREG_TLBI_ALLE1IS:
134310037SARM gem5 Developers          case MISCREG_TLBI_ALLE1:
134410037SARM gem5 Developers          // AArch64 TLBI: invalidate all entries, stage 1, current VMID
134510037SARM gem5 Developers          case MISCREG_TLBI_VMALLE1IS:
134610037SARM gem5 Developers          case MISCREG_TLBI_VMALLE1:
134710037SARM gem5 Developers          // AArch64 TLBI: invalidate all entries, stages 1 & 2, current VMID
134810037SARM gem5 Developers          case MISCREG_TLBI_VMALLS12E1IS:
134910037SARM gem5 Developers          case MISCREG_TLBI_VMALLS12E1:
135010037SARM gem5 Developers            // @todo: handle VMID and stage 2 to enable Virtualization
135110037SARM gem5 Developers            assert64(tc);
135210037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
135310037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
135410037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
135510037SARM gem5 Developers            tlbiALL(tc, secure_lookup, target_el);
135610037SARM gem5 Developers            return;
135710037SARM gem5 Developers          // AArch64 TLBI: invalidate by VA and ASID, stage 1, current VMID
135810037SARM gem5 Developers          // VAEx(IS) and VALEx(IS) are the same because TLBs only store entries
135910037SARM gem5 Developers          // from the last level of translation table walks
136010037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
136110037SARM gem5 Developers          // TLBI all entries, EL0&1
136210037SARM gem5 Developers          case MISCREG_TLBI_VAE3IS_Xt:
136310037SARM gem5 Developers          case MISCREG_TLBI_VAE3_Xt:
136410037SARM gem5 Developers          // TLBI by VA, EL3  regime stage 1, last level walk
136510037SARM gem5 Developers          case MISCREG_TLBI_VALE3IS_Xt:
136610037SARM gem5 Developers          case MISCREG_TLBI_VALE3_Xt:
136710037SARM gem5 Developers            assert64(tc);
136810037SARM gem5 Developers            target_el = 3;
136910037SARM gem5 Developers            asid = 0xbeef; // does not matter, tlbi is global
137010037SARM gem5 Developers            secure_lookup = true;
137110037SARM gem5 Developers            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
137210037SARM gem5 Developers            return;
137310037SARM gem5 Developers          // TLBI by VA, EL2
137410037SARM gem5 Developers          case MISCREG_TLBI_VAE2IS_Xt:
137510037SARM gem5 Developers          case MISCREG_TLBI_VAE2_Xt:
137610037SARM gem5 Developers          // TLBI by VA, EL2, stage1 last level walk
137710037SARM gem5 Developers          case MISCREG_TLBI_VALE2IS_Xt:
137810037SARM gem5 Developers          case MISCREG_TLBI_VALE2_Xt:
137910037SARM gem5 Developers            assert64(tc);
138010037SARM gem5 Developers            target_el = 2;
138110037SARM gem5 Developers            asid = 0xbeef; // does not matter, tlbi is global
138210037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
138310037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
138410037SARM gem5 Developers            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
138510037SARM gem5 Developers            return;
138610037SARM gem5 Developers          // TLBI by VA EL1 & 0, stage1, ASID, current VMID
138710037SARM gem5 Developers          case MISCREG_TLBI_VAE1IS_Xt:
138810037SARM gem5 Developers          case MISCREG_TLBI_VAE1_Xt:
138910037SARM gem5 Developers          case MISCREG_TLBI_VALE1IS_Xt:
139010037SARM gem5 Developers          case MISCREG_TLBI_VALE1_Xt:
139110037SARM gem5 Developers            assert64(tc);
139210037SARM gem5 Developers            asid = bits(newVal, 63, 48);
139310037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
139410037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
139510037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
139610037SARM gem5 Developers            tlbiVA(tc, newVal, asid, secure_lookup, target_el);
139710037SARM gem5 Developers            return;
139810037SARM gem5 Developers          // AArch64 TLBI: invalidate by ASID, stage 1, current VMID
139910037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
140010037SARM gem5 Developers          case MISCREG_TLBI_ASIDE1IS_Xt:
140110037SARM gem5 Developers          case MISCREG_TLBI_ASIDE1_Xt:
140210037SARM gem5 Developers            assert64(tc);
140310037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
140410037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
140510037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
14068284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
14078284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
14088284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
14098284SAli.Saidi@ARM.com                assert(oc->getITBPtr() && oc->getDTBPtr());
141010037SARM gem5 Developers                asid = bits(newVal, 63, 48);
141110709SAndreas.Sandberg@ARM.com                if (!haveLargeAsid64)
141210037SARM gem5 Developers                    asid &= mask(8);
141310037SARM gem5 Developers                oc->getITBPtr()->flushAsid(asid, secure_lookup, target_el);
141410037SARM gem5 Developers                oc->getDTBPtr()->flushAsid(asid, secure_lookup, target_el);
141510037SARM gem5 Developers                CheckerCPU *checker = oc->getCheckerCpuPtr();
141610037SARM gem5 Developers                if (checker) {
141710037SARM gem5 Developers                    checker->getITBPtr()->flushAsid(asid,
141810037SARM gem5 Developers                        secure_lookup, target_el);
141910037SARM gem5 Developers                    checker->getDTBPtr()->flushAsid(asid,
142010037SARM gem5 Developers                        secure_lookup, target_el);
142110037SARM gem5 Developers                }
142210037SARM gem5 Developers            }
142310037SARM gem5 Developers            return;
142410037SARM gem5 Developers          // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID
142510037SARM gem5 Developers          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
142610037SARM gem5 Developers          // entries from the last level of translation table walks
142710037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
142810037SARM gem5 Developers          case MISCREG_TLBI_VAAE1IS_Xt:
142910037SARM gem5 Developers          case MISCREG_TLBI_VAAE1_Xt:
143010037SARM gem5 Developers          case MISCREG_TLBI_VAALE1IS_Xt:
143110037SARM gem5 Developers          case MISCREG_TLBI_VAALE1_Xt:
143210037SARM gem5 Developers            assert64(tc);
143310037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
143410037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
143510037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
143610037SARM gem5 Developers            sys = tc->getSystemPtr();
143710037SARM gem5 Developers            for (x = 0; x < sys->numContexts(); x++) {
143810037SARM gem5 Developers                // @todo: extra controls on TLBI broadcast?
143910037SARM gem5 Developers                oc = sys->getThreadContext(x);
144010037SARM gem5 Developers                assert(oc->getITBPtr() && oc->getDTBPtr());
144110037SARM gem5 Developers                Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
144210037SARM gem5 Developers                oc->getITBPtr()->flushMva(va,
144310037SARM gem5 Developers                    secure_lookup, false, target_el);
144410037SARM gem5 Developers                oc->getDTBPtr()->flushMva(va,
144510037SARM gem5 Developers                    secure_lookup, false, target_el);
14468887Sgeoffrey.blake@arm.com
14478887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
14488733Sgeoffrey.blake@arm.com                if (checker) {
144910037SARM gem5 Developers                    checker->getITBPtr()->flushMva(va,
145010037SARM gem5 Developers                        secure_lookup, false, target_el);
145110037SARM gem5 Developers                    checker->getDTBPtr()->flushMva(va,
145210037SARM gem5 Developers                        secure_lookup, false, target_el);
14538733Sgeoffrey.blake@arm.com                }
14548284SAli.Saidi@ARM.com            }
14557408Sgblack@eecs.umich.edu            return;
145610037SARM gem5 Developers          // AArch64 TLBI: invalidate by IPA, stage 2, current VMID
145710037SARM gem5 Developers          case MISCREG_TLBI_IPAS2LE1IS_Xt:
145810037SARM gem5 Developers          case MISCREG_TLBI_IPAS2LE1_Xt:
145910037SARM gem5 Developers          case MISCREG_TLBI_IPAS2E1IS_Xt:
146010037SARM gem5 Developers          case MISCREG_TLBI_IPAS2E1_Xt:
146110037SARM gem5 Developers            assert64(tc);
146211584SDylan.Johnson@ARM.com            target_el = 1; // EL 0 and 1 are handled together
146311584SDylan.Johnson@ARM.com            scr = readMiscReg(MISCREG_SCR, tc);
146411584SDylan.Johnson@ARM.com            secure_lookup = haveSecurity && !scr.ns;
146511584SDylan.Johnson@ARM.com            sys = tc->getSystemPtr();
146611584SDylan.Johnson@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
146711584SDylan.Johnson@ARM.com                oc = sys->getThreadContext(x);
146811584SDylan.Johnson@ARM.com                assert(oc->getITBPtr() && oc->getDTBPtr());
146911584SDylan.Johnson@ARM.com                Addr ipa = ((Addr) bits(newVal, 35, 0)) << 12;
147011584SDylan.Johnson@ARM.com                oc->getITBPtr()->flushIpaVmid(ipa,
147111584SDylan.Johnson@ARM.com                    secure_lookup, false, target_el);
147211584SDylan.Johnson@ARM.com                oc->getDTBPtr()->flushIpaVmid(ipa,
147311584SDylan.Johnson@ARM.com                    secure_lookup, false, target_el);
147411584SDylan.Johnson@ARM.com
147511584SDylan.Johnson@ARM.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
147611584SDylan.Johnson@ARM.com                if (checker) {
147711584SDylan.Johnson@ARM.com                    checker->getITBPtr()->flushIpaVmid(ipa,
147811584SDylan.Johnson@ARM.com                        secure_lookup, false, target_el);
147911584SDylan.Johnson@ARM.com                    checker->getDTBPtr()->flushIpaVmid(ipa,
148011584SDylan.Johnson@ARM.com                        secure_lookup, false, target_el);
148111584SDylan.Johnson@ARM.com                }
148211584SDylan.Johnson@ARM.com            }
14837405SAli.Saidi@ARM.com            return;
14847583SAli.Saidi@arm.com          case MISCREG_ACTLR:
14857583SAli.Saidi@arm.com            warn("Not doing anything for write of miscreg ACTLR\n");
14867583SAli.Saidi@arm.com            break;
148710461SAndreas.Sandberg@ARM.com
148810461SAndreas.Sandberg@ARM.com          case MISCREG_PMXEVTYPER_PMCCFILTR:
148910461SAndreas.Sandberg@ARM.com          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
149010461SAndreas.Sandberg@ARM.com          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
149110461SAndreas.Sandberg@ARM.com          case MISCREG_PMCR ... MISCREG_PMOVSSET:
149210461SAndreas.Sandberg@ARM.com            pmu->setMiscReg(misc_reg, newVal);
14937583SAli.Saidi@arm.com            break;
149410461SAndreas.Sandberg@ARM.com
149510461SAndreas.Sandberg@ARM.com
149610037SARM gem5 Developers          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
149710037SARM gem5 Developers            {
149810037SARM gem5 Developers                HSTR hstrMask = 0;
149910037SARM gem5 Developers                hstrMask.tjdbx = 1;
150010037SARM gem5 Developers                newVal &= ~((uint32_t) hstrMask);
150110037SARM gem5 Developers                break;
150210037SARM gem5 Developers            }
150310037SARM gem5 Developers          case MISCREG_HCPTR:
150410037SARM gem5 Developers            {
150510037SARM gem5 Developers                // If a CP bit in NSACR is 0 then the corresponding bit in
150610037SARM gem5 Developers                // HCPTR is RAO/WI. Same applies to NSASEDIS
150710037SARM gem5 Developers                secure_lookup = haveSecurity &&
150810037SARM gem5 Developers                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
150910037SARM gem5 Developers                                  readMiscRegNoEffect(MISCREG_CPSR));
151010037SARM gem5 Developers                if (!secure_lookup) {
151110037SARM gem5 Developers                    MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
151210037SARM gem5 Developers                    MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
151310037SARM gem5 Developers                    newVal = (newVal & ~mask) | (oldValue & mask);
151410037SARM gem5 Developers                }
151510037SARM gem5 Developers                break;
151610037SARM gem5 Developers            }
151710037SARM gem5 Developers          case MISCREG_HDFAR: // alias for secure DFAR
151810037SARM gem5 Developers            misc_reg = MISCREG_DFAR_S;
151910037SARM gem5 Developers            break;
152010037SARM gem5 Developers          case MISCREG_HIFAR: // alias for secure IFAR
152110037SARM gem5 Developers            misc_reg = MISCREG_IFAR_S;
152210037SARM gem5 Developers            break;
152310037SARM gem5 Developers          case MISCREG_ATS1CPR:
152410037SARM gem5 Developers          case MISCREG_ATS1CPW:
152510037SARM gem5 Developers          case MISCREG_ATS1CUR:
152610037SARM gem5 Developers          case MISCREG_ATS1CUW:
152710037SARM gem5 Developers          case MISCREG_ATS12NSOPR:
152810037SARM gem5 Developers          case MISCREG_ATS12NSOPW:
152910037SARM gem5 Developers          case MISCREG_ATS12NSOUR:
153010037SARM gem5 Developers          case MISCREG_ATS12NSOUW:
153110037SARM gem5 Developers          case MISCREG_ATS1HR:
153210037SARM gem5 Developers          case MISCREG_ATS1HW:
15337436Sdam.sunwoo@arm.com            {
153411608Snikos.nikoleris@arm.com              Request::Flags flags = 0;
153510037SARM gem5 Developers              BaseTLB::Mode mode = BaseTLB::Read;
153610037SARM gem5 Developers              TLB::ArmTranslationType tranType = TLB::NormalTran;
15377436Sdam.sunwoo@arm.com              Fault fault;
15387436Sdam.sunwoo@arm.com              switch(misc_reg) {
153910037SARM gem5 Developers                case MISCREG_ATS1CPR:
154010037SARM gem5 Developers                  flags    = TLB::MustBeOne;
154110037SARM gem5 Developers                  tranType = TLB::S1CTran;
154210037SARM gem5 Developers                  mode     = BaseTLB::Read;
154310037SARM gem5 Developers                  break;
154410037SARM gem5 Developers                case MISCREG_ATS1CPW:
154510037SARM gem5 Developers                  flags    = TLB::MustBeOne;
154610037SARM gem5 Developers                  tranType = TLB::S1CTran;
154710037SARM gem5 Developers                  mode     = BaseTLB::Write;
154810037SARM gem5 Developers                  break;
154910037SARM gem5 Developers                case MISCREG_ATS1CUR:
155010037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
155110037SARM gem5 Developers                  tranType = TLB::S1CTran;
155210037SARM gem5 Developers                  mode     = BaseTLB::Read;
155310037SARM gem5 Developers                  break;
155410037SARM gem5 Developers                case MISCREG_ATS1CUW:
155510037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
155610037SARM gem5 Developers                  tranType = TLB::S1CTran;
155710037SARM gem5 Developers                  mode     = BaseTLB::Write;
155810037SARM gem5 Developers                  break;
155910037SARM gem5 Developers                case MISCREG_ATS12NSOPR:
156010037SARM gem5 Developers                  if (!haveSecurity)
156110037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPR");
156210037SARM gem5 Developers                  flags    = TLB::MustBeOne;
156310037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
156410037SARM gem5 Developers                  mode     = BaseTLB::Read;
156510037SARM gem5 Developers                  break;
156610037SARM gem5 Developers                case MISCREG_ATS12NSOPW:
156710037SARM gem5 Developers                  if (!haveSecurity)
156810037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPW");
156910037SARM gem5 Developers                  flags    = TLB::MustBeOne;
157010037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
157110037SARM gem5 Developers                  mode     = BaseTLB::Write;
157210037SARM gem5 Developers                  break;
157310037SARM gem5 Developers                case MISCREG_ATS12NSOUR:
157410037SARM gem5 Developers                  if (!haveSecurity)
157510037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUR");
157610037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
157710037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
157810037SARM gem5 Developers                  mode     = BaseTLB::Read;
157910037SARM gem5 Developers                  break;
158010037SARM gem5 Developers                case MISCREG_ATS12NSOUW:
158110037SARM gem5 Developers                  if (!haveSecurity)
158210037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUW");
158310037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
158410037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
158510037SARM gem5 Developers                  mode     = BaseTLB::Write;
158610037SARM gem5 Developers                  break;
158710037SARM gem5 Developers                case MISCREG_ATS1HR: // only really useful from secure mode.
158810037SARM gem5 Developers                  flags    = TLB::MustBeOne;
158910037SARM gem5 Developers                  tranType = TLB::HypMode;
159010037SARM gem5 Developers                  mode     = BaseTLB::Read;
159110037SARM gem5 Developers                  break;
159210037SARM gem5 Developers                case MISCREG_ATS1HW:
159310037SARM gem5 Developers                  flags    = TLB::MustBeOne;
159410037SARM gem5 Developers                  tranType = TLB::HypMode;
159510037SARM gem5 Developers                  mode     = BaseTLB::Write;
159610037SARM gem5 Developers                  break;
15977436Sdam.sunwoo@arm.com              }
159810037SARM gem5 Developers              // If we're in timing mode then doing the translation in
159910037SARM gem5 Developers              // functional mode then we're slightly distorting performance
160010037SARM gem5 Developers              // results obtained from simulations. The translation should be
160110037SARM gem5 Developers              // done in the same mode the core is running in. NOTE: This
160210037SARM gem5 Developers              // can't be an atomic translation because that causes problems
160310037SARM gem5 Developers              // with unexpected atomic snoop requests.
160410037SARM gem5 Developers              warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
160511560Sandreas.sandberg@arm.com              Request req(0, val, 0, flags,  Request::funcMasterId,
160611435Smitch.hayenga@arm.com                          tc->pcState().pc(), tc->contextId());
160710653Sandreas.hansson@arm.com              fault = tc->getDTBPtr()->translateFunctional(&req, tc, mode, tranType);
160810037SARM gem5 Developers              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
160910037SARM gem5 Developers              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
161010037SARM gem5 Developers
161110037SARM gem5 Developers              MiscReg newVal;
16127436Sdam.sunwoo@arm.com              if (fault == NoFault) {
161310653Sandreas.hansson@arm.com                  Addr paddr = req.getPaddr();
161410037SARM gem5 Developers                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
161510037SARM gem5 Developers                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
161610037SARM gem5 Developers                      newVal = (paddr & mask(39, 12)) |
161710037SARM gem5 Developers                               (tc->getDTBPtr()->getAttr());
161810037SARM gem5 Developers                  } else {
161910037SARM gem5 Developers                      newVal = (paddr & 0xfffff000) |
162010037SARM gem5 Developers                               (tc->getDTBPtr()->getAttr());
162110037SARM gem5 Developers                  }
16227436Sdam.sunwoo@arm.com                  DPRINTF(MiscRegs,
16237436Sdam.sunwoo@arm.com                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
162410037SARM gem5 Developers                          val, newVal);
162510037SARM gem5 Developers              } else {
162610037SARM gem5 Developers                  ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get());
162710037SARM gem5 Developers                  // Set fault bit and FSR
162810037SARM gem5 Developers                  FSR fsr = armFault->getFsr(tc);
162910037SARM gem5 Developers
163010037SARM gem5 Developers                  newVal = ((fsr >> 9) & 1) << 11;
163110037SARM gem5 Developers                  if (newVal) {
163210037SARM gem5 Developers                    // LPAE - rearange fault status
163310037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0x3f) << 1;
163410037SARM gem5 Developers                  } else {
163510037SARM gem5 Developers                    // VMSA - rearange fault status
163610037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0xf) << 1;
163710037SARM gem5 Developers                    newVal |= ((fsr >> 10) & 0x1) << 5;
163810037SARM gem5 Developers                    newVal |= ((fsr >> 12) & 0x1) << 6;
163910037SARM gem5 Developers                  }
164010037SARM gem5 Developers                  newVal |= 0x1; // F bit
164110037SARM gem5 Developers                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
164210037SARM gem5 Developers                  newVal |= armFault->isStage2() ? 0x200 : 0;
164310037SARM gem5 Developers                  DPRINTF(MiscRegs,
164410037SARM gem5 Developers                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
164510037SARM gem5 Developers                          val, fsr, newVal);
16467436Sdam.sunwoo@arm.com              }
164710037SARM gem5 Developers              setMiscRegNoEffect(MISCREG_PAR, newVal);
16487436Sdam.sunwoo@arm.com              return;
16497436Sdam.sunwoo@arm.com            }
165010037SARM gem5 Developers          case MISCREG_TTBCR:
165110037SARM gem5 Developers            {
165210037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
165310037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
165410037SARM gem5 Developers                TTBCR ttbcrMask = 0;
165510037SARM gem5 Developers                TTBCR ttbcrNew = newVal;
165610037SARM gem5 Developers
165710037SARM gem5 Developers                // ARM DDI 0406C.b, ARMv7-32
165810037SARM gem5 Developers                ttbcrMask.n = ones; // T0SZ
165910037SARM gem5 Developers                if (haveSecurity) {
166010037SARM gem5 Developers                    ttbcrMask.pd0 = ones;
166110037SARM gem5 Developers                    ttbcrMask.pd1 = ones;
166210037SARM gem5 Developers                }
166310037SARM gem5 Developers                ttbcrMask.epd0 = ones;
166410037SARM gem5 Developers                ttbcrMask.irgn0 = ones;
166510037SARM gem5 Developers                ttbcrMask.orgn0 = ones;
166610037SARM gem5 Developers                ttbcrMask.sh0 = ones;
166710037SARM gem5 Developers                ttbcrMask.ps = ones; // T1SZ
166810037SARM gem5 Developers                ttbcrMask.a1 = ones;
166910037SARM gem5 Developers                ttbcrMask.epd1 = ones;
167010037SARM gem5 Developers                ttbcrMask.irgn1 = ones;
167110037SARM gem5 Developers                ttbcrMask.orgn1 = ones;
167210037SARM gem5 Developers                ttbcrMask.sh1 = ones;
167310037SARM gem5 Developers                if (haveLPAE)
167410037SARM gem5 Developers                    ttbcrMask.eae = ones;
167510037SARM gem5 Developers
167610037SARM gem5 Developers                if (haveLPAE && ttbcrNew.eae) {
167710037SARM gem5 Developers                    newVal = newVal & ttbcrMask;
167810037SARM gem5 Developers                } else {
167910037SARM gem5 Developers                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
168010037SARM gem5 Developers                }
168110037SARM gem5 Developers            }
168210037SARM gem5 Developers          case MISCREG_TTBR0:
168310037SARM gem5 Developers          case MISCREG_TTBR1:
168410037SARM gem5 Developers            {
168510037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
168610037SARM gem5 Developers                if (haveLPAE) {
168710037SARM gem5 Developers                    if (ttbcr.eae) {
168810037SARM gem5 Developers                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
168910037SARM gem5 Developers                        // ARMv8 AArch32 bit 63-56 only
169010037SARM gem5 Developers                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
169110037SARM gem5 Developers                        newVal = (newVal & (~ttbrMask));
169210037SARM gem5 Developers                    }
169310037SARM gem5 Developers                }
169410037SARM gem5 Developers            }
169510508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL1:
169610508SAli.Saidi@ARM.com            {
169710508SAli.Saidi@ARM.com                tc->getITBPtr()->invalidateMiscReg();
169810508SAli.Saidi@ARM.com                tc->getDTBPtr()->invalidateMiscReg();
169910508SAli.Saidi@ARM.com                setMiscRegNoEffect(misc_reg, newVal);
170010508SAli.Saidi@ARM.com            }
17017749SAli.Saidi@ARM.com          case MISCREG_CONTEXTIDR:
17027749SAli.Saidi@ARM.com          case MISCREG_PRRR:
17037749SAli.Saidi@ARM.com          case MISCREG_NMRR:
170410037SARM gem5 Developers          case MISCREG_MAIR0:
170510037SARM gem5 Developers          case MISCREG_MAIR1:
17067749SAli.Saidi@ARM.com          case MISCREG_DACR:
170710037SARM gem5 Developers          case MISCREG_VTTBR:
170810037SARM gem5 Developers          case MISCREG_SCR_EL3:
170911575SDylan.Johnson@ARM.com          case MISCREG_HCR_EL2:
171010037SARM gem5 Developers          case MISCREG_TCR_EL1:
171110037SARM gem5 Developers          case MISCREG_TCR_EL2:
171210037SARM gem5 Developers          case MISCREG_TCR_EL3:
171310508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL2:
171410508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL3:
171511573SDylan.Johnson@ARM.com          case MISCREG_HSCTLR:
171610037SARM gem5 Developers          case MISCREG_TTBR0_EL1:
171710037SARM gem5 Developers          case MISCREG_TTBR1_EL1:
171810037SARM gem5 Developers          case MISCREG_TTBR0_EL2:
171910037SARM gem5 Developers          case MISCREG_TTBR0_EL3:
17207749SAli.Saidi@ARM.com            tc->getITBPtr()->invalidateMiscReg();
17217749SAli.Saidi@ARM.com            tc->getDTBPtr()->invalidateMiscReg();
17227749SAli.Saidi@ARM.com            break;
172310037SARM gem5 Developers          case MISCREG_NZCV:
172410037SARM gem5 Developers            {
172510037SARM gem5 Developers                CPSR cpsr = val;
172610037SARM gem5 Developers
172710338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_NZ, cpsr.nz);
172810338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_C,  cpsr.c);
172910338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_V,  cpsr.v);
173010037SARM gem5 Developers            }
173110037SARM gem5 Developers            break;
173210037SARM gem5 Developers          case MISCREG_DAIF:
173310037SARM gem5 Developers            {
173410037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
173510037SARM gem5 Developers                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
173610037SARM gem5 Developers                newVal = cpsr;
173710037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
173810037SARM gem5 Developers            }
173910037SARM gem5 Developers            break;
174010037SARM gem5 Developers          case MISCREG_SP_EL0:
174110037SARM gem5 Developers            tc->setIntReg(INTREG_SP0, newVal);
174210037SARM gem5 Developers            break;
174310037SARM gem5 Developers          case MISCREG_SP_EL1:
174410037SARM gem5 Developers            tc->setIntReg(INTREG_SP1, newVal);
174510037SARM gem5 Developers            break;
174610037SARM gem5 Developers          case MISCREG_SP_EL2:
174710037SARM gem5 Developers            tc->setIntReg(INTREG_SP2, newVal);
174810037SARM gem5 Developers            break;
174910037SARM gem5 Developers          case MISCREG_SPSEL:
175010037SARM gem5 Developers            {
175110037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
175210037SARM gem5 Developers                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
175310037SARM gem5 Developers                newVal = cpsr;
175410037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
175510037SARM gem5 Developers            }
175610037SARM gem5 Developers            break;
175710037SARM gem5 Developers          case MISCREG_CURRENTEL:
175810037SARM gem5 Developers            {
175910037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
176010037SARM gem5 Developers                cpsr.el = (uint8_t) ((CPSR) newVal).el;
176110037SARM gem5 Developers                newVal = cpsr;
176210037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
176310037SARM gem5 Developers            }
176410037SARM gem5 Developers            break;
176510037SARM gem5 Developers          case MISCREG_AT_S1E1R_Xt:
176610037SARM gem5 Developers          case MISCREG_AT_S1E1W_Xt:
176710037SARM gem5 Developers          case MISCREG_AT_S1E0R_Xt:
176810037SARM gem5 Developers          case MISCREG_AT_S1E0W_Xt:
176910037SARM gem5 Developers          case MISCREG_AT_S1E2R_Xt:
177010037SARM gem5 Developers          case MISCREG_AT_S1E2W_Xt:
177110037SARM gem5 Developers          case MISCREG_AT_S12E1R_Xt:
177210037SARM gem5 Developers          case MISCREG_AT_S12E1W_Xt:
177310037SARM gem5 Developers          case MISCREG_AT_S12E0R_Xt:
177410037SARM gem5 Developers          case MISCREG_AT_S12E0W_Xt:
177510037SARM gem5 Developers          case MISCREG_AT_S1E3R_Xt:
177610037SARM gem5 Developers          case MISCREG_AT_S1E3W_Xt:
177710037SARM gem5 Developers            {
177810037SARM gem5 Developers                RequestPtr req = new Request;
177911608Snikos.nikoleris@arm.com                Request::Flags flags = 0;
178010037SARM gem5 Developers                BaseTLB::Mode mode = BaseTLB::Read;
178110037SARM gem5 Developers                TLB::ArmTranslationType tranType = TLB::NormalTran;
178210037SARM gem5 Developers                Fault fault;
178310037SARM gem5 Developers                switch(misc_reg) {
178410037SARM gem5 Developers                  case MISCREG_AT_S1E1R_Xt:
178510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
178611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
178710037SARM gem5 Developers                    mode     = BaseTLB::Read;
178810037SARM gem5 Developers                    break;
178910037SARM gem5 Developers                  case MISCREG_AT_S1E1W_Xt:
179010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
179111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
179210037SARM gem5 Developers                    mode     = BaseTLB::Write;
179310037SARM gem5 Developers                    break;
179410037SARM gem5 Developers                  case MISCREG_AT_S1E0R_Xt:
179510037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
179611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
179710037SARM gem5 Developers                    mode     = BaseTLB::Read;
179810037SARM gem5 Developers                    break;
179910037SARM gem5 Developers                  case MISCREG_AT_S1E0W_Xt:
180010037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
180111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
180210037SARM gem5 Developers                    mode     = BaseTLB::Write;
180310037SARM gem5 Developers                    break;
180410037SARM gem5 Developers                  case MISCREG_AT_S1E2R_Xt:
180510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
180611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
180710037SARM gem5 Developers                    mode     = BaseTLB::Read;
180810037SARM gem5 Developers                    break;
180910037SARM gem5 Developers                  case MISCREG_AT_S1E2W_Xt:
181010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
181111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
181210037SARM gem5 Developers                    mode     = BaseTLB::Write;
181310037SARM gem5 Developers                    break;
181410037SARM gem5 Developers                  case MISCREG_AT_S12E0R_Xt:
181510037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
181611577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
181710037SARM gem5 Developers                    mode     = BaseTLB::Read;
181810037SARM gem5 Developers                    break;
181910037SARM gem5 Developers                  case MISCREG_AT_S12E0W_Xt:
182010037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
182111577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
182210037SARM gem5 Developers                    mode     = BaseTLB::Write;
182310037SARM gem5 Developers                    break;
182410037SARM gem5 Developers                  case MISCREG_AT_S12E1R_Xt:
182510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
182611577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
182710037SARM gem5 Developers                    mode     = BaseTLB::Read;
182810037SARM gem5 Developers                    break;
182910037SARM gem5 Developers                  case MISCREG_AT_S12E1W_Xt:
183010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
183111577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
183210037SARM gem5 Developers                    mode     = BaseTLB::Write;
183310037SARM gem5 Developers                    break;
183410037SARM gem5 Developers                  case MISCREG_AT_S1E3R_Xt:
183510037SARM gem5 Developers                    flags    = TLB::MustBeOne;
183611577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
183710037SARM gem5 Developers                    mode     = BaseTLB::Read;
183810037SARM gem5 Developers                    break;
183910037SARM gem5 Developers                  case MISCREG_AT_S1E3W_Xt:
184010037SARM gem5 Developers                    flags    = TLB::MustBeOne;
184111577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
184210037SARM gem5 Developers                    mode     = BaseTLB::Write;
184310037SARM gem5 Developers                    break;
184410037SARM gem5 Developers                }
184510037SARM gem5 Developers                // If we're in timing mode then doing the translation in
184610037SARM gem5 Developers                // functional mode then we're slightly distorting performance
184710037SARM gem5 Developers                // results obtained from simulations. The translation should be
184810037SARM gem5 Developers                // done in the same mode the core is running in. NOTE: This
184910037SARM gem5 Developers                // can't be an atomic translation because that causes problems
185010037SARM gem5 Developers                // with unexpected atomic snoop requests.
185110037SARM gem5 Developers                warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
185211560Sandreas.sandberg@arm.com                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
185310037SARM gem5 Developers                               tc->pcState().pc());
185411435Smitch.hayenga@arm.com                req->setContext(tc->contextId());
185510037SARM gem5 Developers                fault = tc->getDTBPtr()->translateFunctional(req, tc, mode,
185610037SARM gem5 Developers                                                             tranType);
185710037SARM gem5 Developers
185810037SARM gem5 Developers                MiscReg newVal;
185910037SARM gem5 Developers                if (fault == NoFault) {
186010037SARM gem5 Developers                    Addr paddr = req->getPaddr();
186110037SARM gem5 Developers                    uint64_t attr = tc->getDTBPtr()->getAttr();
186210037SARM gem5 Developers                    uint64_t attr1 = attr >> 56;
186310037SARM gem5 Developers                    if (!attr1 || attr1 ==0x44) {
186410037SARM gem5 Developers                        attr |= 0x100;
186510037SARM gem5 Developers                        attr &= ~ uint64_t(0x80);
186610037SARM gem5 Developers                    }
186710037SARM gem5 Developers                    newVal = (paddr & mask(47, 12)) | attr;
186810037SARM gem5 Developers                    DPRINTF(MiscRegs,
186910037SARM gem5 Developers                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
187010037SARM gem5 Developers                          val, newVal);
187110037SARM gem5 Developers                } else {
187210037SARM gem5 Developers                    ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get());
187310037SARM gem5 Developers                    // Set fault bit and FSR
187410037SARM gem5 Developers                    FSR fsr = armFault->getFsr(tc);
187510037SARM gem5 Developers
187611577SDylan.Johnson@ARM.com                    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
187711577SDylan.Johnson@ARM.com                    if (cpsr.width) { // AArch32
187811577SDylan.Johnson@ARM.com                        newVal = ((fsr >> 9) & 1) << 11;
187911577SDylan.Johnson@ARM.com                        // rearrange fault status
188011577SDylan.Johnson@ARM.com                        newVal |= ((fsr >>  0) & 0x3f) << 1;
188111577SDylan.Johnson@ARM.com                        newVal |= 0x1; // F bit
188211577SDylan.Johnson@ARM.com                        newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
188311577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 0x200 : 0;
188411577SDylan.Johnson@ARM.com                    } else { // AArch64
188511577SDylan.Johnson@ARM.com                        newVal = 1; // F bit
188611577SDylan.Johnson@ARM.com                        newVal |= fsr << 1; // FST
188711577SDylan.Johnson@ARM.com                        // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
188811577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
188911577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
189011577SDylan.Johnson@ARM.com                        newVal |= 1 << 11; // RES1
189111577SDylan.Johnson@ARM.com                    }
189210037SARM gem5 Developers                    DPRINTF(MiscRegs,
189310037SARM gem5 Developers                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
189410037SARM gem5 Developers                            val, fsr, newVal);
189510037SARM gem5 Developers                }
189610037SARM gem5 Developers                delete req;
189710037SARM gem5 Developers                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
189810037SARM gem5 Developers                return;
189910037SARM gem5 Developers            }
190010037SARM gem5 Developers          case MISCREG_SPSR_EL3:
190110037SARM gem5 Developers          case MISCREG_SPSR_EL2:
190210037SARM gem5 Developers          case MISCREG_SPSR_EL1:
190310037SARM gem5 Developers            // Force bits 23:21 to 0
190410037SARM gem5 Developers            newVal = val & ~(0x7 << 21);
190510037SARM gem5 Developers            break;
19068549Sdaniel.johnson@arm.com          case MISCREG_L2CTLR:
19078549Sdaniel.johnson@arm.com            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
19088549Sdaniel.johnson@arm.com                 miscRegName[misc_reg], uint32_t(val));
190910037SARM gem5 Developers            break;
191010037SARM gem5 Developers
191110037SARM gem5 Developers          // Generic Timer registers
191210844Sandreas.sandberg@arm.com          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
191310844Sandreas.sandberg@arm.com          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
191410844Sandreas.sandberg@arm.com          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
191510844Sandreas.sandberg@arm.com          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
191610844Sandreas.sandberg@arm.com            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
191710037SARM gem5 Developers            break;
19187405SAli.Saidi@ARM.com        }
19197405SAli.Saidi@ARM.com    }
19207405SAli.Saidi@ARM.com    setMiscRegNoEffect(misc_reg, newVal);
19217405SAli.Saidi@ARM.com}
19227405SAli.Saidi@ARM.com
192310037SARM gem5 Developersvoid
192410709SAndreas.Sandberg@ARM.comISA::tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid,
192510709SAndreas.Sandberg@ARM.com            bool secure_lookup, uint8_t target_el)
192610037SARM gem5 Developers{
192710709SAndreas.Sandberg@ARM.com    if (!haveLargeAsid64)
192810037SARM gem5 Developers        asid &= mask(8);
192910037SARM gem5 Developers    Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
193010037SARM gem5 Developers    System *sys = tc->getSystemPtr();
193110037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
193210037SARM gem5 Developers        ThreadContext *oc = sys->getThreadContext(x);
193310037SARM gem5 Developers        assert(oc->getITBPtr() && oc->getDTBPtr());
193410037SARM gem5 Developers        oc->getITBPtr()->flushMvaAsid(va, asid,
193510037SARM gem5 Developers                                      secure_lookup, target_el);
193610037SARM gem5 Developers        oc->getDTBPtr()->flushMvaAsid(va, asid,
193710037SARM gem5 Developers                                      secure_lookup, target_el);
193810037SARM gem5 Developers
193910037SARM gem5 Developers        CheckerCPU *checker = oc->getCheckerCpuPtr();
194010037SARM gem5 Developers        if (checker) {
194110037SARM gem5 Developers            checker->getITBPtr()->flushMvaAsid(
194210037SARM gem5 Developers                va, asid, secure_lookup, target_el);
194310037SARM gem5 Developers            checker->getDTBPtr()->flushMvaAsid(
194410037SARM gem5 Developers                va, asid, secure_lookup, target_el);
194510037SARM gem5 Developers        }
194610037SARM gem5 Developers    }
194710037SARM gem5 Developers}
194810037SARM gem5 Developers
194910037SARM gem5 Developersvoid
195010037SARM gem5 DevelopersISA::tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el)
195110037SARM gem5 Developers{
195210037SARM gem5 Developers    System *sys = tc->getSystemPtr();
195310037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
195410037SARM gem5 Developers        ThreadContext *oc = sys->getThreadContext(x);
195510037SARM gem5 Developers        assert(oc->getITBPtr() && oc->getDTBPtr());
195610037SARM gem5 Developers        oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el);
195710037SARM gem5 Developers        oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el);
195810037SARM gem5 Developers
195910037SARM gem5 Developers        // If CheckerCPU is connected, need to notify it of a flush
196010037SARM gem5 Developers        CheckerCPU *checker = oc->getCheckerCpuPtr();
196110037SARM gem5 Developers        if (checker) {
196210037SARM gem5 Developers            checker->getITBPtr()->flushAllSecurity(secure_lookup,
196310037SARM gem5 Developers                                                   target_el);
196410037SARM gem5 Developers            checker->getDTBPtr()->flushAllSecurity(secure_lookup,
196510037SARM gem5 Developers                                                   target_el);
196610037SARM gem5 Developers        }
196710037SARM gem5 Developers    }
196810037SARM gem5 Developers}
196910037SARM gem5 Developers
197010037SARM gem5 Developersvoid
197110037SARM gem5 DevelopersISA::tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el)
197210037SARM gem5 Developers{
197310037SARM gem5 Developers    System *sys = tc->getSystemPtr();
197410037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
197510037SARM gem5 Developers      ThreadContext *oc = sys->getThreadContext(x);
197610037SARM gem5 Developers      assert(oc->getITBPtr() && oc->getDTBPtr());
197710037SARM gem5 Developers      oc->getITBPtr()->flushAllNs(hyp, target_el);
197810037SARM gem5 Developers      oc->getDTBPtr()->flushAllNs(hyp, target_el);
197910037SARM gem5 Developers
198010037SARM gem5 Developers      CheckerCPU *checker = oc->getCheckerCpuPtr();
198110037SARM gem5 Developers      if (checker) {
198210037SARM gem5 Developers          checker->getITBPtr()->flushAllNs(hyp, target_el);
198310037SARM gem5 Developers          checker->getDTBPtr()->flushAllNs(hyp, target_el);
198410037SARM gem5 Developers      }
198510037SARM gem5 Developers    }
198610037SARM gem5 Developers}
198710037SARM gem5 Developers
198810037SARM gem5 Developersvoid
198910037SARM gem5 DevelopersISA::tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, bool hyp,
199010037SARM gem5 Developers             uint8_t target_el)
199110037SARM gem5 Developers{
199210037SARM gem5 Developers    System *sys = tc->getSystemPtr();
199310037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
199410037SARM gem5 Developers        ThreadContext *oc = sys->getThreadContext(x);
199510037SARM gem5 Developers        assert(oc->getITBPtr() && oc->getDTBPtr());
199610037SARM gem5 Developers        oc->getITBPtr()->flushMva(mbits(newVal, 31,12),
199710037SARM gem5 Developers            secure_lookup, hyp, target_el);
199810037SARM gem5 Developers        oc->getDTBPtr()->flushMva(mbits(newVal, 31,12),
199910037SARM gem5 Developers            secure_lookup, hyp, target_el);
200010037SARM gem5 Developers
200110037SARM gem5 Developers        CheckerCPU *checker = oc->getCheckerCpuPtr();
200210037SARM gem5 Developers        if (checker) {
200310037SARM gem5 Developers            checker->getITBPtr()->flushMva(mbits(newVal, 31,12),
200410037SARM gem5 Developers                secure_lookup, hyp, target_el);
200510037SARM gem5 Developers            checker->getDTBPtr()->flushMva(mbits(newVal, 31,12),
200610037SARM gem5 Developers                secure_lookup, hyp, target_el);
200710037SARM gem5 Developers        }
200810037SARM gem5 Developers    }
200910037SARM gem5 Developers}
201010037SARM gem5 Developers
201110844Sandreas.sandberg@arm.comBaseISADevice &
201210844Sandreas.sandberg@arm.comISA::getGenericTimer(ThreadContext *tc)
201310037SARM gem5 Developers{
201410844Sandreas.sandberg@arm.com    // We only need to create an ISA interface the first time we try
201510844Sandreas.sandberg@arm.com    // to access the timer.
201610844Sandreas.sandberg@arm.com    if (timer)
201710844Sandreas.sandberg@arm.com        return *timer.get();
201810844Sandreas.sandberg@arm.com
201910844Sandreas.sandberg@arm.com    assert(system);
202010844Sandreas.sandberg@arm.com    GenericTimer *generic_timer(system->getGenericTimer());
202110844Sandreas.sandberg@arm.com    if (!generic_timer) {
202210844Sandreas.sandberg@arm.com        panic("Trying to get a generic timer from a system that hasn't "
202310844Sandreas.sandberg@arm.com              "been configured to use a generic timer.\n");
202410037SARM gem5 Developers    }
202510037SARM gem5 Developers
202611150Smitch.hayenga@arm.com    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
202710844Sandreas.sandberg@arm.com    return *timer.get();
202810037SARM gem5 Developers}
202910037SARM gem5 Developers
20307405SAli.Saidi@ARM.com}
20319384SAndreas.Sandberg@arm.com
20329384SAndreas.Sandberg@arm.comArmISA::ISA *
20339384SAndreas.Sandberg@arm.comArmISAParams::create()
20349384SAndreas.Sandberg@arm.com{
20359384SAndreas.Sandberg@arm.com    return new ArmISA::ISA(this);
20369384SAndreas.Sandberg@arm.com}
2037