cpu.hh revision 10407
11689SN/A/*
29608Sandreas.hansson@arm.com * Copyright (c) 2011-2013 ARM Limited
39919Ssteve.reinhardt@amd.com * Copyright (c) 2013 Advanced Micro Devices, Inc.
48707Sandreas.hansson@arm.com * All rights reserved
58707Sandreas.hansson@arm.com *
68707Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
78707Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
88707Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
98707Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
108707Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
118707Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
128707Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
138707Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
148707Sandreas.hansson@arm.com *
151689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
167897Shestness@cs.utexas.edu * Copyright (c) 2011 Regents of the University of California
171689SN/A * All rights reserved.
181689SN/A *
191689SN/A * Redistribution and use in source and binary forms, with or without
201689SN/A * modification, are permitted provided that the following conditions are
211689SN/A * met: redistributions of source code must retain the above copyright
221689SN/A * notice, this list of conditions and the following disclaimer;
231689SN/A * redistributions in binary form must reproduce the above copyright
241689SN/A * notice, this list of conditions and the following disclaimer in the
251689SN/A * documentation and/or other materials provided with the distribution;
261689SN/A * neither the name of the copyright holders nor the names of its
271689SN/A * contributors may be used to endorse or promote products derived from
281689SN/A * this software without specific prior written permission.
291689SN/A *
301689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
311689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
321689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
331689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
341689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
351689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
361689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
371689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
381689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
391689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
401689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
412665Ssaidi@eecs.umich.edu *
422665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
432756Sksewell@umich.edu *          Korey Sewell
447897Shestness@cs.utexas.edu *          Rick Strong
451689SN/A */
461689SN/A
472325SN/A#ifndef __CPU_O3_CPU_HH__
482325SN/A#define __CPU_O3_CPU_HH__
491060SN/A
501060SN/A#include <iostream>
511060SN/A#include <list>
522292SN/A#include <queue>
532292SN/A#include <set>
541681SN/A#include <vector>
551060SN/A
562980Sgblack@eecs.umich.edu#include "arch/types.hh"
571060SN/A#include "base/statistics.hh"
586658Snate@binkert.org#include "config/the_isa.hh"
591717SN/A#include "cpu/o3/comm.hh"
601717SN/A#include "cpu/o3/cpu_policy.hh"
612292SN/A#include "cpu/o3/scoreboard.hh"
622292SN/A#include "cpu/o3/thread_state.hh"
638229Snate@binkert.org#include "cpu/activity.hh"
648229Snate@binkert.org#include "cpu/base.hh"
658229Snate@binkert.org#include "cpu/simple_thread.hh"
668229Snate@binkert.org#include "cpu/timebuf.hh"
672817Sksewell@umich.edu//#include "cpu/o3/thread_context.hh"
688229Snate@binkert.org#include "params/DerivO3CPU.hh"
691060SN/A#include "sim/process.hh"
701060SN/A
712316SN/Atemplate <class>
722316SN/Aclass Checker;
732680Sktlim@umich.educlass ThreadContext;
742817Sksewell@umich.edutemplate <class>
752817Sksewell@umich.educlass O3ThreadContext;
762843Sktlim@umich.edu
772843Sktlim@umich.educlass Checkpoint;
782669Sktlim@umich.educlass MemObject;
791060SN/Aclass Process;
801060SN/A
818737Skoansin.tan@gmail.comstruct BaseCPUParams;
825529Snate@binkert.org
832733Sktlim@umich.educlass BaseO3CPU : public BaseCPU
841060SN/A{
851060SN/A    //Stuff that's pretty ISA independent will go here.
861060SN/A  public:
875529Snate@binkert.org    BaseO3CPU(BaseCPUParams *params);
882292SN/A
892292SN/A    void regStats();
901060SN/A};
911060SN/A
922348SN/A/**
932348SN/A * FullO3CPU class, has each of the stages (fetch through commit)
942348SN/A * within it, as well as all of the time buffers between stages.  The
952348SN/A * tick() function for the CPU is defined here.
962348SN/A */
971060SN/Atemplate <class Impl>
982733Sktlim@umich.educlass FullO3CPU : public BaseO3CPU
991060SN/A{
1001060SN/A  public:
1012325SN/A    // Typedefs from the Impl here.
1021060SN/A    typedef typename Impl::CPUPol CPUPolicy;
1031061SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
1044329Sktlim@umich.edu    typedef typename Impl::O3CPU O3CPU;
1051060SN/A
1065595Sgblack@eecs.umich.edu    typedef O3ThreadState<Impl> ImplState;
1072292SN/A    typedef O3ThreadState<Impl> Thread;
1082292SN/A
1092292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
1102292SN/A
1112817Sksewell@umich.edu    friend class O3ThreadContext<Impl>;
1122829Sksewell@umich.edu
1131060SN/A  public:
1141060SN/A    enum Status {
1151060SN/A        Running,
1161060SN/A        Idle,
1171060SN/A        Halted,
1182307SN/A        Blocked,
1192307SN/A        SwitchedOut
1201060SN/A    };
1211060SN/A
1226022Sgblack@eecs.umich.edu    TheISA::TLB * itb;
1236022Sgblack@eecs.umich.edu    TheISA::TLB * dtb;
1243781Sgblack@eecs.umich.edu
1252292SN/A    /** Overall CPU status. */
1261060SN/A    Status _status;
1271060SN/A
1281060SN/A  private:
1298707Sandreas.hansson@arm.com
1308707Sandreas.hansson@arm.com    /**
1318707Sandreas.hansson@arm.com     * IcachePort class for instruction fetch.
1328707Sandreas.hansson@arm.com     */
1339608Sandreas.hansson@arm.com    class IcachePort : public MasterPort
1348707Sandreas.hansson@arm.com    {
1358707Sandreas.hansson@arm.com      protected:
1368707Sandreas.hansson@arm.com        /** Pointer to fetch. */
1378707Sandreas.hansson@arm.com        DefaultFetch<Impl> *fetch;
1388707Sandreas.hansson@arm.com
1398707Sandreas.hansson@arm.com      public:
1408707Sandreas.hansson@arm.com        /** Default constructor. */
1418707Sandreas.hansson@arm.com        IcachePort(DefaultFetch<Impl> *_fetch, FullO3CPU<Impl>* _cpu)
1429608Sandreas.hansson@arm.com            : MasterPort(_cpu->name() + ".icache_port", _cpu), fetch(_fetch)
1438707Sandreas.hansson@arm.com        { }
1448707Sandreas.hansson@arm.com
1458707Sandreas.hansson@arm.com      protected:
1468707Sandreas.hansson@arm.com
1478707Sandreas.hansson@arm.com        /** Timing version of receive.  Handles setting fetch to the
1488707Sandreas.hansson@arm.com         * proper status to start fetching. */
1498975Sandreas.hansson@arm.com        virtual bool recvTimingResp(PacketPtr pkt);
1508975Sandreas.hansson@arm.com        virtual void recvTimingSnoopReq(PacketPtr pkt) { }
1518707Sandreas.hansson@arm.com
1528707Sandreas.hansson@arm.com        /** Handles doing a retry of a failed fetch. */
1538707Sandreas.hansson@arm.com        virtual void recvRetry();
1548707Sandreas.hansson@arm.com    };
1558707Sandreas.hansson@arm.com
1568707Sandreas.hansson@arm.com    /**
1578707Sandreas.hansson@arm.com     * DcachePort class for the load/store queue.
1588707Sandreas.hansson@arm.com     */
1599608Sandreas.hansson@arm.com    class DcachePort : public MasterPort
1608707Sandreas.hansson@arm.com    {
1618707Sandreas.hansson@arm.com      protected:
1628707Sandreas.hansson@arm.com
1638707Sandreas.hansson@arm.com        /** Pointer to LSQ. */
1648707Sandreas.hansson@arm.com        LSQ<Impl> *lsq;
1658707Sandreas.hansson@arm.com
1668707Sandreas.hansson@arm.com      public:
1678707Sandreas.hansson@arm.com        /** Default constructor. */
1688707Sandreas.hansson@arm.com        DcachePort(LSQ<Impl> *_lsq, FullO3CPU<Impl>* _cpu)
1699608Sandreas.hansson@arm.com            : MasterPort(_cpu->name() + ".dcache_port", _cpu), lsq(_lsq)
1708707Sandreas.hansson@arm.com        { }
1718707Sandreas.hansson@arm.com
1728707Sandreas.hansson@arm.com      protected:
1738707Sandreas.hansson@arm.com
1748707Sandreas.hansson@arm.com        /** Timing version of receive.  Handles writing back and
1758707Sandreas.hansson@arm.com         * completing the load or store that has returned from
1768707Sandreas.hansson@arm.com         * memory. */
1778975Sandreas.hansson@arm.com        virtual bool recvTimingResp(PacketPtr pkt);
1788975Sandreas.hansson@arm.com        virtual void recvTimingSnoopReq(PacketPtr pkt);
1798707Sandreas.hansson@arm.com
1809608Sandreas.hansson@arm.com        virtual void recvFunctionalSnoop(PacketPtr pkt)
1819608Sandreas.hansson@arm.com        {
1829608Sandreas.hansson@arm.com            // @todo: Is there a need for potential invalidation here?
1839608Sandreas.hansson@arm.com        }
1849608Sandreas.hansson@arm.com
1858707Sandreas.hansson@arm.com        /** Handles doing a retry of the previous send. */
1868707Sandreas.hansson@arm.com        virtual void recvRetry();
1878707Sandreas.hansson@arm.com
1888707Sandreas.hansson@arm.com        /**
1898707Sandreas.hansson@arm.com         * As this CPU requires snooping to maintain the load store queue
1908707Sandreas.hansson@arm.com         * change the behaviour from the base CPU port.
1918707Sandreas.hansson@arm.com         *
1928711Sandreas.hansson@arm.com         * @return true since we have to snoop
1938707Sandreas.hansson@arm.com         */
1948922Swilliam.wang@arm.com        virtual bool isSnooping() const { return true; }
1958707Sandreas.hansson@arm.com    };
1968707Sandreas.hansson@arm.com
1971060SN/A    class TickEvent : public Event
1981060SN/A    {
1991060SN/A      private:
2002292SN/A        /** Pointer to the CPU. */
2011755SN/A        FullO3CPU<Impl> *cpu;
2021060SN/A
2031060SN/A      public:
2042292SN/A        /** Constructs a tick event. */
2051755SN/A        TickEvent(FullO3CPU<Impl> *c);
2062292SN/A
2072292SN/A        /** Processes a tick event, calling tick() on the CPU. */
2081060SN/A        void process();
2092292SN/A        /** Returns the description of the tick event. */
2105336Shines@cs.fsu.edu        const char *description() const;
2111060SN/A    };
2121060SN/A
2132292SN/A    /** The tick event used for scheduling CPU ticks. */
2141060SN/A    TickEvent tickEvent;
2151060SN/A
2162292SN/A    /** Schedule tick event, regardless of its current state. */
2179180Sandreas.hansson@arm.com    void scheduleTickEvent(Cycles delay)
2181060SN/A    {
2191060SN/A        if (tickEvent.squashed())
2209179Sandreas.hansson@arm.com            reschedule(tickEvent, clockEdge(delay));
2211060SN/A        else if (!tickEvent.scheduled())
2229179Sandreas.hansson@arm.com            schedule(tickEvent, clockEdge(delay));
2231060SN/A    }
2241060SN/A
2252292SN/A    /** Unschedule tick event, regardless of its current state. */
2261060SN/A    void unscheduleTickEvent()
2271060SN/A    {
2281060SN/A        if (tickEvent.scheduled())
2291060SN/A            tickEvent.squash();
2301060SN/A    }
2311060SN/A
2329444SAndreas.Sandberg@ARM.com    /**
2339444SAndreas.Sandberg@ARM.com     * Check if the pipeline has drained and signal the DrainManager.
2349444SAndreas.Sandberg@ARM.com     *
2359444SAndreas.Sandberg@ARM.com     * This method checks if a drain has been requested and if the CPU
2369444SAndreas.Sandberg@ARM.com     * has drained successfully (i.e., there are no instructions in
2379444SAndreas.Sandberg@ARM.com     * the pipeline). If the CPU has drained, it deschedules the tick
2389444SAndreas.Sandberg@ARM.com     * event and signals the drain manager.
2399444SAndreas.Sandberg@ARM.com     *
2409444SAndreas.Sandberg@ARM.com     * @return False if a drain hasn't been requested or the CPU
2419444SAndreas.Sandberg@ARM.com     * hasn't drained, true otherwise.
2429444SAndreas.Sandberg@ARM.com     */
2439444SAndreas.Sandberg@ARM.com    bool tryDrain();
2449444SAndreas.Sandberg@ARM.com
2459444SAndreas.Sandberg@ARM.com    /**
2469444SAndreas.Sandberg@ARM.com     * Perform sanity checks after a drain.
2479444SAndreas.Sandberg@ARM.com     *
2489444SAndreas.Sandberg@ARM.com     * This method is called from drain() when it has determined that
2499444SAndreas.Sandberg@ARM.com     * the CPU is fully drained when gem5 is compiled with the NDEBUG
2509444SAndreas.Sandberg@ARM.com     * macro undefined. The intention of this method is to do more
2519444SAndreas.Sandberg@ARM.com     * extensive tests than the isDrained() method to weed out any
2529444SAndreas.Sandberg@ARM.com     * draining bugs.
2539444SAndreas.Sandberg@ARM.com     */
2549444SAndreas.Sandberg@ARM.com    void drainSanityCheck() const;
2559444SAndreas.Sandberg@ARM.com
2569444SAndreas.Sandberg@ARM.com    /** Check if a system is in a drained state. */
2579444SAndreas.Sandberg@ARM.com    bool isDrained() const;
2589444SAndreas.Sandberg@ARM.com
2591060SN/A  public:
2602292SN/A    /** Constructs a CPU with the given parameters. */
2615595Sgblack@eecs.umich.edu    FullO3CPU(DerivO3CPUParams *params);
2622292SN/A    /** Destructor. */
2631755SN/A    ~FullO3CPU();
2641060SN/A
2652292SN/A    /** Registers statistics. */
2665595Sgblack@eecs.umich.edu    void regStats();
2671684SN/A
26810023Smatt.horsnell@ARM.com    ProbePointArg<PacketPtr> *ppInstAccessComplete;
26910023Smatt.horsnell@ARM.com    ProbePointArg<std::pair<DynInstPtr, PacketPtr> > *ppDataAccessComplete;
27010023Smatt.horsnell@ARM.com
27110023Smatt.horsnell@ARM.com    /** Register probe points. */
27210023Smatt.horsnell@ARM.com    void regProbePoints();
27310023Smatt.horsnell@ARM.com
2745358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
2755358Sgblack@eecs.umich.edu    {
2765358Sgblack@eecs.umich.edu        this->itb->demapPage(vaddr, asn);
2775358Sgblack@eecs.umich.edu        this->dtb->demapPage(vaddr, asn);
2785358Sgblack@eecs.umich.edu    }
2795358Sgblack@eecs.umich.edu
2805358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
2815358Sgblack@eecs.umich.edu    {
2825358Sgblack@eecs.umich.edu        this->itb->demapPage(vaddr, asn);
2835358Sgblack@eecs.umich.edu    }
2845358Sgblack@eecs.umich.edu
2855358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
2865358Sgblack@eecs.umich.edu    {
2875358Sgblack@eecs.umich.edu        this->dtb->demapPage(vaddr, asn);
2885358Sgblack@eecs.umich.edu    }
2895358Sgblack@eecs.umich.edu
2902292SN/A    /** Ticks CPU, calling tick() on each stage, and checking the overall
2912292SN/A     *  activity to see if the CPU should deschedule itself.
2922292SN/A     */
2931684SN/A    void tick();
2941684SN/A
2952292SN/A    /** Initialize the CPU */
2961060SN/A    void init();
2971060SN/A
2989427SAndreas.Sandberg@ARM.com    void startup();
2999427SAndreas.Sandberg@ARM.com
3002834Sksewell@umich.edu    /** Returns the Number of Active Threads in the CPU */
3012834Sksewell@umich.edu    int numActiveThreads()
3022834Sksewell@umich.edu    { return activeThreads.size(); }
3032834Sksewell@umich.edu
3042829Sksewell@umich.edu    /** Add Thread to Active Threads List */
3056221Snate@binkert.org    void activateThread(ThreadID tid);
3062875Sksewell@umich.edu
3072875Sksewell@umich.edu    /** Remove Thread from Active Threads List */
3086221Snate@binkert.org    void deactivateThread(ThreadID tid);
3092829Sksewell@umich.edu
3102292SN/A    /** Setup CPU to insert a thread's context */
3116221Snate@binkert.org    void insertThread(ThreadID tid);
3121060SN/A
3132292SN/A    /** Remove all of a thread's context from CPU */
3146221Snate@binkert.org    void removeThread(ThreadID tid);
3152292SN/A
3162292SN/A    /** Count the Total Instructions Committed in the CPU. */
3178834Satgutier@umich.edu    virtual Counter totalInsts() const;
3188834Satgutier@umich.edu
3198834Satgutier@umich.edu    /** Count the Total Ops (including micro ops) committed in the CPU. */
3208834Satgutier@umich.edu    virtual Counter totalOps() const;
3212292SN/A
3222292SN/A    /** Add Thread to Active Threads List. */
32310407Smitch.hayenga@arm.com    void activateContext(ThreadID tid);
3242292SN/A
3252292SN/A    /** Remove Thread from Active Threads List */
3266221Snate@binkert.org    void suspendContext(ThreadID tid);
3272292SN/A
3282292SN/A    /** Remove Thread from Active Threads List &&
3293221Sktlim@umich.edu     *  Possibly Remove Thread Context from CPU.
3302292SN/A     */
33110407Smitch.hayenga@arm.com    void deallocateContext(ThreadID tid, bool remove);
3322292SN/A
3332292SN/A    /** Remove Thread from Active Threads List &&
3342292SN/A     *  Remove Thread Context from CPU.
3352292SN/A     */
3366221Snate@binkert.org    void haltContext(ThreadID tid);
3372292SN/A
3382292SN/A    /** Update The Order In Which We Process Threads. */
3392292SN/A    void updateThreadPriority();
3402292SN/A
3419444SAndreas.Sandberg@ARM.com    /** Is the CPU draining? */
3429444SAndreas.Sandberg@ARM.com    bool isDraining() const { return getDrainState() == Drainable::Draining; }
3439444SAndreas.Sandberg@ARM.com
3449448SAndreas.Sandberg@ARM.com    void serializeThread(std::ostream &os, ThreadID tid);
3452864Sktlim@umich.edu
3469448SAndreas.Sandberg@ARM.com    void unserializeThread(Checkpoint *cp, const std::string &section,
3479448SAndreas.Sandberg@ARM.com                           ThreadID tid);
3482864Sktlim@umich.edu
3492864Sktlim@umich.edu  public:
3505595Sgblack@eecs.umich.edu    /** Executes a syscall.
3515595Sgblack@eecs.umich.edu     * @todo: Determine if this needs to be virtual.
3522292SN/A     */
3536221Snate@binkert.org    void syscall(int64_t callnum, ThreadID tid);
3542292SN/A
3552843Sktlim@umich.edu    /** Starts draining the CPU's pipeline of all instructions in
3562843Sktlim@umich.edu     * order to stop all memory accesses. */
3579342SAndreas.Sandberg@arm.com    unsigned int drain(DrainManager *drain_manager);
3582843Sktlim@umich.edu
3592843Sktlim@umich.edu    /** Resumes execution after a drain. */
3609342SAndreas.Sandberg@arm.com    void drainResume();
3612292SN/A
3629444SAndreas.Sandberg@ARM.com    /**
3639444SAndreas.Sandberg@ARM.com     * Commit has reached a safe point to drain a thread.
3649444SAndreas.Sandberg@ARM.com     *
3659444SAndreas.Sandberg@ARM.com     * Commit calls this method to inform the pipeline that it has
3669444SAndreas.Sandberg@ARM.com     * reached a point where it is not executed microcode and is about
3679444SAndreas.Sandberg@ARM.com     * to squash uncommitted instructions to fully drain the pipeline.
3689444SAndreas.Sandberg@ARM.com     */
3699444SAndreas.Sandberg@ARM.com    void commitDrained(ThreadID tid);
3702843Sktlim@umich.edu
3712843Sktlim@umich.edu    /** Switches out this CPU. */
3722843Sktlim@umich.edu    virtual void switchOut();
3732316SN/A
3742348SN/A    /** Takes over from another CPU. */
3752843Sktlim@umich.edu    virtual void takeOverFrom(BaseCPU *oldCPU);
3761060SN/A
3779523SAndreas.Sandberg@ARM.com    void verifyMemoryMode() const;
3789523SAndreas.Sandberg@ARM.com
3791060SN/A    /** Get the current instruction sequence number, and increment it. */
3802316SN/A    InstSeqNum getAndIncrementInstSeq()
3812316SN/A    { return globalSeqNum++; }
3821060SN/A
3835595Sgblack@eecs.umich.edu    /** Traps to handle given fault. */
38410379Sandreas.hansson@arm.com    void trap(const Fault &fault, ThreadID tid, StaticInstPtr inst);
3855595Sgblack@eecs.umich.edu
3865702Ssaidi@eecs.umich.edu    /** HW return from error interrupt. */
3876221Snate@binkert.org    Fault hwrei(ThreadID tid);
3885702Ssaidi@eecs.umich.edu
3896221Snate@binkert.org    bool simPalCheck(int palFunc, ThreadID tid);
3905702Ssaidi@eecs.umich.edu
3915595Sgblack@eecs.umich.edu    /** Returns the Fault for any valid interrupt. */
3925595Sgblack@eecs.umich.edu    Fault getInterrupts();
3935595Sgblack@eecs.umich.edu
3945595Sgblack@eecs.umich.edu    /** Processes any an interrupt fault. */
39510379Sandreas.hansson@arm.com    void processInterrupts(const Fault &interrupt);
3965595Sgblack@eecs.umich.edu
3975595Sgblack@eecs.umich.edu    /** Halts the CPU. */
3985595Sgblack@eecs.umich.edu    void halt() { panic("Halt not implemented!\n"); }
3995595Sgblack@eecs.umich.edu
4001060SN/A    /** Check if this address is a valid instruction address. */
4011060SN/A    bool validInstAddr(Addr addr) { return true; }
4021060SN/A
4031060SN/A    /** Check if this address is a valid data address. */
4041060SN/A    bool validDataAddr(Addr addr) { return true; }
4051060SN/A
4062348SN/A    /** Register accessors.  Index refers to the physical register index. */
4075595Sgblack@eecs.umich.edu
4085595Sgblack@eecs.umich.edu    /** Reads a miscellaneous register. */
4096221Snate@binkert.org    TheISA::MiscReg readMiscRegNoEffect(int misc_reg, ThreadID tid);
4105595Sgblack@eecs.umich.edu
4115595Sgblack@eecs.umich.edu    /** Reads a misc. register, including any side effects the read
4125595Sgblack@eecs.umich.edu     * might have as defined by the architecture.
4135595Sgblack@eecs.umich.edu     */
4146221Snate@binkert.org    TheISA::MiscReg readMiscReg(int misc_reg, ThreadID tid);
4155595Sgblack@eecs.umich.edu
4165595Sgblack@eecs.umich.edu    /** Sets a miscellaneous register. */
4176221Snate@binkert.org    void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val,
4186221Snate@binkert.org            ThreadID tid);
4195595Sgblack@eecs.umich.edu
4205595Sgblack@eecs.umich.edu    /** Sets a misc. register, including any side effects the write
4215595Sgblack@eecs.umich.edu     * might have as defined by the architecture.
4225595Sgblack@eecs.umich.edu     */
4235595Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const TheISA::MiscReg &val,
4246221Snate@binkert.org            ThreadID tid);
4255595Sgblack@eecs.umich.edu
4261060SN/A    uint64_t readIntReg(int reg_idx);
4271060SN/A
4283781Sgblack@eecs.umich.edu    TheISA::FloatReg readFloatReg(int reg_idx);
4291060SN/A
4303781Sgblack@eecs.umich.edu    TheISA::FloatRegBits readFloatRegBits(int reg_idx);
4312455SN/A
4329920Syasuko.eckert@amd.com    TheISA::CCReg readCCReg(int reg_idx);
4339920Syasuko.eckert@amd.com
4341060SN/A    void setIntReg(int reg_idx, uint64_t val);
4351060SN/A
4363781Sgblack@eecs.umich.edu    void setFloatReg(int reg_idx, TheISA::FloatReg val);
4371060SN/A
4383781Sgblack@eecs.umich.edu    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);
4392455SN/A
4409920Syasuko.eckert@amd.com    void setCCReg(int reg_idx, TheISA::CCReg val);
4419920Syasuko.eckert@amd.com
4426221Snate@binkert.org    uint64_t readArchIntReg(int reg_idx, ThreadID tid);
4431060SN/A
4446314Sgblack@eecs.umich.edu    float readArchFloatReg(int reg_idx, ThreadID tid);
4452292SN/A
4466221Snate@binkert.org    uint64_t readArchFloatRegInt(int reg_idx, ThreadID tid);
4472292SN/A
4489920Syasuko.eckert@amd.com    TheISA::CCReg readArchCCReg(int reg_idx, ThreadID tid);
4499920Syasuko.eckert@amd.com
4502348SN/A    /** Architectural register accessors.  Looks up in the commit
4512348SN/A     * rename table to obtain the true physical index of the
4522348SN/A     * architected register first, then accesses that physical
4532348SN/A     * register.
4542348SN/A     */
4556221Snate@binkert.org    void setArchIntReg(int reg_idx, uint64_t val, ThreadID tid);
4562292SN/A
4576314Sgblack@eecs.umich.edu    void setArchFloatReg(int reg_idx, float val, ThreadID tid);
4582292SN/A
4596221Snate@binkert.org    void setArchFloatRegInt(int reg_idx, uint64_t val, ThreadID tid);
4602292SN/A
4619920Syasuko.eckert@amd.com    void setArchCCReg(int reg_idx, TheISA::CCReg val, ThreadID tid);
4629920Syasuko.eckert@amd.com
4637720Sgblack@eecs.umich.edu    /** Sets the commit PC state of a specific thread. */
4647720Sgblack@eecs.umich.edu    void pcState(const TheISA::PCState &newPCState, ThreadID tid);
4657720Sgblack@eecs.umich.edu
4667720Sgblack@eecs.umich.edu    /** Reads the commit PC state of a specific thread. */
4677720Sgblack@eecs.umich.edu    TheISA::PCState pcState(ThreadID tid);
4687720Sgblack@eecs.umich.edu
4692348SN/A    /** Reads the commit PC of a specific thread. */
4707720Sgblack@eecs.umich.edu    Addr instAddr(ThreadID tid);
4712292SN/A
4724636Sgblack@eecs.umich.edu    /** Reads the commit micro PC of a specific thread. */
4737720Sgblack@eecs.umich.edu    MicroPC microPC(ThreadID tid);
4744636Sgblack@eecs.umich.edu
4752348SN/A    /** Reads the next PC of a specific thread. */
4767720Sgblack@eecs.umich.edu    Addr nextInstAddr(ThreadID tid);
4772756Sksewell@umich.edu
4785595Sgblack@eecs.umich.edu    /** Initiates a squash of all in-flight instructions for a given
4795595Sgblack@eecs.umich.edu     * thread.  The source of the squash is an external update of
4805595Sgblack@eecs.umich.edu     * state through the TC.
4815595Sgblack@eecs.umich.edu     */
4826221Snate@binkert.org    void squashFromTC(ThreadID tid);
4835595Sgblack@eecs.umich.edu
4841060SN/A    /** Function to add instruction onto the head of the list of the
4851060SN/A     *  instructions.  Used when new instructions are fetched.
4861060SN/A     */
4872292SN/A    ListIt addInst(DynInstPtr &inst);
4881060SN/A
4891060SN/A    /** Function to tell the CPU that an instruction has completed. */
4908834Satgutier@umich.edu    void instDone(ThreadID tid, DynInstPtr &inst);
4911060SN/A
4922325SN/A    /** Remove an instruction from the front end of the list.  There's
4932325SN/A     *  no restriction on location of the instruction.
4941060SN/A     */
4951061SN/A    void removeFrontInst(DynInstPtr &inst);
4961060SN/A
4972935Sksewell@umich.edu    /** Remove all instructions that are not currently in the ROB.
4982935Sksewell@umich.edu     *  There's also an option to not squash delay slot instructions.*/
4996221Snate@binkert.org    void removeInstsNotInROB(ThreadID tid);
5001060SN/A
5011062SN/A    /** Remove all instructions younger than the given sequence number. */
5026221Snate@binkert.org    void removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid);
5032292SN/A
5042348SN/A    /** Removes the instruction pointed to by the iterator. */
5056221Snate@binkert.org    inline void squashInstIt(const ListIt &instIt, ThreadID tid);
5062292SN/A
5072348SN/A    /** Cleans up all instructions on the remove list. */
5082292SN/A    void cleanUpRemovedInsts();
5091062SN/A
5102348SN/A    /** Debug function to print all instructions on the list. */
5111060SN/A    void dumpInsts();
5121060SN/A
5131060SN/A  public:
5145737Scws3k@cs.virginia.edu#ifndef NDEBUG
5155737Scws3k@cs.virginia.edu    /** Count of total number of dynamic instructions in flight. */
5165737Scws3k@cs.virginia.edu    int instcount;
5175737Scws3k@cs.virginia.edu#endif
5185737Scws3k@cs.virginia.edu
5191060SN/A    /** List of all the instructions in flight. */
5202292SN/A    std::list<DynInstPtr> instList;
5211060SN/A
5222292SN/A    /** List of all the instructions that will be removed at the end of this
5232292SN/A     *  cycle.
5242292SN/A     */
5252292SN/A    std::queue<ListIt> removeList;
5262292SN/A
5272325SN/A#ifdef DEBUG
5282348SN/A    /** Debug structure to keep track of the sequence numbers still in
5292348SN/A     * flight.
5302348SN/A     */
5312292SN/A    std::set<InstSeqNum> snList;
5322325SN/A#endif
5332292SN/A
5342325SN/A    /** Records if instructions need to be removed this cycle due to
5352325SN/A     *  being retired or squashed.
5362292SN/A     */
5372292SN/A    bool removeInstsThisCycle;
5382292SN/A
5391060SN/A  protected:
5401060SN/A    /** The fetch stage. */
5411060SN/A    typename CPUPolicy::Fetch fetch;
5421060SN/A
5431060SN/A    /** The decode stage. */
5441060SN/A    typename CPUPolicy::Decode decode;
5451060SN/A
5461060SN/A    /** The dispatch stage. */
5471060SN/A    typename CPUPolicy::Rename rename;
5481060SN/A
5491060SN/A    /** The issue/execute/writeback stages. */
5501060SN/A    typename CPUPolicy::IEW iew;
5511060SN/A
5521060SN/A    /** The commit stage. */
5531060SN/A    typename CPUPolicy::Commit commit;
5541060SN/A
5551060SN/A    /** The register file. */
5569919Ssteve.reinhardt@amd.com    PhysRegFile regFile;
5571060SN/A
5581060SN/A    /** The free list. */
5591060SN/A    typename CPUPolicy::FreeList freeList;
5601060SN/A
5611060SN/A    /** The rename map. */
5622292SN/A    typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
5632292SN/A
5642292SN/A    /** The commit rename map. */
5652292SN/A    typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
5661060SN/A
5671060SN/A    /** The re-order buffer. */
5681060SN/A    typename CPUPolicy::ROB rob;
5691060SN/A
5702292SN/A    /** Active Threads List */
5716221Snate@binkert.org    std::list<ThreadID> activeThreads;
5722292SN/A
5732292SN/A    /** Integer Register Scoreboard */
5742292SN/A    Scoreboard scoreboard;
5752292SN/A
5769384SAndreas.Sandberg@arm.com    std::vector<TheISA::ISA *> isa;
5776313Sgblack@eecs.umich.edu
5788707Sandreas.hansson@arm.com    /** Instruction port. Note that it has to appear after the fetch stage. */
5798707Sandreas.hansson@arm.com    IcachePort icachePort;
5808707Sandreas.hansson@arm.com
5818707Sandreas.hansson@arm.com    /** Data port. Note that it has to appear after the iew stages */
5828707Sandreas.hansson@arm.com    DcachePort dcachePort;
5838707Sandreas.hansson@arm.com
5841060SN/A  public:
5852292SN/A    /** Enum to give each stage a specific index, so when calling
5862292SN/A     *  activateStage() or deactivateStage(), they can specify which stage
5872292SN/A     *  is being activated/deactivated.
5882292SN/A     */
5892292SN/A    enum StageIdx {
5902292SN/A        FetchIdx,
5912292SN/A        DecodeIdx,
5922292SN/A        RenameIdx,
5932292SN/A        IEWIdx,
5942292SN/A        CommitIdx,
5952292SN/A        NumStages };
5962292SN/A
5971060SN/A    /** Typedefs from the Impl to get the structs that each of the
5981060SN/A     *  time buffers should use.
5991060SN/A     */
6001061SN/A    typedef typename CPUPolicy::TimeStruct TimeStruct;
6011060SN/A
6021061SN/A    typedef typename CPUPolicy::FetchStruct FetchStruct;
6031060SN/A
6041061SN/A    typedef typename CPUPolicy::DecodeStruct DecodeStruct;
6051060SN/A
6061061SN/A    typedef typename CPUPolicy::RenameStruct RenameStruct;
6071060SN/A
6081061SN/A    typedef typename CPUPolicy::IEWStruct IEWStruct;
6091060SN/A
6101060SN/A    /** The main time buffer to do backwards communication. */
6111060SN/A    TimeBuffer<TimeStruct> timeBuffer;
6121060SN/A
6131060SN/A    /** The fetch stage's instruction queue. */
6141060SN/A    TimeBuffer<FetchStruct> fetchQueue;
6151060SN/A
6161060SN/A    /** The decode stage's instruction queue. */
6171060SN/A    TimeBuffer<DecodeStruct> decodeQueue;
6181060SN/A
6191060SN/A    /** The rename stage's instruction queue. */
6201060SN/A    TimeBuffer<RenameStruct> renameQueue;
6211060SN/A
6221060SN/A    /** The IEW stage's instruction queue. */
6231060SN/A    TimeBuffer<IEWStruct> iewQueue;
6241060SN/A
6252348SN/A  private:
6262348SN/A    /** The activity recorder; used to tell if the CPU has any
6272348SN/A     * activity remaining or if it can go to idle and deschedule
6282348SN/A     * itself.
6292348SN/A     */
6302325SN/A    ActivityRecorder activityRec;
6311060SN/A
6322348SN/A  public:
6332348SN/A    /** Records that there was time buffer activity this cycle. */
6342325SN/A    void activityThisCycle() { activityRec.activity(); }
6352292SN/A
6362348SN/A    /** Changes a stage's status to active within the activity recorder. */
6372325SN/A    void activateStage(const StageIdx idx)
6382325SN/A    { activityRec.activateStage(idx); }
6392292SN/A
6402348SN/A    /** Changes a stage's status to inactive within the activity recorder. */
6412325SN/A    void deactivateStage(const StageIdx idx)
6422325SN/A    { activityRec.deactivateStage(idx); }
6432292SN/A
6442292SN/A    /** Wakes the CPU, rescheduling the CPU if it's not already active. */
6452292SN/A    void wakeCPU();
6462260SN/A
6475807Snate@binkert.org    virtual void wakeup();
6485807Snate@binkert.org
6492292SN/A    /** Gets a free thread id. Use if thread ids change across system. */
6506221Snate@binkert.org    ThreadID getFreeTid();
6512292SN/A
6522292SN/A  public:
6532680Sktlim@umich.edu    /** Returns a pointer to a thread context. */
6546221Snate@binkert.org    ThreadContext *
6556221Snate@binkert.org    tcBase(ThreadID tid)
6561681SN/A    {
6572680Sktlim@umich.edu        return thread[tid]->getTC();
6582190SN/A    }
6592190SN/A
6602292SN/A    /** The global sequence number counter. */
6613093Sksewell@umich.edu    InstSeqNum globalSeqNum;//[Impl::MaxThreads];
6621060SN/A
6632348SN/A    /** Pointer to the checker, which can dynamically verify
6642348SN/A     * instruction results at run time.  This can be set to NULL if it
6652348SN/A     * is not being used.
6662348SN/A     */
6678733Sgeoffrey.blake@arm.com    Checker<Impl> *checker;
6682316SN/A
6692292SN/A    /** Pointer to the system. */
6701060SN/A    System *system;
6711060SN/A
6729342SAndreas.Sandberg@arm.com    /** DrainManager to notify when draining has completed. */
6739342SAndreas.Sandberg@arm.com    DrainManager *drainManager;
6742843Sktlim@umich.edu
6752348SN/A    /** Pointers to all of the threads in the CPU. */
6762292SN/A    std::vector<Thread *> thread;
6772260SN/A
6782292SN/A    /** Threads Scheduled to Enter CPU */
6792292SN/A    std::list<int> cpuWaitList;
6802292SN/A
6812292SN/A    /** The cycle that the CPU was last running, used for statistics. */
6829180Sandreas.hansson@arm.com    Cycles lastRunningCycle;
6832292SN/A
6842829Sksewell@umich.edu    /** The cycle that the CPU was last activated by a new thread*/
6852829Sksewell@umich.edu    Tick lastActivatedCycle;
6862829Sksewell@umich.edu
6872292SN/A    /** Mapping for system thread id to cpu id */
6886221Snate@binkert.org    std::map<ThreadID, unsigned> threadMap;
6892292SN/A
6902292SN/A    /** Available thread ids in the cpu*/
6916221Snate@binkert.org    std::vector<ThreadID> tids;
6922292SN/A
6935595Sgblack@eecs.umich.edu    /** CPU read function, forwards read to LSQ. */
6946974Stjones1@inf.ed.ac.uk    Fault read(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh,
6957520Sgblack@eecs.umich.edu               uint8_t *data, int load_idx)
6965595Sgblack@eecs.umich.edu    {
6976974Stjones1@inf.ed.ac.uk        return this->iew.ldstQueue.read(req, sreqLow, sreqHigh,
6986974Stjones1@inf.ed.ac.uk                                        data, load_idx);
6995595Sgblack@eecs.umich.edu    }
7005595Sgblack@eecs.umich.edu
7015595Sgblack@eecs.umich.edu    /** CPU write function, forwards write to LSQ. */
7026974Stjones1@inf.ed.ac.uk    Fault write(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh,
7037520Sgblack@eecs.umich.edu                uint8_t *data, int store_idx)
7045595Sgblack@eecs.umich.edu    {
7056974Stjones1@inf.ed.ac.uk        return this->iew.ldstQueue.write(req, sreqLow, sreqHigh,
7066974Stjones1@inf.ed.ac.uk                                         data, store_idx);
7075595Sgblack@eecs.umich.edu    }
7085595Sgblack@eecs.umich.edu
7098707Sandreas.hansson@arm.com    /** Used by the fetch unit to get a hold of the instruction port. */
7109608Sandreas.hansson@arm.com    virtual MasterPort &getInstPort() { return icachePort; }
7118707Sandreas.hansson@arm.com
7126974Stjones1@inf.ed.ac.uk    /** Get the dcache port (used to find block size for translations). */
7139608Sandreas.hansson@arm.com    virtual MasterPort &getDataPort() { return dcachePort; }
7146974Stjones1@inf.ed.ac.uk
7152292SN/A    /** Stat for total number of times the CPU is descheduled. */
7165999Snate@binkert.org    Stats::Scalar timesIdled;
7172292SN/A    /** Stat for total number of cycles the CPU spends descheduled. */
7185999Snate@binkert.org    Stats::Scalar idleCycles;
7198627SAli.Saidi@ARM.com    /** Stat for total number of cycles the CPU spends descheduled due to a
7208627SAli.Saidi@ARM.com     * quiesce operation or waiting for an interrupt. */
7218627SAli.Saidi@ARM.com    Stats::Scalar quiesceCycles;
7222292SN/A    /** Stat for the number of committed instructions per thread. */
7235999Snate@binkert.org    Stats::Vector committedInsts;
7248834Satgutier@umich.edu    /** Stat for the number of committed ops (including micro ops) per thread. */
7258834Satgutier@umich.edu    Stats::Vector committedOps;
7262292SN/A    /** Stat for the CPI per thread. */
7272292SN/A    Stats::Formula cpi;
7282292SN/A    /** Stat for the total CPI. */
7292292SN/A    Stats::Formula totalCpi;
7302292SN/A    /** Stat for the IPC per thread. */
7312292SN/A    Stats::Formula ipc;
7322292SN/A    /** Stat for the total IPC. */
7332292SN/A    Stats::Formula totalIpc;
7347897Shestness@cs.utexas.edu
7357897Shestness@cs.utexas.edu    //number of integer register file accesses
7367897Shestness@cs.utexas.edu    Stats::Scalar intRegfileReads;
7377897Shestness@cs.utexas.edu    Stats::Scalar intRegfileWrites;
7387897Shestness@cs.utexas.edu    //number of float register file accesses
7397897Shestness@cs.utexas.edu    Stats::Scalar fpRegfileReads;
7407897Shestness@cs.utexas.edu    Stats::Scalar fpRegfileWrites;
7419920Syasuko.eckert@amd.com    //number of CC register file accesses
7429920Syasuko.eckert@amd.com    Stats::Scalar ccRegfileReads;
7439920Syasuko.eckert@amd.com    Stats::Scalar ccRegfileWrites;
7447897Shestness@cs.utexas.edu    //number of misc
7457897Shestness@cs.utexas.edu    Stats::Scalar miscRegfileReads;
7467897Shestness@cs.utexas.edu    Stats::Scalar miscRegfileWrites;
7471060SN/A};
7481060SN/A
7492325SN/A#endif // __CPU_O3_CPU_HH__
750