isa.hh revision 12479
16313Sgblack@eecs.umich.edu/* 212477SCurtis.Dunham@arm.com * Copyright (c) 2010, 2012-2017 ARM Limited 37093Sgblack@eecs.umich.edu * All rights reserved 47093Sgblack@eecs.umich.edu * 57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall 67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual 77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating 87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software 97093Sgblack@eecs.umich.edu * licensed hereunder. You may use the software subject to the license 107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated 117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software, 127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form. 137093Sgblack@eecs.umich.edu * 146313Sgblack@eecs.umich.edu * Copyright (c) 2009 The Regents of The University of Michigan 156313Sgblack@eecs.umich.edu * All rights reserved. 166313Sgblack@eecs.umich.edu * 176313Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 186313Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 196313Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 206313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 216313Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 226313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 236313Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 246313Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 256313Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 266313Sgblack@eecs.umich.edu * this software without specific prior written permission. 276313Sgblack@eecs.umich.edu * 286313Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 296313Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 306313Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 316313Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 326313Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 336313Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 346313Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 356313Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 366313Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 376313Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 386313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 396313Sgblack@eecs.umich.edu * 406313Sgblack@eecs.umich.edu * Authors: Gabe Black 416313Sgblack@eecs.umich.edu */ 426313Sgblack@eecs.umich.edu 436313Sgblack@eecs.umich.edu#ifndef __ARCH_ARM_ISA_HH__ 447404SAli.Saidi@ARM.com#define __ARCH_ARM_ISA_HH__ 456313Sgblack@eecs.umich.edu 4610461SAndreas.Sandberg@ARM.com#include "arch/arm/isa_device.hh" 4712479SCurtis.Dunham@arm.com#include "arch/arm/miscregs.hh" 486333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh" 4910037SARM gem5 Developers#include "arch/arm/system.hh" 507404SAli.Saidi@ARM.com#include "arch/arm/tlb.hh" 516313Sgblack@eecs.umich.edu#include "arch/arm/types.hh" 5212109SRekai.GonzalezAlberquilla@arm.com#include "arch/generic/traits.hh" 538232Snate@binkert.org#include "debug/Checkpoint.hh" 5412109SRekai.GonzalezAlberquilla@arm.com#include "enums/VecRegRenameMode.hh" 559384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh" 5611165SRekai.GonzalezAlberquilla@arm.com#include "enums/DecoderFlavour.hh" 576313Sgblack@eecs.umich.edu 589384SAndreas.Sandberg@arm.comstruct ArmISAParams; 5910461SAndreas.Sandberg@ARM.comstruct DummyArmISADeviceParams; 606333Sgblack@eecs.umich.educlass ThreadContext; 616313Sgblack@eecs.umich.educlass Checkpoint; 626313Sgblack@eecs.umich.educlass EventManager; 636313Sgblack@eecs.umich.edu 646313Sgblack@eecs.umich.edunamespace ArmISA 656313Sgblack@eecs.umich.edu{ 669384SAndreas.Sandberg@arm.com class ISA : public SimObject 676313Sgblack@eecs.umich.edu { 686313Sgblack@eecs.umich.edu protected: 6910037SARM gem5 Developers // Parent system 7010037SARM gem5 Developers ArmSystem *system; 7110037SARM gem5 Developers 7211165SRekai.GonzalezAlberquilla@arm.com // Micro Architecture 7311165SRekai.GonzalezAlberquilla@arm.com const Enums::DecoderFlavour _decoderFlavour; 7412109SRekai.GonzalezAlberquilla@arm.com const Enums::VecRegRenameMode _vecRegRenameMode; 7511165SRekai.GonzalezAlberquilla@arm.com 7610461SAndreas.Sandberg@ARM.com /** Dummy device for to handle non-existing ISA devices */ 7710461SAndreas.Sandberg@ARM.com DummyISADevice dummyDevice; 7810461SAndreas.Sandberg@ARM.com 7910461SAndreas.Sandberg@ARM.com // PMU belonging to this ISA 8010461SAndreas.Sandberg@ARM.com BaseISADevice *pmu; 8110461SAndreas.Sandberg@ARM.com 8210844Sandreas.sandberg@arm.com // Generic timer interface belonging to this ISA 8310844Sandreas.sandberg@arm.com std::unique_ptr<BaseISADevice> timer; 8410844Sandreas.sandberg@arm.com 8510037SARM gem5 Developers // Cached copies of system-level properties 8611771SCurtis.Dunham@arm.com bool highestELIs64; 8710037SARM gem5 Developers bool haveSecurity; 8810037SARM gem5 Developers bool haveLPAE; 8910037SARM gem5 Developers bool haveVirtualization; 9010037SARM gem5 Developers bool haveLargeAsid64; 9110037SARM gem5 Developers uint8_t physAddrRange64; 9210037SARM gem5 Developers 9312478SCurtis.Dunham@arm.com /** MiscReg metadata **/ 9410037SARM gem5 Developers struct MiscRegLUTEntry { 9512477SCurtis.Dunham@arm.com uint32_t lower; // Lower half mapped to this register 9612477SCurtis.Dunham@arm.com uint32_t upper; // Upper half mapped to this register 9712478SCurtis.Dunham@arm.com uint64_t _reset; // value taken on reset (i.e. initialization) 9812478SCurtis.Dunham@arm.com uint64_t _res0; // reserved 9912478SCurtis.Dunham@arm.com uint64_t _res1; // reserved 10012478SCurtis.Dunham@arm.com uint64_t _raz; // read as zero (fixed at 0) 10112478SCurtis.Dunham@arm.com uint64_t _rao; // read as one (fixed at 1) 10212478SCurtis.Dunham@arm.com public: 10312478SCurtis.Dunham@arm.com MiscRegLUTEntry() : 10412478SCurtis.Dunham@arm.com lower(0), upper(0), 10512478SCurtis.Dunham@arm.com _reset(0), _res0(0), _res1(0), _raz(0), _rao(0) {} 10612478SCurtis.Dunham@arm.com uint64_t reset() const { return _reset; } 10712478SCurtis.Dunham@arm.com uint64_t res0() const { return _res0; } 10812478SCurtis.Dunham@arm.com uint64_t res1() const { return _res1; } 10912478SCurtis.Dunham@arm.com uint64_t raz() const { return _raz; } 11012478SCurtis.Dunham@arm.com uint64_t rao() const { return _rao; } 11112478SCurtis.Dunham@arm.com // raz/rao implies writes ignored 11212478SCurtis.Dunham@arm.com uint64_t wi() const { return _raz | _rao; } 11310037SARM gem5 Developers }; 11410037SARM gem5 Developers 11512477SCurtis.Dunham@arm.com /** Metadata table accessible via the value of the register */ 11612479SCurtis.Dunham@arm.com static std::vector<struct MiscRegLUTEntry> lookUpMiscReg; 11712477SCurtis.Dunham@arm.com 11812477SCurtis.Dunham@arm.com class MiscRegLUTEntryInitializer { 11912477SCurtis.Dunham@arm.com struct MiscRegLUTEntry &entry; 12012479SCurtis.Dunham@arm.com std::bitset<NUM_MISCREG_INFOS> &info; 12112477SCurtis.Dunham@arm.com typedef const MiscRegLUTEntryInitializer& chain; 12212477SCurtis.Dunham@arm.com public: 12312477SCurtis.Dunham@arm.com chain mapsTo(uint32_t l, uint32_t u = 0) const { 12412477SCurtis.Dunham@arm.com entry.lower = l; 12512477SCurtis.Dunham@arm.com entry.upper = u; 12612477SCurtis.Dunham@arm.com return *this; 12712477SCurtis.Dunham@arm.com } 12812478SCurtis.Dunham@arm.com chain res0(uint64_t mask) const { 12912478SCurtis.Dunham@arm.com entry._res0 = mask; 13012478SCurtis.Dunham@arm.com return *this; 13112478SCurtis.Dunham@arm.com } 13212478SCurtis.Dunham@arm.com chain res1(uint64_t mask) const { 13312478SCurtis.Dunham@arm.com entry._res1 = mask; 13412478SCurtis.Dunham@arm.com return *this; 13512478SCurtis.Dunham@arm.com } 13612478SCurtis.Dunham@arm.com chain raz(uint64_t mask) const { 13712478SCurtis.Dunham@arm.com entry._raz = mask; 13812478SCurtis.Dunham@arm.com return *this; 13912478SCurtis.Dunham@arm.com } 14012478SCurtis.Dunham@arm.com chain rao(uint64_t mask) const { 14112478SCurtis.Dunham@arm.com entry._rao = mask; 14212478SCurtis.Dunham@arm.com return *this; 14312478SCurtis.Dunham@arm.com } 14412479SCurtis.Dunham@arm.com chain implemented(bool v = true) const { 14512479SCurtis.Dunham@arm.com info[MISCREG_IMPLEMENTED] = v; 14612479SCurtis.Dunham@arm.com return *this; 14712479SCurtis.Dunham@arm.com } 14812479SCurtis.Dunham@arm.com chain unimplemented() const { 14912479SCurtis.Dunham@arm.com return implemented(false); 15012479SCurtis.Dunham@arm.com } 15112479SCurtis.Dunham@arm.com chain unverifiable(bool v = true) const { 15212479SCurtis.Dunham@arm.com info[MISCREG_UNVERIFIABLE] = v; 15312479SCurtis.Dunham@arm.com return *this; 15412479SCurtis.Dunham@arm.com } 15512479SCurtis.Dunham@arm.com chain warnNotFail(bool v = true) const { 15612479SCurtis.Dunham@arm.com info[MISCREG_WARN_NOT_FAIL] = v; 15712479SCurtis.Dunham@arm.com return *this; 15812479SCurtis.Dunham@arm.com } 15912479SCurtis.Dunham@arm.com chain mutex(bool v = true) const { 16012479SCurtis.Dunham@arm.com info[MISCREG_MUTEX] = v; 16112479SCurtis.Dunham@arm.com return *this; 16212479SCurtis.Dunham@arm.com } 16312479SCurtis.Dunham@arm.com chain banked(bool v = true) const { 16412479SCurtis.Dunham@arm.com info[MISCREG_BANKED] = v; 16512479SCurtis.Dunham@arm.com return *this; 16612479SCurtis.Dunham@arm.com } 16712479SCurtis.Dunham@arm.com chain bankedChild(bool v = true) const { 16812479SCurtis.Dunham@arm.com info[MISCREG_BANKED_CHILD] = v; 16912479SCurtis.Dunham@arm.com return *this; 17012479SCurtis.Dunham@arm.com } 17112479SCurtis.Dunham@arm.com chain userNonSecureRead(bool v = true) const { 17212479SCurtis.Dunham@arm.com info[MISCREG_USR_NS_RD] = v; 17312479SCurtis.Dunham@arm.com return *this; 17412479SCurtis.Dunham@arm.com } 17512479SCurtis.Dunham@arm.com chain userNonSecureWrite(bool v = true) const { 17612479SCurtis.Dunham@arm.com info[MISCREG_USR_NS_WR] = v; 17712479SCurtis.Dunham@arm.com return *this; 17812479SCurtis.Dunham@arm.com } 17912479SCurtis.Dunham@arm.com chain userSecureRead(bool v = true) const { 18012479SCurtis.Dunham@arm.com info[MISCREG_USR_S_RD] = v; 18112479SCurtis.Dunham@arm.com return *this; 18212479SCurtis.Dunham@arm.com } 18312479SCurtis.Dunham@arm.com chain userSecureWrite(bool v = true) const { 18412479SCurtis.Dunham@arm.com info[MISCREG_USR_S_WR] = v; 18512479SCurtis.Dunham@arm.com return *this; 18612479SCurtis.Dunham@arm.com } 18712479SCurtis.Dunham@arm.com chain user(bool v = true) const { 18812479SCurtis.Dunham@arm.com userNonSecureRead(v); 18912479SCurtis.Dunham@arm.com userNonSecureWrite(v); 19012479SCurtis.Dunham@arm.com userSecureRead(v); 19112479SCurtis.Dunham@arm.com userSecureWrite(v); 19212479SCurtis.Dunham@arm.com return *this; 19312479SCurtis.Dunham@arm.com } 19412479SCurtis.Dunham@arm.com chain privNonSecureRead(bool v = true) const { 19512479SCurtis.Dunham@arm.com info[MISCREG_PRI_NS_RD] = v; 19612479SCurtis.Dunham@arm.com return *this; 19712479SCurtis.Dunham@arm.com } 19812479SCurtis.Dunham@arm.com chain privNonSecureWrite(bool v = true) const { 19912479SCurtis.Dunham@arm.com info[MISCREG_PRI_NS_WR] = v; 20012479SCurtis.Dunham@arm.com return *this; 20112479SCurtis.Dunham@arm.com } 20212479SCurtis.Dunham@arm.com chain privSecureRead(bool v = true) const { 20312479SCurtis.Dunham@arm.com info[MISCREG_PRI_S_RD] = v; 20412479SCurtis.Dunham@arm.com return *this; 20512479SCurtis.Dunham@arm.com } 20612479SCurtis.Dunham@arm.com chain privSecureWrite(bool v = true) const { 20712479SCurtis.Dunham@arm.com info[MISCREG_PRI_S_WR] = v; 20812479SCurtis.Dunham@arm.com return *this; 20912479SCurtis.Dunham@arm.com } 21012479SCurtis.Dunham@arm.com chain privSecure(bool v = true) const { 21112479SCurtis.Dunham@arm.com privSecureRead(v); 21212479SCurtis.Dunham@arm.com privSecureWrite(v); 21312479SCurtis.Dunham@arm.com return *this; 21412479SCurtis.Dunham@arm.com } 21512479SCurtis.Dunham@arm.com chain hypRead(bool v = true) const { 21612479SCurtis.Dunham@arm.com info[MISCREG_HYP_RD] = v; 21712479SCurtis.Dunham@arm.com return *this; 21812479SCurtis.Dunham@arm.com } 21912479SCurtis.Dunham@arm.com chain hypWrite(bool v = true) const { 22012479SCurtis.Dunham@arm.com info[MISCREG_HYP_WR] = v; 22112479SCurtis.Dunham@arm.com return *this; 22212479SCurtis.Dunham@arm.com } 22312479SCurtis.Dunham@arm.com chain hyp(bool v = true) const { 22412479SCurtis.Dunham@arm.com hypRead(v); 22512479SCurtis.Dunham@arm.com hypWrite(v); 22612479SCurtis.Dunham@arm.com return *this; 22712479SCurtis.Dunham@arm.com } 22812479SCurtis.Dunham@arm.com chain monSecureRead(bool v = true) const { 22912479SCurtis.Dunham@arm.com info[MISCREG_MON_NS0_RD] = v; 23012479SCurtis.Dunham@arm.com return *this; 23112479SCurtis.Dunham@arm.com } 23212479SCurtis.Dunham@arm.com chain monSecureWrite(bool v = true) const { 23312479SCurtis.Dunham@arm.com info[MISCREG_MON_NS0_WR] = v; 23412479SCurtis.Dunham@arm.com return *this; 23512479SCurtis.Dunham@arm.com } 23612479SCurtis.Dunham@arm.com chain monNonSecureRead(bool v = true) const { 23712479SCurtis.Dunham@arm.com info[MISCREG_MON_NS1_RD] = v; 23812479SCurtis.Dunham@arm.com return *this; 23912479SCurtis.Dunham@arm.com } 24012479SCurtis.Dunham@arm.com chain monNonSecureWrite(bool v = true) const { 24112479SCurtis.Dunham@arm.com info[MISCREG_MON_NS1_WR] = v; 24212479SCurtis.Dunham@arm.com return *this; 24312479SCurtis.Dunham@arm.com } 24412479SCurtis.Dunham@arm.com chain mon(bool v = true) const { 24512479SCurtis.Dunham@arm.com monSecureRead(v); 24612479SCurtis.Dunham@arm.com monSecureWrite(v); 24712479SCurtis.Dunham@arm.com monNonSecureRead(v); 24812479SCurtis.Dunham@arm.com monNonSecureWrite(v); 24912479SCurtis.Dunham@arm.com return *this; 25012479SCurtis.Dunham@arm.com } 25112479SCurtis.Dunham@arm.com chain monSecure(bool v = true) const { 25212479SCurtis.Dunham@arm.com monSecureRead(v); 25312479SCurtis.Dunham@arm.com monSecureWrite(v); 25412479SCurtis.Dunham@arm.com return *this; 25512479SCurtis.Dunham@arm.com } 25612479SCurtis.Dunham@arm.com chain monNonSecure(bool v = true) const { 25712479SCurtis.Dunham@arm.com monNonSecureRead(v); 25812479SCurtis.Dunham@arm.com monNonSecureWrite(v); 25912479SCurtis.Dunham@arm.com return *this; 26012479SCurtis.Dunham@arm.com } 26112479SCurtis.Dunham@arm.com chain allPrivileges(bool v = true) const { 26212479SCurtis.Dunham@arm.com userNonSecureRead(v); 26312479SCurtis.Dunham@arm.com userNonSecureWrite(v); 26412479SCurtis.Dunham@arm.com userSecureRead(v); 26512479SCurtis.Dunham@arm.com userSecureWrite(v); 26612479SCurtis.Dunham@arm.com privNonSecureRead(v); 26712479SCurtis.Dunham@arm.com privNonSecureWrite(v); 26812479SCurtis.Dunham@arm.com privSecureRead(v); 26912479SCurtis.Dunham@arm.com privSecureWrite(v); 27012479SCurtis.Dunham@arm.com hypRead(v); 27112479SCurtis.Dunham@arm.com hypWrite(v); 27212479SCurtis.Dunham@arm.com monSecureRead(v); 27312479SCurtis.Dunham@arm.com monSecureWrite(v); 27412479SCurtis.Dunham@arm.com monNonSecureRead(v); 27512479SCurtis.Dunham@arm.com monNonSecureWrite(v); 27612479SCurtis.Dunham@arm.com return *this; 27712479SCurtis.Dunham@arm.com } 27812479SCurtis.Dunham@arm.com chain nonSecure(bool v = true) const { 27912479SCurtis.Dunham@arm.com userNonSecureRead(v); 28012479SCurtis.Dunham@arm.com userNonSecureWrite(v); 28112479SCurtis.Dunham@arm.com privNonSecureRead(v); 28212479SCurtis.Dunham@arm.com privNonSecureWrite(v); 28312479SCurtis.Dunham@arm.com hypRead(v); 28412479SCurtis.Dunham@arm.com hypWrite(v); 28512479SCurtis.Dunham@arm.com monNonSecureRead(v); 28612479SCurtis.Dunham@arm.com monNonSecureWrite(v); 28712479SCurtis.Dunham@arm.com return *this; 28812479SCurtis.Dunham@arm.com } 28912479SCurtis.Dunham@arm.com chain secure(bool v = true) const { 29012479SCurtis.Dunham@arm.com userSecureRead(v); 29112479SCurtis.Dunham@arm.com userSecureWrite(v); 29212479SCurtis.Dunham@arm.com privSecureRead(v); 29312479SCurtis.Dunham@arm.com privSecureWrite(v); 29412479SCurtis.Dunham@arm.com monSecureRead(v); 29512479SCurtis.Dunham@arm.com monSecureWrite(v); 29612479SCurtis.Dunham@arm.com return *this; 29712479SCurtis.Dunham@arm.com } 29812479SCurtis.Dunham@arm.com chain reads(bool v) const { 29912479SCurtis.Dunham@arm.com userNonSecureRead(v); 30012479SCurtis.Dunham@arm.com userSecureRead(v); 30112479SCurtis.Dunham@arm.com privNonSecureRead(v); 30212479SCurtis.Dunham@arm.com privSecureRead(v); 30312479SCurtis.Dunham@arm.com hypRead(v); 30412479SCurtis.Dunham@arm.com monSecureRead(v); 30512479SCurtis.Dunham@arm.com monNonSecureRead(v); 30612479SCurtis.Dunham@arm.com return *this; 30712479SCurtis.Dunham@arm.com } 30812479SCurtis.Dunham@arm.com chain writes(bool v) const { 30912479SCurtis.Dunham@arm.com userNonSecureWrite(v); 31012479SCurtis.Dunham@arm.com userSecureWrite(v); 31112479SCurtis.Dunham@arm.com privNonSecureWrite(v); 31212479SCurtis.Dunham@arm.com privSecureWrite(v); 31312479SCurtis.Dunham@arm.com hypWrite(v); 31412479SCurtis.Dunham@arm.com monSecureWrite(v); 31512479SCurtis.Dunham@arm.com monNonSecureWrite(v); 31612479SCurtis.Dunham@arm.com return *this; 31712479SCurtis.Dunham@arm.com } 31812479SCurtis.Dunham@arm.com chain exceptUserMode() const { 31912479SCurtis.Dunham@arm.com user(0); 32012479SCurtis.Dunham@arm.com return *this; 32112479SCurtis.Dunham@arm.com } 32212479SCurtis.Dunham@arm.com MiscRegLUTEntryInitializer(struct MiscRegLUTEntry &e, 32312479SCurtis.Dunham@arm.com std::bitset<NUM_MISCREG_INFOS> &i) 32412479SCurtis.Dunham@arm.com : entry(e), 32512479SCurtis.Dunham@arm.com info(i) 32612479SCurtis.Dunham@arm.com { 32712479SCurtis.Dunham@arm.com // force unimplemented registers to be thusly declared 32812479SCurtis.Dunham@arm.com implemented(1); 32912479SCurtis.Dunham@arm.com } 33010037SARM gem5 Developers }; 33110037SARM gem5 Developers 33212477SCurtis.Dunham@arm.com const MiscRegLUTEntryInitializer InitReg(uint32_t reg) { 33312479SCurtis.Dunham@arm.com return MiscRegLUTEntryInitializer(lookUpMiscReg[reg], 33412479SCurtis.Dunham@arm.com miscRegInfo[reg]); 33512477SCurtis.Dunham@arm.com } 33610037SARM gem5 Developers 33712477SCurtis.Dunham@arm.com void initializeMiscRegMetadata(); 33810037SARM gem5 Developers 3396333Sgblack@eecs.umich.edu MiscReg miscRegs[NumMiscRegs]; 3406718Sgblack@eecs.umich.edu const IntRegIndex *intRegMap; 3416718Sgblack@eecs.umich.edu 3426718Sgblack@eecs.umich.edu void 3436718Sgblack@eecs.umich.edu updateRegMap(CPSR cpsr) 3446718Sgblack@eecs.umich.edu { 34510037SARM gem5 Developers if (cpsr.width == 0) { 34610037SARM gem5 Developers intRegMap = IntReg64Map; 34710037SARM gem5 Developers } else { 34810037SARM gem5 Developers switch (cpsr.mode) { 34910037SARM gem5 Developers case MODE_USER: 35010037SARM gem5 Developers case MODE_SYSTEM: 35110037SARM gem5 Developers intRegMap = IntRegUsrMap; 35210037SARM gem5 Developers break; 35310037SARM gem5 Developers case MODE_FIQ: 35410037SARM gem5 Developers intRegMap = IntRegFiqMap; 35510037SARM gem5 Developers break; 35610037SARM gem5 Developers case MODE_IRQ: 35710037SARM gem5 Developers intRegMap = IntRegIrqMap; 35810037SARM gem5 Developers break; 35910037SARM gem5 Developers case MODE_SVC: 36010037SARM gem5 Developers intRegMap = IntRegSvcMap; 36110037SARM gem5 Developers break; 36210037SARM gem5 Developers case MODE_MON: 36310037SARM gem5 Developers intRegMap = IntRegMonMap; 36410037SARM gem5 Developers break; 36510037SARM gem5 Developers case MODE_ABORT: 36610037SARM gem5 Developers intRegMap = IntRegAbtMap; 36710037SARM gem5 Developers break; 36810037SARM gem5 Developers case MODE_HYP: 36910037SARM gem5 Developers intRegMap = IntRegHypMap; 37010037SARM gem5 Developers break; 37110037SARM gem5 Developers case MODE_UNDEFINED: 37210037SARM gem5 Developers intRegMap = IntRegUndMap; 37310037SARM gem5 Developers break; 37410037SARM gem5 Developers default: 37510037SARM gem5 Developers panic("Unrecognized mode setting in CPSR.\n"); 37610037SARM gem5 Developers } 3776718Sgblack@eecs.umich.edu } 3786718Sgblack@eecs.umich.edu } 3796313Sgblack@eecs.umich.edu 38010844Sandreas.sandberg@arm.com BaseISADevice &getGenericTimer(ThreadContext *tc); 38110037SARM gem5 Developers 38210037SARM gem5 Developers 38310037SARM gem5 Developers private: 38410037SARM gem5 Developers inline void assert32(ThreadContext *tc) { 38510037SARM gem5 Developers CPSR cpsr M5_VAR_USED = readMiscReg(MISCREG_CPSR, tc); 38610037SARM gem5 Developers assert(cpsr.width); 38710037SARM gem5 Developers } 38810037SARM gem5 Developers 38910037SARM gem5 Developers inline void assert64(ThreadContext *tc) { 39010037SARM gem5 Developers CPSR cpsr M5_VAR_USED = readMiscReg(MISCREG_CPSR, tc); 39110037SARM gem5 Developers assert(!cpsr.width); 39210037SARM gem5 Developers } 39310037SARM gem5 Developers 39410709SAndreas.Sandberg@ARM.com void tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid, 39510037SARM gem5 Developers bool secure_lookup, uint8_t target_el); 39610037SARM gem5 Developers 39710037SARM gem5 Developers void tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el); 39810037SARM gem5 Developers 39910037SARM gem5 Developers void tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el); 40010037SARM gem5 Developers 40110037SARM gem5 Developers void tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup, 40210037SARM gem5 Developers bool hyp, uint8_t target_el); 40310037SARM gem5 Developers 4046313Sgblack@eecs.umich.edu public: 4057427Sgblack@eecs.umich.edu void clear(); 40610037SARM gem5 Developers void clear64(const ArmISAParams *p); 4076313Sgblack@eecs.umich.edu 40810035Sandreas.hansson@arm.com MiscReg readMiscRegNoEffect(int misc_reg) const; 4097405SAli.Saidi@ARM.com MiscReg readMiscReg(int misc_reg, ThreadContext *tc); 4107405SAli.Saidi@ARM.com void setMiscRegNoEffect(int misc_reg, const MiscReg &val); 4117405SAli.Saidi@ARM.com void setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc); 4126313Sgblack@eecs.umich.edu 41312106SRekai.GonzalezAlberquilla@arm.com RegId 41412106SRekai.GonzalezAlberquilla@arm.com flattenRegId(const RegId& regId) const 41512106SRekai.GonzalezAlberquilla@arm.com { 41612106SRekai.GonzalezAlberquilla@arm.com switch (regId.classValue()) { 41712106SRekai.GonzalezAlberquilla@arm.com case IntRegClass: 41812106SRekai.GonzalezAlberquilla@arm.com return RegId(IntRegClass, flattenIntIndex(regId.index())); 41912106SRekai.GonzalezAlberquilla@arm.com case FloatRegClass: 42012106SRekai.GonzalezAlberquilla@arm.com return RegId(FloatRegClass, flattenFloatIndex(regId.index())); 42112109SRekai.GonzalezAlberquilla@arm.com case VecRegClass: 42212109SRekai.GonzalezAlberquilla@arm.com return RegId(VecRegClass, flattenVecIndex(regId.index())); 42312109SRekai.GonzalezAlberquilla@arm.com case VecElemClass: 42412109SRekai.GonzalezAlberquilla@arm.com return RegId(VecElemClass, flattenVecElemIndex(regId.index())); 42512106SRekai.GonzalezAlberquilla@arm.com case CCRegClass: 42612106SRekai.GonzalezAlberquilla@arm.com return RegId(CCRegClass, flattenCCIndex(regId.index())); 42712106SRekai.GonzalezAlberquilla@arm.com case MiscRegClass: 42812106SRekai.GonzalezAlberquilla@arm.com return RegId(MiscRegClass, flattenMiscIndex(regId.index())); 42912106SRekai.GonzalezAlberquilla@arm.com } 43012106SRekai.GonzalezAlberquilla@arm.com return RegId(); 43112106SRekai.GonzalezAlberquilla@arm.com } 43212106SRekai.GonzalezAlberquilla@arm.com 4336313Sgblack@eecs.umich.edu int 43410035Sandreas.hansson@arm.com flattenIntIndex(int reg) const 4356313Sgblack@eecs.umich.edu { 4366718Sgblack@eecs.umich.edu assert(reg >= 0); 4376718Sgblack@eecs.umich.edu if (reg < NUM_ARCH_INTREGS) { 4386718Sgblack@eecs.umich.edu return intRegMap[reg]; 4396726Sgblack@eecs.umich.edu } else if (reg < NUM_INTREGS) { 4406726Sgblack@eecs.umich.edu return reg; 44110037SARM gem5 Developers } else if (reg == INTREG_SPX) { 44210037SARM gem5 Developers CPSR cpsr = miscRegs[MISCREG_CPSR]; 44310037SARM gem5 Developers ExceptionLevel el = opModeToEL( 44410037SARM gem5 Developers (OperatingMode) (uint8_t) cpsr.mode); 44510037SARM gem5 Developers if (!cpsr.sp && el != EL0) 44610037SARM gem5 Developers return INTREG_SP0; 44710037SARM gem5 Developers switch (el) { 44810037SARM gem5 Developers case EL3: 44910037SARM gem5 Developers return INTREG_SP3; 45011574SCurtis.Dunham@arm.com case EL2: 45111574SCurtis.Dunham@arm.com return INTREG_SP2; 45210037SARM gem5 Developers case EL1: 45310037SARM gem5 Developers return INTREG_SP1; 45410037SARM gem5 Developers case EL0: 45510037SARM gem5 Developers return INTREG_SP0; 45610037SARM gem5 Developers default: 45710037SARM gem5 Developers panic("Invalid exception level"); 45810037SARM gem5 Developers break; 45910037SARM gem5 Developers } 4606718Sgblack@eecs.umich.edu } else { 46110037SARM gem5 Developers return flattenIntRegModeIndex(reg); 4626718Sgblack@eecs.umich.edu } 4636313Sgblack@eecs.umich.edu } 4646313Sgblack@eecs.umich.edu 4656313Sgblack@eecs.umich.edu int 46610035Sandreas.hansson@arm.com flattenFloatIndex(int reg) const 4676313Sgblack@eecs.umich.edu { 46810338SCurtis.Dunham@arm.com assert(reg >= 0); 4696313Sgblack@eecs.umich.edu return reg; 4706313Sgblack@eecs.umich.edu } 4716313Sgblack@eecs.umich.edu 4729920Syasuko.eckert@amd.com int 47312109SRekai.GonzalezAlberquilla@arm.com flattenVecIndex(int reg) const 47412109SRekai.GonzalezAlberquilla@arm.com { 47512109SRekai.GonzalezAlberquilla@arm.com assert(reg >= 0); 47612109SRekai.GonzalezAlberquilla@arm.com return reg; 47712109SRekai.GonzalezAlberquilla@arm.com } 47812109SRekai.GonzalezAlberquilla@arm.com 47912109SRekai.GonzalezAlberquilla@arm.com int 48012109SRekai.GonzalezAlberquilla@arm.com flattenVecElemIndex(int reg) const 48112109SRekai.GonzalezAlberquilla@arm.com { 48212109SRekai.GonzalezAlberquilla@arm.com assert(reg >= 0); 48312109SRekai.GonzalezAlberquilla@arm.com return reg; 48412109SRekai.GonzalezAlberquilla@arm.com } 48512109SRekai.GonzalezAlberquilla@arm.com 48612109SRekai.GonzalezAlberquilla@arm.com int 48710035Sandreas.hansson@arm.com flattenCCIndex(int reg) const 4889920Syasuko.eckert@amd.com { 48910338SCurtis.Dunham@arm.com assert(reg >= 0); 4909920Syasuko.eckert@amd.com return reg; 4919920Syasuko.eckert@amd.com } 4929920Syasuko.eckert@amd.com 4937614Sminkyu.jeong@arm.com int 49410035Sandreas.hansson@arm.com flattenMiscIndex(int reg) const 4957614Sminkyu.jeong@arm.com { 49610338SCurtis.Dunham@arm.com assert(reg >= 0); 49710037SARM gem5 Developers int flat_idx = reg; 49810037SARM gem5 Developers 4997614Sminkyu.jeong@arm.com if (reg == MISCREG_SPSR) { 5007614Sminkyu.jeong@arm.com CPSR cpsr = miscRegs[MISCREG_CPSR]; 5017614Sminkyu.jeong@arm.com switch (cpsr.mode) { 50210037SARM gem5 Developers case MODE_EL0T: 50310037SARM gem5 Developers warn("User mode does not have SPSR\n"); 50410037SARM gem5 Developers flat_idx = MISCREG_SPSR; 50510037SARM gem5 Developers break; 50610037SARM gem5 Developers case MODE_EL1T: 50710037SARM gem5 Developers case MODE_EL1H: 50810037SARM gem5 Developers flat_idx = MISCREG_SPSR_EL1; 50910037SARM gem5 Developers break; 51010037SARM gem5 Developers case MODE_EL2T: 51110037SARM gem5 Developers case MODE_EL2H: 51210037SARM gem5 Developers flat_idx = MISCREG_SPSR_EL2; 51310037SARM gem5 Developers break; 51410037SARM gem5 Developers case MODE_EL3T: 51510037SARM gem5 Developers case MODE_EL3H: 51610037SARM gem5 Developers flat_idx = MISCREG_SPSR_EL3; 51710037SARM gem5 Developers break; 5187614Sminkyu.jeong@arm.com case MODE_USER: 5197614Sminkyu.jeong@arm.com warn("User mode does not have SPSR\n"); 52010037SARM gem5 Developers flat_idx = MISCREG_SPSR; 5217614Sminkyu.jeong@arm.com break; 5227614Sminkyu.jeong@arm.com case MODE_FIQ: 52310037SARM gem5 Developers flat_idx = MISCREG_SPSR_FIQ; 5247614Sminkyu.jeong@arm.com break; 5257614Sminkyu.jeong@arm.com case MODE_IRQ: 52610037SARM gem5 Developers flat_idx = MISCREG_SPSR_IRQ; 5277614Sminkyu.jeong@arm.com break; 5287614Sminkyu.jeong@arm.com case MODE_SVC: 52910037SARM gem5 Developers flat_idx = MISCREG_SPSR_SVC; 5307614Sminkyu.jeong@arm.com break; 5317614Sminkyu.jeong@arm.com case MODE_MON: 53210037SARM gem5 Developers flat_idx = MISCREG_SPSR_MON; 5337614Sminkyu.jeong@arm.com break; 5347614Sminkyu.jeong@arm.com case MODE_ABORT: 53510037SARM gem5 Developers flat_idx = MISCREG_SPSR_ABT; 53610037SARM gem5 Developers break; 53710037SARM gem5 Developers case MODE_HYP: 53810037SARM gem5 Developers flat_idx = MISCREG_SPSR_HYP; 5397614Sminkyu.jeong@arm.com break; 5407614Sminkyu.jeong@arm.com case MODE_UNDEFINED: 54110037SARM gem5 Developers flat_idx = MISCREG_SPSR_UND; 5427614Sminkyu.jeong@arm.com break; 5437614Sminkyu.jeong@arm.com default: 5447614Sminkyu.jeong@arm.com warn("Trying to access SPSR in an invalid mode: %d\n", 5457614Sminkyu.jeong@arm.com cpsr.mode); 54610037SARM gem5 Developers flat_idx = MISCREG_SPSR; 5477614Sminkyu.jeong@arm.com break; 5487614Sminkyu.jeong@arm.com } 54910037SARM gem5 Developers } else if (miscRegInfo[reg][MISCREG_MUTEX]) { 55010037SARM gem5 Developers // Mutually exclusive CP15 register 55110037SARM gem5 Developers switch (reg) { 55210037SARM gem5 Developers case MISCREG_PRRR_MAIR0: 55310037SARM gem5 Developers case MISCREG_PRRR_MAIR0_NS: 55410037SARM gem5 Developers case MISCREG_PRRR_MAIR0_S: 55510037SARM gem5 Developers { 55610037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 55710037SARM gem5 Developers // If the muxed reg has been flattened, work out the 55810037SARM gem5 Developers // offset and apply it to the unmuxed reg 55910037SARM gem5 Developers int idxOffset = reg - MISCREG_PRRR_MAIR0; 56010037SARM gem5 Developers if (ttbcr.eae) 56110037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_MAIR0 + 56210037SARM gem5 Developers idxOffset); 56310037SARM gem5 Developers else 56410037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_PRRR + 56510037SARM gem5 Developers idxOffset); 56610037SARM gem5 Developers } 56710037SARM gem5 Developers break; 56810037SARM gem5 Developers case MISCREG_NMRR_MAIR1: 56910037SARM gem5 Developers case MISCREG_NMRR_MAIR1_NS: 57010037SARM gem5 Developers case MISCREG_NMRR_MAIR1_S: 57110037SARM gem5 Developers { 57210037SARM gem5 Developers TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR); 57310037SARM gem5 Developers // If the muxed reg has been flattened, work out the 57410037SARM gem5 Developers // offset and apply it to the unmuxed reg 57510037SARM gem5 Developers int idxOffset = reg - MISCREG_NMRR_MAIR1; 57610037SARM gem5 Developers if (ttbcr.eae) 57710037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_MAIR1 + 57810037SARM gem5 Developers idxOffset); 57910037SARM gem5 Developers else 58010037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_NMRR + 58110037SARM gem5 Developers idxOffset); 58210037SARM gem5 Developers } 58310037SARM gem5 Developers break; 58410037SARM gem5 Developers case MISCREG_PMXEVTYPER_PMCCFILTR: 58510037SARM gem5 Developers { 58610037SARM gem5 Developers PMSELR pmselr = miscRegs[MISCREG_PMSELR]; 58710037SARM gem5 Developers if (pmselr.sel == 31) 58810037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_PMCCFILTR); 58910037SARM gem5 Developers else 59010037SARM gem5 Developers flat_idx = flattenMiscIndex(MISCREG_PMXEVTYPER); 59110037SARM gem5 Developers } 59210037SARM gem5 Developers break; 59310037SARM gem5 Developers default: 59410037SARM gem5 Developers panic("Unrecognized misc. register.\n"); 59510037SARM gem5 Developers break; 59610037SARM gem5 Developers } 59710037SARM gem5 Developers } else { 59810037SARM gem5 Developers if (miscRegInfo[reg][MISCREG_BANKED]) { 59911771SCurtis.Dunham@arm.com bool secureReg = haveSecurity && !highestELIs64 && 60010037SARM gem5 Developers inSecureState(miscRegs[MISCREG_SCR], 60110037SARM gem5 Developers miscRegs[MISCREG_CPSR]); 60210037SARM gem5 Developers flat_idx += secureReg ? 2 : 1; 60310037SARM gem5 Developers } 6047614Sminkyu.jeong@arm.com } 60510037SARM gem5 Developers return flat_idx; 6067614Sminkyu.jeong@arm.com } 6077614Sminkyu.jeong@arm.com 60811771SCurtis.Dunham@arm.com std::pair<int,int> getMiscIndices(int misc_reg) const 60911771SCurtis.Dunham@arm.com { 61011771SCurtis.Dunham@arm.com // Note: indexes of AArch64 registers are left unchanged 61111771SCurtis.Dunham@arm.com int flat_idx = flattenMiscIndex(misc_reg); 61211771SCurtis.Dunham@arm.com 61311771SCurtis.Dunham@arm.com if (lookUpMiscReg[flat_idx].lower == 0) { 61411771SCurtis.Dunham@arm.com return std::make_pair(flat_idx, 0); 61511771SCurtis.Dunham@arm.com } 61611771SCurtis.Dunham@arm.com 61711771SCurtis.Dunham@arm.com // do additional S/NS flattenings if mapped to NS while in S 61811771SCurtis.Dunham@arm.com bool S = haveSecurity && !highestELIs64 && 61911771SCurtis.Dunham@arm.com inSecureState(miscRegs[MISCREG_SCR], 62011771SCurtis.Dunham@arm.com miscRegs[MISCREG_CPSR]); 62111771SCurtis.Dunham@arm.com int lower = lookUpMiscReg[flat_idx].lower; 62211771SCurtis.Dunham@arm.com int upper = lookUpMiscReg[flat_idx].upper; 62311771SCurtis.Dunham@arm.com // upper == 0, which is CPSR, is not MISCREG_BANKED_CHILD (no-op) 62411771SCurtis.Dunham@arm.com lower += S && miscRegInfo[lower][MISCREG_BANKED_CHILD]; 62511771SCurtis.Dunham@arm.com upper += S && miscRegInfo[upper][MISCREG_BANKED_CHILD]; 62611771SCurtis.Dunham@arm.com return std::make_pair(lower, upper); 62711771SCurtis.Dunham@arm.com } 62811771SCurtis.Dunham@arm.com 62910905Sandreas.sandberg@arm.com void serialize(CheckpointOut &cp) const 6307733SAli.Saidi@ARM.com { 6317733SAli.Saidi@ARM.com DPRINTF(Checkpoint, "Serializing Arm Misc Registers\n"); 6327733SAli.Saidi@ARM.com SERIALIZE_ARRAY(miscRegs, NumMiscRegs); 63310037SARM gem5 Developers 63411771SCurtis.Dunham@arm.com SERIALIZE_SCALAR(highestELIs64); 63510037SARM gem5 Developers SERIALIZE_SCALAR(haveSecurity); 63610037SARM gem5 Developers SERIALIZE_SCALAR(haveLPAE); 63710037SARM gem5 Developers SERIALIZE_SCALAR(haveVirtualization); 63810037SARM gem5 Developers SERIALIZE_SCALAR(haveLargeAsid64); 63910037SARM gem5 Developers SERIALIZE_SCALAR(physAddrRange64); 6407733SAli.Saidi@ARM.com } 64110905Sandreas.sandberg@arm.com void unserialize(CheckpointIn &cp) 6427733SAli.Saidi@ARM.com { 6437733SAli.Saidi@ARM.com DPRINTF(Checkpoint, "Unserializing Arm Misc Registers\n"); 6447733SAli.Saidi@ARM.com UNSERIALIZE_ARRAY(miscRegs, NumMiscRegs); 6457733SAli.Saidi@ARM.com CPSR tmp_cpsr = miscRegs[MISCREG_CPSR]; 6467733SAli.Saidi@ARM.com updateRegMap(tmp_cpsr); 64710037SARM gem5 Developers 64811771SCurtis.Dunham@arm.com UNSERIALIZE_SCALAR(highestELIs64); 64910037SARM gem5 Developers UNSERIALIZE_SCALAR(haveSecurity); 65010037SARM gem5 Developers UNSERIALIZE_SCALAR(haveLPAE); 65110037SARM gem5 Developers UNSERIALIZE_SCALAR(haveVirtualization); 65210037SARM gem5 Developers UNSERIALIZE_SCALAR(haveLargeAsid64); 65310037SARM gem5 Developers UNSERIALIZE_SCALAR(physAddrRange64); 6547733SAli.Saidi@ARM.com } 6556313Sgblack@eecs.umich.edu 6569461Snilay@cs.wisc.edu void startup(ThreadContext *tc) {} 6579461Snilay@cs.wisc.edu 65811165SRekai.GonzalezAlberquilla@arm.com Enums::DecoderFlavour decoderFlavour() const { return _decoderFlavour; } 65911165SRekai.GonzalezAlberquilla@arm.com 66012109SRekai.GonzalezAlberquilla@arm.com Enums::VecRegRenameMode 66112109SRekai.GonzalezAlberquilla@arm.com vecRegRenameMode() const 66212109SRekai.GonzalezAlberquilla@arm.com { 66312109SRekai.GonzalezAlberquilla@arm.com return _vecRegRenameMode; 66412109SRekai.GonzalezAlberquilla@arm.com } 66512109SRekai.GonzalezAlberquilla@arm.com 6669553Sandreas.hansson@arm.com /// Explicitly import the otherwise hidden startup 6679553Sandreas.hansson@arm.com using SimObject::startup; 6689553Sandreas.hansson@arm.com 6699384SAndreas.Sandberg@arm.com typedef ArmISAParams Params; 6707400SAli.Saidi@ARM.com 6719384SAndreas.Sandberg@arm.com const Params *params() const; 6729384SAndreas.Sandberg@arm.com 6739384SAndreas.Sandberg@arm.com ISA(Params *p); 6746313Sgblack@eecs.umich.edu }; 6756313Sgblack@eecs.umich.edu} 6766313Sgblack@eecs.umich.edu 67712109SRekai.GonzalezAlberquilla@arm.comtemplate<> 67812109SRekai.GonzalezAlberquilla@arm.comstruct initRenameMode<ArmISA::ISA> 67912109SRekai.GonzalezAlberquilla@arm.com{ 68012109SRekai.GonzalezAlberquilla@arm.com static Enums::VecRegRenameMode mode(const ArmISA::ISA* isa) 68112109SRekai.GonzalezAlberquilla@arm.com { 68212109SRekai.GonzalezAlberquilla@arm.com return isa->vecRegRenameMode(); 68312109SRekai.GonzalezAlberquilla@arm.com } 68412109SRekai.GonzalezAlberquilla@arm.com static bool equals(const ArmISA::ISA* isa1, const ArmISA::ISA* isa2) 68512109SRekai.GonzalezAlberquilla@arm.com { 68612109SRekai.GonzalezAlberquilla@arm.com return mode(isa1) == mode(isa2); 68712109SRekai.GonzalezAlberquilla@arm.com } 68812109SRekai.GonzalezAlberquilla@arm.com}; 68912109SRekai.GonzalezAlberquilla@arm.com 6906313Sgblack@eecs.umich.edu#endif 691