isa.cc revision 13116
17405SAli.Saidi@ARM.com/* 29814Sandreas.hansson@arm.com * Copyright (c) 2010-2018 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" 429050Schander.sudanthi@arm.com#include "arch/arm/pmu.hh" 438887Sgeoffrey.blake@arm.com#include "arch/arm/system.hh" 448232Snate@binkert.org#include "arch/arm/tlb.hh" 458232Snate@binkert.org#include "arch/arm/tlbi_op.hh" 469384SAndreas.Sandberg@arm.com#include "cpu/base.hh" 477678Sgblack@eecs.umich.edu#include "cpu/checker/cpu.hh" 488059SAli.Saidi@ARM.com#include "debug/Arm.hh" 498284SAli.Saidi@ARM.com#include "debug/MiscRegs.hh" 507405SAli.Saidi@ARM.com#include "dev/arm/generic_timer.hh" 517405SAli.Saidi@ARM.com#include "params/ArmISA.hh" 527405SAli.Saidi@ARM.com#include "sim/faults.hh" 537405SAli.Saidi@ARM.com#include "sim/stat_control.hh" 549384SAndreas.Sandberg@arm.com#include "sim/system.hh" 559384SAndreas.Sandberg@arm.com 569384SAndreas.Sandberg@arm.comnamespace ArmISA 579384SAndreas.Sandberg@arm.com{ 589384SAndreas.Sandberg@arm.com 599384SAndreas.Sandberg@arm.comISA::ISA(Params *p) 609384SAndreas.Sandberg@arm.com : SimObject(p), 619384SAndreas.Sandberg@arm.com system(NULL), 629384SAndreas.Sandberg@arm.com _decoderFlavour(p->decoderFlavour), 639384SAndreas.Sandberg@arm.com _vecRegRenameMode(p->vecRegRenameMode), 649384SAndreas.Sandberg@arm.com pmu(p->pmu), 659384SAndreas.Sandberg@arm.com impdefAsNop(p->impdef_nop) 669384SAndreas.Sandberg@arm.com{ 679384SAndreas.Sandberg@arm.com miscRegs[MISCREG_SCTLR_RST] = 0; 689384SAndreas.Sandberg@arm.com 697427Sgblack@eecs.umich.edu // Hook up a dummy device if we haven't been configured with a 707427Sgblack@eecs.umich.edu // real PMU. By using a dummy device, we don't need to check that 717427Sgblack@eecs.umich.edu // the PMU exist every time we try to access a PMU register. 729385SAndreas.Sandberg@arm.com if (!pmu) 739385SAndreas.Sandberg@arm.com pmu = &dummyDevice; 747427Sgblack@eecs.umich.edu 757427Sgblack@eecs.umich.edu // Give all ISA devices a pointer to this ISA 767427Sgblack@eecs.umich.edu pmu->setISA(this); 777427Sgblack@eecs.umich.edu 787427Sgblack@eecs.umich.edu system = dynamic_cast<ArmSystem *>(p->system); 797427Sgblack@eecs.umich.edu 807427Sgblack@eecs.umich.edu // Cache system-level properties 817427Sgblack@eecs.umich.edu if (FullSystem && system) { 827604SGene.Wu@arm.com highestELIs64 = system->highestELIs64(); 837427Sgblack@eecs.umich.edu haveSecurity = system->haveSecurity(); 847427Sgblack@eecs.umich.edu haveLPAE = system->haveLPAE(); 857427Sgblack@eecs.umich.edu haveVirtualization = system->haveVirtualization(); 867427Sgblack@eecs.umich.edu haveLargeAsid64 = system->haveLargeAsid64(); 877427Sgblack@eecs.umich.edu physAddrRange = system->physAddrRange(); 887427Sgblack@eecs.umich.edu } else { 897427Sgblack@eecs.umich.edu highestELIs64 = true; // ArmSystem::highestELIs64 does the same 907427Sgblack@eecs.umich.edu haveSecurity = haveLPAE = haveVirtualization = false; 917427Sgblack@eecs.umich.edu haveLargeAsid64 = false; 927427Sgblack@eecs.umich.edu physAddrRange = 32; // dummy value 937427Sgblack@eecs.umich.edu } 947427Sgblack@eecs.umich.edu 957427Sgblack@eecs.umich.edu initializeMiscRegMetadata(); 967427Sgblack@eecs.umich.edu preUnflattenMiscReg(); 977427Sgblack@eecs.umich.edu 987427Sgblack@eecs.umich.edu clear(); 997427Sgblack@eecs.umich.edu} 1007427Sgblack@eecs.umich.edu 1017427Sgblack@eecs.umich.edustd::vector<struct ISA::MiscRegLUTEntry> ISA::lookUpMiscReg(NUM_MISCREGS); 1027427Sgblack@eecs.umich.edu 1037427Sgblack@eecs.umich.educonst ArmISAParams * 1047427Sgblack@eecs.umich.eduISA::params() const 1057427Sgblack@eecs.umich.edu{ 1067427Sgblack@eecs.umich.edu return dynamic_cast<const Params *>(_params); 1077427Sgblack@eecs.umich.edu} 1087427Sgblack@eecs.umich.edu 1097427Sgblack@eecs.umich.eduvoid 1107427Sgblack@eecs.umich.eduISA::clear() 1117427Sgblack@eecs.umich.edu{ 1127427Sgblack@eecs.umich.edu const Params *p(params()); 1137427Sgblack@eecs.umich.edu 1147427Sgblack@eecs.umich.edu SCTLR sctlr_rst = miscRegs[MISCREG_SCTLR_RST]; 1157427Sgblack@eecs.umich.edu memset(miscRegs, 0, sizeof(miscRegs)); 1167427Sgblack@eecs.umich.edu 1177427Sgblack@eecs.umich.edu initID32(p); 1187427Sgblack@eecs.umich.edu 1197427Sgblack@eecs.umich.edu // We always initialize AArch64 ID registers even 1207436Sdam.sunwoo@arm.com // if we are in AArch32. This is done since if we 1217436Sdam.sunwoo@arm.com // are in SE mode we don't know if our ArmProcess is 1227436Sdam.sunwoo@arm.com // AArch32 or AArch64 1237436Sdam.sunwoo@arm.com initID64(p); 1247436Sdam.sunwoo@arm.com 1257436Sdam.sunwoo@arm.com if (FullSystem && system->highestELIs64()) { 1267436Sdam.sunwoo@arm.com // Initialize AArch64 state 1277436Sdam.sunwoo@arm.com clear64(p); 1287436Sdam.sunwoo@arm.com return; 1297436Sdam.sunwoo@arm.com } 1307436Sdam.sunwoo@arm.com 1317436Sdam.sunwoo@arm.com // Initialize AArch32 state... 1327436Sdam.sunwoo@arm.com 1337436Sdam.sunwoo@arm.com CPSR cpsr = 0; 1347436Sdam.sunwoo@arm.com cpsr.mode = MODE_USER; 1357436Sdam.sunwoo@arm.com miscRegs[MISCREG_CPSR] = cpsr; 1367436Sdam.sunwoo@arm.com updateRegMap(cpsr); 1377436Sdam.sunwoo@arm.com 1387436Sdam.sunwoo@arm.com SCTLR sctlr = 0; 1397436Sdam.sunwoo@arm.com sctlr.te = (bool) sctlr_rst.te; 1407436Sdam.sunwoo@arm.com sctlr.nmfi = (bool) sctlr_rst.nmfi; 1417436Sdam.sunwoo@arm.com sctlr.v = (bool) sctlr_rst.v; 1427436Sdam.sunwoo@arm.com sctlr.u = 1; 1437436Sdam.sunwoo@arm.com sctlr.xp = 1; 1447436Sdam.sunwoo@arm.com sctlr.rao2 = 1; 1457436Sdam.sunwoo@arm.com sctlr.rao3 = 1; 1467436Sdam.sunwoo@arm.com sctlr.rao4 = 0xf; // SCTLR[6:3] 1477436Sdam.sunwoo@arm.com sctlr.uci = 1; 1487436Sdam.sunwoo@arm.com sctlr.dze = 1; 1497436Sdam.sunwoo@arm.com miscRegs[MISCREG_SCTLR_NS] = sctlr; 1507436Sdam.sunwoo@arm.com miscRegs[MISCREG_SCTLR_RST] = sctlr_rst; 1517436Sdam.sunwoo@arm.com miscRegs[MISCREG_HCPTR] = 0; 1527644Sali.saidi@arm.com 1538147SAli.Saidi@ARM.com // Start with an event in the mailbox 1549385SAndreas.Sandberg@arm.com miscRegs[MISCREG_SEV_MAILBOX] = 1; 1559385SAndreas.Sandberg@arm.com 1569385SAndreas.Sandberg@arm.com // Separate Instruction and Data TLBs 1579385SAndreas.Sandberg@arm.com miscRegs[MISCREG_TLBTR] = 1; 1589385SAndreas.Sandberg@arm.com 1599385SAndreas.Sandberg@arm.com MVFR0 mvfr0 = 0; 1609385SAndreas.Sandberg@arm.com mvfr0.advSimdRegisters = 2; 1619385SAndreas.Sandberg@arm.com mvfr0.singlePrecision = 2; 1629385SAndreas.Sandberg@arm.com mvfr0.doublePrecision = 2; 1639385SAndreas.Sandberg@arm.com mvfr0.vfpExceptionTrapping = 0; 1649385SAndreas.Sandberg@arm.com mvfr0.divide = 1; 1659385SAndreas.Sandberg@arm.com mvfr0.squareRoot = 1; 1669385SAndreas.Sandberg@arm.com mvfr0.shortVectors = 1; 1679385SAndreas.Sandberg@arm.com mvfr0.roundingModes = 1; 1689385SAndreas.Sandberg@arm.com miscRegs[MISCREG_MVFR0] = mvfr0; 1699385SAndreas.Sandberg@arm.com 1709385SAndreas.Sandberg@arm.com MVFR1 mvfr1 = 0; 1719385SAndreas.Sandberg@arm.com mvfr1.flushToZero = 1; 1729385SAndreas.Sandberg@arm.com mvfr1.defaultNaN = 1; 1739385SAndreas.Sandberg@arm.com mvfr1.advSimdLoadStore = 1; 1749385SAndreas.Sandberg@arm.com mvfr1.advSimdInteger = 1; 1758147SAli.Saidi@ARM.com mvfr1.advSimdSinglePrecision = 1; 1767427Sgblack@eecs.umich.edu mvfr1.advSimdHalfPrecision = 1; 1777427Sgblack@eecs.umich.edu mvfr1.vfpHalfPrecision = 1; 1787427Sgblack@eecs.umich.edu miscRegs[MISCREG_MVFR1] = mvfr1; 1797405SAli.Saidi@ARM.com 18010035Sandreas.hansson@arm.com // Reset values of PRRR and NMRR are implementation dependent 1817405SAli.Saidi@ARM.com 1827405SAli.Saidi@ARM.com // @todo: PRRR and NMRR in secure state? 1837614Sminkyu.jeong@arm.com miscRegs[MISCREG_PRRR_NS] = 1847614Sminkyu.jeong@arm.com (1 << 19) | // 19 1857614Sminkyu.jeong@arm.com (0 << 18) | // 18 1867614Sminkyu.jeong@arm.com (0 << 17) | // 17 1877614Sminkyu.jeong@arm.com (1 << 16) | // 16 1887614Sminkyu.jeong@arm.com (2 << 14) | // 15:14 1897614Sminkyu.jeong@arm.com (0 << 12) | // 13:12 1907614Sminkyu.jeong@arm.com (2 << 10) | // 11:10 1917614Sminkyu.jeong@arm.com (2 << 8) | // 9:8 1927614Sminkyu.jeong@arm.com (2 << 6) | // 7:6 1937614Sminkyu.jeong@arm.com (2 << 4) | // 5:4 1947405SAli.Saidi@ARM.com (1 << 2) | // 3:2 1957405SAli.Saidi@ARM.com 0; // 1:0 1967405SAli.Saidi@ARM.com miscRegs[MISCREG_NMRR_NS] = 1977405SAli.Saidi@ARM.com (1 << 30) | // 31:30 1987405SAli.Saidi@ARM.com (0 << 26) | // 27:26 1997405SAli.Saidi@ARM.com (0 << 24) | // 25:24 2009050Schander.sudanthi@arm.com (3 << 22) | // 23:22 2019050Schander.sudanthi@arm.com (2 << 20) | // 21:20 2027405SAli.Saidi@ARM.com (0 << 18) | // 19:18 2037405SAli.Saidi@ARM.com (0 << 16) | // 17:16 2047720Sgblack@eecs.umich.edu (1 << 14) | // 15:14 2057720Sgblack@eecs.umich.edu (0 << 12) | // 13:12 2067720Sgblack@eecs.umich.edu (2 << 10) | // 11:10 2077405SAli.Saidi@ARM.com (0 << 8) | // 9:8 2087405SAli.Saidi@ARM.com (3 << 6) | // 7:6 2097757SAli.Saidi@ARM.com (2 << 4) | // 5:4 2107405SAli.Saidi@ARM.com (0 << 2) | // 3:2 2117405SAli.Saidi@ARM.com 0; // 1:0 2127757SAli.Saidi@ARM.com 2137405SAli.Saidi@ARM.com miscRegs[MISCREG_CPACR] = 0; 2148284SAli.Saidi@ARM.com 2159050Schander.sudanthi@arm.com miscRegs[MISCREG_FPSID] = p->fpsid; 2169050Schander.sudanthi@arm.com 2178873SAli.Saidi@ARM.com if (haveLPAE) { 2189050Schander.sudanthi@arm.com TTBCR ttbcr = miscRegs[MISCREG_TTBCR_NS]; 2199050Schander.sudanthi@arm.com ttbcr.eae = 0; 2209050Schander.sudanthi@arm.com miscRegs[MISCREG_TTBCR_NS] = ttbcr; 2219050Schander.sudanthi@arm.com // Enforce consistency with system-level settings 2229050Schander.sudanthi@arm.com miscRegs[MISCREG_ID_MMFR0] = (miscRegs[MISCREG_ID_MMFR0] & ~0xf) | 0x5; 2239050Schander.sudanthi@arm.com } 2249050Schander.sudanthi@arm.com 2259050Schander.sudanthi@arm.com if (haveSecurity) { 2268284SAli.Saidi@ARM.com miscRegs[MISCREG_SCTLR_S] = sctlr; 2277405SAli.Saidi@ARM.com miscRegs[MISCREG_SCR] = 0; 2287731SAli.Saidi@ARM.com miscRegs[MISCREG_VBAR_S] = 0; 2298468Swade.walker@arm.com } else { 2308468Swade.walker@arm.com // we're always non-secure 2318468Swade.walker@arm.com miscRegs[MISCREG_SCR] = 1; 2327405SAli.Saidi@ARM.com } 2337731SAli.Saidi@ARM.com 2347405SAli.Saidi@ARM.com //XXX We need to initialize the rest of the state. 2357405SAli.Saidi@ARM.com} 2367583SAli.Saidi@arm.com 2379130Satgutier@umich.eduvoid 2389130Satgutier@umich.eduISA::clear64(const ArmISAParams *p) 2399130Satgutier@umich.edu{ 2409130Satgutier@umich.edu CPSR cpsr = 0; 2419814Sandreas.hansson@arm.com Addr rvbar = system->resetAddr64(); 2429130Satgutier@umich.edu switch (system->highestEL()) { 2439130Satgutier@umich.edu // Set initial EL to highest implemented EL using associated stack 2449130Satgutier@umich.edu // pointer (SP_ELx); set RVBAR_ELx to implementation defined reset 2459130Satgutier@umich.edu // value 2469130Satgutier@umich.edu case EL3: 2479130Satgutier@umich.edu cpsr.mode = MODE_EL3H; 2489130Satgutier@umich.edu miscRegs[MISCREG_RVBAR_EL3] = rvbar; 2499130Satgutier@umich.edu break; 2509130Satgutier@umich.edu case EL2: 2519130Satgutier@umich.edu cpsr.mode = MODE_EL2H; 2529130Satgutier@umich.edu miscRegs[MISCREG_RVBAR_EL2] = rvbar; 2539130Satgutier@umich.edu break; 2549130Satgutier@umich.edu case EL1: 2559130Satgutier@umich.edu cpsr.mode = MODE_EL1H; 2569130Satgutier@umich.edu miscRegs[MISCREG_RVBAR_EL1] = rvbar; 2579130Satgutier@umich.edu break; 2589130Satgutier@umich.edu default: 2599130Satgutier@umich.edu panic("Invalid highest implemented exception level"); 2609130Satgutier@umich.edu break; 2619130Satgutier@umich.edu } 2629130Satgutier@umich.edu 2639130Satgutier@umich.edu // Initialize rest of CPSR 2647583SAli.Saidi@arm.com cpsr.daif = 0xf; // Mask all interrupts 2657583SAli.Saidi@arm.com cpsr.ss = 0; 2667583SAli.Saidi@arm.com cpsr.il = 0; 2677583SAli.Saidi@arm.com miscRegs[MISCREG_CPSR] = cpsr; 2687583SAli.Saidi@arm.com updateRegMap(cpsr); 2697583SAli.Saidi@arm.com 2708299Schander.sudanthi@arm.com // Initialize other control registers 2717583SAli.Saidi@arm.com miscRegs[MISCREG_MPIDR_EL1] = 0x80000000; 2727583SAli.Saidi@arm.com if (haveSecurity) { 2738302SAli.Saidi@ARM.com miscRegs[MISCREG_SCTLR_EL3] = 0x30c50830; 2748302SAli.Saidi@ARM.com miscRegs[MISCREG_SCR_EL3] = 0x00000030; // RES1 fields 2757783SGiacomo.Gabrielli@arm.com } else if (haveVirtualization) { 2767783SGiacomo.Gabrielli@arm.com // also MISCREG_SCTLR_EL2 (by mapping) 2777783SGiacomo.Gabrielli@arm.com miscRegs[MISCREG_HSCTLR] = 0x30c50830; 2787783SGiacomo.Gabrielli@arm.com } else { 2798549Sdaniel.johnson@arm.com // also MISCREG_SCTLR_EL1 (by mapping) 2808868SMatt.Horsnell@arm.com miscRegs[MISCREG_SCTLR_NS] = 0x30d00800 | 0x00050030; // RES1 | init 2818868SMatt.Horsnell@arm.com // Always non-secure 2828868SMatt.Horsnell@arm.com miscRegs[MISCREG_SCR_EL3] = 1; 2838868SMatt.Horsnell@arm.com } 2848868SMatt.Horsnell@arm.com} 2858868SMatt.Horsnell@arm.com 2868868SMatt.Horsnell@arm.comvoid 2878868SMatt.Horsnell@arm.comISA::initID32(const ArmISAParams *p) 2888868SMatt.Horsnell@arm.com{ 2898868SMatt.Horsnell@arm.com // Initialize configurable default values 2908868SMatt.Horsnell@arm.com miscRegs[MISCREG_MIDR] = p->midr; 2919130Satgutier@umich.edu miscRegs[MISCREG_MIDR_EL1] = p->midr; 2928868SMatt.Horsnell@arm.com miscRegs[MISCREG_VPIDR] = p->midr; 2938868SMatt.Horsnell@arm.com 2947405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_ISAR0] = p->id_isar0; 2957405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_ISAR1] = p->id_isar1; 2967405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_ISAR2] = p->id_isar2; 2977405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_ISAR3] = p->id_isar3; 2987405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_ISAR4] = p->id_isar4; 2997405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_ISAR5] = p->id_isar5; 3007405SAli.Saidi@ARM.com 3017405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_MMFR0] = p->id_mmfr0; 3027614Sminkyu.jeong@arm.com miscRegs[MISCREG_ID_MMFR1] = p->id_mmfr1; 3037614Sminkyu.jeong@arm.com miscRegs[MISCREG_ID_MMFR2] = p->id_mmfr2; 3047614Sminkyu.jeong@arm.com miscRegs[MISCREG_ID_MMFR3] = p->id_mmfr3; 3057614Sminkyu.jeong@arm.com} 3067614Sminkyu.jeong@arm.com 3077614Sminkyu.jeong@arm.comvoid 3087614Sminkyu.jeong@arm.comISA::initID64(const ArmISAParams *p) 3097614Sminkyu.jeong@arm.com{ 3107614Sminkyu.jeong@arm.com // Initialize configurable id registers 3117614Sminkyu.jeong@arm.com miscRegs[MISCREG_ID_AA64AFR0_EL1] = p->id_aa64afr0_el1; 3127405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64AFR1_EL1] = p->id_aa64afr1_el1; 3137405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64DFR0_EL1] = 3147405SAli.Saidi@ARM.com (p->id_aa64dfr0_el1 & 0xfffffffffffff0ffULL) | 3157405SAli.Saidi@ARM.com (p->pmu ? 0x0000000000000100ULL : 0); // Enable PMUv3 3167405SAli.Saidi@ARM.com 3177749SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64DFR1_EL1] = p->id_aa64dfr1_el1; 3187405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64ISAR0_EL1] = p->id_aa64isar0_el1; 3198284SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64ISAR1_EL1] = p->id_aa64isar1_el1; 3208284SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64MMFR0_EL1] = p->id_aa64mmfr0_el1; 3218284SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64MMFR1_EL1] = p->id_aa64mmfr1_el1; 3228284SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64MMFR2_EL1] = p->id_aa64mmfr2_el1; 3237405SAli.Saidi@ARM.com 3247405SAli.Saidi@ARM.com miscRegs[MISCREG_ID_DFR0_EL1] = 3257749SAli.Saidi@ARM.com (p->pmu ? 0x03000000ULL : 0); // Enable PMUv3 3267749SAli.Saidi@ARM.com 3277749SAli.Saidi@ARM.com miscRegs[MISCREG_ID_DFR0] = miscRegs[MISCREG_ID_DFR0_EL1]; 3287749SAli.Saidi@ARM.com 3297405SAli.Saidi@ARM.com // Enforce consistency with system-level settings... 3307749SAli.Saidi@ARM.com 3317749SAli.Saidi@ARM.com // EL3 3327749SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 3337749SAli.Saidi@ARM.com miscRegs[MISCREG_ID_AA64PFR0_EL1], 15, 12, 3347749SAli.Saidi@ARM.com haveSecurity ? 0x2 : 0x0); 3357614Sminkyu.jeong@arm.com // EL2 3367614Sminkyu.jeong@arm.com miscRegs[MISCREG_ID_AA64PFR0_EL1] = insertBits( 3377720Sgblack@eecs.umich.edu miscRegs[MISCREG_ID_AA64PFR0_EL1], 11, 8, 3387720Sgblack@eecs.umich.edu haveVirtualization ? 0x2 : 0x0); 3397720Sgblack@eecs.umich.edu // Large ASID support 3408887Sgeoffrey.blake@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 3418887Sgeoffrey.blake@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1], 7, 4, 3428887Sgeoffrey.blake@arm.com haveLargeAsid64 ? 0x2 : 0x0); 3438887Sgeoffrey.blake@arm.com // Physical address size 3448887Sgeoffrey.blake@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1] = insertBits( 3458887Sgeoffrey.blake@arm.com miscRegs[MISCREG_ID_AA64MMFR0_EL1], 3, 0, 3468887Sgeoffrey.blake@arm.com encodePhysAddrRange64(physAddrRange)); 3478887Sgeoffrey.blake@arm.com} 3488887Sgeoffrey.blake@arm.com 3497408Sgblack@eecs.umich.eduvoid 3507405SAli.Saidi@ARM.comISA::startup(ThreadContext *tc) 3517405SAli.Saidi@ARM.com{ 3527405SAli.Saidi@ARM.com pmu->setThreadContext(tc); 3537408Sgblack@eecs.umich.edu 3547408Sgblack@eecs.umich.edu} 3557408Sgblack@eecs.umich.edu 3567408Sgblack@eecs.umich.edu 3578206SWilliam.Wang@arm.comMiscReg 3588206SWilliam.Wang@arm.comISA::readMiscRegNoEffect(int misc_reg) const 3598206SWilliam.Wang@arm.com{ 3608206SWilliam.Wang@arm.com assert(misc_reg < NumMiscRegs); 3618206SWilliam.Wang@arm.com 3628206SWilliam.Wang@arm.com const auto ® = lookUpMiscReg[misc_reg]; // bit masks 3638206SWilliam.Wang@arm.com const auto &map = getMiscIndices(misc_reg); 3648206SWilliam.Wang@arm.com int lower = map.first, upper = map.second; 3658206SWilliam.Wang@arm.com // NB!: apply architectural masks according to desired register, 3668206SWilliam.Wang@arm.com // despite possibly getting value from different (mapped) register. 3678206SWilliam.Wang@arm.com auto val = !upper ? miscRegs[lower] : ((miscRegs[lower] & mask(32)) 3687408Sgblack@eecs.umich.edu |(miscRegs[upper] << 32)); 3697408Sgblack@eecs.umich.edu if (val & reg.res0()) { 3707408Sgblack@eecs.umich.edu DPRINTF(MiscRegs, "Reading MiscReg %s with set res0 bits: %#x\n", 3717731SAli.Saidi@ARM.com miscRegName[misc_reg], val & reg.res0()); 3728206SWilliam.Wang@arm.com } 3737408Sgblack@eecs.umich.edu if ((val & reg.res1()) != reg.res1()) { 3747408Sgblack@eecs.umich.edu DPRINTF(MiscRegs, "Reading MiscReg %s with clear res1 bits: %#x\n", 3757408Sgblack@eecs.umich.edu miscRegName[misc_reg], (val & reg.res1()) ^ reg.res1()); 3767408Sgblack@eecs.umich.edu } 3777408Sgblack@eecs.umich.edu return (val & ~reg.raz()) | reg.rao(); // enforce raz/rao 3787408Sgblack@eecs.umich.edu} 3797408Sgblack@eecs.umich.edu 3807408Sgblack@eecs.umich.edu 3817408Sgblack@eecs.umich.eduMiscReg 3827408Sgblack@eecs.umich.eduISA::readMiscReg(int misc_reg, ThreadContext *tc) 3837408Sgblack@eecs.umich.edu{ 3847408Sgblack@eecs.umich.edu CPSR cpsr = 0; 3857408Sgblack@eecs.umich.edu PCState pc = 0; 3867408Sgblack@eecs.umich.edu SCR scr = 0; 3877408Sgblack@eecs.umich.edu 3887408Sgblack@eecs.umich.edu if (misc_reg == MISCREG_CPSR) { 3897408Sgblack@eecs.umich.edu cpsr = miscRegs[misc_reg]; 3907408Sgblack@eecs.umich.edu pc = tc->pcState(); 3917408Sgblack@eecs.umich.edu cpsr.j = pc.jazelle() ? 1 : 0; 3927408Sgblack@eecs.umich.edu cpsr.t = pc.thumb() ? 1 : 0; 3937408Sgblack@eecs.umich.edu return cpsr; 3947408Sgblack@eecs.umich.edu } 3957408Sgblack@eecs.umich.edu 3969377Sgblack@eecs.umich.edu#ifndef NDEBUG 3977408Sgblack@eecs.umich.edu if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 3987408Sgblack@eecs.umich.edu if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 3998302SAli.Saidi@ARM.com warn("Unimplemented system register %s read.\n", 4008302SAli.Saidi@ARM.com miscRegName[misc_reg]); 4018302SAli.Saidi@ARM.com else 4028302SAli.Saidi@ARM.com panic("Unimplemented system register %s read.\n", 4038302SAli.Saidi@ARM.com miscRegName[misc_reg]); 4048302SAli.Saidi@ARM.com } 4058302SAli.Saidi@ARM.com#endif 4067783SGiacomo.Gabrielli@arm.com 4077783SGiacomo.Gabrielli@arm.com switch (unflattenMiscReg(misc_reg)) { 4087783SGiacomo.Gabrielli@arm.com case MISCREG_HCR: 4097783SGiacomo.Gabrielli@arm.com { 4107783SGiacomo.Gabrielli@arm.com if (!haveVirtualization) 4117783SGiacomo.Gabrielli@arm.com return 0; 4127783SGiacomo.Gabrielli@arm.com else 4137783SGiacomo.Gabrielli@arm.com return readMiscRegNoEffect(MISCREG_HCR); 4147783SGiacomo.Gabrielli@arm.com } 4157783SGiacomo.Gabrielli@arm.com case MISCREG_CPACR: 4167783SGiacomo.Gabrielli@arm.com { 4177783SGiacomo.Gabrielli@arm.com const uint32_t ones = (uint32_t)(-1); 4187408Sgblack@eecs.umich.edu CPACR cpacrMask = 0; 4197408Sgblack@eecs.umich.edu // Only cp10, cp11, and ase are implemented, nothing else should 4208206SWilliam.Wang@arm.com // be readable? (straight copy from the write code) 4218206SWilliam.Wang@arm.com cpacrMask.cp10 = ones; 4227408Sgblack@eecs.umich.edu cpacrMask.cp11 = ones; 4237408Sgblack@eecs.umich.edu cpacrMask.asedis = ones; 4247408Sgblack@eecs.umich.edu 4257408Sgblack@eecs.umich.edu // Security Extensions may limit the readability of CPACR 4267408Sgblack@eecs.umich.edu if (haveSecurity) { 4277408Sgblack@eecs.umich.edu scr = readMiscRegNoEffect(MISCREG_SCR); 4287408Sgblack@eecs.umich.edu cpsr = readMiscRegNoEffect(MISCREG_CPSR); 4297408Sgblack@eecs.umich.edu if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) { 4307408Sgblack@eecs.umich.edu NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 4317408Sgblack@eecs.umich.edu // NB: Skipping the full loop, here 4327408Sgblack@eecs.umich.edu if (!nsacr.cp10) cpacrMask.cp10 = 0; 4337408Sgblack@eecs.umich.edu if (!nsacr.cp11) cpacrMask.cp11 = 0; 4347749SAli.Saidi@ARM.com } 4357749SAli.Saidi@ARM.com } 4368527SAli.Saidi@ARM.com MiscReg val = readMiscRegNoEffect(MISCREG_CPACR); 4378527SAli.Saidi@ARM.com val &= cpacrMask; 4388527SAli.Saidi@ARM.com DPRINTF(MiscRegs, "Reading misc reg %s: %#x\n", 4398527SAli.Saidi@ARM.com miscRegName[misc_reg], val); 4408527SAli.Saidi@ARM.com return val; 4418527SAli.Saidi@ARM.com } 4428527SAli.Saidi@ARM.com case MISCREG_MPIDR: 4438527SAli.Saidi@ARM.com cpsr = readMiscRegNoEffect(MISCREG_CPSR); 4448527SAli.Saidi@ARM.com scr = readMiscRegNoEffect(MISCREG_SCR); 4458527SAli.Saidi@ARM.com if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 4468527SAli.Saidi@ARM.com return getMPIDR(system, tc); 4478527SAli.Saidi@ARM.com } else { 4488527SAli.Saidi@ARM.com return readMiscReg(MISCREG_VMPIDR, tc); 4498527SAli.Saidi@ARM.com } 4508527SAli.Saidi@ARM.com break; 4518527SAli.Saidi@ARM.com case MISCREG_MPIDR_EL1: 4528887Sgeoffrey.blake@arm.com // @todo in the absence of v8 virtualization support just return MPIDR_EL1 4538887Sgeoffrey.blake@arm.com return getMPIDR(system, tc) & 0xffffffff; 4548887Sgeoffrey.blake@arm.com case MISCREG_VMPIDR: 4558733Sgeoffrey.blake@arm.com // top bit defined as RES1 4568733Sgeoffrey.blake@arm.com return readMiscRegNoEffect(misc_reg) | 0x80000000; 4578733Sgeoffrey.blake@arm.com case MISCREG_ID_AFR0: // not implemented, so alias MIDR 4588733Sgeoffrey.blake@arm.com case MISCREG_REVIDR: // not implemented, so alias MIDR 4598527SAli.Saidi@ARM.com case MISCREG_MIDR: 4607408Sgblack@eecs.umich.edu cpsr = readMiscRegNoEffect(MISCREG_CPSR); 4617408Sgblack@eecs.umich.edu scr = readMiscRegNoEffect(MISCREG_SCR); 4629385SAndreas.Sandberg@arm.com if ((cpsr.mode == MODE_HYP) || inSecureState(scr, cpsr)) { 4639385SAndreas.Sandberg@arm.com return readMiscRegNoEffect(misc_reg); 4649385SAndreas.Sandberg@arm.com } else { 4659385SAndreas.Sandberg@arm.com return readMiscRegNoEffect(MISCREG_VPIDR); 4669385SAndreas.Sandberg@arm.com } 4679385SAndreas.Sandberg@arm.com break; 4689385SAndreas.Sandberg@arm.com case MISCREG_JOSCR: // Jazelle trivial implementation, RAZ/WI 4699385SAndreas.Sandberg@arm.com case MISCREG_JMCR: // Jazelle trivial implementation, RAZ/WI 4709385SAndreas.Sandberg@arm.com case MISCREG_JIDR: // Jazelle trivial implementation, RAZ/WI 4719385SAndreas.Sandberg@arm.com case MISCREG_AIDR: // AUX ID set to 0 4729385SAndreas.Sandberg@arm.com case MISCREG_TCMTR: // No TCM's 4739385SAndreas.Sandberg@arm.com return 0; 4749385SAndreas.Sandberg@arm.com 4759385SAndreas.Sandberg@arm.com case MISCREG_CLIDR: 4769385SAndreas.Sandberg@arm.com warn_once("The clidr register always reports 0 caches.\n"); 4779385SAndreas.Sandberg@arm.com warn_once("clidr LoUIS field of 0b001 to match current " 4789385SAndreas.Sandberg@arm.com "ARM implementations.\n"); 4797408Sgblack@eecs.umich.edu return 0x00200000; 4807408Sgblack@eecs.umich.edu case MISCREG_CCSIDR: 4817408Sgblack@eecs.umich.edu warn_once("The ccsidr register isn't implemented and " 4829385SAndreas.Sandberg@arm.com "always reads as 0.\n"); 4837408Sgblack@eecs.umich.edu break; 4849385SAndreas.Sandberg@arm.com case MISCREG_CTR: // AArch32, ARMv7, top bit set 4857408Sgblack@eecs.umich.edu case MISCREG_CTR_EL0: // AArch64 4867408Sgblack@eecs.umich.edu { 4878284SAli.Saidi@ARM.com //all caches have the same line size in gem5 4888284SAli.Saidi@ARM.com //4 byte words in ARM 4898284SAli.Saidi@ARM.com unsigned lineSizeWords = 4908284SAli.Saidi@ARM.com tc->getSystemPtr()->cacheLineSize() / 4; 4918284SAli.Saidi@ARM.com unsigned log2LineSizeWords = 0; 4928284SAli.Saidi@ARM.com 4938887Sgeoffrey.blake@arm.com while (lineSizeWords >>= 1) { 4948887Sgeoffrey.blake@arm.com ++log2LineSizeWords; 4958887Sgeoffrey.blake@arm.com } 4968733Sgeoffrey.blake@arm.com 4978733Sgeoffrey.blake@arm.com CTR ctr = 0; 4988733Sgeoffrey.blake@arm.com //log2 of minimun i-cache line size (words) 4998733Sgeoffrey.blake@arm.com ctr.iCacheLineSize = log2LineSizeWords; 5008284SAli.Saidi@ARM.com //b11 - gem5 uses pipt 5017408Sgblack@eecs.umich.edu ctr.l1IndexPolicy = 0x3; 5027408Sgblack@eecs.umich.edu //log2 of minimum d-cache line size (words) 5037408Sgblack@eecs.umich.edu ctr.dCacheLineSize = log2LineSizeWords; 5047408Sgblack@eecs.umich.edu //log2 of max reservation size (words) 5057408Sgblack@eecs.umich.edu ctr.erg = log2LineSizeWords; 5067408Sgblack@eecs.umich.edu //log2 of max writeback size (words) 5077408Sgblack@eecs.umich.edu ctr.cwg = log2LineSizeWords; 5087408Sgblack@eecs.umich.edu //b100 - gem5 format is ARMv7 5097408Sgblack@eecs.umich.edu ctr.format = 0x4; 5108284SAli.Saidi@ARM.com 5118284SAli.Saidi@ARM.com return ctr; 5128284SAli.Saidi@ARM.com } 5138284SAli.Saidi@ARM.com case MISCREG_ACTLR: 5148284SAli.Saidi@ARM.com warn("Not doing anything for miscreg ACTLR\n"); 5158284SAli.Saidi@ARM.com break; 5168284SAli.Saidi@ARM.com 5178284SAli.Saidi@ARM.com case MISCREG_PMXEVTYPER_PMCCFILTR: 5188887Sgeoffrey.blake@arm.com case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 5198887Sgeoffrey.blake@arm.com case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 5208733Sgeoffrey.blake@arm.com case MISCREG_PMCR ... MISCREG_PMOVSSET: 5218733Sgeoffrey.blake@arm.com return pmu->readMiscReg(misc_reg); 5228733Sgeoffrey.blake@arm.com 5238733Sgeoffrey.blake@arm.com case MISCREG_CPSR_Q: 5248733Sgeoffrey.blake@arm.com panic("shouldn't be reading this register seperately\n"); 5258733Sgeoffrey.blake@arm.com case MISCREG_FPSCR_QC: 5268284SAli.Saidi@ARM.com return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrQcMask; 5277408Sgblack@eecs.umich.edu case MISCREG_FPSCR_EXC: 5287408Sgblack@eecs.umich.edu return readMiscRegNoEffect(MISCREG_FPSCR) & ~FpscrExcMask; 5297408Sgblack@eecs.umich.edu case MISCREG_FPSR: 5308284SAli.Saidi@ARM.com { 5318284SAli.Saidi@ARM.com const uint32_t ones = (uint32_t)(-1); 5328284SAli.Saidi@ARM.com FPSCR fpscrMask = 0; 5338284SAli.Saidi@ARM.com fpscrMask.ioc = ones; 5348284SAli.Saidi@ARM.com fpscrMask.dzc = ones; 5358284SAli.Saidi@ARM.com fpscrMask.ofc = ones; 5368887Sgeoffrey.blake@arm.com fpscrMask.ufc = ones; 5378733Sgeoffrey.blake@arm.com fpscrMask.ixc = ones; 5388733Sgeoffrey.blake@arm.com fpscrMask.idc = ones; 5398733Sgeoffrey.blake@arm.com fpscrMask.qc = ones; 5408733Sgeoffrey.blake@arm.com fpscrMask.v = ones; 5418284SAli.Saidi@ARM.com fpscrMask.c = ones; 5427408Sgblack@eecs.umich.edu fpscrMask.z = ones; 5437408Sgblack@eecs.umich.edu fpscrMask.n = ones; 5447408Sgblack@eecs.umich.edu return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 5458284SAli.Saidi@ARM.com } 5468284SAli.Saidi@ARM.com case MISCREG_FPCR: 5478284SAli.Saidi@ARM.com { 5488284SAli.Saidi@ARM.com const uint32_t ones = (uint32_t)(-1); 5498284SAli.Saidi@ARM.com FPSCR fpscrMask = 0; 5508284SAli.Saidi@ARM.com fpscrMask.len = ones; 5518887Sgeoffrey.blake@arm.com fpscrMask.stride = ones; 5528887Sgeoffrey.blake@arm.com fpscrMask.rMode = ones; 5538733Sgeoffrey.blake@arm.com fpscrMask.fz = ones; 5548733Sgeoffrey.blake@arm.com fpscrMask.dn = ones; 5558733Sgeoffrey.blake@arm.com fpscrMask.ahp = ones; 5568733Sgeoffrey.blake@arm.com return readMiscRegNoEffect(MISCREG_FPSCR) & (uint32_t)fpscrMask; 5578284SAli.Saidi@ARM.com } 5587408Sgblack@eecs.umich.edu case MISCREG_NZCV: 5597408Sgblack@eecs.umich.edu { 5607408Sgblack@eecs.umich.edu CPSR cpsr = 0; 5617408Sgblack@eecs.umich.edu cpsr.nz = tc->readCCReg(CCREG_NZ); 5627408Sgblack@eecs.umich.edu cpsr.c = tc->readCCReg(CCREG_C); 5637408Sgblack@eecs.umich.edu cpsr.v = tc->readCCReg(CCREG_V); 5647408Sgblack@eecs.umich.edu return cpsr; 5657408Sgblack@eecs.umich.edu } 5667408Sgblack@eecs.umich.edu case MISCREG_DAIF: 5677408Sgblack@eecs.umich.edu { 5687408Sgblack@eecs.umich.edu CPSR cpsr = 0; 5697408Sgblack@eecs.umich.edu cpsr.daif = (uint8_t) ((CPSR) miscRegs[MISCREG_CPSR]).daif; 5707408Sgblack@eecs.umich.edu return cpsr; 5717408Sgblack@eecs.umich.edu } 5727405SAli.Saidi@ARM.com case MISCREG_SP_EL0: 5737583SAli.Saidi@arm.com { 5747583SAli.Saidi@arm.com return tc->readIntReg(INTREG_SP0); 5757583SAli.Saidi@arm.com } 5767583SAli.Saidi@arm.com case MISCREG_SP_EL1: 5778059SAli.Saidi@ARM.com { 5788059SAli.Saidi@ARM.com return tc->readIntReg(INTREG_SP1); 5798059SAli.Saidi@ARM.com } 5808059SAli.Saidi@ARM.com case MISCREG_SP_EL2: 5818059SAli.Saidi@ARM.com { 5828059SAli.Saidi@ARM.com return tc->readIntReg(INTREG_SP2); 5838059SAli.Saidi@ARM.com } 5848059SAli.Saidi@ARM.com case MISCREG_SPSEL: 5858059SAli.Saidi@ARM.com { 5868059SAli.Saidi@ARM.com return miscRegs[MISCREG_CPSR] & 0x1; 5878059SAli.Saidi@ARM.com } 5888059SAli.Saidi@ARM.com case MISCREG_CURRENTEL: 5897583SAli.Saidi@arm.com { 5907583SAli.Saidi@arm.com return miscRegs[MISCREG_CPSR] & 0xc; 5917583SAli.Saidi@arm.com } 5927583SAli.Saidi@arm.com case MISCREG_L2CTLR: 5937583SAli.Saidi@arm.com { 5947436Sdam.sunwoo@arm.com // mostly unimplemented, just set NumCPUs field from sim and return 5957436Sdam.sunwoo@arm.com L2CTLR l2ctlr = 0; 5967436Sdam.sunwoo@arm.com // b00:1CPU to b11:4CPUs 5977436Sdam.sunwoo@arm.com l2ctlr.numCPUs = tc->getSystemPtr()->numContexts() - 1; 5987436Sdam.sunwoo@arm.com return l2ctlr; 5997436Sdam.sunwoo@arm.com } 6007436Sdam.sunwoo@arm.com case MISCREG_DBGDIDR: 6017436Sdam.sunwoo@arm.com /* For now just implement the version number. 6027436Sdam.sunwoo@arm.com * ARMv7, v7.1 Debug architecture (0b0101 --> 0x5) 6037436Sdam.sunwoo@arm.com */ 6047436Sdam.sunwoo@arm.com return 0x5 << 16; 6057436Sdam.sunwoo@arm.com case MISCREG_DBGDSCRint: 6067436Sdam.sunwoo@arm.com return 0; 6077436Sdam.sunwoo@arm.com case MISCREG_ISR: 6087436Sdam.sunwoo@arm.com return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 6097436Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_HCR), 6107436Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_CPSR), 6117436Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_SCR)); 6127436Sdam.sunwoo@arm.com case MISCREG_ISR_EL1: 6137436Sdam.sunwoo@arm.com return tc->getCpuPtr()->getInterruptController(tc->threadId())->getISR( 6147436Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_HCR_EL2), 6157436Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_CPSR), 6167436Sdam.sunwoo@arm.com readMiscRegNoEffect(MISCREG_SCR_EL3)); 6177436Sdam.sunwoo@arm.com case MISCREG_DCZID_EL0: 6187436Sdam.sunwoo@arm.com return 0x04; // DC ZVA clear 64-byte chunks 6197436Sdam.sunwoo@arm.com case MISCREG_HCPTR: 6207436Sdam.sunwoo@arm.com { 6217436Sdam.sunwoo@arm.com MiscReg val = readMiscRegNoEffect(misc_reg); 6227436Sdam.sunwoo@arm.com // The trap bit associated with CP14 is defined as RAZ 6237436Sdam.sunwoo@arm.com val &= ~(1 << 14); 6247442Ssaidi@eecs.umich.edu // If a CP bit in NSACR is 0 then the corresponding bit in 6257436Sdam.sunwoo@arm.com // HCPTR is RAO/WI 6267436Sdam.sunwoo@arm.com bool secure_lookup = haveSecurity && 6278208SAli.Saidi@ARM.com inSecureState(readMiscRegNoEffect(MISCREG_SCR), 6288832SAli.Saidi@ARM.com readMiscRegNoEffect(MISCREG_CPSR)); 6298832SAli.Saidi@ARM.com if (!secure_lookup) { 6307436Sdam.sunwoo@arm.com MiscReg mask = readMiscRegNoEffect(MISCREG_NSACR); 6317436Sdam.sunwoo@arm.com val |= (mask ^ 0x7FFF) & 0xBFFF; 6327436Sdam.sunwoo@arm.com } 6337436Sdam.sunwoo@arm.com // Set the bits for unimplemented coprocessors to RAO/WI 6347436Sdam.sunwoo@arm.com val |= 0x33FF; 6357436Sdam.sunwoo@arm.com return (val); 6367436Sdam.sunwoo@arm.com } 6377436Sdam.sunwoo@arm.com case MISCREG_HDFAR: // alias for secure DFAR 6387436Sdam.sunwoo@arm.com return readMiscRegNoEffect(MISCREG_DFAR_S); 6397436Sdam.sunwoo@arm.com case MISCREG_HIFAR: // alias for secure IFAR 6407436Sdam.sunwoo@arm.com return readMiscRegNoEffect(MISCREG_IFAR_S); 6417436Sdam.sunwoo@arm.com case MISCREG_HVBAR: // bottom bits reserved 6427436Sdam.sunwoo@arm.com return readMiscRegNoEffect(MISCREG_HVBAR) & 0xFFFFFFE0; 6437436Sdam.sunwoo@arm.com case MISCREG_SCTLR: 6447436Sdam.sunwoo@arm.com return (readMiscRegNoEffect(misc_reg) & 0x72DD39FF) | 0x00C00818; 6457436Sdam.sunwoo@arm.com case MISCREG_SCTLR_EL1: 6467436Sdam.sunwoo@arm.com return (readMiscRegNoEffect(misc_reg) & 0x37DDDBBF) | 0x30D00800; 6477436Sdam.sunwoo@arm.com case MISCREG_SCTLR_EL2: 6487436Sdam.sunwoo@arm.com case MISCREG_SCTLR_EL3: 6497436Sdam.sunwoo@arm.com case MISCREG_HSCTLR: 6507749SAli.Saidi@ARM.com return (readMiscRegNoEffect(misc_reg) & 0x32CD183F) | 0x30C50830; 6517749SAli.Saidi@ARM.com 6527749SAli.Saidi@ARM.com case MISCREG_ID_PFR0: 6537749SAli.Saidi@ARM.com // !ThumbEE | !Jazelle | Thumb | ARM 6547749SAli.Saidi@ARM.com return 0x00000031; 6557749SAli.Saidi@ARM.com case MISCREG_ID_PFR1: 6567749SAli.Saidi@ARM.com { // Timer | Virti | !M Profile | TrustZone | ARMv4 6578549Sdaniel.johnson@arm.com bool haveTimer = (system->getGenericTimer() != NULL); 6588549Sdaniel.johnson@arm.com return 0x00000001 6598549Sdaniel.johnson@arm.com | (haveSecurity ? 0x00000010 : 0x0) 6607405SAli.Saidi@ARM.com | (haveVirtualization ? 0x00001000 : 0x0) 6617405SAli.Saidi@ARM.com | (haveTimer ? 0x00010000 : 0x0); 6627405SAli.Saidi@ARM.com } 6637405SAli.Saidi@ARM.com case MISCREG_ID_AA64PFR0_EL1: 6647405SAli.Saidi@ARM.com return 0x0000000000000002 // AArch{64,32} supported at EL0 6657405SAli.Saidi@ARM.com | 0x0000000000000020 // EL1 6669384SAndreas.Sandberg@arm.com | (haveVirtualization ? 0x0000000000000200 : 0) // EL2 6679384SAndreas.Sandberg@arm.com | (haveSecurity ? 0x0000000000002000 : 0); // EL3 6689384SAndreas.Sandberg@arm.com case MISCREG_ID_AA64PFR1_EL1: 6699384SAndreas.Sandberg@arm.com return 0; // bits [63:0] RES0 (reserved for future use) 6709384SAndreas.Sandberg@arm.com 6719384SAndreas.Sandberg@arm.com // Generic Timer registers 672 case MISCREG_CNTHV_CTL_EL2: 673 case MISCREG_CNTHV_CVAL_EL2: 674 case MISCREG_CNTHV_TVAL_EL2: 675 case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 676 case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 677 case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 678 case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 679 return getGenericTimer(tc).readMiscReg(misc_reg); 680 681 default: 682 break; 683 684 } 685 return readMiscRegNoEffect(misc_reg); 686} 687 688void 689ISA::setMiscRegNoEffect(int misc_reg, const MiscReg &val) 690{ 691 assert(misc_reg < NumMiscRegs); 692 693 const auto ® = lookUpMiscReg[misc_reg]; // bit masks 694 const auto &map = getMiscIndices(misc_reg); 695 int lower = map.first, upper = map.second; 696 697 auto v = (val & ~reg.wi()) | reg.rao(); 698 if (upper > 0) { 699 miscRegs[lower] = bits(v, 31, 0); 700 miscRegs[upper] = bits(v, 63, 32); 701 DPRINTF(MiscRegs, "Writing to misc reg %d (%d:%d) : %#x\n", 702 misc_reg, lower, upper, v); 703 } else { 704 miscRegs[lower] = v; 705 DPRINTF(MiscRegs, "Writing to misc reg %d (%d) : %#x\n", 706 misc_reg, lower, v); 707 } 708} 709 710void 711ISA::setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc) 712{ 713 714 MiscReg newVal = val; 715 bool secure_lookup; 716 SCR scr; 717 718 if (misc_reg == MISCREG_CPSR) { 719 updateRegMap(val); 720 721 722 CPSR old_cpsr = miscRegs[MISCREG_CPSR]; 723 int old_mode = old_cpsr.mode; 724 CPSR cpsr = val; 725 if (old_mode != cpsr.mode || cpsr.il != old_cpsr.il) { 726 getITBPtr(tc)->invalidateMiscReg(); 727 getDTBPtr(tc)->invalidateMiscReg(); 728 } 729 730 DPRINTF(Arm, "Updating CPSR from %#x to %#x f:%d i:%d a:%d mode:%#x\n", 731 miscRegs[misc_reg], cpsr, cpsr.f, cpsr.i, cpsr.a, cpsr.mode); 732 PCState pc = tc->pcState(); 733 pc.nextThumb(cpsr.t); 734 pc.nextJazelle(cpsr.j); 735 pc.illegalExec(cpsr.il == 1); 736 737 // Follow slightly different semantics if a CheckerCPU object 738 // is connected 739 CheckerCPU *checker = tc->getCheckerCpuPtr(); 740 if (checker) { 741 tc->pcStateNoRecord(pc); 742 } else { 743 tc->pcState(pc); 744 } 745 } else { 746#ifndef NDEBUG 747 if (!miscRegInfo[misc_reg][MISCREG_IMPLEMENTED]) { 748 if (miscRegInfo[misc_reg][MISCREG_WARN_NOT_FAIL]) 749 warn("Unimplemented system register %s write with %#x.\n", 750 miscRegName[misc_reg], val); 751 else 752 panic("Unimplemented system register %s write with %#x.\n", 753 miscRegName[misc_reg], val); 754 } 755#endif 756 switch (unflattenMiscReg(misc_reg)) { 757 case MISCREG_CPACR: 758 { 759 760 const uint32_t ones = (uint32_t)(-1); 761 CPACR cpacrMask = 0; 762 // Only cp10, cp11, and ase are implemented, nothing else should 763 // be writable 764 cpacrMask.cp10 = ones; 765 cpacrMask.cp11 = ones; 766 cpacrMask.asedis = ones; 767 768 // Security Extensions may limit the writability of CPACR 769 if (haveSecurity) { 770 scr = readMiscRegNoEffect(MISCREG_SCR); 771 CPSR cpsr = readMiscRegNoEffect(MISCREG_CPSR); 772 if (scr.ns && (cpsr.mode != MODE_MON) && ELIs32(tc, EL3)) { 773 NSACR nsacr = readMiscRegNoEffect(MISCREG_NSACR); 774 // NB: Skipping the full loop, here 775 if (!nsacr.cp10) cpacrMask.cp10 = 0; 776 if (!nsacr.cp11) cpacrMask.cp11 = 0; 777 } 778 } 779 780 MiscReg old_val = readMiscRegNoEffect(MISCREG_CPACR); 781 newVal &= cpacrMask; 782 newVal |= old_val & ~cpacrMask; 783 DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 784 miscRegName[misc_reg], newVal); 785 } 786 break; 787 case MISCREG_CPTR_EL2: 788 { 789 const uint32_t ones = (uint32_t)(-1); 790 CPTR cptrMask = 0; 791 cptrMask.tcpac = ones; 792 cptrMask.tta = ones; 793 cptrMask.tfp = ones; 794 newVal &= cptrMask; 795 cptrMask = 0; 796 cptrMask.res1_13_12_el2 = ones; 797 cptrMask.res1_9_0_el2 = ones; 798 newVal |= cptrMask; 799 DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 800 miscRegName[misc_reg], newVal); 801 } 802 break; 803 case MISCREG_CPTR_EL3: 804 { 805 const uint32_t ones = (uint32_t)(-1); 806 CPTR cptrMask = 0; 807 cptrMask.tcpac = ones; 808 cptrMask.tta = ones; 809 cptrMask.tfp = ones; 810 newVal &= cptrMask; 811 DPRINTF(MiscRegs, "Writing misc reg %s: %#x\n", 812 miscRegName[misc_reg], newVal); 813 } 814 break; 815 case MISCREG_CSSELR: 816 warn_once("The csselr register isn't implemented.\n"); 817 return; 818 819 case MISCREG_DC_ZVA_Xt: 820 warn("Calling DC ZVA! Not Implemeted! Expect WEIRD results\n"); 821 return; 822 823 case MISCREG_FPSCR: 824 { 825 const uint32_t ones = (uint32_t)(-1); 826 FPSCR fpscrMask = 0; 827 fpscrMask.ioc = ones; 828 fpscrMask.dzc = ones; 829 fpscrMask.ofc = ones; 830 fpscrMask.ufc = ones; 831 fpscrMask.ixc = ones; 832 fpscrMask.idc = ones; 833 fpscrMask.ioe = ones; 834 fpscrMask.dze = ones; 835 fpscrMask.ofe = ones; 836 fpscrMask.ufe = ones; 837 fpscrMask.ixe = ones; 838 fpscrMask.ide = ones; 839 fpscrMask.len = ones; 840 fpscrMask.stride = ones; 841 fpscrMask.rMode = ones; 842 fpscrMask.fz = ones; 843 fpscrMask.dn = ones; 844 fpscrMask.ahp = ones; 845 fpscrMask.qc = ones; 846 fpscrMask.v = ones; 847 fpscrMask.c = ones; 848 fpscrMask.z = ones; 849 fpscrMask.n = ones; 850 newVal = (newVal & (uint32_t)fpscrMask) | 851 (readMiscRegNoEffect(MISCREG_FPSCR) & 852 ~(uint32_t)fpscrMask); 853 tc->getDecoderPtr()->setContext(newVal); 854 } 855 break; 856 case MISCREG_FPSR: 857 { 858 const uint32_t ones = (uint32_t)(-1); 859 FPSCR fpscrMask = 0; 860 fpscrMask.ioc = ones; 861 fpscrMask.dzc = ones; 862 fpscrMask.ofc = ones; 863 fpscrMask.ufc = ones; 864 fpscrMask.ixc = ones; 865 fpscrMask.idc = ones; 866 fpscrMask.qc = ones; 867 fpscrMask.v = ones; 868 fpscrMask.c = ones; 869 fpscrMask.z = ones; 870 fpscrMask.n = ones; 871 newVal = (newVal & (uint32_t)fpscrMask) | 872 (readMiscRegNoEffect(MISCREG_FPSCR) & 873 ~(uint32_t)fpscrMask); 874 misc_reg = MISCREG_FPSCR; 875 } 876 break; 877 case MISCREG_FPCR: 878 { 879 const uint32_t ones = (uint32_t)(-1); 880 FPSCR fpscrMask = 0; 881 fpscrMask.len = ones; 882 fpscrMask.stride = ones; 883 fpscrMask.rMode = ones; 884 fpscrMask.fz = ones; 885 fpscrMask.dn = ones; 886 fpscrMask.ahp = ones; 887 newVal = (newVal & (uint32_t)fpscrMask) | 888 (readMiscRegNoEffect(MISCREG_FPSCR) & 889 ~(uint32_t)fpscrMask); 890 misc_reg = MISCREG_FPSCR; 891 } 892 break; 893 case MISCREG_CPSR_Q: 894 { 895 assert(!(newVal & ~CpsrMaskQ)); 896 newVal = readMiscRegNoEffect(MISCREG_CPSR) | newVal; 897 misc_reg = MISCREG_CPSR; 898 } 899 break; 900 case MISCREG_FPSCR_QC: 901 { 902 newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 903 (newVal & FpscrQcMask); 904 misc_reg = MISCREG_FPSCR; 905 } 906 break; 907 case MISCREG_FPSCR_EXC: 908 { 909 newVal = readMiscRegNoEffect(MISCREG_FPSCR) | 910 (newVal & FpscrExcMask); 911 misc_reg = MISCREG_FPSCR; 912 } 913 break; 914 case MISCREG_FPEXC: 915 { 916 // vfpv3 architecture, section B.6.1 of DDI04068 917 // bit 29 - valid only if fpexc[31] is 0 918 const uint32_t fpexcMask = 0x60000000; 919 newVal = (newVal & fpexcMask) | 920 (readMiscRegNoEffect(MISCREG_FPEXC) & ~fpexcMask); 921 } 922 break; 923 case MISCREG_HCR: 924 { 925 if (!haveVirtualization) 926 return; 927 } 928 break; 929 case MISCREG_IFSR: 930 { 931 // ARM ARM (ARM DDI 0406C.b) B4.1.96 932 const uint32_t ifsrMask = 933 mask(31, 13) | mask(11, 11) | mask(8, 6); 934 newVal = newVal & ~ifsrMask; 935 } 936 break; 937 case MISCREG_DFSR: 938 { 939 // ARM ARM (ARM DDI 0406C.b) B4.1.52 940 const uint32_t dfsrMask = mask(31, 14) | mask(8, 8); 941 newVal = newVal & ~dfsrMask; 942 } 943 break; 944 case MISCREG_AMAIR0: 945 case MISCREG_AMAIR1: 946 { 947 // ARM ARM (ARM DDI 0406C.b) B4.1.5 948 // Valid only with LPAE 949 if (!haveLPAE) 950 return; 951 DPRINTF(MiscRegs, "Writing AMAIR: %#x\n", newVal); 952 } 953 break; 954 case MISCREG_SCR: 955 getITBPtr(tc)->invalidateMiscReg(); 956 getDTBPtr(tc)->invalidateMiscReg(); 957 break; 958 case MISCREG_SCTLR: 959 { 960 DPRINTF(MiscRegs, "Writing SCTLR: %#x\n", newVal); 961 scr = readMiscRegNoEffect(MISCREG_SCR); 962 963 MiscRegIndex sctlr_idx; 964 if (haveSecurity && !highestELIs64 && !scr.ns) { 965 sctlr_idx = MISCREG_SCTLR_S; 966 } else { 967 sctlr_idx = MISCREG_SCTLR_NS; 968 } 969 970 SCTLR sctlr = miscRegs[sctlr_idx]; 971 SCTLR new_sctlr = newVal; 972 new_sctlr.nmfi = ((bool)sctlr.nmfi) && !haveVirtualization; 973 miscRegs[sctlr_idx] = (MiscReg)new_sctlr; 974 getITBPtr(tc)->invalidateMiscReg(); 975 getDTBPtr(tc)->invalidateMiscReg(); 976 } 977 case MISCREG_MIDR: 978 case MISCREG_ID_PFR0: 979 case MISCREG_ID_PFR1: 980 case MISCREG_ID_DFR0: 981 case MISCREG_ID_MMFR0: 982 case MISCREG_ID_MMFR1: 983 case MISCREG_ID_MMFR2: 984 case MISCREG_ID_MMFR3: 985 case MISCREG_ID_ISAR0: 986 case MISCREG_ID_ISAR1: 987 case MISCREG_ID_ISAR2: 988 case MISCREG_ID_ISAR3: 989 case MISCREG_ID_ISAR4: 990 case MISCREG_ID_ISAR5: 991 992 case MISCREG_MPIDR: 993 case MISCREG_FPSID: 994 case MISCREG_TLBTR: 995 case MISCREG_MVFR0: 996 case MISCREG_MVFR1: 997 998 case MISCREG_ID_AA64AFR0_EL1: 999 case MISCREG_ID_AA64AFR1_EL1: 1000 case MISCREG_ID_AA64DFR0_EL1: 1001 case MISCREG_ID_AA64DFR1_EL1: 1002 case MISCREG_ID_AA64ISAR0_EL1: 1003 case MISCREG_ID_AA64ISAR1_EL1: 1004 case MISCREG_ID_AA64MMFR0_EL1: 1005 case MISCREG_ID_AA64MMFR1_EL1: 1006 case MISCREG_ID_AA64MMFR2_EL1: 1007 case MISCREG_ID_AA64PFR0_EL1: 1008 case MISCREG_ID_AA64PFR1_EL1: 1009 // ID registers are constants. 1010 return; 1011 1012 // TLB Invalidate All 1013 case MISCREG_TLBIALL: // TLBI all entries, EL0&1, 1014 { 1015 assert32(tc); 1016 scr = readMiscReg(MISCREG_SCR, tc); 1017 1018 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1019 tlbiOp(tc); 1020 return; 1021 } 1022 // TLB Invalidate All, Inner Shareable 1023 case MISCREG_TLBIALLIS: 1024 { 1025 assert32(tc); 1026 scr = readMiscReg(MISCREG_SCR, tc); 1027 1028 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1029 tlbiOp.broadcast(tc); 1030 return; 1031 } 1032 // Instruction TLB Invalidate All 1033 case MISCREG_ITLBIALL: 1034 { 1035 assert32(tc); 1036 scr = readMiscReg(MISCREG_SCR, tc); 1037 1038 ITLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1039 tlbiOp(tc); 1040 return; 1041 } 1042 // Data TLB Invalidate All 1043 case MISCREG_DTLBIALL: 1044 { 1045 assert32(tc); 1046 scr = readMiscReg(MISCREG_SCR, tc); 1047 1048 DTLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1049 tlbiOp(tc); 1050 return; 1051 } 1052 // TLB Invalidate by VA 1053 // mcr tlbimval(is) is invalidating all matching entries 1054 // regardless of the level of lookup, since in gem5 we cache 1055 // in the tlb the last level of lookup only. 1056 case MISCREG_TLBIMVA: 1057 case MISCREG_TLBIMVAL: 1058 { 1059 assert32(tc); 1060 scr = readMiscReg(MISCREG_SCR, tc); 1061 1062 TLBIMVA tlbiOp(EL1, 1063 haveSecurity && !scr.ns, 1064 mbits(newVal, 31, 12), 1065 bits(newVal, 7,0)); 1066 1067 tlbiOp(tc); 1068 return; 1069 } 1070 // TLB Invalidate by VA, Inner Shareable 1071 case MISCREG_TLBIMVAIS: 1072 case MISCREG_TLBIMVALIS: 1073 { 1074 assert32(tc); 1075 scr = readMiscReg(MISCREG_SCR, tc); 1076 1077 TLBIMVA tlbiOp(EL1, 1078 haveSecurity && !scr.ns, 1079 mbits(newVal, 31, 12), 1080 bits(newVal, 7,0)); 1081 1082 tlbiOp.broadcast(tc); 1083 return; 1084 } 1085 // TLB Invalidate by ASID match 1086 case MISCREG_TLBIASID: 1087 { 1088 assert32(tc); 1089 scr = readMiscReg(MISCREG_SCR, tc); 1090 1091 TLBIASID tlbiOp(EL1, 1092 haveSecurity && !scr.ns, 1093 bits(newVal, 7,0)); 1094 1095 tlbiOp(tc); 1096 return; 1097 } 1098 // TLB Invalidate by ASID match, Inner Shareable 1099 case MISCREG_TLBIASIDIS: 1100 { 1101 assert32(tc); 1102 scr = readMiscReg(MISCREG_SCR, tc); 1103 1104 TLBIASID tlbiOp(EL1, 1105 haveSecurity && !scr.ns, 1106 bits(newVal, 7,0)); 1107 1108 tlbiOp.broadcast(tc); 1109 return; 1110 } 1111 // mcr tlbimvaal(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, All ASID 1115 case MISCREG_TLBIMVAA: 1116 case MISCREG_TLBIMVAAL: 1117 { 1118 assert32(tc); 1119 scr = readMiscReg(MISCREG_SCR, tc); 1120 1121 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1122 mbits(newVal, 31,12), false); 1123 1124 tlbiOp(tc); 1125 return; 1126 } 1127 // TLB Invalidate by VA, All ASID, Inner Shareable 1128 case MISCREG_TLBIMVAAIS: 1129 case MISCREG_TLBIMVAALIS: 1130 { 1131 assert32(tc); 1132 scr = readMiscReg(MISCREG_SCR, tc); 1133 1134 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1135 mbits(newVal, 31,12), false); 1136 1137 tlbiOp.broadcast(tc); 1138 return; 1139 } 1140 // mcr tlbimvalh(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 VA, Hyp mode 1144 case MISCREG_TLBIMVAH: 1145 case MISCREG_TLBIMVALH: 1146 { 1147 assert32(tc); 1148 scr = readMiscReg(MISCREG_SCR, tc); 1149 1150 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1151 mbits(newVal, 31,12), true); 1152 1153 tlbiOp(tc); 1154 return; 1155 } 1156 // TLB Invalidate by VA, Hyp mode, Inner Shareable 1157 case MISCREG_TLBIMVAHIS: 1158 case MISCREG_TLBIMVALHIS: 1159 { 1160 assert32(tc); 1161 scr = readMiscReg(MISCREG_SCR, tc); 1162 1163 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1164 mbits(newVal, 31,12), true); 1165 1166 tlbiOp.broadcast(tc); 1167 return; 1168 } 1169 // mcr tlbiipas2l(is) is invalidating all matching entries 1170 // regardless of the level of lookup, since in gem5 we cache 1171 // in the tlb the last level of lookup only. 1172 // TLB Invalidate by Intermediate Physical Address, Stage 2 1173 case MISCREG_TLBIIPAS2: 1174 case MISCREG_TLBIIPAS2L: 1175 { 1176 assert32(tc); 1177 scr = readMiscReg(MISCREG_SCR, tc); 1178 1179 TLBIIPA tlbiOp(EL1, 1180 haveSecurity && !scr.ns, 1181 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1182 1183 tlbiOp(tc); 1184 return; 1185 } 1186 // TLB Invalidate by Intermediate Physical Address, Stage 2, 1187 // Inner Shareable 1188 case MISCREG_TLBIIPAS2IS: 1189 case MISCREG_TLBIIPAS2LIS: 1190 { 1191 assert32(tc); 1192 scr = readMiscReg(MISCREG_SCR, tc); 1193 1194 TLBIIPA tlbiOp(EL1, 1195 haveSecurity && !scr.ns, 1196 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1197 1198 tlbiOp.broadcast(tc); 1199 return; 1200 } 1201 // Instruction TLB Invalidate by VA 1202 case MISCREG_ITLBIMVA: 1203 { 1204 assert32(tc); 1205 scr = readMiscReg(MISCREG_SCR, tc); 1206 1207 ITLBIMVA tlbiOp(EL1, 1208 haveSecurity && !scr.ns, 1209 mbits(newVal, 31, 12), 1210 bits(newVal, 7,0)); 1211 1212 tlbiOp(tc); 1213 return; 1214 } 1215 // Data TLB Invalidate by VA 1216 case MISCREG_DTLBIMVA: 1217 { 1218 assert32(tc); 1219 scr = readMiscReg(MISCREG_SCR, tc); 1220 1221 DTLBIMVA tlbiOp(EL1, 1222 haveSecurity && !scr.ns, 1223 mbits(newVal, 31, 12), 1224 bits(newVal, 7,0)); 1225 1226 tlbiOp(tc); 1227 return; 1228 } 1229 // Instruction TLB Invalidate by ASID match 1230 case MISCREG_ITLBIASID: 1231 { 1232 assert32(tc); 1233 scr = readMiscReg(MISCREG_SCR, tc); 1234 1235 ITLBIASID tlbiOp(EL1, 1236 haveSecurity && !scr.ns, 1237 bits(newVal, 7,0)); 1238 1239 tlbiOp(tc); 1240 return; 1241 } 1242 // Data TLB Invalidate by ASID match 1243 case MISCREG_DTLBIASID: 1244 { 1245 assert32(tc); 1246 scr = readMiscReg(MISCREG_SCR, tc); 1247 1248 DTLBIASID tlbiOp(EL1, 1249 haveSecurity && !scr.ns, 1250 bits(newVal, 7,0)); 1251 1252 tlbiOp(tc); 1253 return; 1254 } 1255 // TLB Invalidate All, Non-Secure Non-Hyp 1256 case MISCREG_TLBIALLNSNH: 1257 { 1258 assert32(tc); 1259 1260 TLBIALLN tlbiOp(EL1, false); 1261 tlbiOp(tc); 1262 return; 1263 } 1264 // TLB Invalidate All, Non-Secure Non-Hyp, Inner Shareable 1265 case MISCREG_TLBIALLNSNHIS: 1266 { 1267 assert32(tc); 1268 1269 TLBIALLN tlbiOp(EL1, false); 1270 tlbiOp.broadcast(tc); 1271 return; 1272 } 1273 // TLB Invalidate All, Hyp mode 1274 case MISCREG_TLBIALLH: 1275 { 1276 assert32(tc); 1277 1278 TLBIALLN tlbiOp(EL1, true); 1279 tlbiOp(tc); 1280 return; 1281 } 1282 // TLB Invalidate All, Hyp mode, Inner Shareable 1283 case MISCREG_TLBIALLHIS: 1284 { 1285 assert32(tc); 1286 1287 TLBIALLN tlbiOp(EL1, true); 1288 tlbiOp.broadcast(tc); 1289 return; 1290 } 1291 // AArch64 TLB Invalidate All, EL3 1292 case MISCREG_TLBI_ALLE3: 1293 { 1294 assert64(tc); 1295 1296 TLBIALL tlbiOp(EL3, true); 1297 tlbiOp(tc); 1298 return; 1299 } 1300 // AArch64 TLB Invalidate All, EL3, Inner Shareable 1301 case MISCREG_TLBI_ALLE3IS: 1302 { 1303 assert64(tc); 1304 1305 TLBIALL tlbiOp(EL3, true); 1306 tlbiOp.broadcast(tc); 1307 return; 1308 } 1309 // @todo: uncomment this to enable Virtualization 1310 // case MISCREG_TLBI_ALLE2IS: 1311 // case MISCREG_TLBI_ALLE2: 1312 // AArch64 TLB Invalidate All, EL1 1313 case MISCREG_TLBI_ALLE1: 1314 case MISCREG_TLBI_VMALLE1: 1315 case MISCREG_TLBI_VMALLS12E1: 1316 // @todo: handle VMID and stage 2 to enable Virtualization 1317 { 1318 assert64(tc); 1319 scr = readMiscReg(MISCREG_SCR, tc); 1320 1321 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1322 tlbiOp(tc); 1323 return; 1324 } 1325 // AArch64 TLB Invalidate All, EL1, Inner Shareable 1326 case MISCREG_TLBI_ALLE1IS: 1327 case MISCREG_TLBI_VMALLE1IS: 1328 case MISCREG_TLBI_VMALLS12E1IS: 1329 // @todo: handle VMID and stage 2 to enable Virtualization 1330 { 1331 assert64(tc); 1332 scr = readMiscReg(MISCREG_SCR, tc); 1333 1334 TLBIALL tlbiOp(EL1, haveSecurity && !scr.ns); 1335 tlbiOp.broadcast(tc); 1336 return; 1337 } 1338 // VAEx(IS) and VALEx(IS) are the same because TLBs 1339 // only store entries 1340 // from the last level of translation table walks 1341 // @todo: handle VMID to enable Virtualization 1342 // AArch64 TLB Invalidate by VA, EL3 1343 case MISCREG_TLBI_VAE3_Xt: 1344 case MISCREG_TLBI_VALE3_Xt: 1345 { 1346 assert64(tc); 1347 1348 TLBIMVA tlbiOp(EL3, true, 1349 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1350 0xbeef); 1351 tlbiOp(tc); 1352 return; 1353 } 1354 // AArch64 TLB Invalidate by VA, EL3, Inner Shareable 1355 case MISCREG_TLBI_VAE3IS_Xt: 1356 case MISCREG_TLBI_VALE3IS_Xt: 1357 { 1358 assert64(tc); 1359 1360 TLBIMVA tlbiOp(EL3, true, 1361 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1362 0xbeef); 1363 1364 tlbiOp.broadcast(tc); 1365 return; 1366 } 1367 // AArch64 TLB Invalidate by VA, EL2 1368 case MISCREG_TLBI_VAE2_Xt: 1369 case MISCREG_TLBI_VALE2_Xt: 1370 { 1371 assert64(tc); 1372 scr = readMiscReg(MISCREG_SCR, tc); 1373 1374 TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns, 1375 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1376 0xbeef); 1377 tlbiOp(tc); 1378 return; 1379 } 1380 // AArch64 TLB Invalidate by VA, EL2, Inner Shareable 1381 case MISCREG_TLBI_VAE2IS_Xt: 1382 case MISCREG_TLBI_VALE2IS_Xt: 1383 { 1384 assert64(tc); 1385 scr = readMiscReg(MISCREG_SCR, tc); 1386 1387 TLBIMVA tlbiOp(EL2, haveSecurity && !scr.ns, 1388 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1389 0xbeef); 1390 1391 tlbiOp.broadcast(tc); 1392 return; 1393 } 1394 // AArch64 TLB Invalidate by VA, EL1 1395 case MISCREG_TLBI_VAE1_Xt: 1396 case MISCREG_TLBI_VALE1_Xt: 1397 { 1398 assert64(tc); 1399 scr = readMiscReg(MISCREG_SCR, tc); 1400 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1401 bits(newVal, 55, 48); 1402 1403 TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns, 1404 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1405 asid); 1406 1407 tlbiOp(tc); 1408 return; 1409 } 1410 // AArch64 TLB Invalidate by VA, EL1, Inner Shareable 1411 case MISCREG_TLBI_VAE1IS_Xt: 1412 case MISCREG_TLBI_VALE1IS_Xt: 1413 { 1414 assert64(tc); 1415 scr = readMiscReg(MISCREG_SCR, tc); 1416 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1417 bits(newVal, 55, 48); 1418 1419 TLBIMVA tlbiOp(EL1, haveSecurity && !scr.ns, 1420 static_cast<Addr>(bits(newVal, 43, 0)) << 12, 1421 asid); 1422 1423 tlbiOp.broadcast(tc); 1424 return; 1425 } 1426 // AArch64 TLB Invalidate by ASID, EL1 1427 // @todo: handle VMID to enable Virtualization 1428 case MISCREG_TLBI_ASIDE1_Xt: 1429 { 1430 assert64(tc); 1431 scr = readMiscReg(MISCREG_SCR, tc); 1432 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1433 bits(newVal, 55, 48); 1434 1435 TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid); 1436 tlbiOp(tc); 1437 return; 1438 } 1439 // AArch64 TLB Invalidate by ASID, EL1, Inner Shareable 1440 case MISCREG_TLBI_ASIDE1IS_Xt: 1441 { 1442 assert64(tc); 1443 scr = readMiscReg(MISCREG_SCR, tc); 1444 auto asid = haveLargeAsid64 ? bits(newVal, 63, 48) : 1445 bits(newVal, 55, 48); 1446 1447 TLBIASID tlbiOp(EL1, haveSecurity && !scr.ns, asid); 1448 tlbiOp.broadcast(tc); 1449 return; 1450 } 1451 // VAAE1(IS) and VAALE1(IS) are the same because TLBs only store 1452 // entries from the last level of translation table walks 1453 // AArch64 TLB Invalidate by VA, All ASID, EL1 1454 case MISCREG_TLBI_VAAE1_Xt: 1455 case MISCREG_TLBI_VAALE1_Xt: 1456 { 1457 assert64(tc); 1458 scr = readMiscReg(MISCREG_SCR, tc); 1459 1460 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1461 static_cast<Addr>(bits(newVal, 43, 0)) << 12, false); 1462 1463 tlbiOp(tc); 1464 return; 1465 } 1466 // AArch64 TLB Invalidate by VA, All ASID, EL1, Inner Shareable 1467 case MISCREG_TLBI_VAAE1IS_Xt: 1468 case MISCREG_TLBI_VAALE1IS_Xt: 1469 { 1470 assert64(tc); 1471 scr = readMiscReg(MISCREG_SCR, tc); 1472 1473 TLBIMVAA tlbiOp(EL1, haveSecurity && !scr.ns, 1474 static_cast<Addr>(bits(newVal, 43, 0)) << 12, false); 1475 1476 tlbiOp.broadcast(tc); 1477 return; 1478 } 1479 // AArch64 TLB Invalidate by Intermediate Physical Address, 1480 // Stage 2, EL1 1481 case MISCREG_TLBI_IPAS2E1_Xt: 1482 case MISCREG_TLBI_IPAS2LE1_Xt: 1483 { 1484 assert64(tc); 1485 scr = readMiscReg(MISCREG_SCR, tc); 1486 1487 TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns, 1488 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1489 1490 tlbiOp(tc); 1491 return; 1492 } 1493 // AArch64 TLB Invalidate by Intermediate Physical Address, 1494 // Stage 2, EL1, Inner Shareable 1495 case MISCREG_TLBI_IPAS2E1IS_Xt: 1496 case MISCREG_TLBI_IPAS2LE1IS_Xt: 1497 { 1498 assert64(tc); 1499 scr = readMiscReg(MISCREG_SCR, tc); 1500 1501 TLBIIPA tlbiOp(EL1, haveSecurity && !scr.ns, 1502 static_cast<Addr>(bits(newVal, 35, 0)) << 12); 1503 1504 tlbiOp.broadcast(tc); 1505 return; 1506 } 1507 case MISCREG_ACTLR: 1508 warn("Not doing anything for write of miscreg ACTLR\n"); 1509 break; 1510 1511 case MISCREG_PMXEVTYPER_PMCCFILTR: 1512 case MISCREG_PMINTENSET_EL1 ... MISCREG_PMOVSSET_EL0: 1513 case MISCREG_PMEVCNTR0_EL0 ... MISCREG_PMEVTYPER5_EL0: 1514 case MISCREG_PMCR ... MISCREG_PMOVSSET: 1515 pmu->setMiscReg(misc_reg, newVal); 1516 break; 1517 1518 1519 case MISCREG_HSTR: // TJDBX, now redifined to be RES0 1520 { 1521 HSTR hstrMask = 0; 1522 hstrMask.tjdbx = 1; 1523 newVal &= ~((uint32_t) hstrMask); 1524 break; 1525 } 1526 case MISCREG_HCPTR: 1527 { 1528 // If a CP bit in NSACR is 0 then the corresponding bit in 1529 // HCPTR is RAO/WI. Same applies to NSASEDIS 1530 secure_lookup = haveSecurity && 1531 inSecureState(readMiscRegNoEffect(MISCREG_SCR), 1532 readMiscRegNoEffect(MISCREG_CPSR)); 1533 if (!secure_lookup) { 1534 MiscReg oldValue = readMiscRegNoEffect(MISCREG_HCPTR); 1535 MiscReg mask = (readMiscRegNoEffect(MISCREG_NSACR) ^ 0x7FFF) & 0xBFFF; 1536 newVal = (newVal & ~mask) | (oldValue & mask); 1537 } 1538 break; 1539 } 1540 case MISCREG_HDFAR: // alias for secure DFAR 1541 misc_reg = MISCREG_DFAR_S; 1542 break; 1543 case MISCREG_HIFAR: // alias for secure IFAR 1544 misc_reg = MISCREG_IFAR_S; 1545 break; 1546 case MISCREG_ATS1CPR: 1547 case MISCREG_ATS1CPW: 1548 case MISCREG_ATS1CUR: 1549 case MISCREG_ATS1CUW: 1550 case MISCREG_ATS12NSOPR: 1551 case MISCREG_ATS12NSOPW: 1552 case MISCREG_ATS12NSOUR: 1553 case MISCREG_ATS12NSOUW: 1554 case MISCREG_ATS1HR: 1555 case MISCREG_ATS1HW: 1556 { 1557 Request::Flags flags = 0; 1558 BaseTLB::Mode mode = BaseTLB::Read; 1559 TLB::ArmTranslationType tranType = TLB::NormalTran; 1560 Fault fault; 1561 switch(misc_reg) { 1562 case MISCREG_ATS1CPR: 1563 flags = TLB::MustBeOne; 1564 tranType = TLB::S1CTran; 1565 mode = BaseTLB::Read; 1566 break; 1567 case MISCREG_ATS1CPW: 1568 flags = TLB::MustBeOne; 1569 tranType = TLB::S1CTran; 1570 mode = BaseTLB::Write; 1571 break; 1572 case MISCREG_ATS1CUR: 1573 flags = TLB::MustBeOne | TLB::UserMode; 1574 tranType = TLB::S1CTran; 1575 mode = BaseTLB::Read; 1576 break; 1577 case MISCREG_ATS1CUW: 1578 flags = TLB::MustBeOne | TLB::UserMode; 1579 tranType = TLB::S1CTran; 1580 mode = BaseTLB::Write; 1581 break; 1582 case MISCREG_ATS12NSOPR: 1583 if (!haveSecurity) 1584 panic("Security Extensions required for ATS12NSOPR"); 1585 flags = TLB::MustBeOne; 1586 tranType = TLB::S1S2NsTran; 1587 mode = BaseTLB::Read; 1588 break; 1589 case MISCREG_ATS12NSOPW: 1590 if (!haveSecurity) 1591 panic("Security Extensions required for ATS12NSOPW"); 1592 flags = TLB::MustBeOne; 1593 tranType = TLB::S1S2NsTran; 1594 mode = BaseTLB::Write; 1595 break; 1596 case MISCREG_ATS12NSOUR: 1597 if (!haveSecurity) 1598 panic("Security Extensions required for ATS12NSOUR"); 1599 flags = TLB::MustBeOne | TLB::UserMode; 1600 tranType = TLB::S1S2NsTran; 1601 mode = BaseTLB::Read; 1602 break; 1603 case MISCREG_ATS12NSOUW: 1604 if (!haveSecurity) 1605 panic("Security Extensions required for ATS12NSOUW"); 1606 flags = TLB::MustBeOne | TLB::UserMode; 1607 tranType = TLB::S1S2NsTran; 1608 mode = BaseTLB::Write; 1609 break; 1610 case MISCREG_ATS1HR: // only really useful from secure mode. 1611 flags = TLB::MustBeOne; 1612 tranType = TLB::HypMode; 1613 mode = BaseTLB::Read; 1614 break; 1615 case MISCREG_ATS1HW: 1616 flags = TLB::MustBeOne; 1617 tranType = TLB::HypMode; 1618 mode = BaseTLB::Write; 1619 break; 1620 } 1621 // If we're in timing mode then doing the translation in 1622 // functional mode then we're slightly distorting performance 1623 // results obtained from simulations. The translation should be 1624 // done in the same mode the core is running in. NOTE: This 1625 // can't be an atomic translation because that causes problems 1626 // with unexpected atomic snoop requests. 1627 warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 1628 1629 auto req = std::make_shared<Request>( 1630 0, val, 0, flags, Request::funcMasterId, 1631 tc->pcState().pc(), tc->contextId()); 1632 1633 fault = getDTBPtr(tc)->translateFunctional( 1634 req, tc, mode, tranType); 1635 1636 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 1637 HCR hcr = readMiscRegNoEffect(MISCREG_HCR); 1638 1639 MiscReg newVal; 1640 if (fault == NoFault) { 1641 Addr paddr = req->getPaddr(); 1642 if (haveLPAE && (ttbcr.eae || tranType & TLB::HypMode || 1643 ((tranType & TLB::S1S2NsTran) && hcr.vm) )) { 1644 newVal = (paddr & mask(39, 12)) | 1645 (getDTBPtr(tc)->getAttr()); 1646 } else { 1647 newVal = (paddr & 0xfffff000) | 1648 (getDTBPtr(tc)->getAttr()); 1649 } 1650 DPRINTF(MiscRegs, 1651 "MISCREG: Translated addr 0x%08x: PAR: 0x%08x\n", 1652 val, newVal); 1653 } else { 1654 ArmFault *armFault = static_cast<ArmFault *>(fault.get()); 1655 armFault->update(tc); 1656 // Set fault bit and FSR 1657 FSR fsr = armFault->getFsr(tc); 1658 1659 newVal = ((fsr >> 9) & 1) << 11; 1660 if (newVal) { 1661 // LPAE - rearange fault status 1662 newVal |= ((fsr >> 0) & 0x3f) << 1; 1663 } else { 1664 // VMSA - rearange fault status 1665 newVal |= ((fsr >> 0) & 0xf) << 1; 1666 newVal |= ((fsr >> 10) & 0x1) << 5; 1667 newVal |= ((fsr >> 12) & 0x1) << 6; 1668 } 1669 newVal |= 0x1; // F bit 1670 newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 1671 newVal |= armFault->isStage2() ? 0x200 : 0; 1672 DPRINTF(MiscRegs, 1673 "MISCREG: Translated addr 0x%08x fault fsr %#x: PAR: 0x%08x\n", 1674 val, fsr, newVal); 1675 } 1676 setMiscRegNoEffect(MISCREG_PAR, newVal); 1677 return; 1678 } 1679 case MISCREG_TTBCR: 1680 { 1681 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 1682 const uint32_t ones = (uint32_t)(-1); 1683 TTBCR ttbcrMask = 0; 1684 TTBCR ttbcrNew = newVal; 1685 1686 // ARM DDI 0406C.b, ARMv7-32 1687 ttbcrMask.n = ones; // T0SZ 1688 if (haveSecurity) { 1689 ttbcrMask.pd0 = ones; 1690 ttbcrMask.pd1 = ones; 1691 } 1692 ttbcrMask.epd0 = ones; 1693 ttbcrMask.irgn0 = ones; 1694 ttbcrMask.orgn0 = ones; 1695 ttbcrMask.sh0 = ones; 1696 ttbcrMask.ps = ones; // T1SZ 1697 ttbcrMask.a1 = ones; 1698 ttbcrMask.epd1 = ones; 1699 ttbcrMask.irgn1 = ones; 1700 ttbcrMask.orgn1 = ones; 1701 ttbcrMask.sh1 = ones; 1702 if (haveLPAE) 1703 ttbcrMask.eae = ones; 1704 1705 if (haveLPAE && ttbcrNew.eae) { 1706 newVal = newVal & ttbcrMask; 1707 } else { 1708 newVal = (newVal & ttbcrMask) | (ttbcr & (~ttbcrMask)); 1709 } 1710 // Invalidate TLB MiscReg 1711 getITBPtr(tc)->invalidateMiscReg(); 1712 getDTBPtr(tc)->invalidateMiscReg(); 1713 break; 1714 } 1715 case MISCREG_TTBR0: 1716 case MISCREG_TTBR1: 1717 { 1718 TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 1719 if (haveLPAE) { 1720 if (ttbcr.eae) { 1721 // ARMv7 bit 63-56, 47-40 reserved, UNK/SBZP 1722 // ARMv8 AArch32 bit 63-56 only 1723 uint64_t ttbrMask = mask(63,56) | mask(47,40); 1724 newVal = (newVal & (~ttbrMask)); 1725 } 1726 } 1727 // Invalidate TLB MiscReg 1728 getITBPtr(tc)->invalidateMiscReg(); 1729 getDTBPtr(tc)->invalidateMiscReg(); 1730 break; 1731 } 1732 case MISCREG_SCTLR_EL1: 1733 case MISCREG_CONTEXTIDR: 1734 case MISCREG_PRRR: 1735 case MISCREG_NMRR: 1736 case MISCREG_MAIR0: 1737 case MISCREG_MAIR1: 1738 case MISCREG_DACR: 1739 case MISCREG_VTTBR: 1740 case MISCREG_SCR_EL3: 1741 case MISCREG_HCR_EL2: 1742 case MISCREG_TCR_EL1: 1743 case MISCREG_TCR_EL2: 1744 case MISCREG_TCR_EL3: 1745 case MISCREG_SCTLR_EL2: 1746 case MISCREG_SCTLR_EL3: 1747 case MISCREG_HSCTLR: 1748 case MISCREG_TTBR0_EL1: 1749 case MISCREG_TTBR1_EL1: 1750 case MISCREG_TTBR0_EL2: 1751 case MISCREG_TTBR1_EL2: 1752 case MISCREG_TTBR0_EL3: 1753 getITBPtr(tc)->invalidateMiscReg(); 1754 getDTBPtr(tc)->invalidateMiscReg(); 1755 break; 1756 case MISCREG_NZCV: 1757 { 1758 CPSR cpsr = val; 1759 1760 tc->setCCReg(CCREG_NZ, cpsr.nz); 1761 tc->setCCReg(CCREG_C, cpsr.c); 1762 tc->setCCReg(CCREG_V, cpsr.v); 1763 } 1764 break; 1765 case MISCREG_DAIF: 1766 { 1767 CPSR cpsr = miscRegs[MISCREG_CPSR]; 1768 cpsr.daif = (uint8_t) ((CPSR) newVal).daif; 1769 newVal = cpsr; 1770 misc_reg = MISCREG_CPSR; 1771 } 1772 break; 1773 case MISCREG_SP_EL0: 1774 tc->setIntReg(INTREG_SP0, newVal); 1775 break; 1776 case MISCREG_SP_EL1: 1777 tc->setIntReg(INTREG_SP1, newVal); 1778 break; 1779 case MISCREG_SP_EL2: 1780 tc->setIntReg(INTREG_SP2, newVal); 1781 break; 1782 case MISCREG_SPSEL: 1783 { 1784 CPSR cpsr = miscRegs[MISCREG_CPSR]; 1785 cpsr.sp = (uint8_t) ((CPSR) newVal).sp; 1786 newVal = cpsr; 1787 misc_reg = MISCREG_CPSR; 1788 } 1789 break; 1790 case MISCREG_CURRENTEL: 1791 { 1792 CPSR cpsr = miscRegs[MISCREG_CPSR]; 1793 cpsr.el = (uint8_t) ((CPSR) newVal).el; 1794 newVal = cpsr; 1795 misc_reg = MISCREG_CPSR; 1796 } 1797 break; 1798 case MISCREG_AT_S1E1R_Xt: 1799 case MISCREG_AT_S1E1W_Xt: 1800 case MISCREG_AT_S1E0R_Xt: 1801 case MISCREG_AT_S1E0W_Xt: 1802 case MISCREG_AT_S1E2R_Xt: 1803 case MISCREG_AT_S1E2W_Xt: 1804 case MISCREG_AT_S12E1R_Xt: 1805 case MISCREG_AT_S12E1W_Xt: 1806 case MISCREG_AT_S12E0R_Xt: 1807 case MISCREG_AT_S12E0W_Xt: 1808 case MISCREG_AT_S1E3R_Xt: 1809 case MISCREG_AT_S1E3W_Xt: 1810 { 1811 RequestPtr req = std::make_shared<Request>(); 1812 Request::Flags flags = 0; 1813 BaseTLB::Mode mode = BaseTLB::Read; 1814 TLB::ArmTranslationType tranType = TLB::NormalTran; 1815 Fault fault; 1816 switch(misc_reg) { 1817 case MISCREG_AT_S1E1R_Xt: 1818 flags = TLB::MustBeOne; 1819 tranType = TLB::S1E1Tran; 1820 mode = BaseTLB::Read; 1821 break; 1822 case MISCREG_AT_S1E1W_Xt: 1823 flags = TLB::MustBeOne; 1824 tranType = TLB::S1E1Tran; 1825 mode = BaseTLB::Write; 1826 break; 1827 case MISCREG_AT_S1E0R_Xt: 1828 flags = TLB::MustBeOne | TLB::UserMode; 1829 tranType = TLB::S1E0Tran; 1830 mode = BaseTLB::Read; 1831 break; 1832 case MISCREG_AT_S1E0W_Xt: 1833 flags = TLB::MustBeOne | TLB::UserMode; 1834 tranType = TLB::S1E0Tran; 1835 mode = BaseTLB::Write; 1836 break; 1837 case MISCREG_AT_S1E2R_Xt: 1838 flags = TLB::MustBeOne; 1839 tranType = TLB::S1E2Tran; 1840 mode = BaseTLB::Read; 1841 break; 1842 case MISCREG_AT_S1E2W_Xt: 1843 flags = TLB::MustBeOne; 1844 tranType = TLB::S1E2Tran; 1845 mode = BaseTLB::Write; 1846 break; 1847 case MISCREG_AT_S12E0R_Xt: 1848 flags = TLB::MustBeOne | TLB::UserMode; 1849 tranType = TLB::S12E0Tran; 1850 mode = BaseTLB::Read; 1851 break; 1852 case MISCREG_AT_S12E0W_Xt: 1853 flags = TLB::MustBeOne | TLB::UserMode; 1854 tranType = TLB::S12E0Tran; 1855 mode = BaseTLB::Write; 1856 break; 1857 case MISCREG_AT_S12E1R_Xt: 1858 flags = TLB::MustBeOne; 1859 tranType = TLB::S12E1Tran; 1860 mode = BaseTLB::Read; 1861 break; 1862 case MISCREG_AT_S12E1W_Xt: 1863 flags = TLB::MustBeOne; 1864 tranType = TLB::S12E1Tran; 1865 mode = BaseTLB::Write; 1866 break; 1867 case MISCREG_AT_S1E3R_Xt: 1868 flags = TLB::MustBeOne; 1869 tranType = TLB::S1E3Tran; 1870 mode = BaseTLB::Read; 1871 break; 1872 case MISCREG_AT_S1E3W_Xt: 1873 flags = TLB::MustBeOne; 1874 tranType = TLB::S1E3Tran; 1875 mode = BaseTLB::Write; 1876 break; 1877 } 1878 // If we're in timing mode then doing the translation in 1879 // functional mode then we're slightly distorting performance 1880 // results obtained from simulations. The translation should be 1881 // done in the same mode the core is running in. NOTE: This 1882 // can't be an atomic translation because that causes problems 1883 // with unexpected atomic snoop requests. 1884 warn("Translating via MISCREG(%d) in functional mode! Fix Me!\n", misc_reg); 1885 req->setVirt(0, val, 0, flags, Request::funcMasterId, 1886 tc->pcState().pc()); 1887 req->setContext(tc->contextId()); 1888 fault = getDTBPtr(tc)->translateFunctional(req, tc, mode, 1889 tranType); 1890 1891 MiscReg newVal; 1892 if (fault == NoFault) { 1893 Addr paddr = req->getPaddr(); 1894 uint64_t attr = getDTBPtr(tc)->getAttr(); 1895 uint64_t attr1 = attr >> 56; 1896 if (!attr1 || attr1 ==0x44) { 1897 attr |= 0x100; 1898 attr &= ~ uint64_t(0x80); 1899 } 1900 newVal = (paddr & mask(47, 12)) | attr; 1901 DPRINTF(MiscRegs, 1902 "MISCREG: Translated addr %#x: PAR_EL1: %#xx\n", 1903 val, newVal); 1904 } else { 1905 ArmFault *armFault = static_cast<ArmFault *>(fault.get()); 1906 armFault->update(tc); 1907 // Set fault bit and FSR 1908 FSR fsr = armFault->getFsr(tc); 1909 1910 CPSR cpsr = tc->readMiscReg(MISCREG_CPSR); 1911 if (cpsr.width) { // AArch32 1912 newVal = ((fsr >> 9) & 1) << 11; 1913 // rearrange fault status 1914 newVal |= ((fsr >> 0) & 0x3f) << 1; 1915 newVal |= 0x1; // F bit 1916 newVal |= ((armFault->iss() >> 7) & 0x1) << 8; 1917 newVal |= armFault->isStage2() ? 0x200 : 0; 1918 } else { // AArch64 1919 newVal = 1; // F bit 1920 newVal |= fsr << 1; // FST 1921 // TODO: DDI 0487A.f D7-2083, AbortFault's s1ptw bit. 1922 newVal |= armFault->isStage2() ? 1 << 8 : 0; // PTW 1923 newVal |= armFault->isStage2() ? 1 << 9 : 0; // S 1924 newVal |= 1 << 11; // RES1 1925 } 1926 DPRINTF(MiscRegs, 1927 "MISCREG: Translated addr %#x fault fsr %#x: PAR: %#x\n", 1928 val, fsr, newVal); 1929 } 1930 setMiscRegNoEffect(MISCREG_PAR_EL1, newVal); 1931 return; 1932 } 1933 case MISCREG_SPSR_EL3: 1934 case MISCREG_SPSR_EL2: 1935 case MISCREG_SPSR_EL1: 1936 // Force bits 23:21 to 0 1937 newVal = val & ~(0x7 << 21); 1938 break; 1939 case MISCREG_L2CTLR: 1940 warn("miscreg L2CTLR (%s) written with %#x. ignored...\n", 1941 miscRegName[misc_reg], uint32_t(val)); 1942 break; 1943 1944 // Generic Timer registers 1945 case MISCREG_CNTHV_CTL_EL2: 1946 case MISCREG_CNTHV_CVAL_EL2: 1947 case MISCREG_CNTHV_TVAL_EL2: 1948 case MISCREG_CNTFRQ ... MISCREG_CNTHP_CTL: 1949 case MISCREG_CNTPCT ... MISCREG_CNTHP_CVAL: 1950 case MISCREG_CNTKCTL_EL1 ... MISCREG_CNTV_CVAL_EL0: 1951 case MISCREG_CNTVOFF_EL2 ... MISCREG_CNTPS_CVAL_EL1: 1952 getGenericTimer(tc).setMiscReg(misc_reg, newVal); 1953 break; 1954 } 1955 } 1956 setMiscRegNoEffect(misc_reg, newVal); 1957} 1958 1959BaseISADevice & 1960ISA::getGenericTimer(ThreadContext *tc) 1961{ 1962 // We only need to create an ISA interface the first time we try 1963 // to access the timer. 1964 if (timer) 1965 return *timer.get(); 1966 1967 assert(system); 1968 GenericTimer *generic_timer(system->getGenericTimer()); 1969 if (!generic_timer) { 1970 panic("Trying to get a generic timer from a system that hasn't " 1971 "been configured to use a generic timer.\n"); 1972 } 1973 1974 timer.reset(new GenericTimerISA(*generic_timer, tc->contextId())); 1975 timer->setThreadContext(tc); 1976 1977 return *timer.get(); 1978} 1979 1980} 1981 1982ArmISA::ISA * 1983ArmISAParams::create() 1984{ 1985 return new ArmISA::ISA(this); 1986} 1987