isa.hh revision 10033
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"
498232Snate@binkert.org#include "debug/Checkpoint.hh"
509384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh"
516313Sgblack@eecs.umich.edu
529384SAndreas.Sandberg@arm.comstruct ArmISAParams;
536333Sgblack@eecs.umich.educlass ThreadContext;
546313Sgblack@eecs.umich.educlass Checkpoint;
556313Sgblack@eecs.umich.educlass EventManager;
566313Sgblack@eecs.umich.edu
576313Sgblack@eecs.umich.edunamespace ArmISA
586313Sgblack@eecs.umich.edu{
599384SAndreas.Sandberg@arm.com    class ISA : public SimObject
606313Sgblack@eecs.umich.edu    {
616313Sgblack@eecs.umich.edu      protected:
626333Sgblack@eecs.umich.edu        MiscReg miscRegs[NumMiscRegs];
636718Sgblack@eecs.umich.edu        const IntRegIndex *intRegMap;
646718Sgblack@eecs.umich.edu
656718Sgblack@eecs.umich.edu        void
666718Sgblack@eecs.umich.edu        updateRegMap(CPSR cpsr)
676718Sgblack@eecs.umich.edu        {
686718Sgblack@eecs.umich.edu            switch (cpsr.mode) {
696718Sgblack@eecs.umich.edu              case MODE_USER:
706718Sgblack@eecs.umich.edu              case MODE_SYSTEM:
716718Sgblack@eecs.umich.edu                intRegMap = IntRegUsrMap;
726718Sgblack@eecs.umich.edu                break;
736718Sgblack@eecs.umich.edu              case MODE_FIQ:
746718Sgblack@eecs.umich.edu                intRegMap = IntRegFiqMap;
756718Sgblack@eecs.umich.edu                break;
766718Sgblack@eecs.umich.edu              case MODE_IRQ:
776718Sgblack@eecs.umich.edu                intRegMap = IntRegIrqMap;
786718Sgblack@eecs.umich.edu                break;
796718Sgblack@eecs.umich.edu              case MODE_SVC:
806718Sgblack@eecs.umich.edu                intRegMap = IntRegSvcMap;
816718Sgblack@eecs.umich.edu                break;
826723Sgblack@eecs.umich.edu              case MODE_MON:
836723Sgblack@eecs.umich.edu                intRegMap = IntRegMonMap;
846723Sgblack@eecs.umich.edu                break;
856718Sgblack@eecs.umich.edu              case MODE_ABORT:
866718Sgblack@eecs.umich.edu                intRegMap = IntRegAbtMap;
876718Sgblack@eecs.umich.edu                break;
886718Sgblack@eecs.umich.edu              case MODE_UNDEFINED:
896718Sgblack@eecs.umich.edu                intRegMap = IntRegUndMap;
906718Sgblack@eecs.umich.edu                break;
916718Sgblack@eecs.umich.edu              default:
926718Sgblack@eecs.umich.edu                panic("Unrecognized mode setting in CPSR.\n");
936718Sgblack@eecs.umich.edu            }
946718Sgblack@eecs.umich.edu        }
956313Sgblack@eecs.umich.edu
966313Sgblack@eecs.umich.edu      public:
977427Sgblack@eecs.umich.edu        void clear();
986313Sgblack@eecs.umich.edu
997405SAli.Saidi@ARM.com        MiscReg readMiscRegNoEffect(int misc_reg);
1007405SAli.Saidi@ARM.com        MiscReg readMiscReg(int misc_reg, ThreadContext *tc);
1017405SAli.Saidi@ARM.com        void setMiscRegNoEffect(int misc_reg, const MiscReg &val);
1027405SAli.Saidi@ARM.com        void setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc);
1036313Sgblack@eecs.umich.edu
1046313Sgblack@eecs.umich.edu        int
1056313Sgblack@eecs.umich.edu        flattenIntIndex(int reg)
1066313Sgblack@eecs.umich.edu        {
1076718Sgblack@eecs.umich.edu            assert(reg >= 0);
1086718Sgblack@eecs.umich.edu            if (reg < NUM_ARCH_INTREGS) {
1096718Sgblack@eecs.umich.edu                return intRegMap[reg];
1106726Sgblack@eecs.umich.edu            } else if (reg < NUM_INTREGS) {
1116726Sgblack@eecs.umich.edu                return reg;
1126718Sgblack@eecs.umich.edu            } else {
1137310Sgblack@eecs.umich.edu                int mode = reg / intRegsPerMode;
1147310Sgblack@eecs.umich.edu                reg = reg % intRegsPerMode;
1157310Sgblack@eecs.umich.edu                switch (mode) {
1167310Sgblack@eecs.umich.edu                  case MODE_USER:
1177310Sgblack@eecs.umich.edu                  case MODE_SYSTEM:
1187310Sgblack@eecs.umich.edu                    return INTREG_USR(reg);
1197310Sgblack@eecs.umich.edu                  case MODE_FIQ:
1207310Sgblack@eecs.umich.edu                    return INTREG_FIQ(reg);
1217310Sgblack@eecs.umich.edu                  case MODE_IRQ:
1227310Sgblack@eecs.umich.edu                    return INTREG_IRQ(reg);
1237310Sgblack@eecs.umich.edu                  case MODE_SVC:
1247310Sgblack@eecs.umich.edu                    return INTREG_SVC(reg);
1257310Sgblack@eecs.umich.edu                  case MODE_MON:
1267310Sgblack@eecs.umich.edu                    return INTREG_MON(reg);
1277310Sgblack@eecs.umich.edu                  case MODE_ABORT:
1287310Sgblack@eecs.umich.edu                    return INTREG_ABT(reg);
1297310Sgblack@eecs.umich.edu                  case MODE_UNDEFINED:
1307310Sgblack@eecs.umich.edu                    return INTREG_UND(reg);
1317310Sgblack@eecs.umich.edu                  default:
1327310Sgblack@eecs.umich.edu                    panic("Flattening into an unknown mode.\n");
1337310Sgblack@eecs.umich.edu                }
1346718Sgblack@eecs.umich.edu            }
1356313Sgblack@eecs.umich.edu        }
1366313Sgblack@eecs.umich.edu
1376313Sgblack@eecs.umich.edu        int
1386313Sgblack@eecs.umich.edu        flattenFloatIndex(int reg)
1396313Sgblack@eecs.umich.edu        {
1406313Sgblack@eecs.umich.edu            return reg;
1416313Sgblack@eecs.umich.edu        }
1426313Sgblack@eecs.umich.edu
1439920Syasuko.eckert@amd.com        // dummy
1449920Syasuko.eckert@amd.com        int
1459920Syasuko.eckert@amd.com        flattenCCIndex(int reg)
1469920Syasuko.eckert@amd.com        {
1479920Syasuko.eckert@amd.com            return reg;
1489920Syasuko.eckert@amd.com        }
1499920Syasuko.eckert@amd.com
1507614Sminkyu.jeong@arm.com        int
1517614Sminkyu.jeong@arm.com        flattenMiscIndex(int reg)
1527614Sminkyu.jeong@arm.com        {
1537614Sminkyu.jeong@arm.com            if (reg == MISCREG_SPSR) {
1547614Sminkyu.jeong@arm.com                int spsr_idx = NUM_MISCREGS;
1557614Sminkyu.jeong@arm.com                CPSR cpsr = miscRegs[MISCREG_CPSR];
1567614Sminkyu.jeong@arm.com                switch (cpsr.mode) {
1577614Sminkyu.jeong@arm.com                  case MODE_USER:
1587614Sminkyu.jeong@arm.com                    warn("User mode does not have SPSR\n");
1597614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR;
1607614Sminkyu.jeong@arm.com                    break;
1617614Sminkyu.jeong@arm.com                  case MODE_FIQ:
1627614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_FIQ;
1637614Sminkyu.jeong@arm.com                    break;
1647614Sminkyu.jeong@arm.com                  case MODE_IRQ:
1657614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_IRQ;
1667614Sminkyu.jeong@arm.com                    break;
1677614Sminkyu.jeong@arm.com                  case MODE_SVC:
1687614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_SVC;
1697614Sminkyu.jeong@arm.com                    break;
1707614Sminkyu.jeong@arm.com                  case MODE_MON:
1717614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_MON;
1727614Sminkyu.jeong@arm.com                    break;
1737614Sminkyu.jeong@arm.com                  case MODE_ABORT:
1747614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_ABT;
1757614Sminkyu.jeong@arm.com                    break;
1767614Sminkyu.jeong@arm.com                  case MODE_UNDEFINED:
1777614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR_UND;
1787614Sminkyu.jeong@arm.com                    break;
1797614Sminkyu.jeong@arm.com                  default:
1807614Sminkyu.jeong@arm.com                    warn("Trying to access SPSR in an invalid mode: %d\n",
1817614Sminkyu.jeong@arm.com                         cpsr.mode);
1827614Sminkyu.jeong@arm.com                    spsr_idx = MISCREG_SPSR;
1837614Sminkyu.jeong@arm.com                    break;
1847614Sminkyu.jeong@arm.com                }
1857614Sminkyu.jeong@arm.com                return spsr_idx;
1867614Sminkyu.jeong@arm.com            }
1877614Sminkyu.jeong@arm.com            return reg;
1887614Sminkyu.jeong@arm.com        }
1897614Sminkyu.jeong@arm.com
1909425SAndreas.Sandberg@ARM.com        void serialize(std::ostream &os)
1917733SAli.Saidi@ARM.com        {
1927733SAli.Saidi@ARM.com            DPRINTF(Checkpoint, "Serializing Arm Misc Registers\n");
1937733SAli.Saidi@ARM.com            SERIALIZE_ARRAY(miscRegs, NumMiscRegs);
1947733SAli.Saidi@ARM.com        }
1959425SAndreas.Sandberg@ARM.com        void unserialize(Checkpoint *cp, const std::string &section)
1967733SAli.Saidi@ARM.com        {
1977733SAli.Saidi@ARM.com            DPRINTF(Checkpoint, "Unserializing Arm Misc Registers\n");
1987733SAli.Saidi@ARM.com            UNSERIALIZE_ARRAY(miscRegs, NumMiscRegs);
1997733SAli.Saidi@ARM.com            CPSR tmp_cpsr = miscRegs[MISCREG_CPSR];
2007733SAli.Saidi@ARM.com            updateRegMap(tmp_cpsr);
2017733SAli.Saidi@ARM.com        }
2026313Sgblack@eecs.umich.edu
2039461Snilay@cs.wisc.edu        void startup(ThreadContext *tc) {}
2049461Snilay@cs.wisc.edu
2059553Sandreas.hansson@arm.com        /// Explicitly import the otherwise hidden startup
2069553Sandreas.hansson@arm.com        using SimObject::startup;
2079553Sandreas.hansson@arm.com
2089384SAndreas.Sandberg@arm.com        typedef ArmISAParams Params;
2097400SAli.Saidi@ARM.com
2109384SAndreas.Sandberg@arm.com        const Params *params() const;
2119384SAndreas.Sandberg@arm.com
2129384SAndreas.Sandberg@arm.com        ISA(Params *p);
2136313Sgblack@eecs.umich.edu    };
2146313Sgblack@eecs.umich.edu}
2156313Sgblack@eecs.umich.edu
2166313Sgblack@eecs.umich.edu#endif
217