isa.hh revision 12109
16313Sgblack@eecs.umich.edu/*
211574SCurtis.Dunham@arm.com * Copyright (c) 2010, 2012-2016 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"
476333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh"
4810037SARM gem5 Developers#include "arch/arm/system.hh"
497404SAli.Saidi@ARM.com#include "arch/arm/tlb.hh"
506313Sgblack@eecs.umich.edu#include "arch/arm/types.hh"
5112109SRekai.GonzalezAlberquilla@arm.com#include "arch/generic/traits.hh"
528232Snate@binkert.org#include "debug/Checkpoint.hh"
5312109SRekai.GonzalezAlberquilla@arm.com#include "enums/VecRegRenameMode.hh"
549384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh"
5511165SRekai.GonzalezAlberquilla@arm.com#include "enums/DecoderFlavour.hh"
566313Sgblack@eecs.umich.edu
579384SAndreas.Sandberg@arm.comstruct ArmISAParams;
5810461SAndreas.Sandberg@ARM.comstruct DummyArmISADeviceParams;
596333Sgblack@eecs.umich.educlass ThreadContext;
606313Sgblack@eecs.umich.educlass Checkpoint;
616313Sgblack@eecs.umich.educlass EventManager;
626313Sgblack@eecs.umich.edu
636313Sgblack@eecs.umich.edunamespace ArmISA
646313Sgblack@eecs.umich.edu{
659384SAndreas.Sandberg@arm.com    class ISA : public SimObject
666313Sgblack@eecs.umich.edu    {
676313Sgblack@eecs.umich.edu      protected:
6810037SARM gem5 Developers        // Parent system
6910037SARM gem5 Developers        ArmSystem *system;
7010037SARM gem5 Developers
7111165SRekai.GonzalezAlberquilla@arm.com        // Micro Architecture
7211165SRekai.GonzalezAlberquilla@arm.com        const Enums::DecoderFlavour _decoderFlavour;
7312109SRekai.GonzalezAlberquilla@arm.com        const Enums::VecRegRenameMode _vecRegRenameMode;
7411165SRekai.GonzalezAlberquilla@arm.com
7510461SAndreas.Sandberg@ARM.com        /** Dummy device for to handle non-existing ISA devices */
7610461SAndreas.Sandberg@ARM.com        DummyISADevice dummyDevice;
7710461SAndreas.Sandberg@ARM.com
7810461SAndreas.Sandberg@ARM.com        // PMU belonging to this ISA
7910461SAndreas.Sandberg@ARM.com        BaseISADevice *pmu;
8010461SAndreas.Sandberg@ARM.com
8110844Sandreas.sandberg@arm.com        // Generic timer interface belonging to this ISA
8210844Sandreas.sandberg@arm.com        std::unique_ptr<BaseISADevice> timer;
8310844Sandreas.sandberg@arm.com
8410037SARM gem5 Developers        // Cached copies of system-level properties
8511771SCurtis.Dunham@arm.com        bool highestELIs64;
8610037SARM gem5 Developers        bool haveSecurity;
8710037SARM gem5 Developers        bool haveLPAE;
8810037SARM gem5 Developers        bool haveVirtualization;
8910037SARM gem5 Developers        bool haveLargeAsid64;
9010037SARM gem5 Developers        uint8_t physAddrRange64;
9110037SARM gem5 Developers
9210037SARM gem5 Developers        /** Register translation entry used in lookUpMiscReg */
9310037SARM gem5 Developers        struct MiscRegLUTEntry {
9410037SARM gem5 Developers            uint32_t lower;
9510037SARM gem5 Developers            uint32_t upper;
9610037SARM gem5 Developers        };
9710037SARM gem5 Developers
9810037SARM gem5 Developers        struct MiscRegInitializerEntry {
9910037SARM gem5 Developers            uint32_t index;
10010037SARM gem5 Developers            struct MiscRegLUTEntry entry;
10110037SARM gem5 Developers        };
10210037SARM gem5 Developers
10310037SARM gem5 Developers        /** Register table noting all translations */
10411768SCurtis.Dunham@arm.com        static const struct MiscRegInitializerEntry MiscRegSwitch[];
10510037SARM gem5 Developers
10610037SARM gem5 Developers        /** Translation table accessible via the value of the register */
10710037SARM gem5 Developers        std::vector<struct MiscRegLUTEntry> lookUpMiscReg;
10810037SARM gem5 Developers
1096333Sgblack@eecs.umich.edu        MiscReg miscRegs[NumMiscRegs];
1106718Sgblack@eecs.umich.edu        const IntRegIndex *intRegMap;
1116718Sgblack@eecs.umich.edu
1126718Sgblack@eecs.umich.edu        void
1136718Sgblack@eecs.umich.edu        updateRegMap(CPSR cpsr)
1146718Sgblack@eecs.umich.edu        {
11510037SARM gem5 Developers            if (cpsr.width == 0) {
11610037SARM gem5 Developers                intRegMap = IntReg64Map;
11710037SARM gem5 Developers            } else {
11810037SARM gem5 Developers                switch (cpsr.mode) {
11910037SARM gem5 Developers                  case MODE_USER:
12010037SARM gem5 Developers                  case MODE_SYSTEM:
12110037SARM gem5 Developers                    intRegMap = IntRegUsrMap;
12210037SARM gem5 Developers                    break;
12310037SARM gem5 Developers                  case MODE_FIQ:
12410037SARM gem5 Developers                    intRegMap = IntRegFiqMap;
12510037SARM gem5 Developers                    break;
12610037SARM gem5 Developers                  case MODE_IRQ:
12710037SARM gem5 Developers                    intRegMap = IntRegIrqMap;
12810037SARM gem5 Developers                    break;
12910037SARM gem5 Developers                  case MODE_SVC:
13010037SARM gem5 Developers                    intRegMap = IntRegSvcMap;
13110037SARM gem5 Developers                    break;
13210037SARM gem5 Developers                  case MODE_MON:
13310037SARM gem5 Developers                    intRegMap = IntRegMonMap;
13410037SARM gem5 Developers                    break;
13510037SARM gem5 Developers                  case MODE_ABORT:
13610037SARM gem5 Developers                    intRegMap = IntRegAbtMap;
13710037SARM gem5 Developers                    break;
13810037SARM gem5 Developers                  case MODE_HYP:
13910037SARM gem5 Developers                    intRegMap = IntRegHypMap;
14010037SARM gem5 Developers                    break;
14110037SARM gem5 Developers                  case MODE_UNDEFINED:
14210037SARM gem5 Developers                    intRegMap = IntRegUndMap;
14310037SARM gem5 Developers                    break;
14410037SARM gem5 Developers                  default:
14510037SARM gem5 Developers                    panic("Unrecognized mode setting in CPSR.\n");
14610037SARM gem5 Developers                }
1476718Sgblack@eecs.umich.edu            }
1486718Sgblack@eecs.umich.edu        }
1496313Sgblack@eecs.umich.edu
15010844Sandreas.sandberg@arm.com        BaseISADevice &getGenericTimer(ThreadContext *tc);
15110037SARM gem5 Developers
15210037SARM gem5 Developers
15310037SARM gem5 Developers      private:
15410037SARM gem5 Developers        inline void assert32(ThreadContext *tc) {
15510037SARM gem5 Developers            CPSR cpsr M5_VAR_USED = readMiscReg(MISCREG_CPSR, tc);
15610037SARM gem5 Developers            assert(cpsr.width);
15710037SARM gem5 Developers        }
15810037SARM gem5 Developers
15910037SARM gem5 Developers        inline void assert64(ThreadContext *tc) {
16010037SARM gem5 Developers            CPSR cpsr M5_VAR_USED = readMiscReg(MISCREG_CPSR, tc);
16110037SARM gem5 Developers            assert(!cpsr.width);
16210037SARM gem5 Developers        }
16310037SARM gem5 Developers
16410709SAndreas.Sandberg@ARM.com        void tlbiVA(ThreadContext *tc, MiscReg newVal, uint16_t asid,
16510037SARM gem5 Developers                    bool secure_lookup, uint8_t target_el);
16610037SARM gem5 Developers
16710037SARM gem5 Developers        void tlbiALL(ThreadContext *tc, bool secure_lookup, uint8_t target_el);
16810037SARM gem5 Developers
16910037SARM gem5 Developers        void tlbiALLN(ThreadContext *tc, bool hyp, uint8_t target_el);
17010037SARM gem5 Developers
17110037SARM gem5 Developers        void tlbiMVA(ThreadContext *tc, MiscReg newVal, bool secure_lookup,
17210037SARM gem5 Developers                     bool hyp, uint8_t target_el);
17310037SARM gem5 Developers
1746313Sgblack@eecs.umich.edu      public:
1757427Sgblack@eecs.umich.edu        void clear();
17610037SARM gem5 Developers        void clear64(const ArmISAParams *p);
1776313Sgblack@eecs.umich.edu
17810035Sandreas.hansson@arm.com        MiscReg readMiscRegNoEffect(int misc_reg) const;
1797405SAli.Saidi@ARM.com        MiscReg readMiscReg(int misc_reg, ThreadContext *tc);
1807405SAli.Saidi@ARM.com        void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
1817405SAli.Saidi@ARM.com        void setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc);
1826313Sgblack@eecs.umich.edu
18312106SRekai.GonzalezAlberquilla@arm.com        RegId
18412106SRekai.GonzalezAlberquilla@arm.com        flattenRegId(const RegId& regId) const
18512106SRekai.GonzalezAlberquilla@arm.com        {
18612106SRekai.GonzalezAlberquilla@arm.com            switch (regId.classValue()) {
18712106SRekai.GonzalezAlberquilla@arm.com              case IntRegClass:
18812106SRekai.GonzalezAlberquilla@arm.com                return RegId(IntRegClass, flattenIntIndex(regId.index()));
18912106SRekai.GonzalezAlberquilla@arm.com              case FloatRegClass:
19012106SRekai.GonzalezAlberquilla@arm.com                return RegId(FloatRegClass, flattenFloatIndex(regId.index()));
19112109SRekai.GonzalezAlberquilla@arm.com              case VecRegClass:
19212109SRekai.GonzalezAlberquilla@arm.com                return RegId(VecRegClass, flattenVecIndex(regId.index()));
19312109SRekai.GonzalezAlberquilla@arm.com              case VecElemClass:
19412109SRekai.GonzalezAlberquilla@arm.com                return RegId(VecElemClass, flattenVecElemIndex(regId.index()));
19512106SRekai.GonzalezAlberquilla@arm.com              case CCRegClass:
19612106SRekai.GonzalezAlberquilla@arm.com                return RegId(CCRegClass, flattenCCIndex(regId.index()));
19712106SRekai.GonzalezAlberquilla@arm.com              case MiscRegClass:
19812106SRekai.GonzalezAlberquilla@arm.com                return RegId(MiscRegClass, flattenMiscIndex(regId.index()));
19912106SRekai.GonzalezAlberquilla@arm.com            }
20012106SRekai.GonzalezAlberquilla@arm.com            return RegId();
20112106SRekai.GonzalezAlberquilla@arm.com        }
20212106SRekai.GonzalezAlberquilla@arm.com
2036313Sgblack@eecs.umich.edu        int
20410035Sandreas.hansson@arm.com        flattenIntIndex(int reg) const
2056313Sgblack@eecs.umich.edu        {
2066718Sgblack@eecs.umich.edu            assert(reg >= 0);
2076718Sgblack@eecs.umich.edu            if (reg < NUM_ARCH_INTREGS) {
2086718Sgblack@eecs.umich.edu                return intRegMap[reg];
2096726Sgblack@eecs.umich.edu            } else if (reg < NUM_INTREGS) {
2106726Sgblack@eecs.umich.edu                return reg;
21110037SARM gem5 Developers            } else if (reg == INTREG_SPX) {
21210037SARM gem5 Developers                CPSR cpsr = miscRegs[MISCREG_CPSR];
21310037SARM gem5 Developers                ExceptionLevel el = opModeToEL(
21410037SARM gem5 Developers                    (OperatingMode) (uint8_t) cpsr.mode);
21510037SARM gem5 Developers                if (!cpsr.sp && el != EL0)
21610037SARM gem5 Developers                    return INTREG_SP0;
21710037SARM gem5 Developers                switch (el) {
21810037SARM gem5 Developers                  case EL3:
21910037SARM gem5 Developers                    return INTREG_SP3;
22011574SCurtis.Dunham@arm.com                  case EL2:
22111574SCurtis.Dunham@arm.com                    return INTREG_SP2;
22210037SARM gem5 Developers                  case EL1:
22310037SARM gem5 Developers                    return INTREG_SP1;
22410037SARM gem5 Developers                  case EL0:
22510037SARM gem5 Developers                    return INTREG_SP0;
22610037SARM gem5 Developers                  default:
22710037SARM gem5 Developers                    panic("Invalid exception level");
22810037SARM gem5 Developers                    break;
22910037SARM gem5 Developers                }
2306718Sgblack@eecs.umich.edu            } else {
23110037SARM gem5 Developers                return flattenIntRegModeIndex(reg);
2326718Sgblack@eecs.umich.edu            }
2336313Sgblack@eecs.umich.edu        }
2346313Sgblack@eecs.umich.edu
2356313Sgblack@eecs.umich.edu        int
23610035Sandreas.hansson@arm.com        flattenFloatIndex(int reg) const
2376313Sgblack@eecs.umich.edu        {
23810338SCurtis.Dunham@arm.com            assert(reg >= 0);
2396313Sgblack@eecs.umich.edu            return reg;
2406313Sgblack@eecs.umich.edu        }
2416313Sgblack@eecs.umich.edu
2429920Syasuko.eckert@amd.com        int
24312109SRekai.GonzalezAlberquilla@arm.com        flattenVecIndex(int reg) const
24412109SRekai.GonzalezAlberquilla@arm.com        {
24512109SRekai.GonzalezAlberquilla@arm.com            assert(reg >= 0);
24612109SRekai.GonzalezAlberquilla@arm.com            return reg;
24712109SRekai.GonzalezAlberquilla@arm.com        }
24812109SRekai.GonzalezAlberquilla@arm.com
24912109SRekai.GonzalezAlberquilla@arm.com        int
25012109SRekai.GonzalezAlberquilla@arm.com        flattenVecElemIndex(int reg) const
25112109SRekai.GonzalezAlberquilla@arm.com        {
25212109SRekai.GonzalezAlberquilla@arm.com            assert(reg >= 0);
25312109SRekai.GonzalezAlberquilla@arm.com            return reg;
25412109SRekai.GonzalezAlberquilla@arm.com        }
25512109SRekai.GonzalezAlberquilla@arm.com
25612109SRekai.GonzalezAlberquilla@arm.com        int
25710035Sandreas.hansson@arm.com        flattenCCIndex(int reg) const
2589920Syasuko.eckert@amd.com        {
25910338SCurtis.Dunham@arm.com            assert(reg >= 0);
2609920Syasuko.eckert@amd.com            return reg;
2619920Syasuko.eckert@amd.com        }
2629920Syasuko.eckert@amd.com
2637614Sminkyu.jeong@arm.com        int
26410035Sandreas.hansson@arm.com        flattenMiscIndex(int reg) const
2657614Sminkyu.jeong@arm.com        {
26610338SCurtis.Dunham@arm.com            assert(reg >= 0);
26710037SARM gem5 Developers            int flat_idx = reg;
26810037SARM gem5 Developers
2697614Sminkyu.jeong@arm.com            if (reg == MISCREG_SPSR) {
2707614Sminkyu.jeong@arm.com                CPSR cpsr = miscRegs[MISCREG_CPSR];
2717614Sminkyu.jeong@arm.com                switch (cpsr.mode) {
27210037SARM gem5 Developers                  case MODE_EL0T:
27310037SARM gem5 Developers                    warn("User mode does not have SPSR\n");
27410037SARM gem5 Developers                    flat_idx = MISCREG_SPSR;
27510037SARM gem5 Developers                    break;
27610037SARM gem5 Developers                  case MODE_EL1T:
27710037SARM gem5 Developers                  case MODE_EL1H:
27810037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_EL1;
27910037SARM gem5 Developers                    break;
28010037SARM gem5 Developers                  case MODE_EL2T:
28110037SARM gem5 Developers                  case MODE_EL2H:
28210037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_EL2;
28310037SARM gem5 Developers                    break;
28410037SARM gem5 Developers                  case MODE_EL3T:
28510037SARM gem5 Developers                  case MODE_EL3H:
28610037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_EL3;
28710037SARM gem5 Developers                    break;
2887614Sminkyu.jeong@arm.com                  case MODE_USER:
2897614Sminkyu.jeong@arm.com                    warn("User mode does not have SPSR\n");
29010037SARM gem5 Developers                    flat_idx = MISCREG_SPSR;
2917614Sminkyu.jeong@arm.com                    break;
2927614Sminkyu.jeong@arm.com                  case MODE_FIQ:
29310037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_FIQ;
2947614Sminkyu.jeong@arm.com                    break;
2957614Sminkyu.jeong@arm.com                  case MODE_IRQ:
29610037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_IRQ;
2977614Sminkyu.jeong@arm.com                    break;
2987614Sminkyu.jeong@arm.com                  case MODE_SVC:
29910037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_SVC;
3007614Sminkyu.jeong@arm.com                    break;
3017614Sminkyu.jeong@arm.com                  case MODE_MON:
30210037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_MON;
3037614Sminkyu.jeong@arm.com                    break;
3047614Sminkyu.jeong@arm.com                  case MODE_ABORT:
30510037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_ABT;
30610037SARM gem5 Developers                    break;
30710037SARM gem5 Developers                  case MODE_HYP:
30810037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_HYP;
3097614Sminkyu.jeong@arm.com                    break;
3107614Sminkyu.jeong@arm.com                  case MODE_UNDEFINED:
31110037SARM gem5 Developers                    flat_idx = MISCREG_SPSR_UND;
3127614Sminkyu.jeong@arm.com                    break;
3137614Sminkyu.jeong@arm.com                  default:
3147614Sminkyu.jeong@arm.com                    warn("Trying to access SPSR in an invalid mode: %d\n",
3157614Sminkyu.jeong@arm.com                         cpsr.mode);
31610037SARM gem5 Developers                    flat_idx = MISCREG_SPSR;
3177614Sminkyu.jeong@arm.com                    break;
3187614Sminkyu.jeong@arm.com                }
31910037SARM gem5 Developers            } else if (miscRegInfo[reg][MISCREG_MUTEX]) {
32010037SARM gem5 Developers                // Mutually exclusive CP15 register
32110037SARM gem5 Developers                switch (reg) {
32210037SARM gem5 Developers                  case MISCREG_PRRR_MAIR0:
32310037SARM gem5 Developers                  case MISCREG_PRRR_MAIR0_NS:
32410037SARM gem5 Developers                  case MISCREG_PRRR_MAIR0_S:
32510037SARM gem5 Developers                    {
32610037SARM gem5 Developers                        TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
32710037SARM gem5 Developers                        // If the muxed reg has been flattened, work out the
32810037SARM gem5 Developers                        // offset and apply it to the unmuxed reg
32910037SARM gem5 Developers                        int idxOffset = reg - MISCREG_PRRR_MAIR0;
33010037SARM gem5 Developers                        if (ttbcr.eae)
33110037SARM gem5 Developers                            flat_idx = flattenMiscIndex(MISCREG_MAIR0 +
33210037SARM gem5 Developers                                                        idxOffset);
33310037SARM gem5 Developers                        else
33410037SARM gem5 Developers                            flat_idx = flattenMiscIndex(MISCREG_PRRR +
33510037SARM gem5 Developers                                                        idxOffset);
33610037SARM gem5 Developers                    }
33710037SARM gem5 Developers                    break;
33810037SARM gem5 Developers                  case MISCREG_NMRR_MAIR1:
33910037SARM gem5 Developers                  case MISCREG_NMRR_MAIR1_NS:
34010037SARM gem5 Developers                  case MISCREG_NMRR_MAIR1_S:
34110037SARM gem5 Developers                    {
34210037SARM gem5 Developers                        TTBCR ttbcr = readMiscRegNoEffect(MISCREG_TTBCR);
34310037SARM gem5 Developers                        // If the muxed reg has been flattened, work out the
34410037SARM gem5 Developers                        // offset and apply it to the unmuxed reg
34510037SARM gem5 Developers                        int idxOffset = reg - MISCREG_NMRR_MAIR1;
34610037SARM gem5 Developers                        if (ttbcr.eae)
34710037SARM gem5 Developers                            flat_idx = flattenMiscIndex(MISCREG_MAIR1 +
34810037SARM gem5 Developers                                                        idxOffset);
34910037SARM gem5 Developers                        else
35010037SARM gem5 Developers                            flat_idx = flattenMiscIndex(MISCREG_NMRR +
35110037SARM gem5 Developers                                                        idxOffset);
35210037SARM gem5 Developers                    }
35310037SARM gem5 Developers                    break;
35410037SARM gem5 Developers                  case MISCREG_PMXEVTYPER_PMCCFILTR:
35510037SARM gem5 Developers                    {
35610037SARM gem5 Developers                        PMSELR pmselr = miscRegs[MISCREG_PMSELR];
35710037SARM gem5 Developers                        if (pmselr.sel == 31)
35810037SARM gem5 Developers                            flat_idx = flattenMiscIndex(MISCREG_PMCCFILTR);
35910037SARM gem5 Developers                        else
36010037SARM gem5 Developers                            flat_idx = flattenMiscIndex(MISCREG_PMXEVTYPER);
36110037SARM gem5 Developers                    }
36210037SARM gem5 Developers                    break;
36310037SARM gem5 Developers                  default:
36410037SARM gem5 Developers                    panic("Unrecognized misc. register.\n");
36510037SARM gem5 Developers                    break;
36610037SARM gem5 Developers                }
36710037SARM gem5 Developers            } else {
36810037SARM gem5 Developers                if (miscRegInfo[reg][MISCREG_BANKED]) {
36911771SCurtis.Dunham@arm.com                    bool secureReg = haveSecurity && !highestELIs64 &&
37010037SARM gem5 Developers                                     inSecureState(miscRegs[MISCREG_SCR],
37110037SARM gem5 Developers                                                   miscRegs[MISCREG_CPSR]);
37210037SARM gem5 Developers                    flat_idx += secureReg ? 2 : 1;
37310037SARM gem5 Developers                }
3747614Sminkyu.jeong@arm.com            }
37510037SARM gem5 Developers            return flat_idx;
3767614Sminkyu.jeong@arm.com        }
3777614Sminkyu.jeong@arm.com
37811771SCurtis.Dunham@arm.com        std::pair<int,int> getMiscIndices(int misc_reg) const
37911771SCurtis.Dunham@arm.com        {
38011771SCurtis.Dunham@arm.com            // Note: indexes of AArch64 registers are left unchanged
38111771SCurtis.Dunham@arm.com            int flat_idx = flattenMiscIndex(misc_reg);
38211771SCurtis.Dunham@arm.com
38311771SCurtis.Dunham@arm.com            if (lookUpMiscReg[flat_idx].lower == 0) {
38411771SCurtis.Dunham@arm.com                return std::make_pair(flat_idx, 0);
38511771SCurtis.Dunham@arm.com            }
38611771SCurtis.Dunham@arm.com
38711771SCurtis.Dunham@arm.com            // do additional S/NS flattenings if mapped to NS while in S
38811771SCurtis.Dunham@arm.com            bool S = haveSecurity && !highestELIs64 &&
38911771SCurtis.Dunham@arm.com                     inSecureState(miscRegs[MISCREG_SCR],
39011771SCurtis.Dunham@arm.com                                   miscRegs[MISCREG_CPSR]);
39111771SCurtis.Dunham@arm.com            int lower = lookUpMiscReg[flat_idx].lower;
39211771SCurtis.Dunham@arm.com            int upper = lookUpMiscReg[flat_idx].upper;
39311771SCurtis.Dunham@arm.com            // upper == 0, which is CPSR, is not MISCREG_BANKED_CHILD (no-op)
39411771SCurtis.Dunham@arm.com            lower += S && miscRegInfo[lower][MISCREG_BANKED_CHILD];
39511771SCurtis.Dunham@arm.com            upper += S && miscRegInfo[upper][MISCREG_BANKED_CHILD];
39611771SCurtis.Dunham@arm.com            return std::make_pair(lower, upper);
39711771SCurtis.Dunham@arm.com        }
39811771SCurtis.Dunham@arm.com
39910905Sandreas.sandberg@arm.com        void serialize(CheckpointOut &cp) const
4007733SAli.Saidi@ARM.com        {
4017733SAli.Saidi@ARM.com            DPRINTF(Checkpoint, "Serializing Arm Misc Registers\n");
4027733SAli.Saidi@ARM.com            SERIALIZE_ARRAY(miscRegs, NumMiscRegs);
40310037SARM gem5 Developers
40411771SCurtis.Dunham@arm.com            SERIALIZE_SCALAR(highestELIs64);
40510037SARM gem5 Developers            SERIALIZE_SCALAR(haveSecurity);
40610037SARM gem5 Developers            SERIALIZE_SCALAR(haveLPAE);
40710037SARM gem5 Developers            SERIALIZE_SCALAR(haveVirtualization);
40810037SARM gem5 Developers            SERIALIZE_SCALAR(haveLargeAsid64);
40910037SARM gem5 Developers            SERIALIZE_SCALAR(physAddrRange64);
4107733SAli.Saidi@ARM.com        }
41110905Sandreas.sandberg@arm.com        void unserialize(CheckpointIn &cp)
4127733SAli.Saidi@ARM.com        {
4137733SAli.Saidi@ARM.com            DPRINTF(Checkpoint, "Unserializing Arm Misc Registers\n");
4147733SAli.Saidi@ARM.com            UNSERIALIZE_ARRAY(miscRegs, NumMiscRegs);
4157733SAli.Saidi@ARM.com            CPSR tmp_cpsr = miscRegs[MISCREG_CPSR];
4167733SAli.Saidi@ARM.com            updateRegMap(tmp_cpsr);
41710037SARM gem5 Developers
41811771SCurtis.Dunham@arm.com            UNSERIALIZE_SCALAR(highestELIs64);
41910037SARM gem5 Developers            UNSERIALIZE_SCALAR(haveSecurity);
42010037SARM gem5 Developers            UNSERIALIZE_SCALAR(haveLPAE);
42110037SARM gem5 Developers            UNSERIALIZE_SCALAR(haveVirtualization);
42210037SARM gem5 Developers            UNSERIALIZE_SCALAR(haveLargeAsid64);
42310037SARM gem5 Developers            UNSERIALIZE_SCALAR(physAddrRange64);
4247733SAli.Saidi@ARM.com        }
4256313Sgblack@eecs.umich.edu
4269461Snilay@cs.wisc.edu        void startup(ThreadContext *tc) {}
4279461Snilay@cs.wisc.edu
42811165SRekai.GonzalezAlberquilla@arm.com        Enums::DecoderFlavour decoderFlavour() const { return _decoderFlavour; }
42911165SRekai.GonzalezAlberquilla@arm.com
43012109SRekai.GonzalezAlberquilla@arm.com        Enums::VecRegRenameMode
43112109SRekai.GonzalezAlberquilla@arm.com        vecRegRenameMode() const
43212109SRekai.GonzalezAlberquilla@arm.com        {
43312109SRekai.GonzalezAlberquilla@arm.com            return _vecRegRenameMode;
43412109SRekai.GonzalezAlberquilla@arm.com        }
43512109SRekai.GonzalezAlberquilla@arm.com
4369553Sandreas.hansson@arm.com        /// Explicitly import the otherwise hidden startup
4379553Sandreas.hansson@arm.com        using SimObject::startup;
4389553Sandreas.hansson@arm.com
4399384SAndreas.Sandberg@arm.com        typedef ArmISAParams Params;
4407400SAli.Saidi@ARM.com
4419384SAndreas.Sandberg@arm.com        const Params *params() const;
4429384SAndreas.Sandberg@arm.com
4439384SAndreas.Sandberg@arm.com        ISA(Params *p);
4446313Sgblack@eecs.umich.edu    };
4456313Sgblack@eecs.umich.edu}
4466313Sgblack@eecs.umich.edu
44712109SRekai.GonzalezAlberquilla@arm.comtemplate<>
44812109SRekai.GonzalezAlberquilla@arm.comstruct initRenameMode<ArmISA::ISA>
44912109SRekai.GonzalezAlberquilla@arm.com{
45012109SRekai.GonzalezAlberquilla@arm.com    static Enums::VecRegRenameMode mode(const ArmISA::ISA* isa)
45112109SRekai.GonzalezAlberquilla@arm.com    {
45212109SRekai.GonzalezAlberquilla@arm.com        return isa->vecRegRenameMode();
45312109SRekai.GonzalezAlberquilla@arm.com    }
45412109SRekai.GonzalezAlberquilla@arm.com    static bool equals(const ArmISA::ISA* isa1, const ArmISA::ISA* isa2)
45512109SRekai.GonzalezAlberquilla@arm.com    {
45612109SRekai.GonzalezAlberquilla@arm.com        return mode(isa1) == mode(isa2);
45712109SRekai.GonzalezAlberquilla@arm.com    }
45812109SRekai.GonzalezAlberquilla@arm.com};
45912109SRekai.GonzalezAlberquilla@arm.com
4606313Sgblack@eecs.umich.edu#endif
461