isa.hh revision 6806
16313Sgblack@eecs.umich.edu/*
26313Sgblack@eecs.umich.edu * Copyright (c) 2009 The Regents of The University of Michigan
36313Sgblack@eecs.umich.edu * All rights reserved.
46313Sgblack@eecs.umich.edu *
56313Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
66313Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
76313Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
86313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
96313Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
106313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
116313Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
126313Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
136313Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
146313Sgblack@eecs.umich.edu * this software without specific prior written permission.
156313Sgblack@eecs.umich.edu *
166313Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176313Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186313Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196313Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206313Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216313Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226313Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236313Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246313Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256313Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276313Sgblack@eecs.umich.edu *
286313Sgblack@eecs.umich.edu * Authors: Gabe Black
296313Sgblack@eecs.umich.edu */
306313Sgblack@eecs.umich.edu
316313Sgblack@eecs.umich.edu#ifndef __ARCH_ARM_ISA_HH__
326313Sgblack@eecs.umich.edu#define __ARCH_MRM_ISA_HH__
336313Sgblack@eecs.umich.edu
346333Sgblack@eecs.umich.edu#include "arch/arm/registers.hh"
356313Sgblack@eecs.umich.edu#include "arch/arm/types.hh"
366313Sgblack@eecs.umich.edu
376333Sgblack@eecs.umich.educlass ThreadContext;
386313Sgblack@eecs.umich.educlass Checkpoint;
396313Sgblack@eecs.umich.educlass EventManager;
406313Sgblack@eecs.umich.edu
416313Sgblack@eecs.umich.edunamespace ArmISA
426313Sgblack@eecs.umich.edu{
436313Sgblack@eecs.umich.edu    class ISA
446313Sgblack@eecs.umich.edu    {
456313Sgblack@eecs.umich.edu      protected:
466333Sgblack@eecs.umich.edu        MiscReg miscRegs[NumMiscRegs];
476718Sgblack@eecs.umich.edu        const IntRegIndex *intRegMap;
486718Sgblack@eecs.umich.edu
496718Sgblack@eecs.umich.edu        void
506718Sgblack@eecs.umich.edu        updateRegMap(CPSR cpsr)
516718Sgblack@eecs.umich.edu        {
526718Sgblack@eecs.umich.edu            switch (cpsr.mode) {
536718Sgblack@eecs.umich.edu              case MODE_USER:
546718Sgblack@eecs.umich.edu              case MODE_SYSTEM:
556718Sgblack@eecs.umich.edu                intRegMap = IntRegUsrMap;
566718Sgblack@eecs.umich.edu                break;
576718Sgblack@eecs.umich.edu              case MODE_FIQ:
586718Sgblack@eecs.umich.edu                intRegMap = IntRegFiqMap;
596718Sgblack@eecs.umich.edu                break;
606718Sgblack@eecs.umich.edu              case MODE_IRQ:
616718Sgblack@eecs.umich.edu                intRegMap = IntRegIrqMap;
626718Sgblack@eecs.umich.edu                break;
636718Sgblack@eecs.umich.edu              case MODE_SVC:
646718Sgblack@eecs.umich.edu                intRegMap = IntRegSvcMap;
656718Sgblack@eecs.umich.edu                break;
666723Sgblack@eecs.umich.edu              case MODE_MON:
676723Sgblack@eecs.umich.edu                intRegMap = IntRegMonMap;
686723Sgblack@eecs.umich.edu                break;
696718Sgblack@eecs.umich.edu              case MODE_ABORT:
706718Sgblack@eecs.umich.edu                intRegMap = IntRegAbtMap;
716718Sgblack@eecs.umich.edu                break;
726718Sgblack@eecs.umich.edu              case MODE_UNDEFINED:
736718Sgblack@eecs.umich.edu                intRegMap = IntRegUndMap;
746718Sgblack@eecs.umich.edu                break;
756718Sgblack@eecs.umich.edu              default:
766718Sgblack@eecs.umich.edu                panic("Unrecognized mode setting in CPSR.\n");
776718Sgblack@eecs.umich.edu            }
786718Sgblack@eecs.umich.edu        }
796313Sgblack@eecs.umich.edu
806313Sgblack@eecs.umich.edu      public:
816333Sgblack@eecs.umich.edu        void clear()
826333Sgblack@eecs.umich.edu        {
836401Sgblack@eecs.umich.edu            memset(miscRegs, 0, sizeof(miscRegs));
846401Sgblack@eecs.umich.edu            CPSR cpsr = 0;
856719Sgblack@eecs.umich.edu            cpsr.mode = MODE_USER;
866401Sgblack@eecs.umich.edu            miscRegs[MISCREG_CPSR] = cpsr;
876718Sgblack@eecs.umich.edu            updateRegMap(cpsr);
886735Sgblack@eecs.umich.edu
896735Sgblack@eecs.umich.edu            SCTLR sctlr = 0;
906735Sgblack@eecs.umich.edu            sctlr.nmfi = 1;
916735Sgblack@eecs.umich.edu            sctlr.rao1 = 1;
926735Sgblack@eecs.umich.edu            sctlr.rao2 = 1;
936735Sgblack@eecs.umich.edu            sctlr.rao3 = 1;
946735Sgblack@eecs.umich.edu            sctlr.rao4 = 1;
956735Sgblack@eecs.umich.edu
966401Sgblack@eecs.umich.edu            //XXX We need to initialize the rest of the state.
976333Sgblack@eecs.umich.edu        }
986313Sgblack@eecs.umich.edu
996333Sgblack@eecs.umich.edu        MiscReg
1006333Sgblack@eecs.umich.edu        readMiscRegNoEffect(int misc_reg)
1016333Sgblack@eecs.umich.edu        {
1026333Sgblack@eecs.umich.edu            assert(misc_reg < NumMiscRegs);
1036745Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_SPSR) {
1046745Sgblack@eecs.umich.edu                CPSR cpsr = miscRegs[MISCREG_CPSR];
1056745Sgblack@eecs.umich.edu                switch (cpsr.mode) {
1066745Sgblack@eecs.umich.edu                  case MODE_USER:
1076745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR];
1086745Sgblack@eecs.umich.edu                  case MODE_FIQ:
1096745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_FIQ];
1106745Sgblack@eecs.umich.edu                  case MODE_IRQ:
1116745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_IRQ];
1126745Sgblack@eecs.umich.edu                  case MODE_SVC:
1136745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_SVC];
1146745Sgblack@eecs.umich.edu                  case MODE_MON:
1156745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_MON];
1166745Sgblack@eecs.umich.edu                  case MODE_ABORT:
1176745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_ABT];
1186745Sgblack@eecs.umich.edu                  case MODE_UNDEFINED:
1196745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR_UND];
1206745Sgblack@eecs.umich.edu                  default:
1216745Sgblack@eecs.umich.edu                    return miscRegs[MISCREG_SPSR];
1226745Sgblack@eecs.umich.edu                }
1236745Sgblack@eecs.umich.edu            }
1246333Sgblack@eecs.umich.edu            return miscRegs[misc_reg];
1256333Sgblack@eecs.umich.edu        }
1266313Sgblack@eecs.umich.edu
1276333Sgblack@eecs.umich.edu        MiscReg
1286333Sgblack@eecs.umich.edu        readMiscReg(int misc_reg, ThreadContext *tc)
1296333Sgblack@eecs.umich.edu        {
1306745Sgblack@eecs.umich.edu            return readMiscRegNoEffect(misc_reg);
1316333Sgblack@eecs.umich.edu        }
1326333Sgblack@eecs.umich.edu
1336333Sgblack@eecs.umich.edu        void
1346333Sgblack@eecs.umich.edu        setMiscRegNoEffect(int misc_reg, const MiscReg &val)
1356333Sgblack@eecs.umich.edu        {
1366333Sgblack@eecs.umich.edu            assert(misc_reg < NumMiscRegs);
1376745Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_SPSR) {
1386745Sgblack@eecs.umich.edu                CPSR cpsr = miscRegs[MISCREG_CPSR];
1396745Sgblack@eecs.umich.edu                switch (cpsr.mode) {
1406745Sgblack@eecs.umich.edu                  case MODE_USER:
1416745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR] = val;
1426745Sgblack@eecs.umich.edu                    return;
1436745Sgblack@eecs.umich.edu                  case MODE_FIQ:
1446745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_FIQ] = val;
1456745Sgblack@eecs.umich.edu                    return;
1466745Sgblack@eecs.umich.edu                  case MODE_IRQ:
1476745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_IRQ] = val;
1486745Sgblack@eecs.umich.edu                    return;
1496745Sgblack@eecs.umich.edu                  case MODE_SVC:
1506745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_SVC] = val;
1516745Sgblack@eecs.umich.edu                    return;
1526745Sgblack@eecs.umich.edu                  case MODE_MON:
1536745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_MON] = val;
1546745Sgblack@eecs.umich.edu                    return;
1556745Sgblack@eecs.umich.edu                  case MODE_ABORT:
1566745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_ABT] = val;
1576745Sgblack@eecs.umich.edu                    return;
1586745Sgblack@eecs.umich.edu                  case MODE_UNDEFINED:
1596745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR_UND] = val;
1606745Sgblack@eecs.umich.edu                    return;
1616745Sgblack@eecs.umich.edu                  default:
1626745Sgblack@eecs.umich.edu                    miscRegs[MISCREG_SPSR] = val;
1636745Sgblack@eecs.umich.edu                    return;
1646745Sgblack@eecs.umich.edu                }
1656745Sgblack@eecs.umich.edu            }
1666333Sgblack@eecs.umich.edu            miscRegs[misc_reg] = val;
1676333Sgblack@eecs.umich.edu        }
1686333Sgblack@eecs.umich.edu
1696333Sgblack@eecs.umich.edu        void
1706333Sgblack@eecs.umich.edu        setMiscReg(int misc_reg, const MiscReg &val, ThreadContext *tc)
1716333Sgblack@eecs.umich.edu        {
1726718Sgblack@eecs.umich.edu            if (misc_reg == MISCREG_CPSR) {
1736718Sgblack@eecs.umich.edu                updateRegMap(val);
1746718Sgblack@eecs.umich.edu            }
1756745Sgblack@eecs.umich.edu            return setMiscRegNoEffect(misc_reg, val);
1766333Sgblack@eecs.umich.edu        }
1776313Sgblack@eecs.umich.edu
1786313Sgblack@eecs.umich.edu        int
1796313Sgblack@eecs.umich.edu        flattenIntIndex(int reg)
1806313Sgblack@eecs.umich.edu        {
1816718Sgblack@eecs.umich.edu            assert(reg >= 0);
1826718Sgblack@eecs.umich.edu            if (reg < NUM_ARCH_INTREGS) {
1836718Sgblack@eecs.umich.edu                return intRegMap[reg];
1846726Sgblack@eecs.umich.edu            } else if (reg < NUM_INTREGS) {
1856726Sgblack@eecs.umich.edu                return reg;
1866718Sgblack@eecs.umich.edu            } else {
1876726Sgblack@eecs.umich.edu                reg -= NUM_INTREGS;
1886726Sgblack@eecs.umich.edu                assert(reg < NUM_ARCH_INTREGS);
1896718Sgblack@eecs.umich.edu                return reg;
1906718Sgblack@eecs.umich.edu            }
1916313Sgblack@eecs.umich.edu        }
1926313Sgblack@eecs.umich.edu
1936313Sgblack@eecs.umich.edu        int
1946313Sgblack@eecs.umich.edu        flattenFloatIndex(int reg)
1956313Sgblack@eecs.umich.edu        {
1966313Sgblack@eecs.umich.edu            return reg;
1976313Sgblack@eecs.umich.edu        }
1986313Sgblack@eecs.umich.edu
1996678Sgblack@eecs.umich.edu        void serialize(EventManager *em, std::ostream &os)
2006333Sgblack@eecs.umich.edu        {}
2016678Sgblack@eecs.umich.edu        void unserialize(EventManager *em, Checkpoint *cp,
2026678Sgblack@eecs.umich.edu                const std::string &section)
2036333Sgblack@eecs.umich.edu        {}
2046313Sgblack@eecs.umich.edu
2056313Sgblack@eecs.umich.edu        ISA()
2066313Sgblack@eecs.umich.edu        {
2076313Sgblack@eecs.umich.edu            clear();
2086313Sgblack@eecs.umich.edu        }
2096313Sgblack@eecs.umich.edu    };
2106313Sgblack@eecs.umich.edu}
2116313Sgblack@eecs.umich.edu
2126313Sgblack@eecs.umich.edu#endif
213