isa.cc revision 11575
17405SAli.Saidi@ARM.com/* 211573SDylan.Johnson@ARM.com * Copyright (c) 2010-2016 ARM Limited 37405SAli.Saidi@ARM.com * All rights reserved 47405SAli.Saidi@ARM.com * 57405SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 67405SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 77405SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 87405SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 97405SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 107405SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 117405SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 127405SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 137405SAli.Saidi@ARM.com * 147405SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 157405SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 167405SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 177405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 187405SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 197405SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 207405SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 217405SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 227405SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 237405SAli.Saidi@ARM.com * this software without specific prior written permission. 247405SAli.Saidi@ARM.com * 257405SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 267405SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 277405SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 287405SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 297405SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 307405SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 317405SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 327405SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 337405SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 347405SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 357405SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 367405SAli.Saidi@ARM.com * 377405SAli.Saidi@ARM.com * Authors: Gabe Black 387405SAli.Saidi@ARM.com * Ali Saidi 397405SAli.Saidi@ARM.com */ 407405SAli.Saidi@ARM.com 417405SAli.Saidi@ARM.com#include "arch/arm/isa.hh" 4210461SAndreas.Sandberg@ARM.com#include "arch/arm/pmu.hh" 439050Schander.sudanthi@arm.com#include "arch/arm/system.hh" 448887Sgeoffrey.blake@arm.com#include "cpu/checker/cpu.hh" 4510461SAndreas.Sandberg@ARM.com#include "cpu/base.hh" 468232Snate@binkert.org#include "debug/Arm.hh" 478232Snate@binkert.org#include "debug/MiscRegs.hh" 4810844Sandreas.sandberg@arm.com#include "dev/arm/generic_timer.hh" 499384SAndreas.Sandberg@arm.com#include "params/ArmISA.hh" 507678Sgblack@eecs.umich.edu#include "sim/faults.hh" 518059SAli.Saidi@ARM.com#include "sim/stat_control.hh" 528284SAli.Saidi@ARM.com#include "sim/system.hh" 537405SAli.Saidi@ARM.com 547405SAli.Saidi@ARM.comnamespace ArmISA 557405SAli.Saidi@ARM.com{ 567405SAli.Saidi@ARM.com 5710037SARM gem5 Developers 5810037SARM gem5 Developers/** 5910037SARM gem5 Developers * Some registers aliase with others, and therefore need to be translated. 6010037SARM gem5 Developers * For each entry: 6110037SARM gem5 Developers * The first value is the misc register that is to be looked up 6210037SARM gem5 Developers * the second value is the lower part of the translation 6310037SARM gem5 Developers * the third the upper part 6410037SARM gem5 Developers */ 6510037SARM gem5 Developersconst struct ISA::MiscRegInitializerEntry 6610037SARM gem5 Developers ISA::MiscRegSwitch[miscRegTranslateMax] = { 6710037SARM gem5 Developers {MISCREG_CSSELR_EL1, {MISCREG_CSSELR, 0}}, 6810037SARM gem5 Developers {MISCREG_SCTLR_EL1, {MISCREG_SCTLR, 0}}, 6910037SARM gem5 Developers {MISCREG_SCTLR_EL2, {MISCREG_HSCTLR, 0}}, 7010037SARM gem5 Developers {MISCREG_ACTLR_EL1, {MISCREG_ACTLR, 0}}, 7110037SARM gem5 Developers {MISCREG_ACTLR_EL2, {MISCREG_HACTLR, 0}}, 7210037SARM gem5 Developers {MISCREG_CPACR_EL1, {MISCREG_CPACR, 0}}, 7310037SARM gem5 Developers {MISCREG_CPTR_EL2, {MISCREG_HCPTR, 0}}, 7410037SARM gem5 Developers {MISCREG_HCR_EL2, {MISCREG_HCR, 0}}, 7510037SARM gem5 Developers {MISCREG_MDCR_EL2, {MISCREG_HDCR, 0}}, 7610037SARM gem5 Developers {MISCREG_HSTR_EL2, {MISCREG_HSTR, 0}}, 7710037SARM gem5 Developers {MISCREG_HACR_EL2, {MISCREG_HACR, 0}}, 7810037SARM gem5 Developers {MISCREG_TTBR0_EL1, {MISCREG_TTBR0, 0}}, 7910037SARM gem5 Developers {MISCREG_TTBR1_EL1, {MISCREG_TTBR1, 0}}, 8010037SARM gem5 Developers {MISCREG_TTBR0_EL2, {MISCREG_HTTBR, 0}}, 8110037SARM gem5 Developers {MISCREG_VTTBR_EL2, {MISCREG_VTTBR, 0}}, 8210037SARM gem5 Developers {MISCREG_TCR_EL1, {MISCREG_TTBCR, 0}}, 8310037SARM gem5 Developers {MISCREG_TCR_EL2, {MISCREG_HTCR, 0}}, 8410037SARM gem5 Developers {MISCREG_VTCR_EL2, {MISCREG_VTCR, 0}}, 8510037SARM gem5 Developers {MISCREG_AFSR0_EL1, {MISCREG_ADFSR, 0}}, 8610037SARM gem5 Developers {MISCREG_AFSR1_EL1, {MISCREG_AIFSR, 0}}, 8710037SARM gem5 Developers {MISCREG_AFSR0_EL2, {MISCREG_HADFSR, 0}}, 8810037SARM gem5 Developers {MISCREG_AFSR1_EL2, {MISCREG_HAIFSR, 0}}, 8910037SARM gem5 Developers {MISCREG_ESR_EL2, {MISCREG_HSR, 0}}, 9010037SARM gem5 Developers {MISCREG_FAR_EL1, {MISCREG_DFAR, MISCREG_IFAR}}, 9110037SARM gem5 Developers {MISCREG_FAR_EL2, {MISCREG_HDFAR, MISCREG_HIFAR}}, 9210037SARM gem5 Developers {MISCREG_HPFAR_EL2, {MISCREG_HPFAR, 0}}, 9310037SARM gem5 Developers {MISCREG_PAR_EL1, {MISCREG_PAR, 0}}, 9410037SARM gem5 Developers {MISCREG_MAIR_EL1, {MISCREG_PRRR, MISCREG_NMRR}}, 9510037SARM gem5 Developers {MISCREG_MAIR_EL2, {MISCREG_HMAIR0, MISCREG_HMAIR1}}, 9610037SARM gem5 Developers {MISCREG_AMAIR_EL1, {MISCREG_AMAIR0, MISCREG_AMAIR1}}, 9710037SARM gem5 Developers {MISCREG_VBAR_EL1, {MISCREG_VBAR, 0}}, 9810037SARM gem5 Developers {MISCREG_VBAR_EL2, {MISCREG_HVBAR, 0}}, 9910037SARM gem5 Developers {MISCREG_CONTEXTIDR_EL1, {MISCREG_CONTEXTIDR, 0}}, 10010037SARM gem5 Developers {MISCREG_TPIDR_EL0, {MISCREG_TPIDRURW, 0}}, 10110037SARM gem5 Developers {MISCREG_TPIDRRO_EL0, {MISCREG_TPIDRURO, 0}}, 10210037SARM gem5 Developers {MISCREG_TPIDR_EL1, {MISCREG_TPIDRPRW, 0}}, 10310037SARM gem5 Developers {MISCREG_TPIDR_EL2, {MISCREG_HTPIDR, 0}}, 10410037SARM gem5 Developers {MISCREG_TEECR32_EL1, {MISCREG_TEECR, 0}}, 10510037SARM gem5 Developers {MISCREG_CNTFRQ_EL0, {MISCREG_CNTFRQ, 0}}, 10610037SARM gem5 Developers {MISCREG_CNTPCT_EL0, {MISCREG_CNTPCT, 0}}, 10710037SARM gem5 Developers {MISCREG_CNTVCT_EL0, {MISCREG_CNTVCT, 0}}, 10810037SARM gem5 Developers {MISCREG_CNTVOFF_EL2, {MISCREG_CNTVOFF, 0}}, 10910037SARM gem5 Developers {MISCREG_CNTKCTL_EL1, {MISCREG_CNTKCTL, 0}}, 11010037SARM gem5 Developers {MISCREG_CNTHCTL_EL2, {MISCREG_CNTHCTL, 0}}, 11110037SARM gem5 Developers {MISCREG_CNTP_TVAL_EL0, {MISCREG_CNTP_TVAL, 0}}, 11210037SARM gem5 Developers {MISCREG_CNTP_CTL_EL0, {MISCREG_CNTP_CTL, 0}}, 11310037SARM gem5 Developers {MISCREG_CNTP_CVAL_EL0, {MISCREG_CNTP_CVAL, 0}}, 11410037SARM gem5 Developers {MISCREG_CNTV_TVAL_EL0, {MISCREG_CNTV_TVAL, 0}}, 11510037SARM gem5 Developers {MISCREG_CNTV_CTL_EL0, {MISCREG_CNTV_CTL, 0}}, 11610037SARM gem5 Developers {MISCREG_CNTV_CVAL_EL0, {MISCREG_CNTV_CVAL, 0}}, 11710037SARM gem5 Developers {MISCREG_CNTHP_TVAL_EL2, {MISCREG_CNTHP_TVAL, 0}}, 11810037SARM gem5 Developers {MISCREG_CNTHP_CTL_EL2, {MISCREG_CNTHP_CTL, 0}}, 11910037SARM gem5 Developers {MISCREG_CNTHP_CVAL_EL2, {MISCREG_CNTHP_CVAL, 0}}, 12010037SARM gem5 Developers {MISCREG_DACR32_EL2, {MISCREG_DACR, 0}}, 12110037SARM gem5 Developers {MISCREG_IFSR32_EL2, {MISCREG_IFSR, 0}}, 12210037SARM gem5 Developers {MISCREG_TEEHBR32_EL1, {MISCREG_TEEHBR, 0}}, 12310037SARM gem5 Developers {MISCREG_SDER32_EL3, {MISCREG_SDER, 0}} 12410037SARM gem5 Developers}; 12510037SARM gem5 Developers 12610037SARM gem5 Developers 1279384SAndreas.Sandberg@arm.comISA::ISA(Params *p) 12810461SAndreas.Sandberg@ARM.com : SimObject(p), 12910461SAndreas.Sandberg@ARM.com system(NULL), 13011165SRekai.GonzalezAlberquilla@arm.com _decoderFlavour(p->decoderFlavour), 13110461SAndreas.Sandberg@ARM.com pmu(p->pmu), 13210461SAndreas.Sandberg@ARM.com lookUpMiscReg(NUM_MISCREGS, {0,0}) 1339384SAndreas.Sandberg@arm.com{ 1349384SAndreas.Sandberg@arm.com SCTLR sctlr; 1359384SAndreas.Sandberg@arm.com sctlr = 0; 1369384SAndreas.Sandberg@arm.com miscRegs[MISCREG_SCTLR_RST] = sctlr; 13710037SARM gem5 Developers 13810461SAndreas.Sandberg@ARM.com // Hook up a dummy device if we haven't been configured with a 13910461SAndreas.Sandberg@ARM.com // real PMU. By using a dummy device, we don't need to check that 14010461SAndreas.Sandberg@ARM.com // the PMU exist every time we try to access a PMU register. 14110461SAndreas.Sandberg@ARM.com if (!pmu) 14210461SAndreas.Sandberg@ARM.com pmu = &dummyDevice; 14310461SAndreas.Sandberg@ARM.com 14410609Sandreas.sandberg@arm.com // Give all ISA devices a pointer to this ISA 14510609Sandreas.sandberg@arm.com pmu->setISA(this); 14610609Sandreas.sandberg@arm.com 14710037SARM gem5 Developers system = dynamic_cast<ArmSystem *>(p->system); 14810037SARM gem5 Developers 14910037SARM gem5 Developers // Cache system-level properties 15010037SARM gem5 Developers if (FullSystem && system) { 15110037SARM gem5 Developers haveSecurity = system->haveSecurity(); 15210037SARM gem5 Developers haveLPAE = system->haveLPAE(); 15310037SARM gem5 Developers haveVirtualization = system->haveVirtualization(); 15410037SARM gem5 Developers haveLargeAsid64 = system->haveLargeAsid64(); 15510037SARM gem5 Developers physAddrRange64 = system->physAddrRange64(); 15610037SARM gem5 Developers } else { 15710037SARM gem5 Developers haveSecurity = haveLPAE = haveVirtualization = false; 15810037SARM gem5 Developers haveLargeAsid64 = false; 15910037SARM gem5 Developers physAddrRange64 = 32; // dummy value 16010037SARM gem5 Developers } 16110037SARM gem5 Developers 16210037SARM gem5 Developers /** Fill in the miscReg translation table */ 16310037SARM gem5 Developers for (uint32_t i = 0; i < miscRegTranslateMax; i++) { 16410037SARM gem5 Developers struct MiscRegLUTEntry new_entry; 16510037SARM gem5 Developers 16610037SARM gem5 Developers uint32_t select = MiscRegSwitch[i].index; 16710037SARM gem5 Developers new_entry = MiscRegSwitch[i].entry; 16810037SARM gem5 Developers 16910037SARM gem5 Developers lookUpMiscReg[select] = new_entry; 17010037SARM gem5 Developers } 17110037SARM gem5 Developers 17210037SARM gem5 Developers preUnflattenMiscReg(); 17310037SARM gem5 Developers 1749384SAndreas.Sandberg@arm.com clear(); 1759384SAndreas.Sandberg@arm.com} 1769384SAndreas.Sandberg@arm.com 1779384SAndreas.Sandberg@arm.comconst ArmISAParams * 1789384SAndreas.Sandberg@arm.comISA::params() const 1799384SAndreas.Sandberg@arm.com{ 1809384SAndreas.Sandberg@arm.com return dynamic_cast<const Params *>(_params); 1819384SAndreas.Sandberg@arm.com} 1829384SAndreas.Sandberg@arm.com 1837427Sgblack@eecs.umich.eduvoid 1847427Sgblack@eecs.umich.eduISA::clear() 1857427Sgblack@eecs.umich.edu{ 1869385SAndreas.Sandberg@arm.com const Params *p(params()); 1879385SAndreas.Sandberg@arm.com 1887427Sgblack@eecs.umich.edu SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST]; 1897427Sgblack@eecs.umich.edu memset(miscRegs, 0, sizeof(miscRegs)); 19010037SARM gem5 Developers 19110037SARM gem5 Developers // Initialize configurable default values 19210037SARM gem5 Developers miscRegs[MISCREG_MIDR] = p->midr; 19310037SARM gem5 Developers miscRegs[MISCREG_MIDR_EL1] = p->midr; 19410037SARM gem5 Developers miscRegs[MISCREG_VPIDR] = p->midr; 19510037SARM gem5 Developers 19610037SARM gem5 Developers if (FullSystem && system->highestELIs64()) { 19710037SARM gem5 Developers // Initialize AArch64 state 19810037SARM gem5 Developers clear64(p); 19910037SARM gem5 Developers return; 20010037SARM gem5 Developers } 20110037SARM gem5 Developers 20210037SARM gem5 Developers // Initialize AArch32 state... 20310037SARM gem5 Developers 2047427Sgblack@eecs.umich.edu CPSR cpsr = 0; 2057427Sgblack@eecs.umich.edu cpsr.mode = MODE_USER; 2067427Sgblack@eecs.umich.edu miscRegs[MISCREG_CPSR] = cpsr; 2077427Sgblack@eecs.umich.edu updateRegMap(cpsr); 2087427Sgblack@eecs.umich.edu 2097427Sgblack@eecs.umich.edu SCTLR sctlr = 0; 21010037SARM gem5 Developers sctlr.te = (bool) sctlr_rst.te; 21110037SARM gem5 Developers sctlr.nmfi = (bool) sctlr_rst.nmfi; 21210037SARM gem5 Developers sctlr.v = (bool) sctlr_rst.v; 21310037SARM gem5 Developers sctlr.u = 1; 2147427Sgblack@eecs.umich.edu sctlr.xp = 1; 2157427Sgblack@eecs.umich.edu sctlr.rao2 = 1; 2167427Sgblack@eecs.umich.edu sctlr.rao3 = 1; 21710037SARM gem5 Developers sctlr.rao4 = 0xf; // SCTLR[6:3] 21810204SAli.Saidi@ARM.com sctlr.uci = 1; 21910204SAli.Saidi@ARM.com sctlr.dze = 1; 22010037SARM gem5 Developers miscRegs[MISCREG_SCTLR_NS] = sctlr; 2217427Sgblack@eecs.umich.edu miscRegs[MISCREG_SCTLR_RST] = sctlr_rst; 22210037SARM gem5 Developers miscRegs[MISCREG_HCPTR] = 0; 2237427Sgblack@eecs.umich.edu 22410037SARM gem5 Developers // Start with an event in the mailbox 2257427Sgblack@eecs.umich.edu miscRegs[MISCREG_SEV_MAILBOX] = 1; 2267427Sgblack@eecs.umich.edu 22710037SARM gem5 Developers // Separate Instruction and Data TLBs 2287427Sgblack@eecs.umich.edu miscRegs[MISCREG_TLBTR] = 1; 2297427Sgblack@eecs.umich.edu 2307427Sgblack@eecs.umich.edu MVFR0 mvfr0 = 0; 2317427Sgblack@eecs.umich.edu mvfr0.advSimdRegisters = 2; 2327427Sgblack@eecs.umich.edu mvfr0.singlePrecision = 2; 2337427Sgblack@eecs.umich.edu mvfr0.doublePrecision = 2; 2347427Sgblack@eecs.umich.edu mvfr0.vfpExceptionTrapping = 0; 2357427Sgblack@eecs.umich.edu mvfr0.divide = 1; 2367427Sgblack@eecs.umich.edu mvfr0.squareRoot = 1; 2377427Sgblack@eecs.umich.edu mvfr0.shortVectors = 1; 2387427Sgblack@eecs.umich.edu mvfr0.roundingModes = 1; 2397427Sgblack@eecs.umich.edu miscRegs[MISCREG_MVFR0] = mvfr0; 2407427Sgblack@eecs.umich.edu 2417427Sgblack@eecs.umich.edu MVFR1 mvfr1 = 0; 2427427Sgblack@eecs.umich.edu mvfr1.flushToZero = 1; 2437427Sgblack@eecs.umich.edu mvfr1.defaultNaN = 1; 2447427Sgblack@eecs.umich.edu mvfr1.advSimdLoadStore = 1; 2457427Sgblack@eecs.umich.edu mvfr1.advSimdInteger = 1; 2467427Sgblack@eecs.umich.edu mvfr1.advSimdSinglePrecision = 1; 2477427Sgblack@eecs.umich.edu mvfr1.advSimdHalfPrecision = 1; 2487427Sgblack@eecs.umich.edu mvfr1.vfpHalfPrecision = 1; 2497427Sgblack@eecs.umich.edu miscRegs[MISCREG_MVFR1] = mvfr1; 2507427Sgblack@eecs.umich.edu 2517436Sdam.sunwoo@arm.com // Reset values of PRRR and NMRR are implementation dependent 2527436Sdam.sunwoo@arm.com 25310037SARM gem5 Developers // @todo: PRRR and NMRR in secure state? 25410037SARM gem5 Developers miscRegs[MISCREG_PRRR_NS] = 2557436Sdam.sunwoo@arm.com (1 << 19) | // 19 2567436Sdam.sunwoo@arm.com (0 << 18) | // 18 2577436Sdam.sunwoo@arm.com (0 << 17) | // 17 2587436Sdam.sunwoo@arm.com (1 << 16) | // 16 2597436Sdam.sunwoo@arm.com (2 << 14) | // 15:14 2607436Sdam.sunwoo@arm.com (0 << 12) | // 13:12 2617436Sdam.sunwoo@arm.com (2 << 10) | // 11:10 2627436Sdam.sunwoo@arm.com (2 << 8) | // 9:8 2637436Sdam.sunwoo@arm.com (2 << 6) | // 7:6 2647436Sdam.sunwoo@arm.com (2 << 4) | // 5:4 2657436Sdam.sunwoo@arm.com (1 << 2) | // 3:2 2667436Sdam.sunwoo@arm.com 0; // 1:0 26710037SARM gem5 Developers miscRegs[MISCREG_NMRR_NS] = 2687436Sdam.sunwoo@arm.com (1 << 30) | // 31:30 2697436Sdam.sunwoo@arm.com (0 << 26) | // 27:26 2707436Sdam.sunwoo@arm.com (0 << 24) | // 25:24 2717436Sdam.sunwoo@arm.com (3 << 22) | // 23:22 2727436Sdam.sunwoo@arm.com (2 << 20) | // 21:20 2737436Sdam.sunwoo@arm.com (0 << 18) | // 19:18 2747436Sdam.sunwoo@arm.com (0 << 16) | // 17:16 2757436Sdam.sunwoo@arm.com (1 << 14) | // 15:14 2767436Sdam.sunwoo@arm.com (0 << 12) | // 13:12 2777436Sdam.sunwoo@arm.com (2 << 10) | // 11:10 2787436Sdam.sunwoo@arm.com (0 << 8) | // 9:8 2797436Sdam.sunwoo@arm.com (3 << 6) | // 7:6 2807436Sdam.sunwoo@arm.com (2 << 4) | // 5:4 2817436Sdam.sunwoo@arm.com (0 << 2) | // 3:2 2827436Sdam.sunwoo@arm.com 0; // 1:0 2837436Sdam.sunwoo@arm.com 2847644Sali.saidi@arm.com miscRegs[MISCREG_CPACR] = 0; 2858147SAli.Saidi@ARM.com 2869385SAndreas.Sandberg@arm.com 2879385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_PFR0] = p->id_pfr0; 2889385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_PFR1] = p->id_pfr1; 2899385SAndreas.Sandberg@arm.com 2909385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0; 2919385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1; 2929385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2; 2939385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3; 2949385SAndreas.Sandberg@arm.com 2959385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR0] = p->id_isar0; 2969385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR1] = p->id_isar1; 2979385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR2] = p->id_isar2; 2989385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR3] = p->id_isar3; 2999385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR4] = p->id_isar4; 3009385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR5] = p->id_isar5; 3019385SAndreas.Sandberg@arm.com 3029385SAndreas.Sandberg@arm.com miscRegs[MISCREG_FPSID] = p->fpsid; 3039385SAndreas.Sandberg@arm.com 30410037SARM gem5 Developers if (haveLPAE) { 30510037SARM gem5 Developers TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS]; 30610037SARM gem5 Developers ttbcr.eae = 0; 30710037SARM gem5 Developers miscRegs[MISCREG_TTBCR_NS] = ttbcr; 30810037SARM gem5 Developers // Enforce consistency with system-level settings 30910037SARM gem5 Developers miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5; 31010037SARM gem5 Developers } 31110037SARM gem5 Developers 31210037SARM gem5 Developers if (haveSecurity) { 31310037SARM gem5 Developers miscRegs[MISCREG_SCTLR_S] = sctlr; 31410037SARM gem5 Developers miscRegs[MISCREG_SCR] = 0; 31510037SARM gem5 Developers miscRegs[MISCREG_VBAR_S] = 0; 31610037SARM gem5 Developers } else { 31710037SARM gem5 Developers // we're always non-secure 31810037SARM gem5 Developers miscRegs[MISCREG_SCR] = 1; 31910037SARM gem5 Developers } 3208147SAli.Saidi@ARM.com 3217427Sgblack@eecs.umich.edu //XXX We need to initialize the rest of the state. 3227427Sgblack@eecs.umich.edu} 3237427Sgblack@eecs.umich.edu 32410037SARM gem5 Developersvoid 32510037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p) 32610037SARM gem5 Developers{ 32710037SARM gem5 Developers CPSR cpsr = 0; 32810037SARM gem5 Developers Addr rvbar = system->resetAddr64(); 32910037SARM gem5 Developers switch (system->highestEL()) { 33010037SARM gem5 Developers // Set initial EL to highest implemented EL using associated stack 33110037SARM gem5 Developers // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset 33210037SARM gem5 Developers // value 33310037SARM gem5 Developers case EL3: 33410037SARM gem5 Developers cpsr.mode = MODE_EL3H; 33510037SARM gem5 Developers miscRegs[MISCREG_RVBAR_EL3] = rvbar; 33610037SARM gem5 Developers break; 33710037SARM gem5 Developers case EL2: 33810037SARM gem5 Developers cpsr.mode = MODE_EL2H; 33910037SARM gem5 Developers miscRegs[MISCREG_RVBAR_EL2] = rvbar; 34010037SARM gem5 Developers break; 34110037SARM gem5 Developers case EL1: 34210037SARM gem5 Developers cpsr.mode = MODE_EL1H; 34310037SARM gem5 Developers miscRegs[MISCREG_RVBAR_EL1] = rvbar; 34410037SARM gem5 Developers break; 34510037SARM gem5 Developers default: 34610037SARM gem5 Developers panic("Invalid highest implemented exception level"); 34710037SARM gem5 Developers break; 34810037SARM gem5 Developers } 34910037SARM gem5 Developers 35010037SARM gem5 Developers // Initialize rest of CPSR 35110037SARM gem5 Developers cpsr.daif = 0xf; // Mask all interrupts 35210037SARM gem5 Developers cpsr.ss = 0; 35310037SARM gem5 Developers cpsr.il = 0; 35410037SARM gem5 Developers miscRegs[MISCREG_CPSR] = cpsr; 35510037SARM gem5 Developers updateRegMap(cpsr); 35610037SARM gem5 Developers 35710037SARM gem5 Developers // Initialize other control registers 35810037SARM gem5 Developers miscRegs[MISCREG_MPIDR_EL1] = 0x80000000; 35910037SARM gem5 Developers if (haveSecurity) { 36010037SARM gem5 Developers miscRegs[MISCREG_SCTLR_EL3] = 0x30c50870; 36110037SARM gem5 Developers miscRegs[MISCREG_SCR_EL3] = 0x00000030; // RES1 fields 36211574SCurtis.Dunham@arm.com } else if (haveVirtualization) { 36311574SCurtis.Dunham@arm.com miscRegs[MISCREG_SCTLR_EL2] = 0x30c50870; 36410037SARM gem5 Developers } else { 36510037SARM gem5 Developers miscRegs[MISCREG_SCTLR_EL1] = 0x30c50870; 36610037SARM gem5 Developers // Always non-secure 36710037SARM gem5 Developers miscRegs[MISCREG_SCR_EL3] = 1; 36810037SARM gem5 Developers } 36910037SARM gem5 Developers 37010037SARM gem5 Developers // Initialize configurable id registers 37110037SARM gem5 Developers miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1; 37210037SARM gem5 Developers miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1; 37310461SAndreas.Sandberg@ARM.com miscRegs[MISCREG_ID_AA64DFR0_EL1] = 37410461SAndreas.Sandberg@ARM.com (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) | 37510461SAndreas.Sandberg@ARM.com (p->pmu ? 0x0000000000000100ULL : 0); // Enable PMUv3 37610461SAndreas.Sandberg@ARM.com 37710037SARM gem5 Developers miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1; 37810037SARM gem5 Developers miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1; 37910037SARM gem5 Developers miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1; 38010037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1; 38110037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1; 38210037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1] = p->id_aa64pfr0_el1; 38310037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR1_EL1] = p->id_aa64pfr1_el1; 38410037SARM gem5 Developers 38510461SAndreas.Sandberg@ARM.com miscRegs[MISCREG_ID_DFR0_EL1] = 38610461SAndreas.Sandberg@ARM.com (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3 38710461SAndreas.Sandberg@ARM.com 38810461SAndreas.Sandberg@ARM.com miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1]; 38910461SAndreas.Sandberg@ARM.com 39010037SARM gem5 Developers // Enforce consistency with system-level settings... 39110037SARM gem5 Developers 39210037SARM gem5 Developers // EL3 39310037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 39410037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12, 39511574SCurtis.Dunham@arm.com haveSecurity ? 0x2 : 0x0); 39610037SARM gem5 Developers // EL2 39710037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 39810037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8, 39911574SCurtis.Dunham@arm.com haveVirtualization ? 0x2 : 0x0); 40010037SARM gem5 Developers // Large ASID support 40110037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 40210037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4, 40310037SARM gem5 Developers haveLargeAsid64 ? 0x2 : 0x0); 40410037SARM gem5 Developers // Physical address size 40510037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 40610037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0, 40710037SARM gem5 Developers encodePhysAddrRange64(physAddrRange64)); 40810037SARM gem5 Developers} 40910037SARM gem5 Developers 4107405SAli.Saidi@ARM.comMiscReg 41110035Sandreas.hansson@arm.comISA::readMiscRegNoEffect(int misc_reg) const 4127405SAli.Saidi@ARM.com{ 4137405SAli.Saidi@ARM.com assert(misc_reg < NumMiscRegs); 4147614Sminkyu.jeong@arm.com 41510037SARM gem5 Developers int flat_idx = flattenMiscIndex(misc_reg); // Note: indexes of AArch64 41610037SARM gem5 Developers // registers are left unchanged 41710037SARM gem5 Developers MiscReg val; 4187614Sminkyu.jeong@arm.com 41910037SARM gem5 Developers if (lookUpMiscReg[flat_idx].lower == 0 || flat_idx == MISCREG_SPSR 42010037SARM gem5 Developers || flat_idx == MISCREG_SCTLR_EL1) { 42110037SARM gem5 Developers if (flat_idx == MISCREG_SPSR) 42210037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SPSR); 42310037SARM gem5 Developers if (flat_idx == MISCREG_SCTLR_EL1) 42410037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SCTLR); 42510037SARM gem5 Developers val = miscRegs[flat_idx]; 42610037SARM gem5 Developers } else 42710037SARM gem5 Developers if (lookUpMiscReg[flat_idx].upper > 0) 42810037SARM gem5 Developers val = ((miscRegs[lookUpMiscReg[flat_idx].lower] & mask(32)) 42910037SARM gem5 Developers | (miscRegs[lookUpMiscReg[flat_idx].upper] << 32)); 43010037SARM gem5 Developers else 43110037SARM gem5 Developers val = miscRegs[lookUpMiscReg[flat_idx].lower]; 43210037SARM gem5 Developers 4337614Sminkyu.jeong@arm.com return val; 4347405SAli.Saidi@ARM.com} 4357405SAli.Saidi@ARM.com 4367405SAli.Saidi@ARM.com 4377405SAli.Saidi@ARM.comMiscReg 4387405SAli.Saidi@ARM.comISA::readMiscReg(int misc_reg, ThreadContext *tc) 4397405SAli.Saidi@ARM.com{ 44010037SARM gem5 Developers CPSR cpsr = 0; 44110037SARM gem5 Developers PCState pc = 0; 44210037SARM gem5 Developers SCR scr = 0; 4439050Schander.sudanthi@arm.com 4447405SAli.Saidi@ARM.com if (misc_reg == MISCREG_CPSR) { 44510037SARM gem5 Developers cpsr = miscRegs[misc_reg]; 44610037SARM gem5 Developers pc = tc->pcState(); 4477720Sgblack@eecs.umich.edu cpsr.j = pc.jazelle() ? 1 : 0; 4487720Sgblack@eecs.umich.edu cpsr.t = pc.thumb() ? 1 : 0; 4497405SAli.Saidi@ARM.com return cpsr; 4507405SAli.Saidi@ARM.com } 4517757SAli.Saidi@ARM.com 45210037SARM gem5 Developers#ifndef NDEBUG 45310037SARM gem5 Developers if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 45410037SARM gem5 Developers if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 45510037SARM gem5 Developers warn("Unimplemented system register %s read.\n", 45610037SARM gem5 Developers miscRegName[misc_reg]); 45710037SARM gem5 Developers else 45810037SARM gem5 Developers panic("Unimplemented system register %s read.\n", 45910037SARM gem5 Developers miscRegName[misc_reg]); 46010037SARM gem5 Developers } 46110037SARM gem5 Developers#endif 46210037SARM gem5 Developers 46310037SARM gem5 Developers switch (unflattenMiscReg(misc_reg)) { 46410037SARM gem5 Developers case MISCREG_HCR: 46510037SARM gem5 Developers { 46610037SARM gem5 Developers if (!haveVirtualization) 46710037SARM gem5 Developers return 0; 46810037SARM gem5 Developers else 46910037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_HCR); 47010037SARM gem5 Developers } 47110037SARM gem5 Developers case MISCREG_CPACR: 47210037SARM gem5 Developers { 47310037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 47410037SARM gem5 Developers CPACR cpacrMask = 0; 47510037SARM gem5 Developers // Only cp10, cp11, and ase are implemented, nothing else should 47610037SARM gem5 Developers // be readable? (straight copy from the write code) 47710037SARM gem5 Developers cpacrMask.cp10 = ones; 47810037SARM gem5 Developers cpacrMask.cp11 = ones; 47910037SARM gem5 Developers cpacrMask.asedis = ones; 48010037SARM gem5 Developers 48110037SARM gem5 Developers // Security Extensions may limit the readability of CPACR 48210037SARM gem5 Developers if (haveSecurity) { 48310037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 48410037SARM gem5 Developers cpsr = readMiscRegNoEffect(MISCREG_CPSR); 48510037SARM gem5 Developers if (scr.ns && (cpsr.mode != MODE_MON)) { 48610037SARM gem5 Developers NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 48710037SARM gem5 Developers // NB: Skipping the full loop, here 48810037SARM gem5 Developers if (!nsacr.cp10) cpacrMask.cp10 = 0; 48910037SARM gem5 Developers if (!nsacr.cp11) cpacrMask.cp11 = 0; 49010037SARM gem5 Developers } 49110037SARM gem5 Developers } 49210037SARM gem5 Developers MiscReg val = readMiscRegNoEffect(MISCREG_CPACR); 49310037SARM gem5 Developers val &= cpacrMask; 49410037SARM gem5 Developers DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n", 49510037SARM gem5 Developers miscRegName[misc_reg], val); 49610037SARM gem5 Developers return val; 49710037SARM gem5 Developers } 4988284SAli.Saidi@ARM.com case MISCREG_MPIDR: 49910037SARM gem5 Developers cpsr = readMiscRegNoEffect(MISCREG_CPSR); 50010037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 50110037SARM gem5 Developers if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 50210037SARM gem5 Developers return getMPIDR(system, tc); 5039050Schander.sudanthi@arm.com } else { 50410037SARM gem5 Developers return readMiscReg(MISCREG_VMPIDR, tc); 50510037SARM gem5 Developers } 50610037SARM gem5 Developers break; 50710037SARM gem5 Developers case MISCREG_MPIDR_EL1: 50810037SARM gem5 Developers // @todo in the absence of v8 virtualization support just return MPIDR_EL1 50910037SARM gem5 Developers return getMPIDR(system, tc) & 0xffffffff; 51010037SARM gem5 Developers case MISCREG_VMPIDR: 51110037SARM gem5 Developers // top bit defined as RES1 51210037SARM gem5 Developers return readMiscRegNoEffect(misc_reg) | 0x80000000; 51310037SARM gem5 Developers case MISCREG_ID_AFR0: // not implemented, so alias MIDR 51410037SARM gem5 Developers case MISCREG_REVIDR: // not implemented, so alias MIDR 51510037SARM gem5 Developers case MISCREG_MIDR: 51610037SARM gem5 Developers cpsr = readMiscRegNoEffect(MISCREG_CPSR); 51710037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 51810037SARM gem5 Developers if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 51910037SARM gem5 Developers return readMiscRegNoEffect(misc_reg); 52010037SARM gem5 Developers } else { 52110037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_VPIDR); 5229050Schander.sudanthi@arm.com } 5238284SAli.Saidi@ARM.com break; 52410037SARM gem5 Developers case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI 52510037SARM gem5 Developers case MISCREG_JMCR: // Jazelle trivial implementation, RAZ/WI 52610037SARM gem5 Developers case MISCREG_JIDR: // Jazelle trivial implementation, RAZ/WI 52710037SARM gem5 Developers case MISCREG_AIDR: // AUX ID set to 0 52810037SARM gem5 Developers case MISCREG_TCMTR: // No TCM's 52910037SARM gem5 Developers return 0; 53010037SARM gem5 Developers 5317405SAli.Saidi@ARM.com case MISCREG_CLIDR: 5327731SAli.Saidi@ARM.com warn_once("The clidr register always reports 0 caches.\n"); 5338468Swade.walker@arm.com warn_once("clidr LoUIS field of 0b001 to match current " 5348468Swade.walker@arm.com "ARM implementations.\n"); 5358468Swade.walker@arm.com return 0x00200000; 5367405SAli.Saidi@ARM.com case MISCREG_CCSIDR: 5377731SAli.Saidi@ARM.com warn_once("The ccsidr register isn't implemented and " 5387405SAli.Saidi@ARM.com "always reads as 0.\n"); 5397405SAli.Saidi@ARM.com break; 5407583SAli.Saidi@arm.com case MISCREG_CTR: 5419130Satgutier@umich.edu { 5429130Satgutier@umich.edu //all caches have the same line size in gem5 5439130Satgutier@umich.edu //4 byte words in ARM 5449130Satgutier@umich.edu unsigned lineSizeWords = 5459814Sandreas.hansson@arm.com tc->getSystemPtr()->cacheLineSize() / 4; 5469130Satgutier@umich.edu unsigned log2LineSizeWords = 0; 5479130Satgutier@umich.edu 5489130Satgutier@umich.edu while (lineSizeWords >>= 1) { 5499130Satgutier@umich.edu ++log2LineSizeWords; 5509130Satgutier@umich.edu } 5519130Satgutier@umich.edu 5529130Satgutier@umich.edu CTR ctr = 0; 5539130Satgutier@umich.edu //log2 of minimun i-cache line size (words) 5549130Satgutier@umich.edu ctr.iCacheLineSize = log2LineSizeWords; 5559130Satgutier@umich.edu //b11 - gem5 uses pipt 5569130Satgutier@umich.edu ctr.l1IndexPolicy = 0x3; 5579130Satgutier@umich.edu //log2 of minimum d-cache line size (words) 5589130Satgutier@umich.edu ctr.dCacheLineSize = log2LineSizeWords; 5599130Satgutier@umich.edu //log2 of max reservation size (words) 5609130Satgutier@umich.edu ctr.erg = log2LineSizeWords; 5619130Satgutier@umich.edu //log2 of max writeback size (words) 5629130Satgutier@umich.edu ctr.cwg = log2LineSizeWords; 5639130Satgutier@umich.edu //b100 - gem5 format is ARMv7 5649130Satgutier@umich.edu ctr.format = 0x4; 5659130Satgutier@umich.edu 5669130Satgutier@umich.edu return ctr; 5679130Satgutier@umich.edu } 5687583SAli.Saidi@arm.com case MISCREG_ACTLR: 5697583SAli.Saidi@arm.com warn("Not doing anything for miscreg ACTLR\n"); 5707583SAli.Saidi@arm.com break; 57110461SAndreas.Sandberg@ARM.com 57210461SAndreas.Sandberg@ARM.com case MISCREG_PMXEVTYPER_PMCCFILTR: 57310461SAndreas.Sandberg@ARM.com case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 57410461SAndreas.Sandberg@ARM.com case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 57510461SAndreas.Sandberg@ARM.com case MISCREG_PMCR ... MISCREG_PMOVSSET: 57610461SAndreas.Sandberg@ARM.com return pmu->readMiscReg(misc_reg); 57710461SAndreas.Sandberg@ARM.com 5788302SAli.Saidi@ARM.com case MISCREG_CPSR_Q: 5798302SAli.Saidi@ARM.com panic("shouldn't be reading this register seperately\n"); 5807783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_QC: 5817783SGiacomo.Gabrielli@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask; 5827783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_EXC: 5837783SGiacomo.Gabrielli@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask; 58410037SARM gem5 Developers case MISCREG_FPSR: 58510037SARM gem5 Developers { 58610037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 58710037SARM gem5 Developers FPSCR fpscrMask = 0; 58810037SARM gem5 Developers fpscrMask.ioc = ones; 58910037SARM gem5 Developers fpscrMask.dzc = ones; 59010037SARM gem5 Developers fpscrMask.ofc = ones; 59110037SARM gem5 Developers fpscrMask.ufc = ones; 59210037SARM gem5 Developers fpscrMask.ixc = ones; 59310037SARM gem5 Developers fpscrMask.idc = ones; 59410037SARM gem5 Developers fpscrMask.qc = ones; 59510037SARM gem5 Developers fpscrMask.v = ones; 59610037SARM gem5 Developers fpscrMask.c = ones; 59710037SARM gem5 Developers fpscrMask.z = ones; 59810037SARM gem5 Developers fpscrMask.n = ones; 59910037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 60010037SARM gem5 Developers } 60110037SARM gem5 Developers case MISCREG_FPCR: 60210037SARM gem5 Developers { 60310037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 60410037SARM gem5 Developers FPSCR fpscrMask = 0; 60510037SARM gem5 Developers fpscrMask.ioe = ones; 60610037SARM gem5 Developers fpscrMask.dze = ones; 60710037SARM gem5 Developers fpscrMask.ofe = ones; 60810037SARM gem5 Developers fpscrMask.ufe = ones; 60910037SARM gem5 Developers fpscrMask.ixe = ones; 61010037SARM gem5 Developers fpscrMask.ide = ones; 61110037SARM gem5 Developers fpscrMask.len = ones; 61210037SARM gem5 Developers fpscrMask.stride = ones; 61310037SARM gem5 Developers fpscrMask.rMode = ones; 61410037SARM gem5 Developers fpscrMask.fz = ones; 61510037SARM gem5 Developers fpscrMask.dn = ones; 61610037SARM gem5 Developers fpscrMask.ahp = ones; 61710037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 61810037SARM gem5 Developers } 61910037SARM gem5 Developers case MISCREG_NZCV: 62010037SARM gem5 Developers { 62110037SARM gem5 Developers CPSR cpsr = 0; 62210338SCurtis.Dunham@arm.com cpsr.nz = tc->readCCReg(CCREG_NZ); 62310338SCurtis.Dunham@arm.com cpsr.c = tc->readCCReg(CCREG_C); 62410338SCurtis.Dunham@arm.com cpsr.v = tc->readCCReg(CCREG_V); 62510037SARM gem5 Developers return cpsr; 62610037SARM gem5 Developers } 62710037SARM gem5 Developers case MISCREG_DAIF: 62810037SARM gem5 Developers { 62910037SARM gem5 Developers CPSR cpsr = 0; 63010037SARM gem5 Developers cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif; 63110037SARM gem5 Developers return cpsr; 63210037SARM gem5 Developers } 63310037SARM gem5 Developers case MISCREG_SP_EL0: 63410037SARM gem5 Developers { 63510037SARM gem5 Developers return tc->readIntReg(INTREG_SP0); 63610037SARM gem5 Developers } 63710037SARM gem5 Developers case MISCREG_SP_EL1: 63810037SARM gem5 Developers { 63910037SARM gem5 Developers return tc->readIntReg(INTREG_SP1); 64010037SARM gem5 Developers } 64110037SARM gem5 Developers case MISCREG_SP_EL2: 64210037SARM gem5 Developers { 64310037SARM gem5 Developers return tc->readIntReg(INTREG_SP2); 64410037SARM gem5 Developers } 64510037SARM gem5 Developers case MISCREG_SPSEL: 64610037SARM gem5 Developers { 64710037SARM gem5 Developers return miscRegs[MISCREG_CPSR] & 0x1; 64810037SARM gem5 Developers } 64910037SARM gem5 Developers case MISCREG_CURRENTEL: 65010037SARM gem5 Developers { 65110037SARM gem5 Developers return miscRegs[MISCREG_CPSR] & 0xc; 65210037SARM gem5 Developers } 6538549Sdaniel.johnson@arm.com case MISCREG_L2CTLR: 6548868SMatt.Horsnell@arm.com { 6558868SMatt.Horsnell@arm.com // mostly unimplemented, just set NumCPUs field from sim and return 6568868SMatt.Horsnell@arm.com L2CTLR l2ctlr = 0; 6578868SMatt.Horsnell@arm.com // b00:1CPU to b11:4CPUs 6588868SMatt.Horsnell@arm.com l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1; 6598868SMatt.Horsnell@arm.com return l2ctlr; 6608868SMatt.Horsnell@arm.com } 6618868SMatt.Horsnell@arm.com case MISCREG_DBGDIDR: 6628868SMatt.Horsnell@arm.com /* For now just implement the version number. 66310461SAndreas.Sandberg@ARM.com * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5) 6648868SMatt.Horsnell@arm.com */ 66510461SAndreas.Sandberg@ARM.com return 0x5 << 16; 66610037SARM gem5 Developers case MISCREG_DBGDSCRint: 6678868SMatt.Horsnell@arm.com return 0; 66810037SARM gem5 Developers case MISCREG_ISR: 66911150Smitch.hayenga@arm.com return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 67010037SARM gem5 Developers readMiscRegNoEffect(MISCREG_HCR), 67110037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR), 67210037SARM gem5 Developers readMiscRegNoEffect(MISCREG_SCR)); 67310037SARM gem5 Developers case MISCREG_ISR_EL1: 67411150Smitch.hayenga@arm.com return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 67510037SARM gem5 Developers readMiscRegNoEffect(MISCREG_HCR_EL2), 67610037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR), 67710037SARM gem5 Developers readMiscRegNoEffect(MISCREG_SCR_EL3)); 67810037SARM gem5 Developers case MISCREG_DCZID_EL0: 67910037SARM gem5 Developers return 0x04; // DC ZVA clear 64-byte chunks 68010037SARM gem5 Developers case MISCREG_HCPTR: 68110037SARM gem5 Developers { 68210037SARM gem5 Developers MiscReg val = readMiscRegNoEffect(misc_reg); 68310037SARM gem5 Developers // The trap bit associated with CP14 is defined as RAZ 68410037SARM gem5 Developers val &= ~(1 << 14); 68510037SARM gem5 Developers // If a CP bit in NSACR is 0 then the corresponding bit in 68610037SARM gem5 Developers // HCPTR is RAO/WI 68710037SARM gem5 Developers bool secure_lookup = haveSecurity && 68810037SARM gem5 Developers inSecureState(readMiscRegNoEffect(MISCREG_SCR), 68910037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR)); 69010037SARM gem5 Developers if (!secure_lookup) { 69110037SARM gem5 Developers MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR); 69210037SARM gem5 Developers val |= (mask ^ 0x7FFF) & 0xBFFF; 69310037SARM gem5 Developers } 69410037SARM gem5 Developers // Set the bits for unimplemented coprocessors to RAO/WI 69510037SARM gem5 Developers val |= 0x33FF; 69610037SARM gem5 Developers return (val); 69710037SARM gem5 Developers } 69810037SARM gem5 Developers case MISCREG_HDFAR: // alias for secure DFAR 69910037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_DFAR_S); 70010037SARM gem5 Developers case MISCREG_HIFAR: // alias for secure IFAR 70110037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_IFAR_S); 70210037SARM gem5 Developers case MISCREG_HVBAR: // bottom bits reserved 70310037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0; 70410037SARM gem5 Developers case MISCREG_SCTLR: // Some bits hardwired 70510037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions of the register 70610037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21)) | 70710037SARM gem5 Developers (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818; // V8 SCTLR 70810037SARM gem5 Developers case MISCREG_SCTLR_EL1: 70910037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions of the register 71010037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21)) | 71110037SARM gem5 Developers (readMiscRegNoEffect(misc_reg) & 0x37DDDBFF) | 0x30D00800; // V8 SCTLR_EL1 71210037SARM gem5 Developers case MISCREG_SCTLR_EL3: 71310037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions of the register 71410037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21)) | 71510037SARM gem5 Developers (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830; // V8 SCTLR_EL3 71610037SARM gem5 Developers case MISCREG_HSCTLR: // FI comes from SCTLR 71710037SARM gem5 Developers { 71810037SARM gem5 Developers uint32_t mask = 1 << 27; 71910037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_HSCTLR) & ~mask) | 72010037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_SCTLR) & mask); 72110037SARM gem5 Developers } 72210037SARM gem5 Developers case MISCREG_SCR: 72310037SARM gem5 Developers { 72410037SARM gem5 Developers CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR); 72510037SARM gem5 Developers if (cpsr.width) { 72610037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_SCR); 72710037SARM gem5 Developers } else { 72810037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_SCR_EL3); 72910037SARM gem5 Developers } 73010037SARM gem5 Developers } 73110844Sandreas.sandberg@arm.com 73210037SARM gem5 Developers // Generic Timer registers 73310844Sandreas.sandberg@arm.com case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 73410844Sandreas.sandberg@arm.com case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 73510844Sandreas.sandberg@arm.com case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 73610844Sandreas.sandberg@arm.com case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 73710844Sandreas.sandberg@arm.com return getGenericTimer(tc).readMiscReg(misc_reg); 73810844Sandreas.sandberg@arm.com 73910188Sgeoffrey.blake@arm.com default: 74010037SARM gem5 Developers break; 74110037SARM gem5 Developers 7427405SAli.Saidi@ARM.com } 7437405SAli.Saidi@ARM.com return readMiscRegNoEffect(misc_reg); 7447405SAli.Saidi@ARM.com} 7457405SAli.Saidi@ARM.com 7467405SAli.Saidi@ARM.comvoid 7477405SAli.Saidi@ARM.comISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val) 7487405SAli.Saidi@ARM.com{ 7497405SAli.Saidi@ARM.com assert(misc_reg < NumMiscRegs); 7507614Sminkyu.jeong@arm.com 75110037SARM gem5 Developers int flat_idx = flattenMiscIndex(misc_reg); // Note: indexes of AArch64 75210037SARM gem5 Developers // registers are left unchanged 7537614Sminkyu.jeong@arm.com 75410037SARM gem5 Developers int flat_idx2 = lookUpMiscReg[flat_idx].upper; 75510037SARM gem5 Developers 75610037SARM gem5 Developers if (flat_idx2 > 0) { 75710037SARM gem5 Developers miscRegs[lookUpMiscReg[flat_idx].lower] = bits(val, 31, 0); 75810037SARM gem5 Developers miscRegs[flat_idx2] = bits(val, 63, 32); 75910037SARM gem5 Developers DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n", 76010037SARM gem5 Developers misc_reg, flat_idx, flat_idx2, val); 76110037SARM gem5 Developers } else { 76210037SARM gem5 Developers if (flat_idx == MISCREG_SPSR) 76310037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SPSR); 76410037SARM gem5 Developers else if (flat_idx == MISCREG_SCTLR_EL1) 76510037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SCTLR); 76610037SARM gem5 Developers else 76710037SARM gem5 Developers flat_idx = (lookUpMiscReg[flat_idx].lower > 0) ? 76810037SARM gem5 Developers lookUpMiscReg[flat_idx].lower : flat_idx; 76910037SARM gem5 Developers miscRegs[flat_idx] = val; 77010037SARM gem5 Developers DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n", 77110037SARM gem5 Developers misc_reg, flat_idx, val); 77210037SARM gem5 Developers } 7737405SAli.Saidi@ARM.com} 7747405SAli.Saidi@ARM.com 7757405SAli.Saidi@ARM.comvoid 7767405SAli.Saidi@ARM.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 7777405SAli.Saidi@ARM.com{ 7787749SAli.Saidi@ARM.com 7797405SAli.Saidi@ARM.com MiscReg newVal = val; 7808284SAli.Saidi@ARM.com int x; 78110037SARM gem5 Developers bool secure_lookup; 78210037SARM gem5 Developers bool hyp; 7838284SAli.Saidi@ARM.com System *sys; 7848284SAli.Saidi@ARM.com ThreadContext *oc; 78510037SARM gem5 Developers uint8_t target_el; 78610037SARM gem5 Developers uint16_t asid; 78710037SARM gem5 Developers SCR scr; 7888284SAli.Saidi@ARM.com 7897405SAli.Saidi@ARM.com if (misc_reg == MISCREG_CPSR) { 7907405SAli.Saidi@ARM.com updateRegMap(val); 7917749SAli.Saidi@ARM.com 7927749SAli.Saidi@ARM.com 7937749SAli.Saidi@ARM.com CPSR old_cpsr = miscRegs[MISCREG_CPSR]; 7947749SAli.Saidi@ARM.com int old_mode = old_cpsr.mode; 7957405SAli.Saidi@ARM.com CPSR cpsr = val; 7967749SAli.Saidi@ARM.com if (old_mode != cpsr.mode) { 7977749SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 7987749SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 7997749SAli.Saidi@ARM.com } 8007749SAli.Saidi@ARM.com 8017614Sminkyu.jeong@arm.com DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n", 8027614Sminkyu.jeong@arm.com miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode); 8037720Sgblack@eecs.umich.edu PCState pc = tc->pcState(); 8047720Sgblack@eecs.umich.edu pc.nextThumb(cpsr.t); 8057720Sgblack@eecs.umich.edu pc.nextJazelle(cpsr.j); 8068887Sgeoffrey.blake@arm.com 8078887Sgeoffrey.blake@arm.com // Follow slightly different semantics if a CheckerCPU object 8088887Sgeoffrey.blake@arm.com // is connected 8098887Sgeoffrey.blake@arm.com CheckerCPU *checker = tc->getCheckerCpuPtr(); 8108887Sgeoffrey.blake@arm.com if (checker) { 8118887Sgeoffrey.blake@arm.com tc->pcStateNoRecord(pc); 8128887Sgeoffrey.blake@arm.com } else { 8138887Sgeoffrey.blake@arm.com tc->pcState(pc); 8148887Sgeoffrey.blake@arm.com } 8157408Sgblack@eecs.umich.edu } else { 81610037SARM gem5 Developers#ifndef NDEBUG 81710037SARM gem5 Developers if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 81810037SARM gem5 Developers if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 81910037SARM gem5 Developers warn("Unimplemented system register %s write with %#x.\n", 82010037SARM gem5 Developers miscRegName[misc_reg], val); 82110037SARM gem5 Developers else 82210037SARM gem5 Developers panic("Unimplemented system register %s write with %#x.\n", 82310037SARM gem5 Developers miscRegName[misc_reg], val); 82410037SARM gem5 Developers } 82510037SARM gem5 Developers#endif 82610037SARM gem5 Developers switch (unflattenMiscReg(misc_reg)) { 8277408Sgblack@eecs.umich.edu case MISCREG_CPACR: 8287408Sgblack@eecs.umich.edu { 8298206SWilliam.Wang@arm.com 8308206SWilliam.Wang@arm.com const uint32_t ones = (uint32_t)(-1); 8318206SWilliam.Wang@arm.com CPACR cpacrMask = 0; 8328206SWilliam.Wang@arm.com // Only cp10, cp11, and ase are implemented, nothing else should 8338206SWilliam.Wang@arm.com // be writable 8348206SWilliam.Wang@arm.com cpacrMask.cp10 = ones; 8358206SWilliam.Wang@arm.com cpacrMask.cp11 = ones; 8368206SWilliam.Wang@arm.com cpacrMask.asedis = ones; 83710037SARM gem5 Developers 83810037SARM gem5 Developers // Security Extensions may limit the writability of CPACR 83910037SARM gem5 Developers if (haveSecurity) { 84010037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 84110037SARM gem5 Developers CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR); 84210037SARM gem5 Developers if (scr.ns && (cpsr.mode != MODE_MON)) { 84310037SARM gem5 Developers NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 84410037SARM gem5 Developers // NB: Skipping the full loop, here 84510037SARM gem5 Developers if (!nsacr.cp10) cpacrMask.cp10 = 0; 84610037SARM gem5 Developers if (!nsacr.cp11) cpacrMask.cp11 = 0; 84710037SARM gem5 Developers } 84810037SARM gem5 Developers } 84910037SARM gem5 Developers 85010037SARM gem5 Developers MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR); 8518206SWilliam.Wang@arm.com newVal &= cpacrMask; 85210037SARM gem5 Developers newVal |= old_val & ~cpacrMask; 85310037SARM gem5 Developers DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 85410037SARM gem5 Developers miscRegName[misc_reg], newVal); 85510037SARM gem5 Developers } 85610037SARM gem5 Developers break; 85710037SARM gem5 Developers case MISCREG_CPACR_EL1: 85810037SARM gem5 Developers { 85910037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 86010037SARM gem5 Developers CPACR cpacrMask = 0; 86110037SARM gem5 Developers cpacrMask.tta = ones; 86210037SARM gem5 Developers cpacrMask.fpen = ones; 86310037SARM gem5 Developers newVal &= cpacrMask; 86410037SARM gem5 Developers DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 86510037SARM gem5 Developers miscRegName[misc_reg], newVal); 86610037SARM gem5 Developers } 86710037SARM gem5 Developers break; 86810037SARM gem5 Developers case MISCREG_CPTR_EL2: 86910037SARM gem5 Developers { 87010037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 87110037SARM gem5 Developers CPTR cptrMask = 0; 87210037SARM gem5 Developers cptrMask.tcpac = ones; 87310037SARM gem5 Developers cptrMask.tta = ones; 87410037SARM gem5 Developers cptrMask.tfp = ones; 87510037SARM gem5 Developers newVal &= cptrMask; 87610037SARM gem5 Developers cptrMask = 0; 87710037SARM gem5 Developers cptrMask.res1_13_12_el2 = ones; 87810037SARM gem5 Developers cptrMask.res1_9_0_el2 = ones; 87910037SARM gem5 Developers newVal |= cptrMask; 88010037SARM gem5 Developers DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 88110037SARM gem5 Developers miscRegName[misc_reg], newVal); 88210037SARM gem5 Developers } 88310037SARM gem5 Developers break; 88410037SARM gem5 Developers case MISCREG_CPTR_EL3: 88510037SARM gem5 Developers { 88610037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 88710037SARM gem5 Developers CPTR cptrMask = 0; 88810037SARM gem5 Developers cptrMask.tcpac = ones; 88910037SARM gem5 Developers cptrMask.tta = ones; 89010037SARM gem5 Developers cptrMask.tfp = ones; 89110037SARM gem5 Developers newVal &= cptrMask; 8928206SWilliam.Wang@arm.com DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 8938206SWilliam.Wang@arm.com miscRegName[misc_reg], newVal); 8947408Sgblack@eecs.umich.edu } 8957408Sgblack@eecs.umich.edu break; 8967408Sgblack@eecs.umich.edu case MISCREG_CSSELR: 8977731SAli.Saidi@ARM.com warn_once("The csselr register isn't implemented.\n"); 8988206SWilliam.Wang@arm.com return; 89910037SARM gem5 Developers 90010037SARM gem5 Developers case MISCREG_DC_ZVA_Xt: 90110037SARM gem5 Developers warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n"); 90210037SARM gem5 Developers return; 90310037SARM gem5 Developers 9047408Sgblack@eecs.umich.edu case MISCREG_FPSCR: 9057408Sgblack@eecs.umich.edu { 9067408Sgblack@eecs.umich.edu const uint32_t ones = (uint32_t)(-1); 9077408Sgblack@eecs.umich.edu FPSCR fpscrMask = 0; 9087408Sgblack@eecs.umich.edu fpscrMask.ioc = ones; 9097408Sgblack@eecs.umich.edu fpscrMask.dzc = ones; 9107408Sgblack@eecs.umich.edu fpscrMask.ofc = ones; 9117408Sgblack@eecs.umich.edu fpscrMask.ufc = ones; 9127408Sgblack@eecs.umich.edu fpscrMask.ixc = ones; 9137408Sgblack@eecs.umich.edu fpscrMask.idc = ones; 91410037SARM gem5 Developers fpscrMask.ioe = ones; 91510037SARM gem5 Developers fpscrMask.dze = ones; 91610037SARM gem5 Developers fpscrMask.ofe = ones; 91710037SARM gem5 Developers fpscrMask.ufe = ones; 91810037SARM gem5 Developers fpscrMask.ixe = ones; 91910037SARM gem5 Developers fpscrMask.ide = ones; 9207408Sgblack@eecs.umich.edu fpscrMask.len = ones; 9217408Sgblack@eecs.umich.edu fpscrMask.stride = ones; 9227408Sgblack@eecs.umich.edu fpscrMask.rMode = ones; 9237408Sgblack@eecs.umich.edu fpscrMask.fz = ones; 9247408Sgblack@eecs.umich.edu fpscrMask.dn = ones; 9257408Sgblack@eecs.umich.edu fpscrMask.ahp = ones; 9267408Sgblack@eecs.umich.edu fpscrMask.qc = ones; 9277408Sgblack@eecs.umich.edu fpscrMask.v = ones; 9287408Sgblack@eecs.umich.edu fpscrMask.c = ones; 9297408Sgblack@eecs.umich.edu fpscrMask.z = ones; 9307408Sgblack@eecs.umich.edu fpscrMask.n = ones; 9317408Sgblack@eecs.umich.edu newVal = (newVal & (uint32_t)fpscrMask) | 93210037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPSCR) & 93310037SARM gem5 Developers ~(uint32_t)fpscrMask); 9349377Sgblack@eecs.umich.edu tc->getDecoderPtr()->setContext(newVal); 9357408Sgblack@eecs.umich.edu } 9367408Sgblack@eecs.umich.edu break; 93710037SARM gem5 Developers case MISCREG_FPSR: 93810037SARM gem5 Developers { 93910037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 94010037SARM gem5 Developers FPSCR fpscrMask = 0; 94110037SARM gem5 Developers fpscrMask.ioc = ones; 94210037SARM gem5 Developers fpscrMask.dzc = ones; 94310037SARM gem5 Developers fpscrMask.ofc = ones; 94410037SARM gem5 Developers fpscrMask.ufc = ones; 94510037SARM gem5 Developers fpscrMask.ixc = ones; 94610037SARM gem5 Developers fpscrMask.idc = ones; 94710037SARM gem5 Developers fpscrMask.qc = ones; 94810037SARM gem5 Developers fpscrMask.v = ones; 94910037SARM gem5 Developers fpscrMask.c = ones; 95010037SARM gem5 Developers fpscrMask.z = ones; 95110037SARM gem5 Developers fpscrMask.n = ones; 95210037SARM gem5 Developers newVal = (newVal & (uint32_t)fpscrMask) | 95310037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPSCR) & 95410037SARM gem5 Developers ~(uint32_t)fpscrMask); 95510037SARM gem5 Developers misc_reg = MISCREG_FPSCR; 95610037SARM gem5 Developers } 95710037SARM gem5 Developers break; 95810037SARM gem5 Developers case MISCREG_FPCR: 95910037SARM gem5 Developers { 96010037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 96110037SARM gem5 Developers FPSCR fpscrMask = 0; 96210037SARM gem5 Developers fpscrMask.ioe = ones; 96310037SARM gem5 Developers fpscrMask.dze = ones; 96410037SARM gem5 Developers fpscrMask.ofe = ones; 96510037SARM gem5 Developers fpscrMask.ufe = ones; 96610037SARM gem5 Developers fpscrMask.ixe = ones; 96710037SARM gem5 Developers fpscrMask.ide = ones; 96810037SARM gem5 Developers fpscrMask.len = ones; 96910037SARM gem5 Developers fpscrMask.stride = ones; 97010037SARM gem5 Developers fpscrMask.rMode = ones; 97110037SARM gem5 Developers fpscrMask.fz = ones; 97210037SARM gem5 Developers fpscrMask.dn = ones; 97310037SARM gem5 Developers fpscrMask.ahp = ones; 97410037SARM gem5 Developers newVal = (newVal & (uint32_t)fpscrMask) | 97510037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPSCR) & 97610037SARM gem5 Developers ~(uint32_t)fpscrMask); 97710037SARM gem5 Developers misc_reg = MISCREG_FPSCR; 97810037SARM gem5 Developers } 97910037SARM gem5 Developers break; 9808302SAli.Saidi@ARM.com case MISCREG_CPSR_Q: 9818302SAli.Saidi@ARM.com { 9828302SAli.Saidi@ARM.com assert(!(newVal & ~CpsrMaskQ)); 98310037SARM gem5 Developers newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal; 9848302SAli.Saidi@ARM.com misc_reg = MISCREG_CPSR; 9858302SAli.Saidi@ARM.com } 9868302SAli.Saidi@ARM.com break; 9877783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_QC: 9887783SGiacomo.Gabrielli@arm.com { 98910037SARM gem5 Developers newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 99010037SARM gem5 Developers (newVal & FpscrQcMask); 9917783SGiacomo.Gabrielli@arm.com misc_reg = MISCREG_FPSCR; 9927783SGiacomo.Gabrielli@arm.com } 9937783SGiacomo.Gabrielli@arm.com break; 9947783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_EXC: 9957783SGiacomo.Gabrielli@arm.com { 99610037SARM gem5 Developers newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 99710037SARM gem5 Developers (newVal & FpscrExcMask); 9987783SGiacomo.Gabrielli@arm.com misc_reg = MISCREG_FPSCR; 9997783SGiacomo.Gabrielli@arm.com } 10007783SGiacomo.Gabrielli@arm.com break; 10017408Sgblack@eecs.umich.edu case MISCREG_FPEXC: 10027408Sgblack@eecs.umich.edu { 10038206SWilliam.Wang@arm.com // vfpv3 architecture, section B.6.1 of DDI04068 10048206SWilliam.Wang@arm.com // bit 29 - valid only if fpexc[31] is 0 10057408Sgblack@eecs.umich.edu const uint32_t fpexcMask = 0x60000000; 10067408Sgblack@eecs.umich.edu newVal = (newVal & fpexcMask) | 100710037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask); 10087408Sgblack@eecs.umich.edu } 10097408Sgblack@eecs.umich.edu break; 101010037SARM gem5 Developers case MISCREG_HCR: 101110037SARM gem5 Developers { 101210037SARM gem5 Developers if (!haveVirtualization) 101310037SARM gem5 Developers return; 101410037SARM gem5 Developers } 101510037SARM gem5 Developers break; 101610037SARM gem5 Developers case MISCREG_IFSR: 101710037SARM gem5 Developers { 101810037SARM gem5 Developers // ARM ARM (ARM DDI 0406C.b) B4.1.96 101910037SARM gem5 Developers const uint32_t ifsrMask = 102010037SARM gem5 Developers mask(31, 13) | mask(11, 11) | mask(8, 6); 102110037SARM gem5 Developers newVal = newVal & ~ifsrMask; 102210037SARM gem5 Developers } 102310037SARM gem5 Developers break; 102410037SARM gem5 Developers case MISCREG_DFSR: 102510037SARM gem5 Developers { 102610037SARM gem5 Developers // ARM ARM (ARM DDI 0406C.b) B4.1.52 102710037SARM gem5 Developers const uint32_t dfsrMask = mask(31, 14) | mask(8, 8); 102810037SARM gem5 Developers newVal = newVal & ~dfsrMask; 102910037SARM gem5 Developers } 103010037SARM gem5 Developers break; 103110037SARM gem5 Developers case MISCREG_AMAIR0: 103210037SARM gem5 Developers case MISCREG_AMAIR1: 103310037SARM gem5 Developers { 103410037SARM gem5 Developers // ARM ARM (ARM DDI 0406C.b) B4.1.5 103510037SARM gem5 Developers // Valid only with LPAE 103610037SARM gem5 Developers if (!haveLPAE) 103710037SARM gem5 Developers return; 103810037SARM gem5 Developers DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal); 103910037SARM gem5 Developers } 104010037SARM gem5 Developers break; 104110037SARM gem5 Developers case MISCREG_SCR: 104210037SARM gem5 Developers tc->getITBPtr()->invalidateMiscReg(); 104310037SARM gem5 Developers tc->getDTBPtr()->invalidateMiscReg(); 104410037SARM gem5 Developers break; 10457408Sgblack@eecs.umich.edu case MISCREG_SCTLR: 10467408Sgblack@eecs.umich.edu { 10477408Sgblack@eecs.umich.edu DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal); 104810037SARM gem5 Developers MiscRegIndex sctlr_idx; 104910037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 105010037SARM gem5 Developers if (haveSecurity && !scr.ns) { 105110037SARM gem5 Developers sctlr_idx = MISCREG_SCTLR_S; 105210037SARM gem5 Developers } else { 105310037SARM gem5 Developers sctlr_idx = MISCREG_SCTLR_NS; 105410037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions 105510037SARM gem5 Developers // of the register, we store this in the secure copy of 105610037SARM gem5 Developers // the reg 105710037SARM gem5 Developers miscRegs[MISCREG_SCTLR_S] &= ~(1 << 21); 105810037SARM gem5 Developers miscRegs[MISCREG_SCTLR_S] |= newVal & (1 << 21); 105910037SARM gem5 Developers } 106010037SARM gem5 Developers SCTLR sctlr = miscRegs[sctlr_idx]; 10617408Sgblack@eecs.umich.edu SCTLR new_sctlr = newVal; 106210037SARM gem5 Developers new_sctlr.nmfi = ((bool)sctlr.nmfi) && !haveVirtualization; 106310037SARM gem5 Developers miscRegs[sctlr_idx] = (MiscReg)new_sctlr; 10647749SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 10657749SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 10667408Sgblack@eecs.umich.edu } 10679385SAndreas.Sandberg@arm.com case MISCREG_MIDR: 10689385SAndreas.Sandberg@arm.com case MISCREG_ID_PFR0: 10699385SAndreas.Sandberg@arm.com case MISCREG_ID_PFR1: 107010461SAndreas.Sandberg@ARM.com case MISCREG_ID_DFR0: 10719385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR0: 10729385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR1: 10739385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR2: 10749385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR3: 10759385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR0: 10769385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR1: 10779385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR2: 10789385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR3: 10799385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR4: 10809385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR5: 10819385SAndreas.Sandberg@arm.com 10829385SAndreas.Sandberg@arm.com case MISCREG_MPIDR: 10839385SAndreas.Sandberg@arm.com case MISCREG_FPSID: 10847408Sgblack@eecs.umich.edu case MISCREG_TLBTR: 10857408Sgblack@eecs.umich.edu case MISCREG_MVFR0: 10867408Sgblack@eecs.umich.edu case MISCREG_MVFR1: 108710037SARM gem5 Developers 108810037SARM gem5 Developers case MISCREG_ID_AA64AFR0_EL1: 108910037SARM gem5 Developers case MISCREG_ID_AA64AFR1_EL1: 109010037SARM gem5 Developers case MISCREG_ID_AA64DFR0_EL1: 109110037SARM gem5 Developers case MISCREG_ID_AA64DFR1_EL1: 109210037SARM gem5 Developers case MISCREG_ID_AA64ISAR0_EL1: 109310037SARM gem5 Developers case MISCREG_ID_AA64ISAR1_EL1: 109410037SARM gem5 Developers case MISCREG_ID_AA64MMFR0_EL1: 109510037SARM gem5 Developers case MISCREG_ID_AA64MMFR1_EL1: 109610037SARM gem5 Developers case MISCREG_ID_AA64PFR0_EL1: 109710037SARM gem5 Developers case MISCREG_ID_AA64PFR1_EL1: 10989385SAndreas.Sandberg@arm.com // ID registers are constants. 10997408Sgblack@eecs.umich.edu return; 11009385SAndreas.Sandberg@arm.com 110110037SARM gem5 Developers // TLBI all entries, EL0&1 inner sharable (ignored) 11027408Sgblack@eecs.umich.edu case MISCREG_TLBIALLIS: 110310037SARM gem5 Developers case MISCREG_TLBIALL: // TLBI all entries, EL0&1, 110410037SARM gem5 Developers assert32(tc); 110510037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 110610037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 110710037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 11088284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 11098284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 11108284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 11118284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 111210037SARM gem5 Developers oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el); 111310037SARM gem5 Developers oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el); 11148887Sgeoffrey.blake@arm.com 11158887Sgeoffrey.blake@arm.com // If CheckerCPU is connected, need to notify it of a flush 11168887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 11178733Sgeoffrey.blake@arm.com if (checker) { 111810037SARM gem5 Developers checker->getITBPtr()->flushAllSecurity(secure_lookup, 111910037SARM gem5 Developers target_el); 112010037SARM gem5 Developers checker->getDTBPtr()->flushAllSecurity(secure_lookup, 112110037SARM gem5 Developers target_el); 11228733Sgeoffrey.blake@arm.com } 11238284SAli.Saidi@ARM.com } 11247408Sgblack@eecs.umich.edu return; 112510037SARM gem5 Developers // TLBI all entries, EL0&1, instruction side 11267408Sgblack@eecs.umich.edu case MISCREG_ITLBIALL: 112710037SARM gem5 Developers assert32(tc); 112810037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 112910037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 113010037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 113110037SARM gem5 Developers tc->getITBPtr()->flushAllSecurity(secure_lookup, target_el); 11327408Sgblack@eecs.umich.edu return; 113310037SARM gem5 Developers // TLBI all entries, EL0&1, data side 11347408Sgblack@eecs.umich.edu case MISCREG_DTLBIALL: 113510037SARM gem5 Developers assert32(tc); 113610037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 113710037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 113810037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 113910037SARM gem5 Developers tc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el); 11407408Sgblack@eecs.umich.edu return; 114110037SARM gem5 Developers // TLBI based on VA, EL0&1 inner sharable (ignored) 11427408Sgblack@eecs.umich.edu case MISCREG_TLBIMVAIS: 11437408Sgblack@eecs.umich.edu case MISCREG_TLBIMVA: 114410037SARM gem5 Developers assert32(tc); 114510037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 114610037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 114710037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 11488284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 11498284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 11508284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 11518284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 11528284SAli.Saidi@ARM.com oc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 115310037SARM gem5 Developers bits(newVal, 7,0), 115410037SARM gem5 Developers secure_lookup, target_el); 11558284SAli.Saidi@ARM.com oc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 115610037SARM gem5 Developers bits(newVal, 7,0), 115710037SARM gem5 Developers secure_lookup, target_el); 11588887Sgeoffrey.blake@arm.com 11598887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 11608733Sgeoffrey.blake@arm.com if (checker) { 11618733Sgeoffrey.blake@arm.com checker->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 116210037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 11638733Sgeoffrey.blake@arm.com checker->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 116410037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 11658733Sgeoffrey.blake@arm.com } 11668284SAli.Saidi@ARM.com } 11677408Sgblack@eecs.umich.edu return; 116810037SARM gem5 Developers // TLBI by ASID, EL0&1, inner sharable 11697408Sgblack@eecs.umich.edu case MISCREG_TLBIASIDIS: 11707408Sgblack@eecs.umich.edu case MISCREG_TLBIASID: 117110037SARM gem5 Developers assert32(tc); 117210037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 117310037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 117410037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 11758284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 11768284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 11778284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 11788284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 117910037SARM gem5 Developers oc->getITBPtr()->flushAsid(bits(newVal, 7,0), 118010037SARM gem5 Developers secure_lookup, target_el); 118110037SARM gem5 Developers oc->getDTBPtr()->flushAsid(bits(newVal, 7,0), 118210037SARM gem5 Developers secure_lookup, target_el); 11838887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 11848733Sgeoffrey.blake@arm.com if (checker) { 118510037SARM gem5 Developers checker->getITBPtr()->flushAsid(bits(newVal, 7,0), 118610037SARM gem5 Developers secure_lookup, target_el); 118710037SARM gem5 Developers checker->getDTBPtr()->flushAsid(bits(newVal, 7,0), 118810037SARM gem5 Developers secure_lookup, target_el); 11898733Sgeoffrey.blake@arm.com } 11908284SAli.Saidi@ARM.com } 11917408Sgblack@eecs.umich.edu return; 119210037SARM gem5 Developers // TLBI by address, EL0&1, inner sharable (ignored) 11937408Sgblack@eecs.umich.edu case MISCREG_TLBIMVAAIS: 11947408Sgblack@eecs.umich.edu case MISCREG_TLBIMVAA: 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; 119910037SARM gem5 Developers hyp = 0; 120010037SARM gem5 Developers tlbiMVA(tc, newVal, secure_lookup, hyp, target_el); 120110037SARM gem5 Developers return; 120210037SARM gem5 Developers // TLBI by address, EL2, hypervisor mode 120310037SARM gem5 Developers case MISCREG_TLBIMVAH: 120410037SARM gem5 Developers case MISCREG_TLBIMVAHIS: 120510037SARM gem5 Developers assert32(tc); 120610037SARM gem5 Developers target_el = 1; // aarch32, use hyp bit 120710037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 120810037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 120910037SARM gem5 Developers hyp = 1; 121010037SARM gem5 Developers tlbiMVA(tc, newVal, secure_lookup, hyp, target_el); 121110037SARM gem5 Developers return; 121210037SARM gem5 Developers // TLBI by address and asid, EL0&1, instruction side only 121310037SARM gem5 Developers case MISCREG_ITLBIMVA: 121410037SARM gem5 Developers assert32(tc); 121510037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 121610037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 121710037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 121810037SARM gem5 Developers tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 121910037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 122010037SARM gem5 Developers return; 122110037SARM gem5 Developers // TLBI by address and asid, EL0&1, data side only 122210037SARM gem5 Developers case MISCREG_DTLBIMVA: 122310037SARM gem5 Developers assert32(tc); 122410037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 122510037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 122610037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 122710037SARM gem5 Developers tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 122810037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 122910037SARM gem5 Developers return; 123010037SARM gem5 Developers // TLBI by ASID, EL0&1, instrution side only 123110037SARM gem5 Developers case MISCREG_ITLBIASID: 123210037SARM gem5 Developers assert32(tc); 123310037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 123410037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 123510037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 123610037SARM gem5 Developers tc->getITBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup, 123710037SARM gem5 Developers target_el); 123810037SARM gem5 Developers return; 123910037SARM gem5 Developers // TLBI by ASID EL0&1 data size only 124010037SARM gem5 Developers case MISCREG_DTLBIASID: 124110037SARM gem5 Developers assert32(tc); 124210037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 124310037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 124410037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 124510037SARM gem5 Developers tc->getDTBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup, 124610037SARM gem5 Developers target_el); 124710037SARM gem5 Developers return; 124810037SARM gem5 Developers // Invalidate entire Non-secure Hyp/Non-Hyp Unified TLB 124910037SARM gem5 Developers case MISCREG_TLBIALLNSNH: 125010037SARM gem5 Developers case MISCREG_TLBIALLNSNHIS: 125110037SARM gem5 Developers assert32(tc); 125210037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 125310037SARM gem5 Developers hyp = 0; 125410037SARM gem5 Developers tlbiALLN(tc, hyp, target_el); 125510037SARM gem5 Developers return; 125610037SARM gem5 Developers // TLBI all entries, EL2, hyp, 125710037SARM gem5 Developers case MISCREG_TLBIALLH: 125810037SARM gem5 Developers case MISCREG_TLBIALLHIS: 125910037SARM gem5 Developers assert32(tc); 126010037SARM gem5 Developers target_el = 1; // aarch32, use hyp bit 126110037SARM gem5 Developers hyp = 1; 126210037SARM gem5 Developers tlbiALLN(tc, hyp, target_el); 126310037SARM gem5 Developers return; 126410037SARM gem5 Developers // AArch64 TLBI: invalidate all entries EL3 126510037SARM gem5 Developers case MISCREG_TLBI_ALLE3IS: 126610037SARM gem5 Developers case MISCREG_TLBI_ALLE3: 126710037SARM gem5 Developers assert64(tc); 126810037SARM gem5 Developers target_el = 3; 126910037SARM gem5 Developers secure_lookup = true; 127010037SARM gem5 Developers tlbiALL(tc, secure_lookup, target_el); 127110037SARM gem5 Developers return; 127210037SARM gem5 Developers // @todo: uncomment this to enable Virtualization 127310037SARM gem5 Developers // case MISCREG_TLBI_ALLE2IS: 127410037SARM gem5 Developers // case MISCREG_TLBI_ALLE2: 127510037SARM gem5 Developers // TLBI all entries, EL0&1 127610037SARM gem5 Developers case MISCREG_TLBI_ALLE1IS: 127710037SARM gem5 Developers case MISCREG_TLBI_ALLE1: 127810037SARM gem5 Developers // AArch64 TLBI: invalidate all entries, stage 1, current VMID 127910037SARM gem5 Developers case MISCREG_TLBI_VMALLE1IS: 128010037SARM gem5 Developers case MISCREG_TLBI_VMALLE1: 128110037SARM gem5 Developers // AArch64 TLBI: invalidate all entries, stages 1 & 2, current VMID 128210037SARM gem5 Developers case MISCREG_TLBI_VMALLS12E1IS: 128310037SARM gem5 Developers case MISCREG_TLBI_VMALLS12E1: 128410037SARM gem5 Developers // @todo: handle VMID and stage 2 to enable Virtualization 128510037SARM gem5 Developers assert64(tc); 128610037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 128710037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 128810037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 128910037SARM gem5 Developers tlbiALL(tc, secure_lookup, target_el); 129010037SARM gem5 Developers return; 129110037SARM gem5 Developers // AArch64 TLBI: invalidate by VA and ASID, stage 1, current VMID 129210037SARM gem5 Developers // VAEx(IS) and VALEx(IS) are the same because TLBs only store entries 129310037SARM gem5 Developers // from the last level of translation table walks 129410037SARM gem5 Developers // @todo: handle VMID to enable Virtualization 129510037SARM gem5 Developers // TLBI all entries, EL0&1 129610037SARM gem5 Developers case MISCREG_TLBI_VAE3IS_Xt: 129710037SARM gem5 Developers case MISCREG_TLBI_VAE3_Xt: 129810037SARM gem5 Developers // TLBI by VA, EL3 regime stage 1, last level walk 129910037SARM gem5 Developers case MISCREG_TLBI_VALE3IS_Xt: 130010037SARM gem5 Developers case MISCREG_TLBI_VALE3_Xt: 130110037SARM gem5 Developers assert64(tc); 130210037SARM gem5 Developers target_el = 3; 130310037SARM gem5 Developers asid = 0xbeef; // does not matter, tlbi is global 130410037SARM gem5 Developers secure_lookup = true; 130510037SARM gem5 Developers tlbiVA(tc, newVal, asid, secure_lookup, target_el); 130610037SARM gem5 Developers return; 130710037SARM gem5 Developers // TLBI by VA, EL2 130810037SARM gem5 Developers case MISCREG_TLBI_VAE2IS_Xt: 130910037SARM gem5 Developers case MISCREG_TLBI_VAE2_Xt: 131010037SARM gem5 Developers // TLBI by VA, EL2, stage1 last level walk 131110037SARM gem5 Developers case MISCREG_TLBI_VALE2IS_Xt: 131210037SARM gem5 Developers case MISCREG_TLBI_VALE2_Xt: 131310037SARM gem5 Developers assert64(tc); 131410037SARM gem5 Developers target_el = 2; 131510037SARM gem5 Developers asid = 0xbeef; // does not matter, tlbi is global 131610037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 131710037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 131810037SARM gem5 Developers tlbiVA(tc, newVal, asid, secure_lookup, target_el); 131910037SARM gem5 Developers return; 132010037SARM gem5 Developers // TLBI by VA EL1 & 0, stage1, ASID, current VMID 132110037SARM gem5 Developers case MISCREG_TLBI_VAE1IS_Xt: 132210037SARM gem5 Developers case MISCREG_TLBI_VAE1_Xt: 132310037SARM gem5 Developers case MISCREG_TLBI_VALE1IS_Xt: 132410037SARM gem5 Developers case MISCREG_TLBI_VALE1_Xt: 132510037SARM gem5 Developers assert64(tc); 132610037SARM gem5 Developers asid = bits(newVal, 63, 48); 132710037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 132810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 132910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 133010037SARM gem5 Developers tlbiVA(tc, newVal, asid, secure_lookup, target_el); 133110037SARM gem5 Developers return; 133210037SARM gem5 Developers // AArch64 TLBI: invalidate by ASID, stage 1, current VMID 133310037SARM gem5 Developers // @todo: handle VMID to enable Virtualization 133410037SARM gem5 Developers case MISCREG_TLBI_ASIDE1IS_Xt: 133510037SARM gem5 Developers case MISCREG_TLBI_ASIDE1_Xt: 133610037SARM gem5 Developers assert64(tc); 133710037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 133810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 133910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 13408284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 13418284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 13428284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 13438284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 134410037SARM gem5 Developers asid = bits(newVal, 63, 48); 134510709SAndreas.Sandberg@ARM.com if (!haveLargeAsid64) 134610037SARM gem5 Developers asid &= mask(8); 134710037SARM gem5 Developers oc->getITBPtr()->flushAsid(asid, secure_lookup, target_el); 134810037SARM gem5 Developers oc->getDTBPtr()->flushAsid(asid, secure_lookup, target_el); 134910037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 135010037SARM gem5 Developers if (checker) { 135110037SARM gem5 Developers checker->getITBPtr()->flushAsid(asid, 135210037SARM gem5 Developers secure_lookup, target_el); 135310037SARM gem5 Developers checker->getDTBPtr()->flushAsid(asid, 135410037SARM gem5 Developers secure_lookup, target_el); 135510037SARM gem5 Developers } 135610037SARM gem5 Developers } 135710037SARM gem5 Developers return; 135810037SARM gem5 Developers // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID 135910037SARM gem5 Developers // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store 136010037SARM gem5 Developers // entries from the last level of translation table walks 136110037SARM gem5 Developers // @todo: handle VMID to enable Virtualization 136210037SARM gem5 Developers case MISCREG_TLBI_VAAE1IS_Xt: 136310037SARM gem5 Developers case MISCREG_TLBI_VAAE1_Xt: 136410037SARM gem5 Developers case MISCREG_TLBI_VAALE1IS_Xt: 136510037SARM gem5 Developers case MISCREG_TLBI_VAALE1_Xt: 136610037SARM gem5 Developers assert64(tc); 136710037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 136810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 136910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 137010037SARM gem5 Developers sys = tc->getSystemPtr(); 137110037SARM gem5 Developers for (x = 0; x < sys->numContexts(); x++) { 137210037SARM gem5 Developers // @todo: extra controls on TLBI broadcast? 137310037SARM gem5 Developers oc = sys->getThreadContext(x); 137410037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 137510037SARM gem5 Developers Addr va = ((Addr) bits(newVal, 43, 0)) << 12; 137610037SARM gem5 Developers oc->getITBPtr()->flushMva(va, 137710037SARM gem5 Developers secure_lookup, false, target_el); 137810037SARM gem5 Developers oc->getDTBPtr()->flushMva(va, 137910037SARM gem5 Developers secure_lookup, false, target_el); 13808887Sgeoffrey.blake@arm.com 13818887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 13828733Sgeoffrey.blake@arm.com if (checker) { 138310037SARM gem5 Developers checker->getITBPtr()->flushMva(va, 138410037SARM gem5 Developers secure_lookup, false, target_el); 138510037SARM gem5 Developers checker->getDTBPtr()->flushMva(va, 138610037SARM gem5 Developers secure_lookup, false, target_el); 13878733Sgeoffrey.blake@arm.com } 13888284SAli.Saidi@ARM.com } 13897408Sgblack@eecs.umich.edu return; 139010037SARM gem5 Developers // AArch64 TLBI: invalidate by IPA, stage 2, current VMID 139110037SARM gem5 Developers case MISCREG_TLBI_IPAS2LE1IS_Xt: 139210037SARM gem5 Developers case MISCREG_TLBI_IPAS2LE1_Xt: 139310037SARM gem5 Developers case MISCREG_TLBI_IPAS2E1IS_Xt: 139410037SARM gem5 Developers case MISCREG_TLBI_IPAS2E1_Xt: 139510037SARM gem5 Developers assert64(tc); 139610037SARM gem5 Developers // @todo: implement these as part of Virtualization 139710037SARM gem5 Developers warn("Not doing anything for write of miscreg ITLB_IPAS2\n"); 13987405SAli.Saidi@ARM.com return; 13997583SAli.Saidi@arm.com case MISCREG_ACTLR: 14007583SAli.Saidi@arm.com warn("Not doing anything for write of miscreg ACTLR\n"); 14017583SAli.Saidi@arm.com break; 140210461SAndreas.Sandberg@ARM.com 140310461SAndreas.Sandberg@ARM.com case MISCREG_PMXEVTYPER_PMCCFILTR: 140410461SAndreas.Sandberg@ARM.com case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 140510461SAndreas.Sandberg@ARM.com case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 140610461SAndreas.Sandberg@ARM.com case MISCREG_PMCR ... MISCREG_PMOVSSET: 140710461SAndreas.Sandberg@ARM.com pmu->setMiscReg(misc_reg, newVal); 14087583SAli.Saidi@arm.com break; 140910461SAndreas.Sandberg@ARM.com 141010461SAndreas.Sandberg@ARM.com 141110037SARM gem5 Developers case MISCREG_HSTR: // TJDBX, now redifined to be RES0 141210037SARM gem5 Developers { 141310037SARM gem5 Developers HSTR hstrMask = 0; 141410037SARM gem5 Developers hstrMask.tjdbx = 1; 141510037SARM gem5 Developers newVal &= ~((uint32_t) hstrMask); 141610037SARM gem5 Developers break; 141710037SARM gem5 Developers } 141810037SARM gem5 Developers case MISCREG_HCPTR: 141910037SARM gem5 Developers { 142010037SARM gem5 Developers // If a CP bit in NSACR is 0 then the corresponding bit in 142110037SARM gem5 Developers // HCPTR is RAO/WI. Same applies to NSASEDIS 142210037SARM gem5 Developers secure_lookup = haveSecurity && 142310037SARM gem5 Developers inSecureState(readMiscRegNoEffect(MISCREG_SCR), 142410037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR)); 142510037SARM gem5 Developers if (!secure_lookup) { 142610037SARM gem5 Developers MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR); 142710037SARM gem5 Developers MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF; 142810037SARM gem5 Developers newVal = (newVal & ~mask) | (oldValue & mask); 142910037SARM gem5 Developers } 143010037SARM gem5 Developers break; 143110037SARM gem5 Developers } 143210037SARM gem5 Developers case MISCREG_HDFAR: // alias for secure DFAR 143310037SARM gem5 Developers misc_reg = MISCREG_DFAR_S; 143410037SARM gem5 Developers break; 143510037SARM gem5 Developers case MISCREG_HIFAR: // alias for secure IFAR 143610037SARM gem5 Developers misc_reg = MISCREG_IFAR_S; 143710037SARM gem5 Developers break; 143810037SARM gem5 Developers case MISCREG_ATS1CPR: 143910037SARM gem5 Developers case MISCREG_ATS1CPW: 144010037SARM gem5 Developers case MISCREG_ATS1CUR: 144110037SARM gem5 Developers case MISCREG_ATS1CUW: 144210037SARM gem5 Developers case MISCREG_ATS12NSOPR: 144310037SARM gem5 Developers case MISCREG_ATS12NSOPW: 144410037SARM gem5 Developers case MISCREG_ATS12NSOUR: 144510037SARM gem5 Developers case MISCREG_ATS12NSOUW: 144610037SARM gem5 Developers case MISCREG_ATS1HR: 144710037SARM gem5 Developers case MISCREG_ATS1HW: 14487436Sdam.sunwoo@arm.com { 144910037SARM gem5 Developers unsigned flags = 0; 145010037SARM gem5 Developers BaseTLB::Mode mode = BaseTLB::Read; 145110037SARM gem5 Developers TLB::ArmTranslationType tranType = TLB::NormalTran; 14527436Sdam.sunwoo@arm.com Fault fault; 14537436Sdam.sunwoo@arm.com switch(misc_reg) { 145410037SARM gem5 Developers case MISCREG_ATS1CPR: 145510037SARM gem5 Developers flags = TLB::MustBeOne; 145610037SARM gem5 Developers tranType = TLB::S1CTran; 145710037SARM gem5 Developers mode = BaseTLB::Read; 145810037SARM gem5 Developers break; 145910037SARM gem5 Developers case MISCREG_ATS1CPW: 146010037SARM gem5 Developers flags = TLB::MustBeOne; 146110037SARM gem5 Developers tranType = TLB::S1CTran; 146210037SARM gem5 Developers mode = BaseTLB::Write; 146310037SARM gem5 Developers break; 146410037SARM gem5 Developers case MISCREG_ATS1CUR: 146510037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 146610037SARM gem5 Developers tranType = TLB::S1CTran; 146710037SARM gem5 Developers mode = BaseTLB::Read; 146810037SARM gem5 Developers break; 146910037SARM gem5 Developers case MISCREG_ATS1CUW: 147010037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 147110037SARM gem5 Developers tranType = TLB::S1CTran; 147210037SARM gem5 Developers mode = BaseTLB::Write; 147310037SARM gem5 Developers break; 147410037SARM gem5 Developers case MISCREG_ATS12NSOPR: 147510037SARM gem5 Developers if (!haveSecurity) 147610037SARM gem5 Developers panic("Security Extensions required for ATS12NSOPR"); 147710037SARM gem5 Developers flags = TLB::MustBeOne; 147810037SARM gem5 Developers tranType = TLB::S1S2NsTran; 147910037SARM gem5 Developers mode = BaseTLB::Read; 148010037SARM gem5 Developers break; 148110037SARM gem5 Developers case MISCREG_ATS12NSOPW: 148210037SARM gem5 Developers if (!haveSecurity) 148310037SARM gem5 Developers panic("Security Extensions required for ATS12NSOPW"); 148410037SARM gem5 Developers flags = TLB::MustBeOne; 148510037SARM gem5 Developers tranType = TLB::S1S2NsTran; 148610037SARM gem5 Developers mode = BaseTLB::Write; 148710037SARM gem5 Developers break; 148810037SARM gem5 Developers case MISCREG_ATS12NSOUR: 148910037SARM gem5 Developers if (!haveSecurity) 149010037SARM gem5 Developers panic("Security Extensions required for ATS12NSOUR"); 149110037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 149210037SARM gem5 Developers tranType = TLB::S1S2NsTran; 149310037SARM gem5 Developers mode = BaseTLB::Read; 149410037SARM gem5 Developers break; 149510037SARM gem5 Developers case MISCREG_ATS12NSOUW: 149610037SARM gem5 Developers if (!haveSecurity) 149710037SARM gem5 Developers panic("Security Extensions required for ATS12NSOUW"); 149810037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 149910037SARM gem5 Developers tranType = TLB::S1S2NsTran; 150010037SARM gem5 Developers mode = BaseTLB::Write; 150110037SARM gem5 Developers break; 150210037SARM gem5 Developers case MISCREG_ATS1HR: // only really useful from secure mode. 150310037SARM gem5 Developers flags = TLB::MustBeOne; 150410037SARM gem5 Developers tranType = TLB::HypMode; 150510037SARM gem5 Developers mode = BaseTLB::Read; 150610037SARM gem5 Developers break; 150710037SARM gem5 Developers case MISCREG_ATS1HW: 150810037SARM gem5 Developers flags = TLB::MustBeOne; 150910037SARM gem5 Developers tranType = TLB::HypMode; 151010037SARM gem5 Developers mode = BaseTLB::Write; 151110037SARM gem5 Developers break; 15127436Sdam.sunwoo@arm.com } 151310037SARM gem5 Developers // If we're in timing mode then doing the translation in 151410037SARM gem5 Developers // functional mode then we're slightly distorting performance 151510037SARM gem5 Developers // results obtained from simulations. The translation should be 151610037SARM gem5 Developers // done in the same mode the core is running in. NOTE: This 151710037SARM gem5 Developers // can't be an atomic translation because that causes problems 151810037SARM gem5 Developers // with unexpected atomic snoop requests. 151910037SARM gem5 Developers warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 152011560Sandreas.sandberg@arm.com Request req(0, val, 0, flags, Request::funcMasterId, 152111435Smitch.hayenga@arm.com tc->pcState().pc(), tc->contextId()); 152210653Sandreas.hansson@arm.com fault = tc->getDTBPtr()->translateFunctional(&req, tc, mode, tranType); 152310037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 152410037SARM gem5 Developers HCR hcr = readMiscRegNoEffect(MISCREG_HCR); 152510037SARM gem5 Developers 152610037SARM gem5 Developers MiscReg newVal; 15277436Sdam.sunwoo@arm.com if (fault == NoFault) { 152810653Sandreas.hansson@arm.com Addr paddr = req.getPaddr(); 152910037SARM gem5 Developers if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode || 153010037SARM gem5 Developers ((tranType & TLB::S1S2NsTran) && hcr.vm) )) { 153110037SARM gem5 Developers newVal = (paddr & mask(39, 12)) | 153210037SARM gem5 Developers (tc->getDTBPtr()->getAttr()); 153310037SARM gem5 Developers } else { 153410037SARM gem5 Developers newVal = (paddr & 0xfffff000) | 153510037SARM gem5 Developers (tc->getDTBPtr()->getAttr()); 153610037SARM gem5 Developers } 15377436Sdam.sunwoo@arm.com DPRINTF(MiscRegs, 15387436Sdam.sunwoo@arm.com "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n", 153910037SARM gem5 Developers val, newVal); 154010037SARM gem5 Developers } else { 154110037SARM gem5 Developers ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get()); 154210037SARM gem5 Developers // Set fault bit and FSR 154310037SARM gem5 Developers FSR fsr = armFault->getFsr(tc); 154410037SARM gem5 Developers 154510037SARM gem5 Developers newVal = ((fsr >> 9) & 1) << 11; 154610037SARM gem5 Developers if (newVal) { 154710037SARM gem5 Developers // LPAE - rearange fault status 154810037SARM gem5 Developers newVal |= ((fsr >> 0) & 0x3f) << 1; 154910037SARM gem5 Developers } else { 155010037SARM gem5 Developers // VMSA - rearange fault status 155110037SARM gem5 Developers newVal |= ((fsr >> 0) & 0xf) << 1; 155210037SARM gem5 Developers newVal |= ((fsr >> 10) & 0x1) << 5; 155310037SARM gem5 Developers newVal |= ((fsr >> 12) & 0x1) << 6; 155410037SARM gem5 Developers } 155510037SARM gem5 Developers newVal |= 0x1; // F bit 155610037SARM gem5 Developers newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 155710037SARM gem5 Developers newVal |= armFault->isStage2() ? 0x200 : 0; 155810037SARM gem5 Developers DPRINTF(MiscRegs, 155910037SARM gem5 Developers "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n", 156010037SARM gem5 Developers val, fsr, newVal); 15617436Sdam.sunwoo@arm.com } 156210037SARM gem5 Developers setMiscRegNoEffect(MISCREG_PAR, newVal); 15637436Sdam.sunwoo@arm.com return; 15647436Sdam.sunwoo@arm.com } 156510037SARM gem5 Developers case MISCREG_TTBCR: 156610037SARM gem5 Developers { 156710037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 156810037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 156910037SARM gem5 Developers TTBCR ttbcrMask = 0; 157010037SARM gem5 Developers TTBCR ttbcrNew = newVal; 157110037SARM gem5 Developers 157210037SARM gem5 Developers // ARM DDI 0406C.b, ARMv7-32 157310037SARM gem5 Developers ttbcrMask.n = ones; // T0SZ 157410037SARM gem5 Developers if (haveSecurity) { 157510037SARM gem5 Developers ttbcrMask.pd0 = ones; 157610037SARM gem5 Developers ttbcrMask.pd1 = ones; 157710037SARM gem5 Developers } 157810037SARM gem5 Developers ttbcrMask.epd0 = ones; 157910037SARM gem5 Developers ttbcrMask.irgn0 = ones; 158010037SARM gem5 Developers ttbcrMask.orgn0 = ones; 158110037SARM gem5 Developers ttbcrMask.sh0 = ones; 158210037SARM gem5 Developers ttbcrMask.ps = ones; // T1SZ 158310037SARM gem5 Developers ttbcrMask.a1 = ones; 158410037SARM gem5 Developers ttbcrMask.epd1 = ones; 158510037SARM gem5 Developers ttbcrMask.irgn1 = ones; 158610037SARM gem5 Developers ttbcrMask.orgn1 = ones; 158710037SARM gem5 Developers ttbcrMask.sh1 = ones; 158810037SARM gem5 Developers if (haveLPAE) 158910037SARM gem5 Developers ttbcrMask.eae = ones; 159010037SARM gem5 Developers 159110037SARM gem5 Developers if (haveLPAE && ttbcrNew.eae) { 159210037SARM gem5 Developers newVal = newVal & ttbcrMask; 159310037SARM gem5 Developers } else { 159410037SARM gem5 Developers newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask)); 159510037SARM gem5 Developers } 159610037SARM gem5 Developers } 159710037SARM gem5 Developers case MISCREG_TTBR0: 159810037SARM gem5 Developers case MISCREG_TTBR1: 159910037SARM gem5 Developers { 160010037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 160110037SARM gem5 Developers if (haveLPAE) { 160210037SARM gem5 Developers if (ttbcr.eae) { 160310037SARM gem5 Developers // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP 160410037SARM gem5 Developers // ARMv8 AArch32 bit 63-56 only 160510037SARM gem5 Developers uint64_t ttbrMask = mask(63,56) | mask(47,40); 160610037SARM gem5 Developers newVal = (newVal & (~ttbrMask)); 160710037SARM gem5 Developers } 160810037SARM gem5 Developers } 160910037SARM gem5 Developers } 161010508SAli.Saidi@ARM.com case MISCREG_SCTLR_EL1: 161110508SAli.Saidi@ARM.com { 161210508SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 161310508SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 161410508SAli.Saidi@ARM.com setMiscRegNoEffect(misc_reg, newVal); 161510508SAli.Saidi@ARM.com } 16167749SAli.Saidi@ARM.com case MISCREG_CONTEXTIDR: 16177749SAli.Saidi@ARM.com case MISCREG_PRRR: 16187749SAli.Saidi@ARM.com case MISCREG_NMRR: 161910037SARM gem5 Developers case MISCREG_MAIR0: 162010037SARM gem5 Developers case MISCREG_MAIR1: 16217749SAli.Saidi@ARM.com case MISCREG_DACR: 162210037SARM gem5 Developers case MISCREG_VTTBR: 162310037SARM gem5 Developers case MISCREG_SCR_EL3: 162411575SDylan.Johnson@ARM.com case MISCREG_HCR_EL2: 162510037SARM gem5 Developers case MISCREG_TCR_EL1: 162610037SARM gem5 Developers case MISCREG_TCR_EL2: 162710037SARM gem5 Developers case MISCREG_TCR_EL3: 162810508SAli.Saidi@ARM.com case MISCREG_SCTLR_EL2: 162910508SAli.Saidi@ARM.com case MISCREG_SCTLR_EL3: 163011573SDylan.Johnson@ARM.com case MISCREG_HSCTLR: 163110037SARM gem5 Developers case MISCREG_TTBR0_EL1: 163210037SARM gem5 Developers case MISCREG_TTBR1_EL1: 163310037SARM gem5 Developers case MISCREG_TTBR0_EL2: 163410037SARM gem5 Developers case MISCREG_TTBR0_EL3: 16357749SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 16367749SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 16377749SAli.Saidi@ARM.com break; 163810037SARM gem5 Developers case MISCREG_NZCV: 163910037SARM gem5 Developers { 164010037SARM gem5 Developers CPSR cpsr = val; 164110037SARM gem5 Developers 164210338SCurtis.Dunham@arm.com tc->setCCReg(CCREG_NZ, cpsr.nz); 164310338SCurtis.Dunham@arm.com tc->setCCReg(CCREG_C, cpsr.c); 164410338SCurtis.Dunham@arm.com tc->setCCReg(CCREG_V, cpsr.v); 164510037SARM gem5 Developers } 164610037SARM gem5 Developers break; 164710037SARM gem5 Developers case MISCREG_DAIF: 164810037SARM gem5 Developers { 164910037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 165010037SARM gem5 Developers cpsr.daif = (uint8_t) ((CPSR) newVal).daif; 165110037SARM gem5 Developers newVal = cpsr; 165210037SARM gem5 Developers misc_reg = MISCREG_CPSR; 165310037SARM gem5 Developers } 165410037SARM gem5 Developers break; 165510037SARM gem5 Developers case MISCREG_SP_EL0: 165610037SARM gem5 Developers tc->setIntReg(INTREG_SP0, newVal); 165710037SARM gem5 Developers break; 165810037SARM gem5 Developers case MISCREG_SP_EL1: 165910037SARM gem5 Developers tc->setIntReg(INTREG_SP1, newVal); 166010037SARM gem5 Developers break; 166110037SARM gem5 Developers case MISCREG_SP_EL2: 166210037SARM gem5 Developers tc->setIntReg(INTREG_SP2, newVal); 166310037SARM gem5 Developers break; 166410037SARM gem5 Developers case MISCREG_SPSEL: 166510037SARM gem5 Developers { 166610037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 166710037SARM gem5 Developers cpsr.sp = (uint8_t) ((CPSR) newVal).sp; 166810037SARM gem5 Developers newVal = cpsr; 166910037SARM gem5 Developers misc_reg = MISCREG_CPSR; 167010037SARM gem5 Developers } 167110037SARM gem5 Developers break; 167210037SARM gem5 Developers case MISCREG_CURRENTEL: 167310037SARM gem5 Developers { 167410037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 167510037SARM gem5 Developers cpsr.el = (uint8_t) ((CPSR) newVal).el; 167610037SARM gem5 Developers newVal = cpsr; 167710037SARM gem5 Developers misc_reg = MISCREG_CPSR; 167810037SARM gem5 Developers } 167910037SARM gem5 Developers break; 168010037SARM gem5 Developers case MISCREG_AT_S1E1R_Xt: 168110037SARM gem5 Developers case MISCREG_AT_S1E1W_Xt: 168210037SARM gem5 Developers case MISCREG_AT_S1E0R_Xt: 168310037SARM gem5 Developers case MISCREG_AT_S1E0W_Xt: 168410037SARM gem5 Developers case MISCREG_AT_S1E2R_Xt: 168510037SARM gem5 Developers case MISCREG_AT_S1E2W_Xt: 168610037SARM gem5 Developers case MISCREG_AT_S12E1R_Xt: 168710037SARM gem5 Developers case MISCREG_AT_S12E1W_Xt: 168810037SARM gem5 Developers case MISCREG_AT_S12E0R_Xt: 168910037SARM gem5 Developers case MISCREG_AT_S12E0W_Xt: 169010037SARM gem5 Developers case MISCREG_AT_S1E3R_Xt: 169110037SARM gem5 Developers case MISCREG_AT_S1E3W_Xt: 169210037SARM gem5 Developers { 169310037SARM gem5 Developers RequestPtr req = new Request; 169410037SARM gem5 Developers unsigned flags = 0; 169510037SARM gem5 Developers BaseTLB::Mode mode = BaseTLB::Read; 169610037SARM gem5 Developers TLB::ArmTranslationType tranType = TLB::NormalTran; 169710037SARM gem5 Developers Fault fault; 169810037SARM gem5 Developers switch(misc_reg) { 169910037SARM gem5 Developers case MISCREG_AT_S1E1R_Xt: 170010037SARM gem5 Developers flags = TLB::MustBeOne; 170110037SARM gem5 Developers tranType = TLB::S1CTran; 170210037SARM gem5 Developers mode = BaseTLB::Read; 170310037SARM gem5 Developers break; 170410037SARM gem5 Developers case MISCREG_AT_S1E1W_Xt: 170510037SARM gem5 Developers flags = TLB::MustBeOne; 170610037SARM gem5 Developers tranType = TLB::S1CTran; 170710037SARM gem5 Developers mode = BaseTLB::Write; 170810037SARM gem5 Developers break; 170910037SARM gem5 Developers case MISCREG_AT_S1E0R_Xt: 171010037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 171110037SARM gem5 Developers tranType = TLB::S1CTran; 171210037SARM gem5 Developers mode = BaseTLB::Read; 171310037SARM gem5 Developers break; 171410037SARM gem5 Developers case MISCREG_AT_S1E0W_Xt: 171510037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 171610037SARM gem5 Developers tranType = TLB::S1CTran; 171710037SARM gem5 Developers mode = BaseTLB::Write; 171810037SARM gem5 Developers break; 171910037SARM gem5 Developers case MISCREG_AT_S1E2R_Xt: 172010037SARM gem5 Developers flags = TLB::MustBeOne; 172110037SARM gem5 Developers tranType = TLB::HypMode; 172210037SARM gem5 Developers mode = BaseTLB::Read; 172310037SARM gem5 Developers break; 172410037SARM gem5 Developers case MISCREG_AT_S1E2W_Xt: 172510037SARM gem5 Developers flags = TLB::MustBeOne; 172610037SARM gem5 Developers tranType = TLB::HypMode; 172710037SARM gem5 Developers mode = BaseTLB::Write; 172810037SARM gem5 Developers break; 172910037SARM gem5 Developers case MISCREG_AT_S12E0R_Xt: 173010037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 173110037SARM gem5 Developers tranType = TLB::S1S2NsTran; 173210037SARM gem5 Developers mode = BaseTLB::Read; 173310037SARM gem5 Developers break; 173410037SARM gem5 Developers case MISCREG_AT_S12E0W_Xt: 173510037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 173610037SARM gem5 Developers tranType = TLB::S1S2NsTran; 173710037SARM gem5 Developers mode = BaseTLB::Write; 173810037SARM gem5 Developers break; 173910037SARM gem5 Developers case MISCREG_AT_S12E1R_Xt: 174010037SARM gem5 Developers flags = TLB::MustBeOne; 174110037SARM gem5 Developers tranType = TLB::S1S2NsTran; 174210037SARM gem5 Developers mode = BaseTLB::Read; 174310037SARM gem5 Developers break; 174410037SARM gem5 Developers case MISCREG_AT_S12E1W_Xt: 174510037SARM gem5 Developers flags = TLB::MustBeOne; 174610037SARM gem5 Developers tranType = TLB::S1S2NsTran; 174710037SARM gem5 Developers mode = BaseTLB::Write; 174810037SARM gem5 Developers break; 174910037SARM gem5 Developers case MISCREG_AT_S1E3R_Xt: 175010037SARM gem5 Developers flags = TLB::MustBeOne; 175110037SARM gem5 Developers tranType = TLB::HypMode; // There is no TZ mode defined. 175210037SARM gem5 Developers mode = BaseTLB::Read; 175310037SARM gem5 Developers break; 175410037SARM gem5 Developers case MISCREG_AT_S1E3W_Xt: 175510037SARM gem5 Developers flags = TLB::MustBeOne; 175610037SARM gem5 Developers tranType = TLB::HypMode; // There is no TZ mode defined. 175710037SARM gem5 Developers mode = BaseTLB::Write; 175810037SARM gem5 Developers break; 175910037SARM gem5 Developers } 176010037SARM gem5 Developers // If we're in timing mode then doing the translation in 176110037SARM gem5 Developers // functional mode then we're slightly distorting performance 176210037SARM gem5 Developers // results obtained from simulations. The translation should be 176310037SARM gem5 Developers // done in the same mode the core is running in. NOTE: This 176410037SARM gem5 Developers // can't be an atomic translation because that causes problems 176510037SARM gem5 Developers // with unexpected atomic snoop requests. 176610037SARM gem5 Developers warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 176711560Sandreas.sandberg@arm.com req->setVirt(0, val, 0, flags, Request::funcMasterId, 176810037SARM gem5 Developers tc->pcState().pc()); 176911435Smitch.hayenga@arm.com req->setContext(tc->contextId()); 177010037SARM gem5 Developers fault = tc->getDTBPtr()->translateFunctional(req, tc, mode, 177110037SARM gem5 Developers tranType); 177210037SARM gem5 Developers 177310037SARM gem5 Developers MiscReg newVal; 177410037SARM gem5 Developers if (fault == NoFault) { 177510037SARM gem5 Developers Addr paddr = req->getPaddr(); 177610037SARM gem5 Developers uint64_t attr = tc->getDTBPtr()->getAttr(); 177710037SARM gem5 Developers uint64_t attr1 = attr >> 56; 177810037SARM gem5 Developers if (!attr1 || attr1 ==0x44) { 177910037SARM gem5 Developers attr |= 0x100; 178010037SARM gem5 Developers attr &= ~ uint64_t(0x80); 178110037SARM gem5 Developers } 178210037SARM gem5 Developers newVal = (paddr & mask(47, 12)) | attr; 178310037SARM gem5 Developers DPRINTF(MiscRegs, 178410037SARM gem5 Developers "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n", 178510037SARM gem5 Developers val, newVal); 178610037SARM gem5 Developers } else { 178710037SARM gem5 Developers ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get()); 178810037SARM gem5 Developers // Set fault bit and FSR 178910037SARM gem5 Developers FSR fsr = armFault->getFsr(tc); 179010037SARM gem5 Developers 179110037SARM gem5 Developers newVal = ((fsr >> 9) & 1) << 11; 179210037SARM gem5 Developers // rearange fault status 179310037SARM gem5 Developers newVal |= ((fsr >> 0) & 0x3f) << 1; 179410037SARM gem5 Developers newVal |= 0x1; // F bit 179510037SARM gem5 Developers newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 179610037SARM gem5 Developers newVal |= armFault->isStage2() ? 0x200 : 0; 179710037SARM gem5 Developers DPRINTF(MiscRegs, 179810037SARM gem5 Developers "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n", 179910037SARM gem5 Developers val, fsr, newVal); 180010037SARM gem5 Developers } 180110037SARM gem5 Developers delete req; 180210037SARM gem5 Developers setMiscRegNoEffect(MISCREG_PAR_EL1, newVal); 180310037SARM gem5 Developers return; 180410037SARM gem5 Developers } 180510037SARM gem5 Developers case MISCREG_SPSR_EL3: 180610037SARM gem5 Developers case MISCREG_SPSR_EL2: 180710037SARM gem5 Developers case MISCREG_SPSR_EL1: 180810037SARM gem5 Developers // Force bits 23:21 to 0 180910037SARM gem5 Developers newVal = val & ~(0x7 << 21); 181010037SARM gem5 Developers break; 18118549Sdaniel.johnson@arm.com case MISCREG_L2CTLR: 18128549Sdaniel.johnson@arm.com warn("miscreg L2CTLR (%s) written with %#x. ignored...\n", 18138549Sdaniel.johnson@arm.com miscRegName[misc_reg], uint32_t(val)); 181410037SARM gem5 Developers break; 181510037SARM gem5 Developers 181610037SARM gem5 Developers // Generic Timer registers 181710844Sandreas.sandberg@arm.com case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 181810844Sandreas.sandberg@arm.com case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 181910844Sandreas.sandberg@arm.com case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 182010844Sandreas.sandberg@arm.com case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 182110844Sandreas.sandberg@arm.com getGenericTimer(tc).setMiscReg(misc_reg, newVal); 182210037SARM gem5 Developers break; 18237405SAli.Saidi@ARM.com } 18247405SAli.Saidi@ARM.com } 18257405SAli.Saidi@ARM.com setMiscRegNoEffect(misc_reg, newVal); 18267405SAli.Saidi@ARM.com} 18277405SAli.Saidi@ARM.com 182810037SARM gem5 Developersvoid 182910709SAndreas.Sandberg@ARM.comISA::tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid, 183010709SAndreas.Sandberg@ARM.com bool secure_lookup, uint8_t target_el) 183110037SARM gem5 Developers{ 183210709SAndreas.Sandberg@ARM.com if (!haveLargeAsid64) 183310037SARM gem5 Developers asid &= mask(8); 183410037SARM gem5 Developers Addr va = ((Addr) bits(newVal, 43, 0)) << 12; 183510037SARM gem5 Developers System *sys = tc->getSystemPtr(); 183610037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 183710037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 183810037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 183910037SARM gem5 Developers oc->getITBPtr()->flushMvaAsid(va, asid, 184010037SARM gem5 Developers secure_lookup, target_el); 184110037SARM gem5 Developers oc->getDTBPtr()->flushMvaAsid(va, asid, 184210037SARM gem5 Developers secure_lookup, target_el); 184310037SARM gem5 Developers 184410037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 184510037SARM gem5 Developers if (checker) { 184610037SARM gem5 Developers checker->getITBPtr()->flushMvaAsid( 184710037SARM gem5 Developers va, asid, secure_lookup, target_el); 184810037SARM gem5 Developers checker->getDTBPtr()->flushMvaAsid( 184910037SARM gem5 Developers va, asid, secure_lookup, target_el); 185010037SARM gem5 Developers } 185110037SARM gem5 Developers } 185210037SARM gem5 Developers} 185310037SARM gem5 Developers 185410037SARM gem5 Developersvoid 185510037SARM gem5 DevelopersISA::tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el) 185610037SARM gem5 Developers{ 185710037SARM gem5 Developers System *sys = tc->getSystemPtr(); 185810037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 185910037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 186010037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 186110037SARM gem5 Developers oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el); 186210037SARM gem5 Developers oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el); 186310037SARM gem5 Developers 186410037SARM gem5 Developers // If CheckerCPU is connected, need to notify it of a flush 186510037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 186610037SARM gem5 Developers if (checker) { 186710037SARM gem5 Developers checker->getITBPtr()->flushAllSecurity(secure_lookup, 186810037SARM gem5 Developers target_el); 186910037SARM gem5 Developers checker->getDTBPtr()->flushAllSecurity(secure_lookup, 187010037SARM gem5 Developers target_el); 187110037SARM gem5 Developers } 187210037SARM gem5 Developers } 187310037SARM gem5 Developers} 187410037SARM gem5 Developers 187510037SARM gem5 Developersvoid 187610037SARM gem5 DevelopersISA::tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el) 187710037SARM gem5 Developers{ 187810037SARM gem5 Developers System *sys = tc->getSystemPtr(); 187910037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 188010037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 188110037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 188210037SARM gem5 Developers oc->getITBPtr()->flushAllNs(hyp, target_el); 188310037SARM gem5 Developers oc->getDTBPtr()->flushAllNs(hyp, target_el); 188410037SARM gem5 Developers 188510037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 188610037SARM gem5 Developers if (checker) { 188710037SARM gem5 Developers checker->getITBPtr()->flushAllNs(hyp, target_el); 188810037SARM gem5 Developers checker->getDTBPtr()->flushAllNs(hyp, target_el); 188910037SARM gem5 Developers } 189010037SARM gem5 Developers } 189110037SARM gem5 Developers} 189210037SARM gem5 Developers 189310037SARM gem5 Developersvoid 189410037SARM gem5 DevelopersISA::tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, bool hyp, 189510037SARM gem5 Developers uint8_t target_el) 189610037SARM gem5 Developers{ 189710037SARM gem5 Developers System *sys = tc->getSystemPtr(); 189810037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 189910037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 190010037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 190110037SARM gem5 Developers oc->getITBPtr()->flushMva(mbits(newVal, 31,12), 190210037SARM gem5 Developers secure_lookup, hyp, target_el); 190310037SARM gem5 Developers oc->getDTBPtr()->flushMva(mbits(newVal, 31,12), 190410037SARM gem5 Developers secure_lookup, hyp, target_el); 190510037SARM gem5 Developers 190610037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 190710037SARM gem5 Developers if (checker) { 190810037SARM gem5 Developers checker->getITBPtr()->flushMva(mbits(newVal, 31,12), 190910037SARM gem5 Developers secure_lookup, hyp, target_el); 191010037SARM gem5 Developers checker->getDTBPtr()->flushMva(mbits(newVal, 31,12), 191110037SARM gem5 Developers secure_lookup, hyp, target_el); 191210037SARM gem5 Developers } 191310037SARM gem5 Developers } 191410037SARM gem5 Developers} 191510037SARM gem5 Developers 191610844Sandreas.sandberg@arm.comBaseISADevice & 191710844Sandreas.sandberg@arm.comISA::getGenericTimer(ThreadContext *tc) 191810037SARM gem5 Developers{ 191910844Sandreas.sandberg@arm.com // We only need to create an ISA interface the first time we try 192010844Sandreas.sandberg@arm.com // to access the timer. 192110844Sandreas.sandberg@arm.com if (timer) 192210844Sandreas.sandberg@arm.com return *timer.get(); 192310844Sandreas.sandberg@arm.com 192410844Sandreas.sandberg@arm.com assert(system); 192510844Sandreas.sandberg@arm.com GenericTimer *generic_timer(system->getGenericTimer()); 192610844Sandreas.sandberg@arm.com if (!generic_timer) { 192710844Sandreas.sandberg@arm.com panic("Trying to get a generic timer from a system that hasn't " 192810844Sandreas.sandberg@arm.com "been configured to use a generic timer.\n"); 192910037SARM gem5 Developers } 193010037SARM gem5 Developers 193111150Smitch.hayenga@arm.com timer.reset(new GenericTimerISA(*generic_timer, tc->contextId())); 193210844Sandreas.sandberg@arm.com return *timer.get(); 193310037SARM gem5 Developers} 193410037SARM gem5 Developers 19357405SAli.Saidi@ARM.com} 19369384SAndreas.Sandberg@arm.com 19379384SAndreas.Sandberg@arm.comArmISA::ISA * 19389384SAndreas.Sandberg@arm.comArmISAParams::create() 19399384SAndreas.Sandberg@arm.com{ 19409384SAndreas.Sandberg@arm.com return new ArmISA::ISA(this); 19419384SAndreas.Sandberg@arm.com} 1942