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_MIPS_ISA_HH__
326313Sgblack@eecs.umich.edu#define __ARCH_MIPS_ISA_HH__
336313Sgblack@eecs.umich.edu
348229Snate@binkert.org#include <queue>
356334Sgblack@eecs.umich.edu#include <string>
366334Sgblack@eecs.umich.edu#include <vector>
376334Sgblack@eecs.umich.edu
386334Sgblack@eecs.umich.edu#include "arch/mips/registers.hh"
396313Sgblack@eecs.umich.edu#include "arch/mips/types.hh"
4012106SRekai.GonzalezAlberquilla@arm.com#include "cpu/reg_class.hh"
416334Sgblack@eecs.umich.edu#include "sim/eventq.hh"
429384SAndreas.Sandberg@arm.com#include "sim/sim_object.hh"
436313Sgblack@eecs.umich.edu
446334Sgblack@eecs.umich.educlass BaseCPU;
456313Sgblack@eecs.umich.educlass Checkpoint;
466313Sgblack@eecs.umich.educlass EventManager;
479384SAndreas.Sandberg@arm.comstruct MipsISAParams;
486334Sgblack@eecs.umich.educlass ThreadContext;
496313Sgblack@eecs.umich.edu
506313Sgblack@eecs.umich.edunamespace MipsISA
516313Sgblack@eecs.umich.edu{
529384SAndreas.Sandberg@arm.com    class ISA : public SimObject
536313Sgblack@eecs.umich.edu    {
546334Sgblack@eecs.umich.edu      public:
556334Sgblack@eecs.umich.edu        // The MIPS name for this file is CP0 or Coprocessor 0
566334Sgblack@eecs.umich.edu        typedef ISA CP0;
576334Sgblack@eecs.umich.edu
589384SAndreas.Sandberg@arm.com        typedef MipsISAParams Params;
599384SAndreas.Sandberg@arm.com
606313Sgblack@eecs.umich.edu      protected:
618181Sksewell@umich.edu        // Number of threads and vpes an individual ISA state can handle
628181Sksewell@umich.edu        uint8_t numThreads;
638181Sksewell@umich.edu        uint8_t numVpes;
648181Sksewell@umich.edu
656334Sgblack@eecs.umich.edu        enum BankType {
666334Sgblack@eecs.umich.edu            perProcessor,
676334Sgblack@eecs.umich.edu            perThreadContext,
686334Sgblack@eecs.umich.edu            perVirtProcessor
696334Sgblack@eecs.umich.edu        };
706334Sgblack@eecs.umich.edu
7113615Sgabeblack@google.com        std::vector<std::vector<RegVal> > miscRegFile;
7213615Sgabeblack@google.com        std::vector<std::vector<RegVal> > miscRegFile_WriteMask;
736334Sgblack@eecs.umich.edu        std::vector<BankType> bankType;
746334Sgblack@eecs.umich.edu
756313Sgblack@eecs.umich.edu      public:
768181Sksewell@umich.edu        void clear();
776334Sgblack@eecs.umich.edu
788181Sksewell@umich.edu        void configCP();
796334Sgblack@eecs.umich.edu
8010698Sandreas.hansson@arm.com        unsigned getVPENum(ThreadID tid) const;
816334Sgblack@eecs.umich.edu
826334Sgblack@eecs.umich.edu        //////////////////////////////////////////////////////////
836334Sgblack@eecs.umich.edu        //
846334Sgblack@eecs.umich.edu        // READ/WRITE CP0 STATE
856334Sgblack@eecs.umich.edu        //
866334Sgblack@eecs.umich.edu        //
876334Sgblack@eecs.umich.edu        //////////////////////////////////////////////////////////
886334Sgblack@eecs.umich.edu        //@TODO: MIPS MT's register view automatically connects
896334Sgblack@eecs.umich.edu        //       Status to TCStatus depending on current thread
906334Sgblack@eecs.umich.edu        void updateCP0ReadView(int misc_reg, ThreadID tid) { }
9113615Sgabeblack@google.com        RegVal readMiscRegNoEffect(int misc_reg, ThreadID tid = 0) const;
926334Sgblack@eecs.umich.edu
936334Sgblack@eecs.umich.edu        //template <class TC>
9413615Sgabeblack@google.com        RegVal readMiscReg(int misc_reg, ThreadContext *tc, ThreadID tid = 0);
956334Sgblack@eecs.umich.edu
9613615Sgabeblack@google.com        RegVal filterCP0Write(int misc_reg, int reg_sel, RegVal val);
9713615Sgabeblack@google.com        void setRegMask(int misc_reg, RegVal val, ThreadID tid = 0);
9813615Sgabeblack@google.com        void setMiscRegNoEffect(int misc_reg, RegVal val, ThreadID tid=0);
996334Sgblack@eecs.umich.edu
1006334Sgblack@eecs.umich.edu        //template <class TC>
10113615Sgabeblack@google.com        void setMiscReg(int misc_reg, RegVal val,
10213582Sgabeblack@google.com                        ThreadContext *tc, ThreadID tid=0);
1036334Sgblack@eecs.umich.edu
1046334Sgblack@eecs.umich.edu        //////////////////////////////////////////////////////////
1056334Sgblack@eecs.umich.edu        //
1066334Sgblack@eecs.umich.edu        // DECLARE INTERFACE THAT WILL ALLOW A MiscRegFile (Cop0)
1076334Sgblack@eecs.umich.edu        // TO SCHEDULE EVENTS
1086334Sgblack@eecs.umich.edu        //
1096334Sgblack@eecs.umich.edu        //////////////////////////////////////////////////////////
1106334Sgblack@eecs.umich.edu
1116334Sgblack@eecs.umich.edu        // Flag that is set when CP0 state has been written to.
1126334Sgblack@eecs.umich.edu        bool cp0Updated;
1136334Sgblack@eecs.umich.edu
1146334Sgblack@eecs.umich.edu        // Enumerated List of CP0 Event Types
1156334Sgblack@eecs.umich.edu        enum CP0EventType {
1166334Sgblack@eecs.umich.edu            UpdateCP0
1176334Sgblack@eecs.umich.edu        };
1186334Sgblack@eecs.umich.edu
11912124Sspwilson2@wisc.edu        /** Process a CP0 event */
12012124Sspwilson2@wisc.edu        void processCP0Event(BaseCPU *cpu, CP0EventType);
1216334Sgblack@eecs.umich.edu
1226334Sgblack@eecs.umich.edu        // Schedule a CP0 Update Event
1239180Sandreas.hansson@arm.com        void scheduleCP0Update(BaseCPU *cpu, Cycles delay = Cycles(0));
1246334Sgblack@eecs.umich.edu
1256334Sgblack@eecs.umich.edu        // If any changes have been made, then check the state for changes
1266334Sgblack@eecs.umich.edu        // and if necessary alert the CPU
1276806Sgblack@eecs.umich.edu        void updateCPU(BaseCPU *cpu);
1286334Sgblack@eecs.umich.edu
1296334Sgblack@eecs.umich.edu        static std::string miscRegNames[NumMiscRegs];
1306334Sgblack@eecs.umich.edu
1316334Sgblack@eecs.umich.edu      public:
1329461Snilay@cs.wisc.edu        void startup(ThreadContext *tc) {}
1339461Snilay@cs.wisc.edu
1349553Sandreas.hansson@arm.com        /// Explicitly import the otherwise hidden startup
1359553Sandreas.hansson@arm.com        using SimObject::startup;
1369553Sandreas.hansson@arm.com
1379384SAndreas.Sandberg@arm.com        const Params *params() const;
1389384SAndreas.Sandberg@arm.com
1399384SAndreas.Sandberg@arm.com        ISA(Params *p);
1406313Sgblack@eecs.umich.edu
14112106SRekai.GonzalezAlberquilla@arm.com        RegId flattenRegId(const RegId& regId) const { return regId; }
14212106SRekai.GonzalezAlberquilla@arm.com
1436313Sgblack@eecs.umich.edu        int
14410035Sandreas.hansson@arm.com        flattenIntIndex(int reg) const
1456313Sgblack@eecs.umich.edu        {
1466313Sgblack@eecs.umich.edu            return reg;
1476313Sgblack@eecs.umich.edu        }
1486313Sgblack@eecs.umich.edu
1496313Sgblack@eecs.umich.edu        int
15010035Sandreas.hansson@arm.com        flattenFloatIndex(int reg) const
1516313Sgblack@eecs.umich.edu        {
1526313Sgblack@eecs.umich.edu            return reg;
1536313Sgblack@eecs.umich.edu        }
1549920Syasuko.eckert@amd.com
15512109SRekai.GonzalezAlberquilla@arm.com        int
15612109SRekai.GonzalezAlberquilla@arm.com        flattenVecIndex(int reg) const
15712109SRekai.GonzalezAlberquilla@arm.com        {
15812109SRekai.GonzalezAlberquilla@arm.com            return reg;
15912109SRekai.GonzalezAlberquilla@arm.com        }
16012109SRekai.GonzalezAlberquilla@arm.com
16112109SRekai.GonzalezAlberquilla@arm.com        int
16212109SRekai.GonzalezAlberquilla@arm.com        flattenVecElemIndex(int reg) const
16312109SRekai.GonzalezAlberquilla@arm.com        {
16412109SRekai.GonzalezAlberquilla@arm.com            return reg;
16512109SRekai.GonzalezAlberquilla@arm.com        }
16612109SRekai.GonzalezAlberquilla@arm.com
16713610Sgiacomo.gabrielli@arm.com        int
16813610Sgiacomo.gabrielli@arm.com        flattenVecPredIndex(int reg) const
16913610Sgiacomo.gabrielli@arm.com        {
17013610Sgiacomo.gabrielli@arm.com            return reg;
17113610Sgiacomo.gabrielli@arm.com        }
17213610Sgiacomo.gabrielli@arm.com
1739920Syasuko.eckert@amd.com        // dummy
1749920Syasuko.eckert@amd.com        int
17510035Sandreas.hansson@arm.com        flattenCCIndex(int reg) const
1769920Syasuko.eckert@amd.com        {
1779920Syasuko.eckert@amd.com            return reg;
1789920Syasuko.eckert@amd.com        }
17910033SAli.Saidi@ARM.com
18010033SAli.Saidi@ARM.com        int
18110035Sandreas.hansson@arm.com        flattenMiscIndex(int reg) const
18210033SAli.Saidi@ARM.com        {
18310033SAli.Saidi@ARM.com            return reg;
18410033SAli.Saidi@ARM.com        }
18510033SAli.Saidi@ARM.com
1866313Sgblack@eecs.umich.edu    };
1876313Sgblack@eecs.umich.edu}
1886313Sgblack@eecs.umich.edu
1896313Sgblack@eecs.umich.edu#endif
190