fetch.hh revision 8503
11689SN/A/*
27849SAli.Saidi@ARM.com * Copyright (c) 2010 ARM Limited
37849SAli.Saidi@ARM.com * All rights reserved
47849SAli.Saidi@ARM.com *
57849SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall
67849SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual
77849SAli.Saidi@ARM.com * property including but not limited to intellectual property relating
87849SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software
97849SAli.Saidi@ARM.com * licensed hereunder.  You may use the software subject to the license
107849SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated
117849SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software,
127849SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form.
137849SAli.Saidi@ARM.com *
142329SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
151689SN/A * All rights reserved.
161689SN/A *
171689SN/A * Redistribution and use in source and binary forms, with or without
181689SN/A * modification, are permitted provided that the following conditions are
191689SN/A * met: redistributions of source code must retain the above copyright
201689SN/A * notice, this list of conditions and the following disclaimer;
211689SN/A * redistributions in binary form must reproduce the above copyright
221689SN/A * notice, this list of conditions and the following disclaimer in the
231689SN/A * documentation and/or other materials provided with the distribution;
241689SN/A * neither the name of the copyright holders nor the names of its
251689SN/A * contributors may be used to endorse or promote products derived from
261689SN/A * this software without specific prior written permission.
271689SN/A *
281689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
311689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
321689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
331689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
341689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
351689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
361689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
371689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
381689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392665Ssaidi@eecs.umich.edu *
402665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
412756Sksewell@umich.edu *          Korey Sewell
421689SN/A */
431689SN/A
442292SN/A#ifndef __CPU_O3_FETCH_HH__
452292SN/A#define __CPU_O3_FETCH_HH__
461060SN/A
478229Snate@binkert.org#include "arch/predecoder.hh"
482669Sktlim@umich.edu#include "arch/utility.hh"
491461SN/A#include "base/statistics.hh"
506658Snate@binkert.org#include "config/the_isa.hh"
511060SN/A#include "cpu/pc_event.hh"
528229Snate@binkert.org#include "cpu/timebuf.hh"
537849SAli.Saidi@ARM.com#include "cpu/translation.hh"
543348Sbinkertn@umich.edu#include "mem/packet.hh"
552669Sktlim@umich.edu#include "mem/port.hh"
561461SN/A#include "sim/eventq.hh"
571060SN/A
585529Snate@binkert.orgclass DerivO3CPUParams;
595529Snate@binkert.org
601060SN/A/**
612329SN/A * DefaultFetch class handles both single threaded and SMT fetch. Its
622329SN/A * width is specified by the parameters; each cycle it tries to fetch
632329SN/A * that many instructions. It supports using a branch predictor to
642329SN/A * predict direction and targets.
652348SN/A * It supports the idling functionality of the CPU by indicating to
662329SN/A * the CPU when it is active and inactive.
671060SN/A */
681060SN/Atemplate <class Impl>
692292SN/Aclass DefaultFetch
701060SN/A{
711060SN/A  public:
721060SN/A    /** Typedefs from Impl. */
731061SN/A    typedef typename Impl::CPUPol CPUPol;
741060SN/A    typedef typename Impl::DynInst DynInst;
751061SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
762733Sktlim@umich.edu    typedef typename Impl::O3CPU O3CPU;
771060SN/A
782292SN/A    /** Typedefs from the CPU policy. */
791061SN/A    typedef typename CPUPol::BPredUnit BPredUnit;
801061SN/A    typedef typename CPUPol::FetchStruct FetchStruct;
811061SN/A    typedef typename CPUPol::TimeStruct TimeStruct;
821060SN/A
831060SN/A    /** Typedefs from ISA. */
842107SN/A    typedef TheISA::MachInst MachInst;
852292SN/A    typedef TheISA::ExtMachInst ExtMachInst;
862632Sstever@eecs.umich.edu
872698Sktlim@umich.edu    /** IcachePort class for DefaultFetch.  Handles doing the
882698Sktlim@umich.edu     * communication with the cache/memory.
892698Sktlim@umich.edu     */
902669Sktlim@umich.edu    class IcachePort : public Port
912669Sktlim@umich.edu    {
922669Sktlim@umich.edu      protected:
932698Sktlim@umich.edu        /** Pointer to fetch. */
942669Sktlim@umich.edu        DefaultFetch<Impl> *fetch;
952669Sktlim@umich.edu
962669Sktlim@umich.edu      public:
972698Sktlim@umich.edu        /** Default constructor. */
985494Sstever@gmail.com        IcachePort(DefaultFetch<Impl> *_fetch)
995606Snate@binkert.org            : Port(_fetch->name() + "-iport", _fetch->cpu), fetch(_fetch)
1002669Sktlim@umich.edu        { }
1012669Sktlim@umich.edu
1023647Srdreslin@umich.edu        bool snoopRangeSent;
1033647Srdreslin@umich.edu
1044302Sktlim@umich.edu        virtual void setPeer(Port *port);
1054302Sktlim@umich.edu
1062669Sktlim@umich.edu      protected:
1072698Sktlim@umich.edu        /** Atomic version of receive.  Panics. */
1082669Sktlim@umich.edu        virtual Tick recvAtomic(PacketPtr pkt);
1092669Sktlim@umich.edu
1102698Sktlim@umich.edu        /** Functional version of receive.  Panics. */
1112669Sktlim@umich.edu        virtual void recvFunctional(PacketPtr pkt);
1122669Sktlim@umich.edu
1132698Sktlim@umich.edu        /** Receives status change.  Other than range changing, panics. */
1142669Sktlim@umich.edu        virtual void recvStatusChange(Status status);
1152669Sktlim@umich.edu
1162698Sktlim@umich.edu        /** Returns the address ranges of this device. */
1172669Sktlim@umich.edu        virtual void getDeviceAddressRanges(AddrRangeList &resp,
1184475Sstever@eecs.umich.edu                                            bool &snoop)
1194475Sstever@eecs.umich.edu        { resp.clear(); snoop = true; }
1202669Sktlim@umich.edu
1212698Sktlim@umich.edu        /** Timing version of receive.  Handles setting fetch to the
1222698Sktlim@umich.edu         * proper status to start fetching. */
1232669Sktlim@umich.edu        virtual bool recvTiming(PacketPtr pkt);
1242669Sktlim@umich.edu
1252698Sktlim@umich.edu        /** Handles doing a retry of a failed fetch. */
1262669Sktlim@umich.edu        virtual void recvRetry();
1272669Sktlim@umich.edu    };
1281060SN/A
1297849SAli.Saidi@ARM.com    class FetchTranslation : public BaseTLB::Translation
1307849SAli.Saidi@ARM.com    {
1317849SAli.Saidi@ARM.com      protected:
1327849SAli.Saidi@ARM.com        DefaultFetch<Impl> *fetch;
1337849SAli.Saidi@ARM.com
1347849SAli.Saidi@ARM.com      public:
1357849SAli.Saidi@ARM.com        FetchTranslation(DefaultFetch<Impl> *_fetch)
1367849SAli.Saidi@ARM.com            : fetch(_fetch)
1377849SAli.Saidi@ARM.com        {}
1387849SAli.Saidi@ARM.com
1397849SAli.Saidi@ARM.com        void
1407944SGiacomo.Gabrielli@arm.com        markDelayed()
1417944SGiacomo.Gabrielli@arm.com        {}
1427944SGiacomo.Gabrielli@arm.com
1437944SGiacomo.Gabrielli@arm.com        void
1447849SAli.Saidi@ARM.com        finish(Fault fault, RequestPtr req, ThreadContext *tc,
1457849SAli.Saidi@ARM.com               BaseTLB::Mode mode)
1467849SAli.Saidi@ARM.com        {
1477849SAli.Saidi@ARM.com            assert(mode == BaseTLB::Execute);
1487849SAli.Saidi@ARM.com            fetch->finishTranslation(fault, req);
1497849SAli.Saidi@ARM.com            delete this;
1507849SAli.Saidi@ARM.com        }
1517849SAli.Saidi@ARM.com    };
1522935Sksewell@umich.edu
1538462Sgeoffrey.blake@arm.com  private:
1548462Sgeoffrey.blake@arm.com    /* Event to delay delivery of a fetch translation result in case of
1558462Sgeoffrey.blake@arm.com     * a fault and the nop to carry the fault cannot be generated
1568462Sgeoffrey.blake@arm.com     * immediately */
1578462Sgeoffrey.blake@arm.com    class FinishTranslationEvent : public Event
1588462Sgeoffrey.blake@arm.com    {
1598462Sgeoffrey.blake@arm.com      private:
1608462Sgeoffrey.blake@arm.com        DefaultFetch<Impl> *fetch;
1618462Sgeoffrey.blake@arm.com        Fault fault;
1628462Sgeoffrey.blake@arm.com        RequestPtr req;
1638462Sgeoffrey.blake@arm.com
1648462Sgeoffrey.blake@arm.com      public:
1658462Sgeoffrey.blake@arm.com        FinishTranslationEvent(DefaultFetch<Impl> *_fetch)
1668462Sgeoffrey.blake@arm.com            : fetch(_fetch)
1678462Sgeoffrey.blake@arm.com        {}
1688462Sgeoffrey.blake@arm.com
1698462Sgeoffrey.blake@arm.com        void setFault(Fault _fault)
1708462Sgeoffrey.blake@arm.com        {
1718462Sgeoffrey.blake@arm.com            fault = _fault;
1728462Sgeoffrey.blake@arm.com        }
1738462Sgeoffrey.blake@arm.com
1748462Sgeoffrey.blake@arm.com        void setReq(RequestPtr _req)
1758462Sgeoffrey.blake@arm.com        {
1768462Sgeoffrey.blake@arm.com            req = _req;
1778462Sgeoffrey.blake@arm.com        }
1788462Sgeoffrey.blake@arm.com
1798462Sgeoffrey.blake@arm.com        /** Process the delayed finish translation */
1808462Sgeoffrey.blake@arm.com        void process()
1818462Sgeoffrey.blake@arm.com        {
1828462Sgeoffrey.blake@arm.com            assert(fetch->numInst < fetch->fetchWidth);
1838462Sgeoffrey.blake@arm.com            fetch->finishTranslation(fault, req);
1848462Sgeoffrey.blake@arm.com        }
1858462Sgeoffrey.blake@arm.com
1868462Sgeoffrey.blake@arm.com        const char *description() const
1878462Sgeoffrey.blake@arm.com        {
1888462Sgeoffrey.blake@arm.com            return "FullO3CPU FetchFinishTranslation";
1898462Sgeoffrey.blake@arm.com        }
1908462Sgeoffrey.blake@arm.com      };
1918462Sgeoffrey.blake@arm.com
1921060SN/A  public:
1932329SN/A    /** Overall fetch status. Used to determine if the CPU can
1942329SN/A     * deschedule itsef due to a lack of activity.
1952292SN/A     */
1962292SN/A    enum FetchStatus {
1972292SN/A        Active,
1982292SN/A        Inactive
1992292SN/A    };
2002292SN/A
2012292SN/A    /** Individual thread status. */
2022292SN/A    enum ThreadStatus {
2031060SN/A        Running,
2041060SN/A        Idle,
2051060SN/A        Squashing,
2061060SN/A        Blocked,
2072292SN/A        Fetching,
2082292SN/A        TrapPending,
2092292SN/A        QuiescePending,
2102307SN/A        SwitchOut,
2117849SAli.Saidi@ARM.com        ItlbWait,
2122669Sktlim@umich.edu        IcacheWaitResponse,
2132696Sktlim@umich.edu        IcacheWaitRetry,
2148460SAli.Saidi@ARM.com        IcacheAccessComplete,
2158460SAli.Saidi@ARM.com        NoGoodAddr
2161060SN/A    };
2171060SN/A
2182292SN/A    /** Fetching Policy, Add new policies here.*/
2192292SN/A    enum FetchPriority {
2202292SN/A        SingleThread,
2212292SN/A        RoundRobin,
2222292SN/A        Branch,
2232292SN/A        IQ,
2242292SN/A        LSQ
2252292SN/A    };
2261060SN/A
2272292SN/A  private:
2282292SN/A    /** Fetch status. */
2292292SN/A    FetchStatus _status;
2302292SN/A
2312292SN/A    /** Per-thread status. */
2322292SN/A    ThreadStatus fetchStatus[Impl::MaxThreads];
2332292SN/A
2342292SN/A    /** Fetch policy. */
2352292SN/A    FetchPriority fetchPolicy;
2362292SN/A
2372292SN/A    /** List that has the threads organized by priority. */
2386221Snate@binkert.org    std::list<ThreadID> priorityList;
2391060SN/A
2401060SN/A  public:
2412292SN/A    /** DefaultFetch constructor. */
2425529Snate@binkert.org    DefaultFetch(O3CPU *_cpu, DerivO3CPUParams *params);
2431684SN/A
2442292SN/A    /** Returns the name of fetch. */
2452292SN/A    std::string name() const;
2461684SN/A
2472292SN/A    /** Registers statistics. */
2481062SN/A    void regStats();
2491062SN/A
2502871Sktlim@umich.edu    /** Returns the icache port. */
2512871Sktlim@umich.edu    Port *getIcachePort() { return icachePort; }
2522871Sktlim@umich.edu
2532292SN/A    /** Sets the main backwards communication time buffer pointer. */
2541060SN/A    void setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer);
2551060SN/A
2562292SN/A    /** Sets pointer to list of active threads. */
2576221Snate@binkert.org    void setActiveThreads(std::list<ThreadID> *at_ptr);
2582292SN/A
2592292SN/A    /** Sets pointer to time buffer used to communicate to the next stage. */
2601060SN/A    void setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr);
2611060SN/A
2622292SN/A    /** Initialize stage. */
2632292SN/A    void initStage();
2642292SN/A
2654302Sktlim@umich.edu    /** Tells the fetch stage that the Icache is set. */
2664302Sktlim@umich.edu    void setIcache();
2674302Sktlim@umich.edu
2682292SN/A    /** Processes cache completion event. */
2692669Sktlim@umich.edu    void processCacheCompletion(PacketPtr pkt);
2702292SN/A
2712843Sktlim@umich.edu    /** Begins the drain of the fetch stage. */
2722863Sktlim@umich.edu    bool drain();
2732843Sktlim@umich.edu
2742843Sktlim@umich.edu    /** Resumes execution after a drain. */
2752843Sktlim@umich.edu    void resume();
2762843Sktlim@umich.edu
2772843Sktlim@umich.edu    /** Tells fetch stage to prepare to be switched out. */
2782307SN/A    void switchOut();
2792307SN/A
2802348SN/A    /** Takes over from another CPU's thread. */
2812307SN/A    void takeOverFrom();
2822307SN/A
2832348SN/A    /** Checks if the fetch stage is switched out. */
2842307SN/A    bool isSwitchedOut() { return switchedOut; }
2852307SN/A
2862348SN/A    /** Tells fetch to wake up from a quiesce instruction. */
2872292SN/A    void wakeFromQuiesce();
2881060SN/A
2891061SN/A  private:
2902329SN/A    /** Changes the status of this stage to active, and indicates this
2912329SN/A     * to the CPU.
2922292SN/A     */
2932292SN/A    inline void switchToActive();
2942292SN/A
2952329SN/A    /** Changes the status of this stage to inactive, and indicates
2962329SN/A     * this to the CPU.
2972292SN/A     */
2982292SN/A    inline void switchToInactive();
2992292SN/A
3001061SN/A    /**
3011061SN/A     * Looks up in the branch predictor to see if the next PC should be
3021061SN/A     * either next PC+=MachInst or a branch target.
3031763SN/A     * @param next_PC Next PC variable passed in by reference.  It is
3041061SN/A     * expected to be set to the current PC; it will be updated with what
3051061SN/A     * the next PC will be.
3062935Sksewell@umich.edu     * @param next_NPC Used for ISAs which use delay slots.
3071061SN/A     * @return Whether or not a branch was predicted as taken.
3081061SN/A     */
3097720Sgblack@eecs.umich.edu    bool lookupAndUpdateNextPC(DynInstPtr &inst, TheISA::PCState &pc);
3101062SN/A
3111062SN/A    /**
3121062SN/A     * Fetches the cache line that contains fetch_PC.  Returns any
3131062SN/A     * fault that happened.  Puts the data into the class variable
3141062SN/A     * cacheData.
3157764Sgblack@eecs.umich.edu     * @param vaddr The memory address that is being fetched from.
3162292SN/A     * @param ret_fault The fault reference that will be set to the result of
3172292SN/A     * the icache access.
3182292SN/A     * @param tid Thread id.
3197764Sgblack@eecs.umich.edu     * @param pc The actual PC of the current instruction.
3201062SN/A     * @return Any fault that occured.
3211062SN/A     */
3227849SAli.Saidi@ARM.com    bool fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc);
3237849SAli.Saidi@ARM.com    void finishTranslation(Fault fault, RequestPtr mem_req);
3241062SN/A
3257847Sminkyu.jeong@arm.com
3267847Sminkyu.jeong@arm.com    /** Check if an interrupt is pending and that we need to handle
3277847Sminkyu.jeong@arm.com     */
3287847Sminkyu.jeong@arm.com    bool
3297847Sminkyu.jeong@arm.com    checkInterrupt(Addr pc)
3307847Sminkyu.jeong@arm.com    {
3317847Sminkyu.jeong@arm.com        return (interruptPending && (THE_ISA != ALPHA_ISA || !(pc & 0x3)));
3327847Sminkyu.jeong@arm.com    }
3337847Sminkyu.jeong@arm.com
3342292SN/A    /** Squashes a specific thread and resets the PC. */
3358503Sgblack@eecs.umich.edu    inline void doSquash(const TheISA::PCState &newPC,
3368503Sgblack@eecs.umich.edu                         const DynInstPtr squashInst, ThreadID tid);
3371684SN/A
3382292SN/A    /** Squashes a specific thread and resets the PC. Also tells the CPU to
3392292SN/A     * remove any instructions between fetch and decode that should be sqaushed.
3402292SN/A     */
3417720Sgblack@eecs.umich.edu    void squashFromDecode(const TheISA::PCState &newPC,
3428503Sgblack@eecs.umich.edu                          const DynInstPtr squashInst,
3438503Sgblack@eecs.umich.edu                          const InstSeqNum seq_num, ThreadID tid);
3442292SN/A
3452292SN/A    /** Checks if a thread is stalled. */
3466221Snate@binkert.org    bool checkStall(ThreadID tid) const;
3472292SN/A
3482292SN/A    /** Updates overall fetch stage status; to be called at the end of each
3492292SN/A     * cycle. */
3502292SN/A    FetchStatus updateFetchStatus();
3511684SN/A
3521684SN/A  public:
3532292SN/A    /** Squashes a specific thread and resets the PC. Also tells the CPU to
3542292SN/A     * remove any instructions that are not in the ROB. The source of this
3552292SN/A     * squash should be the commit stage.
3562292SN/A     */
3578503Sgblack@eecs.umich.edu    void squash(const TheISA::PCState &newPC, const InstSeqNum seq_num,
3588503Sgblack@eecs.umich.edu                DynInstPtr squashInst, ThreadID tid);
3591684SN/A
3602292SN/A    /** Ticks the fetch stage, processing all inputs signals and fetching
3612292SN/A     * as many instructions as possible.
3622292SN/A     */
3631684SN/A    void tick();
3641684SN/A
3652292SN/A    /** Checks all input signals and updates the status as necessary.
3662292SN/A     *  @return: Returns if the status has changed due to input signals.
3672292SN/A     */
3686221Snate@binkert.org    bool checkSignalsAndUpdate(ThreadID tid);
3691684SN/A
3702292SN/A    /** Does the actual fetching of instructions and passing them on to the
3712292SN/A     * next stage.
3722292SN/A     * @param status_change fetch() sets this variable if there was a status
3732292SN/A     * change (ie switching to IcacheMissStall).
3742292SN/A     */
3752292SN/A    void fetch(bool &status_change);
3762292SN/A
3772292SN/A    /** Align a PC to the start of an I-cache block. */
3781062SN/A    Addr icacheBlockAlignPC(Addr addr)
3791062SN/A    {
3801062SN/A        return (addr & ~(cacheBlkMask));
3811062SN/A    }
3821061SN/A
3831060SN/A  private:
3847764Sgblack@eecs.umich.edu    DynInstPtr buildInst(ThreadID tid, StaticInstPtr staticInst,
3857764Sgblack@eecs.umich.edu                         StaticInstPtr curMacroop, TheISA::PCState thisPC,
3867764Sgblack@eecs.umich.edu                         TheISA::PCState nextPC, bool trace);
3877764Sgblack@eecs.umich.edu
3882698Sktlim@umich.edu    /** Handles retrying the fetch access. */
3892696Sktlim@umich.edu    void recvRetry();
3902696Sktlim@umich.edu
3912292SN/A    /** Returns the appropriate thread to fetch, given the fetch policy. */
3926221Snate@binkert.org    ThreadID getFetchingThread(FetchPriority &fetch_priority);
3932292SN/A
3942292SN/A    /** Returns the appropriate thread to fetch using a round robin policy. */
3956221Snate@binkert.org    ThreadID roundRobin();
3962292SN/A
3972292SN/A    /** Returns the appropriate thread to fetch using the IQ count policy. */
3986221Snate@binkert.org    ThreadID iqCount();
3992292SN/A
4002292SN/A    /** Returns the appropriate thread to fetch using the LSQ count policy. */
4016221Snate@binkert.org    ThreadID lsqCount();
4022292SN/A
4036221Snate@binkert.org    /** Returns the appropriate thread to fetch using the branch count
4046221Snate@binkert.org     * policy. */
4056221Snate@binkert.org    ThreadID branchCount();
4062292SN/A
4078462Sgeoffrey.blake@arm.com    /** Pipeline the next I-cache access to the current one. */
4088462Sgeoffrey.blake@arm.com    void pipelineIcacheAccesses(ThreadID tid);
4098462Sgeoffrey.blake@arm.com
4108462Sgeoffrey.blake@arm.com    /** Profile the reasons of fetch stall. */
4118462Sgeoffrey.blake@arm.com    void profileStall(ThreadID tid);
4128462Sgeoffrey.blake@arm.com
4132292SN/A  private:
4142733Sktlim@umich.edu    /** Pointer to the O3CPU. */
4152733Sktlim@umich.edu    O3CPU *cpu;
4161060SN/A
4171060SN/A    /** Time buffer interface. */
4181060SN/A    TimeBuffer<TimeStruct> *timeBuffer;
4191060SN/A
4201060SN/A    /** Wire to get decode's information from backwards time buffer. */
4211060SN/A    typename TimeBuffer<TimeStruct>::wire fromDecode;
4221060SN/A
4231060SN/A    /** Wire to get rename's information from backwards time buffer. */
4241060SN/A    typename TimeBuffer<TimeStruct>::wire fromRename;
4251060SN/A
4261060SN/A    /** Wire to get iew's information from backwards time buffer. */
4271060SN/A    typename TimeBuffer<TimeStruct>::wire fromIEW;
4281060SN/A
4291060SN/A    /** Wire to get commit's information from backwards time buffer. */
4301060SN/A    typename TimeBuffer<TimeStruct>::wire fromCommit;
4311060SN/A
4321060SN/A    /** Internal fetch instruction queue. */
4331060SN/A    TimeBuffer<FetchStruct> *fetchQueue;
4341060SN/A
4351060SN/A    //Might be annoying how this name is different than the queue.
4361060SN/A    /** Wire used to write any information heading to decode. */
4371060SN/A    typename TimeBuffer<FetchStruct>::wire toDecode;
4381060SN/A
4391060SN/A    /** Icache interface. */
4402669Sktlim@umich.edu    IcachePort *icachePort;
4411060SN/A
4421061SN/A    /** BPredUnit. */
4431061SN/A    BPredUnit branchPred;
4441061SN/A
4454182Sgblack@eecs.umich.edu    /** Predecoder. */
4464182Sgblack@eecs.umich.edu    TheISA::Predecoder predecoder;
4474182Sgblack@eecs.umich.edu
4487720Sgblack@eecs.umich.edu    TheISA::PCState pc[Impl::MaxThreads];
4492292SN/A
4507764Sgblack@eecs.umich.edu    Addr fetchOffset[Impl::MaxThreads];
4517764Sgblack@eecs.umich.edu
4527764Sgblack@eecs.umich.edu    StaticInstPtr macroop[Impl::MaxThreads];
4537764Sgblack@eecs.umich.edu
4548314Sgeoffrey.blake@arm.com    /** Can the fetch stage redirect from an interrupt on this instruction? */
4558314Sgeoffrey.blake@arm.com    bool delayedCommit[Impl::MaxThreads];
4568314Sgeoffrey.blake@arm.com
4572678Sktlim@umich.edu    /** Memory request used to access cache. */
4582678Sktlim@umich.edu    RequestPtr memReq[Impl::MaxThreads];
4592292SN/A
4602292SN/A    /** Variable that tracks if fetch has written to the time buffer this
4612292SN/A     * cycle. Used to tell CPU if there is activity this cycle.
4622292SN/A     */
4632292SN/A    bool wroteToTimeBuffer;
4642292SN/A
4652292SN/A    /** Tracks how many instructions has been fetched this cycle. */
4662292SN/A    int numInst;
4672292SN/A
4682292SN/A    /** Source of possible stalls. */
4692292SN/A    struct Stalls {
4702292SN/A        bool decode;
4712292SN/A        bool rename;
4722292SN/A        bool iew;
4732292SN/A        bool commit;
4742292SN/A    };
4752292SN/A
4762292SN/A    /** Tracks which stages are telling fetch to stall. */
4772292SN/A    Stalls stalls[Impl::MaxThreads];
4781060SN/A
4791060SN/A    /** Decode to fetch delay, in ticks. */
4801060SN/A    unsigned decodeToFetchDelay;
4811060SN/A
4821060SN/A    /** Rename to fetch delay, in ticks. */
4831060SN/A    unsigned renameToFetchDelay;
4841060SN/A
4851060SN/A    /** IEW to fetch delay, in ticks. */
4861060SN/A    unsigned iewToFetchDelay;
4871060SN/A
4881060SN/A    /** Commit to fetch delay, in ticks. */
4891060SN/A    unsigned commitToFetchDelay;
4901060SN/A
4911060SN/A    /** The width of fetch in instructions. */
4921060SN/A    unsigned fetchWidth;
4931060SN/A
4942696Sktlim@umich.edu    /** Is the cache blocked?  If so no threads can access it. */
4952696Sktlim@umich.edu    bool cacheBlocked;
4962696Sktlim@umich.edu
4972696Sktlim@umich.edu    /** The packet that is waiting to be retried. */
4982696Sktlim@umich.edu    PacketPtr retryPkt;
4992696Sktlim@umich.edu
5002696Sktlim@umich.edu    /** The thread that is waiting on the cache to tell fetch to retry. */
5016221Snate@binkert.org    ThreadID retryTid;
5022696Sktlim@umich.edu
5031060SN/A    /** Cache block size. */
5041062SN/A    int cacheBlkSize;
5051060SN/A
5061060SN/A    /** Mask to get a cache block's address. */
5071062SN/A    Addr cacheBlkMask;
5081060SN/A
5091062SN/A    /** The cache line being fetched. */
5102292SN/A    uint8_t *cacheData[Impl::MaxThreads];
5111060SN/A
5122893Sktlim@umich.edu    /** The PC of the cacheline that has been loaded. */
5132893Sktlim@umich.edu    Addr cacheDataPC[Impl::MaxThreads];
5142893Sktlim@umich.edu
5152906Sktlim@umich.edu    /** Whether or not the cache data is valid. */
5162906Sktlim@umich.edu    bool cacheDataValid[Impl::MaxThreads];
5172906Sktlim@umich.edu
5181060SN/A    /** Size of instructions. */
5191060SN/A    int instSize;
5201060SN/A
5211060SN/A    /** Icache stall statistics. */
5222292SN/A    Counter lastIcacheStall[Impl::MaxThreads];
5231062SN/A
5242292SN/A    /** List of Active Threads */
5256221Snate@binkert.org    std::list<ThreadID> *activeThreads;
5262292SN/A
5272292SN/A    /** Number of threads. */
5286221Snate@binkert.org    ThreadID numThreads;
5292292SN/A
5302292SN/A    /** Number of threads that are actively fetching. */
5316221Snate@binkert.org    ThreadID numFetchingThreads;
5322292SN/A
5332292SN/A    /** Thread ID being fetched. */
5346221Snate@binkert.org    ThreadID threadFetched;
5352292SN/A
5362348SN/A    /** Checks if there is an interrupt pending.  If there is, fetch
5372348SN/A     * must stop once it is not fetching PAL instructions.
5382348SN/A     */
5392292SN/A    bool interruptPending;
5402292SN/A
5412843Sktlim@umich.edu    /** Is there a drain pending. */
5422843Sktlim@umich.edu    bool drainPending;
5432843Sktlim@umich.edu
5442348SN/A    /** Records if fetch is switched out. */
5452307SN/A    bool switchedOut;
5462307SN/A
5478462Sgeoffrey.blake@arm.com    /** Set to true if a pipelined I-cache request should be issued. */
5488462Sgeoffrey.blake@arm.com    bool issuePipelinedIfetch[Impl::MaxThreads];
5498462Sgeoffrey.blake@arm.com
5508462Sgeoffrey.blake@arm.com    /** Event used to delay fault generation of translation faults */
5518462Sgeoffrey.blake@arm.com    FinishTranslationEvent finishTranslationEvent;
5528462Sgeoffrey.blake@arm.com
5532292SN/A    // @todo: Consider making these vectors and tracking on a per thread basis.
5542292SN/A    /** Stat for total number of cycles stalled due to an icache miss. */
5555999Snate@binkert.org    Stats::Scalar icacheStallCycles;
5562292SN/A    /** Stat for total number of fetched instructions. */
5575999Snate@binkert.org    Stats::Scalar fetchedInsts;
5582727Sktlim@umich.edu    /** Total number of fetched branches. */
5595999Snate@binkert.org    Stats::Scalar fetchedBranches;
5602292SN/A    /** Stat for total number of predicted branches. */
5615999Snate@binkert.org    Stats::Scalar predictedBranches;
5622292SN/A    /** Stat for total number of cycles spent fetching. */
5635999Snate@binkert.org    Stats::Scalar fetchCycles;
5642292SN/A    /** Stat for total number of cycles spent squashing. */
5655999Snate@binkert.org    Stats::Scalar fetchSquashCycles;
5667849SAli.Saidi@ARM.com    /** Stat for total number of cycles spent waiting for translation */
5677849SAli.Saidi@ARM.com    Stats::Scalar fetchTlbCycles;
5682292SN/A    /** Stat for total number of cycles spent blocked due to other stages in
5692292SN/A     * the pipeline.
5702292SN/A     */
5715999Snate@binkert.org    Stats::Scalar fetchIdleCycles;
5722348SN/A    /** Total number of cycles spent blocked. */
5735999Snate@binkert.org    Stats::Scalar fetchBlockedCycles;
5742348SN/A    /** Total number of cycles spent in any other state. */
5755999Snate@binkert.org    Stats::Scalar fetchMiscStallCycles;
5768462Sgeoffrey.blake@arm.com    /** Total number of cycles spent in waiting for drains. */
5778462Sgeoffrey.blake@arm.com    Stats::Scalar fetchPendingDrainCycles;
5788462Sgeoffrey.blake@arm.com    /** Total number of stall cycles caused by no active threads to run. */
5798462Sgeoffrey.blake@arm.com    Stats::Scalar fetchNoActiveThreadStallCycles;
5808462Sgeoffrey.blake@arm.com    /** Total number of stall cycles caused by pending traps. */
5818462Sgeoffrey.blake@arm.com    Stats::Scalar fetchPendingTrapStallCycles;
5828462Sgeoffrey.blake@arm.com    /** Total number of stall cycles caused by pending quiesce instructions. */
5838462Sgeoffrey.blake@arm.com    Stats::Scalar fetchPendingQuiesceStallCycles;
5848462Sgeoffrey.blake@arm.com    /** Total number of stall cycles caused by I-cache wait retrys. */
5858462Sgeoffrey.blake@arm.com    Stats::Scalar fetchIcacheWaitRetryStallCycles;
5862292SN/A    /** Stat for total number of fetched cache lines. */
5875999Snate@binkert.org    Stats::Scalar fetchedCacheLines;
5882348SN/A    /** Total number of outstanding icache accesses that were dropped
5892348SN/A     * due to a squash.
5902348SN/A     */
5915999Snate@binkert.org    Stats::Scalar fetchIcacheSquashes;
5928064SAli.Saidi@ARM.com    /** Total number of outstanding tlb accesses that were dropped
5938064SAli.Saidi@ARM.com     * due to a squash.
5948064SAli.Saidi@ARM.com     */
5958064SAli.Saidi@ARM.com    Stats::Scalar fetchTlbSquashes;
5962292SN/A    /** Distribution of number of instructions fetched each cycle. */
5975999Snate@binkert.org    Stats::Distribution fetchNisnDist;
5982348SN/A    /** Rate of how often fetch was idle. */
5992292SN/A    Stats::Formula idleRate;
6002348SN/A    /** Number of branch fetches per cycle. */
6012292SN/A    Stats::Formula branchRate;
6022348SN/A    /** Number of instruction fetched per cycle. */
6032292SN/A    Stats::Formula fetchRate;
6041060SN/A};
6051060SN/A
6062292SN/A#endif //__CPU_O3_FETCH_HH__
607