isa.hh revision 7287
16313Sgblack@eecs.umich.edu/*
27093Sgblack@eecs.umich.edu * Copyright (c) 2010 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__
446313Sgblack@eecs.umich.edu#define __ARCH_MRM_ISA_HH__
456313Sgblack@eecs.umich.edu
466333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh"
476313Sgblack@eecs.umich.edu#include "arch/arm/types.hh"
486313Sgblack@eecs.umich.edu
496333Sgblack@eecs.umich.educlass ThreadContext;
506313Sgblack@eecs.umich.educlass Checkpoint;
516313Sgblack@eecs.umich.educlass EventManager;
526313Sgblack@eecs.umich.edu
536313Sgblack@eecs.umich.edunamespace ArmISA
546313Sgblack@eecs.umich.edu{
556313Sgblack@eecs.umich.edu    class ISA
566313Sgblack@eecs.umich.edu    {
576313Sgblack@eecs.umich.edu      protected:
586333Sgblack@eecs.umich.edu        MiscReg miscRegs[NumMiscRegs];
596718Sgblack@eecs.umich.edu        const IntRegIndex *intRegMap;
606718Sgblack@eecs.umich.edu
616718Sgblack@eecs.umich.edu        void
626718Sgblack@eecs.umich.edu        updateRegMap(CPSR cpsr)
636718Sgblack@eecs.umich.edu        {
646718Sgblack@eecs.umich.edu            switch (cpsr.mode) {
656718Sgblack@eecs.umich.edu              case MODE_USER:
666718Sgblack@eecs.umich.edu              case MODE_SYSTEM:
676718Sgblack@eecs.umich.edu                intRegMap = IntRegUsrMap;
686718Sgblack@eecs.umich.edu                break;
696718Sgblack@eecs.umich.edu              case MODE_FIQ:
706718Sgblack@eecs.umich.edu                intRegMap = IntRegFiqMap;
716718Sgblack@eecs.umich.edu                break;
726718Sgblack@eecs.umich.edu              case MODE_IRQ:
736718Sgblack@eecs.umich.edu                intRegMap = IntRegIrqMap;
746718Sgblack@eecs.umich.edu                break;
756718Sgblack@eecs.umich.edu              case MODE_SVC:
766718Sgblack@eecs.umich.edu                intRegMap = IntRegSvcMap;
776718Sgblack@eecs.umich.edu                break;
786723Sgblack@eecs.umich.edu              case MODE_MON:
796723Sgblack@eecs.umich.edu                intRegMap = IntRegMonMap;
806723Sgblack@eecs.umich.edu                break;
816718Sgblack@eecs.umich.edu              case MODE_ABORT:
826718Sgblack@eecs.umich.edu                intRegMap = IntRegAbtMap;
836718Sgblack@eecs.umich.edu                break;
846718Sgblack@eecs.umich.edu              case MODE_UNDEFINED:
856718Sgblack@eecs.umich.edu                intRegMap = IntRegUndMap;
866718Sgblack@eecs.umich.edu                break;
876718Sgblack@eecs.umich.edu              default:
886718Sgblack@eecs.umich.edu                panic("Unrecognized mode setting in CPSR.\n");
896718Sgblack@eecs.umich.edu            }
906718Sgblack@eecs.umich.edu        }
916313Sgblack@eecs.umich.edu
926313Sgblack@eecs.umich.edu      public:
936333Sgblack@eecs.umich.edu        void clear()
946333Sgblack@eecs.umich.edu        {
956401Sgblack@eecs.umich.edu            memset(miscRegs, 0, sizeof(miscRegs));
966401Sgblack@eecs.umich.edu            CPSR cpsr = 0;
976719Sgblack@eecs.umich.edu            cpsr.mode = MODE_USER;
986401Sgblack@eecs.umich.edu            miscRegs[MISCREG_CPSR] = cpsr;
996718Sgblack@eecs.umich.edu            updateRegMap(cpsr);
1006735Sgblack@eecs.umich.edu
1016735Sgblack@eecs.umich.edu            SCTLR sctlr = 0;
1026735Sgblack@eecs.umich.edu            sctlr.nmfi = 1;
1036735Sgblack@eecs.umich.edu            sctlr.rao1 = 1;
1046735Sgblack@eecs.umich.edu            sctlr.rao2 = 1;
1056735Sgblack@eecs.umich.edu            sctlr.rao3 = 1;
1066735Sgblack@eecs.umich.edu            sctlr.rao4 = 1;
1077270Sgblack@eecs.umich.edu            miscRegs[MISCREG_SCTLR] = sctlr;
1086735Sgblack@eecs.umich.edu
1097271Sgblack@eecs.umich.edu            /*
1107271Sgblack@eecs.umich.edu             * Technically this should be 0, but we don't support those
1117271Sgblack@eecs.umich.edu             * settings.
1127271Sgblack@eecs.umich.edu             */
1137271Sgblack@eecs.umich.edu            miscRegs[MISCREG_CPACR] = 0x0fffffff;
1147271Sgblack@eecs.umich.edu
1156401Sgblack@eecs.umich.edu            //XXX We need to initialize the rest of the state.
1166333Sgblack@eecs.umich.edu        }
1176313Sgblack@eecs.umich.edu
1186333Sgblack@eecs.umich.edu        MiscReg
1196333Sgblack@eecs.umich.edu        readMiscRegNoEffect(int misc_reg)
1206333Sgblack@eecs.umich.edu        {
1216333Sgblack@eecs.umich.edu            assert(misc_reg < NumMiscRegs);
1226745Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_SPSR) {
1236745Sgblack@eecs.umich.edu                CPSR cpsr = miscRegs[MISCREG_CPSR];
1246745Sgblack@eecs.umich.edu                switch (cpsr.mode) {
1256745Sgblack@eecs.umich.edu                  case MODE_USER:
1266745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR];
1276745Sgblack@eecs.umich.edu                  case MODE_FIQ:
1286745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_FIQ];
1296745Sgblack@eecs.umich.edu                  case MODE_IRQ:
1306745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_IRQ];
1316745Sgblack@eecs.umich.edu                  case MODE_SVC:
1326745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_SVC];
1336745Sgblack@eecs.umich.edu                  case MODE_MON:
1346745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_MON];
1356745Sgblack@eecs.umich.edu                  case MODE_ABORT:
1366745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_ABT];
1376745Sgblack@eecs.umich.edu                  case MODE_UNDEFINED:
1386745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_UND];
1396745Sgblack@eecs.umich.edu                  default:
1406745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR];
1416745Sgblack@eecs.umich.edu                }
1426745Sgblack@eecs.umich.edu            }
1436333Sgblack@eecs.umich.edu            return miscRegs[misc_reg];
1446333Sgblack@eecs.umich.edu        }
1456313Sgblack@eecs.umich.edu
1466333Sgblack@eecs.umich.edu        MiscReg
1476333Sgblack@eecs.umich.edu        readMiscReg(int misc_reg, ThreadContext *tc)
1486333Sgblack@eecs.umich.edu        {
1497093Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_CPSR) {
1507093Sgblack@eecs.umich.edu                CPSR cpsr = miscRegs[misc_reg];
1517093Sgblack@eecs.umich.edu                Addr pc = tc->readPC();
1527093Sgblack@eecs.umich.edu                if (pc & (ULL(1) << PcJBitShift))
1537093Sgblack@eecs.umich.edu                    cpsr.j = 1;
1547093Sgblack@eecs.umich.edu                else
1557093Sgblack@eecs.umich.edu                    cpsr.j = 0;
1567093Sgblack@eecs.umich.edu                if (pc & (ULL(1) << PcTBitShift))
1577093Sgblack@eecs.umich.edu                    cpsr.t = 1;
1587093Sgblack@eecs.umich.edu                else
1597093Sgblack@eecs.umich.edu                    cpsr.t = 0;
1607093Sgblack@eecs.umich.edu                return cpsr;
1617093Sgblack@eecs.umich.edu            }
1627259Sgblack@eecs.umich.edu            if (misc_reg >= MISCREG_CP15_UNIMP_START &&
1637259Sgblack@eecs.umich.edu                misc_reg < MISCREG_CP15_END) {
1647259Sgblack@eecs.umich.edu                panic("Unimplemented CP15 register %s read.\n",
1657259Sgblack@eecs.umich.edu                      miscRegName[misc_reg]);
1667259Sgblack@eecs.umich.edu            }
1677273Sgblack@eecs.umich.edu            switch (misc_reg) {
1687273Sgblack@eecs.umich.edu              case MISCREG_CLIDR:
1697273Sgblack@eecs.umich.edu                warn("The clidr register always reports 0 caches.\n");
1707273Sgblack@eecs.umich.edu                break;
1717287Sgblack@eecs.umich.edu              case MISCREG_CCSIDR:
1727287Sgblack@eecs.umich.edu                warn("The ccsidr register isn't implemented and "
1737287Sgblack@eecs.umich.edu                        "always reads as 0.\n");
1747287Sgblack@eecs.umich.edu                break;
1757273Sgblack@eecs.umich.edu            }
1766745Sgblack@eecs.umich.edu            return readMiscRegNoEffect(misc_reg);
1776333Sgblack@eecs.umich.edu        }
1786333Sgblack@eecs.umich.edu
1796333Sgblack@eecs.umich.edu        void
1806333Sgblack@eecs.umich.edu        setMiscRegNoEffect(int misc_reg, const MiscReg &val)
1816333Sgblack@eecs.umich.edu        {
1826333Sgblack@eecs.umich.edu            assert(misc_reg < NumMiscRegs);
1836745Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_SPSR) {
1846745Sgblack@eecs.umich.edu                CPSR cpsr = miscRegs[MISCREG_CPSR];
1856745Sgblack@eecs.umich.edu                switch (cpsr.mode) {
1866745Sgblack@eecs.umich.edu                  case MODE_USER:
1876745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR] = val;
1886745Sgblack@eecs.umich.edu                    return;
1896745Sgblack@eecs.umich.edu                  case MODE_FIQ:
1906745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_FIQ] = val;
1916745Sgblack@eecs.umich.edu                    return;
1926745Sgblack@eecs.umich.edu                  case MODE_IRQ:
1936745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_IRQ] = val;
1946745Sgblack@eecs.umich.edu                    return;
1956745Sgblack@eecs.umich.edu                  case MODE_SVC:
1966745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_SVC] = val;
1976745Sgblack@eecs.umich.edu                    return;
1986745Sgblack@eecs.umich.edu                  case MODE_MON:
1996745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_MON] = val;
2006745Sgblack@eecs.umich.edu                    return;
2016745Sgblack@eecs.umich.edu                  case MODE_ABORT:
2026745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_ABT] = val;
2036745Sgblack@eecs.umich.edu                    return;
2046745Sgblack@eecs.umich.edu                  case MODE_UNDEFINED:
2056745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_UND] = val;
2066745Sgblack@eecs.umich.edu                    return;
2076745Sgblack@eecs.umich.edu                  default:
2086745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR] = val;
2096745Sgblack@eecs.umich.edu                    return;
2106745Sgblack@eecs.umich.edu                }
2116745Sgblack@eecs.umich.edu            }
2126333Sgblack@eecs.umich.edu            miscRegs[misc_reg] = val;
2136333Sgblack@eecs.umich.edu        }
2146333Sgblack@eecs.umich.edu
2156333Sgblack@eecs.umich.edu        void
2166333Sgblack@eecs.umich.edu        setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
2176333Sgblack@eecs.umich.edu        {
2187271Sgblack@eecs.umich.edu            MiscReg newVal = val;
2196718Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_CPSR) {
2206718Sgblack@eecs.umich.edu                updateRegMap(val);
2217093Sgblack@eecs.umich.edu                CPSR cpsr = val;
2227093Sgblack@eecs.umich.edu                Addr npc = tc->readNextPC() & ~PcModeMask;
2237093Sgblack@eecs.umich.edu                if (cpsr.j)
2247093Sgblack@eecs.umich.edu                    npc = npc | (ULL(1) << PcJBitShift);
2257093Sgblack@eecs.umich.edu                if (cpsr.t)
2267093Sgblack@eecs.umich.edu                    npc = npc | (ULL(1) << PcTBitShift);
2277093Sgblack@eecs.umich.edu
2287093Sgblack@eecs.umich.edu                tc->setNextPC(npc);
2296718Sgblack@eecs.umich.edu            }
2307259Sgblack@eecs.umich.edu            if (misc_reg >= MISCREG_CP15_UNIMP_START &&
2317259Sgblack@eecs.umich.edu                misc_reg < MISCREG_CP15_END) {
2327259Sgblack@eecs.umich.edu                panic("Unimplemented CP15 register %s wrote with %#x.\n",
2337259Sgblack@eecs.umich.edu                      miscRegName[misc_reg], val);
2347259Sgblack@eecs.umich.edu            }
2357271Sgblack@eecs.umich.edu            switch (misc_reg) {
2367271Sgblack@eecs.umich.edu              case MISCREG_CPACR:
2377271Sgblack@eecs.umich.edu                newVal = bits(val, 27, 0);
2387271Sgblack@eecs.umich.edu                if (newVal != 0x0fffffff) {
2397271Sgblack@eecs.umich.edu                    panic("Disabling coprocessors isn't implemented.\n");
2407271Sgblack@eecs.umich.edu                }
2417271Sgblack@eecs.umich.edu                break;
2427287Sgblack@eecs.umich.edu              case MISCREG_CSSELR:
2437287Sgblack@eecs.umich.edu                warn("The csselr register isn't implemented.\n");
2447287Sgblack@eecs.umich.edu                break;
2457271Sgblack@eecs.umich.edu            }
2467271Sgblack@eecs.umich.edu            return setMiscRegNoEffect(misc_reg, newVal);
2476333Sgblack@eecs.umich.edu        }
2486313Sgblack@eecs.umich.edu
2496313Sgblack@eecs.umich.edu        int
2506313Sgblack@eecs.umich.edu        flattenIntIndex(int reg)
2516313Sgblack@eecs.umich.edu        {
2526718Sgblack@eecs.umich.edu            assert(reg >= 0);
2536718Sgblack@eecs.umich.edu            if (reg < NUM_ARCH_INTREGS) {
2546718Sgblack@eecs.umich.edu                return intRegMap[reg];
2556726Sgblack@eecs.umich.edu            } else if (reg < NUM_INTREGS) {
2566726Sgblack@eecs.umich.edu                return reg;
2576718Sgblack@eecs.umich.edu            } else {
2586726Sgblack@eecs.umich.edu                reg -= NUM_INTREGS;
2596726Sgblack@eecs.umich.edu                assert(reg < NUM_ARCH_INTREGS);
2606718Sgblack@eecs.umich.edu                return reg;
2616718Sgblack@eecs.umich.edu            }
2626313Sgblack@eecs.umich.edu        }
2636313Sgblack@eecs.umich.edu
2646313Sgblack@eecs.umich.edu        int
2656313Sgblack@eecs.umich.edu        flattenFloatIndex(int reg)
2666313Sgblack@eecs.umich.edu        {
2676313Sgblack@eecs.umich.edu            return reg;
2686313Sgblack@eecs.umich.edu        }
2696313Sgblack@eecs.umich.edu
2706678Sgblack@eecs.umich.edu        void serialize(EventManager *em, std::ostream &os)
2716333Sgblack@eecs.umich.edu        {}
2726678Sgblack@eecs.umich.edu        void unserialize(EventManager *em, Checkpoint *cp,
2736678Sgblack@eecs.umich.edu                const std::string &section)
2746333Sgblack@eecs.umich.edu        {}
2756313Sgblack@eecs.umich.edu
2766313Sgblack@eecs.umich.edu        ISA()
2776313Sgblack@eecs.umich.edu        {
2786313Sgblack@eecs.umich.edu            clear();
2796313Sgblack@eecs.umich.edu        }
2806313Sgblack@eecs.umich.edu    };
2816313Sgblack@eecs.umich.edu}
2826313Sgblack@eecs.umich.edu
2836313Sgblack@eecs.umich.edu#endif
284