isa.cc revision 11150
17405SAli.Saidi@ARM.com/* 210844Sandreas.sandberg@arm.com * Copyright (c) 2010-2015 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), 13010461SAndreas.Sandberg@ARM.com pmu(p->pmu), 13110461SAndreas.Sandberg@ARM.com lookUpMiscReg(NUM_MISCREGS, {0,0}) 1329384SAndreas.Sandberg@arm.com{ 1339384SAndreas.Sandberg@arm.com SCTLR sctlr; 1349384SAndreas.Sandberg@arm.com sctlr = 0; 1359384SAndreas.Sandberg@arm.com miscRegs[MISCREG_SCTLR_RST] = sctlr; 13610037SARM gem5 Developers 13710461SAndreas.Sandberg@ARM.com // Hook up a dummy device if we haven't been configured with a 13810461SAndreas.Sandberg@ARM.com // real PMU. By using a dummy device, we don't need to check that 13910461SAndreas.Sandberg@ARM.com // the PMU exist every time we try to access a PMU register. 14010461SAndreas.Sandberg@ARM.com if (!pmu) 14110461SAndreas.Sandberg@ARM.com pmu = &dummyDevice; 14210461SAndreas.Sandberg@ARM.com 14310609Sandreas.sandberg@arm.com // Give all ISA devices a pointer to this ISA 14410609Sandreas.sandberg@arm.com pmu->setISA(this); 14510609Sandreas.sandberg@arm.com 14610037SARM gem5 Developers system = dynamic_cast<ArmSystem *>(p->system); 14710037SARM gem5 Developers 14810037SARM gem5 Developers // Cache system-level properties 14910037SARM gem5 Developers if (FullSystem && system) { 15010037SARM gem5 Developers haveSecurity = system->haveSecurity(); 15110037SARM gem5 Developers haveLPAE = system->haveLPAE(); 15210037SARM gem5 Developers haveVirtualization = system->haveVirtualization(); 15310037SARM gem5 Developers haveLargeAsid64 = system->haveLargeAsid64(); 15410037SARM gem5 Developers physAddrRange64 = system->physAddrRange64(); 15510037SARM gem5 Developers } else { 15610037SARM gem5 Developers haveSecurity = haveLPAE = haveVirtualization = false; 15710037SARM gem5 Developers haveLargeAsid64 = false; 15810037SARM gem5 Developers physAddrRange64 = 32; // dummy value 15910037SARM gem5 Developers } 16010037SARM gem5 Developers 16110037SARM gem5 Developers /** Fill in the miscReg translation table */ 16210037SARM gem5 Developers for (uint32_t i = 0; i < miscRegTranslateMax; i++) { 16310037SARM gem5 Developers struct MiscRegLUTEntry new_entry; 16410037SARM gem5 Developers 16510037SARM gem5 Developers uint32_t select = MiscRegSwitch[i].index; 16610037SARM gem5 Developers new_entry = MiscRegSwitch[i].entry; 16710037SARM gem5 Developers 16810037SARM gem5 Developers lookUpMiscReg[select] = new_entry; 16910037SARM gem5 Developers } 17010037SARM gem5 Developers 17110037SARM gem5 Developers preUnflattenMiscReg(); 17210037SARM gem5 Developers 1739384SAndreas.Sandberg@arm.com clear(); 1749384SAndreas.Sandberg@arm.com} 1759384SAndreas.Sandberg@arm.com 1769384SAndreas.Sandberg@arm.comconst ArmISAParams * 1779384SAndreas.Sandberg@arm.comISA::params() const 1789384SAndreas.Sandberg@arm.com{ 1799384SAndreas.Sandberg@arm.com return dynamic_cast<const Params *>(_params); 1809384SAndreas.Sandberg@arm.com} 1819384SAndreas.Sandberg@arm.com 1827427Sgblack@eecs.umich.eduvoid 1837427Sgblack@eecs.umich.eduISA::clear() 1847427Sgblack@eecs.umich.edu{ 1859385SAndreas.Sandberg@arm.com const Params *p(params()); 1869385SAndreas.Sandberg@arm.com 1877427Sgblack@eecs.umich.edu SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST]; 1887427Sgblack@eecs.umich.edu memset(miscRegs, 0, sizeof(miscRegs)); 18910037SARM gem5 Developers 19010037SARM gem5 Developers // Initialize configurable default values 19110037SARM gem5 Developers miscRegs[MISCREG_MIDR] = p->midr; 19210037SARM gem5 Developers miscRegs[MISCREG_MIDR_EL1] = p->midr; 19310037SARM gem5 Developers miscRegs[MISCREG_VPIDR] = p->midr; 19410037SARM gem5 Developers 19510037SARM gem5 Developers if (FullSystem && system->highestELIs64()) { 19610037SARM gem5 Developers // Initialize AArch64 state 19710037SARM gem5 Developers clear64(p); 19810037SARM gem5 Developers return; 19910037SARM gem5 Developers } 20010037SARM gem5 Developers 20110037SARM gem5 Developers // Initialize AArch32 state... 20210037SARM gem5 Developers 2037427Sgblack@eecs.umich.edu CPSR cpsr = 0; 2047427Sgblack@eecs.umich.edu cpsr.mode = MODE_USER; 2057427Sgblack@eecs.umich.edu miscRegs[MISCREG_CPSR] = cpsr; 2067427Sgblack@eecs.umich.edu updateRegMap(cpsr); 2077427Sgblack@eecs.umich.edu 2087427Sgblack@eecs.umich.edu SCTLR sctlr = 0; 20910037SARM gem5 Developers sctlr.te = (bool) sctlr_rst.te; 21010037SARM gem5 Developers sctlr.nmfi = (bool) sctlr_rst.nmfi; 21110037SARM gem5 Developers sctlr.v = (bool) sctlr_rst.v; 21210037SARM gem5 Developers sctlr.u = 1; 2137427Sgblack@eecs.umich.edu sctlr.xp = 1; 2147427Sgblack@eecs.umich.edu sctlr.rao2 = 1; 2157427Sgblack@eecs.umich.edu sctlr.rao3 = 1; 21610037SARM gem5 Developers sctlr.rao4 = 0xf; // SCTLR[6:3] 21710204SAli.Saidi@ARM.com sctlr.uci = 1; 21810204SAli.Saidi@ARM.com sctlr.dze = 1; 21910037SARM gem5 Developers miscRegs[MISCREG_SCTLR_NS] = sctlr; 2207427Sgblack@eecs.umich.edu miscRegs[MISCREG_SCTLR_RST] = sctlr_rst; 22110037SARM gem5 Developers miscRegs[MISCREG_HCPTR] = 0; 2227427Sgblack@eecs.umich.edu 22310037SARM gem5 Developers // Start with an event in the mailbox 2247427Sgblack@eecs.umich.edu miscRegs[MISCREG_SEV_MAILBOX] = 1; 2257427Sgblack@eecs.umich.edu 22610037SARM gem5 Developers // Separate Instruction and Data TLBs 2277427Sgblack@eecs.umich.edu miscRegs[MISCREG_TLBTR] = 1; 2287427Sgblack@eecs.umich.edu 2297427Sgblack@eecs.umich.edu MVFR0 mvfr0 = 0; 2307427Sgblack@eecs.umich.edu mvfr0.advSimdRegisters = 2; 2317427Sgblack@eecs.umich.edu mvfr0.singlePrecision = 2; 2327427Sgblack@eecs.umich.edu mvfr0.doublePrecision = 2; 2337427Sgblack@eecs.umich.edu mvfr0.vfpExceptionTrapping = 0; 2347427Sgblack@eecs.umich.edu mvfr0.divide = 1; 2357427Sgblack@eecs.umich.edu mvfr0.squareRoot = 1; 2367427Sgblack@eecs.umich.edu mvfr0.shortVectors = 1; 2377427Sgblack@eecs.umich.edu mvfr0.roundingModes = 1; 2387427Sgblack@eecs.umich.edu miscRegs[MISCREG_MVFR0] = mvfr0; 2397427Sgblack@eecs.umich.edu 2407427Sgblack@eecs.umich.edu MVFR1 mvfr1 = 0; 2417427Sgblack@eecs.umich.edu mvfr1.flushToZero = 1; 2427427Sgblack@eecs.umich.edu mvfr1.defaultNaN = 1; 2437427Sgblack@eecs.umich.edu mvfr1.advSimdLoadStore = 1; 2447427Sgblack@eecs.umich.edu mvfr1.advSimdInteger = 1; 2457427Sgblack@eecs.umich.edu mvfr1.advSimdSinglePrecision = 1; 2467427Sgblack@eecs.umich.edu mvfr1.advSimdHalfPrecision = 1; 2477427Sgblack@eecs.umich.edu mvfr1.vfpHalfPrecision = 1; 2487427Sgblack@eecs.umich.edu miscRegs[MISCREG_MVFR1] = mvfr1; 2497427Sgblack@eecs.umich.edu 2507436Sdam.sunwoo@arm.com // Reset values of PRRR and NMRR are implementation dependent 2517436Sdam.sunwoo@arm.com 25210037SARM gem5 Developers // @todo: PRRR and NMRR in secure state? 25310037SARM gem5 Developers miscRegs[MISCREG_PRRR_NS] = 2547436Sdam.sunwoo@arm.com (1 << 19) | // 19 2557436Sdam.sunwoo@arm.com (0 << 18) | // 18 2567436Sdam.sunwoo@arm.com (0 << 17) | // 17 2577436Sdam.sunwoo@arm.com (1 << 16) | // 16 2587436Sdam.sunwoo@arm.com (2 << 14) | // 15:14 2597436Sdam.sunwoo@arm.com (0 << 12) | // 13:12 2607436Sdam.sunwoo@arm.com (2 << 10) | // 11:10 2617436Sdam.sunwoo@arm.com (2 << 8) | // 9:8 2627436Sdam.sunwoo@arm.com (2 << 6) | // 7:6 2637436Sdam.sunwoo@arm.com (2 << 4) | // 5:4 2647436Sdam.sunwoo@arm.com (1 << 2) | // 3:2 2657436Sdam.sunwoo@arm.com 0; // 1:0 26610037SARM gem5 Developers miscRegs[MISCREG_NMRR_NS] = 2677436Sdam.sunwoo@arm.com (1 << 30) | // 31:30 2687436Sdam.sunwoo@arm.com (0 << 26) | // 27:26 2697436Sdam.sunwoo@arm.com (0 << 24) | // 25:24 2707436Sdam.sunwoo@arm.com (3 << 22) | // 23:22 2717436Sdam.sunwoo@arm.com (2 << 20) | // 21:20 2727436Sdam.sunwoo@arm.com (0 << 18) | // 19:18 2737436Sdam.sunwoo@arm.com (0 << 16) | // 17:16 2747436Sdam.sunwoo@arm.com (1 << 14) | // 15:14 2757436Sdam.sunwoo@arm.com (0 << 12) | // 13:12 2767436Sdam.sunwoo@arm.com (2 << 10) | // 11:10 2777436Sdam.sunwoo@arm.com (0 << 8) | // 9:8 2787436Sdam.sunwoo@arm.com (3 << 6) | // 7:6 2797436Sdam.sunwoo@arm.com (2 << 4) | // 5:4 2807436Sdam.sunwoo@arm.com (0 << 2) | // 3:2 2817436Sdam.sunwoo@arm.com 0; // 1:0 2827436Sdam.sunwoo@arm.com 2837644Sali.saidi@arm.com miscRegs[MISCREG_CPACR] = 0; 2848147SAli.Saidi@ARM.com 2859385SAndreas.Sandberg@arm.com 2869385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_PFR0] = p->id_pfr0; 2879385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_PFR1] = p->id_pfr1; 2889385SAndreas.Sandberg@arm.com 2899385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0; 2909385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1; 2919385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2; 2929385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3; 2939385SAndreas.Sandberg@arm.com 2949385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR0] = p->id_isar0; 2959385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR1] = p->id_isar1; 2969385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR2] = p->id_isar2; 2979385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR3] = p->id_isar3; 2989385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR4] = p->id_isar4; 2999385SAndreas.Sandberg@arm.com miscRegs[MISCREG_ID_ISAR5] = p->id_isar5; 3009385SAndreas.Sandberg@arm.com 3019385SAndreas.Sandberg@arm.com miscRegs[MISCREG_FPSID] = p->fpsid; 3029385SAndreas.Sandberg@arm.com 30310037SARM gem5 Developers if (haveLPAE) { 30410037SARM gem5 Developers TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS]; 30510037SARM gem5 Developers ttbcr.eae = 0; 30610037SARM gem5 Developers miscRegs[MISCREG_TTBCR_NS] = ttbcr; 30710037SARM gem5 Developers // Enforce consistency with system-level settings 30810037SARM gem5 Developers miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5; 30910037SARM gem5 Developers } 31010037SARM gem5 Developers 31110037SARM gem5 Developers if (haveSecurity) { 31210037SARM gem5 Developers miscRegs[MISCREG_SCTLR_S] = sctlr; 31310037SARM gem5 Developers miscRegs[MISCREG_SCR] = 0; 31410037SARM gem5 Developers miscRegs[MISCREG_VBAR_S] = 0; 31510037SARM gem5 Developers } else { 31610037SARM gem5 Developers // we're always non-secure 31710037SARM gem5 Developers miscRegs[MISCREG_SCR] = 1; 31810037SARM gem5 Developers } 3198147SAli.Saidi@ARM.com 3207427Sgblack@eecs.umich.edu //XXX We need to initialize the rest of the state. 3217427Sgblack@eecs.umich.edu} 3227427Sgblack@eecs.umich.edu 32310037SARM gem5 Developersvoid 32410037SARM gem5 DevelopersISA::clear64(const ArmISAParams *p) 32510037SARM gem5 Developers{ 32610037SARM gem5 Developers CPSR cpsr = 0; 32710037SARM gem5 Developers Addr rvbar = system->resetAddr64(); 32810037SARM gem5 Developers switch (system->highestEL()) { 32910037SARM gem5 Developers // Set initial EL to highest implemented EL using associated stack 33010037SARM gem5 Developers // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset 33110037SARM gem5 Developers // value 33210037SARM gem5 Developers case EL3: 33310037SARM gem5 Developers cpsr.mode = MODE_EL3H; 33410037SARM gem5 Developers miscRegs[MISCREG_RVBAR_EL3] = rvbar; 33510037SARM gem5 Developers break; 33610037SARM gem5 Developers case EL2: 33710037SARM gem5 Developers cpsr.mode = MODE_EL2H; 33810037SARM gem5 Developers miscRegs[MISCREG_RVBAR_EL2] = rvbar; 33910037SARM gem5 Developers break; 34010037SARM gem5 Developers case EL1: 34110037SARM gem5 Developers cpsr.mode = MODE_EL1H; 34210037SARM gem5 Developers miscRegs[MISCREG_RVBAR_EL1] = rvbar; 34310037SARM gem5 Developers break; 34410037SARM gem5 Developers default: 34510037SARM gem5 Developers panic("Invalid highest implemented exception level"); 34610037SARM gem5 Developers break; 34710037SARM gem5 Developers } 34810037SARM gem5 Developers 34910037SARM gem5 Developers // Initialize rest of CPSR 35010037SARM gem5 Developers cpsr.daif = 0xf; // Mask all interrupts 35110037SARM gem5 Developers cpsr.ss = 0; 35210037SARM gem5 Developers cpsr.il = 0; 35310037SARM gem5 Developers miscRegs[MISCREG_CPSR] = cpsr; 35410037SARM gem5 Developers updateRegMap(cpsr); 35510037SARM gem5 Developers 35610037SARM gem5 Developers // Initialize other control registers 35710037SARM gem5 Developers miscRegs[MISCREG_MPIDR_EL1] = 0x80000000; 35810037SARM gem5 Developers if (haveSecurity) { 35910037SARM gem5 Developers miscRegs[MISCREG_SCTLR_EL3] = 0x30c50870; 36010037SARM gem5 Developers miscRegs[MISCREG_SCR_EL3] = 0x00000030; // RES1 fields 36110037SARM gem5 Developers // @todo: uncomment this to enable Virtualization 36210037SARM gem5 Developers // } else if (haveVirtualization) { 36310037SARM gem5 Developers // 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 // (no AArch32/64 interprocessing support for now) 39410037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 39510037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12, 39610037SARM gem5 Developers haveSecurity ? 0x1 : 0x0); 39710037SARM gem5 Developers // EL2 39810037SARM gem5 Developers // (no AArch32/64 interprocessing support for now) 39910037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 40010037SARM gem5 Developers miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8, 40110037SARM gem5 Developers haveVirtualization ? 0x1 : 0x0); 40210037SARM gem5 Developers // Large ASID support 40310037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 40410037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4, 40510037SARM gem5 Developers haveLargeAsid64 ? 0x2 : 0x0); 40610037SARM gem5 Developers // Physical address size 40710037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 40810037SARM gem5 Developers miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0, 40910037SARM gem5 Developers encodePhysAddrRange64(physAddrRange64)); 41010037SARM gem5 Developers} 41110037SARM gem5 Developers 4127405SAli.Saidi@ARM.comMiscReg 41310035Sandreas.hansson@arm.comISA::readMiscRegNoEffect(int misc_reg) const 4147405SAli.Saidi@ARM.com{ 4157405SAli.Saidi@ARM.com assert(misc_reg < NumMiscRegs); 4167614Sminkyu.jeong@arm.com 41710037SARM gem5 Developers int flat_idx = flattenMiscIndex(misc_reg); // Note: indexes of AArch64 41810037SARM gem5 Developers // registers are left unchanged 41910037SARM gem5 Developers MiscReg val; 4207614Sminkyu.jeong@arm.com 42110037SARM gem5 Developers if (lookUpMiscReg[flat_idx].lower == 0 || flat_idx == MISCREG_SPSR 42210037SARM gem5 Developers || flat_idx == MISCREG_SCTLR_EL1) { 42310037SARM gem5 Developers if (flat_idx == MISCREG_SPSR) 42410037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SPSR); 42510037SARM gem5 Developers if (flat_idx == MISCREG_SCTLR_EL1) 42610037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SCTLR); 42710037SARM gem5 Developers val = miscRegs[flat_idx]; 42810037SARM gem5 Developers } else 42910037SARM gem5 Developers if (lookUpMiscReg[flat_idx].upper > 0) 43010037SARM gem5 Developers val = ((miscRegs[lookUpMiscReg[flat_idx].lower] & mask(32)) 43110037SARM gem5 Developers | (miscRegs[lookUpMiscReg[flat_idx].upper] << 32)); 43210037SARM gem5 Developers else 43310037SARM gem5 Developers val = miscRegs[lookUpMiscReg[flat_idx].lower]; 43410037SARM gem5 Developers 4357614Sminkyu.jeong@arm.com return val; 4367405SAli.Saidi@ARM.com} 4377405SAli.Saidi@ARM.com 4387405SAli.Saidi@ARM.com 4397405SAli.Saidi@ARM.comMiscReg 4407405SAli.Saidi@ARM.comISA::readMiscReg(int misc_reg, ThreadContext *tc) 4417405SAli.Saidi@ARM.com{ 44210037SARM gem5 Developers CPSR cpsr = 0; 44310037SARM gem5 Developers PCState pc = 0; 44410037SARM gem5 Developers SCR scr = 0; 4459050Schander.sudanthi@arm.com 4467405SAli.Saidi@ARM.com if (misc_reg == MISCREG_CPSR) { 44710037SARM gem5 Developers cpsr = miscRegs[misc_reg]; 44810037SARM gem5 Developers pc = tc->pcState(); 4497720Sgblack@eecs.umich.edu cpsr.j = pc.jazelle() ? 1 : 0; 4507720Sgblack@eecs.umich.edu cpsr.t = pc.thumb() ? 1 : 0; 4517405SAli.Saidi@ARM.com return cpsr; 4527405SAli.Saidi@ARM.com } 4537757SAli.Saidi@ARM.com 45410037SARM gem5 Developers#ifndef NDEBUG 45510037SARM gem5 Developers if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 45610037SARM gem5 Developers if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 45710037SARM gem5 Developers warn("Unimplemented system register %s read.\n", 45810037SARM gem5 Developers miscRegName[misc_reg]); 45910037SARM gem5 Developers else 46010037SARM gem5 Developers panic("Unimplemented system register %s read.\n", 46110037SARM gem5 Developers miscRegName[misc_reg]); 46210037SARM gem5 Developers } 46310037SARM gem5 Developers#endif 46410037SARM gem5 Developers 46510037SARM gem5 Developers switch (unflattenMiscReg(misc_reg)) { 46610037SARM gem5 Developers case MISCREG_HCR: 46710037SARM gem5 Developers { 46810037SARM gem5 Developers if (!haveVirtualization) 46910037SARM gem5 Developers return 0; 47010037SARM gem5 Developers else 47110037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_HCR); 47210037SARM gem5 Developers } 47310037SARM gem5 Developers case MISCREG_CPACR: 47410037SARM gem5 Developers { 47510037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 47610037SARM gem5 Developers CPACR cpacrMask = 0; 47710037SARM gem5 Developers // Only cp10, cp11, and ase are implemented, nothing else should 47810037SARM gem5 Developers // be readable? (straight copy from the write code) 47910037SARM gem5 Developers cpacrMask.cp10 = ones; 48010037SARM gem5 Developers cpacrMask.cp11 = ones; 48110037SARM gem5 Developers cpacrMask.asedis = ones; 48210037SARM gem5 Developers 48310037SARM gem5 Developers // Security Extensions may limit the readability of CPACR 48410037SARM gem5 Developers if (haveSecurity) { 48510037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 48610037SARM gem5 Developers cpsr = readMiscRegNoEffect(MISCREG_CPSR); 48710037SARM gem5 Developers if (scr.ns && (cpsr.mode != MODE_MON)) { 48810037SARM gem5 Developers NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 48910037SARM gem5 Developers // NB: Skipping the full loop, here 49010037SARM gem5 Developers if (!nsacr.cp10) cpacrMask.cp10 = 0; 49110037SARM gem5 Developers if (!nsacr.cp11) cpacrMask.cp11 = 0; 49210037SARM gem5 Developers } 49310037SARM gem5 Developers } 49410037SARM gem5 Developers MiscReg val = readMiscRegNoEffect(MISCREG_CPACR); 49510037SARM gem5 Developers val &= cpacrMask; 49610037SARM gem5 Developers DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n", 49710037SARM gem5 Developers miscRegName[misc_reg], val); 49810037SARM gem5 Developers return val; 49910037SARM gem5 Developers } 5008284SAli.Saidi@ARM.com case MISCREG_MPIDR: 50110037SARM gem5 Developers cpsr = readMiscRegNoEffect(MISCREG_CPSR); 50210037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 50310037SARM gem5 Developers if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 50410037SARM gem5 Developers return getMPIDR(system, tc); 5059050Schander.sudanthi@arm.com } else { 50610037SARM gem5 Developers return readMiscReg(MISCREG_VMPIDR, tc); 50710037SARM gem5 Developers } 50810037SARM gem5 Developers break; 50910037SARM gem5 Developers case MISCREG_MPIDR_EL1: 51010037SARM gem5 Developers // @todo in the absence of v8 virtualization support just return MPIDR_EL1 51110037SARM gem5 Developers return getMPIDR(system, tc) & 0xffffffff; 51210037SARM gem5 Developers case MISCREG_VMPIDR: 51310037SARM gem5 Developers // top bit defined as RES1 51410037SARM gem5 Developers return readMiscRegNoEffect(misc_reg) | 0x80000000; 51510037SARM gem5 Developers case MISCREG_ID_AFR0: // not implemented, so alias MIDR 51610037SARM gem5 Developers case MISCREG_REVIDR: // not implemented, so alias MIDR 51710037SARM gem5 Developers case MISCREG_MIDR: 51810037SARM gem5 Developers cpsr = readMiscRegNoEffect(MISCREG_CPSR); 51910037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 52010037SARM gem5 Developers if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 52110037SARM gem5 Developers return readMiscRegNoEffect(misc_reg); 52210037SARM gem5 Developers } else { 52310037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_VPIDR); 5249050Schander.sudanthi@arm.com } 5258284SAli.Saidi@ARM.com break; 52610037SARM gem5 Developers case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI 52710037SARM gem5 Developers case MISCREG_JMCR: // Jazelle trivial implementation, RAZ/WI 52810037SARM gem5 Developers case MISCREG_JIDR: // Jazelle trivial implementation, RAZ/WI 52910037SARM gem5 Developers case MISCREG_AIDR: // AUX ID set to 0 53010037SARM gem5 Developers case MISCREG_TCMTR: // No TCM's 53110037SARM gem5 Developers return 0; 53210037SARM gem5 Developers 5337405SAli.Saidi@ARM.com case MISCREG_CLIDR: 5347731SAli.Saidi@ARM.com warn_once("The clidr register always reports 0 caches.\n"); 5358468Swade.walker@arm.com warn_once("clidr LoUIS field of 0b001 to match current " 5368468Swade.walker@arm.com "ARM implementations.\n"); 5378468Swade.walker@arm.com return 0x00200000; 5387405SAli.Saidi@ARM.com case MISCREG_CCSIDR: 5397731SAli.Saidi@ARM.com warn_once("The ccsidr register isn't implemented and " 5407405SAli.Saidi@ARM.com "always reads as 0.\n"); 5417405SAli.Saidi@ARM.com break; 5427583SAli.Saidi@arm.com case MISCREG_CTR: 5439130Satgutier@umich.edu { 5449130Satgutier@umich.edu //all caches have the same line size in gem5 5459130Satgutier@umich.edu //4 byte words in ARM 5469130Satgutier@umich.edu unsigned lineSizeWords = 5479814Sandreas.hansson@arm.com tc->getSystemPtr()->cacheLineSize() / 4; 5489130Satgutier@umich.edu unsigned log2LineSizeWords = 0; 5499130Satgutier@umich.edu 5509130Satgutier@umich.edu while (lineSizeWords >>= 1) { 5519130Satgutier@umich.edu ++log2LineSizeWords; 5529130Satgutier@umich.edu } 5539130Satgutier@umich.edu 5549130Satgutier@umich.edu CTR ctr = 0; 5559130Satgutier@umich.edu //log2 of minimun i-cache line size (words) 5569130Satgutier@umich.edu ctr.iCacheLineSize = log2LineSizeWords; 5579130Satgutier@umich.edu //b11 - gem5 uses pipt 5589130Satgutier@umich.edu ctr.l1IndexPolicy = 0x3; 5599130Satgutier@umich.edu //log2 of minimum d-cache line size (words) 5609130Satgutier@umich.edu ctr.dCacheLineSize = log2LineSizeWords; 5619130Satgutier@umich.edu //log2 of max reservation size (words) 5629130Satgutier@umich.edu ctr.erg = log2LineSizeWords; 5639130Satgutier@umich.edu //log2 of max writeback size (words) 5649130Satgutier@umich.edu ctr.cwg = log2LineSizeWords; 5659130Satgutier@umich.edu //b100 - gem5 format is ARMv7 5669130Satgutier@umich.edu ctr.format = 0x4; 5679130Satgutier@umich.edu 5689130Satgutier@umich.edu return ctr; 5699130Satgutier@umich.edu } 5707583SAli.Saidi@arm.com case MISCREG_ACTLR: 5717583SAli.Saidi@arm.com warn("Not doing anything for miscreg ACTLR\n"); 5727583SAli.Saidi@arm.com break; 57310461SAndreas.Sandberg@ARM.com 57410461SAndreas.Sandberg@ARM.com case MISCREG_PMXEVTYPER_PMCCFILTR: 57510461SAndreas.Sandberg@ARM.com case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 57610461SAndreas.Sandberg@ARM.com case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 57710461SAndreas.Sandberg@ARM.com case MISCREG_PMCR ... MISCREG_PMOVSSET: 57810461SAndreas.Sandberg@ARM.com return pmu->readMiscReg(misc_reg); 57910461SAndreas.Sandberg@ARM.com 5808302SAli.Saidi@ARM.com case MISCREG_CPSR_Q: 5818302SAli.Saidi@ARM.com panic("shouldn't be reading this register seperately\n"); 5827783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_QC: 5837783SGiacomo.Gabrielli@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask; 5847783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_EXC: 5857783SGiacomo.Gabrielli@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask; 58610037SARM gem5 Developers case MISCREG_FPSR: 58710037SARM gem5 Developers { 58810037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 58910037SARM gem5 Developers FPSCR fpscrMask = 0; 59010037SARM gem5 Developers fpscrMask.ioc = ones; 59110037SARM gem5 Developers fpscrMask.dzc = ones; 59210037SARM gem5 Developers fpscrMask.ofc = ones; 59310037SARM gem5 Developers fpscrMask.ufc = ones; 59410037SARM gem5 Developers fpscrMask.ixc = ones; 59510037SARM gem5 Developers fpscrMask.idc = ones; 59610037SARM gem5 Developers fpscrMask.qc = ones; 59710037SARM gem5 Developers fpscrMask.v = ones; 59810037SARM gem5 Developers fpscrMask.c = ones; 59910037SARM gem5 Developers fpscrMask.z = ones; 60010037SARM gem5 Developers fpscrMask.n = ones; 60110037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 60210037SARM gem5 Developers } 60310037SARM gem5 Developers case MISCREG_FPCR: 60410037SARM gem5 Developers { 60510037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 60610037SARM gem5 Developers FPSCR fpscrMask = 0; 60710037SARM gem5 Developers fpscrMask.ioe = ones; 60810037SARM gem5 Developers fpscrMask.dze = ones; 60910037SARM gem5 Developers fpscrMask.ofe = ones; 61010037SARM gem5 Developers fpscrMask.ufe = ones; 61110037SARM gem5 Developers fpscrMask.ixe = ones; 61210037SARM gem5 Developers fpscrMask.ide = ones; 61310037SARM gem5 Developers fpscrMask.len = ones; 61410037SARM gem5 Developers fpscrMask.stride = ones; 61510037SARM gem5 Developers fpscrMask.rMode = ones; 61610037SARM gem5 Developers fpscrMask.fz = ones; 61710037SARM gem5 Developers fpscrMask.dn = ones; 61810037SARM gem5 Developers fpscrMask.ahp = ones; 61910037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 62010037SARM gem5 Developers } 62110037SARM gem5 Developers case MISCREG_NZCV: 62210037SARM gem5 Developers { 62310037SARM gem5 Developers CPSR cpsr = 0; 62410338SCurtis.Dunham@arm.com cpsr.nz = tc->readCCReg(CCREG_NZ); 62510338SCurtis.Dunham@arm.com cpsr.c = tc->readCCReg(CCREG_C); 62610338SCurtis.Dunham@arm.com cpsr.v = tc->readCCReg(CCREG_V); 62710037SARM gem5 Developers return cpsr; 62810037SARM gem5 Developers } 62910037SARM gem5 Developers case MISCREG_DAIF: 63010037SARM gem5 Developers { 63110037SARM gem5 Developers CPSR cpsr = 0; 63210037SARM gem5 Developers cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif; 63310037SARM gem5 Developers return cpsr; 63410037SARM gem5 Developers } 63510037SARM gem5 Developers case MISCREG_SP_EL0: 63610037SARM gem5 Developers { 63710037SARM gem5 Developers return tc->readIntReg(INTREG_SP0); 63810037SARM gem5 Developers } 63910037SARM gem5 Developers case MISCREG_SP_EL1: 64010037SARM gem5 Developers { 64110037SARM gem5 Developers return tc->readIntReg(INTREG_SP1); 64210037SARM gem5 Developers } 64310037SARM gem5 Developers case MISCREG_SP_EL2: 64410037SARM gem5 Developers { 64510037SARM gem5 Developers return tc->readIntReg(INTREG_SP2); 64610037SARM gem5 Developers } 64710037SARM gem5 Developers case MISCREG_SPSEL: 64810037SARM gem5 Developers { 64910037SARM gem5 Developers return miscRegs[MISCREG_CPSR] & 0x1; 65010037SARM gem5 Developers } 65110037SARM gem5 Developers case MISCREG_CURRENTEL: 65210037SARM gem5 Developers { 65310037SARM gem5 Developers return miscRegs[MISCREG_CPSR] & 0xc; 65410037SARM gem5 Developers } 6558549Sdaniel.johnson@arm.com case MISCREG_L2CTLR: 6568868SMatt.Horsnell@arm.com { 6578868SMatt.Horsnell@arm.com // mostly unimplemented, just set NumCPUs field from sim and return 6588868SMatt.Horsnell@arm.com L2CTLR l2ctlr = 0; 6598868SMatt.Horsnell@arm.com // b00:1CPU to b11:4CPUs 6608868SMatt.Horsnell@arm.com l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1; 6618868SMatt.Horsnell@arm.com return l2ctlr; 6628868SMatt.Horsnell@arm.com } 6638868SMatt.Horsnell@arm.com case MISCREG_DBGDIDR: 6648868SMatt.Horsnell@arm.com /* For now just implement the version number. 66510461SAndreas.Sandberg@ARM.com * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5) 6668868SMatt.Horsnell@arm.com */ 66710461SAndreas.Sandberg@ARM.com return 0x5 << 16; 66810037SARM gem5 Developers case MISCREG_DBGDSCRint: 6698868SMatt.Horsnell@arm.com return 0; 67010037SARM gem5 Developers case MISCREG_ISR: 67111150Smitch.hayenga@arm.com return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 67210037SARM gem5 Developers readMiscRegNoEffect(MISCREG_HCR), 67310037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR), 67410037SARM gem5 Developers readMiscRegNoEffect(MISCREG_SCR)); 67510037SARM gem5 Developers case MISCREG_ISR_EL1: 67611150Smitch.hayenga@arm.com return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 67710037SARM gem5 Developers readMiscRegNoEffect(MISCREG_HCR_EL2), 67810037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR), 67910037SARM gem5 Developers readMiscRegNoEffect(MISCREG_SCR_EL3)); 68010037SARM gem5 Developers case MISCREG_DCZID_EL0: 68110037SARM gem5 Developers return 0x04; // DC ZVA clear 64-byte chunks 68210037SARM gem5 Developers case MISCREG_HCPTR: 68310037SARM gem5 Developers { 68410037SARM gem5 Developers MiscReg val = readMiscRegNoEffect(misc_reg); 68510037SARM gem5 Developers // The trap bit associated with CP14 is defined as RAZ 68610037SARM gem5 Developers val &= ~(1 << 14); 68710037SARM gem5 Developers // If a CP bit in NSACR is 0 then the corresponding bit in 68810037SARM gem5 Developers // HCPTR is RAO/WI 68910037SARM gem5 Developers bool secure_lookup = haveSecurity && 69010037SARM gem5 Developers inSecureState(readMiscRegNoEffect(MISCREG_SCR), 69110037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR)); 69210037SARM gem5 Developers if (!secure_lookup) { 69310037SARM gem5 Developers MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR); 69410037SARM gem5 Developers val |= (mask ^ 0x7FFF) & 0xBFFF; 69510037SARM gem5 Developers } 69610037SARM gem5 Developers // Set the bits for unimplemented coprocessors to RAO/WI 69710037SARM gem5 Developers val |= 0x33FF; 69810037SARM gem5 Developers return (val); 69910037SARM gem5 Developers } 70010037SARM gem5 Developers case MISCREG_HDFAR: // alias for secure DFAR 70110037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_DFAR_S); 70210037SARM gem5 Developers case MISCREG_HIFAR: // alias for secure IFAR 70310037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_IFAR_S); 70410037SARM gem5 Developers case MISCREG_HVBAR: // bottom bits reserved 70510037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0; 70610037SARM gem5 Developers case MISCREG_SCTLR: // Some bits hardwired 70710037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions of the register 70810037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21)) | 70910037SARM gem5 Developers (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818; // V8 SCTLR 71010037SARM gem5 Developers case MISCREG_SCTLR_EL1: 71110037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions of the register 71210037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21)) | 71310037SARM gem5 Developers (readMiscRegNoEffect(misc_reg) & 0x37DDDBFF) | 0x30D00800; // V8 SCTLR_EL1 71410037SARM gem5 Developers case MISCREG_SCTLR_EL3: 71510037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions of the register 71610037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_SCTLR_S) & (1 << 21)) | 71710037SARM gem5 Developers (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830; // V8 SCTLR_EL3 71810037SARM gem5 Developers case MISCREG_HSCTLR: // FI comes from SCTLR 71910037SARM gem5 Developers { 72010037SARM gem5 Developers uint32_t mask = 1 << 27; 72110037SARM gem5 Developers return (readMiscRegNoEffect(MISCREG_HSCTLR) & ~mask) | 72210037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_SCTLR) & mask); 72310037SARM gem5 Developers } 72410037SARM gem5 Developers case MISCREG_SCR: 72510037SARM gem5 Developers { 72610037SARM gem5 Developers CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR); 72710037SARM gem5 Developers if (cpsr.width) { 72810037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_SCR); 72910037SARM gem5 Developers } else { 73010037SARM gem5 Developers return readMiscRegNoEffect(MISCREG_SCR_EL3); 73110037SARM gem5 Developers } 73210037SARM gem5 Developers } 73310844Sandreas.sandberg@arm.com 73410037SARM gem5 Developers // Generic Timer registers 73510844Sandreas.sandberg@arm.com case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 73610844Sandreas.sandberg@arm.com case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 73710844Sandreas.sandberg@arm.com case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 73810844Sandreas.sandberg@arm.com case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 73910844Sandreas.sandberg@arm.com return getGenericTimer(tc).readMiscReg(misc_reg); 74010844Sandreas.sandberg@arm.com 74110188Sgeoffrey.blake@arm.com default: 74210037SARM gem5 Developers break; 74310037SARM gem5 Developers 7447405SAli.Saidi@ARM.com } 7457405SAli.Saidi@ARM.com return readMiscRegNoEffect(misc_reg); 7467405SAli.Saidi@ARM.com} 7477405SAli.Saidi@ARM.com 7487405SAli.Saidi@ARM.comvoid 7497405SAli.Saidi@ARM.comISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val) 7507405SAli.Saidi@ARM.com{ 7517405SAli.Saidi@ARM.com assert(misc_reg < NumMiscRegs); 7527614Sminkyu.jeong@arm.com 75310037SARM gem5 Developers int flat_idx = flattenMiscIndex(misc_reg); // Note: indexes of AArch64 75410037SARM gem5 Developers // registers are left unchanged 7557614Sminkyu.jeong@arm.com 75610037SARM gem5 Developers int flat_idx2 = lookUpMiscReg[flat_idx].upper; 75710037SARM gem5 Developers 75810037SARM gem5 Developers if (flat_idx2 > 0) { 75910037SARM gem5 Developers miscRegs[lookUpMiscReg[flat_idx].lower] = bits(val, 31, 0); 76010037SARM gem5 Developers miscRegs[flat_idx2] = bits(val, 63, 32); 76110037SARM gem5 Developers DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n", 76210037SARM gem5 Developers misc_reg, flat_idx, flat_idx2, val); 76310037SARM gem5 Developers } else { 76410037SARM gem5 Developers if (flat_idx == MISCREG_SPSR) 76510037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SPSR); 76610037SARM gem5 Developers else if (flat_idx == MISCREG_SCTLR_EL1) 76710037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_SCTLR); 76810037SARM gem5 Developers else 76910037SARM gem5 Developers flat_idx = (lookUpMiscReg[flat_idx].lower > 0) ? 77010037SARM gem5 Developers lookUpMiscReg[flat_idx].lower : flat_idx; 77110037SARM gem5 Developers miscRegs[flat_idx] = val; 77210037SARM gem5 Developers DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n", 77310037SARM gem5 Developers misc_reg, flat_idx, val); 77410037SARM gem5 Developers } 7757405SAli.Saidi@ARM.com} 7767405SAli.Saidi@ARM.com 7777405SAli.Saidi@ARM.comvoid 7787405SAli.Saidi@ARM.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 7797405SAli.Saidi@ARM.com{ 7807749SAli.Saidi@ARM.com 7817405SAli.Saidi@ARM.com MiscReg newVal = val; 7828284SAli.Saidi@ARM.com int x; 78310037SARM gem5 Developers bool secure_lookup; 78410037SARM gem5 Developers bool hyp; 7858284SAli.Saidi@ARM.com System *sys; 7868284SAli.Saidi@ARM.com ThreadContext *oc; 78710037SARM gem5 Developers uint8_t target_el; 78810037SARM gem5 Developers uint16_t asid; 78910037SARM gem5 Developers SCR scr; 7908284SAli.Saidi@ARM.com 7917405SAli.Saidi@ARM.com if (misc_reg == MISCREG_CPSR) { 7927405SAli.Saidi@ARM.com updateRegMap(val); 7937749SAli.Saidi@ARM.com 7947749SAli.Saidi@ARM.com 7957749SAli.Saidi@ARM.com CPSR old_cpsr = miscRegs[MISCREG_CPSR]; 7967749SAli.Saidi@ARM.com int old_mode = old_cpsr.mode; 7977405SAli.Saidi@ARM.com CPSR cpsr = val; 7987749SAli.Saidi@ARM.com if (old_mode != cpsr.mode) { 7997749SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 8007749SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 8017749SAli.Saidi@ARM.com } 8027749SAli.Saidi@ARM.com 8037614Sminkyu.jeong@arm.com DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n", 8047614Sminkyu.jeong@arm.com miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode); 8057720Sgblack@eecs.umich.edu PCState pc = tc->pcState(); 8067720Sgblack@eecs.umich.edu pc.nextThumb(cpsr.t); 8077720Sgblack@eecs.umich.edu pc.nextJazelle(cpsr.j); 8088887Sgeoffrey.blake@arm.com 8098887Sgeoffrey.blake@arm.com // Follow slightly different semantics if a CheckerCPU object 8108887Sgeoffrey.blake@arm.com // is connected 8118887Sgeoffrey.blake@arm.com CheckerCPU *checker = tc->getCheckerCpuPtr(); 8128887Sgeoffrey.blake@arm.com if (checker) { 8138887Sgeoffrey.blake@arm.com tc->pcStateNoRecord(pc); 8148887Sgeoffrey.blake@arm.com } else { 8158887Sgeoffrey.blake@arm.com tc->pcState(pc); 8168887Sgeoffrey.blake@arm.com } 8177408Sgblack@eecs.umich.edu } else { 81810037SARM gem5 Developers#ifndef NDEBUG 81910037SARM gem5 Developers if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 82010037SARM gem5 Developers if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 82110037SARM gem5 Developers warn("Unimplemented system register %s write with %#x.\n", 82210037SARM gem5 Developers miscRegName[misc_reg], val); 82310037SARM gem5 Developers else 82410037SARM gem5 Developers panic("Unimplemented system register %s write with %#x.\n", 82510037SARM gem5 Developers miscRegName[misc_reg], val); 82610037SARM gem5 Developers } 82710037SARM gem5 Developers#endif 82810037SARM gem5 Developers switch (unflattenMiscReg(misc_reg)) { 8297408Sgblack@eecs.umich.edu case MISCREG_CPACR: 8307408Sgblack@eecs.umich.edu { 8318206SWilliam.Wang@arm.com 8328206SWilliam.Wang@arm.com const uint32_t ones = (uint32_t)(-1); 8338206SWilliam.Wang@arm.com CPACR cpacrMask = 0; 8348206SWilliam.Wang@arm.com // Only cp10, cp11, and ase are implemented, nothing else should 8358206SWilliam.Wang@arm.com // be writable 8368206SWilliam.Wang@arm.com cpacrMask.cp10 = ones; 8378206SWilliam.Wang@arm.com cpacrMask.cp11 = ones; 8388206SWilliam.Wang@arm.com cpacrMask.asedis = ones; 83910037SARM gem5 Developers 84010037SARM gem5 Developers // Security Extensions may limit the writability of CPACR 84110037SARM gem5 Developers if (haveSecurity) { 84210037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 84310037SARM gem5 Developers CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR); 84410037SARM gem5 Developers if (scr.ns && (cpsr.mode != MODE_MON)) { 84510037SARM gem5 Developers NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 84610037SARM gem5 Developers // NB: Skipping the full loop, here 84710037SARM gem5 Developers if (!nsacr.cp10) cpacrMask.cp10 = 0; 84810037SARM gem5 Developers if (!nsacr.cp11) cpacrMask.cp11 = 0; 84910037SARM gem5 Developers } 85010037SARM gem5 Developers } 85110037SARM gem5 Developers 85210037SARM gem5 Developers MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR); 8538206SWilliam.Wang@arm.com newVal &= cpacrMask; 85410037SARM gem5 Developers newVal |= old_val & ~cpacrMask; 85510037SARM gem5 Developers DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 85610037SARM gem5 Developers miscRegName[misc_reg], newVal); 85710037SARM gem5 Developers } 85810037SARM gem5 Developers break; 85910037SARM gem5 Developers case MISCREG_CPACR_EL1: 86010037SARM gem5 Developers { 86110037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 86210037SARM gem5 Developers CPACR cpacrMask = 0; 86310037SARM gem5 Developers cpacrMask.tta = ones; 86410037SARM gem5 Developers cpacrMask.fpen = ones; 86510037SARM gem5 Developers newVal &= cpacrMask; 86610037SARM gem5 Developers DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 86710037SARM gem5 Developers miscRegName[misc_reg], newVal); 86810037SARM gem5 Developers } 86910037SARM gem5 Developers break; 87010037SARM gem5 Developers case MISCREG_CPTR_EL2: 87110037SARM gem5 Developers { 87210037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 87310037SARM gem5 Developers CPTR cptrMask = 0; 87410037SARM gem5 Developers cptrMask.tcpac = ones; 87510037SARM gem5 Developers cptrMask.tta = ones; 87610037SARM gem5 Developers cptrMask.tfp = ones; 87710037SARM gem5 Developers newVal &= cptrMask; 87810037SARM gem5 Developers cptrMask = 0; 87910037SARM gem5 Developers cptrMask.res1_13_12_el2 = ones; 88010037SARM gem5 Developers cptrMask.res1_9_0_el2 = ones; 88110037SARM gem5 Developers newVal |= cptrMask; 88210037SARM gem5 Developers DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 88310037SARM gem5 Developers miscRegName[misc_reg], newVal); 88410037SARM gem5 Developers } 88510037SARM gem5 Developers break; 88610037SARM gem5 Developers case MISCREG_CPTR_EL3: 88710037SARM gem5 Developers { 88810037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 88910037SARM gem5 Developers CPTR cptrMask = 0; 89010037SARM gem5 Developers cptrMask.tcpac = ones; 89110037SARM gem5 Developers cptrMask.tta = ones; 89210037SARM gem5 Developers cptrMask.tfp = ones; 89310037SARM gem5 Developers newVal &= cptrMask; 8948206SWilliam.Wang@arm.com DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 8958206SWilliam.Wang@arm.com miscRegName[misc_reg], newVal); 8967408Sgblack@eecs.umich.edu } 8977408Sgblack@eecs.umich.edu break; 8987408Sgblack@eecs.umich.edu case MISCREG_CSSELR: 8997731SAli.Saidi@ARM.com warn_once("The csselr register isn't implemented.\n"); 9008206SWilliam.Wang@arm.com return; 90110037SARM gem5 Developers 90210037SARM gem5 Developers case MISCREG_DC_ZVA_Xt: 90310037SARM gem5 Developers warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n"); 90410037SARM gem5 Developers return; 90510037SARM gem5 Developers 9067408Sgblack@eecs.umich.edu case MISCREG_FPSCR: 9077408Sgblack@eecs.umich.edu { 9087408Sgblack@eecs.umich.edu const uint32_t ones = (uint32_t)(-1); 9097408Sgblack@eecs.umich.edu FPSCR fpscrMask = 0; 9107408Sgblack@eecs.umich.edu fpscrMask.ioc = ones; 9117408Sgblack@eecs.umich.edu fpscrMask.dzc = ones; 9127408Sgblack@eecs.umich.edu fpscrMask.ofc = ones; 9137408Sgblack@eecs.umich.edu fpscrMask.ufc = ones; 9147408Sgblack@eecs.umich.edu fpscrMask.ixc = ones; 9157408Sgblack@eecs.umich.edu fpscrMask.idc = ones; 91610037SARM gem5 Developers fpscrMask.ioe = ones; 91710037SARM gem5 Developers fpscrMask.dze = ones; 91810037SARM gem5 Developers fpscrMask.ofe = ones; 91910037SARM gem5 Developers fpscrMask.ufe = ones; 92010037SARM gem5 Developers fpscrMask.ixe = ones; 92110037SARM gem5 Developers fpscrMask.ide = ones; 9227408Sgblack@eecs.umich.edu fpscrMask.len = ones; 9237408Sgblack@eecs.umich.edu fpscrMask.stride = ones; 9247408Sgblack@eecs.umich.edu fpscrMask.rMode = ones; 9257408Sgblack@eecs.umich.edu fpscrMask.fz = ones; 9267408Sgblack@eecs.umich.edu fpscrMask.dn = ones; 9277408Sgblack@eecs.umich.edu fpscrMask.ahp = ones; 9287408Sgblack@eecs.umich.edu fpscrMask.qc = ones; 9297408Sgblack@eecs.umich.edu fpscrMask.v = ones; 9307408Sgblack@eecs.umich.edu fpscrMask.c = ones; 9317408Sgblack@eecs.umich.edu fpscrMask.z = ones; 9327408Sgblack@eecs.umich.edu fpscrMask.n = ones; 9337408Sgblack@eecs.umich.edu newVal = (newVal & (uint32_t)fpscrMask) | 93410037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPSCR) & 93510037SARM gem5 Developers ~(uint32_t)fpscrMask); 9369377Sgblack@eecs.umich.edu tc->getDecoderPtr()->setContext(newVal); 9377408Sgblack@eecs.umich.edu } 9387408Sgblack@eecs.umich.edu break; 93910037SARM gem5 Developers case MISCREG_FPSR: 94010037SARM gem5 Developers { 94110037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 94210037SARM gem5 Developers FPSCR fpscrMask = 0; 94310037SARM gem5 Developers fpscrMask.ioc = ones; 94410037SARM gem5 Developers fpscrMask.dzc = ones; 94510037SARM gem5 Developers fpscrMask.ofc = ones; 94610037SARM gem5 Developers fpscrMask.ufc = ones; 94710037SARM gem5 Developers fpscrMask.ixc = ones; 94810037SARM gem5 Developers fpscrMask.idc = ones; 94910037SARM gem5 Developers fpscrMask.qc = ones; 95010037SARM gem5 Developers fpscrMask.v = ones; 95110037SARM gem5 Developers fpscrMask.c = ones; 95210037SARM gem5 Developers fpscrMask.z = ones; 95310037SARM gem5 Developers fpscrMask.n = ones; 95410037SARM gem5 Developers newVal = (newVal & (uint32_t)fpscrMask) | 95510037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPSCR) & 95610037SARM gem5 Developers ~(uint32_t)fpscrMask); 95710037SARM gem5 Developers misc_reg = MISCREG_FPSCR; 95810037SARM gem5 Developers } 95910037SARM gem5 Developers break; 96010037SARM gem5 Developers case MISCREG_FPCR: 96110037SARM gem5 Developers { 96210037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 96310037SARM gem5 Developers FPSCR fpscrMask = 0; 96410037SARM gem5 Developers fpscrMask.ioe = ones; 96510037SARM gem5 Developers fpscrMask.dze = ones; 96610037SARM gem5 Developers fpscrMask.ofe = ones; 96710037SARM gem5 Developers fpscrMask.ufe = ones; 96810037SARM gem5 Developers fpscrMask.ixe = ones; 96910037SARM gem5 Developers fpscrMask.ide = ones; 97010037SARM gem5 Developers fpscrMask.len = ones; 97110037SARM gem5 Developers fpscrMask.stride = ones; 97210037SARM gem5 Developers fpscrMask.rMode = ones; 97310037SARM gem5 Developers fpscrMask.fz = ones; 97410037SARM gem5 Developers fpscrMask.dn = ones; 97510037SARM gem5 Developers fpscrMask.ahp = ones; 97610037SARM gem5 Developers newVal = (newVal & (uint32_t)fpscrMask) | 97710037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPSCR) & 97810037SARM gem5 Developers ~(uint32_t)fpscrMask); 97910037SARM gem5 Developers misc_reg = MISCREG_FPSCR; 98010037SARM gem5 Developers } 98110037SARM gem5 Developers break; 9828302SAli.Saidi@ARM.com case MISCREG_CPSR_Q: 9838302SAli.Saidi@ARM.com { 9848302SAli.Saidi@ARM.com assert(!(newVal & ~CpsrMaskQ)); 98510037SARM gem5 Developers newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal; 9868302SAli.Saidi@ARM.com misc_reg = MISCREG_CPSR; 9878302SAli.Saidi@ARM.com } 9888302SAli.Saidi@ARM.com break; 9897783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_QC: 9907783SGiacomo.Gabrielli@arm.com { 99110037SARM gem5 Developers newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 99210037SARM gem5 Developers (newVal & FpscrQcMask); 9937783SGiacomo.Gabrielli@arm.com misc_reg = MISCREG_FPSCR; 9947783SGiacomo.Gabrielli@arm.com } 9957783SGiacomo.Gabrielli@arm.com break; 9967783SGiacomo.Gabrielli@arm.com case MISCREG_FPSCR_EXC: 9977783SGiacomo.Gabrielli@arm.com { 99810037SARM gem5 Developers newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 99910037SARM gem5 Developers (newVal & FpscrExcMask); 10007783SGiacomo.Gabrielli@arm.com misc_reg = MISCREG_FPSCR; 10017783SGiacomo.Gabrielli@arm.com } 10027783SGiacomo.Gabrielli@arm.com break; 10037408Sgblack@eecs.umich.edu case MISCREG_FPEXC: 10047408Sgblack@eecs.umich.edu { 10058206SWilliam.Wang@arm.com // vfpv3 architecture, section B.6.1 of DDI04068 10068206SWilliam.Wang@arm.com // bit 29 - valid only if fpexc[31] is 0 10077408Sgblack@eecs.umich.edu const uint32_t fpexcMask = 0x60000000; 10087408Sgblack@eecs.umich.edu newVal = (newVal & fpexcMask) | 100910037SARM gem5 Developers (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask); 10107408Sgblack@eecs.umich.edu } 10117408Sgblack@eecs.umich.edu break; 101210037SARM gem5 Developers case MISCREG_HCR: 101310037SARM gem5 Developers { 101410037SARM gem5 Developers if (!haveVirtualization) 101510037SARM gem5 Developers return; 101610037SARM gem5 Developers } 101710037SARM gem5 Developers break; 101810037SARM gem5 Developers case MISCREG_IFSR: 101910037SARM gem5 Developers { 102010037SARM gem5 Developers // ARM ARM (ARM DDI 0406C.b) B4.1.96 102110037SARM gem5 Developers const uint32_t ifsrMask = 102210037SARM gem5 Developers mask(31, 13) | mask(11, 11) | mask(8, 6); 102310037SARM gem5 Developers newVal = newVal & ~ifsrMask; 102410037SARM gem5 Developers } 102510037SARM gem5 Developers break; 102610037SARM gem5 Developers case MISCREG_DFSR: 102710037SARM gem5 Developers { 102810037SARM gem5 Developers // ARM ARM (ARM DDI 0406C.b) B4.1.52 102910037SARM gem5 Developers const uint32_t dfsrMask = mask(31, 14) | mask(8, 8); 103010037SARM gem5 Developers newVal = newVal & ~dfsrMask; 103110037SARM gem5 Developers } 103210037SARM gem5 Developers break; 103310037SARM gem5 Developers case MISCREG_AMAIR0: 103410037SARM gem5 Developers case MISCREG_AMAIR1: 103510037SARM gem5 Developers { 103610037SARM gem5 Developers // ARM ARM (ARM DDI 0406C.b) B4.1.5 103710037SARM gem5 Developers // Valid only with LPAE 103810037SARM gem5 Developers if (!haveLPAE) 103910037SARM gem5 Developers return; 104010037SARM gem5 Developers DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal); 104110037SARM gem5 Developers } 104210037SARM gem5 Developers break; 104310037SARM gem5 Developers case MISCREG_SCR: 104410037SARM gem5 Developers tc->getITBPtr()->invalidateMiscReg(); 104510037SARM gem5 Developers tc->getDTBPtr()->invalidateMiscReg(); 104610037SARM gem5 Developers break; 10477408Sgblack@eecs.umich.edu case MISCREG_SCTLR: 10487408Sgblack@eecs.umich.edu { 10497408Sgblack@eecs.umich.edu DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal); 105010037SARM gem5 Developers MiscRegIndex sctlr_idx; 105110037SARM gem5 Developers scr = readMiscRegNoEffect(MISCREG_SCR); 105210037SARM gem5 Developers if (haveSecurity && !scr.ns) { 105310037SARM gem5 Developers sctlr_idx = MISCREG_SCTLR_S; 105410037SARM gem5 Developers } else { 105510037SARM gem5 Developers sctlr_idx = MISCREG_SCTLR_NS; 105610037SARM gem5 Developers // The FI field (bit 21) is common between S/NS versions 105710037SARM gem5 Developers // of the register, we store this in the secure copy of 105810037SARM gem5 Developers // the reg 105910037SARM gem5 Developers miscRegs[MISCREG_SCTLR_S] &= ~(1 << 21); 106010037SARM gem5 Developers miscRegs[MISCREG_SCTLR_S] |= newVal & (1 << 21); 106110037SARM gem5 Developers } 106210037SARM gem5 Developers SCTLR sctlr = miscRegs[sctlr_idx]; 10637408Sgblack@eecs.umich.edu SCTLR new_sctlr = newVal; 106410037SARM gem5 Developers new_sctlr.nmfi = ((bool)sctlr.nmfi) && !haveVirtualization; 106510037SARM gem5 Developers miscRegs[sctlr_idx] = (MiscReg)new_sctlr; 10667749SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 10677749SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 10687408Sgblack@eecs.umich.edu } 10699385SAndreas.Sandberg@arm.com case MISCREG_MIDR: 10709385SAndreas.Sandberg@arm.com case MISCREG_ID_PFR0: 10719385SAndreas.Sandberg@arm.com case MISCREG_ID_PFR1: 107210461SAndreas.Sandberg@ARM.com case MISCREG_ID_DFR0: 10739385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR0: 10749385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR1: 10759385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR2: 10769385SAndreas.Sandberg@arm.com case MISCREG_ID_MMFR3: 10779385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR0: 10789385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR1: 10799385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR2: 10809385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR3: 10819385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR4: 10829385SAndreas.Sandberg@arm.com case MISCREG_ID_ISAR5: 10839385SAndreas.Sandberg@arm.com 10849385SAndreas.Sandberg@arm.com case MISCREG_MPIDR: 10859385SAndreas.Sandberg@arm.com case MISCREG_FPSID: 10867408Sgblack@eecs.umich.edu case MISCREG_TLBTR: 10877408Sgblack@eecs.umich.edu case MISCREG_MVFR0: 10887408Sgblack@eecs.umich.edu case MISCREG_MVFR1: 108910037SARM gem5 Developers 109010037SARM gem5 Developers case MISCREG_ID_AA64AFR0_EL1: 109110037SARM gem5 Developers case MISCREG_ID_AA64AFR1_EL1: 109210037SARM gem5 Developers case MISCREG_ID_AA64DFR0_EL1: 109310037SARM gem5 Developers case MISCREG_ID_AA64DFR1_EL1: 109410037SARM gem5 Developers case MISCREG_ID_AA64ISAR0_EL1: 109510037SARM gem5 Developers case MISCREG_ID_AA64ISAR1_EL1: 109610037SARM gem5 Developers case MISCREG_ID_AA64MMFR0_EL1: 109710037SARM gem5 Developers case MISCREG_ID_AA64MMFR1_EL1: 109810037SARM gem5 Developers case MISCREG_ID_AA64PFR0_EL1: 109910037SARM gem5 Developers case MISCREG_ID_AA64PFR1_EL1: 11009385SAndreas.Sandberg@arm.com // ID registers are constants. 11017408Sgblack@eecs.umich.edu return; 11029385SAndreas.Sandberg@arm.com 110310037SARM gem5 Developers // TLBI all entries, EL0&1 inner sharable (ignored) 11047408Sgblack@eecs.umich.edu case MISCREG_TLBIALLIS: 110510037SARM gem5 Developers case MISCREG_TLBIALL: // TLBI all entries, EL0&1, 110610037SARM gem5 Developers assert32(tc); 110710037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 110810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 110910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 11108284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 11118284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 11128284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 11138284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 111410037SARM gem5 Developers oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el); 111510037SARM gem5 Developers oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el); 11168887Sgeoffrey.blake@arm.com 11178887Sgeoffrey.blake@arm.com // If CheckerCPU is connected, need to notify it of a flush 11188887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 11198733Sgeoffrey.blake@arm.com if (checker) { 112010037SARM gem5 Developers checker->getITBPtr()->flushAllSecurity(secure_lookup, 112110037SARM gem5 Developers target_el); 112210037SARM gem5 Developers checker->getDTBPtr()->flushAllSecurity(secure_lookup, 112310037SARM gem5 Developers target_el); 11248733Sgeoffrey.blake@arm.com } 11258284SAli.Saidi@ARM.com } 11267408Sgblack@eecs.umich.edu return; 112710037SARM gem5 Developers // TLBI all entries, EL0&1, instruction side 11287408Sgblack@eecs.umich.edu case MISCREG_ITLBIALL: 112910037SARM gem5 Developers assert32(tc); 113010037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 113110037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 113210037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 113310037SARM gem5 Developers tc->getITBPtr()->flushAllSecurity(secure_lookup, target_el); 11347408Sgblack@eecs.umich.edu return; 113510037SARM gem5 Developers // TLBI all entries, EL0&1, data side 11367408Sgblack@eecs.umich.edu case MISCREG_DTLBIALL: 113710037SARM gem5 Developers assert32(tc); 113810037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 113910037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 114010037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 114110037SARM gem5 Developers tc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el); 11427408Sgblack@eecs.umich.edu return; 114310037SARM gem5 Developers // TLBI based on VA, EL0&1 inner sharable (ignored) 11447408Sgblack@eecs.umich.edu case MISCREG_TLBIMVAIS: 11457408Sgblack@eecs.umich.edu case MISCREG_TLBIMVA: 114610037SARM gem5 Developers assert32(tc); 114710037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 114810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 114910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 11508284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 11518284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 11528284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 11538284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 11548284SAli.Saidi@ARM.com oc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 115510037SARM gem5 Developers bits(newVal, 7,0), 115610037SARM gem5 Developers secure_lookup, target_el); 11578284SAli.Saidi@ARM.com oc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 115810037SARM gem5 Developers bits(newVal, 7,0), 115910037SARM gem5 Developers secure_lookup, target_el); 11608887Sgeoffrey.blake@arm.com 11618887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 11628733Sgeoffrey.blake@arm.com if (checker) { 11638733Sgeoffrey.blake@arm.com checker->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 116410037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 11658733Sgeoffrey.blake@arm.com checker->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 116610037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 11678733Sgeoffrey.blake@arm.com } 11688284SAli.Saidi@ARM.com } 11697408Sgblack@eecs.umich.edu return; 117010037SARM gem5 Developers // TLBI by ASID, EL0&1, inner sharable 11717408Sgblack@eecs.umich.edu case MISCREG_TLBIASIDIS: 11727408Sgblack@eecs.umich.edu case MISCREG_TLBIASID: 117310037SARM gem5 Developers assert32(tc); 117410037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 117510037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 117610037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 11778284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 11788284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 11798284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 11808284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 118110037SARM gem5 Developers oc->getITBPtr()->flushAsid(bits(newVal, 7,0), 118210037SARM gem5 Developers secure_lookup, target_el); 118310037SARM gem5 Developers oc->getDTBPtr()->flushAsid(bits(newVal, 7,0), 118410037SARM gem5 Developers secure_lookup, target_el); 11858887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 11868733Sgeoffrey.blake@arm.com if (checker) { 118710037SARM gem5 Developers checker->getITBPtr()->flushAsid(bits(newVal, 7,0), 118810037SARM gem5 Developers secure_lookup, target_el); 118910037SARM gem5 Developers checker->getDTBPtr()->flushAsid(bits(newVal, 7,0), 119010037SARM gem5 Developers secure_lookup, target_el); 11918733Sgeoffrey.blake@arm.com } 11928284SAli.Saidi@ARM.com } 11937408Sgblack@eecs.umich.edu return; 119410037SARM gem5 Developers // TLBI by address, EL0&1, inner sharable (ignored) 11957408Sgblack@eecs.umich.edu case MISCREG_TLBIMVAAIS: 11967408Sgblack@eecs.umich.edu case MISCREG_TLBIMVAA: 119710037SARM gem5 Developers assert32(tc); 119810037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 119910037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 120010037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 120110037SARM gem5 Developers hyp = 0; 120210037SARM gem5 Developers tlbiMVA(tc, newVal, secure_lookup, hyp, target_el); 120310037SARM gem5 Developers return; 120410037SARM gem5 Developers // TLBI by address, EL2, hypervisor mode 120510037SARM gem5 Developers case MISCREG_TLBIMVAH: 120610037SARM gem5 Developers case MISCREG_TLBIMVAHIS: 120710037SARM gem5 Developers assert32(tc); 120810037SARM gem5 Developers target_el = 1; // aarch32, use hyp bit 120910037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 121010037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 121110037SARM gem5 Developers hyp = 1; 121210037SARM gem5 Developers tlbiMVA(tc, newVal, secure_lookup, hyp, target_el); 121310037SARM gem5 Developers return; 121410037SARM gem5 Developers // TLBI by address and asid, EL0&1, instruction side only 121510037SARM gem5 Developers case MISCREG_ITLBIMVA: 121610037SARM gem5 Developers assert32(tc); 121710037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 121810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 121910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 122010037SARM gem5 Developers tc->getITBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 122110037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 122210037SARM gem5 Developers return; 122310037SARM gem5 Developers // TLBI by address and asid, EL0&1, data side only 122410037SARM gem5 Developers case MISCREG_DTLBIMVA: 122510037SARM gem5 Developers assert32(tc); 122610037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 122710037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 122810037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 122910037SARM gem5 Developers tc->getDTBPtr()->flushMvaAsid(mbits(newVal, 31, 12), 123010037SARM gem5 Developers bits(newVal, 7,0), secure_lookup, target_el); 123110037SARM gem5 Developers return; 123210037SARM gem5 Developers // TLBI by ASID, EL0&1, instrution side only 123310037SARM gem5 Developers case MISCREG_ITLBIASID: 123410037SARM gem5 Developers assert32(tc); 123510037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 123610037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 123710037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 123810037SARM gem5 Developers tc->getITBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup, 123910037SARM gem5 Developers target_el); 124010037SARM gem5 Developers return; 124110037SARM gem5 Developers // TLBI by ASID EL0&1 data size only 124210037SARM gem5 Developers case MISCREG_DTLBIASID: 124310037SARM gem5 Developers assert32(tc); 124410037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 124510037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 124610037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 124710037SARM gem5 Developers tc->getDTBPtr()->flushAsid(bits(newVal, 7,0), secure_lookup, 124810037SARM gem5 Developers target_el); 124910037SARM gem5 Developers return; 125010037SARM gem5 Developers // Invalidate entire Non-secure Hyp/Non-Hyp Unified TLB 125110037SARM gem5 Developers case MISCREG_TLBIALLNSNH: 125210037SARM gem5 Developers case MISCREG_TLBIALLNSNHIS: 125310037SARM gem5 Developers assert32(tc); 125410037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 125510037SARM gem5 Developers hyp = 0; 125610037SARM gem5 Developers tlbiALLN(tc, hyp, target_el); 125710037SARM gem5 Developers return; 125810037SARM gem5 Developers // TLBI all entries, EL2, hyp, 125910037SARM gem5 Developers case MISCREG_TLBIALLH: 126010037SARM gem5 Developers case MISCREG_TLBIALLHIS: 126110037SARM gem5 Developers assert32(tc); 126210037SARM gem5 Developers target_el = 1; // aarch32, use hyp bit 126310037SARM gem5 Developers hyp = 1; 126410037SARM gem5 Developers tlbiALLN(tc, hyp, target_el); 126510037SARM gem5 Developers return; 126610037SARM gem5 Developers // AArch64 TLBI: invalidate all entries EL3 126710037SARM gem5 Developers case MISCREG_TLBI_ALLE3IS: 126810037SARM gem5 Developers case MISCREG_TLBI_ALLE3: 126910037SARM gem5 Developers assert64(tc); 127010037SARM gem5 Developers target_el = 3; 127110037SARM gem5 Developers secure_lookup = true; 127210037SARM gem5 Developers tlbiALL(tc, secure_lookup, target_el); 127310037SARM gem5 Developers return; 127410037SARM gem5 Developers // @todo: uncomment this to enable Virtualization 127510037SARM gem5 Developers // case MISCREG_TLBI_ALLE2IS: 127610037SARM gem5 Developers // case MISCREG_TLBI_ALLE2: 127710037SARM gem5 Developers // TLBI all entries, EL0&1 127810037SARM gem5 Developers case MISCREG_TLBI_ALLE1IS: 127910037SARM gem5 Developers case MISCREG_TLBI_ALLE1: 128010037SARM gem5 Developers // AArch64 TLBI: invalidate all entries, stage 1, current VMID 128110037SARM gem5 Developers case MISCREG_TLBI_VMALLE1IS: 128210037SARM gem5 Developers case MISCREG_TLBI_VMALLE1: 128310037SARM gem5 Developers // AArch64 TLBI: invalidate all entries, stages 1 & 2, current VMID 128410037SARM gem5 Developers case MISCREG_TLBI_VMALLS12E1IS: 128510037SARM gem5 Developers case MISCREG_TLBI_VMALLS12E1: 128610037SARM gem5 Developers // @todo: handle VMID and stage 2 to enable Virtualization 128710037SARM gem5 Developers assert64(tc); 128810037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 128910037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 129010037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 129110037SARM gem5 Developers tlbiALL(tc, secure_lookup, target_el); 129210037SARM gem5 Developers return; 129310037SARM gem5 Developers // AArch64 TLBI: invalidate by VA and ASID, stage 1, current VMID 129410037SARM gem5 Developers // VAEx(IS) and VALEx(IS) are the same because TLBs only store entries 129510037SARM gem5 Developers // from the last level of translation table walks 129610037SARM gem5 Developers // @todo: handle VMID to enable Virtualization 129710037SARM gem5 Developers // TLBI all entries, EL0&1 129810037SARM gem5 Developers case MISCREG_TLBI_VAE3IS_Xt: 129910037SARM gem5 Developers case MISCREG_TLBI_VAE3_Xt: 130010037SARM gem5 Developers // TLBI by VA, EL3 regime stage 1, last level walk 130110037SARM gem5 Developers case MISCREG_TLBI_VALE3IS_Xt: 130210037SARM gem5 Developers case MISCREG_TLBI_VALE3_Xt: 130310037SARM gem5 Developers assert64(tc); 130410037SARM gem5 Developers target_el = 3; 130510037SARM gem5 Developers asid = 0xbeef; // does not matter, tlbi is global 130610037SARM gem5 Developers secure_lookup = true; 130710037SARM gem5 Developers tlbiVA(tc, newVal, asid, secure_lookup, target_el); 130810037SARM gem5 Developers return; 130910037SARM gem5 Developers // TLBI by VA, EL2 131010037SARM gem5 Developers case MISCREG_TLBI_VAE2IS_Xt: 131110037SARM gem5 Developers case MISCREG_TLBI_VAE2_Xt: 131210037SARM gem5 Developers // TLBI by VA, EL2, stage1 last level walk 131310037SARM gem5 Developers case MISCREG_TLBI_VALE2IS_Xt: 131410037SARM gem5 Developers case MISCREG_TLBI_VALE2_Xt: 131510037SARM gem5 Developers assert64(tc); 131610037SARM gem5 Developers target_el = 2; 131710037SARM gem5 Developers asid = 0xbeef; // does not matter, tlbi is global 131810037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 131910037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 132010037SARM gem5 Developers tlbiVA(tc, newVal, asid, secure_lookup, target_el); 132110037SARM gem5 Developers return; 132210037SARM gem5 Developers // TLBI by VA EL1 & 0, stage1, ASID, current VMID 132310037SARM gem5 Developers case MISCREG_TLBI_VAE1IS_Xt: 132410037SARM gem5 Developers case MISCREG_TLBI_VAE1_Xt: 132510037SARM gem5 Developers case MISCREG_TLBI_VALE1IS_Xt: 132610037SARM gem5 Developers case MISCREG_TLBI_VALE1_Xt: 132710037SARM gem5 Developers assert64(tc); 132810037SARM gem5 Developers asid = bits(newVal, 63, 48); 132910037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 133010037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 133110037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 133210037SARM gem5 Developers tlbiVA(tc, newVal, asid, secure_lookup, target_el); 133310037SARM gem5 Developers return; 133410037SARM gem5 Developers // AArch64 TLBI: invalidate by ASID, stage 1, current VMID 133510037SARM gem5 Developers // @todo: handle VMID to enable Virtualization 133610037SARM gem5 Developers case MISCREG_TLBI_ASIDE1IS_Xt: 133710037SARM gem5 Developers case MISCREG_TLBI_ASIDE1_Xt: 133810037SARM gem5 Developers assert64(tc); 133910037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 134010037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 134110037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 13428284SAli.Saidi@ARM.com sys = tc->getSystemPtr(); 13438284SAli.Saidi@ARM.com for (x = 0; x < sys->numContexts(); x++) { 13448284SAli.Saidi@ARM.com oc = sys->getThreadContext(x); 13458284SAli.Saidi@ARM.com assert(oc->getITBPtr() && oc->getDTBPtr()); 134610037SARM gem5 Developers asid = bits(newVal, 63, 48); 134710709SAndreas.Sandberg@ARM.com if (!haveLargeAsid64) 134810037SARM gem5 Developers asid &= mask(8); 134910037SARM gem5 Developers oc->getITBPtr()->flushAsid(asid, secure_lookup, target_el); 135010037SARM gem5 Developers oc->getDTBPtr()->flushAsid(asid, secure_lookup, target_el); 135110037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 135210037SARM gem5 Developers if (checker) { 135310037SARM gem5 Developers checker->getITBPtr()->flushAsid(asid, 135410037SARM gem5 Developers secure_lookup, target_el); 135510037SARM gem5 Developers checker->getDTBPtr()->flushAsid(asid, 135610037SARM gem5 Developers secure_lookup, target_el); 135710037SARM gem5 Developers } 135810037SARM gem5 Developers } 135910037SARM gem5 Developers return; 136010037SARM gem5 Developers // AArch64 TLBI: invalidate by VA, ASID, stage 1, current VMID 136110037SARM gem5 Developers // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store 136210037SARM gem5 Developers // entries from the last level of translation table walks 136310037SARM gem5 Developers // @todo: handle VMID to enable Virtualization 136410037SARM gem5 Developers case MISCREG_TLBI_VAAE1IS_Xt: 136510037SARM gem5 Developers case MISCREG_TLBI_VAAE1_Xt: 136610037SARM gem5 Developers case MISCREG_TLBI_VAALE1IS_Xt: 136710037SARM gem5 Developers case MISCREG_TLBI_VAALE1_Xt: 136810037SARM gem5 Developers assert64(tc); 136910037SARM gem5 Developers target_el = 1; // el 0 and 1 are handled together 137010037SARM gem5 Developers scr = readMiscReg(MISCREG_SCR, tc); 137110037SARM gem5 Developers secure_lookup = haveSecurity && !scr.ns; 137210037SARM gem5 Developers sys = tc->getSystemPtr(); 137310037SARM gem5 Developers for (x = 0; x < sys->numContexts(); x++) { 137410037SARM gem5 Developers // @todo: extra controls on TLBI broadcast? 137510037SARM gem5 Developers oc = sys->getThreadContext(x); 137610037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 137710037SARM gem5 Developers Addr va = ((Addr) bits(newVal, 43, 0)) << 12; 137810037SARM gem5 Developers oc->getITBPtr()->flushMva(va, 137910037SARM gem5 Developers secure_lookup, false, target_el); 138010037SARM gem5 Developers oc->getDTBPtr()->flushMva(va, 138110037SARM gem5 Developers secure_lookup, false, target_el); 13828887Sgeoffrey.blake@arm.com 13838887Sgeoffrey.blake@arm.com CheckerCPU *checker = oc->getCheckerCpuPtr(); 13848733Sgeoffrey.blake@arm.com if (checker) { 138510037SARM gem5 Developers checker->getITBPtr()->flushMva(va, 138610037SARM gem5 Developers secure_lookup, false, target_el); 138710037SARM gem5 Developers checker->getDTBPtr()->flushMva(va, 138810037SARM gem5 Developers secure_lookup, false, target_el); 13898733Sgeoffrey.blake@arm.com } 13908284SAli.Saidi@ARM.com } 13917408Sgblack@eecs.umich.edu return; 139210037SARM gem5 Developers // AArch64 TLBI: invalidate by IPA, stage 2, current VMID 139310037SARM gem5 Developers case MISCREG_TLBI_IPAS2LE1IS_Xt: 139410037SARM gem5 Developers case MISCREG_TLBI_IPAS2LE1_Xt: 139510037SARM gem5 Developers case MISCREG_TLBI_IPAS2E1IS_Xt: 139610037SARM gem5 Developers case MISCREG_TLBI_IPAS2E1_Xt: 139710037SARM gem5 Developers assert64(tc); 139810037SARM gem5 Developers // @todo: implement these as part of Virtualization 139910037SARM gem5 Developers warn("Not doing anything for write of miscreg ITLB_IPAS2\n"); 14007405SAli.Saidi@ARM.com return; 14017583SAli.Saidi@arm.com case MISCREG_ACTLR: 14027583SAli.Saidi@arm.com warn("Not doing anything for write of miscreg ACTLR\n"); 14037583SAli.Saidi@arm.com break; 140410461SAndreas.Sandberg@ARM.com 140510461SAndreas.Sandberg@ARM.com case MISCREG_PMXEVTYPER_PMCCFILTR: 140610461SAndreas.Sandberg@ARM.com case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 140710461SAndreas.Sandberg@ARM.com case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 140810461SAndreas.Sandberg@ARM.com case MISCREG_PMCR ... MISCREG_PMOVSSET: 140910461SAndreas.Sandberg@ARM.com pmu->setMiscReg(misc_reg, newVal); 14107583SAli.Saidi@arm.com break; 141110461SAndreas.Sandberg@ARM.com 141210461SAndreas.Sandberg@ARM.com 141310037SARM gem5 Developers case MISCREG_HSTR: // TJDBX, now redifined to be RES0 141410037SARM gem5 Developers { 141510037SARM gem5 Developers HSTR hstrMask = 0; 141610037SARM gem5 Developers hstrMask.tjdbx = 1; 141710037SARM gem5 Developers newVal &= ~((uint32_t) hstrMask); 141810037SARM gem5 Developers break; 141910037SARM gem5 Developers } 142010037SARM gem5 Developers case MISCREG_HCPTR: 142110037SARM gem5 Developers { 142210037SARM gem5 Developers // If a CP bit in NSACR is 0 then the corresponding bit in 142310037SARM gem5 Developers // HCPTR is RAO/WI. Same applies to NSASEDIS 142410037SARM gem5 Developers secure_lookup = haveSecurity && 142510037SARM gem5 Developers inSecureState(readMiscRegNoEffect(MISCREG_SCR), 142610037SARM gem5 Developers readMiscRegNoEffect(MISCREG_CPSR)); 142710037SARM gem5 Developers if (!secure_lookup) { 142810037SARM gem5 Developers MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR); 142910037SARM gem5 Developers MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF; 143010037SARM gem5 Developers newVal = (newVal & ~mask) | (oldValue & mask); 143110037SARM gem5 Developers } 143210037SARM gem5 Developers break; 143310037SARM gem5 Developers } 143410037SARM gem5 Developers case MISCREG_HDFAR: // alias for secure DFAR 143510037SARM gem5 Developers misc_reg = MISCREG_DFAR_S; 143610037SARM gem5 Developers break; 143710037SARM gem5 Developers case MISCREG_HIFAR: // alias for secure IFAR 143810037SARM gem5 Developers misc_reg = MISCREG_IFAR_S; 143910037SARM gem5 Developers break; 144010037SARM gem5 Developers case MISCREG_ATS1CPR: 144110037SARM gem5 Developers case MISCREG_ATS1CPW: 144210037SARM gem5 Developers case MISCREG_ATS1CUR: 144310037SARM gem5 Developers case MISCREG_ATS1CUW: 144410037SARM gem5 Developers case MISCREG_ATS12NSOPR: 144510037SARM gem5 Developers case MISCREG_ATS12NSOPW: 144610037SARM gem5 Developers case MISCREG_ATS12NSOUR: 144710037SARM gem5 Developers case MISCREG_ATS12NSOUW: 144810037SARM gem5 Developers case MISCREG_ATS1HR: 144910037SARM gem5 Developers case MISCREG_ATS1HW: 14507436Sdam.sunwoo@arm.com { 145110037SARM gem5 Developers unsigned flags = 0; 145210037SARM gem5 Developers BaseTLB::Mode mode = BaseTLB::Read; 145310037SARM gem5 Developers TLB::ArmTranslationType tranType = TLB::NormalTran; 14547436Sdam.sunwoo@arm.com Fault fault; 14557436Sdam.sunwoo@arm.com switch(misc_reg) { 145610037SARM gem5 Developers case MISCREG_ATS1CPR: 145710037SARM gem5 Developers flags = TLB::MustBeOne; 145810037SARM gem5 Developers tranType = TLB::S1CTran; 145910037SARM gem5 Developers mode = BaseTLB::Read; 146010037SARM gem5 Developers break; 146110037SARM gem5 Developers case MISCREG_ATS1CPW: 146210037SARM gem5 Developers flags = TLB::MustBeOne; 146310037SARM gem5 Developers tranType = TLB::S1CTran; 146410037SARM gem5 Developers mode = BaseTLB::Write; 146510037SARM gem5 Developers break; 146610037SARM gem5 Developers case MISCREG_ATS1CUR: 146710037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 146810037SARM gem5 Developers tranType = TLB::S1CTran; 146910037SARM gem5 Developers mode = BaseTLB::Read; 147010037SARM gem5 Developers break; 147110037SARM gem5 Developers case MISCREG_ATS1CUW: 147210037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 147310037SARM gem5 Developers tranType = TLB::S1CTran; 147410037SARM gem5 Developers mode = BaseTLB::Write; 147510037SARM gem5 Developers break; 147610037SARM gem5 Developers case MISCREG_ATS12NSOPR: 147710037SARM gem5 Developers if (!haveSecurity) 147810037SARM gem5 Developers panic("Security Extensions required for ATS12NSOPR"); 147910037SARM gem5 Developers flags = TLB::MustBeOne; 148010037SARM gem5 Developers tranType = TLB::S1S2NsTran; 148110037SARM gem5 Developers mode = BaseTLB::Read; 148210037SARM gem5 Developers break; 148310037SARM gem5 Developers case MISCREG_ATS12NSOPW: 148410037SARM gem5 Developers if (!haveSecurity) 148510037SARM gem5 Developers panic("Security Extensions required for ATS12NSOPW"); 148610037SARM gem5 Developers flags = TLB::MustBeOne; 148710037SARM gem5 Developers tranType = TLB::S1S2NsTran; 148810037SARM gem5 Developers mode = BaseTLB::Write; 148910037SARM gem5 Developers break; 149010037SARM gem5 Developers case MISCREG_ATS12NSOUR: 149110037SARM gem5 Developers if (!haveSecurity) 149210037SARM gem5 Developers panic("Security Extensions required for ATS12NSOUR"); 149310037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 149410037SARM gem5 Developers tranType = TLB::S1S2NsTran; 149510037SARM gem5 Developers mode = BaseTLB::Read; 149610037SARM gem5 Developers break; 149710037SARM gem5 Developers case MISCREG_ATS12NSOUW: 149810037SARM gem5 Developers if (!haveSecurity) 149910037SARM gem5 Developers panic("Security Extensions required for ATS12NSOUW"); 150010037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 150110037SARM gem5 Developers tranType = TLB::S1S2NsTran; 150210037SARM gem5 Developers mode = BaseTLB::Write; 150310037SARM gem5 Developers break; 150410037SARM gem5 Developers case MISCREG_ATS1HR: // only really useful from secure mode. 150510037SARM gem5 Developers flags = TLB::MustBeOne; 150610037SARM gem5 Developers tranType = TLB::HypMode; 150710037SARM gem5 Developers mode = BaseTLB::Read; 150810037SARM gem5 Developers break; 150910037SARM gem5 Developers case MISCREG_ATS1HW: 151010037SARM gem5 Developers flags = TLB::MustBeOne; 151110037SARM gem5 Developers tranType = TLB::HypMode; 151210037SARM gem5 Developers mode = BaseTLB::Write; 151310037SARM gem5 Developers break; 15147436Sdam.sunwoo@arm.com } 151510037SARM gem5 Developers // If we're in timing mode then doing the translation in 151610037SARM gem5 Developers // functional mode then we're slightly distorting performance 151710037SARM gem5 Developers // results obtained from simulations. The translation should be 151810037SARM gem5 Developers // done in the same mode the core is running in. NOTE: This 151910037SARM gem5 Developers // can't be an atomic translation because that causes problems 152010037SARM gem5 Developers // with unexpected atomic snoop requests. 152110037SARM gem5 Developers warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 152210653Sandreas.hansson@arm.com Request req(0, val, 1, flags, Request::funcMasterId, 152310653Sandreas.hansson@arm.com tc->pcState().pc(), tc->contextId(), 152410653Sandreas.hansson@arm.com tc->threadId()); 152510653Sandreas.hansson@arm.com fault = tc->getDTBPtr()->translateFunctional(&req, tc, mode, tranType); 152610037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 152710037SARM gem5 Developers HCR hcr = readMiscRegNoEffect(MISCREG_HCR); 152810037SARM gem5 Developers 152910037SARM gem5 Developers MiscReg newVal; 15307436Sdam.sunwoo@arm.com if (fault == NoFault) { 153110653Sandreas.hansson@arm.com Addr paddr = req.getPaddr(); 153210037SARM gem5 Developers if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode || 153310037SARM gem5 Developers ((tranType & TLB::S1S2NsTran) && hcr.vm) )) { 153410037SARM gem5 Developers newVal = (paddr & mask(39, 12)) | 153510037SARM gem5 Developers (tc->getDTBPtr()->getAttr()); 153610037SARM gem5 Developers } else { 153710037SARM gem5 Developers newVal = (paddr & 0xfffff000) | 153810037SARM gem5 Developers (tc->getDTBPtr()->getAttr()); 153910037SARM gem5 Developers } 15407436Sdam.sunwoo@arm.com DPRINTF(MiscRegs, 15417436Sdam.sunwoo@arm.com "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n", 154210037SARM gem5 Developers val, newVal); 154310037SARM gem5 Developers } else { 154410037SARM gem5 Developers ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get()); 154510037SARM gem5 Developers // Set fault bit and FSR 154610037SARM gem5 Developers FSR fsr = armFault->getFsr(tc); 154710037SARM gem5 Developers 154810037SARM gem5 Developers newVal = ((fsr >> 9) & 1) << 11; 154910037SARM gem5 Developers if (newVal) { 155010037SARM gem5 Developers // LPAE - rearange fault status 155110037SARM gem5 Developers newVal |= ((fsr >> 0) & 0x3f) << 1; 155210037SARM gem5 Developers } else { 155310037SARM gem5 Developers // VMSA - rearange fault status 155410037SARM gem5 Developers newVal |= ((fsr >> 0) & 0xf) << 1; 155510037SARM gem5 Developers newVal |= ((fsr >> 10) & 0x1) << 5; 155610037SARM gem5 Developers newVal |= ((fsr >> 12) & 0x1) << 6; 155710037SARM gem5 Developers } 155810037SARM gem5 Developers newVal |= 0x1; // F bit 155910037SARM gem5 Developers newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 156010037SARM gem5 Developers newVal |= armFault->isStage2() ? 0x200 : 0; 156110037SARM gem5 Developers DPRINTF(MiscRegs, 156210037SARM gem5 Developers "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n", 156310037SARM gem5 Developers val, fsr, newVal); 15647436Sdam.sunwoo@arm.com } 156510037SARM gem5 Developers setMiscRegNoEffect(MISCREG_PAR, newVal); 15667436Sdam.sunwoo@arm.com return; 15677436Sdam.sunwoo@arm.com } 156810037SARM gem5 Developers case MISCREG_TTBCR: 156910037SARM gem5 Developers { 157010037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 157110037SARM gem5 Developers const uint32_t ones = (uint32_t)(-1); 157210037SARM gem5 Developers TTBCR ttbcrMask = 0; 157310037SARM gem5 Developers TTBCR ttbcrNew = newVal; 157410037SARM gem5 Developers 157510037SARM gem5 Developers // ARM DDI 0406C.b, ARMv7-32 157610037SARM gem5 Developers ttbcrMask.n = ones; // T0SZ 157710037SARM gem5 Developers if (haveSecurity) { 157810037SARM gem5 Developers ttbcrMask.pd0 = ones; 157910037SARM gem5 Developers ttbcrMask.pd1 = ones; 158010037SARM gem5 Developers } 158110037SARM gem5 Developers ttbcrMask.epd0 = ones; 158210037SARM gem5 Developers ttbcrMask.irgn0 = ones; 158310037SARM gem5 Developers ttbcrMask.orgn0 = ones; 158410037SARM gem5 Developers ttbcrMask.sh0 = ones; 158510037SARM gem5 Developers ttbcrMask.ps = ones; // T1SZ 158610037SARM gem5 Developers ttbcrMask.a1 = ones; 158710037SARM gem5 Developers ttbcrMask.epd1 = ones; 158810037SARM gem5 Developers ttbcrMask.irgn1 = ones; 158910037SARM gem5 Developers ttbcrMask.orgn1 = ones; 159010037SARM gem5 Developers ttbcrMask.sh1 = ones; 159110037SARM gem5 Developers if (haveLPAE) 159210037SARM gem5 Developers ttbcrMask.eae = ones; 159310037SARM gem5 Developers 159410037SARM gem5 Developers if (haveLPAE && ttbcrNew.eae) { 159510037SARM gem5 Developers newVal = newVal & ttbcrMask; 159610037SARM gem5 Developers } else { 159710037SARM gem5 Developers newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask)); 159810037SARM gem5 Developers } 159910037SARM gem5 Developers } 160010037SARM gem5 Developers case MISCREG_TTBR0: 160110037SARM gem5 Developers case MISCREG_TTBR1: 160210037SARM gem5 Developers { 160310037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 160410037SARM gem5 Developers if (haveLPAE) { 160510037SARM gem5 Developers if (ttbcr.eae) { 160610037SARM gem5 Developers // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP 160710037SARM gem5 Developers // ARMv8 AArch32 bit 63-56 only 160810037SARM gem5 Developers uint64_t ttbrMask = mask(63,56) | mask(47,40); 160910037SARM gem5 Developers newVal = (newVal & (~ttbrMask)); 161010037SARM gem5 Developers } 161110037SARM gem5 Developers } 161210037SARM gem5 Developers } 161310508SAli.Saidi@ARM.com case MISCREG_SCTLR_EL1: 161410508SAli.Saidi@ARM.com { 161510508SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 161610508SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 161710508SAli.Saidi@ARM.com setMiscRegNoEffect(misc_reg, newVal); 161810508SAli.Saidi@ARM.com } 16197749SAli.Saidi@ARM.com case MISCREG_CONTEXTIDR: 16207749SAli.Saidi@ARM.com case MISCREG_PRRR: 16217749SAli.Saidi@ARM.com case MISCREG_NMRR: 162210037SARM gem5 Developers case MISCREG_MAIR0: 162310037SARM gem5 Developers case MISCREG_MAIR1: 16247749SAli.Saidi@ARM.com case MISCREG_DACR: 162510037SARM gem5 Developers case MISCREG_VTTBR: 162610037SARM gem5 Developers case MISCREG_SCR_EL3: 162710037SARM gem5 Developers case MISCREG_TCR_EL1: 162810037SARM gem5 Developers case MISCREG_TCR_EL2: 162910037SARM gem5 Developers case MISCREG_TCR_EL3: 163010508SAli.Saidi@ARM.com case MISCREG_SCTLR_EL2: 163110508SAli.Saidi@ARM.com case MISCREG_SCTLR_EL3: 163210037SARM gem5 Developers case MISCREG_TTBR0_EL1: 163310037SARM gem5 Developers case MISCREG_TTBR1_EL1: 163410037SARM gem5 Developers case MISCREG_TTBR0_EL2: 163510037SARM gem5 Developers case MISCREG_TTBR0_EL3: 16367749SAli.Saidi@ARM.com tc->getITBPtr()->invalidateMiscReg(); 16377749SAli.Saidi@ARM.com tc->getDTBPtr()->invalidateMiscReg(); 16387749SAli.Saidi@ARM.com break; 163910037SARM gem5 Developers case MISCREG_NZCV: 164010037SARM gem5 Developers { 164110037SARM gem5 Developers CPSR cpsr = val; 164210037SARM gem5 Developers 164310338SCurtis.Dunham@arm.com tc->setCCReg(CCREG_NZ, cpsr.nz); 164410338SCurtis.Dunham@arm.com tc->setCCReg(CCREG_C, cpsr.c); 164510338SCurtis.Dunham@arm.com tc->setCCReg(CCREG_V, cpsr.v); 164610037SARM gem5 Developers } 164710037SARM gem5 Developers break; 164810037SARM gem5 Developers case MISCREG_DAIF: 164910037SARM gem5 Developers { 165010037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 165110037SARM gem5 Developers cpsr.daif = (uint8_t) ((CPSR) newVal).daif; 165210037SARM gem5 Developers newVal = cpsr; 165310037SARM gem5 Developers misc_reg = MISCREG_CPSR; 165410037SARM gem5 Developers } 165510037SARM gem5 Developers break; 165610037SARM gem5 Developers case MISCREG_SP_EL0: 165710037SARM gem5 Developers tc->setIntReg(INTREG_SP0, newVal); 165810037SARM gem5 Developers break; 165910037SARM gem5 Developers case MISCREG_SP_EL1: 166010037SARM gem5 Developers tc->setIntReg(INTREG_SP1, newVal); 166110037SARM gem5 Developers break; 166210037SARM gem5 Developers case MISCREG_SP_EL2: 166310037SARM gem5 Developers tc->setIntReg(INTREG_SP2, newVal); 166410037SARM gem5 Developers break; 166510037SARM gem5 Developers case MISCREG_SPSEL: 166610037SARM gem5 Developers { 166710037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 166810037SARM gem5 Developers cpsr.sp = (uint8_t) ((CPSR) newVal).sp; 166910037SARM gem5 Developers newVal = cpsr; 167010037SARM gem5 Developers misc_reg = MISCREG_CPSR; 167110037SARM gem5 Developers } 167210037SARM gem5 Developers break; 167310037SARM gem5 Developers case MISCREG_CURRENTEL: 167410037SARM gem5 Developers { 167510037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 167610037SARM gem5 Developers cpsr.el = (uint8_t) ((CPSR) newVal).el; 167710037SARM gem5 Developers newVal = cpsr; 167810037SARM gem5 Developers misc_reg = MISCREG_CPSR; 167910037SARM gem5 Developers } 168010037SARM gem5 Developers break; 168110037SARM gem5 Developers case MISCREG_AT_S1E1R_Xt: 168210037SARM gem5 Developers case MISCREG_AT_S1E1W_Xt: 168310037SARM gem5 Developers case MISCREG_AT_S1E0R_Xt: 168410037SARM gem5 Developers case MISCREG_AT_S1E0W_Xt: 168510037SARM gem5 Developers case MISCREG_AT_S1E2R_Xt: 168610037SARM gem5 Developers case MISCREG_AT_S1E2W_Xt: 168710037SARM gem5 Developers case MISCREG_AT_S12E1R_Xt: 168810037SARM gem5 Developers case MISCREG_AT_S12E1W_Xt: 168910037SARM gem5 Developers case MISCREG_AT_S12E0R_Xt: 169010037SARM gem5 Developers case MISCREG_AT_S12E0W_Xt: 169110037SARM gem5 Developers case MISCREG_AT_S1E3R_Xt: 169210037SARM gem5 Developers case MISCREG_AT_S1E3W_Xt: 169310037SARM gem5 Developers { 169410037SARM gem5 Developers RequestPtr req = new Request; 169510037SARM gem5 Developers unsigned flags = 0; 169610037SARM gem5 Developers BaseTLB::Mode mode = BaseTLB::Read; 169710037SARM gem5 Developers TLB::ArmTranslationType tranType = TLB::NormalTran; 169810037SARM gem5 Developers Fault fault; 169910037SARM gem5 Developers switch(misc_reg) { 170010037SARM gem5 Developers case MISCREG_AT_S1E1R_Xt: 170110037SARM gem5 Developers flags = TLB::MustBeOne; 170210037SARM gem5 Developers tranType = TLB::S1CTran; 170310037SARM gem5 Developers mode = BaseTLB::Read; 170410037SARM gem5 Developers break; 170510037SARM gem5 Developers case MISCREG_AT_S1E1W_Xt: 170610037SARM gem5 Developers flags = TLB::MustBeOne; 170710037SARM gem5 Developers tranType = TLB::S1CTran; 170810037SARM gem5 Developers mode = BaseTLB::Write; 170910037SARM gem5 Developers break; 171010037SARM gem5 Developers case MISCREG_AT_S1E0R_Xt: 171110037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 171210037SARM gem5 Developers tranType = TLB::S1CTran; 171310037SARM gem5 Developers mode = BaseTLB::Read; 171410037SARM gem5 Developers break; 171510037SARM gem5 Developers case MISCREG_AT_S1E0W_Xt: 171610037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 171710037SARM gem5 Developers tranType = TLB::S1CTran; 171810037SARM gem5 Developers mode = BaseTLB::Write; 171910037SARM gem5 Developers break; 172010037SARM gem5 Developers case MISCREG_AT_S1E2R_Xt: 172110037SARM gem5 Developers flags = TLB::MustBeOne; 172210037SARM gem5 Developers tranType = TLB::HypMode; 172310037SARM gem5 Developers mode = BaseTLB::Read; 172410037SARM gem5 Developers break; 172510037SARM gem5 Developers case MISCREG_AT_S1E2W_Xt: 172610037SARM gem5 Developers flags = TLB::MustBeOne; 172710037SARM gem5 Developers tranType = TLB::HypMode; 172810037SARM gem5 Developers mode = BaseTLB::Write; 172910037SARM gem5 Developers break; 173010037SARM gem5 Developers case MISCREG_AT_S12E0R_Xt: 173110037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 173210037SARM gem5 Developers tranType = TLB::S1S2NsTran; 173310037SARM gem5 Developers mode = BaseTLB::Read; 173410037SARM gem5 Developers break; 173510037SARM gem5 Developers case MISCREG_AT_S12E0W_Xt: 173610037SARM gem5 Developers flags = TLB::MustBeOne | TLB::UserMode; 173710037SARM gem5 Developers tranType = TLB::S1S2NsTran; 173810037SARM gem5 Developers mode = BaseTLB::Write; 173910037SARM gem5 Developers break; 174010037SARM gem5 Developers case MISCREG_AT_S12E1R_Xt: 174110037SARM gem5 Developers flags = TLB::MustBeOne; 174210037SARM gem5 Developers tranType = TLB::S1S2NsTran; 174310037SARM gem5 Developers mode = BaseTLB::Read; 174410037SARM gem5 Developers break; 174510037SARM gem5 Developers case MISCREG_AT_S12E1W_Xt: 174610037SARM gem5 Developers flags = TLB::MustBeOne; 174710037SARM gem5 Developers tranType = TLB::S1S2NsTran; 174810037SARM gem5 Developers mode = BaseTLB::Write; 174910037SARM gem5 Developers break; 175010037SARM gem5 Developers case MISCREG_AT_S1E3R_Xt: 175110037SARM gem5 Developers flags = TLB::MustBeOne; 175210037SARM gem5 Developers tranType = TLB::HypMode; // There is no TZ mode defined. 175310037SARM gem5 Developers mode = BaseTLB::Read; 175410037SARM gem5 Developers break; 175510037SARM gem5 Developers case MISCREG_AT_S1E3W_Xt: 175610037SARM gem5 Developers flags = TLB::MustBeOne; 175710037SARM gem5 Developers tranType = TLB::HypMode; // There is no TZ mode defined. 175810037SARM gem5 Developers mode = BaseTLB::Write; 175910037SARM gem5 Developers break; 176010037SARM gem5 Developers } 176110037SARM gem5 Developers // If we're in timing mode then doing the translation in 176210037SARM gem5 Developers // functional mode then we're slightly distorting performance 176310037SARM gem5 Developers // results obtained from simulations. The translation should be 176410037SARM gem5 Developers // done in the same mode the core is running in. NOTE: This 176510037SARM gem5 Developers // can't be an atomic translation because that causes problems 176610037SARM gem5 Developers // with unexpected atomic snoop requests. 176710037SARM gem5 Developers warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 176810037SARM gem5 Developers req->setVirt(0, val, 1, flags, Request::funcMasterId, 176910037SARM gem5 Developers tc->pcState().pc()); 177010037SARM gem5 Developers req->setThreadContext(tc->contextId(), tc->threadId()); 177110037SARM gem5 Developers fault = tc->getDTBPtr()->translateFunctional(req, tc, mode, 177210037SARM gem5 Developers tranType); 177310037SARM gem5 Developers 177410037SARM gem5 Developers MiscReg newVal; 177510037SARM gem5 Developers if (fault == NoFault) { 177610037SARM gem5 Developers Addr paddr = req->getPaddr(); 177710037SARM gem5 Developers uint64_t attr = tc->getDTBPtr()->getAttr(); 177810037SARM gem5 Developers uint64_t attr1 = attr >> 56; 177910037SARM gem5 Developers if (!attr1 || attr1 ==0x44) { 178010037SARM gem5 Developers attr |= 0x100; 178110037SARM gem5 Developers attr &= ~ uint64_t(0x80); 178210037SARM gem5 Developers } 178310037SARM gem5 Developers newVal = (paddr & mask(47, 12)) | attr; 178410037SARM gem5 Developers DPRINTF(MiscRegs, 178510037SARM gem5 Developers "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n", 178610037SARM gem5 Developers val, newVal); 178710037SARM gem5 Developers } else { 178810037SARM gem5 Developers ArmFault *armFault = reinterpret_cast<ArmFault *>(fault.get()); 178910037SARM gem5 Developers // Set fault bit and FSR 179010037SARM gem5 Developers FSR fsr = armFault->getFsr(tc); 179110037SARM gem5 Developers 179210037SARM gem5 Developers newVal = ((fsr >> 9) & 1) << 11; 179310037SARM gem5 Developers // rearange fault status 179410037SARM gem5 Developers newVal |= ((fsr >> 0) & 0x3f) << 1; 179510037SARM gem5 Developers newVal |= 0x1; // F bit 179610037SARM gem5 Developers newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 179710037SARM gem5 Developers newVal |= armFault->isStage2() ? 0x200 : 0; 179810037SARM gem5 Developers DPRINTF(MiscRegs, 179910037SARM gem5 Developers "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n", 180010037SARM gem5 Developers val, fsr, newVal); 180110037SARM gem5 Developers } 180210037SARM gem5 Developers delete req; 180310037SARM gem5 Developers setMiscRegNoEffect(MISCREG_PAR_EL1, newVal); 180410037SARM gem5 Developers return; 180510037SARM gem5 Developers } 180610037SARM gem5 Developers case MISCREG_SPSR_EL3: 180710037SARM gem5 Developers case MISCREG_SPSR_EL2: 180810037SARM gem5 Developers case MISCREG_SPSR_EL1: 180910037SARM gem5 Developers // Force bits 23:21 to 0 181010037SARM gem5 Developers newVal = val & ~(0x7 << 21); 181110037SARM gem5 Developers break; 18128549Sdaniel.johnson@arm.com case MISCREG_L2CTLR: 18138549Sdaniel.johnson@arm.com warn("miscreg L2CTLR (%s) written with %#x. ignored...\n", 18148549Sdaniel.johnson@arm.com miscRegName[misc_reg], uint32_t(val)); 181510037SARM gem5 Developers break; 181610037SARM gem5 Developers 181710037SARM gem5 Developers // Generic Timer registers 181810844Sandreas.sandberg@arm.com case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 181910844Sandreas.sandberg@arm.com case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 182010844Sandreas.sandberg@arm.com case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 182110844Sandreas.sandberg@arm.com case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 182210844Sandreas.sandberg@arm.com getGenericTimer(tc).setMiscReg(misc_reg, newVal); 182310037SARM gem5 Developers break; 18247405SAli.Saidi@ARM.com } 18257405SAli.Saidi@ARM.com } 18267405SAli.Saidi@ARM.com setMiscRegNoEffect(misc_reg, newVal); 18277405SAli.Saidi@ARM.com} 18287405SAli.Saidi@ARM.com 182910037SARM gem5 Developersvoid 183010709SAndreas.Sandberg@ARM.comISA::tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid, 183110709SAndreas.Sandberg@ARM.com bool secure_lookup, uint8_t target_el) 183210037SARM gem5 Developers{ 183310709SAndreas.Sandberg@ARM.com if (!haveLargeAsid64) 183410037SARM gem5 Developers asid &= mask(8); 183510037SARM gem5 Developers Addr va = ((Addr) bits(newVal, 43, 0)) << 12; 183610037SARM gem5 Developers System *sys = tc->getSystemPtr(); 183710037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 183810037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 183910037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 184010037SARM gem5 Developers oc->getITBPtr()->flushMvaAsid(va, asid, 184110037SARM gem5 Developers secure_lookup, target_el); 184210037SARM gem5 Developers oc->getDTBPtr()->flushMvaAsid(va, asid, 184310037SARM gem5 Developers secure_lookup, target_el); 184410037SARM gem5 Developers 184510037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 184610037SARM gem5 Developers if (checker) { 184710037SARM gem5 Developers checker->getITBPtr()->flushMvaAsid( 184810037SARM gem5 Developers va, asid, secure_lookup, target_el); 184910037SARM gem5 Developers checker->getDTBPtr()->flushMvaAsid( 185010037SARM gem5 Developers va, asid, secure_lookup, target_el); 185110037SARM gem5 Developers } 185210037SARM gem5 Developers } 185310037SARM gem5 Developers} 185410037SARM gem5 Developers 185510037SARM gem5 Developersvoid 185610037SARM gem5 DevelopersISA::tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el) 185710037SARM gem5 Developers{ 185810037SARM gem5 Developers System *sys = tc->getSystemPtr(); 185910037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 186010037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 186110037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 186210037SARM gem5 Developers oc->getITBPtr()->flushAllSecurity(secure_lookup, target_el); 186310037SARM gem5 Developers oc->getDTBPtr()->flushAllSecurity(secure_lookup, target_el); 186410037SARM gem5 Developers 186510037SARM gem5 Developers // If CheckerCPU is connected, need to notify it of a flush 186610037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 186710037SARM gem5 Developers if (checker) { 186810037SARM gem5 Developers checker->getITBPtr()->flushAllSecurity(secure_lookup, 186910037SARM gem5 Developers target_el); 187010037SARM gem5 Developers checker->getDTBPtr()->flushAllSecurity(secure_lookup, 187110037SARM gem5 Developers target_el); 187210037SARM gem5 Developers } 187310037SARM gem5 Developers } 187410037SARM gem5 Developers} 187510037SARM gem5 Developers 187610037SARM gem5 Developersvoid 187710037SARM gem5 DevelopersISA::tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el) 187810037SARM gem5 Developers{ 187910037SARM gem5 Developers System *sys = tc->getSystemPtr(); 188010037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 188110037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 188210037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 188310037SARM gem5 Developers oc->getITBPtr()->flushAllNs(hyp, target_el); 188410037SARM gem5 Developers oc->getDTBPtr()->flushAllNs(hyp, target_el); 188510037SARM gem5 Developers 188610037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 188710037SARM gem5 Developers if (checker) { 188810037SARM gem5 Developers checker->getITBPtr()->flushAllNs(hyp, target_el); 188910037SARM gem5 Developers checker->getDTBPtr()->flushAllNs(hyp, target_el); 189010037SARM gem5 Developers } 189110037SARM gem5 Developers } 189210037SARM gem5 Developers} 189310037SARM gem5 Developers 189410037SARM gem5 Developersvoid 189510037SARM gem5 DevelopersISA::tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, bool hyp, 189610037SARM gem5 Developers uint8_t target_el) 189710037SARM gem5 Developers{ 189810037SARM gem5 Developers System *sys = tc->getSystemPtr(); 189910037SARM gem5 Developers for (int x = 0; x < sys->numContexts(); x++) { 190010037SARM gem5 Developers ThreadContext *oc = sys->getThreadContext(x); 190110037SARM gem5 Developers assert(oc->getITBPtr() && oc->getDTBPtr()); 190210037SARM gem5 Developers oc->getITBPtr()->flushMva(mbits(newVal, 31,12), 190310037SARM gem5 Developers secure_lookup, hyp, target_el); 190410037SARM gem5 Developers oc->getDTBPtr()->flushMva(mbits(newVal, 31,12), 190510037SARM gem5 Developers secure_lookup, hyp, target_el); 190610037SARM gem5 Developers 190710037SARM gem5 Developers CheckerCPU *checker = oc->getCheckerCpuPtr(); 190810037SARM gem5 Developers if (checker) { 190910037SARM gem5 Developers checker->getITBPtr()->flushMva(mbits(newVal, 31,12), 191010037SARM gem5 Developers secure_lookup, hyp, target_el); 191110037SARM gem5 Developers checker->getDTBPtr()->flushMva(mbits(newVal, 31,12), 191210037SARM gem5 Developers secure_lookup, hyp, target_el); 191310037SARM gem5 Developers } 191410037SARM gem5 Developers } 191510037SARM gem5 Developers} 191610037SARM gem5 Developers 191710844Sandreas.sandberg@arm.comBaseISADevice & 191810844Sandreas.sandberg@arm.comISA::getGenericTimer(ThreadContext *tc) 191910037SARM gem5 Developers{ 192010844Sandreas.sandberg@arm.com // We only need to create an ISA interface the first time we try 192110844Sandreas.sandberg@arm.com // to access the timer. 192210844Sandreas.sandberg@arm.com if (timer) 192310844Sandreas.sandberg@arm.com return *timer.get(); 192410844Sandreas.sandberg@arm.com 192510844Sandreas.sandberg@arm.com assert(system); 192610844Sandreas.sandberg@arm.com GenericTimer *generic_timer(system->getGenericTimer()); 192710844Sandreas.sandberg@arm.com if (!generic_timer) { 192810844Sandreas.sandberg@arm.com panic("Trying to get a generic timer from a system that hasn't " 192910844Sandreas.sandberg@arm.com "been configured to use a generic timer.\n"); 193010037SARM gem5 Developers } 193110037SARM gem5 Developers 193211150Smitch.hayenga@arm.com timer.reset(new GenericTimerISA(*generic_timer, tc->contextId())); 193310844Sandreas.sandberg@arm.com return *timer.get(); 193410037SARM gem5 Developers} 193510037SARM gem5 Developers 19367405SAli.Saidi@ARM.com} 19379384SAndreas.Sandberg@arm.com 19389384SAndreas.Sandberg@arm.comArmISA::ISA * 19399384SAndreas.Sandberg@arm.comArmISAParams::create() 19409384SAndreas.Sandberg@arm.com{ 19419384SAndreas.Sandberg@arm.com return new ArmISA::ISA(this); 19429384SAndreas.Sandberg@arm.com} 1943