cpu.hh revision 7684
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"
456658Snate@binkert.org#include "config/the_isa.hh"
464598Sbinkertn@umich.edu#include "config/use_checker.hh"
472325SN/A#include "cpu/activity.hh"
481717SN/A#include "cpu/base.hh"
492683Sktlim@umich.edu#include "cpu/simple_thread.hh"
501717SN/A#include "cpu/o3/comm.hh"
511717SN/A#include "cpu/o3/cpu_policy.hh"
522292SN/A#include "cpu/o3/scoreboard.hh"
532292SN/A#include "cpu/o3/thread_state.hh"
542817Sksewell@umich.edu//#include "cpu/o3/thread_context.hh"
551060SN/A#include "sim/process.hh"
561060SN/A
575529Snate@binkert.org#include "params/DerivO3CPU.hh"
585529Snate@binkert.org
592316SN/Atemplate <class>
602316SN/Aclass Checker;
612680Sktlim@umich.educlass ThreadContext;
622817Sksewell@umich.edutemplate <class>
632817Sksewell@umich.educlass O3ThreadContext;
642843Sktlim@umich.edu
652843Sktlim@umich.educlass Checkpoint;
662669Sktlim@umich.educlass MemObject;
671060SN/Aclass Process;
681060SN/A
695529Snate@binkert.orgclass BaseCPUParams;
705529Snate@binkert.org
712733Sktlim@umich.educlass BaseO3CPU : public BaseCPU
721060SN/A{
731060SN/A    //Stuff that's pretty ISA independent will go here.
741060SN/A  public:
755529Snate@binkert.org    BaseO3CPU(BaseCPUParams *params);
762292SN/A
772292SN/A    void regStats();
781060SN/A};
791060SN/A
802348SN/A/**
812348SN/A * FullO3CPU class, has each of the stages (fetch through commit)
822348SN/A * within it, as well as all of the time buffers between stages.  The
832348SN/A * tick() function for the CPU is defined here.
842348SN/A */
851060SN/Atemplate <class Impl>
862733Sktlim@umich.educlass FullO3CPU : public BaseO3CPU
871060SN/A{
881060SN/A  public:
892325SN/A    // Typedefs from the Impl here.
901060SN/A    typedef typename Impl::CPUPol CPUPolicy;
911061SN/A    typedef typename Impl::DynInstPtr DynInstPtr;
924329Sktlim@umich.edu    typedef typename Impl::O3CPU O3CPU;
931060SN/A
945595Sgblack@eecs.umich.edu    typedef O3ThreadState<Impl> ImplState;
952292SN/A    typedef O3ThreadState<Impl> Thread;
962292SN/A
972292SN/A    typedef typename std::list<DynInstPtr>::iterator ListIt;
982292SN/A
992817Sksewell@umich.edu    friend class O3ThreadContext<Impl>;
1002829Sksewell@umich.edu
1011060SN/A  public:
1021060SN/A    enum Status {
1031060SN/A        Running,
1041060SN/A        Idle,
1051060SN/A        Halted,
1062307SN/A        Blocked,
1072307SN/A        SwitchedOut
1081060SN/A    };
1091060SN/A
1106022Sgblack@eecs.umich.edu    TheISA::TLB * itb;
1116022Sgblack@eecs.umich.edu    TheISA::TLB * dtb;
1123781Sgblack@eecs.umich.edu
1132292SN/A    /** Overall CPU status. */
1141060SN/A    Status _status;
1151060SN/A
1162829Sksewell@umich.edu    /** Per-thread status in CPU, used for SMT.  */
1172829Sksewell@umich.edu    Status _threadStatus[Impl::MaxThreads];
1182829Sksewell@umich.edu
1191060SN/A  private:
1201060SN/A    class TickEvent : public Event
1211060SN/A    {
1221060SN/A      private:
1232292SN/A        /** Pointer to the CPU. */
1241755SN/A        FullO3CPU<Impl> *cpu;
1251060SN/A
1261060SN/A      public:
1272292SN/A        /** Constructs a tick event. */
1281755SN/A        TickEvent(FullO3CPU<Impl> *c);
1292292SN/A
1302292SN/A        /** Processes a tick event, calling tick() on the CPU. */
1311060SN/A        void process();
1322292SN/A        /** Returns the description of the tick event. */
1335336Shines@cs.fsu.edu        const char *description() const;
1341060SN/A    };
1351060SN/A
1362292SN/A    /** The tick event used for scheduling CPU ticks. */
1371060SN/A    TickEvent tickEvent;
1381060SN/A
1392292SN/A    /** Schedule tick event, regardless of its current state. */
1401060SN/A    void scheduleTickEvent(int delay)
1411060SN/A    {
1421060SN/A        if (tickEvent.squashed())
1435606Snate@binkert.org            reschedule(tickEvent, nextCycle(curTick + ticks(delay)));
1441060SN/A        else if (!tickEvent.scheduled())
1455606Snate@binkert.org            schedule(tickEvent, nextCycle(curTick + ticks(delay)));
1461060SN/A    }
1471060SN/A
1482292SN/A    /** Unschedule tick event, regardless of its current state. */
1491060SN/A    void unscheduleTickEvent()
1501060SN/A    {
1511060SN/A        if (tickEvent.scheduled())
1521060SN/A            tickEvent.squash();
1531060SN/A    }
1541060SN/A
1552829Sksewell@umich.edu    class ActivateThreadEvent : public Event
1562829Sksewell@umich.edu    {
1572829Sksewell@umich.edu      private:
1582829Sksewell@umich.edu        /** Number of Thread to Activate */
1596221Snate@binkert.org        ThreadID tid;
1602829Sksewell@umich.edu
1612829Sksewell@umich.edu        /** Pointer to the CPU. */
1622829Sksewell@umich.edu        FullO3CPU<Impl> *cpu;
1632829Sksewell@umich.edu
1642829Sksewell@umich.edu      public:
1652829Sksewell@umich.edu        /** Constructs the event. */
1662829Sksewell@umich.edu        ActivateThreadEvent();
1672829Sksewell@umich.edu
1682829Sksewell@umich.edu        /** Initialize Event */
1692829Sksewell@umich.edu        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
1702829Sksewell@umich.edu
1712829Sksewell@umich.edu        /** Processes the event, calling activateThread() on the CPU. */
1722829Sksewell@umich.edu        void process();
1732829Sksewell@umich.edu
1742829Sksewell@umich.edu        /** Returns the description of the event. */
1755336Shines@cs.fsu.edu        const char *description() const;
1762829Sksewell@umich.edu    };
1772829Sksewell@umich.edu
1782829Sksewell@umich.edu    /** Schedule thread to activate , regardless of its current state. */
1796221Snate@binkert.org    void
1806221Snate@binkert.org    scheduleActivateThreadEvent(ThreadID tid, int delay)
1812829Sksewell@umich.edu    {
1822829Sksewell@umich.edu        // Schedule thread to activate, regardless of its current state.
1832829Sksewell@umich.edu        if (activateThreadEvent[tid].squashed())
1845606Snate@binkert.org            reschedule(activateThreadEvent[tid],
1855606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
1862829Sksewell@umich.edu        else if (!activateThreadEvent[tid].scheduled())
1875606Snate@binkert.org            schedule(activateThreadEvent[tid],
1885606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
1892829Sksewell@umich.edu    }
1902829Sksewell@umich.edu
1912829Sksewell@umich.edu    /** Unschedule actiavte thread event, regardless of its current state. */
1926221Snate@binkert.org    void
1936221Snate@binkert.org    unscheduleActivateThreadEvent(ThreadID tid)
1942829Sksewell@umich.edu    {
1952829Sksewell@umich.edu        if (activateThreadEvent[tid].scheduled())
1962829Sksewell@umich.edu            activateThreadEvent[tid].squash();
1972829Sksewell@umich.edu    }
1982829Sksewell@umich.edu
1992829Sksewell@umich.edu    /** The tick event used for scheduling CPU ticks. */
2002829Sksewell@umich.edu    ActivateThreadEvent activateThreadEvent[Impl::MaxThreads];
2012829Sksewell@umich.edu
2022875Sksewell@umich.edu    class DeallocateContextEvent : public Event
2032875Sksewell@umich.edu    {
2042875Sksewell@umich.edu      private:
2053221Sktlim@umich.edu        /** Number of Thread to deactivate */
2066221Snate@binkert.org        ThreadID tid;
2072875Sksewell@umich.edu
2083221Sktlim@umich.edu        /** Should the thread be removed from the CPU? */
2093221Sktlim@umich.edu        bool remove;
2103221Sktlim@umich.edu
2112875Sksewell@umich.edu        /** Pointer to the CPU. */
2122875Sksewell@umich.edu        FullO3CPU<Impl> *cpu;
2132875Sksewell@umich.edu
2142875Sksewell@umich.edu      public:
2152875Sksewell@umich.edu        /** Constructs the event. */
2162875Sksewell@umich.edu        DeallocateContextEvent();
2172875Sksewell@umich.edu
2182875Sksewell@umich.edu        /** Initialize Event */
2192875Sksewell@umich.edu        void init(int thread_num, FullO3CPU<Impl> *thread_cpu);
2202875Sksewell@umich.edu
2212875Sksewell@umich.edu        /** Processes the event, calling activateThread() on the CPU. */
2222875Sksewell@umich.edu        void process();
2232875Sksewell@umich.edu
2243221Sktlim@umich.edu        /** Sets whether the thread should also be removed from the CPU. */
2253221Sktlim@umich.edu        void setRemove(bool _remove) { remove = _remove; }
2263221Sktlim@umich.edu
2272875Sksewell@umich.edu        /** Returns the description of the event. */
2285336Shines@cs.fsu.edu        const char *description() const;
2292875Sksewell@umich.edu    };
2302875Sksewell@umich.edu
2312875Sksewell@umich.edu    /** Schedule cpu to deallocate thread context.*/
2326221Snate@binkert.org    void
2336221Snate@binkert.org    scheduleDeallocateContextEvent(ThreadID tid, bool remove, int delay)
2342875Sksewell@umich.edu    {
2352875Sksewell@umich.edu        // Schedule thread to activate, regardless of its current state.
2362875Sksewell@umich.edu        if (deallocateContextEvent[tid].squashed())
2375606Snate@binkert.org            reschedule(deallocateContextEvent[tid],
2385606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
2392875Sksewell@umich.edu        else if (!deallocateContextEvent[tid].scheduled())
2405606Snate@binkert.org            schedule(deallocateContextEvent[tid],
2415606Snate@binkert.org                nextCycle(curTick + ticks(delay)));
2422875Sksewell@umich.edu    }
2432875Sksewell@umich.edu
2442875Sksewell@umich.edu    /** Unschedule thread deallocation in CPU */
2456221Snate@binkert.org    void
2466221Snate@binkert.org    unscheduleDeallocateContextEvent(ThreadID tid)
2472875Sksewell@umich.edu    {
2482875Sksewell@umich.edu        if (deallocateContextEvent[tid].scheduled())
2492875Sksewell@umich.edu            deallocateContextEvent[tid].squash();
2502875Sksewell@umich.edu    }
2512875Sksewell@umich.edu
2522875Sksewell@umich.edu    /** The tick event used for scheduling CPU ticks. */
2532875Sksewell@umich.edu    DeallocateContextEvent deallocateContextEvent[Impl::MaxThreads];
2542875Sksewell@umich.edu
2551060SN/A  public:
2562292SN/A    /** Constructs a CPU with the given parameters. */
2575595Sgblack@eecs.umich.edu    FullO3CPU(DerivO3CPUParams *params);
2582292SN/A    /** Destructor. */
2591755SN/A    ~FullO3CPU();
2601060SN/A
2612292SN/A    /** Registers statistics. */
2625595Sgblack@eecs.umich.edu    void regStats();
2631684SN/A
2645358Sgblack@eecs.umich.edu    void demapPage(Addr vaddr, uint64_t asn)
2655358Sgblack@eecs.umich.edu    {
2665358Sgblack@eecs.umich.edu        this->itb->demapPage(vaddr, asn);
2675358Sgblack@eecs.umich.edu        this->dtb->demapPage(vaddr, asn);
2685358Sgblack@eecs.umich.edu    }
2695358Sgblack@eecs.umich.edu
2705358Sgblack@eecs.umich.edu    void demapInstPage(Addr vaddr, uint64_t asn)
2715358Sgblack@eecs.umich.edu    {
2725358Sgblack@eecs.umich.edu        this->itb->demapPage(vaddr, asn);
2735358Sgblack@eecs.umich.edu    }
2745358Sgblack@eecs.umich.edu
2755358Sgblack@eecs.umich.edu    void demapDataPage(Addr vaddr, uint64_t asn)
2765358Sgblack@eecs.umich.edu    {
2775358Sgblack@eecs.umich.edu        this->dtb->demapPage(vaddr, asn);
2785358Sgblack@eecs.umich.edu    }
2795358Sgblack@eecs.umich.edu
2802871Sktlim@umich.edu    /** Returns a specific port. */
2812871Sktlim@umich.edu    Port *getPort(const std::string &if_name, int idx);
2822871Sktlim@umich.edu
2832292SN/A    /** Ticks CPU, calling tick() on each stage, and checking the overall
2842292SN/A     *  activity to see if the CPU should deschedule itself.
2852292SN/A     */
2861684SN/A    void tick();
2871684SN/A
2882292SN/A    /** Initialize the CPU */
2891060SN/A    void init();
2901060SN/A
2912834Sksewell@umich.edu    /** Returns the Number of Active Threads in the CPU */
2922834Sksewell@umich.edu    int numActiveThreads()
2932834Sksewell@umich.edu    { return activeThreads.size(); }
2942834Sksewell@umich.edu
2952829Sksewell@umich.edu    /** Add Thread to Active Threads List */
2966221Snate@binkert.org    void activateThread(ThreadID tid);
2972875Sksewell@umich.edu
2982875Sksewell@umich.edu    /** Remove Thread from Active Threads List */
2996221Snate@binkert.org    void deactivateThread(ThreadID tid);
3002829Sksewell@umich.edu
3012292SN/A    /** Setup CPU to insert a thread's context */
3026221Snate@binkert.org    void insertThread(ThreadID tid);
3031060SN/A
3042292SN/A    /** Remove all of a thread's context from CPU */
3056221Snate@binkert.org    void removeThread(ThreadID tid);
3062292SN/A
3072292SN/A    /** Count the Total Instructions Committed in the CPU. */
3086221Snate@binkert.org    virtual Counter totalInstructions() const;
3092292SN/A
3102292SN/A    /** Add Thread to Active Threads List. */
3116221Snate@binkert.org    void activateContext(ThreadID tid, int delay);
3122292SN/A
3132292SN/A    /** Remove Thread from Active Threads List */
3146221Snate@binkert.org    void suspendContext(ThreadID tid);
3152292SN/A
3162292SN/A    /** Remove Thread from Active Threads List &&
3173221Sktlim@umich.edu     *  Possibly Remove Thread Context from CPU.
3182292SN/A     */
3196221Snate@binkert.org    bool deallocateContext(ThreadID tid, bool remove, int delay = 1);
3202292SN/A
3212292SN/A    /** Remove Thread from Active Threads List &&
3222292SN/A     *  Remove Thread Context from CPU.
3232292SN/A     */
3246221Snate@binkert.org    void haltContext(ThreadID tid);
3252292SN/A
3262292SN/A    /** Activate a Thread When CPU Resources are Available. */
3276221Snate@binkert.org    void activateWhenReady(ThreadID tid);
3282292SN/A
3292292SN/A    /** Add or Remove a Thread Context in the CPU. */
3302292SN/A    void doContextSwitch();
3312292SN/A
3322292SN/A    /** Update The Order In Which We Process Threads. */
3332292SN/A    void updateThreadPriority();
3342292SN/A
3352864Sktlim@umich.edu    /** Serialize state. */
3362864Sktlim@umich.edu    virtual void serialize(std::ostream &os);
3372864Sktlim@umich.edu
3382864Sktlim@umich.edu    /** Unserialize from a checkpoint. */
3392864Sktlim@umich.edu    virtual void unserialize(Checkpoint *cp, const std::string &section);
3402864Sktlim@umich.edu
3412864Sktlim@umich.edu  public:
3425595Sgblack@eecs.umich.edu#if !FULL_SYSTEM
3435595Sgblack@eecs.umich.edu    /** Executes a syscall.
3445595Sgblack@eecs.umich.edu     * @todo: Determine if this needs to be virtual.
3452292SN/A     */
3466221Snate@binkert.org    void syscall(int64_t callnum, ThreadID tid);
3475595Sgblack@eecs.umich.edu#endif
3482292SN/A
3492843Sktlim@umich.edu    /** Starts draining the CPU's pipeline of all instructions in
3502843Sktlim@umich.edu     * order to stop all memory accesses. */
3512905Sktlim@umich.edu    virtual unsigned int drain(Event *drain_event);
3522843Sktlim@umich.edu
3532843Sktlim@umich.edu    /** Resumes execution after a drain. */
3542843Sktlim@umich.edu    virtual void resume();
3552292SN/A
3562348SN/A    /** Signals to this CPU that a stage has completed switching out. */
3572843Sktlim@umich.edu    void signalDrained();
3582843Sktlim@umich.edu
3592843Sktlim@umich.edu    /** Switches out this CPU. */
3602843Sktlim@umich.edu    virtual void switchOut();
3612316SN/A
3622348SN/A    /** Takes over from another CPU. */
3632843Sktlim@umich.edu    virtual void takeOverFrom(BaseCPU *oldCPU);
3641060SN/A
3651060SN/A    /** Get the current instruction sequence number, and increment it. */
3662316SN/A    InstSeqNum getAndIncrementInstSeq()
3672316SN/A    { return globalSeqNum++; }
3681060SN/A
3695595Sgblack@eecs.umich.edu    /** Traps to handle given fault. */
3707684Sgblack@eecs.umich.edu    void trap(Fault fault, ThreadID tid, StaticInstPtr inst);
3715595Sgblack@eecs.umich.edu
3721858SN/A#if FULL_SYSTEM
3735702Ssaidi@eecs.umich.edu    /** HW return from error interrupt. */
3746221Snate@binkert.org    Fault hwrei(ThreadID tid);
3755702Ssaidi@eecs.umich.edu
3766221Snate@binkert.org    bool simPalCheck(int palFunc, ThreadID tid);
3775702Ssaidi@eecs.umich.edu
3785595Sgblack@eecs.umich.edu    /** Returns the Fault for any valid interrupt. */
3795595Sgblack@eecs.umich.edu    Fault getInterrupts();
3805595Sgblack@eecs.umich.edu
3815595Sgblack@eecs.umich.edu    /** Processes any an interrupt fault. */
3825595Sgblack@eecs.umich.edu    void processInterrupts(Fault interrupt);
3835595Sgblack@eecs.umich.edu
3845595Sgblack@eecs.umich.edu    /** Halts the CPU. */
3855595Sgblack@eecs.umich.edu    void halt() { panic("Halt not implemented!\n"); }
3865595Sgblack@eecs.umich.edu
3874192Sktlim@umich.edu    /** Update the Virt and Phys ports of all ThreadContexts to
3884192Sktlim@umich.edu     * reflect change in memory connections. */
3894192Sktlim@umich.edu    void updateMemPorts();
3904192Sktlim@umich.edu
3911060SN/A    /** Check if this address is a valid instruction address. */
3921060SN/A    bool validInstAddr(Addr addr) { return true; }
3931060SN/A
3941060SN/A    /** Check if this address is a valid data address. */
3951060SN/A    bool validDataAddr(Addr addr) { return true; }
3961060SN/A#endif
3971060SN/A
3982348SN/A    /** Register accessors.  Index refers to the physical register index. */
3995595Sgblack@eecs.umich.edu
4005595Sgblack@eecs.umich.edu    /** Reads a miscellaneous register. */
4016221Snate@binkert.org    TheISA::MiscReg readMiscRegNoEffect(int misc_reg, ThreadID tid);
4025595Sgblack@eecs.umich.edu
4035595Sgblack@eecs.umich.edu    /** Reads a misc. register, including any side effects the read
4045595Sgblack@eecs.umich.edu     * might have as defined by the architecture.
4055595Sgblack@eecs.umich.edu     */
4066221Snate@binkert.org    TheISA::MiscReg readMiscReg(int misc_reg, ThreadID tid);
4075595Sgblack@eecs.umich.edu
4085595Sgblack@eecs.umich.edu    /** Sets a miscellaneous register. */
4096221Snate@binkert.org    void setMiscRegNoEffect(int misc_reg, const TheISA::MiscReg &val,
4106221Snate@binkert.org            ThreadID tid);
4115595Sgblack@eecs.umich.edu
4125595Sgblack@eecs.umich.edu    /** Sets a misc. register, including any side effects the write
4135595Sgblack@eecs.umich.edu     * might have as defined by the architecture.
4145595Sgblack@eecs.umich.edu     */
4155595Sgblack@eecs.umich.edu    void setMiscReg(int misc_reg, const TheISA::MiscReg &val,
4166221Snate@binkert.org            ThreadID tid);
4175595Sgblack@eecs.umich.edu
4181060SN/A    uint64_t readIntReg(int reg_idx);
4191060SN/A
4203781Sgblack@eecs.umich.edu    TheISA::FloatReg readFloatReg(int reg_idx);
4211060SN/A
4223781Sgblack@eecs.umich.edu    TheISA::FloatRegBits readFloatRegBits(int reg_idx);
4232455SN/A
4241060SN/A    void setIntReg(int reg_idx, uint64_t val);
4251060SN/A
4263781Sgblack@eecs.umich.edu    void setFloatReg(int reg_idx, TheISA::FloatReg val);
4271060SN/A
4283781Sgblack@eecs.umich.edu    void setFloatRegBits(int reg_idx, TheISA::FloatRegBits val);
4292455SN/A
4306221Snate@binkert.org    uint64_t readArchIntReg(int reg_idx, ThreadID tid);
4311060SN/A
4326314Sgblack@eecs.umich.edu    float readArchFloatReg(int reg_idx, ThreadID tid);
4332292SN/A
4346221Snate@binkert.org    uint64_t readArchFloatRegInt(int reg_idx, ThreadID tid);
4352292SN/A
4362348SN/A    /** Architectural register accessors.  Looks up in the commit
4372348SN/A     * rename table to obtain the true physical index of the
4382348SN/A     * architected register first, then accesses that physical
4392348SN/A     * register.
4402348SN/A     */
4416221Snate@binkert.org    void setArchIntReg(int reg_idx, uint64_t val, ThreadID tid);
4422292SN/A
4436314Sgblack@eecs.umich.edu    void setArchFloatReg(int reg_idx, float val, ThreadID tid);
4442292SN/A
4456221Snate@binkert.org    void setArchFloatRegInt(int reg_idx, uint64_t val, ThreadID tid);
4462292SN/A
4472348SN/A    /** Reads the commit PC of a specific thread. */
4486221Snate@binkert.org    Addr readPC(ThreadID tid);
4492292SN/A
4502348SN/A    /** Sets the commit PC of a specific thread. */
4516221Snate@binkert.org    void setPC(Addr new_PC, ThreadID tid);
4522292SN/A
4534636Sgblack@eecs.umich.edu    /** Reads the commit micro PC of a specific thread. */
4546221Snate@binkert.org    Addr readMicroPC(ThreadID tid);
4554636Sgblack@eecs.umich.edu
4564636Sgblack@eecs.umich.edu    /** Sets the commmit micro PC of a specific thread. */
4576221Snate@binkert.org    void setMicroPC(Addr new_microPC, ThreadID tid);
4584636Sgblack@eecs.umich.edu
4592348SN/A    /** Reads the next PC of a specific thread. */
4606221Snate@binkert.org    Addr readNextPC(ThreadID tid);
4612292SN/A
4622348SN/A    /** Sets the next PC of a specific thread. */
4636221Snate@binkert.org    void setNextPC(Addr val, ThreadID tid);
4641060SN/A
4652756Sksewell@umich.edu    /** Reads the next NPC of a specific thread. */
4666221Snate@binkert.org    Addr readNextNPC(ThreadID tid);
4672756Sksewell@umich.edu
4682756Sksewell@umich.edu    /** Sets the next NPC of a specific thread. */
4696221Snate@binkert.org    void setNextNPC(Addr val, ThreadID tid);
4704636Sgblack@eecs.umich.edu
4714636Sgblack@eecs.umich.edu    /** Reads the commit next micro PC of a specific thread. */
4726221Snate@binkert.org    Addr readNextMicroPC(ThreadID tid);
4734636Sgblack@eecs.umich.edu
4744636Sgblack@eecs.umich.edu    /** Sets the commit next micro PC of a specific thread. */
4756221Snate@binkert.org    void setNextMicroPC(Addr val, ThreadID tid);
4762756Sksewell@umich.edu
4775595Sgblack@eecs.umich.edu    /** Initiates a squash of all in-flight instructions for a given
4785595Sgblack@eecs.umich.edu     * thread.  The source of the squash is an external update of
4795595Sgblack@eecs.umich.edu     * state through the TC.
4805595Sgblack@eecs.umich.edu     */
4816221Snate@binkert.org    void squashFromTC(ThreadID tid);
4825595Sgblack@eecs.umich.edu
4831060SN/A    /** Function to add instruction onto the head of the list of the
4841060SN/A     *  instructions.  Used when new instructions are fetched.
4851060SN/A     */
4862292SN/A    ListIt addInst(DynInstPtr &inst);
4871060SN/A
4881060SN/A    /** Function to tell the CPU that an instruction has completed. */
4896221Snate@binkert.org    void instDone(ThreadID tid);
4901060SN/A
4912292SN/A    /** Add Instructions to the CPU Remove List*/
4922292SN/A    void addToRemoveList(DynInstPtr &inst);
4931060SN/A
4942325SN/A    /** Remove an instruction from the front end of the list.  There's
4952325SN/A     *  no restriction on location of the instruction.
4961060SN/A     */
4971061SN/A    void removeFrontInst(DynInstPtr &inst);
4981060SN/A
4992935Sksewell@umich.edu    /** Remove all instructions that are not currently in the ROB.
5002935Sksewell@umich.edu     *  There's also an option to not squash delay slot instructions.*/
5016221Snate@binkert.org    void removeInstsNotInROB(ThreadID tid);
5021060SN/A
5031062SN/A    /** Remove all instructions younger than the given sequence number. */
5046221Snate@binkert.org    void removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid);
5052292SN/A
5062348SN/A    /** Removes the instruction pointed to by the iterator. */
5076221Snate@binkert.org    inline void squashInstIt(const ListIt &instIt, ThreadID tid);
5082292SN/A
5092348SN/A    /** Cleans up all instructions on the remove list. */
5102292SN/A    void cleanUpRemovedInsts();
5111062SN/A
5122348SN/A    /** Debug function to print all instructions on the list. */
5131060SN/A    void dumpInsts();
5141060SN/A
5151060SN/A  public:
5165737Scws3k@cs.virginia.edu#ifndef NDEBUG
5175737Scws3k@cs.virginia.edu    /** Count of total number of dynamic instructions in flight. */
5185737Scws3k@cs.virginia.edu    int instcount;
5195737Scws3k@cs.virginia.edu#endif
5205737Scws3k@cs.virginia.edu
5211060SN/A    /** List of all the instructions in flight. */
5222292SN/A    std::list<DynInstPtr> instList;
5231060SN/A
5242292SN/A    /** List of all the instructions that will be removed at the end of this
5252292SN/A     *  cycle.
5262292SN/A     */
5272292SN/A    std::queue<ListIt> removeList;
5282292SN/A
5292325SN/A#ifdef DEBUG
5302348SN/A    /** Debug structure to keep track of the sequence numbers still in
5312348SN/A     * flight.
5322348SN/A     */
5332292SN/A    std::set<InstSeqNum> snList;
5342325SN/A#endif
5352292SN/A
5362325SN/A    /** Records if instructions need to be removed this cycle due to
5372325SN/A     *  being retired or squashed.
5382292SN/A     */
5392292SN/A    bool removeInstsThisCycle;
5402292SN/A
5411060SN/A  protected:
5421060SN/A    /** The fetch stage. */
5431060SN/A    typename CPUPolicy::Fetch fetch;
5441060SN/A
5451060SN/A    /** The decode stage. */
5461060SN/A    typename CPUPolicy::Decode decode;
5471060SN/A
5481060SN/A    /** The dispatch stage. */
5491060SN/A    typename CPUPolicy::Rename rename;
5501060SN/A
5511060SN/A    /** The issue/execute/writeback stages. */
5521060SN/A    typename CPUPolicy::IEW iew;
5531060SN/A
5541060SN/A    /** The commit stage. */
5551060SN/A    typename CPUPolicy::Commit commit;
5561060SN/A
5571060SN/A    /** The register file. */
5581060SN/A    typename CPUPolicy::RegFile regFile;
5591060SN/A
5601060SN/A    /** The free list. */
5611060SN/A    typename CPUPolicy::FreeList freeList;
5621060SN/A
5631060SN/A    /** The rename map. */
5642292SN/A    typename CPUPolicy::RenameMap renameMap[Impl::MaxThreads];
5652292SN/A
5662292SN/A    /** The commit rename map. */
5672292SN/A    typename CPUPolicy::RenameMap commitRenameMap[Impl::MaxThreads];
5681060SN/A
5691060SN/A    /** The re-order buffer. */
5701060SN/A    typename CPUPolicy::ROB rob;
5711060SN/A
5722292SN/A    /** Active Threads List */
5736221Snate@binkert.org    std::list<ThreadID> activeThreads;
5742292SN/A
5752292SN/A    /** Integer Register Scoreboard */
5762292SN/A    Scoreboard scoreboard;
5772292SN/A
5786313Sgblack@eecs.umich.edu    TheISA::ISA isa[Impl::MaxThreads];
5796313Sgblack@eecs.umich.edu
5801060SN/A  public:
5812292SN/A    /** Enum to give each stage a specific index, so when calling
5822292SN/A     *  activateStage() or deactivateStage(), they can specify which stage
5832292SN/A     *  is being activated/deactivated.
5842292SN/A     */
5852292SN/A    enum StageIdx {
5862292SN/A        FetchIdx,
5872292SN/A        DecodeIdx,
5882292SN/A        RenameIdx,
5892292SN/A        IEWIdx,
5902292SN/A        CommitIdx,
5912292SN/A        NumStages };
5922292SN/A
5931060SN/A    /** Typedefs from the Impl to get the structs that each of the
5941060SN/A     *  time buffers should use.
5951060SN/A     */
5961061SN/A    typedef typename CPUPolicy::TimeStruct TimeStruct;
5971060SN/A
5981061SN/A    typedef typename CPUPolicy::FetchStruct FetchStruct;
5991060SN/A
6001061SN/A    typedef typename CPUPolicy::DecodeStruct DecodeStruct;
6011060SN/A
6021061SN/A    typedef typename CPUPolicy::RenameStruct RenameStruct;
6031060SN/A
6041061SN/A    typedef typename CPUPolicy::IEWStruct IEWStruct;
6051060SN/A
6061060SN/A    /** The main time buffer to do backwards communication. */
6071060SN/A    TimeBuffer<TimeStruct> timeBuffer;
6081060SN/A
6091060SN/A    /** The fetch stage's instruction queue. */
6101060SN/A    TimeBuffer<FetchStruct> fetchQueue;
6111060SN/A
6121060SN/A    /** The decode stage's instruction queue. */
6131060SN/A    TimeBuffer<DecodeStruct> decodeQueue;
6141060SN/A
6151060SN/A    /** The rename stage's instruction queue. */
6161060SN/A    TimeBuffer<RenameStruct> renameQueue;
6171060SN/A
6181060SN/A    /** The IEW stage's instruction queue. */
6191060SN/A    TimeBuffer<IEWStruct> iewQueue;
6201060SN/A
6212348SN/A  private:
6222348SN/A    /** The activity recorder; used to tell if the CPU has any
6232348SN/A     * activity remaining or if it can go to idle and deschedule
6242348SN/A     * itself.
6252348SN/A     */
6262325SN/A    ActivityRecorder activityRec;
6271060SN/A
6282348SN/A  public:
6292348SN/A    /** Records that there was time buffer activity this cycle. */
6302325SN/A    void activityThisCycle() { activityRec.activity(); }
6312292SN/A
6322348SN/A    /** Changes a stage's status to active within the activity recorder. */
6332325SN/A    void activateStage(const StageIdx idx)
6342325SN/A    { activityRec.activateStage(idx); }
6352292SN/A
6362348SN/A    /** Changes a stage's status to inactive within the activity recorder. */
6372325SN/A    void deactivateStage(const StageIdx idx)
6382325SN/A    { activityRec.deactivateStage(idx); }
6392292SN/A
6402292SN/A    /** Wakes the CPU, rescheduling the CPU if it's not already active. */
6412292SN/A    void wakeCPU();
6422260SN/A
6435807Snate@binkert.org#if FULL_SYSTEM
6445807Snate@binkert.org    virtual void wakeup();
6455807Snate@binkert.org#endif
6465807Snate@binkert.org
6472292SN/A    /** Gets a free thread id. Use if thread ids change across system. */
6486221Snate@binkert.org    ThreadID getFreeTid();
6492292SN/A
6502292SN/A  public:
6512680Sktlim@umich.edu    /** Returns a pointer to a thread context. */
6526221Snate@binkert.org    ThreadContext *
6536221Snate@binkert.org    tcBase(ThreadID tid)
6541681SN/A    {
6552680Sktlim@umich.edu        return thread[tid]->getTC();
6562190SN/A    }
6572190SN/A
6582292SN/A    /** The global sequence number counter. */
6593093Sksewell@umich.edu    InstSeqNum globalSeqNum;//[Impl::MaxThreads];
6601060SN/A
6614598Sbinkertn@umich.edu#if USE_CHECKER
6622348SN/A    /** Pointer to the checker, which can dynamically verify
6632348SN/A     * instruction results at run time.  This can be set to NULL if it
6642348SN/A     * is not being used.
6652348SN/A     */
6662316SN/A    Checker<DynInstPtr> *checker;
6674598Sbinkertn@umich.edu#endif
6682316SN/A
6691858SN/A#if FULL_SYSTEM
6702292SN/A    /** Pointer to the system. */
6711060SN/A    System *system;
6722292SN/A#endif
6731060SN/A
6742843Sktlim@umich.edu    /** Event to call process() on once draining has completed. */
6752843Sktlim@umich.edu    Event *drainEvent;
6762843Sktlim@umich.edu
6772843Sktlim@umich.edu    /** Counter of how many stages have completed draining. */
6782843Sktlim@umich.edu    int drainCount;
6792316SN/A
6802348SN/A    /** Pointers to all of the threads in the CPU. */
6812292SN/A    std::vector<Thread *> thread;
6822260SN/A
6832292SN/A    /** Whether or not the CPU should defer its registration. */
6841060SN/A    bool deferRegistration;
6851060SN/A
6862292SN/A    /** Is there a context switch pending? */
6872292SN/A    bool contextSwitch;
6881060SN/A
6892292SN/A    /** Threads Scheduled to Enter CPU */
6902292SN/A    std::list<int> cpuWaitList;
6912292SN/A
6922292SN/A    /** The cycle that the CPU was last running, used for statistics. */
6932292SN/A    Tick lastRunningCycle;
6942292SN/A
6952829Sksewell@umich.edu    /** The cycle that the CPU was last activated by a new thread*/
6962829Sksewell@umich.edu    Tick lastActivatedCycle;
6972829Sksewell@umich.edu
6982292SN/A    /** Mapping for system thread id to cpu id */
6996221Snate@binkert.org    std::map<ThreadID, unsigned> threadMap;
7002292SN/A
7012292SN/A    /** Available thread ids in the cpu*/
7026221Snate@binkert.org    std::vector<ThreadID> tids;
7032292SN/A
7045595Sgblack@eecs.umich.edu    /** CPU read function, forwards read to LSQ. */
7056974Stjones1@inf.ed.ac.uk    Fault read(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh,
7067520Sgblack@eecs.umich.edu               uint8_t *data, int load_idx)
7075595Sgblack@eecs.umich.edu    {
7086974Stjones1@inf.ed.ac.uk        return this->iew.ldstQueue.read(req, sreqLow, sreqHigh,
7096974Stjones1@inf.ed.ac.uk                                        data, load_idx);
7105595Sgblack@eecs.umich.edu    }
7115595Sgblack@eecs.umich.edu
7125595Sgblack@eecs.umich.edu    /** CPU write function, forwards write to LSQ. */
7136974Stjones1@inf.ed.ac.uk    Fault write(RequestPtr &req, RequestPtr &sreqLow, RequestPtr &sreqHigh,
7147520Sgblack@eecs.umich.edu                uint8_t *data, int store_idx)
7155595Sgblack@eecs.umich.edu    {
7166974Stjones1@inf.ed.ac.uk        return this->iew.ldstQueue.write(req, sreqLow, sreqHigh,
7176974Stjones1@inf.ed.ac.uk                                         data, store_idx);
7185595Sgblack@eecs.umich.edu    }
7195595Sgblack@eecs.umich.edu
7206974Stjones1@inf.ed.ac.uk    /** Get the dcache port (used to find block size for translations). */
7216974Stjones1@inf.ed.ac.uk    Port *getDcachePort() { return this->iew.ldstQueue.getDcachePort(); }
7226974Stjones1@inf.ed.ac.uk
7235595Sgblack@eecs.umich.edu    Addr lockAddr;
7245595Sgblack@eecs.umich.edu
7255595Sgblack@eecs.umich.edu    /** Temporary fix for the lock flag, works in the UP case. */
7265595Sgblack@eecs.umich.edu    bool lockFlag;
7275595Sgblack@eecs.umich.edu
7282292SN/A    /** Stat for total number of times the CPU is descheduled. */
7295999Snate@binkert.org    Stats::Scalar timesIdled;
7302292SN/A    /** Stat for total number of cycles the CPU spends descheduled. */
7315999Snate@binkert.org    Stats::Scalar idleCycles;
7322292SN/A    /** Stat for the number of committed instructions per thread. */
7335999Snate@binkert.org    Stats::Vector committedInsts;
7342292SN/A    /** Stat for the total number of committed instructions. */
7355999Snate@binkert.org    Stats::Scalar totalCommittedInsts;
7362292SN/A    /** Stat for the CPI per thread. */
7372292SN/A    Stats::Formula cpi;
7382292SN/A    /** Stat for the total CPI. */
7392292SN/A    Stats::Formula totalCpi;
7402292SN/A    /** Stat for the IPC per thread. */
7412292SN/A    Stats::Formula ipc;
7422292SN/A    /** Stat for the total IPC. */
7432292SN/A    Stats::Formula totalIpc;
7441060SN/A};
7451060SN/A
7462325SN/A#endif // __CPU_O3_CPU_HH__
747