isa.cc revision 12763
12810SN/A/* 29614Srene.dejong@arm.com * Copyright (c) 2010-2018 ARM Limited 38856Sandreas.hansson@arm.com * All rights reserved 48856Sandreas.hansson@arm.com * 58856Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 68856Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 78856Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 88856Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 98856Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 108856Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 118856Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 128856Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 138856Sandreas.hansson@arm.com * 142810SN/A * Redistribution and use in source and binary forms, with or without 152810SN/A * modification, are permitted provided that the following conditions are 162810SN/A * met: redistributions of source code must retain the above copyright 172810SN/A * notice, this list of conditions and the following disclaimer; 182810SN/A * redistributions in binary form must reproduce the above copyright 192810SN/A * notice, this list of conditions and the following disclaimer in the 202810SN/A * documentation and/or other materials provided with the distribution; 212810SN/A * neither the name of the copyright holders nor the names of its 222810SN/A * contributors may be used to endorse or promote products derived from 232810SN/A * this software without specific prior written permission. 242810SN/A * 252810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 262810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 272810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 282810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 292810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 302810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 312810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 322810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 332810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 342810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 352810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 362810SN/A * 372810SN/A * Authors: Gabe Black 382810SN/A * Ali Saidi 392810SN/A */ 402810SN/A 412810SN/A#include "arch/arm/isa.hh" 422810SN/A#include "arch/arm/pmu.hh" 432810SN/A#include "arch/arm/system.hh" 442810SN/A#include "arch/arm/tlb.hh" 452810SN/A#include "arch/arm/tlbi_op.hh" 462810SN/A#include "cpu/base.hh" 472810SN/A#include "cpu/checker/cpu.hh" 483348SN/A#include "debug/Arm.hh" 493348SN/A#include "debug/MiscRegs.hh" 508232Snate@binkert.org#include "dev/arm/generic_timer.hh" 519152Satgutier@umich.edu#include "params/ArmISA.hh" 525338Sstever@gmail.com#include "sim/faults.hh" 535338Sstever@gmail.com#include "sim/stat_control.hh" 548786Sgblack@eecs.umich.edu#include "sim/system.hh" 552810SN/A 562810SN/Anamespace ArmISA 572810SN/A{ 588856Sandreas.hansson@arm.com 598856Sandreas.hansson@arm.comISA::ISA(Params *p) 608856Sandreas.hansson@arm.com : SimObject(p), 618922Swilliam.wang@arm.com system(NULL), 628914Sandreas.hansson@arm.com _decoderFlavour(p->decoderFlavour), 638856Sandreas.hansson@arm.com _vecRegRenameMode(p->vecRegRenameMode), 648856Sandreas.hansson@arm.com pmu(p->pmu), 654475SN/A impdefAsNop(p->impdef_nop) 665034SN/A{ 675034SN/A miscRegs[MISCREG_SCTLR_RST] = 0; 685314SN/A 695314SN/A // Hook up a dummy device if we haven't been configured with a 704628SN/A // real PMU. By using a dummy device, we don't need to check that 715034SN/A // the PMU exist every time we try to access a PMU register. 729263Smrinmoy.ghosh@arm.com if (!pmu) 739263Smrinmoy.ghosh@arm.com pmu = &dummyDevice; 745034SN/A 756122SSteve.Reinhardt@amd.com // Give all ISA devices a pointer to this ISA 768134SAli.Saidi@ARM.com pmu->setISA(this); 774626SN/A 784626SN/A system = dynamic_cast<ArmSystem *>(p->system); 795034SN/A 808883SAli.Saidi@ARM.com // Cache system-level properties 818833Sdam.sunwoo@arm.com if (FullSystem && system) { 824458SN/A highestELIs64 = system->highestELIs64(); 832810SN/A haveSecurity = system->haveSecurity(); 842810SN/A haveLPAE = system->haveLPAE(); 853013SN/A haveVirtualization = system->haveVirtualization(); 868856Sandreas.hansson@arm.com haveLargeAsid64 = system->haveLargeAsid64(); 872810SN/A physAddrRange64 = system->physAddrRange64(); 883013SN/A } else { 898856Sandreas.hansson@arm.com highestELIs64 = true; // ArmSystem::highestELIs64 does the same 902810SN/A haveSecurity = haveLPAE = haveVirtualization = false; 919614Srene.dejong@arm.com haveLargeAsid64 = false; 929614Srene.dejong@arm.com physAddrRange64 = 32; // dummy value 939614Srene.dejong@arm.com } 949614Srene.dejong@arm.com 959614Srene.dejong@arm.com initializeMiscRegMetadata(); 969614Srene.dejong@arm.com preUnflattenMiscReg(); 979614Srene.dejong@arm.com 982810SN/A clear(); 992810SN/A} 1002810SN/A 1018856Sandreas.hansson@arm.comstd::vector<struct ISA::MiscRegLUTEntry> ISA::lookUpMiscReg(NUM_MISCREGS); 1022810SN/A 1033013SN/Aconst ArmISAParams * 1048856Sandreas.hansson@arm.comISA::params() const 1053013SN/A{ 1068856Sandreas.hansson@arm.com return dynamic_cast<const Params *>(_params); 1078856Sandreas.hansson@arm.com} 1082897SN/A 1094666SN/Avoid 1108922Swilliam.wang@arm.comISA::clear() 1112897SN/A{ 1122810SN/A const Params *p(params()); 1132810SN/A 1142844SN/A SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST]; 1152810SN/A memset(miscRegs, 0, sizeof(miscRegs)); 1162858SN/A 1172858SN/A // Initialize configurable default values 1188856Sandreas.hansson@arm.com miscRegs[MISCREG_MIDR] = p->midr; 1198922Swilliam.wang@arm.com miscRegs[MISCREG_MIDR_EL1] = p->midr; 1208711Sandreas.hansson@arm.com miscRegs[MISCREG_VPIDR] = p->midr; 1212858SN/A 1222858SN/A miscRegs[MISCREG_ID_ISAR0] = p->id_isar0; 1239294Sandreas.hansson@arm.com miscRegs[MISCREG_ID_ISAR1] = p->id_isar1; 1249294Sandreas.hansson@arm.com miscRegs[MISCREG_ID_ISAR2] = p->id_isar2; 1258922Swilliam.wang@arm.com miscRegs[MISCREG_ID_ISAR3] = p->id_isar3; 1268922Swilliam.wang@arm.com miscRegs[MISCREG_ID_ISAR4] = p->id_isar4; 1278922Swilliam.wang@arm.com miscRegs[MISCREG_ID_ISAR5] = p->id_isar5; 1288922Swilliam.wang@arm.com 1298922Swilliam.wang@arm.com miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0; 1308922Swilliam.wang@arm.com miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1; 1318922Swilliam.wang@arm.com miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2; 1328922Swilliam.wang@arm.com miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3; 1339294Sandreas.hansson@arm.com 1349294Sandreas.hansson@arm.com if (FullSystem && system->highestELIs64()) { 1358922Swilliam.wang@arm.com // Initialize AArch64 state 1368922Swilliam.wang@arm.com clear64(p); 1378922Swilliam.wang@arm.com return; 1388922Swilliam.wang@arm.com } 1398922Swilliam.wang@arm.com 1408922Swilliam.wang@arm.com // Initialize AArch32 state... 1418922Swilliam.wang@arm.com 1424628SN/A CPSR cpsr = 0; 1432858SN/A cpsr.mode = MODE_USER; 1442810SN/A miscRegs[MISCREG_CPSR] = cpsr; 1452810SN/A updateRegMap(cpsr); 1462810SN/A 1472810SN/A SCTLR sctlr = 0; 1482810SN/A sctlr.te = (bool) sctlr_rst.te; 1494022SN/A sctlr.nmfi = (bool) sctlr_rst.nmfi; 1504022SN/A sctlr.v = (bool) sctlr_rst.v; 1514022SN/A sctlr.u = 1; 1522810SN/A sctlr.xp = 1; 1532810SN/A sctlr.rao2 = 1; 1548833Sdam.sunwoo@arm.com sctlr.rao3 = 1; 1552810SN/A sctlr.rao4 = 0xf; // SCTLR[6:3] 1562810SN/A sctlr.uci = 1; 1572810SN/A sctlr.dze = 1; 1582810SN/A miscRegs[MISCREG_SCTLR_NS] = sctlr; 1598833Sdam.sunwoo@arm.com miscRegs[MISCREG_SCTLR_RST] = sctlr_rst; 1608833Sdam.sunwoo@arm.com miscRegs[MISCREG_HCPTR] = 0; 1618833Sdam.sunwoo@arm.com 1622810SN/A // Start with an event in the mailbox 1632810SN/A miscRegs[MISCREG_SEV_MAILBOX] = 1; 1644871SN/A 1654871SN/A // Separate Instruction and Data TLBs 1664871SN/A miscRegs[MISCREG_TLBTR] = 1; 1674871SN/A 1684871SN/A MVFR0 mvfr0 = 0; 1694871SN/A mvfr0.advSimdRegisters = 2; 1704871SN/A mvfr0.singlePrecision = 2; 1714871SN/A mvfr0.doublePrecision = 2; 1724871SN/A mvfr0.vfpExceptionTrapping = 0; 1734871SN/A mvfr0.divide = 1; 1742810SN/A mvfr0.squareRoot = 1; 1752810SN/A mvfr0.shortVectors = 1; 1762810SN/A mvfr0.roundingModes = 1; 1778833Sdam.sunwoo@arm.com miscRegs[MISCREG_MVFR0] = mvfr0; 1782810SN/A 1794871SN/A MVFR1 mvfr1 = 0; 1808833Sdam.sunwoo@arm.com mvfr1.flushToZero = 1; 1818833Sdam.sunwoo@arm.com mvfr1.defaultNaN = 1; 1828833Sdam.sunwoo@arm.com mvfr1.advSimdLoadStore = 1; 1832810SN/A mvfr1.advSimdInteger = 1; 1842810SN/A mvfr1.advSimdSinglePrecision = 1; 1852810SN/A mvfr1.advSimdHalfPrecision = 1; 1862810SN/A mvfr1.vfpHalfPrecision = 1; 1878833Sdam.sunwoo@arm.com miscRegs[MISCREG_MVFR1] = mvfr1; 1882810SN/A 1894871SN/A // Reset values of PRRR and NMRR are implementation dependent 1908833Sdam.sunwoo@arm.com 1918833Sdam.sunwoo@arm.com // @todo: PRRR and NMRR in secure state? 1928833Sdam.sunwoo@arm.com miscRegs[MISCREG_PRRR_NS] = 1932810SN/A (1 << 19) | // 19 1942810SN/A (0 << 18) | // 18 1954022SN/A (0 << 17) | // 17 1964022SN/A (1 << 16) | // 16 1974022SN/A (2 << 14) | // 15:14 1982810SN/A (0 << 12) | // 13:12 1992810SN/A (2 << 10) | // 11:10 2008833Sdam.sunwoo@arm.com (2 << 8) | // 9:8 2012810SN/A (2 << 6) | // 7:6 2022810SN/A (2 << 4) | // 5:4 2032810SN/A (1 << 2) | // 3:2 2042810SN/A 0; // 1:0 2058833Sdam.sunwoo@arm.com miscRegs[MISCREG_NMRR_NS] = 2068833Sdam.sunwoo@arm.com (1 << 30) | // 31:30 2078833Sdam.sunwoo@arm.com (0 << 26) | // 27:26 2082810SN/A (0 << 24) | // 25:24 2092810SN/A (3 << 22) | // 23:22 2102810SN/A (2 << 20) | // 21:20 2112810SN/A (0 << 18) | // 19:18 2122810SN/A (0 << 16) | // 17:16 2138833Sdam.sunwoo@arm.com (1 << 14) | // 15:14 2142810SN/A (0 << 12) | // 13:12 2154871SN/A (2 << 10) | // 11:10 2168833Sdam.sunwoo@arm.com (0 << 8) | // 9:8 2178833Sdam.sunwoo@arm.com (3 << 6) | // 7:6 2188833Sdam.sunwoo@arm.com (2 << 4) | // 5:4 2192810SN/A (0 << 2) | // 3:2 2202810SN/A 0; // 1:0 2212810SN/A 2222810SN/A miscRegs[MISCREG_CPACR] = 0; 2238833Sdam.sunwoo@arm.com 2242810SN/A miscRegs[MISCREG_FPSID] = p->fpsid; 2254871SN/A 2268833Sdam.sunwoo@arm.com if (haveLPAE) { 2278833Sdam.sunwoo@arm.com TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS]; 2288833Sdam.sunwoo@arm.com ttbcr.eae = 0; 2292810SN/A miscRegs[MISCREG_TTBCR_NS] = ttbcr; 2302810SN/A // Enforce consistency with system-level settings 2314022SN/A miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5; 2324022SN/A } 2334022SN/A 2342810SN/A if (haveSecurity) { 2352810SN/A miscRegs[MISCREG_SCTLR_S] = sctlr; 2368833Sdam.sunwoo@arm.com miscRegs[MISCREG_SCR] = 0; 2372810SN/A miscRegs[MISCREG_VBAR_S] = 0; 2382810SN/A } else { 2392810SN/A // we're always non-secure 2402810SN/A miscRegs[MISCREG_SCR] = 1; 2418833Sdam.sunwoo@arm.com } 2428833Sdam.sunwoo@arm.com 2438833Sdam.sunwoo@arm.com //XXX We need to initialize the rest of the state. 2442810SN/A} 2452810SN/A 2462810SN/Avoid 2472810SN/AISA::clear64(const ArmISAParams *p) 2482810SN/A{ 2498833Sdam.sunwoo@arm.com CPSR cpsr = 0; 2502810SN/A Addr rvbar = system->resetAddr64(); 2514871SN/A switch (system->highestEL()) { 2528833Sdam.sunwoo@arm.com // Set initial EL to highest implemented EL using associated stack 2538833Sdam.sunwoo@arm.com // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset 2548833Sdam.sunwoo@arm.com // value 2552810SN/A case EL3: 2562810SN/A cpsr.mode = MODE_EL3H; 2572810SN/A miscRegs[MISCREG_RVBAR_EL3] = rvbar; 2582810SN/A break; 2598833Sdam.sunwoo@arm.com case EL2: 2602810SN/A cpsr.mode = MODE_EL2H; 2614871SN/A miscRegs[MISCREG_RVBAR_EL2] = rvbar; 2628833Sdam.sunwoo@arm.com break; 2638833Sdam.sunwoo@arm.com case EL1: 2648833Sdam.sunwoo@arm.com cpsr.mode = MODE_EL1H; 2652810SN/A miscRegs[MISCREG_RVBAR_EL1] = rvbar; 2662810SN/A break; 2674022SN/A default: 2684022SN/A panic("Invalid highest implemented exception level"); 2694022SN/A break; 2702810SN/A } 2712810SN/A 2722810SN/A // Initialize rest of CPSR 2732810SN/A cpsr.daif = 0xf; // Mask all interrupts 2742810SN/A cpsr.ss = 0; 2752810SN/A cpsr.il = 0; 2768833Sdam.sunwoo@arm.com miscRegs[MISCREG_CPSR] = cpsr; 2772810SN/A updateRegMap(cpsr); 2788833Sdam.sunwoo@arm.com 2798833Sdam.sunwoo@arm.com // Initialize other control registers 2808833Sdam.sunwoo@arm.com miscRegs[MISCREG_MPIDR_EL1] = 0x80000000; 2812810SN/A if (haveSecurity) { 2822810SN/A miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830; 2832810SN/A miscRegs[MISCREG_SCR_EL3] = 0x00000030; // RES1 fields 2842810SN/A } else if (haveVirtualization) { 2852810SN/A // also MISCREG_SCTLR_EL2 (by mapping) 2868833Sdam.sunwoo@arm.com miscRegs[MISCREG_HSCTLR] = 0x30c50830; 2872810SN/A } else { 2882810SN/A // also MISCREG_SCTLR_EL1 (by mapping) 2898833Sdam.sunwoo@arm.com miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init 2908833Sdam.sunwoo@arm.com // Always non-secure 2918833Sdam.sunwoo@arm.com miscRegs[MISCREG_SCR_EL3] = 1; 2922810SN/A } 2932810SN/A 2942810SN/A // Initialize configurable id registers 2952810SN/A miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1; 2968833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1; 2972810SN/A miscRegs[MISCREG_ID_AA64DFR0_EL1] = 2982810SN/A (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) | 2998833Sdam.sunwoo@arm.com (p->pmu ? 0x0000000000000100ULL : 0); // Enable PMUv3 3008833Sdam.sunwoo@arm.com 3018833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1; 3022810SN/A miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1; 3032810SN/A miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1; 3044022SN/A miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1; 3054022SN/A miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1; 3064022SN/A 3072810SN/A miscRegs[MISCREG_ID_DFR0_EL1] = 3082810SN/A (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3 3092810SN/A 3102810SN/A miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1]; 3112810SN/A 3122810SN/A // Enforce consistency with system-level settings... 3138833Sdam.sunwoo@arm.com 3142810SN/A // EL3 3158833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 3168833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12, 3178833Sdam.sunwoo@arm.com haveSecurity ? 0x2 : 0x0); 3182810SN/A // EL2 3192810SN/A miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 3202810SN/A miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8, 3212810SN/A haveVirtualization ? 0x2 : 0x0); 3222810SN/A // Large ASID support 3238833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 3242810SN/A miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4, 3252810SN/A haveLargeAsid64 ? 0x2 : 0x0); 3268833Sdam.sunwoo@arm.com // Physical address size 3278833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 3288833Sdam.sunwoo@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0, 3292810SN/A encodePhysAddrRange64(physAddrRange64)); 3302810SN/A} 3312810SN/A 3322810SN/AMiscReg 3338833Sdam.sunwoo@arm.comISA::readMiscRegNoEffect(int misc_reg) const 3342810SN/A{ 3352810SN/A assert(misc_reg < NumMiscRegs); 3368833Sdam.sunwoo@arm.com 3378833Sdam.sunwoo@arm.com const auto ® = lookUpMiscReg[misc_reg]; // bit masks 3388833Sdam.sunwoo@arm.com const auto &map = getMiscIndices(misc_reg); 3392810SN/A int lower = map.first, upper = map.second; 3402810SN/A // NB!: apply architectural masks according to desired register, 3414022SN/A // despite possibly getting value from different (mapped) register. 3424022SN/A auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32)) 3434022SN/A |(miscRegs[upper] << 32)); 3442810SN/A if (val & reg.res0()) { 3452810SN/A DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n", 3462810SN/A miscRegName[misc_reg], val & reg.res0()); 3472810SN/A } 3482810SN/A if ((val & reg.res1()) != reg.res1()) { 3492810SN/A DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n", 3502810SN/A miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1()); 3512810SN/A } 3528833Sdam.sunwoo@arm.com return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao 3538833Sdam.sunwoo@arm.com} 3548833Sdam.sunwoo@arm.com 3558833Sdam.sunwoo@arm.com 3562810SN/AMiscReg 3572810SN/AISA::readMiscReg(int misc_reg, ThreadContext *tc) 3582810SN/A{ 3592810SN/A CPSR cpsr = 0; 3602810SN/A PCState pc = 0; 3618833Sdam.sunwoo@arm.com SCR scr = 0; 3622810SN/A 3632810SN/A if (misc_reg == MISCREG_CPSR) { 3648833Sdam.sunwoo@arm.com cpsr = miscRegs[misc_reg]; 3658833Sdam.sunwoo@arm.com pc = tc->pcState(); 3668833Sdam.sunwoo@arm.com cpsr.j = pc.jazelle() ? 1 : 0; 3672810SN/A cpsr.t = pc.thumb() ? 1 : 0; 3682810SN/A return cpsr; 3692810SN/A } 3702810SN/A 3718833Sdam.sunwoo@arm.com#ifndef NDEBUG 3722810SN/A if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 3732810SN/A if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 3748833Sdam.sunwoo@arm.com warn("Unimplemented system register %s read.\n", 3758833Sdam.sunwoo@arm.com miscRegName[misc_reg]); 3768833Sdam.sunwoo@arm.com else 3772810SN/A panic("Unimplemented system register %s read.\n", 3782810SN/A miscRegName[misc_reg]); 3792810SN/A } 3802810SN/A#endif 3812810SN/A 3822810SN/A switch (unflattenMiscReg(misc_reg)) { 3832810SN/A case MISCREG_HCR: 3842810SN/A { 3852810SN/A if (!haveVirtualization) 3862810SN/A return 0; 3872810SN/A else 3882810SN/A return readMiscRegNoEffect(MISCREG_HCR); 3892810SN/A } 3902810SN/A case MISCREG_CPACR: 3912810SN/A { 3922810SN/A const uint32_t ones = (uint32_t)(-1); 3932810SN/A CPACR cpacrMask = 0; 3942810SN/A // Only cp10, cp11, and ase are implemented, nothing else should 3952810SN/A // be readable? (straight copy from the write code) 3962810SN/A cpacrMask.cp10 = ones; 3972810SN/A cpacrMask.cp11 = ones; 3982810SN/A cpacrMask.asedis = ones; 3992810SN/A 4002810SN/A // Security Extensions may limit the readability of CPACR 4012810SN/A if (haveSecurity) { 4022810SN/A scr = readMiscRegNoEffect(MISCREG_SCR); 4032810SN/A cpsr = readMiscRegNoEffect(MISCREG_CPSR); 4042810SN/A if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) { 4052810SN/A NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 4062810SN/A // NB: Skipping the full loop, here 4072810SN/A if (!nsacr.cp10) cpacrMask.cp10 = 0; 4082810SN/A if (!nsacr.cp11) cpacrMask.cp11 = 0; 4092810SN/A } 4102810SN/A } 4112810SN/A MiscReg val = readMiscRegNoEffect(MISCREG_CPACR); 4122810SN/A val &= cpacrMask; 4132826SN/A DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n", 4144626SN/A miscRegName[misc_reg], val); 4158833Sdam.sunwoo@arm.com return val; 4164626SN/A } 4174626SN/A case MISCREG_MPIDR: 4188833Sdam.sunwoo@arm.com cpsr = readMiscRegNoEffect(MISCREG_CPSR); 4194626SN/A scr = readMiscRegNoEffect(MISCREG_SCR); 4208833Sdam.sunwoo@arm.com if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 4218833Sdam.sunwoo@arm.com return getMPIDR(system, tc); 4228833Sdam.sunwoo@arm.com } else { 4234626SN/A return readMiscReg(MISCREG_VMPIDR, tc); 4244626SN/A } 4254626SN/A break; 4264626SN/A case MISCREG_MPIDR_EL1: 4274626SN/A // @todo in the absence of v8 virtualization support just return MPIDR_EL1 4284626SN/A return getMPIDR(system, tc) & 0xffffffff; 4294626SN/A case MISCREG_VMPIDR: 4304626SN/A // top bit defined as RES1 4318833Sdam.sunwoo@arm.com return readMiscRegNoEffect(misc_reg) | 0x80000000; 4324626SN/A case MISCREG_ID_AFR0: // not implemented, so alias MIDR 4334626SN/A case MISCREG_REVIDR: // not implemented, so alias MIDR 4344626SN/A case MISCREG_MIDR: 4354626SN/A cpsr = readMiscRegNoEffect(MISCREG_CPSR); 4368833Sdam.sunwoo@arm.com scr = readMiscRegNoEffect(MISCREG_SCR); 4378833Sdam.sunwoo@arm.com if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 4388833Sdam.sunwoo@arm.com return readMiscRegNoEffect(misc_reg); 4394626SN/A } else { 4404626SN/A return readMiscRegNoEffect(MISCREG_VPIDR); 4414626SN/A } 4424626SN/A break; 4434626SN/A case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI 4448833Sdam.sunwoo@arm.com case MISCREG_JMCR: // Jazelle trivial implementation, RAZ/WI 4454626SN/A case MISCREG_JIDR: // Jazelle trivial implementation, RAZ/WI 4464871SN/A case MISCREG_AIDR: // AUX ID set to 0 4478833Sdam.sunwoo@arm.com case MISCREG_TCMTR: // No TCM's 4488833Sdam.sunwoo@arm.com return 0; 4498833Sdam.sunwoo@arm.com 4504626SN/A case MISCREG_CLIDR: 4514626SN/A warn_once("The clidr register always reports 0 caches.\n"); 4524626SN/A warn_once("clidr LoUIS field of 0b001 to match current " 4534626SN/A "ARM implementations.\n"); 4548833Sdam.sunwoo@arm.com return 0x00200000; 4554626SN/A case MISCREG_CCSIDR: 4564871SN/A warn_once("The ccsidr register isn't implemented and " 4578833Sdam.sunwoo@arm.com "always reads as 0.\n"); 4588833Sdam.sunwoo@arm.com break; 4598833Sdam.sunwoo@arm.com case MISCREG_CTR: // AArch32, ARMv7, top bit set 4604626SN/A case MISCREG_CTR_EL0: // AArch64 4614626SN/A { 4624626SN/A //all caches have the same line size in gem5 4634626SN/A //4 byte words in ARM 4644626SN/A unsigned lineSizeWords = 4654626SN/A tc->getSystemPtr()->cacheLineSize() / 4; 4664626SN/A unsigned log2LineSizeWords = 0; 4678833Sdam.sunwoo@arm.com 4684626SN/A while (lineSizeWords >>= 1) { 4694626SN/A ++log2LineSizeWords; 4704626SN/A } 4714626SN/A 4728833Sdam.sunwoo@arm.com CTR ctr = 0; 4738833Sdam.sunwoo@arm.com //log2 of minimun i-cache line size (words) 4748833Sdam.sunwoo@arm.com ctr.iCacheLineSize = log2LineSizeWords; 4754626SN/A //b11 - gem5 uses pipt 4764626SN/A ctr.l1IndexPolicy = 0x3; 4774626SN/A //log2 of minimum d-cache line size (words) 4784626SN/A ctr.dCacheLineSize = log2LineSizeWords; 4794626SN/A //log2 of max reservation size (words) 4808833Sdam.sunwoo@arm.com ctr.erg = log2LineSizeWords; 4814626SN/A //log2 of max writeback size (words) 4824871SN/A ctr.cwg = log2LineSizeWords; 4838833Sdam.sunwoo@arm.com //b100 - gem5 format is ARMv7 4848833Sdam.sunwoo@arm.com ctr.format = 0x4; 4858833Sdam.sunwoo@arm.com 4864626SN/A return ctr; 4874626SN/A } 4884626SN/A case MISCREG_ACTLR: 4894626SN/A warn("Not doing anything for miscreg ACTLR\n"); 4908833Sdam.sunwoo@arm.com break; 4914626SN/A 4924871SN/A case MISCREG_PMXEVTYPER_PMCCFILTR: 4938833Sdam.sunwoo@arm.com case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 4948833Sdam.sunwoo@arm.com case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 4958833Sdam.sunwoo@arm.com case MISCREG_PMCR ... MISCREG_PMOVSSET: 4964626SN/A return pmu->readMiscReg(misc_reg); 4974626SN/A 4984626SN/A case MISCREG_CPSR_Q: 4994626SN/A panic("shouldn't be reading this register seperately\n"); 5004626SN/A case MISCREG_FPSCR_QC: 5014626SN/A return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask; 5024626SN/A case MISCREG_FPSCR_EXC: 5038833Sdam.sunwoo@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask; 5044626SN/A case MISCREG_FPSR: 5054626SN/A { 5064626SN/A const uint32_t ones = (uint32_t)(-1); 5074626SN/A FPSCR fpscrMask = 0; 5088833Sdam.sunwoo@arm.com fpscrMask.ioc = ones; 5098833Sdam.sunwoo@arm.com fpscrMask.dzc = ones; 5108833Sdam.sunwoo@arm.com fpscrMask.ofc = ones; 5114626SN/A fpscrMask.ufc = ones; 5124626SN/A fpscrMask.ixc = ones; 5134626SN/A fpscrMask.idc = ones; 5144626SN/A fpscrMask.qc = ones; 5154626SN/A fpscrMask.v = ones; 5168833Sdam.sunwoo@arm.com fpscrMask.c = ones; 5174626SN/A fpscrMask.z = ones; 5184871SN/A fpscrMask.n = ones; 5198833Sdam.sunwoo@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 5208833Sdam.sunwoo@arm.com } 5218833Sdam.sunwoo@arm.com case MISCREG_FPCR: 5224626SN/A { 5234626SN/A const uint32_t ones = (uint32_t)(-1); 5244626SN/A FPSCR fpscrMask = 0; 5254626SN/A fpscrMask.len = ones; 5268833Sdam.sunwoo@arm.com fpscrMask.stride = ones; 5274626SN/A fpscrMask.rMode = ones; 5284871SN/A fpscrMask.fz = ones; 5294871SN/A fpscrMask.dn = ones; 5308833Sdam.sunwoo@arm.com fpscrMask.ahp = ones; 5318833Sdam.sunwoo@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 5328833Sdam.sunwoo@arm.com } 5334626SN/A case MISCREG_NZCV: 5344626SN/A { 5354626SN/A CPSR cpsr = 0; 5364626SN/A cpsr.nz = tc->readCCReg(CCREG_NZ); 5374626SN/A cpsr.c = tc->readCCReg(CCREG_C); 5384626SN/A cpsr.v = tc->readCCReg(CCREG_V); 5394626SN/A return cpsr; 5408833Sdam.sunwoo@arm.com } 5414626SN/A case MISCREG_DAIF: 5424626SN/A { 5434626SN/A CPSR cpsr = 0; 5444626SN/A cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif; 5458833Sdam.sunwoo@arm.com return cpsr; 5468833Sdam.sunwoo@arm.com } 5478833Sdam.sunwoo@arm.com case MISCREG_SP_EL0: 5484626SN/A { 5494626SN/A return tc->readIntReg(INTREG_SP0); 5504626SN/A } 5514626SN/A case MISCREG_SP_EL1: 5524626SN/A { 5538833Sdam.sunwoo@arm.com return tc->readIntReg(INTREG_SP1); 5544626SN/A } 5554871SN/A case MISCREG_SP_EL2: 5564871SN/A { 5578833Sdam.sunwoo@arm.com return tc->readIntReg(INTREG_SP2); 5588833Sdam.sunwoo@arm.com } 5598833Sdam.sunwoo@arm.com case MISCREG_SPSEL: 5604626SN/A { 5614626SN/A return miscRegs[MISCREG_CPSR] & 0x1; 5624626SN/A } 5634626SN/A case MISCREG_CURRENTEL: 5644626SN/A { 5654626SN/A return miscRegs[MISCREG_CPSR] & 0xc; 5664626SN/A } 5678833Sdam.sunwoo@arm.com case MISCREG_L2CTLR: 5684626SN/A { 5694626SN/A // mostly unimplemented, just set NumCPUs field from sim and return 5704626SN/A L2CTLR l2ctlr = 0; 5714626SN/A // b00:1CPU to b11:4CPUs 5728833Sdam.sunwoo@arm.com l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1; 5738833Sdam.sunwoo@arm.com return l2ctlr; 5748833Sdam.sunwoo@arm.com } 5754626SN/A case MISCREG_DBGDIDR: 5764626SN/A /* For now just implement the version number. 5774626SN/A * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5) 5784626SN/A */ 5794626SN/A return 0x5 << 16; 5808833Sdam.sunwoo@arm.com case MISCREG_DBGDSCRint: 5814626SN/A return 0; 5824871SN/A case MISCREG_ISR: 5834871SN/A return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 5844871SN/A readMiscRegNoEffect(MISCREG_HCR), 5858833Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_CPSR), 5868833Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_SCR)); 5878833Sdam.sunwoo@arm.com case MISCREG_ISR_EL1: 5884626SN/A return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 5894626SN/A readMiscRegNoEffect(MISCREG_HCR_EL2), 5904626SN/A readMiscRegNoEffect(MISCREG_CPSR), 5914626SN/A readMiscRegNoEffect(MISCREG_SCR_EL3)); 5924626SN/A case MISCREG_DCZID_EL0: 5934626SN/A return 0x04; // DC ZVA clear 64-byte chunks 5944626SN/A case MISCREG_HCPTR: 5954626SN/A { 5964626SN/A MiscReg val = readMiscRegNoEffect(misc_reg); 5974626SN/A // The trap bit associated with CP14 is defined as RAZ 5984626SN/A val &= ~(1 << 14); 5994626SN/A // If a CP bit in NSACR is 0 then the corresponding bit in 6004626SN/A // HCPTR is RAO/WI 6014626SN/A bool secure_lookup = haveSecurity && 6024626SN/A inSecureState(readMiscRegNoEffect(MISCREG_SCR), 6034626SN/A readMiscRegNoEffect(MISCREG_CPSR)); 6044626SN/A if (!secure_lookup) { 6054626SN/A MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR); 6064626SN/A val |= (mask ^ 0x7FFF) & 0xBFFF; 6074626SN/A } 6084626SN/A // Set the bits for unimplemented coprocessors to RAO/WI 6094626SN/A val |= 0x33FF; 6104626SN/A return (val); 6114626SN/A } 6124626SN/A case MISCREG_HDFAR: // alias for secure DFAR 6134626SN/A return readMiscRegNoEffect(MISCREG_DFAR_S); 6144626SN/A case MISCREG_HIFAR: // alias for secure IFAR 6154626SN/A return readMiscRegNoEffect(MISCREG_IFAR_S); 6164626SN/A case MISCREG_HVBAR: // bottom bits reserved 6174626SN/A return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0; 6184626SN/A case MISCREG_SCTLR: 6194626SN/A return (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818; 6204626SN/A case MISCREG_SCTLR_EL1: 6214626SN/A return (readMiscRegNoEffect(misc_reg) & 0x37DDDBBF) | 0x30D00800; 6224626SN/A case MISCREG_SCTLR_EL2: 6234626SN/A case MISCREG_SCTLR_EL3: 6244626SN/A case MISCREG_HSCTLR: 6254626SN/A return (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830; 6264626SN/A 6274626SN/A case MISCREG_ID_PFR0: 6284626SN/A // !ThumbEE | !Jazelle | Thumb | ARM 6294626SN/A return 0x00000031; 6304626SN/A case MISCREG_ID_PFR1: 6314626SN/A { // Timer | Virti | !M Profile | TrustZone | ARMv4 6324626SN/A bool haveTimer = (system->getGenericTimer() != NULL); 6338833Sdam.sunwoo@arm.com return 0x00000001 6348833Sdam.sunwoo@arm.com | (haveSecurity ? 0x00000010 : 0x0) 6358833Sdam.sunwoo@arm.com | (haveVirtualization ? 0x00001000 : 0x0) 6368833Sdam.sunwoo@arm.com | (haveTimer ? 0x00010000 : 0x0); 6374626SN/A } 6384626SN/A case MISCREG_ID_AA64PFR0_EL1: 6394626SN/A return 0x0000000000000002 // AArch{64,32} supported at EL0 6404626SN/A | 0x0000000000000020 // EL1 6414626SN/A | (haveVirtualization ? 0x0000000000000200 : 0) // EL2 6428833Sdam.sunwoo@arm.com | (haveSecurity ? 0x0000000000002000 : 0); // EL3 6434626SN/A case MISCREG_ID_AA64PFR1_EL1: 6444626SN/A return 0; // bits [63:0] RES0 (reserved for future use) 6458833Sdam.sunwoo@arm.com 6468833Sdam.sunwoo@arm.com // Generic Timer registers 6478833Sdam.sunwoo@arm.com case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 6484626SN/A case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 6494626SN/A case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 6504626SN/A case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 6514626SN/A return getGenericTimer(tc).readMiscReg(misc_reg); 6528833Sdam.sunwoo@arm.com 6534626SN/A default: 6544626SN/A break; 6558833Sdam.sunwoo@arm.com 6568833Sdam.sunwoo@arm.com } 6578833Sdam.sunwoo@arm.com return readMiscRegNoEffect(misc_reg); 6584626SN/A} 6594626SN/A 6604626SN/Avoid 6614626SN/AISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val) 6624626SN/A{ 6634626SN/A assert(misc_reg < NumMiscRegs); 6644626SN/A 6654626SN/A const auto ® = lookUpMiscReg[misc_reg]; // bit masks 6664626SN/A const auto &map = getMiscIndices(misc_reg); 6674626SN/A int lower = map.first, upper = map.second; 6684626SN/A 6694626SN/A auto v = (val & ~reg.wi()) | reg.rao(); 6704626SN/A if (upper > 0) { 6718833Sdam.sunwoo@arm.com miscRegs[lower] = bits(v, 31, 0); 6728833Sdam.sunwoo@arm.com miscRegs[upper] = bits(v, 63, 32); 6738833Sdam.sunwoo@arm.com DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n", 6748833Sdam.sunwoo@arm.com misc_reg, lower, upper, v); 6754626SN/A } else { 6764626SN/A miscRegs[lower] = v; 6774626SN/A DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n", 6784626SN/A misc_reg, lower, v); 6794626SN/A } 6808833Sdam.sunwoo@arm.com} 6814626SN/A 6824626SN/Avoid 6838833Sdam.sunwoo@arm.comISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 6848833Sdam.sunwoo@arm.com{ 6858833Sdam.sunwoo@arm.com 6864626SN/A MiscReg newVal = val; 6874626SN/A bool secure_lookup; 6884626SN/A SCR scr; 6894626SN/A 6908833Sdam.sunwoo@arm.com if (misc_reg == MISCREG_CPSR) { 6914626SN/A updateRegMap(val); 6924626SN/A 6938833Sdam.sunwoo@arm.com 6948833Sdam.sunwoo@arm.com CPSR old_cpsr = miscRegs[MISCREG_CPSR]; 6958833Sdam.sunwoo@arm.com int old_mode = old_cpsr.mode; 6964626SN/A CPSR cpsr = val; 6974626SN/A if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) { 6984626SN/A getITBPtr(tc)->invalidateMiscReg(); 6994626SN/A getDTBPtr(tc)->invalidateMiscReg(); 7004626SN/A } 7014626SN/A 7024626SN/A DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n", 7034626SN/A miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode); 7044626SN/A PCState pc = tc->pcState(); 7054626SN/A pc.nextThumb(cpsr.t); 7064626SN/A pc.nextJazelle(cpsr.j); 7074626SN/A pc.illegalExec(cpsr.il == 1); 7084626SN/A 7098833Sdam.sunwoo@arm.com // Follow slightly different semantics if a CheckerCPU object 7108833Sdam.sunwoo@arm.com // is connected 7118833Sdam.sunwoo@arm.com CheckerCPU *checker = tc->getCheckerCpuPtr(); 7128833Sdam.sunwoo@arm.com if (checker) { 7134626SN/A tc->pcStateNoRecord(pc); 7144626SN/A } else { 7154626SN/A tc->pcState(pc); 7164626SN/A } 7174626SN/A } else { 7188833Sdam.sunwoo@arm.com#ifndef NDEBUG 7194626SN/A if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 7204626SN/A if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 7218833Sdam.sunwoo@arm.com warn("Unimplemented system register %s write with %#x.\n", 7228833Sdam.sunwoo@arm.com miscRegName[misc_reg], val); 7238833Sdam.sunwoo@arm.com else 7244626SN/A panic("Unimplemented system register %s write with %#x.\n", 7254626SN/A miscRegName[misc_reg], val); 7268833Sdam.sunwoo@arm.com } 7274626SN/A#endif 7284626SN/A switch (unflattenMiscReg(misc_reg)) { 7298833Sdam.sunwoo@arm.com case MISCREG_CPACR: 7304626SN/A { 7318833Sdam.sunwoo@arm.com 7328833Sdam.sunwoo@arm.com const uint32_t ones = (uint32_t)(-1); 7338833Sdam.sunwoo@arm.com CPACR cpacrMask = 0; 7344626SN/A // Only cp10, cp11, and ase are implemented, nothing else should 7354626SN/A // be writable 7364626SN/A cpacrMask.cp10 = ones; 7378833Sdam.sunwoo@arm.com cpacrMask.cp11 = ones; 7384626SN/A cpacrMask.asedis = ones; 7394626SN/A 7408833Sdam.sunwoo@arm.com // Security Extensions may limit the writability of CPACR 7414626SN/A if (haveSecurity) { 7428833Sdam.sunwoo@arm.com scr = readMiscRegNoEffect(MISCREG_SCR); 7438833Sdam.sunwoo@arm.com CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR); 7448833Sdam.sunwoo@arm.com if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) { 7454626SN/A NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 7464626SN/A // NB: Skipping the full loop, here 7474626SN/A if (!nsacr.cp10) cpacrMask.cp10 = 0; 7484626SN/A if (!nsacr.cp11) cpacrMask.cp11 = 0; 7494626SN/A } 7504626SN/A } 7512810SN/A 7523503SN/A MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR); 7533503SN/A newVal &= cpacrMask; 7549342SAndreas.Sandberg@arm.com newVal |= old_val & ~cpacrMask; 7553503SN/A DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 7569347SAndreas.Sandberg@arm.com miscRegName[misc_reg], newVal); 7579347SAndreas.Sandberg@arm.com } 7584626SN/A break; 7593503SN/A case MISCREG_CPTR_EL2: 7604626SN/A { 7619342SAndreas.Sandberg@arm.com const uint32_t ones = (uint32_t)(-1); 7629152Satgutier@umich.edu CPTR cptrMask = 0; 7634626SN/A cptrMask.tcpac = ones; 7643503SN/A cptrMask.tta = ones; 7653503SN/A cptrMask.tfp = ones; 7669342SAndreas.Sandberg@arm.com newVal &= cptrMask; 7673503SN/A cptrMask = 0; 7683503SN/A cptrMask.res1_13_12_el2 = ones; 769 cptrMask.res1_9_0_el2 = ones; 770 newVal |= cptrMask; 771 DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 772 miscRegName[misc_reg], newVal); 773 } 774 break; 775 case MISCREG_CPTR_EL3: 776 { 777 const uint32_t ones = (uint32_t)(-1); 778 CPTR cptrMask = 0; 779 cptrMask.tcpac = ones; 780 cptrMask.tta = ones; 781 cptrMask.tfp = ones; 782 newVal &= cptrMask; 783 DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 784 miscRegName[misc_reg], newVal); 785 } 786 break; 787 case MISCREG_CSSELR: 788 warn_once("The csselr register isn't implemented.\n"); 789 return; 790 791 case MISCREG_DC_ZVA_Xt: 792 warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n"); 793 return; 794 795 case MISCREG_FPSCR: 796 { 797 const uint32_t ones = (uint32_t)(-1); 798 FPSCR fpscrMask = 0; 799 fpscrMask.ioc = ones; 800 fpscrMask.dzc = ones; 801 fpscrMask.ofc = ones; 802 fpscrMask.ufc = ones; 803 fpscrMask.ixc = ones; 804 fpscrMask.idc = ones; 805 fpscrMask.ioe = ones; 806 fpscrMask.dze = ones; 807 fpscrMask.ofe = ones; 808 fpscrMask.ufe = ones; 809 fpscrMask.ixe = ones; 810 fpscrMask.ide = ones; 811 fpscrMask.len = ones; 812 fpscrMask.stride = ones; 813 fpscrMask.rMode = ones; 814 fpscrMask.fz = ones; 815 fpscrMask.dn = ones; 816 fpscrMask.ahp = ones; 817 fpscrMask.qc = ones; 818 fpscrMask.v = ones; 819 fpscrMask.c = ones; 820 fpscrMask.z = ones; 821 fpscrMask.n = ones; 822 newVal = (newVal & (uint32_t)fpscrMask) | 823 (readMiscRegNoEffect(MISCREG_FPSCR) & 824 ~(uint32_t)fpscrMask); 825 tc->getDecoderPtr()->setContext(newVal); 826 } 827 break; 828 case MISCREG_FPSR: 829 { 830 const uint32_t ones = (uint32_t)(-1); 831 FPSCR fpscrMask = 0; 832 fpscrMask.ioc = ones; 833 fpscrMask.dzc = ones; 834 fpscrMask.ofc = ones; 835 fpscrMask.ufc = ones; 836 fpscrMask.ixc = ones; 837 fpscrMask.idc = ones; 838 fpscrMask.qc = ones; 839 fpscrMask.v = ones; 840 fpscrMask.c = ones; 841 fpscrMask.z = ones; 842 fpscrMask.n = ones; 843 newVal = (newVal & (uint32_t)fpscrMask) | 844 (readMiscRegNoEffect(MISCREG_FPSCR) & 845 ~(uint32_t)fpscrMask); 846 misc_reg = MISCREG_FPSCR; 847 } 848 break; 849 case MISCREG_FPCR: 850 { 851 const uint32_t ones = (uint32_t)(-1); 852 FPSCR fpscrMask = 0; 853 fpscrMask.len = ones; 854 fpscrMask.stride = ones; 855 fpscrMask.rMode = ones; 856 fpscrMask.fz = ones; 857 fpscrMask.dn = ones; 858 fpscrMask.ahp = ones; 859 newVal = (newVal & (uint32_t)fpscrMask) | 860 (readMiscRegNoEffect(MISCREG_FPSCR) & 861 ~(uint32_t)fpscrMask); 862 misc_reg = MISCREG_FPSCR; 863 } 864 break; 865 case MISCREG_CPSR_Q: 866 { 867 assert(!(newVal & ~CpsrMaskQ)); 868 newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal; 869 misc_reg = MISCREG_CPSR; 870 } 871 break; 872 case MISCREG_FPSCR_QC: 873 { 874 newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 875 (newVal & FpscrQcMask); 876 misc_reg = MISCREG_FPSCR; 877 } 878 break; 879 case MISCREG_FPSCR_EXC: 880 { 881 newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 882 (newVal & FpscrExcMask); 883 misc_reg = MISCREG_FPSCR; 884 } 885 break; 886 case MISCREG_FPEXC: 887 { 888 // vfpv3 architecture, section B.6.1 of DDI04068 889 // bit 29 - valid only if fpexc[31] is 0 890 const uint32_t fpexcMask = 0x60000000; 891 newVal = (newVal & fpexcMask) | 892 (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask); 893 } 894 break; 895 case MISCREG_HCR: 896 { 897 if (!haveVirtualization) 898 return; 899 } 900 break; 901 case MISCREG_IFSR: 902 { 903 // ARM ARM (ARM DDI 0406C.b) B4.1.96 904 const uint32_t ifsrMask = 905 mask(31, 13) | mask(11, 11) | mask(8, 6); 906 newVal = newVal & ~ifsrMask; 907 } 908 break; 909 case MISCREG_DFSR: 910 { 911 // ARM ARM (ARM DDI 0406C.b) B4.1.52 912 const uint32_t dfsrMask = mask(31, 14) | mask(8, 8); 913 newVal = newVal & ~dfsrMask; 914 } 915 break; 916 case MISCREG_AMAIR0: 917 case MISCREG_AMAIR1: 918 { 919 // ARM ARM (ARM DDI 0406C.b) B4.1.5 920 // Valid only with LPAE 921 if (!haveLPAE) 922 return; 923 DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal); 924 } 925 break; 926 case MISCREG_SCR: 927 getITBPtr(tc)->invalidateMiscReg(); 928 getDTBPtr(tc)->invalidateMiscReg(); 929 break; 930 case MISCREG_SCTLR: 931 { 932 DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal); 933 scr = readMiscRegNoEffect(MISCREG_SCR); 934 935 MiscRegIndex sctlr_idx; 936 if (haveSecurity && !highestELIs64 && !scr.ns) { 937 sctlr_idx = MISCREG_SCTLR_S; 938 } else { 939 sctlr_idx = MISCREG_SCTLR_NS; 940 } 941 942 SCTLR sctlr = miscRegs[sctlr_idx]; 943 SCTLR new_sctlr = newVal; 944 new_sctlr.nmfi = ((bool)sctlr.nmfi) && !haveVirtualization; 945 miscRegs[sctlr_idx] = (MiscReg)new_sctlr; 946 getITBPtr(tc)->invalidateMiscReg(); 947 getDTBPtr(tc)->invalidateMiscReg(); 948 } 949 case MISCREG_MIDR: 950 case MISCREG_ID_PFR0: 951 case MISCREG_ID_PFR1: 952 case MISCREG_ID_DFR0: 953 case MISCREG_ID_MMFR0: 954 case MISCREG_ID_MMFR1: 955 case MISCREG_ID_MMFR2: 956 case MISCREG_ID_MMFR3: 957 case MISCREG_ID_ISAR0: 958 case MISCREG_ID_ISAR1: 959 case MISCREG_ID_ISAR2: 960 case MISCREG_ID_ISAR3: 961 case MISCREG_ID_ISAR4: 962 case MISCREG_ID_ISAR5: 963 964 case MISCREG_MPIDR: 965 case MISCREG_FPSID: 966 case MISCREG_TLBTR: 967 case MISCREG_MVFR0: 968 case MISCREG_MVFR1: 969 970 case MISCREG_ID_AA64AFR0_EL1: 971 case MISCREG_ID_AA64AFR1_EL1: 972 case MISCREG_ID_AA64DFR0_EL1: 973 case MISCREG_ID_AA64DFR1_EL1: 974 case MISCREG_ID_AA64ISAR0_EL1: 975 case MISCREG_ID_AA64ISAR1_EL1: 976 case MISCREG_ID_AA64MMFR0_EL1: 977 case MISCREG_ID_AA64MMFR1_EL1: 978 case MISCREG_ID_AA64PFR0_EL1: 979 case MISCREG_ID_AA64PFR1_EL1: 980 // ID registers are constants. 981 return; 982 983 // TLB Invalidate All 984 case MISCREG_TLBIALL: // TLBI all entries, EL0&1, 985 { 986 assert32(tc); 987 scr = readMiscReg(MISCREG_SCR, tc); 988 989 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 990 tlbiOp(tc); 991 return; 992 } 993 // TLB Invalidate All, Inner Shareable 994 case MISCREG_TLBIALLIS: 995 { 996 assert32(tc); 997 scr = readMiscReg(MISCREG_SCR, tc); 998 999 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1000 tlbiOp.broadcast(tc); 1001 return; 1002 } 1003 // Instruction TLB Invalidate All 1004 case MISCREG_ITLBIALL: 1005 { 1006 assert32(tc); 1007 scr = readMiscReg(MISCREG_SCR, tc); 1008 1009 ITLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1010 tlbiOp(tc); 1011 return; 1012 } 1013 // Data TLB Invalidate All 1014 case MISCREG_DTLBIALL: 1015 { 1016 assert32(tc); 1017 scr = readMiscReg(MISCREG_SCR, tc); 1018 1019 DTLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1020 tlbiOp(tc); 1021 return; 1022 } 1023 // TLB Invalidate by VA 1024 // mcr tlbimval(is) is invalidating all matching entries 1025 // regardless of the level of lookup, since in gem5 we cache 1026 // in the tlb the last level of lookup only. 1027 case MISCREG_TLBIMVA: 1028 case MISCREG_TLBIMVAL: 1029 { 1030 assert32(tc); 1031 scr = readMiscReg(MISCREG_SCR, tc); 1032 1033 TLBIMVA tlbiOp(EL1, 1034 haveSecurity && !scr.ns, 1035 mbits(newVal, 31, 12), 1036 bits(newVal, 7,0)); 1037 1038 tlbiOp(tc); 1039 return; 1040 } 1041 // TLB Invalidate by VA, Inner Shareable 1042 case MISCREG_TLBIMVAIS: 1043 case MISCREG_TLBIMVALIS: 1044 { 1045 assert32(tc); 1046 scr = readMiscReg(MISCREG_SCR, tc); 1047 1048 TLBIMVA tlbiOp(EL1, 1049 haveSecurity && !scr.ns, 1050 mbits(newVal, 31, 12), 1051 bits(newVal, 7,0)); 1052 1053 tlbiOp.broadcast(tc); 1054 return; 1055 } 1056 // TLB Invalidate by ASID match 1057 case MISCREG_TLBIASID: 1058 { 1059 assert32(tc); 1060 scr = readMiscReg(MISCREG_SCR, tc); 1061 1062 TLBIASID tlbiOp(EL1, 1063 haveSecurity && !scr.ns, 1064 bits(newVal, 7,0)); 1065 1066 tlbiOp(tc); 1067 return; 1068 } 1069 // TLB Invalidate by ASID match, Inner Shareable 1070 case MISCREG_TLBIASIDIS: 1071 { 1072 assert32(tc); 1073 scr = readMiscReg(MISCREG_SCR, tc); 1074 1075 TLBIASID tlbiOp(EL1, 1076 haveSecurity && !scr.ns, 1077 bits(newVal, 7,0)); 1078 1079 tlbiOp.broadcast(tc); 1080 return; 1081 } 1082 // mcr tlbimvaal(is) is invalidating all matching entries 1083 // regardless of the level of lookup, since in gem5 we cache 1084 // in the tlb the last level of lookup only. 1085 // TLB Invalidate by VA, All ASID 1086 case MISCREG_TLBIMVAA: 1087 case MISCREG_TLBIMVAAL: 1088 { 1089 assert32(tc); 1090 scr = readMiscReg(MISCREG_SCR, tc); 1091 1092 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1093 mbits(newVal, 31,12), false); 1094 1095 tlbiOp(tc); 1096 return; 1097 } 1098 // TLB Invalidate by VA, All ASID, Inner Shareable 1099 case MISCREG_TLBIMVAAIS: 1100 case MISCREG_TLBIMVAALIS: 1101 { 1102 assert32(tc); 1103 scr = readMiscReg(MISCREG_SCR, tc); 1104 1105 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1106 mbits(newVal, 31,12), false); 1107 1108 tlbiOp.broadcast(tc); 1109 return; 1110 } 1111 // mcr tlbimvalh(is) is invalidating all matching entries 1112 // regardless of the level of lookup, since in gem5 we cache 1113 // in the tlb the last level of lookup only. 1114 // TLB Invalidate by VA, Hyp mode 1115 case MISCREG_TLBIMVAH: 1116 case MISCREG_TLBIMVALH: 1117 { 1118 assert32(tc); 1119 scr = readMiscReg(MISCREG_SCR, tc); 1120 1121 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1122 mbits(newVal, 31,12), true); 1123 1124 tlbiOp(tc); 1125 return; 1126 } 1127 // TLB Invalidate by VA, Hyp mode, Inner Shareable 1128 case MISCREG_TLBIMVAHIS: 1129 case MISCREG_TLBIMVALHIS: 1130 { 1131 assert32(tc); 1132 scr = readMiscReg(MISCREG_SCR, tc); 1133 1134 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1135 mbits(newVal, 31,12), true); 1136 1137 tlbiOp.broadcast(tc); 1138 return; 1139 } 1140 // mcr tlbiipas2l(is) is invalidating all matching entries 1141 // regardless of the level of lookup, since in gem5 we cache 1142 // in the tlb the last level of lookup only. 1143 // TLB Invalidate by Intermediate Physical Address, Stage 2 1144 case MISCREG_TLBIIPAS2: 1145 case MISCREG_TLBIIPAS2L: 1146 { 1147 assert32(tc); 1148 scr = readMiscReg(MISCREG_SCR, tc); 1149 1150 TLBIIPA tlbiOp(EL1, 1151 haveSecurity && !scr.ns, 1152 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1153 1154 tlbiOp(tc); 1155 return; 1156 } 1157 // TLB Invalidate by Intermediate Physical Address, Stage 2, 1158 // Inner Shareable 1159 case MISCREG_TLBIIPAS2IS: 1160 case MISCREG_TLBIIPAS2LIS: 1161 { 1162 assert32(tc); 1163 scr = readMiscReg(MISCREG_SCR, tc); 1164 1165 TLBIIPA tlbiOp(EL1, 1166 haveSecurity && !scr.ns, 1167 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1168 1169 tlbiOp.broadcast(tc); 1170 return; 1171 } 1172 // Instruction TLB Invalidate by VA 1173 case MISCREG_ITLBIMVA: 1174 { 1175 assert32(tc); 1176 scr = readMiscReg(MISCREG_SCR, tc); 1177 1178 ITLBIMVA tlbiOp(EL1, 1179 haveSecurity && !scr.ns, 1180 mbits(newVal, 31, 12), 1181 bits(newVal, 7,0)); 1182 1183 tlbiOp(tc); 1184 return; 1185 } 1186 // Data TLB Invalidate by VA 1187 case MISCREG_DTLBIMVA: 1188 { 1189 assert32(tc); 1190 scr = readMiscReg(MISCREG_SCR, tc); 1191 1192 DTLBIMVA tlbiOp(EL1, 1193 haveSecurity && !scr.ns, 1194 mbits(newVal, 31, 12), 1195 bits(newVal, 7,0)); 1196 1197 tlbiOp(tc); 1198 return; 1199 } 1200 // Instruction TLB Invalidate by ASID match 1201 case MISCREG_ITLBIASID: 1202 { 1203 assert32(tc); 1204 scr = readMiscReg(MISCREG_SCR, tc); 1205 1206 ITLBIASID tlbiOp(EL1, 1207 haveSecurity && !scr.ns, 1208 bits(newVal, 7,0)); 1209 1210 tlbiOp(tc); 1211 return; 1212 } 1213 // Data TLB Invalidate by ASID match 1214 case MISCREG_DTLBIASID: 1215 { 1216 assert32(tc); 1217 scr = readMiscReg(MISCREG_SCR, tc); 1218 1219 DTLBIASID tlbiOp(EL1, 1220 haveSecurity && !scr.ns, 1221 bits(newVal, 7,0)); 1222 1223 tlbiOp(tc); 1224 return; 1225 } 1226 // TLB Invalidate All, Non-Secure Non-Hyp 1227 case MISCREG_TLBIALLNSNH: 1228 { 1229 assert32(tc); 1230 1231 TLBIALLN tlbiOp(EL1, false); 1232 tlbiOp(tc); 1233 return; 1234 } 1235 // TLB Invalidate All, Non-Secure Non-Hyp, Inner Shareable 1236 case MISCREG_TLBIALLNSNHIS: 1237 { 1238 assert32(tc); 1239 1240 TLBIALLN tlbiOp(EL1, false); 1241 tlbiOp.broadcast(tc); 1242 return; 1243 } 1244 // TLB Invalidate All, Hyp mode 1245 case MISCREG_TLBIALLH: 1246 { 1247 assert32(tc); 1248 1249 TLBIALLN tlbiOp(EL1, true); 1250 tlbiOp(tc); 1251 return; 1252 } 1253 // TLB Invalidate All, Hyp mode, Inner Shareable 1254 case MISCREG_TLBIALLHIS: 1255 { 1256 assert32(tc); 1257 1258 TLBIALLN tlbiOp(EL1, true); 1259 tlbiOp.broadcast(tc); 1260 return; 1261 } 1262 // AArch64 TLB Invalidate All, EL3 1263 case MISCREG_TLBI_ALLE3: 1264 { 1265 assert64(tc); 1266 1267 TLBIALL tlbiOp(EL3, true); 1268 tlbiOp(tc); 1269 return; 1270 } 1271 // AArch64 TLB Invalidate All, EL3, Inner Shareable 1272 case MISCREG_TLBI_ALLE3IS: 1273 { 1274 assert64(tc); 1275 1276 TLBIALL tlbiOp(EL3, true); 1277 tlbiOp.broadcast(tc); 1278 return; 1279 } 1280 // @todo: uncomment this to enable Virtualization 1281 // case MISCREG_TLBI_ALLE2IS: 1282 // case MISCREG_TLBI_ALLE2: 1283 // AArch64 TLB Invalidate All, EL1 1284 case MISCREG_TLBI_ALLE1: 1285 case MISCREG_TLBI_VMALLE1: 1286 case MISCREG_TLBI_VMALLS12E1: 1287 // @todo: handle VMID and stage 2 to enable Virtualization 1288 { 1289 assert64(tc); 1290 scr = readMiscReg(MISCREG_SCR, tc); 1291 1292 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1293 tlbiOp(tc); 1294 return; 1295 } 1296 // AArch64 TLB Invalidate All, EL1, Inner Shareable 1297 case MISCREG_TLBI_ALLE1IS: 1298 case MISCREG_TLBI_VMALLE1IS: 1299 case MISCREG_TLBI_VMALLS12E1IS: 1300 // @todo: handle VMID and stage 2 to enable Virtualization 1301 { 1302 assert64(tc); 1303 scr = readMiscReg(MISCREG_SCR, tc); 1304 1305 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1306 tlbiOp.broadcast(tc); 1307 return; 1308 } 1309 // VAEx(IS) and VALEx(IS) are the same because TLBs 1310 // only store entries 1311 // from the last level of translation table walks 1312 // @todo: handle VMID to enable Virtualization 1313 // AArch64 TLB Invalidate by VA, EL3 1314 case MISCREG_TLBI_VAE3_Xt: 1315 case MISCREG_TLBI_VALE3_Xt: 1316 { 1317 assert64(tc); 1318 1319 TLBIMVA tlbiOp(EL3, true, 1320 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1321 0xbeef); 1322 tlbiOp(tc); 1323 return; 1324 } 1325 // AArch64 TLB Invalidate by VA, EL3, Inner Shareable 1326 case MISCREG_TLBI_VAE3IS_Xt: 1327 case MISCREG_TLBI_VALE3IS_Xt: 1328 { 1329 assert64(tc); 1330 1331 TLBIMVA tlbiOp(EL3, true, 1332 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1333 0xbeef); 1334 1335 tlbiOp.broadcast(tc); 1336 return; 1337 } 1338 // AArch64 TLB Invalidate by VA, EL2 1339 case MISCREG_TLBI_VAE2_Xt: 1340 case MISCREG_TLBI_VALE2_Xt: 1341 { 1342 assert64(tc); 1343 scr = readMiscReg(MISCREG_SCR, tc); 1344 1345 TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns, 1346 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1347 0xbeef); 1348 tlbiOp(tc); 1349 return; 1350 } 1351 // AArch64 TLB Invalidate by VA, EL2, Inner Shareable 1352 case MISCREG_TLBI_VAE2IS_Xt: 1353 case MISCREG_TLBI_VALE2IS_Xt: 1354 { 1355 assert64(tc); 1356 scr = readMiscReg(MISCREG_SCR, tc); 1357 1358 TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns, 1359 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1360 0xbeef); 1361 1362 tlbiOp.broadcast(tc); 1363 return; 1364 } 1365 // AArch64 TLB Invalidate by VA, EL1 1366 case MISCREG_TLBI_VAE1_Xt: 1367 case MISCREG_TLBI_VALE1_Xt: 1368 { 1369 assert64(tc); 1370 scr = readMiscReg(MISCREG_SCR, tc); 1371 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1372 bits(newVal, 55, 48); 1373 1374 TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns, 1375 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1376 asid); 1377 1378 tlbiOp(tc); 1379 return; 1380 } 1381 // AArch64 TLB Invalidate by VA, EL1, Inner Shareable 1382 case MISCREG_TLBI_VAE1IS_Xt: 1383 case MISCREG_TLBI_VALE1IS_Xt: 1384 { 1385 assert64(tc); 1386 scr = readMiscReg(MISCREG_SCR, tc); 1387 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1388 bits(newVal, 55, 48); 1389 1390 TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns, 1391 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1392 asid); 1393 1394 tlbiOp.broadcast(tc); 1395 return; 1396 } 1397 // AArch64 TLB Invalidate by ASID, EL1 1398 // @todo: handle VMID to enable Virtualization 1399 case MISCREG_TLBI_ASIDE1_Xt: 1400 { 1401 assert64(tc); 1402 scr = readMiscReg(MISCREG_SCR, tc); 1403 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1404 bits(newVal, 55, 48); 1405 1406 TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid); 1407 tlbiOp(tc); 1408 return; 1409 } 1410 // AArch64 TLB Invalidate by ASID, EL1, Inner Shareable 1411 case MISCREG_TLBI_ASIDE1IS_Xt: 1412 { 1413 assert64(tc); 1414 scr = readMiscReg(MISCREG_SCR, tc); 1415 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1416 bits(newVal, 55, 48); 1417 1418 TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid); 1419 tlbiOp.broadcast(tc); 1420 return; 1421 } 1422 // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store 1423 // entries from the last level of translation table walks 1424 // AArch64 TLB Invalidate by VA, All ASID, EL1 1425 case MISCREG_TLBI_VAAE1_Xt: 1426 case MISCREG_TLBI_VAALE1_Xt: 1427 { 1428 assert64(tc); 1429 scr = readMiscReg(MISCREG_SCR, tc); 1430 1431 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1432 static_cast<Addr>(bits(newVal, 43, 0)) << 12, false); 1433 1434 tlbiOp(tc); 1435 return; 1436 } 1437 // AArch64 TLB Invalidate by VA, All ASID, EL1, Inner Shareable 1438 case MISCREG_TLBI_VAAE1IS_Xt: 1439 case MISCREG_TLBI_VAALE1IS_Xt: 1440 { 1441 assert64(tc); 1442 scr = readMiscReg(MISCREG_SCR, tc); 1443 1444 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1445 static_cast<Addr>(bits(newVal, 43, 0)) << 12, false); 1446 1447 tlbiOp.broadcast(tc); 1448 return; 1449 } 1450 // AArch64 TLB Invalidate by Intermediate Physical Address, 1451 // Stage 2, EL1 1452 case MISCREG_TLBI_IPAS2E1_Xt: 1453 case MISCREG_TLBI_IPAS2LE1_Xt: 1454 { 1455 assert64(tc); 1456 scr = readMiscReg(MISCREG_SCR, tc); 1457 1458 TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns, 1459 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1460 1461 tlbiOp(tc); 1462 return; 1463 } 1464 // AArch64 TLB Invalidate by Intermediate Physical Address, 1465 // Stage 2, EL1, Inner Shareable 1466 case MISCREG_TLBI_IPAS2E1IS_Xt: 1467 case MISCREG_TLBI_IPAS2LE1IS_Xt: 1468 { 1469 assert64(tc); 1470 scr = readMiscReg(MISCREG_SCR, tc); 1471 1472 TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns, 1473 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1474 1475 tlbiOp.broadcast(tc); 1476 return; 1477 } 1478 case MISCREG_ACTLR: 1479 warn("Not doing anything for write of miscreg ACTLR\n"); 1480 break; 1481 1482 case MISCREG_PMXEVTYPER_PMCCFILTR: 1483 case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 1484 case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 1485 case MISCREG_PMCR ... MISCREG_PMOVSSET: 1486 pmu->setMiscReg(misc_reg, newVal); 1487 break; 1488 1489 1490 case MISCREG_HSTR: // TJDBX, now redifined to be RES0 1491 { 1492 HSTR hstrMask = 0; 1493 hstrMask.tjdbx = 1; 1494 newVal &= ~((uint32_t) hstrMask); 1495 break; 1496 } 1497 case MISCREG_HCPTR: 1498 { 1499 // If a CP bit in NSACR is 0 then the corresponding bit in 1500 // HCPTR is RAO/WI. Same applies to NSASEDIS 1501 secure_lookup = haveSecurity && 1502 inSecureState(readMiscRegNoEffect(MISCREG_SCR), 1503 readMiscRegNoEffect(MISCREG_CPSR)); 1504 if (!secure_lookup) { 1505 MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR); 1506 MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF; 1507 newVal = (newVal & ~mask) | (oldValue & mask); 1508 } 1509 break; 1510 } 1511 case MISCREG_HDFAR: // alias for secure DFAR 1512 misc_reg = MISCREG_DFAR_S; 1513 break; 1514 case MISCREG_HIFAR: // alias for secure IFAR 1515 misc_reg = MISCREG_IFAR_S; 1516 break; 1517 case MISCREG_ATS1CPR: 1518 case MISCREG_ATS1CPW: 1519 case MISCREG_ATS1CUR: 1520 case MISCREG_ATS1CUW: 1521 case MISCREG_ATS12NSOPR: 1522 case MISCREG_ATS12NSOPW: 1523 case MISCREG_ATS12NSOUR: 1524 case MISCREG_ATS12NSOUW: 1525 case MISCREG_ATS1HR: 1526 case MISCREG_ATS1HW: 1527 { 1528 Request::Flags flags = 0; 1529 BaseTLB::Mode mode = BaseTLB::Read; 1530 TLB::ArmTranslationType tranType = TLB::NormalTran; 1531 Fault fault; 1532 switch(misc_reg) { 1533 case MISCREG_ATS1CPR: 1534 flags = TLB::MustBeOne; 1535 tranType = TLB::S1CTran; 1536 mode = BaseTLB::Read; 1537 break; 1538 case MISCREG_ATS1CPW: 1539 flags = TLB::MustBeOne; 1540 tranType = TLB::S1CTran; 1541 mode = BaseTLB::Write; 1542 break; 1543 case MISCREG_ATS1CUR: 1544 flags = TLB::MustBeOne | TLB::UserMode; 1545 tranType = TLB::S1CTran; 1546 mode = BaseTLB::Read; 1547 break; 1548 case MISCREG_ATS1CUW: 1549 flags = TLB::MustBeOne | TLB::UserMode; 1550 tranType = TLB::S1CTran; 1551 mode = BaseTLB::Write; 1552 break; 1553 case MISCREG_ATS12NSOPR: 1554 if (!haveSecurity) 1555 panic("Security Extensions required for ATS12NSOPR"); 1556 flags = TLB::MustBeOne; 1557 tranType = TLB::S1S2NsTran; 1558 mode = BaseTLB::Read; 1559 break; 1560 case MISCREG_ATS12NSOPW: 1561 if (!haveSecurity) 1562 panic("Security Extensions required for ATS12NSOPW"); 1563 flags = TLB::MustBeOne; 1564 tranType = TLB::S1S2NsTran; 1565 mode = BaseTLB::Write; 1566 break; 1567 case MISCREG_ATS12NSOUR: 1568 if (!haveSecurity) 1569 panic("Security Extensions required for ATS12NSOUR"); 1570 flags = TLB::MustBeOne | TLB::UserMode; 1571 tranType = TLB::S1S2NsTran; 1572 mode = BaseTLB::Read; 1573 break; 1574 case MISCREG_ATS12NSOUW: 1575 if (!haveSecurity) 1576 panic("Security Extensions required for ATS12NSOUW"); 1577 flags = TLB::MustBeOne | TLB::UserMode; 1578 tranType = TLB::S1S2NsTran; 1579 mode = BaseTLB::Write; 1580 break; 1581 case MISCREG_ATS1HR: // only really useful from secure mode. 1582 flags = TLB::MustBeOne; 1583 tranType = TLB::HypMode; 1584 mode = BaseTLB::Read; 1585 break; 1586 case MISCREG_ATS1HW: 1587 flags = TLB::MustBeOne; 1588 tranType = TLB::HypMode; 1589 mode = BaseTLB::Write; 1590 break; 1591 } 1592 // If we're in timing mode then doing the translation in 1593 // functional mode then we're slightly distorting performance 1594 // results obtained from simulations. The translation should be 1595 // done in the same mode the core is running in. NOTE: This 1596 // can't be an atomic translation because that causes problems 1597 // with unexpected atomic snoop requests. 1598 warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 1599 1600 auto req = std::make_shared<Request>( 1601 0, val, 0, flags, Request::funcMasterId, 1602 tc->pcState().pc(), tc->contextId()); 1603 1604 fault = getDTBPtr(tc)->translateFunctional( 1605 req, tc, mode, tranType); 1606 1607 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 1608 HCR hcr = readMiscRegNoEffect(MISCREG_HCR); 1609 1610 MiscReg newVal; 1611 if (fault == NoFault) { 1612 Addr paddr = req->getPaddr(); 1613 if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode || 1614 ((tranType & TLB::S1S2NsTran) && hcr.vm) )) { 1615 newVal = (paddr & mask(39, 12)) | 1616 (getDTBPtr(tc)->getAttr()); 1617 } else { 1618 newVal = (paddr & 0xfffff000) | 1619 (getDTBPtr(tc)->getAttr()); 1620 } 1621 DPRINTF(MiscRegs, 1622 "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n", 1623 val, newVal); 1624 } else { 1625 ArmFault *armFault = static_cast<ArmFault *>(fault.get()); 1626 armFault->update(tc); 1627 // Set fault bit and FSR 1628 FSR fsr = armFault->getFsr(tc); 1629 1630 newVal = ((fsr >> 9) & 1) << 11; 1631 if (newVal) { 1632 // LPAE - rearange fault status 1633 newVal |= ((fsr >> 0) & 0x3f) << 1; 1634 } else { 1635 // VMSA - rearange fault status 1636 newVal |= ((fsr >> 0) & 0xf) << 1; 1637 newVal |= ((fsr >> 10) & 0x1) << 5; 1638 newVal |= ((fsr >> 12) & 0x1) << 6; 1639 } 1640 newVal |= 0x1; // F bit 1641 newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 1642 newVal |= armFault->isStage2() ? 0x200 : 0; 1643 DPRINTF(MiscRegs, 1644 "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n", 1645 val, fsr, newVal); 1646 } 1647 setMiscRegNoEffect(MISCREG_PAR, newVal); 1648 return; 1649 } 1650 case MISCREG_TTBCR: 1651 { 1652 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 1653 const uint32_t ones = (uint32_t)(-1); 1654 TTBCR ttbcrMask = 0; 1655 TTBCR ttbcrNew = newVal; 1656 1657 // ARM DDI 0406C.b, ARMv7-32 1658 ttbcrMask.n = ones; // T0SZ 1659 if (haveSecurity) { 1660 ttbcrMask.pd0 = ones; 1661 ttbcrMask.pd1 = ones; 1662 } 1663 ttbcrMask.epd0 = ones; 1664 ttbcrMask.irgn0 = ones; 1665 ttbcrMask.orgn0 = ones; 1666 ttbcrMask.sh0 = ones; 1667 ttbcrMask.ps = ones; // T1SZ 1668 ttbcrMask.a1 = ones; 1669 ttbcrMask.epd1 = ones; 1670 ttbcrMask.irgn1 = ones; 1671 ttbcrMask.orgn1 = ones; 1672 ttbcrMask.sh1 = ones; 1673 if (haveLPAE) 1674 ttbcrMask.eae = ones; 1675 1676 if (haveLPAE && ttbcrNew.eae) { 1677 newVal = newVal & ttbcrMask; 1678 } else { 1679 newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask)); 1680 } 1681 // Invalidate TLB MiscReg 1682 getITBPtr(tc)->invalidateMiscReg(); 1683 getDTBPtr(tc)->invalidateMiscReg(); 1684 break; 1685 } 1686 case MISCREG_TTBR0: 1687 case MISCREG_TTBR1: 1688 { 1689 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 1690 if (haveLPAE) { 1691 if (ttbcr.eae) { 1692 // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP 1693 // ARMv8 AArch32 bit 63-56 only 1694 uint64_t ttbrMask = mask(63,56) | mask(47,40); 1695 newVal = (newVal & (~ttbrMask)); 1696 } 1697 } 1698 // Invalidate TLB MiscReg 1699 getITBPtr(tc)->invalidateMiscReg(); 1700 getDTBPtr(tc)->invalidateMiscReg(); 1701 break; 1702 } 1703 case MISCREG_SCTLR_EL1: 1704 case MISCREG_CONTEXTIDR: 1705 case MISCREG_PRRR: 1706 case MISCREG_NMRR: 1707 case MISCREG_MAIR0: 1708 case MISCREG_MAIR1: 1709 case MISCREG_DACR: 1710 case MISCREG_VTTBR: 1711 case MISCREG_SCR_EL3: 1712 case MISCREG_HCR_EL2: 1713 case MISCREG_TCR_EL1: 1714 case MISCREG_TCR_EL2: 1715 case MISCREG_TCR_EL3: 1716 case MISCREG_SCTLR_EL2: 1717 case MISCREG_SCTLR_EL3: 1718 case MISCREG_HSCTLR: 1719 case MISCREG_TTBR0_EL1: 1720 case MISCREG_TTBR1_EL1: 1721 case MISCREG_TTBR0_EL2: 1722 case MISCREG_TTBR1_EL2: 1723 case MISCREG_TTBR0_EL3: 1724 getITBPtr(tc)->invalidateMiscReg(); 1725 getDTBPtr(tc)->invalidateMiscReg(); 1726 break; 1727 case MISCREG_NZCV: 1728 { 1729 CPSR cpsr = val; 1730 1731 tc->setCCReg(CCREG_NZ, cpsr.nz); 1732 tc->setCCReg(CCREG_C, cpsr.c); 1733 tc->setCCReg(CCREG_V, cpsr.v); 1734 } 1735 break; 1736 case MISCREG_DAIF: 1737 { 1738 CPSR cpsr = miscRegs[MISCREG_CPSR]; 1739 cpsr.daif = (uint8_t) ((CPSR) newVal).daif; 1740 newVal = cpsr; 1741 misc_reg = MISCREG_CPSR; 1742 } 1743 break; 1744 case MISCREG_SP_EL0: 1745 tc->setIntReg(INTREG_SP0, newVal); 1746 break; 1747 case MISCREG_SP_EL1: 1748 tc->setIntReg(INTREG_SP1, newVal); 1749 break; 1750 case MISCREG_SP_EL2: 1751 tc->setIntReg(INTREG_SP2, newVal); 1752 break; 1753 case MISCREG_SPSEL: 1754 { 1755 CPSR cpsr = miscRegs[MISCREG_CPSR]; 1756 cpsr.sp = (uint8_t) ((CPSR) newVal).sp; 1757 newVal = cpsr; 1758 misc_reg = MISCREG_CPSR; 1759 } 1760 break; 1761 case MISCREG_CURRENTEL: 1762 { 1763 CPSR cpsr = miscRegs[MISCREG_CPSR]; 1764 cpsr.el = (uint8_t) ((CPSR) newVal).el; 1765 newVal = cpsr; 1766 misc_reg = MISCREG_CPSR; 1767 } 1768 break; 1769 case MISCREG_AT_S1E1R_Xt: 1770 case MISCREG_AT_S1E1W_Xt: 1771 case MISCREG_AT_S1E0R_Xt: 1772 case MISCREG_AT_S1E0W_Xt: 1773 case MISCREG_AT_S1E2R_Xt: 1774 case MISCREG_AT_S1E2W_Xt: 1775 case MISCREG_AT_S12E1R_Xt: 1776 case MISCREG_AT_S12E1W_Xt: 1777 case MISCREG_AT_S12E0R_Xt: 1778 case MISCREG_AT_S12E0W_Xt: 1779 case MISCREG_AT_S1E3R_Xt: 1780 case MISCREG_AT_S1E3W_Xt: 1781 { 1782 RequestPtr req = std::make_shared<Request>(); 1783 Request::Flags flags = 0; 1784 BaseTLB::Mode mode = BaseTLB::Read; 1785 TLB::ArmTranslationType tranType = TLB::NormalTran; 1786 Fault fault; 1787 switch(misc_reg) { 1788 case MISCREG_AT_S1E1R_Xt: 1789 flags = TLB::MustBeOne; 1790 tranType = TLB::S1E1Tran; 1791 mode = BaseTLB::Read; 1792 break; 1793 case MISCREG_AT_S1E1W_Xt: 1794 flags = TLB::MustBeOne; 1795 tranType = TLB::S1E1Tran; 1796 mode = BaseTLB::Write; 1797 break; 1798 case MISCREG_AT_S1E0R_Xt: 1799 flags = TLB::MustBeOne | TLB::UserMode; 1800 tranType = TLB::S1E0Tran; 1801 mode = BaseTLB::Read; 1802 break; 1803 case MISCREG_AT_S1E0W_Xt: 1804 flags = TLB::MustBeOne | TLB::UserMode; 1805 tranType = TLB::S1E0Tran; 1806 mode = BaseTLB::Write; 1807 break; 1808 case MISCREG_AT_S1E2R_Xt: 1809 flags = TLB::MustBeOne; 1810 tranType = TLB::S1E2Tran; 1811 mode = BaseTLB::Read; 1812 break; 1813 case MISCREG_AT_S1E2W_Xt: 1814 flags = TLB::MustBeOne; 1815 tranType = TLB::S1E2Tran; 1816 mode = BaseTLB::Write; 1817 break; 1818 case MISCREG_AT_S12E0R_Xt: 1819 flags = TLB::MustBeOne | TLB::UserMode; 1820 tranType = TLB::S12E0Tran; 1821 mode = BaseTLB::Read; 1822 break; 1823 case MISCREG_AT_S12E0W_Xt: 1824 flags = TLB::MustBeOne | TLB::UserMode; 1825 tranType = TLB::S12E0Tran; 1826 mode = BaseTLB::Write; 1827 break; 1828 case MISCREG_AT_S12E1R_Xt: 1829 flags = TLB::MustBeOne; 1830 tranType = TLB::S12E1Tran; 1831 mode = BaseTLB::Read; 1832 break; 1833 case MISCREG_AT_S12E1W_Xt: 1834 flags = TLB::MustBeOne; 1835 tranType = TLB::S12E1Tran; 1836 mode = BaseTLB::Write; 1837 break; 1838 case MISCREG_AT_S1E3R_Xt: 1839 flags = TLB::MustBeOne; 1840 tranType = TLB::S1E3Tran; 1841 mode = BaseTLB::Read; 1842 break; 1843 case MISCREG_AT_S1E3W_Xt: 1844 flags = TLB::MustBeOne; 1845 tranType = TLB::S1E3Tran; 1846 mode = BaseTLB::Write; 1847 break; 1848 } 1849 // If we're in timing mode then doing the translation in 1850 // functional mode then we're slightly distorting performance 1851 // results obtained from simulations. The translation should be 1852 // done in the same mode the core is running in. NOTE: This 1853 // can't be an atomic translation because that causes problems 1854 // with unexpected atomic snoop requests. 1855 warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 1856 req->setVirt(0, val, 0, flags, Request::funcMasterId, 1857 tc->pcState().pc()); 1858 req->setContext(tc->contextId()); 1859 fault = getDTBPtr(tc)->translateFunctional(req, tc, mode, 1860 tranType); 1861 1862 MiscReg newVal; 1863 if (fault == NoFault) { 1864 Addr paddr = req->getPaddr(); 1865 uint64_t attr = getDTBPtr(tc)->getAttr(); 1866 uint64_t attr1 = attr >> 56; 1867 if (!attr1 || attr1 ==0x44) { 1868 attr |= 0x100; 1869 attr &= ~ uint64_t(0x80); 1870 } 1871 newVal = (paddr & mask(47, 12)) | attr; 1872 DPRINTF(MiscRegs, 1873 "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n", 1874 val, newVal); 1875 } else { 1876 ArmFault *armFault = static_cast<ArmFault *>(fault.get()); 1877 armFault->update(tc); 1878 // Set fault bit and FSR 1879 FSR fsr = armFault->getFsr(tc); 1880 1881 CPSR cpsr = tc->readMiscReg(MISCREG_CPSR); 1882 if (cpsr.width) { // AArch32 1883 newVal = ((fsr >> 9) & 1) << 11; 1884 // rearrange fault status 1885 newVal |= ((fsr >> 0) & 0x3f) << 1; 1886 newVal |= 0x1; // F bit 1887 newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 1888 newVal |= armFault->isStage2() ? 0x200 : 0; 1889 } else { // AArch64 1890 newVal = 1; // F bit 1891 newVal |= fsr << 1; // FST 1892 // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit. 1893 newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW 1894 newVal |= armFault->isStage2() ? 1 << 9 : 0; // S 1895 newVal |= 1 << 11; // RES1 1896 } 1897 DPRINTF(MiscRegs, 1898 "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n", 1899 val, fsr, newVal); 1900 } 1901 setMiscRegNoEffect(MISCREG_PAR_EL1, newVal); 1902 return; 1903 } 1904 case MISCREG_SPSR_EL3: 1905 case MISCREG_SPSR_EL2: 1906 case MISCREG_SPSR_EL1: 1907 // Force bits 23:21 to 0 1908 newVal = val & ~(0x7 << 21); 1909 break; 1910 case MISCREG_L2CTLR: 1911 warn("miscreg L2CTLR (%s) written with %#x. ignored...\n", 1912 miscRegName[misc_reg], uint32_t(val)); 1913 break; 1914 1915 // Generic Timer registers 1916 case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 1917 case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 1918 case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 1919 case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 1920 getGenericTimer(tc).setMiscReg(misc_reg, newVal); 1921 break; 1922 } 1923 } 1924 setMiscRegNoEffect(misc_reg, newVal); 1925} 1926 1927BaseISADevice & 1928ISA::getGenericTimer(ThreadContext *tc) 1929{ 1930 // We only need to create an ISA interface the first time we try 1931 // to access the timer. 1932 if (timer) 1933 return *timer.get(); 1934 1935 assert(system); 1936 GenericTimer *generic_timer(system->getGenericTimer()); 1937 if (!generic_timer) { 1938 panic("Trying to get a generic timer from a system that hasn't " 1939 "been configured to use a generic timer.\n"); 1940 } 1941 1942 timer.reset(new GenericTimerISA(*generic_timer, tc->contextId())); 1943 return *timer.get(); 1944} 1945 1946} 1947 1948ArmISA::ISA * 1949ArmISAParams::create() 1950{ 1951 return new ArmISA::ISA(this); 1952} 1953