cpu.cc revision 8766
11689SN/A/*
22325SN/A * Copyright (c) 2004-2006 The Regents of The University of Michigan
37897Shestness@cs.utexas.edu * Copyright (c) 2011 Regents of the University of California
41689SN/A * All rights reserved.
51689SN/A *
61689SN/A * Redistribution and use in source and binary forms, with or without
71689SN/A * modification, are permitted provided that the following conditions are
81689SN/A * met: redistributions of source code must retain the above copyright
91689SN/A * notice, this list of conditions and the following disclaimer;
101689SN/A * redistributions in binary form must reproduce the above copyright
111689SN/A * notice, this list of conditions and the following disclaimer in the
121689SN/A * documentation and/or other materials provided with the distribution;
131689SN/A * neither the name of the copyright holders nor the names of its
141689SN/A * contributors may be used to endorse or promote products derived from
151689SN/A * this software without specific prior written permission.
161689SN/A *
171689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
282665Ssaidi@eecs.umich.edu *
292665Ssaidi@eecs.umich.edu * Authors: Kevin Lim
302756Sksewell@umich.edu *          Korey Sewell
317897Shestness@cs.utexas.edu *          Rick Strong
321689SN/A */
331689SN/A
341858SN/A#include "config/full_system.hh"
356658Snate@binkert.org#include "config/the_isa.hh"
362733Sktlim@umich.edu#include "config/use_checker.hh"
378229Snate@binkert.org#include "cpu/o3/cpu.hh"
388229Snate@binkert.org#include "cpu/o3/isa_specific.hh"
398229Snate@binkert.org#include "cpu/o3/thread_context.hh"
404762Snate@binkert.org#include "cpu/activity.hh"
414762Snate@binkert.org#include "cpu/simple_thread.hh"
424762Snate@binkert.org#include "cpu/thread_context.hh"
438232Snate@binkert.org#include "debug/Activity.hh"
448232Snate@binkert.org#include "debug/O3CPU.hh"
458232Snate@binkert.org#include "debug/Quiesce.hh"
464762Snate@binkert.org#include "enums/MemoryMode.hh"
474762Snate@binkert.org#include "sim/core.hh"
484762Snate@binkert.org#include "sim/stat_control.hh"
498460SAli.Saidi@ARM.com#include "sim/system.hh"
504762Snate@binkert.org
511858SN/A#if FULL_SYSTEM
522356SN/A#include "cpu/quiesce_event.hh"
531060SN/A#else
541060SN/A#include "sim/process.hh"
551060SN/A#endif
561060SN/A
572794Sktlim@umich.edu#if USE_CHECKER
582794Sktlim@umich.edu#include "cpu/checker/cpu.hh"
592794Sktlim@umich.edu#endif
602794Sktlim@umich.edu
615702Ssaidi@eecs.umich.edu#if THE_ISA == ALPHA_ISA
625702Ssaidi@eecs.umich.edu#include "arch/alpha/osfpal.hh"
638232Snate@binkert.org#include "debug/Activity.hh"
645702Ssaidi@eecs.umich.edu#endif
655702Ssaidi@eecs.umich.edu
665529Snate@binkert.orgclass BaseCPUParams;
675529Snate@binkert.org
682669Sktlim@umich.eduusing namespace TheISA;
696221Snate@binkert.orgusing namespace std;
701060SN/A
715529Snate@binkert.orgBaseO3CPU::BaseO3CPU(BaseCPUParams *params)
725712Shsul@eecs.umich.edu    : BaseCPU(params)
731060SN/A{
741060SN/A}
751060SN/A
762292SN/Avoid
772733Sktlim@umich.eduBaseO3CPU::regStats()
782292SN/A{
792292SN/A    BaseCPU::regStats();
802292SN/A}
812292SN/A
821060SN/Atemplate <class Impl>
831755SN/AFullO3CPU<Impl>::TickEvent::TickEvent(FullO3CPU<Impl> *c)
845606Snate@binkert.org    : Event(CPU_Tick_Pri), cpu(c)
851060SN/A{
861060SN/A}
871060SN/A
881060SN/Atemplate <class Impl>
891060SN/Avoid
901755SN/AFullO3CPU<Impl>::TickEvent::process()
911060SN/A{
921060SN/A    cpu->tick();
931060SN/A}
941060SN/A
951060SN/Atemplate <class Impl>
961060SN/Aconst char *
975336Shines@cs.fsu.eduFullO3CPU<Impl>::TickEvent::description() const
981060SN/A{
994873Sstever@eecs.umich.edu    return "FullO3CPU tick";
1001060SN/A}
1011060SN/A
1021060SN/Atemplate <class Impl>
1032829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::ActivateThreadEvent()
1045606Snate@binkert.org    : Event(CPU_Switch_Pri)
1052829Sksewell@umich.edu{
1062829Sksewell@umich.edu}
1072829Sksewell@umich.edu
1082829Sksewell@umich.edutemplate <class Impl>
1092829Sksewell@umich.eduvoid
1102829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::init(int thread_num,
1112829Sksewell@umich.edu                                           FullO3CPU<Impl> *thread_cpu)
1122829Sksewell@umich.edu{
1132829Sksewell@umich.edu    tid = thread_num;
1142829Sksewell@umich.edu    cpu = thread_cpu;
1152829Sksewell@umich.edu}
1162829Sksewell@umich.edu
1172829Sksewell@umich.edutemplate <class Impl>
1182829Sksewell@umich.eduvoid
1192829Sksewell@umich.eduFullO3CPU<Impl>::ActivateThreadEvent::process()
1202829Sksewell@umich.edu{
1212829Sksewell@umich.edu    cpu->activateThread(tid);
1222829Sksewell@umich.edu}
1232829Sksewell@umich.edu
1242829Sksewell@umich.edutemplate <class Impl>
1252829Sksewell@umich.educonst char *
1265336Shines@cs.fsu.eduFullO3CPU<Impl>::ActivateThreadEvent::description() const
1272829Sksewell@umich.edu{
1284873Sstever@eecs.umich.edu    return "FullO3CPU \"Activate Thread\"";
1292829Sksewell@umich.edu}
1302829Sksewell@umich.edu
1312829Sksewell@umich.edutemplate <class Impl>
1322875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::DeallocateContextEvent()
1335606Snate@binkert.org    : Event(CPU_Tick_Pri), tid(0), remove(false), cpu(NULL)
1342875Sksewell@umich.edu{
1352875Sksewell@umich.edu}
1362875Sksewell@umich.edu
1372875Sksewell@umich.edutemplate <class Impl>
1382875Sksewell@umich.eduvoid
1392875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::init(int thread_num,
1403859Sbinkertn@umich.edu                                              FullO3CPU<Impl> *thread_cpu)
1412875Sksewell@umich.edu{
1422875Sksewell@umich.edu    tid = thread_num;
1432875Sksewell@umich.edu    cpu = thread_cpu;
1443859Sbinkertn@umich.edu    remove = false;
1452875Sksewell@umich.edu}
1462875Sksewell@umich.edu
1472875Sksewell@umich.edutemplate <class Impl>
1482875Sksewell@umich.eduvoid
1492875Sksewell@umich.eduFullO3CPU<Impl>::DeallocateContextEvent::process()
1502875Sksewell@umich.edu{
1512875Sksewell@umich.edu    cpu->deactivateThread(tid);
1523221Sktlim@umich.edu    if (remove)
1533221Sktlim@umich.edu        cpu->removeThread(tid);
1542875Sksewell@umich.edu}
1552875Sksewell@umich.edu
1562875Sksewell@umich.edutemplate <class Impl>
1572875Sksewell@umich.educonst char *
1585336Shines@cs.fsu.eduFullO3CPU<Impl>::DeallocateContextEvent::description() const
1592875Sksewell@umich.edu{
1604873Sstever@eecs.umich.edu    return "FullO3CPU \"Deallocate Context\"";
1612875Sksewell@umich.edu}
1622875Sksewell@umich.edu
1632875Sksewell@umich.edutemplate <class Impl>
1645595Sgblack@eecs.umich.eduFullO3CPU<Impl>::FullO3CPU(DerivO3CPUParams *params)
1652733Sktlim@umich.edu    : BaseO3CPU(params),
1663781Sgblack@eecs.umich.edu      itb(params->itb),
1673781Sgblack@eecs.umich.edu      dtb(params->dtb),
1681060SN/A      tickEvent(this),
1695737Scws3k@cs.virginia.edu#ifndef NDEBUG
1705737Scws3k@cs.virginia.edu      instcount(0),
1715737Scws3k@cs.virginia.edu#endif
1722292SN/A      removeInstsThisCycle(false),
1735595Sgblack@eecs.umich.edu      fetch(this, params),
1745595Sgblack@eecs.umich.edu      decode(this, params),
1755595Sgblack@eecs.umich.edu      rename(this, params),
1765595Sgblack@eecs.umich.edu      iew(this, params),
1775595Sgblack@eecs.umich.edu      commit(this, params),
1781060SN/A
1795595Sgblack@eecs.umich.edu      regFile(this, params->numPhysIntRegs,
1804329Sktlim@umich.edu              params->numPhysFloatRegs),
1811060SN/A
1825529Snate@binkert.org      freeList(params->numThreads,
1832292SN/A               TheISA::NumIntRegs, params->numPhysIntRegs,
1842292SN/A               TheISA::NumFloatRegs, params->numPhysFloatRegs),
1851060SN/A
1865595Sgblack@eecs.umich.edu      rob(this,
1874329Sktlim@umich.edu          params->numROBEntries, params->squashWidth,
1882292SN/A          params->smtROBPolicy, params->smtROBThreshold,
1895529Snate@binkert.org          params->numThreads),
1901060SN/A
1915529Snate@binkert.org      scoreboard(params->numThreads,
1922292SN/A                 TheISA::NumIntRegs, params->numPhysIntRegs,
1932292SN/A                 TheISA::NumFloatRegs, params->numPhysFloatRegs,
1946221Snate@binkert.org                 TheISA::NumMiscRegs * numThreads,
1952292SN/A                 TheISA::ZeroReg),
1961060SN/A
1972873Sktlim@umich.edu      timeBuffer(params->backComSize, params->forwardComSize),
1982873Sktlim@umich.edu      fetchQueue(params->backComSize, params->forwardComSize),
1992873Sktlim@umich.edu      decodeQueue(params->backComSize, params->forwardComSize),
2002873Sktlim@umich.edu      renameQueue(params->backComSize, params->forwardComSize),
2012873Sktlim@umich.edu      iewQueue(params->backComSize, params->forwardComSize),
2025804Snate@binkert.org      activityRec(name(), NumStages,
2032873Sktlim@umich.edu                  params->backComSize + params->forwardComSize,
2042873Sktlim@umich.edu                  params->activity),
2051060SN/A
2061060SN/A      globalSeqNum(1),
2072292SN/A      system(params->system),
2082843Sktlim@umich.edu      drainCount(0),
2096221Snate@binkert.org      deferRegistration(params->defer_registration)
2101060SN/A{
2113221Sktlim@umich.edu    if (!deferRegistration) {
2123221Sktlim@umich.edu        _status = Running;
2133221Sktlim@umich.edu    } else {
2143221Sktlim@umich.edu        _status = Idle;
2153221Sktlim@umich.edu    }
2161681SN/A
2174598Sbinkertn@umich.edu#if USE_CHECKER
2182794Sktlim@umich.edu    if (params->checker) {
2192316SN/A        BaseCPU *temp_checker = params->checker;
2202316SN/A        checker = dynamic_cast<Checker<DynInstPtr> *>(temp_checker);
2212316SN/A#if FULL_SYSTEM
2222316SN/A        checker->setSystem(params->system);
2232316SN/A#endif
2244598Sbinkertn@umich.edu    } else {
2254598Sbinkertn@umich.edu        checker = NULL;
2264598Sbinkertn@umich.edu    }
2272794Sktlim@umich.edu#endif // USE_CHECKER
2282316SN/A
2291858SN/A#if !FULL_SYSTEM
2306221Snate@binkert.org    thread.resize(numThreads);
2316221Snate@binkert.org    tids.resize(numThreads);
2321681SN/A#endif
2331681SN/A
2342325SN/A    // The stages also need their CPU pointer setup.  However this
2352325SN/A    // must be done at the upper level CPU because they have pointers
2362325SN/A    // to the upper level CPU, and not this FullO3CPU.
2371060SN/A
2382292SN/A    // Set up Pointers to the activeThreads list for each stage
2392292SN/A    fetch.setActiveThreads(&activeThreads);
2402292SN/A    decode.setActiveThreads(&activeThreads);
2412292SN/A    rename.setActiveThreads(&activeThreads);
2422292SN/A    iew.setActiveThreads(&activeThreads);
2432292SN/A    commit.setActiveThreads(&activeThreads);
2441060SN/A
2451060SN/A    // Give each of the stages the time buffer they will use.
2461060SN/A    fetch.setTimeBuffer(&timeBuffer);
2471060SN/A    decode.setTimeBuffer(&timeBuffer);
2481060SN/A    rename.setTimeBuffer(&timeBuffer);
2491060SN/A    iew.setTimeBuffer(&timeBuffer);
2501060SN/A    commit.setTimeBuffer(&timeBuffer);
2511060SN/A
2521060SN/A    // Also setup each of the stages' queues.
2531060SN/A    fetch.setFetchQueue(&fetchQueue);
2541060SN/A    decode.setFetchQueue(&fetchQueue);
2552292SN/A    commit.setFetchQueue(&fetchQueue);
2561060SN/A    decode.setDecodeQueue(&decodeQueue);
2571060SN/A    rename.setDecodeQueue(&decodeQueue);
2581060SN/A    rename.setRenameQueue(&renameQueue);
2591060SN/A    iew.setRenameQueue(&renameQueue);
2601060SN/A    iew.setIEWQueue(&iewQueue);
2611060SN/A    commit.setIEWQueue(&iewQueue);
2621060SN/A    commit.setRenameQueue(&renameQueue);
2631060SN/A
2642292SN/A    commit.setIEWStage(&iew);
2652292SN/A    rename.setIEWStage(&iew);
2662292SN/A    rename.setCommitStage(&commit);
2672292SN/A
2682292SN/A#if !FULL_SYSTEM
2696221Snate@binkert.org    ThreadID active_threads = params->workload.size();
2702831Sksewell@umich.edu
2712831Sksewell@umich.edu    if (active_threads > Impl::MaxThreads) {
2722831Sksewell@umich.edu        panic("Workload Size too large. Increase the 'MaxThreads'"
2732831Sksewell@umich.edu              "constant in your O3CPU impl. file (e.g. o3/alpha/impl.hh) or "
2742831Sksewell@umich.edu              "edit your workload size.");
2752831Sksewell@umich.edu    }
2762292SN/A#else
2776221Snate@binkert.org    ThreadID active_threads = 1;
2782292SN/A#endif
2792292SN/A
2802316SN/A    //Make Sure That this a Valid Architeture
2812292SN/A    assert(params->numPhysIntRegs   >= numThreads * TheISA::NumIntRegs);
2822292SN/A    assert(params->numPhysFloatRegs >= numThreads * TheISA::NumFloatRegs);
2832292SN/A
2842292SN/A    rename.setScoreboard(&scoreboard);
2852292SN/A    iew.setScoreboard(&scoreboard);
2862292SN/A
2871060SN/A    // Setup the rename map for whichever stages need it.
2882292SN/A    PhysRegIndex lreg_idx = 0;
2892292SN/A    PhysRegIndex freg_idx = params->numPhysIntRegs; //Index to 1 after int regs
2901060SN/A
2916221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
2922307SN/A        bool bindRegs = (tid <= active_threads - 1);
2932292SN/A
2942292SN/A        commitRenameMap[tid].init(TheISA::NumIntRegs,
2952292SN/A                                  params->numPhysIntRegs,
2962325SN/A                                  lreg_idx,            //Index for Logical. Regs
2972292SN/A
2982292SN/A                                  TheISA::NumFloatRegs,
2992292SN/A                                  params->numPhysFloatRegs,
3002325SN/A                                  freg_idx,            //Index for Float Regs
3012292SN/A
3022292SN/A                                  TheISA::NumMiscRegs,
3032292SN/A
3042292SN/A                                  TheISA::ZeroReg,
3052292SN/A                                  TheISA::ZeroReg,
3062292SN/A
3072292SN/A                                  tid,
3082292SN/A                                  false);
3092292SN/A
3102292SN/A        renameMap[tid].init(TheISA::NumIntRegs,
3112292SN/A                            params->numPhysIntRegs,
3122325SN/A                            lreg_idx,                  //Index for Logical. Regs
3132292SN/A
3142292SN/A                            TheISA::NumFloatRegs,
3152292SN/A                            params->numPhysFloatRegs,
3162325SN/A                            freg_idx,                  //Index for Float Regs
3172292SN/A
3182292SN/A                            TheISA::NumMiscRegs,
3192292SN/A
3202292SN/A                            TheISA::ZeroReg,
3212292SN/A                            TheISA::ZeroReg,
3222292SN/A
3232292SN/A                            tid,
3242292SN/A                            bindRegs);
3253221Sktlim@umich.edu
3263221Sktlim@umich.edu        activateThreadEvent[tid].init(tid, this);
3273221Sktlim@umich.edu        deallocateContextEvent[tid].init(tid, this);
3282292SN/A    }
3292292SN/A
3302292SN/A    rename.setRenameMap(renameMap);
3312292SN/A    commit.setRenameMap(commitRenameMap);
3322292SN/A
3332292SN/A    // Give renameMap & rename stage access to the freeList;
3346221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
3356221Snate@binkert.org        renameMap[tid].setFreeList(&freeList);
3361060SN/A    rename.setFreeList(&freeList);
3372292SN/A
3381060SN/A    // Setup the ROB for whichever stages need it.
3391060SN/A    commit.setROB(&rob);
3402292SN/A
3417823Ssteve.reinhardt@amd.com    lastRunningCycle = curTick();
3422292SN/A
3432829Sksewell@umich.edu    lastActivatedCycle = -1;
3446221Snate@binkert.org#if 0
3453093Sksewell@umich.edu    // Give renameMap & rename stage access to the freeList;
3466221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++)
3476221Snate@binkert.org        globalSeqNum[tid] = 1;
3486221Snate@binkert.org#endif
3493093Sksewell@umich.edu
3502292SN/A    contextSwitch = false;
3515595Sgblack@eecs.umich.edu    DPRINTF(O3CPU, "Creating O3CPU object.\n");
3525595Sgblack@eecs.umich.edu
3535595Sgblack@eecs.umich.edu    // Setup any thread state.
3545595Sgblack@eecs.umich.edu    this->thread.resize(this->numThreads);
3555595Sgblack@eecs.umich.edu
3566221Snate@binkert.org    for (ThreadID tid = 0; tid < this->numThreads; ++tid) {
3575595Sgblack@eecs.umich.edu#if FULL_SYSTEM
3585595Sgblack@eecs.umich.edu        // SMT is not supported in FS mode yet.
3595595Sgblack@eecs.umich.edu        assert(this->numThreads == 1);
3608766Sgblack@eecs.umich.edu        this->thread[tid] = new Thread(this, 0, NULL);
3615595Sgblack@eecs.umich.edu#else
3626221Snate@binkert.org        if (tid < params->workload.size()) {
3635595Sgblack@eecs.umich.edu            DPRINTF(O3CPU, "Workload[%i] process is %#x",
3646221Snate@binkert.org                    tid, this->thread[tid]);
3656221Snate@binkert.org            this->thread[tid] = new typename FullO3CPU<Impl>::Thread(
3665595Sgblack@eecs.umich.edu                    (typename Impl::O3CPU *)(this),
3676331Sgblack@eecs.umich.edu                    tid, params->workload[tid]);
3685595Sgblack@eecs.umich.edu
3696221Snate@binkert.org            //usedTids[tid] = true;
3706221Snate@binkert.org            //threadMap[tid] = tid;
3715595Sgblack@eecs.umich.edu        } else {
3725595Sgblack@eecs.umich.edu            //Allocate Empty thread so M5 can use later
3735595Sgblack@eecs.umich.edu            //when scheduling threads to CPU
3745595Sgblack@eecs.umich.edu            Process* dummy_proc = NULL;
3755595Sgblack@eecs.umich.edu
3766221Snate@binkert.org            this->thread[tid] = new typename FullO3CPU<Impl>::Thread(
3775595Sgblack@eecs.umich.edu                    (typename Impl::O3CPU *)(this),
3786331Sgblack@eecs.umich.edu                    tid, dummy_proc);
3796221Snate@binkert.org            //usedTids[tid] = false;
3805595Sgblack@eecs.umich.edu        }
3815595Sgblack@eecs.umich.edu#endif // !FULL_SYSTEM
3825595Sgblack@eecs.umich.edu
3835595Sgblack@eecs.umich.edu        ThreadContext *tc;
3845595Sgblack@eecs.umich.edu
3855595Sgblack@eecs.umich.edu        // Setup the TC that will serve as the interface to the threads/CPU.
3865595Sgblack@eecs.umich.edu        O3ThreadContext<Impl> *o3_tc = new O3ThreadContext<Impl>;
3875595Sgblack@eecs.umich.edu
3885595Sgblack@eecs.umich.edu        tc = o3_tc;
3895595Sgblack@eecs.umich.edu
3905595Sgblack@eecs.umich.edu        // If we're using a checker, then the TC should be the
3915595Sgblack@eecs.umich.edu        // CheckerThreadContext.
3925595Sgblack@eecs.umich.edu#if USE_CHECKER
3935595Sgblack@eecs.umich.edu        if (params->checker) {
3945595Sgblack@eecs.umich.edu            tc = new CheckerThreadContext<O3ThreadContext<Impl> >(
3955595Sgblack@eecs.umich.edu                o3_tc, this->checker);
3965595Sgblack@eecs.umich.edu        }
3975595Sgblack@eecs.umich.edu#endif
3985595Sgblack@eecs.umich.edu
3995595Sgblack@eecs.umich.edu        o3_tc->cpu = (typename Impl::O3CPU *)(this);
4005595Sgblack@eecs.umich.edu        assert(o3_tc->cpu);
4016221Snate@binkert.org        o3_tc->thread = this->thread[tid];
4025595Sgblack@eecs.umich.edu
4035595Sgblack@eecs.umich.edu#if FULL_SYSTEM
4045595Sgblack@eecs.umich.edu        // Setup quiesce event.
4056221Snate@binkert.org        this->thread[tid]->quiesceEvent = new EndQuiesceEvent(tc);
4065595Sgblack@eecs.umich.edu#endif
4075595Sgblack@eecs.umich.edu        // Give the thread the TC.
4086221Snate@binkert.org        this->thread[tid]->tc = tc;
4095595Sgblack@eecs.umich.edu
4105595Sgblack@eecs.umich.edu        // Add the TC to the CPU's list of TC's.
4115595Sgblack@eecs.umich.edu        this->threadContexts.push_back(tc);
4125595Sgblack@eecs.umich.edu    }
4135595Sgblack@eecs.umich.edu
4146221Snate@binkert.org    for (ThreadID tid = 0; tid < this->numThreads; tid++)
4156221Snate@binkert.org        this->thread[tid]->setFuncExeInst(0);
4165595Sgblack@eecs.umich.edu
4175595Sgblack@eecs.umich.edu    lockAddr = 0;
4185595Sgblack@eecs.umich.edu    lockFlag = false;
4191060SN/A}
4201060SN/A
4211060SN/Atemplate <class Impl>
4221755SN/AFullO3CPU<Impl>::~FullO3CPU()
4231060SN/A{
4241060SN/A}
4251060SN/A
4261060SN/Atemplate <class Impl>
4271060SN/Avoid
4285595Sgblack@eecs.umich.eduFullO3CPU<Impl>::regStats()
4291062SN/A{
4302733Sktlim@umich.edu    BaseO3CPU::regStats();
4312292SN/A
4322733Sktlim@umich.edu    // Register any of the O3CPU's stats here.
4332292SN/A    timesIdled
4342292SN/A        .name(name() + ".timesIdled")
4352292SN/A        .desc("Number of times that the entire CPU went into an idle state and"
4362292SN/A              " unscheduled itself")
4372292SN/A        .prereq(timesIdled);
4382292SN/A
4392292SN/A    idleCycles
4402292SN/A        .name(name() + ".idleCycles")
4412292SN/A        .desc("Total number of cycles that the CPU has spent unscheduled due "
4422292SN/A              "to idling")
4432292SN/A        .prereq(idleCycles);
4442292SN/A
4452292SN/A    // Number of Instructions simulated
4462292SN/A    // --------------------------------
4472292SN/A    // Should probably be in Base CPU but need templated
4482292SN/A    // MaxThreads so put in here instead
4492292SN/A    committedInsts
4502292SN/A        .init(numThreads)
4512292SN/A        .name(name() + ".committedInsts")
4522292SN/A        .desc("Number of Instructions Simulated");
4532292SN/A
4542292SN/A    totalCommittedInsts
4552292SN/A        .name(name() + ".committedInsts_total")
4562292SN/A        .desc("Number of Instructions Simulated");
4572292SN/A
4582292SN/A    cpi
4592292SN/A        .name(name() + ".cpi")
4602292SN/A        .desc("CPI: Cycles Per Instruction")
4612292SN/A        .precision(6);
4624392Sktlim@umich.edu    cpi = numCycles / committedInsts;
4632292SN/A
4642292SN/A    totalCpi
4652292SN/A        .name(name() + ".cpi_total")
4662292SN/A        .desc("CPI: Total CPI of All Threads")
4672292SN/A        .precision(6);
4684392Sktlim@umich.edu    totalCpi = numCycles / totalCommittedInsts;
4692292SN/A
4702292SN/A    ipc
4712292SN/A        .name(name() + ".ipc")
4722292SN/A        .desc("IPC: Instructions Per Cycle")
4732292SN/A        .precision(6);
4744392Sktlim@umich.edu    ipc =  committedInsts / numCycles;
4752292SN/A
4762292SN/A    totalIpc
4772292SN/A        .name(name() + ".ipc_total")
4782292SN/A        .desc("IPC: Total IPC of All Threads")
4792292SN/A        .precision(6);
4804392Sktlim@umich.edu    totalIpc =  totalCommittedInsts / numCycles;
4812292SN/A
4825595Sgblack@eecs.umich.edu    this->fetch.regStats();
4835595Sgblack@eecs.umich.edu    this->decode.regStats();
4845595Sgblack@eecs.umich.edu    this->rename.regStats();
4855595Sgblack@eecs.umich.edu    this->iew.regStats();
4865595Sgblack@eecs.umich.edu    this->commit.regStats();
4877897Shestness@cs.utexas.edu    this->rob.regStats();
4887897Shestness@cs.utexas.edu
4897897Shestness@cs.utexas.edu    intRegfileReads
4907897Shestness@cs.utexas.edu        .name(name() + ".int_regfile_reads")
4917897Shestness@cs.utexas.edu        .desc("number of integer regfile reads")
4927897Shestness@cs.utexas.edu        .prereq(intRegfileReads);
4937897Shestness@cs.utexas.edu
4947897Shestness@cs.utexas.edu    intRegfileWrites
4957897Shestness@cs.utexas.edu        .name(name() + ".int_regfile_writes")
4967897Shestness@cs.utexas.edu        .desc("number of integer regfile writes")
4977897Shestness@cs.utexas.edu        .prereq(intRegfileWrites);
4987897Shestness@cs.utexas.edu
4997897Shestness@cs.utexas.edu    fpRegfileReads
5007897Shestness@cs.utexas.edu        .name(name() + ".fp_regfile_reads")
5017897Shestness@cs.utexas.edu        .desc("number of floating regfile reads")
5027897Shestness@cs.utexas.edu        .prereq(fpRegfileReads);
5037897Shestness@cs.utexas.edu
5047897Shestness@cs.utexas.edu    fpRegfileWrites
5057897Shestness@cs.utexas.edu        .name(name() + ".fp_regfile_writes")
5067897Shestness@cs.utexas.edu        .desc("number of floating regfile writes")
5077897Shestness@cs.utexas.edu        .prereq(fpRegfileWrites);
5087897Shestness@cs.utexas.edu
5097897Shestness@cs.utexas.edu    miscRegfileReads
5107897Shestness@cs.utexas.edu        .name(name() + ".misc_regfile_reads")
5117897Shestness@cs.utexas.edu        .desc("number of misc regfile reads")
5127897Shestness@cs.utexas.edu        .prereq(miscRegfileReads);
5137897Shestness@cs.utexas.edu
5147897Shestness@cs.utexas.edu    miscRegfileWrites
5157897Shestness@cs.utexas.edu        .name(name() + ".misc_regfile_writes")
5167897Shestness@cs.utexas.edu        .desc("number of misc regfile writes")
5177897Shestness@cs.utexas.edu        .prereq(miscRegfileWrites);
5181062SN/A}
5191062SN/A
5201062SN/Atemplate <class Impl>
5212871Sktlim@umich.eduPort *
5222871Sktlim@umich.eduFullO3CPU<Impl>::getPort(const std::string &if_name, int idx)
5232871Sktlim@umich.edu{
5242871Sktlim@umich.edu    if (if_name == "dcache_port")
5252871Sktlim@umich.edu        return iew.getDcachePort();
5262871Sktlim@umich.edu    else if (if_name == "icache_port")
5272871Sktlim@umich.edu        return fetch.getIcachePort();
5282871Sktlim@umich.edu    else
5292871Sktlim@umich.edu        panic("No Such Port\n");
5302871Sktlim@umich.edu}
5312871Sktlim@umich.edu
5322871Sktlim@umich.edutemplate <class Impl>
5331062SN/Avoid
5341755SN/AFullO3CPU<Impl>::tick()
5351060SN/A{
5362733Sktlim@umich.edu    DPRINTF(O3CPU, "\n\nFullO3CPU: Ticking main, FullO3CPU.\n");
5371060SN/A
5382292SN/A    ++numCycles;
5392292SN/A
5402325SN/A//    activity = false;
5412292SN/A
5422292SN/A    //Tick each of the stages
5431060SN/A    fetch.tick();
5441060SN/A
5451060SN/A    decode.tick();
5461060SN/A
5471060SN/A    rename.tick();
5481060SN/A
5491060SN/A    iew.tick();
5501060SN/A
5511060SN/A    commit.tick();
5521060SN/A
5532292SN/A#if !FULL_SYSTEM
5542292SN/A    doContextSwitch();
5552292SN/A#endif
5562292SN/A
5572292SN/A    // Now advance the time buffers
5581060SN/A    timeBuffer.advance();
5591060SN/A
5601060SN/A    fetchQueue.advance();
5611060SN/A    decodeQueue.advance();
5621060SN/A    renameQueue.advance();
5631060SN/A    iewQueue.advance();
5641060SN/A
5652325SN/A    activityRec.advance();
5662292SN/A
5672292SN/A    if (removeInstsThisCycle) {
5682292SN/A        cleanUpRemovedInsts();
5692292SN/A    }
5702292SN/A
5712325SN/A    if (!tickEvent.scheduled()) {
5722867Sktlim@umich.edu        if (_status == SwitchedOut ||
5732905Sktlim@umich.edu            getState() == SimObject::Drained) {
5743226Sktlim@umich.edu            DPRINTF(O3CPU, "Switched out!\n");
5752325SN/A            // increment stat
5767823Ssteve.reinhardt@amd.com            lastRunningCycle = curTick();
5773221Sktlim@umich.edu        } else if (!activityRec.active() || _status == Idle) {
5783226Sktlim@umich.edu            DPRINTF(O3CPU, "Idle!\n");
5797823Ssteve.reinhardt@amd.com            lastRunningCycle = curTick();
5802325SN/A            timesIdled++;
5812325SN/A        } else {
5827823Ssteve.reinhardt@amd.com            schedule(tickEvent, nextCycle(curTick() + ticks(1)));
5833226Sktlim@umich.edu            DPRINTF(O3CPU, "Scheduling next tick!\n");
5842325SN/A        }
5852292SN/A    }
5862292SN/A
5872292SN/A#if !FULL_SYSTEM
5882292SN/A    updateThreadPriority();
5892292SN/A#endif
5901060SN/A}
5911060SN/A
5921060SN/Atemplate <class Impl>
5931060SN/Avoid
5941755SN/AFullO3CPU<Impl>::init()
5951060SN/A{
5965714Shsul@eecs.umich.edu    BaseCPU::init();
5971060SN/A
5982292SN/A    // Set inSyscall so that the CPU doesn't squash when initially
5992292SN/A    // setting up registers.
6006221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; ++tid)
6016221Snate@binkert.org        thread[tid]->inSyscall = true;
6022292SN/A
6036034Ssteve.reinhardt@amd.com#if FULL_SYSTEM
6046221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
6052680Sktlim@umich.edu        ThreadContext *src_tc = threadContexts[tid];
6066034Ssteve.reinhardt@amd.com        TheISA::initCPU(src_tc, src_tc->contextId());
6076034Ssteve.reinhardt@amd.com    }
6081681SN/A#endif
6092292SN/A
6102292SN/A    // Clear inSyscall.
6116221Snate@binkert.org    for (int tid = 0; tid < numThreads; ++tid)
6126221Snate@binkert.org        thread[tid]->inSyscall = false;
6132292SN/A
6142316SN/A    // Initialize stages.
6152292SN/A    fetch.initStage();
6162292SN/A    iew.initStage();
6172292SN/A    rename.initStage();
6182292SN/A    commit.initStage();
6192292SN/A
6202292SN/A    commit.setThreads(thread);
6212292SN/A}
6222292SN/A
6232292SN/Atemplate <class Impl>
6242292SN/Avoid
6256221Snate@binkert.orgFullO3CPU<Impl>::activateThread(ThreadID tid)
6262875Sksewell@umich.edu{
6276221Snate@binkert.org    list<ThreadID>::iterator isActive =
6285314Sstever@gmail.com        std::find(activeThreads.begin(), activeThreads.end(), tid);
6292875Sksewell@umich.edu
6303226Sktlim@umich.edu    DPRINTF(O3CPU, "[tid:%i]: Calling activate thread.\n", tid);
6313226Sktlim@umich.edu
6322875Sksewell@umich.edu    if (isActive == activeThreads.end()) {
6332875Sksewell@umich.edu        DPRINTF(O3CPU, "[tid:%i]: Adding to active threads list\n",
6342875Sksewell@umich.edu                tid);
6352875Sksewell@umich.edu
6362875Sksewell@umich.edu        activeThreads.push_back(tid);
6372875Sksewell@umich.edu    }
6382875Sksewell@umich.edu}
6392875Sksewell@umich.edu
6402875Sksewell@umich.edutemplate <class Impl>
6412875Sksewell@umich.eduvoid
6426221Snate@binkert.orgFullO3CPU<Impl>::deactivateThread(ThreadID tid)
6432875Sksewell@umich.edu{
6442875Sksewell@umich.edu    //Remove From Active List, if Active
6456221Snate@binkert.org    list<ThreadID>::iterator thread_it =
6465314Sstever@gmail.com        std::find(activeThreads.begin(), activeThreads.end(), tid);
6472875Sksewell@umich.edu
6483226Sktlim@umich.edu    DPRINTF(O3CPU, "[tid:%i]: Calling deactivate thread.\n", tid);
6493226Sktlim@umich.edu
6502875Sksewell@umich.edu    if (thread_it != activeThreads.end()) {
6512875Sksewell@umich.edu        DPRINTF(O3CPU,"[tid:%i]: Removing from active threads list\n",
6522875Sksewell@umich.edu                tid);
6532875Sksewell@umich.edu        activeThreads.erase(thread_it);
6542875Sksewell@umich.edu    }
6552875Sksewell@umich.edu}
6562875Sksewell@umich.edu
6572875Sksewell@umich.edutemplate <class Impl>
6586221Snate@binkert.orgCounter
6596221Snate@binkert.orgFullO3CPU<Impl>::totalInstructions() const
6606221Snate@binkert.org{
6616221Snate@binkert.org    Counter total(0);
6626221Snate@binkert.org
6636221Snate@binkert.org    ThreadID size = thread.size();
6646221Snate@binkert.org    for (ThreadID i = 0; i < size; i++)
6656221Snate@binkert.org        total += thread[i]->numInst;
6666221Snate@binkert.org
6676221Snate@binkert.org    return total;
6686221Snate@binkert.org}
6696221Snate@binkert.org
6706221Snate@binkert.orgtemplate <class Impl>
6712875Sksewell@umich.eduvoid
6726221Snate@binkert.orgFullO3CPU<Impl>::activateContext(ThreadID tid, int delay)
6732875Sksewell@umich.edu{
6742875Sksewell@umich.edu    // Needs to set each stage to running as well.
6752875Sksewell@umich.edu    if (delay){
6762875Sksewell@umich.edu        DPRINTF(O3CPU, "[tid:%i]: Scheduling thread context to activate "
6777823Ssteve.reinhardt@amd.com                "on cycle %d\n", tid, curTick() + ticks(delay));
6782875Sksewell@umich.edu        scheduleActivateThreadEvent(tid, delay);
6792875Sksewell@umich.edu    } else {
6802875Sksewell@umich.edu        activateThread(tid);
6812875Sksewell@umich.edu    }
6822875Sksewell@umich.edu
6837823Ssteve.reinhardt@amd.com    if (lastActivatedCycle < curTick()) {
6842875Sksewell@umich.edu        scheduleTickEvent(delay);
6852875Sksewell@umich.edu
6862875Sksewell@umich.edu        // Be sure to signal that there's some activity so the CPU doesn't
6872875Sksewell@umich.edu        // deschedule itself.
6882875Sksewell@umich.edu        activityRec.activity();
6892875Sksewell@umich.edu        fetch.wakeFromQuiesce();
6902875Sksewell@umich.edu
6917823Ssteve.reinhardt@amd.com        lastActivatedCycle = curTick();
6922875Sksewell@umich.edu
6932875Sksewell@umich.edu        _status = Running;
6942875Sksewell@umich.edu    }
6952875Sksewell@umich.edu}
6962875Sksewell@umich.edu
6972875Sksewell@umich.edutemplate <class Impl>
6983221Sktlim@umich.edubool
6996221Snate@binkert.orgFullO3CPU<Impl>::deallocateContext(ThreadID tid, bool remove, int delay)
7002875Sksewell@umich.edu{
7012875Sksewell@umich.edu    // Schedule removal of thread data from CPU
7022875Sksewell@umich.edu    if (delay){
7032875Sksewell@umich.edu        DPRINTF(O3CPU, "[tid:%i]: Scheduling thread context to deallocate "
7047823Ssteve.reinhardt@amd.com                "on cycle %d\n", tid, curTick() + ticks(delay));
7053221Sktlim@umich.edu        scheduleDeallocateContextEvent(tid, remove, delay);
7063221Sktlim@umich.edu        return false;
7072875Sksewell@umich.edu    } else {
7082875Sksewell@umich.edu        deactivateThread(tid);
7093221Sktlim@umich.edu        if (remove)
7103221Sktlim@umich.edu            removeThread(tid);
7113221Sktlim@umich.edu        return true;
7122875Sksewell@umich.edu    }
7132875Sksewell@umich.edu}
7142875Sksewell@umich.edu
7152875Sksewell@umich.edutemplate <class Impl>
7162875Sksewell@umich.eduvoid
7176221Snate@binkert.orgFullO3CPU<Impl>::suspendContext(ThreadID tid)
7182875Sksewell@umich.edu{
7192875Sksewell@umich.edu    DPRINTF(O3CPU,"[tid: %i]: Suspending Thread Context.\n", tid);
7203221Sktlim@umich.edu    bool deallocated = deallocateContext(tid, false, 1);
7213221Sktlim@umich.edu    // If this was the last thread then unschedule the tick event.
7225570Snate@binkert.org    if ((activeThreads.size() == 1 && !deallocated) ||
7233859Sbinkertn@umich.edu        activeThreads.size() == 0)
7242910Sksewell@umich.edu        unscheduleTickEvent();
7252875Sksewell@umich.edu    _status = Idle;
7262875Sksewell@umich.edu}
7272875Sksewell@umich.edu
7282875Sksewell@umich.edutemplate <class Impl>
7292875Sksewell@umich.eduvoid
7306221Snate@binkert.orgFullO3CPU<Impl>::haltContext(ThreadID tid)
7312875Sksewell@umich.edu{
7322910Sksewell@umich.edu    //For now, this is the same as deallocate
7332910Sksewell@umich.edu    DPRINTF(O3CPU,"[tid:%i]: Halt Context called. Deallocating", tid);
7343221Sktlim@umich.edu    deallocateContext(tid, true, 1);
7352875Sksewell@umich.edu}
7362875Sksewell@umich.edu
7372875Sksewell@umich.edutemplate <class Impl>
7382875Sksewell@umich.eduvoid
7396221Snate@binkert.orgFullO3CPU<Impl>::insertThread(ThreadID tid)
7402292SN/A{
7412847Sksewell@umich.edu    DPRINTF(O3CPU,"[tid:%i] Initializing thread into CPU");
7422292SN/A    // Will change now that the PC and thread state is internal to the CPU
7432683Sktlim@umich.edu    // and not in the ThreadContext.
7442292SN/A#if FULL_SYSTEM
7452680Sktlim@umich.edu    ThreadContext *src_tc = system->threadContexts[tid];
7462292SN/A#else
7472847Sksewell@umich.edu    ThreadContext *src_tc = tcBase(tid);
7482292SN/A#endif
7492292SN/A
7502292SN/A    //Bind Int Regs to Rename Map
7512292SN/A    for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) {
7522292SN/A        PhysRegIndex phys_reg = freeList.getIntReg();
7532292SN/A
7542292SN/A        renameMap[tid].setEntry(ireg,phys_reg);
7552292SN/A        scoreboard.setReg(phys_reg);
7562292SN/A    }
7572292SN/A
7582292SN/A    //Bind Float Regs to Rename Map
7592292SN/A    for (int freg = 0; freg < TheISA::NumFloatRegs; freg++) {
7602292SN/A        PhysRegIndex phys_reg = freeList.getFloatReg();
7612292SN/A
7622292SN/A        renameMap[tid].setEntry(freg,phys_reg);
7632292SN/A        scoreboard.setReg(phys_reg);
7642292SN/A    }
7652292SN/A
7662292SN/A    //Copy Thread Data Into RegFile
7672847Sksewell@umich.edu    //this->copyFromTC(tid);
7682292SN/A
7692847Sksewell@umich.edu    //Set PC/NPC/NNPC
7707720Sgblack@eecs.umich.edu    pcState(src_tc->pcState(), tid);
7712292SN/A
7722680Sktlim@umich.edu    src_tc->setStatus(ThreadContext::Active);
7732292SN/A
7742292SN/A    activateContext(tid,1);
7752292SN/A
7762292SN/A    //Reset ROB/IQ/LSQ Entries
7772292SN/A    commit.rob->resetEntries();
7782292SN/A    iew.resetEntries();
7792292SN/A}
7802292SN/A
7812292SN/Atemplate <class Impl>
7822292SN/Avoid
7836221Snate@binkert.orgFullO3CPU<Impl>::removeThread(ThreadID tid)
7842292SN/A{
7852877Sksewell@umich.edu    DPRINTF(O3CPU,"[tid:%i] Removing thread context from CPU.\n", tid);
7862847Sksewell@umich.edu
7872847Sksewell@umich.edu    // Copy Thread Data From RegFile
7882847Sksewell@umich.edu    // If thread is suspended, it might be re-allocated
7895364Sksewell@umich.edu    // this->copyToTC(tid);
7905364Sksewell@umich.edu
7915364Sksewell@umich.edu
7925364Sksewell@umich.edu    // @todo: 2-27-2008: Fix how we free up rename mappings
7935364Sksewell@umich.edu    // here to alleviate the case for double-freeing registers
7945364Sksewell@umich.edu    // in SMT workloads.
7952847Sksewell@umich.edu
7962847Sksewell@umich.edu    // Unbind Int Regs from Rename Map
7972292SN/A    for (int ireg = 0; ireg < TheISA::NumIntRegs; ireg++) {
7982292SN/A        PhysRegIndex phys_reg = renameMap[tid].lookup(ireg);
7992292SN/A
8002292SN/A        scoreboard.unsetReg(phys_reg);
8012292SN/A        freeList.addReg(phys_reg);
8022292SN/A    }
8032292SN/A
8042847Sksewell@umich.edu    // Unbind Float Regs from Rename Map
8055362Sksewell@umich.edu    for (int freg = TheISA::NumIntRegs; freg < TheISA::NumFloatRegs; freg++) {
8062292SN/A        PhysRegIndex phys_reg = renameMap[tid].lookup(freg);
8072292SN/A
8082292SN/A        scoreboard.unsetReg(phys_reg);
8092292SN/A        freeList.addReg(phys_reg);
8102292SN/A    }
8112292SN/A
8122847Sksewell@umich.edu    // Squash Throughout Pipeline
8138138SAli.Saidi@ARM.com    DynInstPtr inst = commit.rob->readHeadInst(tid);
8148138SAli.Saidi@ARM.com    InstSeqNum squash_seq_num = inst->seqNum;
8158138SAli.Saidi@ARM.com    fetch.squash(0, squash_seq_num, inst, tid);
8162292SN/A    decode.squash(tid);
8172935Sksewell@umich.edu    rename.squash(squash_seq_num, tid);
8182875Sksewell@umich.edu    iew.squash(tid);
8195363Sksewell@umich.edu    iew.ldstQueue.squash(squash_seq_num, tid);
8202935Sksewell@umich.edu    commit.rob->squash(squash_seq_num, tid);
8212292SN/A
8225362Sksewell@umich.edu
8235362Sksewell@umich.edu    assert(iew.instQueue.getCount(tid) == 0);
8242292SN/A    assert(iew.ldstQueue.getCount(tid) == 0);
8252292SN/A
8262847Sksewell@umich.edu    // Reset ROB/IQ/LSQ Entries
8273229Sktlim@umich.edu
8283229Sktlim@umich.edu    // Commented out for now.  This should be possible to do by
8293229Sktlim@umich.edu    // telling all the pipeline stages to drain first, and then
8303229Sktlim@umich.edu    // checking until the drain completes.  Once the pipeline is
8313229Sktlim@umich.edu    // drained, call resetEntries(). - 10-09-06 ktlim
8323229Sktlim@umich.edu/*
8332292SN/A    if (activeThreads.size() >= 1) {
8342292SN/A        commit.rob->resetEntries();
8352292SN/A        iew.resetEntries();
8362292SN/A    }
8373229Sktlim@umich.edu*/
8382292SN/A}
8392292SN/A
8402292SN/A
8412292SN/Atemplate <class Impl>
8422292SN/Avoid
8436221Snate@binkert.orgFullO3CPU<Impl>::activateWhenReady(ThreadID tid)
8442292SN/A{
8452733Sktlim@umich.edu    DPRINTF(O3CPU,"[tid:%i]: Checking if resources are available for incoming"
8462292SN/A            "(e.g. PhysRegs/ROB/IQ/LSQ) \n",
8472292SN/A            tid);
8482292SN/A
8492292SN/A    bool ready = true;
8502292SN/A
8512292SN/A    if (freeList.numFreeIntRegs() >= TheISA::NumIntRegs) {
8522733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
8532292SN/A                "Phys. Int. Regs.\n",
8542292SN/A                tid);
8552292SN/A        ready = false;
8562292SN/A    } else if (freeList.numFreeFloatRegs() >= TheISA::NumFloatRegs) {
8572733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
8582292SN/A                "Phys. Float. Regs.\n",
8592292SN/A                tid);
8602292SN/A        ready = false;
8612292SN/A    } else if (commit.rob->numFreeEntries() >=
8622292SN/A               commit.rob->entryAmount(activeThreads.size() + 1)) {
8632733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
8642292SN/A                "ROB entries.\n",
8652292SN/A                tid);
8662292SN/A        ready = false;
8672292SN/A    } else if (iew.instQueue.numFreeEntries() >=
8682292SN/A               iew.instQueue.entryAmount(activeThreads.size() + 1)) {
8692733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
8702292SN/A                "IQ entries.\n",
8712292SN/A                tid);
8722292SN/A        ready = false;
8732292SN/A    } else if (iew.ldstQueue.numFreeEntries() >=
8742292SN/A               iew.ldstQueue.entryAmount(activeThreads.size() + 1)) {
8752733Sktlim@umich.edu        DPRINTF(O3CPU,"[tid:%i] Suspending thread due to not enough "
8762292SN/A                "LSQ entries.\n",
8772292SN/A                tid);
8782292SN/A        ready = false;
8792292SN/A    }
8802292SN/A
8812292SN/A    if (ready) {
8822292SN/A        insertThread(tid);
8832292SN/A
8842292SN/A        contextSwitch = false;
8852292SN/A
8862292SN/A        cpuWaitList.remove(tid);
8872292SN/A    } else {
8882292SN/A        suspendContext(tid);
8892292SN/A
8902292SN/A        //blocks fetch
8912292SN/A        contextSwitch = true;
8922292SN/A
8932875Sksewell@umich.edu        //@todo: dont always add to waitlist
8942292SN/A        //do waitlist
8952292SN/A        cpuWaitList.push_back(tid);
8961060SN/A    }
8971060SN/A}
8981060SN/A
8994192Sktlim@umich.edu#if FULL_SYSTEM
9004192Sktlim@umich.edutemplate <class Impl>
9015595Sgblack@eecs.umich.eduFault
9026221Snate@binkert.orgFullO3CPU<Impl>::hwrei(ThreadID tid)
9035702Ssaidi@eecs.umich.edu{
9045702Ssaidi@eecs.umich.edu#if THE_ISA == ALPHA_ISA
9055702Ssaidi@eecs.umich.edu    // Need to clear the lock flag upon returning from an interrupt.
9065702Ssaidi@eecs.umich.edu    this->setMiscRegNoEffect(AlphaISA::MISCREG_LOCKFLAG, false, tid);
9075702Ssaidi@eecs.umich.edu
9085702Ssaidi@eecs.umich.edu    this->thread[tid]->kernelStats->hwrei();
9095702Ssaidi@eecs.umich.edu
9105702Ssaidi@eecs.umich.edu    // FIXME: XXX check for interrupts? XXX
9115702Ssaidi@eecs.umich.edu#endif
9125702Ssaidi@eecs.umich.edu    return NoFault;
9135702Ssaidi@eecs.umich.edu}
9145702Ssaidi@eecs.umich.edu
9155702Ssaidi@eecs.umich.edutemplate <class Impl>
9165702Ssaidi@eecs.umich.edubool
9176221Snate@binkert.orgFullO3CPU<Impl>::simPalCheck(int palFunc, ThreadID tid)
9185702Ssaidi@eecs.umich.edu{
9195702Ssaidi@eecs.umich.edu#if THE_ISA == ALPHA_ISA
9205702Ssaidi@eecs.umich.edu    if (this->thread[tid]->kernelStats)
9215702Ssaidi@eecs.umich.edu        this->thread[tid]->kernelStats->callpal(palFunc,
9225702Ssaidi@eecs.umich.edu                                                this->threadContexts[tid]);
9235702Ssaidi@eecs.umich.edu
9245702Ssaidi@eecs.umich.edu    switch (palFunc) {
9255702Ssaidi@eecs.umich.edu      case PAL::halt:
9265702Ssaidi@eecs.umich.edu        halt();
9275702Ssaidi@eecs.umich.edu        if (--System::numSystemsRunning == 0)
9285702Ssaidi@eecs.umich.edu            exitSimLoop("all cpus halted");
9295702Ssaidi@eecs.umich.edu        break;
9305702Ssaidi@eecs.umich.edu
9315702Ssaidi@eecs.umich.edu      case PAL::bpt:
9325702Ssaidi@eecs.umich.edu      case PAL::bugchk:
9335702Ssaidi@eecs.umich.edu        if (this->system->breakpoint())
9345702Ssaidi@eecs.umich.edu            return false;
9355702Ssaidi@eecs.umich.edu        break;
9365702Ssaidi@eecs.umich.edu    }
9375702Ssaidi@eecs.umich.edu#endif
9385702Ssaidi@eecs.umich.edu    return true;
9395702Ssaidi@eecs.umich.edu}
9405702Ssaidi@eecs.umich.edu
9415702Ssaidi@eecs.umich.edutemplate <class Impl>
9425702Ssaidi@eecs.umich.eduFault
9435595Sgblack@eecs.umich.eduFullO3CPU<Impl>::getInterrupts()
9445595Sgblack@eecs.umich.edu{
9455595Sgblack@eecs.umich.edu    // Check if there are any outstanding interrupts
9465647Sgblack@eecs.umich.edu    return this->interrupts->getInterrupt(this->threadContexts[0]);
9475595Sgblack@eecs.umich.edu}
9485595Sgblack@eecs.umich.edu
9495595Sgblack@eecs.umich.edutemplate <class Impl>
9505595Sgblack@eecs.umich.eduvoid
9515595Sgblack@eecs.umich.eduFullO3CPU<Impl>::processInterrupts(Fault interrupt)
9525595Sgblack@eecs.umich.edu{
9535595Sgblack@eecs.umich.edu    // Check for interrupts here.  For now can copy the code that
9545595Sgblack@eecs.umich.edu    // exists within isa_fullsys_traits.hh.  Also assume that thread 0
9555595Sgblack@eecs.umich.edu    // is the one that handles the interrupts.
9565595Sgblack@eecs.umich.edu    // @todo: Possibly consolidate the interrupt checking code.
9575595Sgblack@eecs.umich.edu    // @todo: Allow other threads to handle interrupts.
9585595Sgblack@eecs.umich.edu
9595595Sgblack@eecs.umich.edu    assert(interrupt != NoFault);
9605647Sgblack@eecs.umich.edu    this->interrupts->updateIntrInfo(this->threadContexts[0]);
9615595Sgblack@eecs.umich.edu
9625595Sgblack@eecs.umich.edu    DPRINTF(O3CPU, "Interrupt %s being handled\n", interrupt->name());
9637684Sgblack@eecs.umich.edu    this->trap(interrupt, 0, NULL);
9645595Sgblack@eecs.umich.edu}
9655595Sgblack@eecs.umich.edu
9665595Sgblack@eecs.umich.edutemplate <class Impl>
9675595Sgblack@eecs.umich.eduvoid
9684192Sktlim@umich.eduFullO3CPU<Impl>::updateMemPorts()
9694192Sktlim@umich.edu{
9704192Sktlim@umich.edu    // Update all ThreadContext's memory ports (Functional/Virtual
9714192Sktlim@umich.edu    // Ports)
9726221Snate@binkert.org    ThreadID size = thread.size();
9736221Snate@binkert.org    for (ThreadID i = 0; i < size; ++i)
9745497Ssaidi@eecs.umich.edu        thread[i]->connectMemPorts(thread[i]->getTC());
9754192Sktlim@umich.edu}
9764192Sktlim@umich.edu#endif
9774192Sktlim@umich.edu
9781060SN/Atemplate <class Impl>
9792852Sktlim@umich.eduvoid
9807684Sgblack@eecs.umich.eduFullO3CPU<Impl>::trap(Fault fault, ThreadID tid, StaticInstPtr inst)
9815595Sgblack@eecs.umich.edu{
9825595Sgblack@eecs.umich.edu    // Pass the thread's TC into the invoke method.
9837684Sgblack@eecs.umich.edu    fault->invoke(this->threadContexts[tid], inst);
9845595Sgblack@eecs.umich.edu}
9855595Sgblack@eecs.umich.edu
9865595Sgblack@eecs.umich.edu#if !FULL_SYSTEM
9875595Sgblack@eecs.umich.edu
9885595Sgblack@eecs.umich.edutemplate <class Impl>
9895595Sgblack@eecs.umich.eduvoid
9906221Snate@binkert.orgFullO3CPU<Impl>::syscall(int64_t callnum, ThreadID tid)
9915595Sgblack@eecs.umich.edu{
9925595Sgblack@eecs.umich.edu    DPRINTF(O3CPU, "[tid:%i] Executing syscall().\n\n", tid);
9935595Sgblack@eecs.umich.edu
9945595Sgblack@eecs.umich.edu    DPRINTF(Activity,"Activity: syscall() called.\n");
9955595Sgblack@eecs.umich.edu
9965595Sgblack@eecs.umich.edu    // Temporarily increase this by one to account for the syscall
9975595Sgblack@eecs.umich.edu    // instruction.
9985595Sgblack@eecs.umich.edu    ++(this->thread[tid]->funcExeInst);
9995595Sgblack@eecs.umich.edu
10005595Sgblack@eecs.umich.edu    // Execute the actual syscall.
10015595Sgblack@eecs.umich.edu    this->thread[tid]->syscall(callnum);
10025595Sgblack@eecs.umich.edu
10035595Sgblack@eecs.umich.edu    // Decrease funcExeInst by one as the normal commit will handle
10045595Sgblack@eecs.umich.edu    // incrementing it.
10055595Sgblack@eecs.umich.edu    --(this->thread[tid]->funcExeInst);
10065595Sgblack@eecs.umich.edu}
10075595Sgblack@eecs.umich.edu
10085595Sgblack@eecs.umich.edu#endif
10095595Sgblack@eecs.umich.edu
10105595Sgblack@eecs.umich.edutemplate <class Impl>
10115595Sgblack@eecs.umich.eduvoid
10122864Sktlim@umich.eduFullO3CPU<Impl>::serialize(std::ostream &os)
10132864Sktlim@umich.edu{
10142918Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
10152918Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
10162864Sktlim@umich.edu    BaseCPU::serialize(os);
10172864Sktlim@umich.edu    nameOut(os, csprintf("%s.tickEvent", name()));
10182864Sktlim@umich.edu    tickEvent.serialize(os);
10192864Sktlim@umich.edu
10202864Sktlim@umich.edu    // Use SimpleThread's ability to checkpoint to make it easier to
10212864Sktlim@umich.edu    // write out the registers.  Also make this static so it doesn't
10222864Sktlim@umich.edu    // get instantiated multiple times (causes a panic in statistics).
10232864Sktlim@umich.edu    static SimpleThread temp;
10242864Sktlim@umich.edu
10256221Snate@binkert.org    ThreadID size = thread.size();
10266221Snate@binkert.org    for (ThreadID i = 0; i < size; i++) {
10272864Sktlim@umich.edu        nameOut(os, csprintf("%s.xc.%i", name(), i));
10282864Sktlim@umich.edu        temp.copyTC(thread[i]->getTC());
10292864Sktlim@umich.edu        temp.serialize(os);
10302864Sktlim@umich.edu    }
10312864Sktlim@umich.edu}
10322864Sktlim@umich.edu
10332864Sktlim@umich.edutemplate <class Impl>
10342864Sktlim@umich.eduvoid
10352864Sktlim@umich.eduFullO3CPU<Impl>::unserialize(Checkpoint *cp, const std::string &section)
10362864Sktlim@umich.edu{
10372918Sktlim@umich.edu    SimObject::State so_state;
10382918Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
10392864Sktlim@umich.edu    BaseCPU::unserialize(cp, section);
10402864Sktlim@umich.edu    tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
10412864Sktlim@umich.edu
10422864Sktlim@umich.edu    // Use SimpleThread's ability to checkpoint to make it easier to
10432864Sktlim@umich.edu    // read in the registers.  Also make this static so it doesn't
10442864Sktlim@umich.edu    // get instantiated multiple times (causes a panic in statistics).
10452864Sktlim@umich.edu    static SimpleThread temp;
10462864Sktlim@umich.edu
10476221Snate@binkert.org    ThreadID size = thread.size();
10486221Snate@binkert.org    for (ThreadID i = 0; i < size; i++) {
10492864Sktlim@umich.edu        temp.copyTC(thread[i]->getTC());
10502864Sktlim@umich.edu        temp.unserialize(cp, csprintf("%s.xc.%i", section, i));
10512864Sktlim@umich.edu        thread[i]->getTC()->copyArchRegs(temp.getTC());
10522864Sktlim@umich.edu    }
10532864Sktlim@umich.edu}
10542864Sktlim@umich.edu
10552864Sktlim@umich.edutemplate <class Impl>
10562905Sktlim@umich.eduunsigned int
10572843Sktlim@umich.eduFullO3CPU<Impl>::drain(Event *drain_event)
10581060SN/A{
10593125Sktlim@umich.edu    DPRINTF(O3CPU, "Switching out\n");
10603512Sktlim@umich.edu
10613512Sktlim@umich.edu    // If the CPU isn't doing anything, then return immediately.
10623512Sktlim@umich.edu    if (_status == Idle || _status == SwitchedOut) {
10633512Sktlim@umich.edu        return 0;
10643512Sktlim@umich.edu    }
10653512Sktlim@umich.edu
10662843Sktlim@umich.edu    drainCount = 0;
10672843Sktlim@umich.edu    fetch.drain();
10682843Sktlim@umich.edu    decode.drain();
10692843Sktlim@umich.edu    rename.drain();
10702843Sktlim@umich.edu    iew.drain();
10712843Sktlim@umich.edu    commit.drain();
10722325SN/A
10732325SN/A    // Wake the CPU and record activity so everything can drain out if
10742863Sktlim@umich.edu    // the CPU was not able to immediately drain.
10752905Sktlim@umich.edu    if (getState() != SimObject::Drained) {
10762864Sktlim@umich.edu        // A bit of a hack...set the drainEvent after all the drain()
10772864Sktlim@umich.edu        // calls have been made, that way if all of the stages drain
10782864Sktlim@umich.edu        // immediately, the signalDrained() function knows not to call
10792864Sktlim@umich.edu        // process on the drain event.
10802864Sktlim@umich.edu        drainEvent = drain_event;
10812843Sktlim@umich.edu
10822863Sktlim@umich.edu        wakeCPU();
10832863Sktlim@umich.edu        activityRec.activity();
10842852Sktlim@umich.edu
10852905Sktlim@umich.edu        return 1;
10862863Sktlim@umich.edu    } else {
10872905Sktlim@umich.edu        return 0;
10882863Sktlim@umich.edu    }
10892316SN/A}
10902310SN/A
10912316SN/Atemplate <class Impl>
10922316SN/Avoid
10932843Sktlim@umich.eduFullO3CPU<Impl>::resume()
10942316SN/A{
10952843Sktlim@umich.edu    fetch.resume();
10962843Sktlim@umich.edu    decode.resume();
10972843Sktlim@umich.edu    rename.resume();
10982843Sktlim@umich.edu    iew.resume();
10992843Sktlim@umich.edu    commit.resume();
11002316SN/A
11012905Sktlim@umich.edu    changeState(SimObject::Running);
11022905Sktlim@umich.edu
11032864Sktlim@umich.edu    if (_status == SwitchedOut || _status == Idle)
11042864Sktlim@umich.edu        return;
11052864Sktlim@umich.edu
11064762Snate@binkert.org    assert(system->getMemoryMode() == Enums::timing);
11073319Shsul@eecs.umich.edu
11082843Sktlim@umich.edu    if (!tickEvent.scheduled())
11095606Snate@binkert.org        schedule(tickEvent, nextCycle());
11102843Sktlim@umich.edu    _status = Running;
11112843Sktlim@umich.edu}
11122316SN/A
11132843Sktlim@umich.edutemplate <class Impl>
11142843Sktlim@umich.eduvoid
11152843Sktlim@umich.eduFullO3CPU<Impl>::signalDrained()
11162843Sktlim@umich.edu{
11172843Sktlim@umich.edu    if (++drainCount == NumStages) {
11182316SN/A        if (tickEvent.scheduled())
11192316SN/A            tickEvent.squash();
11202863Sktlim@umich.edu
11212905Sktlim@umich.edu        changeState(SimObject::Drained);
11222863Sktlim@umich.edu
11233126Sktlim@umich.edu        BaseCPU::switchOut();
11243126Sktlim@umich.edu
11252863Sktlim@umich.edu        if (drainEvent) {
11262863Sktlim@umich.edu            drainEvent->process();
11272863Sktlim@umich.edu            drainEvent = NULL;
11282863Sktlim@umich.edu        }
11292310SN/A    }
11302843Sktlim@umich.edu    assert(drainCount <= 5);
11312843Sktlim@umich.edu}
11322843Sktlim@umich.edu
11332843Sktlim@umich.edutemplate <class Impl>
11342843Sktlim@umich.eduvoid
11352843Sktlim@umich.eduFullO3CPU<Impl>::switchOut()
11362843Sktlim@umich.edu{
11372843Sktlim@umich.edu    fetch.switchOut();
11382843Sktlim@umich.edu    rename.switchOut();
11392325SN/A    iew.switchOut();
11402843Sktlim@umich.edu    commit.switchOut();
11412843Sktlim@umich.edu    instList.clear();
11422843Sktlim@umich.edu    while (!removeList.empty()) {
11432843Sktlim@umich.edu        removeList.pop();
11442843Sktlim@umich.edu    }
11452843Sktlim@umich.edu
11462843Sktlim@umich.edu    _status = SwitchedOut;
11472843Sktlim@umich.edu#if USE_CHECKER
11482843Sktlim@umich.edu    if (checker)
11492843Sktlim@umich.edu        checker->switchOut();
11502843Sktlim@umich.edu#endif
11513126Sktlim@umich.edu    if (tickEvent.scheduled())
11523126Sktlim@umich.edu        tickEvent.squash();
11531060SN/A}
11541060SN/A
11551060SN/Atemplate <class Impl>
11561060SN/Avoid
11571755SN/AFullO3CPU<Impl>::takeOverFrom(BaseCPU *oldCPU)
11581060SN/A{
11592325SN/A    // Flush out any old data from the time buffers.
11602873Sktlim@umich.edu    for (int i = 0; i < timeBuffer.getSize(); ++i) {
11612307SN/A        timeBuffer.advance();
11622307SN/A        fetchQueue.advance();
11632307SN/A        decodeQueue.advance();
11642307SN/A        renameQueue.advance();
11652307SN/A        iewQueue.advance();
11662307SN/A    }
11672307SN/A
11682325SN/A    activityRec.reset();
11692307SN/A
11704192Sktlim@umich.edu    BaseCPU::takeOverFrom(oldCPU, fetch.getIcachePort(), iew.getDcachePort());
11711060SN/A
11722307SN/A    fetch.takeOverFrom();
11732307SN/A    decode.takeOverFrom();
11742307SN/A    rename.takeOverFrom();
11752307SN/A    iew.takeOverFrom();
11762307SN/A    commit.takeOverFrom();
11772307SN/A
11787507Stjones1@inf.ed.ac.uk    assert(!tickEvent.scheduled() || tickEvent.squashed());
11791060SN/A
11802325SN/A    // @todo: Figure out how to properly select the tid to put onto
11812325SN/A    // the active threads list.
11826221Snate@binkert.org    ThreadID tid = 0;
11832307SN/A
11846221Snate@binkert.org    list<ThreadID>::iterator isActive =
11855314Sstever@gmail.com        std::find(activeThreads.begin(), activeThreads.end(), tid);
11862307SN/A
11872307SN/A    if (isActive == activeThreads.end()) {
11882325SN/A        //May Need to Re-code this if the delay variable is the delay
11892325SN/A        //needed for thread to activate
11902733Sktlim@umich.edu        DPRINTF(O3CPU, "Adding Thread %i to active threads list\n",
11912307SN/A                tid);
11922307SN/A
11932307SN/A        activeThreads.push_back(tid);
11942307SN/A    }
11952307SN/A
11962325SN/A    // Set all statuses to active, schedule the CPU's tick event.
11972307SN/A    // @todo: Fix up statuses so this is handled properly
11986221Snate@binkert.org    ThreadID size = threadContexts.size();
11996221Snate@binkert.org    for (ThreadID i = 0; i < size; ++i) {
12002680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
12012680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
12021681SN/A            _status = Running;
12037507Stjones1@inf.ed.ac.uk            reschedule(tickEvent, nextCycle(), true);
12041681SN/A        }
12051060SN/A    }
12062307SN/A    if (!tickEvent.scheduled())
12075606Snate@binkert.org        schedule(tickEvent, nextCycle());
12081060SN/A}
12091060SN/A
12101060SN/Atemplate <class Impl>
12115595Sgblack@eecs.umich.eduTheISA::MiscReg
12126221Snate@binkert.orgFullO3CPU<Impl>::readMiscRegNoEffect(int misc_reg, ThreadID tid)
12135595Sgblack@eecs.umich.edu{
12146313Sgblack@eecs.umich.edu    return this->isa[tid].readMiscRegNoEffect(misc_reg);
12155595Sgblack@eecs.umich.edu}
12165595Sgblack@eecs.umich.edu
12175595Sgblack@eecs.umich.edutemplate <class Impl>
12185595Sgblack@eecs.umich.eduTheISA::MiscReg
12196221Snate@binkert.orgFullO3CPU<Impl>::readMiscReg(int misc_reg, ThreadID tid)
12205595Sgblack@eecs.umich.edu{
12217897Shestness@cs.utexas.edu    miscRegfileReads++;
12226313Sgblack@eecs.umich.edu    return this->isa[tid].readMiscReg(misc_reg, tcBase(tid));
12235595Sgblack@eecs.umich.edu}
12245595Sgblack@eecs.umich.edu
12255595Sgblack@eecs.umich.edutemplate <class Impl>
12265595Sgblack@eecs.umich.eduvoid
12275595Sgblack@eecs.umich.eduFullO3CPU<Impl>::setMiscRegNoEffect(int misc_reg,
12286221Snate@binkert.org        const TheISA::MiscReg &val, ThreadID tid)
12295595Sgblack@eecs.umich.edu{
12306313Sgblack@eecs.umich.edu    this->isa[tid].setMiscRegNoEffect(misc_reg, val);
12315595Sgblack@eecs.umich.edu}
12325595Sgblack@eecs.umich.edu
12335595Sgblack@eecs.umich.edutemplate <class Impl>
12345595Sgblack@eecs.umich.eduvoid
12355595Sgblack@eecs.umich.eduFullO3CPU<Impl>::setMiscReg(int misc_reg,
12366221Snate@binkert.org        const TheISA::MiscReg &val, ThreadID tid)
12375595Sgblack@eecs.umich.edu{
12387897Shestness@cs.utexas.edu    miscRegfileWrites++;
12396313Sgblack@eecs.umich.edu    this->isa[tid].setMiscReg(misc_reg, val, tcBase(tid));
12405595Sgblack@eecs.umich.edu}
12415595Sgblack@eecs.umich.edu
12425595Sgblack@eecs.umich.edutemplate <class Impl>
12431060SN/Auint64_t
12441755SN/AFullO3CPU<Impl>::readIntReg(int reg_idx)
12451060SN/A{
12467897Shestness@cs.utexas.edu    intRegfileReads++;
12471060SN/A    return regFile.readIntReg(reg_idx);
12481060SN/A}
12491060SN/A
12501060SN/Atemplate <class Impl>
12512455SN/AFloatReg
12522455SN/AFullO3CPU<Impl>::readFloatReg(int reg_idx)
12531060SN/A{
12547897Shestness@cs.utexas.edu    fpRegfileReads++;
12552455SN/A    return regFile.readFloatReg(reg_idx);
12561060SN/A}
12571060SN/A
12581060SN/Atemplate <class Impl>
12592455SN/AFloatRegBits
12602455SN/AFullO3CPU<Impl>::readFloatRegBits(int reg_idx)
12612455SN/A{
12627897Shestness@cs.utexas.edu    fpRegfileReads++;
12632455SN/A    return regFile.readFloatRegBits(reg_idx);
12641060SN/A}
12651060SN/A
12661060SN/Atemplate <class Impl>
12671060SN/Avoid
12681755SN/AFullO3CPU<Impl>::setIntReg(int reg_idx, uint64_t val)
12691060SN/A{
12707897Shestness@cs.utexas.edu    intRegfileWrites++;
12711060SN/A    regFile.setIntReg(reg_idx, val);
12721060SN/A}
12731060SN/A
12741060SN/Atemplate <class Impl>
12751060SN/Avoid
12762455SN/AFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val)
12771060SN/A{
12787897Shestness@cs.utexas.edu    fpRegfileWrites++;
12792455SN/A    regFile.setFloatReg(reg_idx, val);
12801060SN/A}
12811060SN/A
12821060SN/Atemplate <class Impl>
12831060SN/Avoid
12842455SN/AFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val)
12852455SN/A{
12867897Shestness@cs.utexas.edu    fpRegfileWrites++;
12872455SN/A    regFile.setFloatRegBits(reg_idx, val);
12881060SN/A}
12891060SN/A
12901060SN/Atemplate <class Impl>
12911060SN/Auint64_t
12926221Snate@binkert.orgFullO3CPU<Impl>::readArchIntReg(int reg_idx, ThreadID tid)
12931060SN/A{
12947897Shestness@cs.utexas.edu    intRegfileReads++;
12952292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
12962292SN/A
12972292SN/A    return regFile.readIntReg(phys_reg);
12982292SN/A}
12992292SN/A
13002292SN/Atemplate <class Impl>
13012292SN/Afloat
13026314Sgblack@eecs.umich.eduFullO3CPU<Impl>::readArchFloatReg(int reg_idx, ThreadID tid)
13032292SN/A{
13047897Shestness@cs.utexas.edu    fpRegfileReads++;
13056032Ssteve.reinhardt@amd.com    int idx = reg_idx + TheISA::NumIntRegs;
13062307SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
13072292SN/A
13082669Sktlim@umich.edu    return regFile.readFloatReg(phys_reg);
13092292SN/A}
13102292SN/A
13112292SN/Atemplate <class Impl>
13122292SN/Auint64_t
13136221Snate@binkert.orgFullO3CPU<Impl>::readArchFloatRegInt(int reg_idx, ThreadID tid)
13142292SN/A{
13157897Shestness@cs.utexas.edu    fpRegfileReads++;
13166032Ssteve.reinhardt@amd.com    int idx = reg_idx + TheISA::NumIntRegs;
13172307SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
13182292SN/A
13192669Sktlim@umich.edu    return regFile.readFloatRegBits(phys_reg);
13201060SN/A}
13211060SN/A
13221060SN/Atemplate <class Impl>
13231060SN/Avoid
13246221Snate@binkert.orgFullO3CPU<Impl>::setArchIntReg(int reg_idx, uint64_t val, ThreadID tid)
13251060SN/A{
13267897Shestness@cs.utexas.edu    intRegfileWrites++;
13272292SN/A    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);
13282292SN/A
13292292SN/A    regFile.setIntReg(phys_reg, val);
13301060SN/A}
13311060SN/A
13321060SN/Atemplate <class Impl>
13331060SN/Avoid
13346314Sgblack@eecs.umich.eduFullO3CPU<Impl>::setArchFloatReg(int reg_idx, float val, ThreadID tid)
13351060SN/A{
13367897Shestness@cs.utexas.edu    fpRegfileWrites++;
13376032Ssteve.reinhardt@amd.com    int idx = reg_idx + TheISA::NumIntRegs;
13382918Sktlim@umich.edu    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
13392292SN/A
13402669Sktlim@umich.edu    regFile.setFloatReg(phys_reg, val);
13411060SN/A}
13421060SN/A
13431060SN/Atemplate <class Impl>
13441060SN/Avoid
13456221Snate@binkert.orgFullO3CPU<Impl>::setArchFloatRegInt(int reg_idx, uint64_t val, ThreadID tid)
13461060SN/A{
13477897Shestness@cs.utexas.edu    fpRegfileWrites++;
13486032Ssteve.reinhardt@amd.com    int idx = reg_idx + TheISA::NumIntRegs;
13492918Sktlim@umich.edu    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);
13501060SN/A
13512669Sktlim@umich.edu    regFile.setFloatRegBits(phys_reg, val);
13522292SN/A}
13532292SN/A
13542292SN/Atemplate <class Impl>
13557720Sgblack@eecs.umich.eduTheISA::PCState
13567720Sgblack@eecs.umich.eduFullO3CPU<Impl>::pcState(ThreadID tid)
13572292SN/A{
13587720Sgblack@eecs.umich.edu    return commit.pcState(tid);
13591060SN/A}
13601060SN/A
13611060SN/Atemplate <class Impl>
13621060SN/Avoid
13637720Sgblack@eecs.umich.eduFullO3CPU<Impl>::pcState(const TheISA::PCState &val, ThreadID tid)
13641060SN/A{
13657720Sgblack@eecs.umich.edu    commit.pcState(val, tid);
13662292SN/A}
13671060SN/A
13682292SN/Atemplate <class Impl>
13697720Sgblack@eecs.umich.eduAddr
13707720Sgblack@eecs.umich.eduFullO3CPU<Impl>::instAddr(ThreadID tid)
13714636Sgblack@eecs.umich.edu{
13727720Sgblack@eecs.umich.edu    return commit.instAddr(tid);
13734636Sgblack@eecs.umich.edu}
13744636Sgblack@eecs.umich.edu
13754636Sgblack@eecs.umich.edutemplate <class Impl>
13767720Sgblack@eecs.umich.eduAddr
13777720Sgblack@eecs.umich.eduFullO3CPU<Impl>::nextInstAddr(ThreadID tid)
13784636Sgblack@eecs.umich.edu{
13797720Sgblack@eecs.umich.edu    return commit.nextInstAddr(tid);
13804636Sgblack@eecs.umich.edu}
13814636Sgblack@eecs.umich.edu
13824636Sgblack@eecs.umich.edutemplate <class Impl>
13837720Sgblack@eecs.umich.eduMicroPC
13847720Sgblack@eecs.umich.eduFullO3CPU<Impl>::microPC(ThreadID tid)
13852292SN/A{
13867720Sgblack@eecs.umich.edu    return commit.microPC(tid);
13874636Sgblack@eecs.umich.edu}
13884636Sgblack@eecs.umich.edu
13894636Sgblack@eecs.umich.edutemplate <class Impl>
13905595Sgblack@eecs.umich.eduvoid
13916221Snate@binkert.orgFullO3CPU<Impl>::squashFromTC(ThreadID tid)
13925595Sgblack@eecs.umich.edu{
13935595Sgblack@eecs.umich.edu    this->thread[tid]->inSyscall = true;
13945595Sgblack@eecs.umich.edu    this->commit.generateTCEvent(tid);
13955595Sgblack@eecs.umich.edu}
13965595Sgblack@eecs.umich.edu
13975595Sgblack@eecs.umich.edutemplate <class Impl>
13982292SN/Atypename FullO3CPU<Impl>::ListIt
13992292SN/AFullO3CPU<Impl>::addInst(DynInstPtr &inst)
14002292SN/A{
14012292SN/A    instList.push_back(inst);
14021060SN/A
14032292SN/A    return --(instList.end());
14042292SN/A}
14051060SN/A
14062292SN/Atemplate <class Impl>
14072292SN/Avoid
14086221Snate@binkert.orgFullO3CPU<Impl>::instDone(ThreadID tid)
14092292SN/A{
14102292SN/A    // Keep an instruction count.
14112292SN/A    thread[tid]->numInst++;
14122292SN/A    thread[tid]->numInsts++;
14132292SN/A    committedInsts[tid]++;
14142292SN/A    totalCommittedInsts++;
14157897Shestness@cs.utexas.edu    system->totalNumInsts++;
14162292SN/A    // Check for instruction-count-based events.
14172292SN/A    comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst);
14187897Shestness@cs.utexas.edu    system->instEventQueue.serviceEvents(system->totalNumInsts);
14192292SN/A}
14202292SN/A
14212292SN/Atemplate <class Impl>
14222292SN/Avoid
14231755SN/AFullO3CPU<Impl>::removeFrontInst(DynInstPtr &inst)
14241060SN/A{
14257720Sgblack@eecs.umich.edu    DPRINTF(O3CPU, "Removing committed instruction [tid:%i] PC %s "
14262292SN/A            "[sn:%lli]\n",
14277720Sgblack@eecs.umich.edu            inst->threadNumber, inst->pcState(), inst->seqNum);
14281060SN/A
14292292SN/A    removeInstsThisCycle = true;
14301060SN/A
14311060SN/A    // Remove the front instruction.
14322292SN/A    removeList.push(inst->getInstListIt());
14331060SN/A}
14341060SN/A
14351060SN/Atemplate <class Impl>
14361060SN/Avoid
14376221Snate@binkert.orgFullO3CPU<Impl>::removeInstsNotInROB(ThreadID tid)
14381060SN/A{
14392733Sktlim@umich.edu    DPRINTF(O3CPU, "Thread %i: Deleting instructions from instruction"
14402292SN/A            " list.\n", tid);
14411060SN/A
14422292SN/A    ListIt end_it;
14431060SN/A
14442292SN/A    bool rob_empty = false;
14452292SN/A
14462292SN/A    if (instList.empty()) {
14472292SN/A        return;
14482292SN/A    } else if (rob.isEmpty(/*tid*/)) {
14492733Sktlim@umich.edu        DPRINTF(O3CPU, "ROB is empty, squashing all insts.\n");
14502292SN/A        end_it = instList.begin();
14512292SN/A        rob_empty = true;
14522292SN/A    } else {
14532292SN/A        end_it = (rob.readTailInst(tid))->getInstListIt();
14542733Sktlim@umich.edu        DPRINTF(O3CPU, "ROB is not empty, squashing insts not in ROB.\n");
14552292SN/A    }
14562292SN/A
14572292SN/A    removeInstsThisCycle = true;
14582292SN/A
14592292SN/A    ListIt inst_it = instList.end();
14602292SN/A
14612292SN/A    inst_it--;
14622292SN/A
14632292SN/A    // Walk through the instruction list, removing any instructions
14642292SN/A    // that were inserted after the given instruction iterator, end_it.
14652292SN/A    while (inst_it != end_it) {
14662292SN/A        assert(!instList.empty());
14672292SN/A
14682292SN/A        squashInstIt(inst_it, tid);
14692292SN/A
14702292SN/A        inst_it--;
14712292SN/A    }
14722292SN/A
14732292SN/A    // If the ROB was empty, then we actually need to remove the first
14742292SN/A    // instruction as well.
14752292SN/A    if (rob_empty) {
14762292SN/A        squashInstIt(inst_it, tid);
14772292SN/A    }
14781060SN/A}
14791060SN/A
14801060SN/Atemplate <class Impl>
14811060SN/Avoid
14826221Snate@binkert.orgFullO3CPU<Impl>::removeInstsUntil(const InstSeqNum &seq_num, ThreadID tid)
14831062SN/A{
14842292SN/A    assert(!instList.empty());
14852292SN/A
14862292SN/A    removeInstsThisCycle = true;
14872292SN/A
14882292SN/A    ListIt inst_iter = instList.end();
14892292SN/A
14902292SN/A    inst_iter--;
14912292SN/A
14922733Sktlim@umich.edu    DPRINTF(O3CPU, "Deleting instructions from instruction "
14932292SN/A            "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",
14942292SN/A            tid, seq_num, (*inst_iter)->seqNum);
14951062SN/A
14962292SN/A    while ((*inst_iter)->seqNum > seq_num) {
14971062SN/A
14982292SN/A        bool break_loop = (inst_iter == instList.begin());
14991062SN/A
15002292SN/A        squashInstIt(inst_iter, tid);
15011062SN/A
15022292SN/A        inst_iter--;
15031062SN/A
15042292SN/A        if (break_loop)
15052292SN/A            break;
15062292SN/A    }
15072292SN/A}
15082292SN/A
15092292SN/Atemplate <class Impl>
15102292SN/Ainline void
15116221Snate@binkert.orgFullO3CPU<Impl>::squashInstIt(const ListIt &instIt, ThreadID tid)
15122292SN/A{
15132292SN/A    if ((*instIt)->threadNumber == tid) {
15142733Sktlim@umich.edu        DPRINTF(O3CPU, "Squashing instruction, "
15157720Sgblack@eecs.umich.edu                "[tid:%i] [sn:%lli] PC %s\n",
15162292SN/A                (*instIt)->threadNumber,
15172292SN/A                (*instIt)->seqNum,
15187720Sgblack@eecs.umich.edu                (*instIt)->pcState());
15191062SN/A
15201062SN/A        // Mark it as squashed.
15212292SN/A        (*instIt)->setSquashed();
15222292SN/A
15232325SN/A        // @todo: Formulate a consistent method for deleting
15242325SN/A        // instructions from the instruction list
15252292SN/A        // Remove the instruction from the list.
15262292SN/A        removeList.push(instIt);
15272292SN/A    }
15282292SN/A}
15292292SN/A
15302292SN/Atemplate <class Impl>
15312292SN/Avoid
15322292SN/AFullO3CPU<Impl>::cleanUpRemovedInsts()
15332292SN/A{
15342292SN/A    while (!removeList.empty()) {
15352733Sktlim@umich.edu        DPRINTF(O3CPU, "Removing instruction, "
15367720Sgblack@eecs.umich.edu                "[tid:%i] [sn:%lli] PC %s\n",
15372292SN/A                (*removeList.front())->threadNumber,
15382292SN/A                (*removeList.front())->seqNum,
15397720Sgblack@eecs.umich.edu                (*removeList.front())->pcState());
15402292SN/A
15412292SN/A        instList.erase(removeList.front());
15422292SN/A
15432292SN/A        removeList.pop();
15441062SN/A    }
15451062SN/A
15462292SN/A    removeInstsThisCycle = false;
15471062SN/A}
15482325SN/A/*
15491062SN/Atemplate <class Impl>
15501062SN/Avoid
15511755SN/AFullO3CPU<Impl>::removeAllInsts()
15521060SN/A{
15531060SN/A    instList.clear();
15541060SN/A}
15552325SN/A*/
15561060SN/Atemplate <class Impl>
15571060SN/Avoid
15581755SN/AFullO3CPU<Impl>::dumpInsts()
15591060SN/A{
15601060SN/A    int num = 0;
15611060SN/A
15622292SN/A    ListIt inst_list_it = instList.begin();
15632292SN/A
15642292SN/A    cprintf("Dumping Instruction List\n");
15652292SN/A
15662292SN/A    while (inst_list_it != instList.end()) {
15672292SN/A        cprintf("Instruction:%i\nPC:%#x\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"
15682292SN/A                "Squashed:%i\n\n",
15697720Sgblack@eecs.umich.edu                num, (*inst_list_it)->instAddr(), (*inst_list_it)->threadNumber,
15702292SN/A                (*inst_list_it)->seqNum, (*inst_list_it)->isIssued(),
15712292SN/A                (*inst_list_it)->isSquashed());
15721060SN/A        inst_list_it++;
15731060SN/A        ++num;
15741060SN/A    }
15751060SN/A}
15762325SN/A/*
15771060SN/Atemplate <class Impl>
15781060SN/Avoid
15791755SN/AFullO3CPU<Impl>::wakeDependents(DynInstPtr &inst)
15801060SN/A{
15811060SN/A    iew.wakeDependents(inst);
15821060SN/A}
15832325SN/A*/
15842292SN/Atemplate <class Impl>
15852292SN/Avoid
15862292SN/AFullO3CPU<Impl>::wakeCPU()
15872292SN/A{
15882325SN/A    if (activityRec.active() || tickEvent.scheduled()) {
15892325SN/A        DPRINTF(Activity, "CPU already running.\n");
15902292SN/A        return;
15912292SN/A    }
15922292SN/A
15932325SN/A    DPRINTF(Activity, "Waking up CPU\n");
15942325SN/A
15957823Ssteve.reinhardt@amd.com    idleCycles += tickToCycles((curTick() - 1) - lastRunningCycle);
15967823Ssteve.reinhardt@amd.com    numCycles += tickToCycles((curTick() - 1) - lastRunningCycle);
15972292SN/A
15985606Snate@binkert.org    schedule(tickEvent, nextCycle());
15992292SN/A}
16002292SN/A
16015807Snate@binkert.org#if FULL_SYSTEM
16025807Snate@binkert.orgtemplate <class Impl>
16035807Snate@binkert.orgvoid
16045807Snate@binkert.orgFullO3CPU<Impl>::wakeup()
16055807Snate@binkert.org{
16065807Snate@binkert.org    if (this->thread[0]->status() != ThreadContext::Suspended)
16075807Snate@binkert.org        return;
16085807Snate@binkert.org
16095807Snate@binkert.org    this->wakeCPU();
16105807Snate@binkert.org
16115807Snate@binkert.org    DPRINTF(Quiesce, "Suspended Processor woken\n");
16125807Snate@binkert.org    this->threadContexts[0]->activate();
16135807Snate@binkert.org}
16145807Snate@binkert.org#endif
16155807Snate@binkert.org
16162292SN/Atemplate <class Impl>
16176221Snate@binkert.orgThreadID
16182292SN/AFullO3CPU<Impl>::getFreeTid()
16192292SN/A{
16206221Snate@binkert.org    for (ThreadID tid = 0; tid < numThreads; tid++) {
16216221Snate@binkert.org        if (!tids[tid]) {
16226221Snate@binkert.org            tids[tid] = true;
16236221Snate@binkert.org            return tid;
16242292SN/A        }
16252292SN/A    }
16262292SN/A
16276221Snate@binkert.org    return InvalidThreadID;
16282292SN/A}
16292292SN/A
16302292SN/Atemplate <class Impl>
16312292SN/Avoid
16322292SN/AFullO3CPU<Impl>::doContextSwitch()
16332292SN/A{
16342292SN/A    if (contextSwitch) {
16352292SN/A
16362292SN/A        //ADD CODE TO DEACTIVE THREAD HERE (???)
16372292SN/A
16386221Snate@binkert.org        ThreadID size = cpuWaitList.size();
16396221Snate@binkert.org        for (ThreadID tid = 0; tid < size; tid++) {
16402292SN/A            activateWhenReady(tid);
16412292SN/A        }
16422292SN/A
16432292SN/A        if (cpuWaitList.size() == 0)
16442292SN/A            contextSwitch = true;
16452292SN/A    }
16462292SN/A}
16472292SN/A
16482292SN/Atemplate <class Impl>
16492292SN/Avoid
16502292SN/AFullO3CPU<Impl>::updateThreadPriority()
16512292SN/A{
16526221Snate@binkert.org    if (activeThreads.size() > 1) {
16532292SN/A        //DEFAULT TO ROUND ROBIN SCHEME
16542292SN/A        //e.g. Move highest priority to end of thread list
16556221Snate@binkert.org        list<ThreadID>::iterator list_begin = activeThreads.begin();
16566221Snate@binkert.org        list<ThreadID>::iterator list_end   = activeThreads.end();
16572292SN/A
16582292SN/A        unsigned high_thread = *list_begin;
16592292SN/A
16602292SN/A        activeThreads.erase(list_begin);
16612292SN/A
16622292SN/A        activeThreads.push_back(high_thread);
16632292SN/A    }
16642292SN/A}
16651060SN/A
16661755SN/A// Forward declaration of FullO3CPU.
16672818Sksewell@umich.edutemplate class FullO3CPU<O3CPUImpl>;
1668