isa.cc revision 12477
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"
4412406Sgabeblack@google.com#include "arch/arm/tlb.hh"
4511793Sbrandon.potter@amd.com#include "cpu/base.hh"
468887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh"
478232Snate@binkert.org#include "debug/Arm.hh"
488232Snate@binkert.org#include "debug/MiscRegs.hh"
4910844Sandreas.sandberg@arm.com#include "dev/arm/generic_timer.hh"
509384SAndreas.Sandberg@arm.com#include "params/ArmISA.hh"
517678Sgblack@eecs.umich.edu#include "sim/faults.hh"
528059SAli.Saidi@ARM.com#include "sim/stat_control.hh"
538284SAli.Saidi@ARM.com#include "sim/system.hh"
547405SAli.Saidi@ARM.com
557405SAli.Saidi@ARM.comnamespace ArmISA
567405SAli.Saidi@ARM.com{
577405SAli.Saidi@ARM.com
5810037SARM gem5 Developers
5910037SARM gem5 Developers/**
6011768SCurtis.Dunham@arm.com * Some registers alias with others, and therefore need to be translated.
6112477SCurtis.Dunham@arm.com * When two mapping registers are given, they are the 32b lower and
6212477SCurtis.Dunham@arm.com * upper halves, respectively, of the 64b register being mapped.
6311768SCurtis.Dunham@arm.com * aligned with reference documentation ARM DDI 0487A.i pp 1540-1543
6410037SARM gem5 Developers */
6512477SCurtis.Dunham@arm.comvoid
6612477SCurtis.Dunham@arm.comISA::initializeMiscRegMetadata()
6712477SCurtis.Dunham@arm.com{
6812477SCurtis.Dunham@arm.com    InitReg(MISCREG_ACTLR_EL1).mapsTo(MISCREG_ACTLR_NS);
6912477SCurtis.Dunham@arm.com    InitReg(MISCREG_AFSR0_EL1).mapsTo(MISCREG_ADFSR_NS);
7012477SCurtis.Dunham@arm.com    InitReg(MISCREG_AFSR1_EL1).mapsTo(MISCREG_AIFSR_NS);
7112477SCurtis.Dunham@arm.com    InitReg(MISCREG_AMAIR_EL1).mapsTo(MISCREG_AMAIR0_NS,
7212477SCurtis.Dunham@arm.com                                      MISCREG_AMAIR1_NS);
7312477SCurtis.Dunham@arm.com    InitReg(MISCREG_CONTEXTIDR_EL1).mapsTo(MISCREG_CONTEXTIDR_NS);
7412477SCurtis.Dunham@arm.com    InitReg(MISCREG_CPACR_EL1).mapsTo(MISCREG_CPACR);
7512477SCurtis.Dunham@arm.com    InitReg(MISCREG_CSSELR_EL1).mapsTo(MISCREG_CSSELR_NS);
7612477SCurtis.Dunham@arm.com    InitReg(MISCREG_DACR32_EL2).mapsTo(MISCREG_DACR_NS);
7712477SCurtis.Dunham@arm.com    InitReg(MISCREG_FAR_EL1).mapsTo(MISCREG_DFAR_NS,
7812477SCurtis.Dunham@arm.com                                    MISCREG_IFAR_NS);
7911768SCurtis.Dunham@arm.com    // ESR_EL1 -> DFSR
8012477SCurtis.Dunham@arm.com    InitReg(MISCREG_HACR_EL2).mapsTo(MISCREG_HACR);
8112477SCurtis.Dunham@arm.com    InitReg(MISCREG_ACTLR_EL2).mapsTo(MISCREG_HACTLR);
8212477SCurtis.Dunham@arm.com    InitReg(MISCREG_AFSR0_EL2).mapsTo(MISCREG_HADFSR);
8312477SCurtis.Dunham@arm.com    InitReg(MISCREG_AFSR1_EL2).mapsTo(MISCREG_HAIFSR);
8412477SCurtis.Dunham@arm.com    InitReg(MISCREG_AMAIR_EL2).mapsTo(MISCREG_HAMAIR0,
8512477SCurtis.Dunham@arm.com                                      MISCREG_HAMAIR1);
8612477SCurtis.Dunham@arm.com    InitReg(MISCREG_CPTR_EL2).mapsTo(MISCREG_HCPTR);
8712477SCurtis.Dunham@arm.com    InitReg(MISCREG_HCR_EL2).mapsTo(MISCREG_HCR /*,
8812477SCurtis.Dunham@arm.com                                    MISCREG_HCR2*/);
8912477SCurtis.Dunham@arm.com    InitReg(MISCREG_MDCR_EL2).mapsTo(MISCREG_HDCR);
9012477SCurtis.Dunham@arm.com    InitReg(MISCREG_FAR_EL2).mapsTo(MISCREG_HDFAR,
9112477SCurtis.Dunham@arm.com                                    MISCREG_HIFAR);
9212477SCurtis.Dunham@arm.com    InitReg(MISCREG_MAIR_EL2).mapsTo(MISCREG_HMAIR0,
9312477SCurtis.Dunham@arm.com                                     MISCREG_HMAIR1);
9412477SCurtis.Dunham@arm.com    InitReg(MISCREG_HPFAR_EL2).mapsTo(MISCREG_HPFAR);
9512477SCurtis.Dunham@arm.com    InitReg(MISCREG_SCTLR_EL2).mapsTo(MISCREG_HSCTLR);
9612477SCurtis.Dunham@arm.com    InitReg(MISCREG_ESR_EL2).mapsTo(MISCREG_HSR);
9712477SCurtis.Dunham@arm.com    InitReg(MISCREG_HSTR_EL2).mapsTo(MISCREG_HSTR);
9812477SCurtis.Dunham@arm.com    InitReg(MISCREG_TCR_EL2).mapsTo(MISCREG_HTCR);
9912477SCurtis.Dunham@arm.com    InitReg(MISCREG_TPIDR_EL2).mapsTo(MISCREG_HTPIDR);
10012477SCurtis.Dunham@arm.com    InitReg(MISCREG_TTBR0_EL2).mapsTo(MISCREG_HTTBR);
10112477SCurtis.Dunham@arm.com    InitReg(MISCREG_VBAR_EL2).mapsTo(MISCREG_HVBAR);
10212477SCurtis.Dunham@arm.com    InitReg(MISCREG_IFSR32_EL2).mapsTo(MISCREG_IFSR_NS);
10312477SCurtis.Dunham@arm.com    InitReg(MISCREG_MAIR_EL1).mapsTo(MISCREG_PRRR_NS,
10412477SCurtis.Dunham@arm.com                                     MISCREG_NMRR_NS);
10512477SCurtis.Dunham@arm.com    InitReg(MISCREG_PAR_EL1).mapsTo(MISCREG_PAR_NS);
10611768SCurtis.Dunham@arm.com    // RMR_EL1 -> RMR
10711768SCurtis.Dunham@arm.com    // RMR_EL2 -> HRMR
10812477SCurtis.Dunham@arm.com    InitReg(MISCREG_SCTLR_EL1).mapsTo(MISCREG_SCTLR_NS);
10912477SCurtis.Dunham@arm.com    InitReg(MISCREG_SDER32_EL3).mapsTo(MISCREG_SDER);
11012477SCurtis.Dunham@arm.com    InitReg(MISCREG_TPIDR_EL1).mapsTo(MISCREG_TPIDRPRW_NS);
11112477SCurtis.Dunham@arm.com    InitReg(MISCREG_TPIDRRO_EL0).mapsTo(MISCREG_TPIDRURO_NS);
11212477SCurtis.Dunham@arm.com    InitReg(MISCREG_TPIDR_EL0).mapsTo(MISCREG_TPIDRURW_NS);
11312477SCurtis.Dunham@arm.com    InitReg(MISCREG_TCR_EL1).mapsTo(MISCREG_TTBCR_NS);
11412477SCurtis.Dunham@arm.com    InitReg(MISCREG_TTBR0_EL1).mapsTo(MISCREG_TTBR0_NS);
11512477SCurtis.Dunham@arm.com    InitReg(MISCREG_TTBR1_EL1).mapsTo(MISCREG_TTBR1_NS);
11612477SCurtis.Dunham@arm.com    InitReg(MISCREG_VBAR_EL1).mapsTo(MISCREG_VBAR_NS);
11712477SCurtis.Dunham@arm.com    InitReg(MISCREG_VMPIDR_EL2).mapsTo(MISCREG_VMPIDR);
11812477SCurtis.Dunham@arm.com    InitReg(MISCREG_VPIDR_EL2).mapsTo(MISCREG_VPIDR);
11912477SCurtis.Dunham@arm.com    InitReg(MISCREG_VTCR_EL2).mapsTo(MISCREG_VTCR);
12012477SCurtis.Dunham@arm.com    InitReg(MISCREG_VTTBR_EL2).mapsTo(MISCREG_VTTBR);
12112477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTFRQ_EL0).mapsTo(MISCREG_CNTFRQ);
12212477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTHCTL_EL2).mapsTo(MISCREG_CNTHCTL);
12312477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTHP_CTL_EL2).mapsTo(MISCREG_CNTHP_CTL);
12412477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTHP_CVAL_EL2).mapsTo(MISCREG_CNTHP_CVAL); /* 64b */
12512477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTHP_TVAL_EL2).mapsTo(MISCREG_CNTHP_TVAL);
12612477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTKCTL_EL1).mapsTo(MISCREG_CNTKCTL);
12712477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTP_CTL_EL0).mapsTo(MISCREG_CNTP_CTL_NS);
12812477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTP_CVAL_EL0).mapsTo(MISCREG_CNTP_CVAL_NS); /* 64b */
12912477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTP_TVAL_EL0).mapsTo(MISCREG_CNTP_TVAL_NS);
13012477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTPCT_EL0).mapsTo(MISCREG_CNTPCT); /* 64b */
13112477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTV_CTL_EL0).mapsTo(MISCREG_CNTV_CTL);
13212477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTV_CVAL_EL0).mapsTo(MISCREG_CNTV_CVAL); /* 64b */
13312477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTV_TVAL_EL0).mapsTo(MISCREG_CNTV_TVAL);
13412477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTVCT_EL0).mapsTo(MISCREG_CNTVCT); /* 64b */
13512477SCurtis.Dunham@arm.com    InitReg(MISCREG_CNTVOFF_EL2).mapsTo(MISCREG_CNTVOFF); /* 64b */
13612477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGAUTHSTATUS_EL1).mapsTo(MISCREG_DBGAUTHSTATUS);
13712477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBCR0_EL1).mapsTo(MISCREG_DBGBCR0);
13812477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBCR1_EL1).mapsTo(MISCREG_DBGBCR1);
13912477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBCR2_EL1).mapsTo(MISCREG_DBGBCR2);
14012477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBCR3_EL1).mapsTo(MISCREG_DBGBCR3);
14112477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBCR4_EL1).mapsTo(MISCREG_DBGBCR4);
14212477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBCR5_EL1).mapsTo(MISCREG_DBGBCR5);
14312477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBVR0_EL1).mapsTo(MISCREG_DBGBVR0 /*,
14412477SCurtis.Dunham@arm.com                                        MISCREG_DBGBXVR0 */);
14512477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBVR1_EL1).mapsTo(MISCREG_DBGBVR1 /*,
14612477SCurtis.Dunham@arm.com                                        MISCREG_DBGBXVR1 */);
14712477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBVR2_EL1).mapsTo(MISCREG_DBGBVR2 /*,
14812477SCurtis.Dunham@arm.com                                        MISCREG_DBGBXVR2 */);
14912477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBVR3_EL1).mapsTo(MISCREG_DBGBVR3 /*,
15012477SCurtis.Dunham@arm.com                                        MISCREG_DBGBXVR3 */);
15112477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBVR4_EL1).mapsTo(MISCREG_DBGBVR4 /*,
15212477SCurtis.Dunham@arm.com                                        MISCREG_DBGBXVR4 */);
15312477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGBVR5_EL1).mapsTo(MISCREG_DBGBVR5 /*,
15412477SCurtis.Dunham@arm.com                                        MISCREG_DBGBXVR5 */);
15512477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGCLAIMSET_EL1).mapsTo(MISCREG_DBGCLAIMSET);
15612477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGCLAIMCLR_EL1).mapsTo(MISCREG_DBGCLAIMCLR);
15711768SCurtis.Dunham@arm.com    // DBGDTR_EL0 -> DBGDTR{R or T}Xint
15811768SCurtis.Dunham@arm.com    // DBGDTRRX_EL0 -> DBGDTRRXint
15911768SCurtis.Dunham@arm.com    // DBGDTRTX_EL0 -> DBGDTRRXint
16012477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGPRCR_EL1).mapsTo(MISCREG_DBGPRCR);
16112477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGVCR32_EL2).mapsTo(MISCREG_DBGVCR);
16212477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWCR0_EL1).mapsTo(MISCREG_DBGWCR0);
16312477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWCR1_EL1).mapsTo(MISCREG_DBGWCR1);
16412477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWCR2_EL1).mapsTo(MISCREG_DBGWCR2);
16512477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWCR3_EL1).mapsTo(MISCREG_DBGWCR3);
16612477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWVR0_EL1).mapsTo(MISCREG_DBGWVR0);
16712477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWVR1_EL1).mapsTo(MISCREG_DBGWVR1);
16812477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWVR2_EL1).mapsTo(MISCREG_DBGWVR2);
16912477SCurtis.Dunham@arm.com    InitReg(MISCREG_DBGWVR3_EL1).mapsTo(MISCREG_DBGWVR3);
17012477SCurtis.Dunham@arm.com    InitReg(MISCREG_ID_DFR0_EL1).mapsTo(MISCREG_ID_DFR0);
17112477SCurtis.Dunham@arm.com    InitReg(MISCREG_MDCCSR_EL0).mapsTo(MISCREG_DBGDSCRint);
17212477SCurtis.Dunham@arm.com    InitReg(MISCREG_MDRAR_EL1).mapsTo(MISCREG_DBGDRAR);
17312477SCurtis.Dunham@arm.com    InitReg(MISCREG_MDSCR_EL1).mapsTo(MISCREG_DBGDSCRext);
17412477SCurtis.Dunham@arm.com    InitReg(MISCREG_OSDLR_EL1).mapsTo(MISCREG_DBGOSDLR);
17512477SCurtis.Dunham@arm.com    InitReg(MISCREG_OSDTRRX_EL1).mapsTo(MISCREG_DBGDTRRXext);
17612477SCurtis.Dunham@arm.com    InitReg(MISCREG_OSDTRTX_EL1).mapsTo(MISCREG_DBGDTRTXext);
17712477SCurtis.Dunham@arm.com    InitReg(MISCREG_OSECCR_EL1).mapsTo(MISCREG_DBGOSECCR);
17812477SCurtis.Dunham@arm.com    InitReg(MISCREG_OSLAR_EL1).mapsTo(MISCREG_DBGOSLAR);
17912477SCurtis.Dunham@arm.com    InitReg(MISCREG_OSLSR_EL1).mapsTo(MISCREG_DBGOSLSR);
18012477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMCCNTR_EL0).mapsTo(MISCREG_PMCCNTR);
18112477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMCEID0_EL0).mapsTo(MISCREG_PMCEID0);
18212477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMCEID1_EL0).mapsTo(MISCREG_PMCEID1);
18312477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMCNTENSET_EL0).mapsTo(MISCREG_PMCNTENSET);
18412477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMCNTENCLR_EL0).mapsTo(MISCREG_PMCNTENCLR);
18512477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMCR_EL0).mapsTo(MISCREG_PMCR);
18612477SCurtis.Dunham@arm.com/*  InitReg(MISCREG_PMEVCNTR0_EL0).mapsTo(MISCREG_PMEVCNTR0);
18712477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVCNTR1_EL0).mapsTo(MISCREG_PMEVCNTR1);
18812477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVCNTR2_EL0).mapsTo(MISCREG_PMEVCNTR2);
18912477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVCNTR3_EL0).mapsTo(MISCREG_PMEVCNTR3);
19012477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVCNTR4_EL0).mapsTo(MISCREG_PMEVCNTR4);
19112477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVCNTR5_EL0).mapsTo(MISCREG_PMEVCNTR5);
19212477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVTYPER0_EL0).mapsTo(MISCREG_PMEVTYPER0);
19312477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVTYPER1_EL0).mapsTo(MISCREG_PMEVTYPER1);
19412477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVTYPER2_EL0).mapsTo(MISCREG_PMEVTYPER2);
19512477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVTYPER3_EL0).mapsTo(MISCREG_PMEVTYPER3);
19612477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVTYPER4_EL0).mapsTo(MISCREG_PMEVTYPER4);
19712477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMEVTYPER5_EL0).mapsTo(MISCREG_PMEVTYPER5); */
19812477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMINTENCLR_EL1).mapsTo(MISCREG_PMINTENCLR);
19912477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMINTENSET_EL1).mapsTo(MISCREG_PMINTENSET);
20012477SCurtis.Dunham@arm.com//  InitReg(MISCREG_PMOVSCLR_EL0).mapsTo(MISCREG_PMOVSCLR);
20112477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMOVSSET_EL0).mapsTo(MISCREG_PMOVSSET);
20212477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMSELR_EL0).mapsTo(MISCREG_PMSELR);
20312477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMSWINC_EL0).mapsTo(MISCREG_PMSWINC);
20412477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMUSERENR_EL0).mapsTo(MISCREG_PMUSERENR);
20512477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMXEVCNTR_EL0).mapsTo(MISCREG_PMXEVCNTR);
20612477SCurtis.Dunham@arm.com    InitReg(MISCREG_PMXEVTYPER_EL0).mapsTo(MISCREG_PMXEVTYPER);
20711768SCurtis.Dunham@arm.com
20811768SCurtis.Dunham@arm.com    // from ARM DDI 0487A.i, template text
20911768SCurtis.Dunham@arm.com    // "AArch64 System register ___ can be mapped to
21011768SCurtis.Dunham@arm.com    //  AArch32 System register ___, but this is not
21111768SCurtis.Dunham@arm.com    //  architecturally mandated."
21212477SCurtis.Dunham@arm.com    InitReg(MISCREG_SCR_EL3).mapsTo(MISCREG_SCR); // D7-2005
21311768SCurtis.Dunham@arm.com    // MDCR_EL3 -> SDCR, D7-2108 (the latter is unimpl. in gem5)
21412477SCurtis.Dunham@arm.com    InitReg(MISCREG_SPSR_EL1).mapsTo(MISCREG_SPSR_SVC); // C5.2.17 SPSR_EL1
21512477SCurtis.Dunham@arm.com    InitReg(MISCREG_SPSR_EL2).mapsTo(MISCREG_SPSR_HYP); // C5.2.18 SPSR_EL2
21612477SCurtis.Dunham@arm.com    InitReg(MISCREG_SPSR_EL3).mapsTo(MISCREG_SPSR_MON); // C5.2.19 SPSR_EL3
21712477SCurtis.Dunham@arm.com}
21810037SARM gem5 Developers
2199384SAndreas.Sandberg@arm.comISA::ISA(Params *p)
22010461SAndreas.Sandberg@ARM.com    : SimObject(p),
22110461SAndreas.Sandberg@ARM.com      system(NULL),
22211165SRekai.GonzalezAlberquilla@arm.com      _decoderFlavour(p->decoderFlavour),
22312109SRekai.GonzalezAlberquilla@arm.com      _vecRegRenameMode(p->vecRegRenameMode),
22410461SAndreas.Sandberg@ARM.com      pmu(p->pmu),
22512477SCurtis.Dunham@arm.com      lookUpMiscReg(NUM_MISCREGS)
2269384SAndreas.Sandberg@arm.com{
22711770SCurtis.Dunham@arm.com    miscRegs[MISCREG_SCTLR_RST] = 0;
22810037SARM gem5 Developers
22910461SAndreas.Sandberg@ARM.com    // Hook up a dummy device if we haven't been configured with a
23010461SAndreas.Sandberg@ARM.com    // real PMU. By using a dummy device, we don't need to check that
23110461SAndreas.Sandberg@ARM.com    // the PMU exist every time we try to access a PMU register.
23210461SAndreas.Sandberg@ARM.com    if (!pmu)
23310461SAndreas.Sandberg@ARM.com        pmu = &dummyDevice;
23410461SAndreas.Sandberg@ARM.com
23510609Sandreas.sandberg@arm.com    // Give all ISA devices a pointer to this ISA
23610609Sandreas.sandberg@arm.com    pmu->setISA(this);
23710609Sandreas.sandberg@arm.com
23810037SARM gem5 Developers    system = dynamic_cast<ArmSystem *>(p->system);
23910037SARM gem5 Developers
24010037SARM gem5 Developers    // Cache system-level properties
24110037SARM gem5 Developers    if (FullSystem && system) {
24211771SCurtis.Dunham@arm.com        highestELIs64 = system->highestELIs64();
24310037SARM gem5 Developers        haveSecurity = system->haveSecurity();
24410037SARM gem5 Developers        haveLPAE = system->haveLPAE();
24510037SARM gem5 Developers        haveVirtualization = system->haveVirtualization();
24610037SARM gem5 Developers        haveLargeAsid64 = system->haveLargeAsid64();
24710037SARM gem5 Developers        physAddrRange64 = system->physAddrRange64();
24810037SARM gem5 Developers    } else {
24911771SCurtis.Dunham@arm.com        highestELIs64 = true; // ArmSystem::highestELIs64 does the same
25010037SARM gem5 Developers        haveSecurity = haveLPAE = haveVirtualization = false;
25110037SARM gem5 Developers        haveLargeAsid64 = false;
25210037SARM gem5 Developers        physAddrRange64 = 32;  // dummy value
25310037SARM gem5 Developers    }
25410037SARM gem5 Developers
25512477SCurtis.Dunham@arm.com    initializeMiscRegMetadata();
25610037SARM gem5 Developers    preUnflattenMiscReg();
25710037SARM gem5 Developers
2589384SAndreas.Sandberg@arm.com    clear();
2599384SAndreas.Sandberg@arm.com}
2609384SAndreas.Sandberg@arm.com
2619384SAndreas.Sandberg@arm.comconst ArmISAParams *
2629384SAndreas.Sandberg@arm.comISA::params() const
2639384SAndreas.Sandberg@arm.com{
2649384SAndreas.Sandberg@arm.com    return dynamic_cast<const Params *>(_params);
2659384SAndreas.Sandberg@arm.com}
2669384SAndreas.Sandberg@arm.com
2677427Sgblack@eecs.umich.eduvoid
2687427Sgblack@eecs.umich.eduISA::clear()
2697427Sgblack@eecs.umich.edu{
2709385SAndreas.Sandberg@arm.com    const Params *p(params());
2719385SAndreas.Sandberg@arm.com
2727427Sgblack@eecs.umich.edu    SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST];
2737427Sgblack@eecs.umich.edu    memset(miscRegs, 0, sizeof(miscRegs));
27410037SARM gem5 Developers
27510037SARM gem5 Developers    // Initialize configurable default values
27610037SARM gem5 Developers    miscRegs[MISCREG_MIDR] = p->midr;
27710037SARM gem5 Developers    miscRegs[MISCREG_MIDR_EL1] = p->midr;
27810037SARM gem5 Developers    miscRegs[MISCREG_VPIDR] = p->midr;
27910037SARM gem5 Developers
28010037SARM gem5 Developers    if (FullSystem && system->highestELIs64()) {
28110037SARM gem5 Developers        // Initialize AArch64 state
28210037SARM gem5 Developers        clear64(p);
28310037SARM gem5 Developers        return;
28410037SARM gem5 Developers    }
28510037SARM gem5 Developers
28610037SARM gem5 Developers    // Initialize AArch32 state...
28710037SARM gem5 Developers
2887427Sgblack@eecs.umich.edu    CPSR cpsr = 0;
2897427Sgblack@eecs.umich.edu    cpsr.mode = MODE_USER;
2907427Sgblack@eecs.umich.edu    miscRegs[MISCREG_CPSR] = cpsr;
2917427Sgblack@eecs.umich.edu    updateRegMap(cpsr);
2927427Sgblack@eecs.umich.edu
2937427Sgblack@eecs.umich.edu    SCTLR sctlr = 0;
29410037SARM gem5 Developers    sctlr.te = (bool) sctlr_rst.te;
29510037SARM gem5 Developers    sctlr.nmfi = (bool) sctlr_rst.nmfi;
29610037SARM gem5 Developers    sctlr.v = (bool) sctlr_rst.v;
29710037SARM gem5 Developers    sctlr.u = 1;
2987427Sgblack@eecs.umich.edu    sctlr.xp = 1;
2997427Sgblack@eecs.umich.edu    sctlr.rao2 = 1;
3007427Sgblack@eecs.umich.edu    sctlr.rao3 = 1;
30110037SARM gem5 Developers    sctlr.rao4 = 0xf;  // SCTLR[6:3]
30210204SAli.Saidi@ARM.com    sctlr.uci = 1;
30310204SAli.Saidi@ARM.com    sctlr.dze = 1;
30410037SARM gem5 Developers    miscRegs[MISCREG_SCTLR_NS] = sctlr;
3057427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SCTLR_RST] = sctlr_rst;
30610037SARM gem5 Developers    miscRegs[MISCREG_HCPTR] = 0;
3077427Sgblack@eecs.umich.edu
30810037SARM gem5 Developers    // Start with an event in the mailbox
3097427Sgblack@eecs.umich.edu    miscRegs[MISCREG_SEV_MAILBOX] = 1;
3107427Sgblack@eecs.umich.edu
31110037SARM gem5 Developers    // Separate Instruction and Data TLBs
3127427Sgblack@eecs.umich.edu    miscRegs[MISCREG_TLBTR] = 1;
3137427Sgblack@eecs.umich.edu
3147427Sgblack@eecs.umich.edu    MVFR0 mvfr0 = 0;
3157427Sgblack@eecs.umich.edu    mvfr0.advSimdRegisters = 2;
3167427Sgblack@eecs.umich.edu    mvfr0.singlePrecision = 2;
3177427Sgblack@eecs.umich.edu    mvfr0.doublePrecision = 2;
3187427Sgblack@eecs.umich.edu    mvfr0.vfpExceptionTrapping = 0;
3197427Sgblack@eecs.umich.edu    mvfr0.divide = 1;
3207427Sgblack@eecs.umich.edu    mvfr0.squareRoot = 1;
3217427Sgblack@eecs.umich.edu    mvfr0.shortVectors = 1;
3227427Sgblack@eecs.umich.edu    mvfr0.roundingModes = 1;
3237427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR0] = mvfr0;
3247427Sgblack@eecs.umich.edu
3257427Sgblack@eecs.umich.edu    MVFR1 mvfr1 = 0;
3267427Sgblack@eecs.umich.edu    mvfr1.flushToZero = 1;
3277427Sgblack@eecs.umich.edu    mvfr1.defaultNaN = 1;
3287427Sgblack@eecs.umich.edu    mvfr1.advSimdLoadStore = 1;
3297427Sgblack@eecs.umich.edu    mvfr1.advSimdInteger = 1;
3307427Sgblack@eecs.umich.edu    mvfr1.advSimdSinglePrecision = 1;
3317427Sgblack@eecs.umich.edu    mvfr1.advSimdHalfPrecision = 1;
3327427Sgblack@eecs.umich.edu    mvfr1.vfpHalfPrecision = 1;
3337427Sgblack@eecs.umich.edu    miscRegs[MISCREG_MVFR1] = mvfr1;
3347427Sgblack@eecs.umich.edu
3357436Sdam.sunwoo@arm.com    // Reset values of PRRR and NMRR are implementation dependent
3367436Sdam.sunwoo@arm.com
33710037SARM gem5 Developers    // @todo: PRRR and NMRR in secure state?
33810037SARM gem5 Developers    miscRegs[MISCREG_PRRR_NS] =
3397436Sdam.sunwoo@arm.com        (1 << 19) | // 19
3407436Sdam.sunwoo@arm.com        (0 << 18) | // 18
3417436Sdam.sunwoo@arm.com        (0 << 17) | // 17
3427436Sdam.sunwoo@arm.com        (1 << 16) | // 16
3437436Sdam.sunwoo@arm.com        (2 << 14) | // 15:14
3447436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
3457436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
3467436Sdam.sunwoo@arm.com        (2 << 8)  | // 9:8
3477436Sdam.sunwoo@arm.com        (2 << 6)  | // 7:6
3487436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
3497436Sdam.sunwoo@arm.com        (1 << 2)  | // 3:2
3507436Sdam.sunwoo@arm.com        0;          // 1:0
35110037SARM gem5 Developers    miscRegs[MISCREG_NMRR_NS] =
3527436Sdam.sunwoo@arm.com        (1 << 30) | // 31:30
3537436Sdam.sunwoo@arm.com        (0 << 26) | // 27:26
3547436Sdam.sunwoo@arm.com        (0 << 24) | // 25:24
3557436Sdam.sunwoo@arm.com        (3 << 22) | // 23:22
3567436Sdam.sunwoo@arm.com        (2 << 20) | // 21:20
3577436Sdam.sunwoo@arm.com        (0 << 18) | // 19:18
3587436Sdam.sunwoo@arm.com        (0 << 16) | // 17:16
3597436Sdam.sunwoo@arm.com        (1 << 14) | // 15:14
3607436Sdam.sunwoo@arm.com        (0 << 12) | // 13:12
3617436Sdam.sunwoo@arm.com        (2 << 10) | // 11:10
3627436Sdam.sunwoo@arm.com        (0 << 8)  | // 9:8
3637436Sdam.sunwoo@arm.com        (3 << 6)  | // 7:6
3647436Sdam.sunwoo@arm.com        (2 << 4)  | // 5:4
3657436Sdam.sunwoo@arm.com        (0 << 2)  | // 3:2
3667436Sdam.sunwoo@arm.com        0;          // 1:0
3677436Sdam.sunwoo@arm.com
3687644Sali.saidi@arm.com    miscRegs[MISCREG_CPACR] = 0;
3698147SAli.Saidi@ARM.com
3709385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0;
3719385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1;
3729385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2;
3739385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3;
3749385SAndreas.Sandberg@arm.com
3759385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR0] = p->id_isar0;
3769385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR1] = p->id_isar1;
3779385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR2] = p->id_isar2;
3789385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR3] = p->id_isar3;
3799385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR4] = p->id_isar4;
3809385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_ID_ISAR5] = p->id_isar5;
3819385SAndreas.Sandberg@arm.com
3829385SAndreas.Sandberg@arm.com    miscRegs[MISCREG_FPSID] = p->fpsid;
3839385SAndreas.Sandberg@arm.com
38410037SARM gem5 Developers    if (haveLPAE) {
38510037SARM gem5 Developers        TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS];
38610037SARM gem5 Developers        ttbcr.eae = 0;
38710037SARM gem5 Developers        miscRegs[MISCREG_TTBCR_NS] = ttbcr;
38810037SARM gem5 Developers        // Enforce consistency with system-level settings
38910037SARM gem5 Developers        miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5;
39010037SARM gem5 Developers    }
39110037SARM gem5 Developers
39210037SARM gem5 Developers    if (haveSecurity) {
39310037SARM gem5 Developers        miscRegs[MISCREG_SCTLR_S] = sctlr;
39410037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 0;
39510037SARM gem5 Developers        miscRegs[MISCREG_VBAR_S] = 0;
39610037SARM gem5 Developers    } else {
39710037SARM gem5 Developers        // we're always non-secure
39810037SARM gem5 Developers        miscRegs[MISCREG_SCR] = 1;
39910037SARM gem5 Developers    }
4008147SAli.Saidi@ARM.com
4017427Sgblack@eecs.umich.edu    //XXX We need to initialize the rest of the state.
4027427Sgblack@eecs.umich.edu}
4037427Sgblack@eecs.umich.edu
40410037SARM gem5 Developersvoid
40510037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p)
40610037SARM gem5 Developers{
40710037SARM gem5 Developers    CPSR cpsr = 0;
40810037SARM gem5 Developers    Addr rvbar = system->resetAddr64();
40910037SARM gem5 Developers    switch (system->highestEL()) {
41010037SARM gem5 Developers        // Set initial EL to highest implemented EL using associated stack
41110037SARM gem5 Developers        // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset
41210037SARM gem5 Developers        // value
41310037SARM gem5 Developers      case EL3:
41410037SARM gem5 Developers        cpsr.mode = MODE_EL3H;
41510037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL3] = rvbar;
41610037SARM gem5 Developers        break;
41710037SARM gem5 Developers      case EL2:
41810037SARM gem5 Developers        cpsr.mode = MODE_EL2H;
41910037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL2] = rvbar;
42010037SARM gem5 Developers        break;
42110037SARM gem5 Developers      case EL1:
42210037SARM gem5 Developers        cpsr.mode = MODE_EL1H;
42310037SARM gem5 Developers        miscRegs[MISCREG_RVBAR_EL1] = rvbar;
42410037SARM gem5 Developers        break;
42510037SARM gem5 Developers      default:
42610037SARM gem5 Developers        panic("Invalid highest implemented exception level");
42710037SARM gem5 Developers        break;
42810037SARM gem5 Developers    }
42910037SARM gem5 Developers
43010037SARM gem5 Developers    // Initialize rest of CPSR
43110037SARM gem5 Developers    cpsr.daif = 0xf;  // Mask all interrupts
43210037SARM gem5 Developers    cpsr.ss = 0;
43310037SARM gem5 Developers    cpsr.il = 0;
43410037SARM gem5 Developers    miscRegs[MISCREG_CPSR] = cpsr;
43510037SARM gem5 Developers    updateRegMap(cpsr);
43610037SARM gem5 Developers
43710037SARM gem5 Developers    // Initialize other control registers
43810037SARM gem5 Developers    miscRegs[MISCREG_MPIDR_EL1] = 0x80000000;
43910037SARM gem5 Developers    if (haveSecurity) {
44011770SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830;
44110037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3]   = 0x00000030;  // RES1 fields
44211574SCurtis.Dunham@arm.com    } else if (haveVirtualization) {
44311770SCurtis.Dunham@arm.com        // also  MISCREG_SCTLR_EL2 (by mapping)
44411770SCurtis.Dunham@arm.com        miscRegs[MISCREG_HSCTLR] = 0x30c50830;
44510037SARM gem5 Developers    } else {
44611770SCurtis.Dunham@arm.com        // also  MISCREG_SCTLR_EL1 (by mapping)
44711770SCurtis.Dunham@arm.com        miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init
44810037SARM gem5 Developers        // Always non-secure
44910037SARM gem5 Developers        miscRegs[MISCREG_SCR_EL3] = 1;
45010037SARM gem5 Developers    }
45110037SARM gem5 Developers
45210037SARM gem5 Developers    // Initialize configurable id registers
45310037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1;
45410037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1;
45510461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_AA64DFR0_EL1] =
45610461SAndreas.Sandberg@ARM.com        (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) |
45710461SAndreas.Sandberg@ARM.com        (p->pmu ?             0x0000000000000100ULL : 0); // Enable PMUv3
45810461SAndreas.Sandberg@ARM.com
45910037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1;
46010037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1;
46110037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1;
46210037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1;
46310037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1;
46410037SARM gem5 Developers
46510461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0_EL1] =
46610461SAndreas.Sandberg@ARM.com        (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3
46710461SAndreas.Sandberg@ARM.com
46810461SAndreas.Sandberg@ARM.com    miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1];
46910461SAndreas.Sandberg@ARM.com
47010037SARM gem5 Developers    // Enforce consistency with system-level settings...
47110037SARM gem5 Developers
47210037SARM gem5 Developers    // EL3
47310037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
47410037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12,
47511574SCurtis.Dunham@arm.com        haveSecurity ? 0x2 : 0x0);
47610037SARM gem5 Developers    // EL2
47710037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits(
47810037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8,
47911574SCurtis.Dunham@arm.com        haveVirtualization ? 0x2 : 0x0);
48010037SARM gem5 Developers    // Large ASID support
48110037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
48210037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4,
48310037SARM gem5 Developers        haveLargeAsid64 ? 0x2 : 0x0);
48410037SARM gem5 Developers    // Physical address size
48510037SARM gem5 Developers    miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits(
48610037SARM gem5 Developers        miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0,
48710037SARM gem5 Developers        encodePhysAddrRange64(physAddrRange64));
48810037SARM gem5 Developers}
48910037SARM gem5 Developers
4907405SAli.Saidi@ARM.comMiscReg
49110035Sandreas.hansson@arm.comISA::readMiscRegNoEffect(int misc_reg) const
4927405SAli.Saidi@ARM.com{
4937405SAli.Saidi@ARM.com    assert(misc_reg < NumMiscRegs);
4947614Sminkyu.jeong@arm.com
49511771SCurtis.Dunham@arm.com    auto regs = getMiscIndices(misc_reg);
49611771SCurtis.Dunham@arm.com    int lower = regs.first, upper = regs.second;
49711771SCurtis.Dunham@arm.com    return !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32))
49811771SCurtis.Dunham@arm.com                                      |(miscRegs[upper] << 32));
4997405SAli.Saidi@ARM.com}
5007405SAli.Saidi@ARM.com
5017405SAli.Saidi@ARM.com
5027405SAli.Saidi@ARM.comMiscReg
5037405SAli.Saidi@ARM.comISA::readMiscReg(int misc_reg, ThreadContext *tc)
5047405SAli.Saidi@ARM.com{
50510037SARM gem5 Developers    CPSR cpsr = 0;
50610037SARM gem5 Developers    PCState pc = 0;
50710037SARM gem5 Developers    SCR scr = 0;
5089050Schander.sudanthi@arm.com
5097405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
51010037SARM gem5 Developers        cpsr = miscRegs[misc_reg];
51110037SARM gem5 Developers        pc = tc->pcState();
5127720Sgblack@eecs.umich.edu        cpsr.j = pc.jazelle() ? 1 : 0;
5137720Sgblack@eecs.umich.edu        cpsr.t = pc.thumb() ? 1 : 0;
5147405SAli.Saidi@ARM.com        return cpsr;
5157405SAli.Saidi@ARM.com    }
5167757SAli.Saidi@ARM.com
51710037SARM gem5 Developers#ifndef NDEBUG
51810037SARM gem5 Developers    if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
51910037SARM gem5 Developers        if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
52010037SARM gem5 Developers            warn("Unimplemented system register %s read.\n",
52110037SARM gem5 Developers                 miscRegName[misc_reg]);
52210037SARM gem5 Developers        else
52310037SARM gem5 Developers            panic("Unimplemented system register %s read.\n",
52410037SARM gem5 Developers                  miscRegName[misc_reg]);
52510037SARM gem5 Developers    }
52610037SARM gem5 Developers#endif
52710037SARM gem5 Developers
52810037SARM gem5 Developers    switch (unflattenMiscReg(misc_reg)) {
52910037SARM gem5 Developers      case MISCREG_HCR:
53010037SARM gem5 Developers        {
53110037SARM gem5 Developers            if (!haveVirtualization)
53210037SARM gem5 Developers                return 0;
53310037SARM gem5 Developers            else
53410037SARM gem5 Developers                return readMiscRegNoEffect(MISCREG_HCR);
53510037SARM gem5 Developers        }
53610037SARM gem5 Developers      case MISCREG_CPACR:
53710037SARM gem5 Developers        {
53810037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
53910037SARM gem5 Developers            CPACR cpacrMask = 0;
54010037SARM gem5 Developers            // Only cp10, cp11, and ase are implemented, nothing else should
54110037SARM gem5 Developers            // be readable? (straight copy from the write code)
54210037SARM gem5 Developers            cpacrMask.cp10 = ones;
54310037SARM gem5 Developers            cpacrMask.cp11 = ones;
54410037SARM gem5 Developers            cpacrMask.asedis = ones;
54510037SARM gem5 Developers
54610037SARM gem5 Developers            // Security Extensions may limit the readability of CPACR
54710037SARM gem5 Developers            if (haveSecurity) {
54810037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
54910037SARM gem5 Developers                cpsr = readMiscRegNoEffect(MISCREG_CPSR);
55010037SARM gem5 Developers                if (scr.ns && (cpsr.mode != MODE_MON)) {
55110037SARM gem5 Developers                    NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
55210037SARM gem5 Developers                    // NB: Skipping the full loop, here
55310037SARM gem5 Developers                    if (!nsacr.cp10) cpacrMask.cp10 = 0;
55410037SARM gem5 Developers                    if (!nsacr.cp11) cpacrMask.cp11 = 0;
55510037SARM gem5 Developers                }
55610037SARM gem5 Developers            }
55710037SARM gem5 Developers            MiscReg val = readMiscRegNoEffect(MISCREG_CPACR);
55810037SARM gem5 Developers            val &= cpacrMask;
55910037SARM gem5 Developers            DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n",
56010037SARM gem5 Developers                    miscRegName[misc_reg], val);
56110037SARM gem5 Developers            return val;
56210037SARM gem5 Developers        }
5638284SAli.Saidi@ARM.com      case MISCREG_MPIDR:
56410037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
56510037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
56610037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
56710037SARM gem5 Developers            return getMPIDR(system, tc);
5689050Schander.sudanthi@arm.com        } else {
56910037SARM gem5 Developers            return readMiscReg(MISCREG_VMPIDR, tc);
57010037SARM gem5 Developers        }
57110037SARM gem5 Developers            break;
57210037SARM gem5 Developers      case MISCREG_MPIDR_EL1:
57310037SARM gem5 Developers        // @todo in the absence of v8 virtualization support just return MPIDR_EL1
57410037SARM gem5 Developers        return getMPIDR(system, tc) & 0xffffffff;
57510037SARM gem5 Developers      case MISCREG_VMPIDR:
57610037SARM gem5 Developers        // top bit defined as RES1
57710037SARM gem5 Developers        return readMiscRegNoEffect(misc_reg) | 0x80000000;
57810037SARM gem5 Developers      case MISCREG_ID_AFR0: // not implemented, so alias MIDR
57910037SARM gem5 Developers      case MISCREG_REVIDR:  // not implemented, so alias MIDR
58010037SARM gem5 Developers      case MISCREG_MIDR:
58110037SARM gem5 Developers        cpsr = readMiscRegNoEffect(MISCREG_CPSR);
58210037SARM gem5 Developers        scr  = readMiscRegNoEffect(MISCREG_SCR);
58310037SARM gem5 Developers        if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) {
58410037SARM gem5 Developers            return readMiscRegNoEffect(misc_reg);
58510037SARM gem5 Developers        } else {
58610037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_VPIDR);
5879050Schander.sudanthi@arm.com        }
5888284SAli.Saidi@ARM.com        break;
58910037SARM gem5 Developers      case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI
59010037SARM gem5 Developers      case MISCREG_JMCR:  // Jazelle trivial implementation, RAZ/WI
59110037SARM gem5 Developers      case MISCREG_JIDR:  // Jazelle trivial implementation, RAZ/WI
59210037SARM gem5 Developers      case MISCREG_AIDR:  // AUX ID set to 0
59310037SARM gem5 Developers      case MISCREG_TCMTR: // No TCM's
59410037SARM gem5 Developers        return 0;
59510037SARM gem5 Developers
5967405SAli.Saidi@ARM.com      case MISCREG_CLIDR:
5977731SAli.Saidi@ARM.com        warn_once("The clidr register always reports 0 caches.\n");
5988468Swade.walker@arm.com        warn_once("clidr LoUIS field of 0b001 to match current "
5998468Swade.walker@arm.com                  "ARM implementations.\n");
6008468Swade.walker@arm.com        return 0x00200000;
6017405SAli.Saidi@ARM.com      case MISCREG_CCSIDR:
6027731SAli.Saidi@ARM.com        warn_once("The ccsidr register isn't implemented and "
6037405SAli.Saidi@ARM.com                "always reads as 0.\n");
6047405SAli.Saidi@ARM.com        break;
60511809Sbaz21@cam.ac.uk      case MISCREG_CTR:                 // AArch32, ARMv7, top bit set
60611809Sbaz21@cam.ac.uk      case MISCREG_CTR_EL0:             // AArch64
6079130Satgutier@umich.edu        {
6089130Satgutier@umich.edu            //all caches have the same line size in gem5
6099130Satgutier@umich.edu            //4 byte words in ARM
6109130Satgutier@umich.edu            unsigned lineSizeWords =
6119814Sandreas.hansson@arm.com                tc->getSystemPtr()->cacheLineSize() / 4;
6129130Satgutier@umich.edu            unsigned log2LineSizeWords = 0;
6139130Satgutier@umich.edu
6149130Satgutier@umich.edu            while (lineSizeWords >>= 1) {
6159130Satgutier@umich.edu                ++log2LineSizeWords;
6169130Satgutier@umich.edu            }
6179130Satgutier@umich.edu
6189130Satgutier@umich.edu            CTR ctr = 0;
6199130Satgutier@umich.edu            //log2 of minimun i-cache line size (words)
6209130Satgutier@umich.edu            ctr.iCacheLineSize = log2LineSizeWords;
6219130Satgutier@umich.edu            //b11 - gem5 uses pipt
6229130Satgutier@umich.edu            ctr.l1IndexPolicy = 0x3;
6239130Satgutier@umich.edu            //log2 of minimum d-cache line size (words)
6249130Satgutier@umich.edu            ctr.dCacheLineSize = log2LineSizeWords;
6259130Satgutier@umich.edu            //log2 of max reservation size (words)
6269130Satgutier@umich.edu            ctr.erg = log2LineSizeWords;
6279130Satgutier@umich.edu            //log2 of max writeback size (words)
6289130Satgutier@umich.edu            ctr.cwg = log2LineSizeWords;
6299130Satgutier@umich.edu            //b100 - gem5 format is ARMv7
6309130Satgutier@umich.edu            ctr.format = 0x4;
6319130Satgutier@umich.edu
6329130Satgutier@umich.edu            return ctr;
6339130Satgutier@umich.edu        }
6347583SAli.Saidi@arm.com      case MISCREG_ACTLR:
6357583SAli.Saidi@arm.com        warn("Not doing anything for miscreg ACTLR\n");
6367583SAli.Saidi@arm.com        break;
63710461SAndreas.Sandberg@ARM.com
63810461SAndreas.Sandberg@ARM.com      case MISCREG_PMXEVTYPER_PMCCFILTR:
63910461SAndreas.Sandberg@ARM.com      case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
64010461SAndreas.Sandberg@ARM.com      case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
64110461SAndreas.Sandberg@ARM.com      case MISCREG_PMCR ... MISCREG_PMOVSSET:
64210461SAndreas.Sandberg@ARM.com        return pmu->readMiscReg(misc_reg);
64310461SAndreas.Sandberg@ARM.com
6448302SAli.Saidi@ARM.com      case MISCREG_CPSR_Q:
6458302SAli.Saidi@ARM.com        panic("shouldn't be reading this register seperately\n");
6467783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_QC:
6477783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask;
6487783SGiacomo.Gabrielli@arm.com      case MISCREG_FPSCR_EXC:
6497783SGiacomo.Gabrielli@arm.com        return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask;
65010037SARM gem5 Developers      case MISCREG_FPSR:
65110037SARM gem5 Developers        {
65210037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
65310037SARM gem5 Developers            FPSCR fpscrMask = 0;
65410037SARM gem5 Developers            fpscrMask.ioc = ones;
65510037SARM gem5 Developers            fpscrMask.dzc = ones;
65610037SARM gem5 Developers            fpscrMask.ofc = ones;
65710037SARM gem5 Developers            fpscrMask.ufc = ones;
65810037SARM gem5 Developers            fpscrMask.ixc = ones;
65910037SARM gem5 Developers            fpscrMask.idc = ones;
66010037SARM gem5 Developers            fpscrMask.qc = ones;
66110037SARM gem5 Developers            fpscrMask.v = ones;
66210037SARM gem5 Developers            fpscrMask.c = ones;
66310037SARM gem5 Developers            fpscrMask.z = ones;
66410037SARM gem5 Developers            fpscrMask.n = ones;
66510037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
66610037SARM gem5 Developers        }
66710037SARM gem5 Developers      case MISCREG_FPCR:
66810037SARM gem5 Developers        {
66910037SARM gem5 Developers            const uint32_t ones = (uint32_t)(-1);
67010037SARM gem5 Developers            FPSCR fpscrMask  = 0;
67110037SARM gem5 Developers            fpscrMask.ioe = ones;
67210037SARM gem5 Developers            fpscrMask.dze = ones;
67310037SARM gem5 Developers            fpscrMask.ofe = ones;
67410037SARM gem5 Developers            fpscrMask.ufe = ones;
67510037SARM gem5 Developers            fpscrMask.ixe = ones;
67610037SARM gem5 Developers            fpscrMask.ide = ones;
67710037SARM gem5 Developers            fpscrMask.len    = ones;
67810037SARM gem5 Developers            fpscrMask.stride = ones;
67910037SARM gem5 Developers            fpscrMask.rMode  = ones;
68010037SARM gem5 Developers            fpscrMask.fz     = ones;
68110037SARM gem5 Developers            fpscrMask.dn     = ones;
68210037SARM gem5 Developers            fpscrMask.ahp    = ones;
68310037SARM gem5 Developers            return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask;
68410037SARM gem5 Developers        }
68510037SARM gem5 Developers      case MISCREG_NZCV:
68610037SARM gem5 Developers        {
68710037SARM gem5 Developers            CPSR cpsr = 0;
68810338SCurtis.Dunham@arm.com            cpsr.nz   = tc->readCCReg(CCREG_NZ);
68910338SCurtis.Dunham@arm.com            cpsr.c    = tc->readCCReg(CCREG_C);
69010338SCurtis.Dunham@arm.com            cpsr.v    = tc->readCCReg(CCREG_V);
69110037SARM gem5 Developers            return cpsr;
69210037SARM gem5 Developers        }
69310037SARM gem5 Developers      case MISCREG_DAIF:
69410037SARM gem5 Developers        {
69510037SARM gem5 Developers            CPSR cpsr = 0;
69610037SARM gem5 Developers            cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif;
69710037SARM gem5 Developers            return cpsr;
69810037SARM gem5 Developers        }
69910037SARM gem5 Developers      case MISCREG_SP_EL0:
70010037SARM gem5 Developers        {
70110037SARM gem5 Developers            return tc->readIntReg(INTREG_SP0);
70210037SARM gem5 Developers        }
70310037SARM gem5 Developers      case MISCREG_SP_EL1:
70410037SARM gem5 Developers        {
70510037SARM gem5 Developers            return tc->readIntReg(INTREG_SP1);
70610037SARM gem5 Developers        }
70710037SARM gem5 Developers      case MISCREG_SP_EL2:
70810037SARM gem5 Developers        {
70910037SARM gem5 Developers            return tc->readIntReg(INTREG_SP2);
71010037SARM gem5 Developers        }
71110037SARM gem5 Developers      case MISCREG_SPSEL:
71210037SARM gem5 Developers        {
71310037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0x1;
71410037SARM gem5 Developers        }
71510037SARM gem5 Developers      case MISCREG_CURRENTEL:
71610037SARM gem5 Developers        {
71710037SARM gem5 Developers            return miscRegs[MISCREG_CPSR] & 0xc;
71810037SARM gem5 Developers        }
7198549Sdaniel.johnson@arm.com      case MISCREG_L2CTLR:
7208868SMatt.Horsnell@arm.com        {
7218868SMatt.Horsnell@arm.com            // mostly unimplemented, just set NumCPUs field from sim and return
7228868SMatt.Horsnell@arm.com            L2CTLR l2ctlr = 0;
7238868SMatt.Horsnell@arm.com            // b00:1CPU to b11:4CPUs
7248868SMatt.Horsnell@arm.com            l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1;
7258868SMatt.Horsnell@arm.com            return l2ctlr;
7268868SMatt.Horsnell@arm.com        }
7278868SMatt.Horsnell@arm.com      case MISCREG_DBGDIDR:
7288868SMatt.Horsnell@arm.com        /* For now just implement the version number.
72910461SAndreas.Sandberg@ARM.com         * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5)
7308868SMatt.Horsnell@arm.com         */
73110461SAndreas.Sandberg@ARM.com        return 0x5 << 16;
73210037SARM gem5 Developers      case MISCREG_DBGDSCRint:
7338868SMatt.Horsnell@arm.com        return 0;
73410037SARM gem5 Developers      case MISCREG_ISR:
73511150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
73610037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR),
73710037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
73810037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR));
73910037SARM gem5 Developers      case MISCREG_ISR_EL1:
74011150Smitch.hayenga@arm.com        return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR(
74110037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_HCR_EL2),
74210037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_CPSR),
74310037SARM gem5 Developers            readMiscRegNoEffect(MISCREG_SCR_EL3));
74410037SARM gem5 Developers      case MISCREG_DCZID_EL0:
74510037SARM gem5 Developers        return 0x04;  // DC ZVA clear 64-byte chunks
74610037SARM gem5 Developers      case MISCREG_HCPTR:
74710037SARM gem5 Developers        {
74810037SARM gem5 Developers            MiscReg val = readMiscRegNoEffect(misc_reg);
74910037SARM gem5 Developers            // The trap bit associated with CP14 is defined as RAZ
75010037SARM gem5 Developers            val &= ~(1 << 14);
75110037SARM gem5 Developers            // If a CP bit in NSACR is 0 then the corresponding bit in
75210037SARM gem5 Developers            // HCPTR is RAO/WI
75310037SARM gem5 Developers            bool secure_lookup = haveSecurity &&
75410037SARM gem5 Developers                inSecureState(readMiscRegNoEffect(MISCREG_SCR),
75510037SARM gem5 Developers                              readMiscRegNoEffect(MISCREG_CPSR));
75610037SARM gem5 Developers            if (!secure_lookup) {
75710037SARM gem5 Developers                MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR);
75810037SARM gem5 Developers                val |= (mask ^ 0x7FFF) & 0xBFFF;
75910037SARM gem5 Developers            }
76010037SARM gem5 Developers            // Set the bits for unimplemented coprocessors to RAO/WI
76110037SARM gem5 Developers            val |= 0x33FF;
76210037SARM gem5 Developers            return (val);
76310037SARM gem5 Developers        }
76410037SARM gem5 Developers      case MISCREG_HDFAR: // alias for secure DFAR
76510037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_DFAR_S);
76610037SARM gem5 Developers      case MISCREG_HIFAR: // alias for secure IFAR
76710037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_IFAR_S);
76810037SARM gem5 Developers      case MISCREG_HVBAR: // bottom bits reserved
76910037SARM gem5 Developers        return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0;
77011769SCurtis.Dunham@arm.com      case MISCREG_SCTLR:
77111769SCurtis.Dunham@arm.com        return (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818;
77210037SARM gem5 Developers      case MISCREG_SCTLR_EL1:
77311770SCurtis.Dunham@arm.com        return (readMiscRegNoEffect(misc_reg) & 0x37DDDBBF) | 0x30D00800;
77411770SCurtis.Dunham@arm.com      case MISCREG_SCTLR_EL2:
77510037SARM gem5 Developers      case MISCREG_SCTLR_EL3:
77611770SCurtis.Dunham@arm.com      case MISCREG_HSCTLR:
77711769SCurtis.Dunham@arm.com        return (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830;
77810844Sandreas.sandberg@arm.com
77911772SCurtis.Dunham@arm.com      case MISCREG_ID_PFR0:
78011772SCurtis.Dunham@arm.com        // !ThumbEE | !Jazelle | Thumb | ARM
78111772SCurtis.Dunham@arm.com        return 0x00000031;
78211772SCurtis.Dunham@arm.com      case MISCREG_ID_PFR1:
78311774SCurtis.Dunham@arm.com        {   // Timer | Virti | !M Profile | TrustZone | ARMv4
78411774SCurtis.Dunham@arm.com            bool haveTimer = (system->getGenericTimer() != NULL);
78511774SCurtis.Dunham@arm.com            return 0x00000001
78611774SCurtis.Dunham@arm.com                 | (haveSecurity       ? 0x00000010 : 0x0)
78711774SCurtis.Dunham@arm.com                 | (haveVirtualization ? 0x00001000 : 0x0)
78811774SCurtis.Dunham@arm.com                 | (haveTimer          ? 0x00010000 : 0x0);
78911774SCurtis.Dunham@arm.com        }
79011773SCurtis.Dunham@arm.com      case MISCREG_ID_AA64PFR0_EL1:
79111773SCurtis.Dunham@arm.com        return 0x0000000000000002   // AArch{64,32} supported at EL0
79211773SCurtis.Dunham@arm.com             | 0x0000000000000020                             // EL1
79311773SCurtis.Dunham@arm.com             | (haveVirtualization ? 0x0000000000000200 : 0)  // EL2
79411773SCurtis.Dunham@arm.com             | (haveSecurity       ? 0x0000000000002000 : 0); // EL3
79511773SCurtis.Dunham@arm.com      case MISCREG_ID_AA64PFR1_EL1:
79611773SCurtis.Dunham@arm.com        return 0; // bits [63:0] RES0 (reserved for future use)
79711772SCurtis.Dunham@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
81711771SCurtis.Dunham@arm.com    auto regs = getMiscIndices(misc_reg);
81811771SCurtis.Dunham@arm.com    int lower = regs.first, upper = regs.second;
81911771SCurtis.Dunham@arm.com    if (upper > 0) {
82011771SCurtis.Dunham@arm.com        miscRegs[lower] = bits(val, 31, 0);
82111771SCurtis.Dunham@arm.com        miscRegs[upper] = bits(val, 63, 32);
82210037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n",
82311771SCurtis.Dunham@arm.com                misc_reg, lower, upper, val);
82410037SARM gem5 Developers    } else {
82511771SCurtis.Dunham@arm.com        miscRegs[lower] = val;
82610037SARM gem5 Developers        DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n",
82711771SCurtis.Dunham@arm.com                misc_reg, lower, val);
82810037SARM gem5 Developers    }
8297405SAli.Saidi@ARM.com}
8307405SAli.Saidi@ARM.com
83112406Sgabeblack@google.comnamespace {
83212406Sgabeblack@google.com
83312406Sgabeblack@google.comtemplate<typename T>
83412406Sgabeblack@google.comTLB *
83512406Sgabeblack@google.comgetITBPtr(T *tc)
83612406Sgabeblack@google.com{
83712406Sgabeblack@google.com    auto tlb = dynamic_cast<TLB *>(tc->getITBPtr());
83812406Sgabeblack@google.com    assert(tlb);
83912406Sgabeblack@google.com    return tlb;
84012406Sgabeblack@google.com}
84112406Sgabeblack@google.com
84212406Sgabeblack@google.comtemplate<typename T>
84312406Sgabeblack@google.comTLB *
84412406Sgabeblack@google.comgetDTBPtr(T *tc)
84512406Sgabeblack@google.com{
84612406Sgabeblack@google.com    auto tlb = dynamic_cast<TLB *>(tc->getDTBPtr());
84712406Sgabeblack@google.com    assert(tlb);
84812406Sgabeblack@google.com    return tlb;
84912406Sgabeblack@google.com}
85012406Sgabeblack@google.com
85112406Sgabeblack@google.com} // anonymous namespace
85212406Sgabeblack@google.com
8537405SAli.Saidi@ARM.comvoid
8547405SAli.Saidi@ARM.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
8557405SAli.Saidi@ARM.com{
8567749SAli.Saidi@ARM.com
8577405SAli.Saidi@ARM.com    MiscReg newVal = val;
8588284SAli.Saidi@ARM.com    int x;
85910037SARM gem5 Developers    bool secure_lookup;
86010037SARM gem5 Developers    bool hyp;
8618284SAli.Saidi@ARM.com    System *sys;
8628284SAli.Saidi@ARM.com    ThreadContext *oc;
86310037SARM gem5 Developers    uint8_t target_el;
86410037SARM gem5 Developers    uint16_t asid;
86510037SARM gem5 Developers    SCR scr;
8668284SAli.Saidi@ARM.com
8677405SAli.Saidi@ARM.com    if (misc_reg == MISCREG_CPSR) {
8687405SAli.Saidi@ARM.com        updateRegMap(val);
8697749SAli.Saidi@ARM.com
8707749SAli.Saidi@ARM.com
8717749SAli.Saidi@ARM.com        CPSR old_cpsr = miscRegs[MISCREG_CPSR];
8727749SAli.Saidi@ARM.com        int old_mode = old_cpsr.mode;
8737405SAli.Saidi@ARM.com        CPSR cpsr = val;
8747749SAli.Saidi@ARM.com        if (old_mode != cpsr.mode) {
87512406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
87612406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
8777749SAli.Saidi@ARM.com        }
8787749SAli.Saidi@ARM.com
8797614Sminkyu.jeong@arm.com        DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n",
8807614Sminkyu.jeong@arm.com                miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode);
8817720Sgblack@eecs.umich.edu        PCState pc = tc->pcState();
8827720Sgblack@eecs.umich.edu        pc.nextThumb(cpsr.t);
8837720Sgblack@eecs.umich.edu        pc.nextJazelle(cpsr.j);
8848887Sgeoffrey.blake@arm.com
8858887Sgeoffrey.blake@arm.com        // Follow slightly different semantics if a CheckerCPU object
8868887Sgeoffrey.blake@arm.com        // is connected
8878887Sgeoffrey.blake@arm.com        CheckerCPU *checker = tc->getCheckerCpuPtr();
8888887Sgeoffrey.blake@arm.com        if (checker) {
8898887Sgeoffrey.blake@arm.com            tc->pcStateNoRecord(pc);
8908887Sgeoffrey.blake@arm.com        } else {
8918887Sgeoffrey.blake@arm.com            tc->pcState(pc);
8928887Sgeoffrey.blake@arm.com        }
8937408Sgblack@eecs.umich.edu    } else {
89410037SARM gem5 Developers#ifndef NDEBUG
89510037SARM gem5 Developers        if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) {
89610037SARM gem5 Developers            if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL])
89710037SARM gem5 Developers                warn("Unimplemented system register %s write with %#x.\n",
89810037SARM gem5 Developers                    miscRegName[misc_reg], val);
89910037SARM gem5 Developers            else
90010037SARM gem5 Developers                panic("Unimplemented system register %s write with %#x.\n",
90110037SARM gem5 Developers                    miscRegName[misc_reg], val);
90210037SARM gem5 Developers        }
90310037SARM gem5 Developers#endif
90410037SARM gem5 Developers        switch (unflattenMiscReg(misc_reg)) {
9057408Sgblack@eecs.umich.edu          case MISCREG_CPACR:
9067408Sgblack@eecs.umich.edu            {
9078206SWilliam.Wang@arm.com
9088206SWilliam.Wang@arm.com                const uint32_t ones = (uint32_t)(-1);
9098206SWilliam.Wang@arm.com                CPACR cpacrMask = 0;
9108206SWilliam.Wang@arm.com                // Only cp10, cp11, and ase are implemented, nothing else should
9118206SWilliam.Wang@arm.com                // be writable
9128206SWilliam.Wang@arm.com                cpacrMask.cp10 = ones;
9138206SWilliam.Wang@arm.com                cpacrMask.cp11 = ones;
9148206SWilliam.Wang@arm.com                cpacrMask.asedis = ones;
91510037SARM gem5 Developers
91610037SARM gem5 Developers                // Security Extensions may limit the writability of CPACR
91710037SARM gem5 Developers                if (haveSecurity) {
91810037SARM gem5 Developers                    scr = readMiscRegNoEffect(MISCREG_SCR);
91910037SARM gem5 Developers                    CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR);
92010037SARM gem5 Developers                    if (scr.ns && (cpsr.mode != MODE_MON)) {
92110037SARM gem5 Developers                        NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR);
92210037SARM gem5 Developers                        // NB: Skipping the full loop, here
92310037SARM gem5 Developers                        if (!nsacr.cp10) cpacrMask.cp10 = 0;
92410037SARM gem5 Developers                        if (!nsacr.cp11) cpacrMask.cp11 = 0;
92510037SARM gem5 Developers                    }
92610037SARM gem5 Developers                }
92710037SARM gem5 Developers
92810037SARM gem5 Developers                MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR);
9298206SWilliam.Wang@arm.com                newVal &= cpacrMask;
93010037SARM gem5 Developers                newVal |= old_val & ~cpacrMask;
93110037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
93210037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
93310037SARM gem5 Developers            }
93410037SARM gem5 Developers            break;
93510037SARM gem5 Developers          case MISCREG_CPACR_EL1:
93610037SARM gem5 Developers            {
93710037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
93810037SARM gem5 Developers                CPACR cpacrMask = 0;
93910037SARM gem5 Developers                cpacrMask.tta = ones;
94010037SARM gem5 Developers                cpacrMask.fpen = ones;
94110037SARM gem5 Developers                newVal &= cpacrMask;
94210037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
94310037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
94410037SARM gem5 Developers            }
94510037SARM gem5 Developers            break;
94610037SARM gem5 Developers          case MISCREG_CPTR_EL2:
94710037SARM gem5 Developers            {
94810037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
94910037SARM gem5 Developers                CPTR cptrMask = 0;
95010037SARM gem5 Developers                cptrMask.tcpac = ones;
95110037SARM gem5 Developers                cptrMask.tta = ones;
95210037SARM gem5 Developers                cptrMask.tfp = ones;
95310037SARM gem5 Developers                newVal &= cptrMask;
95410037SARM gem5 Developers                cptrMask = 0;
95510037SARM gem5 Developers                cptrMask.res1_13_12_el2 = ones;
95610037SARM gem5 Developers                cptrMask.res1_9_0_el2 = ones;
95710037SARM gem5 Developers                newVal |= cptrMask;
95810037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
95910037SARM gem5 Developers                        miscRegName[misc_reg], newVal);
96010037SARM gem5 Developers            }
96110037SARM gem5 Developers            break;
96210037SARM gem5 Developers          case MISCREG_CPTR_EL3:
96310037SARM gem5 Developers            {
96410037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
96510037SARM gem5 Developers                CPTR cptrMask = 0;
96610037SARM gem5 Developers                cptrMask.tcpac = ones;
96710037SARM gem5 Developers                cptrMask.tta = ones;
96810037SARM gem5 Developers                cptrMask.tfp = ones;
96910037SARM gem5 Developers                newVal &= cptrMask;
9708206SWilliam.Wang@arm.com                DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n",
9718206SWilliam.Wang@arm.com                        miscRegName[misc_reg], newVal);
9727408Sgblack@eecs.umich.edu            }
9737408Sgblack@eecs.umich.edu            break;
9747408Sgblack@eecs.umich.edu          case MISCREG_CSSELR:
9757731SAli.Saidi@ARM.com            warn_once("The csselr register isn't implemented.\n");
9768206SWilliam.Wang@arm.com            return;
97710037SARM gem5 Developers
97810037SARM gem5 Developers          case MISCREG_DC_ZVA_Xt:
97910037SARM gem5 Developers            warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n");
98010037SARM gem5 Developers            return;
98110037SARM gem5 Developers
9827408Sgblack@eecs.umich.edu          case MISCREG_FPSCR:
9837408Sgblack@eecs.umich.edu            {
9847408Sgblack@eecs.umich.edu                const uint32_t ones = (uint32_t)(-1);
9857408Sgblack@eecs.umich.edu                FPSCR fpscrMask = 0;
9867408Sgblack@eecs.umich.edu                fpscrMask.ioc = ones;
9877408Sgblack@eecs.umich.edu                fpscrMask.dzc = ones;
9887408Sgblack@eecs.umich.edu                fpscrMask.ofc = ones;
9897408Sgblack@eecs.umich.edu                fpscrMask.ufc = ones;
9907408Sgblack@eecs.umich.edu                fpscrMask.ixc = ones;
9917408Sgblack@eecs.umich.edu                fpscrMask.idc = ones;
99210037SARM gem5 Developers                fpscrMask.ioe = ones;
99310037SARM gem5 Developers                fpscrMask.dze = ones;
99410037SARM gem5 Developers                fpscrMask.ofe = ones;
99510037SARM gem5 Developers                fpscrMask.ufe = ones;
99610037SARM gem5 Developers                fpscrMask.ixe = ones;
99710037SARM gem5 Developers                fpscrMask.ide = ones;
9987408Sgblack@eecs.umich.edu                fpscrMask.len = ones;
9997408Sgblack@eecs.umich.edu                fpscrMask.stride = ones;
10007408Sgblack@eecs.umich.edu                fpscrMask.rMode = ones;
10017408Sgblack@eecs.umich.edu                fpscrMask.fz = ones;
10027408Sgblack@eecs.umich.edu                fpscrMask.dn = ones;
10037408Sgblack@eecs.umich.edu                fpscrMask.ahp = ones;
10047408Sgblack@eecs.umich.edu                fpscrMask.qc = ones;
10057408Sgblack@eecs.umich.edu                fpscrMask.v = ones;
10067408Sgblack@eecs.umich.edu                fpscrMask.c = ones;
10077408Sgblack@eecs.umich.edu                fpscrMask.z = ones;
10087408Sgblack@eecs.umich.edu                fpscrMask.n = ones;
10097408Sgblack@eecs.umich.edu                newVal = (newVal & (uint32_t)fpscrMask) |
101010037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
101110037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
10129377Sgblack@eecs.umich.edu                tc->getDecoderPtr()->setContext(newVal);
10137408Sgblack@eecs.umich.edu            }
10147408Sgblack@eecs.umich.edu            break;
101510037SARM gem5 Developers          case MISCREG_FPSR:
101610037SARM gem5 Developers            {
101710037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
101810037SARM gem5 Developers                FPSCR fpscrMask = 0;
101910037SARM gem5 Developers                fpscrMask.ioc = ones;
102010037SARM gem5 Developers                fpscrMask.dzc = ones;
102110037SARM gem5 Developers                fpscrMask.ofc = ones;
102210037SARM gem5 Developers                fpscrMask.ufc = ones;
102310037SARM gem5 Developers                fpscrMask.ixc = ones;
102410037SARM gem5 Developers                fpscrMask.idc = ones;
102510037SARM gem5 Developers                fpscrMask.qc = ones;
102610037SARM gem5 Developers                fpscrMask.v = ones;
102710037SARM gem5 Developers                fpscrMask.c = ones;
102810037SARM gem5 Developers                fpscrMask.z = ones;
102910037SARM gem5 Developers                fpscrMask.n = ones;
103010037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
103110037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
103210037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
103310037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
103410037SARM gem5 Developers            }
103510037SARM gem5 Developers            break;
103610037SARM gem5 Developers          case MISCREG_FPCR:
103710037SARM gem5 Developers            {
103810037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
103910037SARM gem5 Developers                FPSCR fpscrMask  = 0;
104010037SARM gem5 Developers                fpscrMask.ioe = ones;
104110037SARM gem5 Developers                fpscrMask.dze = ones;
104210037SARM gem5 Developers                fpscrMask.ofe = ones;
104310037SARM gem5 Developers                fpscrMask.ufe = ones;
104410037SARM gem5 Developers                fpscrMask.ixe = ones;
104510037SARM gem5 Developers                fpscrMask.ide = ones;
104610037SARM gem5 Developers                fpscrMask.len    = ones;
104710037SARM gem5 Developers                fpscrMask.stride = ones;
104810037SARM gem5 Developers                fpscrMask.rMode  = ones;
104910037SARM gem5 Developers                fpscrMask.fz     = ones;
105010037SARM gem5 Developers                fpscrMask.dn     = ones;
105110037SARM gem5 Developers                fpscrMask.ahp    = ones;
105210037SARM gem5 Developers                newVal = (newVal & (uint32_t)fpscrMask) |
105310037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPSCR) &
105410037SARM gem5 Developers                          ~(uint32_t)fpscrMask);
105510037SARM gem5 Developers                misc_reg = MISCREG_FPSCR;
105610037SARM gem5 Developers            }
105710037SARM gem5 Developers            break;
10588302SAli.Saidi@ARM.com          case MISCREG_CPSR_Q:
10598302SAli.Saidi@ARM.com            {
10608302SAli.Saidi@ARM.com                assert(!(newVal & ~CpsrMaskQ));
106110037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal;
10628302SAli.Saidi@ARM.com                misc_reg = MISCREG_CPSR;
10638302SAli.Saidi@ARM.com            }
10648302SAli.Saidi@ARM.com            break;
10657783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_QC:
10667783SGiacomo.Gabrielli@arm.com            {
106710037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
106810037SARM gem5 Developers                         (newVal & FpscrQcMask);
10697783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
10707783SGiacomo.Gabrielli@arm.com            }
10717783SGiacomo.Gabrielli@arm.com            break;
10727783SGiacomo.Gabrielli@arm.com          case MISCREG_FPSCR_EXC:
10737783SGiacomo.Gabrielli@arm.com            {
107410037SARM gem5 Developers                newVal = readMiscRegNoEffect(MISCREG_FPSCR) |
107510037SARM gem5 Developers                         (newVal & FpscrExcMask);
10767783SGiacomo.Gabrielli@arm.com                misc_reg = MISCREG_FPSCR;
10777783SGiacomo.Gabrielli@arm.com            }
10787783SGiacomo.Gabrielli@arm.com            break;
10797408Sgblack@eecs.umich.edu          case MISCREG_FPEXC:
10807408Sgblack@eecs.umich.edu            {
10818206SWilliam.Wang@arm.com                // vfpv3 architecture, section B.6.1 of DDI04068
10828206SWilliam.Wang@arm.com                // bit 29 - valid only if fpexc[31] is 0
10837408Sgblack@eecs.umich.edu                const uint32_t fpexcMask = 0x60000000;
10847408Sgblack@eecs.umich.edu                newVal = (newVal & fpexcMask) |
108510037SARM gem5 Developers                         (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask);
10867408Sgblack@eecs.umich.edu            }
10877408Sgblack@eecs.umich.edu            break;
108810037SARM gem5 Developers          case MISCREG_HCR:
108910037SARM gem5 Developers            {
109010037SARM gem5 Developers                if (!haveVirtualization)
109110037SARM gem5 Developers                    return;
109210037SARM gem5 Developers            }
109310037SARM gem5 Developers            break;
109410037SARM gem5 Developers          case MISCREG_IFSR:
109510037SARM gem5 Developers            {
109610037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.96
109710037SARM gem5 Developers                const uint32_t ifsrMask =
109810037SARM gem5 Developers                    mask(31, 13) | mask(11, 11) | mask(8, 6);
109910037SARM gem5 Developers                newVal = newVal & ~ifsrMask;
110010037SARM gem5 Developers            }
110110037SARM gem5 Developers            break;
110210037SARM gem5 Developers          case MISCREG_DFSR:
110310037SARM gem5 Developers            {
110410037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.52
110510037SARM gem5 Developers                const uint32_t dfsrMask = mask(31, 14) | mask(8, 8);
110610037SARM gem5 Developers                newVal = newVal & ~dfsrMask;
110710037SARM gem5 Developers            }
110810037SARM gem5 Developers            break;
110910037SARM gem5 Developers          case MISCREG_AMAIR0:
111010037SARM gem5 Developers          case MISCREG_AMAIR1:
111110037SARM gem5 Developers            {
111210037SARM gem5 Developers                // ARM ARM (ARM DDI 0406C.b) B4.1.5
111310037SARM gem5 Developers                // Valid only with LPAE
111410037SARM gem5 Developers                if (!haveLPAE)
111510037SARM gem5 Developers                    return;
111610037SARM gem5 Developers                DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal);
111710037SARM gem5 Developers            }
111810037SARM gem5 Developers            break;
111910037SARM gem5 Developers          case MISCREG_SCR:
112012406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
112112406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
112210037SARM gem5 Developers            break;
11237408Sgblack@eecs.umich.edu          case MISCREG_SCTLR:
11247408Sgblack@eecs.umich.edu            {
11257408Sgblack@eecs.umich.edu                DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal);
112610037SARM gem5 Developers                scr = readMiscRegNoEffect(MISCREG_SCR);
112711769SCurtis.Dunham@arm.com                MiscRegIndex sctlr_idx = (haveSecurity && !scr.ns)
112811769SCurtis.Dunham@arm.com                                         ? MISCREG_SCTLR_S : MISCREG_SCTLR_NS;
112910037SARM gem5 Developers                SCTLR sctlr = miscRegs[sctlr_idx];
11307408Sgblack@eecs.umich.edu                SCTLR new_sctlr = newVal;
113110037SARM gem5 Developers                new_sctlr.nmfi =  ((bool)sctlr.nmfi) && !haveVirtualization;
113210037SARM gem5 Developers                miscRegs[sctlr_idx] = (MiscReg)new_sctlr;
113312406Sgabeblack@google.com                getITBPtr(tc)->invalidateMiscReg();
113412406Sgabeblack@google.com                getDTBPtr(tc)->invalidateMiscReg();
11357408Sgblack@eecs.umich.edu            }
11369385SAndreas.Sandberg@arm.com          case MISCREG_MIDR:
11379385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR0:
11389385SAndreas.Sandberg@arm.com          case MISCREG_ID_PFR1:
113910461SAndreas.Sandberg@ARM.com          case MISCREG_ID_DFR0:
11409385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR0:
11419385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR1:
11429385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR2:
11439385SAndreas.Sandberg@arm.com          case MISCREG_ID_MMFR3:
11449385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR0:
11459385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR1:
11469385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR2:
11479385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR3:
11489385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR4:
11499385SAndreas.Sandberg@arm.com          case MISCREG_ID_ISAR5:
11509385SAndreas.Sandberg@arm.com
11519385SAndreas.Sandberg@arm.com          case MISCREG_MPIDR:
11529385SAndreas.Sandberg@arm.com          case MISCREG_FPSID:
11537408Sgblack@eecs.umich.edu          case MISCREG_TLBTR:
11547408Sgblack@eecs.umich.edu          case MISCREG_MVFR0:
11557408Sgblack@eecs.umich.edu          case MISCREG_MVFR1:
115610037SARM gem5 Developers
115710037SARM gem5 Developers          case MISCREG_ID_AA64AFR0_EL1:
115810037SARM gem5 Developers          case MISCREG_ID_AA64AFR1_EL1:
115910037SARM gem5 Developers          case MISCREG_ID_AA64DFR0_EL1:
116010037SARM gem5 Developers          case MISCREG_ID_AA64DFR1_EL1:
116110037SARM gem5 Developers          case MISCREG_ID_AA64ISAR0_EL1:
116210037SARM gem5 Developers          case MISCREG_ID_AA64ISAR1_EL1:
116310037SARM gem5 Developers          case MISCREG_ID_AA64MMFR0_EL1:
116410037SARM gem5 Developers          case MISCREG_ID_AA64MMFR1_EL1:
116510037SARM gem5 Developers          case MISCREG_ID_AA64PFR0_EL1:
116610037SARM gem5 Developers          case MISCREG_ID_AA64PFR1_EL1:
11679385SAndreas.Sandberg@arm.com            // ID registers are constants.
11687408Sgblack@eecs.umich.edu            return;
11699385SAndreas.Sandberg@arm.com
117010037SARM gem5 Developers          // TLBI all entries, EL0&1 inner sharable (ignored)
11717408Sgblack@eecs.umich.edu          case MISCREG_TLBIALLIS:
117210037SARM gem5 Developers          case MISCREG_TLBIALL: // TLBI all entries, EL0&1,
117310037SARM gem5 Developers            assert32(tc);
117410037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
117510037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
117610037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
11778284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
11788284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
11798284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
118012406Sgabeblack@google.com                getITBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
118112406Sgabeblack@google.com                getDTBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
11828887Sgeoffrey.blake@arm.com
11838887Sgeoffrey.blake@arm.com                // If CheckerCPU is connected, need to notify it of a flush
11848887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
11858733Sgeoffrey.blake@arm.com                if (checker) {
118612406Sgabeblack@google.com                    getITBPtr(checker)->flushAllSecurity(secure_lookup,
118712406Sgabeblack@google.com                                                         target_el);
118812406Sgabeblack@google.com                    getDTBPtr(checker)->flushAllSecurity(secure_lookup,
118912406Sgabeblack@google.com                                                         target_el);
11908733Sgeoffrey.blake@arm.com                }
11918284SAli.Saidi@ARM.com            }
11927408Sgblack@eecs.umich.edu            return;
119310037SARM gem5 Developers          // TLBI all entries, EL0&1, instruction side
11947408Sgblack@eecs.umich.edu          case MISCREG_ITLBIALL:
119510037SARM gem5 Developers            assert32(tc);
119610037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
119710037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
119810037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
119912406Sgabeblack@google.com            getITBPtr(tc)->flushAllSecurity(secure_lookup, target_el);
12007408Sgblack@eecs.umich.edu            return;
120110037SARM gem5 Developers          // TLBI all entries, EL0&1, data side
12027408Sgblack@eecs.umich.edu          case MISCREG_DTLBIALL:
120310037SARM gem5 Developers            assert32(tc);
120410037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
120510037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
120610037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
120712406Sgabeblack@google.com            getDTBPtr(tc)->flushAllSecurity(secure_lookup, target_el);
12087408Sgblack@eecs.umich.edu            return;
120910037SARM gem5 Developers          // TLBI based on VA, EL0&1 inner sharable (ignored)
12107408Sgblack@eecs.umich.edu          case MISCREG_TLBIMVAIS:
12117408Sgblack@eecs.umich.edu          case MISCREG_TLBIMVA:
121210037SARM gem5 Developers            assert32(tc);
121310037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
121410037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
121510037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
12168284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
12178284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
12188284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
121912406Sgabeblack@google.com                getITBPtr(oc)->flushMvaAsid(mbits(newVal, 31, 12),
122010037SARM gem5 Developers                                              bits(newVal, 7,0),
122110037SARM gem5 Developers                                              secure_lookup, target_el);
122212406Sgabeblack@google.com                getDTBPtr(oc)->flushMvaAsid(mbits(newVal, 31, 12),
122310037SARM gem5 Developers                                              bits(newVal, 7,0),
122410037SARM gem5 Developers                                              secure_lookup, target_el);
12258887Sgeoffrey.blake@arm.com
12268887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
12278733Sgeoffrey.blake@arm.com                if (checker) {
122812406Sgabeblack@google.com                    getITBPtr(checker)->flushMvaAsid(mbits(newVal, 31, 12),
122910037SARM gem5 Developers                        bits(newVal, 7,0), secure_lookup, target_el);
123012406Sgabeblack@google.com                    getDTBPtr(checker)->flushMvaAsid(mbits(newVal, 31, 12),
123110037SARM gem5 Developers                        bits(newVal, 7,0), secure_lookup, target_el);
12328733Sgeoffrey.blake@arm.com                }
12338284SAli.Saidi@ARM.com            }
12347408Sgblack@eecs.umich.edu            return;
123510037SARM gem5 Developers          // TLBI by ASID, EL0&1, inner sharable
12367408Sgblack@eecs.umich.edu          case MISCREG_TLBIASIDIS:
12377408Sgblack@eecs.umich.edu          case MISCREG_TLBIASID:
123810037SARM gem5 Developers            assert32(tc);
123910037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
124010037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
124110037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
12428284SAli.Saidi@ARM.com            sys = tc->getSystemPtr();
12438284SAli.Saidi@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
12448284SAli.Saidi@ARM.com                oc = sys->getThreadContext(x);
124512406Sgabeblack@google.com                getITBPtr(oc)->flushAsid(bits(newVal, 7,0),
124610037SARM gem5 Developers                    secure_lookup, target_el);
124712406Sgabeblack@google.com                getDTBPtr(oc)->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) {
125112406Sgabeblack@google.com                    getITBPtr(checker)->flushAsid(bits(newVal, 7,0),
125210037SARM gem5 Developers                        secure_lookup, target_el);
125312406Sgabeblack@google.com                    getDTBPtr(checker)->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;
128412406Sgabeblack@google.com            getITBPtr(tc)->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;
129312406Sgabeblack@google.com            getDTBPtr(tc)->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;
130212406Sgabeblack@google.com            getITBPtr(tc)->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;
131112406Sgabeblack@google.com            getDTBPtr(tc)->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);
140910037SARM gem5 Developers                asid = bits(newVal, 63, 48);
141010709SAndreas.Sandberg@ARM.com                if (!haveLargeAsid64)
141110037SARM gem5 Developers                    asid &= mask(8);
141212406Sgabeblack@google.com                getITBPtr(oc)->flushAsid(asid, secure_lookup, target_el);
141312406Sgabeblack@google.com                getDTBPtr(oc)->flushAsid(asid, secure_lookup, target_el);
141410037SARM gem5 Developers                CheckerCPU *checker = oc->getCheckerCpuPtr();
141510037SARM gem5 Developers                if (checker) {
141612406Sgabeblack@google.com                    getITBPtr(checker)->flushAsid(asid,
141710037SARM gem5 Developers                        secure_lookup, target_el);
141812406Sgabeblack@google.com                    getDTBPtr(checker)->flushAsid(asid,
141910037SARM gem5 Developers                        secure_lookup, target_el);
142010037SARM gem5 Developers                }
142110037SARM gem5 Developers            }
142210037SARM gem5 Developers            return;
142310037SARM gem5 Developers          // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID
142410037SARM gem5 Developers          // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store
142510037SARM gem5 Developers          // entries from the last level of translation table walks
142610037SARM gem5 Developers          // @todo: handle VMID to enable Virtualization
142710037SARM gem5 Developers          case MISCREG_TLBI_VAAE1IS_Xt:
142810037SARM gem5 Developers          case MISCREG_TLBI_VAAE1_Xt:
142910037SARM gem5 Developers          case MISCREG_TLBI_VAALE1IS_Xt:
143010037SARM gem5 Developers          case MISCREG_TLBI_VAALE1_Xt:
143110037SARM gem5 Developers            assert64(tc);
143210037SARM gem5 Developers            target_el = 1; // el 0 and 1 are handled together
143310037SARM gem5 Developers            scr = readMiscReg(MISCREG_SCR, tc);
143410037SARM gem5 Developers            secure_lookup = haveSecurity && !scr.ns;
143510037SARM gem5 Developers            sys = tc->getSystemPtr();
143610037SARM gem5 Developers            for (x = 0; x < sys->numContexts(); x++) {
143710037SARM gem5 Developers                // @todo: extra controls on TLBI broadcast?
143810037SARM gem5 Developers                oc = sys->getThreadContext(x);
143910037SARM gem5 Developers                Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
144012406Sgabeblack@google.com                getITBPtr(oc)->flushMva(va,
144110037SARM gem5 Developers                    secure_lookup, false, target_el);
144212406Sgabeblack@google.com                getDTBPtr(oc)->flushMva(va,
144310037SARM gem5 Developers                    secure_lookup, false, target_el);
14448887Sgeoffrey.blake@arm.com
14458887Sgeoffrey.blake@arm.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
14468733Sgeoffrey.blake@arm.com                if (checker) {
144712406Sgabeblack@google.com                    getITBPtr(checker)->flushMva(va,
144810037SARM gem5 Developers                        secure_lookup, false, target_el);
144912406Sgabeblack@google.com                    getDTBPtr(checker)->flushMva(va,
145010037SARM gem5 Developers                        secure_lookup, false, target_el);
14518733Sgeoffrey.blake@arm.com                }
14528284SAli.Saidi@ARM.com            }
14537408Sgblack@eecs.umich.edu            return;
145410037SARM gem5 Developers          // AArch64 TLBI: invalidate by IPA, stage 2, current VMID
145510037SARM gem5 Developers          case MISCREG_TLBI_IPAS2LE1IS_Xt:
145610037SARM gem5 Developers          case MISCREG_TLBI_IPAS2LE1_Xt:
145710037SARM gem5 Developers          case MISCREG_TLBI_IPAS2E1IS_Xt:
145810037SARM gem5 Developers          case MISCREG_TLBI_IPAS2E1_Xt:
145910037SARM gem5 Developers            assert64(tc);
146011584SDylan.Johnson@ARM.com            target_el = 1; // EL 0 and 1 are handled together
146111584SDylan.Johnson@ARM.com            scr = readMiscReg(MISCREG_SCR, tc);
146211584SDylan.Johnson@ARM.com            secure_lookup = haveSecurity && !scr.ns;
146311584SDylan.Johnson@ARM.com            sys = tc->getSystemPtr();
146411584SDylan.Johnson@ARM.com            for (x = 0; x < sys->numContexts(); x++) {
146511584SDylan.Johnson@ARM.com                oc = sys->getThreadContext(x);
146611584SDylan.Johnson@ARM.com                Addr ipa = ((Addr) bits(newVal, 35, 0)) << 12;
146712406Sgabeblack@google.com                getITBPtr(oc)->flushIpaVmid(ipa,
146811584SDylan.Johnson@ARM.com                    secure_lookup, false, target_el);
146912406Sgabeblack@google.com                getDTBPtr(oc)->flushIpaVmid(ipa,
147011584SDylan.Johnson@ARM.com                    secure_lookup, false, target_el);
147111584SDylan.Johnson@ARM.com
147211584SDylan.Johnson@ARM.com                CheckerCPU *checker = oc->getCheckerCpuPtr();
147311584SDylan.Johnson@ARM.com                if (checker) {
147412406Sgabeblack@google.com                    getITBPtr(checker)->flushIpaVmid(ipa,
147511584SDylan.Johnson@ARM.com                        secure_lookup, false, target_el);
147612406Sgabeblack@google.com                    getDTBPtr(checker)->flushIpaVmid(ipa,
147711584SDylan.Johnson@ARM.com                        secure_lookup, false, target_el);
147811584SDylan.Johnson@ARM.com                }
147911584SDylan.Johnson@ARM.com            }
14807405SAli.Saidi@ARM.com            return;
14817583SAli.Saidi@arm.com          case MISCREG_ACTLR:
14827583SAli.Saidi@arm.com            warn("Not doing anything for write of miscreg ACTLR\n");
14837583SAli.Saidi@arm.com            break;
148410461SAndreas.Sandberg@ARM.com
148510461SAndreas.Sandberg@ARM.com          case MISCREG_PMXEVTYPER_PMCCFILTR:
148610461SAndreas.Sandberg@ARM.com          case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0:
148710461SAndreas.Sandberg@ARM.com          case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0:
148810461SAndreas.Sandberg@ARM.com          case MISCREG_PMCR ... MISCREG_PMOVSSET:
148910461SAndreas.Sandberg@ARM.com            pmu->setMiscReg(misc_reg, newVal);
14907583SAli.Saidi@arm.com            break;
149110461SAndreas.Sandberg@ARM.com
149210461SAndreas.Sandberg@ARM.com
149310037SARM gem5 Developers          case MISCREG_HSTR: // TJDBX, now redifined to be RES0
149410037SARM gem5 Developers            {
149510037SARM gem5 Developers                HSTR hstrMask = 0;
149610037SARM gem5 Developers                hstrMask.tjdbx = 1;
149710037SARM gem5 Developers                newVal &= ~((uint32_t) hstrMask);
149810037SARM gem5 Developers                break;
149910037SARM gem5 Developers            }
150010037SARM gem5 Developers          case MISCREG_HCPTR:
150110037SARM gem5 Developers            {
150210037SARM gem5 Developers                // If a CP bit in NSACR is 0 then the corresponding bit in
150310037SARM gem5 Developers                // HCPTR is RAO/WI. Same applies to NSASEDIS
150410037SARM gem5 Developers                secure_lookup = haveSecurity &&
150510037SARM gem5 Developers                    inSecureState(readMiscRegNoEffect(MISCREG_SCR),
150610037SARM gem5 Developers                                  readMiscRegNoEffect(MISCREG_CPSR));
150710037SARM gem5 Developers                if (!secure_lookup) {
150810037SARM gem5 Developers                    MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR);
150910037SARM gem5 Developers                    MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF;
151010037SARM gem5 Developers                    newVal = (newVal & ~mask) | (oldValue & mask);
151110037SARM gem5 Developers                }
151210037SARM gem5 Developers                break;
151310037SARM gem5 Developers            }
151410037SARM gem5 Developers          case MISCREG_HDFAR: // alias for secure DFAR
151510037SARM gem5 Developers            misc_reg = MISCREG_DFAR_S;
151610037SARM gem5 Developers            break;
151710037SARM gem5 Developers          case MISCREG_HIFAR: // alias for secure IFAR
151810037SARM gem5 Developers            misc_reg = MISCREG_IFAR_S;
151910037SARM gem5 Developers            break;
152010037SARM gem5 Developers          case MISCREG_ATS1CPR:
152110037SARM gem5 Developers          case MISCREG_ATS1CPW:
152210037SARM gem5 Developers          case MISCREG_ATS1CUR:
152310037SARM gem5 Developers          case MISCREG_ATS1CUW:
152410037SARM gem5 Developers          case MISCREG_ATS12NSOPR:
152510037SARM gem5 Developers          case MISCREG_ATS12NSOPW:
152610037SARM gem5 Developers          case MISCREG_ATS12NSOUR:
152710037SARM gem5 Developers          case MISCREG_ATS12NSOUW:
152810037SARM gem5 Developers          case MISCREG_ATS1HR:
152910037SARM gem5 Developers          case MISCREG_ATS1HW:
15307436Sdam.sunwoo@arm.com            {
153111608Snikos.nikoleris@arm.com              Request::Flags flags = 0;
153210037SARM gem5 Developers              BaseTLB::Mode mode = BaseTLB::Read;
153310037SARM gem5 Developers              TLB::ArmTranslationType tranType = TLB::NormalTran;
15347436Sdam.sunwoo@arm.com              Fault fault;
15357436Sdam.sunwoo@arm.com              switch(misc_reg) {
153610037SARM gem5 Developers                case MISCREG_ATS1CPR:
153710037SARM gem5 Developers                  flags    = TLB::MustBeOne;
153810037SARM gem5 Developers                  tranType = TLB::S1CTran;
153910037SARM gem5 Developers                  mode     = BaseTLB::Read;
154010037SARM gem5 Developers                  break;
154110037SARM gem5 Developers                case MISCREG_ATS1CPW:
154210037SARM gem5 Developers                  flags    = TLB::MustBeOne;
154310037SARM gem5 Developers                  tranType = TLB::S1CTran;
154410037SARM gem5 Developers                  mode     = BaseTLB::Write;
154510037SARM gem5 Developers                  break;
154610037SARM gem5 Developers                case MISCREG_ATS1CUR:
154710037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
154810037SARM gem5 Developers                  tranType = TLB::S1CTran;
154910037SARM gem5 Developers                  mode     = BaseTLB::Read;
155010037SARM gem5 Developers                  break;
155110037SARM gem5 Developers                case MISCREG_ATS1CUW:
155210037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
155310037SARM gem5 Developers                  tranType = TLB::S1CTran;
155410037SARM gem5 Developers                  mode     = BaseTLB::Write;
155510037SARM gem5 Developers                  break;
155610037SARM gem5 Developers                case MISCREG_ATS12NSOPR:
155710037SARM gem5 Developers                  if (!haveSecurity)
155810037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPR");
155910037SARM gem5 Developers                  flags    = TLB::MustBeOne;
156010037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
156110037SARM gem5 Developers                  mode     = BaseTLB::Read;
156210037SARM gem5 Developers                  break;
156310037SARM gem5 Developers                case MISCREG_ATS12NSOPW:
156410037SARM gem5 Developers                  if (!haveSecurity)
156510037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOPW");
156610037SARM gem5 Developers                  flags    = TLB::MustBeOne;
156710037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
156810037SARM gem5 Developers                  mode     = BaseTLB::Write;
156910037SARM gem5 Developers                  break;
157010037SARM gem5 Developers                case MISCREG_ATS12NSOUR:
157110037SARM gem5 Developers                  if (!haveSecurity)
157210037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUR");
157310037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
157410037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
157510037SARM gem5 Developers                  mode     = BaseTLB::Read;
157610037SARM gem5 Developers                  break;
157710037SARM gem5 Developers                case MISCREG_ATS12NSOUW:
157810037SARM gem5 Developers                  if (!haveSecurity)
157910037SARM gem5 Developers                      panic("Security Extensions required for ATS12NSOUW");
158010037SARM gem5 Developers                  flags    = TLB::MustBeOne | TLB::UserMode;
158110037SARM gem5 Developers                  tranType = TLB::S1S2NsTran;
158210037SARM gem5 Developers                  mode     = BaseTLB::Write;
158310037SARM gem5 Developers                  break;
158410037SARM gem5 Developers                case MISCREG_ATS1HR: // only really useful from secure mode.
158510037SARM gem5 Developers                  flags    = TLB::MustBeOne;
158610037SARM gem5 Developers                  tranType = TLB::HypMode;
158710037SARM gem5 Developers                  mode     = BaseTLB::Read;
158810037SARM gem5 Developers                  break;
158910037SARM gem5 Developers                case MISCREG_ATS1HW:
159010037SARM gem5 Developers                  flags    = TLB::MustBeOne;
159110037SARM gem5 Developers                  tranType = TLB::HypMode;
159210037SARM gem5 Developers                  mode     = BaseTLB::Write;
159310037SARM gem5 Developers                  break;
15947436Sdam.sunwoo@arm.com              }
159510037SARM gem5 Developers              // If we're in timing mode then doing the translation in
159610037SARM gem5 Developers              // functional mode then we're slightly distorting performance
159710037SARM gem5 Developers              // results obtained from simulations. The translation should be
159810037SARM gem5 Developers              // done in the same mode the core is running in. NOTE: This
159910037SARM gem5 Developers              // can't be an atomic translation because that causes problems
160010037SARM gem5 Developers              // with unexpected atomic snoop requests.
160110037SARM gem5 Developers              warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
160211560Sandreas.sandberg@arm.com              Request req(0, val, 0, flags,  Request::funcMasterId,
160311435Smitch.hayenga@arm.com                          tc->pcState().pc(), tc->contextId());
160412406Sgabeblack@google.com              fault = getDTBPtr(tc)->translateFunctional(
160512406Sgabeblack@google.com                      &req, tc, mode, tranType);
160610037SARM gem5 Developers              TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
160710037SARM gem5 Developers              HCR   hcr   = readMiscRegNoEffect(MISCREG_HCR);
160810037SARM gem5 Developers
160910037SARM gem5 Developers              MiscReg newVal;
16107436Sdam.sunwoo@arm.com              if (fault == NoFault) {
161110653Sandreas.hansson@arm.com                  Addr paddr = req.getPaddr();
161210037SARM gem5 Developers                  if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode ||
161310037SARM gem5 Developers                     ((tranType & TLB::S1S2NsTran) && hcr.vm) )) {
161410037SARM gem5 Developers                      newVal = (paddr & mask(39, 12)) |
161512406Sgabeblack@google.com                               (getDTBPtr(tc)->getAttr());
161610037SARM gem5 Developers                  } else {
161710037SARM gem5 Developers                      newVal = (paddr & 0xfffff000) |
161812406Sgabeblack@google.com                               (getDTBPtr(tc)->getAttr());
161910037SARM gem5 Developers                  }
16207436Sdam.sunwoo@arm.com                  DPRINTF(MiscRegs,
16217436Sdam.sunwoo@arm.com                          "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n",
162210037SARM gem5 Developers                          val, newVal);
162310037SARM gem5 Developers              } else {
162410037SARM gem5 Developers                  ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get());
162510037SARM gem5 Developers                  // Set fault bit and FSR
162610037SARM gem5 Developers                  FSR fsr = armFault->getFsr(tc);
162710037SARM gem5 Developers
162810037SARM gem5 Developers                  newVal = ((fsr >> 9) & 1) << 11;
162910037SARM gem5 Developers                  if (newVal) {
163010037SARM gem5 Developers                    // LPAE - rearange fault status
163110037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0x3f) << 1;
163210037SARM gem5 Developers                  } else {
163310037SARM gem5 Developers                    // VMSA - rearange fault status
163410037SARM gem5 Developers                    newVal |= ((fsr >>  0) & 0xf) << 1;
163510037SARM gem5 Developers                    newVal |= ((fsr >> 10) & 0x1) << 5;
163610037SARM gem5 Developers                    newVal |= ((fsr >> 12) & 0x1) << 6;
163710037SARM gem5 Developers                  }
163810037SARM gem5 Developers                  newVal |= 0x1; // F bit
163910037SARM gem5 Developers                  newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
164010037SARM gem5 Developers                  newVal |= armFault->isStage2() ? 0x200 : 0;
164110037SARM gem5 Developers                  DPRINTF(MiscRegs,
164210037SARM gem5 Developers                          "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n",
164310037SARM gem5 Developers                          val, fsr, newVal);
16447436Sdam.sunwoo@arm.com              }
164510037SARM gem5 Developers              setMiscRegNoEffect(MISCREG_PAR, newVal);
16467436Sdam.sunwoo@arm.com              return;
16477436Sdam.sunwoo@arm.com            }
164810037SARM gem5 Developers          case MISCREG_TTBCR:
164910037SARM gem5 Developers            {
165010037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
165110037SARM gem5 Developers                const uint32_t ones = (uint32_t)(-1);
165210037SARM gem5 Developers                TTBCR ttbcrMask = 0;
165310037SARM gem5 Developers                TTBCR ttbcrNew = newVal;
165410037SARM gem5 Developers
165510037SARM gem5 Developers                // ARM DDI 0406C.b, ARMv7-32
165610037SARM gem5 Developers                ttbcrMask.n = ones; // T0SZ
165710037SARM gem5 Developers                if (haveSecurity) {
165810037SARM gem5 Developers                    ttbcrMask.pd0 = ones;
165910037SARM gem5 Developers                    ttbcrMask.pd1 = ones;
166010037SARM gem5 Developers                }
166110037SARM gem5 Developers                ttbcrMask.epd0 = ones;
166210037SARM gem5 Developers                ttbcrMask.irgn0 = ones;
166310037SARM gem5 Developers                ttbcrMask.orgn0 = ones;
166410037SARM gem5 Developers                ttbcrMask.sh0 = ones;
166510037SARM gem5 Developers                ttbcrMask.ps = ones; // T1SZ
166610037SARM gem5 Developers                ttbcrMask.a1 = ones;
166710037SARM gem5 Developers                ttbcrMask.epd1 = ones;
166810037SARM gem5 Developers                ttbcrMask.irgn1 = ones;
166910037SARM gem5 Developers                ttbcrMask.orgn1 = ones;
167010037SARM gem5 Developers                ttbcrMask.sh1 = ones;
167110037SARM gem5 Developers                if (haveLPAE)
167210037SARM gem5 Developers                    ttbcrMask.eae = ones;
167310037SARM gem5 Developers
167410037SARM gem5 Developers                if (haveLPAE && ttbcrNew.eae) {
167510037SARM gem5 Developers                    newVal = newVal & ttbcrMask;
167610037SARM gem5 Developers                } else {
167710037SARM gem5 Developers                    newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask));
167810037SARM gem5 Developers                }
167910037SARM gem5 Developers            }
168012392Sjason@lowepower.com            M5_FALLTHROUGH;
168110037SARM gem5 Developers          case MISCREG_TTBR0:
168210037SARM gem5 Developers          case MISCREG_TTBR1:
168310037SARM gem5 Developers            {
168410037SARM gem5 Developers                TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
168510037SARM gem5 Developers                if (haveLPAE) {
168610037SARM gem5 Developers                    if (ttbcr.eae) {
168710037SARM gem5 Developers                        // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP
168810037SARM gem5 Developers                        // ARMv8 AArch32 bit 63-56 only
168910037SARM gem5 Developers                        uint64_t ttbrMask = mask(63,56) | mask(47,40);
169010037SARM gem5 Developers                        newVal = (newVal & (~ttbrMask));
169110037SARM gem5 Developers                    }
169210037SARM gem5 Developers                }
169310037SARM gem5 Developers            }
169412392Sjason@lowepower.com            M5_FALLTHROUGH;
169510508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL1:
169610508SAli.Saidi@ARM.com            {
169712406Sgabeblack@google.com                getITBPtr(tc)->invalidateMiscReg();
169812406Sgabeblack@google.com                getDTBPtr(tc)->invalidateMiscReg();
169910508SAli.Saidi@ARM.com                setMiscRegNoEffect(misc_reg, newVal);
170010508SAli.Saidi@ARM.com            }
170112392Sjason@lowepower.com            M5_FALLTHROUGH;
17027749SAli.Saidi@ARM.com          case MISCREG_CONTEXTIDR:
17037749SAli.Saidi@ARM.com          case MISCREG_PRRR:
17047749SAli.Saidi@ARM.com          case MISCREG_NMRR:
170510037SARM gem5 Developers          case MISCREG_MAIR0:
170610037SARM gem5 Developers          case MISCREG_MAIR1:
17077749SAli.Saidi@ARM.com          case MISCREG_DACR:
170810037SARM gem5 Developers          case MISCREG_VTTBR:
170910037SARM gem5 Developers          case MISCREG_SCR_EL3:
171011575SDylan.Johnson@ARM.com          case MISCREG_HCR_EL2:
171110037SARM gem5 Developers          case MISCREG_TCR_EL1:
171210037SARM gem5 Developers          case MISCREG_TCR_EL2:
171310037SARM gem5 Developers          case MISCREG_TCR_EL3:
171410508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL2:
171510508SAli.Saidi@ARM.com          case MISCREG_SCTLR_EL3:
171611573SDylan.Johnson@ARM.com          case MISCREG_HSCTLR:
171710037SARM gem5 Developers          case MISCREG_TTBR0_EL1:
171810037SARM gem5 Developers          case MISCREG_TTBR1_EL1:
171910037SARM gem5 Developers          case MISCREG_TTBR0_EL2:
172010037SARM gem5 Developers          case MISCREG_TTBR0_EL3:
172112406Sgabeblack@google.com            getITBPtr(tc)->invalidateMiscReg();
172212406Sgabeblack@google.com            getDTBPtr(tc)->invalidateMiscReg();
17237749SAli.Saidi@ARM.com            break;
172410037SARM gem5 Developers          case MISCREG_NZCV:
172510037SARM gem5 Developers            {
172610037SARM gem5 Developers                CPSR cpsr = val;
172710037SARM gem5 Developers
172810338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_NZ, cpsr.nz);
172910338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_C,  cpsr.c);
173010338SCurtis.Dunham@arm.com                tc->setCCReg(CCREG_V,  cpsr.v);
173110037SARM gem5 Developers            }
173210037SARM gem5 Developers            break;
173310037SARM gem5 Developers          case MISCREG_DAIF:
173410037SARM gem5 Developers            {
173510037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
173610037SARM gem5 Developers                cpsr.daif = (uint8_t) ((CPSR) newVal).daif;
173710037SARM gem5 Developers                newVal = cpsr;
173810037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
173910037SARM gem5 Developers            }
174010037SARM gem5 Developers            break;
174110037SARM gem5 Developers          case MISCREG_SP_EL0:
174210037SARM gem5 Developers            tc->setIntReg(INTREG_SP0, newVal);
174310037SARM gem5 Developers            break;
174410037SARM gem5 Developers          case MISCREG_SP_EL1:
174510037SARM gem5 Developers            tc->setIntReg(INTREG_SP1, newVal);
174610037SARM gem5 Developers            break;
174710037SARM gem5 Developers          case MISCREG_SP_EL2:
174810037SARM gem5 Developers            tc->setIntReg(INTREG_SP2, newVal);
174910037SARM gem5 Developers            break;
175010037SARM gem5 Developers          case MISCREG_SPSEL:
175110037SARM gem5 Developers            {
175210037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
175310037SARM gem5 Developers                cpsr.sp = (uint8_t) ((CPSR) newVal).sp;
175410037SARM gem5 Developers                newVal = cpsr;
175510037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
175610037SARM gem5 Developers            }
175710037SARM gem5 Developers            break;
175810037SARM gem5 Developers          case MISCREG_CURRENTEL:
175910037SARM gem5 Developers            {
176010037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
176110037SARM gem5 Developers                cpsr.el = (uint8_t) ((CPSR) newVal).el;
176210037SARM gem5 Developers                newVal = cpsr;
176310037SARM gem5 Developers                misc_reg = MISCREG_CPSR;
176410037SARM gem5 Developers            }
176510037SARM gem5 Developers            break;
176610037SARM gem5 Developers          case MISCREG_AT_S1E1R_Xt:
176710037SARM gem5 Developers          case MISCREG_AT_S1E1W_Xt:
176810037SARM gem5 Developers          case MISCREG_AT_S1E0R_Xt:
176910037SARM gem5 Developers          case MISCREG_AT_S1E0W_Xt:
177010037SARM gem5 Developers          case MISCREG_AT_S1E2R_Xt:
177110037SARM gem5 Developers          case MISCREG_AT_S1E2W_Xt:
177210037SARM gem5 Developers          case MISCREG_AT_S12E1R_Xt:
177310037SARM gem5 Developers          case MISCREG_AT_S12E1W_Xt:
177410037SARM gem5 Developers          case MISCREG_AT_S12E0R_Xt:
177510037SARM gem5 Developers          case MISCREG_AT_S12E0W_Xt:
177610037SARM gem5 Developers          case MISCREG_AT_S1E3R_Xt:
177710037SARM gem5 Developers          case MISCREG_AT_S1E3W_Xt:
177810037SARM gem5 Developers            {
177910037SARM gem5 Developers                RequestPtr req = new Request;
178011608Snikos.nikoleris@arm.com                Request::Flags flags = 0;
178110037SARM gem5 Developers                BaseTLB::Mode mode = BaseTLB::Read;
178210037SARM gem5 Developers                TLB::ArmTranslationType tranType = TLB::NormalTran;
178310037SARM gem5 Developers                Fault fault;
178410037SARM gem5 Developers                switch(misc_reg) {
178510037SARM gem5 Developers                  case MISCREG_AT_S1E1R_Xt:
178610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
178711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
178810037SARM gem5 Developers                    mode     = BaseTLB::Read;
178910037SARM gem5 Developers                    break;
179010037SARM gem5 Developers                  case MISCREG_AT_S1E1W_Xt:
179110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
179211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E1Tran;
179310037SARM gem5 Developers                    mode     = BaseTLB::Write;
179410037SARM gem5 Developers                    break;
179510037SARM gem5 Developers                  case MISCREG_AT_S1E0R_Xt:
179610037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
179711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
179810037SARM gem5 Developers                    mode     = BaseTLB::Read;
179910037SARM gem5 Developers                    break;
180010037SARM gem5 Developers                  case MISCREG_AT_S1E0W_Xt:
180110037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
180211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E0Tran;
180310037SARM gem5 Developers                    mode     = BaseTLB::Write;
180410037SARM gem5 Developers                    break;
180510037SARM gem5 Developers                  case MISCREG_AT_S1E2R_Xt:
180610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
180711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
180810037SARM gem5 Developers                    mode     = BaseTLB::Read;
180910037SARM gem5 Developers                    break;
181010037SARM gem5 Developers                  case MISCREG_AT_S1E2W_Xt:
181110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
181211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E2Tran;
181310037SARM gem5 Developers                    mode     = BaseTLB::Write;
181410037SARM gem5 Developers                    break;
181510037SARM gem5 Developers                  case MISCREG_AT_S12E0R_Xt:
181610037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
181711577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
181810037SARM gem5 Developers                    mode     = BaseTLB::Read;
181910037SARM gem5 Developers                    break;
182010037SARM gem5 Developers                  case MISCREG_AT_S12E0W_Xt:
182110037SARM gem5 Developers                    flags    = TLB::MustBeOne | TLB::UserMode;
182211577SDylan.Johnson@ARM.com                    tranType = TLB::S12E0Tran;
182310037SARM gem5 Developers                    mode     = BaseTLB::Write;
182410037SARM gem5 Developers                    break;
182510037SARM gem5 Developers                  case MISCREG_AT_S12E1R_Xt:
182610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
182711577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
182810037SARM gem5 Developers                    mode     = BaseTLB::Read;
182910037SARM gem5 Developers                    break;
183010037SARM gem5 Developers                  case MISCREG_AT_S12E1W_Xt:
183110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
183211577SDylan.Johnson@ARM.com                    tranType = TLB::S12E1Tran;
183310037SARM gem5 Developers                    mode     = BaseTLB::Write;
183410037SARM gem5 Developers                    break;
183510037SARM gem5 Developers                  case MISCREG_AT_S1E3R_Xt:
183610037SARM gem5 Developers                    flags    = TLB::MustBeOne;
183711577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
183810037SARM gem5 Developers                    mode     = BaseTLB::Read;
183910037SARM gem5 Developers                    break;
184010037SARM gem5 Developers                  case MISCREG_AT_S1E3W_Xt:
184110037SARM gem5 Developers                    flags    = TLB::MustBeOne;
184211577SDylan.Johnson@ARM.com                    tranType = TLB::S1E3Tran;
184310037SARM gem5 Developers                    mode     = BaseTLB::Write;
184410037SARM gem5 Developers                    break;
184510037SARM gem5 Developers                }
184610037SARM gem5 Developers                // If we're in timing mode then doing the translation in
184710037SARM gem5 Developers                // functional mode then we're slightly distorting performance
184810037SARM gem5 Developers                // results obtained from simulations. The translation should be
184910037SARM gem5 Developers                // done in the same mode the core is running in. NOTE: This
185010037SARM gem5 Developers                // can't be an atomic translation because that causes problems
185110037SARM gem5 Developers                // with unexpected atomic snoop requests.
185210037SARM gem5 Developers                warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg);
185311560Sandreas.sandberg@arm.com                req->setVirt(0, val, 0, flags,  Request::funcMasterId,
185410037SARM gem5 Developers                               tc->pcState().pc());
185511435Smitch.hayenga@arm.com                req->setContext(tc->contextId());
185612406Sgabeblack@google.com                fault = getDTBPtr(tc)->translateFunctional(req, tc, mode,
185712406Sgabeblack@google.com                                                           tranType);
185810037SARM gem5 Developers
185910037SARM gem5 Developers                MiscReg newVal;
186010037SARM gem5 Developers                if (fault == NoFault) {
186110037SARM gem5 Developers                    Addr paddr = req->getPaddr();
186212406Sgabeblack@google.com                    uint64_t attr = getDTBPtr(tc)->getAttr();
186310037SARM gem5 Developers                    uint64_t attr1 = attr >> 56;
186410037SARM gem5 Developers                    if (!attr1 || attr1 ==0x44) {
186510037SARM gem5 Developers                        attr |= 0x100;
186610037SARM gem5 Developers                        attr &= ~ uint64_t(0x80);
186710037SARM gem5 Developers                    }
186810037SARM gem5 Developers                    newVal = (paddr & mask(47, 12)) | attr;
186910037SARM gem5 Developers                    DPRINTF(MiscRegs,
187010037SARM gem5 Developers                          "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n",
187110037SARM gem5 Developers                          val, newVal);
187210037SARM gem5 Developers                } else {
187310037SARM gem5 Developers                    ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get());
187410037SARM gem5 Developers                    // Set fault bit and FSR
187510037SARM gem5 Developers                    FSR fsr = armFault->getFsr(tc);
187610037SARM gem5 Developers
187711577SDylan.Johnson@ARM.com                    CPSR cpsr = tc->readMiscReg(MISCREG_CPSR);
187811577SDylan.Johnson@ARM.com                    if (cpsr.width) { // AArch32
187911577SDylan.Johnson@ARM.com                        newVal = ((fsr >> 9) & 1) << 11;
188011577SDylan.Johnson@ARM.com                        // rearrange fault status
188111577SDylan.Johnson@ARM.com                        newVal |= ((fsr >>  0) & 0x3f) << 1;
188211577SDylan.Johnson@ARM.com                        newVal |= 0x1; // F bit
188311577SDylan.Johnson@ARM.com                        newVal |= ((armFault->iss() >> 7) & 0x1) << 8;
188411577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 0x200 : 0;
188511577SDylan.Johnson@ARM.com                    } else { // AArch64
188611577SDylan.Johnson@ARM.com                        newVal = 1; // F bit
188711577SDylan.Johnson@ARM.com                        newVal |= fsr << 1; // FST
188811577SDylan.Johnson@ARM.com                        // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit.
188911577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW
189011577SDylan.Johnson@ARM.com                        newVal |= armFault->isStage2() ? 1 << 9 : 0; // S
189111577SDylan.Johnson@ARM.com                        newVal |= 1 << 11; // RES1
189211577SDylan.Johnson@ARM.com                    }
189310037SARM gem5 Developers                    DPRINTF(MiscRegs,
189410037SARM gem5 Developers                            "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n",
189510037SARM gem5 Developers                            val, fsr, newVal);
189610037SARM gem5 Developers                }
189710037SARM gem5 Developers                delete req;
189810037SARM gem5 Developers                setMiscRegNoEffect(MISCREG_PAR_EL1, newVal);
189910037SARM gem5 Developers                return;
190010037SARM gem5 Developers            }
190110037SARM gem5 Developers          case MISCREG_SPSR_EL3:
190210037SARM gem5 Developers          case MISCREG_SPSR_EL2:
190310037SARM gem5 Developers          case MISCREG_SPSR_EL1:
190410037SARM gem5 Developers            // Force bits 23:21 to 0
190510037SARM gem5 Developers            newVal = val & ~(0x7 << 21);
190610037SARM gem5 Developers            break;
19078549Sdaniel.johnson@arm.com          case MISCREG_L2CTLR:
19088549Sdaniel.johnson@arm.com            warn("miscreg L2CTLR (%s) written with %#x. ignored...\n",
19098549Sdaniel.johnson@arm.com                 miscRegName[misc_reg], uint32_t(val));
191010037SARM gem5 Developers            break;
191110037SARM gem5 Developers
191210037SARM gem5 Developers          // Generic Timer registers
191310844Sandreas.sandberg@arm.com          case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL:
191410844Sandreas.sandberg@arm.com          case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL:
191510844Sandreas.sandberg@arm.com          case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0:
191610844Sandreas.sandberg@arm.com          case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1:
191710844Sandreas.sandberg@arm.com            getGenericTimer(tc).setMiscReg(misc_reg, newVal);
191810037SARM gem5 Developers            break;
19197405SAli.Saidi@ARM.com        }
19207405SAli.Saidi@ARM.com    }
19217405SAli.Saidi@ARM.com    setMiscRegNoEffect(misc_reg, newVal);
19227405SAli.Saidi@ARM.com}
19237405SAli.Saidi@ARM.com
192410037SARM gem5 Developersvoid
192510709SAndreas.Sandberg@ARM.comISA::tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid,
192610709SAndreas.Sandberg@ARM.com            bool secure_lookup, uint8_t target_el)
192710037SARM gem5 Developers{
192810709SAndreas.Sandberg@ARM.com    if (!haveLargeAsid64)
192910037SARM gem5 Developers        asid &= mask(8);
193010037SARM gem5 Developers    Addr va = ((Addr) bits(newVal, 43, 0)) << 12;
193110037SARM gem5 Developers    System *sys = tc->getSystemPtr();
193210037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
193310037SARM gem5 Developers        ThreadContext *oc = sys->getThreadContext(x);
193412406Sgabeblack@google.com        getITBPtr(oc)->flushMvaAsid(va, asid,
193510037SARM gem5 Developers                                      secure_lookup, target_el);
193612406Sgabeblack@google.com        getDTBPtr(oc)->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) {
194112406Sgabeblack@google.com            getITBPtr(checker)->flushMvaAsid(
194210037SARM gem5 Developers                va, asid, secure_lookup, target_el);
194312406Sgabeblack@google.com            getDTBPtr(checker)->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);
195512406Sgabeblack@google.com        getITBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
195612406Sgabeblack@google.com        getDTBPtr(oc)->flushAllSecurity(secure_lookup, target_el);
195710037SARM gem5 Developers
195810037SARM gem5 Developers        // If CheckerCPU is connected, need to notify it of a flush
195910037SARM gem5 Developers        CheckerCPU *checker = oc->getCheckerCpuPtr();
196010037SARM gem5 Developers        if (checker) {
196112406Sgabeblack@google.com            getITBPtr(checker)->flushAllSecurity(secure_lookup,
196210037SARM gem5 Developers                                                   target_el);
196312406Sgabeblack@google.com            getDTBPtr(checker)->flushAllSecurity(secure_lookup,
196410037SARM gem5 Developers                                                   target_el);
196510037SARM gem5 Developers        }
196610037SARM gem5 Developers    }
196710037SARM gem5 Developers}
196810037SARM gem5 Developers
196910037SARM gem5 Developersvoid
197010037SARM gem5 DevelopersISA::tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el)
197110037SARM gem5 Developers{
197210037SARM gem5 Developers    System *sys = tc->getSystemPtr();
197310037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
197410037SARM gem5 Developers      ThreadContext *oc = sys->getThreadContext(x);
197512406Sgabeblack@google.com      getITBPtr(oc)->flushAllNs(hyp, target_el);
197612406Sgabeblack@google.com      getDTBPtr(oc)->flushAllNs(hyp, target_el);
197710037SARM gem5 Developers
197810037SARM gem5 Developers      CheckerCPU *checker = oc->getCheckerCpuPtr();
197910037SARM gem5 Developers      if (checker) {
198012406Sgabeblack@google.com          getITBPtr(checker)->flushAllNs(hyp, target_el);
198112406Sgabeblack@google.com          getDTBPtr(checker)->flushAllNs(hyp, target_el);
198210037SARM gem5 Developers      }
198310037SARM gem5 Developers    }
198410037SARM gem5 Developers}
198510037SARM gem5 Developers
198610037SARM gem5 Developersvoid
198710037SARM gem5 DevelopersISA::tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, bool hyp,
198810037SARM gem5 Developers             uint8_t target_el)
198910037SARM gem5 Developers{
199010037SARM gem5 Developers    System *sys = tc->getSystemPtr();
199110037SARM gem5 Developers    for (int x = 0; x < sys->numContexts(); x++) {
199210037SARM gem5 Developers        ThreadContext *oc = sys->getThreadContext(x);
199312406Sgabeblack@google.com        getITBPtr(oc)->flushMva(mbits(newVal, 31,12),
199410037SARM gem5 Developers            secure_lookup, hyp, target_el);
199512406Sgabeblack@google.com        getDTBPtr(oc)->flushMva(mbits(newVal, 31,12),
199610037SARM gem5 Developers            secure_lookup, hyp, target_el);
199710037SARM gem5 Developers
199810037SARM gem5 Developers        CheckerCPU *checker = oc->getCheckerCpuPtr();
199910037SARM gem5 Developers        if (checker) {
200012406Sgabeblack@google.com            getITBPtr(checker)->flushMva(mbits(newVal, 31,12),
200110037SARM gem5 Developers                secure_lookup, hyp, target_el);
200212406Sgabeblack@google.com            getDTBPtr(checker)->flushMva(mbits(newVal, 31,12),
200310037SARM gem5 Developers                secure_lookup, hyp, target_el);
200410037SARM gem5 Developers        }
200510037SARM gem5 Developers    }
200610037SARM gem5 Developers}
200710037SARM gem5 Developers
200810844Sandreas.sandberg@arm.comBaseISADevice &
200910844Sandreas.sandberg@arm.comISA::getGenericTimer(ThreadContext *tc)
201010037SARM gem5 Developers{
201110844Sandreas.sandberg@arm.com    // We only need to create an ISA interface the first time we try
201210844Sandreas.sandberg@arm.com    // to access the timer.
201310844Sandreas.sandberg@arm.com    if (timer)
201410844Sandreas.sandberg@arm.com        return *timer.get();
201510844Sandreas.sandberg@arm.com
201610844Sandreas.sandberg@arm.com    assert(system);
201710844Sandreas.sandberg@arm.com    GenericTimer *generic_timer(system->getGenericTimer());
201810844Sandreas.sandberg@arm.com    if (!generic_timer) {
201910844Sandreas.sandberg@arm.com        panic("Trying to get a generic timer from a system that hasn't "
202010844Sandreas.sandberg@arm.com              "been configured to use a generic timer.\n");
202110037SARM gem5 Developers    }
202210037SARM gem5 Developers
202311150Smitch.hayenga@arm.com    timer.reset(new GenericTimerISA(*generic_timer, tc->contextId()));
202410844Sandreas.sandberg@arm.com    return *timer.get();
202510037SARM gem5 Developers}
202610037SARM gem5 Developers
20277405SAli.Saidi@ARM.com}
20289384SAndreas.Sandberg@arm.com
20299384SAndreas.Sandberg@arm.comArmISA::ISA *
20309384SAndreas.Sandberg@arm.comArmISAParams::create()
20319384SAndreas.Sandberg@arm.com{
20329384SAndreas.Sandberg@arm.com    return new ArmISA::ISA(this);
20339384SAndreas.Sandberg@arm.com}
2034