cpu.hh revision 5737
11689SN/A/*
21689SN/A * Copyright (c) 2004-2005 The Regents of The University of Michigan
31689SN/A * All rights reserved.
41689SN/A *
51689SN/A * Redistribution and use in source and binary forms, with or without
61689SN/A * modification, are permitted provided that the following conditions are
71689SN/A * met: redistributions of source code must retain the above copyright
81689SN/A * notice, this list of conditions and the following disclaimer;
91689SN/A * redistributions in binary form must reproduce the above copyright
101689SN/A * notice, this list of conditions and the following disclaimer in the
111689SN/A * documentation and/or other materials provided with the distribution;
121689SN/A * neither the name of the copyright holders nor the names of its
131689SN/A * contributors may be used to endorse or promote products derived from
141689SN/A * this software without specific prior written permission.
151689SN/A *
161689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
171689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
181689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
191689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
201689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
211689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
221689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
261689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
292756Sksewell@umich.edu *          Korey Sewell
301689SN/A */
311689SN/A
322325SN/A#ifndef __CPU_O3_CPU_HH__
332325SN/A#define __CPU_O3_CPU_HH__
341060SN/A
351060SN/A#include <iostream>
361060SN/A#include <list>
372292SN/A#include <queue>
382292SN/A#include <set>
391681SN/A#include <vector>
401060SN/A
412980Sgblack@eecs.umich.edu#include "arch/types.hh"
421060SN/A#include "base/statistics.hh"
431060SN/A#include "base/timebuf.hh"
441858SN/A#include "config/full_system.hh"
454598Sbinkertn@umich.edu#include "config/use_checker.hh"
462325SN/A#include "cpu/activity.hh"
471717SN/A#include "cpu/base.hh"
482683Sktlim@umich.edu#include "cpu/simple_thread.hh"
491717SN/A#include "cpu/o3/comm.hh"
501717SN/A#include "cpu/o3/cpu_policy.hh"
512292SN/A#include "cpu/o3/scoreboard.hh"
522292SN/A#include "cpu/o3/thread_state.hh"
532817Sksewell@umich.edu//#include "cpu/o3/thread_context.hh"
541060SN/A#include "sim/process.hh"
551060SN/A
565529Snate@binkert.org#include "params/DerivO3CPU.hh"
575529Snate@binkert.org
582316SN/Atemplate <class>
592316SN/Aclass Checker;
602680Sktlim@umich.educlass ThreadContext;
612817Sksewell@umich.edutemplate <class>
622817Sksewell@umich.educlass O3ThreadContext;
632843Sktlim@umich.edu
642843Sktlim@umich.educlass Checkpoint;
652669Sktlim@umich.educlass MemObject;
661060SN/Aclass Process;
671060SN/A
685529Snate@binkert.orgclass BaseCPUParams;
695529Snate@binkert.org
702733Sktlim@umich.educlass BaseO3CPU : public BaseCPU
711060SN/A{
721060SN/A    //Stuff that's pretty ISA independent will go here.
731060SN/A  public:
745529Snate@binkert.org    BaseO3CPU(BaseCPUParams *params);
752292SN/A
762292SN/A    void regStats();
771060SN/A};
781060SN/A
792348SN/A/**
802348SN/A * FullO3CPU class, has each of the stages (fetch through commit)
812348SN/A * within it, as well as all of the time buffers between stages.  The
822348SN/A * tick() function for the CPU is defined here.
832348SN/A */
841060SN/Atemplate <class Impl>
852733Sktlim@umich.educlass FullO3CPU : public BaseO3CPU
861060SN/A{
871060SN/A  public:
882325SN/A    // Typedefs from the Impl here.
891060SN/A    typedef typename Impl::CPUPol CPUPolicy;
901061SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
914329Sktlim@umich.edu    typedef typename Impl::O3CPU O3CPU;
921060SN/A
935595Sgblack@eecs.umich.edu    typedef O3ThreadState<Impl> ImplState;
942292SN/A    typedef O3ThreadState<Impl> Thread;
952292SN/A
962292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
972292SN/A
982817Sksewell@umich.edu    friend class O3ThreadContext<Impl>;
992829Sksewell@umich.edu
1001060SN/A  public:
1011060SN/A    enum Status {
1021060SN/A        Running,
1031060SN/A        Idle,
1041060SN/A        Halted,
1052307SN/A        Blocked,
1062307SN/A        SwitchedOut
1071060SN/A    };
1081060SN/A
1093781Sgblack@eecs.umich.edu    TheISA::ITB * itb;
1103781Sgblack@eecs.umich.edu    TheISA::DTB * dtb;
1113781Sgblack@eecs.umich.edu
1122292SN/A    /** Overall CPU status. */
1131060SN/A    Status _status;
1141060SN/A
1152829Sksewell@umich.edu    /** Per-thread status in CPU, used for SMT.  */
1162829Sksewell@umich.edu    Status _threadStatus[Impl::MaxThreads];
1172829Sksewell@umich.edu
1181060SN/A  private:
1191060SN/A    class TickEvent : public Event
1201060SN/A    {
1211060SN/A      private:
1222292SN/A        /** Pointer to the CPU. */
1231755SN/A        FullO3CPU<Impl> *cpu;
1241060SN/A
1251060SN/A      public:
1262292SN/A        /** Constructs a tick event. */
1271755SN/A        TickEvent(FullO3CPU<Impl> *c);
1282292SN/A
1292292SN/A        /** Processes a tick event, calling tick() on the CPU. */
1301060SN/A        void process();
1312292SN/A        /** Returns the description of the tick event. */
1325336Shines@cs.fsu.edu        const char *description() const;
1331060SN/A    };
1341060SN/A
1352292SN/A    /** The tick event used for scheduling CPU ticks. */
1361060SN/A    TickEvent tickEvent;
1371060SN/A
1382292SN/A    /** Schedule tick event, regardless of its current state. */
1391060SN/A    void scheduleTickEvent(int delay)
1401060SN/A    {
1411060SN/A        if (tickEvent.squashed())
1425606Snate@binkert.org            reschedule(tickEvent, nextCycle(curTick + ticks(delay)));
1431060SN/A        else if (!tickEvent.scheduled())
1445606Snate@binkert.org            schedule(tickEvent, nextCycle(curTick + ticks(delay)));
1451060SN/A    }
1461060SN/A
1472292SN/A    /** Unschedule tick event, regardless of its current state. */
1481060SN/A    void unscheduleTickEvent()
1491060SN/A    {
1501060SN/A        if (tickEvent.scheduled())
1511060SN/A            tickEvent.squash();
1521060SN/A    }
1531060SN/A
1542829Sksewell@umich.edu    class ActivateThreadEvent : public Event
1552829Sksewell@umich.edu    {
1562829Sksewell@umich.edu      private:
1572829Sksewell@umich.edu        /** Number of Thread to Activate */
1582829Sksewell@umich.edu        int tid;
1592829Sksewell@umich.edu
1602829Sksewell@umich.edu        /** Pointer to the CPU. */
1612829Sksewell@umich.edu        FullO3CPU<Impl> *cpu;
1622829Sksewell@umich.edu
1632829Sksewell@umich.edu      public:
1642829Sksewell@umich.edu        /** Constructs the event. */
1652829Sksewell@umich.edu        ActivateThreadEvent();
1662829Sksewell@umich.edu
1672829Sksewell@umich.edu        /** Initialize Event */
1682829Sksewell@umich.edu        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
1692829Sksewell@umich.edu
1702829Sksewell@umich.edu        /** Processes the event, calling activateThread() on the CPU. */
1712829Sksewell@umich.edu        void process();
1722829Sksewell@umich.edu
1732829Sksewell@umich.edu        /** Returns the description of the event. */
1745336Shines@cs.fsu.edu        const char *description() const;
1752829Sksewell@umich.edu    };
1762829Sksewell@umich.edu
1772829Sksewell@umich.edu    /** Schedule thread to activate , regardless of its current state. */
1782829Sksewell@umich.edu    void scheduleActivateThreadEvent(int tid, int delay)
1792829Sksewell@umich.edu    {
1802829Sksewell@umich.edu        // Schedule thread to activate, regardless of its current state.
1812829Sksewell@umich.edu        if (activateThreadEvent[tid].squashed())
1825606Snate@binkert.org            reschedule(activateThreadEvent[tid],
1835606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
1842829Sksewell@umich.edu        else if (!activateThreadEvent[tid].scheduled())
1855606Snate@binkert.org            schedule(activateThreadEvent[tid],
1865606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
1872829Sksewell@umich.edu    }
1882829Sksewell@umich.edu
1892829Sksewell@umich.edu    /** Unschedule actiavte thread event, regardless of its current state. */
1902829Sksewell@umich.edu    void unscheduleActivateThreadEvent(int tid)
1912829Sksewell@umich.edu    {
1922829Sksewell@umich.edu        if (activateThreadEvent[tid].scheduled())
1932829Sksewell@umich.edu            activateThreadEvent[tid].squash();
1942829Sksewell@umich.edu    }
1952829Sksewell@umich.edu
1965595Sgblack@eecs.umich.edu#if !FULL_SYSTEM
1975595Sgblack@eecs.umich.edu    TheISA::IntReg getSyscallArg(int i, int tid);
1985595Sgblack@eecs.umich.edu
1995595Sgblack@eecs.umich.edu    /** Used to shift args for indirect syscall. */
2005595Sgblack@eecs.umich.edu    void setSyscallArg(int i, TheISA::IntReg val, int tid);
2015595Sgblack@eecs.umich.edu#endif
2025595Sgblack@eecs.umich.edu
2032829Sksewell@umich.edu    /** The tick event used for scheduling CPU ticks. */
2042829Sksewell@umich.edu    ActivateThreadEvent activateThreadEvent[Impl::MaxThreads];
2052829Sksewell@umich.edu
2062875Sksewell@umich.edu    class DeallocateContextEvent : public Event
2072875Sksewell@umich.edu    {
2082875Sksewell@umich.edu      private:
2093221Sktlim@umich.edu        /** Number of Thread to deactivate */
2102875Sksewell@umich.edu        int tid;
2112875Sksewell@umich.edu
2123221Sktlim@umich.edu        /** Should the thread be removed from the CPU? */
2133221Sktlim@umich.edu        bool remove;
2143221Sktlim@umich.edu
2152875Sksewell@umich.edu        /** Pointer to the CPU. */
2162875Sksewell@umich.edu        FullO3CPU<Impl> *cpu;
2172875Sksewell@umich.edu
2182875Sksewell@umich.edu      public:
2192875Sksewell@umich.edu        /** Constructs the event. */
2202875Sksewell@umich.edu        DeallocateContextEvent();
2212875Sksewell@umich.edu
2222875Sksewell@umich.edu        /** Initialize Event */
2232875Sksewell@umich.edu        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
2242875Sksewell@umich.edu
2252875Sksewell@umich.edu        /** Processes the event, calling activateThread() on the CPU. */
2262875Sksewell@umich.edu        void process();
2272875Sksewell@umich.edu
2283221Sktlim@umich.edu        /** Sets whether the thread should also be removed from the CPU. */
2293221Sktlim@umich.edu        void setRemove(bool _remove) { remove = _remove; }
2303221Sktlim@umich.edu
2312875Sksewell@umich.edu        /** Returns the description of the event. */
2325336Shines@cs.fsu.edu        const char *description() const;
2332875Sksewell@umich.edu    };
2342875Sksewell@umich.edu
2352875Sksewell@umich.edu    /** Schedule cpu to deallocate thread context.*/
2363221Sktlim@umich.edu    void scheduleDeallocateContextEvent(int tid, bool remove, int delay)
2372875Sksewell@umich.edu    {
2382875Sksewell@umich.edu        // Schedule thread to activate, regardless of its current state.
2392875Sksewell@umich.edu        if (deallocateContextEvent[tid].squashed())
2405606Snate@binkert.org            reschedule(deallocateContextEvent[tid],
2415606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
2422875Sksewell@umich.edu        else if (!deallocateContextEvent[tid].scheduled())
2435606Snate@binkert.org            schedule(deallocateContextEvent[tid],
2445606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
2452875Sksewell@umich.edu    }
2462875Sksewell@umich.edu
2472875Sksewell@umich.edu    /** Unschedule thread deallocation in CPU */
2482875Sksewell@umich.edu    void unscheduleDeallocateContextEvent(int tid)
2492875Sksewell@umich.edu    {
2502875Sksewell@umich.edu        if (deallocateContextEvent[tid].scheduled())
2512875Sksewell@umich.edu            deallocateContextEvent[tid].squash();
2522875Sksewell@umich.edu    }
2532875Sksewell@umich.edu
2542875Sksewell@umich.edu    /** The tick event used for scheduling CPU ticks. */
2552875Sksewell@umich.edu    DeallocateContextEvent deallocateContextEvent[Impl::MaxThreads];
2562875Sksewell@umich.edu
2571060SN/A  public:
2582292SN/A    /** Constructs a CPU with the given parameters. */
2595595Sgblack@eecs.umich.edu    FullO3CPU(DerivO3CPUParams *params);
2602292SN/A    /** Destructor. */
2611755SN/A    ~FullO3CPU();
2621060SN/A
2632292SN/A    /** Registers statistics. */
2645595Sgblack@eecs.umich.edu    void regStats();
2651684SN/A
2665358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
2675358Sgblack@eecs.umich.edu    {
2685358Sgblack@eecs.umich.edu        this->itb->demapPage(vaddr, asn);
2695358Sgblack@eecs.umich.edu        this->dtb->demapPage(vaddr, asn);
2705358Sgblack@eecs.umich.edu    }
2715358Sgblack@eecs.umich.edu
2725358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
2735358Sgblack@eecs.umich.edu    {
2745358Sgblack@eecs.umich.edu        this->itb->demapPage(vaddr, asn);
2755358Sgblack@eecs.umich.edu    }
2765358Sgblack@eecs.umich.edu
2775358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
2785358Sgblack@eecs.umich.edu    {
2795358Sgblack@eecs.umich.edu        this->dtb->demapPage(vaddr, asn);
2805358Sgblack@eecs.umich.edu    }
2815358Sgblack@eecs.umich.edu
2824988Sgblack@eecs.umich.edu    /** Translates instruction requestion. */
2834988Sgblack@eecs.umich.edu    Fault translateInstReq(RequestPtr &req, Thread *thread)
2844988Sgblack@eecs.umich.edu    {
2854988Sgblack@eecs.umich.edu        return this->itb->translate(req, thread->getTC());
2864988Sgblack@eecs.umich.edu    }
2874988Sgblack@eecs.umich.edu
2884988Sgblack@eecs.umich.edu    /** Translates data read request. */
2894988Sgblack@eecs.umich.edu    Fault translateDataReadReq(RequestPtr &req, Thread *thread)
2904988Sgblack@eecs.umich.edu    {
2914988Sgblack@eecs.umich.edu        return this->dtb->translate(req, thread->getTC(), false);
2924988Sgblack@eecs.umich.edu    }
2934988Sgblack@eecs.umich.edu
2944988Sgblack@eecs.umich.edu    /** Translates data write request. */
2954988Sgblack@eecs.umich.edu    Fault translateDataWriteReq(RequestPtr &req, Thread *thread)
2964988Sgblack@eecs.umich.edu    {
2974988Sgblack@eecs.umich.edu        return this->dtb->translate(req, thread->getTC(), true);
2984988Sgblack@eecs.umich.edu    }
2994988Sgblack@eecs.umich.edu
3002871Sktlim@umich.edu    /** Returns a specific port. */
3012871Sktlim@umich.edu    Port *getPort(const std::string &if_name, int idx);
3022871Sktlim@umich.edu
3032292SN/A    /** Ticks CPU, calling tick() on each stage, and checking the overall
3042292SN/A     *  activity to see if the CPU should deschedule itself.
3052292SN/A     */
3061684SN/A    void tick();
3071684SN/A
3082292SN/A    /** Initialize the CPU */
3091060SN/A    void init();
3101060SN/A
3112834Sksewell@umich.edu    /** Returns the Number of Active Threads in the CPU */
3122834Sksewell@umich.edu    int numActiveThreads()
3132834Sksewell@umich.edu    { return activeThreads.size(); }
3142834Sksewell@umich.edu
3152829Sksewell@umich.edu    /** Add Thread to Active Threads List */
3162875Sksewell@umich.edu    void activateThread(unsigned tid);
3172875Sksewell@umich.edu
3182875Sksewell@umich.edu    /** Remove Thread from Active Threads List */
3192875Sksewell@umich.edu    void deactivateThread(unsigned tid);
3202829Sksewell@umich.edu
3212292SN/A    /** Setup CPU to insert a thread's context */
3222292SN/A    void insertThread(unsigned tid);
3231060SN/A
3242292SN/A    /** Remove all of a thread's context from CPU */
3252292SN/A    void removeThread(unsigned tid);
3262292SN/A
3272292SN/A    /** Count the Total Instructions Committed in the CPU. */
3282292SN/A    virtual Counter totalInstructions() const
3292292SN/A    {
3302292SN/A        Counter total(0);
3312292SN/A
3322292SN/A        for (int i=0; i < thread.size(); i++)
3332292SN/A            total += thread[i]->numInst;
3342292SN/A
3352292SN/A        return total;
3362292SN/A    }
3372292SN/A
3382292SN/A    /** Add Thread to Active Threads List. */
3392292SN/A    void activateContext(int tid, int delay);
3402292SN/A
3412292SN/A    /** Remove Thread from Active Threads List */
3422292SN/A    void suspendContext(int tid);
3432292SN/A
3442292SN/A    /** Remove Thread from Active Threads List &&
3453221Sktlim@umich.edu     *  Possibly Remove Thread Context from CPU.
3462292SN/A     */
3473221Sktlim@umich.edu    bool deallocateContext(int tid, bool remove, int delay = 1);
3482292SN/A
3492292SN/A    /** Remove Thread from Active Threads List &&
3502292SN/A     *  Remove Thread Context from CPU.
3512292SN/A     */
3522292SN/A    void haltContext(int tid);
3532292SN/A
3542292SN/A    /** Activate a Thread When CPU Resources are Available. */
3552292SN/A    void activateWhenReady(int tid);
3562292SN/A
3572292SN/A    /** Add or Remove a Thread Context in the CPU. */
3582292SN/A    void doContextSwitch();
3592292SN/A
3602292SN/A    /** Update The Order In Which We Process Threads. */
3612292SN/A    void updateThreadPriority();
3622292SN/A
3632864Sktlim@umich.edu    /** Serialize state. */
3642864Sktlim@umich.edu    virtual void serialize(std::ostream &os);
3652864Sktlim@umich.edu
3662864Sktlim@umich.edu    /** Unserialize from a checkpoint. */
3672864Sktlim@umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
3682864Sktlim@umich.edu
3692864Sktlim@umich.edu  public:
3705595Sgblack@eecs.umich.edu#if !FULL_SYSTEM
3715595Sgblack@eecs.umich.edu    /** Executes a syscall.
3725595Sgblack@eecs.umich.edu     * @todo: Determine if this needs to be virtual.
3732292SN/A     */
3745595Sgblack@eecs.umich.edu    void syscall(int64_t callnum, int tid);
3755595Sgblack@eecs.umich.edu
3765595Sgblack@eecs.umich.edu    /** Sets the return value of a syscall. */
3775595Sgblack@eecs.umich.edu    void setSyscallReturn(SyscallReturn return_value, int tid);
3785595Sgblack@eecs.umich.edu
3795595Sgblack@eecs.umich.edu#endif
3802292SN/A
3812843Sktlim@umich.edu    /** Starts draining the CPU's pipeline of all instructions in
3822843Sktlim@umich.edu     * order to stop all memory accesses. */
3832905Sktlim@umich.edu    virtual unsigned int drain(Event *drain_event);
3842843Sktlim@umich.edu
3852843Sktlim@umich.edu    /** Resumes execution after a drain. */
3862843Sktlim@umich.edu    virtual void resume();
3872292SN/A
3882348SN/A    /** Signals to this CPU that a stage has completed switching out. */
3892843Sktlim@umich.edu    void signalDrained();
3902843Sktlim@umich.edu
3912843Sktlim@umich.edu    /** Switches out this CPU. */
3922843Sktlim@umich.edu    virtual void switchOut();
3932316SN/A
3942348SN/A    /** Takes over from another CPU. */
3952843Sktlim@umich.edu    virtual void takeOverFrom(BaseCPU *oldCPU);
3961060SN/A
3971060SN/A    /** Get the current instruction sequence number, and increment it. */
3982316SN/A    InstSeqNum getAndIncrementInstSeq()
3992316SN/A    { return globalSeqNum++; }
4001060SN/A
4015595Sgblack@eecs.umich.edu    /** Traps to handle given fault. */
4025595Sgblack@eecs.umich.edu    void trap(Fault fault, unsigned tid);
4035595Sgblack@eecs.umich.edu
4041858SN/A#if FULL_SYSTEM
4055595Sgblack@eecs.umich.edu    /** Posts an interrupt. */
4065704Snate@binkert.org    void postInterrupt(int int_num, int index);
4075595Sgblack@eecs.umich.edu
4085702Ssaidi@eecs.umich.edu    /** HW return from error interrupt. */
4095702Ssaidi@eecs.umich.edu    Fault hwrei(unsigned tid);
4105702Ssaidi@eecs.umich.edu
4115702Ssaidi@eecs.umich.edu    bool simPalCheck(int palFunc, unsigned tid);
4125702Ssaidi@eecs.umich.edu
4135595Sgblack@eecs.umich.edu    /** Returns the Fault for any valid interrupt. */
4145595Sgblack@eecs.umich.edu    Fault getInterrupts();
4155595Sgblack@eecs.umich.edu
4165595Sgblack@eecs.umich.edu    /** Processes any an interrupt fault. */
4175595Sgblack@eecs.umich.edu    void processInterrupts(Fault interrupt);
4185595Sgblack@eecs.umich.edu
4195595Sgblack@eecs.umich.edu    /** Halts the CPU. */
4205595Sgblack@eecs.umich.edu    void halt() { panic("Halt not implemented!\n"); }
4215595Sgblack@eecs.umich.edu
4224192Sktlim@umich.edu    /** Update the Virt and Phys ports of all ThreadContexts to
4234192Sktlim@umich.edu     * reflect change in memory connections. */
4244192Sktlim@umich.edu    void updateMemPorts();
4254192Sktlim@umich.edu
4261060SN/A    /** Check if this address is a valid instruction address. */
4271060SN/A    bool validInstAddr(Addr addr) { return true; }
4281060SN/A
4291060SN/A    /** Check if this address is a valid data address. */
4301060SN/A    bool validDataAddr(Addr addr) { return true; }
4311060SN/A
4321060SN/A    /** Get instruction asid. */
4332292SN/A    int getInstAsid(unsigned tid)
4342292SN/A    { return regFile.miscRegs[tid].getInstAsid(); }
4351060SN/A
4361060SN/A    /** Get data asid. */
4372292SN/A    int getDataAsid(unsigned tid)
4382292SN/A    { return regFile.miscRegs[tid].getDataAsid(); }
4391060SN/A#else
4402292SN/A    /** Get instruction asid. */
4412292SN/A    int getInstAsid(unsigned tid)
4422683Sktlim@umich.edu    { return thread[tid]->getInstAsid(); }
4431060SN/A
4442292SN/A    /** Get data asid. */
4452292SN/A    int getDataAsid(unsigned tid)
4462683Sktlim@umich.edu    { return thread[tid]->getDataAsid(); }
4471060SN/A
4481060SN/A#endif
4491060SN/A
4502348SN/A    /** Register accessors.  Index refers to the physical register index. */
4515595Sgblack@eecs.umich.edu
4525595Sgblack@eecs.umich.edu    /** Reads a miscellaneous register. */
4535595Sgblack@eecs.umich.edu    TheISA::MiscReg readMiscRegNoEffect(int misc_reg, unsigned tid);
4545595Sgblack@eecs.umich.edu
4555595Sgblack@eecs.umich.edu    /** Reads a misc. register, including any side effects the read
4565595Sgblack@eecs.umich.edu     * might have as defined by the architecture.
4575595Sgblack@eecs.umich.edu     */
4585595Sgblack@eecs.umich.edu    TheISA::MiscReg readMiscReg(int misc_reg, unsigned tid);
4595595Sgblack@eecs.umich.edu
4605595Sgblack@eecs.umich.edu    /** Sets a miscellaneous register. */
4615595Sgblack@eecs.umich.edu    void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val, unsigned tid);
4625595Sgblack@eecs.umich.edu
4635595Sgblack@eecs.umich.edu    /** Sets a misc. register, including any side effects the write
4645595Sgblack@eecs.umich.edu     * might have as defined by the architecture.
4655595Sgblack@eecs.umich.edu     */
4665595Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const TheISA::MiscReg &val,
4675595Sgblack@eecs.umich.edu            unsigned tid);
4685595Sgblack@eecs.umich.edu
4691060SN/A    uint64_t readIntReg(int reg_idx);
4701060SN/A
4713781Sgblack@eecs.umich.edu    TheISA::FloatReg readFloatReg(int reg_idx);
4721060SN/A
4733781Sgblack@eecs.umich.edu    TheISA::FloatReg readFloatReg(int reg_idx, int width);
4741060SN/A
4753781Sgblack@eecs.umich.edu    TheISA::FloatRegBits readFloatRegBits(int reg_idx);
4762455SN/A
4773781Sgblack@eecs.umich.edu    TheISA::FloatRegBits readFloatRegBits(int reg_idx, int width);
4781060SN/A
4791060SN/A    void setIntReg(int reg_idx, uint64_t val);
4801060SN/A
4813781Sgblack@eecs.umich.edu    void setFloatReg(int reg_idx, TheISA::FloatReg val);
4821060SN/A
4833781Sgblack@eecs.umich.edu    void setFloatReg(int reg_idx, TheISA::FloatReg val, int width);
4841060SN/A
4853781Sgblack@eecs.umich.edu    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);
4862455SN/A
4873781Sgblack@eecs.umich.edu    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val, int width);
4881060SN/A
4892292SN/A    uint64_t readArchIntReg(int reg_idx, unsigned tid);
4901060SN/A
4912292SN/A    float readArchFloatRegSingle(int reg_idx, unsigned tid);
4921060SN/A
4932292SN/A    double readArchFloatRegDouble(int reg_idx, unsigned tid);
4942292SN/A
4952292SN/A    uint64_t readArchFloatRegInt(int reg_idx, unsigned tid);
4962292SN/A
4972348SN/A    /** Architectural register accessors.  Looks up in the commit
4982348SN/A     * rename table to obtain the true physical index of the
4992348SN/A     * architected register first, then accesses that physical
5002348SN/A     * register.
5012348SN/A     */
5022292SN/A    void setArchIntReg(int reg_idx, uint64_t val, unsigned tid);
5032292SN/A
5042292SN/A    void setArchFloatRegSingle(int reg_idx, float val, unsigned tid);
5052292SN/A
5062292SN/A    void setArchFloatRegDouble(int reg_idx, double val, unsigned tid);
5072292SN/A
5082292SN/A    void setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid);
5092292SN/A
5102348SN/A    /** Reads the commit PC of a specific thread. */
5114636Sgblack@eecs.umich.edu    Addr readPC(unsigned tid);
5122292SN/A
5132348SN/A    /** Sets the commit PC of a specific thread. */
5142348SN/A    void setPC(Addr new_PC, unsigned tid);
5152292SN/A
5164636Sgblack@eecs.umich.edu    /** Reads the commit micro PC of a specific thread. */
5174636Sgblack@eecs.umich.edu    Addr readMicroPC(unsigned tid);
5184636Sgblack@eecs.umich.edu
5194636Sgblack@eecs.umich.edu    /** Sets the commmit micro PC of a specific thread. */
5204636Sgblack@eecs.umich.edu    void setMicroPC(Addr new_microPC, unsigned tid);
5214636Sgblack@eecs.umich.edu
5222348SN/A    /** Reads the next PC of a specific thread. */
5234636Sgblack@eecs.umich.edu    Addr readNextPC(unsigned tid);
5242292SN/A
5252348SN/A    /** Sets the next PC of a specific thread. */
5264636Sgblack@eecs.umich.edu    void setNextPC(Addr val, unsigned tid);
5271060SN/A
5282756Sksewell@umich.edu    /** Reads the next NPC of a specific thread. */
5294636Sgblack@eecs.umich.edu    Addr readNextNPC(unsigned tid);
5302756Sksewell@umich.edu
5312756Sksewell@umich.edu    /** Sets the next NPC of a specific thread. */
5324636Sgblack@eecs.umich.edu    void setNextNPC(Addr val, unsigned tid);
5334636Sgblack@eecs.umich.edu
5344636Sgblack@eecs.umich.edu    /** Reads the commit next micro PC of a specific thread. */
5354636Sgblack@eecs.umich.edu    Addr readNextMicroPC(unsigned tid);
5364636Sgblack@eecs.umich.edu
5374636Sgblack@eecs.umich.edu    /** Sets the commit next micro PC of a specific thread. */
5384636Sgblack@eecs.umich.edu    void setNextMicroPC(Addr val, unsigned tid);
5392756Sksewell@umich.edu
5405595Sgblack@eecs.umich.edu    /** Initiates a squash of all in-flight instructions for a given
5415595Sgblack@eecs.umich.edu     * thread.  The source of the squash is an external update of
5425595Sgblack@eecs.umich.edu     * state through the TC.
5435595Sgblack@eecs.umich.edu     */
5445595Sgblack@eecs.umich.edu    void squashFromTC(unsigned tid);
5455595Sgblack@eecs.umich.edu
5461060SN/A    /** Function to add instruction onto the head of the list of the
5471060SN/A     *  instructions.  Used when new instructions are fetched.
5481060SN/A     */
5492292SN/A    ListIt addInst(DynInstPtr &inst);
5501060SN/A
5511060SN/A    /** Function to tell the CPU that an instruction has completed. */
5522292SN/A    void instDone(unsigned tid);
5531060SN/A
5542292SN/A    /** Add Instructions to the CPU Remove List*/
5552292SN/A    void addToRemoveList(DynInstPtr &inst);
5561060SN/A
5572325SN/A    /** Remove an instruction from the front end of the list.  There's
5582325SN/A     *  no restriction on location of the instruction.
5591060SN/A     */
5601061SN/A    void removeFrontInst(DynInstPtr &inst);
5611060SN/A
5622935Sksewell@umich.edu    /** Remove all instructions that are not currently in the ROB.
5632935Sksewell@umich.edu     *  There's also an option to not squash delay slot instructions.*/
5644632Sgblack@eecs.umich.edu    void removeInstsNotInROB(unsigned tid);
5651060SN/A
5661062SN/A    /** Remove all instructions younger than the given sequence number. */
5672292SN/A    void removeInstsUntil(const InstSeqNum &seq_num,unsigned tid);
5682292SN/A
5692348SN/A    /** Removes the instruction pointed to by the iterator. */
5702292SN/A    inline void squashInstIt(const ListIt &instIt, const unsigned &tid);
5712292SN/A
5722348SN/A    /** Cleans up all instructions on the remove list. */
5732292SN/A    void cleanUpRemovedInsts();
5741062SN/A
5752348SN/A    /** Debug function to print all instructions on the list. */
5761060SN/A    void dumpInsts();
5771060SN/A
5781060SN/A  public:
5795737Scws3k@cs.virginia.edu#ifndef NDEBUG
5805737Scws3k@cs.virginia.edu    /** Count of total number of dynamic instructions in flight. */
5815737Scws3k@cs.virginia.edu    int instcount;
5825737Scws3k@cs.virginia.edu#endif
5835737Scws3k@cs.virginia.edu
5841060SN/A    /** List of all the instructions in flight. */
5852292SN/A    std::list<DynInstPtr> instList;
5861060SN/A
5872292SN/A    /** List of all the instructions that will be removed at the end of this
5882292SN/A     *  cycle.
5892292SN/A     */
5902292SN/A    std::queue<ListIt> removeList;
5912292SN/A
5922325SN/A#ifdef DEBUG
5932348SN/A    /** Debug structure to keep track of the sequence numbers still in
5942348SN/A     * flight.
5952348SN/A     */
5962292SN/A    std::set<InstSeqNum> snList;
5972325SN/A#endif
5982292SN/A
5992325SN/A    /** Records if instructions need to be removed this cycle due to
6002325SN/A     *  being retired or squashed.
6012292SN/A     */
6022292SN/A    bool removeInstsThisCycle;
6032292SN/A
6041060SN/A  protected:
6051060SN/A    /** The fetch stage. */
6061060SN/A    typename CPUPolicy::Fetch fetch;
6071060SN/A
6081060SN/A    /** The decode stage. */
6091060SN/A    typename CPUPolicy::Decode decode;
6101060SN/A
6111060SN/A    /** The dispatch stage. */
6121060SN/A    typename CPUPolicy::Rename rename;
6131060SN/A
6141060SN/A    /** The issue/execute/writeback stages. */
6151060SN/A    typename CPUPolicy::IEW iew;
6161060SN/A
6171060SN/A    /** The commit stage. */
6181060SN/A    typename CPUPolicy::Commit commit;
6191060SN/A
6201060SN/A    /** The register file. */
6211060SN/A    typename CPUPolicy::RegFile regFile;
6221060SN/A
6231060SN/A    /** The free list. */
6241060SN/A    typename CPUPolicy::FreeList freeList;
6251060SN/A
6261060SN/A    /** The rename map. */
6272292SN/A    typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
6282292SN/A
6292292SN/A    /** The commit rename map. */
6302292SN/A    typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
6311060SN/A
6321060SN/A    /** The re-order buffer. */
6331060SN/A    typename CPUPolicy::ROB rob;
6341060SN/A
6352292SN/A    /** Active Threads List */
6362292SN/A    std::list<unsigned> activeThreads;
6372292SN/A
6382292SN/A    /** Integer Register Scoreboard */
6392292SN/A    Scoreboard scoreboard;
6402292SN/A
6411060SN/A  public:
6422292SN/A    /** Enum to give each stage a specific index, so when calling
6432292SN/A     *  activateStage() or deactivateStage(), they can specify which stage
6442292SN/A     *  is being activated/deactivated.
6452292SN/A     */
6462292SN/A    enum StageIdx {
6472292SN/A        FetchIdx,
6482292SN/A        DecodeIdx,
6492292SN/A        RenameIdx,
6502292SN/A        IEWIdx,
6512292SN/A        CommitIdx,
6522292SN/A        NumStages };
6532292SN/A
6541060SN/A    /** Typedefs from the Impl to get the structs that each of the
6551060SN/A     *  time buffers should use.
6561060SN/A     */
6571061SN/A    typedef typename CPUPolicy::TimeStruct TimeStruct;
6581060SN/A
6591061SN/A    typedef typename CPUPolicy::FetchStruct FetchStruct;
6601060SN/A
6611061SN/A    typedef typename CPUPolicy::DecodeStruct DecodeStruct;
6621060SN/A
6631061SN/A    typedef typename CPUPolicy::RenameStruct RenameStruct;
6641060SN/A
6651061SN/A    typedef typename CPUPolicy::IEWStruct IEWStruct;
6661060SN/A
6671060SN/A    /** The main time buffer to do backwards communication. */
6681060SN/A    TimeBuffer<TimeStruct> timeBuffer;
6691060SN/A
6701060SN/A    /** The fetch stage's instruction queue. */
6711060SN/A    TimeBuffer<FetchStruct> fetchQueue;
6721060SN/A
6731060SN/A    /** The decode stage's instruction queue. */
6741060SN/A    TimeBuffer<DecodeStruct> decodeQueue;
6751060SN/A
6761060SN/A    /** The rename stage's instruction queue. */
6771060SN/A    TimeBuffer<RenameStruct> renameQueue;
6781060SN/A
6791060SN/A    /** The IEW stage's instruction queue. */
6801060SN/A    TimeBuffer<IEWStruct> iewQueue;
6811060SN/A
6822348SN/A  private:
6832348SN/A    /** The activity recorder; used to tell if the CPU has any
6842348SN/A     * activity remaining or if it can go to idle and deschedule
6852348SN/A     * itself.
6862348SN/A     */
6872325SN/A    ActivityRecorder activityRec;
6881060SN/A
6892348SN/A  public:
6902348SN/A    /** Records that there was time buffer activity this cycle. */
6912325SN/A    void activityThisCycle() { activityRec.activity(); }
6922292SN/A
6932348SN/A    /** Changes a stage's status to active within the activity recorder. */
6942325SN/A    void activateStage(const StageIdx idx)
6952325SN/A    { activityRec.activateStage(idx); }
6962292SN/A
6972348SN/A    /** Changes a stage's status to inactive within the activity recorder. */
6982325SN/A    void deactivateStage(const StageIdx idx)
6992325SN/A    { activityRec.deactivateStage(idx); }
7002292SN/A
7012292SN/A    /** Wakes the CPU, rescheduling the CPU if it's not already active. */
7022292SN/A    void wakeCPU();
7032260SN/A
7042292SN/A    /** Gets a free thread id. Use if thread ids change across system. */
7052292SN/A    int getFreeTid();
7062292SN/A
7072292SN/A  public:
7082680Sktlim@umich.edu    /** Returns a pointer to a thread context. */
7092680Sktlim@umich.edu    ThreadContext *tcBase(unsigned tid)
7101681SN/A    {
7112680Sktlim@umich.edu        return thread[tid]->getTC();
7122190SN/A    }
7132190SN/A
7142292SN/A    /** The global sequence number counter. */
7153093Sksewell@umich.edu    InstSeqNum globalSeqNum;//[Impl::MaxThreads];
7161060SN/A
7174598Sbinkertn@umich.edu#if USE_CHECKER
7182348SN/A    /** Pointer to the checker, which can dynamically verify
7192348SN/A     * instruction results at run time.  This can be set to NULL if it
7202348SN/A     * is not being used.
7212348SN/A     */
7222316SN/A    Checker<DynInstPtr> *checker;
7234598Sbinkertn@umich.edu#endif
7242316SN/A
7251858SN/A#if FULL_SYSTEM
7262292SN/A    /** Pointer to the system. */
7271060SN/A    System *system;
7281060SN/A
7292292SN/A    /** Pointer to physical memory. */
7301060SN/A    PhysicalMemory *physmem;
7312292SN/A#endif
7321060SN/A
7332843Sktlim@umich.edu    /** Event to call process() on once draining has completed. */
7342843Sktlim@umich.edu    Event *drainEvent;
7352843Sktlim@umich.edu
7362843Sktlim@umich.edu    /** Counter of how many stages have completed draining. */
7372843Sktlim@umich.edu    int drainCount;
7382316SN/A
7392348SN/A    /** Pointers to all of the threads in the CPU. */
7402292SN/A    std::vector<Thread *> thread;
7412260SN/A
7422292SN/A    /** Whether or not the CPU should defer its registration. */
7431060SN/A    bool deferRegistration;
7441060SN/A
7452292SN/A    /** Is there a context switch pending? */
7462292SN/A    bool contextSwitch;
7471060SN/A
7482292SN/A    /** Threads Scheduled to Enter CPU */
7492292SN/A    std::list<int> cpuWaitList;
7502292SN/A
7512292SN/A    /** The cycle that the CPU was last running, used for statistics. */
7522292SN/A    Tick lastRunningCycle;
7532292SN/A
7542829Sksewell@umich.edu    /** The cycle that the CPU was last activated by a new thread*/
7552829Sksewell@umich.edu    Tick lastActivatedCycle;
7562829Sksewell@umich.edu
7572292SN/A    /** Number of Threads CPU can process */
7582292SN/A    unsigned numThreads;
7592292SN/A
7602292SN/A    /** Mapping for system thread id to cpu id */
7612292SN/A    std::map<unsigned,unsigned> threadMap;
7622292SN/A
7632292SN/A    /** Available thread ids in the cpu*/
7642292SN/A    std::vector<unsigned> tids;
7652292SN/A
7665595Sgblack@eecs.umich.edu    /** CPU read function, forwards read to LSQ. */
7675595Sgblack@eecs.umich.edu    template <class T>
7685595Sgblack@eecs.umich.edu    Fault read(RequestPtr &req, T &data, int load_idx)
7695595Sgblack@eecs.umich.edu    {
7705595Sgblack@eecs.umich.edu        return this->iew.ldstQueue.read(req, data, load_idx);
7715595Sgblack@eecs.umich.edu    }
7725595Sgblack@eecs.umich.edu
7735595Sgblack@eecs.umich.edu    /** CPU write function, forwards write to LSQ. */
7745595Sgblack@eecs.umich.edu    template <class T>
7755595Sgblack@eecs.umich.edu    Fault write(RequestPtr &req, T &data, int store_idx)
7765595Sgblack@eecs.umich.edu    {
7775595Sgblack@eecs.umich.edu        return this->iew.ldstQueue.write(req, data, store_idx);
7785595Sgblack@eecs.umich.edu    }
7795595Sgblack@eecs.umich.edu
7805595Sgblack@eecs.umich.edu    Addr lockAddr;
7815595Sgblack@eecs.umich.edu
7825595Sgblack@eecs.umich.edu    /** Temporary fix for the lock flag, works in the UP case. */
7835595Sgblack@eecs.umich.edu    bool lockFlag;
7845595Sgblack@eecs.umich.edu
7852292SN/A    /** Stat for total number of times the CPU is descheduled. */
7862292SN/A    Stats::Scalar<> timesIdled;
7872292SN/A    /** Stat for total number of cycles the CPU spends descheduled. */
7882292SN/A    Stats::Scalar<> idleCycles;
7892292SN/A    /** Stat for the number of committed instructions per thread. */
7902292SN/A    Stats::Vector<> committedInsts;
7912292SN/A    /** Stat for the total number of committed instructions. */
7922292SN/A    Stats::Scalar<> totalCommittedInsts;
7932292SN/A    /** Stat for the CPI per thread. */
7942292SN/A    Stats::Formula cpi;
7952292SN/A    /** Stat for the total CPI. */
7962292SN/A    Stats::Formula totalCpi;
7972292SN/A    /** Stat for the IPC per thread. */
7982292SN/A    Stats::Formula ipc;
7992292SN/A    /** Stat for the total IPC. */
8002292SN/A    Stats::Formula totalIpc;
8011060SN/A};
8021060SN/A
8032325SN/A#endif // __CPU_O3_CPU_HH__
804