isa.hh revision 7878
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__
447404SAli.Saidi@ARM.com#define __ARCH_ARM_ISA_HH__
456313Sgblack@eecs.umich.edu
466333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh"
477404SAli.Saidi@ARM.com#include "arch/arm/tlb.hh"
486313Sgblack@eecs.umich.edu#include "arch/arm/types.hh"
496313Sgblack@eecs.umich.edu
506333Sgblack@eecs.umich.educlass ThreadContext;
516313Sgblack@eecs.umich.educlass Checkpoint;
526313Sgblack@eecs.umich.educlass EventManager;
536313Sgblack@eecs.umich.edu
546313Sgblack@eecs.umich.edunamespace ArmISA
556313Sgblack@eecs.umich.edu{
566313Sgblack@eecs.umich.edu    class ISA
576313Sgblack@eecs.umich.edu    {
586313Sgblack@eecs.umich.edu      protected:
596333Sgblack@eecs.umich.edu        MiscReg miscRegs[NumMiscRegs];
606718Sgblack@eecs.umich.edu        const IntRegIndex *intRegMap;
616718Sgblack@eecs.umich.edu
626718Sgblack@eecs.umich.edu        void
636718Sgblack@eecs.umich.edu        updateRegMap(CPSR cpsr)
646718Sgblack@eecs.umich.edu        {
656718Sgblack@eecs.umich.edu            switch (cpsr.mode) {
666718Sgblack@eecs.umich.edu              case MODE_USER:
676718Sgblack@eecs.umich.edu              case MODE_SYSTEM:
686718Sgblack@eecs.umich.edu                intRegMap = IntRegUsrMap;
696718Sgblack@eecs.umich.edu                break;
706718Sgblack@eecs.umich.edu              case MODE_FIQ:
716718Sgblack@eecs.umich.edu                intRegMap = IntRegFiqMap;
726718Sgblack@eecs.umich.edu                break;
736718Sgblack@eecs.umich.edu              case MODE_IRQ:
746718Sgblack@eecs.umich.edu                intRegMap = IntRegIrqMap;
756718Sgblack@eecs.umich.edu                break;
766718Sgblack@eecs.umich.edu              case MODE_SVC:
776718Sgblack@eecs.umich.edu                intRegMap = IntRegSvcMap;
786718Sgblack@eecs.umich.edu                break;
796723Sgblack@eecs.umich.edu              case MODE_MON:
806723Sgblack@eecs.umich.edu                intRegMap = IntRegMonMap;
816723Sgblack@eecs.umich.edu                break;
826718Sgblack@eecs.umich.edu              case MODE_ABORT:
836718Sgblack@eecs.umich.edu                intRegMap = IntRegAbtMap;
846718Sgblack@eecs.umich.edu                break;
856718Sgblack@eecs.umich.edu              case MODE_UNDEFINED:
866718Sgblack@eecs.umich.edu                intRegMap = IntRegUndMap;
876718Sgblack@eecs.umich.edu                break;
886718Sgblack@eecs.umich.edu              default:
896718Sgblack@eecs.umich.edu                panic("Unrecognized mode setting in CPSR.\n");
906718Sgblack@eecs.umich.edu            }
916718Sgblack@eecs.umich.edu        }
926313Sgblack@eecs.umich.edu
936313Sgblack@eecs.umich.edu      public:
947427Sgblack@eecs.umich.edu        void clear();
956313Sgblack@eecs.umich.edu
967405SAli.Saidi@ARM.com        MiscReg readMiscRegNoEffect(int misc_reg);
977405SAli.Saidi@ARM.com        MiscReg readMiscReg(int misc_reg, ThreadContext *tc);
987405SAli.Saidi@ARM.com        void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
997405SAli.Saidi@ARM.com        void setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc);
1006313Sgblack@eecs.umich.edu
1016313Sgblack@eecs.umich.edu        int
1026313Sgblack@eecs.umich.edu        flattenIntIndex(int reg)
1036313Sgblack@eecs.umich.edu        {
1046718Sgblack@eecs.umich.edu            assert(reg >= 0);
1056718Sgblack@eecs.umich.edu            if (reg < NUM_ARCH_INTREGS) {
1066718Sgblack@eecs.umich.edu                return intRegMap[reg];
1076726Sgblack@eecs.umich.edu            } else if (reg < NUM_INTREGS) {
1086726Sgblack@eecs.umich.edu                return reg;
1096718Sgblack@eecs.umich.edu            } else {
1107310Sgblack@eecs.umich.edu                int mode = reg / intRegsPerMode;
1117310Sgblack@eecs.umich.edu                reg = reg % intRegsPerMode;
1127310Sgblack@eecs.umich.edu                switch (mode) {
1137310Sgblack@eecs.umich.edu                  case MODE_USER:
1147310Sgblack@eecs.umich.edu                  case MODE_SYSTEM:
1157310Sgblack@eecs.umich.edu                    return INTREG_USR(reg);
1167310Sgblack@eecs.umich.edu                  case MODE_FIQ:
1177310Sgblack@eecs.umich.edu                    return INTREG_FIQ(reg);
1187310Sgblack@eecs.umich.edu                  case MODE_IRQ:
1197310Sgblack@eecs.umich.edu                    return INTREG_IRQ(reg);
1207310Sgblack@eecs.umich.edu                  case MODE_SVC:
1217310Sgblack@eecs.umich.edu                    return INTREG_SVC(reg);
1227310Sgblack@eecs.umich.edu                  case MODE_MON:
1237310Sgblack@eecs.umich.edu                    return INTREG_MON(reg);
1247310Sgblack@eecs.umich.edu                  case MODE_ABORT:
1257310Sgblack@eecs.umich.edu                    return INTREG_ABT(reg);
1267310Sgblack@eecs.umich.edu                  case MODE_UNDEFINED:
1277310Sgblack@eecs.umich.edu                    return INTREG_UND(reg);
1287310Sgblack@eecs.umich.edu                  default:
1297310Sgblack@eecs.umich.edu                    panic("Flattening into an unknown mode.\n");
1307310Sgblack@eecs.umich.edu                }
1316718Sgblack@eecs.umich.edu            }
1326313Sgblack@eecs.umich.edu        }
1336313Sgblack@eecs.umich.edu
1346313Sgblack@eecs.umich.edu        int
1356313Sgblack@eecs.umich.edu        flattenFloatIndex(int reg)
1366313Sgblack@eecs.umich.edu        {
1376313Sgblack@eecs.umich.edu            return reg;
1386313Sgblack@eecs.umich.edu        }
1396313Sgblack@eecs.umich.edu
1407614Sminkyu.jeong@arm.com        int
1417614Sminkyu.jeong@arm.com        flattenMiscIndex(int reg)
1427614Sminkyu.jeong@arm.com        {
1437614Sminkyu.jeong@arm.com            if (reg == MISCREG_SPSR) {
1447614Sminkyu.jeong@arm.com                int spsr_idx = NUM_MISCREGS;
1457614Sminkyu.jeong@arm.com                CPSR cpsr = miscRegs[MISCREG_CPSR];
1467614Sminkyu.jeong@arm.com                switch (cpsr.mode) {
1477614Sminkyu.jeong@arm.com                  case MODE_USER:
1487614Sminkyu.jeong@arm.com                    warn("User mode does not have SPSR\n");
1497614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR;
1507614Sminkyu.jeong@arm.com                    break;
1517614Sminkyu.jeong@arm.com                  case MODE_FIQ:
1527614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_FIQ;
1537614Sminkyu.jeong@arm.com                    break;
1547614Sminkyu.jeong@arm.com                  case MODE_IRQ:
1557614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_IRQ;
1567614Sminkyu.jeong@arm.com                    break;
1577614Sminkyu.jeong@arm.com                  case MODE_SVC:
1587614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_SVC;
1597614Sminkyu.jeong@arm.com                    break;
1607614Sminkyu.jeong@arm.com                  case MODE_MON:
1617614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_MON;
1627614Sminkyu.jeong@arm.com                    break;
1637614Sminkyu.jeong@arm.com                  case MODE_ABORT:
1647614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_ABT;
1657614Sminkyu.jeong@arm.com                    break;
1667614Sminkyu.jeong@arm.com                  case MODE_UNDEFINED:
1677614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_UND;
1687614Sminkyu.jeong@arm.com                    break;
1697614Sminkyu.jeong@arm.com                  default:
1707614Sminkyu.jeong@arm.com                    warn("Trying to access SPSR in an invalid mode: %d\n",
1717614Sminkyu.jeong@arm.com                         cpsr.mode);
1727614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR;
1737614Sminkyu.jeong@arm.com                    break;
1747614Sminkyu.jeong@arm.com                }
1757614Sminkyu.jeong@arm.com                return spsr_idx;
1767614Sminkyu.jeong@arm.com            }
1777614Sminkyu.jeong@arm.com            return reg;
1787614Sminkyu.jeong@arm.com        }
1797614Sminkyu.jeong@arm.com
1806678Sgblack@eecs.umich.edu        void serialize(EventManager *em, std::ostream &os)
1817733SAli.Saidi@ARM.com        {
1827733SAli.Saidi@ARM.com            DPRINTF(Checkpoint, "Serializing Arm Misc Registers\n");
1837733SAli.Saidi@ARM.com            SERIALIZE_ARRAY(miscRegs, NumMiscRegs);
1847733SAli.Saidi@ARM.com        }
1856678Sgblack@eecs.umich.edu        void unserialize(EventManager *em, Checkpoint *cp,
1866678Sgblack@eecs.umich.edu                const std::string &section)
1877733SAli.Saidi@ARM.com        {
1887733SAli.Saidi@ARM.com            DPRINTF(Checkpoint, "Unserializing Arm Misc Registers\n");
1897733SAli.Saidi@ARM.com            UNSERIALIZE_ARRAY(miscRegs, NumMiscRegs);
1907733SAli.Saidi@ARM.com            CPSR tmp_cpsr = miscRegs[MISCREG_CPSR];
1917733SAli.Saidi@ARM.com            updateRegMap(tmp_cpsr);
1927733SAli.Saidi@ARM.com        }
1936313Sgblack@eecs.umich.edu
1946313Sgblack@eecs.umich.edu        ISA()
1956313Sgblack@eecs.umich.edu        {
1967400SAli.Saidi@ARM.com            SCTLR sctlr;
1977400SAli.Saidi@ARM.com            sctlr = 0;
1987400SAli.Saidi@ARM.com            miscRegs[MISCREG_SCTLR_RST] = sctlr;
1997400SAli.Saidi@ARM.com
2006313Sgblack@eecs.umich.edu            clear();
2016313Sgblack@eecs.umich.edu        }
2026313Sgblack@eecs.umich.edu    };
2036313Sgblack@eecs.umich.edu}
2046313Sgblack@eecs.umich.edu
2056313Sgblack@eecs.umich.edu#endif
206